Merge pull request #4156 from reaperrr/widgets04

Improved Widget text customizability rev.2
This commit is contained in:
Paul Chote
2013-11-27 00:47:00 -08:00
15 changed files with 137 additions and 31 deletions

View File

@@ -78,6 +78,7 @@ NEW:
Added language translation support. Added language translation support.
Added game ID and version information to exception and sync reports. Added game ID and version information to exception and sync reports.
Map folders are now explicitly specified in mod.yaml. 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. Replaced the OS X binary launcher with a script to use a new SDL2 renderer.
Improved cash tick sound playback. Improved cash tick sound playback.
Added modifier support to hotkeys. Added modifier support to hotkeys.
@@ -94,6 +95,7 @@ NEW:
Linux packages now install to /usr/lib/openra for consistency with other Mono applications. Linux packages now install to /usr/lib/openra for consistency with other Mono applications.
Mod / Custom map compatibility: Mod / Custom map compatibility:
Mods can now include traits from TD and D2K in RA. 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. 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 CarpetBomb trait to AttackBomber, and additional functionality added. An Armament trait is now required to specify the weapons.
Renamed Capture trait to ExternalCapture. Renamed Capture trait to ExternalCapture.

View File

@@ -1,6 +1,6 @@
#region Copyright & License Information #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 * 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 * available to you under the terms of the GNU General Public License
* as published by the Free Software Foundation. For more information, * as published by the Free Software Foundation. For more information,
@@ -27,9 +27,16 @@ namespace OpenRA.Widgets
public bool Depressed = false; public bool Depressed = false;
public int VisualHeight = ChromeMetrics.Get<int>("ButtonDepth"); public int VisualHeight = ChromeMetrics.Get<int>("ButtonDepth");
public string Font = ChromeMetrics.Get<string>("ButtonFont"); public string Font = ChromeMetrics.Get<string>("ButtonFont");
public Color TextColor = ChromeMetrics.Get<Color>("ButtonTextColor");
public Color TextColorDisabled = ChromeMetrics.Get<Color>("ButtonTextColorDisabled");
public bool Contrast = ChromeMetrics.Get<bool>("ButtonTextContrast");
public Color ContrastColor = ChromeMetrics.Get<Color>("ButtonTextContrastColor");
public bool Disabled = false; public bool Disabled = false;
public bool Highlighted = false; public bool Highlighted = false;
public Func<string> GetText; public Func<string> GetText;
public Func<Color> GetColor;
public Func<Color> GetColorDisabled;
public Func<Color> GetContrastColor;
public Func<bool> IsDisabled; public Func<bool> IsDisabled;
public Func<bool> IsHighlighted; public Func<bool> IsHighlighted;
public Action<MouseInput> OnMouseDown = _ => {}; public Action<MouseInput> OnMouseDown = _ => {};
@@ -48,6 +55,9 @@ namespace OpenRA.Widgets
public ButtonWidget() public ButtonWidget()
{ {
GetText = () => { return Text; }; GetText = () => { return Text; };
GetColor = () => TextColor;
GetColorDisabled = () => TextColorDisabled;
GetContrastColor = () => ContrastColor;
OnMouseUp = _ => OnClick(); OnMouseUp = _ => OnClick();
OnKeyPress = _ => OnClick(); OnKeyPress = _ => OnClick();
IsDisabled = () => Disabled; IsDisabled = () => Disabled;
@@ -61,9 +71,16 @@ namespace OpenRA.Widgets
{ {
Text = other.Text; Text = other.Text;
Font = other.Font; Font = other.Font;
TextColor = other.TextColor;
TextColorDisabled = other.TextColorDisabled;
Contrast = other.Contrast;
ContrastColor = other.ContrastColor;
Depressed = other.Depressed; Depressed = other.Depressed;
VisualHeight = other.VisualHeight; VisualHeight = other.VisualHeight;
GetText = other.GetText; GetText = other.GetText;
GetColor = other.GetColor;
GetColorDisabled = other.GetColorDisabled;
GetContrastColor = other.GetContrastColor;
OnMouseDown = other.OnMouseDown; OnMouseDown = other.OnMouseDown;
Disabled = other.Disabled; Disabled = other.Disabled;
IsDisabled = other.IsDisabled; IsDisabled = other.IsDisabled;
@@ -172,12 +189,20 @@ namespace OpenRA.Widgets
var font = Game.Renderer.Fonts[Font]; var font = Game.Renderer.Fonts[Font];
var text = GetText(); var text = GetText();
var color = GetColor();
var colordisabled = GetColorDisabled();
var contrast = GetContrastColor();
var s = font.Measure(text); var s = font.Measure(text);
var stateOffset = (Depressed) ? new int2(VisualHeight, VisualHeight) : new int2(0, 0); 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); 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, if (Contrast)
disabled ? Color.Gray : Color.White); font.DrawTextWithContrast(text, position + stateOffset,
disabled ? colordisabled : color, contrast, 2);
else
font.DrawText(text, position + stateOffset,
disabled ? colordisabled : color);
} }
public override Widget Clone() { return new ButtonWidget(this); } public override Widget Clone() { return new ButtonWidget(this); }

