diff --git a/OpenRA.Mods.Common/Widgets/CheckboxWidget.cs b/OpenRA.Mods.Common/Widgets/CheckboxWidget.cs index e15a362d53..4032f4d909 100644 --- a/OpenRA.Mods.Common/Widgets/CheckboxWidget.cs +++ b/OpenRA.Mods.Common/Widgets/CheckboxWidget.cs @@ -23,7 +23,14 @@ namespace OpenRA.Mods.Common.Widgets public Func GetCheckmark; public Func IsChecked = () => false; - CachedTransform<(string, bool, bool), CachedTransform<(bool, bool, bool, bool), Sprite>> getCheckmarkImageCache; + readonly CachedTransform<(string, bool), CachedTransform<(bool, bool, bool, bool, bool), Sprite>> getCheckmarkImageCache + = new CachedTransform<(string, bool), CachedTransform<(bool, bool, bool, bool, bool), Sprite>>( + ((string CheckType, bool Checked) args) => + { + var variantImageCollection = "checkmark-" + args.CheckType; + var variantBaseName = args.Checked ? "checked" : "unchecked"; + return WidgetUtils.GetCachedStatefulImage(variantImageCollection, variantBaseName); + }); [ObjectCreator.UseCtor] public CheckboxWidget(ModData modData) @@ -34,7 +41,6 @@ namespace OpenRA.Mods.Common.Widgets TextColorDisabled = ChromeMetrics.Get("TextDisabledColor"); GetColor = () => TextColor; GetColorDisabled = () => TextColorDisabled; - CreateCheckmarkImageCache(); } protected CheckboxWidget(CheckboxWidget other) @@ -48,18 +54,6 @@ namespace OpenRA.Mods.Common.Widgets 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() @@ -83,8 +77,8 @@ namespace OpenRA.Mods.Common.Widgets disabled ? colordisabled : color); var checkmarkImage = getCheckmarkImageCache - .Update((GetCheckmark(), IsHighlighted(), IsChecked())) - .Update((disabled, Depressed, hover, false)); + .Update((GetCheckmark(), IsChecked())) + .Update((disabled, Depressed, hover, false, IsHighlighted())); WidgetUtils.DrawSprite(checkmarkImage, new float2(rect.Right - (int)((rect.Height + checkmarkImage.Size.X) / 2), rect.Top + (int)((rect.Height - checkmarkImage.Size.Y) / 2))); } diff --git a/OpenRA.Mods.Common/Widgets/DropDownButtonWidget.cs b/OpenRA.Mods.Common/Widgets/DropDownButtonWidget.cs index 374f9f1ede..4c41818a45 100644 --- a/OpenRA.Mods.Common/Widgets/DropDownButtonWidget.cs +++ b/OpenRA.Mods.Common/Widgets/DropDownButtonWidget.cs @@ -30,8 +30,8 @@ namespace OpenRA.Mods.Common.Widgets Widget panel; MaskWidget fullscreenMask; Widget panelRoot; - CachedTransform<(bool Disabled, bool Pressed, bool Hover, bool Focused), Sprite> getMarkerImage; - CachedTransform<(bool Disabled, bool Pressed, bool Hover, bool Focused), Sprite> getSeparatorImage; + CachedTransform<(bool Disabled, bool Pressed, bool Hover, bool Focused, bool Highlighted), Sprite> getMarkerImage; + CachedTransform<(bool Disabled, bool Pressed, bool Hover, bool Focused, bool Highlighted), Sprite> getSeparatorImage; [ObjectCreator.UseCtor] public DropDownButtonWidget(ModData modData) @@ -59,13 +59,13 @@ namespace OpenRA.Mods.Common.Widgets if (getMarkerImage == null) getMarkerImage = WidgetUtils.GetCachedStatefulImage(Decorations, DecorationMarker); - var arrowImage = getMarkerImage.Update((isDisabled, Depressed, isHover, false)); + var arrowImage = getMarkerImage.Update((isDisabled, Depressed, isHover, false, IsHighlighted())); WidgetUtils.DrawSprite(arrowImage, stateOffset + new float2(rb.Right - (int)((rb.Height + arrowImage.Size.X) / 2), rb.Top + (int)((rb.Height - arrowImage.Size.Y) / 2))); if (getSeparatorImage == null) getSeparatorImage = WidgetUtils.GetCachedStatefulImage(Separators, SeparatorImage); - var separatorImage = getSeparatorImage.Update((isDisabled, Depressed, isHover, false)); + var separatorImage = getSeparatorImage.Update((isDisabled, Depressed, isHover, false, IsHighlighted())); if (separatorImage != null) WidgetUtils.DrawSprite(separatorImage, stateOffset + new float2(-3, 0) + new float2(rb.Right - rb.Height + 4, rb.Top + (int)((rb.Height - separatorImage.Size.Y) / 2))); } diff --git a/OpenRA.Mods.Common/Widgets/ProductionTabsWidget.cs b/OpenRA.Mods.Common/Widgets/ProductionTabsWidget.cs index 0c100b2553..1da40d5cf2 100644 --- a/OpenRA.Mods.Common/Widgets/ProductionTabsWidget.cs +++ b/OpenRA.Mods.Common/Widgets/ProductionTabsWidget.cs @@ -86,8 +86,8 @@ namespace OpenRA.Mods.Common.Widgets public readonly string Decorations = "scrollpanel-decorations"; public readonly string DecorationScrollLeft = "left"; public readonly string DecorationScrollRight = "right"; - readonly CachedTransform<(bool Disabled, bool Pressed, bool Hover, bool Focused), Sprite> getLeftArrowImage; - readonly CachedTransform<(bool Disabled, bool Pressed, bool Hover, bool Focused), Sprite> getRightArrowImage; + readonly CachedTransform<(bool Disabled, bool Pressed, bool Hover, bool Focused, bool Highlighted), Sprite> getLeftArrowImage; + readonly CachedTransform<(bool Disabled, bool Pressed, bool Hover, bool Focused, bool Highlighted), Sprite> getRightArrowImage; int contentWidth = 0; float listOffset = 0; @@ -193,11 +193,11 @@ namespace OpenRA.Mods.Common.Widgets ButtonWidget.DrawBackground(Button, leftButtonRect, leftDisabled, leftPressed, leftHover, false); ButtonWidget.DrawBackground(Button, rightButtonRect, rightDisabled, rightPressed, rightHover, false); - var leftArrowImage = getLeftArrowImage.Update((leftDisabled, leftPressed, leftHover, false)); + var leftArrowImage = getLeftArrowImage.Update((leftDisabled, leftPressed, leftHover, false, false)); WidgetUtils.DrawSprite(leftArrowImage, new float2(leftButtonRect.Left + 2, leftButtonRect.Top + 2)); - var rightArrowImage = getRightArrowImage.Update((rightDisabled, rightPressed, rightHover, false)); + var rightArrowImage = getRightArrowImage.Update((rightDisabled, rightPressed, rightHover, false, false)); WidgetUtils.DrawSprite(rightArrowImage, new float2(rightButtonRect.Left + 2, rightButtonRect.Top + 2)); diff --git a/OpenRA.Mods.Common/Widgets/ScrollPanelWidget.cs b/OpenRA.Mods.Common/Widgets/ScrollPanelWidget.cs index b001150659..bb6ac69842 100644 --- a/OpenRA.Mods.Common/Widgets/ScrollPanelWidget.cs +++ b/OpenRA.Mods.Common/Widgets/ScrollPanelWidget.cs @@ -52,8 +52,8 @@ namespace OpenRA.Mods.Common.Widgets public string Decorations = "scrollpanel-decorations"; public readonly string DecorationScrollUp = "up"; public readonly string DecorationScrollDown = "down"; - readonly CachedTransform<(bool Disabled, bool Pressed, bool Hover, bool Focused), Sprite> getUpArrowImage; - readonly CachedTransform<(bool Disabled, bool Pressed, bool Hover, bool Focused), Sprite> getDownArrowImage; + readonly CachedTransform<(bool Disabled, bool Pressed, bool Hover, bool Focused, bool Highlighted), Sprite> getUpArrowImage; + readonly CachedTransform<(bool Disabled, bool Pressed, bool Hover, bool Focused, bool Highlighted), Sprite> getDownArrowImage; public int ContentHeight; public ILayout Layout; public int MinimumThumbSize = 10; @@ -211,11 +211,11 @@ namespace OpenRA.Mods.Common.Widgets var upOffset = !upPressed || upDisabled ? 4 : 4 + ButtonDepth; var downOffset = !downPressed || downDisabled ? 4 : 4 + ButtonDepth; - var upArrowImage = getUpArrowImage.Update((upDisabled, upPressed, upHover, false)); + var upArrowImage = getUpArrowImage.Update((upDisabled, upPressed, upHover, false, false)); WidgetUtils.DrawSprite(upArrowImage, new float2(upButtonRect.Left + upOffset, upButtonRect.Top + upOffset)); - var downArrowImage = getDownArrowImage.Update((downDisabled, downPressed, downHover, false)); + var downArrowImage = getDownArrowImage.Update((downDisabled, downPressed, downHover, false, false)); WidgetUtils.DrawSprite(downArrowImage, new float2(downButtonRect.Left + downOffset, downButtonRect.Top + downOffset)); } diff --git a/OpenRA.Mods.Common/Widgets/WidgetUtils.cs b/OpenRA.Mods.Common/Widgets/WidgetUtils.cs index f4f8f7591a..ce9abf1c91 100644 --- a/OpenRA.Mods.Common/Widgets/WidgetUtils.cs +++ b/OpenRA.Mods.Common/Widgets/WidgetUtils.cs @@ -31,13 +31,14 @@ namespace OpenRA.Mods.Common.Widgets return baseName + suffix; } - public static CachedTransform<(bool Disabled, bool Pressed, bool Hover, bool Focused), Sprite> GetCachedStatefulImage(string collection, string baseName) + public static CachedTransform<(bool Disabled, bool Pressed, bool Hover, bool Focused, bool Highlighted), Sprite> GetCachedStatefulImage(string collection, string imageName) { - return new CachedTransform<(bool, bool, bool, bool), Sprite>( - ((bool Disabled, bool Pressed, bool Hover, bool Focused) args) => + return new CachedTransform<(bool, bool, bool, bool, bool), Sprite>( + ((bool Disabled, bool Pressed, bool Hover, bool Focused, bool Highlighted) args) => { - var imageName = GetStatefulImageName(baseName, args.Disabled, args.Pressed, args.Hover, args.Focused); - return ChromeProvider.GetImage(collection, imageName) ?? ChromeProvider.GetImage(collection, baseName); + var collectionName = collection + (args.Highlighted ? "-highlighted" : ""); + var variantImageName = GetStatefulImageName(imageName, args.Disabled, args.Pressed, args.Hover, args.Focused); + return ChromeProvider.GetImage(collectionName, variantImageName) ?? ChromeProvider.GetImage(collectionName, imageName); }); } diff --git a/mods/cnc/chrome.yaml b/mods/cnc/chrome.yaml index 9dce30c39d..d9c4a40679 100644 --- a/mods/cnc/chrome.yaml +++ b/mods/cnc/chrome.yaml @@ -435,7 +435,7 @@ checkmark-tick: unchecked: 0, 0, 0, 0 unchecked-pressed: 989, 17, 16, 16 -checkmark-highlighted-tick: +checkmark-tick-highlighted: Inherits: checkmark-tick checkmark-cross: @@ -447,7 +447,7 @@ checkmark-cross: unchecked: 0, 0, 0, 0 unchecked-pressed: 989, 0, 16, 16 -checkmark-highlighted-cross: +checkmark-cross-highlighted: Inherits: checkmark-cross checkmark-mute: @@ -458,7 +458,7 @@ checkmark-mute: checked: 1006, 34, 16, 16 checked-pressed: 989, 34, 16, 16 -checkmark-highlighted-mute: +checkmark-mute-highlighted: Inherits: checkmark-mute flags: diff --git a/mods/d2k/chrome.yaml b/mods/d2k/chrome.yaml index d21adcd647..c73d9be5f5 100644 --- a/mods/d2k/chrome.yaml +++ b/mods/d2k/chrome.yaml @@ -381,7 +381,7 @@ checkmark-tick: unchecked: 0, 0, 0, 0 unchecked-pressed: 204, 0, 16, 16 -checkmark-highlighted-tick: +checkmark-tick-highlighted: Inherits: checkmark-tick checkmark-cross: @@ -392,7 +392,7 @@ checkmark-cross: unchecked: 0, 0, 0, 0 unchecked-pressed: 238, 0, 16, 16 -checkmark-highlighted-cross: +checkmark-cross-highlighted: Inherits: checkmark-cross checkmark-mute: @@ -403,7 +403,7 @@ checkmark-mute: checked: 238, 34, 16, 16 checked-pressed: 221, 34, 16, 16 -checkmark-highlighted-mute: +checkmark-mute-highlighted: Inherits: checkmark-mute checkbox-hover: diff --git a/mods/ra/chrome.yaml b/mods/ra/chrome.yaml index 2ac56eb634..176aa9f34a 100644 --- a/mods/ra/chrome.yaml +++ b/mods/ra/chrome.yaml @@ -518,7 +518,7 @@ checkmark-tick: unchecked: 0, 0, 0, 0 unchecked-pressed: 204, 0, 16, 16 -checkmark-highlighted-tick: +checkmark-tick-highlighted: Inherits: checkmark-tick checkmark-cross: @@ -529,7 +529,7 @@ checkmark-cross: unchecked: 0, 0, 0, 0 unchecked-pressed: 238, 0, 16, 16 -checkmark-highlighted-cross: +checkmark-cross-highlighted: Inherits: checkmark-cross checkmark-mute: @@ -540,7 +540,7 @@ checkmark-mute: checked: 17, 170, 16, 16 checked-pressed: 0, 170, 16, 16 -checkmark-highlighted-mute: +checkmark-mute-highlighted: Inherits: checkmark-mute checkbox-hover: diff --git a/mods/ts/chrome.yaml b/mods/ts/chrome.yaml index 7dbdf03fc3..a9fb381110 100644 --- a/mods/ts/chrome.yaml +++ b/mods/ts/chrome.yaml @@ -643,7 +643,7 @@ checkmark-tick: unchecked: 0, 0, 0, 0 unchecked-pressed: 204, 0, 16, 16 -checkmark-highlighted-tick: +checkmark-tick-highlighted: Inherits: checkmark-tick checkmark-cross: @@ -654,7 +654,7 @@ checkmark-cross: unchecked: 0, 0, 0, 0 unchecked-pressed: 238, 0, 16, 16 -checkmark-highlighted-cross: +checkmark-cross-highlighted: Inherits: checkmark-cross checkmark-mute: @@ -665,7 +665,7 @@ checkmark-mute: checked: 238, 34, 16, 16 checked-pressed: 221, 34, 16, 16 -checkmark-highlighted-mute: +checkmark-mute-highlighted: Inherits: checkmark-mute checkbox-hover: