From 21833f34b098d8a7d0c2bb0a63720a1b73d467bb Mon Sep 17 00:00:00 2001 From: Paul Chote Date: Mon, 8 Apr 2013 21:45:22 +1200 Subject: [PATCH 1/5] Remove leftovers from moving cheats into options menu. --- OpenRA.Mods.Cnc/Widgets/Logic/CncIngameChromeLogic.cs | 9 --------- 1 file changed, 9 deletions(-) diff --git a/OpenRA.Mods.Cnc/Widgets/Logic/CncIngameChromeLogic.cs b/OpenRA.Mods.Cnc/Widgets/Logic/CncIngameChromeLogic.cs index 8d9d3f26b4..2582274ac6 100644 --- a/OpenRA.Mods.Cnc/Widgets/Logic/CncIngameChromeLogic.cs +++ b/OpenRA.Mods.Cnc/Widgets/Logic/CncIngameChromeLogic.cs @@ -19,9 +19,6 @@ namespace OpenRA.Mods.Cnc.Widgets.Logic { public class CncIngameChromeLogic { - enum MenuType { None, Cheats } - MenuType menu = MenuType.None; - Widget ingameRoot; ProductionTabsWidget queueTabs; World world; @@ -87,12 +84,6 @@ namespace OpenRA.Mods.Cnc.Widgets.Logic { var cachedPause = world.Paused; - if (menu != MenuType.None) - { - Ui.CloseWindow(); - menu = MenuType.None; - } - ingameRoot.IsVisible = () => false; if (world.LobbyInfo.IsSinglePlayer) world.IssueOrder(Order.PauseGame(true)); From 71999bdc520e00b1f7881d562a01d239dfef6950 Mon Sep 17 00:00:00 2001 From: Paul Chote Date: Mon, 8 Apr 2013 22:30:14 +1200 Subject: [PATCH 2/5] Break production tabs logic into a separate file. Also unhardcodes the production types. --- OpenRA.Mods.Cnc/OpenRA.Mods.Cnc.csproj | 2 + .../Widgets/Logic/CncIngameChromeLogic.cs | 38 ---------- .../Widgets/Logic/ProductionTabsLogic.cs | 70 +++++++++++++++++++ .../Widgets/ProductionTabsWidget.cs | 2 + .../Widgets/ProductionTypeButtonWidget.cs | 29 ++++++++ mods/cnc/chrome/ingame.yaml | 17 +++-- 6 files changed, 115 insertions(+), 43 deletions(-) create mode 100644 OpenRA.Mods.Cnc/Widgets/Logic/ProductionTabsLogic.cs create mode 100644 OpenRA.Mods.Cnc/Widgets/ProductionTypeButtonWidget.cs diff --git a/OpenRA.Mods.Cnc/OpenRA.Mods.Cnc.csproj b/OpenRA.Mods.Cnc/OpenRA.Mods.Cnc.csproj index 687c921db7..c3db98869f 100644 --- a/OpenRA.Mods.Cnc/OpenRA.Mods.Cnc.csproj +++ b/OpenRA.Mods.Cnc/OpenRA.Mods.Cnc.csproj @@ -115,6 +115,8 @@ + + diff --git a/OpenRA.Mods.Cnc/Widgets/Logic/CncIngameChromeLogic.cs b/OpenRA.Mods.Cnc/Widgets/Logic/CncIngameChromeLogic.cs index 2582274ac6..dd2609c3b7 100644 --- a/OpenRA.Mods.Cnc/Widgets/Logic/CncIngameChromeLogic.cs +++ b/OpenRA.Mods.Cnc/Widgets/Logic/CncIngameChromeLogic.cs @@ -20,7 +20,6 @@ namespace OpenRA.Mods.Cnc.Widgets.Logic public class CncIngameChromeLogic { Widget ingameRoot; - ProductionTabsWidget queueTabs; World world; void AddChatLine(Color c, string from, string text) @@ -32,32 +31,6 @@ namespace OpenRA.Mods.Cnc.Widgets.Logic { Game.AddChatLine -= AddChatLine; Game.BeforeGameStart -= UnregisterEvents; - - if (queueTabs != null) - { - world.ActorAdded += queueTabs.ActorChanged; - world.ActorRemoved += queueTabs.ActorChanged; - } - } - - void SetupProductionGroupButton(ToggleButtonWidget button, string group) - { - Action selectTab = reverse => - { - if (queueTabs.QueueGroup == group) - queueTabs.SelectNextTab(reverse); - else - queueTabs.QueueGroup = group; - }; - - button.IsDisabled = () => queueTabs.Groups[group].Tabs.Count == 0; - button.OnMouseUp = mi => selectTab(mi.Modifiers.HasModifier(Modifiers.Shift)); - button.OnKeyPress = e => selectTab(e.Modifiers.HasModifier(Modifiers.Shift)); - button.IsToggled = () => queueTabs.QueueGroup == group; - var chromeName = group.ToLowerInvariant(); - var icon = button.Get("ICON"); - icon.GetImageName = () => button.IsDisabled() ? chromeName+"-disabled" : - queueTabs.Groups[group].Alert ? chromeName+"-alert" : chromeName; } [ObjectCreator.UseCtor] @@ -125,17 +98,6 @@ namespace OpenRA.Mods.Cnc.Widgets.Logic sidebarRoot.Get("CASH").GetText = () => "${0}".F(playerResources.DisplayCash + playerResources.DisplayOre); - queueTabs = playerWidgets.Get("PRODUCTION_TABS"); - world.ActorAdded += queueTabs.ActorChanged; - world.ActorRemoved += queueTabs.ActorChanged; - - var queueTypes = sidebarRoot.Get("PRODUCTION_TYPES"); - SetupProductionGroupButton(queueTypes.Get("BUILDING"), "Building"); - SetupProductionGroupButton(queueTypes.Get("DEFENSE"), "Defense"); - SetupProductionGroupButton(queueTypes.Get("INFANTRY"), "Infantry"); - SetupProductionGroupButton(queueTypes.Get("VEHICLE"), "Vehicle"); - SetupProductionGroupButton(queueTypes.Get("AIRCRAFT"), "Aircraft"); - playerWidgets.Get("OPTIONS_BUTTON").OnClick = OptionsClicked; var winLossWatcher = playerWidgets.Get("WIN_LOSS_WATCHER"); diff --git a/OpenRA.Mods.Cnc/Widgets/Logic/ProductionTabsLogic.cs b/OpenRA.Mods.Cnc/Widgets/Logic/ProductionTabsLogic.cs new file mode 100644 index 0000000000..09bab8b0ce --- /dev/null +++ b/OpenRA.Mods.Cnc/Widgets/Logic/ProductionTabsLogic.cs @@ -0,0 +1,70 @@ +#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.Mods.RA.Orders; +using OpenRA.Mods.RA.Buildings; +using OpenRA.Traits; +using OpenRA.Widgets; + +namespace OpenRA.Mods.Cnc.Widgets.Logic +{ + public class ProductionTabsLogic + { + ProductionTabsWidget tabs; + World world; + + void SetupProductionGroupButton(ProductionTypeButtonWidget button) + { + if (button == null) + return; + + Action selectTab = reverse => + { + if (tabs.QueueGroup == button.ProductionGroup) + tabs.SelectNextTab(reverse); + else + tabs.QueueGroup = button.ProductionGroup; + }; + + button.IsDisabled = () => tabs.Groups[button.ProductionGroup].Tabs.Count == 0; + button.OnMouseUp = mi => selectTab(mi.Modifiers.HasModifier(Modifiers.Shift)); + button.OnKeyPress = e => selectTab(e.Modifiers.HasModifier(Modifiers.Shift)); + button.IsToggled = () => tabs.QueueGroup == button.ProductionGroup; + + var chromeName = button.ProductionGroup.ToLowerInvariant(); + var icon = button.Get("ICON"); + icon.GetImageName = () => button.IsDisabled() ? chromeName+"-disabled" : + tabs.Groups[button.ProductionGroup].Alert ? chromeName+"-alert" : chromeName; + } + + [ObjectCreator.UseCtor] + public ProductionTabsLogic(Widget widget, World world) + { + this.world = world; + tabs = widget.Get("PRODUCTION_TABS"); + world.ActorAdded += tabs.ActorChanged; + world.ActorRemoved += tabs.ActorChanged; + Game.BeforeGameStart += UnregisterEvents; + + var typesContainer = Ui.Root.Get(tabs.TypesContainer); + foreach (var i in typesContainer.Children) + SetupProductionGroupButton(i as ProductionTypeButtonWidget); + } + + void UnregisterEvents() + { + Game.BeforeGameStart -= UnregisterEvents; + world.ActorAdded -= tabs.ActorChanged; + world.ActorRemoved -= tabs.ActorChanged; + } + } +} diff --git a/OpenRA.Mods.Cnc/Widgets/ProductionTabsWidget.cs b/OpenRA.Mods.Cnc/Widgets/ProductionTabsWidget.cs index deda1ea1b8..c584d2cfa8 100755 --- a/OpenRA.Mods.Cnc/Widgets/ProductionTabsWidget.cs +++ b/OpenRA.Mods.Cnc/Widgets/ProductionTabsWidget.cs @@ -61,6 +61,8 @@ namespace OpenRA.Mods.Cnc.Widgets class ProductionTabsWidget : Widget { public readonly string PaletteWidget = null; + public readonly string TypesContainer = null; + public readonly float ScrollVelocity = 4f; public readonly int TabWidth = 30; public readonly int ArrowWidth = 20; diff --git a/OpenRA.Mods.Cnc/Widgets/ProductionTypeButtonWidget.cs b/OpenRA.Mods.Cnc/Widgets/ProductionTypeButtonWidget.cs new file mode 100644 index 0000000000..f521509f97 --- /dev/null +++ b/OpenRA.Mods.Cnc/Widgets/ProductionTypeButtonWidget.cs @@ -0,0 +1,29 @@ +#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.FileFormats; +using OpenRA.Widgets; + +namespace OpenRA.Mods.Cnc.Widgets +{ + public class ProductionTypeButtonWidget : ToggleButtonWidget + { + public readonly string ProductionGroup; + + public ProductionTypeButtonWidget() : base() {} + protected ProductionTypeButtonWidget(ProductionTypeButtonWidget other) + : base(other) + { + ProductionGroup = other.ProductionGroup; + } + } +} diff --git a/mods/cnc/chrome/ingame.yaml b/mods/cnc/chrome/ingame.yaml index c1e935cfe6..1e864cb18c 100644 --- a/mods/cnc/chrome/ingame.yaml +++ b/mods/cnc/chrome/ingame.yaml @@ -190,67 +190,74 @@ Container@PLAYER_WIDGETS: Width:170 Height:30 Children: - ToggleButton@BUILDING: + ProductionTypeButton@BUILDING: Width:30 Height:30 Key: q TooltipText: Buildings TooltipContainer:TOOLTIP_CONTAINER + ProductionGroup:Building Children: Image@ICON: X:7 Y:7 ImageCollection:production-icons - ToggleButton@DEFENSE: + ProductionTypeButton@DEFENSE: X:35 Width:30 Height:30 Key: w TooltipText: Defense TooltipContainer:TOOLTIP_CONTAINER + ProductionGroup:Defense Children: Image@ICON: X:7 Y:7 ImageCollection:production-icons - ToggleButton@INFANTRY: + ProductionTypeButton@INFANTRY: X:70 Width:30 Height:30 Key: e TooltipText: Infantry TooltipContainer:TOOLTIP_CONTAINER + ProductionGroup:Infantry Children: Image@ICON: X:7 Y:7 ImageCollection:production-icons - ToggleButton@VEHICLE: + ProductionTypeButton@VEHICLE: X:105 Width:30 Height:30 Key: r TooltipText: Vehicles TooltipContainer:TOOLTIP_CONTAINER + ProductionGroup:Vehicle Children: Image@ICON: X:7 Y:7 ImageCollection:production-icons - ToggleButton@AIRCRAFT: + ProductionTypeButton@AIRCRAFT: X:140 Width:30 Height:30 Key: t TooltipText: Aircraft TooltipContainer:TOOLTIP_CONTAINER + ProductionGroup:Aircraft Children: Image@ICON: X:7 Y:7 ImageCollection:production-icons ProductionTabs@PRODUCTION_TABS: + Logic:ProductionTabsLogic PaletteWidget:PRODUCTION_PALETTE + TypesContainer:PRODUCTION_TYPES X:WINDOW_RIGHT - 204 Y:268 Width:194 From eddc1fc0cfbf20aeb68904ee9cab9f6fb9953f70 Mon Sep 17 00:00:00 2001 From: Paul Chote Date: Mon, 8 Apr 2013 22:55:01 +1200 Subject: [PATCH 3/5] Remove duplication between ButtonWidget and ToggleButtonWidget. --- OpenRA.Game/Widgets/ButtonWidget.cs | 5 ++--- OpenRA.Mods.Cnc/Widgets/Logic/CncIngameChromeLogic.cs | 2 +- OpenRA.Mods.Cnc/Widgets/Logic/ProductionTabsLogic.cs | 2 +- OpenRA.Mods.Cnc/Widgets/ProductionTabsWidget.cs | 2 +- OpenRA.Mods.Cnc/Widgets/ToggleButtonWidget.cs | 7 ------- mods/cnc-classic/chrome.yaml | 6 +++--- mods/cnc/chrome.yaml | 8 ++++---- mods/ra/chrome.yaml | 6 +++--- 8 files changed, 15 insertions(+), 23 deletions(-) diff --git a/OpenRA.Game/Widgets/ButtonWidget.cs b/OpenRA.Game/Widgets/ButtonWidget.cs index 3dbb483533..41bfa1870e 100644 --- a/OpenRA.Game/Widgets/ButtonWidget.cs +++ b/OpenRA.Game/Widgets/ButtonWidget.cs @@ -166,14 +166,13 @@ namespace OpenRA.Widgets public static void DrawBackground(string baseName, Rectangle rect, bool disabled, bool pressed, bool hover, bool highlighted) { + var variant = highlighted ? "-highlighted" : ""; var state = disabled ? "-disabled" : pressed ? "-pressed" : hover ? "-hover" : ""; - if (highlighted) - state += "-highlighted"; - WidgetUtils.DrawPanel(baseName + state, rect); + WidgetUtils.DrawPanel(baseName + variant + state, rect); } } } diff --git a/OpenRA.Mods.Cnc/Widgets/Logic/CncIngameChromeLogic.cs b/OpenRA.Mods.Cnc/Widgets/Logic/CncIngameChromeLogic.cs index dd2609c3b7..c8dde9418b 100644 --- a/OpenRA.Mods.Cnc/Widgets/Logic/CncIngameChromeLogic.cs +++ b/OpenRA.Mods.Cnc/Widgets/Logic/CncIngameChromeLogic.cs @@ -141,7 +141,7 @@ namespace OpenRA.Mods.Cnc.Widgets.Logic { var w = parent.Get(button); w.OnClick = () => world.ToggleInputMode(); - w.IsToggled = () => world.OrderGenerator is T; + w.IsHighlighted = () => world.OrderGenerator is T; w.Get("ICON").GetImageName = () => world.OrderGenerator is T ? icon+"-active" : icon; diff --git a/OpenRA.Mods.Cnc/Widgets/Logic/ProductionTabsLogic.cs b/OpenRA.Mods.Cnc/Widgets/Logic/ProductionTabsLogic.cs index 09bab8b0ce..aeb8f48df0 100644 --- a/OpenRA.Mods.Cnc/Widgets/Logic/ProductionTabsLogic.cs +++ b/OpenRA.Mods.Cnc/Widgets/Logic/ProductionTabsLogic.cs @@ -38,7 +38,7 @@ namespace OpenRA.Mods.Cnc.Widgets.Logic button.IsDisabled = () => tabs.Groups[button.ProductionGroup].Tabs.Count == 0; button.OnMouseUp = mi => selectTab(mi.Modifiers.HasModifier(Modifiers.Shift)); button.OnKeyPress = e => selectTab(e.Modifiers.HasModifier(Modifiers.Shift)); - button.IsToggled = () => tabs.QueueGroup == button.ProductionGroup; + button.IsHighlighted = () => tabs.QueueGroup == button.ProductionGroup; var chromeName = button.ProductionGroup.ToLowerInvariant(); var icon = button.Get("ICON"); diff --git a/OpenRA.Mods.Cnc/Widgets/ProductionTabsWidget.cs b/OpenRA.Mods.Cnc/Widgets/ProductionTabsWidget.cs index c584d2cfa8..d83f3bd5b7 100755 --- a/OpenRA.Mods.Cnc/Widgets/ProductionTabsWidget.cs +++ b/OpenRA.Mods.Cnc/Widgets/ProductionTabsWidget.cs @@ -158,7 +158,7 @@ namespace OpenRA.Mods.Cnc.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 baseName = tab.Queue == CurrentQueue ? "button-toggled" : "button"; + var baseName = tab.Queue == CurrentQueue ? "button-highlighted" : "button"; ButtonWidget.DrawBackground(baseName, rect, false, false, hover, false); ContentWidth += TabWidth - 1; diff --git a/OpenRA.Mods.Cnc/Widgets/ToggleButtonWidget.cs b/OpenRA.Mods.Cnc/Widgets/ToggleButtonWidget.cs index a55a807814..662aef4c30 100644 --- a/OpenRA.Mods.Cnc/Widgets/ToggleButtonWidget.cs +++ b/OpenRA.Mods.Cnc/Widgets/ToggleButtonWidget.cs @@ -20,7 +20,6 @@ namespace OpenRA.Mods.Cnc.Widgets public readonly string TooltipTemplate = "BUTTON_TOOLTIP"; public readonly string TooltipText; public readonly string TooltipContainer; - public Func IsToggled = () => false; Lazy tooltipContainer; public ToggleButtonWidget() @@ -52,11 +51,5 @@ namespace OpenRA.Mods.Cnc.Widgets if (TooltipContainer == null) return; tooltipContainer.Value.RemoveTooltip(); } - - public override void DrawBackground(Rectangle rect, bool disabled, bool pressed, bool hover, bool highlighted) - { - var baseName = IsToggled() ? "button-toggled" : "button"; - ButtonWidget.DrawBackground(baseName, rect, disabled, pressed, hover, highlighted); - } } } diff --git a/mods/cnc-classic/chrome.yaml b/mods/cnc-classic/chrome.yaml index 5f7630db6c..fa99b6009b 100644 --- a/mods/cnc-classic/chrome.yaml +++ b/mods/cnc-classic/chrome.yaml @@ -272,7 +272,7 @@ button-hover: dialog.png corner-bl: 512,82,1,1 corner-br: 594,82,1,1 -button-hover-highlighted: dialog.png +button-highlighted-hover: dialog.png background: 513,145,126,126 border-r: 639,145,1,126 border-l: 512,145,1,126 @@ -295,7 +295,7 @@ button-disabled: dialog.png corner-bl: 512,82,1,1 corner-br: 594,82,1,1 -button-disabled-highlighted: dialog.png +button-highlighted-disabled: dialog.png background: 513,145,126,126 border-r: 639,145,1,126 border-l: 512,145,1,126 @@ -318,7 +318,7 @@ button-pressed: dialog.png corner-bl: 640,82,1,1 corner-br: 722,82,1,1 -button-pressed-highlighted: dialog.png +button-highlighted-pressed: dialog.png background: 641,145,126,126 border-r: 767,145,1,126 border-l: 640,145,1,126 diff --git a/mods/cnc/chrome.yaml b/mods/cnc/chrome.yaml index a75519177f..0e0821f783 100644 --- a/mods/cnc/chrome.yaml +++ b/mods/cnc/chrome.yaml @@ -54,7 +54,7 @@ button-pressed: chrome.png corner-bl: 64,254,2,2 corner-br: 126,254,2,2 -button-toggled: chrome.png +button-highlighted: chrome.png background: 257,129,30,30 border-r: 287,129,1,30 border-l: 256,129,1,30 @@ -65,7 +65,7 @@ button-toggled: chrome.png corner-bl: 256,159,1,1 corner-br: 287,159,1,1 -button-toggled-hover: chrome.png +button-highlighted-hover: chrome.png background: 289,129,30,30 border-r: 319,129,1,30 border-l: 288,129,1,30 @@ -76,7 +76,7 @@ button-toggled-hover: chrome.png corner-bl: 288,159,1,1 corner-br: 319,159,1,1 -button-toggled-pressed: chrome.png +button-highlighted-pressed: chrome.png background: 257,161,30,30 border-r: 287,161,1,30 border-l: 256,161,1,30 @@ -87,7 +87,7 @@ button-toggled-pressed: chrome.png corner-bl: 256,191,1,1 corner-br: 287,191,1,1 -button-toggled-disabled: chrome.png +button-highlighted-disabled: chrome.png background: 289,161,30,30 border-r: 319,161,1,30 border-l: 288,161,1,30 diff --git a/mods/ra/chrome.yaml b/mods/ra/chrome.yaml index cabb02a44f..56dc9f0ea0 100644 --- a/mods/ra/chrome.yaml +++ b/mods/ra/chrome.yaml @@ -272,7 +272,7 @@ button-hover: dialog.png corner-bl: 512,82,1,1 corner-br: 594,82,1,1 -button-hover-highlighted: dialog.png +button-highlighted-hover: dialog.png background: 513,145,126,126 border-r: 639,145,1,126 border-l: 512,145,1,126 @@ -295,7 +295,7 @@ button-disabled: dialog.png corner-bl: 512,82,1,1 corner-br: 594,82,1,1 -button-disabled-highlighted: dialog.png +button-highlighted-disabled: dialog.png background: 513,145,126,126 border-r: 639,145,1,126 border-l: 512,145,1,126 @@ -318,7 +318,7 @@ button-pressed: dialog.png corner-bl: 640,82,1,1 corner-br: 722,82,1,1 -button-pressed-highlighted: dialog.png +button-highlighted-pressed: dialog.png background: 641,145,126,126 border-r: 767,145,1,126 border-l: 640,145,1,126 From f368556b2390def12c9a0dc3da65eddebf0f4891 Mon Sep 17 00:00:00 2001 From: Paul Chote Date: Mon, 8 Apr 2013 23:01:21 +1200 Subject: [PATCH 4/5] Merge tooltip support into Button and remove ToggleButton. --- OpenRA.Game/Widgets/ButtonWidget.cs | 51 +++++++++++++---- OpenRA.Mods.Cnc/OpenRA.Mods.Cnc.csproj | 1 - .../Widgets/Logic/ButtonTooltipLogic.cs | 2 +- .../Widgets/Logic/CncIngameChromeLogic.cs | 6 +- .../Widgets/ProductionTypeButtonWidget.cs | 2 +- OpenRA.Mods.Cnc/Widgets/ToggleButtonWidget.cs | 55 ------------------- mods/cnc/chrome/ingame.yaml | 8 +-- 7 files changed, 48 insertions(+), 77 deletions(-) delete mode 100644 OpenRA.Mods.Cnc/Widgets/ToggleButtonWidget.cs diff --git a/OpenRA.Game/Widgets/ButtonWidget.cs b/OpenRA.Game/Widgets/ButtonWidget.cs index 41bfa1870e..0773bc8534 100644 --- a/OpenRA.Game/Widgets/ButtonWidget.cs +++ b/OpenRA.Game/Widgets/ButtonWidget.cs @@ -11,6 +11,7 @@ using System; using System.Collections.Generic; using System.Drawing; +using OpenRA.FileFormats; using OpenRA.Graphics; namespace OpenRA.Widgets @@ -36,6 +37,11 @@ namespace OpenRA.Widgets public Action OnMouseDown = _ => {}; public Action OnMouseUp = _ => {}; + public readonly string TooltipTemplate = "BUTTON_TOOLTIP"; + public readonly string TooltipText; + public readonly string TooltipContainer; + Lazy tooltipContainer; + // Equivalent to OnMouseUp, but without an input arg public Action OnClick = () => {}; public Action OnDoubleClick = () => {}; @@ -49,24 +55,32 @@ namespace OpenRA.Widgets OnKeyPress = _ => OnClick(); IsDisabled = () => Disabled; IsHighlighted = () => Highlighted; + tooltipContainer = Lazy.New(() => + Ui.Root.Get(TooltipContainer)); } - protected ButtonWidget(ButtonWidget widget) - : base(widget) + protected ButtonWidget(ButtonWidget other) + : base(other) { - Text = widget.Text; - Font = widget.Font; - Depressed = widget.Depressed; - VisualHeight = widget.VisualHeight; - GetText = widget.GetText; - OnMouseDown = widget.OnMouseDown; - Disabled = widget.Disabled; - IsDisabled = widget.IsDisabled; - Highlighted = widget.Highlighted; - IsHighlighted = widget.IsHighlighted; + Text = other.Text; + Font = other.Font; + Depressed = other.Depressed; + VisualHeight = other.VisualHeight; + GetText = other.GetText; + OnMouseDown = other.OnMouseDown; + Disabled = other.Disabled; + IsDisabled = other.IsDisabled; + Highlighted = other.Highlighted; + IsHighlighted = other.IsHighlighted; OnMouseUp = mi => OnClick(); OnKeyPress = _ => OnClick(); + + TooltipTemplate = other.TooltipTemplate; + TooltipText = other.TooltipText; + TooltipContainer = other.TooltipContainer; + tooltipContainer = Lazy.New(() => + Ui.Root.Get(TooltipContainer)); } public override bool LoseFocus(MouseInput mi) @@ -137,6 +151,19 @@ namespace OpenRA.Widgets return Depressed; } + public override void MouseEntered() + { + if (TooltipContainer == null) return; + tooltipContainer.Value.SetTooltip(TooltipTemplate, + new WidgetArgs() {{ "button", this }}); + } + + public override void MouseExited() + { + if (TooltipContainer == null) return; + tooltipContainer.Value.RemoveTooltip(); + } + public override int2 ChildOrigin { get { return RenderOrigin + ((Depressed) ? new int2(VisualHeight, VisualHeight) : new int2(0, 0)); } } diff --git a/OpenRA.Mods.Cnc/OpenRA.Mods.Cnc.csproj b/OpenRA.Mods.Cnc/OpenRA.Mods.Cnc.csproj index c3db98869f..c7d8551f80 100644 --- a/OpenRA.Mods.Cnc/OpenRA.Mods.Cnc.csproj +++ b/OpenRA.Mods.Cnc/OpenRA.Mods.Cnc.csproj @@ -110,7 +110,6 @@ - diff --git a/OpenRA.Mods.Cnc/Widgets/Logic/ButtonTooltipLogic.cs b/OpenRA.Mods.Cnc/Widgets/Logic/ButtonTooltipLogic.cs index d9e6efd096..32d9a57cda 100644 --- a/OpenRA.Mods.Cnc/Widgets/Logic/ButtonTooltipLogic.cs +++ b/OpenRA.Mods.Cnc/Widgets/Logic/ButtonTooltipLogic.cs @@ -15,7 +15,7 @@ namespace OpenRA.Mods.Cnc.Widgets.Logic public class ButtonTooltipLogic { [ObjectCreator.UseCtor] - public ButtonTooltipLogic(Widget widget, ToggleButtonWidget button) + public ButtonTooltipLogic(Widget widget, ButtonWidget button) { var label = widget.Get("LABEL"); var hotkey = widget.Get("HOTKEY"); diff --git a/OpenRA.Mods.Cnc/Widgets/Logic/CncIngameChromeLogic.cs b/OpenRA.Mods.Cnc/Widgets/Logic/CncIngameChromeLogic.cs index c8dde9418b..316e660252 100644 --- a/OpenRA.Mods.Cnc/Widgets/Logic/CncIngameChromeLogic.cs +++ b/OpenRA.Mods.Cnc/Widgets/Logic/CncIngameChromeLogic.cs @@ -90,8 +90,8 @@ namespace OpenRA.Mods.Cnc.Widgets.Logic 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; + 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(); @@ -139,7 +139,7 @@ namespace OpenRA.Mods.Cnc.Widgets.Logic static void BindOrderButton(World world, Widget parent, string button, string icon) where T : IOrderGenerator, new() { - var w = parent.Get(button); + var w = parent.Get(button); w.OnClick = () => world.ToggleInputMode(); w.IsHighlighted = () => world.OrderGenerator is T; diff --git a/OpenRA.Mods.Cnc/Widgets/ProductionTypeButtonWidget.cs b/OpenRA.Mods.Cnc/Widgets/ProductionTypeButtonWidget.cs index f521509f97..f7643ba15b 100644 --- a/OpenRA.Mods.Cnc/Widgets/ProductionTypeButtonWidget.cs +++ b/OpenRA.Mods.Cnc/Widgets/ProductionTypeButtonWidget.cs @@ -15,7 +15,7 @@ using OpenRA.Widgets; namespace OpenRA.Mods.Cnc.Widgets { - public class ProductionTypeButtonWidget : ToggleButtonWidget + public class ProductionTypeButtonWidget : ButtonWidget { public readonly string ProductionGroup; diff --git a/OpenRA.Mods.Cnc/Widgets/ToggleButtonWidget.cs b/OpenRA.Mods.Cnc/Widgets/ToggleButtonWidget.cs deleted file mode 100644 index 662aef4c30..0000000000 --- a/OpenRA.Mods.Cnc/Widgets/ToggleButtonWidget.cs +++ /dev/null @@ -1,55 +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.FileFormats; -using OpenRA.Widgets; - -namespace OpenRA.Mods.Cnc.Widgets -{ - public class ToggleButtonWidget : ButtonWidget - { - public readonly string TooltipTemplate = "BUTTON_TOOLTIP"; - public readonly string TooltipText; - public readonly string TooltipContainer; - Lazy tooltipContainer; - - public ToggleButtonWidget() - : base() - { - tooltipContainer = Lazy.New(() => - Ui.Root.Get(TooltipContainer)); - } - - protected ToggleButtonWidget(ToggleButtonWidget other) - : base(other) - { - TooltipTemplate = other.TooltipTemplate; - TooltipText = other.TooltipText; - TooltipContainer = other.TooltipContainer; - tooltipContainer = Lazy.New(() => - Ui.Root.Get(TooltipContainer)); - } - - public override void MouseEntered() - { - if (TooltipContainer == null) return; - tooltipContainer.Value.SetTooltip(TooltipTemplate, - new WidgetArgs() {{ "button", this }}); - } - - public override void MouseExited() - { - if (TooltipContainer == null) return; - tooltipContainer.Value.RemoveTooltip(); - } - } -} diff --git a/mods/cnc/chrome/ingame.yaml b/mods/cnc/chrome/ingame.yaml index 1e864cb18c..3ce898813e 100644 --- a/mods/cnc/chrome/ingame.yaml +++ b/mods/cnc/chrome/ingame.yaml @@ -44,7 +44,7 @@ Container@INGAME_ROOT: TooltipContainer@TOOLTIP_CONTAINER: Container@OBSERVER_WIDGETS: Children: - ToggleButton@OPTIONS_BUTTON: + Button@OPTIONS_BUTTON: Key:escape X:WINDOW_RIGHT-202 Y:5 @@ -98,7 +98,7 @@ Container@PLAYER_WIDGETS: Height:240 Background:panel-black Children: - ToggleButton@OPTIONS_BUTTON: + Button@OPTIONS_BUTTON: Key:escape X:42 Y:0-24 @@ -113,7 +113,7 @@ Container@PLAYER_WIDGETS: Y:5 ImageCollection:order-icons ImageName:options - ToggleButton@SELL_BUTTON: + Button@SELL_BUTTON: X:82 Y:0-24 Width:30 @@ -126,7 +126,7 @@ Container@PLAYER_WIDGETS: X:7 Y:5 ImageCollection:order-icons - ToggleButton@REPAIR_BUTTON: + Button@REPAIR_BUTTON: X:122 Y:0-24 Width:30 From 09efeed1054f8f48f770c8f32e010594e26bbd66 Mon Sep 17 00:00:00 2001 From: Paul Chote Date: Mon, 8 Apr 2013 23:04:23 +1200 Subject: [PATCH 5/5] Use IsHighlighted for settings / ingame menu tabs. --- OpenRA.Mods.Cnc/Widgets/Logic/CncIngameMenuLogic.cs | 4 ++-- OpenRA.Mods.Cnc/Widgets/Logic/CncSettingsLogic.cs | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/OpenRA.Mods.Cnc/Widgets/Logic/CncIngameMenuLogic.cs b/OpenRA.Mods.Cnc/Widgets/Logic/CncIngameMenuLogic.cs index 14ad6a064b..bdb80ccfec 100644 --- a/OpenRA.Mods.Cnc/Widgets/Logic/CncIngameMenuLogic.cs +++ b/OpenRA.Mods.Cnc/Widgets/Logic/CncIngameMenuLogic.cs @@ -98,7 +98,7 @@ namespace OpenRA.Mods.Cnc.Widgets.Logic // Debug / Cheats panel var debugButton = panelParent.Get("DEBUG_BUTTON"); debugButton.OnClick = () => Panel = PanelType.Debug; - debugButton.IsDisabled = () => Panel == PanelType.Debug; + debugButton.IsHighlighted = () => Panel == PanelType.Debug; if (world.LocalPlayer != null && world.LobbyInfo.GlobalSettings.AllowCheats) { @@ -113,7 +113,7 @@ namespace OpenRA.Mods.Cnc.Widgets.Logic var iop = world.WorldActor.TraitsImplementing().FirstOrDefault(); var objectivesButton = panelParent.Get("OBJECTIVES_BUTTON"); objectivesButton.OnClick = () => Panel = PanelType.Objectives; - objectivesButton.IsDisabled = () => Panel == PanelType.Objectives; + objectivesButton.IsHighlighted = () => Panel == PanelType.Objectives; if (iop != null && iop.ObjectivesPanel != null) { diff --git a/OpenRA.Mods.Cnc/Widgets/Logic/CncSettingsLogic.cs b/OpenRA.Mods.Cnc/Widgets/Logic/CncSettingsLogic.cs index 5c3b99e9d0..413ce4b5aa 100644 --- a/OpenRA.Mods.Cnc/Widgets/Logic/CncSettingsLogic.cs +++ b/OpenRA.Mods.Cnc/Widgets/Logic/CncSettingsLogic.cs @@ -39,7 +39,7 @@ namespace OpenRA.Mods.Cnc.Widgets.Logic // General pane var generalButton = panel.Get("GENERAL_BUTTON"); generalButton.OnClick = () => Settings = PanelType.General; - generalButton.IsDisabled = () => Settings == PanelType.General; + generalButton.IsHighlighted = () => Settings == PanelType.General; var generalPane = panel.Get("GENERAL_CONTROLS"); generalPane.IsVisible = () => Settings == PanelType.General; @@ -118,7 +118,7 @@ namespace OpenRA.Mods.Cnc.Widgets.Logic var inputButton = panel.Get("INPUT_BUTTON"); inputButton.OnClick = () => Settings = PanelType.Input; - inputButton.IsDisabled = () => Settings == PanelType.Input; + inputButton.IsHighlighted = () => Settings == PanelType.Input; var classicMouseCheckbox = inputPane.Get("CLASSICORDERS_CHECKBOX"); classicMouseCheckbox.IsChecked = () => gameSettings.UseClassicMouseStyle;