Merge pull request #9650 from r34ch/health-bars-on-damage

Display status bars dropdown
This commit is contained in:
Matthias Mailänder
2015-12-05 19:45:20 +01:00
8 changed files with 95 additions and 28 deletions

View File

@@ -18,17 +18,26 @@ namespace OpenRA.Graphics
{
readonly WPos pos;
readonly Actor actor;
readonly bool displayHealth;
readonly bool displayExtra;
public SelectionBarsRenderable(Actor actor)
: this(actor.CenterPosition, actor) { }
public SelectionBarsRenderable(Actor actor, bool displayHealth, bool displayExtra)
: this(actor.CenterPosition, actor)
{
this.displayHealth = displayHealth;
this.displayExtra = displayExtra;
}
public SelectionBarsRenderable(WPos pos, Actor actor)
: this()
{
this.pos = pos;
this.actor = actor;
}
public WPos Pos { get { return pos; } }
public bool DisplayHealth { get { return displayHealth; } }
public bool DisplayExtra { get { return displayExtra; } }
public PaletteReference Palette { get { return null; } }
public int ZOffset { get { return 0; } }
@@ -164,7 +173,10 @@ namespace OpenRA.Graphics
var start = new float2(bounds.Left + 1, bounds.Top);
var end = new float2(bounds.Right - 1, bounds.Top);
if (DisplayHealth)
DrawHealthBar(wr, health, start, end);
if (DisplayExtra)
DrawExtraBars(wr, start, end);
}

View File

@@ -183,13 +183,26 @@ namespace OpenRA.Graphics
foreach (var r in g)
r.RenderDebugGeometry(this);
if (World.Type == WorldType.Regular && Game.Settings.Game.AlwaysShowStatusBars)
if (World.Type == WorldType.Regular)
{
foreach (var g in World.ActorsHavingTrait<Selectable>().Where(a => !a.Disposed
&& !World.FogObscures(a)
&& !World.Selection.Actors.Contains(a)))
{
if (Game.Settings.Game.StatusBars == StatusBarsType.Standard)
new SelectionBarsRenderable(g, false, false).Render(this);
DrawRollover(g);
if (Game.Settings.Game.StatusBars == StatusBarsType.AlwaysShow)
new SelectionBarsRenderable(g, true, true).Render(this);
if (Game.Settings.Game.StatusBars == StatusBarsType.DamageShow)
{
if (g.GetDamageState() != DamageState.Undamaged)
new SelectionBarsRenderable(g, true, true).Render(this);
else
new SelectionBarsRenderable(g, false, true).Render(this);
}
}
}
Game.Renderer.Flush();
@@ -198,7 +211,7 @@ namespace OpenRA.Graphics
public void DrawRollover(Actor unit)
{
if (unit.Info.HasTraitInfo<SelectableInfo>())
new SelectionBarsRenderable(unit).Render(this);
new SelectionBarsRenderable(unit, true, true).Render(this);
}
public void DrawRangeCircle(WPos pos, WDist range, Color c)

View File

@@ -20,6 +20,7 @@ using OpenRA.Traits;
namespace OpenRA
{
public enum MouseScrollType { Disabled, Standard, Inverted, Joystick }
public enum StatusBarsType { Standard, DamageShow, AlwaysShow }
public class ServerSettings
{
@@ -153,7 +154,7 @@ namespace OpenRA
public int JoystickScrollDeadzone = 8;
public bool UseClassicMouseStyle = false;
public bool AlwaysShowStatusBars = false;
public StatusBarsType StatusBars = StatusBarsType.Standard;
public bool TeamHealthColors = false;
public bool DrawTargetLine = true;
@@ -197,7 +198,7 @@ namespace OpenRA
public Hotkey ObserverCombinedView = new Hotkey(Keycode.MINUS, Modifiers.None);
public Hotkey ObserverWorldView = new Hotkey(Keycode.EQUALS, Modifiers.None);
public Hotkey ToggleStatusBarsKey = new Hotkey(Keycode.COMMA, Modifiers.None);
public Hotkey CycleStatusBarsKey = new Hotkey(Keycode.COMMA, Modifiers.None);
public Hotkey TogglePixelDoubleKey = new Hotkey(Keycode.PERIOD, Modifiers.None);
public Hotkey DevReloadChromeKey = new Hotkey(Keycode.C, Modifiers.Ctrl | Modifiers.Shift);

View File

@@ -275,8 +275,8 @@ namespace OpenRA.Widgets
World.Selection.Combine(World, newSelection, true, false);
}
else if (key == Game.Settings.Keys.ToggleStatusBarsKey)
return ToggleStatusBars();
else if (key == Game.Settings.Keys.CycleStatusBarsKey)
return CycleStatusBars();
else if (key == Game.Settings.Keys.TogglePixelDoubleKey)
return TogglePixelDouble();
}
@@ -319,9 +319,15 @@ namespace OpenRA.Widgets
.SubsetWithHighestSelectionPriority();
}
bool ToggleStatusBars()
bool CycleStatusBars()
{
Game.Settings.Game.AlwaysShowStatusBars ^= true;
if (Game.Settings.Game.StatusBars == StatusBarsType.Standard)
Game.Settings.Game.StatusBars = StatusBarsType.DamageShow;
else if (Game.Settings.Game.StatusBars == StatusBarsType.DamageShow)
Game.Settings.Game.StatusBars = StatusBarsType.AlwaysShow;
else if (Game.Settings.Game.StatusBars == StatusBarsType.AlwaysShow)
Game.Settings.Game.StatusBars = StatusBarsType.Standard;
return true;
}

