Refactor: Streamline popups (#1735)

First, `PopupTable` and all extending classes had the `Table` at the end removed. Second, the popup base classes `Popup(Table)` and `YesNoPopup(Table)` were moved from the worldscreen to the util package.

Third: The popups were inconsistent. In CameraStageBaseScreen, there was a check with 3 parts, one if any tutorial was showing, second if any child is a TradePopup, and third if the boolean field "hasPopupOpen" is true.

However, all of these checks were, in the end, `Popup(Table)`s on the screen. So, this check has simply been changed to check if any child is a `Popup(Table)`. All the other checks and their relating code could simply be removed.
This commit is contained in:
Timo T
2020-01-20 18:13:21 +01:00
committed by Yair Morgenstern
parent 43e9ee112e
commit b95844d2f4
26 changed files with 127 additions and 140 deletions

View File

@ -11,7 +11,7 @@ import com.unciv.models.ruleset.Building
import com.unciv.models.stats.Stat import com.unciv.models.stats.Stat
import com.unciv.models.translations.tr import com.unciv.models.translations.tr
import com.unciv.ui.utils.* import com.unciv.ui.utils.*
import com.unciv.ui.worldscreen.optionstable.YesNoPopupTable import com.unciv.ui.utils.YesNoPopup
import java.text.DecimalFormat import java.text.DecimalFormat
class CityInfoTable(private val cityScreen: CityScreen) : Table(CameraStageBaseScreen.skin) { 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() wonderDetailsTable.add(sellBuildingButton).pad(5f).row()
sellBuildingButton.onClick { sellBuildingButton.onClick {
YesNoPopupTable("Are you sure you want to sell this [${building.name}]?".tr(), YesNoPopup("Are you sure you want to sell this [${building.name}]?".tr(),
{ {
cityScreen.city.sellBuilding(building.name) cityScreen.city.sellBuilding(building.name)
cityScreen.city.cityStats.update() cityScreen.city.cityStats.update()
cityScreen.update() cityScreen.update()
}, cityScreen) }, cityScreen)
} }
if (cityScreen.city.hasSoldBuildingThisTurn || cityScreen.city.isPuppet if (cityScreen.city.hasSoldBuildingThisTurn || cityScreen.city.isPuppet
|| !UncivGame.Current.worldScreen.isPlayersTurn) || !UncivGame.Current.worldScreen.isPlayersTurn)
@ -296,4 +296,4 @@ class CityInfoTable(private val cityScreen: CityScreen) : Table(CameraStageBaseS
return specialist return specialist
} }
} }

View File

