diff --git a/core/src/com/unciv/ui/cityscreen/CityInfoTable.kt b/core/src/com/unciv/ui/cityscreen/CityInfoTable.kt index 53493166fb..17b971d64e 100644 --- a/core/src/com/unciv/ui/cityscreen/CityInfoTable.kt +++ b/core/src/com/unciv/ui/cityscreen/CityInfoTable.kt @@ -11,7 +11,7 @@ import com.unciv.models.ruleset.Building import com.unciv.models.stats.Stat import com.unciv.models.translations.tr import com.unciv.ui.utils.* -import com.unciv.ui.worldscreen.optionstable.YesNoPopupTable +import com.unciv.ui.utils.YesNoPopup import java.text.DecimalFormat class CityInfoTable(private val cityScreen: CityScreen) : Table(CameraStageBaseScreen.skin) { @@ -89,12 +89,12 @@ class CityInfoTable(private val cityScreen: CityScreen) : Table(CameraStageBaseS wonderDetailsTable.add(sellBuildingButton).pad(5f).row() sellBuildingButton.onClick { - YesNoPopupTable("Are you sure you want to sell this [${building.name}]?".tr(), - { - cityScreen.city.sellBuilding(building.name) - cityScreen.city.cityStats.update() - cityScreen.update() - }, cityScreen) + YesNoPopup("Are you sure you want to sell this [${building.name}]?".tr(), + { + cityScreen.city.sellBuilding(building.name) + cityScreen.city.cityStats.update() + cityScreen.update() + }, cityScreen) } if (cityScreen.city.hasSoldBuildingThisTurn || cityScreen.city.isPuppet || !UncivGame.Current.worldScreen.isPlayersTurn) @@ -296,4 +296,4 @@ class CityInfoTable(private val cityScreen: CityScreen) : Table(CameraStageBaseS return specialist } -} \ No newline at end of file +} diff --git a/core/src/com/unciv/ui/cityscreen/CityScreenCityPickerTable.kt b/core/src/com/unciv/ui/cityscreen/CityScreenCityPickerTable.kt index e637997e82..9357a4cee3 100644 --- a/core/src/com/unciv/ui/cityscreen/CityScreenCityPickerTable.kt +++ b/core/src/com/unciv/ui/cityscreen/CityScreenCityPickerTable.kt @@ -10,7 +10,7 @@ import com.unciv.ui.utils.CameraStageBaseScreen import com.unciv.ui.utils.ImageGetter import com.unciv.ui.utils.onClick import com.unciv.ui.utils.toLabel -import com.unciv.ui.worldscreen.optionstable.PopupTable +import com.unciv.ui.utils.Popup class CityScreenCityPickerTable(val cityScreen: CityScreen) : Table(){ @@ -53,7 +53,7 @@ class CityScreenCityPickerTable(val cityScreen: CityScreen) : Table(){ val currentCityLabel = city.name.toLabel(fontSize = 30) currentCityLabel.onClick { - val editCityNamePopup = PopupTable(cityScreen) + val editCityNamePopup = Popup(cityScreen) val textArea = TextField(city.name, CameraStageBaseScreen.skin) textArea.alignment = Align.center editCityNamePopup.add(textArea).colspan(2).row() @@ -96,4 +96,4 @@ class CityScreenCityPickerTable(val cityScreen: CityScreen) : Table(){ pack() } -} \ No newline at end of file +} diff --git a/core/src/com/unciv/ui/cityscreen/ConstructionsTable.kt b/core/src/com/unciv/ui/cityscreen/ConstructionsTable.kt index e640bd1adc..6a21c90b0e 100644 --- a/core/src/com/unciv/ui/cityscreen/ConstructionsTable.kt +++ b/core/src/com/unciv/ui/cityscreen/ConstructionsTable.kt @@ -14,7 +14,7 @@ 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.worldscreen.optionstable.YesNoPopupTable +import com.unciv.ui.utils.YesNoPopup class ConstructionsTable(val cityScreen: CityScreen) : Table(CameraStageBaseScreen.skin) { /* -2 = Nothing, -1 = current construction, >= 0 queue entry */ @@ -281,7 +281,7 @@ class ConstructionsTable(val cityScreen: CityScreen) : Table(CameraStageBaseScre button.add(ImageGetter.getStatIcon(Stat.Gold.name)).size(20f).padBottom(2f) button.onClick(UncivSound.Coin) { - YesNoPopupTable("Would you like to purchase [${construction.name}] for [$constructionGoldCost] gold?".tr(), { + YesNoPopup("Would you like to purchase [${construction.name}] for [$constructionGoldCost] gold?".tr(), { cityConstructions.purchaseConstruction(construction.name) if (isSelectedQueueEntry()) { cityConstructions.removeFromQueue(selectedQueueEntry) @@ -361,4 +361,4 @@ class ConstructionsTable(val cityScreen: CityScreen) : Table(CameraStageBaseScre if (table != list.last()) addSeparator() } } -} \ No newline at end of file +} diff --git a/core/src/com/unciv/ui/mapeditor/LoadMapScreen.kt b/core/src/com/unciv/ui/mapeditor/LoadMapScreen.kt index d3d9c1f04b..231c0bb61d 100644 --- a/core/src/com/unciv/ui/mapeditor/LoadMapScreen.kt +++ b/core/src/com/unciv/ui/mapeditor/LoadMapScreen.kt @@ -12,7 +12,7 @@ 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.worldscreen.optionstable.YesNoPopupTable +import com.unciv.ui.utils.YesNoPopup class LoadMapScreen(previousMap: TileMap?) : PickerScreen(){ var chosenMap = "" @@ -43,7 +43,7 @@ class LoadMapScreen(previousMap: TileMap?) : PickerScreen(){ val downloadMapButton = TextButton("Download map".tr(), skin) downloadMapButton.onClick { - MapDownloadTable(this) + MapDownloadPopup(this) } rightSideTable.add(downloadMapButton).row() @@ -67,7 +67,7 @@ class LoadMapScreen(previousMap: TileMap?) : PickerScreen(){ rightSideTable.add(couldNotLoadMapLabel).row() deleteMapButton.onClick { - YesNoPopupTable("Are you sure you want to delete this map?", { + YesNoPopup("Are you sure you want to delete this map?", { MapSaver().deleteMap(chosenMap) UncivGame.Current.setScreen(LoadMapScreen(previousMap)) }, this) diff --git a/core/src/com/unciv/ui/mapeditor/MapDownloadTable.kt b/core/src/com/unciv/ui/mapeditor/MapDownloadPopup.kt similarity index 91% rename from core/src/com/unciv/ui/mapeditor/MapDownloadTable.kt rename to core/src/com/unciv/ui/mapeditor/MapDownloadPopup.kt index 2c28b69a7d..7ec9bb478e 100644 --- a/core/src/com/unciv/ui/mapeditor/MapDownloadTable.kt +++ b/core/src/com/unciv/ui/mapeditor/MapDownloadPopup.kt @@ -9,11 +9,11 @@ import com.unciv.logic.MapSaver import com.unciv.ui.saves.Gzip import com.unciv.ui.utils.CameraStageBaseScreen import com.unciv.ui.utils.onClick -import com.unciv.ui.worldscreen.optionstable.DropBox -import com.unciv.ui.worldscreen.optionstable.PopupTable +import com.unciv.ui.worldscreen.mainmenu.DropBox +import com.unciv.ui.utils.Popup import kotlin.concurrent.thread -class MapDownloadTable(loadMapScreen: LoadMapScreen): PopupTable(loadMapScreen) { +class MapDownloadPopup(loadMapScreen: LoadMapScreen): Popup(loadMapScreen) { init { val folderList: DropBox.FolderList try { @@ -36,7 +36,7 @@ class MapDownloadTable(loadMapScreen: LoadMapScreen): PopupTable(loadMapScreen) // Yes, even creating popups. Gdx.app.postRunnable { - val couldNotDownloadMapPopup = PopupTable(screen) + val couldNotDownloadMapPopup = Popup(screen) couldNotDownloadMapPopup.addGoodSizedLabel("Could not download map!").row() couldNotDownloadMapPopup.addCloseButton() } @@ -52,4 +52,4 @@ class MapDownloadTable(loadMapScreen: LoadMapScreen): PopupTable(loadMapScreen) addCloseButton() open() } -} \ No newline at end of file +} diff --git a/core/src/com/unciv/ui/mapeditor/MapEditorMenuPopup.kt b/core/src/com/unciv/ui/mapeditor/MapEditorMenuPopup.kt index b281f6f921..ed6ff13007 100644 --- a/core/src/com/unciv/ui/mapeditor/MapEditorMenuPopup.kt +++ b/core/src/com/unciv/ui/mapeditor/MapEditorMenuPopup.kt @@ -12,16 +12,16 @@ import com.unciv.logic.map.RoadStatus import com.unciv.models.translations.tr import com.unciv.ui.saves.Gzip import com.unciv.ui.utils.onClick -import com.unciv.ui.worldscreen.optionstable.DropBox -import com.unciv.ui.worldscreen.optionstable.PopupTable +import com.unciv.ui.worldscreen.mainmenu.DropBox +import com.unciv.ui.utils.Popup import kotlin.concurrent.thread -class MapEditorMenuPopup(mapEditorScreen: MapEditorScreen): PopupTable(mapEditorScreen){ +class MapEditorMenuPopup(mapEditorScreen: MapEditorScreen): Popup(mapEditorScreen){ init{ val mapNameEditor = TextField(mapEditorScreen.mapName, skin) mapNameEditor.addListener{ mapEditorScreen.mapName=mapNameEditor.text; true } add(mapNameEditor).row() - + val clearCurrentMapButton = TextButton("Clear current map".tr(),skin) clearCurrentMapButton.onClick { for(tileGroup in mapEditorScreen.mapHolder.tileGroups.values) @@ -72,13 +72,13 @@ class MapEditorMenuPopup(mapEditorScreen: MapEditorScreen): PopupTable(mapEditor DropBox().uploadFile("/Maps/" + mapEditorScreen.mapName, gzippedMap) remove() - val uploadedSuccessfully = PopupTable(screen) + val uploadedSuccessfully = Popup(screen) uploadedSuccessfully.addGoodSizedLabel("Map uploaded successfully!").row() uploadedSuccessfully.addCloseButton() uploadedSuccessfully.open() } catch (ex: Exception) { remove() - val couldNotUpload = PopupTable(screen) + val couldNotUpload = Popup(screen) couldNotUpload.addGoodSizedLabel("Could not upload map!").row() couldNotUpload.addCloseButton() couldNotUpload.open() diff --git a/core/src/com/unciv/ui/newgamescreen/NewGameScreen.kt b/core/src/com/unciv/ui/newgamescreen/NewGameScreen.kt index a17175fdd5..7c2905829f 100644 --- a/core/src/com/unciv/ui/newgamescreen/NewGameScreen.kt +++ b/core/src/com/unciv/ui/newgamescreen/NewGameScreen.kt @@ -16,8 +16,8 @@ import com.unciv.ui.pickerscreens.PickerScreen import com.unciv.ui.utils.disable import com.unciv.ui.utils.enable import com.unciv.ui.utils.onClick -import com.unciv.ui.worldscreen.optionstable.OnlineMultiplayer -import com.unciv.ui.worldscreen.optionstable.PopupTable +import com.unciv.ui.worldscreen.mainmenu.OnlineMultiplayer +import com.unciv.ui.utils.Popup import java.util.* import kotlin.concurrent.thread @@ -41,7 +41,7 @@ class NewGameScreen: PickerScreen(){ rightSideButton.setText("Start game!".tr()) rightSideButton.onClick { if (newGameParameters.players.none { it.playerType == PlayerType.Human }) { - val noHumanPlayersPopup = PopupTable(this) + val noHumanPlayersPopup = Popup(this) noHumanPlayersPopup.addGoodSizedLabel("No human players selected!".tr()).row() noHumanPlayersPopup.addCloseButton() noHumanPlayersPopup.open() @@ -53,7 +53,7 @@ class NewGameScreen: PickerScreen(){ try { UUID.fromString(player.playerId) } catch (ex: Exception) { - val invalidPlayerIdPopup = PopupTable(this) + val invalidPlayerIdPopup = Popup(this) invalidPlayerIdPopup.addGoodSizedLabel("Invalid player ID!".tr()).row() invalidPlayerIdPopup.addCloseButton() invalidPlayerIdPopup.open() @@ -76,7 +76,7 @@ class NewGameScreen: PickerScreen(){ OnlineMultiplayer().tryUploadGame(newGame!!) GameSaver().autoSave(newGame!!){} } catch (ex: Exception) { - val cantUploadNewGamePopup = PopupTable(this) + val cantUploadNewGamePopup = Popup(this) cantUploadNewGamePopup.addGoodSizedLabel("Could not upload game!") cantUploadNewGamePopup.addCloseButton() cantUploadNewGamePopup.open() @@ -84,7 +84,7 @@ class NewGameScreen: PickerScreen(){ } } } catch (exception: Exception) { - val cantMakeThatMapPopup = PopupTable(this) + val cantMakeThatMapPopup = Popup(this) cantMakeThatMapPopup.addGoodSizedLabel("It looks like we can't make a map with the parameters you requested!".tr()).row() cantMakeThatMapPopup.addGoodSizedLabel("Maybe you put too many players into too small a map?".tr()).row() cantMakeThatMapPopup.addCloseButton() diff --git a/core/src/com/unciv/ui/newgamescreen/PlayerPickerTable.kt b/core/src/com/unciv/ui/newgamescreen/PlayerPickerTable.kt index be470ab20f..1560e5873a 100644 --- a/core/src/com/unciv/ui/newgamescreen/PlayerPickerTable.kt +++ b/core/src/com/unciv/ui/newgamescreen/PlayerPickerTable.kt @@ -15,7 +15,7 @@ import com.unciv.models.metadata.Player import com.unciv.models.ruleset.Ruleset import com.unciv.models.translations.tr import com.unciv.ui.utils.* -import com.unciv.ui.worldscreen.optionstable.PopupTable +import com.unciv.ui.utils.Popup import java.util.* class PlayerPickerTable(val newGameScreen: NewGameScreen, val newGameParameters: GameParameters): Table() { @@ -122,7 +122,7 @@ class PlayerPickerTable(val newGameScreen: NewGameScreen, val newGameParameters: } private fun popupNationPicker(player: Player) { - val nationsPopup = PopupTable(newGameScreen) + val nationsPopup = Popup(newGameScreen) val nationListTable = Table() val randomPlayerTable = Table() diff --git a/core/src/com/unciv/ui/saves/LoadGameScreen.kt b/core/src/com/unciv/ui/saves/LoadGameScreen.kt index fec4c7544b..419b56ca4a 100644 --- a/core/src/com/unciv/ui/saves/LoadGameScreen.kt +++ b/core/src/com/unciv/ui/saves/LoadGameScreen.kt @@ -16,7 +16,7 @@ import com.unciv.ui.utils.disable import com.unciv.ui.utils.enable import com.unciv.ui.utils.onClick import com.unciv.ui.utils.toLabel -import com.unciv.ui.worldscreen.optionstable.PopupTable +import com.unciv.ui.utils.Popup import java.text.SimpleDateFormat import java.util.* @@ -42,7 +42,7 @@ class LoadGameScreen : PickerScreen() { UncivGame.Current.loadGame(selectedSave) } catch (ex:Exception){ - val cantLoadGamePopup = PopupTable(this) + val cantLoadGamePopup = Popup(this) cantLoadGamePopup.addGoodSizedLabel("It looks like your saved game can't be loaded!").row() cantLoadGamePopup.addGoodSizedLabel("If you could copy your game data (\"Copy saved game to clipboard\" - ").row() cantLoadGamePopup.addGoodSizedLabel(" paste into an email to yairm210@hotmail.com)").row() diff --git a/core/src/com/unciv/ui/trade/DiplomacyScreen.kt b/core/src/com/unciv/ui/trade/DiplomacyScreen.kt index b1421430ac..e8377c6679 100644 --- a/core/src/com/unciv/ui/trade/DiplomacyScreen.kt +++ b/core/src/com/unciv/ui/trade/DiplomacyScreen.kt @@ -20,7 +20,7 @@ import com.unciv.logic.trade.TradeOffer import com.unciv.logic.trade.TradeType import com.unciv.models.translations.tr import com.unciv.ui.utils.* -import com.unciv.ui.worldscreen.optionstable.YesNoPopupTable +import com.unciv.ui.utils.YesNoPopup import kotlin.math.roundToInt class DiplomacyScreen(val viewingCiv:CivilizationInfo):CameraStageBaseScreen() { @@ -152,7 +152,7 @@ class DiplomacyScreen(val viewingCiv:CivilizationInfo):CameraStageBaseScreen() { if (viewingCiv.isAtWarWith(otherCiv)) { val peaceButton = TextButton("Negotiate Peace".tr(), skin) peaceButton.onClick { - YesNoPopupTable("Peace with [${otherCiv.civName}]?".tr(), { + YesNoPopup("Peace with [${otherCiv.civName}]?".tr(), { val tradeLogic = TradeLogic(viewingCiv, otherCiv) tradeLogic.currentTrade.ourOffers.add(TradeOffer(Constants.peaceTreaty, TradeType.Treaty, 30)) tradeLogic.currentTrade.theirOffers.add(TradeOffer(Constants.peaceTreaty, TradeType.Treaty, 30)) @@ -334,9 +334,9 @@ class DiplomacyScreen(val viewingCiv:CivilizationInfo):CameraStageBaseScreen() { declareWarButton.setText(declareWarButton.text.toString() + " ($turnsToPeaceTreaty)") } declareWarButton.onClick { - YesNoPopupTable("Declare war on [${otherCiv.civName}]?".tr(), { + YesNoPopup("Declare war on [${otherCiv.civName}]?".tr(), { diplomacyManager.declareWar() - setRightSideFlavorText(otherCiv,otherCiv.getTranslatedNation().attacked,"Very well.") + setRightSideFlavorText(otherCiv, otherCiv.getTranslatedNation().attacked, "Very well.") updateLeftSideTable() }, this) } @@ -358,4 +358,4 @@ class DiplomacyScreen(val viewingCiv:CivilizationInfo):CameraStageBaseScreen() { rightSideTable.add(diplomacyTable) } -} \ 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 bb56de2940..84ad02b612 100644 --- a/core/src/com/unciv/ui/tutorials/TutorialController.kt +++ b/core/src/com/unciv/ui/tutorials/TutorialController.kt @@ -20,8 +20,6 @@ class TutorialController( showTutorialIfNeeded() } - fun isTutorialShowing(): Boolean = isTutorialShowing - private fun showTutorialIfNeeded() { val tutorial = tutorialQueue.firstOrNull() if (tutorial == null) { @@ -42,4 +40,4 @@ class TutorialController( } } } -} \ No newline at end of file +} diff --git a/core/src/com/unciv/ui/tutorials/TutorialRender.kt b/core/src/com/unciv/ui/tutorials/TutorialRender.kt index aa715d7ff2..bea7a7c24c 100644 --- a/core/src/com/unciv/ui/tutorials/TutorialRender.kt +++ b/core/src/com/unciv/ui/tutorials/TutorialRender.kt @@ -6,8 +6,8 @@ import com.unciv.models.Tutorial import com.unciv.models.translations.tr import com.unciv.ui.utils.CameraStageBaseScreen import com.unciv.ui.utils.ImageGetter +import com.unciv.ui.utils.Popup import com.unciv.ui.utils.onClick -import com.unciv.ui.worldscreen.optionstable.PopupTable data class TutorialForRender(val tutorial: Tutorial, val texts: List) @@ -22,21 +22,21 @@ class TutorialRender(private val screen: CameraStageBaseScreen) { if (text == null) { closeAction() } else { - val tutorialTable = PopupTable(screen) + val tutorialPopup = Popup(screen) if (Gdx.files.internal("ExtraImages/$tutorialName").exists()) { - tutorialTable.add(ImageGetter.getExternalImage(tutorialName)).row() + tutorialPopup.add(ImageGetter.getExternalImage(tutorialName)).row() } - tutorialTable.addGoodSizedLabel(texts[0]).row() + tutorialPopup.addGoodSizedLabel(texts[0]).row() val button = TextButton("Close".tr(), CameraStageBaseScreen.skin) button.onClick { - tutorialTable.remove() + tutorialPopup.remove() showDialog(tutorialName, texts - text, closeAction) } - tutorialTable.add(button).pad(10f) - tutorialTable.open() + tutorialPopup.add(button).pad(10f) + tutorialPopup.open() } } -} \ No newline at end of file +} diff --git a/core/src/com/unciv/ui/utils/CameraStageBaseScreen.kt b/core/src/com/unciv/ui/utils/CameraStageBaseScreen.kt index 441cd2a6eb..b86a51cbb2 100644 --- a/core/src/com/unciv/ui/utils/CameraStageBaseScreen.kt +++ b/core/src/com/unciv/ui/utils/CameraStageBaseScreen.kt @@ -32,14 +32,12 @@ import com.unciv.models.translations.tr import com.unciv.ui.tutorials.TutorialController import com.unciv.ui.tutorials.TutorialMiner import com.unciv.ui.tutorials.TutorialRender -import com.unciv.ui.worldscreen.TradePopup import kotlin.concurrent.thread open class CameraStageBaseScreen : Screen { var game: UncivGame = UncivGame.Current var stage: Stage - var hasPopupOpen = false val tutorialController by lazy { TutorialController(TutorialMiner(JsonParser()), TutorialRender(this)) @@ -85,8 +83,8 @@ open class CameraStageBaseScreen : Screen { tutorialController.showTutorial(tutorial) } - fun hasVisibleDialogs(): Boolean = - tutorialController.isTutorialShowing() || stage.actors.any { it is TradePopup } || hasPopupOpen + 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/CrashController.kt b/core/src/com/unciv/ui/utils/CrashController.kt index b27b6ec007..aeb4291b6a 100644 --- a/core/src/com/unciv/ui/utils/CrashController.kt +++ b/core/src/com/unciv/ui/utils/CrashController.kt @@ -4,7 +4,6 @@ import com.badlogic.gdx.utils.Json import com.unciv.UncivGame import com.unciv.models.CrashReport import com.unciv.ui.saves.Gzip -import com.unciv.ui.worldscreen.optionstable.PopupTable interface CrashController { @@ -40,14 +39,14 @@ interface CrashController { } } - private fun prepareDialog(): PopupTable { + private fun prepareDialog(): Popup { return if (crashReportSender == null) { - PopupTable(UncivGame.Current.worldScreen).apply { + Popup(UncivGame.Current.worldScreen).apply { addGoodSizedLabel(MESSAGE_FALLBACK).row() addCloseButton() } } else { - PopupTable(UncivGame.Current.worldScreen).apply { + Popup(UncivGame.Current.worldScreen).apply { addGoodSizedLabel(MESSAGE).row() addButton("Send report") { crashReportSender.sendReport(buildReport()) @@ -65,4 +64,4 @@ interface CrashController { } } } -} \ No newline at end of file +} diff --git a/core/src/com/unciv/ui/worldscreen/optionstable/PopupTable.kt b/core/src/com/unciv/ui/utils/Popup.kt similarity index 79% rename from core/src/com/unciv/ui/worldscreen/optionstable/PopupTable.kt rename to core/src/com/unciv/ui/utils/Popup.kt index fe149438d7..14b82c7823 100644 --- a/core/src/com/unciv/ui/worldscreen/optionstable/PopupTable.kt +++ b/core/src/com/unciv/ui/utils/Popup.kt @@ -1,4 +1,4 @@ -package com.unciv.ui.worldscreen.optionstable +package com.unciv.ui.utils import com.badlogic.gdx.graphics.Color import com.badlogic.gdx.scenes.scene2d.Touchable @@ -8,9 +8,11 @@ import com.badlogic.gdx.scenes.scene2d.ui.Table import com.badlogic.gdx.scenes.scene2d.ui.TextButton import com.badlogic.gdx.utils.Align import com.unciv.models.translations.tr -import com.unciv.ui.utils.* -open class PopupTable(val screen: CameraStageBaseScreen): Table(CameraStageBaseScreen.skin) { +/** + * Base class for all Popups, i.e. Tables that get rendered in the middle of a screen and on top of everything else + */ +open class Popup(val screen: CameraStageBaseScreen): Table(CameraStageBaseScreen.skin) { init { background = ImageGetter.getBackground(ImageGetter.getBlue().lerp(Color.BLACK, 0.5f)) @@ -18,7 +20,11 @@ open class PopupTable(val screen: CameraStageBaseScreen): Table(CameraStageBaseS this.defaults().pad(5f) } + /** + * Displays the Popup on the screen. Will not open the popup if another one is already open. + */ fun open() { + if (screen.hasOpenPopups()) return; pack() center(screen.stage) screen.stage.addActor(this) diff --git a/core/src/com/unciv/ui/utils/YesNoPopup.kt b/core/src/com/unciv/ui/utils/YesNoPopup.kt new file mode 100644 index 0000000000..ca28572680 --- /dev/null +++ b/core/src/com/unciv/ui/utils/YesNoPopup.kt @@ -0,0 +1,15 @@ +package com.unciv.ui.utils + +import com.badlogic.gdx.scenes.scene2d.ui.TextButton +import com.unciv.UncivGame +import com.unciv.models.translations.tr + +class YesNoPopup(question:String, action:()->Unit, + screen: CameraStageBaseScreen = UncivGame.Current.worldScreen, restoredefault:()->Unit = {}) : Popup(screen){ + init{ + add(question.toLabel()).colspan(2).row() + add(TextButton("No".tr(), skin).onClick { close(); restoredefault() }) + add(TextButton("Yes".tr(), skin).onClick { close(); action() }) + open() + } +} diff --git a/core/src/com/unciv/ui/worldscreen/AlertPopup.kt b/core/src/com/unciv/ui/worldscreen/AlertPopup.kt index a58db69bd6..4f8d7c1b33 100644 --- a/core/src/com/unciv/ui/worldscreen/AlertPopup.kt +++ b/core/src/com/unciv/ui/worldscreen/AlertPopup.kt @@ -7,9 +7,8 @@ import com.unciv.logic.civilization.CivilizationInfo import com.unciv.logic.civilization.PopupAlert import com.unciv.models.translations.tr import com.unciv.ui.utils.* -import com.unciv.ui.worldscreen.optionstable.PopupTable -class AlertPopup(val worldScreen: WorldScreen, val popupAlert: PopupAlert): PopupTable(worldScreen){ +class AlertPopup(val worldScreen: WorldScreen, val popupAlert: PopupAlert): Popup(worldScreen){ fun getCloseButton(text: String, action: (() -> Unit)?=null): TextButton { val button = TextButton(text.tr(), skin) button.onClick { @@ -119,7 +118,7 @@ class AlertPopup(val worldScreen: WorldScreen, val popupAlert: PopupAlert): Popu addGoodSizedLabel("Destroying the city instantly razes the city to the ground.").row() } - + } AlertType.BorderConflict -> { val civInfo = worldScreen.gameInfo.getCivilization(popupAlert.value) @@ -180,12 +179,10 @@ class AlertPopup(val worldScreen: WorldScreen, val popupAlert: PopupAlert): Popu } } open() - worldScreen.hasPopupOpen = true } override fun close(){ worldScreen.viewingCiv.popupAlerts.remove(popupAlert) - worldScreen.hasPopupOpen = false super.close() } -} \ No newline at end of file +} diff --git a/core/src/com/unciv/ui/worldscreen/TradePopup.kt b/core/src/com/unciv/ui/worldscreen/TradePopup.kt index 82f7cf25b5..0d3bd1003d 100644 --- a/core/src/com/unciv/ui/worldscreen/TradePopup.kt +++ b/core/src/com/unciv/ui/worldscreen/TradePopup.kt @@ -11,11 +11,11 @@ import com.unciv.models.translations.tr import com.unciv.ui.trade.DiplomacyScreen import com.unciv.ui.utils.addSeparator import com.unciv.ui.utils.toLabel -import com.unciv.ui.worldscreen.optionstable.PopupTable +import com.unciv.ui.utils.Popup import kotlin.math.max import kotlin.math.min -class TradePopup(worldScreen: WorldScreen): PopupTable(worldScreen){ +class TradePopup(worldScreen: WorldScreen): Popup(worldScreen){ init{ val viewingCiv = worldScreen.viewingCiv val tradeRequest = viewingCiv.tradeRequests.first() @@ -52,7 +52,7 @@ class TradePopup(worldScreen: WorldScreen): PopupTable(worldScreen){ tradeLogic.acceptTrade() viewingCiv.tradeRequests.remove(tradeRequest) close() - PopupTable(worldScreen).apply { + Popup(worldScreen).apply { add(otherCivLeaderName.toLabel()).colspan(2) addSeparator() addGoodSizedLabel("Excellent!").row() @@ -94,4 +94,4 @@ class TradePopup(worldScreen: WorldScreen): PopupTable(worldScreen){ } open() } -} \ No newline at end of file +} diff --git a/core/src/com/unciv/ui/worldscreen/WorldScreen.kt b/core/src/com/unciv/ui/worldscreen/WorldScreen.kt index ce2ba5c20b..ec7eafc596 100644 --- a/core/src/com/unciv/ui/worldscreen/WorldScreen.kt +++ b/core/src/com/unciv/ui/worldscreen/WorldScreen.kt @@ -30,8 +30,7 @@ import com.unciv.ui.trade.DiplomacyScreen import com.unciv.ui.utils.* import com.unciv.ui.worldscreen.bottombar.BattleTable import com.unciv.ui.worldscreen.bottombar.TileInfoTable -import com.unciv.ui.worldscreen.optionstable.OnlineMultiplayer -import com.unciv.ui.worldscreen.optionstable.PopupTable +import com.unciv.ui.worldscreen.mainmenu.OnlineMultiplayer import com.unciv.ui.worldscreen.unit.UnitActionsTable import com.unciv.ui.worldscreen.unit.UnitTable import kotlin.concurrent.thread @@ -137,7 +136,7 @@ class WorldScreen(val viewingCiv:CivilizationInfo) : CameraStageBaseScreen() { } private fun loadLatestMultiplayerState(){ - val loadingGamePopup = PopupTable(this) + val loadingGamePopup = Popup(this) loadingGamePopup.add("Loading latest game state...") loadingGamePopup.open() thread(name="MultiplayerLoad") { @@ -153,7 +152,7 @@ class WorldScreen(val viewingCiv:CivilizationInfo) : CameraStageBaseScreen() { } catch (ex: Exception) { loadingGamePopup.close() - val couldntDownloadLatestGame = PopupTable(this) + val couldntDownloadLatestGame = Popup(this) couldntDownloadLatestGame.addGoodSizedLabel("Couldn't download the latest game state!").row() couldntDownloadLatestGame.addCloseButton() couldntDownloadLatestGame.addAction(Actions.delay(5f, Actions.run { couldntDownloadLatestGame.close() })) @@ -204,7 +203,7 @@ class WorldScreen(val viewingCiv:CivilizationInfo) : CameraStageBaseScreen() { techPolicyAndVictoryHolder.setPosition(10f, topBar.y - techPolicyAndVictoryHolder.height - 5f) updateDiplomacyButton(viewingCiv) - if (!hasVisibleDialogs() && isPlayersTurn) { + if (!hasOpenPopups() && isPlayersTurn) { when { !gameInfo.oneMoreTurnMode && viewingCiv.isDefeated() -> game.setScreen(VictoryScreen()) !gameInfo.oneMoreTurnMode && gameInfo.civilizations.any { it.victoryManager.hasWon() } -> game.setScreen(VictoryScreen()) @@ -214,7 +213,7 @@ class WorldScreen(val viewingCiv:CivilizationInfo) : CameraStageBaseScreen() { viewingCiv.tradeRequests.isNotEmpty() -> TradePopup(this) } } - updateNextTurnButton(hasVisibleDialogs()) // This must be before the notifications update, since its position is based on it + updateNextTurnButton(hasOpenPopups()) // This must be before the notifications update, since its position is based on it notificationsScroll.update(viewingCiv.notifications) notificationsScroll.setPosition(stage.width - notificationsScroll.width - 5f, nextTurnButton.y - notificationsScroll.height - 5f) @@ -389,7 +388,7 @@ class WorldScreen(val viewingCiv:CivilizationInfo) : CameraStageBaseScreen() { try { OnlineMultiplayer().tryUploadGame(gameInfoClone) } catch (ex: Exception) { - val cantUploadNewGamePopup = PopupTable(this) + val cantUploadNewGamePopup = Popup(this) cantUploadNewGamePopup.addGoodSizedLabel("Could not upload game!").row() cantUploadNewGamePopup.addCloseButton() cantUploadNewGamePopup.open() @@ -518,7 +517,7 @@ class WorldScreen(val viewingCiv:CivilizationInfo) : CameraStageBaseScreen() { // remove current listener for the "BACK" button to avoid showing the dialog twice stage.removeListener( backButtonListener ) - var promptWindow = PopupTable(this) + var promptWindow = Popup(this) promptWindow.addGoodSizedLabel("Do you want to exit the game?".tr()) promptWindow.row() promptWindow.addButton("Yes"){game.exitEvent?.invoke()} diff --git a/core/src/com/unciv/ui/worldscreen/WorldScreenTopBar.kt b/core/src/com/unciv/ui/worldscreen/WorldScreenTopBar.kt index 7568b90d77..da9c3a1e6e 100644 --- a/core/src/com/unciv/ui/worldscreen/WorldScreenTopBar.kt +++ b/core/src/com/unciv/ui/worldscreen/WorldScreenTopBar.kt @@ -10,11 +10,11 @@ import com.badlogic.gdx.scenes.scene2d.ui.TextButton import com.unciv.UncivGame import com.unciv.logic.civilization.CivilizationInfo import com.unciv.models.ruleset.tile.ResourceType -import com.unciv.models.translations.tr import com.unciv.models.stats.Stats +import com.unciv.models.translations.tr import com.unciv.ui.EmpireOverviewScreen import com.unciv.ui.utils.* -import com.unciv.ui.worldscreen.optionstable.WorldScreenMenuTable +import com.unciv.ui.worldscreen.mainmenu.WorldScreenMenuPopup import kotlin.math.abs import kotlin.math.ceil import kotlin.math.roundToInt @@ -95,8 +95,8 @@ class WorldScreenTopBar(val worldScreen: WorldScreen) : Table() { .apply { setSize(50f, 50f) } menuButton.color = Color.WHITE menuButton.onClick { - if(worldScreen.stage.actors.none { it is WorldScreenMenuTable }) - WorldScreenMenuTable(worldScreen) + if(worldScreen.stage.actors.none { it is WorldScreenMenuPopup }) + WorldScreenMenuPopup(worldScreen) } menuButton.centerY(this) menuButton.x = menuButton.y diff --git a/core/src/com/unciv/ui/worldscreen/bottombar/BattleTable.kt b/core/src/com/unciv/ui/worldscreen/bottombar/BattleTable.kt index 3f2855f7d5..6105dfbff9 100644 --- a/core/src/com/unciv/ui/worldscreen/bottombar/BattleTable.kt +++ b/core/src/com/unciv/ui/worldscreen/bottombar/BattleTable.kt @@ -17,7 +17,7 @@ import com.unciv.models.translations.tr import com.unciv.models.ruleset.unit.UnitType import com.unciv.ui.utils.* import com.unciv.ui.worldscreen.WorldScreen -import com.unciv.ui.worldscreen.optionstable.PopupTable +import com.unciv.ui.utils.Popup import kotlin.math.max class BattleTable(val worldScreen: WorldScreen): Table() { @@ -187,7 +187,7 @@ class BattleTable(val worldScreen: WorldScreen): Table() { val canBombard = UnitAutomation().getBombardTargets(attacker.city).contains(defender.getTile()) if (canBombard) { attackableEnemy = AttackableTile(attacker.getTile(), defender.getTile()) - } + } } } @@ -204,7 +204,7 @@ class BattleTable(val worldScreen: WorldScreen): Table() { worldScreen.shouldUpdate = true } catch (ex:Exception){ - val battleBugPopup = PopupTable(worldScreen) + val battleBugPopup = Popup(worldScreen) battleBugPopup.addGoodSizedLabel("You've encountered a bug that I've been looking for for a while!").row() battleBugPopup.addGoodSizedLabel("If you could copy your game data (\"Copy saved game to clipboard\" - ").row() battleBugPopup.addGoodSizedLabel(" paste into an email to yairm210@hotmail.com)").row() diff --git a/core/src/com/unciv/ui/worldscreen/optionstable/DropBox.kt b/core/src/com/unciv/ui/worldscreen/mainmenu/DropBox.kt similarity index 98% rename from core/src/com/unciv/ui/worldscreen/optionstable/DropBox.kt rename to core/src/com/unciv/ui/worldscreen/mainmenu/DropBox.kt index d023ecd76c..0ea54335c4 100644 --- a/core/src/com/unciv/ui/worldscreen/optionstable/DropBox.kt +++ b/core/src/com/unciv/ui/worldscreen/mainmenu/DropBox.kt @@ -1,4 +1,4 @@ -package com.unciv.ui.worldscreen.optionstable +package com.unciv.ui.worldscreen.mainmenu import com.unciv.logic.GameInfo import com.unciv.logic.GameSaver @@ -103,4 +103,4 @@ class OnlineMultiplayer { val zippedGameInfo = DropBox().downloadFileAsString(getGameLocation(gameId)) return GameSaver().gameInfoFromString(Gzip.unzip(zippedGameInfo)) } -} \ No newline at end of file +} diff --git a/core/src/com/unciv/ui/worldscreen/optionstable/WorldScreenMenuTable.kt b/core/src/com/unciv/ui/worldscreen/mainmenu/WorldScreenMenuPopup.kt similarity index 93% rename from core/src/com/unciv/ui/worldscreen/optionstable/WorldScreenMenuTable.kt rename to core/src/com/unciv/ui/worldscreen/mainmenu/WorldScreenMenuPopup.kt index de6c8230a8..1e51e6fb6d 100644 --- a/core/src/com/unciv/ui/worldscreen/optionstable/WorldScreenMenuTable.kt +++ b/core/src/com/unciv/ui/worldscreen/mainmenu/WorldScreenMenuPopup.kt @@ -1,4 +1,4 @@ -package com.unciv.ui.worldscreen.optionstable +package com.unciv.ui.worldscreen.mainmenu import com.badlogic.gdx.Gdx import com.badlogic.gdx.graphics.Color @@ -11,6 +11,7 @@ import com.unciv.ui.mapeditor.MapEditorScreen import com.unciv.ui.newgamescreen.NewGameScreen import com.unciv.ui.saves.LoadGameScreen import com.unciv.ui.saves.SaveGameScreen +import com.unciv.ui.utils.Popup import com.unciv.ui.utils.addSeparator import com.unciv.ui.utils.disable import com.unciv.ui.utils.toLabel @@ -19,7 +20,7 @@ import java.util.* import kotlin.collections.ArrayList import kotlin.concurrent.thread -class WorldScreenMenuTable(val worldScreen: WorldScreen) : PopupTable(worldScreen) { +class WorldScreenMenuPopup(val worldScreen: WorldScreen) : Popup(worldScreen) { init { val width = 200f @@ -69,13 +70,13 @@ class WorldScreenMenuTable(val worldScreen: WorldScreen) : PopupTable(worldScree addSeparator() addSquareButton("Options".tr()){ - UncivGame.Current.worldScreen.stage.addActor(WorldScreenOptionsTable(worldScreen)) + UncivGame.Current.worldScreen.stage.addActor(WorldScreenOptionsPopup(worldScreen)) remove() }.size(width,height) addSeparator() addSquareButton("Community"){ - WorldScreenCommunityTable(worldScreen) + WorldScreenCommunityPopup(worldScreen) remove() }.size(width,height) addSeparator() @@ -92,7 +93,7 @@ class WorldScreenMenuTable(val worldScreen: WorldScreen) : PopupTable(worldScree fun openMultiplayerPopup(){ close() - val multiplayerPopup = PopupTable(screen) + val multiplayerPopup = Popup(screen) multiplayerPopup.addGoodSizedLabel("To create a multiplayer game, check the 'multiplayer' toggle in the New Game screen, and for each human player insert that player's user ID.").row() multiplayerPopup.addGoodSizedLabel("You can assign your own user ID there easily, and other players can copy their user IDs here and send them to you for you to include them in the game.").row() @@ -138,7 +139,7 @@ class WorldScreenMenuTable(val worldScreen: WorldScreen) : PopupTable(worldScree } } -class WorldScreenCommunityTable(val worldScreen: WorldScreen) : PopupTable(worldScreen) { +class WorldScreenCommunityPopup(val worldScreen: WorldScreen) : Popup(worldScreen) { init{ addButton("Discord"){ Gdx.net.openURI("https://discord.gg/bjrB4Xw") diff --git a/core/src/com/unciv/ui/worldscreen/optionstable/WorldScreenOptionsTable.kt b/core/src/com/unciv/ui/worldscreen/mainmenu/WorldScreenOptionsPopup.kt similarity index 93% rename from core/src/com/unciv/ui/worldscreen/optionstable/WorldScreenOptionsTable.kt rename to core/src/com/unciv/ui/worldscreen/mainmenu/WorldScreenOptionsPopup.kt index b91ec56cf1..bc3857821c 100644 --- a/core/src/com/unciv/ui/worldscreen/optionstable/WorldScreenOptionsTable.kt +++ b/core/src/com/unciv/ui/worldscreen/mainmenu/WorldScreenOptionsPopup.kt @@ -1,4 +1,4 @@ -package com.unciv.ui.worldscreen.optionstable +package com.unciv.ui.worldscreen.mainmenu import com.badlogic.gdx.Gdx import com.badlogic.gdx.graphics.Color @@ -20,7 +20,7 @@ class Language(val language:String, val percentComplete:Int){ } } -class WorldScreenOptionsTable(val worldScreen:WorldScreen) : PopupTable(worldScreen){ +class WorldScreenOptionsPopup(val worldScreen:WorldScreen) : Popup(worldScreen){ var selectedLanguage: String = "English" init { @@ -35,7 +35,7 @@ class WorldScreenOptionsTable(val worldScreen:WorldScreen) : PopupTable(worldScr settings.save() clear() - val innerTable = PopupTable(screen) // cheating, to get the old code to fit inside a Scroll =) + val innerTable = Popup(screen) // cheating, to get the old code to fit inside a Scroll =) innerTable.background = null innerTable.add("Display options".toLabel(fontSize = 24)).colspan(2).row() @@ -143,7 +143,7 @@ class WorldScreenOptionsTable(val worldScreen:WorldScreen) : PopupTable(worldScr } - private fun addSoundEffectsVolumeSlider(innerTable: PopupTable) { + private fun addSoundEffectsVolumeSlider(innerTable: Popup) { innerTable.add("Sound effects volume".tr()) val soundEffectsVolumeSlider = Slider(0f, 1.0f, 0.1f, false, skin) @@ -158,7 +158,7 @@ class WorldScreenOptionsTable(val worldScreen:WorldScreen) : PopupTable(worldScr innerTable.add(soundEffectsVolumeSlider).row() } - private fun addMusicVolumeSlider(innerTable: PopupTable) { + private fun addMusicVolumeSlider(innerTable: Popup) { val musicLocation =Gdx.files.local(UncivGame.Current.musicLocation) if(musicLocation.exists()) { innerTable.add("Music volume".tr()) @@ -200,7 +200,7 @@ class WorldScreenOptionsTable(val worldScreen:WorldScreen) : PopupTable(worldScr } } - private fun addResolutionSelectBox(innerTable: PopupTable) { + private fun addResolutionSelectBox(innerTable: Popup) { innerTable.add("Resolution".toLabel()) val resolutionSelectBox = SelectBox(skin) @@ -216,12 +216,12 @@ class WorldScreenOptionsTable(val worldScreen:WorldScreen) : PopupTable(worldScr UncivGame.Current.settings.save() UncivGame.Current.worldScreen = WorldScreen(worldScreen.viewingCiv) UncivGame.Current.setWorldScreen() - WorldScreenOptionsTable(UncivGame.Current.worldScreen) + WorldScreenOptionsPopup(UncivGame.Current.worldScreen) } }) } - private fun addTileSetSelectBox(innerTable: PopupTable) { + private fun addTileSetSelectBox(innerTable: Popup) { innerTable.add("Tileset".toLabel()) val tileSetSelectBox = SelectBox(skin) @@ -239,12 +239,12 @@ class WorldScreenOptionsTable(val worldScreen:WorldScreen) : PopupTable(worldScr UncivGame.Current.settings.save() UncivGame.Current.worldScreen = WorldScreen(worldScreen.viewingCiv) UncivGame.Current.setWorldScreen() - WorldScreenOptionsTable(UncivGame.Current.worldScreen) + WorldScreenOptionsPopup(UncivGame.Current.worldScreen) } }) } - private fun addAutosaveTurnsSelectBox(innerTable: PopupTable) { + private fun addAutosaveTurnsSelectBox(innerTable: Popup) { innerTable.add("Turns between autosaves".toLabel()) val autosaveTurnsSelectBox = SelectBox(skin) @@ -264,7 +264,7 @@ class WorldScreenOptionsTable(val worldScreen:WorldScreen) : PopupTable(worldScr }) } - private fun addLanguageSelectBox(innerTable: PopupTable) { + private fun addLanguageSelectBox(innerTable: Popup) { val languageSelectBox = SelectBox(skin) val languageArray = Array() UncivGame.Current.translations.percentCompleteOfLanguages @@ -298,6 +298,6 @@ class WorldScreenOptionsTable(val worldScreen:WorldScreen) : PopupTable(worldScr CameraStageBaseScreen.resetFonts() // to load chinese characters if necessary UncivGame.Current.worldScreen = WorldScreen(worldScreen.viewingCiv) UncivGame.Current.setWorldScreen() - WorldScreenOptionsTable(UncivGame.Current.worldScreen) + WorldScreenOptionsPopup(UncivGame.Current.worldScreen) } } diff --git a/core/src/com/unciv/ui/worldscreen/optionstable/YesNoPopupTable.kt b/core/src/com/unciv/ui/worldscreen/optionstable/YesNoPopupTable.kt deleted file mode 100644 index 8abe6b8f4d..0000000000 --- a/core/src/com/unciv/ui/worldscreen/optionstable/YesNoPopupTable.kt +++ /dev/null @@ -1,26 +0,0 @@ -package com.unciv.ui.worldscreen.optionstable - -import com.badlogic.gdx.scenes.scene2d.ui.TextButton -import com.unciv.UncivGame -import com.unciv.models.translations.tr -import com.unciv.ui.utils.CameraStageBaseScreen -import com.unciv.ui.utils.onClick -import com.unciv.ui.utils.toLabel - -class YesNoPopupTable(question:String, action:()->Unit, - screen: CameraStageBaseScreen = UncivGame.Current.worldScreen, restoredefault:()->Unit = {}) : PopupTable(screen){ - init{ - if(!screen.hasPopupOpen) { - screen.hasPopupOpen=true - add(question.toLabel()).colspan(2).row() - add(TextButton("No".tr(), skin).onClick { close(); restoredefault() }) - add(TextButton("Yes".tr(), skin).onClick { close(); action() }) - open() - } - } - - override fun close(){ - super.close() - screen.hasPopupOpen=false - } -} \ No newline at end of file diff --git a/core/src/com/unciv/ui/worldscreen/unit/UnitActions.kt b/core/src/com/unciv/ui/worldscreen/unit/UnitActions.kt index e208576e49..9ccedb69db 100644 --- a/core/src/com/unciv/ui/worldscreen/unit/UnitActions.kt +++ b/core/src/com/unciv/ui/worldscreen/unit/UnitActions.kt @@ -16,7 +16,7 @@ import com.unciv.models.translations.tr import com.unciv.ui.pickerscreens.ImprovementPickerScreen import com.unciv.ui.pickerscreens.PromotionPickerScreen import com.unciv.ui.worldscreen.WorldScreen -import com.unciv.ui.worldscreen.optionstable.YesNoPopupTable +import com.unciv.ui.utils.YesNoPopup class UnitActions { @@ -314,7 +314,7 @@ class UnitActions { val disbandText = if (unit.currentTile.getOwner() == unit.civInfo) "Disband this unit for [${unit.baseUnit.getDisbandGold()}] gold?".tr() else "Do you really want to disband this unit?".tr() - YesNoPopupTable(disbandText, { unit.disband(); worldScreen.shouldUpdate = true }) + YesNoPopup(disbandText, { unit.disband(); worldScreen.shouldUpdate = true }) }) return actionList @@ -328,4 +328,4 @@ class UnitActions { // Can't pillage friendly tiles, just like you can't attack them - it's an 'act of war' thing return tileOwner == null || tileOwner == unit.civInfo || unit.civInfo.isAtWarWith(tileOwner) } -} \ No newline at end of file +}