Fix buy current construction (#1794)

This commit is contained in:
Federico Luongo 2020-01-27 22:59:40 +01:00 committed by Yair Morgenstern
parent d22b3acbb3
commit ea29f91519

View File

@ -99,9 +99,9 @@ class ConstructionsTable(val cityScreen: CityScreen) : Table(CameraStageBaseScre
constructionsQueueTable.addSeparator()
if (currentConstruction != "")
constructionsQueueTable.add(getQueueEntry(-1, currentConstruction, queue.isEmpty(), selectedQueueEntry == -1))
constructionsQueueTable.add(getQueueEntry(-1, currentConstruction, queue.isEmpty(), isSelectedCurrentConstruction()))
.expandX().fillX().row()
else
else
constructionsQueueTable.add("Pick a construction".toLabel()).pad(2f).row()
constructionsQueueTable.addSeparator()
@ -227,6 +227,7 @@ class ConstructionsTable(val cityScreen: CityScreen) : Table(CameraStageBaseScre
return pickProductionButton
}
private fun isSelectedQueueEntry(): Boolean = selectedQueueEntry > -2
private fun isSelectedCurrentConstruction(): Boolean = selectedQueueEntry == -1
private fun getQueueButton(construction: IConstruction?): TextButton {
val city = cityScreen.city
@ -287,7 +288,10 @@ class ConstructionsTable(val cityScreen: CityScreen) : Table(CameraStageBaseScre
YesNoPopup("Would you like to purchase [${construction.name}] for [$constructionGoldCost] gold?".tr(), {
cityConstructions.purchaseConstruction(construction.name)
if (isSelectedQueueEntry()) {
cityConstructions.removeFromQueue(selectedQueueEntry)
// currentConstruction is removed from the queue by purchaseConstruction
// to avoid conflicts with NextTurnAutomation
if (!isSelectedCurrentConstruction())
cityConstructions.removeFromQueue(selectedQueueEntry)
selectedQueueEntry = -2
cityScreen.selectedConstruction = null
}