Skip to content

Commit

Permalink
Show the mod switcher during the initial install screen.
Browse files Browse the repository at this point in the history
  • Loading branch information
pchote committed Jan 27, 2011
1 parent a3f26ce commit 724a72c
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 49 deletions.
48 changes: 48 additions & 0 deletions OpenRA.Mods.RA/Widgets/Delegates/GameInitDelegate.cs
Expand Up @@ -19,6 +19,7 @@
using System.ComponentModel;
using System.IO;
using System.Threading;
using System.Drawing;

namespace OpenRA.Mods.RA.Widgets.Delegates
{
Expand Down Expand Up @@ -64,6 +65,53 @@ public GameInitDelegate([ObjectCreator.Param] Widget widget)
{
ShowInstallMethodDialog();
}

var selector = Game.modData.WidgetLoader.LoadWidget( new Dictionary<string,object>(), Widget.RootWidget, "QUICKMODSWITCHER" );
var switcher = selector.GetWidget<ButtonWidget>("SWITCHER");
switcher.OnMouseDown = _ => ShowModsDropDown(switcher);
switcher.GetText = ActiveModTitle;
selector.GetWidget<LabelWidget>("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<Pair<string, Action>>();

foreach (var kv in Mod.AllMods)
{
var modList = new List<string>() { 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<string, Action>( 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()
Expand Down
49 changes: 0 additions & 49 deletions OpenRA.Mods.RA/Widgets/Delegates/MainMenuButtonsDelegate.cs
Expand Up @@ -13,8 +13,6 @@
using OpenRA.Network;
using OpenRA.Server;
using OpenRA.Widgets;
using System;
using System.Drawing;

namespace OpenRA.Mods.RA.Widgets.Delegates
{
Expand All @@ -30,53 +28,6 @@ public MainMenuButtonsDelegate([ObjectCreator.Param] Widget widget)
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<string,object>(), Widget.RootWidget, "QUICKMODSWITCHER" );
var switcher = selector.GetWidget<ButtonWidget>("SWITCHER");
switcher.OnMouseDown = _ => ShowModsDropDown(switcher);
switcher.GetText = ActiveModTitle;
selector.GetWidget<LabelWidget>("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<Pair<string, Action>>();

foreach (var kv in Mod.AllMods)
{
var modList = new List<string>() { 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<string, Action>( 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;
}
}
}

0 comments on commit 724a72c

Please sign in to comment.