diff --git a/core/src/com/unciv/ui/options/MultiplayerTab.kt b/core/src/com/unciv/ui/options/MultiplayerTab.kt index 55acf17b94..6c9a181de5 100644 --- a/core/src/com/unciv/ui/options/MultiplayerTab.kt +++ b/core/src/com/unciv/ui/options/MultiplayerTab.kt @@ -12,8 +12,11 @@ import com.unciv.models.metadata.GameSetting import com.unciv.models.metadata.GameSettings import com.unciv.models.ruleset.Ruleset import com.unciv.models.ruleset.RulesetCache +import com.unciv.ui.images.ImageGetter import com.unciv.ui.popup.Popup import com.unciv.ui.utils.BaseScreen +import com.unciv.ui.utils.extensions.addSeparator +import com.unciv.ui.utils.extensions.brighten import com.unciv.ui.utils.extensions.format import com.unciv.ui.utils.extensions.isEnabled import com.unciv.ui.utils.extensions.onChange @@ -40,6 +43,8 @@ fun multiplayerTab( settings.multiplayer::statusButtonInSinglePlayer, updateWorld = true ) + addSeparator(tab) + val curRefreshSelect = RefreshSelect( "Update status of currently played game every:", createRefreshOptions(ChronoUnit.SECONDS, 3, 5), @@ -47,7 +52,7 @@ fun multiplayerTab( GameSetting.MULTIPLAYER_CURRENT_GAME_REFRESH_DELAY, settings ) - curRefreshSelect.addTo(tab) + addSelectAsSeparateTable(tab, curRefreshSelect) val allRefreshSelect = RefreshSelect( "In-game, update status of all games every:", @@ -56,21 +61,27 @@ fun multiplayerTab( GameSetting.MULTIPLAYER_ALL_GAME_REFRESH_DELAY, settings ) - allRefreshSelect.addTo(tab) + addSelectAsSeparateTable(tab, allRefreshSelect) + + addSeparator(tab) val turnCheckerSelect = addTurnCheckerOptions(tab, optionsPopup) - SettingsSelect("Sound notification for when it's your turn in your currently open game:", + addSeparator(tab) + + addSelectAsSeparateTable(tab, SettingsSelect("Sound notification for when it's your turn in your currently open game:", createNotificationSoundOptions(), GameSetting.MULTIPLAYER_CURRENT_GAME_TURN_NOTIFICATION_SOUND, settings - ).addTo(tab) + )) - SettingsSelect("Sound notification for when it's your turn in any other game:", + addSelectAsSeparateTable(tab, SettingsSelect("Sound notification for when it's your turn in any other game:", createNotificationSoundOptions(), GameSetting.MULTIPLAYER_OTHER_GAME_TURN_NOTIFICATION_SOUND, settings - ).addTo(tab) + )) + + addSeparator(tab) addMultiplayerServerOptions(tab, optionsPopup, listOf(curRefreshSelect, allRefreshSelect, turnCheckerSelect).filterNotNull()) @@ -127,7 +138,7 @@ private fun addMultiplayerServerOptions( serverIpTable.add("Server address".toLabel().onClick { multiplayerServerTextField.text = Gdx.app.clipboard.contents - }).row() + }).row() multiplayerServerTextField.onChange { val isCustomServer = OnlineMultiplayer.usesCustomServer() connectionToServerButton.isEnabled = isCustomServer @@ -186,7 +197,7 @@ private fun addTurnCheckerOptions( GameSetting.MULTIPLAYER_TURN_CHECKER_DELAY, settings ) - turnCheckerSelect.addTo(tab) + addSelectAsSeparateTable(tab, turnCheckerSelect) optionsPopup.addCheckbox( @@ -213,25 +224,23 @@ private class RefreshSelect( dropboxOptions: List>, setting: GameSetting, settings: GameSettings -) { +) : SettingsSelect(labelText, getInitialOptions(extraCustomServerOptions, dropboxOptions), setting, settings) { private val customServerItems = (extraCustomServerOptions + dropboxOptions).toGdxArray() private val dropboxItems = dropboxOptions.toGdxArray() - private val settingsSelect: SettingsSelect - - init { - val initialOptions = if (OnlineMultiplayer.usesCustomServer()) customServerItems else dropboxItems - settingsSelect = SettingsSelect(labelText, initialOptions, setting, settings) - } fun update(isCustomServer: Boolean) { - if (isCustomServer && settingsSelect.items.size != customServerItems.size) { - settingsSelect.replaceItems(customServerItems) - } else if (!isCustomServer && settingsSelect.items.size != dropboxItems.size) { - settingsSelect.replaceItems(dropboxItems) + if (isCustomServer && items.size != customServerItems.size) { + replaceItems(customServerItems) + } else if (!isCustomServer && items.size != dropboxItems.size) { + replaceItems(dropboxItems) } } +} - fun addTo(tab: Table) = settingsSelect.addTo(tab) +private fun getInitialOptions(extraCustomServerOptions: List>, dropboxOptions: List>): Iterable> { + val customServerItems = (extraCustomServerOptions + dropboxOptions).toGdxArray() + val dropboxItems = dropboxOptions.toGdxArray() + return if (OnlineMultiplayer.usesCustomServer()) customServerItems else dropboxItems } private fun fixTextFieldUrlOnType(TextField: TextField) { @@ -260,3 +269,13 @@ private fun createRefreshOptions(unit: ChronoUnit, vararg options: Long): List) { + val table = Table() + settingsSelect.addTo(table) + tab.add(table).growX().fillX().row() +} + +private fun addSeparator(tab: Table) { + tab.addSeparator(ImageGetter.getBlue().brighten(0.1f)) +} diff --git a/core/src/com/unciv/ui/options/OptionsPopup.kt b/core/src/com/unciv/ui/options/OptionsPopup.kt index d6c42af26d..87ca00330d 100644 --- a/core/src/com/unciv/ui/options/OptionsPopup.kt +++ b/core/src/com/unciv/ui/options/OptionsPopup.kt @@ -3,6 +3,7 @@ package com.unciv.ui.options import com.badlogic.gdx.Gdx import com.badlogic.gdx.Input import com.badlogic.gdx.graphics.Color +import com.badlogic.gdx.scenes.scene2d.ui.Label import com.badlogic.gdx.scenes.scene2d.ui.SelectBox import com.badlogic.gdx.scenes.scene2d.ui.Table import com.badlogic.gdx.scenes.scene2d.utils.ChangeListener @@ -191,10 +192,16 @@ open class SettingsSelect( settings: GameSettings ) { private val settingsProperty: KMutableProperty0 = setting.getProperty(settings) - private val label = labelText.toLabel() + private val label = createLabel(labelText) protected val refreshSelectBox = createSelectBox(items.toGdxArray(), settings) val items by refreshSelectBox::items + private fun createLabel(labelText: String): Label { + val selectLabel = labelText.toLabel() + selectLabel.wrap = true + return selectLabel + } + private fun createSelectBox(initialItems: Array>, settings: GameSettings): SelectBox> { val selectBox = SelectBox>(BaseScreen.skin) selectBox.items = initialItems @@ -215,7 +222,7 @@ open class SettingsSelect( } fun addTo(table: Table) { - table.add(label).left() + table.add(label).growX().left() table.add(refreshSelectBox).row() }