From 2f69ab0fadb7a0597cf6fd57cf9f67ed3d101208 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Leonard=20G=C3=BCnther?= Date: Thu, 10 Nov 2022 16:06:47 +0100 Subject: [PATCH] Added unitset selection to options menu (#7980) * Added unitset selection to options menu * Added None type to unitset selection + added logic to switch unitset when changing tileset as long as one with the same name exists and both are selected * Updated default unitset to be HexaRealm --- core/src/com/unciv/Constants.kt | 1 + .../com/unciv/models/metadata/GameSettings.kt | 3 +- core/src/com/unciv/ui/images/ImageGetter.kt | 5 +++- core/src/com/unciv/ui/options/DisplayTab.kt | 30 ++++++++++++++++++- .../com/unciv/ui/tilegroups/TileSetStrings.kt | 7 +++-- 5 files changed, 40 insertions(+), 6 deletions(-) diff --git a/core/src/com/unciv/Constants.kt b/core/src/com/unciv/Constants.kt index 40d72cc5f9..ab30d676fa 100644 --- a/core/src/com/unciv/Constants.kt +++ b/core/src/com/unciv/Constants.kt @@ -81,6 +81,7 @@ object Constants { const val dropboxMultiplayerServer = "Dropbox" const val defaultTileset = "HexaRealm" + const val defaultUnitset = "HexaRealm" const val defaultSkin = "Minimal" /** diff --git a/core/src/com/unciv/models/metadata/GameSettings.kt b/core/src/com/unciv/models/metadata/GameSettings.kt index 04bab2f862..fb6b8a3267 100644 --- a/core/src/com/unciv/models/metadata/GameSettings.kt +++ b/core/src/com/unciv/models/metadata/GameSettings.kt @@ -38,6 +38,7 @@ class GameSettings { var turnsBetweenAutosaves = 1 var tileSet: String = Constants.defaultTileset + var unitSet: String? = Constants.defaultUnitset var skin: String = Constants.defaultSkin var showTutorials: Boolean = true var autoAssignCityProduction: Boolean = true @@ -47,7 +48,7 @@ class GameSettings { var showMinimap: Boolean = true var minimapSize: Int = 6 // default corresponds to 15% screen space var unitIconOpacity = 1f // default corresponds to fully opaque - var showPixelUnits: Boolean = true + val showPixelUnits: Boolean get() = unitSet != null var showPixelImprovements: Boolean = true var continuousRendering = false var orderTradeOffersByAmount = true diff --git a/core/src/com/unciv/ui/images/ImageGetter.kt b/core/src/com/unciv/ui/images/ImageGetter.kt index 62f43ccaf8..b6c980eeeb 100644 --- a/core/src/com/unciv/ui/images/ImageGetter.kt +++ b/core/src/com/unciv/ui/images/ImageGetter.kt @@ -481,6 +481,9 @@ object ImageGetter { fun getAvailableSkins() = ninePatchDrawables.keys.asSequence().map { it.split("/")[1] }.distinct() - fun getAvailableTilesets() = textureRegionDrawables.keys.asSequence().filter { it.startsWith("TileSets") } + fun getAvailableTilesets() = textureRegionDrawables.keys.asSequence().filter { it.startsWith("TileSets") && !it.contains("/Units/") } .map { it.split("/")[1] }.distinct() + + fun getAvailableUnitsets() = textureRegionDrawables.keys.asSequence().filter { it.contains("/Units/") } + .map { it.split("/")[1] }.distinct() } diff --git a/core/src/com/unciv/ui/options/DisplayTab.kt b/core/src/com/unciv/ui/options/DisplayTab.kt index 4bdc9d1f97..3d6f1cab8b 100644 --- a/core/src/com/unciv/ui/options/DisplayTab.kt +++ b/core/src/com/unciv/ui/options/DisplayTab.kt @@ -34,7 +34,6 @@ fun displayTab( optionsPopup.addCheckbox(this, "Show worked tiles", settings.showWorkedTiles, true) { settings.showWorkedTiles = it } optionsPopup.addCheckbox(this, "Show resources and improvements", settings.showResourcesAndImprovements, true) { settings.showResourcesAndImprovements = it } optionsPopup.addCheckbox(this, "Show tutorials", settings.showTutorials, true) { settings.showTutorials = it } - optionsPopup.addCheckbox(this, "Show pixel units", settings.showPixelUnits, true) { settings.showPixelUnits = it } optionsPopup.addCheckbox(this, "Show pixel improvements", settings.showPixelImprovements, true) { settings.showPixelImprovements = it } optionsPopup.addCheckbox(this, "Experimental Demographics scoreboard", settings.useDemographics, true) { settings.useDemographics = it } optionsPopup.addCheckbox(this, "Show zoom buttons in world screen", settings.showZoomButtons, true) { settings.showZoomButtons = it } @@ -47,6 +46,8 @@ fun displayTab( addTileSetSelectBox(this, settings, optionsPopup.selectBoxMinWidth, onChange) + addUnitSetSelectBox(this, settings, optionsPopup.selectBoxMinWidth, onChange) + addSkinSelectBox(this, settings, optionsPopup.selectBoxMinWidth, onChange) optionsPopup.addCheckbox(this, "Continuous rendering", settings.continuousRendering) { @@ -141,7 +142,13 @@ private fun addTileSetSelectBox(table: Table, settings: GameSettings, selectBoxM tileSetSelectBox.selected = settings.tileSet table.add(tileSetSelectBox).minWidth(selectBoxMinWidth).pad(10f).row() + val unitSets = ImageGetter.getAvailableUnitsets() + tileSetSelectBox.onChange { + // Switch unitSet together with tileSet as long as one with the same name exists and both are selected + if (settings.tileSet == settings.unitSet && unitSets.contains(tileSetSelectBox.selected)) { + settings.unitSet = tileSetSelectBox.selected + } settings.tileSet = tileSetSelectBox.selected // ImageGetter ruleset should be correct no matter what screen we're on TileSetCache.assembleTileSetConfigs(ImageGetter.ruleset.mods) @@ -149,6 +156,27 @@ private fun addTileSetSelectBox(table: Table, settings: GameSettings, selectBoxM } } +private fun addUnitSetSelectBox(table: Table, settings: GameSettings, selectBoxMinWidth: Float, onUnitsetChange: () -> Unit) { + table.add("Unitset".toLabel()).left().fillX() + + val unitSetSelectBox = SelectBox(table.skin) + val unitSetArray = Array() + val nullValue = "None".tr() + unitSetArray.add(nullValue) + val unitSets = ImageGetter.getAvailableUnitsets() + for (unitset in unitSets) unitSetArray.add(unitset) + unitSetSelectBox.items = unitSetArray + unitSetSelectBox.selected = settings.unitSet ?: nullValue + table.add(unitSetSelectBox).minWidth(selectBoxMinWidth).pad(10f).row() + + unitSetSelectBox.onChange { + settings.unitSet = if (unitSetSelectBox.selected != nullValue) unitSetSelectBox.selected else null + // ImageGetter ruleset should be correct no matter what screen we're on + TileSetCache.assembleTileSetConfigs(ImageGetter.ruleset.mods) + onUnitsetChange() + } +} + private fun addSkinSelectBox(table: Table, settings: GameSettings, selectBoxMinWidth: Float, onSkinChange: () -> Unit) { table.add("UI Skin".toLabel()).left().fillX() diff --git a/core/src/com/unciv/ui/tilegroups/TileSetStrings.kt b/core/src/com/unciv/ui/tilegroups/TileSetStrings.kt index 57bb32dcb7..0a9d56fa04 100644 --- a/core/src/com/unciv/ui/tilegroups/TileSetStrings.kt +++ b/core/src/com/unciv/ui/tilegroups/TileSetStrings.kt @@ -13,11 +13,12 @@ import com.unciv.ui.images.ImageGetter * @param tileSet Name of the tileset. Defaults to active at time of instantiation. * @param fallbackDepth Maximum number of fallback tilesets to try. Used to prevent infinite recursion. * */ -class TileSetStrings(tileSet: String = UncivGame.Current.settings.tileSet, fallbackDepth: Int = 1) { +class TileSetStrings(tileSet: String = UncivGame.Current.settings.tileSet, unitSet: String? = UncivGame.Current.settings.unitSet, fallbackDepth: Int = 1) { // this is so that when we have 100s of TileGroups, they won't all individually come up with all these strings themselves, // it gets pretty memory-intensive (10s of MBs which is a lot for lower-end phones) val tileSetLocation = "TileSets/$tileSet/" + val unitSetLocation = "TileSets/$unitSet/" val tileSetConfig = TileSetCache[tileSet] ?: TileSetConfig() // These need to be by lazy since the orFallback expects a tileset, which it may not get. @@ -36,7 +37,7 @@ class TileSetStrings(tileSet: String = UncivGame.Current.settings.tileSet, fallb val bottomRiver by lazy { orFallback { tilesLocation + "River-Bottom"} } val bottomLeftRiver by lazy { orFallback { tilesLocation + "River-BottomLeft"} } - val unitsLocation = tileSetLocation + "Units/" + val unitsLocation = unitSetLocation + "Units/" val bordersLocation = tileSetLocation + "Borders/" @@ -74,7 +75,7 @@ class TileSetStrings(tileSet: String = UncivGame.Current.settings.tileSet, fallb if (fallbackDepth <= 0 || tileSetConfig.fallbackTileSet == null) null else - TileSetStrings(tileSetConfig.fallbackTileSet!!, fallbackDepth-1) + TileSetStrings(tileSetConfig.fallbackTileSet!!, tileSetConfig.fallbackTileSet!!, fallbackDepth-1) } @Suppress("MemberVisibilityCanBePrivate")