Use new mechanism for mod list
This commit is contained in:
@@ -29,24 +29,7 @@ namespace OpenRA.Mods.Cnc.Widgets
|
||||
var panel = widget.GetWidget("MODS_PANEL");
|
||||
var modList = panel.GetWidget<ScrollPanelWidget>("MOD_LIST");
|
||||
var loadButton = panel.GetWidget<ButtonWidget>("LOAD_BUTTON");
|
||||
loadButton.OnClick = () =>
|
||||
{
|
||||
// TODO: This is crap
|
||||
var mods = new List<string>() { currentMod.Id };
|
||||
var m = currentMod;
|
||||
while (!string.IsNullOrEmpty(m.Requires))
|
||||
{
|
||||
m = Mod.AllMods[currentMod.Requires];
|
||||
mods.Add(m.Id);
|
||||
}
|
||||
|
||||
Game.RunAfterTick(() =>
|
||||
{
|
||||
Widget.CloseWindow();
|
||||
onSwitch();
|
||||
Game.InitializeWithMods(mods.ToArray());
|
||||
});
|
||||
};
|
||||
loadButton.OnClick = () => LoadMod(currentMod.Id, onSwitch);
|
||||
loadButton.IsDisabled = () => currentMod.Id == Game.CurrentMods.Keys.First();
|
||||
|
||||
panel.GetWidget<ButtonWidget>("BACK_BUTTON").OnClick = () => { Widget.CloseWindow(); onExit(); };
|
||||
@@ -64,17 +47,23 @@ namespace OpenRA.Mods.Cnc.Widgets
|
||||
item.GetWidget<LabelWidget>("AUTHOR").GetText = () => mod.Author;
|
||||
modList.AddChild(item);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
// Server info
|
||||
var infoPanel = panel.GetWidget("SERVER_INFO");
|
||||
infoPanel.IsVisible = () => currentServer != null;
|
||||
infoPanel.GetWidget<LabelWidget>("SERVER_IP").GetText = () => currentServer.Address;
|
||||
infoPanel.GetWidget<LabelWidget>("SERVER_MODS").GetText = () => ServerBrowserDelegate.GenerateModsLabel(currentServer);
|
||||
infoPanel.GetWidget<LabelWidget>("MAP_TITLE").GetText = () => (CurrentMap() != null) ? CurrentMap().Title : "Unknown";
|
||||
infoPanel.GetWidget<LabelWidget>("MAP_PLAYERS").GetText = () => GetPlayersLabel(currentServer);
|
||||
*/
|
||||
}
|
||||
|
||||
void LoadMod(string mod, Action onSwitch)
|
||||
{
|
||||
var mods = new List<string>();
|
||||
while (!string.IsNullOrEmpty(mod))
|
||||
{
|
||||
mods.Add(mod);
|
||||
mod = Mod.AllMods[mod].Requires;
|
||||
}
|
||||
|
||||
Game.RunAfterTick(() =>
|
||||
{
|
||||
Widget.CloseWindow();
|
||||
onSwitch();
|
||||
Game.InitializeWithMods(mods.ToArray());
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -38,13 +38,12 @@ namespace OpenRA.Mods.RA.Widgets.Delegates
|
||||
public static void DisplayModSelector()
|
||||
{
|
||||
var selector = Game.modData.WidgetLoader.LoadWidget( new WidgetArgs(), Widget.RootWidget, "QUICKMODSWITCHER" );
|
||||
var switcher = selector.GetWidget<ButtonWidget>("SWITCHER");
|
||||
var switcher = selector.GetWidget<DropDownButtonWidget>("SWITCHER");
|
||||
switcher.OnMouseDown = _ => ShowModsDropDown(switcher);
|
||||
switcher.GetText = ActiveModTitle;
|
||||
selector.GetWidget<LabelWidget>("VERSION").GetText = ActiveModVersion;
|
||||
}
|
||||
|
||||
|
||||
static string ActiveModTitle()
|
||||
{
|
||||
var mod = Game.modData.Manifest.Mods[0];
|
||||
@@ -57,37 +56,36 @@ namespace OpenRA.Mods.RA.Widgets.Delegates
|
||||
return Mod.AllMods[mod].Version;
|
||||
}
|
||||
|
||||
static bool ShowModsDropDown(ButtonWidget selector)
|
||||
static void LoadMod(string mod)
|
||||
{
|
||||
var dropDownOptions = new List<Pair<string, Action>>();
|
||||
|
||||
foreach (var kv in Mod.AllMods)
|
||||
var mods = new List<string>();
|
||||
while (!string.IsNullOrEmpty(mod))
|
||||
{
|
||||
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,
|
||||
() =>
|
||||
{
|
||||
if (Game.CurrentMods.Keys.ToArray().SymmetricDifference(modList.ToArray()).Any())
|
||||
Game.RunAfterTick(() => Game.InitializeWithMods( modList.ToArray() ) );
|
||||
}
|
||||
));
|
||||
mods.Add(mod);
|
||||
mod = Mod.AllMods[mod].Requires;
|
||||
}
|
||||
|
||||
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; },
|
||||
});
|
||||
|
||||
if (!Game.CurrentMods.Keys.ToArray().SymmetricDifference(mods.ToArray()).Any())
|
||||
return;
|
||||
|
||||
Game.RunAfterTick(() =>
|
||||
{
|
||||
Game.InitializeWithMods(mods.ToArray());
|
||||
});
|
||||
}
|
||||
|
||||
static bool ShowModsDropDown(DropDownButtonWidget dropdown)
|
||||
{
|
||||
Func<string, ScrollItemWidget, ScrollItemWidget> setupItem = (m, itemTemplate) =>
|
||||
{
|
||||
var item = ScrollItemWidget.Setup(itemTemplate,
|
||||
() => m == Game.CurrentMods.Keys.First(),
|
||||
() => LoadMod(m));
|
||||
item.GetWidget<LabelWidget>("LABEL").GetText = () => Mod.AllMods[m].Title;
|
||||
return item;
|
||||
};
|
||||
|
||||
dropdown.ShowDropDown("LABEL_DROPDOWN_TEMPLATE", 150, Mod.AllMods.Keys.ToList(), setupItem);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user