Add highlighted state to GetCachedStatefulImage
This commit is contained in:
@@ -23,7 +23,14 @@ namespace OpenRA.Mods.Common.Widgets
|
|||||||
public Func<string> GetCheckmark;
|
public Func<string> GetCheckmark;
|
||||||
public Func<bool> IsChecked = () => false;
|
public Func<bool> 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]
|
[ObjectCreator.UseCtor]
|
||||||
public CheckboxWidget(ModData modData)
|
public CheckboxWidget(ModData modData)
|
||||||
@@ -34,7 +41,6 @@ namespace OpenRA.Mods.Common.Widgets
|
|||||||
TextColorDisabled = ChromeMetrics.Get<Color>("TextDisabledColor");
|
TextColorDisabled = ChromeMetrics.Get<Color>("TextDisabledColor");
|
||||||
GetColor = () => TextColor;
|
GetColor = () => TextColor;
|
||||||
GetColorDisabled = () => TextColorDisabled;
|
GetColorDisabled = () => TextColorDisabled;
|
||||||
CreateCheckmarkImageCache();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected CheckboxWidget(CheckboxWidget other)
|
protected CheckboxWidget(CheckboxWidget other)
|
||||||
@@ -48,18 +54,6 @@ namespace OpenRA.Mods.Common.Widgets
|
|||||||
TextColorDisabled = other.TextColorDisabled;
|
TextColorDisabled = other.TextColorDisabled;
|
||||||
GetColor = other.GetColor;
|
GetColor = other.GetColor;
|
||||||
GetColorDisabled = other.GetColorDisabled;
|
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()
|
public override void Draw()
|
||||||
@@ -83,8 +77,8 @@ namespace OpenRA.Mods.Common.Widgets
|
|||||||
disabled ? colordisabled : color);
|
disabled ? colordisabled : color);
|
||||||
|
|
||||||
var checkmarkImage = getCheckmarkImageCache
|
var checkmarkImage = getCheckmarkImageCache
|
||||||
.Update((GetCheckmark(), IsHighlighted(), IsChecked()))
|
.Update((GetCheckmark(), IsChecked()))
|
||||||
.Update((disabled, Depressed, hover, false));
|
.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)));
|
WidgetUtils.DrawSprite(checkmarkImage, new float2(rect.Right - (int)((rect.Height + checkmarkImage.Size.X) / 2), rect.Top + (int)((rect.Height - checkmarkImage.Size.Y) / 2)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -30,8 +30,8 @@ namespace OpenRA.Mods.Common.Widgets
|
|||||||
Widget panel;
|
Widget panel;
|
||||||
MaskWidget fullscreenMask;
|
MaskWidget fullscreenMask;
|
||||||
Widget panelRoot;
|
Widget panelRoot;
|
||||||
CachedTransform<(bool Disabled, bool Pressed, bool Hover, bool Focused), Sprite> getMarkerImage;
|
CachedTransform<(bool Disabled, bool Pressed, bool Hover, bool Focused, bool Highlighted), 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> getSeparatorImage;
|
||||||
|
|
||||||
[ObjectCreator.UseCtor]
|
[ObjectCreator.UseCtor]
|
||||||
public DropDownButtonWidget(ModData modData)
|
public DropDownButtonWidget(ModData modData)
|
||||||
@@ -59,13 +59,13 @@ namespace OpenRA.Mods.Common.Widgets
|
|||||||
if (getMarkerImage == null)
|
if (getMarkerImage == null)
|
||||||
getMarkerImage = WidgetUtils.GetCachedStatefulImage(Decorations, DecorationMarker);
|
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)));
|
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)
|
if (getSeparatorImage == null)
|
||||||
getSeparatorImage = WidgetUtils.GetCachedStatefulImage(Separators, SeparatorImage);
|
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)
|
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)));
|
WidgetUtils.DrawSprite(separatorImage, stateOffset + new float2(-3, 0) + new float2(rb.Right - rb.Height + 4, rb.Top + (int)((rb.Height - separatorImage.Size.Y) / 2)));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -86,8 +86,8 @@ namespace OpenRA.Mods.Common.Widgets
|
|||||||
public readonly string Decorations = "scrollpanel-decorations";
|
public readonly string Decorations = "scrollpanel-decorations";
|
||||||
public readonly string DecorationScrollLeft = "left";
|
public readonly string DecorationScrollLeft = "left";
|
||||||
public readonly string DecorationScrollRight = "right";
|
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, bool Highlighted), 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> getRightArrowImage;
|
||||||
|
|
||||||
int contentWidth = 0;
|
int contentWidth = 0;
|
||||||
float listOffset = 0;
|
float listOffset = 0;
|
||||||
@@ -193,11 +193,11 @@ namespace OpenRA.Mods.Common.Widgets
|
|||||||
ButtonWidget.DrawBackground(Button, leftButtonRect, leftDisabled, leftPressed, leftHover, false);
|
ButtonWidget.DrawBackground(Button, leftButtonRect, leftDisabled, leftPressed, leftHover, false);
|
||||||
ButtonWidget.DrawBackground(Button, rightButtonRect, rightDisabled, rightPressed, rightHover, 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,
|
WidgetUtils.DrawSprite(leftArrowImage,
|
||||||
new float2(leftButtonRect.Left + 2, leftButtonRect.Top + 2));
|
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,
|
WidgetUtils.DrawSprite(rightArrowImage,
|
||||||
new float2(rightButtonRect.Left + 2, rightButtonRect.Top + 2));
|
new float2(rightButtonRect.Left + 2, rightButtonRect.Top + 2));
|
||||||
|
|
||||||
|
|||||||
@@ -52,8 +52,8 @@ namespace OpenRA.Mods.Common.Widgets
|
|||||||
public string Decorations = "scrollpanel-decorations";
|
public string Decorations = "scrollpanel-decorations";
|
||||||
public readonly string DecorationScrollUp = "up";
|
public readonly string DecorationScrollUp = "up";
|
||||||
public readonly string DecorationScrollDown = "down";
|
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, bool Highlighted), 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> getDownArrowImage;
|
||||||
public int ContentHeight;
|
public int ContentHeight;
|
||||||
public ILayout Layout;
|
public ILayout Layout;
|
||||||
public int MinimumThumbSize = 10;
|
public int MinimumThumbSize = 10;
|
||||||
@@ -211,11 +211,11 @@ namespace OpenRA.Mods.Common.Widgets
|
|||||||
var upOffset = !upPressed || upDisabled ? 4 : 4 + ButtonDepth;
|
var upOffset = !upPressed || upDisabled ? 4 : 4 + ButtonDepth;
|
||||||
var downOffset = !downPressed || downDisabled ? 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,
|
WidgetUtils.DrawSprite(upArrowImage,
|
||||||
new float2(upButtonRect.Left + upOffset, upButtonRect.Top + upOffset));
|
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,
|
WidgetUtils.DrawSprite(downArrowImage,
|
||||||
new float2(downButtonRect.Left + downOffset, downButtonRect.Top + downOffset));
|
new float2(downButtonRect.Left + downOffset, downButtonRect.Top + downOffset));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -31,13 +31,14 @@ namespace OpenRA.Mods.Common.Widgets
|
|||||||
return baseName + suffix;
|
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>(
|
return new CachedTransform<(bool, bool, bool, bool, bool), Sprite>(
|
||||||
((bool Disabled, bool Pressed, bool Hover, bool Focused) args) =>
|
((bool Disabled, bool Pressed, bool Hover, bool Focused, bool Highlighted) args) =>
|
||||||
{
|
{
|
||||||
var imageName = GetStatefulImageName(baseName, args.Disabled, args.Pressed, args.Hover, args.Focused);
|
var collectionName = collection + (args.Highlighted ? "-highlighted" : "");
|
||||||
return ChromeProvider.GetImage(collection, imageName) ?? ChromeProvider.GetImage(collection, baseName);
|
var variantImageName = GetStatefulImageName(imageName, args.Disabled, args.Pressed, args.Hover, args.Focused);
|
||||||
|
return ChromeProvider.GetImage(collectionName, variantImageName) ?? ChromeProvider.GetImage(collectionName, imageName);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -435,7 +435,7 @@ checkmark-tick:
|
|||||||
unchecked: 0, 0, 0, 0
|
unchecked: 0, 0, 0, 0
|
||||||
unchecked-pressed: 989, 17, 16, 16
|
unchecked-pressed: 989, 17, 16, 16
|
||||||
|
|
||||||
checkmark-highlighted-tick:
|
checkmark-tick-highlighted:
|
||||||
Inherits: checkmark-tick
|
Inherits: checkmark-tick
|
||||||
|
|
||||||
checkmark-cross:
|
checkmark-cross:
|
||||||
@@ -447,7 +447,7 @@ checkmark-cross:
|
|||||||
unchecked: 0, 0, 0, 0
|
unchecked: 0, 0, 0, 0
|
||||||
unchecked-pressed: 989, 0, 16, 16
|
unchecked-pressed: 989, 0, 16, 16
|
||||||
|
|
||||||
checkmark-highlighted-cross:
|
checkmark-cross-highlighted:
|
||||||
Inherits: checkmark-cross
|
Inherits: checkmark-cross
|
||||||
|
|
||||||
checkmark-mute:
|
checkmark-mute:
|
||||||
@@ -458,7 +458,7 @@ checkmark-mute:
|
|||||||
checked: 1006, 34, 16, 16
|
checked: 1006, 34, 16, 16
|
||||||
checked-pressed: 989, 34, 16, 16
|
checked-pressed: 989, 34, 16, 16
|
||||||
|
|
||||||
checkmark-highlighted-mute:
|
checkmark-mute-highlighted:
|
||||||
Inherits: checkmark-mute
|
Inherits: checkmark-mute
|
||||||
|
|
||||||
flags:
|
flags:
|
||||||
|
|||||||
@@ -381,7 +381,7 @@ checkmark-tick:
|
|||||||
unchecked: 0, 0, 0, 0
|
unchecked: 0, 0, 0, 0
|
||||||
unchecked-pressed: 204, 0, 16, 16
|
unchecked-pressed: 204, 0, 16, 16
|
||||||
|
|
||||||
checkmark-highlighted-tick:
|
checkmark-tick-highlighted:
|
||||||
Inherits: checkmark-tick
|
Inherits: checkmark-tick
|
||||||
|
|
||||||
checkmark-cross:
|
checkmark-cross:
|
||||||
@@ -392,7 +392,7 @@ checkmark-cross:
|
|||||||
unchecked: 0, 0, 0, 0
|
unchecked: 0, 0, 0, 0
|
||||||
unchecked-pressed: 238, 0, 16, 16
|
unchecked-pressed: 238, 0, 16, 16
|
||||||
|
|
||||||
checkmark-highlighted-cross:
|
checkmark-cross-highlighted:
|
||||||
Inherits: checkmark-cross
|
Inherits: checkmark-cross
|
||||||
|
|
||||||
checkmark-mute:
|
checkmark-mute:
|
||||||
@@ -403,7 +403,7 @@ checkmark-mute:
|
|||||||
checked: 238, 34, 16, 16
|
checked: 238, 34, 16, 16
|
||||||
checked-pressed: 221, 34, 16, 16
|
checked-pressed: 221, 34, 16, 16
|
||||||
|
|
||||||
checkmark-highlighted-mute:
|
checkmark-mute-highlighted:
|
||||||
Inherits: checkmark-mute
|
Inherits: checkmark-mute
|
||||||
|
|
||||||
checkbox-hover:
|
checkbox-hover:
|
||||||
|
|||||||
@@ -518,7 +518,7 @@ checkmark-tick:
|
|||||||
unchecked: 0, 0, 0, 0
|
unchecked: 0, 0, 0, 0
|
||||||
unchecked-pressed: 204, 0, 16, 16
|
unchecked-pressed: 204, 0, 16, 16
|
||||||
|
|
||||||
checkmark-highlighted-tick:
|
checkmark-tick-highlighted:
|
||||||
Inherits: checkmark-tick
|
Inherits: checkmark-tick
|
||||||
|
|
||||||
checkmark-cross:
|
checkmark-cross:
|
||||||
@@ -529,7 +529,7 @@ checkmark-cross:
|
|||||||
unchecked: 0, 0, 0, 0
|
unchecked: 0, 0, 0, 0
|
||||||
unchecked-pressed: 238, 0, 16, 16
|
unchecked-pressed: 238, 0, 16, 16
|
||||||
|
|
||||||
checkmark-highlighted-cross:
|
checkmark-cross-highlighted:
|
||||||
Inherits: checkmark-cross
|
Inherits: checkmark-cross
|
||||||
|
|
||||||
checkmark-mute:
|
checkmark-mute:
|
||||||
@@ -540,7 +540,7 @@ checkmark-mute:
|
|||||||
checked: 17, 170, 16, 16
|
checked: 17, 170, 16, 16
|
||||||
checked-pressed: 0, 170, 16, 16
|
checked-pressed: 0, 170, 16, 16
|
||||||
|
|
||||||
checkmark-highlighted-mute:
|
checkmark-mute-highlighted:
|
||||||
Inherits: checkmark-mute
|
Inherits: checkmark-mute
|
||||||
|
|
||||||
checkbox-hover:
|
checkbox-hover:
|
||||||
|
|||||||
@@ -643,7 +643,7 @@ checkmark-tick:
|
|||||||
unchecked: 0, 0, 0, 0
|
unchecked: 0, 0, 0, 0
|
||||||
unchecked-pressed: 204, 0, 16, 16
|
unchecked-pressed: 204, 0, 16, 16
|
||||||
|
|
||||||
checkmark-highlighted-tick:
|
checkmark-tick-highlighted:
|
||||||
Inherits: checkmark-tick
|
Inherits: checkmark-tick
|
||||||
|
|
||||||
checkmark-cross:
|
checkmark-cross:
|
||||||
@@ -654,7 +654,7 @@ checkmark-cross:
|
|||||||
unchecked: 0, 0, 0, 0
|
unchecked: 0, 0, 0, 0
|
||||||
unchecked-pressed: 238, 0, 16, 16
|
unchecked-pressed: 238, 0, 16, 16
|
||||||
|
|
||||||
checkmark-highlighted-cross:
|
checkmark-cross-highlighted:
|
||||||
Inherits: checkmark-cross
|
Inherits: checkmark-cross
|
||||||
|
|
||||||
checkmark-mute:
|
checkmark-mute:
|
||||||
@@ -665,7 +665,7 @@ checkmark-mute:
|
|||||||
checked: 238, 34, 16, 16
|
checked: 238, 34, 16, 16
|
||||||
checked-pressed: 221, 34, 16, 16
|
checked-pressed: 221, 34, 16, 16
|
||||||
|
|
||||||
checkmark-highlighted-mute:
|
checkmark-mute-highlighted:
|
||||||
Inherits: checkmark-mute
|
Inherits: checkmark-mute
|
||||||
|
|
||||||
checkbox-hover:
|
checkbox-hover:
|
||||||
|
|||||||
Reference in New Issue
Block a user