View File

@@ -43,7 +43,11 @@ namespace OpenRA.Widgets
{ {
var disabled = IsDisabled(); var disabled = IsDisabled();
var font = Game.Renderer.Fonts[Font]; var font = Game.Renderer.Fonts[Font];
var color = GetColor();
var colordisabled = GetColorDisabled();
var contrast = GetContrastColor();
var rect = RenderBounds; var rect = RenderBounds;
var textSize = font.Measure(Text);
var check = new Rectangle(rect.Location, new Size(Bounds.Height, Bounds.Height)); var check = new Rectangle(rect.Location, new Size(Bounds.Height, Bounds.Height));
var state = disabled ? "checkbox-disabled" : var state = disabled ? "checkbox-disabled" :
Depressed && HasPressedState ? "checkbox-pressed" : Depressed && HasPressedState ? "checkbox-pressed" :
@@ -51,11 +55,14 @@ namespace OpenRA.Widgets
"checkbox"; "checkbox";
WidgetUtils.DrawPanel(state, check); WidgetUtils.DrawPanel(state, check);
var position = new float2(rect.Left + rect.Height * 1.5f, RenderOrigin.Y - BaseLine + (Bounds.Height - textSize.Y)/2);
var textSize = font.Measure(Text); if (Contrast)
font.DrawText(Text, font.DrawTextWithContrast(Text, position,
new float2(rect.Left + rect.Height * 1.5f, RenderOrigin.Y - BaseLine + (Bounds.Height - textSize.Y)/2), disabled ? colordisabled : color, contrast, 2);
disabled ? Color.Gray : Color.White); else
font.DrawText(Text, position,
disabled ? colordisabled : color);
if (IsChecked() || (Depressed && HasPressedState && !disabled)) if (IsChecked() || (Depressed && HasPressedState && !disabled))
{ {

View File

@@ -31,6 +31,8 @@ namespace OpenRA.Widgets
var image = ChromeProvider.GetImage("scrollbar", IsDisabled() ? "down_pressed" : "down_arrow"); var image = ChromeProvider.GetImage("scrollbar", IsDisabled() ? "down_pressed" : "down_arrow");
var rb = RenderBounds; var rb = RenderBounds;
var color = GetColor();
var colordisabled = GetColorDisabled();
WidgetUtils.DrawRGBA( image, WidgetUtils.DrawRGBA( image,
stateOffset + new float2( rb.Right - rb.Height + 4, 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, WidgetUtils.FillRectWithColor(new Rectangle(stateOffset.X + rb.Right - rb.Height,
stateOffset.Y + rb.Top + 3, 1, rb.Height - 6), stateOffset.Y + rb.Top + 3, 1, rb.Height - 6),
Color.White); IsDisabled() ? colordisabled : color);
} }
public override Widget Clone() { return new DropDownButtonWidget(this); } public override Widget Clone() { return new DropDownButtonWidget(this); }

View File

@@ -25,9 +25,9 @@ namespace OpenRA.Widgets
public Action OnLoseFocus = () => { }; public Action OnLoseFocus = () => { };
public Func<bool> IsDisabled = () => false; public Func<bool> IsDisabled = () => false;
public Color TextColor = Color.White; public string Font = ChromeMetrics.Get<string>("HotkeyFont");
public Color DisabledColor = Color.Gray; public Color TextColor = ChromeMetrics.Get<Color>("HotkeyColor");
public string Font = "Regular"; public Color TextColorDisabled = ChromeMetrics.Get<Color>("HotkeyColorDisabled");
public HotkeyEntryWidget() {} public HotkeyEntryWidget() {}
protected HotkeyEntryWidget(HotkeyEntryWidget widget) protected HotkeyEntryWidget(HotkeyEntryWidget widget)
@@ -35,7 +35,7 @@ namespace OpenRA.Widgets
{ {
Font = widget.Font; Font = widget.Font;
TextColor = widget.TextColor; TextColor = widget.TextColor;
DisabledColor = widget.DisabledColor; TextColorDisabled = widget.TextColorDisabled;
VisualHeight = widget.VisualHeight; VisualHeight = widget.VisualHeight;
} }
@@ -126,7 +126,7 @@ namespace OpenRA.Widgets
Bounds.Width - LeftMargin - RightMargin, Bounds.Bottom)); Bounds.Width - LeftMargin - RightMargin, Bounds.Bottom));
} }
var color = disabled ? DisabledColor : TextColor; var color = disabled ? TextColorDisabled : TextColor;
font.DrawText(apparentText, textPos, color); font.DrawText(apparentText, textPos, color);
if (textSize.X > Bounds.Width - LeftMargin - RightMargin) if (textSize.X > Bounds.Width - LeftMargin - RightMargin)

