ProductionTabsWidget: allow specifying different panels for left/right scroll button and tab buttons.
This commit is contained in:
@@ -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<string> 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;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -105,6 +105,7 @@ namespace OpenRA.Mods.Common.UpdateRules
|
||||
new TextNotificationsDisplayWidgetRemoveTime(),
|
||||
new ExplicitSequenceFilenames(),
|
||||
new RenameEngineerRepair(),
|
||||
new ProductionTabsWidgetAddTabButtonCollection()
|
||||
})
|
||||
};
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -81,7 +81,9 @@ namespace OpenRA.Mods.Common.Widgets
|
||||
|
||||
public readonly Dictionary<string, ProductionTabGroup> 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);
|
||||
|
||||
Reference in New Issue
Block a user