diff --git a/core/src/com/unciv/Constants.kt b/core/src/com/unciv/Constants.kt index e1ebcd4c8d..f3af663c59 100644 --- a/core/src/com/unciv/Constants.kt +++ b/core/src/com/unciv/Constants.kt @@ -52,4 +52,6 @@ object Constants { val unitActionAutomation = "Automate" val unitActionExplore = "Explore" val futureTech = "Future Tech" + + const val tutorialPopupNamePrefix = "Tutorial: " } \ No newline at end of file diff --git a/core/src/com/unciv/ui/tutorials/TutorialController.kt b/core/src/com/unciv/ui/tutorials/TutorialController.kt index a90c68d443..6025c984c2 100644 --- a/core/src/com/unciv/ui/tutorials/TutorialController.kt +++ b/core/src/com/unciv/ui/tutorials/TutorialController.kt @@ -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) } } } diff --git a/core/src/com/unciv/ui/tutorials/TutorialRender.kt b/core/src/com/unciv/ui/tutorials/TutorialRender.kt index a95356a965..f99163efe4 100644 --- a/core/src/com/unciv/ui/tutorials/TutorialRender.kt +++ b/core/src/com/unciv/ui/tutorials/TutorialRender.kt @@ -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() diff --git a/core/src/com/unciv/ui/utils/Popup.kt b/core/src/com/unciv/ui/utils/Popup.kt index fd959daa9d..74283b8a67 100644 --- a/core/src/com/unciv/ui/utils/Popup.kt +++ b/core/src/com/unciv/ui/utils/Popup.kt @@ -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 get() = stage.actors.filterIsInstance() diff --git a/core/src/com/unciv/ui/worldscreen/WorldScreen.kt b/core/src/com/unciv/ui/worldscreen/WorldScreen.kt index 8f025269bc..bf828b785d 100644 --- a/core/src/com/unciv/ui/worldscreen/WorldScreen.kt +++ b/core/src/com/unciv/ui/worldscreen/WorldScreen.kt @@ -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 } diff --git a/core/src/com/unciv/ui/worldscreen/mainmenu/WorldScreenMenuPopup.kt b/core/src/com/unciv/ui/worldscreen/mainmenu/WorldScreenMenuPopup.kt index 4727edcf2c..cbeac8a611 100644 --- a/core/src/com/unciv/ui/worldscreen/mainmenu/WorldScreenMenuPopup.kt +++ b/core/src/com/unciv/ui/worldscreen/mainmenu/WorldScreenMenuPopup.kt @@ -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) } }