View File

@@ -1,6 +1,6 @@
#region Copyright & License Information #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 * 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 * available to you under the terms of the GNU General Public License
* as published by the Free Software Foundation. For more information, * as published by the Free Software Foundation. For more information,
@@ -23,10 +23,10 @@ namespace OpenRA.Widgets
[Translate] public string Text = null; [Translate] public string Text = null;
public TextAlign Align = TextAlign.Left; public TextAlign Align = TextAlign.Left;
public TextVAlign VAlign = TextVAlign.Middle; public TextVAlign VAlign = TextVAlign.Middle;
public string Font = "Regular"; public string Font = ChromeMetrics.Get<string>("TextFont");
public Color Color = Color.White; public Color TextColor = ChromeMetrics.Get<Color>("TextColor");
public bool Contrast = false; public bool Contrast = ChromeMetrics.Get<bool>("TextContrast");
public Color ContrastColor = Color.Black; public Color ContrastColor = ChromeMetrics.Get<Color>("TextContrastColor");
public bool WordWrap = false; public bool WordWrap = false;
public Func<string> GetText; public Func<string> GetText;
public Func<Color> GetColor; public Func<Color> GetColor;
@@ -35,7 +35,7 @@ namespace OpenRA.Widgets
public LabelWidget() public LabelWidget()
{ {
GetText = () => Text; GetText = () => Text;
GetColor = () => Color; GetColor = () => TextColor;
GetContrastColor = () => ContrastColor; GetContrastColor = () => ContrastColor;
} }
@@ -45,7 +45,7 @@ namespace OpenRA.Widgets
Text = other.Text; Text = other.Text;
Align = other.Align; Align = other.Align;
Font = other.Font; Font = other.Font;
Color = other.Color; TextColor = other.TextColor;
Contrast = other.Contrast; Contrast = other.Contrast;
ContrastColor = other.ContrastColor; ContrastColor = other.ContrastColor;
WordWrap = other.WordWrap; WordWrap = other.WordWrap;

