Fixed crash when diplomacy values change while ending the turn

This commit is contained in:
Yair Morgenstern
2020-03-03 21:45:39 +02:00
parent 163d4ad347
commit 86576e25ae
3 changed files with 22 additions and 20 deletions

View File

@ -457,7 +457,7 @@ class CivilizationInfo {
goldenAges.endTurn(getHappiness()) goldenAges.endTurn(getHappiness())
getCivUnits().forEach { it.endTurn() } getCivUnits().forEach { it.endTurn() }
diplomacy.values.forEach { it.nextTurn() } diplomacy.values.toList().forEach { it.nextTurn() } // we copy the diplomacy values so if it changes in-loop we won't crash
updateAllyCivForCityState() updateAllyCivForCityState()
updateHasActiveGreatWall() updateHasActiveGreatWall()
} }

View File

@ -26,13 +26,13 @@ class EmpireOverviewScreen(private val viewingPlayer:CivilizationInfo) : CameraS
init { init {
onBackButtonClicked { UncivGame.Current.setWorldScreen() } onBackButtonClicked { UncivGame.Current.setWorldScreen() }
val closeButton = "×".toLabel(Color.BLACK,30).apply { this.setAlignment(Align.center) } val closeButton = "×".toLabel(Color.BLACK, 30).apply { this.setAlignment(Align.center) }
.surroundWithCircle(30f).apply { circle.color=Color.RED } .surroundWithCircle(50f).apply { circle.color = Color.RED.cpy().lerp(Color.BLACK, 0.1f) }
closeButton.onClick { UncivGame.Current.setWorldScreen() } closeButton.onClick { UncivGame.Current.setWorldScreen() }
closeButton.y = stage.height - closeButton.height - 5 closeButton.y = stage.height - closeButton.height - 5
topTable.add(closeButton) topTable.add(closeButton)
val setCityInfoButton = TextButton("Cities".tr(),skin) val setCityInfoButton = TextButton("Cities".tr(), skin)
val setCities = { val setCities = {
centerTable.clear() centerTable.clear()
centerTable.add(getCityInfoTable()) centerTable.add(getCityInfoTable())
@ -42,7 +42,7 @@ class EmpireOverviewScreen(private val viewingPlayer:CivilizationInfo) : CameraS
setCityInfoButton.onClick(setCities) setCityInfoButton.onClick(setCities)
topTable.add(setCityInfoButton) topTable.add(setCityInfoButton)
val setStatsInfoButton = TextButton("Stats".tr(),skin) val setStatsInfoButton = TextButton("Stats".tr(), skin)
setStatsInfoButton.onClick { setStatsInfoButton.onClick {
game.settings.addCompletedTutorialTask("See your stats breakdown") game.settings.addCompletedTutorialTask("See your stats breakdown")
centerTable.clear() centerTable.clear()
@ -57,41 +57,41 @@ class EmpireOverviewScreen(private val viewingPlayer:CivilizationInfo) : CameraS
} }
topTable.add(setStatsInfoButton) topTable.add(setStatsInfoButton)
val setCurrentTradesButton = TextButton("Trades".tr(),skin) val setCurrentTradesButton = TextButton("Trades".tr(), skin)
setCurrentTradesButton.onClick { setCurrentTradesButton.onClick {
centerTable.clear() centerTable.clear()
centerTable.add(ScrollPane(getTradesTable())).height(stage.height*0.8f) // so it doesn't cover the navigation buttons centerTable.add(ScrollPane(getTradesTable())).height(stage.height * 0.8f) // so it doesn't cover the navigation buttons
centerTable.pack() centerTable.pack()
} }
topTable.add(setCurrentTradesButton) topTable.add(setCurrentTradesButton)
if(viewingPlayer.diplomacy.values.all { it.trades.isEmpty() }) if (viewingPlayer.diplomacy.values.all { it.trades.isEmpty() })
setCurrentTradesButton.disable() setCurrentTradesButton.disable()
val setUnitsButton = TextButton("Units".tr(),skin) val setUnitsButton = TextButton("Units".tr(), skin)
setUnitsButton.onClick { setUnitsButton.onClick {
centerTable.clear() centerTable.clear()
centerTable.add(ScrollPane(getUnitTable())).height(stage.height*0.8f) centerTable.add(ScrollPane(getUnitTable())).height(stage.height * 0.8f)
centerTable.pack() centerTable.pack()
} }
topTable.add(setUnitsButton ) topTable.add(setUnitsButton)
val setDiplomacyButton = TextButton("Diplomacy".tr(),skin) val setDiplomacyButton = TextButton("Diplomacy".tr(), skin)
setDiplomacyButton.onClick { setDiplomacyButton.onClick {
centerTable.clear() centerTable.clear()
centerTable.add(getDiplomacyGroup()).height(stage.height*0.8f) centerTable.add(getDiplomacyGroup()).height(stage.height * 0.8f)
centerTable.pack() centerTable.pack()
} }
topTable.add(setDiplomacyButton) topTable.add(setDiplomacyButton)
val setResourcesButton = TextButton("Resources".tr(),skin) val setResourcesButton = TextButton("Resources".tr(), skin)
setResourcesButton.onClick { setResourcesButton.onClick {
centerTable.clear() centerTable.clear()
centerTable.add(ScrollPane(getResourcesTable())).size(stage.width*0.8f, stage.height*0.8f) centerTable.add(ScrollPane(getResourcesTable())).size(stage.width * 0.8f, stage.height * 0.8f)
centerTable.pack() centerTable.pack()
} }
topTable.add(setResourcesButton) topTable.add(setResourcesButton)
if(viewingPlayer.detailedCivResources.isEmpty()) if (viewingPlayer.detailedCivResources.isEmpty())
setResourcesButton.disable() setResourcesButton.disable()
topTable.pack() topTable.pack()

View File

@ -48,8 +48,9 @@ class SpecialistAllocationTable(val cityScreen: CityScreen): Table(CameraStageBa
private fun getAssignButton(assignedSpecialists: Int, maxSpecialists: Int, stat: Stat):Actor { private fun getAssignButton(assignedSpecialists: Int, maxSpecialists: Int, stat: Stat):Actor {
if (assignedSpecialists >= maxSpecialists || cityInfo.isPuppet) return Table() if (assignedSpecialists >= maxSpecialists || cityInfo.isPuppet) return Table()
val assignButton = "+".toLabel(Color.BLACK,24).apply { this.setAlignment(Align.center) } val assignButton = "+".toLabel(Color.BLACK,24)
.surroundWithCircle(30f).apply { circle.color= Color.GREEN } .apply { this.setAlignment(Align.center) }
.surroundWithCircle(30f).apply { circle.color= Color.GREEN.cpy().lerp(Color.BLACK,0.2f) }
assignButton.onClick { assignButton.onClick {
cityInfo.population.specialists.add(stat, 1f) cityInfo.population.specialists.add(stat, 1f)
cityInfo.cityStats.update() cityInfo.cityStats.update()
@ -63,8 +64,9 @@ class SpecialistAllocationTable(val cityScreen: CityScreen): Table(CameraStageBa
private fun getUnassignButton(assignedSpecialists: Int, stat: Stat):Actor { private fun getUnassignButton(assignedSpecialists: Int, stat: Stat):Actor {
if (assignedSpecialists <= 0 || cityInfo.isPuppet) return Table() if (assignedSpecialists <= 0 || cityInfo.isPuppet) return Table()
val unassignButton = "-".toLabel(Color.BLACK,24).apply { this.setAlignment(Align.center) } val unassignButton = "-".toLabel(Color.BLACK,24)
.surroundWithCircle(30f).apply { circle.color= Color.RED } .apply { this.setAlignment(Align.center) }
.surroundWithCircle(30f).apply { circle.color= Color.RED.cpy().lerp(Color.BLACK,0.1f) }
unassignButton.onClick { unassignButton.onClick {
cityInfo.population.specialists.add(stat, -1f) cityInfo.population.specialists.add(stat, -1f)
cityInfo.cityStats.update() cityInfo.cityStats.update()