Merge pull request #4054 from cjshmyr/healthbars

Added 2 new settings for unit health bars (fixes #3867)
This commit is contained in:
Matthias Mailänder
2013-11-24 13:08:50 -08:00
8 changed files with 106 additions and 44 deletions

View File

@@ -13,6 +13,8 @@ NEW:
Improved the ingame chat interface and input, with it defaulting to Team Chat. Improved the ingame chat interface and input, with it defaulting to Team Chat.
Redesigned the settings panel. Redesigned the settings panel.
Re-added move flashes. Re-added move flashes.
Added a setting to always display unit status bars (can also be toggled by hotkey).
Added a setting for team health bar colors.
Asset Browser: Asset Browser:
Fixed crashes when trying to load invalid filenames or sprites with just 1 frame. Fixed crashes when trying to load invalid filenames or sprites with just 1 frame.
Added support for browsing the folders for R8 files. Added support for browsing the folders for R8 files.

View File

@@ -133,6 +133,8 @@ namespace OpenRA.GameRules
public float ViewportEdgeScrollStep = 10f; public float ViewportEdgeScrollStep = 10f;
public bool UseClassicMouseStyle = false; public bool UseClassicMouseStyle = false;
public bool AlwaysShowStatusBars = false;
public bool TeamHealthColors = false;
// Internal game settings // Internal game settings
public int Timestep = 40; public int Timestep = 40;
@@ -146,6 +148,7 @@ namespace OpenRA.GameRules
public Hotkey CycleBaseKey = new Hotkey(Keycode.BACKSPACE, Modifiers.None); public Hotkey CycleBaseKey = new Hotkey(Keycode.BACKSPACE, Modifiers.None);
public Hotkey ToLastEventKey = new Hotkey(Keycode.SPACE, Modifiers.None); public Hotkey ToLastEventKey = new Hotkey(Keycode.SPACE, Modifiers.None);
public Hotkey ToSelectionKey = new Hotkey(Keycode.HOME, 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 PauseKey = new Hotkey(Keycode.F9, Modifiers.None);
public Hotkey SellKey = new Hotkey(Keycode.F10, 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) foreach (var t in g)
t.RenderAfterWorld(this); 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(); Game.Renderer.Flush();
} }
@@ -177,7 +187,7 @@ namespace OpenRA.Graphics
{ {
var selectable = unit.TraitOrDefault<Selectable>(); var selectable = unit.TraitOrDefault<Selectable>();
if (selectable != null) if (selectable != null)
selectable.DrawRollover(this, unit); selectable.DrawRollover(this);
} }
public void DrawRangeCircle(Color c, float2 location, float range) 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); var Xy = new float2(bounds.Right, bounds.Top);
wr.DrawSelectionBox(self, Color.White); wr.DrawSelectionBox(self, Color.White);
DrawHealthBar(wr, self, xy, Xy); DrawHealthBar(wr, xy, Xy);
DrawExtraBars(wr, self, xy, Xy); DrawExtraBars(wr, xy, Xy);
DrawUnitPath(wr, self); DrawUnitPath(wr);
} }
public void DrawRollover(WorldRenderer wr, Actor self) public void DrawRollover(WorldRenderer wr)
{ {
if (!Info.Selectable) if (!Info.Selectable)
return; return;
@@ -65,11 +65,11 @@ namespace OpenRA.Traits
var xy = new float2(bounds.Left, bounds.Top); var xy = new float2(bounds.Left, bounds.Top);
var Xy = new float2(bounds.Right, bounds.Top); var Xy = new float2(bounds.Right, bounds.Top);
DrawHealthBar(wr, self, xy, Xy); DrawHealthBar(wr, xy, Xy);
DrawExtraBars(wr, self, 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>()) 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);
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) if (!self.IsInWorld)
return; return;
@@ -110,7 +110,7 @@ namespace OpenRA.Traits
wlr.DrawLine(xy + r, z + r, barColor2, barColor2); 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; if (!self.IsInWorld) return;
@@ -123,9 +123,7 @@ namespace OpenRA.Traits
var q = new float2(0, -3 / wr.Viewport.Zoom); var q = new float2(0, -3 / wr.Viewport.Zoom);
var r = new float2(0, -2 / wr.Viewport.Zoom); var r = new float2(0, -2 / wr.Viewport.Zoom);
var healthColor = (health.DamageState == DamageState.Critical) ? Color.Red : var healthColor = GetHealthColor(health);
(health.DamageState == DamageState.Heavy) ? Color.Yellow : Color.LimeGreen;
var healthColor2 = Color.FromArgb( var healthColor2 = Color.FromArgb(
255, 255,
healthColor.R / 2, 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) if (self.World.LocalPlayer == null || !self.World.LocalPlayer.PlayerActor.Trait<DeveloperMode>().PathDebug)
return; 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;
}
} }
} }

