From d95138b6008fdc49e021e54f83b59b943f3e1ad5 Mon Sep 17 00:00:00 2001 From: Paul Chote Date: Sun, 8 May 2011 21:23:01 +1200 Subject: [PATCH] Use the same mechanism for loading ingame and shellmap ui. --- OpenRA.Game/Game.cs | 10 ++++++++ .../Widgets/CncIngameChromeLogic.cs | 5 +--- OpenRA.Mods.RA/OpenWidgetAtGameStart.cs | 23 +++++++++++++++++++ .../Widgets/Delegates/GameInitDelegate.cs | 8 +++---- mods/cnc/maps/shellmap/map.yaml | 3 ++- mods/cnc/rules/system.yaml | 3 +-- 6 files changed, 41 insertions(+), 11 deletions(-) diff --git a/OpenRA.Game/Game.cs b/OpenRA.Game/Game.cs index bead1df213..544ab00424 100755 --- a/OpenRA.Game/Game.cs +++ b/OpenRA.Game/Game.cs @@ -112,6 +112,16 @@ namespace OpenRA { "worldRenderer", worldRenderer }, }); } + + public static Widget LoadWidget(World world, string widget, Dictionary args) + { + return Widget.LoadWidget(widget, new Dictionary(args) + { + { "world", world }, + { "orderManager", orderManager }, + { "worldRenderer", worldRenderer }, + }); + } static ActionQueue afterTickActions = new ActionQueue(); public static void RunAfterTick(Action a) { afterTickActions.Add(a); } diff --git a/OpenRA.Mods.Cnc/Widgets/CncIngameChromeLogic.cs b/OpenRA.Mods.Cnc/Widgets/CncIngameChromeLogic.cs index 65cc348d09..13172f744f 100755 --- a/OpenRA.Mods.Cnc/Widgets/CncIngameChromeLogic.cs +++ b/OpenRA.Mods.Cnc/Widgets/CncIngameChromeLogic.cs @@ -91,11 +91,8 @@ namespace OpenRA.Mods.Cnc.Widgets var onQuit = (Action)(() => { Game.DisconnectOnly(); - - // This is stupid. It should be handled by the shellmap - Game.LoadShellMap(); Widget.RootWidget.RemoveChildren(); - Widget.LoadWidget("MENU_BACKGROUND", new Dictionary()); + Game.LoadShellMap(); }); var doNothing = (Action)(() => {}); diff --git a/OpenRA.Mods.RA/OpenWidgetAtGameStart.cs b/OpenRA.Mods.RA/OpenWidgetAtGameStart.cs index f094e4aa86..b3c1dd46c9 100644 --- a/OpenRA.Mods.RA/OpenWidgetAtGameStart.cs +++ b/OpenRA.Mods.RA/OpenWidgetAtGameStart.cs @@ -10,9 +10,11 @@ using OpenRA.Traits; using OpenRA.Widgets; +using System.Collections.Generic; namespace OpenRA.Mods.RA { + // Legacy crap public class OpenWidgetAtGameStartInfo : ITraitInfo { public readonly string Widget = "INGAME_ROOT"; @@ -40,4 +42,25 @@ namespace OpenRA.Mods.RA Game.OpenWindow(world, Info.ObserverWidget); } } + + // New version + public class LoadWidgetAtGameStartInfo : ITraitInfo + { + public readonly string Widget = null; + public object Create(ActorInitializer init) { return new LoadWidgetAtGameStart(this); } + } + + public class LoadWidgetAtGameStart: IWorldLoaded + { + readonly LoadWidgetAtGameStartInfo Info; + public LoadWidgetAtGameStart(LoadWidgetAtGameStartInfo Info) + { + this.Info = Info; + } + + public void WorldLoaded(World world) + { + Game.LoadWidget(world, Info.Widget, new Dictionary()); + } + } } \ No newline at end of file diff --git a/OpenRA.Mods.RA/Widgets/Delegates/GameInitDelegate.cs b/OpenRA.Mods.RA/Widgets/Delegates/GameInitDelegate.cs index f9aa3c1214..244e06bf5f 100755 --- a/OpenRA.Mods.RA/Widgets/Delegates/GameInitDelegate.cs +++ b/OpenRA.Mods.RA/Widgets/Delegates/GameInitDelegate.cs @@ -71,11 +71,11 @@ namespace OpenRA.Mods.RA.Widgets.Delegates if (FileSystem.Exists(Info.TestFile)) { Game.LoadShellMap(); - Widget.RootWidget.RemoveChildren(); - if (Info.InstallMode == "cnc") - Widget.LoadWidget("MENU_BACKGROUND", new Dictionary()); - else + if (Info.InstallMode != "cnc") + { + Widget.RootWidget.RemoveChildren(); Widget.OpenWindow("MAINMENU_BG"); + } } else { diff --git a/mods/cnc/maps/shellmap/map.yaml b/mods/cnc/maps/shellmap/map.yaml index 374bba9b5f..b61b853892 100755 --- a/mods/cnc/maps/shellmap/map.yaml +++ b/mods/cnc/maps/shellmap/map.yaml @@ -1014,7 +1014,8 @@ Rules: -CrateSpawner: CncShellmapScript: DesaturatedPaletteEffect: - -OpenWidgetAtGameStart: + LoadWidgetAtGameStart: + Widget:MENU_BACKGROUND LST: Mobile: Speed: 3 diff --git a/mods/cnc/rules/system.yaml b/mods/cnc/rules/system.yaml index d785a10d9a..9876335de6 100644 --- a/mods/cnc/rules/system.yaml +++ b/mods/cnc/rules/system.yaml @@ -44,9 +44,8 @@ Player: SurrenderOnDisconnect: World: - OpenWidgetAtGameStart: + LoadWidgetAtGameStart: Widget: INGAME_ROOT - ObserverWidget: OBSERVER_ROOT ScreenShaker: NukePaletteEffect: CncWaterPaletteRotation: