Added close() function to popup

This commit is contained in:
Yair Morgenstern 2019-08-27 17:00:28 +03:00
parent 834290001b
commit e82b6c5090
13 changed files with 91 additions and 47 deletions

View File

@ -2,7 +2,6 @@ package com.unciv.logic
import com.badlogic.gdx.graphics.Color import com.badlogic.gdx.graphics.Color
import com.unciv.Constants import com.unciv.Constants
import com.unciv.models.metadata.GameParameters
import com.unciv.logic.automation.NextTurnAutomation import com.unciv.logic.automation.NextTurnAutomation
import com.unciv.logic.city.CityConstructions import com.unciv.logic.city.CityConstructions
import com.unciv.logic.civilization.CivilizationInfo import com.unciv.logic.civilization.CivilizationInfo
@ -12,11 +11,15 @@ import com.unciv.logic.map.TileInfo
import com.unciv.logic.map.TileMap import com.unciv.logic.map.TileMap
import com.unciv.models.gamebasics.Difficulty import com.unciv.models.gamebasics.Difficulty
import com.unciv.models.gamebasics.GameBasics import com.unciv.models.gamebasics.GameBasics
import com.unciv.models.metadata.GameParameters
import java.util.* import java.util.*
class GameInfo { class GameInfo {
@Transient lateinit var difficultyObject: Difficulty // Since this is static game-wide, and was taking a large part of nextTurn @Transient lateinit var difficultyObject: Difficulty // Since this is static game-wide, and was taking a large part of nextTurn
@Transient lateinit var currentPlayerCiv:CivilizationInfo // this is called thousands of times, no reason to search for it with a find{} every time @Transient lateinit var currentPlayerCiv:CivilizationInfo // this is called thousands of times, no reason to search for it with a find{} every time
/** This is used in multiplayer games, where I may have a saved game state on my phone
* that is inconsistent with the saved game on the cloud */
@Transient var isUpToDate=false
var civilizations = mutableListOf<CivilizationInfo>() var civilizations = mutableListOf<CivilizationInfo>()
var difficulty="Chieftain" // difficulty is game-wide, think what would happen if 2 human players could play on different difficulties? var difficulty="Chieftain" // difficulty is game-wide, think what would happen if 2 human players could play on different difficulties?

View File

@ -6,8 +6,8 @@ import com.unciv.logic.civilization.CivilizationInfo
import com.unciv.logic.map.BFS import com.unciv.logic.map.BFS
import com.unciv.logic.map.TileInfo import com.unciv.logic.map.TileInfo
import com.unciv.logic.map.TileMap import com.unciv.logic.map.TileMap
import com.unciv.models.metadata.GameParameters
import com.unciv.models.gamebasics.GameBasics import com.unciv.models.gamebasics.GameBasics
import com.unciv.models.metadata.GameParameters
import java.util.* import java.util.*
import kotlin.collections.ArrayList import kotlin.collections.ArrayList
@ -18,6 +18,7 @@ class GameStarter{
gameInfo.gameParameters = newGameParameters gameInfo.gameParameters = newGameParameters
gameInfo.tileMap = TileMap(newGameParameters) gameInfo.tileMap = TileMap(newGameParameters)
gameInfo.tileMap.gameInfo = gameInfo // need to set this transient before placing units in the map gameInfo.tileMap.gameInfo = gameInfo // need to set this transient before placing units in the map
gameInfo.difficulty = newGameParameters.difficulty
val availableCivNames = Stack<String>() val availableCivNames = Stack<String>()
@ -34,8 +35,8 @@ class GameStarter{
else availableCivNames.pop() else availableCivNames.pop()
val playerCiv = CivilizationInfo(nationName) val playerCiv = CivilizationInfo(nationName)
gameInfo.difficulty = newGameParameters.difficulty
playerCiv.playerType = player.playerType playerCiv.playerType = player.playerType
playerCiv.playerId = player.playerId
gameInfo.civilizations.add(playerCiv) gameInfo.civilizations.add(playerCiv)
} }

View File

@ -42,9 +42,10 @@ class CivilizationInfo {
@Transient var statsForNextTurn = Stats() @Transient var statsForNextTurn = Stats()
@Transient var detailedCivResources = ResourceSupplyList() @Transient var detailedCivResources = ResourceSupplyList()
var playerType = PlayerType.AI
/** Used in online multiplayer for human players */ var playerId = ""
var gold = 0 var gold = 0
@Deprecated("As of 2.11.1") var difficulty = "Chieftain" @Deprecated("As of 2.11.1") var difficulty = "Chieftain"
var playerType = PlayerType.AI
var civName = "" var civName = ""
var tech = TechManager() var tech = TechManager()
var policies = PolicyManager() var policies = PolicyManager()

View File

@ -96,9 +96,9 @@ class MapEditorOptionsTable(mapEditorScreen: MapEditorScreen): PopupTable(mapEdi
exitMapEditorButton.onClick { UnCivGame.Current.setWorldScreen(); mapEditorScreen.dispose() } exitMapEditorButton.onClick { UnCivGame.Current.setWorldScreen(); mapEditorScreen.dispose() }
add(exitMapEditorButton ).row() add(exitMapEditorButton ).row()
val closeOptionsButtton = TextButton("Close".tr(), skin) val closeOptionsButton = TextButton("Close".tr(), skin)
closeOptionsButtton.onClick { remove() } closeOptionsButton.onClick { close() }
add(closeOptionsButtton).row() add(closeOptionsButton).row()
open() open()
} }
@ -125,7 +125,7 @@ class MapDownloadTable(mapEditorScreen: MapEditorScreen):PopupTable(mapEditorScr
} catch (ex: Exception) { } catch (ex: Exception) {
addGoodSizedLabel("Could not get list of maps!").row() addGoodSizedLabel("Could not get list of maps!").row()
} }
addButton("Close") { remove() } addButton("Close") { close() }
open() open()
} }
} }

