mirror of
https://github.com/yairm210/Unciv.git
synced 2025-07-16 18:59:15 +07:00
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:
@ -52,4 +52,6 @@ object Constants {
|
||||
val unitActionAutomation = "Automate"
|
||||
val unitActionExplore = "Explore"
|
||||
val futureTech = "Future Tech"
|
||||
|
||||
const val tutorialPopupNamePrefix = "Tutorial: "
|
||||
}
|
@ -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)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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()
|
||||
|
@ -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>()
|
||||
|
@ -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
|
||||
}
|
||||
|
||||
|
@ -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)
|
||||
}
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user