Added "permanent visual mods" option to mod management

This commit is contained in:
Yair Morgenstern 2021-03-18 18:36:05 +02:00
parent 7ba12ad5c6
commit c98100f1a7
5 changed files with 24 additions and 10 deletions

View File

@ -85,9 +85,9 @@ class UncivGame(parameters: UncivGameParameters) : Game() {
* - Font (hence Fonts.resetFont() inside setSkin())
*/
ImageGetter.atlas = TextureAtlas("game.atlas")
ImageGetter.setNewRuleset(ImageGetter.ruleset)
settings = GameSaver.getGeneralSettings() // needed for the screen
ImageGetter.setNewRuleset(ImageGetter.ruleset) // This needs to come after the settings, since we may have default visual mods
CameraStageBaseScreen.setSkin() // needs to come AFTER the Texture reset, since the buttons depend on it
settings = GameSaver.getGeneralSettings() // needed for the screen - this also needs the atlas to be configured
Gdx.graphics.isContinuousRendering = settings.continuousRendering
screen = LoadingScreen()

View File

@ -115,11 +115,6 @@ object GameSaver {
GameSettings().apply { isFreshlyCreated = true }
}
val atlas = ImageGetter.atlas
val currentTileSets = atlas.regions.asSequence()
.filter { it.name.startsWith("TileSets") }
.map { it.name.split("/")[1] }.distinct()
if (settings.tileSet !in currentTileSets) settings.tileSet = "Default"
return settings
}

View File

@ -37,6 +37,7 @@ class GameSettings {
var orderTradeOffersByAmount = true
var windowState = WindowState()
var isFreshlyCreated = false
var visualMods = HashSet<String>()
var showExperimentalWorldWrap = false

View File

@ -114,13 +114,30 @@ class ModManagementScreen: PickerScreen() {
}
}
fun refreshModActions(mod: Ruleset) {
modActionTable.clear()
val visualMods = game.settings.visualMods
if (!visualMods.contains(mod.name))
modActionTable.add("Enable as permanent visual mod".toTextButton().onClick {
visualMods.add(mod.name); game.settings.save()
ImageGetter.setNewRuleset(ImageGetter.ruleset)
refreshModActions(mod)
})
else modActionTable.add("Disable as permanent visual mod".toTextButton().onClick {
visualMods.remove(mod.name)
game.settings.save()
ImageGetter.setNewRuleset(ImageGetter.ruleset)
refreshModActions(mod)
})
modActionTable.row()
}
fun refreshModTable(){
modTable.clear()
val currentMods = RulesetCache.values.filter { it.name != "" }
for (mod in currentMods) {
val button = mod.name.toTextButton().onClick {
// modActionTable.add("Last updated: ${mod.getSummary()}")
refreshModActions(mod)
rightSideButton.setText("Delete [${mod.name}]".tr())
rightSideButton.enable()
descriptionLabel.setText(mod.getSummary())

View File

@ -15,6 +15,7 @@ import com.badlogic.gdx.scenes.scene2d.utils.NinePatchDrawable
import com.badlogic.gdx.scenes.scene2d.utils.TextureRegionDrawable
import com.badlogic.gdx.utils.Align
import com.unciv.Constants
import com.unciv.UncivGame
import com.unciv.models.ruleset.Nation
import com.unciv.models.ruleset.Ruleset
import com.unciv.models.ruleset.tile.ResourceType
@ -65,7 +66,7 @@ object ImageGetter {
}
// These are from the mods
for (mod in ruleset.mods) {
for (mod in UncivGame.Current.settings.visualMods + ruleset.mods) {
val modAtlasFile = Gdx.files.local("mods/$mod/game.atlas")
if (!modAtlasFile.exists()) continue
val modAtlas = TextureAtlas(modAtlasFile)