Rework mod content installation.
This commit is contained in:
@@ -235,7 +235,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
||||
{
|
||||
using (var stream = File.OpenRead(file))
|
||||
{
|
||||
var packageLoader = download.ObjectCreator.CreateObject<IPackageLoader>($"{download.Type}Loader");
|
||||
var packageLoader = modData.ObjectCreator.CreateObject<IPackageLoader>($"{download.Type}Loader");
|
||||
|
||||
if (packageLoader.TryParsePackage(stream, file, modData.ModFiles, out var package))
|
||||
{
|
||||
|
||||
@@ -87,7 +87,6 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
||||
readonly ModData modData;
|
||||
readonly ModContent content;
|
||||
readonly Dictionary<string, ModContent.ModSource> sources;
|
||||
readonly FluentBundle externalFluentBundle;
|
||||
|
||||
readonly Widget panel;
|
||||
readonly LabelWidget titleLabel;
|
||||
@@ -118,12 +117,11 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
||||
|
||||
[ObjectCreator.UseCtor]
|
||||
public InstallFromSourceLogic(
|
||||
Widget widget, ModData modData, ModContent content, Dictionary<string, ModContent.ModSource> sources, FluentBundle externalFluentBundle)
|
||||
Widget widget, ModData modData, ModContent content, Dictionary<string, ModContent.ModSource> sources)
|
||||
{
|
||||
this.modData = modData;
|
||||
this.content = content;
|
||||
this.sources = sources;
|
||||
this.externalFluentBundle = externalFluentBundle;
|
||||
|
||||
Log.AddChannel("install", "install.log");
|
||||
|
||||
@@ -173,7 +171,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
||||
{
|
||||
message = FluentProvider.GetString(SearchingSourceFor, "title", kv.Value.Title);
|
||||
|
||||
var sourceResolver = kv.Value.ObjectCreator.CreateObject<ISourceResolver>($"{kv.Value.Type.Value}SourceResolver");
|
||||
var sourceResolver = modData.ObjectCreator.CreateObject<ISourceResolver>($"{kv.Value.Type.Value}SourceResolver");
|
||||
|
||||
var path = sourceResolver.FindSourcePath(kv.Value);
|
||||
if (path != null)
|
||||
@@ -210,7 +208,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
||||
|
||||
foreach (var source in missingSources)
|
||||
{
|
||||
var sourceResolver = source.ObjectCreator.CreateObject<ISourceResolver>($"{source.Type.Value}SourceResolver");
|
||||
var sourceResolver = modData.ObjectCreator.CreateObject<ISourceResolver>($"{source.Type.Value}SourceResolver");
|
||||
|
||||
var availability = sourceResolver.GetAvailability();
|
||||
|
||||
@@ -260,7 +258,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
||||
var split = key.IndexOf('@');
|
||||
if (split != -1)
|
||||
key = key[..split];
|
||||
var sourceAction = modSource.ObjectCreator.CreateObject<ISourceAction>($"{key}SourceAction");
|
||||
var sourceAction = modData.ObjectCreator.CreateObject<ISourceAction>($"{key}SourceAction");
|
||||
sourceAction.RunActionOnSource(sourceActionNode.Value, path, modData, extracted, m => message = m);
|
||||
}
|
||||
}
|
||||
@@ -342,7 +340,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
||||
{
|
||||
var containerWidget = (ContainerWidget)checkboxListTemplate.Clone();
|
||||
var checkboxWidget = containerWidget.Get<CheckboxWidget>("PACKAGE_CHECKBOX");
|
||||
var title = externalFluentBundle.GetString(package.Title);
|
||||
var title = FluentProvider.GetString(package.Title);
|
||||
checkboxWidget.GetText = () => title;
|
||||
checkboxWidget.IsDisabled = () => package.Required;
|
||||
checkboxWidget.IsChecked = () => selectedPackages[package.Identifier];
|
||||
|
||||
@@ -13,13 +13,47 @@ using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using OpenRA.FileSystem;
|
||||
using OpenRA.Widgets;
|
||||
using FS = OpenRA.FileSystem.FileSystem;
|
||||
|
||||
namespace OpenRA.Mods.Common.Widgets.Logic
|
||||
{
|
||||
public class ModContentLogic : ChromeLogic
|
||||
{
|
||||
[ObjectCreator.UseCtor]
|
||||
public ModContentLogic(ModData modData)
|
||||
{
|
||||
var content = modData.Manifest.Get<ModContent>();
|
||||
if (!IsModInstalled(content))
|
||||
{
|
||||
var widgetArgs = new WidgetArgs
|
||||
{
|
||||
{ "continueLoading", () => Game.RunAfterTick(() => Game.InitializeMod(content.Mod, new Arguments())) },
|
||||
{ "content", content },
|
||||
};
|
||||
|
||||
Ui.OpenWindow("CONTENT_PROMPT_PANEL", widgetArgs);
|
||||
}
|
||||
else
|
||||
{
|
||||
var widgetArgs = new WidgetArgs
|
||||
{
|
||||
{ "onCancel", () => Game.RunAfterTick(() => Game.InitializeMod(content.Mod, new Arguments())) },
|
||||
{ "content", content },
|
||||
};
|
||||
|
||||
Ui.OpenWindow("CONTENT_PANEL", widgetArgs);
|
||||
}
|
||||
}
|
||||
|
||||
static bool IsModInstalled(ModContent content)
|
||||
{
|
||||
return content.Packages
|
||||
.Where(p => p.Value.Required)
|
||||
.All(p => p.Value.TestFiles.All(f => File.Exists(Platform.ResolvePath(f))));
|
||||
}
|
||||
}
|
||||
|
||||
public class ModContentInstallerLogic : ChromeLogic
|
||||
{
|
||||
[FluentReference]
|
||||
const string ManualInstall = "button-manual-install";
|
||||
@@ -31,56 +65,28 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
||||
readonly Dictionary<string, ModContent.ModSource> sources = new();
|
||||
readonly Dictionary<string, ModContent.ModDownload> downloads = new();
|
||||
|
||||
readonly FluentBundle externalFluentBundle;
|
||||
|
||||
bool sourceAvailable;
|
||||
|
||||
[ObjectCreator.UseCtor]
|
||||
public ModContentLogic(Widget widget, Manifest mod, ModContent content, Action onCancel, string translationFilePath)
|
||||
public ModContentInstallerLogic(ModData modData, Widget widget, ModContent content, Action onCancel)
|
||||
{
|
||||
this.content = content;
|
||||
|
||||
var panel = widget.Get("CONTENT_PANEL");
|
||||
|
||||
var modObjectCreator = new ObjectCreator(mod, Game.Mods);
|
||||
var modPackageLoaders = modObjectCreator.GetLoaders<IPackageLoader>(mod.PackageFormats, "package");
|
||||
var modFileSystem = new FS(mod.Id, Game.Mods, modPackageLoaders);
|
||||
|
||||
var modFileSystemLoader = modObjectCreator.GetLoader<IFileSystemLoader>(mod.FileSystem.Value, "filesystem");
|
||||
FieldLoader.Load(modFileSystemLoader, mod.FileSystem);
|
||||
modFileSystemLoader.Mount(modFileSystem, modObjectCreator);
|
||||
modFileSystem.TrimExcess();
|
||||
|
||||
var sourceYaml = MiniYaml.Load(modFileSystem, content.Sources, null);
|
||||
var sourceYaml = MiniYaml.Load(modData.DefaultFileSystem, content.Sources, null);
|
||||
foreach (var s in sourceYaml)
|
||||
sources.Add(s.Key, new ModContent.ModSource(s.Value, modObjectCreator));
|
||||
sources.Add(s.Key, new ModContent.ModSource(s.Value));
|
||||
|
||||
var downloadYaml = MiniYaml.Load(modFileSystem, content.Downloads, null);
|
||||
var downloadYaml = MiniYaml.Load(modData.DefaultFileSystem, content.Downloads, null);
|
||||
foreach (var d in downloadYaml)
|
||||
downloads.Add(d.Key, new ModContent.ModDownload(d.Value, modObjectCreator));
|
||||
|
||||
modFileSystem.UnmountAll();
|
||||
|
||||
externalFluentBundle = new FluentBundle(Game.Settings.Player.Language, File.ReadAllText(translationFilePath), _ => { });
|
||||
downloads.Add(d.Key, new ModContent.ModDownload(d.Value));
|
||||
|
||||
scrollPanel = panel.Get<ScrollPanelWidget>("PACKAGES");
|
||||
template = scrollPanel.Get<ContainerWidget>("PACKAGE_TEMPLATE");
|
||||
|
||||
var headerTemplate = panel.Get<LabelWidget>("HEADER_TEMPLATE");
|
||||
var headerLines =
|
||||
!string.IsNullOrEmpty(content.HeaderMessage)
|
||||
? externalFluentBundle.GetString(content.HeaderMessage)
|
||||
: null;
|
||||
var headerHeight = 0;
|
||||
if (headerLines != null)
|
||||
{
|
||||
var label = (LabelWidget)headerTemplate.Clone();
|
||||
label.GetText = () => headerLines;
|
||||
label.IncreaseHeightToFitCurrentText();
|
||||
panel.AddChild(label);
|
||||
|
||||
headerHeight += label.Bounds.Height;
|
||||
}
|
||||
var headerLabel = panel.Get<LabelWidget>("HEADER_LABEL");
|
||||
headerLabel.IncreaseHeightToFitCurrentText();
|
||||
var headerHeight = headerLabel.Bounds.Height;
|
||||
|
||||
panel.Bounds.Height += headerHeight;
|
||||
panel.Bounds.Y -= headerHeight / 2;
|
||||
@@ -94,7 +100,6 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
||||
{
|
||||
{ "sources", sources },
|
||||
{ "content", content },
|
||||
{ "externalFluentBundle", externalFluentBundle },
|
||||
});
|
||||
|
||||
var backButton = panel.Get<ButtonWidget>("BACK_BUTTON");
|
||||
@@ -118,7 +123,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
||||
{
|
||||
var container = template.Clone();
|
||||
var titleWidget = container.Get<LabelWidget>("TITLE");
|
||||
var title = externalFluentBundle.GetString(p.Value.Title);
|
||||
var title = FluentProvider.GetString(p.Value.Title);
|
||||
titleWidget.GetText = () => title;
|
||||
|
||||
var requiredWidget = container.Get<LabelWidget>("REQUIRED");
|
||||
|
||||
@@ -12,9 +12,7 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using OpenRA.FileSystem;
|
||||
using OpenRA.Widgets;
|
||||
using FS = OpenRA.FileSystem.FileSystem;
|
||||
|
||||
namespace OpenRA.Mods.Common.Widgets.Logic
|
||||
{
|
||||
@@ -27,36 +25,21 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
||||
const string Quit = "button-quit";
|
||||
|
||||
readonly ModContent content;
|
||||
readonly FluentBundle externalFluentBundle;
|
||||
bool requiredContentInstalled;
|
||||
|
||||
[ObjectCreator.UseCtor]
|
||||
public ModContentPromptLogic(ModData modData, Widget widget, Manifest mod, ModContent content, Action continueLoading, string translationFilePath)
|
||||
public ModContentPromptLogic(ModData modData, Widget widget, ModContent content, Action continueLoading)
|
||||
{
|
||||
this.content = content;
|
||||
CheckRequiredContentInstalled();
|
||||
|
||||
externalFluentBundle = new FluentBundle(Game.Settings.Player.Language, File.ReadAllText(translationFilePath), _ => { });
|
||||
|
||||
var continueMessage = FluentProvider.GetString(Continue);
|
||||
var quitMessage = FluentProvider.GetString(Quit);
|
||||
|
||||
var panel = widget.Get("CONTENT_PROMPT_PANEL");
|
||||
var headerTemplate = panel.Get<LabelWidget>("HEADER_TEMPLATE");
|
||||
var headerLines =
|
||||
!string.IsNullOrEmpty(content.InstallPromptMessage)
|
||||
? externalFluentBundle.GetString(content.InstallPromptMessage)
|
||||
: null;
|
||||
var headerHeight = 0;
|
||||
if (headerLines != null)
|
||||
{
|
||||
var label = (LabelWidget)headerTemplate.Clone();
|
||||
label.GetText = () => headerLines;
|
||||
label.IncreaseHeightToFitCurrentText();
|
||||
panel.AddChild(label);
|
||||
|
||||
headerHeight += label.Bounds.Height;
|
||||
}
|
||||
var headerLabel = panel.Get<LabelWidget>("HEADER_LABEL");
|
||||
headerLabel.IncreaseHeightToFitCurrentText();
|
||||
var headerHeight = headerLabel.Bounds.Height;
|
||||
|
||||
panel.Bounds.Height += headerHeight;
|
||||
panel.Bounds.Y -= headerHeight / 2;
|
||||
@@ -68,9 +51,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
||||
Ui.OpenWindow("CONTENT_PANEL", new WidgetArgs
|
||||
{
|
||||
{ "onCancel", CheckRequiredContentInstalled },
|
||||
{ "mod", mod },
|
||||
{ "content", content },
|
||||
{ "translationFilePath", translationFilePath },
|
||||
});
|
||||
};
|
||||
|
||||
@@ -79,25 +60,14 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
||||
quickButton.Bounds.Y += headerHeight;
|
||||
quickButton.OnClick = () =>
|
||||
{
|
||||
var modObjectCreator = new ObjectCreator(mod, Game.Mods);
|
||||
var modPackageLoaders = modObjectCreator.GetLoaders<IPackageLoader>(mod.PackageFormats, "package");
|
||||
var modFileSystem = new FS(mod.Id, Game.Mods, modPackageLoaders);
|
||||
|
||||
var modFileSystemLoader = modObjectCreator.GetLoader<IFileSystemLoader>(mod.FileSystem.Value, "filesystem");
|
||||
FieldLoader.Load(modFileSystemLoader, mod.FileSystem);
|
||||
modFileSystemLoader.Mount(modFileSystem, modObjectCreator);
|
||||
modFileSystem.TrimExcess();
|
||||
|
||||
var downloadYaml = MiniYaml.Load(modFileSystem, content.Downloads, null);
|
||||
modFileSystem.UnmountAll();
|
||||
|
||||
var downloadYaml = MiniYaml.Load(modData.DefaultFileSystem, content.Downloads, null);
|
||||
var download = downloadYaml.FirstOrDefault(n => n.Key == content.QuickDownload);
|
||||
if (download == null)
|
||||
throw new InvalidOperationException($"Mod QuickDownload `{content.QuickDownload}` definition not found.");
|
||||
|
||||
Ui.OpenWindow("PACKAGE_DOWNLOAD_PANEL", new WidgetArgs
|
||||
{
|
||||
{ "download", new ModContent.ModDownload(download.Value, modObjectCreator) },
|
||||
{ "download", new ModContent.ModDownload(download.Value) },
|
||||
{ "onSuccess", continueLoading }
|
||||
});
|
||||
};
|
||||
|
||||
@@ -15,6 +15,7 @@ using System.Globalization;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using OpenRA.Mods.Common.FileSystem;
|
||||
using OpenRA.Network;
|
||||
using OpenRA.Support;
|
||||
using OpenRA.Widgets;
|
||||
@@ -81,24 +82,16 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
||||
var contentButton = mainMenu.GetOrNull<ButtonWidget>("CONTENT_BUTTON");
|
||||
if (contentButton != null)
|
||||
{
|
||||
var hasContent = modData.Manifest.Contains<ModContent>();
|
||||
contentButton.Disabled = !hasContent;
|
||||
var contentInstaller = modData.FileSystemLoader as ContentInstallerFileSystemLoader;
|
||||
contentButton.Disabled = contentInstaller == null;
|
||||
contentButton.OnClick = () =>
|
||||
{
|
||||
// Switching mods changes the world state (by disposing it),
|
||||
// so we can't do this inside the input handler.
|
||||
Game.RunAfterTick(() =>
|
||||
{
|
||||
if (!hasContent)
|
||||
return;
|
||||
|
||||
var content = modData.Manifest.Get<ModContent>();
|
||||
string translationPath;
|
||||
using (var fs = (FileStream)modData.DefaultFileSystem.Open(content.Translation))
|
||||
translationPath = fs.Name;
|
||||
Game.InitializeMod(
|
||||
content.ContentInstallerMod,
|
||||
new Arguments(new[] { "Content.Mod=" + modData.Manifest.Id, "Content.TranslationFile=" + translationPath }));
|
||||
if (contentInstaller != null)
|
||||
Game.InitializeMod(contentInstaller.ContentInstallerMod, new Arguments());
|
||||
});
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user