mirror of
https://github.com/yairm210/Unciv.git
synced 2025-09-27 13:55:54 -04:00
Removed usages of global UncivGame.gameInfo, where more local usage is possible
This commit is contained in:
parent
4c1f5bb097
commit
d184a829a2
@ -133,9 +133,9 @@ class UncivGame(parameters: UncivGameParameters) : Game() {
|
||||
ImageGetter.setNewRuleset(gameInfo.ruleSet)
|
||||
Gdx.input.inputProcessor = null // Since we will set the world screen when we're ready,
|
||||
if (gameInfo.civilizations.count { it.playerType == PlayerType.Human } > 1 && !gameInfo.gameParameters.isOnlineMultiplayer)
|
||||
setScreen(PlayerReadyScreen(gameInfo.getPlayerToViewAs()))
|
||||
setScreen(PlayerReadyScreen(gameInfo, gameInfo.getPlayerToViewAs()))
|
||||
else {
|
||||
worldScreen = WorldScreen(gameInfo.getPlayerToViewAs())
|
||||
worldScreen = WorldScreen(gameInfo, gameInfo.getPlayerToViewAs())
|
||||
setWorldScreen()
|
||||
}
|
||||
}
|
||||
|
@ -7,6 +7,7 @@ import com.badlogic.gdx.scenes.scene2d.ui.Table
|
||||
import com.badlogic.gdx.scenes.scene2d.ui.TextField
|
||||
import com.badlogic.gdx.utils.Json
|
||||
import com.unciv.UncivGame
|
||||
import com.unciv.logic.GameInfo
|
||||
import com.unciv.logic.GameSaver
|
||||
import com.unciv.models.translations.tr
|
||||
import com.unciv.ui.pickerscreens.PickerScreen
|
||||
@ -16,7 +17,7 @@ import kotlin.concurrent.thread
|
||||
import com.unciv.ui.utils.AutoScrollPane as ScrollPane
|
||||
|
||||
|
||||
class SaveGameScreen : PickerScreen() {
|
||||
class SaveGameScreen(val gameInfo: GameInfo) : PickerScreen() {
|
||||
val gameNameTextField = TextField("", skin)
|
||||
val currentSaves = Table()
|
||||
|
||||
@ -29,7 +30,7 @@ class SaveGameScreen : PickerScreen() {
|
||||
topTable.add(ScrollPane(currentSaves)).height(stage.height * 2 / 3)
|
||||
|
||||
val newSave = Table()
|
||||
val defaultSaveName = game.gameInfo.currentPlayer + " - " + game.gameInfo.turns + " turns"
|
||||
val defaultSaveName = gameInfo.currentPlayer + " - " + gameInfo.turns + " turns"
|
||||
gameNameTextField.text = defaultSaveName
|
||||
|
||||
newSave.add("Saved game name".toLabel()).row()
|
||||
@ -37,7 +38,7 @@ class SaveGameScreen : PickerScreen() {
|
||||
|
||||
val copyJsonButton = "Copy to clipboard".toTextButton()
|
||||
copyJsonButton.onClick {
|
||||
val json = Json().toJson(game.gameInfo)
|
||||
val json = Json().toJson(gameInfo)
|
||||
val base64Gzip = Gzip.zip(json)
|
||||
Gdx.app.clipboard.contents = base64Gzip
|
||||
}
|
||||
@ -51,9 +52,9 @@ class SaveGameScreen : PickerScreen() {
|
||||
saveToCustomLocation.setText("Saving...".tr())
|
||||
saveToCustomLocation.disable()
|
||||
thread(name = "SaveGame") {
|
||||
GameSaver.saveGameToCustomLocation(UncivGame.Current.gameInfo, gameNameTextField.text) { e ->
|
||||
GameSaver.saveGameToCustomLocation(gameInfo, gameNameTextField.text) { e ->
|
||||
if (e == null) {
|
||||
Gdx.app.postRunnable { UncivGame.Current.setWorldScreen() }
|
||||
Gdx.app.postRunnable { game.setWorldScreen() }
|
||||
} else if (e !is CancellationException) {
|
||||
errorLabel.setText("Could not save game to custom location".tr())
|
||||
e.printStackTrace()
|
||||
@ -89,7 +90,7 @@ class SaveGameScreen : PickerScreen() {
|
||||
private fun saveGame() {
|
||||
rightSideButton.setText("Saving...".tr())
|
||||
thread(name = "SaveGame") {
|
||||
GameSaver.saveGame(UncivGame.Current.gameInfo, gameNameTextField.text) {
|
||||
GameSaver.saveGame(gameInfo, gameNameTextField.text) {
|
||||
Gdx.app.postRunnable {
|
||||
if (it != null) ToastPopup("Could not save game!", this)
|
||||
else UncivGame.Current.setWorldScreen()
|
||||
|
@ -54,7 +54,7 @@ class DiplomacyScreen(val viewingCiv:CivilizationInfo):CameraStageBaseScreen() {
|
||||
|
||||
private fun updateLeftSideTable() {
|
||||
leftSideTable.clear()
|
||||
for (civ in UncivGame.Current.gameInfo.civilizations
|
||||
for (civ in viewingCiv.gameInfo.civilizations
|
||||
.filterNot { it.isDefeated() || it == viewingCiv || it.isBarbarian() || it.isSpectator() }) {
|
||||
if (!viewingCiv.knows(civ)) continue
|
||||
|
||||
|
@ -16,9 +16,10 @@ import com.unciv.ui.utils.*
|
||||
import com.unciv.ui.worldscreen.WorldScreen
|
||||
|
||||
class VictoryScreen(val worldScreen: WorldScreen) : PickerScreen() {
|
||||
|
||||
|
||||
val gameInfo = worldScreen.gameInfo
|
||||
private val playerCivInfo = worldScreen.viewingCiv
|
||||
val victoryTypes = playerCivInfo.gameInfo.gameParameters.victoryTypes
|
||||
val victoryTypes = gameInfo.gameParameters.victoryTypes
|
||||
private val scientificVictoryEnabled = victoryTypes.contains(VictoryType.Scientific)
|
||||
private val culturalVictoryEnabled = victoryTypes.contains(VictoryType.Cultural)
|
||||
private val dominationVictoryEnabled = victoryTypes.contains(VictoryType.Domination)
|
||||
@ -27,7 +28,7 @@ class VictoryScreen(val worldScreen: WorldScreen) : PickerScreen() {
|
||||
private val contentsTable = Table()
|
||||
|
||||
init {
|
||||
val difficultyLabel = ("{Difficulty}: {${worldScreen.gameInfo.difficulty}}").toLabel()
|
||||
val difficultyLabel = ("{Difficulty}: {${gameInfo.difficulty}}").toLabel()
|
||||
difficultyLabel.setPosition(10f, stage.height - 10, Align.topLeft)
|
||||
stage.addActor(difficultyLabel)
|
||||
|
||||
@ -61,7 +62,7 @@ class VictoryScreen(val worldScreen: WorldScreen) : PickerScreen() {
|
||||
VictoryType.Neutral -> wonOrLost("You have won!")
|
||||
}
|
||||
}
|
||||
for (civ in game.gameInfo.civilizations.filter { it.isMajorCiv() && it != playerCivInfo }) {
|
||||
for (civ in gameInfo.civilizations.filter { it.isMajorCiv() && it != playerCivInfo }) {
|
||||
val civVictoryType = civ.victoryManager.hasWonVictoryType()
|
||||
if (civVictoryType != null) {
|
||||
someoneHasWon = true
|
||||
@ -100,12 +101,12 @@ class VictoryScreen(val worldScreen: WorldScreen) : PickerScreen() {
|
||||
rightSideButton.isVisible = true
|
||||
rightSideButton.enable()
|
||||
rightSideButton.onClick {
|
||||
game.setScreen(NewGameScreen(this, GameSetupInfo(worldScreen.gameInfo)))
|
||||
game.setScreen(NewGameScreen(this, GameSetupInfo(gameInfo)))
|
||||
}
|
||||
|
||||
closeButton.setText("One more turn...!".tr())
|
||||
closeButton.onClick {
|
||||
playerCivInfo.gameInfo.oneMoreTurnMode = true
|
||||
gameInfo.oneMoreTurnMode = true
|
||||
game.setWorldScreen()
|
||||
}
|
||||
}
|
||||
@ -177,7 +178,7 @@ class VictoryScreen(val worldScreen: WorldScreen) : PickerScreen() {
|
||||
|
||||
|
||||
private fun setGlobalVictoryTable() {
|
||||
val majorCivs = game.gameInfo.civilizations.filter { it.isMajorCiv() }
|
||||
val majorCivs = gameInfo.civilizations.filter { it.isMajorCiv() }
|
||||
val globalVictoryTable = Table().apply { defaults().pad(10f) }
|
||||
|
||||
if (scientificVictoryEnabled) globalVictoryTable.add(getGlobalScientificVictoryColumn(majorCivs))
|
||||
@ -241,7 +242,7 @@ class VictoryScreen(val worldScreen: WorldScreen) : PickerScreen() {
|
||||
}
|
||||
|
||||
private fun setCivRankingsTable() {
|
||||
val majorCivs = game.gameInfo.civilizations.filter { it.isMajorCiv() }
|
||||
val majorCivs = gameInfo.civilizations.filter { it.isMajorCiv() }
|
||||
val civRankingsTable = Table().apply { defaults().pad(5f) }
|
||||
|
||||
for (category in RankingType.values()) {
|
||||
|
@ -4,13 +4,14 @@ import com.badlogic.gdx.Gdx
|
||||
import com.badlogic.gdx.scenes.scene2d.Touchable
|
||||
import com.badlogic.gdx.scenes.scene2d.ui.Table
|
||||
import com.unciv.UncivGame
|
||||
import com.unciv.logic.GameInfo
|
||||
import com.unciv.logic.civilization.CivilizationInfo
|
||||
import com.unciv.ui.utils.CameraStageBaseScreen
|
||||
import com.unciv.ui.utils.ImageGetter
|
||||
import com.unciv.ui.utils.onClick
|
||||
import com.unciv.ui.utils.toLabel
|
||||
|
||||
class PlayerReadyScreen(currentPlayerCiv: CivilizationInfo) : CameraStageBaseScreen(){
|
||||
class PlayerReadyScreen(gameInfo: GameInfo, currentPlayerCiv: CivilizationInfo) : CameraStageBaseScreen(){
|
||||
init {
|
||||
val table= Table()
|
||||
table.touchable= Touchable.enabled
|
||||
@ -20,7 +21,7 @@ class PlayerReadyScreen(currentPlayerCiv: CivilizationInfo) : CameraStageBaseScr
|
||||
|
||||
table.onClick {
|
||||
Gdx.app.postRunnable { // To avoid ANRs on Android when the creation of the worldscreen takes more than 500ms
|
||||
UncivGame.Current.worldScreen = WorldScreen(currentPlayerCiv)
|
||||
UncivGame.Current.worldScreen = WorldScreen(gameInfo, currentPlayerCiv)
|
||||
UncivGame.Current.setWorldScreen()
|
||||
}
|
||||
}
|
||||
|
@ -40,8 +40,7 @@ import java.util.*
|
||||
import kotlin.concurrent.thread
|
||||
import kotlin.concurrent.timer
|
||||
|
||||
class WorldScreen(val viewingCiv:CivilizationInfo) : CameraStageBaseScreen() {
|
||||
val gameInfo = game.gameInfo
|
||||
class WorldScreen(val gameInfo: GameInfo, val viewingCiv:CivilizationInfo) : CameraStageBaseScreen() {
|
||||
|
||||
var isPlayersTurn = viewingCiv == gameInfo.currentPlayerCiv // todo this should be updated when passing turns
|
||||
var selectedCiv = viewingCiv // Selected civilization, used in spectator and replay mode, equals viewingCiv in ordinary games
|
||||
@ -485,7 +484,7 @@ class WorldScreen(val viewingCiv:CivilizationInfo) : CameraStageBaseScreen() {
|
||||
fun createNewWorldScreen(gameInfo:GameInfo) {
|
||||
|
||||
game.gameInfo = gameInfo
|
||||
val newWorldScreen = WorldScreen(gameInfo.getPlayerToViewAs())
|
||||
val newWorldScreen = WorldScreen(gameInfo, gameInfo.getPlayerToViewAs())
|
||||
newWorldScreen.mapHolder.scrollX = mapHolder.scrollX
|
||||
newWorldScreen.mapHolder.scrollY = mapHolder.scrollY
|
||||
newWorldScreen.mapHolder.scaleX = mapHolder.scaleX
|
||||
@ -541,7 +540,7 @@ class WorldScreen(val viewingCiv:CivilizationInfo) : CameraStageBaseScreen() {
|
||||
|
||||
if (gameInfoClone.currentPlayerCiv.civName != viewingCiv.civName
|
||||
&& !gameInfoClone.gameParameters.isOnlineMultiplayer)
|
||||
game.setScreen(PlayerReadyScreen(gameInfoClone.getCurrentPlayerCivilization()))
|
||||
game.setScreen(PlayerReadyScreen(gameInfoClone, gameInfoClone.getCurrentPlayerCivilization()))
|
||||
else {
|
||||
createNewWorldScreen(gameInfoClone)
|
||||
}
|
||||
|
@ -68,7 +68,7 @@ class OptionsPopup(val previousScreen:CameraStageBaseScreen) : Popup(previousScr
|
||||
private fun reloadWorldAndOptions() {
|
||||
settings.save()
|
||||
if (previousScreen is WorldScreen) {
|
||||
previousScreen.game.worldScreen = WorldScreen(previousScreen.viewingCiv)
|
||||
previousScreen.game.worldScreen = WorldScreen(previousScreen.gameInfo, previousScreen.viewingCiv)
|
||||
previousScreen.game.setWorldScreen()
|
||||
} else if (previousScreen is MainMenuScreen) {
|
||||
previousScreen.game.setScreen(MainMenuScreen())
|
||||
|
@ -26,7 +26,7 @@ class WorldScreenMenuPopup(val worldScreen: WorldScreen) : Popup(worldScreen) {
|
||||
init {
|
||||
addMenuButton("Main menu") { worldScreen.game.setScreen(MainMenuScreen()) }
|
||||
addMenuButton("Civilopedia") { worldScreen.game.setScreen(CivilopediaScreen(worldScreen.gameInfo.ruleSet)) }
|
||||
addMenuButton("Save game") { worldScreen.game.setScreen(SaveGameScreen()) }
|
||||
addMenuButton("Save game") { worldScreen.game.setScreen(SaveGameScreen(worldScreen.gameInfo)) }
|
||||
addMenuButton("Load game") { worldScreen.game.setScreen(LoadGameScreen(worldScreen)) }
|
||||
|
||||
addMenuButton("Start new game") {
|
||||
|
Loading…
x
Reference in New Issue
Block a user