View File

@ -15,6 +15,7 @@ import com.unciv.ui.utils.enable
import com.unciv.ui.utils.onClick import com.unciv.ui.utils.onClick
import com.unciv.ui.worldscreen.WorldScreen import com.unciv.ui.worldscreen.WorldScreen
import com.unciv.ui.worldscreen.optionstable.PopupTable import com.unciv.ui.worldscreen.optionstable.PopupTable
import java.util.*
import kotlin.concurrent.thread import kotlin.concurrent.thread
class NewGameScreen: PickerScreen(){ class NewGameScreen: PickerScreen(){
@ -34,13 +35,28 @@ 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 popup = PopupTable(this) val noHumanPlayersPopup = PopupTable(this)
popup.addGoodSizedLabel("No human players selected!").row() noHumanPlayersPopup.addGoodSizedLabel("No human players selected!").row()
popup.addButton("Close") { popup.remove() } noHumanPlayersPopup.addButton("Close") { noHumanPlayersPopup.close() }
popup.open() noHumanPlayersPopup.open()
return@onClick return@onClick
} }
if (newGameParameters.isOnlineMultiplayer){
for(player in newGameParameters.players.filter{ it.playerType == PlayerType.Human}) {
try {
UUID.fromString(player.playerId)
}
catch (ex:Exception) {
val invalidPlayerIdPopup = PopupTable(this)
invalidPlayerIdPopup.addGoodSizedLabel("Invalid player ID!").row()
invalidPlayerIdPopup.addButton("Close") { invalidPlayerIdPopup.remove() }
invalidPlayerIdPopup.open()
return@onClick
}
}
}
Gdx.input.inputProcessor = null // remove input processing - nothing will be clicked! Gdx.input.inputProcessor = null // remove input processing - nothing will be clicked!
rightSideButton.disable() rightSideButton.disable()
rightSideButton.setText("Working...".tr()) rightSideButton.setText("Working...".tr())
@ -50,10 +66,10 @@ class NewGameScreen: PickerScreen(){
try { try {
newGame = GameStarter().startNewGame(newGameParameters) newGame = GameStarter().startNewGame(newGameParameters)
} catch (exception: Exception) { } catch (exception: Exception) {
val popup = PopupTable(this) val cantMakeThatMapPopup = PopupTable(this)
popup.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()
popup.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()
popup.open() cantMakeThatMapPopup.open()
} }
} }
} }

View File

@ -86,8 +86,6 @@ class PlayerPickerTable(val newGameScreen: NewGameScreen, val newGameParameters:
playerIdTable.add(setCurrentUserButton) playerIdTable.add(setCurrentUserButton)
playerTable.add(playerIdTable).colspan(playerTable.columns) playerTable.add(playerIdTable).colspan(playerTable.columns)
} }
return playerTable return playerTable
@ -111,7 +109,7 @@ class PlayerPickerTable(val newGameScreen: NewGameScreen, val newGameParameters:
nationListTable.add(NationTable(nation, halfWidth) { nationListTable.add(NationTable(nation, halfWidth) {
player.chosenCiv = nation.name player.chosenCiv = nation.name
nationsPopup.remove() nationsPopup.close()
update() update()
}).pad(10f).width(halfWidth).row() }).pad(10f).width(halfWidth).row()
} }

