diff --git a/OpenRA.Mods.Cnc/OpenRA.Mods.Cnc.csproj b/OpenRA.Mods.Cnc/OpenRA.Mods.Cnc.csproj index 9458478a7a..50bc2842d9 100644 --- a/OpenRA.Mods.Cnc/OpenRA.Mods.Cnc.csproj +++ b/OpenRA.Mods.Cnc/OpenRA.Mods.Cnc.csproj @@ -107,6 +107,7 @@ + diff --git a/OpenRA.Mods.Cnc/Widgets/CncWidgetUtils.cs b/OpenRA.Mods.Cnc/Widgets/CncWidgetUtils.cs new file mode 100644 index 0000000000..401f959d02 --- /dev/null +++ b/OpenRA.Mods.Cnc/Widgets/CncWidgetUtils.cs @@ -0,0 +1,44 @@ +#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 OpenRA.FileFormats; +using OpenRA.Widgets; + +namespace OpenRA.Mods.Cnc.Widgets +{ + public static class CncWidgetUtils + { + public static string ActiveModVersion() + { + var mod = Game.modData.Manifest.Mods[0]; + return Mod.AllMods[mod].Version; + } + + public static void PromptConfirmAction(string title, string text, Action onConfirm, Action onCancel) + { + var prompt = Widget.OpenWindow("CONFIRM_PROMPT"); + prompt.GetWidget("PROMPT_TITLE").GetText = () => title; + prompt.GetWidget("PROMPT_TEXT").GetText = () => text; + + prompt.GetWidget("CONFIRM_BUTTON").OnClick = () => + { + Widget.CloseWindow(); + onConfirm(); + }; + + prompt.GetWidget("CANCEL_BUTTON").OnClick = () => + { + Widget.CloseWindow(); + onCancel(); + }; + } + } +} diff --git a/OpenRA.Mods.Cnc/Widgets/Logic/CncIngameMenuLogic.cs b/OpenRA.Mods.Cnc/Widgets/Logic/CncIngameMenuLogic.cs index bbc7160dd5..253549ae10 100644 --- a/OpenRA.Mods.Cnc/Widgets/Logic/CncIngameMenuLogic.cs +++ b/OpenRA.Mods.Cnc/Widgets/Logic/CncIngameMenuLogic.cs @@ -31,7 +31,7 @@ namespace OpenRA.Mods.Cnc.Widgets.Logic var mpe = world.WorldActor.Trait(); mpe.Fade(CncMenuPaletteEffect.EffectType.Desaturated); - menu.GetWidget("VERSION_LABEL").GetText = ActiveModVersion; + menu.GetWidget("VERSION_LABEL").GetText = CncWidgetUtils.ActiveModVersion; bool hideButtons = false; menu.GetWidget("MENU_BUTTONS").IsVisible = () => !hideButtons; @@ -53,13 +53,13 @@ namespace OpenRA.Mods.Cnc.Widgets.Logic Action doNothing = () => {}; menu.GetWidget("QUIT_BUTTON").OnClick = () => - PromptConfirmAction("Abort Mission", "Leave this game and return to the menu?", onQuit, doNothing); + CncWidgetUtils.PromptConfirmAction("Abort Mission", "Leave this game and return to the menu?", onQuit, doNothing); Action onSurrender = () => world.IssueOrder(new Order("Surrender", world.LocalPlayer.PlayerActor, false)); var surrenderButton = menu.GetWidget("SURRENDER_BUTTON"); surrenderButton.IsDisabled = () => (world.LocalPlayer == null || world.LocalPlayer.WinState != WinState.Undefined); surrenderButton.OnClick = () => - PromptConfirmAction("Surrender", "Are you sure you want to surrender?", onSurrender, doNothing); + CncWidgetUtils.PromptConfirmAction("Surrender", "Are you sure you want to surrender?", onSurrender, doNothing); menu.GetWidget("MUSIC_BUTTON").OnClick = () => { @@ -95,30 +95,5 @@ namespace OpenRA.Mods.Cnc.Widgets.Logic if (iop != null && iop.ObjectivesPanel != null) Game.OpenWindow(world, iop.ObjectivesPanel); } - - static string ActiveModVersion() - { - var mod = Game.modData.Manifest.Mods[0]; - return Mod.AllMods[mod].Version; - } - - public void PromptConfirmAction(string title, string text, Action onConfirm, Action onCancel) - { - var prompt = Widget.OpenWindow("CONFIRM_PROMPT"); - prompt.GetWidget("PROMPT_TITLE").GetText = () => title; - prompt.GetWidget("PROMPT_TEXT").GetText = () => text; - - prompt.GetWidget("CONFIRM_BUTTON").OnClick = () => - { - Widget.CloseWindow(); - onConfirm(); - }; - - prompt.GetWidget("CANCEL_BUTTON").OnClick = () => - { - Widget.CloseWindow(); - onCancel(); - }; - } } } diff --git a/OpenRA.Mods.Cnc/Widgets/Logic/CncMenuLogic.cs b/OpenRA.Mods.Cnc/Widgets/Logic/CncMenuLogic.cs index 35f94a2843..a41b61def2 100644 --- a/OpenRA.Mods.Cnc/Widgets/Logic/CncMenuLogic.cs +++ b/OpenRA.Mods.Cnc/Widgets/Logic/CncMenuLogic.cs @@ -35,7 +35,7 @@ namespace OpenRA.Mods.Cnc.Widgets.Logic .Fade(CncMenuPaletteEffect.EffectType.Desaturated); rootMenu = widget.GetWidget("MENU_BACKGROUND"); - rootMenu.GetWidget("VERSION_LABEL").GetText = ActiveModVersion; + rootMenu.GetWidget("VERSION_LABEL").GetText = CncWidgetUtils.ActiveModVersion; // Menu buttons var mainMenu = widget.GetWidget("MAIN_MENU"); @@ -128,13 +128,7 @@ namespace OpenRA.Mods.Cnc.Widgets.Logic rootMenu.GetWidget("RECBLOCK").IsVisible = () => world.FrameNumber / 25 % 2 == 0; } - - static string ActiveModVersion() - { - var mod = Game.modData.Manifest.Mods[0]; - return Mod.AllMods[mod].Version; - } - + void RemoveShellmapUI() { rootMenu.Parent.RemoveChild(rootMenu); diff --git a/mods/cnc/chrome/dropdowns.yaml b/mods/cnc/chrome/dialogs.yaml similarity index 74% rename from mods/cnc/chrome/dropdowns.yaml rename to mods/cnc/chrome/dialogs.yaml index 25f41676a2..cf329f2a73 100644 --- a/mods/cnc/chrome/dropdowns.yaml +++ b/mods/cnc/chrome/dialogs.yaml @@ -137,3 +137,45 @@ ScrollPanel@TEAM_DROPDOWN_TEMPLATE: Width:PARENT_RIGHT Height:25 Align:Center + +Container@CONFIRM_PROMPT: + Id:CONFIRM_PROMPT + X:(WINDOW_RIGHT - WIDTH)/2 + Y:(WINDOW_BOTTOM - 90)/2 + Width:370 + Height:125 + Children: + Label@PROMPT_TITLE: + Id:PROMPT_TITLE + Width:PARENT_RIGHT + Y:0-25 + Font:BigBold + Contrast:true + Align:Center + Background@bg: + Width:370 + Height:90 + Background:panel-black + Children: + Label@PROMPT_TEXT: + Id:PROMPT_TEXT + Y:(PARENT_BOTTOM-HEIGHT)/2 + Width:PARENT_RIGHT + Height:25 + Font:Bold + Align:Center + Button@CANCEL_BUTTON: + Id:CANCEL_BUTTON + Key:escape + Y:89 + Width:140 + Height:35 + Text:Cancel + Button@CONFIRM_BUTTON: + Id:CONFIRM_BUTTON + Key:return + X:230 + Y:89 + Width:140 + Height:35 + Text:Confirm \ No newline at end of file diff --git a/mods/cnc/chrome/ingamemenu.yaml b/mods/cnc/chrome/ingamemenu.yaml index 32bc57e440..cd42f949e9 100644 --- a/mods/cnc/chrome/ingamemenu.yaml +++ b/mods/cnc/chrome/ingamemenu.yaml @@ -64,46 +64,4 @@ Container@INGAME_MENU: Y:0 Width:140 Height:35 - Text:Resume - -Container@CONFIRM_PROMPT: - Id:CONFIRM_PROMPT - X:(WINDOW_RIGHT - WIDTH)/2 - Y:(WINDOW_BOTTOM - 90)/2 - Width:370 - Height:125 - Children: - Label@PROMPT_TITLE: - Id:PROMPT_TITLE - Width:PARENT_RIGHT - Y:0-25 - Font:BigBold - Contrast:true - Align:Center - Background@bg: - Width:370 - Height:90 - Background:panel-black - Children: - Label@PROMPT_TEXT: - Id:PROMPT_TEXT - Y:(PARENT_BOTTOM-HEIGHT)/2 - Width:PARENT_RIGHT - Height:25 - Font:Bold - Align:Center - Button@CANCEL_BUTTON: - Id:CANCEL_BUTTON - Key:escape - Y:89 - Width:140 - Height:35 - Text:Cancel - Button@CONFIRM_BUTTON: - Id:CONFIRM_BUTTON - Key:return - X:230 - Y:89 - Width:140 - Height:35 - Text:Confirm \ No newline at end of file + Text:Resume \ No newline at end of file diff --git a/mods/cnc/mod.yaml b/mods/cnc/mod.yaml index cb76bea51e..e154cf4650 100644 --- a/mods/cnc/mod.yaml +++ b/mods/cnc/mod.yaml @@ -76,7 +76,7 @@ ChromeLayout: mods/cnc/chrome/modchooser.yaml mods/cnc/chrome/preferences.yaml mods/cnc/chrome/cheats.yaml - mods/cnc/chrome/dropdowns.yaml + mods/cnc/chrome/dialogs.yaml mods/cnc/chrome/objectives.yaml mods/cnc/chrome/tooltips.yaml