Add resource supply status bars.
Change bar size for buildings. Only highlight one entity on mouse hover, and only if it's not a unit. Display status bars on foundations. This was SVN commit r8249.
This commit is contained in:
parent
1d32223e1a
commit
9a0db9713e
BIN
binaries/data/mods/public/art/textures/ui/session/icons/supply_bg.png
(Stored with Git LFS)
Normal file
BIN
binaries/data/mods/public/art/textures/ui/session/icons/supply_bg.png
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
binaries/data/mods/public/art/textures/ui/session/icons/supply_fg.png
(Stored with Git LFS)
Normal file
BIN
binaries/data/mods/public/art/textures/ui/session/icons/supply_fg.png
(Stored with Git LFS)
Normal file
Binary file not shown.
@ -1,4 +1,5 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<Textures>
|
<Textures>
|
||||||
<File pattern="health_*.png" format="rgba" mipmap="true"/>
|
<File pattern="health_*.png" format="rgba" mipmap="true"/>
|
||||||
|
<File pattern="supply_*.png" format="rgba" mipmap="true"/>
|
||||||
</Textures>
|
</Textures>
|
||||||
|
@ -471,8 +471,21 @@ function handleInputAfterGui(ev)
|
|||||||
switch (ev.type)
|
switch (ev.type)
|
||||||
{
|
{
|
||||||
case "mousemotion":
|
case "mousemotion":
|
||||||
|
// Highlight the first hovered entities, if it's not a unit
|
||||||
var ents = Engine.PickEntitiesAtPoint(ev.x, ev.y);
|
var ents = Engine.PickEntitiesAtPoint(ev.x, ev.y);
|
||||||
g_Selection.setHighlightList(ents);
|
if (ents.length == 0)
|
||||||
|
{
|
||||||
|
g_Selection.setHighlightList([]);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
var entState = GetEntityState(ents[0]);
|
||||||
|
if (entState && !isUnit(entState))
|
||||||
|
g_Selection.setHighlightList([ents[0]]);
|
||||||
|
else
|
||||||
|
g_Selection.setHighlightList([]);
|
||||||
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
case "mousebuttondown":
|
case "mousebuttondown":
|
||||||
|
@ -56,6 +56,8 @@ ResourceSupply.prototype.TakeResources = function(rate)
|
|||||||
if (this.amount == 0)
|
if (this.amount == 0)
|
||||||
Engine.DestroyEntity(this.entity);
|
Engine.DestroyEntity(this.entity);
|
||||||
|
|
||||||
|
Engine.PostMessage(this.entity, MT_ResourceSupplyChanged, { "from": old, "to": this.amount });
|
||||||
|
|
||||||
return { "amount": change, "exhausted": (old == 0) };
|
return { "amount": change, "exhausted": (old == 0) };
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -1,6 +1,12 @@
|
|||||||
function StatusBars() {}
|
function StatusBars() {}
|
||||||
|
|
||||||
StatusBars.prototype.Schema =
|
StatusBars.prototype.Schema =
|
||||||
|
"<element name='BarWidth'>" +
|
||||||
|
"<data type='decimal'/>" +
|
||||||
|
"</element>" +
|
||||||
|
"<element name='BarHeight'>" +
|
||||||
|
"<data type='decimal'/>" +
|
||||||
|
"</element>" +
|
||||||
"<element name='HeightOffset'>" +
|
"<element name='HeightOffset'>" +
|
||||||
"<data type='decimal'/>" +
|
"<data type='decimal'/>" +
|
||||||
"</element>";
|
"</element>";
|
||||||
@ -34,6 +40,12 @@ StatusBars.prototype.OnHealthChanged = function(msg)
|
|||||||
this.RegenerateSprites();
|
this.RegenerateSprites();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
StatusBars.prototype.OnResourceSupplyChanged = function(msg)
|
||||||
|
{
|
||||||
|
if (this.enabled)
|
||||||
|
this.RegenerateSprites();
|
||||||
|
};
|
||||||
|
|
||||||
StatusBars.prototype.ResetSprites = function()
|
StatusBars.prototype.ResetSprites = function()
|
||||||
{
|
{
|
||||||
var cmpOverlayRenderer = Engine.QueryInterface(this.entity, IID_OverlayRenderer);
|
var cmpOverlayRenderer = Engine.QueryInterface(this.entity, IID_OverlayRenderer);
|
||||||
@ -46,28 +58,42 @@ StatusBars.prototype.RegenerateSprites = function()
|
|||||||
cmpOverlayRenderer.Reset();
|
cmpOverlayRenderer.Reset();
|
||||||
|
|
||||||
// Size of health bar (in world-space units)
|
// Size of health bar (in world-space units)
|
||||||
var width = 2;
|
var width = +this.template.BarWidth;
|
||||||
var height = 1/3;
|
var height = +this.template.BarHeight;
|
||||||
|
|
||||||
// Offset from the unit's position
|
// World-space offset from the unit's position
|
||||||
var offset = { "x": 0, "y": +this.template.HeightOffset, "z": 0 };
|
var offset = { "x": 0, "y": +this.template.HeightOffset, "z": 0 };
|
||||||
|
|
||||||
|
// Billboard offset of next bar
|
||||||
|
var yoffset = 0;
|
||||||
|
|
||||||
|
var AddBar = function(type, amount)
|
||||||
|
{
|
||||||
|
cmpOverlayRenderer.AddSprite(
|
||||||
|
"art/textures/ui/session/icons/"+type+"_bg.png",
|
||||||
|
{ "x": -width/2, "y": -height/2 + yoffset }, { "x": width/2, "y": height/2 + yoffset },
|
||||||
|
offset
|
||||||
|
);
|
||||||
|
|
||||||
|
cmpOverlayRenderer.AddSprite(
|
||||||
|
"art/textures/ui/session/icons/"+type+"_fg.png",
|
||||||
|
{ "x": -width/2, "y": -height/2 + yoffset }, { "x": width*(amount - 0.5), "y": height/2 + yoffset },
|
||||||
|
offset
|
||||||
|
);
|
||||||
|
|
||||||
|
yoffset -= height * 1.2;
|
||||||
|
};
|
||||||
|
|
||||||
var cmpHealth = Engine.QueryInterface(this.entity, IID_Health);
|
var cmpHealth = Engine.QueryInterface(this.entity, IID_Health);
|
||||||
if (cmpHealth)
|
if (cmpHealth)
|
||||||
{
|
{
|
||||||
var filled = cmpHealth.GetHitpoints() / cmpHealth.GetMaxHitpoints();
|
AddBar("health", cmpHealth.GetHitpoints() / cmpHealth.GetMaxHitpoints());
|
||||||
|
}
|
||||||
|
|
||||||
cmpOverlayRenderer.AddSprite(
|
var cmpResourceSupply = Engine.QueryInterface(this.entity, IID_ResourceSupply);
|
||||||
"art/textures/ui/session/icons/health_bg.png",
|
if (cmpResourceSupply)
|
||||||
{ "x": -width/2, "y": -height/2 }, { "x": width/2, "y": height/2 },
|
{
|
||||||
offset
|
AddBar("supply", cmpResourceSupply.GetCurrentAmount() / cmpResourceSupply.GetMaxAmount());
|
||||||
);
|
|
||||||
|
|
||||||
cmpOverlayRenderer.AddSprite(
|
|
||||||
"art/textures/ui/session/icons/health_fg.png",
|
|
||||||
{ "x": -width/2, "y": -height/2 }, { "x": width*(filled - 0.5), "y": height/2 },
|
|
||||||
offset
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -1 +1,5 @@
|
|||||||
Engine.RegisterInterface("ResourceSupply");
|
Engine.RegisterInterface("ResourceSupply");
|
||||||
|
|
||||||
|
// Message of the form { "from": 100, "to", 90 },
|
||||||
|
// sent whenever supply level changes.
|
||||||
|
Engine.RegisterMessageType("ResourceSupplyChanged");
|
||||||
|
@ -8,4 +8,10 @@
|
|||||||
<Range>0</Range>
|
<Range>0</Range>
|
||||||
<RetainInFog>true</RetainInFog>
|
<RetainInFog>true</RetainInFog>
|
||||||
</Vision>
|
</Vision>
|
||||||
|
<StatusBars>
|
||||||
|
<BarWidth>2.0</BarWidth>
|
||||||
|
<BarHeight>0.333</BarHeight>
|
||||||
|
<HeightOffset>5.0</HeightOffset>
|
||||||
|
</StatusBars>
|
||||||
|
<OverlayRenderer/>
|
||||||
</Entity>
|
</Entity>
|
||||||
|
@ -44,6 +44,8 @@
|
|||||||
<Crush>10.0</Crush>
|
<Crush>10.0</Crush>
|
||||||
</Armour>
|
</Armour>
|
||||||
<StatusBars>
|
<StatusBars>
|
||||||
|
<BarWidth>8.0</BarWidth>
|
||||||
|
<BarHeight>0.666</BarHeight>
|
||||||
<HeightOffset>12.0</HeightOffset>
|
<HeightOffset>12.0</HeightOffset>
|
||||||
</StatusBars>
|
</StatusBars>
|
||||||
<OverlayRenderer/>
|
<OverlayRenderer/>
|
||||||
|
@ -55,6 +55,8 @@
|
|||||||
<CostClass>default</CostClass>
|
<CostClass>default</CostClass>
|
||||||
</UnitMotion>
|
</UnitMotion>
|
||||||
<StatusBars>
|
<StatusBars>
|
||||||
|
<BarWidth>2.0</BarWidth>
|
||||||
|
<BarHeight>0.333</BarHeight>
|
||||||
<HeightOffset>5.0</HeightOffset>
|
<HeightOffset>5.0</HeightOffset>
|
||||||
</StatusBars>
|
</StatusBars>
|
||||||
<OverlayRenderer/>
|
<OverlayRenderer/>
|
||||||
|
@ -462,6 +462,8 @@ void CCmpTemplateManager::CopyFoundationSubset(CParamNode& out, const CParamNode
|
|||||||
permittedComponentTypes.insert("Footprint");
|
permittedComponentTypes.insert("Footprint");
|
||||||
permittedComponentTypes.insert("Armour");
|
permittedComponentTypes.insert("Armour");
|
||||||
permittedComponentTypes.insert("Health");
|
permittedComponentTypes.insert("Health");
|
||||||
|
permittedComponentTypes.insert("StatusBars");
|
||||||
|
permittedComponentTypes.insert("OverlayRenderer");
|
||||||
permittedComponentTypes.insert("Decay");
|
permittedComponentTypes.insert("Decay");
|
||||||
permittedComponentTypes.insert("Cost");
|
permittedComponentTypes.insert("Cost");
|
||||||
permittedComponentTypes.insert("Sound");
|
permittedComponentTypes.insert("Sound");
|
||||||
|
Loading…
Reference in New Issue
Block a user