diff --git a/OpenRA.Mods.RA/Widgets/Delegates/GameInitDelegate.cs b/OpenRA.Mods.RA/Widgets/Delegates/GameInitDelegate.cs index 5f5fc4f5ef..90624984ee 100755 --- a/OpenRA.Mods.RA/Widgets/Delegates/GameInitDelegate.cs +++ b/OpenRA.Mods.RA/Widgets/Delegates/GameInitDelegate.cs @@ -19,6 +19,7 @@ using System.Net; using System.ComponentModel; using System.IO; using System.Threading; +using System.Drawing; namespace OpenRA.Mods.RA.Widgets.Delegates { @@ -64,6 +65,53 @@ namespace OpenRA.Mods.RA.Widgets.Delegates { ShowInstallMethodDialog(); } + + var selector = Game.modData.WidgetLoader.LoadWidget( new Dictionary(), Widget.RootWidget, "QUICKMODSWITCHER" ); + var switcher = selector.GetWidget("SWITCHER"); + switcher.OnMouseDown = _ => ShowModsDropDown(switcher); + switcher.GetText = ActiveModTitle; + selector.GetWidget("VERSION").GetText = ActiveModVersion; + } + + string ActiveModTitle() + { + var mod = Game.modData.Manifest.Mods[0]; + return Mod.AllMods[mod].Title; + } + + string ActiveModVersion() + { + var mod = Game.modData.Manifest.Mods[0]; + return Mod.AllMods[mod].Version; + } + + bool ShowModsDropDown(ButtonWidget selector) + { + var dropDownOptions = new List>(); + + foreach (var kv in Mod.AllMods) + { + var modList = new List() { kv.Key }; + var m = kv.Key; + while (!string.IsNullOrEmpty(Mod.AllMods[m].Requires)) + { + m = Mod.AllMods[m].Requires; + modList.Add(m); + } + + dropDownOptions.Add(new Pair( kv.Value.Title, + () => Game.RunAfterTick(() => Game.InitializeWithMods( modList.ToArray() ) ))); + } + + DropDownButtonWidget.ShowDropDown( selector, + dropDownOptions, + (ac, w) => new LabelWidget + { + Bounds = new Rectangle(0, 0, w, 24), + Text = " {0}".F(ac.First), + OnMouseUp = mi => { ac.Second(); return true; }, + }); + return true; } void ShowInstallMethodDialog() diff --git a/OpenRA.Mods.RA/Widgets/Delegates/MainMenuButtonsDelegate.cs b/OpenRA.Mods.RA/Widgets/Delegates/MainMenuButtonsDelegate.cs index 61d520e56a..c65ea9768d 100755 --- a/OpenRA.Mods.RA/Widgets/Delegates/MainMenuButtonsDelegate.cs +++ b/OpenRA.Mods.RA/Widgets/Delegates/MainMenuButtonsDelegate.cs @@ -13,8 +13,6 @@ using OpenRA.FileFormats; using OpenRA.Network; using OpenRA.Server; using OpenRA.Widgets; -using System; -using System.Drawing; namespace OpenRA.Mods.RA.Widgets.Delegates { @@ -30,53 +28,6 @@ namespace OpenRA.Mods.RA.Widgets.Delegates widget.GetWidget("MAINMENU_BUTTON_MUSIC").OnMouseUp = mi => { Widget.OpenWindow("MUSIC_MENU"); return true; }; widget.GetWidget("MAINMENU_BUTTON_REPLAY_VIEWER").OnMouseUp = mi => { Widget.OpenWindow("REPLAYBROWSER_BG"); return true; }; widget.GetWidget("MAINMENU_BUTTON_QUIT").OnMouseUp = mi => { Game.Exit(); return true; }; - - var selector = Game.modData.WidgetLoader.LoadWidget( new Dictionary(), Widget.RootWidget, "QUICKMODSWITCHER" ); - var switcher = selector.GetWidget("SWITCHER"); - switcher.OnMouseDown = _ => ShowModsDropDown(switcher); - switcher.GetText = ActiveModTitle; - selector.GetWidget("VERSION").GetText = ActiveModVersion; - } - - string ActiveModTitle() - { - var mod = Game.modData.Manifest.Mods[0]; - return Mod.AllMods[mod].Title; - } - - string ActiveModVersion() - { - var mod = Game.modData.Manifest.Mods[0]; - return Mod.AllMods[mod].Version; - } - - bool ShowModsDropDown(ButtonWidget selector) - { - var dropDownOptions = new List>(); - - foreach (var kv in Mod.AllMods) - { - var modList = new List() { kv.Key }; - var m = kv.Key; - while (!string.IsNullOrEmpty(Mod.AllMods[m].Requires)) - { - m = Mod.AllMods[m].Requires; - modList.Add(m); - } - - dropDownOptions.Add(new Pair( kv.Value.Title, - () => Game.RunAfterTick(() => Game.InitializeWithMods( modList.ToArray() ) ))); - } - - DropDownButtonWidget.ShowDropDown( selector, - dropDownOptions, - (ac, w) => new LabelWidget - { - Bounds = new Rectangle(0, 0, w, 24), - Text = " {0}".F(ac.First), - OnMouseUp = mi => { ac.Second(); return true; }, - }); - return true; } } }