View File

@@ -78,7 +78,7 @@ namespace OpenRA.Mods.Common.Traits
yield return new SelectionBoxRenderable(self, Info.SelectionBoxColor);
if (Info.RenderSelectionBars)
yield return new SelectionBarsRenderable(self);
yield return new SelectionBarsRenderable(self, true, true);
if (!self.Owner.IsAlliedWith(wr.World.RenderPlayer))
yield break;

View File

@@ -153,7 +153,6 @@ namespace OpenRA.Mods.Common.Widgets.Logic
BindCheckboxPref(panel, "CURSORDOUBLE_CHECKBOX", ds, "CursorDouble");
BindCheckboxPref(panel, "FRAME_LIMIT_CHECKBOX", ds, "CapFramerate");
BindCheckboxPref(panel, "SHOW_SHELLMAP", gs, "ShowShellmap");
BindCheckboxPref(panel, "ALWAYS_SHOW_STATUS_BARS_CHECKBOX", gs, "AlwaysShowStatusBars");
BindCheckboxPref(panel, "DISPLAY_TARGET_LINES_CHECKBOX", gs, "DrawTargetLine");
BindCheckboxPref(panel, "TEAM_HEALTH_COLORS_CHECKBOX", gs, "TeamHealthColors");
@@ -166,6 +165,11 @@ namespace OpenRA.Mods.Common.Widgets.Logic
windowModeDropdown.GetText = () => ds.Mode == WindowMode.Windowed ?
"Windowed" : ds.Mode == WindowMode.Fullscreen ? "Fullscreen" : "Pseudo-Fullscreen";
var statusBarsDropDown = panel.Get<DropDownButtonWidget>("STATUS_BAR_DROPDOWN");
statusBarsDropDown.OnMouseDown = _ => ShowStatusBarsDropdown(statusBarsDropDown, gs);
statusBarsDropDown.GetText = () => gs.StatusBars.ToString() == "Standard" ?
"Standard" : gs.StatusBars.ToString() == "DamageShow" ? "Show On Damage" : "Always Show";
// Update zoom immediately
var pixelDoubleCheckbox = panel.Get<CheckboxWidget>("PIXELDOUBLE_CHECKBOX");
var pixelDoubleOnClick = pixelDoubleCheckbox.OnClick;
@@ -408,7 +412,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
{ "PreviousProductionTabKey", "Previous production tab" },
{ "CycleProductionBuildingsKey", "Cycle production facilities" },
{ "ToggleStatusBarsKey", "Toggle status bars" },
{ "CycleStatusBarsKey", "Cycle status bars display" },
{ "TogglePixelDoubleKey", "Toggle pixel doubling" },
{ "MapScrollUp", "Map scroll up" },
@@ -669,6 +673,29 @@ namespace OpenRA.Mods.Common.Widgets.Logic
return true;
}
static bool ShowStatusBarsDropdown(DropDownButtonWidget dropdown, GameSettings s)
{
var options = new Dictionary<string, StatusBarsType>()
{
{ "Standard", StatusBarsType.Standard },
{ "Show On Damage", StatusBarsType.DamageShow },
{ "Always Show", StatusBarsType.AlwaysShow },
};
Func<string, ScrollItemWidget, ScrollItemWidget> setupItem = (o, itemTemplate) =>
{
var item = ScrollItemWidget.Setup(itemTemplate,
() => s.StatusBars == options[o],
() => s.StatusBars = options[o]);
item.Get<LabelWidget>("LABEL").GetText = () => o;
return item;
};
dropdown.ShowDropDown("LABEL_DROPDOWN_TEMPLATE", 500, options.Keys, setupItem);
return true;
}
void MakeMouseFocusSettingsLive()
{
var gameSettings = Game.Settings.Game;

View File

@@ -183,16 +183,20 @@ Container@SETTINGS_PANEL:
Y: 6
Width: PARENT_RIGHT-35
Height: PARENT_BOTTOM-12
Checkbox@ALWAYS_SHOW_STATUS_BARS_CHECKBOX:
Label@STATUS_BARS:
X: 310
Y: 215
Width: 200
Height: 20
Y: 255
Text: Status Bars:
DropDownButton@STATUS_BAR_DROPDOWN:
X: 400
Y: 245
Width: 170
Height: 25
Font: Regular
Text: Always Show Status Bars
Text: Standard
Checkbox@DISPLAY_TARGET_LINES_CHECKBOX:
X: 310
Y: 245
Y: 215
Width: 200
Height: 20
Font: Regular

View File

@@ -196,16 +196,20 @@ Background@SETTINGS_PANEL:
Y: 6
Width: PARENT_RIGHT-35
Height: PARENT_BOTTOM-12
Checkbox@ALWAYS_SHOW_STATUS_BARS_CHECKBOX:
Label@STATUS_BARS:
X: 310
Y: 230
Width: 200
Height: 20
Y: 275
Text: Status Bars:
DropDownButton@STATUS_BAR_DROPDOWN:
X: 400
Y: 265
Width: 170
Height: 25
Font: Regular
Text: Always Show Status Bars
Text: Standard
Checkbox@DISPLAY_TARGET_LINES_CHECKBOX:
X: 310
Y: 265
Y: 230
Width: 200
Height: 20
Font: Regular