Add mod asset checks to ModBrowserLogic

This commit is contained in:
Pavel Penev
2015-08-31 17:25:18 +03:00
parent 4314fae77a
commit d472805fc6
7 changed files with 63 additions and 28 deletions

View File

@@ -8,6 +8,7 @@
*/ */
#endregion #endregion
using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.IO; using System.IO;
using System.Linq; using System.Linq;
@@ -24,6 +25,7 @@ namespace OpenRA
public string Version; public string Version;
public string Author; public string Author;
public bool Hidden; public bool Hidden;
public ContentInstaller Content;
static Dictionary<string, ModMetadata> ValidateMods() static Dictionary<string, ModMetadata> ValidateMods()
{ {
@@ -34,19 +36,30 @@ namespace OpenRA
var ret = new Dictionary<string, ModMetadata>(); var ret = new Dictionary<string, ModMetadata>();
foreach (var m in mods) foreach (var m in mods)
{ {
var yamlPath = Platform.ResolvePath(".", "mods", m, "mod.yaml"); try
if (!File.Exists(yamlPath)) {
continue; var yamlPath = Platform.ResolvePath(".", "mods", m, "mod.yaml");
if (!File.Exists(yamlPath))
continue;
var yaml = new MiniYaml(null, MiniYaml.FromFile(yamlPath)); var yaml = new MiniYaml(null, MiniYaml.FromFile(yamlPath));
var nd = yaml.ToDictionary(); var nd = yaml.ToDictionary();
if (!nd.ContainsKey("Metadata")) if (!nd.ContainsKey("Metadata"))
continue; continue;
var mod = FieldLoader.Load<ModMetadata>(nd["Metadata"]); var mod = FieldLoader.Load<ModMetadata>(nd["Metadata"]);
mod.Id = m; 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; return ret;

View File

@@ -13,7 +13,9 @@ using System.Collections.Generic;
using System.Drawing; using System.Drawing;
using System.IO; using System.IO;
using System.Linq; using System.Linq;
using OpenRA.FileSystem;
using OpenRA.Graphics; using OpenRA.Graphics;
using OpenRA.Primitives;
using OpenRA.Widgets; using OpenRA.Widgets;
namespace OpenRA.Mods.Common.Widgets.Logic namespace OpenRA.Mods.Common.Widgets.Logic
@@ -25,6 +27,9 @@ namespace OpenRA.Mods.Common.Widgets.Logic
readonly ModMetadata[] allMods; readonly ModMetadata[] allMods;
readonly Dictionary<string, Sprite> previews = new Dictionary<string, Sprite>(); readonly Dictionary<string, Sprite> previews = new Dictionary<string, Sprite>();
readonly Dictionary<string, Sprite> logos = 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; readonly SheetBuilder sheetBuilder;
ModMetadata selectedMod; ModMetadata selectedMod;
string selectedAuthor; string selectedAuthor;
@@ -34,30 +39,30 @@ namespace OpenRA.Mods.Common.Widgets.Logic
[ObjectCreator.UseCtor] [ObjectCreator.UseCtor]
public ModBrowserLogic(Widget widget) public ModBrowserLogic(Widget widget)
{ {
var panel = widget; modChooserPanel = widget;
var loadButton = panel.Get<ButtonWidget>("LOAD_BUTTON"); loadButton = modChooserPanel.Get<ButtonWidget>("LOAD_BUTTON");
loadButton.OnClick = () => LoadMod(selectedMod); loadButton.OnClick = () => LoadMod(selectedMod);
loadButton.IsDisabled = () => selectedMod.Id == Game.ModData.Manifest.Mod.Id; 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"); modTemplate = modList.Get<ButtonWidget>("MOD_TEMPLATE");
panel.Get<LabelWidget>("MOD_DESC").GetText = () => selectedDescription; modChooserPanel.Get<LabelWidget>("MOD_DESC").GetText = () => selectedDescription;
panel.Get<LabelWidget>("MOD_TITLE").GetText = () => selectedMod.Title; modChooserPanel.Get<LabelWidget>("MOD_TITLE").GetText = () => selectedMod.Title;
panel.Get<LabelWidget>("MOD_AUTHOR").GetText = () => selectedAuthor; modChooserPanel.Get<LabelWidget>("MOD_AUTHOR").GetText = () => selectedAuthor;
panel.Get<LabelWidget>("MOD_VERSION").GetText = () => selectedMod.Version; 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.OnClick = () => { modOffset -= 1; RebuildModList(); };
prevMod.IsVisible = () => modOffset > 0; prevMod.IsVisible = () => modOffset > 0;
var nextMod = panel.Get<ButtonWidget>("NEXT_MOD"); var nextMod = modChooserPanel.Get<ButtonWidget>("NEXT_MOD");
nextMod.OnClick = () => { modOffset += 1; RebuildModList(); }; nextMod.OnClick = () => { modOffset += 1; RebuildModList(); };
nextMod.IsVisible = () => modOffset + 5 < allMods.Length; nextMod.IsVisible = () => modOffset + 5 < allMods.Length;
panel.Get<RGBASpriteWidget>("MOD_PREVIEW").GetSprite = () => modChooserPanel.Get<RGBASpriteWidget>("MOD_PREVIEW").GetSprite = () =>
{ {
Sprite ret = null; Sprite ret = null;
previews.TryGetValue(selectedMod.Id, out ret); previews.TryGetValue(selectedMod.Id, out ret);
@@ -89,9 +94,11 @@ namespace OpenRA.Mods.Common.Widgets.Logic
catch (Exception) { } catch (Exception) { }
} }
modInstallStatus = new Cache<ModMetadata, bool>(IsModInstalled);
ModMetadata initialMod = null; ModMetadata initialMod = null;
ModMetadata.AllMods.TryGetValue(Game.Settings.Game.PreviousMod, out initialMod); 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(); RebuildModList();
} }
@@ -113,6 +120,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
break; break;
var mod = allMods[j]; var mod = allMods[j];
var item = modTemplate.Clone() as ButtonWidget; var item = modTemplate.Clone() as ButtonWidget;
item.Bounds = new Rectangle(outerMargin + i * stride, 0, width, height); item.Bounds = new Rectangle(outerMargin + i * stride, 0, width, height);
item.IsHighlighted = () => selectedMod == mod; item.IsHighlighted = () => selectedMod == mod;
@@ -148,10 +156,25 @@ namespace OpenRA.Mods.Common.Widgets.Logic
var selectedIndex = Array.IndexOf(allMods, mod); var selectedIndex = Array.IndexOf(allMods, mod);
if (selectedIndex - modOffset > 4) if (selectedIndex - modOffset > 4)
modOffset = selectedIndex - 4; modOffset = selectedIndex - 4;
loadButton.Text = modInstallStatus[mod] ? "Load Mod" : "Install Assets";
} }
void LoadMod(ModMetadata mod) 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(() => Game.RunAfterTick(() =>
{ {
Ui.CloseWindow(); Ui.CloseWindow();
@@ -159,5 +182,10 @@ namespace OpenRA.Mods.Common.Widgets.Logic
Game.InitializeMod(mod.Id, null); Game.InitializeMod(mod.Id, null);
}); });
} }
static bool IsModInstalled(ModMetadata mod)
{
return mod.Content.TestFiles.All(file => File.Exists(Path.GetFullPath(Platform.ResolvePath(file))));
}
} }
} }

