DrawHealthBar in own function

This commit is contained in:
Chris Forbes
2009-12-19 16:29:13 +13:00
parent 5ac0fa5cde
commit 407fa3c8ea

View File

@@ -90,8 +90,10 @@ namespace OpenRa.Game.Graphics
Game.controller.orderGenerator.Render();
lineRenderer.Flush();
spriteRenderer.Flush();
}
// depends on the order of pips in TraitsInterfaces.cs!
static readonly string[] pipStrings = { "pip-empty", "pip-green", "pip-yellow", "pip-red", "pip-gray" };
public void DrawSelectionBox(Actor selectedUnit, Color c, bool drawHealthBar)
@@ -116,39 +118,7 @@ namespace OpenRa.Game.Graphics
if (drawHealthBar)
{
c = Color.Gray;
lineRenderer.DrawLine(xy + new float2(0, -2), xy + new float2(0, -4), c, c);
lineRenderer.DrawLine(Xy + new float2(0, -2), Xy + new float2(0, -4), c, c);
var healthAmount = (float)selectedUnit.Health / selectedUnit.Info.Strength;
var healthColor = (healthAmount < Rules.General.ConditionRed) ? Color.Red
: (healthAmount < Rules.General.ConditionYellow) ? Color.Yellow
: Color.LimeGreen;
var healthColor2 = Color.FromArgb(
255,
healthColor.R / 2,
healthColor.G / 2,
healthColor.B / 2);
var z = float2.Lerp(xy, Xy, healthAmount);
lineRenderer.DrawLine(z + new float2(0, -4), Xy + new float2(0, -4), c, c);
lineRenderer.DrawLine(z + new float2(0, -2), Xy + new float2(0, -2), c, c);
lineRenderer.DrawLine(xy + new float2(0, -3),
z + new float2(0, -3),
healthColor, healthColor);
lineRenderer.DrawLine(xy + new float2(0, -2),
z + new float2(0, -2),
healthColor2, healthColor2);
lineRenderer.DrawLine(xy + new float2(0, -4),
z + new float2(0, -4),
healthColor2, healthColor2);
// Render Pips
DrawHealthBar(selectedUnit, xy, Xy);
DrawPips(selectedUnit, xY);
}
@@ -170,7 +140,33 @@ namespace OpenRa.Game.Graphics
}
}
}
spriteRenderer.Flush();
}
void DrawHealthBar(Actor selectedUnit, float2 xy, float2 Xy)
{
var c = Color.Gray;
lineRenderer.DrawLine(xy + new float2(0, -2), xy + new float2(0, -4), c, c);
lineRenderer.DrawLine(Xy + new float2(0, -2), Xy + new float2(0, -4), c, c);
var healthAmount = (float)selectedUnit.Health / selectedUnit.Info.Strength;
var healthColor = (healthAmount < Rules.General.ConditionRed) ? Color.Red
: (healthAmount < Rules.General.ConditionYellow) ? Color.Yellow
: Color.LimeGreen;
var healthColor2 = Color.FromArgb(
255,
healthColor.R / 2,
healthColor.G / 2,
healthColor.B / 2);
var z = float2.Lerp(xy, Xy, healthAmount);
lineRenderer.DrawLine(z + new float2(0, -4), Xy + new float2(0, -4), c, c);
lineRenderer.DrawLine(z + new float2(0, -2), Xy + new float2(0, -2), c, c);
lineRenderer.DrawLine(xy + new float2(0, -3), z + new float2(0, -3), healthColor, healthColor);
lineRenderer.DrawLine(xy + new float2(0, -2), z + new float2(0, -2), healthColor2, healthColor2);
lineRenderer.DrawLine(xy + new float2(0, -4), z + new float2(0, -4), healthColor2, healthColor2);
}
void DrawPips(Actor selectedUnit, float2 xY)