From 79567f3f8af761bfe34f11874586097d32397e41 Mon Sep 17 00:00:00 2001 From: Paul Chote Date: Wed, 3 Dec 2025 18:35:11 +0000 Subject: [PATCH] Move content mod switching to IFileSystemExternalContent interface. --- .../FileSystem/ContentInstallerFileSystemLoader.cs | 7 +++++++ .../FileSystem/DefaultFileSystemLoader.cs | 1 + OpenRA.Mods.Common/Widgets/Logic/MainMenuLogic.cs | 13 ++----------- 3 files changed, 10 insertions(+), 11 deletions(-) diff --git a/OpenRA.Mods.Common/FileSystem/ContentInstallerFileSystemLoader.cs b/OpenRA.Mods.Common/FileSystem/ContentInstallerFileSystemLoader.cs index 6ca45e7e64..c4478ab6b4 100644 --- a/OpenRA.Mods.Common/FileSystem/ContentInstallerFileSystemLoader.cs +++ b/OpenRA.Mods.Common/FileSystem/ContentInstallerFileSystemLoader.cs @@ -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())); + } } } diff --git a/OpenRA.Mods.Common/FileSystem/DefaultFileSystemLoader.cs b/OpenRA.Mods.Common/FileSystem/DefaultFileSystemLoader.cs index 15b9e3da36..2194fa4862 100644 --- a/OpenRA.Mods.Common/FileSystem/DefaultFileSystemLoader.cs +++ b/OpenRA.Mods.Common/FileSystem/DefaultFileSystemLoader.cs @@ -18,6 +18,7 @@ namespace OpenRA.Mods.Common.FileSystem public interface IFileSystemExternalContent { bool InstallContentIfRequired(ModData modData); + void ManageContent(ModData modData); } public class DefaultFileSystemLoader : IFileSystemLoader diff --git a/OpenRA.Mods.Common/Widgets/Logic/MainMenuLogic.cs b/OpenRA.Mods.Common/Widgets/Logic/MainMenuLogic.cs index de0b7e9f7a..2acffee501 100644 --- a/OpenRA.Mods.Common/Widgets/Logic/MainMenuLogic.cs +++ b/OpenRA.Mods.Common/Widgets/Logic/MainMenuLogic.cs @@ -83,18 +83,9 @@ namespace OpenRA.Mods.Common.Widgets.Logic var contentButton = mainMenu.GetOrNull("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("SETTINGS_BUTTON").OnClick = () =>