chore: TranslatedSelectBox doesn't need a skin parameter when it always uses the default anyway

This commit is contained in:
yairm210 2024-07-11 16:54:19 +03:00
parent b58b73a790
commit ea1073c208
10 changed files with 23 additions and 27 deletions

View File

@ -1,11 +1,11 @@
package com.unciv.ui.components.widgets
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
import com.unciv.ui.screens.basescreen.BaseScreen
class TranslatedSelectBox(values: Collection<String>, default: String, skin: Skin) : SelectBox<TranslatedSelectBox.TranslatedString>(skin) {
class TranslatedSelectBox(values: Collection<String>, default: String) : SelectBox<TranslatedSelectBox.TranslatedString>(BaseScreen.skin) {
class TranslatedString(val value: String) {
val translation = value.tr(hideIcons = true)
override fun toString() = translation

View File

@ -196,7 +196,7 @@ private fun addScreenModeSelectBox(table: Table, settings: GameSettings, selectB
private fun addScreenSizeSelectBox(table: Table, settings: GameSettings, selectBoxMinWidth: Float, onResolutionChange: () -> Unit) {
table.add("Screen Size".toLabel()).left().fillX()
val screenSizeSelectBox = TranslatedSelectBox(ScreenSize.values().map { it.name }, settings.screenSize.name, table.skin)
val screenSizeSelectBox = TranslatedSelectBox(ScreenSize.entries.map { it.name }, settings.screenSize.name)
table.add(screenSizeSelectBox).minWidth(selectBoxMinWidth).pad(10f).row()
screenSizeSelectBox.onChange {
@ -291,9 +291,8 @@ private fun addNotificationScrollSelect(table: Table, settings: GameSettings, se
table.add("Notifications on world screen".toLabel()).left().fillX()
val selectBox = TranslatedSelectBox(
NotificationsScroll.UserSetting.values().map { it.name },
settings.notificationScroll,
table.skin
NotificationsScroll.UserSetting.entries.map { it.name },
settings.notificationScroll
)
table.add(selectBox).minWidth(selectBoxMinWidth).pad(10f).row()

View File

@ -51,7 +51,7 @@ class ModCheckTab(
val labeledBaseSelect = Table().apply {
add("Check extension mods based on:".toLabel()).padRight(10f)
val baseMods = listOf(MOD_CHECK_WITHOUT_BASE) + RulesetCache.getSortedBaseRulesets()
modCheckBaseSelect = TranslatedSelectBox(baseMods, MOD_CHECK_WITHOUT_BASE, BaseScreen.skin).apply {
modCheckBaseSelect = TranslatedSelectBox(baseMods, MOD_CHECK_WITHOUT_BASE).apply {
selectedIndex = 0
onChange { runAction() }
}

View File

@ -38,7 +38,7 @@ class MapEditorModsTab(
modsTable = ModCheckboxTable(linkedSetOf(), rulesetName, editorScreen, false) {}
val baseRulesets = RulesetCache.getSortedBaseRulesets()
baseRulesetSelectBox = TranslatedSelectBox(baseRulesets, rulesetName, BaseScreen.skin)
baseRulesetSelectBox = TranslatedSelectBox(baseRulesets, rulesetName)
baseRulesetSelectBox.onChange {
val newBaseRuleset = baseRulesetSelectBox.selected.value
editorScreen.newMapParameters.baseRuleset = newBaseRuleset

View File

@ -59,12 +59,12 @@ internal class ModManagementOptions(private val modManagementScreen: ModManageme
Stars("Stars ${Fonts.sortDownArrow}", "${Fonts.star}${Fonts.sortDownArrow}", sortByStars),
Status("Status ${Fonts.sortDownArrow}", "${Fonts.status}${Fonts.sortDownArrow}", sortByStatus)
;
fun next() = values()[(ordinal + 1) % values().size]
fun next() = entries[(ordinal + 1) % entries.size]
companion object {
fun fromSelectBox(selectBox: TranslatedSelectBox): SortType {
val selected = selectBox.selected.value
return values().firstOrNull { it.label == selected } ?: Name
return entries.firstOrNull { it.label == selected } ?: Name
}
}
}
@ -97,9 +97,8 @@ internal class ModManagementOptions(private val modManagementScreen: ModManageme
.surroundWithCircle(50f, color = Color.CLEAR)
sortInstalledSelect = TranslatedSelectBox(
SortType.values().filter { sort -> sort != SortType.Stars }.map { sort -> sort.label },
sortInstalled.label,
BaseScreen.skin
SortType.entries.filter { sort -> sort != SortType.Stars }.map { sort -> sort.label },
sortInstalled.label
)
sortInstalledSelect.onChange {
sortInstalled = SortType.fromSelectBox(sortInstalledSelect)
@ -107,9 +106,8 @@ internal class ModManagementOptions(private val modManagementScreen: ModManageme
}
sortOnlineSelect = TranslatedSelectBox(
SortType.values().map { sort -> sort.label },
sortOnline.label,
BaseScreen.skin
SortType.entries.map { sort -> sort.label },
sortOnline.label
)
sortOnlineSelect.onChange {
sortOnline = SortType.fromSelectBox(sortOnlineSelect)
@ -118,8 +116,7 @@ internal class ModManagementOptions(private val modManagementScreen: ModManageme
categorySelect = TranslatedSelectBox(
ModCategories.asSequence().map { it.label }.toList(),
category.label,
BaseScreen.skin
category.label
)
categorySelect.onChange {
category = ModCategories.fromSelectBox(categorySelect)

View File

@ -352,7 +352,7 @@ class GameOptionsTable(
private fun Table.addSelectBox(text: String, values: Collection<String>, initialState: String, onChange: (newValue: String) -> String?): TranslatedSelectBox {
add(text.toLabel(hideIcons = true)).left()
val selectBox = TranslatedSelectBox(values, initialState, BaseScreen.skin)
val selectBox = TranslatedSelectBox(values, initialState)
selectBox.isDisabled = locked
selectBox.onChange {
val changedValue = onChange(selectBox.selected.value)

View File

@ -24,7 +24,7 @@ class MapOptionsTable(private val newGameScreen: NewGameScreen) : Table() {
val mapTypes = arrayListOf(MapGeneratedMainType.generated, MapGeneratedMainType.randomGenerated)
if (savedMapOptionsTable.isNotEmpty()) mapTypes.add(MapGeneratedMainType.custom)
mapTypeSelectBox = TranslatedSelectBox(mapTypes, MapGeneratedMainType.generated, BaseScreen.skin)
mapTypeSelectBox = TranslatedSelectBox(mapTypes, MapGeneratedMainType.generated)
fun updateOnMapTypeChange() {
mapTypeSpecificTable.clear()

View File

@ -121,7 +121,7 @@ class MapParametersTable(
add(optionsTable).colspan(2).grow().row()
} else {
val mapShapeSelectBox =
TranslatedSelectBox(mapShapes, mapParameters.shape, skin)
TranslatedSelectBox(mapShapes, mapParameters.shape)
mapShapeSelectBox.onChange {
mapParameters.shape = mapShapeSelectBox.selected.value
updateWorldSizeTable()
@ -160,7 +160,7 @@ class MapParametersTable(
}
add(optionsTable).colspan(2).grow().row()
} else {
mapTypeSelectBox = TranslatedSelectBox(mapTypes, mapParameters.type, skin)
mapTypeSelectBox = TranslatedSelectBox(mapTypes, mapParameters.type)
mapTypeSelectBox.onChange {
mapParameters.type = mapTypeSelectBox.selected.value
@ -189,7 +189,7 @@ class MapParametersTable(
add(optionsTable).colspan(2).grow().row()
} else {
val mapSizes = MapSize.names() + listOf(MapSize.custom)
worldSizeSelectBox = TranslatedSelectBox(mapSizes, mapParameters.mapSize.name, skin)
worldSizeSelectBox = TranslatedSelectBox(mapSizes, mapParameters.mapSize.name)
worldSizeSelectBox.onChange { updateWorldSizeTable() }
addHexagonalSizeTable()
@ -271,7 +271,7 @@ class MapParametersTable(
}
add(optionsTable).colspan(2).grow().row()
} else {
resourceSelectBox = TranslatedSelectBox(mapResources, mapParameters.mapResources, skin)
resourceSelectBox = TranslatedSelectBox(mapResources, mapParameters.mapResources)
resourceSelectBox.onChange {
mapParameters.mapResources = resourceSelectBox.selected.value

View File

@ -25,7 +25,7 @@ class VictoryScreenCharts(
private var selectedCiv = worldScreen.selectedCiv
private val viewingCiv = worldScreen.viewingCiv
private val rankingTypeSelect = TranslatedSelectBox(RankingType.values().map { it.label }, rankingType.name, skin)
private val rankingTypeSelect = TranslatedSelectBox(RankingType.entries.map { it.label }, rankingType.name)
private val civButtonsTable = Table()
private val civButtonsScroll = AutoScrollPane(civButtonsTable)
private val controlsColumn = Table()
@ -56,7 +56,7 @@ class VictoryScreenCharts(
lineChart.addListener(onChartClick)
rankingTypeSelect.onChange {
rankingType = RankingType.values()
rankingType = RankingType.entries
.firstOrNull { it.label == rankingTypeSelect.selected.value }
?: RankingType.Score
update()

View File

@ -2622,7 +2622,7 @@ Simple unique parameters are explained by mouseover. Complex parameters are expl
??? example "Disable religion"
Applicable to: ModOptions
??? example "Can only start games from the default era"
??? example "Can only start games from the starting era"
Applicable to: ModOptions
??? example "Allow raze capital"