From ca7e7c2304a9d9a90c24ff6f74d4632242f70c3e Mon Sep 17 00:00:00 2001 From: michaeldgg2 <119738087+michaeldgg2@users.noreply.github.com> Date: Wed, 25 Jan 2023 11:42:25 +0100 Subject: [PATCH] ProductionTabsWidget: allow specifying different panels for left/right scroll button and tab buttons. --- ...ductionTabsWidgetAddTabButtonCollection.cs | 43 +++++++++++++++++++ OpenRA.Mods.Common/UpdateRules/UpdatePath.cs | 1 + .../Logic/Ingame/AddFactionSuffixLogic.cs | 3 +- .../Widgets/ProductionTabsWidget.cs | 10 +++-- 4 files changed, 52 insertions(+), 5 deletions(-) create mode 100644 OpenRA.Mods.Common/UpdateRules/Rules/20221203/ProductionTabsWidgetAddTabButtonCollection.cs diff --git a/OpenRA.Mods.Common/UpdateRules/Rules/20221203/ProductionTabsWidgetAddTabButtonCollection.cs b/OpenRA.Mods.Common/UpdateRules/Rules/20221203/ProductionTabsWidgetAddTabButtonCollection.cs new file mode 100644 index 0000000000..d5fa294b5a --- /dev/null +++ b/OpenRA.Mods.Common/UpdateRules/Rules/20221203/ProductionTabsWidgetAddTabButtonCollection.cs @@ -0,0 +1,43 @@ +#region Copyright & License Information +/* + * Copyright (c) The OpenRA Developers and Contributors + * This file is part of OpenRA, which is free software. It is made + * available to you under the terms of the GNU General Public License + * as published by the Free Software Foundation, either version 3 of + * the License, or (at your option) any later version. For more + * information, see COPYING. + */ +#endregion + +using System.Collections.Generic; + +namespace OpenRA.Mods.Common.UpdateRules.Rules +{ + public class ProductionTabsWidgetAddTabButtonCollection : UpdateRule + { + public override string Name => "Change name of Button field of ProductionTabsWidget and add ArrowButton if necessary."; + + public override string Description => + "Change the field name from Button to TabButton and add ArrowButton, if Button field was set."; + + public override IEnumerable UpdateChromeNode(ModData modData, MiniYamlNode chromeNode) + { + if (!chromeNode.KeyMatches("ProductionTabs")) + yield break; + + string buttonCollection = null; + foreach (var field in chromeNode.ChildrenMatching("Button")) + { + field.RenameKey("TabButton"); + buttonCollection = field.Value.Value; + } + + if (buttonCollection != null) + { + chromeNode.AddNode(new MiniYamlNode("ArrowButton", buttonCollection)); + } + + yield break; + } + } +} diff --git a/OpenRA.Mods.Common/UpdateRules/UpdatePath.cs b/OpenRA.Mods.Common/UpdateRules/UpdatePath.cs index cf0cf24692..f7569a7eca 100644 --- a/OpenRA.Mods.Common/UpdateRules/UpdatePath.cs +++ b/OpenRA.Mods.Common/UpdateRules/UpdatePath.cs @@ -105,6 +105,7 @@ namespace OpenRA.Mods.Common.UpdateRules new TextNotificationsDisplayWidgetRemoveTime(), new ExplicitSequenceFilenames(), new RenameEngineerRepair(), + new ProductionTabsWidgetAddTabButtonCollection() }) }; diff --git a/OpenRA.Mods.Common/Widgets/Logic/Ingame/AddFactionSuffixLogic.cs b/OpenRA.Mods.Common/Widgets/Logic/Ingame/AddFactionSuffixLogic.cs index ba591635da..09384449ec 100644 --- a/OpenRA.Mods.Common/Widgets/Logic/Ingame/AddFactionSuffixLogic.cs +++ b/OpenRA.Mods.Common/Widgets/Logic/Ingame/AddFactionSuffixLogic.cs @@ -43,7 +43,8 @@ namespace OpenRA.Mods.Common.Widgets.Logic } else if (widget is ProductionTabsWidget ptw) { - ptw.Button += suffix; + ptw.ArrowButton += suffix; + ptw.TabButton += suffix; ptw.Background += suffix; } else diff --git a/OpenRA.Mods.Common/Widgets/ProductionTabsWidget.cs b/OpenRA.Mods.Common/Widgets/ProductionTabsWidget.cs index 93d03cc4cc..776568c447 100644 --- a/OpenRA.Mods.Common/Widgets/ProductionTabsWidget.cs +++ b/OpenRA.Mods.Common/Widgets/ProductionTabsWidget.cs @@ -81,7 +81,9 @@ namespace OpenRA.Mods.Common.Widgets public readonly Dictionary Groups; - public string Button = "button"; + public string ArrowButton = "button"; + public string TabButton = "button"; + public string Background = "panel-black"; public readonly string Decorations = "scrollpanel-decorations"; public readonly string DecorationScrollLeft = "left"; @@ -190,8 +192,8 @@ namespace OpenRA.Mods.Common.Widgets var rightHover = Ui.MouseOverWidget == this && rightButtonRect.Contains(Viewport.LastMousePos); WidgetUtils.DrawPanel(Background, rb); - ButtonWidget.DrawBackground(Button, leftButtonRect, leftDisabled, leftPressed, leftHover, false); - ButtonWidget.DrawBackground(Button, rightButtonRect, rightDisabled, rightPressed, rightHover, false); + ButtonWidget.DrawBackground(ArrowButton, leftButtonRect, leftDisabled, leftPressed, leftHover, false); + ButtonWidget.DrawBackground(ArrowButton, rightButtonRect, rightDisabled, rightPressed, rightHover, false); var leftArrowImage = getLeftArrowImage.Update((leftDisabled, leftPressed, leftHover, false, false)); WidgetUtils.DrawSprite(leftArrowImage, @@ -211,7 +213,7 @@ namespace OpenRA.Mods.Common.Widgets var rect = new Rectangle(origin.X + contentWidth, origin.Y, TabWidth, rb.Height); var hover = !leftHover && !rightHover && Ui.MouseOverWidget == this && rect.Contains(Viewport.LastMousePos); var highlighted = tab.Queue == CurrentQueue; - ButtonWidget.DrawBackground(Button, rect, false, false, hover, highlighted); + ButtonWidget.DrawBackground(TabButton, rect, false, false, hover, highlighted); contentWidth += TabWidth - 1; var textSize = font.Measure(tab.Name);