View File

@@ -140,8 +140,6 @@ LoadScreen: CncLoadScreen
ContentInstaller: ContentInstaller:
TestFiles: conquer.mix, desert.mix, sounds.mix, speech.mix, temperat.mix, tempicnh.mix, winter.mix 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 MusicMenuWidget: INSTALL_MUSIC_PANEL
FilesToCopy: CONQUER.MIX, DESERT.MIX, SCORES.MIX, SOUNDS.MIX, TEMPERAT.MIX, WINTER.MIX FilesToCopy: CONQUER.MIX, DESERT.MIX, SCORES.MIX, SOUNDS.MIX, TEMPERAT.MIX, WINTER.MIX
FilesToExtract: speech.mix, tempicnh.mix, transit.mix FilesToExtract: speech.mix, tempicnh.mix, transit.mix

View File

@@ -123,7 +123,6 @@ LoadScreen: LogoStripeLoadScreen
Text: Filling Crates..., Breeding Sandworms..., Fuelling carryalls..., Deploying harvesters..., Preparing 'thopters..., Summoning mentats... Text: Filling Crates..., Breeding Sandworms..., Fuelling carryalls..., Deploying harvesters..., Preparing 'thopters..., Summoning mentats...
ContentInstaller: ContentInstaller:
MenuWidget: INSTALL_PANEL
MusicMenuWidget: INSTALL_MUSIC_PANEL MusicMenuWidget: INSTALL_MUSIC_PANEL
# TODO: check if DATA.R8 is at 1.03 patch level with 4840 frames # 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 TestFiles: BLOXBASE.R8, BLOXBAT.R8, BLOXBGBS.R8, BLOXICE.R8, BLOXTREE.R8, BLOXWAST.R8, DATA.R8, SOUND.RS

View File

@@ -8,7 +8,6 @@ Folders:
. .
./mods/modchooser ./mods/modchooser
Cursors: Cursors:
./mods/modchooser/cursors.yaml ./mods/modchooser/cursors.yaml

View File

@@ -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... Text: Filling Crates..., Charging Capacitors..., Reticulating Splines..., Planting Trees..., Building Bridges..., Aging Empires..., Compiling EVA..., Constructing Pylons..., Activating Skynet..., Splitting Atoms...
ContentInstaller: ContentInstaller:
MenuWidget: INSTALL_PANEL
MusicMenuWidget: INSTALL_MUSIC_PANEL MusicMenuWidget: INSTALL_MUSIC_PANEL
TestFiles: allies.mix, conquer.mix, interior.mix, redalert.mix, russian.mix, snow.mix, sounds.mix, temperat.mix 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 PackageMirrorList: http://www.openra.net/packages/ra-mirrors.txt

View File

@@ -189,7 +189,6 @@ LoadScreen: LogoStripeLoadScreen
Text: Updating EVA installation..., Changing perspective... Text: Updating EVA installation..., Changing perspective...
ContentInstaller: ContentInstaller:
MenuWidget: INSTALL_PANEL
MusicMenuWidget: INSTALL_MUSIC_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 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 PackageMirrorList: http://www.openra.net/packages/ts-mirrors.txt