View File

@@ -18,7 +18,7 @@ using OpenRA.GameRules;
using OpenRA.Graphics; using OpenRA.Graphics;
using OpenRA.Widgets; using OpenRA.Widgets;
namespace OpenRA.Mods.Ra.Widgets.Logic namespace OpenRA.Mods.RA.Widgets.Logic
{ {
public class SettingsLogic public class SettingsLogic
{ {
@@ -120,6 +120,8 @@ namespace OpenRA.Mods.Ra.Widgets.Logic
BindCheckboxPref(panel, "PIXELDOUBLE_CHECKBOX", ds, "PixelDouble"); BindCheckboxPref(panel, "PIXELDOUBLE_CHECKBOX", ds, "PixelDouble");
BindCheckboxPref(panel, "FRAME_LIMIT_CHECKBOX", ds, "CapFramerate"); BindCheckboxPref(panel, "FRAME_LIMIT_CHECKBOX", ds, "CapFramerate");
BindCheckboxPref(panel, "SHOW_SHELLMAP", gs, "ShowShellmap"); BindCheckboxPref(panel, "SHOW_SHELLMAP", gs, "ShowShellmap");
BindCheckboxPref(panel, "ALWAYS_SHOW_STATUS_BARS_CHECKBOX", gs, "AlwaysShowStatusBars");
BindCheckboxPref(panel, "TEAM_HEALTH_COLORS_CHECKBOX", gs, "TeamHealthColors");
var languageDropDownButton = panel.Get<DropDownButtonWidget>("LANGUAGE_DROPDOWNBUTTON"); var languageDropDownButton = panel.Get<DropDownButtonWidget>("LANGUAGE_DROPDOWNBUTTON");
languageDropDownButton.OnMouseDown = _ => ShowLanguageDropdown(languageDropDownButton); languageDropDownButton.OnMouseDown = _ => ShowLanguageDropdown(languageDropDownButton);
@@ -244,7 +246,8 @@ namespace OpenRA.Mods.Ra.Widgets.Logic
{ "SellKey", "Sell mode" }, { "SellKey", "Sell mode" },
{ "PowerDownKey", "Power-down mode" }, { "PowerDownKey", "Power-down mode" },
{ "RepairKey", "Repair mode" }, { "RepairKey", "Repair mode" },
{ "CycleTabsKey", "Cycle production tabs" } { "CycleTabsKey", "Cycle production tabs" },
{ "ToggleStatusBarsKey", "Toggle status bars" }
}; };
var unitHotkeys = new Dictionary<string, string>() var unitHotkeys = new Dictionary<string, string>()

View File

@@ -56,6 +56,9 @@ namespace OpenRA.Mods.RA.Widgets
if (key == ks.ToSelectionKey) if (key == ks.ToSelectionKey)
return ToSelection(); return ToSelection();
if (key == ks.ToggleStatusBarsKey)
return ToggleStatusBars();
// Put all functions that aren't unit-specific before this line! // Put all functions that aren't unit-specific before this line!
if (!world.Selection.Actors.Any()) if (!world.Selection.Actors.Any())
return false; return false;
@@ -217,5 +220,11 @@ namespace OpenRA.Mods.RA.Widgets
worldRenderer.Viewport.Center(world.Selection.Actors); worldRenderer.Viewport.Center(world.Selection.Actors);
return true; return true;
} }
bool ToggleStatusBars()
{
Game.Settings.Game.AlwaysShowStatusBars ^= true;
return true;
}
} }
} }

View File

