mirror of
https://github.com/yairm210/Unciv.git
synced 2025-07-22 22:00:24 +07:00
Unified exit game popups, removed obsolete closing handler (#4048)
This commit is contained in:
@ -14,7 +14,6 @@ import com.unciv.logic.map.MapSize
|
||||
import com.unciv.logic.map.MapSizeNew
|
||||
import com.unciv.logic.map.MapType
|
||||
import com.unciv.models.ruleset.RulesetCache
|
||||
import com.unciv.models.translations.tr
|
||||
import com.unciv.ui.MultiplayerScreen
|
||||
import com.unciv.ui.mapeditor.*
|
||||
import com.unciv.ui.newgamescreen.GameSetupInfo
|
||||
@ -22,7 +21,6 @@ import com.unciv.ui.newgamescreen.NewGameScreen
|
||||
import com.unciv.ui.pickerscreens.ModManagementScreen
|
||||
import com.unciv.ui.saves.LoadGameScreen
|
||||
import com.unciv.ui.utils.*
|
||||
import com.unciv.ui.worldscreen.mainmenu.OptionsPopup
|
||||
import kotlin.concurrent.thread
|
||||
|
||||
class MainMenuScreen: CameraStageBaseScreen() {
|
||||
@ -128,13 +126,7 @@ class MainMenuScreen: CameraStageBaseScreen() {
|
||||
closeAllPopups()
|
||||
return@onBackButtonClicked
|
||||
}
|
||||
val promptWindow = Popup(this)
|
||||
promptWindow.addGoodSizedLabel("Do you want to exit the game?".tr())
|
||||
promptWindow.row()
|
||||
promptWindow.addButton("Yes") { Gdx.app.exit() }
|
||||
promptWindow.addButton("No") { promptWindow.close() }
|
||||
// show the dialog
|
||||
promptWindow.open() // true = always on top
|
||||
ExitGamePopup(this)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -19,10 +19,7 @@ class TutorialController(screen: CameraStageBaseScreen) {
|
||||
showTutorialIfNeeded()
|
||||
}
|
||||
|
||||
fun removeTutorial(tutorialName: String) {
|
||||
Tutorial.valueOf(tutorialName).let { removeTutorial(it) }
|
||||
}
|
||||
fun removeTutorial(tutorial: Tutorial) {
|
||||
private fun removeTutorial(tutorial: Tutorial) {
|
||||
isTutorialShowing = false
|
||||
tutorialQueue.remove(tutorial)
|
||||
with(UncivGame.Current.settings) {
|
||||
|
@ -28,13 +28,11 @@ class TutorialRender(private val screen: CameraStageBaseScreen) {
|
||||
|
||||
tutorialPopup.addGoodSizedLabel(texts[0]).row()
|
||||
|
||||
val button = Constants.close.toTextButton()
|
||||
button.onClick {
|
||||
tutorialPopup.addCloseButton(additionalKey = KeyCharAndCode(' ')) {
|
||||
tutorialPopup.remove()
|
||||
texts.removeIndex(0)
|
||||
showDialog(tutorialName, texts, closeAction)
|
||||
}
|
||||
tutorialPopup.add(button).pad(10f)
|
||||
tutorialPopup.open()
|
||||
}
|
||||
}
|
||||
|
@ -72,7 +72,7 @@ open class Popup(val screen: CameraStageBaseScreen): Table(CameraStageBaseScreen
|
||||
}
|
||||
|
||||
/* All additions to the popup are to the inner table - we shouldn't care that there's an inner table at all */
|
||||
override fun <T : Actor?> add(actor: T): Cell<T> = innerTable.add(actor)
|
||||
final override fun <T : Actor?> add(actor: T): Cell<T> = innerTable.add(actor)
|
||||
override fun row(): Cell<Actor> = innerTable.row()
|
||||
fun addSeparator() = innerTable.addSeparator()
|
||||
|
||||
|
@ -1,5 +1,6 @@
|
||||
package com.unciv.ui.utils
|
||||
|
||||
import com.badlogic.gdx.Gdx
|
||||
import com.badlogic.gdx.Input
|
||||
import com.unciv.UncivGame
|
||||
|
||||
@ -9,7 +10,7 @@ import com.unciv.UncivGame
|
||||
* @param screen The parent screen - see [Popup.screen]. Optional, defaults to the current [WorldScreen][com.unciv.ui.worldscreen.WorldScreen]
|
||||
* @param restoreDefault A lambda to execute when "No" is chosen
|
||||
*/
|
||||
class YesNoPopup (
|
||||
open class YesNoPopup (
|
||||
question:String,
|
||||
action:()->Unit,
|
||||
screen: CameraStageBaseScreen = UncivGame.Current.worldScreen,
|
||||
@ -26,3 +27,15 @@ class YesNoPopup (
|
||||
keyPressDispatcher[Input.Keys.BACK] = no
|
||||
}
|
||||
}
|
||||
|
||||
/** Shortcut to open a [YesNoPopup] with the exit game question */
|
||||
class ExitGamePopup(screen: CameraStageBaseScreen, force: Boolean = false)
|
||||
: YesNoPopup (
|
||||
question = "Do you want to exit the game?",
|
||||
action = { Gdx.app.exit() },
|
||||
screen = screen
|
||||
) {
|
||||
init {
|
||||
open(force)
|
||||
}
|
||||
}
|
||||
|
@ -760,19 +760,6 @@ class WorldScreen(val gameInfo: GameInfo, val viewingCiv:CivilizationInfo) : Cam
|
||||
|
||||
private fun backButtonAndESCHandler() {
|
||||
|
||||
// Since Popups including the Main Menu and the Options screen have no own back button
|
||||
// listener and no trivial way to set one, back/esc with one of them open ends up here.
|
||||
// Also, the reaction of other popups like 'disband this unit' to back/esc feels nicer this way.
|
||||
// After removeListener just in case this is slow (enumerating all stage actors)
|
||||
if (hasOpenPopups()) {
|
||||
val closedName = closeOneVisiblePopup() ?: return
|
||||
if (closedName.startsWith(Constants.tutorialPopupNamePrefix)) {
|
||||
closedName.removePrefix(Constants.tutorialPopupNamePrefix)
|
||||
tutorialController.removeTutorial(closedName)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// Deselect Unit
|
||||
if (bottomUnitTable.selectedUnit != null) {
|
||||
bottomUnitTable.selectUnit()
|
||||
@ -789,13 +776,8 @@ class WorldScreen(val gameInfo: GameInfo, val viewingCiv:CivilizationInfo) : Cam
|
||||
return
|
||||
}
|
||||
|
||||
val promptWindow = Popup(this)
|
||||
promptWindow.addGoodSizedLabel("Do you want to exit the game?".tr())
|
||||
promptWindow.row()
|
||||
promptWindow.addButton("Yes") { Gdx.app.exit() }
|
||||
promptWindow.addButton("No") { promptWindow.close() }
|
||||
// show the dialog
|
||||
promptWindow.open(true) // true = always on top
|
||||
ExitGamePopup(this, true)
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user