1
0
forked from 0ad/0ad

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:
Ykkrosh 2010-10-03 00:30:43 +00:00
parent 1d32223e1a
commit 9a0db9713e
11 changed files with 80 additions and 16 deletions

Binary file not shown.

Binary file not shown.

View File

@ -1,4 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<Textures>
<File pattern="health_*.png" format="rgba" mipmap="true"/>
<File pattern="supply_*.png" format="rgba" mipmap="true"/>
</Textures>

View File

@ -471,8 +471,21 @@ function handleInputAfterGui(ev)
switch (ev.type)
{
case "mousemotion":
// Highlight the first hovered entities, if it's not a unit
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;
case "mousebuttondown":

View File

@ -56,6 +56,8 @@ ResourceSupply.prototype.TakeResources = function(rate)
if (this.amount == 0)
Engine.DestroyEntity(this.entity);
Engine.PostMessage(this.entity, MT_ResourceSupplyChanged, { "from": old, "to": this.amount });
return { "amount": change, "exhausted": (old == 0) };
};

View File

@ -1,6 +1,12 @@
function StatusBars() {}
StatusBars.prototype.Schema =
"<element name='BarWidth'>" +
"<data type='decimal'/>" +
"</element>" +
"<element name='BarHeight'>" +
"<data type='decimal'/>" +
"</element>" +
"<element name='HeightOffset'>" +
"<data type='decimal'/>" +
"</element>";
@ -34,6 +40,12 @@ StatusBars.prototype.OnHealthChanged = function(msg)
this.RegenerateSprites();
};
StatusBars.prototype.OnResourceSupplyChanged = function(msg)
{
if (this.enabled)
this.RegenerateSprites();
};
StatusBars.prototype.ResetSprites = function()
{
var cmpOverlayRenderer = Engine.QueryInterface(this.entity, IID_OverlayRenderer);
@ -46,28 +58,42 @@ StatusBars.prototype.RegenerateSprites = function()
cmpOverlayRenderer.Reset();
// Size of health bar (in world-space units)
var width = 2;
var height = 1/3;
var width = +this.template.BarWidth;
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 };
// 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);
if (cmpHealth)
{
var filled = cmpHealth.GetHitpoints() / cmpHealth.GetMaxHitpoints();
AddBar("health", cmpHealth.GetHitpoints() / cmpHealth.GetMaxHitpoints());
}
cmpOverlayRenderer.AddSprite(
"art/textures/ui/session/icons/health_bg.png",
{ "x": -width/2, "y": -height/2 }, { "x": width/2, "y": height/2 },
offset
);
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
);
var cmpResourceSupply = Engine.QueryInterface(this.entity, IID_ResourceSupply);
if (cmpResourceSupply)
{
AddBar("supply", cmpResourceSupply.GetCurrentAmount() / cmpResourceSupply.GetMaxAmount());
}
};

View File

@ -1 +1,5 @@
Engine.RegisterInterface("ResourceSupply");
// Message of the form { "from": 100, "to", 90 },
// sent whenever supply level changes.
Engine.RegisterMessageType("ResourceSupplyChanged");

View File

@ -8,4 +8,10 @@
<Range>0</Range>
<RetainInFog>true</RetainInFog>
</Vision>
<StatusBars>
<BarWidth>2.0</BarWidth>
<BarHeight>0.333</BarHeight>
<HeightOffset>5.0</HeightOffset>
</StatusBars>
<OverlayRenderer/>
</Entity>

View File

@ -44,6 +44,8 @@
<Crush>10.0</Crush>
</Armour>
<StatusBars>
<BarWidth>8.0</BarWidth>
<BarHeight>0.666</BarHeight>
<HeightOffset>12.0</HeightOffset>
</StatusBars>
<OverlayRenderer/>

View File

@ -55,6 +55,8 @@
<CostClass>default</CostClass>
</UnitMotion>
<StatusBars>
<BarWidth>2.0</BarWidth>
<BarHeight>0.333</BarHeight>
<HeightOffset>5.0</HeightOffset>
</StatusBars>
<OverlayRenderer/>

View File

@ -462,6 +462,8 @@ void CCmpTemplateManager::CopyFoundationSubset(CParamNode& out, const CParamNode
permittedComponentTypes.insert("Footprint");
permittedComponentTypes.insert("Armour");
permittedComponentTypes.insert("Health");
permittedComponentTypes.insert("StatusBars");
permittedComponentTypes.insert("OverlayRenderer");
permittedComponentTypes.insert("Decay");
permittedComponentTypes.insert("Cost");
permittedComponentTypes.insert("Sound");