Esc/Back and popups - closing all not best idea? (#2376)

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

* Update Nations.json

* ESC/Back handling with multiple popups

* ESC/Back handling with multiple popups

* ESC/Back handling with multiple popups - clearer code
This commit is contained in:
proteus-anguinus
2020-04-11 20:40:08 +02:00
committed by GitHub
parent 4cc10aa38f
commit c866d96707
6 changed files with 32 additions and 14 deletions

View File

@ -52,4 +52,6 @@ object Constants {
val unitActionAutomation = "Automate"
val unitActionExplore = "Explore"
val futureTech = "Future Tech"
const val tutorialPopupNamePrefix = "Tutorial: "
}

View File

@ -19,7 +19,23 @@ class TutorialController(screen: CameraStageBaseScreen) {
showTutorialIfNeeded()
}
fun removeTutorial(tutorialName: String) {
Tutorial.valueOf(tutorialName)?.let { removeTutorial(it) }
}
fun removeTutorial(tutorial: Tutorial) {
isTutorialShowing = false
tutorialQueue.remove(tutorial)
with(UncivGame.Current.settings) {
if (!tutorialsShown.contains(tutorial.name)) {
tutorialsShown.add(tutorial.name)
save()
}
}
showTutorialIfNeeded()
}
private fun showTutorialIfNeeded() {
if (!UncivGame.Current.settings.showTutorials) return
val tutorial = tutorialQueue.firstOrNull()
if (tutorial == null) {
allTutorialsShowedCallback?.invoke()
@ -27,15 +43,7 @@ class TutorialController(screen: CameraStageBaseScreen) {
isTutorialShowing = true
val texts = getTutorial(tutorial)
tutorialRender.showTutorial(TutorialForRender(tutorial, texts)) {
tutorialQueue.remove(tutorial)
isTutorialShowing = false
with(UncivGame.Current.settings) {
if (!tutorialsShown.contains(tutorial.name)) {
tutorialsShown.add(tutorial.name)
save()
}
}
showTutorialIfNeeded()
removeTutorial(tutorial)
}
}
}

View File

@ -3,6 +3,7 @@ package com.unciv.ui.tutorials
import com.badlogic.gdx.Gdx
import com.badlogic.gdx.scenes.scene2d.ui.TextButton
import com.badlogic.gdx.utils.Array
import com.unciv.Constants
import com.unciv.models.Tutorial
import com.unciv.models.translations.tr
import com.unciv.ui.utils.CameraStageBaseScreen
@ -24,6 +25,7 @@ class TutorialRender(private val screen: CameraStageBaseScreen) {
closeAction()
} else {
val tutorialPopup = Popup(screen)
tutorialPopup.name = Constants.tutorialPopupNamePrefix + tutorialName
if (Gdx.files.internal("ExtraImages/$tutorialName").exists()) {
tutorialPopup.add(ImageGetter.getExternalImage(tutorialName)).row()

View File

@ -67,7 +67,8 @@ open class Popup(val screen: CameraStageBaseScreen): Table(CameraStageBaseScreen
}
fun CameraStageBaseScreen.hasOpenPopups(): Boolean = stage.actors.any { it is Popup && it.isVisible }
fun CameraStageBaseScreen.closeAllPopups() { for (popup in popups) popup.close() }
fun CameraStageBaseScreen.closeAllPopups() = popups.forEach { it.close() }
fun CameraStageBaseScreen.closeOneVisiblePopup() = popups.lastOrNull { it.isVisible }?.apply { close() }?.name
val CameraStageBaseScreen.popups: List<Popup>
get() = stage.actors.filterIsInstance<Popup>()

View File

@ -30,6 +30,7 @@ import com.unciv.ui.pickerscreens.PolicyPickerScreen
import com.unciv.ui.pickerscreens.TechButton
import com.unciv.ui.pickerscreens.TechPickerScreen
import com.unciv.ui.trade.DiplomacyScreen
import com.unciv.ui.tutorials.TutorialController
import com.unciv.ui.utils.*
import com.unciv.ui.worldscreen.bottombar.BattleTable
import com.unciv.ui.worldscreen.bottombar.TileInfoTable
@ -599,7 +600,11 @@ class WorldScreen(val viewingCiv:CivilizationInfo) : CameraStageBaseScreen() {
// 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()
val closedName = closeOneVisiblePopup() ?: return
if (closedName.startsWith(Constants.tutorialPopupNamePrefix)) {
closedName.removePrefix(Constants.tutorialPopupNamePrefix)
tutorialController.removeTutorial(closedName)
}
return
}

View File

@ -65,13 +65,13 @@ class WorldScreenMenuPopup(val worldScreen: WorldScreen) : Popup(worldScreen) {
addSeparator()
addSquareButton("Options".tr()){
WorldScreenOptionsPopup(worldScreen).open()
WorldScreenOptionsPopup(worldScreen).open(force = true)
close()
}.size(width,height)
addSeparator()
addSquareButton("Community"){
WorldScreenCommunityPopup(worldScreen).open()
WorldScreenCommunityPopup(worldScreen).open(force = true)
close()
}.size(width,height)
addSeparator()
@ -108,7 +108,7 @@ class WorldScreenMenuPopup(val worldScreen: WorldScreen) : Popup(worldScreen) {
}
mapEditorPopup.addCloseButton()
mapEditorPopup.open()
mapEditorPopup.open(force = true)
}
}