Refactor ScrollItemWidget to use stateful image names

This commit is contained in:
Gustas
2022-08-23 16:40:47 +03:00
committed by Pavel Penev
parent 11a2e6e19b
commit 08dbfe0cbd
7 changed files with 65 additions and 24 deletions

View File

@@ -41,6 +41,18 @@ namespace OpenRA.Mods.Common.Widgets
});
}
// TODO: refactor buttons and related UI to use this function
public static CachedTransform<(bool Disabled, bool Pressed, bool Hover, bool Focused, bool Highlighted), Sprite[]> GetCachedStatefulPanelImages(string collection)
{
return new CachedTransform<(bool, bool, bool, bool, bool), Sprite[]>(
((bool Disabled, bool Pressed, bool Hover, bool Focused, bool Highlighted) args) =>
{
var collectionName = collection + (args.Highlighted ? "-highlighted" : "");
var variantCollectionName = GetStatefulImageName(collectionName, args.Disabled, args.Pressed, args.Hover, args.Focused);
return ChromeProvider.GetPanelImages(variantCollectionName) ?? ChromeProvider.GetPanelImages(collectionName);
});
}
public static void DrawSprite(Sprite s, float2 pos)
{
Game.Renderer.RgbaSpriteRenderer.DrawSprite(s, pos);