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 panel = widget.GetWidget("MODS_PANEL");
|
||||||
var modList = panel.GetWidget<ScrollPanelWidget>("MOD_LIST");
|
var modList = panel.GetWidget<ScrollPanelWidget>("MOD_LIST");
|
||||||
var loadButton = panel.GetWidget<ButtonWidget>("LOAD_BUTTON");
|
var loadButton = panel.GetWidget<ButtonWidget>("LOAD_BUTTON");
|
||||||
loadButton.OnClick = () =>
|
loadButton.OnClick = () => LoadMod(currentMod.Id, onSwitch);
|
||||||
{
|
|
||||||
// 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.IsDisabled = () => currentMod.Id == Game.CurrentMods.Keys.First();
|
loadButton.IsDisabled = () => currentMod.Id == Game.CurrentMods.Keys.First();
|
||||||
|
|
||||||
panel.GetWidget<ButtonWidget>("BACK_BUTTON").OnClick = () => { Widget.CloseWindow(); onExit(); };
|
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;
|
item.GetWidget<LabelWidget>("AUTHOR").GetText = () => mod.Author;
|
||||||
modList.AddChild(item);
|
modList.AddChild(item);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
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(() =>
|
||||||
// Server info
|
{
|
||||||
var infoPanel = panel.GetWidget("SERVER_INFO");
|
Widget.CloseWindow();
|
||||||
infoPanel.IsVisible = () => currentServer != null;
|
onSwitch();
|
||||||
infoPanel.GetWidget<LabelWidget>("SERVER_IP").GetText = () => currentServer.Address;
|
Game.InitializeWithMods(mods.ToArray());
|
||||||
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);
|
|
||||||
*/
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -38,13 +38,12 @@ namespace OpenRA.Mods.RA.Widgets.Delegates
|
|||||||
public static void DisplayModSelector()
|
public static void DisplayModSelector()
|
||||||
{
|
{
|
||||||
var selector = Game.modData.WidgetLoader.LoadWidget( new WidgetArgs(), Widget.RootWidget, "QUICKMODSWITCHER" );
|
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.OnMouseDown = _ => ShowModsDropDown(switcher);
|
||||||
switcher.GetText = ActiveModTitle;
|
switcher.GetText = ActiveModTitle;
|
||||||
selector.GetWidget<LabelWidget>("VERSION").GetText = ActiveModVersion;
|
selector.GetWidget<LabelWidget>("VERSION").GetText = ActiveModVersion;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static string ActiveModTitle()
|
static string ActiveModTitle()
|
||||||
{
|
{
|
||||||
var mod = Game.modData.Manifest.Mods[0];
|
var mod = Game.modData.Manifest.Mods[0];
|
||||||
@@ -57,37 +56,36 @@ namespace OpenRA.Mods.RA.Widgets.Delegates
|
|||||||
return Mod.AllMods[mod].Version;
|
return Mod.AllMods[mod].Version;
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool ShowModsDropDown(ButtonWidget selector)
|
static void LoadMod(string mod)
|
||||||
{
|
{
|
||||||
var dropDownOptions = new List<Pair<string, Action>>();
|
var mods = new List<string>();
|
||||||
|
while (!string.IsNullOrEmpty(mod))
|
||||||
foreach (var kv in Mod.AllMods)
|
|
||||||
{
|
{
|
||||||
var modList = new List<string>() { kv.Key };
|
mods.Add(mod);
|
||||||
var m = kv.Key;
|
mod = Mod.AllMods[mod].Requires;
|
||||||
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(mods.ToArray()).Any())
|
||||||
() =>
|
return;
|
||||||
{
|
|
||||||
if (Game.CurrentMods.Keys.ToArray().SymmetricDifference(modList.ToArray()).Any())
|
|
||||||
Game.RunAfterTick(() => Game.InitializeWithMods( modList.ToArray() ) );
|
|
||||||
}
|
|
||||||
));
|
|
||||||
}
|
|
||||||
|
|
||||||
DropDownButtonWidget.ShowDropDown( selector,
|
Game.RunAfterTick(() =>
|
||||||
dropDownOptions,
|
|
||||||
(ac, w) => new LabelWidget
|
|
||||||
{
|
{
|
||||||
Bounds = new Rectangle(0, 0, w, 24),
|
Game.InitializeWithMods(mods.ToArray());
|
||||||
Text = " {0}".F(ac.First),
|
|
||||||
OnMouseUp = mi => { ac.Second(); return true; },
|
|
||||||
});
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
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;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user