-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Remove unneeded chrome yaml declarations #18436
Remove unneeded chrome yaml declarations #18436
Conversation
The fallback behaviour requires additional lookups, so wouldn't it be better for performance to keep them? |
What about mods that don't need/have art for all states (as is the case for d2k and actually for all core mods)? We should then define all states or figure out a way to do that without a performance hit. |
Its not pretty, but maybe something like this would work? diff --git a/OpenRA.Mods.Common/Widgets/DropDownButtonWidget.cs b/OpenRA.Mods.Common/Widgets/DropDownButtonWidget.cs
index 8c104e2fab..f1805a3a7e 100644
--- a/OpenRA.Mods.Common/Widgets/DropDownButtonWidget.cs
+++ b/OpenRA.Mods.Common/Widgets/DropDownButtonWidget.cs
@@ -29,18 +29,29 @@ public class DropDownButtonWidget : ButtonWidget
Widget panel;
MaskWidget fullscreenMask;
Widget panelRoot;
+ readonly CachedTransform<(bool Disabled, bool Pressed, bool Hover), Sprite> getSeparatorImage;
public string PanelRoot;
public string SelectedItem;
+ Sprite GetSeperatorImageInner((bool Disabled, bool Pressed, bool Hover) args)
+ {
+ var separatorImageName = WidgetUtils.GetStatefulImageName(SeparatorImage, args.Disabled, args.Pressed, args.Hover);
+ return ChromeProvider.GetImage(Separators, separatorImageName) ?? ChromeProvider.GetImage(Separators, SeparatorImage);
+ }
+
[ObjectCreator.UseCtor]
public DropDownButtonWidget(ModData modData)
- : base(modData) { }
+ : base(modData)
+ {
+ getSeparatorImage = new CachedTransform<(bool, bool, bool), Sprite>(GetSeperatorImageInner);
+ }
protected DropDownButtonWidget(DropDownButtonWidget widget)
: base(widget)
{
PanelRoot = widget.PanelRoot;
+ getSeparatorImage = new CachedTransform<(bool, bool, bool), Sprite>(GetSeperatorImageInner);
}
public override void Draw()
@@ -57,9 +68,7 @@ public override void Draw()
WidgetUtils.DrawRGBA(arrowImage, stateOffset + new float2(rb.Right - (int)((rb.Height + arrowImage.Size.X) / 2), rb.Top + (int)((rb.Height - arrowImage.Size.Y) / 2)));
- var separatorImageName = WidgetUtils.GetStatefulImageName(SeparatorImage, isDisabled, Depressed, isHover);
- var separatorImage = ChromeProvider.GetImage(Separators, separatorImageName) ?? ChromeProvider.GetImage(Separators, SeparatorImage);
-
+ var separatorImage = getSeparatorImage.Update((isDisabled, Depressed, isHover));
if (separatorImage != null)
WidgetUtils.DrawRGBA(separatorImage, stateOffset + new float2(-3, 0) + new float2(rb.Right - rb.Height + 4, rb.Top + (int)((rb.Height - separatorImage.Size.Y) / 2)));
} On the other hand, I may be splitting hairs over something that has a completely negligible perf impact, meaning that the extra code uglyness would outweigh any theoretical gains. |
|
@pchote Should this optimization be applied to all image queries that use the same pattern? |
I'm not sure off the top of my head: probably, but maybe not worthwhile if this means a significant number of changes. |
What is the status here? |
No updates. We could take this PR as-is and take care of the code optimizations in a follow-up. Or close this PR as it doesn't have a lot of value and deal with everything in another PR. |
An oversight from #17663
These declarations are not needed because dropdowns and scrollbars fall back to the base name if there is no image defined for a given state and the state sprites in these cases are the same as the base.