Reload images when downloading or removing a mod

This commit is contained in:
Yair Morgenstern 2023-09-21 14:58:23 +03:00
parent 92b71102e1
commit 0d942ac175
4 changed files with 12 additions and 8 deletions

View File

@ -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

View File

@ -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) {

View File

@ -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)

View File

@ -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()