@@ -3,7 +3,7 @@ Container@SETTINGS_PANEL:
X:(WINDOW_RIGHT - WIDTH)/2 X:(WINDOW_RIGHT - WIDTH)/2
Y:(WINDOW_BOTTOM - HEIGHT)/2 Y:(WINDOW_BOTTOM - HEIGHT)/2
Width:590 Width:590
Height:260+68 Height:310+68
Children: Children:
Label@TITLE: Label@TITLE:
Width:590 Width:590
@@ -34,21 +34,21 @@ Container@SETTINGS_PANEL:
Height:35 Height:35
Text:Advanced Text:Advanced
Button@RESET_BUTTON: Button@RESET_BUTTON:
Y:293 Y:343
Width:140 Width:140
Height:35 Height:35
Text:Reset Text:Reset
Button@BACK_BUTTON: Button@BACK_BUTTON:
Key:escape Key:escape
X:PARENT_RIGHT-WIDTH X:PARENT_RIGHT-WIDTH
Y:293 Y:343
Width:140 Width:140
Height:35 Height:35
Text:Back Text:Back
Background@bg: Background@bg:
Y:34 Y:34
Width:590 Width:590
Height:260 Height:310
Background:panel-black Background:panel-black
Children: Children:
Container@DISPLAY_PANEL: Container@DISPLAY_PANEL:
@@ -120,7 +120,7 @@ Container@SETTINGS_PANEL:
Text:Enable Frame Limiter Text:Enable Frame Limiter
Checkbox@PIXELDOUBLE_CHECKBOX: Checkbox@PIXELDOUBLE_CHECKBOX:
X:310 X:310
Y:105 Y:100
Width:200 Width:200
Height:20 Height:20
Font:Regular Font:Regular
@@ -143,41 +143,55 @@ Container@SETTINGS_PANEL:
Y:132 Y:132
Height:25 Height:25
Text: FPS Text: FPS
Checkbox@SHOW_SHELLMAP: Checkbox@TEAM_HEALTH_COLORS_CHECKBOX:
X:310 X:310
Y:135 Y:135
Width:200 Width:200
Height:20 Height:20
Font:Regular Font:Regular
Text:Team Health Colors
Checkbox@SHOW_SHELLMAP:
X:15
Y:170
Width:200
Height:20
Font:Regular
Text:Show Shellmap Text:Show Shellmap
Checkbox@ALWAYS_SHOW_STATUS_BARS_CHECKBOX:
X:310
Y:170
Width:200
Height:20
Font:Regular
Text:Always Show Status Bars
Label@VIDEO_TITLE: Label@VIDEO_TITLE:
Y:175 Y:225
Width:PARENT_RIGHT Width:PARENT_RIGHT
Font:Bold Font:Bold
Text:Localization Text:Localization
Align:Center Align:Center
Label@LANGUAGE_LABEL: Label@LANGUAGE_LABEL:
X:230 - WIDTH - 5 X:230 - WIDTH - 5
Y:194 Y:244
Width:75 Width:75
Height:25 Height:25
Align:Right Align:Right
Text:Language: Text:Language:
DropDownButton@LANGUAGE_DROPDOWNBUTTON: DropDownButton@LANGUAGE_DROPDOWNBUTTON:
X:230 X:230
Y:195 Y:245
Width:200 Width:200
Height:25 Height:25
Font:Regular Font:Regular
Label@VIDEO_DESC_A: Label@VIDEO_DESC_A:
Y:215 Y:265
Width:PARENT_RIGHT Width:PARENT_RIGHT
Height:25 Height:25
Font:Tiny Font:Tiny
Align:Center Align:Center
Text:Language changes will be applied after the game is restarted Text:Language changes will be applied after the game is restarted
Label@VIDEO_DESC_B: Label@VIDEO_DESC_B:
Y:230 Y:280
Width:PARENT_RIGHT Width:PARENT_RIGHT
Height:25 Height:25
Font:Tiny Font:Tiny
@@ -248,18 +262,18 @@ Container@SETTINGS_PANEL:
Ticks:5 Ticks:5
Label@AUDIO_DEVICE_LABEL: Label@AUDIO_DEVICE_LABEL:
X:190 - WIDTH - 5 X:190 - WIDTH - 5
Y:194 Y:244
Width:75 Width:75
Height:25 Height:25
Align:Right Align:Right
Text:Audio Device: Text:Audio Device:
DropDownButton@AUDIO_DEVICE: DropDownButton@AUDIO_DEVICE:
X:190 X:190
Y:195 Y:245
Width:300 Width:300
Height:25 Height:25
Label@AUDIO_DEVICE_DESC: Label@AUDIO_DEVICE_DESC:
Y:215 Y:265
Width:PARENT_RIGHT Width:PARENT_RIGHT
Height:25 Height:25
Font:Tiny Font:Tiny
@@ -330,7 +344,7 @@ Container@SETTINGS_PANEL:
Y:135 Y:135
Width:560 Width:560
ItemSpacing:4 ItemSpacing:4
Height:110 Height:160
Children: Children:
ScrollItem@HEADER: ScrollItem@HEADER:
Width:528 Width:528