View File

@@ -1,6 +1,6 @@
#region Copyright & License Information #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 * 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 * available to you under the terms of the GNU General Public License
* as published by the Free Software Foundation. For more information, * as published by the Free Software Foundation. For more information,
@@ -34,9 +34,9 @@ namespace OpenRA.Widgets
public int CursorPosition { get; set; } public int CursorPosition { get; set; }
public Func<bool> IsDisabled = () => false; public Func<bool> IsDisabled = () => false;
public Color TextColor = Color.White; public string Font = ChromeMetrics.Get<string>("TextfieldFont");
public Color DisabledColor = Color.Gray; public Color TextColor = ChromeMetrics.Get<Color>("TextfieldColor");
public string Font = "Regular"; public Color TextColorDisabled = ChromeMetrics.Get<Color>("TextfieldColorDisabled");
public TextFieldWidget() {} public TextFieldWidget() {}
protected TextFieldWidget(TextFieldWidget widget) protected TextFieldWidget(TextFieldWidget widget)
@@ -46,7 +46,7 @@ namespace OpenRA.Widgets
MaxLength = widget.MaxLength; MaxLength = widget.MaxLength;
Font = widget.Font; Font = widget.Font;
TextColor = widget.TextColor; TextColor = widget.TextColor;
DisabledColor = widget.DisabledColor; TextColorDisabled = widget.TextColorDisabled;
VisualHeight = widget.VisualHeight; VisualHeight = widget.VisualHeight;
} }
@@ -215,11 +215,11 @@ namespace OpenRA.Widgets
Bounds.Width - LeftMargin - RightMargin, Bounds.Bottom)); Bounds.Width - LeftMargin - RightMargin, Bounds.Bottom));
} }
var color = disabled ? DisabledColor : TextColor; var color = disabled ? TextColorDisabled : TextColor;
font.DrawText(apparentText, textPos, color); font.DrawText(apparentText, textPos, color);
if (showCursor && HasKeyboardFocus) 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) if (textSize.X > Bounds.Width - LeftMargin - RightMargin)
Game.Renderer.DisableScissor(); Game.Renderer.DisableScissor();

View File

@@ -1,6 +1,6 @@
#region Copyright & License Information #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 * 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 * available to you under the terms of the GNU General Public License
* as published by the Free Software Foundation. For more information, * as published by the Free Software Foundation. For more information,
@@ -8,20 +8,28 @@
*/ */
#endregion #endregion
using System;
using System.Drawing; using System.Drawing;
using OpenRA.FileFormats;
using OpenRA.Graphics;
namespace OpenRA.Widgets namespace OpenRA.Widgets
{ {
public class TimerWidget : Widget public class TimerWidget : LabelWidget
{ {
public override void Draw() public override void Draw()
{ {
var font = Game.Renderer.Fonts["Title"]; var font = Game.Renderer.Fonts[Font];
var rb = RenderBounds; var rb = RenderBounds;
var color = GetColor();
var contrast = GetContrastColor();
var s = WidgetUtils.FormatTime(Game.LocalTick) + (Game.orderManager.world.Paused?" (paused)":""); var s = WidgetUtils.FormatTime(Game.LocalTick) + (Game.orderManager.world.Paused?" (paused)":"");
var pos = new float2(rb.Left - font.Measure(s).X / 2, rb.Top); 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);
} }
} }
} }

View File

@@ -4,6 +4,8 @@ Container@INGAME_ROOT:
Timer@GAME_TIMER: Timer@GAME_TIMER:
X: WINDOW_RIGHT/2 X: WINDOW_RIGHT/2
Y: 0 Y: 0
Font: Title
Contrast: true
StrategicProgress@STRATEGIC_PROGRESS: StrategicProgress@STRATEGIC_PROGRESS:
X: WINDOW_RIGHT/2 X: WINDOW_RIGHT/2
Y: 40 Y: 40

