From d472805fc68aa8601efac43b1534d6f89a04749f Mon Sep 17 00:00:00 2001 From: Pavel Penev Date: Mon, 31 Aug 2015 17:25:18 +0300 Subject: [PATCH] Add mod asset checks to ModBrowserLogic --- OpenRA.Game/ModMetadata.cs | 33 ++++++++---- .../Widgets/Logic/ModBrowserLogic.cs | 52 ++++++++++++++----- mods/cnc/mod.yaml | 2 - mods/d2k/mod.yaml | 1 - mods/modchooser/mod.yaml | 1 - mods/ra/mod.yaml | 1 - mods/ts/mod.yaml | 1 - 7 files changed, 63 insertions(+), 28 deletions(-) diff --git a/OpenRA.Game/ModMetadata.cs b/OpenRA.Game/ModMetadata.cs index a3430d319a..72222a6f21 100644 --- a/OpenRA.Game/ModMetadata.cs +++ b/OpenRA.Game/ModMetadata.cs @@ -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 ValidateMods() { @@ -34,19 +36,30 @@ namespace OpenRA var ret = new Dictionary(); 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(nd["Metadata"]); - mod.Id = m; + var mod = FieldLoader.Load(nd["Metadata"]); + mod.Id = m; - ret.Add(m, mod); + if (nd.ContainsKey("ContentInstaller")) + mod.Content = FieldLoader.Load(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; diff --git a/OpenRA.Mods.Common/Widgets/Logic/ModBrowserLogic.cs b/OpenRA.Mods.Common/Widgets/Logic/ModBrowserLogic.cs index 7672102c1c..ca5af451db 100644 --- a/OpenRA.Mods.Common/Widgets/Logic/ModBrowserLogic.cs +++ b/OpenRA.Mods.Common/Widgets/Logic/ModBrowserLogic.cs @@ -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 previews = new Dictionary(); readonly Dictionary logos = new Dictionary(); + readonly Cache 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("LOAD_BUTTON"); + modChooserPanel = widget; + loadButton = modChooserPanel.Get("LOAD_BUTTON"); loadButton.OnClick = () => LoadMod(selectedMod); loadButton.IsDisabled = () => selectedMod.Id == Game.ModData.Manifest.Mod.Id; - panel.Get("QUIT_BUTTON").OnClick = Game.Exit; + modChooserPanel.Get("QUIT_BUTTON").OnClick = Game.Exit; - modList = panel.Get("MOD_LIST"); + modList = modChooserPanel.Get("MOD_LIST"); modTemplate = modList.Get("MOD_TEMPLATE"); - panel.Get("MOD_DESC").GetText = () => selectedDescription; - panel.Get("MOD_TITLE").GetText = () => selectedMod.Title; - panel.Get("MOD_AUTHOR").GetText = () => selectedAuthor; - panel.Get("MOD_VERSION").GetText = () => selectedMod.Version; + modChooserPanel.Get("MOD_DESC").GetText = () => selectedDescription; + modChooserPanel.Get("MOD_TITLE").GetText = () => selectedMod.Title; + modChooserPanel.Get("MOD_AUTHOR").GetText = () => selectedAuthor; + modChooserPanel.Get("MOD_VERSION").GetText = () => selectedMod.Version; - var prevMod = panel.Get("PREV_MOD"); + var prevMod = modChooserPanel.Get("PREV_MOD"); prevMod.OnClick = () => { modOffset -= 1; RebuildModList(); }; prevMod.IsVisible = () => modOffset > 0; - var nextMod = panel.Get("NEXT_MOD"); + var nextMod = modChooserPanel.Get("NEXT_MOD"); nextMod.OnClick = () => { modOffset += 1; RebuildModList(); }; nextMod.IsVisible = () => modOffset + 5 < allMods.Length; - panel.Get("MOD_PREVIEW").GetSprite = () => + modChooserPanel.Get("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(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)))); + } } } diff --git a/mods/cnc/mod.yaml b/mods/cnc/mod.yaml index a19b2c892a..11a2f510a3 100644 --- a/mods/cnc/mod.yaml +++ b/mods/cnc/mod.yaml @@ -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 diff --git a/mods/d2k/mod.yaml b/mods/d2k/mod.yaml index d72d9ab63f..a9aabe792d 100644 --- a/mods/d2k/mod.yaml +++ b/mods/d2k/mod.yaml @@ -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 diff --git a/mods/modchooser/mod.yaml b/mods/modchooser/mod.yaml index 1811c45686..dee26ab27f 100644 --- a/mods/modchooser/mod.yaml +++ b/mods/modchooser/mod.yaml @@ -8,7 +8,6 @@ Folders: . ./mods/modchooser - Cursors: ./mods/modchooser/cursors.yaml diff --git a/mods/ra/mod.yaml b/mods/ra/mod.yaml index 0c387cb8cc..742cc47016 100644 --- a/mods/ra/mod.yaml +++ b/mods/ra/mod.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 diff --git a/mods/ts/mod.yaml b/mods/ts/mod.yaml index 352ad2e585..18f85c941c 100644 --- a/mods/ts/mod.yaml +++ b/mods/ts/mod.yaml @@ -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