diff --git a/OpenRA.Game/Widgets/WidgetUtils.cs b/OpenRA.Game/Widgets/WidgetUtils.cs index 4e83fcd8ef..f5abcf2922 100644 --- a/OpenRA.Game/Widgets/WidgetUtils.cs +++ b/OpenRA.Game/Widgets/WidgetUtils.cs @@ -12,6 +12,7 @@ using System; using System.Collections.Generic; using System.Drawing; using System.Linq; +using OpenRA.FileFormats; using OpenRA.Graphics; namespace OpenRA.Widgets @@ -208,6 +209,18 @@ namespace OpenRA.Widgets } public static Action Once( Action a ) { return () => { if (a != null) { a(); a = null; } }; } + + public static string ActiveModVersion() + { + var mod = Game.modData.Manifest.Mods[0]; + return Mod.AllMods[mod].Version; + } + + public static string ActiveModTitle() + { + var mod = Game.modData.Manifest.Mods[0]; + return Mod.AllMods[mod].Title; + } } [Flags] diff --git a/OpenRA.Mods.Cnc/CncLoadScreen.cs b/OpenRA.Mods.Cnc/CncLoadScreen.cs index a7ad484943..ddd69eda5b 100644 --- a/OpenRA.Mods.Cnc/CncLoadScreen.cs +++ b/OpenRA.Mods.Cnc/CncLoadScreen.cs @@ -33,16 +33,17 @@ namespace OpenRA.Mods.Cnc public void Init(Dictionary info) { Info = info; + // Avoid standard loading mechanisms so we // can display loadscreen as early as possible r = Game.Renderer; if (r == null) return; - var s = new Sheet("mods/cnc/uibits/chrome.png"); var res = Renderer.Resolution; Bounds = new Rectangle(0, 0, res.Width, res.Height); - ss = new Sprite[] + + ss = new [] { new Sprite(s, new Rectangle(161,128,62,33), TextureChannel.Alpha), new Sprite(s, new Rectangle(161,223,62,33), TextureChannel.Alpha), @@ -53,6 +54,7 @@ namespace OpenRA.Mods.Cnc new Sprite(s, new Rectangle(128,223,33,33), TextureChannel.Alpha), new Sprite(s, new Rectangle(223,223,33,33), TextureChannel.Alpha) }; + nodLogo = new Sprite(s, new Rectangle(0, 256, 256, 256), TextureChannel.Alpha); gdiLogo = new Sprite(s, new Rectangle(256, 256, 256, 256), TextureChannel.Alpha); evaLogo = new Sprite(s, new Rectangle(256, 64, 128, 64), TextureChannel.Alpha); @@ -73,6 +75,7 @@ namespace OpenRA.Mods.Cnc { if (r == null || loadTimer.ElapsedTime() < 0.25) return; + loadTimer.Reset(); loadTick = ++loadTick % 8; @@ -91,7 +94,7 @@ namespace OpenRA.Mods.Cnc loadingPos = new float2((Bounds.Width - loadingFont.Measure(loadingText).X) / 2, barY); versionFont = r.Fonts["Regular"]; - versionText = CncWidgetUtils.ActiveModVersion(); + versionText = WidgetUtils.ActiveModVersion(); var versionSize = versionFont.Measure(versionText); versionPos = new float2(Bounds.Width - 107 - versionSize.X/2, 115 - versionSize.Y/2); diff --git a/OpenRA.Mods.Cnc/Widgets/CncWidgetUtils.cs b/OpenRA.Mods.Cnc/Widgets/CncWidgetUtils.cs index 2969ffa321..ef3a652c9b 100644 --- a/OpenRA.Mods.Cnc/Widgets/CncWidgetUtils.cs +++ b/OpenRA.Mods.Cnc/Widgets/CncWidgetUtils.cs @@ -17,12 +17,6 @@ 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 string ChooseInitialMap(string map) { var availableMaps = Game.modData.AvailableMaps; @@ -37,13 +31,13 @@ namespace OpenRA.Mods.Cnc.Widgets 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(); diff --git a/OpenRA.Mods.Cnc/Widgets/Logic/CncIngameMenuLogic.cs b/OpenRA.Mods.Cnc/Widgets/Logic/CncIngameMenuLogic.cs index 4064c71b63..32aef2a3cb 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 = CncWidgetUtils.ActiveModVersion; + menu.GetWidget("VERSION_LABEL").GetText = WidgetUtils.ActiveModVersion; bool hideButtons = false; menu.GetWidget("MENU_BUTTONS").IsVisible = () => !hideButtons; diff --git a/OpenRA.Mods.Cnc/Widgets/Logic/CncMenuLogic.cs b/OpenRA.Mods.Cnc/Widgets/Logic/CncMenuLogic.cs index 72cff693ad..d2030917e3 100644 --- a/OpenRA.Mods.Cnc/Widgets/Logic/CncMenuLogic.cs +++ b/OpenRA.Mods.Cnc/Widgets/Logic/CncMenuLogic.cs @@ -30,7 +30,7 @@ namespace OpenRA.Mods.Cnc.Widgets.Logic .Fade(CncMenuPaletteEffect.EffectType.Desaturated); rootMenu = widget.GetWidget("MENU_BACKGROUND"); - rootMenu.GetWidget("VERSION_LABEL").GetText = CncWidgetUtils.ActiveModVersion; + rootMenu.GetWidget("VERSION_LABEL").GetText = WidgetUtils.ActiveModVersion; // Menu buttons var mainMenu = widget.GetWidget("MAIN_MENU"); diff --git a/OpenRA.Mods.RA/Widgets/Logic/MainMenuButtonsLogic.cs b/OpenRA.Mods.RA/Widgets/Logic/MainMenuButtonsLogic.cs index 2658ca8f3b..f0ebffafc8 100644 --- a/OpenRA.Mods.RA/Widgets/Logic/MainMenuButtonsLogic.cs +++ b/OpenRA.Mods.RA/Widgets/Logic/MainMenuButtonsLogic.cs @@ -40,20 +40,8 @@ namespace OpenRA.Mods.RA.Widgets.Logic var selector = Game.modData.WidgetLoader.LoadWidget( new WidgetArgs(), Widget.RootWidget, "QUICKMODSWITCHER" ); var switcher = selector.GetWidget("SWITCHER"); switcher.OnMouseDown = _ => ShowModsDropDown(switcher); - switcher.GetText = ActiveModTitle; - selector.GetWidget("VERSION").GetText = ActiveModVersion; - } - - static string ActiveModTitle() - { - var mod = Game.modData.Manifest.Mods[0]; - return Mod.AllMods[mod].Title; - } - - static string ActiveModVersion() - { - var mod = Game.modData.Manifest.Mods[0]; - return Mod.AllMods[mod].Version; + switcher.GetText = WidgetUtils.ActiveModTitle; + selector.GetWidget("VERSION").GetText = WidgetUtils.ActiveModVersion; } static void LoadMod(string mod) @@ -64,23 +52,18 @@ namespace OpenRA.Mods.RA.Widgets.Logic mods.Add(mod); mod = Mod.AllMods[mod].Requires; } - - if (!Game.CurrentMods.Keys.ToArray().SymmetricDifference(mods.ToArray()).Any()) - return; - - Game.RunAfterTick(() => - { - Game.InitializeWithMods(mods.ToArray()); - }); + + if (Game.CurrentMods.Keys.ToArray().SymmetricDifference(mods.ToArray()).Any()) + Game.RunAfterTick(() => Game.InitializeWithMods(mods.ToArray())); } - + static void ShowModsDropDown(DropDownButtonWidget dropdown) { Func setupItem = (m, itemTemplate) => { var item = ScrollItemWidget.Setup(itemTemplate, - () => m == Game.CurrentMods.Keys.First(), - () => LoadMod(m)); + () => m == Game.CurrentMods.Keys.First(), + () => LoadMod(m)); item.GetWidget("LABEL").GetText = () => Mod.AllMods[m].Title; return item; };