diff --git a/OpenRA.Game/Widgets/Widget.cs b/OpenRA.Game/Widgets/Widget.cs index 433aeca78c..94fa3225f6 100644 --- a/OpenRA.Game/Widgets/Widget.cs +++ b/OpenRA.Game/Widgets/Widget.cs @@ -334,9 +334,9 @@ namespace OpenRA.Widgets return window; } - public static Widget LoadWidget(string id) + public static Widget LoadWidget(string id, Dictionary args) { - return Game.modData.WidgetLoader.LoadWidget(new Dictionary(), rootWidget, id); + return Game.modData.WidgetLoader.LoadWidget(args, rootWidget, id); } public static void DoTick() diff --git a/OpenRA.Mods.Cnc/Missions/Gdi01Script.cs b/OpenRA.Mods.Cnc/Missions/Gdi01Script.cs index 89543a4446..5d9f74ae6d 100644 --- a/OpenRA.Mods.Cnc/Missions/Gdi01Script.cs +++ b/OpenRA.Mods.Cnc/Missions/Gdi01Script.cs @@ -58,9 +58,9 @@ namespace OpenRA.Mods.Cnc () => Scripting.Media.PlayFMVFullscreen(w, "consyard.vqa", () => { Sound.StopMusic(); - Game.Disconnect(); - Widget.CloseWindow(); - Widget.LoadWidget("MENU_BACKGROUND"); + //Game.Disconnect(); + //Widget.CloseWindow(); + //Widget.LoadWidget("MENU_BACKGROUND"); }))); } @@ -76,9 +76,9 @@ namespace OpenRA.Mods.Cnc () => Scripting.Media.PlayFMVFullscreen(w, "gameover.vqa", () => { Sound.StopMusic(); - Game.Disconnect(); - Widget.CloseWindow(); - Widget.LoadWidget("MENU_BACKGROUND"); + //Game.Disconnect(); + //Widget.CloseWindow(); + //Widget.LoadWidget("MENU_BACKGROUND"); }))); } diff --git a/OpenRA.Mods.Cnc/OpenRA.Mods.Cnc.csproj b/OpenRA.Mods.Cnc/OpenRA.Mods.Cnc.csproj index e95ab6b598..9097616fd4 100644 --- a/OpenRA.Mods.Cnc/OpenRA.Mods.Cnc.csproj +++ b/OpenRA.Mods.Cnc/OpenRA.Mods.Cnc.csproj @@ -78,6 +78,7 @@ + diff --git a/OpenRA.Mods.Cnc/Widgets/CncIngameChromeLogic.cs b/OpenRA.Mods.Cnc/Widgets/CncIngameChromeLogic.cs new file mode 100755 index 0000000000..0e1d0f374d --- /dev/null +++ b/OpenRA.Mods.Cnc/Widgets/CncIngameChromeLogic.cs @@ -0,0 +1,106 @@ +#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.Traits; +using OpenRA.Widgets; +using System.Drawing; +using System.Collections.Generic; +using System; + +namespace OpenRA.Mods.Cnc.Widgets +{ + public class CncIngameChromeLogic : IWidgetDelegate + { + static bool staticSetup; + Widget ingameRoot; + + public static CncIngameChromeLogic GetHandler() + { + var panel = Widget.RootWidget.GetWidget("INGAME_ROOT"); + if (panel == null) + return null; + + return panel.DelegateObject as CncIngameChromeLogic; + } + + static void AddChatLineStub(Color c, string from, string text) + { + var handler = GetHandler(); + if (handler == null) + return; + + handler.AddChatLine(c, from, text); + } + + + void AddChatLine(Color c, string from, string text) + { + ingameRoot.GetWidget("CHAT_DISPLAY").AddLine(c, from, text); + } + + [ObjectCreator.UseCtor] + public CncIngameChromeLogic([ObjectCreator.Param] Widget widget, + [ObjectCreator.Param] World world ) + { + ingameRoot = widget.GetWidget("INGAME_ROOT"); + if (!staticSetup) + { + staticSetup = true; + Game.AddChatLine += AddChatLineStub; + } + + ingameRoot.GetWidget("OPTIONS_BUTTON").OnClick = () => + { + ingameRoot.IsVisible = () => false; + var onExit = new Action(() => {ingameRoot.IsVisible = () => true;}); + Widget.LoadWidget("INGAME_MENU", new Dictionary() {{ "world", world }, { "onExit", onExit }}); + }; + + var postgameBG = ingameRoot.GetWidget("POSTGAME_BG"); + postgameBG.IsVisible = () => + { + return world.LocalPlayer != null && world.LocalPlayer.WinState != WinState.Undefined; + }; + + postgameBG.GetWidget("TEXT").GetText = () => + { + var state = world.LocalPlayer.WinState; + return (state == WinState.Undefined)? "" : + ((state == WinState.Lost)? "YOU ARE DEFEATED" : "YOU ARE VICTORIOUS"); + }; + } + } + + public class CncIngameMenuLogic : IWidgetDelegate + { + [ObjectCreator.UseCtor] + public CncIngameMenuLogic([ObjectCreator.Param] Widget widget, + [ObjectCreator.Param] World world, + [ObjectCreator.Param] Action onExit) + { + var menu = widget.GetWidget("INGAME_MENU"); + menu.GetWidget("QUIT_BUTTON").OnClick = () => + { + Game.DisconnectOnly(); + + // This is stupid. It should be handled by the shellmap + Game.LoadShellMap(); + Widget.RootWidget.RemoveChildren(); + Widget.LoadWidget("MENU_BACKGROUND", new Dictionary()); + }; + + menu.GetWidget("RESUME_BUTTON").OnClick = () => + { + Widget.RootWidget.RemoveChild(menu); + onExit(); + }; + } + } +} diff --git a/OpenRA.Mods.RA/Widgets/Delegates/GameInitDelegate.cs b/OpenRA.Mods.RA/Widgets/Delegates/GameInitDelegate.cs index 65ae348b9b..f9aa3c1214 100755 --- a/OpenRA.Mods.RA/Widgets/Delegates/GameInitDelegate.cs +++ b/OpenRA.Mods.RA/Widgets/Delegates/GameInitDelegate.cs @@ -42,7 +42,7 @@ namespace OpenRA.Mods.RA.Widgets.Delegates switch (orderManager.Connection.ConnectionState) { case ConnectionState.PreConnecting: - Widget.LoadWidget("MAINMENU_BG"); + Widget.LoadWidget("MAINMENU_BG", new Dictionary()); break; case ConnectionState.Connecting: Widget.OpenWindow("CONNECTING_BG", @@ -73,7 +73,7 @@ namespace OpenRA.Mods.RA.Widgets.Delegates Game.LoadShellMap(); Widget.RootWidget.RemoveChildren(); if (Info.InstallMode == "cnc") - Widget.LoadWidget("MENU_BACKGROUND"); + Widget.LoadWidget("MENU_BACKGROUND", new Dictionary()); else Widget.OpenWindow("MAINMENU_BG"); } diff --git a/mods/cnc/chrome/ingame.yaml b/mods/cnc/chrome/ingame.yaml index 6386eed1b9..db615832bd 100644 --- a/mods/cnc/chrome/ingame.yaml +++ b/mods/cnc/chrome/ingame.yaml @@ -1,21 +1,15 @@ Container@INGAME_ROOT: Id:INGAME_ROOT - Delegate:IngameChromeDelegate + Delegate:CncIngameChromeLogic Children: WorldInteractionController: Id:INTERACTION_CONTROLLER - X:0 - Y:0 Width:WINDOW_RIGHT Height:WINDOW_BOTTOM ViewportScrollController: - X:0 - Y:0 Width:WINDOW_RIGHT Height:WINDOW_BOTTOM WorldCommand: - X:0 - Y:0 Width:WINDOW_RIGHT Height:WINDOW_BOTTOM Timer@GAME_TIMER: @@ -45,7 +39,6 @@ Container@INGAME_ROOT: Bold:True SpecialPowerBin@INGAME_POWERS_BIN: Id:INGAME_POWERS_BIN - X:0 Y:25 BuildPalette@INGAME_BUILD_PALETTE: Id:INGAME_BUILD_PALETTE @@ -56,26 +49,26 @@ Container@INGAME_ROOT: TabClick: button.aud BuildPaletteOpen: appear1.aud BuildPaletteClose: appear1.aud - Button@INGAME_OPTIONS_BUTTON: - Id:INGAME_OPTIONS_BUTTON - X:0 - Y:0 - Width:160 - Height:25 + CncMenuButton@OPTIONS_BUTTON: + Id:OPTIONS_BUTTON + X:5 + Y:5 + Width:140 + Height:35 Text:Options Bold:True - Button@INGAME_DIPLOMACY_BUTTON: - Id:INGAME_DIPLOMACY_BUTTON - X:162 - Y:0 - Width:160 - Height:25 + CncMenuButton@DIPLOMACY_BUTTON: + Id:DIPLOMACY_BUTTON + X:150 + Y:5 + Width:140 + Height:35 Text:Diplomacy Bold:True - Button@INGAME_DEVELOPERMODE_BUTTON: - Id:INGAME_DEVELOPERMODE_BUTTON - X:324 - Y:0 + CncMenuButton@DEVELOPERMODE_BUTTON: + Id:DEVELOPERMODE_BUTTON + X:295 + Y:5 Width:160 Height:25 Text:Developer Mode @@ -115,89 +108,6 @@ Container@INGAME_ROOT: Description:Repair LongDesc:Repair damaged buildings WorldTooltip: - Background@INGAME_OPTIONS_BG: - Id:INGAME_OPTIONS_BG - X:(WINDOW_RIGHT - WIDTH)/2 - Y:(WINDOW_BOTTOM - HEIGHT)/2 - Width:300 - Height:320 - Visible:false - Children: - Label@LABEL_TITLE: - Id:LABEL_TITLE - X:(PARENT_RIGHT - WIDTH)/2 - Y:20 - Width:250 - Height:25 - Text:Options - Align:Center - Bold:True - Button@RESUME: - Id:RESUME - X:(PARENT_RIGHT - WIDTH)/2 - Y:60 - Width:160 - Height:25 - Text:Resume - Bold:True - Button@SETTINGS: - Id:SETTINGS - X:(PARENT_RIGHT - WIDTH)/2 - Y:100 - Width:160 - Height:25 - Text:Settings - Bold:True - Button@MUSIC: - Id:MUSIC - X:(PARENT_RIGHT - WIDTH)/2 - Y:140 - Width:160 - Height:25 - Text:Music - Bold:True - Button@SURRENDER: - Id:SURRENDER - X:(PARENT_RIGHT - WIDTH)/2 - Y:180 - Width:160 - Height:25 - Text:Surrender - Bold:True - Button@DISCONNECT: - Id:DISCONNECT - X:(PARENT_RIGHT - WIDTH)/2 - Y:220 - Width:160 - Height:25 - Text:Disconnect - Bold:True - Button@QUIT: - Id:QUIT - X:(PARENT_RIGHT - WIDTH)/2 - Y:260 - Width:160 - Height:25 - Text:Quit - Bold:True - Background@DIPLOMACY_BG: - Id:DIPLOMACY_BG - Delegate:DiplomacyDelegate - X:(WINDOW_RIGHT - WIDTH)/2 - Y:(WINDOW_BOTTOM - HEIGHT)/2 - Width:450 - Height:400 - Visible:false - Children: - Label@LABEL_TITLE: - Id:LABEL_TITLE - X:(PARENT_RIGHT - WIDTH)/2 - Y:20 - Width:250 - Height:25 - Text:Diplomacy - Align:Center - Bold:True ChatDisplay@CHAT_DISPLAY: Id:CHAT_DISPLAY X:250 @@ -213,270 +123,4 @@ Container@INGAME_ROOT: Y:WINDOW_BOTTOM - HEIGHT Width: 760 Height: 30 - UseContrast: yes - Background@DEVELOPERMODE_BG: - Id:DEVELOPERMODE_BG - Delegate:DeveloperModeDelegate - X:(WINDOW_RIGHT - WIDTH)/2 - Y:(WINDOW_BOTTOM - HEIGHT)/2 - Width:350 - Height:370 - Visible:false - Children: - Label@LABEL_TITLE: - Id:LABEL_TITLE - X:(PARENT_RIGHT - WIDTH)/2 - Y:20 - Width:250 - Height:25 - Text:Developer Mode - Align:Center - Checkbox@CHECKBOX_SHROUD - Id:CHECKBOX_SHROUD - X:30 - Y:50 - Height:20 - Width:PARENT_RIGHT - 30 - Text:Disable Shroud - Button@GIVE_EXPLORATION - Id:GIVE_EXPLORATION - X:30 - Y:80 - Width:200 - Height:20 - Text: Give Exploration - Checkbox@CHECKBOX_PATHDEBUG: - Id:CHECKBOX_PATHDEBUG - X:30 - Y:110 - Width:PARENT_RIGHT - 30 - Height:20 - Text:Show Unit Paths - Button@GIVE_CASH - Id:GIVE_CASH - X:30 - Y:140 - Width:200 - Height:20 - Text: Give Cash - Checkbox@INSTANT_BUILD - Id:INSTANT_BUILD - X:30 - Y:170 - Width:PARENT_RIGHT - 30 - Height:20 - Text:Instant Build Speed - Checkbox@INSTANT_CHARGE - Id:INSTANT_CHARGE - X:30 - Y:200 - Width:PARENT_RIGHT - 30 - Height:20 - Text:Instant Charge Time (Special Powers) - Checkbox@ENABLE_TECH - Id:ENABLE_TECH - X:30 - Y:230 - Width:PARENT_RIGHT - 30 - Height:20 - Text:Build Everything - Checkbox@UNLIMITED_POWER - Id:UNLIMITED_POWER - X:30 - Y:260 - Width:PARENT_RIGHT - 30 - Height:20 - Text:Unlimited Power - Checkbox@BUILD_ANYWHERE - Id:BUILD_ANYWHERE - X:30 - Y:290 - Width:PARENT_RIGHT - 30 - Height:20 - Text:Build Anywhere - Background@PERF_BG: - ClickThrough:true - Id:PERF_BG - Background:dialog4 - Delegate:PerfDebugDelegate - X:10 - Y:WINDOW_BOTTOM - 250 - Width: 210 - Height: 250 - Children: - PerfGraph@GRAPH: - Id:GRAPH - X:5 - Y:5 - Width:200 - Height:200 - Label@TEXT: - Id:TEXT - Bold: false - X:20 - Y:205 - Width:170 - Height:40 -Container@OBSERVER_ROOT: - Id:OBSERVER_ROOT - Visible:true - Delegate:IngameObserverChromeDelegate - Children: - WorldInteractionController: - X:0 - Y:0 - Width:WINDOW_RIGHT - Height:WINDOW_BOTTOM - ViewportScrollController: - X:0 - Y:0 - Width:WINDOW_RIGHT - Height:WINDOW_BOTTOM - Timer@GAME_TIMER: - Id:GAME_TIMER - X: WINDOW_RIGHT/2 - Y: 10 - Background@POSTGAME_BG: - Id:POSTGAME_BG - X:(WINDOW_RIGHT - WIDTH)/2 - Y:(WINDOW_BOTTOM - HEIGHT)/2 - Width:400 - Height:100 - Background:dialog4 - Visible:false - Children: - Label@TEXT: - Id:TEXT - X:(PARENT_RIGHT - WIDTH)/2 - Y:(PARENT_BOTTOM - HEIGHT)/2 - Width:200 - Height:40 - Align:Center - Bold:True - SpecialPowerBin@INGAME_POWERS_BIN: - Id:INGAME_POWERS_BIN - X:0 - Y:25 - Button@INGAME_OPTIONS_BUTTON: - Id:INGAME_OPTIONS_BUTTON - X:0 - Y:0 - Width:160 - Height:25 - Text:Options - Bold:True - WorldTooltip: - Background@INGAME_OPTIONS_BG: - Id:INGAME_OPTIONS_BG - X:(WINDOW_RIGHT - WIDTH)/2 - Y:(WINDOW_BOTTOM - HEIGHT)/2 - Width:300 - Height:320 - Visible:false - Children: - Label@LABEL_TITLE: - Id:LABEL_TITLE - X:(PARENT_RIGHT - WIDTH)/2 - Y:20 - Width:250 - Height:25 - Text:Options - Align:Center - Bold:True - Button@RESUME: - Id:RESUME - X:(PARENT_RIGHT - WIDTH)/2 - Y:60 - Width:160 - Height:25 - Text:Resume - Bold:True - Button@SETTINGS: - Id:SETTINGS - X:(PARENT_RIGHT - WIDTH)/2 - Y:100 - Width:160 - Height:25 - Text:Settings - Bold:True - Button@MUSIC: - Id:MUSIC - X:(PARENT_RIGHT - WIDTH)/2 - Y:140 - Width:160 - Height:25 - Text:Music - Bold:True - Button@SURRENDER: - Id:SURRENDER - X:(PARENT_RIGHT - WIDTH)/2 - Y:180 - Width:160 - Height:25 - Text:Surrender - Bold:True - Button@DISCONNECT: - Id:DISCONNECT - X:(PARENT_RIGHT - WIDTH)/2 - Y:220 - Width:160 - Height:25 - Text:Disconnect - Bold:True - Button@QUIT: - Id:QUIT - X:(PARENT_RIGHT - WIDTH)/2 - Y:260 - Width:160 - Height:25 - Text:Quit - Bold:True - ChatDisplay@CHAT_DISPLAY: - Id:CHAT_DISPLAY - X:250 - Y:WINDOW_BOTTOM - HEIGHT - 30 - Width: 760 - Height: 200 - DrawBackground: False - RemoveTime:250 - ChatEntry@CHAT_ENTRY: - Id:CHAT_ENTRY - X:250 - Y:WINDOW_BOTTOM - HEIGHT - Width: 760 - Height: 30 - Background@PERF_BG: - ClickThrough:true - Id:PERF_BG - Background:dialog4 - Delegate:PerfDebugDelegate - X:10 - Y:WINDOW_BOTTOM - 250 - Width: 210 - Height: 250 - Children: - PerfGraph@GRAPH: - Id:GRAPH - X:5 - Y:5 - Width:200 - Height:200 - Label@TEXT: - Id:TEXT - Bold: false - X:20 - Y:205 - Width:170 - Height:40 -Background@FMVPLAYER: - Id:FMVPLAYER - Width:WINDOW_RIGHT - Height:WINDOW_BOTTOM - Background:dialog4 - Children: - VqaPlayer: - Id:PLAYER - X:0 - Y:0 - Width:WINDOW_RIGHT - Height:WINDOW_BOTTOM \ No newline at end of file + UseContrast: yes \ No newline at end of file diff --git a/mods/cnc/chrome/ingamemenu.yaml b/mods/cnc/chrome/ingamemenu.yaml new file mode 100644 index 0000000000..66d6e00733 --- /dev/null +++ b/mods/cnc/chrome/ingamemenu.yaml @@ -0,0 +1,54 @@ +Container@INGAME_MENU: + Id:INGAME_MENU + Width:WINDOW_RIGHT + Height:WINDOW_BOTTOM + Delegate:CncIngameMenuLogic + Children: + Image@RETICLE: + X:(WINDOW_RIGHT-WIDTH)/2 + Y:(WINDOW_BOTTOM-HEIGHT)/2 + Width:512 + Height:512 + ImageCollection:shellmap + ImageName:reticle + ScanLine: + Width:WINDOW_RIGHT + Height:WINDOW_BOTTOM + Background@BORDER: + Width:WINDOW_RIGHT + Height:WINDOW_BOTTOM + Background:shellmapborder + Container@MENUS: + X:(WINDOW_RIGHT-WIDTH)/2 + Y:WINDOW_BOTTOM-33-HEIGHT-10 + Width:740 + Height:35 + Children: + CncMenuButton@QUIT_BUTTON: + Id:QUIT_BUTTON + X:0 + Y:0 + Width:140 + Height:35 + Text:Exit Game + CncMenuButton@SURRENDER_BUTTON: + Id:SURRENDER_BUTTON + X:150 + Y:0 + Width:140 + Height:35 + Text:Surrender + CncMenuButton@SETTINGS_BUTTON: + Id:SETTINGS_BUTTON + X:450 + Y:0 + Width:140 + Height:35 + Text:Settings + CncMenuButton@RESUME_BUTTON: + Id:RESUME_BUTTON + X:600 + Y:0 + Width:140 + Height:35 + Text:Resume \ No newline at end of file diff --git a/mods/cnc/mod.yaml b/mods/cnc/mod.yaml index 658abee239..c82aac65de 100644 --- a/mods/cnc/mod.yaml +++ b/mods/cnc/mod.yaml @@ -69,6 +69,7 @@ ChromeLayout: mods/cnc/chrome/mapchooser.yaml mods/cnc/chrome/replaybrowser.yaml mods/cnc/chrome/ingame.yaml + mods/cnc/chrome/ingamemenu.yaml Weapons: mods/cnc/weapons.yaml