Fix Back=Leave game on Android, ESC=Back, both in Popups (#2356)

* Bring Incas into the main game
(also changes slinger withdraw ability to inheritable)

* Update Nations.json

* Back button fix, ESC, and behaviour of them in popups

* ESC/Back now work if there's no exitEvent

* ESC/Back: JackRainy is right, exit prompt now cancellable with same key
This commit is contained in:
proteus-anguinus 2020-04-08 14:55:00 +02:00 committed by GitHub
parent c3f038ee36
commit 9f46ceea24
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 21 additions and 14 deletions

View file

@ -20,9 +20,11 @@ class AndroidLauncher : AndroidApplication() {
}
val config = AndroidApplicationConfiguration().apply { useImmersiveMode = true }
val game = UncivGame(BuildConfig.VERSION_NAME,
CrashReportSenderAndroid(this))
{this.finish()}
val game = UncivGame (
version = BuildConfig.VERSION_NAME,
crashReportSender = CrashReportSenderAndroid(this),
exitEvent = this::finish
)
initialize(game, config)
}

View file

@ -86,7 +86,7 @@ open class CameraStageBaseScreen : Screen {
fun onBackButtonClicked(action:()->Unit): InputListener {
val listener = object : InputListener(){
override fun keyDown(event: InputEvent?, keycode: Int): Boolean {
if(keycode == Input.Keys.BACK){
if(keycode == Input.Keys.BACK || keycode == Input.Keys.ESCAPE){
action()
return true
}

View file

@ -132,7 +132,7 @@ class WorldScreen(val viewingCiv:CivilizationInfo) : CameraStageBaseScreen() {
shouldUpdate = true
}
backButtonListener = onBackButtonClicked { exitGamePrompt() }
backButtonListener = onBackButtonClicked { backButtonAndESCHandler() }
addKeyboardListener() // for map panning by W,S,A,D
@ -565,26 +565,31 @@ class WorldScreen(val viewingCiv:CivilizationInfo) : CameraStageBaseScreen() {
displayTutorial(Tutorial.Embarking)
}
private fun exitGamePrompt() {
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()) {
closeAllPopups()
return
}
// don't show a dialog, if it can't exit the game
if (game.exitEvent == null)
if (game.exitEvent == null) {
return
// remove current listener for the "BACK" button to avoid showing the dialog twice
stage.removeListener( backButtonListener )
}
val promptWindow = Popup(this)
promptWindow.addGoodSizedLabel("Do you want to exit the game?".tr())
promptWindow.row()
promptWindow.addButton("Yes"){game.exitEvent?.invoke()}
promptWindow.addButton("Yes") { game.exitEvent?.invoke() }
promptWindow.addButton("No") {
// restore the listener back
stage.addListener(backButtonListener)
promptWindow.close()
}
// show the dialog
promptWindow.open()
promptWindow.open (true) // true = always on top
}
}