Unify all mods on the C&C order button logic.
This commit is contained in:
@@ -1,36 +0,0 @@
|
||||
#region Copyright & License Information
|
||||
/*
|
||||
* Copyright 2007-2011 The OpenRA Developers (see AUTHORS)
|
||||
* 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. For more information,
|
||||
* see COPYING.
|
||||
*/
|
||||
#endregion
|
||||
|
||||
using OpenRA.Widgets;
|
||||
|
||||
namespace OpenRA.Mods.Cnc.Widgets.Logic
|
||||
{
|
||||
public class ButtonTooltipLogic
|
||||
{
|
||||
[ObjectCreator.UseCtor]
|
||||
public ButtonTooltipLogic(Widget widget, ButtonWidget button)
|
||||
{
|
||||
var label = widget.Get<LabelWidget>("LABEL");
|
||||
var hotkey = widget.Get<LabelWidget>("HOTKEY");
|
||||
|
||||
label.GetText = () => button.TooltipText;
|
||||
var labelWidth = Game.Renderer.Fonts[label.Font].Measure(button.TooltipText).X;
|
||||
label.Bounds.Width = labelWidth;
|
||||
|
||||
var hotkeyLabel = "({0})".F(button.Key.DisplayString());
|
||||
hotkey.GetText = () => hotkeyLabel;
|
||||
hotkey.Bounds.X = labelWidth + 2 * label.Bounds.X;
|
||||
|
||||
var panelWidth = hotkey.Bounds.X + label.Bounds.X
|
||||
+ Game.Renderer.Fonts[label.Font].Measure(hotkeyLabel).X;
|
||||
widget.Bounds.Width = panelWidth;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -24,17 +24,6 @@ namespace OpenRA.Mods.Cnc.Widgets.Logic
|
||||
Widget ingameRoot;
|
||||
World world;
|
||||
|
||||
static void BindOrderButton<T>(World world, Widget parent, string button, string icon)
|
||||
where T : IOrderGenerator, new()
|
||||
{
|
||||
var w = parent.Get<ButtonWidget>(button);
|
||||
w.OnClick = () => world.ToggleInputMode<T>();
|
||||
w.IsHighlighted = () => world.OrderGenerator is T;
|
||||
|
||||
w.Get<ImageWidget>("ICON").GetImageName =
|
||||
() => world.OrderGenerator is T ? icon + "-active" : icon;
|
||||
}
|
||||
|
||||
[ObjectCreator.UseCtor]
|
||||
public CncIngameChromeLogic(Widget widget, World world)
|
||||
{
|
||||
@@ -87,13 +76,6 @@ namespace OpenRA.Mods.Cnc.Widgets.Logic
|
||||
playerWidgets.IsVisible = () => true;
|
||||
|
||||
var sidebarRoot = playerWidgets.Get("SIDEBAR_BACKGROUND");
|
||||
|
||||
BindOrderButton<SellOrderGenerator>(world, sidebarRoot, "SELL_BUTTON", "sell");
|
||||
BindOrderButton<RepairOrderGenerator>(world, sidebarRoot, "REPAIR_BUTTON", "repair");
|
||||
|
||||
sidebarRoot.Get<ButtonWidget>("SELL_BUTTON").Key = Game.Settings.Keys.SellKey;
|
||||
sidebarRoot.Get<ButtonWidget>("REPAIR_BUTTON").Key = Game.Settings.Keys.RepairKey;
|
||||
|
||||
var powerManager = world.LocalPlayer.PlayerActor.Trait<PowerManager>();
|
||||
var playerResources = world.LocalPlayer.PlayerActor.Trait<PlayerResources>();
|
||||
sidebarRoot.Get<LabelWidget>("CASH").GetText = () =>
|
||||
|
||||
Reference in New Issue
Block a user