View File

@ -101,9 +101,9 @@ class AlertPopup(val worldScreen: WorldScreen, val popupAlert: PopupAlert): Popu
worldScreen.alertPopupIsOpen = true worldScreen.alertPopupIsOpen = true
} }
fun close(){ override fun close(){
worldScreen.viewingCiv.popupAlerts.remove(popupAlert) worldScreen.viewingCiv.popupAlerts.remove(popupAlert)
worldScreen.alertPopupIsOpen = false worldScreen.alertPopupIsOpen = false
remove() super.close()
} }
} }

View File

@ -43,13 +43,13 @@ class TradePopup(worldScreen: WorldScreen): PopupTable(worldScreen){
tradeLogic.currentTrade.set(trade) tradeLogic.currentTrade.set(trade)
tradeLogic.acceptTrade() tradeLogic.acceptTrade()
currentPlayerCiv.tradeRequests.remove(tradeRequest) currentPlayerCiv.tradeRequests.remove(tradeRequest)
remove() close()
PopupTable(worldScreen).apply { PopupTable(worldScreen).apply {
add(otherCivLeaderName.toLabel()).colspan(2) add(otherCivLeaderName.toLabel()).colspan(2)
addSeparator() addSeparator()
addGoodSizedLabel("Excellent!").row() addGoodSizedLabel("Excellent!").row()
addButton("Farewell."){ addButton("Farewell."){
this.remove() close()
worldScreen.shouldUpdate=true worldScreen.shouldUpdate=true
// in all cases, worldScreen.shouldUpdate should be set to true when we remove the last of the popups // in all cases, worldScreen.shouldUpdate should be set to true when we remove the last of the popups
// in order for the next trade to appear immediately // in order for the next trade to appear immediately
@ -68,14 +68,14 @@ class TradePopup(worldScreen: WorldScreen): PopupTable(worldScreen){
if(trade.ourOffers.any{ it.type==TradeType.Treaty && it.name== Constants.peaceTreaty }) if(trade.ourOffers.any{ it.type==TradeType.Treaty && it.name== Constants.peaceTreaty })
diplomacyManager.setFlag(DiplomacyFlags.DeclinedPeace,5) diplomacyManager.setFlag(DiplomacyFlags.DeclinedPeace,5)
remove() close()
requestingCiv.addNotification("[${currentPlayerCiv.civName}] has denied your trade request", Color.GOLD) requestingCiv.addNotification("[${currentPlayerCiv.civName}] has denied your trade request", Color.GOLD)
worldScreen.shouldUpdate=true worldScreen.shouldUpdate=true
} }
addButton("How about something else...".tr()){ addButton("How about something else...".tr()){
currentPlayerCiv.tradeRequests.remove(tradeRequest) currentPlayerCiv.tradeRequests.remove(tradeRequest)
remove() close()
val diplomacyScreen= DiplomacyScreen() val diplomacyScreen= DiplomacyScreen()
val tradeTable = diplomacyScreen.setTrade(requestingCiv) val tradeTable = diplomacyScreen.setTrade(requestingCiv)

View File

@ -26,6 +26,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.WorldScreenBottomBar import com.unciv.ui.worldscreen.bottombar.WorldScreenBottomBar
import com.unciv.ui.worldscreen.optionstable.PopupTable
import com.unciv.ui.worldscreen.unit.UnitActionsTable import com.unciv.ui.worldscreen.unit.UnitActionsTable
import kotlin.concurrent.thread import kotlin.concurrent.thread
@ -99,6 +100,20 @@ class WorldScreen(val viewingCiv:CivilizationInfo) : CameraStageBaseScreen() {
tileMapHolder.setCenterPosition(tileToCenterOn,true) tileMapHolder.setCenterPosition(tileToCenterOn,true)
update() update()
if(gameInfo.gameParameters.isOnlineMultiplayer && !gameInfo.isUpToDate){
val loadingGamePopup = PopupTable(this)
loadingGamePopup.add("Loading latest game state...")
loadingGamePopup.open()
thread {
try{
// todo!!!
}
catch (ex:Exception){
loadingGamePopup.close()
}
}
}
} }
// This is private so that we will set the shouldUpdate to true instead. // This is private so that we will set the shouldUpdate to true instead.

View File

@ -6,7 +6,6 @@ import com.badlogic.gdx.scenes.scene2d.ui.Label
import com.badlogic.gdx.scenes.scene2d.ui.Table 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.UnCivGame
import com.unciv.models.gamebasics.tr import com.unciv.models.gamebasics.tr
import com.unciv.ui.utils.* import com.unciv.ui.utils.*
@ -25,6 +24,8 @@ open class PopupTable(val screen: CameraStageBaseScreen): Table(CameraStageBaseS
screen.stage.addActor(this) screen.stage.addActor(this)
} }
open fun close(){ remove() }
fun addGoodSizedLabel(text: String): Cell<Label> { fun addGoodSizedLabel(text: String): Cell<Label> {
val label = text.toLabel() val label = text.toLabel()
label.setWrap(true) label.setWrap(true)
@ -39,20 +40,3 @@ open class PopupTable(val screen: CameraStageBaseScreen): Table(CameraStageBaseS
} }
} }
class YesNoPopupTable(question:String, action:()->Unit,
screen: CameraStageBaseScreen = UnCivGame.Current.worldScreen) : PopupTable(screen){
init{
if(!screen.hasPopupOpen) {
screen.hasPopupOpen=true
add(question.toLabel()).colspan(2).row()
add(TextButton("No".tr(), skin).onClick { close() })
add(TextButton("Yes".tr(), skin).onClick { close(); action() })
open()
}
}
fun close(){
remove()
screen.hasPopupOpen=false
}
}

View File

@ -5,9 +5,9 @@ import com.unciv.UnCivGame
import com.unciv.logic.map.RoadStatus import com.unciv.logic.map.RoadStatus
import com.unciv.models.gamebasics.tr import com.unciv.models.gamebasics.tr
import com.unciv.ui.CivilopediaScreen import com.unciv.ui.CivilopediaScreen
import com.unciv.ui.newgamescreen.NewGameScreen
import com.unciv.ui.VictoryScreen import com.unciv.ui.VictoryScreen
import com.unciv.ui.mapeditor.MapEditorScreen import com.unciv.ui.mapeditor.MapEditorScreen
import com.unciv.ui.newgamescreen.NewGameScreen
import com.unciv.ui.pickerscreens.PolicyPickerScreen import com.unciv.ui.pickerscreens.PolicyPickerScreen
import com.unciv.ui.saves.LoadGameScreen import com.unciv.ui.saves.LoadGameScreen
import com.unciv.ui.saves.SaveGameScreen import com.unciv.ui.saves.SaveGameScreen
@ -65,7 +65,7 @@ class WorldScreenMenuTable(val worldScreen: WorldScreen) : PopupTable(worldScree
remove() remove()
} }
addButton("Close".tr()){ remove() } addButton("Close".tr()){ close() }
open() open()
} }
@ -83,7 +83,7 @@ class WorldScreenCommunityTable(val worldScreen: WorldScreen) : PopupTable(world
remove() remove()
} }
addButton("Close".tr()){ remove() } addButton("Close".tr()){ close() }
open() open()
} }

View File

@ -96,7 +96,7 @@ class WorldScreenOptionsTable(val worldScreen:WorldScreen) : PopupTable(worldScr
scrollPane.setScrollingDisabled(true,false) scrollPane.setScrollingDisabled(true,false)
add(scrollPane).maxHeight(screen.stage.height*0.6f).row() add(scrollPane).maxHeight(screen.stage.height*0.6f).row()
addButton("Close"){ remove() } addButton("Close"){ close() }
pack() // Needed to show the background. pack() // Needed to show the background.
center(UnCivGame.Current.worldScreen.stage) center(UnCivGame.Current.worldScreen.stage)

View File

@ -0,0 +1,26 @@
package com.unciv.ui.worldscreen.optionstable
import com.badlogic.gdx.scenes.scene2d.ui.TextButton
import com.unciv.UnCivGame
import com.unciv.models.gamebasics.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) : PopupTable(screen){
init{
if(!screen.hasPopupOpen) {
screen.hasPopupOpen=true
add(question.toLabel()).colspan(2).row()
add(TextButton("No".tr(), skin).onClick { close() })
add(TextButton("Yes".tr(), skin).onClick { close(); action() })
open()
}
}
override fun close(){
super.close()
screen.hasPopupOpen=false
}
}