Removed may references to UncivGame.Current

This commit is contained in:
Yair Morgenstern
2020-04-20 23:35:38 +03:00
parent eaf7c0a150
commit bb3a84fbe7
8 changed files with 64 additions and 65 deletions

View File

@ -28,11 +28,11 @@ class EmpireOverviewScreen(private val viewingPlayer:CivilizationInfo, private v
private val centerTable = Table().apply { defaults().pad(20f) } private val centerTable = Table().apply { defaults().pad(20f) }
init { init {
onBackButtonClicked { UncivGame.Current.setWorldScreen() } onBackButtonClicked { game.setWorldScreen() }
val clicks = HashMap<String,() -> Unit>() val clicks = HashMap<String,() -> Unit>()
val closeButton = Constants.close.toTextButton() val closeButton = Constants.close.toTextButton()
closeButton.onClick { UncivGame.Current.setWorldScreen() } closeButton.onClick { game.setWorldScreen() }
closeButton.y = stage.height - closeButton.height - 5 closeButton.y = stage.height - closeButton.height - 5
topTable.add(closeButton) topTable.add(closeButton)
@ -351,7 +351,7 @@ class EmpireOverviewScreen(private val viewingPlayer:CivilizationInfo, private v
for (city in cityList) { for (city in cityList) {
val button = Button(city.name.toLabel(), skin) val button = Button(city.name.toLabel(), skin)
button.onClick { button.onClick {
UncivGame.Current.setScreen(CityScreen(city)) game.setScreen(CityScreen(city))
} }
citiesTable.add(button) citiesTable.add(button)
citiesTable.add(city.cityConstructions.getCityProductionTextForCityButton()).actor!!.setAlignment(Align.left) citiesTable.add(city.cityConstructions.getCityProductionTextForCityButton()).actor!!.setAlignment(Align.left)
@ -385,8 +385,8 @@ class EmpireOverviewScreen(private val viewingPlayer:CivilizationInfo, private v
val baseUnit = unit.baseUnit() val baseUnit = unit.baseUnit()
val button = unit.name.toTextButton() val button = unit.name.toTextButton()
button.onClick { button.onClick {
UncivGame.Current.setWorldScreen() game.setWorldScreen()
UncivGame.Current.worldScreen.mapHolder.setCenterPosition(unit.currentTile.position) game.worldScreen.mapHolder.setCenterPosition(unit.currentTile.position)
} }
table.add(button).left() table.add(button).left()
val mapUnitAction = unit.mapUnitAction val mapUnitAction = unit.mapUnitAction
@ -404,7 +404,7 @@ class EmpireOverviewScreen(private val viewingPlayer:CivilizationInfo, private v
if (unit.canUpgrade()) promotionsTable.add(ImageGetter.getUnitIcon(baseUnit.upgradesTo!!, Color.GREEN)).size(28f).padLeft(8f) if (unit.canUpgrade()) promotionsTable.add(ImageGetter.getUnitIcon(baseUnit.upgradesTo!!, Color.GREEN)).size(28f).padLeft(8f)
promotionsTable.onClick { promotionsTable.onClick {
if (unit.promotions.canBePromoted() || unit.promotions.promotions.isNotEmpty()) { if (unit.promotions.canBePromoted() || unit.promotions.promotions.isNotEmpty()) {
UncivGame.Current.setScreen(PromotionPickerScreen(unit)) game.setScreen(PromotionPickerScreen(unit))
} }
} }
table.add(promotionsTable) table.add(promotionsTable)
@ -611,7 +611,7 @@ class EmpireOverviewScreen(private val viewingPlayer:CivilizationInfo, private v
civGroup.add(ImageGetter.getImage("OtherIcons/DisbandUnit")).size(30f) civGroup.add(ImageGetter.getImage("OtherIcons/DisbandUnit")).size(30f)
backgroundColor = Color.LIGHT_GRAY backgroundColor = Color.LIGHT_GRAY
labelColor = Color.BLACK labelColor = Color.BLACK
} else if (currentPlayer==civ || UncivGame.Current.viewEntireMapForDebug } else if (currentPlayer==civ // game.viewEntireMapForDebug
|| currentPlayer.knows(civ) || currentPlayer.isDefeated() || currentPlayer.victoryManager.hasWon()) { || currentPlayer.knows(civ) || currentPlayer.isDefeated() || currentPlayer.victoryManager.hasWon()) {
civGroup.add(ImageGetter.getNationIndicator(civ.nation, 30f)) civGroup.add(ImageGetter.getNationIndicator(civ.nation, 30f))
backgroundColor = civ.nation.getOuterColor() backgroundColor = civ.nation.getOuterColor()

View File

@ -15,7 +15,7 @@ import com.unciv.ui.worldscreen.mainmenu.OnlineMultiplayer
import java.util.* import java.util.*
import kotlin.concurrent.thread import kotlin.concurrent.thread
class MultiplayerScreen() : PickerScreen() { class MultiplayerScreen(val uncivGame: UncivGame) : PickerScreen() {
private lateinit var selectedGame: GameInfo private lateinit var selectedGame: GameInfo
private lateinit var selectedGameName: String private lateinit var selectedGameName: String
@ -77,7 +77,7 @@ class MultiplayerScreen() : PickerScreen() {
//rightTable Setup //rightTable Setup
copyUserIdButton.onClick { copyUserIdButton.onClick {
Gdx.app.clipboard.contents = UncivGame.Current.settings.userId Gdx.app.clipboard.contents = uncivGame.settings.userId
ResponsePopup("UserID copied to clipboard".tr(), this) ResponsePopup("UserID copied to clipboard".tr(), this)
} }
rightSideTable.add(copyUserIdButton).pad(10f).padBottom(30f).row() rightSideTable.add(copyUserIdButton).pad(10f).padBottom(30f).row()
@ -89,14 +89,14 @@ class MultiplayerScreen() : PickerScreen() {
rightSideTable.add(copyGameIdButton).pad(10f).row() rightSideTable.add(copyGameIdButton).pad(10f).row()
editButton.onClick { editButton.onClick {
UncivGame.Current.setScreen(EditMultiplayerGameInfoScreen(selectedGame, selectedGameName, this)) uncivGame.setScreen(EditMultiplayerGameInfoScreen(selectedGame, selectedGameName, this))
//game must be unselected in case the game gets deleted inside the EditScreen //game must be unselected in case the game gets deleted inside the EditScreen
unselectGame() unselectGame()
} }
rightSideTable.add(editButton).pad(10f).row() rightSideTable.add(editButton).pad(10f).row()
addGameButton.onClick { addGameButton.onClick {
UncivGame.Current.setScreen(AddMultiplayerGameScreen(this)) uncivGame.setScreen(AddMultiplayerGameScreen(this))
} }
rightSideTable.add(addGameButton).pad(10f).padBottom(30f).row() rightSideTable.add(addGameButton).pad(10f).padBottom(30f).row()
@ -161,7 +161,7 @@ class MultiplayerScreen() : PickerScreen() {
//the game will be downloaded opon joining it anyway //the game will be downloaded opon joining it anyway
private fun joinMultiplaerGame(){ private fun joinMultiplaerGame(){
try { try {
UncivGame.Current.loadGame(selectedGame) uncivGame.loadGame(selectedGame)
} catch (ex: Exception) { } catch (ex: Exception) {
val errorPopup = Popup(this) val errorPopup = Popup(this)
errorPopup.addGoodSizedLabel("Could not download game!".tr()) errorPopup.addGoodSizedLabel("Could not download game!".tr())
@ -267,7 +267,7 @@ class MultiplayerScreen() : PickerScreen() {
//Adds a Button to add the currently running game to multiplayerGameList //Adds a Button to add the currently running game to multiplayerGameList
private fun addCurrentGameButton(){ private fun addCurrentGameButton(){
val currentlyRunningGame = UncivGame.Current.gameInfo val currentlyRunningGame = uncivGame.gameInfo
if (!currentlyRunningGame.gameParameters.isOnlineMultiplayer || gameIsAlreadySavedAsMultiplayer(currentlyRunningGame.gameId)) if (!currentlyRunningGame.gameParameters.isOnlineMultiplayer || gameIsAlreadySavedAsMultiplayer(currentlyRunningGame.gameId))
return return
@ -301,7 +301,7 @@ class MultiplayerScreen() : PickerScreen() {
//check if its the users turn //check if its the users turn
private fun isUsersTurn(game: GameInfo) : Boolean{ private fun isUsersTurn(game: GameInfo) : Boolean{
return (game.currentPlayerCiv.playerId == UncivGame.Current.settings.userId) return (game.currentPlayerCiv.playerId == uncivGame.settings.userId)
} }
fun removeFromList(gameId: String){ fun removeFromList(gameId: String){
@ -328,7 +328,7 @@ class EditMultiplayerGameInfoScreen(game: GameInfo, gameName: String, backScreen
askPopup.addButton("Yes"){ askPopup.addButton("Yes"){
try { try {
GameSaver.deleteSave(gameName, true) GameSaver.deleteSave(gameName, true)
UncivGame.Current.setScreen(backScreen) backScreen.uncivGame.setScreen(backScreen)
backScreen.reloadGameListUI() backScreen.reloadGameListUI()
}catch (ex: Exception) { }catch (ex: Exception) {
askPopup.close() askPopup.close()
@ -346,7 +346,7 @@ class EditMultiplayerGameInfoScreen(game: GameInfo, gameName: String, backScreen
//CloseButton Setup //CloseButton Setup
closeButton.setText("Back".tr()) closeButton.setText("Back".tr())
closeButton.onClick { closeButton.onClick {
UncivGame.Current.setScreen(backScreen) backScreen.uncivGame.setScreen(backScreen)
} }
//RightSideButton Setup //RightSideButton Setup
@ -359,7 +359,7 @@ class EditMultiplayerGameInfoScreen(game: GameInfo, gameName: String, backScreen
//using addMultiplayerGame will download the game from Dropbox so the descriptionLabel displays the right things //using addMultiplayerGame will download the game from Dropbox so the descriptionLabel displays the right things
backScreen.addMultiplayerGame(game.gameId, textField.text) backScreen.addMultiplayerGame(game.gameId, textField.text)
GameSaver.deleteSave(gameName, true) GameSaver.deleteSave(gameName, true)
UncivGame.Current.setScreen(backScreen) backScreen.uncivGame.setScreen(backScreen)
backScreen.reloadGameListUI() backScreen.reloadGameListUI()
}catch (ex: Exception) { }catch (ex: Exception) {
val errorPopup = Popup(this) val errorPopup = Popup(this)
@ -393,7 +393,7 @@ class AddMultiplayerGameScreen(backScreen: MultiplayerScreen) : PickerScreen(){
//CloseButton Setup //CloseButton Setup
closeButton.setText("Back".tr()) closeButton.setText("Back".tr())
closeButton.onClick { closeButton.onClick {
UncivGame.Current.setScreen(backScreen) backScreen.uncivGame.setScreen(backScreen)
} }
//RightSideButton Setup //RightSideButton Setup
@ -408,7 +408,7 @@ class AddMultiplayerGameScreen(backScreen: MultiplayerScreen) : PickerScreen(){
} }
backScreen.addMultiplayerGame(gameIDTextField.text.trim(), gameNameTextField.text.trim()) backScreen.addMultiplayerGame(gameIDTextField.text.trim(), gameNameTextField.text.trim())
UncivGame.Current.setScreen(backScreen) backScreen.uncivGame.setScreen(backScreen)
} }
} }
} }

View File

@ -7,10 +7,8 @@ import com.badlogic.gdx.scenes.scene2d.Group
import com.badlogic.gdx.scenes.scene2d.Touchable import com.badlogic.gdx.scenes.scene2d.Touchable
import com.badlogic.gdx.scenes.scene2d.actions.Actions import com.badlogic.gdx.scenes.scene2d.actions.Actions
import com.badlogic.gdx.scenes.scene2d.ui.Label import com.badlogic.gdx.scenes.scene2d.ui.Label
import com.badlogic.gdx.scenes.scene2d.ui.Skin
import com.badlogic.gdx.scenes.scene2d.ui.Table import com.badlogic.gdx.scenes.scene2d.ui.Table
import com.badlogic.gdx.utils.Align import com.badlogic.gdx.utils.Align
import com.unciv.UncivGame
import com.unciv.logic.city.CityConstructions import com.unciv.logic.city.CityConstructions
import com.unciv.logic.city.CityInfo import com.unciv.logic.city.CityInfo
import com.unciv.logic.city.PerpetualConstruction import com.unciv.logic.city.PerpetualConstruction
@ -18,7 +16,9 @@ import com.unciv.ui.cityscreen.CityScreen
import com.unciv.ui.trade.DiplomacyScreen import com.unciv.ui.trade.DiplomacyScreen
import com.unciv.ui.utils.* import com.unciv.ui.utils.*
class CityButton(val city: CityInfo, private val tileGroup: WorldTileGroup, skin: Skin): Table(skin){ class CityButton(val city: CityInfo, private val tileGroup: WorldTileGroup): Table(CameraStageBaseScreen.skin){
val worldScreen = tileGroup.worldScreen
val uncivGame = worldScreen.game
init { init {
isTransform = true // If this is not set then the city button won't scale! isTransform = true // If this is not set then the city button won't scale!
@ -126,11 +126,11 @@ class CityButton(val city: CityInfo, private val tileGroup: WorldTileGroup, skin
add(airUnitTable).row() add(airUnitTable).row()
} }
private fun belongsToViewingCiv() = city.civInfo == UncivGame.Current.worldScreen.viewingCiv private fun belongsToViewingCiv() = city.civInfo == worldScreen.viewingCiv
private fun setButtonActions() { private fun setButtonActions() {
val unitTable = tileGroup.worldScreen.bottomUnitTable val unitTable = worldScreen.bottomUnitTable
// So you can click anywhere on the button to go to the city // So you can click anywhere on the button to go to the city
touchable = Touchable.childrenOnly touchable = Touchable.childrenOnly
@ -139,16 +139,16 @@ class CityButton(val city: CityInfo, private val tileGroup: WorldTileGroup, skin
// clicking swings the button a little down to allow selection of units there. // clicking swings the button a little down to allow selection of units there.
// this also allows to target selected units to move to the city tile from elsewhere. // this also allows to target selected units to move to the city tile from elsewhere.
if (isButtonMoved) { if (isButtonMoved) {
val viewingCiv = UncivGame.Current.worldScreen.viewingCiv val viewingCiv = worldScreen.viewingCiv
// second tap on the button will go to the city screen // second tap on the button will go to the city screen
// if this city belongs to you // if this city belongs to you
if (UncivGame.Current.viewEntireMapForDebug || belongsToViewingCiv()) { if (uncivGame.viewEntireMapForDebug || belongsToViewingCiv()) {
UncivGame.Current.setScreen(CityScreen(city)) uncivGame.setScreen(CityScreen(city))
} else if (viewingCiv.knows(city.civInfo)) { } else if (viewingCiv.knows(city.civInfo)) {
// If city doesn't belong to you, go directly to its owner's diplomacy screen. // If city doesn't belong to you, go directly to its owner's diplomacy screen.
val screen = DiplomacyScreen(viewingCiv) val screen = DiplomacyScreen(viewingCiv)
screen.updateRightSide(city.civInfo) screen.updateRightSide(city.civInfo)
UncivGame.Current.setScreen(screen) uncivGame.setScreen(screen)
} }
} else { } else {
moveButtonDown() moveButtonDown()
@ -203,7 +203,7 @@ class CityButton(val city: CityInfo, private val tileGroup: WorldTileGroup, skin
iconTable.add(connectionImage).size(20f).pad(2f).padLeft(5f) iconTable.add(connectionImage).size(20f).pad(2f).padLeft(5f)
} }
iconTable.add(getPopulationGroup(UncivGame.Current.viewEntireMapForDebug || belongsToViewingCiv())) iconTable.add(getPopulationGroup(uncivGame.viewEntireMapForDebug || belongsToViewingCiv()))
.padLeft(10f) .padLeft(10f)
val cityButtonText = city.name val cityButtonText = city.name
@ -211,7 +211,7 @@ class CityButton(val city: CityInfo, private val tileGroup: WorldTileGroup, skin
iconTable.add(label).pad(10f) // sufficient horizontal padding iconTable.add(label).pad(10f) // sufficient horizontal padding
.fillY() // provide full-height clicking area .fillY() // provide full-height clicking area
if (UncivGame.Current.viewEntireMapForDebug || belongsToViewingCiv()) if (uncivGame.viewEntireMapForDebug || belongsToViewingCiv())
iconTable.add(getConstructionGroup(city.cityConstructions)).padRight(10f).padLeft(10f) iconTable.add(getConstructionGroup(city.cityConstructions)).padRight(10f).padLeft(10f)
else if (city.civInfo.isMajorCiv()) { else if (city.civInfo.isMajorCiv()) {
val nationIcon = ImageGetter.getNationIcon(city.civInfo.nation.name) val nationIcon = ImageGetter.getNationIcon(city.civInfo.nation.name)

View File

@ -47,7 +47,7 @@ class WorldTileGroup(internal val worldScreen: WorldScreen, tileInfo: TileInfo,
} }
if (city != null && tileInfo.isCityCenter()) { if (city != null && tileInfo.isCityCenter()) {
if (cityButton == null) { if (cityButton == null) {
cityButton = CityButton(city, this, CameraStageBaseScreen.skin) cityButton = CityButton(city, this)
cityButtonLayerGroup.addActor(cityButton) cityButtonLayerGroup.addActor(cityButton)
} }

View File

@ -14,7 +14,6 @@ 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.Constants import com.unciv.Constants
import com.unciv.UncivGame
import com.unciv.logic.GameSaver import com.unciv.logic.GameSaver
import com.unciv.logic.civilization.CivilizationInfo import com.unciv.logic.civilization.CivilizationInfo
import com.unciv.logic.civilization.diplomacy.DiplomaticStatus import com.unciv.logic.civilization.diplomacy.DiplomaticStatus
@ -246,7 +245,7 @@ class WorldScreen(val viewingCiv:CivilizationInfo) : CameraStageBaseScreen() {
bottomUnitTable.update() bottomUnitTable.update()
bottomTileInfoTable.updateTileTable(mapHolder.selectedTile) bottomTileInfoTable.updateTileTable(mapHolder.selectedTile)
bottomTileInfoTable.x = stage.width - bottomTileInfoTable.width bottomTileInfoTable.x = stage.width - bottomTileInfoTable.width
bottomTileInfoTable.y = if (UncivGame.Current.settings.showMinimap) minimapWrapper.height else 0f bottomTileInfoTable.y = if (game.settings.showMinimap) minimapWrapper.height else 0f
battleTable.update() battleTable.update()
tutorialTaskTable.clear() tutorialTaskTable.clear()
@ -341,7 +340,7 @@ class WorldScreen(val viewingCiv:CivilizationInfo) : CameraStageBaseScreen() {
} }
private fun displayTutorialsOnUpdate() { private fun displayTutorialsOnUpdate() {
UncivGame.Current.crashController.showDialogIfNeeded() game.crashController.showDialogIfNeeded()
displayTutorial(Tutorial.Introduction) displayTutorial(Tutorial.Introduction)
@ -376,7 +375,7 @@ class WorldScreen(val viewingCiv:CivilizationInfo) : CameraStageBaseScreen() {
.any()) { .any()) {
displayTutorial(Tutorial.OtherCivEncountered) displayTutorial(Tutorial.OtherCivEncountered)
val btn = "Diplomacy".toTextButton() val btn = "Diplomacy".toTextButton()
btn.onClick { UncivGame.Current.setScreen(DiplomacyScreen(viewingCiv)) } btn.onClick { game.setScreen(DiplomacyScreen(viewingCiv)) }
btn.label.setFontSize(30) btn.label.setFontSize(30)
btn.labelCell.pad(10f) btn.labelCell.pad(10f)
diplomacyButtonWrapper.add(btn) diplomacyButtonWrapper.add(btn)
@ -453,7 +452,7 @@ class WorldScreen(val viewingCiv:CivilizationInfo) : CameraStageBaseScreen() {
} }
} }
} catch (ex: Exception) { } catch (ex: Exception) {
UncivGame.Current.crashController.crashOccurred() game.crashController.crashOccurred()
throw ex throw ex
} }
@ -478,7 +477,7 @@ class WorldScreen(val viewingCiv:CivilizationInfo) : CameraStageBaseScreen() {
if (gameInfoClone.currentPlayerCiv.civName != viewingCiv.civName if (gameInfoClone.currentPlayerCiv.civName != viewingCiv.civName
&& !gameInfoClone.gameParameters.isOnlineMultiplayer) && !gameInfoClone.gameParameters.isOnlineMultiplayer)
UncivGame.Current.setScreen(PlayerReadyScreen(gameInfoClone.getCurrentPlayerCivilization())) game.setScreen(PlayerReadyScreen(gameInfoClone.getCurrentPlayerCivilization()))
else { else {
createNewWorldScreen() createNewWorldScreen()
} }
@ -577,7 +576,7 @@ class WorldScreen(val viewingCiv:CivilizationInfo) : CameraStageBaseScreen() {
} }
private fun showTutorialsOnNextTurn(){ private fun showTutorialsOnNextTurn(){
if (!UncivGame.Current.settings.showTutorials) return if (!game.settings.showTutorials) return
displayTutorial(Tutorial.SlowStart) displayTutorial(Tutorial.SlowStart)
displayTutorial(Tutorial.CityExpansion){ viewingCiv.cities.any { it.expansion.tilesClaimed()>0 } } displayTutorial(Tutorial.CityExpansion){ viewingCiv.cities.any { it.expansion.tilesClaimed()>0 } }
displayTutorial(Tutorial.BarbarianEncountered) { viewingCiv.viewableTiles.any { it.getUnits().any { unit -> unit.civInfo.isBarbarian() } } } displayTutorial(Tutorial.BarbarianEncountered) { viewingCiv.viewableTiles.any { it.getUnits().any { unit -> unit.civInfo.isBarbarian() } } }
@ -585,7 +584,7 @@ class WorldScreen(val viewingCiv:CivilizationInfo) : CameraStageBaseScreen() {
displayTutorial(Tutorial.Happiness) { viewingCiv.getHappiness() < 5 } displayTutorial(Tutorial.Happiness) { viewingCiv.getHappiness() < 5 }
displayTutorial(Tutorial.Unhappiness) { viewingCiv.getHappiness() < 0 } displayTutorial(Tutorial.Unhappiness) { viewingCiv.getHappiness() < 0 }
displayTutorial(Tutorial.GoldenAge) { viewingCiv.goldenAges.isGoldenAge() } displayTutorial(Tutorial.GoldenAge) { viewingCiv.goldenAges.isGoldenAge() }
displayTutorial(Tutorial.IdleUnits) { gameInfo.turns >= 50 && UncivGame.Current.settings.checkForDueUnits } displayTutorial(Tutorial.IdleUnits) { gameInfo.turns >= 50 && game.settings.checkForDueUnits }
displayTutorial(Tutorial.ContactMe) { gameInfo.turns >= 100 } displayTutorial(Tutorial.ContactMe) { gameInfo.turns >= 100 }
val resources = viewingCiv.detailedCivResources.asSequence().filter { it.origin == "All" } // Avoid full list copy val resources = viewingCiv.detailedCivResources.asSequence().filter { it.origin == "All" } // Avoid full list copy
displayTutorial(Tutorial.LuxuryResource) { resources.any { it.resource.resourceType==ResourceType.Luxury } } displayTutorial(Tutorial.LuxuryResource) { resources.any { it.resource.resourceType==ResourceType.Luxury } }

View File

@ -51,7 +51,7 @@ class WorldScreenTopBar(val worldScreen: WorldScreen) : Table() {
val overviewButton = "Overview".toTextButton() val overviewButton = "Overview".toTextButton()
overviewButton.labelCell.pad(10f) overviewButton.labelCell.pad(10f)
overviewButton.pack() overviewButton.pack()
overviewButton.onClick { UncivGame.Current.setScreen(EmpireOverviewScreen(worldScreen.viewingCiv)) } overviewButton.onClick { worldScreen.game.setScreen(EmpireOverviewScreen(worldScreen.viewingCiv)) }
overviewButton.center(this) overviewButton.center(this)
overviewButton.x = worldScreen.stage.width-overviewButton.width-10 overviewButton.x = worldScreen.stage.width-overviewButton.width-10
addActor(overviewButton) addActor(overviewButton)
@ -70,7 +70,7 @@ class WorldScreenTopBar(val worldScreen: WorldScreen) : Table() {
val resourceLabel = "0".toLabel() val resourceLabel = "0".toLabel()
resourceLabels[resource.name] = resourceLabel resourceLabels[resource.name] = resourceLabel
resourceTable.add(resourceLabel) resourceTable.add(resourceLabel)
val invokeResourcesPage = { UncivGame.Current.setScreen(EmpireOverviewScreen(worldScreen.viewingCiv, "Resources")) } val invokeResourcesPage = { worldScreen.game.setScreen(EmpireOverviewScreen(worldScreen.viewingCiv, "Resources")) }
resourceLabel.onClick(invokeResourcesPage) resourceLabel.onClick(invokeResourcesPage)
resourceImage.onClick(invokeResourcesPage) resourceImage.onClick(invokeResourcesPage)
} }
@ -86,27 +86,27 @@ class WorldScreenTopBar(val worldScreen: WorldScreen) : Table() {
statsTable.add(goldLabel) statsTable.add(goldLabel)
val goldImage = ImageGetter.getStatIcon("Gold") val goldImage = ImageGetter.getStatIcon("Gold")
statsTable.add(goldImage).padRight(20f).size(20f) statsTable.add(goldImage).padRight(20f).size(20f)
val invokeStatsPage = { UncivGame.Current.setScreen(EmpireOverviewScreen(worldScreen.viewingCiv, "Stats")) } val invokeStatsPage = { worldScreen.game.setScreen(EmpireOverviewScreen(worldScreen.viewingCiv, "Stats")) }
goldLabel.onClick(invokeStatsPage) goldLabel.onClick(invokeStatsPage)
goldImage.onClick(invokeStatsPage) goldImage.onClick(invokeStatsPage)
statsTable.add(scienceLabel) //.apply { setAlignment(Align.center) }).align(Align.top) statsTable.add(scienceLabel) //.apply { setAlignment(Align.center) }).align(Align.top)
val scienceImage = ImageGetter.getStatIcon("Science") val scienceImage = ImageGetter.getStatIcon("Science")
statsTable.add(scienceImage).padRight(20f).size(20f) statsTable.add(scienceImage).padRight(20f).size(20f)
val invokeTechScreen = { UncivGame.Current.setScreen(TechPickerScreen(worldScreen.viewingCiv)) } val invokeTechScreen = { worldScreen.game.setScreen(TechPickerScreen(worldScreen.viewingCiv)) }
scienceLabel.onClick(invokeTechScreen) scienceLabel.onClick(invokeTechScreen)
scienceImage.onClick(invokeTechScreen) scienceImage.onClick(invokeTechScreen)
statsTable.add(happinessImage).size(20f) statsTable.add(happinessImage).size(20f)
statsTable.add(happinessLabel).padRight(20f)//.apply { setAlignment(Align.center) }).align(Align.top) statsTable.add(happinessLabel).padRight(20f)//.apply { setAlignment(Align.center) }).align(Align.top)
val invokeResourcesPage = { UncivGame.Current.setScreen(EmpireOverviewScreen(worldScreen.viewingCiv, "Resources")) } val invokeResourcesPage = { worldScreen.game.setScreen(EmpireOverviewScreen(worldScreen.viewingCiv, "Resources")) }
happinessImage.onClick(invokeResourcesPage) happinessImage.onClick(invokeResourcesPage)
happinessLabel.onClick(invokeResourcesPage) happinessLabel.onClick(invokeResourcesPage)
statsTable.add(cultureLabel)//.apply { setAlignment(Align.center) }).align(Align.top) statsTable.add(cultureLabel)//.apply { setAlignment(Align.center) }).align(Align.top)
val cultureImage = ImageGetter.getStatIcon("Culture") val cultureImage = ImageGetter.getStatIcon("Culture")
statsTable.add(cultureImage).size(20f) statsTable.add(cultureImage).size(20f)
val invokePoliciesPage = { UncivGame.Current.setScreen(PolicyPickerScreen(worldScreen)) } val invokePoliciesPage = { worldScreen.game.setScreen(PolicyPickerScreen(worldScreen)) }
cultureLabel.onClick(invokePoliciesPage) cultureLabel.onClick(invokePoliciesPage)
cultureImage.onClick(invokePoliciesPage) cultureImage.onClick(invokePoliciesPage)
@ -155,7 +155,7 @@ class WorldScreenTopBar(val worldScreen: WorldScreen) : Table() {
val yearText = "["+ abs(year)+"] "+ if (year<0) "BC" else "AD" val yearText = "["+ abs(year)+"] "+ if (year<0) "BC" else "AD"
turnsLabel.setText("Turn".tr()+" " + civInfo.gameInfo.turns + " | "+ yearText.tr()) turnsLabel.setText("Turn".tr()+" " + civInfo.gameInfo.turns + " | "+ yearText.tr())
turnsLabel.onClick { UncivGame.Current.setScreen(VictoryScreen(worldScreen)) } turnsLabel.onClick { worldScreen.game.setScreen(VictoryScreen(worldScreen)) }
val nextTurnStats = civInfo.statsForNextTurn val nextTurnStats = civInfo.statsForNextTurn
val goldPerTurn = "(" + (if (nextTurnStats.gold > 0) "+" else "") + nextTurnStats.gold.roundToInt() + ")" val goldPerTurn = "(" + (if (nextTurnStats.gold > 0) "+" else "") + nextTurnStats.gold.roundToInt() + ")"

View File

@ -52,7 +52,7 @@ class WorldScreenMenuPopup(val worldScreen: WorldScreen) : Popup(worldScreen) {
addSeparator() addSeparator()
addSquareButton("Multiplayer".tr()){ addSquareButton("Multiplayer".tr()){
worldScreen.game.setScreen(MultiplayerScreen()) worldScreen.game.setScreen(MultiplayerScreen(worldScreen.game))
close() close()
}.size(width,height) }.size(width,height)
addSeparator() addSeparator()
@ -91,7 +91,7 @@ class WorldScreenMenuPopup(val worldScreen: WorldScreen) : Popup(worldScreen) {
// Create a new map // Create a new map
mapEditorPopup.addButton("New map") { mapEditorPopup.addButton("New map") {
UncivGame.Current.setScreen(NewMapScreen()) worldScreen.game.setScreen(NewMapScreen())
mapEditorPopup.close() mapEditorPopup.close()
} }
@ -100,9 +100,9 @@ class WorldScreenMenuPopup(val worldScreen: WorldScreen) : Popup(worldScreen) {
val loadMapScreen = LoadMapScreen(null) val loadMapScreen = LoadMapScreen(null)
loadMapScreen.closeButton.isVisible = true loadMapScreen.closeButton.isVisible = true
loadMapScreen.closeButton.onClick { loadMapScreen.closeButton.onClick {
UncivGame.Current.setWorldScreen() worldScreen.game.setWorldScreen()
loadMapScreen.dispose() } loadMapScreen.dispose() }
UncivGame.Current.setScreen(loadMapScreen) worldScreen.game.setScreen(loadMapScreen)
mapEditorPopup.close() mapEditorPopup.close()
} }

View File

@ -26,7 +26,7 @@ class Language(val language:String, val percentComplete:Int){
class WorldScreenOptionsPopup(val worldScreen:WorldScreen) : Popup(worldScreen) { class WorldScreenOptionsPopup(val worldScreen:WorldScreen) : Popup(worldScreen) {
var selectedLanguage: String = "English" var selectedLanguage: String = "English"
private val settings = UncivGame.Current.settings private val settings = worldScreen.game.settings
private val innerTable = Table(CameraStageBaseScreen.skin) private val innerTable = Table(CameraStageBaseScreen.skin)
init { init {
@ -43,7 +43,7 @@ class WorldScreenOptionsPopup(val worldScreen:WorldScreen) : Popup(worldScreen)
addCloseButton() { worldScreen.enableNextTurnButtonAfterOptions() } addCloseButton() { worldScreen.enableNextTurnButtonAfterOptions() }
pack() // Needed to show the background. pack() // Needed to show the background.
center(UncivGame.Current.worldScreen.stage) center(worldScreen.game.worldScreen.stage)
} }
private fun addHeader (text: String) { private fun addHeader (text: String) {
@ -56,16 +56,16 @@ class WorldScreenOptionsPopup(val worldScreen:WorldScreen) : Popup(worldScreen)
action(it) action(it)
settings.save() settings.save()
if (updateWorld) if (updateWorld)
UncivGame.Current.worldScreen.shouldUpdate = true worldScreen.game.worldScreen.shouldUpdate = true
} }
innerTable.add(button).row() innerTable.add(button).row()
} }
private fun reloadWorldAndOptions() { private fun reloadWorldAndOptions() {
settings.save() settings.save()
UncivGame.Current.worldScreen = WorldScreen(worldScreen.viewingCiv) worldScreen.game.worldScreen = WorldScreen(worldScreen.viewingCiv)
UncivGame.Current.setWorldScreen() worldScreen.game.setWorldScreen()
WorldScreenOptionsPopup(UncivGame.Current.worldScreen).open() WorldScreenOptionsPopup(worldScreen.game.worldScreen).open()
} }
private fun rebuildInnerTable() { private fun rebuildInnerTable() {
@ -104,7 +104,7 @@ class WorldScreenOptionsPopup(val worldScreen:WorldScreen) : Popup(worldScreen)
addYesNoRow ("Auto-assign city production", settings.autoAssignCityProduction, true) { addYesNoRow ("Auto-assign city production", settings.autoAssignCityProduction, true) {
settings.autoAssignCityProduction = it settings.autoAssignCityProduction = it
if (it && worldScreen.viewingCiv.isCurrentPlayer() && worldScreen.viewingCiv.playerType == PlayerType.Human) { if (it && worldScreen.viewingCiv.isCurrentPlayer() && worldScreen.viewingCiv.playerType == PlayerType.Human) {
UncivGame.Current.gameInfo.currentPlayerCiv.cities.forEach { worldScreen.game.gameInfo.currentPlayerCiv.cities.forEach {
city -> city.cityConstructions.chooseNextConstruction() city -> city.cityConstructions.chooseNextConstruction()
} }
} }
@ -125,7 +125,7 @@ class WorldScreenOptionsPopup(val worldScreen:WorldScreen) : Popup(worldScreen)
addSetUserId() addSetUserId()
innerTable.add("Version".toLabel()).pad(10f) innerTable.add("Version".toLabel()).pad(10f)
innerTable.add(UncivGame.Current.version.toLabel()).pad(10f).row() innerTable.add(worldScreen.game.version.toLabel()).pad(10f).row()
} }
private fun addSetUserId() { private fun addSetUserId() {
@ -196,7 +196,7 @@ class WorldScreenOptionsPopup(val worldScreen:WorldScreen) : Popup(worldScreen)
} }
private fun addMusicVolumeSlider() { private fun addMusicVolumeSlider() {
val musicLocation = Gdx.files.local(UncivGame.Current.musicLocation) val musicLocation = Gdx.files.local(worldScreen.game.musicLocation)
if (musicLocation.exists()) { if (musicLocation.exists()) {
innerTable.add("Music volume".tr()) innerTable.add("Music volume".tr())
@ -206,9 +206,9 @@ class WorldScreenOptionsPopup(val worldScreen:WorldScreen) : Popup(worldScreen)
settings.musicVolume = musicVolumeSlider.value settings.musicVolume = musicVolumeSlider.value
settings.save() settings.save()
val music = UncivGame.Current.music val music = worldScreen.game.music
if (music == null) // restart music, if it was off at the app start if (music == null) // restart music, if it was off at the app start
thread(name = "Music") { UncivGame.Current.startMusic() } thread(name = "Music") { worldScreen.game.startMusic() }
music?.volume = 0.4f * musicVolumeSlider.value music?.volume = 0.4f * musicVolumeSlider.value
} }
@ -229,7 +229,7 @@ class WorldScreenOptionsPopup(val worldScreen:WorldScreen) : Popup(worldScreen)
val file = DropBox.downloadFile("/Music/thatched-villagers.mp3") val file = DropBox.downloadFile("/Music/thatched-villagers.mp3")
musicLocation.write(file, false) musicLocation.write(file, false)
rebuildInnerTable() rebuildInnerTable()
UncivGame.Current.startMusic() worldScreen.game.startMusic()
} catch (ex: Exception) { } catch (ex: Exception) {
errorTable.clear() errorTable.clear()
errorTable.add("Could not download music!".toLabel(Color.RED)) errorTable.add("Could not download music!".toLabel(Color.RED))
@ -310,7 +310,7 @@ class WorldScreenOptionsPopup(val worldScreen:WorldScreen) : Popup(worldScreen)
private fun addLanguageSelectBox() { private fun addLanguageSelectBox() {
val languageSelectBox = SelectBox<Language>(skin) val languageSelectBox = SelectBox<Language>(skin)
val languageArray = Array<Language>() val languageArray = Array<Language>()
UncivGame.Current.translations.percentCompleteOfLanguages worldScreen.game.translations.percentCompleteOfLanguages
.map { Language(it.key, if (it.key == "English") 100 else it.value) } .map { Language(it.key, if (it.key == "English") 100 else it.value) }
.sortedByDescending { it.percentComplete } .sortedByDescending { it.percentComplete }
.forEach { languageArray.add(it) } .forEach { languageArray.add(it) }
@ -333,7 +333,7 @@ class WorldScreenOptionsPopup(val worldScreen:WorldScreen) : Popup(worldScreen)
private fun selectLanguage() { private fun selectLanguage() {
settings.language = selectedLanguage settings.language = selectedLanguage
UncivGame.Current.translations.tryReadTranslationForCurrentLanguage() worldScreen.game.translations.tryReadTranslationForCurrentLanguage()
CameraStageBaseScreen.resetFonts() // to load chinese characters if necessary CameraStageBaseScreen.resetFonts() // to load chinese characters if necessary
reloadWorldAndOptions() reloadWorldAndOptions()
} }