@ -10,7 +10,7 @@ import com.unciv.ui.utils.CameraStageBaseScreen
import com.unciv.ui.utils.ImageGetter import com.unciv.ui.utils.ImageGetter
import com.unciv.ui.utils.onClick import com.unciv.ui.utils.onClick
import com.unciv.ui.utils.toLabel 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(){ class CityScreenCityPickerTable(val cityScreen: CityScreen) : Table(){
@ -53,7 +53,7 @@ class CityScreenCityPickerTable(val cityScreen: CityScreen) : Table(){
val currentCityLabel = city.name.toLabel(fontSize = 30) val currentCityLabel = city.name.toLabel(fontSize = 30)
currentCityLabel.onClick { currentCityLabel.onClick {
val editCityNamePopup = PopupTable(cityScreen) val editCityNamePopup = Popup(cityScreen)
val textArea = TextField(city.name, CameraStageBaseScreen.skin) val textArea = TextField(city.name, CameraStageBaseScreen.skin)
textArea.alignment = Align.center textArea.alignment = Align.center
editCityNamePopup.add(textArea).colspan(2).row() editCityNamePopup.add(textArea).colspan(2).row()
@ -96,4 +96,4 @@ class CityScreenCityPickerTable(val cityScreen: CityScreen) : Table(){
pack() pack()
} }
} }

View File

@ -14,7 +14,7 @@ import com.unciv.models.UncivSound
import com.unciv.models.stats.Stat import com.unciv.models.stats.Stat
import com.unciv.models.translations.tr import com.unciv.models.translations.tr
import com.unciv.ui.utils.* 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) { class ConstructionsTable(val cityScreen: CityScreen) : Table(CameraStageBaseScreen.skin) {
/* -2 = Nothing, -1 = current construction, >= 0 queue entry */ /* -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.add(ImageGetter.getStatIcon(Stat.Gold.name)).size(20f).padBottom(2f)
button.onClick(UncivSound.Coin) { 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) cityConstructions.purchaseConstruction(construction.name)
if (isSelectedQueueEntry()) { if (isSelectedQueueEntry()) {
cityConstructions.removeFromQueue(selectedQueueEntry) cityConstructions.removeFromQueue(selectedQueueEntry)
@ -361,4 +361,4 @@ class ConstructionsTable(val cityScreen: CityScreen) : Table(CameraStageBaseScre
if (table != list.last()) addSeparator() if (table != list.last()) addSeparator()
} }
} }
} }

View File

@ -12,7 +12,7 @@ import com.unciv.models.translations.tr
import com.unciv.ui.pickerscreens.PickerScreen import com.unciv.ui.pickerscreens.PickerScreen
import com.unciv.ui.saves.Gzip import com.unciv.ui.saves.Gzip
import com.unciv.ui.utils.* import com.unciv.ui.utils.*
import com.unciv.ui.worldscreen.optionstable.YesNoPopupTable import com.unciv.ui.utils.YesNoPopup
class LoadMapScreen(previousMap: TileMap?) : PickerScreen(){ class LoadMapScreen(previousMap: TileMap?) : PickerScreen(){
var chosenMap = "" var chosenMap = ""
@ -43,7 +43,7 @@ class LoadMapScreen(previousMap: TileMap?) : PickerScreen(){
val downloadMapButton = TextButton("Download map".tr(), skin) val downloadMapButton = TextButton("Download map".tr(), skin)
downloadMapButton.onClick { downloadMapButton.onClick {
MapDownloadTable(this) MapDownloadPopup(this)
} }
rightSideTable.add(downloadMapButton).row() rightSideTable.add(downloadMapButton).row()
@ -67,7 +67,7 @@ class LoadMapScreen(previousMap: TileMap?) : PickerScreen(){
rightSideTable.add(couldNotLoadMapLabel).row() rightSideTable.add(couldNotLoadMapLabel).row()
deleteMapButton.onClick { 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) MapSaver().deleteMap(chosenMap)
UncivGame.Current.setScreen(LoadMapScreen(previousMap)) UncivGame.Current.setScreen(LoadMapScreen(previousMap))
}, this) }, this)

View File

@ -9,11 +9,11 @@ import com.unciv.logic.MapSaver
import com.unciv.ui.saves.Gzip import com.unciv.ui.saves.Gzip
import com.unciv.ui.utils.CameraStageBaseScreen import com.unciv.ui.utils.CameraStageBaseScreen
import com.unciv.ui.utils.onClick import com.unciv.ui.utils.onClick
import com.unciv.ui.worldscreen.optionstable.DropBox import com.unciv.ui.worldscreen.mainmenu.DropBox
import com.unciv.ui.worldscreen.optionstable.PopupTable import com.unciv.ui.utils.Popup
import kotlin.concurrent.thread import kotlin.concurrent.thread
class MapDownloadTable(loadMapScreen: LoadMapScreen): PopupTable(loadMapScreen) { class MapDownloadPopup(loadMapScreen: LoadMapScreen): Popup(loadMapScreen) {
init { init {
val folderList: DropBox.FolderList val folderList: DropBox.FolderList
try { try {
@ -36,7 +36,7 @@ class MapDownloadTable(loadMapScreen: LoadMapScreen): PopupTable(loadMapScreen)
// Yes, even creating popups. // Yes, even creating popups.
Gdx.app.postRunnable { Gdx.app.postRunnable {
val couldNotDownloadMapPopup = PopupTable(screen) val couldNotDownloadMapPopup = Popup(screen)
couldNotDownloadMapPopup.addGoodSizedLabel("Could not download map!").row() couldNotDownloadMapPopup.addGoodSizedLabel("Could not download map!").row()
couldNotDownloadMapPopup.addCloseButton() couldNotDownloadMapPopup.addCloseButton()
} }
@ -52,4 +52,4 @@ class MapDownloadTable(loadMapScreen: LoadMapScreen): PopupTable(loadMapScreen)
addCloseButton() addCloseButton()
open() open()
} }
} }

View File

@ -12,16 +12,16 @@ import com.unciv.logic.map.RoadStatus
import com.unciv.models.translations.tr import com.unciv.models.translations.tr
import com.unciv.ui.saves.Gzip import com.unciv.ui.saves.Gzip
import com.unciv.ui.utils.onClick import com.unciv.ui.utils.onClick
import com.unciv.ui.worldscreen.optionstable.DropBox import com.unciv.ui.worldscreen.mainmenu.DropBox
import com.unciv.ui.worldscreen.optionstable.PopupTable import com.unciv.ui.utils.Popup
import kotlin.concurrent.thread import kotlin.concurrent.thread
class MapEditorMenuPopup(mapEditorScreen: MapEditorScreen): PopupTable(mapEditorScreen){ class MapEditorMenuPopup(mapEditorScreen: MapEditorScreen): Popup(mapEditorScreen){
init{ init{
val mapNameEditor = TextField(mapEditorScreen.mapName, skin) val mapNameEditor = TextField(mapEditorScreen.mapName, skin)
mapNameEditor.addListener{ mapEditorScreen.mapName=mapNameEditor.text; true } mapNameEditor.addListener{ mapEditorScreen.mapName=mapNameEditor.text; true }
add(mapNameEditor).row() add(mapNameEditor).row()
val clearCurrentMapButton = TextButton("Clear current map".tr(),skin) val clearCurrentMapButton = TextButton("Clear current map".tr(),skin)
clearCurrentMapButton.onClick { clearCurrentMapButton.onClick {
for(tileGroup in mapEditorScreen.mapHolder.tileGroups.values) for(tileGroup in mapEditorScreen.mapHolder.tileGroups.values)
@ -72,13 +72,13 @@ class MapEditorMenuPopup(mapEditorScreen: MapEditorScreen): PopupTable(mapEditor
DropBox().uploadFile("/Maps/" + mapEditorScreen.mapName, gzippedMap) DropBox().uploadFile("/Maps/" + mapEditorScreen.mapName, gzippedMap)
remove() remove()
val uploadedSuccessfully = PopupTable(screen) val uploadedSuccessfully = Popup(screen)
uploadedSuccessfully.addGoodSizedLabel("Map uploaded successfully!").row() uploadedSuccessfully.addGoodSizedLabel("Map uploaded successfully!").row()
uploadedSuccessfully.addCloseButton() uploadedSuccessfully.addCloseButton()
uploadedSuccessfully.open() uploadedSuccessfully.open()
} catch (ex: Exception) { } catch (ex: Exception) {
remove() remove()
val couldNotUpload = PopupTable(screen) val couldNotUpload = Popup(screen)
couldNotUpload.addGoodSizedLabel("Could not upload map!").row() couldNotUpload.addGoodSizedLabel("Could not upload map!").row()
couldNotUpload.addCloseButton() couldNotUpload.addCloseButton()
couldNotUpload.open() couldNotUpload.open()

View File

@ -16,8 +16,8 @@ import com.unciv.ui.pickerscreens.PickerScreen
import com.unciv.ui.utils.disable import com.unciv.ui.utils.disable
import com.unciv.ui.utils.enable import com.unciv.ui.utils.enable
import com.unciv.ui.utils.onClick import com.unciv.ui.utils.onClick
import com.unciv.ui.worldscreen.optionstable.OnlineMultiplayer import com.unciv.ui.worldscreen.mainmenu.OnlineMultiplayer
import com.unciv.ui.worldscreen.optionstable.PopupTable import com.unciv.ui.utils.Popup
import java.util.* import java.util.*
import kotlin.concurrent.thread import kotlin.concurrent.thread
@ -41,7 +41,7 @@ class NewGameScreen: PickerScreen(){
rightSideButton.setText("Start game!".tr()) rightSideButton.setText("Start game!".tr())
rightSideButton.onClick { rightSideButton.onClick {
if (newGameParameters.players.none { it.playerType == PlayerType.Human }) { 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.addGoodSizedLabel("No human players selected!".tr()).row()
noHumanPlayersPopup.addCloseButton() noHumanPlayersPopup.addCloseButton()
noHumanPlayersPopup.open() noHumanPlayersPopup.open()
@ -53,7 +53,7 @@ class NewGameScreen: PickerScreen(){
try { try {
UUID.fromString(player.playerId) UUID.fromString(player.playerId)
} catch (ex: Exception) { } catch (ex: Exception) {
val invalidPlayerIdPopup = PopupTable(this) val invalidPlayerIdPopup = Popup(this)
invalidPlayerIdPopup.addGoodSizedLabel("Invalid player ID!".tr()).row() invalidPlayerIdPopup.addGoodSizedLabel("Invalid player ID!".tr()).row()
invalidPlayerIdPopup.addCloseButton() invalidPlayerIdPopup.addCloseButton()
invalidPlayerIdPopup.open() invalidPlayerIdPopup.open()
@ -76,7 +76,7 @@ class NewGameScreen: PickerScreen(){
OnlineMultiplayer().tryUploadGame(newGame!!) OnlineMultiplayer().tryUploadGame(newGame!!)
GameSaver().autoSave(newGame!!){} GameSaver().autoSave(newGame!!){}
} catch (ex: Exception) { } catch (ex: Exception) {
val cantUploadNewGamePopup = PopupTable(this) val cantUploadNewGamePopup = Popup(this)
cantUploadNewGamePopup.addGoodSizedLabel("Could not upload game!") cantUploadNewGamePopup.addGoodSizedLabel("Could not upload game!")
cantUploadNewGamePopup.addCloseButton() cantUploadNewGamePopup.addCloseButton()
cantUploadNewGamePopup.open() cantUploadNewGamePopup.open()
@ -84,7 +84,7 @@ class NewGameScreen: PickerScreen(){
} }
} }
} catch (exception: Exception) { } 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("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.addGoodSizedLabel("Maybe you put too many players into too small a map?".tr()).row()
cantMakeThatMapPopup.addCloseButton() cantMakeThatMapPopup.addCloseButton()

View File

@ -15,7 +15,7 @@ import com.unciv.models.metadata.Player
import com.unciv.models.ruleset.Ruleset import com.unciv.models.ruleset.Ruleset
import com.unciv.models.translations.tr import com.unciv.models.translations.tr
import com.unciv.ui.utils.* import com.unciv.ui.utils.*
import com.unciv.ui.worldscreen.optionstable.PopupTable import com.unciv.ui.utils.Popup
import java.util.* import java.util.*
class PlayerPickerTable(val newGameScreen: NewGameScreen, val newGameParameters: GameParameters): Table() { 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) { private fun popupNationPicker(player: Player) {
val nationsPopup = PopupTable(newGameScreen) val nationsPopup = Popup(newGameScreen)
val nationListTable = Table() val nationListTable = Table()
val randomPlayerTable = Table() val randomPlayerTable = Table()

View File

@ -16,7 +16,7 @@ import com.unciv.ui.utils.disable
import com.unciv.ui.utils.enable import com.unciv.ui.utils.enable
import com.unciv.ui.utils.onClick import com.unciv.ui.utils.onClick
import com.unciv.ui.utils.toLabel 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.text.SimpleDateFormat
import java.util.* import java.util.*
@ -42,7 +42,7 @@ class LoadGameScreen : PickerScreen() {
UncivGame.Current.loadGame(selectedSave) UncivGame.Current.loadGame(selectedSave)
} }
catch (ex:Exception){ 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("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("If you could copy your game data (\"Copy saved game to clipboard\" - ").row()
cantLoadGamePopup.addGoodSizedLabel(" paste into an email to yairm210@hotmail.com)").row() cantLoadGamePopup.addGoodSizedLabel(" paste into an email to yairm210@hotmail.com)").row()

View File

@ -20,7 +20,7 @@ import com.unciv.logic.trade.TradeOffer
import com.unciv.logic.trade.TradeType import com.unciv.logic.trade.TradeType
import com.unciv.models.translations.tr import com.unciv.models.translations.tr
import com.unciv.ui.utils.* import com.unciv.ui.utils.*
import com.unciv.ui.worldscreen.optionstable.YesNoPopupTable import com.unciv.ui.utils.YesNoPopup
import kotlin.math.roundToInt import kotlin.math.roundToInt
class DiplomacyScreen(val viewingCiv:CivilizationInfo):CameraStageBaseScreen() { class DiplomacyScreen(val viewingCiv:CivilizationInfo):CameraStageBaseScreen() {
@ -152,7 +152,7 @@ class DiplomacyScreen(val viewingCiv:CivilizationInfo):CameraStageBaseScreen() {
if (viewingCiv.isAtWarWith(otherCiv)) { if (viewingCiv.isAtWarWith(otherCiv)) {
val peaceButton = TextButton("Negotiate Peace".tr(), skin) val peaceButton = TextButton("Negotiate Peace".tr(), skin)
peaceButton.onClick { peaceButton.onClick {
YesNoPopupTable("Peace with [${otherCiv.civName}]?".tr(), { YesNoPopup("Peace with [${otherCiv.civName}]?".tr(), {
val tradeLogic = TradeLogic(viewingCiv, otherCiv) val tradeLogic = TradeLogic(viewingCiv, otherCiv)
tradeLogic.currentTrade.ourOffers.add(TradeOffer(Constants.peaceTreaty, TradeType.Treaty, 30)) tradeLogic.currentTrade.ourOffers.add(TradeOffer(Constants.peaceTreaty, TradeType.Treaty, 30))
tradeLogic.currentTrade.theirOffers.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.setText(declareWarButton.text.toString() + " ($turnsToPeaceTreaty)")
} }
declareWarButton.onClick { declareWarButton.onClick {
YesNoPopupTable("Declare war on [${otherCiv.civName}]?".tr(), { YesNoPopup("Declare war on [${otherCiv.civName}]?".tr(), {
diplomacyManager.declareWar() diplomacyManager.declareWar()
setRightSideFlavorText(otherCiv,otherCiv.getTranslatedNation().attacked,"Very well.") setRightSideFlavorText(otherCiv, otherCiv.getTranslatedNation().attacked, "Very well.")
updateLeftSideTable() updateLeftSideTable()
}, this) }, this)
} }
@ -358,4 +358,4 @@ class DiplomacyScreen(val viewingCiv:CivilizationInfo):CameraStageBaseScreen() {
rightSideTable.add(diplomacyTable) rightSideTable.add(diplomacyTable)
} }
} }

View File

@ -20,8 +20,6 @@ class TutorialController(
showTutorialIfNeeded() showTutorialIfNeeded()
} }
fun isTutorialShowing(): Boolean = isTutorialShowing
private fun showTutorialIfNeeded() { private fun showTutorialIfNeeded() {
val tutorial = tutorialQueue.firstOrNull() val tutorial = tutorialQueue.firstOrNull()
if (tutorial == null) { if (tutorial == null) {
@ -42,4 +40,4 @@ class TutorialController(
} }
} }
} }
} }

View File

@ -6,8 +6,8 @@ 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
import com.unciv.ui.utils.ImageGetter import com.unciv.ui.utils.ImageGetter
import com.unciv.ui.utils.Popup
import com.unciv.ui.utils.onClick import com.unciv.ui.utils.onClick
import com.unciv.ui.worldscreen.optionstable.PopupTable
data class TutorialForRender(val tutorial: Tutorial, val texts: List<String>) data class TutorialForRender(val tutorial: Tutorial, val texts: List<String>)
@ -22,21 +22,21 @@ class TutorialRender(private val screen: CameraStageBaseScreen) {
if (text == null) { if (text == null) {
closeAction() closeAction()
} else { } else {
val tutorialTable = PopupTable(screen) val tutorialPopup = Popup(screen)
if (Gdx.files.internal("ExtraImages/$tutorialName").exists()) { 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) val button = TextButton("Close".tr(), CameraStageBaseScreen.skin)
button.onClick { button.onClick {
tutorialTable.remove() tutorialPopup.remove()
showDialog(tutorialName, texts - text, closeAction) showDialog(tutorialName, texts - text, closeAction)
} }
tutorialTable.add(button).pad(10f) tutorialPopup.add(button).pad(10f)
tutorialTable.open() tutorialPopup.open()
} }
} }
} }

View File

@ -32,14 +32,12 @@ import com.unciv.models.translations.tr
import com.unciv.ui.tutorials.TutorialController import com.unciv.ui.tutorials.TutorialController
import com.unciv.ui.tutorials.TutorialMiner import com.unciv.ui.tutorials.TutorialMiner
import com.unciv.ui.tutorials.TutorialRender import com.unciv.ui.tutorials.TutorialRender
import com.unciv.ui.worldscreen.TradePopup
import kotlin.concurrent.thread import kotlin.concurrent.thread
open class CameraStageBaseScreen : Screen { open class CameraStageBaseScreen : Screen {
var game: UncivGame = UncivGame.Current var game: UncivGame = UncivGame.Current
var stage: Stage var stage: Stage
var hasPopupOpen = false
val tutorialController by lazy { val tutorialController by lazy {
TutorialController(TutorialMiner(JsonParser()), TutorialRender(this)) TutorialController(TutorialMiner(JsonParser()), TutorialRender(this))
@ -85,8 +83,8 @@ open class CameraStageBaseScreen : Screen {
tutorialController.showTutorial(tutorial) tutorialController.showTutorial(tutorial)
} }
fun hasVisibleDialogs(): Boolean = fun hasOpenPopups(): Boolean =
tutorialController.isTutorialShowing() || stage.actors.any { it is TradePopup } || hasPopupOpen stage.actors.any { it is Popup }
companion object { companion object {
var skin = Skin(Gdx.files.internal("skin/flat-earth-ui.json")) var skin = Skin(Gdx.files.internal("skin/flat-earth-ui.json"))

View File

@ -4,7 +4,6 @@ import com.badlogic.gdx.utils.Json
import com.unciv.UncivGame import com.unciv.UncivGame
import com.unciv.models.CrashReport import com.unciv.models.CrashReport
import com.unciv.ui.saves.Gzip import com.unciv.ui.saves.Gzip
import com.unciv.ui.worldscreen.optionstable.PopupTable
interface CrashController { interface CrashController {
@ -40,14 +39,14 @@ interface CrashController {
} }
} }
private fun prepareDialog(): PopupTable { private fun prepareDialog(): Popup {
return if (crashReportSender == null) { return if (crashReportSender == null) {
PopupTable(UncivGame.Current.worldScreen).apply { Popup(UncivGame.Current.worldScreen).apply {
addGoodSizedLabel(MESSAGE_FALLBACK).row() addGoodSizedLabel(MESSAGE_FALLBACK).row()
addCloseButton() addCloseButton()
} }
} else { } else {
PopupTable(UncivGame.Current.worldScreen).apply { Popup(UncivGame.Current.worldScreen).apply {
addGoodSizedLabel(MESSAGE).row() addGoodSizedLabel(MESSAGE).row()
addButton("Send report") { addButton("Send report") {
crashReportSender.sendReport(buildReport()) crashReportSender.sendReport(buildReport())
@ -65,4 +64,4 @@ interface CrashController {
} }
} }
} }
} }

View File

@ -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.graphics.Color
import com.badlogic.gdx.scenes.scene2d.Touchable 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.scenes.scene2d.ui.TextButton
import com.badlogic.gdx.utils.Align import com.badlogic.gdx.utils.Align
import com.unciv.models.translations.tr 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 { init {
background = ImageGetter.getBackground(ImageGetter.getBlue().lerp(Color.BLACK, 0.5f)) 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) this.defaults().pad(5f)
} }
/**
* Displays the Popup on the screen. Will not open the popup if another one is already open.
*/
fun open() { fun open() {
if (screen.hasOpenPopups()) return;
pack() pack()
center(screen.stage) center(screen.stage)
screen.stage.addActor(this) screen.stage.addActor(this)

View File

@ -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()
}
}

View File

@ -7,9 +7,8 @@ import com.unciv.logic.civilization.CivilizationInfo
import com.unciv.logic.civilization.PopupAlert import com.unciv.logic.civilization.PopupAlert
import com.unciv.models.translations.tr import com.unciv.models.translations.tr
import com.unciv.ui.utils.* 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 { fun getCloseButton(text: String, action: (() -> Unit)?=null): TextButton {
val button = TextButton(text.tr(), skin) val button = TextButton(text.tr(), skin)
button.onClick { 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() addGoodSizedLabel("Destroying the city instantly razes the city to the ground.").row()
} }
} }
AlertType.BorderConflict -> { AlertType.BorderConflict -> {
val civInfo = worldScreen.gameInfo.getCivilization(popupAlert.value) val civInfo = worldScreen.gameInfo.getCivilization(popupAlert.value)
@ -180,12 +179,10 @@ class AlertPopup(val worldScreen: WorldScreen, val popupAlert: PopupAlert): Popu
} }
} }
open() open()
worldScreen.hasPopupOpen = true
} }
override fun close(){ override fun close(){
worldScreen.viewingCiv.popupAlerts.remove(popupAlert) worldScreen.viewingCiv.popupAlerts.remove(popupAlert)
worldScreen.hasPopupOpen = false
super.close() super.close()
} }
} }

