mirror of
https://github.com/yairm210/Unciv.git
synced 2025-07-21 13:18:56 +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 unitActionAutomation = "Automate"
|
||||||
val unitActionExplore = "Explore"
|
val unitActionExplore = "Explore"
|
||||||
val futureTech = "Future Tech"
|
val futureTech = "Future Tech"
|
||||||
|
|
||||||
|
const val tutorialPopupNamePrefix = "Tutorial: "
|
||||||
}
|
}
|
@ -19,7 +19,23 @@ class TutorialController(screen: CameraStageBaseScreen) {
|
|||||||
showTutorialIfNeeded()
|
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() {
|
private fun showTutorialIfNeeded() {
|
||||||
|
if (!UncivGame.Current.settings.showTutorials) return
|
||||||
val tutorial = tutorialQueue.firstOrNull()
|
val tutorial = tutorialQueue.firstOrNull()
|
||||||
if (tutorial == null) {
|
if (tutorial == null) {
|
||||||
allTutorialsShowedCallback?.invoke()
|
allTutorialsShowedCallback?.invoke()
|
||||||
@ -27,15 +43,7 @@ class TutorialController(screen: CameraStageBaseScreen) {
|
|||||||
isTutorialShowing = true
|
isTutorialShowing = true
|
||||||
val texts = getTutorial(tutorial)
|
val texts = getTutorial(tutorial)
|
||||||
tutorialRender.showTutorial(TutorialForRender(tutorial, texts)) {
|
tutorialRender.showTutorial(TutorialForRender(tutorial, texts)) {
|
||||||
tutorialQueue.remove(tutorial)
|
removeTutorial(tutorial)
|
||||||
isTutorialShowing = false
|
|
||||||
with(UncivGame.Current.settings) {
|
|
||||||
if (!tutorialsShown.contains(tutorial.name)) {
|
|
||||||
tutorialsShown.add(tutorial.name)
|
|
||||||
save()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
showTutorialIfNeeded()
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -3,6 +3,7 @@ package com.unciv.ui.tutorials
|
|||||||
import com.badlogic.gdx.Gdx
|
import com.badlogic.gdx.Gdx
|
||||||
import com.badlogic.gdx.scenes.scene2d.ui.TextButton
|
import com.badlogic.gdx.scenes.scene2d.ui.TextButton
|
||||||
import com.badlogic.gdx.utils.Array
|
import com.badlogic.gdx.utils.Array
|
||||||
|
import com.unciv.Constants
|
||||||
import com.unciv.models.Tutorial
|
import com.unciv.models.Tutorial
|
||||||
import com.unciv.models.translations.tr
|
import com.unciv.models.translations.tr
|
||||||
import com.unciv.ui.utils.CameraStageBaseScreen
|
import com.unciv.ui.utils.CameraStageBaseScreen
|
||||||
@ -24,6 +25,7 @@ class TutorialRender(private val screen: CameraStageBaseScreen) {
|
|||||||
closeAction()
|
closeAction()
|
||||||
} else {
|
} else {
|
||||||
val tutorialPopup = Popup(screen)
|
val tutorialPopup = Popup(screen)
|
||||||
|
tutorialPopup.name = Constants.tutorialPopupNamePrefix + tutorialName
|
||||||
|
|
||||||
if (Gdx.files.internal("ExtraImages/$tutorialName").exists()) {
|
if (Gdx.files.internal("ExtraImages/$tutorialName").exists()) {
|
||||||
tutorialPopup.add(ImageGetter.getExternalImage(tutorialName)).row()
|
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.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>
|
val CameraStageBaseScreen.popups: List<Popup>
|
||||||
get() = stage.actors.filterIsInstance<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.TechButton
|
||||||
import com.unciv.ui.pickerscreens.TechPickerScreen
|
import com.unciv.ui.pickerscreens.TechPickerScreen
|
||||||
import com.unciv.ui.trade.DiplomacyScreen
|
import com.unciv.ui.trade.DiplomacyScreen
|
||||||
|
import com.unciv.ui.tutorials.TutorialController
|
||||||
import com.unciv.ui.utils.*
|
import com.unciv.ui.utils.*
|
||||||
import com.unciv.ui.worldscreen.bottombar.BattleTable
|
import com.unciv.ui.worldscreen.bottombar.BattleTable
|
||||||
import com.unciv.ui.worldscreen.bottombar.TileInfoTable
|
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.
|
// 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)
|
// After removeListener just in case this is slow (enumerating all stage actors)
|
||||||
if (hasOpenPopups()) {
|
if (hasOpenPopups()) {
|
||||||
closeAllPopups()
|
val closedName = closeOneVisiblePopup() ?: return
|
||||||
|
if (closedName.startsWith(Constants.tutorialPopupNamePrefix)) {
|
||||||
|
closedName.removePrefix(Constants.tutorialPopupNamePrefix)
|
||||||
|
tutorialController.removeTutorial(closedName)
|
||||||
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -65,13 +65,13 @@ class WorldScreenMenuPopup(val worldScreen: WorldScreen) : Popup(worldScreen) {
|
|||||||
addSeparator()
|
addSeparator()
|
||||||
|
|
||||||
addSquareButton("Options".tr()){
|
addSquareButton("Options".tr()){
|
||||||
WorldScreenOptionsPopup(worldScreen).open()
|
WorldScreenOptionsPopup(worldScreen).open(force = true)
|
||||||
close()
|
close()
|
||||||
}.size(width,height)
|
}.size(width,height)
|
||||||
addSeparator()
|
addSeparator()
|
||||||
|
|
||||||
addSquareButton("Community"){
|
addSquareButton("Community"){
|
||||||
WorldScreenCommunityPopup(worldScreen).open()
|
WorldScreenCommunityPopup(worldScreen).open(force = true)
|
||||||
close()
|
close()
|
||||||
}.size(width,height)
|
}.size(width,height)
|
||||||
addSeparator()
|
addSeparator()
|
||||||
@ -108,7 +108,7 @@ class WorldScreenMenuPopup(val worldScreen: WorldScreen) : Popup(worldScreen) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
mapEditorPopup.addCloseButton()
|
mapEditorPopup.addCloseButton()
|
||||||
mapEditorPopup.open()
|
mapEditorPopup.open(force = true)
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user