From 86576e25aeff6161f46e9b1f942013034b4059de Mon Sep 17 00:00:00 2001 From: Yair Morgenstern Date: Tue, 3 Mar 2020 21:45:39 +0200 Subject: [PATCH] Fixed crash when diplomacy values change while ending the turn --- .../logic/civilization/CivilizationInfo.kt | 2 +- core/src/com/unciv/ui/EmpireOverviewScreen.kt | 30 +++++++++---------- .../cityscreen/SpecialistAllocationTable.kt | 10 ++++--- 3 files changed, 22 insertions(+), 20 deletions(-) diff --git a/core/src/com/unciv/logic/civilization/CivilizationInfo.kt b/core/src/com/unciv/logic/civilization/CivilizationInfo.kt index 5a998b242d..253a230d1e 100644 --- a/core/src/com/unciv/logic/civilization/CivilizationInfo.kt +++ b/core/src/com/unciv/logic/civilization/CivilizationInfo.kt @@ -457,7 +457,7 @@ class CivilizationInfo { goldenAges.endTurn(getHappiness()) 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() updateHasActiveGreatWall() } diff --git a/core/src/com/unciv/ui/EmpireOverviewScreen.kt b/core/src/com/unciv/ui/EmpireOverviewScreen.kt index daf61ef687..33e648171c 100644 --- a/core/src/com/unciv/ui/EmpireOverviewScreen.kt +++ b/core/src/com/unciv/ui/EmpireOverviewScreen.kt @@ -26,13 +26,13 @@ class EmpireOverviewScreen(private val viewingPlayer:CivilizationInfo) : CameraS init { onBackButtonClicked { UncivGame.Current.setWorldScreen() } - val closeButton = "×".toLabel(Color.BLACK,30).apply { this.setAlignment(Align.center) } - .surroundWithCircle(30f).apply { circle.color=Color.RED } + val closeButton = "×".toLabel(Color.BLACK, 30).apply { this.setAlignment(Align.center) } + .surroundWithCircle(50f).apply { circle.color = Color.RED.cpy().lerp(Color.BLACK, 0.1f) } closeButton.onClick { UncivGame.Current.setWorldScreen() } closeButton.y = stage.height - closeButton.height - 5 topTable.add(closeButton) - val setCityInfoButton = TextButton("Cities".tr(),skin) + val setCityInfoButton = TextButton("Cities".tr(), skin) val setCities = { centerTable.clear() centerTable.add(getCityInfoTable()) @@ -42,7 +42,7 @@ class EmpireOverviewScreen(private val viewingPlayer:CivilizationInfo) : CameraS setCityInfoButton.onClick(setCities) topTable.add(setCityInfoButton) - val setStatsInfoButton = TextButton("Stats".tr(),skin) + val setStatsInfoButton = TextButton("Stats".tr(), skin) setStatsInfoButton.onClick { game.settings.addCompletedTutorialTask("See your stats breakdown") centerTable.clear() @@ -57,41 +57,41 @@ class EmpireOverviewScreen(private val viewingPlayer:CivilizationInfo) : CameraS } topTable.add(setStatsInfoButton) - val setCurrentTradesButton = TextButton("Trades".tr(),skin) + val setCurrentTradesButton = TextButton("Trades".tr(), skin) setCurrentTradesButton.onClick { 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() } topTable.add(setCurrentTradesButton) - if(viewingPlayer.diplomacy.values.all { it.trades.isEmpty() }) + if (viewingPlayer.diplomacy.values.all { it.trades.isEmpty() }) setCurrentTradesButton.disable() - val setUnitsButton = TextButton("Units".tr(),skin) + val setUnitsButton = TextButton("Units".tr(), skin) setUnitsButton.onClick { centerTable.clear() - centerTable.add(ScrollPane(getUnitTable())).height(stage.height*0.8f) + centerTable.add(ScrollPane(getUnitTable())).height(stage.height * 0.8f) centerTable.pack() } - topTable.add(setUnitsButton ) + topTable.add(setUnitsButton) - val setDiplomacyButton = TextButton("Diplomacy".tr(),skin) + val setDiplomacyButton = TextButton("Diplomacy".tr(), skin) setDiplomacyButton.onClick { centerTable.clear() - centerTable.add(getDiplomacyGroup()).height(stage.height*0.8f) + centerTable.add(getDiplomacyGroup()).height(stage.height * 0.8f) centerTable.pack() } topTable.add(setDiplomacyButton) - val setResourcesButton = TextButton("Resources".tr(),skin) + val setResourcesButton = TextButton("Resources".tr(), skin) setResourcesButton.onClick { 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() } topTable.add(setResourcesButton) - if(viewingPlayer.detailedCivResources.isEmpty()) + if (viewingPlayer.detailedCivResources.isEmpty()) setResourcesButton.disable() topTable.pack() diff --git a/core/src/com/unciv/ui/cityscreen/SpecialistAllocationTable.kt b/core/src/com/unciv/ui/cityscreen/SpecialistAllocationTable.kt index 1f836baeab..68399d9148 100644 --- a/core/src/com/unciv/ui/cityscreen/SpecialistAllocationTable.kt +++ b/core/src/com/unciv/ui/cityscreen/SpecialistAllocationTable.kt @@ -48,8 +48,9 @@ class SpecialistAllocationTable(val cityScreen: CityScreen): Table(CameraStageBa private fun getAssignButton(assignedSpecialists: Int, maxSpecialists: Int, stat: Stat):Actor { if (assignedSpecialists >= maxSpecialists || cityInfo.isPuppet) return Table() - val assignButton = "+".toLabel(Color.BLACK,24).apply { this.setAlignment(Align.center) } - .surroundWithCircle(30f).apply { circle.color= Color.GREEN } + val assignButton = "+".toLabel(Color.BLACK,24) + .apply { this.setAlignment(Align.center) } + .surroundWithCircle(30f).apply { circle.color= Color.GREEN.cpy().lerp(Color.BLACK,0.2f) } assignButton.onClick { cityInfo.population.specialists.add(stat, 1f) cityInfo.cityStats.update() @@ -63,8 +64,9 @@ class SpecialistAllocationTable(val cityScreen: CityScreen): Table(CameraStageBa private fun getUnassignButton(assignedSpecialists: Int, stat: Stat):Actor { if (assignedSpecialists <= 0 || cityInfo.isPuppet) return Table() - val unassignButton = "-".toLabel(Color.BLACK,24).apply { this.setAlignment(Align.center) } - .surroundWithCircle(30f).apply { circle.color= Color.RED } + val unassignButton = "-".toLabel(Color.BLACK,24) + .apply { this.setAlignment(Align.center) } + .surroundWithCircle(30f).apply { circle.color= Color.RED.cpy().lerp(Color.BLACK,0.1f) } unassignButton.onClick { cityInfo.population.specialists.add(stat, -1f) cityInfo.cityStats.update()