diff --git a/OpenRA.Mods.Common/Widgets/CheckboxWidget.cs b/OpenRA.Mods.Common/Widgets/CheckboxWidget.cs index c84ccc9ff0..e15a362d53 100644 --- a/OpenRA.Mods.Common/Widgets/CheckboxWidget.cs +++ b/OpenRA.Mods.Common/Widgets/CheckboxWidget.cs @@ -18,73 +18,74 @@ namespace OpenRA.Mods.Common.Widgets { public class CheckboxWidget : ButtonWidget { - public string CheckType = "checked"; - public Func GetCheckType; + public new string Background = "checkbox"; + public string Checkmark = "tick"; + public Func GetCheckmark; public Func IsChecked = () => false; - public int CheckOffset = 2; - public bool HasPressedState = ChromeMetrics.Get("CheckboxPressedState"); + + CachedTransform<(string, bool, bool), CachedTransform<(bool, bool, bool, bool), Sprite>> getCheckmarkImageCache; [ObjectCreator.UseCtor] public CheckboxWidget(ModData modData) : base(modData) { - GetCheckType = () => CheckType; + GetCheckmark = () => Checkmark; TextColor = ChromeMetrics.Get("TextColor"); TextColorDisabled = ChromeMetrics.Get("TextDisabledColor"); GetColor = () => TextColor; GetColorDisabled = () => TextColorDisabled; + CreateCheckmarkImageCache(); } protected CheckboxWidget(CheckboxWidget other) : base(other) { - CheckType = other.CheckType; - GetCheckType = other.GetCheckType; + Background = other.Background; + Checkmark = other.Checkmark; + GetCheckmark = other.GetCheckmark; IsChecked = other.IsChecked; - CheckOffset = other.CheckOffset; - HasPressedState = other.HasPressedState; TextColor = other.TextColor; TextColorDisabled = other.TextColorDisabled; GetColor = other.GetColor; GetColorDisabled = other.GetColorDisabled; + CreateCheckmarkImageCache(); + } + + void CreateCheckmarkImageCache() + { + getCheckmarkImageCache = new CachedTransform<(string, bool, bool), CachedTransform<(bool, bool, bool, bool), Sprite>>( + ((string CheckType, bool Highlighted, bool Checked) args) => + { + var variantImageCollection = args.Highlighted ? "checkmark-highlighted-" : "checkmark-" + args.CheckType; + var variantBaseName = args.Checked ? "checked" : "unchecked"; + return WidgetUtils.GetCachedStatefulImage(variantImageCollection, variantBaseName); + }); } public override void Draw() { var disabled = IsDisabled(); var font = Game.Renderer.Fonts[Font]; + var hover = Ui.MouseOverWidget == this; var color = GetColor(); var colordisabled = GetColorDisabled(); - var bgDark = GetContrastColorDark(); - var bgLight = GetContrastColorLight(); - var rect = RenderBounds; var text = GetText(); - var textSize = font.Measure(text); - var check = new Rectangle(rect.Location, new Size(Bounds.Height, Bounds.Height)); - var baseName = IsHighlighted() ? "checkbox-highlighted" : "checkbox"; - var state = WidgetUtils.GetStatefulImageName(baseName, disabled, Depressed && HasPressedState, Ui.MouseOverWidget == this); + var rect = new Rectangle(RenderBounds.Location, new Size(Bounds.Height, Bounds.Height)); - WidgetUtils.DrawPanel(state, check); - - var topOffset = font.TopOffset; - var position = new float2(rect.Left + rect.Height * 1.5f, RenderOrigin.Y + (Bounds.Height - textSize.Y - topOffset) / 2); + DrawBackground(Background, rect, disabled, Depressed, hover, IsHighlighted()); + var textPosition = new float2(RenderBounds.Left + RenderBounds.Height * 1.5f, RenderOrigin.Y + (Bounds.Height - font.Measure(text).Y - font.TopOffset) / 2); if (Contrast) - font.DrawTextWithContrast(text, position, - disabled ? colordisabled : color, bgDark, bgLight, 2); + font.DrawTextWithContrast(text, textPosition, + disabled ? colordisabled : color, GetContrastColorDark(), GetContrastColorLight(), 2); else - font.DrawText(text, position, + font.DrawText(text, textPosition, disabled ? colordisabled : color); - if (IsChecked() || (Depressed && HasPressedState && !disabled)) - { - var checkType = GetCheckType(); - if (HasPressedState && (Depressed || disabled)) - checkType += "-disabled"; - - var offset = new float2(rect.Left + CheckOffset, rect.Top + CheckOffset); - WidgetUtils.DrawSprite(ChromeProvider.GetImage("checkbox-bits", checkType), offset); - } + var checkmarkImage = getCheckmarkImageCache + .Update((GetCheckmark(), IsHighlighted(), IsChecked())) + .Update((disabled, Depressed, hover, false)); + WidgetUtils.DrawSprite(checkmarkImage, new float2(rect.Right - (int)((rect.Height + checkmarkImage.Size.X) / 2), rect.Top + (int)((rect.Height - checkmarkImage.Size.Y) / 2))); } public override Widget Clone() { return new CheckboxWidget(this); } diff --git a/OpenRA.Mods.Common/Widgets/Logic/Ingame/GameInfoObjectivesLogic.cs b/OpenRA.Mods.Common/Widgets/Logic/Ingame/GameInfoObjectivesLogic.cs index 6e762a730d..97dfbf829d 100644 --- a/OpenRA.Mods.Common/Widgets/Logic/Ingame/GameInfoObjectivesLogic.cs +++ b/OpenRA.Mods.Common/Widgets/Logic/Ingame/GameInfoObjectivesLogic.cs @@ -70,7 +70,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic var checkbox = widget.Get("OBJECTIVE_STATUS"); checkbox.IsChecked = () => objective.State != ObjectiveState.Incomplete; - checkbox.GetCheckType = () => objective.State == ObjectiveState.Completed ? "checked" : "crossed"; + checkbox.GetCheckmark = () => objective.State == ObjectiveState.Completed ? "tick" : "cross"; checkbox.GetText = () => objective.Description; parent.AddChild(widget); diff --git a/OpenRA.Mods.Common/Widgets/Logic/Ingame/GameInfoStatsLogic.cs b/OpenRA.Mods.Common/Widgets/Logic/Ingame/GameInfoStatsLogic.cs index 6b46618989..88ade69eb7 100644 --- a/OpenRA.Mods.Common/Widgets/Logic/Ingame/GameInfoStatsLogic.cs +++ b/OpenRA.Mods.Common/Widgets/Logic/Ingame/GameInfoStatsLogic.cs @@ -34,8 +34,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic var statusLabel = widget.Get("STATS_STATUS"); checkbox.IsChecked = () => player.WinState != WinState.Undefined; - checkbox.GetCheckType = () => player.WinState == WinState.Won ? - "checked" : "crossed"; + checkbox.GetCheckmark = () => player.WinState == WinState.Won ? "tick" : "cross"; if (player.HasObjectives) { diff --git a/mods/cnc/chrome.yaml b/mods/cnc/chrome.yaml index aa4c4efdbe..f9ede3236a 100644 --- a/mods/cnc/chrome.yaml +++ b/mods/cnc/chrome.yaml @@ -394,13 +394,29 @@ reload-icon: disabled-10: 955, 34, 16, 16 disabled-11: 972, 34, 16, 16 -checkbox-bits: +checkmark-tick: Inherits: ^Chrome Regions: checked: 972, 17, 16, 16 + checked-pressed: 989, 17, 16, 16 checked-disabled: 989, 17, 16, 16 - crossed: 972, 0, 16, 16 - crossed-disabled: 989, 0, 16, 16 + unchecked: 0, 0, 0, 0 + unchecked-pressed: 989, 17, 16, 16 + +checkmark-highlighted-tick: + Inherits: checkmark-tick + +checkmark-cross: + Inherits: ^Chrome + Regions: + checked: 972, 0, 16, 16 + checked-pressed: 989, 0, 16, 16 + checked-disabled: 989, 0, 16, 16 + unchecked: 0, 0, 0, 0 + unchecked-pressed: 989, 0, 16, 16 + +checkmark-highlighted-cross: + Inherits: checkmark-cross flags: Inherits: ^Chrome diff --git a/mods/cnc/chrome/lobby-players.yaml b/mods/cnc/chrome/lobby-players.yaml index 6a6644403f..c6f94f5589 100644 --- a/mods/cnc/chrome/lobby-players.yaml +++ b/mods/cnc/chrome/lobby-players.yaml @@ -166,7 +166,7 @@ Container@LOBBY_PLAYER_BIN: Y: 4 Width: 20 Height: 20 - ImageCollection: checkbox-bits + ImageCollection: checkmark-tick ImageName: checked Visible: false Checkbox@STATUS_CHECKBOX: @@ -294,7 +294,7 @@ Container@LOBBY_PLAYER_BIN: Y: 4 Width: 20 Height: 20 - ImageCollection: checkbox-bits + ImageCollection: checkmark-tick ImageName: checked Visible: false Container@TEMPLATE_EMPTY: @@ -376,7 +376,7 @@ Container@LOBBY_PLAYER_BIN: Y: 4 Width: 20 Height: 20 - ImageCollection: checkbox-bits + ImageCollection: checkmark-tick ImageName: checked Visible: false Checkbox@STATUS_CHECKBOX: @@ -457,7 +457,7 @@ Container@LOBBY_PLAYER_BIN: Y: 4 Width: 20 Height: 20 - ImageCollection: checkbox-bits + ImageCollection: checkmark-tick ImageName: checked Visible: false Container@TEMPLATE_NEW_SPECTATOR: diff --git a/mods/cnc/metrics.yaml b/mods/cnc/metrics.yaml index 89222bdaf4..4c717915e3 100644 --- a/mods/cnc/metrics.yaml +++ b/mods/cnc/metrics.yaml @@ -3,5 +3,4 @@ Metrics: ButtonDepth: 0 ButtonFont: Bold - CheckboxPressedState: true TextfieldColorHighlight: 800000 diff --git a/mods/common/chrome/lobby-players.yaml b/mods/common/chrome/lobby-players.yaml index dfbef77ee9..34716af303 100644 --- a/mods/common/chrome/lobby-players.yaml +++ b/mods/common/chrome/lobby-players.yaml @@ -168,7 +168,7 @@ Container@LOBBY_PLAYER_BIN: Y: 4 Width: 20 Height: 20 - ImageCollection: checkbox-bits + ImageCollection: checkmark-tick ImageName: checked Visible: false Container@TEMPLATE_NONEDITABLE_PLAYER: @@ -288,7 +288,7 @@ Container@LOBBY_PLAYER_BIN: Y: 4 Width: 20 Height: 20 - ImageCollection: checkbox-bits + ImageCollection: checkmark-tick ImageName: checked Visible: false Container@TEMPLATE_EMPTY: @@ -373,7 +373,7 @@ Container@LOBBY_PLAYER_BIN: Y: 4 Width: 20 Height: 20 - ImageCollection: checkbox-bits + ImageCollection: checkmark-tick ImageName: checked Visible: false Container@TEMPLATE_NONEDITABLE_SPECTATOR: @@ -448,7 +448,7 @@ Container@LOBBY_PLAYER_BIN: Y: 4 Width: 20 Height: 20 - ImageCollection: checkbox-bits + ImageCollection: checkmark-tick ImageName: checked Visible: false Container@TEMPLATE_NEW_SPECTATOR: diff --git a/mods/common/metrics.yaml b/mods/common/metrics.yaml index 976e57d9d0..9767c8c60c 100644 --- a/mods/common/metrics.yaml +++ b/mods/common/metrics.yaml @@ -8,7 +8,6 @@ Metrics: ButtonTextContrastColorLight: 7F7F7F ButtonTextContrastRadius: 1 ButtonTextShadow: false - CheckboxPressedState: false GameStartedColor: FFA500 HotkeyColor: FFFFFF HotkeyColorDisabled: 808080 diff --git a/mods/d2k/chrome.yaml b/mods/d2k/chrome.yaml index c753c2abc1..4c936e79b8 100644 --- a/mods/d2k/chrome.yaml +++ b/mods/d2k/chrome.yaml @@ -373,18 +373,35 @@ slider-thumb-disabled: checkbox: Inherits: button-pressed -checkbox-bits: +checkmark-tick: Inherits: ^Glyphs Regions: checked: 187, 0, 16, 16 - checked-disabled: 204, 0, 16, 16 - crossed: 221, 0, 16, 16 - crossed-disabled: 238, 0, 16, 16 + checked-pressed: 204, 0, 16, 16 + unchecked: 0, 0, 0, 0 + unchecked-pressed: 204, 0, 16, 16 + +checkmark-highlighted-tick: + Inherits: checkmark-tick + +checkmark-cross: + Inherits: ^Glyphs + Regions: + checked: 221, 0, 16, 16 + checked-pressed: 238, 0, 16, 16 + unchecked: 0, 0, 0, 0 + unchecked-pressed: 238, 0, 16, 16 + +checkmark-highlighted-cross: + Inherits: checkmark-cross checkbox-hover: Inherits: ^Dialog PanelRegion: 641, 129, 2, 2, 122, 122, 2, 2 +checkbox-pressed: + Inherits: checkbox-hover + # Same as a button-disabled-pressed checkbox-disabled: Inherits: ^Dialog @@ -396,6 +413,9 @@ checkbox-highlighted: checkbox-highlighted-hover: Inherits: checkbox-highlighted +checkbox-highlighted-pressed: + Inherits: checkbox-highlighted + checkbox-highlighted-disabled: Inherits: checkbox-disabled diff --git a/mods/d2k/chrome/lobby-players.yaml b/mods/d2k/chrome/lobby-players.yaml index eb15f28c6e..42767d8894 100644 --- a/mods/d2k/chrome/lobby-players.yaml +++ b/mods/d2k/chrome/lobby-players.yaml @@ -168,7 +168,7 @@ Container@LOBBY_PLAYER_BIN: Y: 4 Width: 20 Height: 20 - ImageCollection: checkbox-bits + ImageCollection: checkmark-tick ImageName: checked Visible: false Container@TEMPLATE_NONEDITABLE_PLAYER: @@ -288,7 +288,7 @@ Container@LOBBY_PLAYER_BIN: Y: 4 Width: 20 Height: 20 - ImageCollection: checkbox-bits + ImageCollection: checkmark-tick ImageName: checked Visible: false Container@TEMPLATE_EMPTY: @@ -373,7 +373,7 @@ Container@LOBBY_PLAYER_BIN: Y: 4 Width: 20 Height: 20 - ImageCollection: checkbox-bits + ImageCollection: checkmark-tick ImageName: checked Visible: false Container@TEMPLATE_NONEDITABLE_SPECTATOR: @@ -448,7 +448,7 @@ Container@LOBBY_PLAYER_BIN: Y: 4 Width: 20 Height: 20 - ImageCollection: checkbox-bits + ImageCollection: checkmark-tick ImageName: checked Visible: false Container@TEMPLATE_NEW_SPECTATOR: diff --git a/mods/modcontent/metrics.yaml b/mods/modcontent/metrics.yaml index cf2b40e3d2..30c39e64a5 100644 --- a/mods/modcontent/metrics.yaml +++ b/mods/modcontent/metrics.yaml @@ -3,7 +3,6 @@ Metrics: ButtonDepth: 0 ButtonFont: Bold - CheckboxPressedState: true ChatLineSound: ChatLine ClickDisabledSound: ClickDisabledSound ClickSound: ClickSound diff --git a/mods/ra/chrome.yaml b/mods/ra/chrome.yaml index 6843752f35..f023df0b4a 100644 --- a/mods/ra/chrome.yaml +++ b/mods/ra/chrome.yaml @@ -502,18 +502,35 @@ slider-thumb-disabled: checkbox: Inherits: button-pressed -checkbox-bits: +checkmark-tick: Inherits: ^Glyphs Regions: checked: 187, 0, 16, 16 - checked-disabled: 204, 0, 16, 16 - crossed: 221, 0, 16, 16 - crossed-disabled: 238, 0, 16, 16 + checked-pressed: 204, 0, 16, 16 + unchecked: 0, 0, 0, 0 + unchecked-pressed: 204, 0, 16, 16 + +checkmark-highlighted-tick: + Inherits: checkmark-tick + +checkmark-cross: + Inherits: ^Glyphs + Regions: + checked: 221, 0, 16, 16 + checked-pressed: 238, 0, 16, 16 + unchecked: 0, 0, 0, 0 + unchecked-pressed: 238, 0, 16, 16 + +checkmark-highlighted-cross: + Inherits: checkmark-cross checkbox-hover: Inherits: ^Dialog PanelRegion: 641, 129, 2, 2, 122, 122, 2, 2 +checkbox-pressed: + Inherits: checkbox-hover + checkbox-disabled: Inherits: ^Dialog PanelRegion: 641, 257, 2, 2, 122, 122, 2, 2 @@ -525,6 +542,9 @@ checkbox-highlighted: checkbox-highlighted-hover: Inherits: checkbox-highlighted +checkbox-highlighted-pressed: + Inherits: checkbox-highlighted + checkbox-highlighted-disabled: Inherits: checkbox-disabled diff --git a/mods/ts/chrome.yaml b/mods/ts/chrome.yaml index 335280e8af..7d771a24ad 100644 --- a/mods/ts/chrome.yaml +++ b/mods/ts/chrome.yaml @@ -635,18 +635,35 @@ slider-thumb-disabled: checkbox: Inherits: button-pressed -checkbox-bits: +checkmark-tick: Inherits: ^Glyphs Regions: checked: 187, 0, 16, 16 - checked-disabled: 204, 0, 16, 16 - crossed: 221, 0, 16, 16 - crossed-disabled: 238, 0, 16, 16 + checked-pressed: 204, 0, 16, 16 + unchecked: 0, 0, 0, 0 + unchecked-pressed: 204, 0, 16, 16 + +checkmark-highlighted-tick: + Inherits: checkmark-tick + +checkmark-cross: + Inherits: ^Glyphs + Regions: + checked: 221, 0, 16, 16 + checked-pressed: 238, 0, 16, 16 + unchecked: 0, 0, 0, 0 + unchecked-pressed: 238, 0, 16, 16 + +checkmark-highlighted-cross: + Inherits: checkmark-cross checkbox-hover: Inherits: ^Dialog PanelRegion: 641, 129, 2, 2, 122, 122, 2, 2 +checkbox-pressed: + Inherits: checkbox-hover + checkbox-disabled: Inherits: ^Dialog PanelRegion: 641, 257, 2, 2, 122, 122, 2, 2 @@ -658,6 +675,9 @@ checkbox-highlighted: checkbox-highlighted-hover: Inherits: checkbox-highlighted +checkbox-highlighted-pressed: + Inherits: checkbox-highlighted + checkbox-highlighted-disabled: Inherits: checkbox-disabled