DrawHealthBar in own function
This commit is contained in:
@@ -90,8 +90,10 @@ namespace OpenRa.Game.Graphics
|
|||||||
Game.controller.orderGenerator.Render();
|
Game.controller.orderGenerator.Render();
|
||||||
|
|
||||||
lineRenderer.Flush();
|
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" };
|
static readonly string[] pipStrings = { "pip-empty", "pip-green", "pip-yellow", "pip-red", "pip-gray" };
|
||||||
|
|
||||||
public void DrawSelectionBox(Actor selectedUnit, Color c, bool drawHealthBar)
|
public void DrawSelectionBox(Actor selectedUnit, Color c, bool drawHealthBar)
|
||||||
@@ -116,39 +118,7 @@ namespace OpenRa.Game.Graphics
|
|||||||
|
|
||||||
if (drawHealthBar)
|
if (drawHealthBar)
|
||||||
{
|
{
|
||||||
c = Color.Gray;
|
DrawHealthBar(selectedUnit, xy, Xy);
|
||||||
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
|
|
||||||
DrawPips(selectedUnit, 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)
|
void DrawPips(Actor selectedUnit, float2 xY)
|
||||||
|
|||||||
Reference in New Issue
Block a user