From fa41e50a33923ddb861f6eb55f792d146fef126e Mon Sep 17 00:00:00 2001 From: Yair Morgenstern Date: Sat, 14 Mar 2020 21:46:45 +0200 Subject: [PATCH] Resolves #2157 - 3.6.7-patch2 --- build.gradle | 4 +- .../unciv/ui/cityscreen/ConstructionsTable.kt | 68 ++++++++++--------- 2 files changed, 38 insertions(+), 34 deletions(-) diff --git a/build.gradle b/build.gradle index bac960b055..81b7fc0b49 100644 --- a/build.gradle +++ b/build.gradle @@ -33,8 +33,8 @@ allprojects { version = '1.0.1' ext { appName = "Unciv" - appCodeNumber = 394 - appVersion = "3.6.7-patch1" + appCodeNumber = 395 + appVersion = "3.6.7-patch2" gdxVersion = '1.9.10' roboVMVersion = '2.3.1' diff --git a/core/src/com/unciv/ui/cityscreen/ConstructionsTable.kt b/core/src/com/unciv/ui/cityscreen/ConstructionsTable.kt index 21abe14671..305495708c 100644 --- a/core/src/com/unciv/ui/cityscreen/ConstructionsTable.kt +++ b/core/src/com/unciv/ui/cityscreen/ConstructionsTable.kt @@ -213,19 +213,18 @@ class ConstructionsTable(val cityScreen: CityScreen) : Table(CameraStageBaseScre pickProductionButton.add(buttonText.toLabel()).expandX().fillX().left() // no rejection reason means we can build it! - if(rejectionReason == "") { - pickProductionButton.onClick { - cityScreen.selectedConstruction = cityScreen.city.cityConstructions.getConstruction(construction) - cityScreen.selectedTile = null - selectedQueueEntry = -2 - cityScreen.update() - } - } else { + if(rejectionReason != "") { pickProductionButton.color = Color.GRAY pickProductionButton.row() pickProductionButton.add(rejectionReason.toLabel(Color.RED).apply{ setWrap(true)} ) .colspan(pickProductionButton.columns).fillX().left().padTop(2f) } + pickProductionButton.onClick { + cityScreen.selectedConstruction = cityScreen.city.cityConstructions.getConstruction(construction) + cityScreen.selectedTile = null + selectedQueueEntry = -2 + cityScreen.update() + } return pickProductionButton } @@ -270,6 +269,34 @@ class ConstructionsTable(val cityScreen: CityScreen) : Table(CameraStageBaseScre return button } + + fun purchaseConstruction(construction: IConstruction) { + val city = cityScreen.city + val cityConstructions = city.cityConstructions + // We can't trust the isSelectedQueueEntry because that fails when we have the same unit as both the current construction and in the queue, + // and then we purchase the unit from the queue - see #2157 + val constructionIsCurrentConstruction = construction.name==cityConstructions.currentConstruction + + if (!cityConstructions.purchaseConstruction(construction.name)) { + Popup(cityScreen).apply { + add("No space available to place [${construction.name}] near [${city.name}]".tr()).row() + addCloseButton() + open() + } + return + } + if (isSelectedQueueEntry()) { + // currentConstruction is removed from the queue by purchaseConstruction + // to avoid conflicts with NextTurnAutomation + if (!constructionIsCurrentConstruction && cityConstructions.constructionQueue[selectedQueueEntry] == construction.name) + cityConstructions.removeFromQueue(selectedQueueEntry) + selectedQueueEntry = -2 + cityScreen.selectedConstruction = null + } + if (!construction.shouldBeDisplayed(cityConstructions)) cityScreen.selectedConstruction = null + cityScreen.update() + } + private fun getBuyButton(construction: IConstruction?): TextButton { val city = cityScreen.city val cityConstructions = city.cityConstructions @@ -283,28 +310,6 @@ class ConstructionsTable(val cityScreen: CityScreen) : Table(CameraStageBaseScre button.setText("Buy".tr()) button.disable() } else { - - fun purchaseConstruction() { - if (!cityConstructions.purchaseConstruction(construction.name)) { - Popup(cityScreen).apply { - add("No space available to place [${construction.name}] near [${city.name}]".tr()).row() - addCloseButton() - open() - } - } else { - if (isSelectedQueueEntry()) { - // currentConstruction is removed from the queue by purchaseConstruction - // to avoid conflicts with NextTurnAutomation - if (!isSelectedCurrentConstruction() && cityConstructions.constructionQueue[selectedQueueEntry] == construction.name) - cityConstructions.removeFromQueue(selectedQueueEntry) - selectedQueueEntry = -2 - cityScreen.selectedConstruction = null - } - if (!construction.shouldBeDisplayed(cityConstructions)) cityScreen.selectedConstruction = null - cityScreen.update() - } - } - val constructionGoldCost = construction.getGoldCost(city.civInfo) button.setText("Buy".tr() + " " + constructionGoldCost) button.add(ImageGetter.getStatIcon(Stat.Gold.name)).size(20f).padBottom(2f) @@ -315,12 +320,11 @@ class ConstructionsTable(val cityScreen: CityScreen) : Table(CameraStageBaseScre val purchasePrompt = "Currently you have [${city.civInfo.gold}] gold.".tr() + "\n\n" + "Would you like to purchase [${construction.name}] for [$constructionGoldCost] gold?".tr() - YesNoPopup(purchasePrompt, { purchaseConstruction() }, cityScreen, { cityScreen.update() }).open() + YesNoPopup(purchasePrompt, { purchaseConstruction(construction) }, cityScreen, { cityScreen.update() }).open() } if (constructionGoldCost > city.civInfo.gold) button.disable() - } button.labelCell.pad(5f)