Added 'back button' functionality to victory screen (#2824)

This commit is contained in:
Yair Morgenstern 2020-09-18 13:58:17 +03:00
parent 8db955b851
commit eb7aac0959
3 changed files with 8 additions and 5 deletions

View file

@ -47,7 +47,7 @@ open class PickerScreen : CameraStageBaseScreen() {
fun setDefaultCloseAction(previousScreen: CameraStageBaseScreen?=null) { fun setDefaultCloseAction(previousScreen: CameraStageBaseScreen?=null) {
closeButton.onClick { closeButton.onClick {
if(previousScreen!=null) game.setScreen(previousScreen) if (previousScreen != null) game.setScreen(previousScreen)
else game.setWorldScreen() else game.setWorldScreen()
dispose() dispose()
} }

View file

@ -95,16 +95,16 @@ open class CameraStageBaseScreen : Screen {
/** It returns the assigned [InputListener] */ /** It returns the assigned [InputListener] */
fun onBackButtonClicked(action:()->Unit): InputListener { fun onBackButtonClicked(action:()->Unit): InputListener {
val listener = object : InputListener(){ val listener = object : InputListener() {
override fun keyDown(event: InputEvent?, keycode: Int): Boolean { 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() action()
return true return true
} }
return false return false
} }
} }
stage.addListener( listener ) stage.addListener(listener)
return listener return listener
} }

View file

@ -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.Table
import com.badlogic.gdx.scenes.scene2d.ui.TextButton import com.badlogic.gdx.scenes.scene2d.ui.TextButton
import com.badlogic.gdx.utils.Align import com.badlogic.gdx.utils.Align
import com.unciv.UncivGame
import com.unciv.logic.civilization.CivilizationInfo import com.unciv.logic.civilization.CivilizationInfo
import com.unciv.models.ruleset.VictoryType import com.unciv.models.ruleset.VictoryType
import com.unciv.models.translations.tr import com.unciv.models.translations.tr
@ -74,8 +75,10 @@ class VictoryScreen(val worldScreen: WorldScreen) : PickerScreen() {
if (playerCivInfo.isDefeated()) { if (playerCivInfo.isDefeated()) {
wonOrLost("") wonOrLost("")
} else if(!someoneHasWon) } else if(!someoneHasWon) {
setDefaultCloseAction() setDefaultCloseAction()
onBackButtonClicked { game.setWorldScreen() }
}
} }