Ingame mod selector ui.

This commit is contained in:
Paul Chote
2011-01-21 10:34:47 +13:00
parent f44903b50f
commit 37fc836b46
6 changed files with 89 additions and 6 deletions

View File

@@ -13,6 +13,8 @@ using OpenRA.FileFormats;
using OpenRA.Network;
using OpenRA.Server;
using OpenRA.Widgets;
using System;
using System.Drawing;
namespace OpenRA.Mods.RA.Widgets.Delegates
{
@@ -28,6 +30,45 @@ 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 = widget.GetWidget<ButtonWidget>("QUICKMODSWITCHER");
selector.OnMouseDown = _ => ShowModsDropDown(selector);
selector.GetText = ActiveModTitle;
}
string ActiveModTitle()
{
var mod = Game.modData.Manifest.Mods[0];
return Mod.AllMods[mod].Title;
}
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.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;
}
}
}