Added 2 settings for unit health bars: always show unit health, and team health bar colors

This commit is contained in:
Curtis Shmyr
2013-11-10 11:48:41 -07:00
parent 90fa7743c3
commit d30f60809b
8 changed files with 106 additions and 44 deletions

View File

@@ -133,6 +133,8 @@ namespace OpenRA.GameRules
public float ViewportEdgeScrollStep = 10f;
public bool UseClassicMouseStyle = false;
public bool AlwaysShowStatusBars = false;
public bool TeamHealthColors = false;
// Internal game settings
public int Timestep = 40;
@@ -146,6 +148,7 @@ namespace OpenRA.GameRules
public Hotkey CycleBaseKey = new Hotkey(Keycode.BACKSPACE, Modifiers.None);
public Hotkey ToLastEventKey = new Hotkey(Keycode.SPACE, Modifiers.None);
public Hotkey ToSelectionKey = new Hotkey(Keycode.HOME, Modifiers.None);
public Hotkey ToggleStatusBarsKey = new Hotkey(Keycode.INSERT, Modifiers.None);
public Hotkey PauseKey = new Hotkey(Keycode.F9, Modifiers.None);
public Hotkey SellKey = new Hotkey(Keycode.F10, Modifiers.None);

View File

@@ -146,6 +146,16 @@ namespace OpenRA.Graphics
foreach (var t in g)
t.RenderAfterWorld(this);
if (!world.IsShellmap && Game.Settings.Game.AlwaysShowStatusBars)
{
foreach (var g in world.Actors.Where(a => !a.Destroyed
&& a.HasTrait<Selectable>()
&& !world.FogObscures(a)
&& !world.Selection.Actors.Contains(a)))
DrawRollover(g);
}
Game.Renderer.Flush();
}
@@ -177,7 +187,7 @@ namespace OpenRA.Graphics
{
var selectable = unit.TraitOrDefault<Selectable>();
if (selectable != null)
selectable.DrawRollover(this, unit);
selectable.DrawRollover(this);
}
public void DrawRangeCircle(Color c, float2 location, float range)

View File

@@ -48,12 +48,12 @@ namespace OpenRA.Traits
var Xy = new float2(bounds.Right, bounds.Top);
wr.DrawSelectionBox(self, Color.White);
DrawHealthBar(wr, self, xy, Xy);
DrawExtraBars(wr, self, xy, Xy);
DrawUnitPath(wr, self);
DrawHealthBar(wr, xy, Xy);
DrawExtraBars(wr, xy, Xy);
DrawUnitPath(wr);
}
public void DrawRollover(WorldRenderer wr, Actor self)
public void DrawRollover(WorldRenderer wr)
{
if (!Info.Selectable)
return;
@@ -65,11 +65,11 @@ namespace OpenRA.Traits
var xy = new float2(bounds.Left, bounds.Top);
var Xy = new float2(bounds.Right, bounds.Top);
DrawHealthBar(wr, self, xy, Xy);
DrawExtraBars(wr, self, xy, Xy);
DrawHealthBar(wr, xy, Xy);
DrawExtraBars(wr, xy, Xy);
}
void DrawExtraBars(WorldRenderer wr, Actor self, float2 xy, float2 Xy)
void DrawExtraBars(WorldRenderer wr, float2 xy, float2 Xy)
{
foreach (var extraBar in self.TraitsImplementing<ISelectionBar>())
{
@@ -78,12 +78,12 @@ namespace OpenRA.Traits
{
xy.Y += (int)(4 / wr.Viewport.Zoom);
Xy.Y += (int)(4 / wr.Viewport.Zoom);
DrawSelectionBar(wr, self, xy, Xy, extraBar.GetValue(), extraBar.GetColor());
DrawSelectionBar(wr, xy, Xy, extraBar.GetValue(), extraBar.GetColor());
}
}
}
void DrawSelectionBar(WorldRenderer wr, Actor self, float2 xy, float2 Xy, float value, Color barColor)
void DrawSelectionBar(WorldRenderer wr, float2 xy, float2 Xy, float value, Color barColor)
{
if (!self.IsInWorld)
return;
@@ -110,7 +110,7 @@ namespace OpenRA.Traits
wlr.DrawLine(xy + r, z + r, barColor2, barColor2);
}
void DrawHealthBar(WorldRenderer wr, Actor self, float2 xy, float2 Xy)
void DrawHealthBar(WorldRenderer wr, float2 xy, float2 Xy)
{
if (!self.IsInWorld) return;
@@ -123,9 +123,7 @@ namespace OpenRA.Traits
var q = new float2(0, -3 / wr.Viewport.Zoom);
var r = new float2(0, -2 / wr.Viewport.Zoom);
var healthColor = (health.DamageState == DamageState.Critical) ? Color.Red :
(health.DamageState == DamageState.Heavy) ? Color.Yellow : Color.LimeGreen;
var healthColor = GetHealthColor(health);
var healthColor2 = Color.FromArgb(
255,
healthColor.R / 2,
@@ -159,7 +157,7 @@ namespace OpenRA.Traits
}
}
void DrawUnitPath(WorldRenderer wr, Actor self)
void DrawUnitPath(WorldRenderer wr)
{
if (self.World.LocalPlayer == null || !self.World.LocalPlayer.PlayerActor.Trait<DeveloperMode>().PathDebug)
return;
@@ -180,5 +178,14 @@ namespace OpenRA.Traits
}
}
Color GetHealthColor(Health health)
{
if (Game.Settings.Game.TeamHealthColors)
return self.Owner.IsAlliedWith(self.World.LocalPlayer) ? Color.LimeGreen :
self.Owner.NonCombatant ? Color.Tan : Color.Red;
else
return health.DamageState == DamageState.Critical ? Color.Red :
health.DamageState == DamageState.Heavy ? Color.Yellow : Color.LimeGreen;
}
}
}