Add faction suffix support to text fields and scroll panels

This commit is contained in:
Ivaylo Draganov
2021-07-04 11:24:36 +03:00
committed by abcdefg30
parent 9687988976
commit cbdf6c3747
4 changed files with 73 additions and 3 deletions

View File

@@ -29,13 +29,22 @@ namespace OpenRA.Mods.Common.Widgets.Logic
iw.ImageCollection += suffix;
else if (widget is BackgroundWidget bgw)
bgw.Background += suffix;
else if (widget is TextFieldWidget tfw)
tfw.Background += suffix;
else if (widget is ScrollPanelWidget spw)
{
spw.Button += suffix;
spw.Background += suffix;
spw.ScrollBarBackground += suffix;
spw.Decorations += suffix;
}
else if (widget is ProductionTabsWidget ptw)
{
ptw.Button += suffix;
ptw.Background += suffix;
}
else
throw new InvalidOperationException("AddFactionSuffixLogic only supports ButtonWidget, ImageWidget, BackgroundWidget and ProductionTabsWidget");
throw new InvalidOperationException("AddFactionSuffixLogic only supports ButtonWidget, ImageWidget, BackgroundWidget, TextFieldWidget, ScrollPanelWidget and ProductionTabsWidget");
}
}
}

View File

@@ -48,7 +48,7 @@ namespace OpenRA.Mods.Common.Widgets
public string Background = "scrollpanel-bg";
public string ScrollBarBackground = "scrollpanel-bg";
public string Button = "scrollpanel-button";
public readonly string Decorations = "scrollpanel-decorations";
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;

View File

@@ -37,6 +37,7 @@ namespace OpenRA.Mods.Common.Widgets
public int VisualHeight = 1;
public int LeftMargin = 5;
public int RightMargin = 5;
public string Background = "textfield";
public bool Disabled = false;
@@ -561,7 +562,7 @@ namespace OpenRA.Mods.Common.Widgets
var disabled = IsDisabled();
var hover = Ui.MouseOverWidget == this || Children.Any(c => c == Ui.MouseOverWidget);
var state = WidgetUtils.GetStatefulImageName("textfield", disabled, false, hover, HasKeyboardFocus);
var state = WidgetUtils.GetStatefulImageName(Background, disabled, false, hover, HasKeyboardFocus);
WidgetUtils.DrawPanel(state,
new Rectangle(pos.X, pos.Y, Bounds.Width, Bounds.Height));