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) {
closeButton.onClick {
if(previousScreen!=null) game.setScreen(previousScreen)
if (previousScreen != null) game.setScreen(previousScreen)
else game.setWorldScreen()
dispose()
}

View file

@ -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
}

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.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() }
}
}