diff --git a/core/src/com/unciv/ui/cityscreen/CityInfoTable.kt b/core/src/com/unciv/ui/cityscreen/CityInfoTable.kt index 5cfd63c74d..42cd842250 100644 --- a/core/src/com/unciv/ui/cityscreen/CityInfoTable.kt +++ b/core/src/com/unciv/ui/cityscreen/CityInfoTable.kt @@ -95,7 +95,7 @@ class CityInfoTable(private val cityScreen: CityScreen) : Table(CameraStageBaseS cityScreen.city.sellBuilding(building.name) cityScreen.city.cityStats.update() cityScreen.update() - }, cityScreen) + }, cityScreen).open() } if (cityScreen.city.hasSoldBuildingThisTurn || cityScreen.city.isPuppet || !UncivGame.Current.worldScreen.isPlayersTurn) diff --git a/core/src/com/unciv/ui/cityscreen/ConstructionsTable.kt b/core/src/com/unciv/ui/cityscreen/ConstructionsTable.kt index 49fa99f9eb..142421b04f 100644 --- a/core/src/com/unciv/ui/cityscreen/ConstructionsTable.kt +++ b/core/src/com/unciv/ui/cityscreen/ConstructionsTable.kt @@ -14,7 +14,6 @@ import com.unciv.models.UncivSound import com.unciv.models.stats.Stat import com.unciv.models.translations.tr import com.unciv.ui.utils.* -import com.unciv.ui.utils.YesNoPopup class ConstructionsTable(val cityScreen: CityScreen) : Table(CameraStageBaseScreen.skin) { /* -2 = Nothing, -1 = current construction, >= 0 queue entry */ @@ -294,7 +293,7 @@ class ConstructionsTable(val cityScreen: CityScreen) : Table(CameraStageBaseScre } if (!construction.shouldBeDisplayed(cityConstructions)) cityScreen.selectedConstruction = null cityScreen.update() - }, cityScreen) + }, cityScreen).open() } if (constructionGoldCost > city.civInfo.gold) diff --git a/core/src/com/unciv/ui/mapeditor/LoadMapScreen.kt b/core/src/com/unciv/ui/mapeditor/LoadMapScreen.kt index 231c0bb61d..6daa7700b5 100644 --- a/core/src/com/unciv/ui/mapeditor/LoadMapScreen.kt +++ b/core/src/com/unciv/ui/mapeditor/LoadMapScreen.kt @@ -12,7 +12,6 @@ import com.unciv.models.translations.tr import com.unciv.ui.pickerscreens.PickerScreen import com.unciv.ui.saves.Gzip import com.unciv.ui.utils.* -import com.unciv.ui.utils.YesNoPopup class LoadMapScreen(previousMap: TileMap?) : PickerScreen(){ var chosenMap = "" @@ -43,7 +42,7 @@ class LoadMapScreen(previousMap: TileMap?) : PickerScreen(){ val downloadMapButton = TextButton("Download map".tr(), skin) downloadMapButton.onClick { - MapDownloadPopup(this) + MapDownloadPopup(this).open() } rightSideTable.add(downloadMapButton).row() @@ -70,7 +69,7 @@ class LoadMapScreen(previousMap: TileMap?) : PickerScreen(){ YesNoPopup("Are you sure you want to delete this map?", { MapSaver().deleteMap(chosenMap) UncivGame.Current.setScreen(LoadMapScreen(previousMap)) - }, this) + }, this).open() } deleteMapButton.disable() deleteMapButton.color = Color.RED diff --git a/core/src/com/unciv/ui/mapeditor/MapDownloadPopup.kt b/core/src/com/unciv/ui/mapeditor/MapDownloadPopup.kt index 7ec9bb478e..6469f2a80a 100644 --- a/core/src/com/unciv/ui/mapeditor/MapDownloadPopup.kt +++ b/core/src/com/unciv/ui/mapeditor/MapDownloadPopup.kt @@ -8,9 +8,9 @@ import com.unciv.UncivGame import com.unciv.logic.MapSaver import com.unciv.ui.saves.Gzip import com.unciv.ui.utils.CameraStageBaseScreen +import com.unciv.ui.utils.Popup import com.unciv.ui.utils.onClick import com.unciv.ui.worldscreen.mainmenu.DropBox -import com.unciv.ui.utils.Popup import kotlin.concurrent.thread class MapDownloadPopup(loadMapScreen: LoadMapScreen): Popup(loadMapScreen) { @@ -39,6 +39,7 @@ class MapDownloadPopup(loadMapScreen: LoadMapScreen): Popup(loadMapScreen) { val couldNotDownloadMapPopup = Popup(screen) couldNotDownloadMapPopup.addGoodSizedLabel("Could not download map!").row() couldNotDownloadMapPopup.addCloseButton() + couldNotDownloadMapPopup.open() } } } @@ -50,6 +51,5 @@ class MapDownloadPopup(loadMapScreen: LoadMapScreen): Popup(loadMapScreen) { addGoodSizedLabel("Could not get list of maps!").row() } addCloseButton() - open() } } diff --git a/core/src/com/unciv/ui/mapeditor/MapEditorMenuPopup.kt b/core/src/com/unciv/ui/mapeditor/MapEditorMenuPopup.kt index ed6ff13007..5c5b6ddb1f 100644 --- a/core/src/com/unciv/ui/mapeditor/MapEditorMenuPopup.kt +++ b/core/src/com/unciv/ui/mapeditor/MapEditorMenuPopup.kt @@ -11,9 +11,9 @@ import com.unciv.logic.map.MapType import com.unciv.logic.map.RoadStatus import com.unciv.models.translations.tr import com.unciv.ui.saves.Gzip +import com.unciv.ui.utils.Popup import com.unciv.ui.utils.onClick import com.unciv.ui.worldscreen.mainmenu.DropBox -import com.unciv.ui.utils.Popup import kotlin.concurrent.thread class MapEditorMenuPopup(mapEditorScreen: MapEditorScreen): Popup(mapEditorScreen){ @@ -95,7 +95,5 @@ class MapEditorMenuPopup(mapEditorScreen: MapEditorScreen): Popup(mapEditorScree val closeOptionsButton = TextButton("Close".tr(), skin) closeOptionsButton.onClick { close() } add(closeOptionsButton).row() - - open() } } diff --git a/core/src/com/unciv/ui/mapeditor/MapEditorScreen.kt b/core/src/com/unciv/ui/mapeditor/MapEditorScreen.kt index be09dcb86c..d2b969b7cd 100644 --- a/core/src/com/unciv/ui/mapeditor/MapEditorScreen.kt +++ b/core/src/com/unciv/ui/mapeditor/MapEditorScreen.kt @@ -13,6 +13,7 @@ import com.unciv.models.ruleset.RulesetCache import com.unciv.models.translations.tr import com.unciv.ui.utils.CameraStageBaseScreen import com.unciv.ui.utils.onClick +import com.unciv.ui.utils.popups import com.unciv.ui.utils.setFontSize class MapEditorScreen(): CameraStageBaseScreen() { @@ -76,9 +77,9 @@ class MapEditorScreen(): CameraStageBaseScreen() { val optionsMenuButton = TextButton("Menu".tr(), skin) optionsMenuButton.onClick { - if(stage.actors.any { it is MapEditorMenuPopup }) + if(popups.any { it is MapEditorMenuPopup }) return@onClick // already open - MapEditorMenuPopup(this) + MapEditorMenuPopup(this).open(force = true) } optionsMenuButton.label.setFontSize(24) optionsMenuButton.labelCell.pad(20f) diff --git a/core/src/com/unciv/ui/trade/DiplomacyScreen.kt b/core/src/com/unciv/ui/trade/DiplomacyScreen.kt index b3b3614360..55b5692210 100644 --- a/core/src/com/unciv/ui/trade/DiplomacyScreen.kt +++ b/core/src/com/unciv/ui/trade/DiplomacyScreen.kt @@ -158,7 +158,7 @@ class DiplomacyScreen(val viewingCiv:CivilizationInfo):CameraStageBaseScreen() { tradeLogic.currentTrade.theirOffers.add(TradeOffer(Constants.peaceTreaty, TradeType.Treaty, 30)) tradeLogic.acceptTrade() updateLeftSideTable() - }, this) + }, this).open() } diplomacyTable.add(peaceButton).row() if(isNotPlayersTurn()) peaceButton.disable() @@ -373,7 +373,7 @@ class DiplomacyScreen(val viewingCiv:CivilizationInfo):CameraStageBaseScreen() { diplomacyManager.declareWar() setRightSideFlavorText(otherCiv, otherCiv.getTranslatedNation().attacked, "Very well.") updateLeftSideTable() - }, this) + }, this).open() } return declareWarButton } diff --git a/core/src/com/unciv/ui/utils/CameraStageBaseScreen.kt b/core/src/com/unciv/ui/utils/CameraStageBaseScreen.kt index b86a51cbb2..4dc2534428 100644 --- a/core/src/com/unciv/ui/utils/CameraStageBaseScreen.kt +++ b/core/src/com/unciv/ui/utils/CameraStageBaseScreen.kt @@ -7,21 +7,8 @@ import com.badlogic.gdx.graphics.Color import com.badlogic.gdx.graphics.GL20 import com.badlogic.gdx.graphics.g2d.Batch import com.badlogic.gdx.graphics.g2d.SpriteBatch -import com.badlogic.gdx.scenes.scene2d.Actor -import com.badlogic.gdx.scenes.scene2d.InputEvent -import com.badlogic.gdx.scenes.scene2d.InputListener -import com.badlogic.gdx.scenes.scene2d.Stage -import com.badlogic.gdx.scenes.scene2d.Touchable -import com.badlogic.gdx.scenes.scene2d.ui.Button -import com.badlogic.gdx.scenes.scene2d.ui.Cell -import com.badlogic.gdx.scenes.scene2d.ui.CheckBox -import com.badlogic.gdx.scenes.scene2d.ui.Image -import com.badlogic.gdx.scenes.scene2d.ui.Label -import com.badlogic.gdx.scenes.scene2d.ui.SelectBox -import com.badlogic.gdx.scenes.scene2d.ui.Skin -import com.badlogic.gdx.scenes.scene2d.ui.Table -import com.badlogic.gdx.scenes.scene2d.ui.TextButton -import com.badlogic.gdx.scenes.scene2d.ui.TextField +import com.badlogic.gdx.scenes.scene2d.* +import com.badlogic.gdx.scenes.scene2d.ui.* import com.badlogic.gdx.scenes.scene2d.utils.ClickListener import com.badlogic.gdx.utils.viewport.ExtendViewport import com.unciv.JsonParser @@ -83,9 +70,6 @@ open class CameraStageBaseScreen : Screen { tutorialController.showTutorial(tutorial) } - fun hasOpenPopups(): Boolean = - stage.actors.any { it is Popup } - companion object { var skin = Skin(Gdx.files.internal("skin/flat-earth-ui.json")) diff --git a/core/src/com/unciv/ui/utils/Popup.kt b/core/src/com/unciv/ui/utils/Popup.kt index 14b82c7823..1dbee4b6f9 100644 --- a/core/src/com/unciv/ui/utils/Popup.kt +++ b/core/src/com/unciv/ui/utils/Popup.kt @@ -18,20 +18,30 @@ open class Popup(val screen: CameraStageBaseScreen): Table(CameraStageBaseScreen this.pad(20f) this.defaults().pad(5f) + + this.isVisible = false } /** - * Displays the Popup on the screen. Will not open the popup if another one is already open. + * Displays the Popup on the screen. If another popup is already open, this one will display after the other has + * closed. Use [force] = true if you want to open this popup above the other one anyway. */ - fun open() { - if (screen.hasOpenPopups()) return; + fun open(force: Boolean = false) { + if (force || !screen.hasOpenPopups()) { + this.isVisible = true + } + + screen.stage.addActor(this) pack() center(screen.stage) - screen.stage.addActor(this) + } open fun close() { remove() + if (screen.popups.isNotEmpty()) { + screen.popups[0].isVisible = true; + } } fun addGoodSizedLabel(text: String, size:Int=18): Cell