View File

@@ -3,5 +3,19 @@
Metrics: Metrics:
ButtonDepth: 0 ButtonDepth: 0
ButtonFont: Bold ButtonFont: Bold
ButtonTextColor: 255,255,255
ButtonTextColorDisabled: 128,128,128
ButtonTextContrast: false
ButtonTextContrastColor: 0,0,0
CheckboxPressedState: true CheckboxPressedState: true
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
TextContrastColor: 0,0,0
ColorPickerRemapIndices: 176, 178, 180, 182, 184, 186, 189, 191, 177, 179, 181, 183, 185, 187, 188, 190 ColorPickerRemapIndices: 176, 178, 180, 182, 184, 186, 189, 191, 177, 179, 181, 183, 185, 187, 188, 190

View File

@@ -20,6 +20,8 @@ Container@INGAME_ROOT:
Timer@GAME_TIMER: Timer@GAME_TIMER:
X: WINDOW_RIGHT/2 X: WINDOW_RIGHT/2
Y: 0 Y: 0
Font: Title
Contrast: true
StrategicProgress@STRATEGIC_PROGRESS: StrategicProgress@STRATEGIC_PROGRESS:
X: WINDOW_RIGHT/2 X: WINDOW_RIGHT/2
Y: 40 Y: 40

View File

@@ -3,5 +3,19 @@
Metrics: Metrics:
ButtonDepth: 1 ButtonDepth: 1
ButtonFont: Regular ButtonFont: Regular
ButtonTextColor: 255,255,255
ButtonTextColorDisabled: 128,128,128
ButtonTextContrast: false
ButtonTextContrastColor: 0,0,0
CheckboxPressedState: false CheckboxPressedState: false
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
TextContrastColor: 0,0,0
ColorPickerRemapIndices: 255, 254, 253, 252, 251, 250, 249, 248, 247, 246, 245, 244, 243, 242, 241, 240 ColorPickerRemapIndices: 255, 254, 253, 252, 251, 250, 249, 248, 247, 246, 245, 244, 243, 242, 241, 240

View File

@@ -20,6 +20,8 @@ Container@INGAME_ROOT:
Timer@GAME_TIMER: Timer@GAME_TIMER:
X: WINDOW_RIGHT/2 X: WINDOW_RIGHT/2
Y: 0-10 Y: 0-10
Font: Title
Contrast: true
StrategicProgress@STRATEGIC_PROGRESS: StrategicProgress@STRATEGIC_PROGRESS:
X: WINDOW_RIGHT/2 X: WINDOW_RIGHT/2
Y: 40 Y: 40

View File

@@ -3,5 +3,19 @@
Metrics: Metrics:
ButtonDepth: 1 ButtonDepth: 1
ButtonFont: Regular ButtonFont: Regular
ButtonTextColor: 255,255,255
ButtonTextColorDisabled: 128,128,128
ButtonTextContrast: false
ButtonTextContrastColor: 0,0,0
CheckboxPressedState: false CheckboxPressedState: false
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
TextContrastColor: 0,0,0
ColorPickerRemapIndices: 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95 ColorPickerRemapIndices: 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95

View File

@@ -3,5 +3,19 @@
Metrics: Metrics:
ButtonDepth: 1 ButtonDepth: 1
ButtonFont: Regular ButtonFont: Regular
ButtonTextColor: 255,255,255
ButtonTextColorDisabled: 128,128,128
ButtonTextContrast: false
ButtonTextContrastColor: 0,0,0
CheckboxPressedState: false CheckboxPressedState: false
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
TextContrastColor: 0,0,0
ColorPickerRemapIndices: 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31 ColorPickerRemapIndices: 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31