View File

@@ -3,7 +3,7 @@ Background@SETTINGS_PANEL:
X:(WINDOW_RIGHT - WIDTH)/2 X:(WINDOW_RIGHT - WIDTH)/2
Y:(WINDOW_BOTTOM- HEIGHT)/2 Y:(WINDOW_BOTTOM- HEIGHT)/2
Width:600 Width:600
Height:351 Height:400
Children: Children:
Label@SETTINGS_LABEL_TITLE: Label@SETTINGS_LABEL_TITLE:
Y:20 Y:20
@@ -120,7 +120,7 @@ Background@SETTINGS_PANEL:
Text:Enable Frame Limiter Text:Enable Frame Limiter
Checkbox@PIXELDOUBLE_CHECKBOX: Checkbox@PIXELDOUBLE_CHECKBOX:
X:310 X:310
Y:105 Y:100
Width:200 Width:200
Height:20 Height:20
Font:Regular Font:Regular
@@ -143,40 +143,54 @@ Background@SETTINGS_PANEL:
Y:132 Y:132
Height:25 Height:25
Text: FPS Text: FPS
Checkbox@SHOW_SHELLMAP: Checkbox@TEAM_HEALTH_COLORS_CHECKBOX:
X:310 X:310
Y:135 Y:135
Width:200 Width:200
Height:20 Height:20
Font:Regular Font:Regular
Text:Team Health Colors
Checkbox@SHOW_SHELLMAP:
X:15
Y:170
Width:200
Height:20
Font:Regular
Text:Show Shellmap Text:Show Shellmap
Checkbox@ALWAYS_SHOW_STATUS_BARS_CHECKBOX:
X:310
Y:170
Width:200
Height:20
Font:Regular
Text:Always Show Status Bars
Label@VIDEO_TITLE: Label@VIDEO_TITLE:
Y:175 Y:225
Width:PARENT_RIGHT Width:PARENT_RIGHT
Font:Bold Font:Bold
Text:Localization Text:Localization
Align:Center Align:Center
Label@LANGUAGE_LABEL: Label@LANGUAGE_LABEL:
X:230 - WIDTH - 5 X:230 - WIDTH - 5
Y:194 Y:244
Width:75 Width:75
Height:25 Height:25
Align:Right Align:Right
Text:Language: Text:Language:
DropDownButton@LANGUAGE_DROPDOWNBUTTON: DropDownButton@LANGUAGE_DROPDOWNBUTTON:
X:230 X:230
Y:195 Y:245
Width:200 Width:200
Height:25 Height:25
Label@VIDEO_DESC_A: Label@VIDEO_DESC_A:
Y:215 Y:265
Width:PARENT_RIGHT Width:PARENT_RIGHT
Height:25 Height:25
Font:Tiny Font:Tiny
Align:Center Align:Center
Text:Language changes will be applied after the game is restarted Text:Language changes will be applied after the game is restarted
Label@VIDEO_DESC_B: Label@VIDEO_DESC_B:
Y:230 Y:280
Width:PARENT_RIGHT Width:PARENT_RIGHT
Height:25 Height:25
Font:Tiny Font:Tiny
@@ -243,18 +257,18 @@ Background@SETTINGS_PANEL:
Ticks:5 Ticks:5
Label@AUDIO_DEVICE_LABEL: Label@AUDIO_DEVICE_LABEL:
X:190 - WIDTH - 5 X:190 - WIDTH - 5
Y:194 Y:244
Width:75 Width:75
Height:25 Height:25
Align:Right Align:Right
Text:Audio Device: Text:Audio Device:
DropDownButton@AUDIO_DEVICE: DropDownButton@AUDIO_DEVICE:
X:190 X:190
Y:195 Y:245
Width:300 Width:300
Height:25 Height:25
Label@AUDIO_DEVICE_DESC: Label@AUDIO_DEVICE_DESC:
Y:215 Y:265
Width:PARENT_RIGHT Width:PARENT_RIGHT
Height:25 Height:25
Font:Tiny Font:Tiny
@@ -321,7 +335,7 @@ Background@SETTINGS_PANEL:
Y:135 Y:135
Width:560 Width:560
ItemSpacing:4 ItemSpacing:4
Height:110 Height:160
Children: Children:
ScrollItem@HEADER: ScrollItem@HEADER:
BaseName:scrollheader BaseName:scrollheader