From 0d942ac1759ca3e65d7ff1fa9182b7a172e907ac Mon Sep 17 00:00:00 2001 From: Yair Morgenstern Date: Thu, 21 Sep 2023 14:58:23 +0300 Subject: [PATCH] Reload images when downloading or removing a mod --- core/src/com/unciv/UncivGame.kt | 2 +- core/src/com/unciv/ui/images/ImageGetter.kt | 2 +- .../ui/screens/modmanager/ModManagementScreen.kt | 14 +++++++++----- tests/src/com/unciv/dev/FasterUIDevelopment.kt | 2 +- 4 files changed, 12 insertions(+), 8 deletions(-) diff --git a/core/src/com/unciv/UncivGame.kt b/core/src/com/unciv/UncivGame.kt index 2518a8ddd0..dd2d4a9071 100644 --- a/core/src/com/unciv/UncivGame.kt +++ b/core/src/com/unciv/UncivGame.kt @@ -191,7 +191,7 @@ open class UncivGame(val isConsoleMode: Boolean = false) : Game(), PlatformSpeci } ImageGetter.resetAtlases() - ImageGetter.setNewRuleset(ImageGetter.ruleset) // This needs to come after the settings, since we may have default visual mods + ImageGetter.reloadImages() // This needs to come after the settings, since we may have default visual mods val imageGetterTilesets = ImageGetter.getAvailableTilesets() val availableTileSets = TileSetCache.getAvailableTilesets(imageGetterTilesets) if (settings.tileSet !in availableTileSets) { // If the configured tileset is no longer available, default back diff --git a/core/src/com/unciv/ui/images/ImageGetter.kt b/core/src/com/unciv/ui/images/ImageGetter.kt index 8c0db9b72c..7a87d8191a 100644 --- a/core/src/com/unciv/ui/images/ImageGetter.kt +++ b/core/src/com/unciv/ui/images/ImageGetter.kt @@ -62,7 +62,7 @@ object ImageGetter { atlases["game"] = atlas } - + fun reloadImages() = setNewRuleset(ruleset) /** Required every time the ruleset changes, in order to load mod-specific images */ fun setNewRuleset(ruleset: Ruleset) { diff --git a/core/src/com/unciv/ui/screens/modmanager/ModManagementScreen.kt b/core/src/com/unciv/ui/screens/modmanager/ModManagementScreen.kt index 7e190099b0..d7cc4bf446 100644 --- a/core/src/com/unciv/ui/screens/modmanager/ModManagementScreen.kt +++ b/core/src/com/unciv/ui/screens/modmanager/ModManagementScreen.kt @@ -447,8 +447,7 @@ class ModManagementScreen private constructor( launchOnGLThread { val repoName = modFolder.name() // repo.name still has the replaced "-"'s ToastPopup("[$repoName] Downloaded!", this@ModManagementScreen) - RulesetCache.loadRulesets() - TileSetCache.loadTileSetConfigs() + reloadCachesAfterModChange() UncivGame.Current.translations.tryReadTranslationForCurrentLanguage() RulesetCache[repoName]?.let { installedModInfo[repoName] = ModUIData(it, false) @@ -513,7 +512,7 @@ class ModManagementScreen private constructor( else game.settings.visualMods.remove(mod.name) game.settings.save() - ImageGetter.setNewRuleset(ImageGetter.ruleset) + ImageGetter.reloadImages() refreshInstalledModActions(mod) if (optionsManager.sortInstalled == SortType.Status) refreshInstalledModTable() @@ -583,12 +582,17 @@ class ModManagementScreen private constructor( /** Delete a Mod, refresh ruleset cache and update installed mod table */ private fun deleteMod(mod: Ruleset) { mod.folderLocation!!.deleteDirectory() - RulesetCache.loadRulesets() - TileSetCache.loadTileSetConfigs() + reloadCachesAfterModChange() installedModInfo.remove(mod.name) refreshInstalledModTable() } + private fun reloadCachesAfterModChange(){ + RulesetCache.loadRulesets() + ImageGetter.reloadImages() + TileSetCache.loadTileSetConfigs() + } + internal fun refreshOnlineModTable() { if (runningSearchJob != null) { ToastPopup("Sorting and filtering needs to wait until the online query finishes", this) diff --git a/tests/src/com/unciv/dev/FasterUIDevelopment.kt b/tests/src/com/unciv/dev/FasterUIDevelopment.kt index 45079630d5..af57fa3b99 100644 --- a/tests/src/com/unciv/dev/FasterUIDevelopment.kt +++ b/tests/src/com/unciv/dev/FasterUIDevelopment.kt @@ -72,7 +72,7 @@ object FasterUIDevelopment { UncivGame.Current.files = UncivFiles(Gdx.files) game.settings = UncivGame.Current.files.getGeneralSettings() ImageGetter.resetAtlases() - ImageGetter.setNewRuleset(ImageGetter.ruleset) + ImageGetter.reloadImages() BaseScreen.setSkin() game.pushScreen(UIDevScreen()) Gdx.graphics.requestRendering()