Move content mod switching to IFileSystemExternalContent interface.

This commit is contained in:
Paul Chote
2025-12-03 18:35:11 +00:00
committed by Gustas Kažukauskas
parent 8b8651dcf7
commit 79567f3f8a
3 changed files with 10 additions and 11 deletions

View File

@@ -65,5 +65,12 @@ namespace OpenRA.Mods.Common.FileSystem
return !isContentAvailable;
}
void IFileSystemExternalContent.ManageContent(ModData modData)
{
// Switching mods changes the world state (by disposing it),
// so we can't do this inside the input handler.
Game.RunAfterTick(() => Game.InitializeMod(ContentInstallerMod, new Arguments()));
}
}
}

View File

@@ -18,6 +18,7 @@ namespace OpenRA.Mods.Common.FileSystem
public interface IFileSystemExternalContent
{
bool InstallContentIfRequired(ModData modData);
void ManageContent(ModData modData);
}
public class DefaultFileSystemLoader : IFileSystemLoader

View File

@@ -83,18 +83,9 @@ namespace OpenRA.Mods.Common.Widgets.Logic
var contentButton = mainMenu.GetOrNull<ButtonWidget>("CONTENT_BUTTON");
if (contentButton != null)
{
var contentInstaller = modData.FileSystemLoader as ContentInstallerFileSystemLoader;
var contentInstaller = modData.FileSystemLoader as IFileSystemExternalContent;
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 (contentInstaller != null)
Game.InitializeMod(contentInstaller.ContentInstallerMod, new Arguments());
});
};
contentButton.OnClick = () => contentInstaller?.ManageContent(modData);
}
mainMenu.Get<ButtonWidget>("SETTINGS_BUTTON").OnClick = () =>