mirror of
https://github.com/yairm210/Unciv.git
synced 2025-09-28 14:24:43 -04:00
Added helper class GameSetupInfo - this will help us when setting up multiplayer games for transferring data from/to the server
This commit is contained in:
parent
b64391d767
commit
c756014fec
@ -20,6 +20,7 @@ import com.unciv.ui.mapeditor.EditorMapHolder
|
|||||||
import com.unciv.ui.mapeditor.LoadMapScreen
|
import com.unciv.ui.mapeditor.LoadMapScreen
|
||||||
import com.unciv.ui.mapeditor.MapEditorScreen
|
import com.unciv.ui.mapeditor.MapEditorScreen
|
||||||
import com.unciv.ui.mapeditor.NewMapScreen
|
import com.unciv.ui.mapeditor.NewMapScreen
|
||||||
|
import com.unciv.ui.newgamescreen.GameSetupInfo
|
||||||
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.utils.*
|
import com.unciv.ui.utils.*
|
||||||
@ -75,7 +76,7 @@ class MainMenuScreen: CameraStageBaseScreen() {
|
|||||||
table.add(resumeTable).row()
|
table.add(resumeTable).row()
|
||||||
}
|
}
|
||||||
|
|
||||||
val quickstartTable = getTableBlock("Quickstart","OtherIcons/Quickstart") { startNewGame() }
|
val quickstartTable = getTableBlock("Quickstart","OtherIcons/Quickstart") { QuickstartNewGame() }
|
||||||
table.add(quickstartTable).row()
|
table.add(quickstartTable).row()
|
||||||
|
|
||||||
val newGameButton = getTableBlock("Start new game","OtherIcons/New") {
|
val newGameButton = getTableBlock("Start new game","OtherIcons/New") {
|
||||||
@ -148,8 +149,8 @@ class MainMenuScreen: CameraStageBaseScreen() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun startNewGame() {
|
private fun QuickstartNewGame() {
|
||||||
val newGame = GameStarter.startNewGame(GameParameters().apply { difficulty = "Chieftain" }, MapParameters())
|
val newGame = GameStarter.startNewGame(GameSetupInfo().apply { gameParameters.difficulty = "Chieftain" })
|
||||||
game.loadGame(newGame)
|
game.loadGame(newGame)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -367,5 +367,6 @@ class GameInfo {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -7,25 +7,26 @@ import com.unciv.logic.map.*
|
|||||||
import com.unciv.models.metadata.GameParameters
|
import com.unciv.models.metadata.GameParameters
|
||||||
import com.unciv.models.ruleset.Ruleset
|
import com.unciv.models.ruleset.Ruleset
|
||||||
import com.unciv.models.ruleset.RulesetCache
|
import com.unciv.models.ruleset.RulesetCache
|
||||||
|
import com.unciv.ui.newgamescreen.GameSetupInfo
|
||||||
import java.util.*
|
import java.util.*
|
||||||
import kotlin.collections.ArrayList
|
import kotlin.collections.ArrayList
|
||||||
import kotlin.math.max
|
import kotlin.math.max
|
||||||
|
|
||||||
object GameStarter {
|
object GameStarter {
|
||||||
|
|
||||||
fun startNewGame(newGameParameters: GameParameters, mapParameters: MapParameters): GameInfo {
|
fun startNewGame(gameSetupInfo: GameSetupInfo): GameInfo {
|
||||||
val gameInfo = GameInfo()
|
val gameInfo = GameInfo()
|
||||||
|
|
||||||
gameInfo.gameParameters = newGameParameters
|
gameInfo.gameParameters = gameSetupInfo.gameParameters
|
||||||
val ruleset = RulesetCache.getComplexRuleset(newGameParameters.mods)
|
val ruleset = RulesetCache.getComplexRuleset(gameInfo.gameParameters.mods)
|
||||||
|
|
||||||
if (mapParameters.name != "")
|
if (gameSetupInfo.mapParameters.name != "")
|
||||||
gameInfo.tileMap = MapSaver.loadMap(mapParameters.name)
|
gameInfo.tileMap = MapSaver.loadMap(gameSetupInfo.mapParameters.name)
|
||||||
else gameInfo.tileMap = MapGenerator(ruleset).generateMap(mapParameters)
|
else gameInfo.tileMap = MapGenerator(ruleset).generateMap(gameSetupInfo.mapParameters)
|
||||||
gameInfo.tileMap.mapParameters = mapParameters
|
gameInfo.tileMap.mapParameters = gameSetupInfo.mapParameters
|
||||||
|
|
||||||
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
|
||||||
addCivilizations(newGameParameters, gameInfo, ruleset) // this is before gameInfo.setTransients, so gameInfo doesn't yet have the gameBasics
|
addCivilizations(gameSetupInfo.gameParameters, gameInfo, ruleset) // this is before gameInfo.setTransients, so gameInfo doesn't yet have the gameBasics
|
||||||
|
|
||||||
for(tile in gameInfo.tileMap.values)
|
for(tile in gameInfo.tileMap.values)
|
||||||
for(unit in tile.getUnits())
|
for(unit in tile.getUnits())
|
||||||
@ -36,7 +37,7 @@ object GameStarter {
|
|||||||
|
|
||||||
gameInfo.tileMap.setTransients(ruleset) // if we're starting from a map with preplaced units, they need the civs to exist first
|
gameInfo.tileMap.setTransients(ruleset) // if we're starting from a map with preplaced units, they need the civs to exist first
|
||||||
|
|
||||||
gameInfo.difficulty = newGameParameters.difficulty
|
gameInfo.difficulty = gameSetupInfo.gameParameters.difficulty
|
||||||
|
|
||||||
|
|
||||||
gameInfo.setTransients() // needs to be before placeBarbarianUnit because it depends on the tilemap having its gameinfo set
|
gameInfo.setTransients() // needs to be before placeBarbarianUnit because it depends on the tilemap having its gameinfo set
|
||||||
@ -49,7 +50,7 @@ object GameStarter {
|
|||||||
civInfo.tech.addTechnology(tech)
|
civInfo.tech.addTechnology(tech)
|
||||||
|
|
||||||
for (tech in ruleset.technologies.values
|
for (tech in ruleset.technologies.values
|
||||||
.filter { ruleset.getEraNumber(it.era()) < ruleset.getEraNumber(newGameParameters.startingEra) })
|
.filter { ruleset.getEraNumber(it.era()) < ruleset.getEraNumber(gameSetupInfo.gameParameters.startingEra) })
|
||||||
if (!civInfo.tech.isResearched(tech.name))
|
if (!civInfo.tech.isResearched(tech.name))
|
||||||
civInfo.tech.addTechnology(tech.name)
|
civInfo.tech.addTechnology(tech.name)
|
||||||
|
|
||||||
|
@ -21,17 +21,22 @@ import com.unciv.ui.worldscreen.mainmenu.OnlineMultiplayer
|
|||||||
import java.util.*
|
import java.util.*
|
||||||
import kotlin.concurrent.thread
|
import kotlin.concurrent.thread
|
||||||
|
|
||||||
class NewGameScreen(previousScreen:CameraStageBaseScreen, currentGame:GameInfo?=null): PickerScreen(){
|
|
||||||
|
|
||||||
val newGameParameters= currentGame?.gameParameters?.clone() ?: GameParameters()
|
class GameSetupInfo(var gameId:String, var gameParameters: GameParameters, var mapParameters: MapParameters) {
|
||||||
val mapParameters = currentGame?.tileMap?.mapParameters ?: MapParameters()
|
constructor() : this("", GameParameters(), MapParameters())
|
||||||
val ruleset = RulesetCache.getComplexRuleset(newGameParameters.mods)
|
constructor(gameInfo: GameInfo) : this("", gameInfo.gameParameters.clone(), gameInfo.tileMap.mapParameters)
|
||||||
|
}
|
||||||
|
|
||||||
|
class NewGameScreen(previousScreen:CameraStageBaseScreen, _gameSetupInfo: GameSetupInfo?=null): PickerScreen(){
|
||||||
|
|
||||||
|
var gameSetupInfo:GameSetupInfo= _gameSetupInfo ?: GameSetupInfo()
|
||||||
|
val ruleset = RulesetCache.getComplexRuleset(gameSetupInfo.gameParameters.mods)
|
||||||
|
|
||||||
init {
|
init {
|
||||||
setDefaultCloseAction(previousScreen)
|
setDefaultCloseAction(previousScreen)
|
||||||
scrollPane.setScrollingDisabled(true,true)
|
scrollPane.setScrollingDisabled(true,true)
|
||||||
|
|
||||||
val playerPickerTable = PlayerPickerTable(this, newGameParameters)
|
val playerPickerTable = PlayerPickerTable(this, gameSetupInfo.gameParameters)
|
||||||
val newGameScreenOptionsTable = NewGameScreenOptionsTable(this) { desiredCiv: String -> playerPickerTable.update(desiredCiv) }
|
val newGameScreenOptionsTable = NewGameScreenOptionsTable(this) { desiredCiv: String -> playerPickerTable.update(desiredCiv) }
|
||||||
topTable.add(ScrollPane(newGameScreenOptionsTable).apply{setOverscroll(false,false)}).height(topTable.parent.height)
|
topTable.add(ScrollPane(newGameScreenOptionsTable).apply{setOverscroll(false,false)}).height(topTable.parent.height)
|
||||||
topTable.add(playerPickerTable).height(topTable.parent.height)
|
topTable.add(playerPickerTable).height(topTable.parent.height)
|
||||||
@ -41,7 +46,7 @@ class NewGameScreen(previousScreen:CameraStageBaseScreen, currentGame:GameInfo?=
|
|||||||
rightSideButton.enable()
|
rightSideButton.enable()
|
||||||
rightSideButton.setText("Start game!".tr())
|
rightSideButton.setText("Start game!".tr())
|
||||||
rightSideButton.onClick {
|
rightSideButton.onClick {
|
||||||
if (newGameParameters.players.none { it.playerType == PlayerType.Human }) {
|
if (gameSetupInfo.gameParameters.players.none { it.playerType == PlayerType.Human }) {
|
||||||
val noHumanPlayersPopup = Popup(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()
|
||||||
@ -49,8 +54,8 @@ class NewGameScreen(previousScreen:CameraStageBaseScreen, currentGame:GameInfo?=
|
|||||||
return@onClick
|
return@onClick
|
||||||
}
|
}
|
||||||
|
|
||||||
if (newGameParameters.isOnlineMultiplayer) {
|
if (gameSetupInfo.gameParameters.isOnlineMultiplayer) {
|
||||||
for (player in newGameParameters.players.filter { it.playerType == PlayerType.Human }) {
|
for (player in gameSetupInfo.gameParameters.players.filter { it.playerType == PlayerType.Human }) {
|
||||||
try {
|
try {
|
||||||
UUID.fromString(IdChecker.checkAndReturnPlayerUuid(player.playerId))
|
UUID.fromString(IdChecker.checkAndReturnPlayerUuid(player.playerId))
|
||||||
} catch (ex: Exception) {
|
} catch (ex: Exception) {
|
||||||
@ -76,8 +81,8 @@ class NewGameScreen(previousScreen:CameraStageBaseScreen, currentGame:GameInfo?=
|
|||||||
|
|
||||||
private fun newGameThread() {
|
private fun newGameThread() {
|
||||||
try {
|
try {
|
||||||
newGame = GameStarter.startNewGame(newGameParameters, mapParameters)
|
newGame = GameStarter.startNewGame(gameSetupInfo)
|
||||||
if (newGameParameters.isOnlineMultiplayer) {
|
if (gameSetupInfo.gameParameters.isOnlineMultiplayer) {
|
||||||
newGame!!.isUpToDate = true // So we don't try to download it from dropbox the second after we upload it - the file is not yet ready for loading!
|
newGame!!.isUpToDate = true // So we don't try to download it from dropbox the second after we upload it - the file is not yet ready for loading!
|
||||||
try {
|
try {
|
||||||
OnlineMultiplayer().tryUploadGame(newGame!!)
|
OnlineMultiplayer().tryUploadGame(newGame!!)
|
||||||
|
@ -17,8 +17,8 @@ import com.unciv.ui.utils.toLabel
|
|||||||
|
|
||||||
class NewGameScreenOptionsTable(val newGameScreen: NewGameScreen, val updatePlayerPickerTable:(desiredCiv:String)->Unit)
|
class NewGameScreenOptionsTable(val newGameScreen: NewGameScreen, val updatePlayerPickerTable:(desiredCiv:String)->Unit)
|
||||||
: Table(CameraStageBaseScreen.skin) {
|
: Table(CameraStageBaseScreen.skin) {
|
||||||
val newGameParameters = newGameScreen.newGameParameters
|
val newGameParameters = newGameScreen.gameSetupInfo.gameParameters
|
||||||
val mapParameters = newGameScreen.mapParameters
|
val mapParameters = newGameScreen.gameSetupInfo.mapParameters
|
||||||
val ruleset = newGameScreen.ruleset
|
val ruleset = newGameScreen.ruleset
|
||||||
|
|
||||||
private var mapTypeSpecificTable = Table()
|
private var mapTypeSpecificTable = Table()
|
||||||
|
@ -7,6 +7,7 @@ import com.unciv.logic.civilization.CivilizationInfo
|
|||||||
import com.unciv.models.ruleset.VictoryType
|
import com.unciv.models.ruleset.VictoryType
|
||||||
import com.unciv.models.translations.tr
|
import com.unciv.models.translations.tr
|
||||||
import com.unciv.ui.EmpireOverviewScreen
|
import com.unciv.ui.EmpireOverviewScreen
|
||||||
|
import com.unciv.ui.newgamescreen.GameSetupInfo
|
||||||
import com.unciv.ui.newgamescreen.NewGameScreen
|
import com.unciv.ui.newgamescreen.NewGameScreen
|
||||||
import com.unciv.ui.pickerscreens.PickerScreen
|
import com.unciv.ui.pickerscreens.PickerScreen
|
||||||
import com.unciv.ui.utils.*
|
import com.unciv.ui.utils.*
|
||||||
@ -85,7 +86,7 @@ class VictoryScreen(val worldScreen: WorldScreen) : PickerScreen() {
|
|||||||
rightSideButton.isVisible = true
|
rightSideButton.isVisible = true
|
||||||
rightSideButton.enable()
|
rightSideButton.enable()
|
||||||
rightSideButton.onClick {
|
rightSideButton.onClick {
|
||||||
game.setScreen(NewGameScreen(this, worldScreen.gameInfo))
|
game.setScreen(NewGameScreen(this, GameSetupInfo(worldScreen.gameInfo)))
|
||||||
}
|
}
|
||||||
|
|
||||||
closeButton.setText("One more turn...!".tr())
|
closeButton.setText("One more turn...!".tr())
|
||||||
|
@ -5,6 +5,7 @@ import com.unciv.Constants
|
|||||||
import com.unciv.MainMenuScreen
|
import com.unciv.MainMenuScreen
|
||||||
import com.unciv.models.translations.tr
|
import com.unciv.models.translations.tr
|
||||||
import com.unciv.ui.CivilopediaScreen
|
import com.unciv.ui.CivilopediaScreen
|
||||||
|
import com.unciv.ui.newgamescreen.GameSetupInfo
|
||||||
import com.unciv.ui.newgamescreen.NewGameScreen
|
import com.unciv.ui.newgamescreen.NewGameScreen
|
||||||
import com.unciv.ui.saves.SaveGameScreen
|
import com.unciv.ui.saves.SaveGameScreen
|
||||||
import com.unciv.ui.utils.Popup
|
import com.unciv.ui.utils.Popup
|
||||||
@ -37,7 +38,7 @@ class WorldScreenMenuPopup(val worldScreen: WorldScreen) : Popup(worldScreen) {
|
|||||||
|
|
||||||
|
|
||||||
addSquareButton("Start new game".tr()){
|
addSquareButton("Start new game".tr()){
|
||||||
worldScreen.game.setScreen(NewGameScreen(worldScreen, worldScreen.gameInfo))
|
worldScreen.game.setScreen(NewGameScreen(worldScreen, GameSetupInfo(worldScreen.gameInfo)))
|
||||||
close()
|
close()
|
||||||
}.size(width,height)
|
}.size(width,height)
|
||||||
addSeparator()
|
addSeparator()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user