From eb7aac0959cfefdb3e791f3d78441ff253c695a3 Mon Sep 17 00:00:00 2001 From: Yair Morgenstern Date: Fri, 18 Sep 2020 13:58:17 +0300 Subject: [PATCH] Added 'back button' functionality to victory screen (#2824) --- core/src/com/unciv/ui/pickerscreens/PickerScreen.kt | 2 +- core/src/com/unciv/ui/utils/CameraStageBaseScreen.kt | 6 +++--- core/src/com/unciv/ui/victoryscreen/VictoryScreen.kt | 5 ++++- 3 files changed, 8 insertions(+), 5 deletions(-) diff --git a/core/src/com/unciv/ui/pickerscreens/PickerScreen.kt b/core/src/com/unciv/ui/pickerscreens/PickerScreen.kt index 91a38f8d..98b64db9 100644 --- a/core/src/com/unciv/ui/pickerscreens/PickerScreen.kt +++ b/core/src/com/unciv/ui/pickerscreens/PickerScreen.kt @@ -47,7 +47,7 @@ open class PickerScreen : CameraStageBaseScreen() { fun setDefaultCloseAction(previousScreen: CameraStageBaseScreen?=null) { closeButton.onClick { - if(previousScreen!=null) game.setScreen(previousScreen) + if (previousScreen != null) game.setScreen(previousScreen) else game.setWorldScreen() dispose() } diff --git a/core/src/com/unciv/ui/utils/CameraStageBaseScreen.kt b/core/src/com/unciv/ui/utils/CameraStageBaseScreen.kt index e5684c9b..23538266 100644 --- a/core/src/com/unciv/ui/utils/CameraStageBaseScreen.kt +++ b/core/src/com/unciv/ui/utils/CameraStageBaseScreen.kt @@ -95,16 +95,16 @@ open class CameraStageBaseScreen : Screen { /** It returns the assigned [InputListener] */ fun onBackButtonClicked(action:()->Unit): InputListener { - val listener = object : InputListener(){ + val listener = object : InputListener() { override fun keyDown(event: InputEvent?, keycode: Int): Boolean { - if(keycode == Input.Keys.BACK || keycode == Input.Keys.ESCAPE){ + if (keycode == Input.Keys.BACK || keycode == Input.Keys.ESCAPE) { action() return true } return false } } - stage.addListener( listener ) + stage.addListener(listener) return listener } diff --git a/core/src/com/unciv/ui/victoryscreen/VictoryScreen.kt b/core/src/com/unciv/ui/victoryscreen/VictoryScreen.kt index 60b49562..18b56ff9 100644 --- a/core/src/com/unciv/ui/victoryscreen/VictoryScreen.kt +++ b/core/src/com/unciv/ui/victoryscreen/VictoryScreen.kt @@ -4,6 +4,7 @@ import com.badlogic.gdx.graphics.Color import com.badlogic.gdx.scenes.scene2d.ui.Table import com.badlogic.gdx.scenes.scene2d.ui.TextButton import com.badlogic.gdx.utils.Align +import com.unciv.UncivGame import com.unciv.logic.civilization.CivilizationInfo import com.unciv.models.ruleset.VictoryType import com.unciv.models.translations.tr @@ -74,8 +75,10 @@ class VictoryScreen(val worldScreen: WorldScreen) : PickerScreen() { if (playerCivInfo.isDefeated()) { wonOrLost("") - } else if(!someoneHasWon) + } else if(!someoneHasWon) { setDefaultCloseAction() + onBackButtonClicked { game.setWorldScreen() } + } }