diff --git a/core/src/com/unciv/models/metadata/ModCategories.kt b/core/src/com/unciv/models/metadata/ModCategories.kt index bf2e9b8fdc..df411f2675 100644 --- a/core/src/com/unciv/models/metadata/ModCategories.kt +++ b/core/src/com/unciv/models/metadata/ModCategories.kt @@ -2,7 +2,7 @@ package com.unciv.models.metadata import com.badlogic.gdx.Gdx import com.unciv.json.json -import com.unciv.ui.screens.newgamescreen.TranslatedSelectBox +import com.unciv.ui.components.TranslatedSelectBox import com.unciv.ui.screens.pickerscreens.Github diff --git a/core/src/com/unciv/ui/components/TranslatedSelectBox.kt b/core/src/com/unciv/ui/components/TranslatedSelectBox.kt new file mode 100644 index 0000000000..509eff17ba --- /dev/null +++ b/core/src/com/unciv/ui/components/TranslatedSelectBox.kt @@ -0,0 +1,27 @@ +package com.unciv.ui.components + +import com.badlogic.gdx.scenes.scene2d.ui.SelectBox +import com.badlogic.gdx.scenes.scene2d.ui.Skin +import com.badlogic.gdx.utils.Array +import com.unciv.models.translations.tr + +class TranslatedSelectBox(values : Collection, default:String, skin: Skin) : SelectBox(skin) { + class TranslatedString(val value: String) { + val translation = value.tr() + override fun toString() = translation + // Equality contract needs to be implemented else TranslatedSelectBox.setSelected won't work properly + override fun equals(other: Any?): Boolean = other is TranslatedString && value == other.value + override fun hashCode() = value.hashCode() + } + + init { + val array = Array() + values.forEach { array.add(TranslatedString(it)) } + items = array + selected = array.firstOrNull { it.value == default } ?: array.first() + } + + fun setSelected(newValue: String) { + selected = items.firstOrNull { it == TranslatedString(newValue) } ?: return + } +} diff --git a/core/src/com/unciv/ui/popups/options/DisplayTab.kt b/core/src/com/unciv/ui/popups/options/DisplayTab.kt index 575e3b88a1..7622379df0 100644 --- a/core/src/com/unciv/ui/popups/options/DisplayTab.kt +++ b/core/src/com/unciv/ui/popups/options/DisplayTab.kt @@ -23,7 +23,7 @@ import com.unciv.ui.components.extensions.toTextButton import com.unciv.ui.images.ImageGetter import com.unciv.ui.popups.ConfirmPopup import com.unciv.ui.screens.basescreen.BaseScreen -import com.unciv.ui.screens.newgamescreen.TranslatedSelectBox +import com.unciv.ui.components.TranslatedSelectBox import com.unciv.ui.screens.worldscreen.NotificationsScroll import com.unciv.utils.Display import com.unciv.utils.ScreenMode diff --git a/core/src/com/unciv/ui/popups/options/ModCheckTab.kt b/core/src/com/unciv/ui/popups/options/ModCheckTab.kt index dad575d9d6..03630b8bfc 100644 --- a/core/src/com/unciv/ui/popups/options/ModCheckTab.kt +++ b/core/src/com/unciv/ui/popups/options/ModCheckTab.kt @@ -23,7 +23,7 @@ import com.unciv.ui.components.input.onClick import com.unciv.ui.images.ImageGetter import com.unciv.ui.popups.ToastPopup import com.unciv.ui.screens.basescreen.BaseScreen -import com.unciv.ui.screens.newgamescreen.TranslatedSelectBox +import com.unciv.ui.components.TranslatedSelectBox import com.unciv.utils.Concurrency import com.unciv.utils.Log import com.unciv.utils.debug diff --git a/core/src/com/unciv/ui/screens/mapeditorscreen/tabs/MapEditorModsTab.kt b/core/src/com/unciv/ui/screens/mapeditorscreen/tabs/MapEditorModsTab.kt index 612ea0daf7..5725055d4b 100644 --- a/core/src/com/unciv/ui/screens/mapeditorscreen/tabs/MapEditorModsTab.kt +++ b/core/src/com/unciv/ui/screens/mapeditorscreen/tabs/MapEditorModsTab.kt @@ -10,7 +10,7 @@ import com.unciv.models.ruleset.RulesetCache import com.unciv.ui.screens.mapeditorscreen.MapEditorScreen import com.unciv.ui.screens.mapeditorscreen.TileInfoNormalizer import com.unciv.ui.screens.newgamescreen.ModCheckboxTable -import com.unciv.ui.screens.newgamescreen.TranslatedSelectBox +import com.unciv.ui.components.TranslatedSelectBox import com.unciv.ui.popups.Popup import com.unciv.ui.screens.basescreen.BaseScreen import com.unciv.ui.components.TabbedPager diff --git a/core/src/com/unciv/ui/screens/modmanager/ModManagementOptions.kt b/core/src/com/unciv/ui/screens/modmanager/ModManagementOptions.kt index fdc957c529..7b3bfbcd0d 100644 --- a/core/src/com/unciv/ui/screens/modmanager/ModManagementOptions.kt +++ b/core/src/com/unciv/ui/screens/modmanager/ModManagementOptions.kt @@ -17,7 +17,7 @@ import com.unciv.ui.components.input.onActivation import com.unciv.ui.components.input.onChange import com.unciv.ui.images.ImageGetter import com.unciv.ui.screens.basescreen.BaseScreen -import com.unciv.ui.screens.newgamescreen.TranslatedSelectBox +import com.unciv.ui.components.TranslatedSelectBox import kotlin.math.sign /** diff --git a/core/src/com/unciv/ui/screens/newgamescreen/GameOptionsTable.kt b/core/src/com/unciv/ui/screens/newgamescreen/GameOptionsTable.kt index cbb9c70ca3..996c2edb56 100644 --- a/core/src/com/unciv/ui/screens/newgamescreen/GameOptionsTable.kt +++ b/core/src/com/unciv/ui/screens/newgamescreen/GameOptionsTable.kt @@ -19,6 +19,7 @@ import com.unciv.ui.audio.MusicMood import com.unciv.ui.audio.MusicTrackChooserFlags import com.unciv.ui.components.AutoScrollPane import com.unciv.ui.components.ExpanderTab +import com.unciv.ui.components.TranslatedSelectBox import com.unciv.ui.components.UncivSlider import com.unciv.ui.components.extensions.pad import com.unciv.ui.components.extensions.toCheckBox diff --git a/core/src/com/unciv/ui/screens/newgamescreen/MapOptionsTable.kt b/core/src/com/unciv/ui/screens/newgamescreen/MapOptionsTable.kt index 5075a94a00..05260b6335 100644 --- a/core/src/com/unciv/ui/screens/newgamescreen/MapOptionsTable.kt +++ b/core/src/com/unciv/ui/screens/newgamescreen/MapOptionsTable.kt @@ -2,6 +2,7 @@ package com.unciv.ui.screens.newgamescreen import com.badlogic.gdx.scenes.scene2d.ui.Table import com.unciv.logic.map.MapGeneratedMainType +import com.unciv.ui.components.TranslatedSelectBox import com.unciv.ui.components.extensions.toLabel import com.unciv.ui.components.input.onChange import com.unciv.ui.screens.basescreen.BaseScreen diff --git a/core/src/com/unciv/ui/screens/newgamescreen/MapParametersTable.kt b/core/src/com/unciv/ui/screens/newgamescreen/MapParametersTable.kt index f907a1ad77..392e795fd7 100644 --- a/core/src/com/unciv/ui/screens/newgamescreen/MapParametersTable.kt +++ b/core/src/com/unciv/ui/screens/newgamescreen/MapParametersTable.kt @@ -15,6 +15,7 @@ import com.unciv.logic.map.MapSize import com.unciv.logic.map.MapSizeNew import com.unciv.logic.map.MapType import com.unciv.ui.components.ExpanderTab +import com.unciv.ui.components.TranslatedSelectBox import com.unciv.ui.components.UncivSlider import com.unciv.ui.components.UncivTextField import com.unciv.ui.components.WrappableLabel diff --git a/core/src/com/unciv/ui/screens/newgamescreen/NewGameScreen.kt b/core/src/com/unciv/ui/screens/newgamescreen/NewGameScreen.kt index 9dd43260a0..4e572a80b7 100644 --- a/core/src/com/unciv/ui/screens/newgamescreen/NewGameScreen.kt +++ b/core/src/com/unciv/ui/screens/newgamescreen/NewGameScreen.kt @@ -2,10 +2,7 @@ package com.unciv.ui.screens.newgamescreen import com.badlogic.gdx.Gdx import com.badlogic.gdx.graphics.Color -import com.badlogic.gdx.scenes.scene2d.ui.SelectBox -import com.badlogic.gdx.scenes.scene2d.ui.Skin import com.badlogic.gdx.scenes.scene2d.ui.VerticalGroup -import com.badlogic.gdx.utils.Array import com.unciv.Constants import com.unciv.UncivGame import com.unciv.logic.GameInfo @@ -411,23 +408,3 @@ class NewGameScreen( override fun recreate(): BaseScreen = NewGameScreen(gameSetupInfo) } -class TranslatedSelectBox(values : Collection, default:String, skin: Skin) : SelectBox(skin) { - class TranslatedString(val value: String) { - val translation = value.tr() - override fun toString() = translation - // Equality contract needs to be implemented else TranslatedSelectBox.setSelected won't work properly - override fun equals(other: Any?): Boolean = other is TranslatedString && value == other.value - override fun hashCode() = value.hashCode() - } - - init { - val array = Array() - values.forEach { array.add(TranslatedString(it)) } - items = array - selected = array.firstOrNull { it.value == default } ?: array.first() - } - - fun setSelected(newValue: String) { - selected = items.firstOrNull { it == TranslatedString(newValue) } ?: return - } -} diff --git a/core/src/com/unciv/ui/screens/victoryscreen/VictoryScreenCharts.kt b/core/src/com/unciv/ui/screens/victoryscreen/VictoryScreenCharts.kt index 6a96137a3d..02ef732afc 100644 --- a/core/src/com/unciv/ui/screens/victoryscreen/VictoryScreenCharts.kt +++ b/core/src/com/unciv/ui/screens/victoryscreen/VictoryScreenCharts.kt @@ -14,7 +14,7 @@ import com.unciv.ui.components.extensions.packIfNeeded import com.unciv.ui.components.input.OnClickListener import com.unciv.ui.images.ImageGetter import com.unciv.ui.screens.basescreen.BaseScreen -import com.unciv.ui.screens.newgamescreen.TranslatedSelectBox +import com.unciv.ui.components.TranslatedSelectBox import com.unciv.ui.screens.victoryscreen.VictoryScreenCivGroup.DefeatedPlayerStyle import com.unciv.ui.screens.worldscreen.WorldScreen