Merge pull request #4156 from reaperrr/widgets04
Improved Widget text customizability rev.2
This commit is contained in:
@@ -78,6 +78,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.
|
||||
@@ -94,6 +95,7 @@ NEW:
|
||||
Linux packages now install to /usr/lib/openra for consistency with other Mono applications.
|
||||
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.
|
||||
|
||||
@@ -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<int>("ButtonDepth");
|
||||
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 Highlighted = false;
|
||||
public Func<string> GetText;
|
||||
public Func<Color> GetColor;
|
||||
public Func<Color> GetColorDisabled;
|
||||
public Func<Color> GetContrastColor;
|
||||
public Func<bool> IsDisabled;
|
||||
public Func<bool> IsHighlighted;
|
||||
public Action<MouseInput> 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,20 @@ 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);
|
||||
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);
|
||||
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, position + stateOffset,
|
||||
disabled ? colordisabled : color, contrast, 2);
|
||||
else
|
||||
font.DrawText(text, position + stateOffset,
|
||||
disabled ? colordisabled : color);
|
||||
}
|
||||
|
||||
public override Widget Clone() { return new ButtonWidget(this); }
|
||||
|
||||
@@ -43,7 +43,11 @@ 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 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" :
|
||||
@@ -51,11 +55,14 @@ namespace OpenRA.Widgets
|
||||
"checkbox";
|
||||
|
||||
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);
|
||||
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, position,
|
||||
disabled ? colordisabled : color, contrast, 2);
|
||||
else
|
||||
font.DrawText(Text, position,
|
||||
disabled ? colordisabled : color);
|
||||
|
||||
if (IsChecked() || (Depressed && HasPressedState && !disabled))
|
||||
{
|
||||
|
||||
@@ -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); }
|
||||
|
||||
@@ -25,9 +25,9 @@ namespace OpenRA.Widgets
|
||||
public Action OnLoseFocus = () => { };
|
||||
|
||||
public Func<bool> IsDisabled = () => false;
|
||||
public Color TextColor = Color.White;
|
||||
public Color DisabledColor = Color.Gray;
|
||||
public string Font = "Regular";
|
||||
public string Font = ChromeMetrics.Get<string>("HotkeyFont");
|
||||
public Color TextColor = ChromeMetrics.Get<Color>("HotkeyColor");
|
||||
public Color TextColorDisabled = ChromeMetrics.Get<Color>("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)
|
||||
|
||||
@@ -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<string>("TextFont");
|
||||
public Color TextColor = ChromeMetrics.Get<Color>("TextColor");
|
||||
public bool Contrast = ChromeMetrics.Get<bool>("TextContrast");
|
||||
public Color ContrastColor = ChromeMetrics.Get<Color>("TextContrastColor");
|
||||
public bool WordWrap = false;
|
||||
public Func<string> GetText;
|
||||
public Func<Color> 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;
|
||||
|
||||
@@ -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<bool> IsDisabled = () => false;
|
||||
public Color TextColor = Color.White;
|
||||
public Color DisabledColor = Color.Gray;
|
||||
public string Font = "Regular";
|
||||
public string Font = ChromeMetrics.Get<string>("TextfieldFont");
|
||||
public Color TextColor = ChromeMetrics.Get<Color>("TextfieldColor");
|
||||
public Color TextColorDisabled = ChromeMetrics.Get<Color>("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();
|
||||
|
||||
@@ -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"];
|
||||
var 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -3,5 +3,19 @@
|
||||
Metrics:
|
||||
ButtonDepth: 0
|
||||
ButtonFont: Bold
|
||||
ButtonTextColor: 255,255,255
|
||||
ButtonTextColorDisabled: 128,128,128
|
||||
ButtonTextContrast: false
|
||||
ButtonTextContrastColor: 0,0,0
|
||||
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
|
||||
@@ -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
|
||||
|
||||
@@ -3,5 +3,19 @@
|
||||
Metrics:
|
||||
ButtonDepth: 1
|
||||
ButtonFont: Regular
|
||||
ButtonTextColor: 255,255,255
|
||||
ButtonTextColorDisabled: 128,128,128
|
||||
ButtonTextContrast: false
|
||||
ButtonTextContrastColor: 0,0,0
|
||||
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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -3,5 +3,19 @@
|
||||
Metrics:
|
||||
ButtonDepth: 1
|
||||
ButtonFont: Regular
|
||||
ButtonTextColor: 255,255,255
|
||||
ButtonTextColorDisabled: 128,128,128
|
||||
ButtonTextContrast: false
|
||||
ButtonTextContrastColor: 0,0,0
|
||||
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
|
||||
|
||||
@@ -3,5 +3,19 @@
|
||||
Metrics:
|
||||
ButtonDepth: 1
|
||||
ButtonFont: Regular
|
||||
ButtonTextColor: 255,255,255
|
||||
ButtonTextColorDisabled: 128,128,128
|
||||
ButtonTextContrast: false
|
||||
ButtonTextContrastColor: 0,0,0
|
||||
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
|
||||
|
||||
Reference in New Issue
Block a user