Options button now appears in main menu

This commit is contained in:
Yair Morgenstern 2020-08-31 23:42:09 +03:00
parent e111bba509
commit 91ad769eb2
3 changed files with 38 additions and 23 deletions

View File

@ -21,6 +21,7 @@ import com.unciv.ui.newgamescreen.NewGameScreen
import com.unciv.ui.pickerscreens.ModManagementScreen import com.unciv.ui.pickerscreens.ModManagementScreen
import com.unciv.ui.saves.LoadGameScreen import com.unciv.ui.saves.LoadGameScreen
import com.unciv.ui.utils.* import com.unciv.ui.utils.*
import com.unciv.ui.worldscreen.mainmenu.OptionsPopup
import kotlin.concurrent.thread import kotlin.concurrent.thread
class MainMenuScreen: CameraStageBaseScreen() { class MainMenuScreen: CameraStageBaseScreen() {
@ -76,7 +77,7 @@ class MainMenuScreen: CameraStageBaseScreen() {
val autosaveGame = GameSaver.getSave(autosave, false) val autosaveGame = GameSaver.getSave(autosave, false)
if (autosaveGame.exists()) { if (autosaveGame.exists()) {
val resumeTable = getTableBlock("Resume","OtherIcons/Resume") { autoLoadGame() } val resumeTable = getTableBlock("Resume","OtherIcons/Resume") { autoLoadGame() }
column1.add(resumeTable).padTop(0f).row() column1.add(resumeTable).row()
} }
val quickstartTable = getTableBlock("Quickstart", "OtherIcons/Quickstart") { quickstartNewGame() } val quickstartTable = getTableBlock("Quickstart", "OtherIcons/Quickstart") { quickstartNewGame() }
@ -109,6 +110,11 @@ class MainMenuScreen: CameraStageBaseScreen() {
} }
val optionsTable = getTableBlock("Options", "OtherIcons/Options")
{ OptionsPopup(this).open() }
column2.add(optionsTable).row()
val table=Table().apply { defaults().pad(10f) } val table=Table().apply { defaults().pad(10f) }
table.add(column1) table.add(column1)
table.add(column2) table.add(column2)

View File

@ -5,6 +5,7 @@ import com.badlogic.gdx.Gdx
import com.badlogic.gdx.graphics.Color import com.badlogic.gdx.graphics.Color
import com.badlogic.gdx.scenes.scene2d.ui.* import com.badlogic.gdx.scenes.scene2d.ui.*
import com.badlogic.gdx.utils.Array import com.badlogic.gdx.utils.Array
import com.unciv.MainMenuScreen
import com.unciv.logic.civilization.PlayerType import com.unciv.logic.civilization.PlayerType
import com.unciv.models.UncivSound import com.unciv.models.UncivSound
import com.unciv.models.translations.TranslationFileWriter import com.unciv.models.translations.TranslationFileWriter
@ -23,9 +24,9 @@ class Language(val language:String, val percentComplete:Int){
} }
} }
class WorldScreenOptionsPopup(val worldScreen:WorldScreen) : Popup(worldScreen) { class OptionsPopup(val previousScreen:CameraStageBaseScreen) : Popup(previousScreen) {
var selectedLanguage: String = "English" var selectedLanguage: String = "English"
private val settings = worldScreen.game.settings private val settings = previousScreen.game.settings
private val innerTable = Table(CameraStageBaseScreen.skin) private val innerTable = Table(CameraStageBaseScreen.skin)
init { init {
@ -39,10 +40,13 @@ class WorldScreenOptionsPopup(val worldScreen:WorldScreen) : Popup(worldScreen)
scrollPane.setScrollingDisabled(true, false) scrollPane.setScrollingDisabled(true, false)
add(scrollPane).maxHeight(screen.stage.height * 0.6f).row() add(scrollPane).maxHeight(screen.stage.height * 0.6f).row()
addCloseButton() { worldScreen.enableNextTurnButtonAfterOptions() } addCloseButton() {
if(previousScreen is WorldScreen)
previousScreen.enableNextTurnButtonAfterOptions()
}
pack() // Needed to show the background. pack() // Needed to show the background.
center(worldScreen.game.worldScreen.stage) center(previousScreen.stage)
} }
private fun addHeader (text: String) { private fun addHeader (text: String) {
@ -54,17 +58,21 @@ class WorldScreenOptionsPopup(val worldScreen:WorldScreen) : Popup(worldScreen)
val button = YesNoButton(initialValue, skin) { val button = YesNoButton(initialValue, skin) {
action(it) action(it)
settings.save() settings.save()
if (updateWorld) if (updateWorld && previousScreen is WorldScreen)
worldScreen.game.worldScreen.shouldUpdate = true previousScreen.shouldUpdate = true
} }
innerTable.add(button).row() innerTable.add(button).row()
} }
private fun reloadWorldAndOptions() { private fun reloadWorldAndOptions() {
settings.save() settings.save()
worldScreen.game.worldScreen = WorldScreen(worldScreen.viewingCiv) if (previousScreen is WorldScreen) {
worldScreen.game.setWorldScreen() previousScreen.game.worldScreen = WorldScreen(previousScreen.viewingCiv)
WorldScreenOptionsPopup(worldScreen.game.worldScreen).open() previousScreen.game.setWorldScreen()
} else if (previousScreen is MainMenuScreen) {
previousScreen.game.setScreen(MainMenuScreen())
}
OptionsPopup(previousScreen.game.screen as CameraStageBaseScreen).open()
} }
private fun rebuildInnerTable() { private fun rebuildInnerTable() {
@ -102,9 +110,10 @@ class WorldScreenOptionsPopup(val worldScreen:WorldScreen) : Popup(worldScreen)
addYesNoRow ("Move units with a single tap", settings.singleTapMove) { settings.singleTapMove = it } addYesNoRow ("Move units with a single tap", settings.singleTapMove) { settings.singleTapMove = it }
addYesNoRow ("Auto-assign city production", settings.autoAssignCityProduction, true) { addYesNoRow ("Auto-assign city production", settings.autoAssignCityProduction, true) {
settings.autoAssignCityProduction = it settings.autoAssignCityProduction = it
if (it && worldScreen.viewingCiv.isCurrentPlayer() && worldScreen.viewingCiv.playerType == PlayerType.Human) { if (it && previousScreen is WorldScreen &&
worldScreen.game.gameInfo.currentPlayerCiv.cities.forEach { previousScreen.viewingCiv.isCurrentPlayer() && previousScreen.viewingCiv.playerType == PlayerType.Human) {
city -> city.cityConstructions.chooseNextConstruction() previousScreen.gameInfo.currentPlayerCiv.cities.forEach { city ->
city.cityConstructions.chooseNextConstruction()
} }
} }
} }
@ -114,13 +123,13 @@ class WorldScreenOptionsPopup(val worldScreen:WorldScreen) : Popup(worldScreen)
addAutosaveTurnsSelectBox() addAutosaveTurnsSelectBox()
// at the moment the notification service only exists on Android // at the moment tmainmhe notification service only exists on Android
addNotificationOptions() addNotificationOptions()
addHeader("Other options") addHeader("Other options")
addYesNoRow("Extended map editor", settings.extendedMapEditor) { settings.extendedMapEditor = it } addYesNoRow("Extended map editor", settings.extendedMapEditor) { settings.extendedMapEditor = it }
addYesNoRow("Experimental mod manager", settings.showModManager) { settings.showModManager = it } addYesNoRow("Experimental mod manager", settings.showModManager) { settings.showModManager = it; reloadWorldAndOptions() }
addSoundEffectsVolumeSlider() addSoundEffectsVolumeSlider()
addMusicVolumeSlider() addMusicVolumeSlider()
@ -128,7 +137,7 @@ class WorldScreenOptionsPopup(val worldScreen:WorldScreen) : Popup(worldScreen)
addSetUserId() addSetUserId()
innerTable.add("Version".toLabel()).pad(10f) innerTable.add("Version".toLabel()).pad(10f)
innerTable.add(worldScreen.game.version.toLabel()).pad(10f).row() innerTable.add(previousScreen.game.version.toLabel()).pad(10f).row()
} }
private fun addSetUserId() { private fun addSetUserId() {
@ -199,7 +208,7 @@ class WorldScreenOptionsPopup(val worldScreen:WorldScreen) : Popup(worldScreen)
} }
private fun addMusicVolumeSlider() { private fun addMusicVolumeSlider() {
val musicLocation = Gdx.files.local(worldScreen.game.musicLocation) val musicLocation = Gdx.files.local(previousScreen.game.musicLocation)
if (musicLocation.exists()) { if (musicLocation.exists()) {
innerTable.add("Music volume".tr()) innerTable.add("Music volume".tr())
@ -209,9 +218,9 @@ class WorldScreenOptionsPopup(val worldScreen:WorldScreen) : Popup(worldScreen)
settings.musicVolume = musicVolumeSlider.value settings.musicVolume = musicVolumeSlider.value
settings.save() settings.save()
val music = worldScreen.game.music val music = previousScreen.game.music
if (music == null) // restart music, if it was off at the app start if (music == null) // restart music, if it was off at the app start
thread(name = "Music") { worldScreen.game.startMusic() } thread(name = "Music") { previousScreen.game.startMusic() }
music?.volume = 0.4f * musicVolumeSlider.value music?.volume = 0.4f * musicVolumeSlider.value
} }
@ -234,7 +243,7 @@ class WorldScreenOptionsPopup(val worldScreen:WorldScreen) : Popup(worldScreen)
musicLocation.write(file, false) musicLocation.write(file, false)
Gdx.app.postRunnable { Gdx.app.postRunnable {
rebuildInnerTable() rebuildInnerTable()
worldScreen.game.startMusic() previousScreen.game.startMusic()
} }
} catch (ex: Exception) { } catch (ex: Exception) {
Gdx.app.postRunnable { Gdx.app.postRunnable {
@ -318,7 +327,7 @@ class WorldScreenOptionsPopup(val worldScreen:WorldScreen) : Popup(worldScreen)
private fun addLanguageSelectBox() { private fun addLanguageSelectBox() {
val languageSelectBox = SelectBox<Language>(skin) val languageSelectBox = SelectBox<Language>(skin)
val languageArray = Array<Language>() val languageArray = Array<Language>()
worldScreen.game.translations.percentCompleteOfLanguages previousScreen.game.translations.percentCompleteOfLanguages
.map { Language(it.key, if (it.key == "English") 100 else it.value) } .map { Language(it.key, if (it.key == "English") 100 else it.value) }
.sortedByDescending { it.percentComplete } .sortedByDescending { it.percentComplete }
.forEach { languageArray.add(it) } .forEach { languageArray.add(it) }
@ -341,7 +350,7 @@ class WorldScreenOptionsPopup(val worldScreen:WorldScreen) : Popup(worldScreen)
private fun selectLanguage() { private fun selectLanguage() {
settings.language = selectedLanguage settings.language = selectedLanguage
worldScreen.game.translations.tryReadTranslationForCurrentLanguage() previousScreen.game.translations.tryReadTranslationForCurrentLanguage()
reloadWorldAndOptions() reloadWorldAndOptions()
} }

View File

@ -50,7 +50,7 @@ class WorldScreenMenuPopup(val worldScreen: WorldScreen) : Popup(worldScreen) {
addSeparator() addSeparator()
addSquareButton("Options".tr()){ addSquareButton("Options".tr()){
WorldScreenOptionsPopup(worldScreen).open(force = true) OptionsPopup(worldScreen).open(force = true)
close() close()
}.size(width,height) }.size(width,height)
addSeparator() addSeparator()