Add mod asset checks to ModBrowserLogic
This commit is contained in:
@@ -8,6 +8,7 @@
|
||||
*/
|
||||
#endregion
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
@@ -24,6 +25,7 @@ namespace OpenRA
|
||||
public string Version;
|
||||
public string Author;
|
||||
public bool Hidden;
|
||||
public ContentInstaller Content;
|
||||
|
||||
static Dictionary<string, ModMetadata> ValidateMods()
|
||||
{
|
||||
@@ -34,19 +36,30 @@ namespace OpenRA
|
||||
var ret = new Dictionary<string, ModMetadata>();
|
||||
foreach (var m in mods)
|
||||
{
|
||||
var yamlPath = Platform.ResolvePath(".", "mods", m, "mod.yaml");
|
||||
if (!File.Exists(yamlPath))
|
||||
continue;
|
||||
try
|
||||
{
|
||||
var yamlPath = Platform.ResolvePath(".", "mods", m, "mod.yaml");
|
||||
if (!File.Exists(yamlPath))
|
||||
continue;
|
||||
|
||||
var yaml = new MiniYaml(null, MiniYaml.FromFile(yamlPath));
|
||||
var nd = yaml.ToDictionary();
|
||||
if (!nd.ContainsKey("Metadata"))
|
||||
continue;
|
||||
var yaml = new MiniYaml(null, MiniYaml.FromFile(yamlPath));
|
||||
var nd = yaml.ToDictionary();
|
||||
if (!nd.ContainsKey("Metadata"))
|
||||
continue;
|
||||
|
||||
var mod = FieldLoader.Load<ModMetadata>(nd["Metadata"]);
|
||||
mod.Id = m;
|
||||
var mod = FieldLoader.Load<ModMetadata>(nd["Metadata"]);
|
||||
mod.Id = m;
|
||||
|
||||
ret.Add(m, mod);
|
||||
if (nd.ContainsKey("ContentInstaller"))
|
||||
mod.Content = FieldLoader.Load<ContentInstaller>(nd["ContentInstaller"]);
|
||||
|
||||
ret.Add(m, mod);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Console.WriteLine("An exception occured when trying to load ModMetadata for `{0}`:".F(m));
|
||||
Console.WriteLine(ex.Message);
|
||||
}
|
||||
}
|
||||
|
||||
return ret;
|
||||
|
||||
@@ -13,7 +13,9 @@ using System.Collections.Generic;
|
||||
using System.Drawing;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using OpenRA.FileSystem;
|
||||
using OpenRA.Graphics;
|
||||
using OpenRA.Primitives;
|
||||
using OpenRA.Widgets;
|
||||
|
||||
namespace OpenRA.Mods.Common.Widgets.Logic
|
||||
@@ -25,6 +27,9 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
||||
readonly ModMetadata[] allMods;
|
||||
readonly Dictionary<string, Sprite> previews = new Dictionary<string, Sprite>();
|
||||
readonly Dictionary<string, Sprite> logos = new Dictionary<string, Sprite>();
|
||||
readonly Cache<ModMetadata, bool> modInstallStatus;
|
||||
readonly Widget modChooserPanel;
|
||||
readonly ButtonWidget loadButton;
|
||||
readonly SheetBuilder sheetBuilder;
|
||||
ModMetadata selectedMod;
|
||||
string selectedAuthor;
|
||||
@@ -34,30 +39,30 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
||||
[ObjectCreator.UseCtor]
|
||||
public ModBrowserLogic(Widget widget)
|
||||
{
|
||||
var panel = widget;
|
||||
var loadButton = panel.Get<ButtonWidget>("LOAD_BUTTON");
|
||||
modChooserPanel = widget;
|
||||
loadButton = modChooserPanel.Get<ButtonWidget>("LOAD_BUTTON");
|
||||
loadButton.OnClick = () => LoadMod(selectedMod);
|
||||
loadButton.IsDisabled = () => selectedMod.Id == Game.ModData.Manifest.Mod.Id;
|
||||
|
||||
panel.Get<ButtonWidget>("QUIT_BUTTON").OnClick = Game.Exit;
|
||||
modChooserPanel.Get<ButtonWidget>("QUIT_BUTTON").OnClick = Game.Exit;
|
||||
|
||||
modList = panel.Get("MOD_LIST");
|
||||
modList = modChooserPanel.Get("MOD_LIST");
|
||||
modTemplate = modList.Get<ButtonWidget>("MOD_TEMPLATE");
|
||||
|
||||
panel.Get<LabelWidget>("MOD_DESC").GetText = () => selectedDescription;
|
||||
panel.Get<LabelWidget>("MOD_TITLE").GetText = () => selectedMod.Title;
|
||||
panel.Get<LabelWidget>("MOD_AUTHOR").GetText = () => selectedAuthor;
|
||||
panel.Get<LabelWidget>("MOD_VERSION").GetText = () => selectedMod.Version;
|
||||
modChooserPanel.Get<LabelWidget>("MOD_DESC").GetText = () => selectedDescription;
|
||||
modChooserPanel.Get<LabelWidget>("MOD_TITLE").GetText = () => selectedMod.Title;
|
||||
modChooserPanel.Get<LabelWidget>("MOD_AUTHOR").GetText = () => selectedAuthor;
|
||||
modChooserPanel.Get<LabelWidget>("MOD_VERSION").GetText = () => selectedMod.Version;
|
||||
|
||||
var prevMod = panel.Get<ButtonWidget>("PREV_MOD");
|
||||
var prevMod = modChooserPanel.Get<ButtonWidget>("PREV_MOD");
|
||||
prevMod.OnClick = () => { modOffset -= 1; RebuildModList(); };
|
||||
prevMod.IsVisible = () => modOffset > 0;
|
||||
|
||||
var nextMod = panel.Get<ButtonWidget>("NEXT_MOD");
|
||||
var nextMod = modChooserPanel.Get<ButtonWidget>("NEXT_MOD");
|
||||
nextMod.OnClick = () => { modOffset += 1; RebuildModList(); };
|
||||
nextMod.IsVisible = () => modOffset + 5 < allMods.Length;
|
||||
|
||||
panel.Get<RGBASpriteWidget>("MOD_PREVIEW").GetSprite = () =>
|
||||
modChooserPanel.Get<RGBASpriteWidget>("MOD_PREVIEW").GetSprite = () =>
|
||||
{
|
||||
Sprite ret = null;
|
||||
previews.TryGetValue(selectedMod.Id, out ret);
|
||||
@@ -89,9 +94,11 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
||||
catch (Exception) { }
|
||||
}
|
||||
|
||||
modInstallStatus = new Cache<ModMetadata, bool>(IsModInstalled);
|
||||
|
||||
ModMetadata initialMod = null;
|
||||
ModMetadata.AllMods.TryGetValue(Game.Settings.Game.PreviousMod, out initialMod);
|
||||
SelectMod(initialMod ?? ModMetadata.AllMods["ra"]);
|
||||
SelectMod(initialMod != null && initialMod.Id != "modchooser" ? initialMod : ModMetadata.AllMods["ra"]);
|
||||
|
||||
RebuildModList();
|
||||
}
|
||||
@@ -113,6 +120,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
||||
break;
|
||||
|
||||
var mod = allMods[j];
|
||||
|
||||
var item = modTemplate.Clone() as ButtonWidget;
|
||||
item.Bounds = new Rectangle(outerMargin + i * stride, 0, width, height);
|
||||
item.IsHighlighted = () => selectedMod == mod;
|
||||
@@ -148,10 +156,25 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
||||
var selectedIndex = Array.IndexOf(allMods, mod);
|
||||
if (selectedIndex - modOffset > 4)
|
||||
modOffset = selectedIndex - 4;
|
||||
|
||||
loadButton.Text = modInstallStatus[mod] ? "Load Mod" : "Install Assets";
|
||||
}
|
||||
|
||||
void LoadMod(ModMetadata mod)
|
||||
{
|
||||
if (!modInstallStatus[mod])
|
||||
{
|
||||
var widgetArgs = new WidgetArgs
|
||||
{
|
||||
{ "continueLoading", () =>
|
||||
Game.RunAfterTick(() => Game.InitializeMod(Game.Settings.Game.Mod, new Arguments())) }
|
||||
};
|
||||
|
||||
Ui.OpenWindow("INSTALL_PANEL", widgetArgs);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
Game.RunAfterTick(() =>
|
||||
{
|
||||
Ui.CloseWindow();
|
||||
@@ -159,5 +182,10 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
||||
Game.InitializeMod(mod.Id, null);
|
||||
});
|
||||
}
|
||||
|
||||
static bool IsModInstalled(ModMetadata mod)
|
||||
{
|
||||
return mod.Content.TestFiles.All(file => File.Exists(Path.GetFullPath(Platform.ResolvePath(file))));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -140,8 +140,6 @@ LoadScreen: CncLoadScreen
|
||||
|
||||
ContentInstaller:
|
||||
TestFiles: conquer.mix, desert.mix, sounds.mix, speech.mix, temperat.mix, tempicnh.mix, winter.mix
|
||||
BackgroundWidget: INSTALL_BACKGROUND
|
||||
MenuWidget: INSTALL_PANEL
|
||||
MusicMenuWidget: INSTALL_MUSIC_PANEL
|
||||
FilesToCopy: CONQUER.MIX, DESERT.MIX, SCORES.MIX, SOUNDS.MIX, TEMPERAT.MIX, WINTER.MIX
|
||||
FilesToExtract: speech.mix, tempicnh.mix, transit.mix
|
||||
|
||||
@@ -123,7 +123,6 @@ LoadScreen: LogoStripeLoadScreen
|
||||
Text: Filling Crates..., Breeding Sandworms..., Fuelling carryalls..., Deploying harvesters..., Preparing 'thopters..., Summoning mentats...
|
||||
|
||||
ContentInstaller:
|
||||
MenuWidget: INSTALL_PANEL
|
||||
MusicMenuWidget: INSTALL_MUSIC_PANEL
|
||||
# TODO: check if DATA.R8 is at 1.03 patch level with 4840 frames
|
||||
TestFiles: BLOXBASE.R8, BLOXBAT.R8, BLOXBGBS.R8, BLOXICE.R8, BLOXTREE.R8, BLOXWAST.R8, DATA.R8, SOUND.RS
|
||||
|
||||
@@ -8,7 +8,6 @@ Folders:
|
||||
.
|
||||
./mods/modchooser
|
||||
|
||||
|
||||
Cursors:
|
||||
./mods/modchooser/cursors.yaml
|
||||
|
||||
|
||||
@@ -141,7 +141,6 @@ LoadScreen: LogoStripeLoadScreen
|
||||
Text: Filling Crates..., Charging Capacitors..., Reticulating Splines..., Planting Trees..., Building Bridges..., Aging Empires..., Compiling EVA..., Constructing Pylons..., Activating Skynet..., Splitting Atoms...
|
||||
|
||||
ContentInstaller:
|
||||
MenuWidget: INSTALL_PANEL
|
||||
MusicMenuWidget: INSTALL_MUSIC_PANEL
|
||||
TestFiles: allies.mix, conquer.mix, interior.mix, redalert.mix, russian.mix, snow.mix, sounds.mix, temperat.mix
|
||||
PackageMirrorList: http://www.openra.net/packages/ra-mirrors.txt
|
||||
|
||||
@@ -189,7 +189,6 @@ LoadScreen: LogoStripeLoadScreen
|
||||
Text: Updating EVA installation..., Changing perspective...
|
||||
|
||||
ContentInstaller:
|
||||
MenuWidget: INSTALL_PANEL
|
||||
MusicMenuWidget: INSTALL_MUSIC_PANEL
|
||||
TestFiles: cache.mix, conquer.mix, isosnow.mix, isotemp.mix, local.mix, sidec01.mix, sidec02.mix, sno.mix, snow.mix, sounds.mix, speech01.mix, tem.mix, temperat.mix
|
||||
PackageMirrorList: http://www.openra.net/packages/ts-mirrors.txt
|
||||
|
||||
Reference in New Issue
Block a user