View File

@ -11,11 +11,11 @@ import com.unciv.models.translations.tr
import com.unciv.ui.trade.DiplomacyScreen import com.unciv.ui.trade.DiplomacyScreen
import com.unciv.ui.utils.addSeparator import com.unciv.ui.utils.addSeparator
import com.unciv.ui.utils.toLabel 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.max
import kotlin.math.min import kotlin.math.min
class TradePopup(worldScreen: WorldScreen): PopupTable(worldScreen){ class TradePopup(worldScreen: WorldScreen): Popup(worldScreen){
init{ init{
val viewingCiv = worldScreen.viewingCiv val viewingCiv = worldScreen.viewingCiv
val tradeRequest = viewingCiv.tradeRequests.first() val tradeRequest = viewingCiv.tradeRequests.first()
@ -52,7 +52,7 @@ class TradePopup(worldScreen: WorldScreen): PopupTable(worldScreen){
tradeLogic.acceptTrade() tradeLogic.acceptTrade()
viewingCiv.tradeRequests.remove(tradeRequest) viewingCiv.tradeRequests.remove(tradeRequest)
close() close()
PopupTable(worldScreen).apply { Popup(worldScreen).apply {
add(otherCivLeaderName.toLabel()).colspan(2) add(otherCivLeaderName.toLabel()).colspan(2)
addSeparator() addSeparator()
addGoodSizedLabel("Excellent!").row() addGoodSizedLabel("Excellent!").row()
@ -94,4 +94,4 @@ class TradePopup(worldScreen: WorldScreen): PopupTable(worldScreen){
} }
open() open()
} }
} }

View File

@ -30,8 +30,7 @@ import com.unciv.ui.trade.DiplomacyScreen
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
import com.unciv.ui.worldscreen.optionstable.OnlineMultiplayer import com.unciv.ui.worldscreen.mainmenu.OnlineMultiplayer
import com.unciv.ui.worldscreen.optionstable.PopupTable
import com.unciv.ui.worldscreen.unit.UnitActionsTable import com.unciv.ui.worldscreen.unit.UnitActionsTable
import com.unciv.ui.worldscreen.unit.UnitTable import com.unciv.ui.worldscreen.unit.UnitTable
import kotlin.concurrent.thread import kotlin.concurrent.thread
@ -137,7 +136,7 @@ class WorldScreen(val viewingCiv:CivilizationInfo) : CameraStageBaseScreen() {
} }
private fun loadLatestMultiplayerState(){ private fun loadLatestMultiplayerState(){
val loadingGamePopup = PopupTable(this) val loadingGamePopup = Popup(this)
loadingGamePopup.add("Loading latest game state...") loadingGamePopup.add("Loading latest game state...")
loadingGamePopup.open() loadingGamePopup.open()
thread(name="MultiplayerLoad") { thread(name="MultiplayerLoad") {
@ -153,7 +152,7 @@ class WorldScreen(val viewingCiv:CivilizationInfo) : CameraStageBaseScreen() {
} catch (ex: Exception) { } catch (ex: Exception) {
loadingGamePopup.close() loadingGamePopup.close()
val couldntDownloadLatestGame = PopupTable(this) val couldntDownloadLatestGame = Popup(this)
couldntDownloadLatestGame.addGoodSizedLabel("Couldn't download the latest game state!").row() couldntDownloadLatestGame.addGoodSizedLabel("Couldn't download the latest game state!").row()
couldntDownloadLatestGame.addCloseButton() couldntDownloadLatestGame.addCloseButton()
couldntDownloadLatestGame.addAction(Actions.delay(5f, Actions.run { couldntDownloadLatestGame.close() })) 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) techPolicyAndVictoryHolder.setPosition(10f, topBar.y - techPolicyAndVictoryHolder.height - 5f)
updateDiplomacyButton(viewingCiv) updateDiplomacyButton(viewingCiv)
if (!hasVisibleDialogs() && isPlayersTurn) { if (!hasOpenPopups() && isPlayersTurn) {
when { when {
!gameInfo.oneMoreTurnMode && viewingCiv.isDefeated() -> game.setScreen(VictoryScreen()) !gameInfo.oneMoreTurnMode && viewingCiv.isDefeated() -> game.setScreen(VictoryScreen())
!gameInfo.oneMoreTurnMode && gameInfo.civilizations.any { it.victoryManager.hasWon() } -> 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) 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.update(viewingCiv.notifications)
notificationsScroll.setPosition(stage.width - notificationsScroll.width - 5f, notificationsScroll.setPosition(stage.width - notificationsScroll.width - 5f,
nextTurnButton.y - notificationsScroll.height - 5f) nextTurnButton.y - notificationsScroll.height - 5f)
@ -389,7 +388,7 @@ class WorldScreen(val viewingCiv:CivilizationInfo) : CameraStageBaseScreen() {
try { try {
OnlineMultiplayer().tryUploadGame(gameInfoClone) OnlineMultiplayer().tryUploadGame(gameInfoClone)
} catch (ex: Exception) { } catch (ex: Exception) {
val cantUploadNewGamePopup = PopupTable(this) val cantUploadNewGamePopup = Popup(this)
cantUploadNewGamePopup.addGoodSizedLabel("Could not upload game!").row() cantUploadNewGamePopup.addGoodSizedLabel("Could not upload game!").row()
cantUploadNewGamePopup.addCloseButton() cantUploadNewGamePopup.addCloseButton()
cantUploadNewGamePopup.open() 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 // remove current listener for the "BACK" button to avoid showing the dialog twice
stage.removeListener( backButtonListener ) stage.removeListener( backButtonListener )
var promptWindow = PopupTable(this) var promptWindow = Popup(this)
promptWindow.addGoodSizedLabel("Do you want to exit the game?".tr()) promptWindow.addGoodSizedLabel("Do you want to exit the game?".tr())
promptWindow.row() promptWindow.row()
promptWindow.addButton("Yes"){game.exitEvent?.invoke()} promptWindow.addButton("Yes"){game.exitEvent?.invoke()}

View File

@ -10,11 +10,11 @@ import com.badlogic.gdx.scenes.scene2d.ui.TextButton
import com.unciv.UncivGame import com.unciv.UncivGame
import com.unciv.logic.civilization.CivilizationInfo import com.unciv.logic.civilization.CivilizationInfo
import com.unciv.models.ruleset.tile.ResourceType import com.unciv.models.ruleset.tile.ResourceType
import com.unciv.models.translations.tr
import com.unciv.models.stats.Stats import com.unciv.models.stats.Stats
import com.unciv.models.translations.tr
import com.unciv.ui.EmpireOverviewScreen import com.unciv.ui.EmpireOverviewScreen
import com.unciv.ui.utils.* 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.abs
import kotlin.math.ceil import kotlin.math.ceil
import kotlin.math.roundToInt import kotlin.math.roundToInt
@ -95,8 +95,8 @@ class WorldScreenTopBar(val worldScreen: WorldScreen) : Table() {
.apply { setSize(50f, 50f) } .apply { setSize(50f, 50f) }
menuButton.color = Color.WHITE menuButton.color = Color.WHITE
menuButton.onClick { menuButton.onClick {
if(worldScreen.stage.actors.none { it is WorldScreenMenuTable }) if(worldScreen.stage.actors.none { it is WorldScreenMenuPopup })
WorldScreenMenuTable(worldScreen) WorldScreenMenuPopup(worldScreen)
} }
menuButton.centerY(this) menuButton.centerY(this)
menuButton.x = menuButton.y menuButton.x = menuButton.y

View File

@ -17,7 +17,7 @@ import com.unciv.models.translations.tr
import com.unciv.models.ruleset.unit.UnitType import com.unciv.models.ruleset.unit.UnitType
import com.unciv.ui.utils.* import com.unciv.ui.utils.*
import com.unciv.ui.worldscreen.WorldScreen import com.unciv.ui.worldscreen.WorldScreen
import com.unciv.ui.worldscreen.optionstable.PopupTable import com.unciv.ui.utils.Popup
import kotlin.math.max import kotlin.math.max
class BattleTable(val worldScreen: WorldScreen): Table() { 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()) val canBombard = UnitAutomation().getBombardTargets(attacker.city).contains(defender.getTile())
if (canBombard) { if (canBombard) {
attackableEnemy = AttackableTile(attacker.getTile(), defender.getTile()) attackableEnemy = AttackableTile(attacker.getTile(), defender.getTile())
} }
} }
} }
@ -204,7 +204,7 @@ class BattleTable(val worldScreen: WorldScreen): Table() {
worldScreen.shouldUpdate = true worldScreen.shouldUpdate = true
} }
catch (ex:Exception){ 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("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("If you could copy your game data (\"Copy saved game to clipboard\" - ").row()
battleBugPopup.addGoodSizedLabel(" paste into an email to yairm210@hotmail.com)").row() battleBugPopup.addGoodSizedLabel(" paste into an email to yairm210@hotmail.com)").row()

View File

@ -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.GameInfo
import com.unciv.logic.GameSaver import com.unciv.logic.GameSaver
@ -103,4 +103,4 @@ class OnlineMultiplayer {
val zippedGameInfo = DropBox().downloadFileAsString(getGameLocation(gameId)) val zippedGameInfo = DropBox().downloadFileAsString(getGameLocation(gameId))
return GameSaver().gameInfoFromString(Gzip.unzip(zippedGameInfo)) return GameSaver().gameInfoFromString(Gzip.unzip(zippedGameInfo))
} }
} }

View File

@ -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.Gdx
import com.badlogic.gdx.graphics.Color 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.newgamescreen.NewGameScreen
import com.unciv.ui.saves.LoadGameScreen import com.unciv.ui.saves.LoadGameScreen
import com.unciv.ui.saves.SaveGameScreen import com.unciv.ui.saves.SaveGameScreen
import com.unciv.ui.utils.Popup
import com.unciv.ui.utils.addSeparator import com.unciv.ui.utils.addSeparator
import com.unciv.ui.utils.disable import com.unciv.ui.utils.disable
import com.unciv.ui.utils.toLabel import com.unciv.ui.utils.toLabel
@ -19,7 +20,7 @@ import java.util.*
import kotlin.collections.ArrayList import kotlin.collections.ArrayList
import kotlin.concurrent.thread import kotlin.concurrent.thread
class WorldScreenMenuTable(val worldScreen: WorldScreen) : PopupTable(worldScreen) { class WorldScreenMenuPopup(val worldScreen: WorldScreen) : Popup(worldScreen) {
init { init {
val width = 200f val width = 200f
@ -69,13 +70,13 @@ class WorldScreenMenuTable(val worldScreen: WorldScreen) : PopupTable(worldScree
addSeparator() addSeparator()
addSquareButton("Options".tr()){ addSquareButton("Options".tr()){
UncivGame.Current.worldScreen.stage.addActor(WorldScreenOptionsTable(worldScreen)) UncivGame.Current.worldScreen.stage.addActor(WorldScreenOptionsPopup(worldScreen))
remove() remove()
}.size(width,height) }.size(width,height)
addSeparator() addSeparator()
addSquareButton("Community"){ addSquareButton("Community"){
WorldScreenCommunityTable(worldScreen) WorldScreenCommunityPopup(worldScreen)
remove() remove()
}.size(width,height) }.size(width,height)
addSeparator() addSeparator()
@ -92,7 +93,7 @@ class WorldScreenMenuTable(val worldScreen: WorldScreen) : PopupTable(worldScree
fun openMultiplayerPopup(){ fun openMultiplayerPopup(){
close() 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("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() 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{ init{
addButton("Discord"){ addButton("Discord"){
Gdx.net.openURI("https://discord.gg/bjrB4Xw") Gdx.net.openURI("https://discord.gg/bjrB4Xw")

View File

@ -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.Gdx
import com.badlogic.gdx.graphics.Color 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" var selectedLanguage: String = "English"
init { init {
@ -35,7 +35,7 @@ class WorldScreenOptionsTable(val worldScreen:WorldScreen) : PopupTable(worldScr
settings.save() settings.save()
clear() 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.background = null
innerTable.add("Display options".toLabel(fontSize = 24)).colspan(2).row() 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()) innerTable.add("Sound effects volume".tr())
val soundEffectsVolumeSlider = Slider(0f, 1.0f, 0.1f, false, skin) 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() innerTable.add(soundEffectsVolumeSlider).row()
} }
private fun addMusicVolumeSlider(innerTable: PopupTable) { private fun addMusicVolumeSlider(innerTable: Popup) {
val musicLocation =Gdx.files.local(UncivGame.Current.musicLocation) val musicLocation =Gdx.files.local(UncivGame.Current.musicLocation)
if(musicLocation.exists()) { if(musicLocation.exists()) {
innerTable.add("Music volume".tr()) 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()) innerTable.add("Resolution".toLabel())
val resolutionSelectBox = SelectBox<String>(skin) val resolutionSelectBox = SelectBox<String>(skin)
@ -216,12 +216,12 @@ class WorldScreenOptionsTable(val worldScreen:WorldScreen) : PopupTable(worldScr
UncivGame.Current.settings.save() UncivGame.Current.settings.save()
UncivGame.Current.worldScreen = WorldScreen(worldScreen.viewingCiv) UncivGame.Current.worldScreen = WorldScreen(worldScreen.viewingCiv)
UncivGame.Current.setWorldScreen() 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()) innerTable.add("Tileset".toLabel())
val tileSetSelectBox = SelectBox<String>(skin) val tileSetSelectBox = SelectBox<String>(skin)
@ -239,12 +239,12 @@ class WorldScreenOptionsTable(val worldScreen:WorldScreen) : PopupTable(worldScr
UncivGame.Current.settings.save() UncivGame.Current.settings.save()
UncivGame.Current.worldScreen = WorldScreen(worldScreen.viewingCiv) UncivGame.Current.worldScreen = WorldScreen(worldScreen.viewingCiv)
UncivGame.Current.setWorldScreen() 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()) innerTable.add("Turns between autosaves".toLabel())
val autosaveTurnsSelectBox = SelectBox<Int>(skin) val autosaveTurnsSelectBox = SelectBox<Int>(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<Language>(skin) val languageSelectBox = SelectBox<Language>(skin)
val languageArray = Array<Language>() val languageArray = Array<Language>()
UncivGame.Current.translations.percentCompleteOfLanguages UncivGame.Current.translations.percentCompleteOfLanguages
@ -298,6 +298,6 @@ class WorldScreenOptionsTable(val worldScreen:WorldScreen) : PopupTable(worldScr
CameraStageBaseScreen.resetFonts() // to load chinese characters if necessary CameraStageBaseScreen.resetFonts() // to load chinese characters if necessary
UncivGame.Current.worldScreen = WorldScreen(worldScreen.viewingCiv) UncivGame.Current.worldScreen = WorldScreen(worldScreen.viewingCiv)
UncivGame.Current.setWorldScreen() UncivGame.Current.setWorldScreen()
WorldScreenOptionsTable(UncivGame.Current.worldScreen) WorldScreenOptionsPopup(UncivGame.Current.worldScreen)
} }
} }

View File

@ -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
}
}

View File

@ -16,7 +16,7 @@ import com.unciv.models.translations.tr
import com.unciv.ui.pickerscreens.ImprovementPickerScreen import com.unciv.ui.pickerscreens.ImprovementPickerScreen
import com.unciv.ui.pickerscreens.PromotionPickerScreen import com.unciv.ui.pickerscreens.PromotionPickerScreen
import com.unciv.ui.worldscreen.WorldScreen import com.unciv.ui.worldscreen.WorldScreen
import com.unciv.ui.worldscreen.optionstable.YesNoPopupTable import com.unciv.ui.utils.YesNoPopup
class UnitActions { class UnitActions {
@ -314,7 +314,7 @@ class UnitActions {
val disbandText = if (unit.currentTile.getOwner() == unit.civInfo) val disbandText = if (unit.currentTile.getOwner() == unit.civInfo)
"Disband this unit for [${unit.baseUnit.getDisbandGold()}] gold?".tr() "Disband this unit for [${unit.baseUnit.getDisbandGold()}] gold?".tr()
else "Do you really want to disband this unit?".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 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 // 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) return tileOwner == null || tileOwner == unit.civInfo || unit.civInfo.isAtWarWith(tileOwner)
} }
} }