diff --git a/OpenRA.Mods.Cnc/OpenRA.Mods.Cnc.csproj b/OpenRA.Mods.Cnc/OpenRA.Mods.Cnc.csproj index c62b2d062c..ff0533880f 100644 --- a/OpenRA.Mods.Cnc/OpenRA.Mods.Cnc.csproj +++ b/OpenRA.Mods.Cnc/OpenRA.Mods.Cnc.csproj @@ -84,7 +84,6 @@ - diff --git a/OpenRA.Mods.Cnc/Widgets/Logic/CncIngameChromeLogic.cs b/OpenRA.Mods.Cnc/Widgets/Logic/CncIngameChromeLogic.cs index d32ea18393..bf4946a9bb 100644 --- a/OpenRA.Mods.Cnc/Widgets/Logic/CncIngameChromeLogic.cs +++ b/OpenRA.Mods.Cnc/Widgets/Logic/CncIngameChromeLogic.cs @@ -24,17 +24,6 @@ namespace OpenRA.Mods.Cnc.Widgets.Logic Widget ingameRoot; World world; - static void BindOrderButton(World world, Widget parent, string button, string icon) - where T : IOrderGenerator, new() - { - var w = parent.Get(button); - w.OnClick = () => world.ToggleInputMode(); - w.IsHighlighted = () => world.OrderGenerator is T; - - w.Get("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(world, sidebarRoot, "SELL_BUTTON", "sell"); - BindOrderButton(world, sidebarRoot, "REPAIR_BUTTON", "repair"); - - sidebarRoot.Get("SELL_BUTTON").Key = Game.Settings.Keys.SellKey; - sidebarRoot.Get("REPAIR_BUTTON").Key = Game.Settings.Keys.RepairKey; - var powerManager = world.LocalPlayer.PlayerActor.Trait(); var playerResources = world.LocalPlayer.PlayerActor.Trait(); sidebarRoot.Get("CASH").GetText = () => diff --git a/OpenRA.Mods.RA/OpenRA.Mods.RA.csproj b/OpenRA.Mods.RA/OpenRA.Mods.RA.csproj index 454ae9097b..b8d440bbf6 100644 --- a/OpenRA.Mods.RA/OpenRA.Mods.RA.csproj +++ b/OpenRA.Mods.RA/OpenRA.Mods.RA.csproj @@ -406,7 +406,6 @@ - @@ -488,6 +487,7 @@ + diff --git a/OpenRA.Mods.Cnc/Widgets/Logic/ButtonTooltipLogic.cs b/OpenRA.Mods.RA/Widgets/Logic/ButtonTooltipLogic.cs similarity index 91% rename from OpenRA.Mods.Cnc/Widgets/Logic/ButtonTooltipLogic.cs rename to OpenRA.Mods.RA/Widgets/Logic/ButtonTooltipLogic.cs index 49277b0643..88cd4d794b 100644 --- a/OpenRA.Mods.Cnc/Widgets/Logic/ButtonTooltipLogic.cs +++ b/OpenRA.Mods.RA/Widgets/Logic/ButtonTooltipLogic.cs @@ -1,6 +1,6 @@ #region Copyright & License Information /* - * Copyright 2007-2011 The OpenRA Developers (see AUTHORS) + * Copyright 2007-2014 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, @@ -10,7 +10,7 @@ using OpenRA.Widgets; -namespace OpenRA.Mods.Cnc.Widgets.Logic +namespace OpenRA.Mods.RA.Widgets.Logic { public class ButtonTooltipLogic { diff --git a/OpenRA.Mods.RA/Widgets/Logic/IngameChromeLogic.cs b/OpenRA.Mods.RA/Widgets/Logic/IngameChromeLogic.cs index 96efb7ea5c..efd918068a 100644 --- a/OpenRA.Mods.RA/Widgets/Logic/IngameChromeLogic.cs +++ b/OpenRA.Mods.RA/Widgets/Logic/IngameChromeLogic.cs @@ -111,11 +111,6 @@ namespace OpenRA.Mods.RA.Widgets.Logic objectivesButton.OnClick += () => objectivesWidget.Visible ^= true; } - var moneyBin = playerWidgets.Get("INGAME_MONEY_BIN"); - moneyBin.Get("SELL").GetKey = _ => Game.Settings.Keys.SellKey; - moneyBin.Get("POWER_DOWN").GetKey = _ => Game.Settings.Keys.PowerDownKey; - moneyBin.Get("REPAIR").GetKey = _ => Game.Settings.Keys.RepairKey; - bool radarActive = false; RadarBinState binState = RadarBinState.Closed; var radarBin = playerWidgets.Get("INGAME_RADAR_BIN"); diff --git a/OpenRA.Mods.RA/Widgets/Logic/OrderButtonsChromeLogic.cs b/OpenRA.Mods.RA/Widgets/Logic/OrderButtonsChromeLogic.cs index d885fcb68d..a9793db2f3 100644 --- a/OpenRA.Mods.RA/Widgets/Logic/OrderButtonsChromeLogic.cs +++ b/OpenRA.Mods.RA/Widgets/Logic/OrderButtonsChromeLogic.cs @@ -16,32 +16,38 @@ namespace OpenRA.Mods.RA.Widgets.Logic public class OrderButtonsChromeLogic { [ObjectCreator.UseCtor] - public OrderButtonsChromeLogic(World world) + public OrderButtonsChromeLogic(Widget widget, World world) { - /* TODO: attach this to the correct widget, to remove the lookups below */ - var r = Ui.Root; - var gameRoot = r.Get("INGAME_ROOT"); + var sell = widget.GetOrNull("SELL_BUTTON"); + if (sell != null) + { + sell.GetKey = _ => Game.Settings.Keys.SellKey; + BindOrderButton(world, sell, "sell"); + } - var moneybin = gameRoot.Get("INGAME_MONEY_BIN"); - moneybin.IsVisible = () => { - return world.LocalPlayer.WinState == WinState.Undefined; - }; + var repair = widget.GetOrNull("REPAIR_BUTTON"); + if (repair != null) + { + repair.GetKey = _ => Game.Settings.Keys.RepairKey; + BindOrderButton(world, repair, "repair"); + } - BindOrderButton(world, moneybin, "SELL"); - BindOrderButton(world, moneybin, "POWER_DOWN"); - BindOrderButton(world, moneybin, "REPAIR"); + var power = widget.GetOrNull("POWER_BUTTON"); + if (power != null) + { + power.GetKey = _ => Game.Settings.Keys.PowerDownKey; + BindOrderButton(world, power, "power"); + } } - static void BindOrderButton(World world, Widget parent, string button) + static void BindOrderButton(World world, ButtonWidget w, string icon) where T : IOrderGenerator, new() { - var w = parent.GetOrNull(button); - if (w != null) - { - w.Pressed = () => world.OrderGenerator is T; - w.OnMouseDown = mi => world.ToggleInputMode(); - w.OnKeyPress = ki => world.ToggleInputMode(); - } + w.OnClick = () => world.ToggleInputMode(); + w.IsHighlighted = () => world.OrderGenerator is T; + + w.Get("ICON").GetImageName = + () => world.OrderGenerator is T ? icon + "-active" : icon; } } } diff --git a/OpenRA.Mods.RA/Widgets/OrderButtonWidget.cs b/OpenRA.Mods.RA/Widgets/OrderButtonWidget.cs deleted file mode 100755 index 5d6f7d0cd5..0000000000 --- a/OpenRA.Mods.RA/Widgets/OrderButtonWidget.cs +++ /dev/null @@ -1,78 +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 System; -using System.Drawing; -using OpenRA.Graphics; -using OpenRA.Widgets; - -namespace OpenRA.Mods.RA.Widgets -{ - public class OrderButtonWidget : ButtonWidget - { - public Func Enabled = () => true; - public Func Pressed = () => false; - - public string Image, Description, LongDesc = ""; - - public Func GetImage, GetDescription, GetLongDesc; - - public OrderButtonWidget() - { - GetImage = () => Enabled() ? Pressed() ? "pressed" : "normal" : "disabled"; - GetDescription = () => Key.IsValid() ? "{0} ({1})".F(Description, Key.DisplayString()) : Description; - GetLongDesc = () => LongDesc; - } - - public override void Draw() - { - var image = ChromeProvider.GetImage(Image + "-button", GetImage()); - var rect = new Rectangle(RenderBounds.X, RenderBounds.Y, (int)image.size.X, (int)image.size.Y); - - if (rect.Contains(Viewport.LastMousePos)) - { - rect = rect.InflateBy(3, 3, 3, 3); - var pos = new int2(rect.Left, rect.Top); - var m = pos + new int2(rect.Width, rect.Height); - var br = pos + new int2(rect.Width, rect.Height + 20); - - var u = Game.Renderer.Fonts["Regular"].Measure(GetLongDesc().Replace("\\n", "\n")); - - br.X -= u.X; - br.Y += u.Y; - br += new int2(-15, 25); - - var border = WidgetUtils.GetBorderSizes("dialog4"); - - WidgetUtils.DrawPanelPartial("dialog4", rect - .InflateBy(0, 0, 0, border[1]), - PanelSides.Top | PanelSides.Left | PanelSides.Right | PanelSides.Center); - - WidgetUtils.DrawPanelPartial("dialog4", new Rectangle(br.X, m.Y, pos.X - br.X, br.Y - m.Y) - .InflateBy(0, 0, border[3], 0), - PanelSides.Top | PanelSides.Left | PanelSides.Bottom | PanelSides.Center); - - WidgetUtils.DrawPanelPartial("dialog4", new Rectangle(pos.X, m.Y, m.X - pos.X, br.Y - m.Y) - .InflateBy(border[2], border[0], 0, 0), - PanelSides.Right | PanelSides.Bottom | PanelSides.Center); - - pos.X = br.X + 8; - pos.Y = m.Y + 8; - Game.Renderer.Fonts["Bold"].DrawText(GetDescription(), pos, Color.White); - - pos += new int2(0, 20); - Game.Renderer.Fonts["Regular"].DrawText(GetLongDesc().Replace("\\n", "\n"), pos, Color.White); - } - - Game.Renderer.RgbaSpriteRenderer.DrawSprite(image, new int2(RenderBounds.X, RenderBounds.Y)); - } - } -} - diff --git a/mods/cnc/chrome/ingame.yaml b/mods/cnc/chrome/ingame.yaml index c2d9ef3671..493b4d54b7 100644 --- a/mods/cnc/chrome/ingame.yaml +++ b/mods/cnc/chrome/ingame.yaml @@ -172,6 +172,7 @@ Container@PLAYER_WIDGETS: ReadyText:Ready HoldText:On Hold Background@SIDEBAR_BACKGROUND: + Logic:OrderButtonsChromeLogic X:WINDOW_RIGHT - 204 Y:30 Width:194 diff --git a/mods/d2k/chrome.yaml b/mods/d2k/chrome.yaml index ce814e20d1..d4b795e453 100644 --- a/mods/d2k/chrome.yaml +++ b/mods/d2k/chrome.yaml @@ -237,20 +237,16 @@ strategic: strategic.png enemy_owned: 32,32,32,32 player_owned: 96,0,32,32 -sell-button: buttons.png - normal: 0,0,34,28 - pressed: 34,0,34,28 - disabled: 68,0,34,28 - -repair-button: buttons.png - normal: 0,28,34,28 - pressed: 34,28,34,28 - disabled: 68,28,34,28 - -power-button: buttons.png - normal: 0,56,34,28 - pressed: 34,56,34,28 - disabled: 68,56,34,28 +order-icons: buttons.png + sell: 0,0,34,28 + sell-disabled: 68,0,34,28 + sell-active: 34,0,34,28 + repair: 0,28,34,28 + repair-disabled: 68,28,34,28 + repair-active: 34,28,34,28 + power: 0,56,34,28 + power-disabled: 68,56,34,28 + power-active: 34,56,34,28 music: musicplayer.png pause: 0,0,25,25 diff --git a/mods/d2k/chrome/ingame-player.yaml b/mods/d2k/chrome/ingame-player.yaml index 1de56a6f78..de7b8cf3dd 100644 --- a/mods/d2k/chrome/ingame-player.yaml +++ b/mods/d2k/chrome/ingame-player.yaml @@ -51,38 +51,41 @@ Container@PLAYER_WIDGETS: Orientation:Horizontal Style:Bevelled MoneyBin@INGAME_MONEY_BIN: + Logic:OrderButtonsChromeLogic X:WINDOW_RIGHT - WIDTH - Y:0 Width:320 Height: 32 Children: - OrderButton@SELL: - Logic:OrderButtonsChromeLogic + Button@SELL_BUTTON: X:3 - Y:0 - Width:30 - Height:30 - Image:sell - Description:Sell - LongDesc:Sell buildings, reclaiming a \nproportion of their build cost - OrderButton@POWER_DOWN: - Logic:OrderButtonsChromeLogic + Width:34 + Height:28 + TooltipText: Sell + TooltipContainer:TOOLTIP_CONTAINER + VisualHeight:0 + Children: + Image@ICON: + ImageCollection:order-icons + Button@POWER_BUTTON: X:39 - Y:0 - Width:30 - Height:30 - Image:power - Description:Powerdown - LongDesc:Disable unneeded structures so their \npower can be used elsewhere - OrderButton@REPAIR: - Logic:OrderButtonsChromeLogic + Width:34 + Height:28 + TooltipText: Power Down + TooltipContainer:TOOLTIP_CONTAINER + VisualHeight:0 + Children: + Image@ICON: + ImageCollection:order-icons + Button@REPAIR_BUTTON: X:75 - Y:0 - Width:30 - Height:30 - Image:repair - Description:Repair - LongDesc:Repair damaged buildings + Width:34 + Height:28 + TooltipText: Repair + TooltipContainer:TOOLTIP_CONTAINER + VisualHeight:0 + Children: + Image@ICON: + ImageCollection:order-icons SupportPowerBin@INGAME_POWERS_BIN: X:0 Y:25 diff --git a/mods/d2k/chrome/tooltips.yaml b/mods/d2k/chrome/tooltips.yaml index 7486ad1ed4..7fd7ed719b 100644 --- a/mods/d2k/chrome/tooltips.yaml +++ b/mods/d2k/chrome/tooltips.yaml @@ -9,6 +9,22 @@ Background@SIMPLE_TOOLTIP: Height:23 Font:Bold +Background@BUTTON_TOOLTIP: + Logic:ButtonTooltipLogic + Background:dialog3 + Height:31 + Children: + Label@LABEL: + X:5 + Y:3 + Height:23 + Font:Bold + Label@HOTKEY: + Y:3 + Height:23 + TextColor:255,255,0 + Font:Bold + Background@WORLD_TOOLTIP: Logic:WorldTooltipLogic Background:dialog3 diff --git a/mods/ra/chrome.yaml b/mods/ra/chrome.yaml index fed9f093d4..594cf24b85 100644 --- a/mods/ra/chrome.yaml +++ b/mods/ra/chrome.yaml @@ -181,20 +181,16 @@ strategic: strategic.png enemy_owned: 32,32,32,32 player_owned: 96,0,32,32 -sell-button: buttons.png - normal: 0,0,34,28 - pressed: 34,0,34,28 - disabled: 68,0,34,28 - -repair-button: buttons.png - normal: 0,28,34,28 - pressed: 34,28,34,28 - disabled: 68,28,34,28 - -power-button: buttons.png - normal: 0,56,34,28 - pressed: 34,56,34,28 - disabled: 68,56,34,28 +order-icons: buttons.png + sell: 0,0,34,28 + sell-disabled: 68,0,34,28 + sell-active: 34,0,34,28 + repair: 0,28,34,28 + repair-disabled: 68,28,34,28 + repair-active: 34,28,34,28 + power: 0,56,34,28 + power-disabled: 68,56,34,28 + power-active: 34,56,34,28 flags: buttons.png allies: 30,84,30,15 diff --git a/mods/ra/chrome/ingame-player.yaml b/mods/ra/chrome/ingame-player.yaml index e8619b72c3..efba0275fe 100644 --- a/mods/ra/chrome/ingame-player.yaml +++ b/mods/ra/chrome/ingame-player.yaml @@ -51,38 +51,41 @@ Container@PLAYER_WIDGETS: Orientation:Horizontal Style:Bevelled MoneyBin@INGAME_MONEY_BIN: + Logic:OrderButtonsChromeLogic X:WINDOW_RIGHT - WIDTH - Y:0 Width:320 - Height: 32 + Height:32 Children: - OrderButton@SELL: - Logic:OrderButtonsChromeLogic + Button@SELL_BUTTON: X:3 - Y:0 - Width:30 - Height:30 - Image:sell - Description:Sell - LongDesc:Sell buildings, reclaiming a \nproportion of their build cost - OrderButton@POWER_DOWN: - Logic:OrderButtonsChromeLogic + Width:34 + Height:28 + TooltipText: Sell + TooltipContainer:TOOLTIP_CONTAINER + VisualHeight:0 + Children: + Image@ICON: + ImageCollection:order-icons + Button@POWER_BUTTON: X:39 - Y:0 - Width:30 - Height:30 - Image:power - Description:Powerdown - LongDesc:Disable unneeded structures so their \npower can be used elsewhere - OrderButton@REPAIR: - Logic:OrderButtonsChromeLogic + Width:34 + Height:28 + TooltipText: Power Down + TooltipContainer:TOOLTIP_CONTAINER + VisualHeight:0 + Children: + Image@ICON: + ImageCollection:order-icons + Button@REPAIR_BUTTON: X:75 - Y:0 - Width:30 - Height:30 - Image:repair - Description:Repair - LongDesc:Repair damaged buildings + Width:34 + Height:28 + TooltipText: Repair + TooltipContainer:TOOLTIP_CONTAINER + VisualHeight:0 + Children: + Image@ICON: + ImageCollection:order-icons SupportPowerBin@INGAME_POWERS_BIN: X:0 Y:25 diff --git a/mods/ra/chrome/tooltips.yaml b/mods/ra/chrome/tooltips.yaml index 5fa419777d..41b44a53a2 100644 --- a/mods/ra/chrome/tooltips.yaml +++ b/mods/ra/chrome/tooltips.yaml @@ -9,6 +9,22 @@ Background@SIMPLE_TOOLTIP: Height:23 Font:Bold +Background@BUTTON_TOOLTIP: + Logic:ButtonTooltipLogic + Background:dialog4 + Height:29 + Children: + Label@LABEL: + X:7 + Y:2 + Height:23 + Font:Bold + Label@HOTKEY: + Y:2 + Height:23 + TextColor:255,255,0 + Font:Bold + Background@WORLD_TOOLTIP: Logic:WorldTooltipLogic Background:dialog4 diff --git a/mods/ts/chrome.yaml b/mods/ts/chrome.yaml index 163bbe615e..b2251e741b 100644 --- a/mods/ts/chrome.yaml +++ b/mods/ts/chrome.yaml @@ -175,20 +175,16 @@ strategic: strategic.png enemy_owned: 32,32,32,32 player_owned: 96,0,32,32 -sell-button: buttons.png - normal: 0,0,34,28 - pressed: 34,0,34,28 - disabled: 68,0,34,28 - -repair-button: buttons.png - normal: 0,28,34,28 - pressed: 34,28,34,28 - disabled: 68,28,34,28 - -power-button: buttons.png - normal: 0,56,34,28 - pressed: 34,56,34,28 - disabled: 68,56,34,28 +order-icons: buttons.png + sell: 0,0,34,28 + sell-disabled: 68,0,34,28 + sell-active: 34,0,34,28 + repair: 0,28,34,28 + repair-disabled: 68,28,34,28 + repair-active: 34,28,34,28 + power: 0,56,34,28 + power-disabled: 68,56,34,28 + power-active: 34,56,34,28 flags: buttons.png gdi: 30,84,30,15