From 915bf2cff04921321fa685b11660636fe7e50d77 Mon Sep 17 00:00:00 2001 From: reaperrr Date: Tue, 19 Nov 2013 01:37:01 +0100 Subject: [PATCH 1/9] Makes TimerWidget LabelWidget-based for better customizability. Sets defaults for LabelWidget in metrics.yaml. --- OpenRA.Game/Widgets/LabelWidget.cs | 14 +++++++------- OpenRA.Game/Widgets/TimerWidget.cs | 16 ++++++++++++---- mods/cnc/chrome/ingame.yaml | 2 ++ mods/cnc/metrics.yaml | 4 ++++ mods/d2k/chrome/ingame.yaml | 2 ++ mods/d2k/metrics.yaml | 4 ++++ mods/ra/chrome/ingame.yaml | 2 ++ mods/ra/metrics.yaml | 4 ++++ mods/ts/metrics.yaml | 4 ++++ 9 files changed, 41 insertions(+), 11 deletions(-) diff --git a/OpenRA.Game/Widgets/LabelWidget.cs b/OpenRA.Game/Widgets/LabelWidget.cs index d4546a9890..5f454f14fe 100644 --- a/OpenRA.Game/Widgets/LabelWidget.cs +++ b/OpenRA.Game/Widgets/LabelWidget.cs @@ -1,6 +1,6 @@ #region Copyright & License Information /* - * Copyright 2007-2011 The OpenRA Developers (see AUTHORS) + * Copyright 2007-2013 The OpenRA Developers (see AUTHORS) * This file is part of OpenRA, which is free software. It is made * available to you under the terms of the GNU General Public License * as published by the Free Software Foundation. For more information, @@ -23,10 +23,10 @@ namespace OpenRA.Widgets [Translate] public string Text = null; public TextAlign Align = TextAlign.Left; public TextVAlign VAlign = TextVAlign.Middle; - public string Font = "Regular"; - public Color Color = Color.White; - public bool Contrast = false; - public Color ContrastColor = Color.Black; + public string Font = ChromeMetrics.Get("TextFont"); + public Color TextColor = ChromeMetrics.Get("TextColor"); + public bool Contrast = ChromeMetrics.Get("TextContrast"); + public Color ContrastColor = ChromeMetrics.Get("TextContrastColor"); public bool WordWrap = false; public Func GetText; public Func GetColor; @@ -35,7 +35,7 @@ namespace OpenRA.Widgets public LabelWidget() { GetText = () => Text; - GetColor = () => Color; + GetColor = () => TextColor; GetContrastColor = () => ContrastColor; } @@ -45,7 +45,7 @@ namespace OpenRA.Widgets Text = other.Text; Align = other.Align; Font = other.Font; - Color = other.Color; + TextColor = other.TextColor; Contrast = other.Contrast; ContrastColor = other.ContrastColor; WordWrap = other.WordWrap; diff --git a/OpenRA.Game/Widgets/TimerWidget.cs b/OpenRA.Game/Widgets/TimerWidget.cs index e66bbc2611..41dade46c6 100644 --- a/OpenRA.Game/Widgets/TimerWidget.cs +++ b/OpenRA.Game/Widgets/TimerWidget.cs @@ -1,6 +1,6 @@ #region Copyright & License Information /* - * Copyright 2007-2011 The OpenRA Developers (see AUTHORS) + * Copyright 2007-2013 The OpenRA Developers (see AUTHORS) * This file is part of OpenRA, which is free software. It is made * available to you under the terms of the GNU General Public License * as published by the Free Software Foundation. For more information, @@ -8,20 +8,28 @@ */ #endregion +using System; using System.Drawing; +using OpenRA.FileFormats; +using OpenRA.Graphics; namespace OpenRA.Widgets { - public class TimerWidget : Widget + public class TimerWidget : LabelWidget { public override void Draw() { - var font = Game.Renderer.Fonts["Title"]; + SpriteFont font = Game.Renderer.Fonts[Font]; var rb = RenderBounds; + var color = GetColor(); + var contrast = GetContrastColor(); var s = WidgetUtils.FormatTime(Game.LocalTick) + (Game.orderManager.world.Paused?" (paused)":""); var pos = new float2(rb.Left - font.Measure(s).X / 2, rb.Top); - font.DrawTextWithContrast(s, pos, Color.White, Color.Black, 1); + if (Contrast) + font.DrawTextWithContrast(s, pos, color, contrast, 1); + else + font.DrawText(s, pos, color); } } } diff --git a/mods/cnc/chrome/ingame.yaml b/mods/cnc/chrome/ingame.yaml index 3533a7f621..fa94cd273f 100644 --- a/mods/cnc/chrome/ingame.yaml +++ b/mods/cnc/chrome/ingame.yaml @@ -4,6 +4,8 @@ Container@INGAME_ROOT: Timer@GAME_TIMER: X: WINDOW_RIGHT/2 Y: 0 + Font: Title + Contrast: true StrategicProgress@STRATEGIC_PROGRESS: X: WINDOW_RIGHT/2 Y: 40 diff --git a/mods/cnc/metrics.yaml b/mods/cnc/metrics.yaml index 80121ae959..9cff61744d 100644 --- a/mods/cnc/metrics.yaml +++ b/mods/cnc/metrics.yaml @@ -4,4 +4,8 @@ Metrics: ButtonDepth: 0 ButtonFont: Bold CheckboxPressedState: true + TextFont: Regular + TextColor: 255,255,255 + TextContrast: false + TextContrastColor: 0,0,0 ColorPickerRemapIndices: 176, 178, 180, 182, 184, 186, 189, 191, 177, 179, 181, 183, 185, 187, 188, 190 \ No newline at end of file diff --git a/mods/d2k/chrome/ingame.yaml b/mods/d2k/chrome/ingame.yaml index 3d1dd5e046..92876a52a9 100644 --- a/mods/d2k/chrome/ingame.yaml +++ b/mods/d2k/chrome/ingame.yaml @@ -20,6 +20,8 @@ Container@INGAME_ROOT: Timer@GAME_TIMER: X: WINDOW_RIGHT/2 Y: 0 + Font: Title + Contrast: true StrategicProgress@STRATEGIC_PROGRESS: X: WINDOW_RIGHT/2 Y: 40 diff --git a/mods/d2k/metrics.yaml b/mods/d2k/metrics.yaml index c88a8055d8..22430341c3 100644 --- a/mods/d2k/metrics.yaml +++ b/mods/d2k/metrics.yaml @@ -4,4 +4,8 @@ Metrics: ButtonDepth: 1 ButtonFont: Regular CheckboxPressedState: false + TextFont: Regular + TextColor: 255,255,255 + TextContrast: false + TextContrastColor: 0,0,0 ColorPickerRemapIndices: 255, 254, 253, 252, 251, 250, 249, 248, 247, 246, 245, 244, 243, 242, 241, 240 diff --git a/mods/ra/chrome/ingame.yaml b/mods/ra/chrome/ingame.yaml index 21280cc850..233cb833ea 100644 --- a/mods/ra/chrome/ingame.yaml +++ b/mods/ra/chrome/ingame.yaml @@ -20,6 +20,8 @@ Container@INGAME_ROOT: Timer@GAME_TIMER: X: WINDOW_RIGHT/2 Y: 0-10 + Font: Title + Contrast: true StrategicProgress@STRATEGIC_PROGRESS: X: WINDOW_RIGHT/2 Y: 40 diff --git a/mods/ra/metrics.yaml b/mods/ra/metrics.yaml index e5ae5dd388..f9f698467d 100644 --- a/mods/ra/metrics.yaml +++ b/mods/ra/metrics.yaml @@ -4,4 +4,8 @@ Metrics: ButtonDepth: 1 ButtonFont: Regular CheckboxPressedState: false + TextFont: Regular + TextColor: 255,255,255 + TextContrast: false + TextContrastColor: 0,0,0 ColorPickerRemapIndices: 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95 diff --git a/mods/ts/metrics.yaml b/mods/ts/metrics.yaml index c9c34371f2..d016b5aab9 100644 --- a/mods/ts/metrics.yaml +++ b/mods/ts/metrics.yaml @@ -4,4 +4,8 @@ Metrics: ButtonDepth: 1 ButtonFont: Regular CheckboxPressedState: false + TextFont: Regular + TextColor: 255,255,255 + TextContrast: false + TextContrastColor: 0,0,0 ColorPickerRemapIndices: 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31 From 394a2b5166686ee38aa48b34f3c20e1c516c3c90 Mon Sep 17 00:00:00 2001 From: reaperrr Date: Tue, 19 Nov 2013 01:39:57 +0100 Subject: [PATCH 2/9] Makes ButtonWidget and Widgets based on it more customizable, sets defaults in metrics.yaml. --- OpenRA.Game/Widgets/ButtonWidget.cs | 30 ++++++++++++++++++--- OpenRA.Game/Widgets/CheckboxWidget.cs | 15 ++++++++--- OpenRA.Game/Widgets/DropDownButtonWidget.cs | 4 ++- mods/cnc/metrics.yaml | 4 +++ mods/d2k/metrics.yaml | 4 +++ mods/ra/metrics.yaml | 4 +++ mods/ts/metrics.yaml | 4 +++ 7 files changed, 58 insertions(+), 7 deletions(-) diff --git a/OpenRA.Game/Widgets/ButtonWidget.cs b/OpenRA.Game/Widgets/ButtonWidget.cs index 4b3b6c7389..6f87839c2d 100644 --- a/OpenRA.Game/Widgets/ButtonWidget.cs +++ b/OpenRA.Game/Widgets/ButtonWidget.cs @@ -1,6 +1,6 @@ #region Copyright & License Information /* - * Copyright 2007-2011 The OpenRA Developers (see AUTHORS) + * Copyright 2007-2013 The OpenRA Developers (see AUTHORS) * This file is part of OpenRA, which is free software. It is made * available to you under the terms of the GNU General Public License * as published by the Free Software Foundation. For more information, @@ -27,9 +27,16 @@ namespace OpenRA.Widgets public bool Depressed = false; public int VisualHeight = ChromeMetrics.Get("ButtonDepth"); public string Font = ChromeMetrics.Get("ButtonFont"); + public Color TextColor = ChromeMetrics.Get("ButtonTextColor"); + public Color TextColorDisabled = ChromeMetrics.Get("ButtonTextColorDisabled"); + public bool Contrast = ChromeMetrics.Get("ButtonTextContrast"); + public Color ContrastColor = ChromeMetrics.Get("ButtonTextContrastColor"); public bool Disabled = false; public bool Highlighted = false; public Func GetText; + public Func GetColor; + public Func GetColorDisabled; + public Func GetContrastColor; public Func IsDisabled; public Func IsHighlighted; public Action OnMouseDown = _ => {}; @@ -48,6 +55,9 @@ namespace OpenRA.Widgets public ButtonWidget() { GetText = () => { return Text; }; + GetColor = () => TextColor; + GetColorDisabled = () => TextColorDisabled; + GetContrastColor = () => ContrastColor; OnMouseUp = _ => OnClick(); OnKeyPress = _ => OnClick(); IsDisabled = () => Disabled; @@ -61,9 +71,16 @@ namespace OpenRA.Widgets { Text = other.Text; Font = other.Font; + TextColor = other.TextColor; + TextColorDisabled = other.TextColorDisabled; + Contrast = other.Contrast; + ContrastColor = other.ContrastColor; Depressed = other.Depressed; VisualHeight = other.VisualHeight; GetText = other.GetText; + GetColor = other.GetColor; + GetColorDisabled = other.GetColorDisabled; + GetContrastColor = other.GetContrastColor; OnMouseDown = other.OnMouseDown; Disabled = other.Disabled; IsDisabled = other.IsDisabled; @@ -172,12 +189,19 @@ namespace OpenRA.Widgets var font = Game.Renderer.Fonts[Font]; var text = GetText(); + var color = GetColor(); + var colordisabled = GetColorDisabled(); + var contrast = GetContrastColor(); var s = font.Measure(text); var stateOffset = (Depressed) ? new int2(VisualHeight, VisualHeight) : new int2(0, 0); DrawBackground(rb, disabled, Depressed, Ui.MouseOverWidget == this, highlighted); - font.DrawText(text, new int2(rb.X + (UsableWidth - s.X)/ 2, rb.Y + (Bounds.Height - s.Y) / 2) + stateOffset, - disabled ? Color.Gray : Color.White); + if (Contrast) + font.DrawTextWithContrast(text, new int2(rb.X + (UsableWidth - s.X) / 2, rb.Y + (Bounds.Height - s.Y) / 2) + stateOffset, + disabled ? colordisabled : color, contrast, 2); + else + font.DrawText(text, new int2(rb.X + (UsableWidth - s.X)/ 2, rb.Y + (Bounds.Height - s.Y) / 2) + stateOffset, + disabled ? colordisabled : color); } public override Widget Clone() { return new ButtonWidget(this); } diff --git a/OpenRA.Game/Widgets/CheckboxWidget.cs b/OpenRA.Game/Widgets/CheckboxWidget.cs index f6bfd941b9..523dc05f97 100644 --- a/OpenRA.Game/Widgets/CheckboxWidget.cs +++ b/OpenRA.Game/Widgets/CheckboxWidget.cs @@ -43,6 +43,9 @@ namespace OpenRA.Widgets { var disabled = IsDisabled(); var font = Game.Renderer.Fonts[Font]; + var color = GetColor(); + var colordisabled = GetColorDisabled(); + var contrast = GetContrastColor(); var rect = RenderBounds; var check = new Rectangle(rect.Location, new Size(Bounds.Height, Bounds.Height)); var state = disabled ? "checkbox-disabled" : @@ -53,9 +56,15 @@ namespace OpenRA.Widgets WidgetUtils.DrawPanel(state, check); var textSize = font.Measure(Text); - font.DrawText(Text, - new float2(rect.Left + rect.Height * 1.5f, RenderOrigin.Y - BaseLine + (Bounds.Height - textSize.Y)/2), - disabled ? Color.Gray : Color.White); + + if (Contrast) + font.DrawTextWithContrast(Text, + new float2(rect.Left + rect.Height * 1.5f, RenderOrigin.Y - BaseLine + (Bounds.Height - textSize.Y)/2), + disabled ? colordisabled : color, contrast, 2); + else + font.DrawText(Text, + new float2(rect.Left + rect.Height * 1.5f, RenderOrigin.Y - BaseLine + (Bounds.Height - textSize.Y)/2), + disabled ? colordisabled : color); if (IsChecked() || (Depressed && HasPressedState && !disabled)) { diff --git a/OpenRA.Game/Widgets/DropDownButtonWidget.cs b/OpenRA.Game/Widgets/DropDownButtonWidget.cs index ca3ae8aba0..d3ccc37a6d 100644 --- a/OpenRA.Game/Widgets/DropDownButtonWidget.cs +++ b/OpenRA.Game/Widgets/DropDownButtonWidget.cs @@ -31,6 +31,8 @@ namespace OpenRA.Widgets var image = ChromeProvider.GetImage("scrollbar", IsDisabled() ? "down_pressed" : "down_arrow"); var rb = RenderBounds; + var color = GetColor(); + var colordisabled = GetColorDisabled(); WidgetUtils.DrawRGBA( image, stateOffset + new float2( rb.Right - rb.Height + 4, @@ -38,7 +40,7 @@ namespace OpenRA.Widgets WidgetUtils.FillRectWithColor(new Rectangle(stateOffset.X + rb.Right - rb.Height, stateOffset.Y + rb.Top + 3, 1, rb.Height - 6), - Color.White); + IsDisabled() ? colordisabled : color); } public override Widget Clone() { return new DropDownButtonWidget(this); } diff --git a/mods/cnc/metrics.yaml b/mods/cnc/metrics.yaml index 9cff61744d..2de15b4c20 100644 --- a/mods/cnc/metrics.yaml +++ b/mods/cnc/metrics.yaml @@ -3,6 +3,10 @@ Metrics: ButtonDepth: 0 ButtonFont: Bold + ButtonTextColor: 255,255,255 + ButtonTextColorDisabled: 128,128,128 + ButtonTextContrast: false + ButtonTextContrastColor: 0,0,0 CheckboxPressedState: true TextFont: Regular TextColor: 255,255,255 diff --git a/mods/d2k/metrics.yaml b/mods/d2k/metrics.yaml index 22430341c3..37a2ec020a 100644 --- a/mods/d2k/metrics.yaml +++ b/mods/d2k/metrics.yaml @@ -3,6 +3,10 @@ Metrics: ButtonDepth: 1 ButtonFont: Regular + ButtonTextColor: 255,255,255 + ButtonTextColorDisabled: 128,128,128 + ButtonTextContrast: false + ButtonTextContrastColor: 0,0,0 CheckboxPressedState: false TextFont: Regular TextColor: 255,255,255 diff --git a/mods/ra/metrics.yaml b/mods/ra/metrics.yaml index f9f698467d..b1318e9ccb 100644 --- a/mods/ra/metrics.yaml +++ b/mods/ra/metrics.yaml @@ -3,6 +3,10 @@ Metrics: ButtonDepth: 1 ButtonFont: Regular + ButtonTextColor: 255,255,255 + ButtonTextColorDisabled: 128,128,128 + ButtonTextContrast: true + ButtonTextContrastColor: 0,0,0 CheckboxPressedState: false TextFont: Regular TextColor: 255,255,255 diff --git a/mods/ts/metrics.yaml b/mods/ts/metrics.yaml index d016b5aab9..7de90760a5 100644 --- a/mods/ts/metrics.yaml +++ b/mods/ts/metrics.yaml @@ -3,6 +3,10 @@ Metrics: ButtonDepth: 1 ButtonFont: Regular + ButtonTextColor: 255,255,255 + ButtonTextColorDisabled: 128,128,128 + ButtonTextContrast: false + ButtonTextContrastColor: 0,0,0 CheckboxPressedState: false TextFont: Regular TextColor: 255,255,255 From e73b3705c61a1ae7ddbe6b71f6c55590692abaad Mon Sep 17 00:00:00 2001 From: reaperrr Date: Tue, 19 Nov 2013 01:41:32 +0100 Subject: [PATCH 3/9] Moves defaults for HotkeyEntryWidget to global settings in metrics.yaml. --- OpenRA.Game/Widgets/HotkeyEntryWidget.cs | 10 +++++----- mods/cnc/metrics.yaml | 3 +++ mods/d2k/metrics.yaml | 3 +++ mods/ra/metrics.yaml | 3 +++ mods/ts/metrics.yaml | 3 +++ 5 files changed, 17 insertions(+), 5 deletions(-) diff --git a/OpenRA.Game/Widgets/HotkeyEntryWidget.cs b/OpenRA.Game/Widgets/HotkeyEntryWidget.cs index 93ba40f735..5b3941a580 100644 --- a/OpenRA.Game/Widgets/HotkeyEntryWidget.cs +++ b/OpenRA.Game/Widgets/HotkeyEntryWidget.cs @@ -25,9 +25,9 @@ namespace OpenRA.Widgets public Action OnLoseFocus = () => { }; public Func IsDisabled = () => false; - public Color TextColor = Color.White; - public Color DisabledColor = Color.Gray; - public string Font = "Regular"; + public string Font = ChromeMetrics.Get("HotkeyFont"); + public Color TextColor = ChromeMetrics.Get("HotkeyColor"); + public Color TextColorDisabled = ChromeMetrics.Get("HotkeyColorDisabled"); public HotkeyEntryWidget() {} protected HotkeyEntryWidget(HotkeyEntryWidget widget) @@ -35,7 +35,7 @@ namespace OpenRA.Widgets { Font = widget.Font; TextColor = widget.TextColor; - DisabledColor = widget.DisabledColor; + TextColorDisabled = widget.TextColorDisabled; VisualHeight = widget.VisualHeight; } @@ -126,7 +126,7 @@ namespace OpenRA.Widgets Bounds.Width - LeftMargin - RightMargin, Bounds.Bottom)); } - var color = disabled ? DisabledColor : TextColor; + var color = disabled ? TextColorDisabled : TextColor; font.DrawText(apparentText, textPos, color); if (textSize.X > Bounds.Width - LeftMargin - RightMargin) diff --git a/mods/cnc/metrics.yaml b/mods/cnc/metrics.yaml index 2de15b4c20..faad630657 100644 --- a/mods/cnc/metrics.yaml +++ b/mods/cnc/metrics.yaml @@ -8,6 +8,9 @@ Metrics: ButtonTextContrast: false ButtonTextContrastColor: 0,0,0 CheckboxPressedState: true + HotkeyFont: Regular + HotkeyColor: 255,255,255 + HotkeyColorDisabled: 128,128,128 TextFont: Regular TextColor: 255,255,255 TextContrast: false diff --git a/mods/d2k/metrics.yaml b/mods/d2k/metrics.yaml index 37a2ec020a..1f5f933e0a 100644 --- a/mods/d2k/metrics.yaml +++ b/mods/d2k/metrics.yaml @@ -8,6 +8,9 @@ Metrics: ButtonTextContrast: false ButtonTextContrastColor: 0,0,0 CheckboxPressedState: false + HotkeyFont: Regular + HotkeyColor: 255,255,255 + HotkeyColorDisabled: 128,128,128 TextFont: Regular TextColor: 255,255,255 TextContrast: false diff --git a/mods/ra/metrics.yaml b/mods/ra/metrics.yaml index b1318e9ccb..3624347ef1 100644 --- a/mods/ra/metrics.yaml +++ b/mods/ra/metrics.yaml @@ -8,6 +8,9 @@ Metrics: ButtonTextContrast: true ButtonTextContrastColor: 0,0,0 CheckboxPressedState: false + HotkeyFont: Regular + HotkeyColor: 255,255,255 + HotkeyColorDisabled: 128,128,128 TextFont: Regular TextColor: 255,255,255 TextContrast: false diff --git a/mods/ts/metrics.yaml b/mods/ts/metrics.yaml index 7de90760a5..40cdc94b0c 100644 --- a/mods/ts/metrics.yaml +++ b/mods/ts/metrics.yaml @@ -8,6 +8,9 @@ Metrics: ButtonTextContrast: false ButtonTextContrastColor: 0,0,0 CheckboxPressedState: false + HotkeyFont: Regular + HotkeyColor: 255,255,255 + HotkeyColorDisabled: 128,128,128 TextFont: Regular TextColor: 255,255,255 TextContrast: false From f9c2e90c6bc66fdb389e006f604316e286be86cf Mon Sep 17 00:00:00 2001 From: reaperrr Date: Tue, 19 Nov 2013 01:42:16 +0100 Subject: [PATCH 4/9] Moves TextFieldWidget defaults to metrics.yaml. --- OpenRA.Game/Widgets/TextFieldWidget.cs | 14 +++++++------- mods/cnc/metrics.yaml | 3 +++ mods/d2k/metrics.yaml | 3 +++ mods/ra/metrics.yaml | 3 +++ mods/ts/metrics.yaml | 3 +++ 5 files changed, 19 insertions(+), 7 deletions(-) diff --git a/OpenRA.Game/Widgets/TextFieldWidget.cs b/OpenRA.Game/Widgets/TextFieldWidget.cs index de1125b588..bf9a3c50d5 100644 --- a/OpenRA.Game/Widgets/TextFieldWidget.cs +++ b/OpenRA.Game/Widgets/TextFieldWidget.cs @@ -1,6 +1,6 @@ #region Copyright & License Information /* - * Copyright 2007-2011 The OpenRA Developers (see AUTHORS) + * Copyright 2007-2013 The OpenRA Developers (see AUTHORS) * This file is part of OpenRA, which is free software. It is made * available to you under the terms of the GNU General Public License * as published by the Free Software Foundation. For more information, @@ -34,9 +34,9 @@ namespace OpenRA.Widgets public int CursorPosition { get; set; } public Func IsDisabled = () => false; - public Color TextColor = Color.White; - public Color DisabledColor = Color.Gray; - public string Font = "Regular"; + public string Font = ChromeMetrics.Get("TextfieldFont"); + public Color TextColor = ChromeMetrics.Get("TextfieldColor"); + public Color TextColorDisabled = ChromeMetrics.Get("TextfieldColorDisabled"); public TextFieldWidget() {} protected TextFieldWidget(TextFieldWidget widget) @@ -46,7 +46,7 @@ namespace OpenRA.Widgets MaxLength = widget.MaxLength; Font = widget.Font; TextColor = widget.TextColor; - DisabledColor = widget.DisabledColor; + TextColorDisabled = widget.TextColorDisabled; VisualHeight = widget.VisualHeight; } @@ -215,11 +215,11 @@ namespace OpenRA.Widgets Bounds.Width - LeftMargin - RightMargin, Bounds.Bottom)); } - var color = disabled ? DisabledColor : TextColor; + var color = disabled ? TextColorDisabled : TextColor; font.DrawText(apparentText, textPos, color); if (showCursor && HasKeyboardFocus) - font.DrawText("|", new float2(textPos.X + cursorPosition.X - 2, textPos.Y), Color.White); + font.DrawText("|", new float2(textPos.X + cursorPosition.X - 2, textPos.Y), TextColor); if (textSize.X > Bounds.Width - LeftMargin - RightMargin) Game.Renderer.DisableScissor(); diff --git a/mods/cnc/metrics.yaml b/mods/cnc/metrics.yaml index faad630657..dcbaf3bfa1 100644 --- a/mods/cnc/metrics.yaml +++ b/mods/cnc/metrics.yaml @@ -11,6 +11,9 @@ Metrics: HotkeyFont: Regular HotkeyColor: 255,255,255 HotkeyColorDisabled: 128,128,128 + TextfieldFont: Regular + TextfieldColor: 255,255,255 + TextfieldColorDisabled: 128,128,128 TextFont: Regular TextColor: 255,255,255 TextContrast: false diff --git a/mods/d2k/metrics.yaml b/mods/d2k/metrics.yaml index 1f5f933e0a..1f3a480376 100644 --- a/mods/d2k/metrics.yaml +++ b/mods/d2k/metrics.yaml @@ -11,6 +11,9 @@ Metrics: HotkeyFont: Regular HotkeyColor: 255,255,255 HotkeyColorDisabled: 128,128,128 + TextfieldFont: Regular + TextfieldColor: 255,255,255 + TextfieldColorDisabled: 128,128,128 TextFont: Regular TextColor: 255,255,255 TextContrast: false diff --git a/mods/ra/metrics.yaml b/mods/ra/metrics.yaml index 3624347ef1..7a37014ee2 100644 --- a/mods/ra/metrics.yaml +++ b/mods/ra/metrics.yaml @@ -11,6 +11,9 @@ Metrics: HotkeyFont: Regular HotkeyColor: 255,255,255 HotkeyColorDisabled: 128,128,128 + TextfieldFont: Regular + TextfieldColor: 255,255,255 + TextfieldColorDisabled: 128,128,128 TextFont: Regular TextColor: 255,255,255 TextContrast: false diff --git a/mods/ts/metrics.yaml b/mods/ts/metrics.yaml index 40cdc94b0c..f0e66e52a0 100644 --- a/mods/ts/metrics.yaml +++ b/mods/ts/metrics.yaml @@ -11,6 +11,9 @@ Metrics: HotkeyFont: Regular HotkeyColor: 255,255,255 HotkeyColorDisabled: 128,128,128 + TextfieldFont: Regular + TextfieldColor: 255,255,255 + TextfieldColorDisabled: 128,128,128 TextFont: Regular TextColor: 255,255,255 TextContrast: false From 701c5b6aacd05579eec02f9cf5067a40a70cf960 Mon Sep 17 00:00:00 2001 From: reaperrr Date: Tue, 19 Nov 2013 15:53:13 +0100 Subject: [PATCH 5/9] Disables ButtonWidget contrast default (accidental left-over from testing). --- mods/ra/metrics.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mods/ra/metrics.yaml b/mods/ra/metrics.yaml index 7a37014ee2..8917a2d756 100644 --- a/mods/ra/metrics.yaml +++ b/mods/ra/metrics.yaml @@ -5,7 +5,7 @@ Metrics: ButtonFont: Regular ButtonTextColor: 255,255,255 ButtonTextColorDisabled: 128,128,128 - ButtonTextContrast: true + ButtonTextContrast: false ButtonTextContrastColor: 0,0,0 CheckboxPressedState: false HotkeyFont: Regular From 4c92280b7e6b705bf8742723306a39a903747437 Mon Sep 17 00:00:00 2001 From: reaperrr Date: Fri, 22 Nov 2013 13:34:46 +0100 Subject: [PATCH 6/9] Moved duplicated int2 in ButtonWidget before if as suggested. --- OpenRA.Game/Widgets/ButtonWidget.cs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/OpenRA.Game/Widgets/ButtonWidget.cs b/OpenRA.Game/Widgets/ButtonWidget.cs index 6f87839c2d..9b3016be55 100644 --- a/OpenRA.Game/Widgets/ButtonWidget.cs +++ b/OpenRA.Game/Widgets/ButtonWidget.cs @@ -194,13 +194,14 @@ namespace OpenRA.Widgets var contrast = GetContrastColor(); var s = font.Measure(text); var stateOffset = (Depressed) ? new int2(VisualHeight, VisualHeight) : new int2(0, 0); + var position = new int2(rb.X + (UsableWidth - s.X) / 2, rb.Y + (Bounds.Height - s.Y) / 2); DrawBackground(rb, disabled, Depressed, Ui.MouseOverWidget == this, highlighted); if (Contrast) - font.DrawTextWithContrast(text, new int2(rb.X + (UsableWidth - s.X) / 2, rb.Y + (Bounds.Height - s.Y) / 2) + stateOffset, + font.DrawTextWithContrast(text, position + stateOffset, disabled ? colordisabled : color, contrast, 2); else - font.DrawText(text, new int2(rb.X + (UsableWidth - s.X)/ 2, rb.Y + (Bounds.Height - s.Y) / 2) + stateOffset, + font.DrawText(text, position + stateOffset, disabled ? colordisabled : color); } From 09606e8ffdc8d4cad61f0c1365e5e8d6cb0341b5 Mon Sep 17 00:00:00 2001 From: reaperrr Date: Fri, 22 Nov 2013 13:36:22 +0100 Subject: [PATCH 7/9] Moved duplicate float2 before if as suggested. --- OpenRA.Game/Widgets/CheckboxWidget.cs | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/OpenRA.Game/Widgets/CheckboxWidget.cs b/OpenRA.Game/Widgets/CheckboxWidget.cs index 523dc05f97..a8c1fd41e5 100644 --- a/OpenRA.Game/Widgets/CheckboxWidget.cs +++ b/OpenRA.Game/Widgets/CheckboxWidget.cs @@ -47,6 +47,7 @@ namespace OpenRA.Widgets var colordisabled = GetColorDisabled(); var contrast = GetContrastColor(); var rect = RenderBounds; + var textSize = font.Measure(Text); var check = new Rectangle(rect.Location, new Size(Bounds.Height, Bounds.Height)); var state = disabled ? "checkbox-disabled" : Depressed && HasPressedState ? "checkbox-pressed" : @@ -54,16 +55,13 @@ namespace OpenRA.Widgets "checkbox"; WidgetUtils.DrawPanel(state, check); - - var textSize = font.Measure(Text); + var position = new float2(rect.Left + rect.Height * 1.5f, RenderOrigin.Y - BaseLine + (Bounds.Height - textSize.Y)/2); if (Contrast) - font.DrawTextWithContrast(Text, - new float2(rect.Left + rect.Height * 1.5f, RenderOrigin.Y - BaseLine + (Bounds.Height - textSize.Y)/2), + font.DrawTextWithContrast(Text, position, disabled ? colordisabled : color, contrast, 2); else - font.DrawText(Text, - new float2(rect.Left + rect.Height * 1.5f, RenderOrigin.Y - BaseLine + (Bounds.Height - textSize.Y)/2), + font.DrawText(Text, position, disabled ? colordisabled : color); if (IsChecked() || (Depressed && HasPressedState && !disabled)) From f743cedb10c06e080cde7d87a06034189ec0f406 Mon Sep 17 00:00:00 2001 From: reaperrr Date: Fri, 22 Nov 2013 13:36:55 +0100 Subject: [PATCH 8/9] Adds improved UI customizability to changelog. --- CHANGELOG | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG b/CHANGELOG index cf0f4d2d48..fbbbf7d8d2 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -71,6 +71,7 @@ NEW: Added language translation support. Added game ID and version information to exception and sync reports. Map folders are now explicitly specified in mod.yaml. + Most UI widgets are now customizable in terms of font type, color, contrast and had their global defaults moved from code to metrics.yaml. Replaced the OS X binary launcher with a script to use a new SDL2 renderer. Improved cash tick sound playback. Added modifier support to hotkeys. @@ -85,6 +86,7 @@ NEW: Renamed Game.Mods launch argument to Game.Mod. Mod / Custom map compatibility: Mods can now include traits from TD and D2K in RA. + Mods can now customize UI text settings like font type/color/contrast for most widgets and set global defaults in metrics.yaml. New sections MapFolders and Translations added to mod.yaml. Renamed CarpetBomb trait to AttackBomber, and additional functionality added. An Armament trait is now required to specify the weapons. Renamed Capture trait to ExternalCapture. From 1f789b42965e0fe7a8b1547c2a60f89a2ae533e0 Mon Sep 17 00:00:00 2001 From: reaperrr Date: Fri, 22 Nov 2013 13:49:18 +0100 Subject: [PATCH 9/9] var instead of SpriteFont on TimerWidget. --- OpenRA.Game/Widgets/TimerWidget.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/OpenRA.Game/Widgets/TimerWidget.cs b/OpenRA.Game/Widgets/TimerWidget.cs index 41dade46c6..9a63adf860 100644 --- a/OpenRA.Game/Widgets/TimerWidget.cs +++ b/OpenRA.Game/Widgets/TimerWidget.cs @@ -19,7 +19,7 @@ namespace OpenRA.Widgets { public override void Draw() { - SpriteFont font = Game.Renderer.Fonts[Font]; + var font = Game.Renderer.Fonts[Font]; var rb = RenderBounds; var color = GetColor(); var contrast = GetContrastColor();