mirror of
https://github.com/yairm210/Unciv.git
synced 2025-09-27 22:06:05 -04:00
Added button to add construction items directly to the queue
This commit is contained in:
parent
93a26f635c
commit
81a38be5f4
@ -5,7 +5,7 @@ import com.badlogic.gdx.scenes.scene2d.Touchable
|
|||||||
import com.badlogic.gdx.scenes.scene2d.ui.Table
|
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.UncivGame
|
import com.unciv.logic.city.CityConstructions
|
||||||
import com.unciv.logic.city.CityInfo
|
import com.unciv.logic.city.CityInfo
|
||||||
import com.unciv.logic.city.IConstruction
|
import com.unciv.logic.city.IConstruction
|
||||||
import com.unciv.logic.city.PerpetualConstruction
|
import com.unciv.logic.city.PerpetualConstruction
|
||||||
@ -108,6 +108,8 @@ class ConstructionsTable(val cityScreen: CityScreen) : Table(CameraStageBaseScre
|
|||||||
|
|
||||||
constructionsQueueTable.addSeparator()
|
constructionsQueueTable.addSeparator()
|
||||||
constructionsQueueTable.add(getHeader("Construction queue".tr())).fillX()
|
constructionsQueueTable.add(getHeader("Construction queue".tr())).fillX()
|
||||||
|
constructionsQueueTable.addSeparator()
|
||||||
|
|
||||||
|
|
||||||
if (queue.isNotEmpty()) {
|
if (queue.isNotEmpty()) {
|
||||||
queue.forEachIndexed { i, constructionName ->
|
queue.forEachIndexed { i, constructionName ->
|
||||||
@ -138,7 +140,7 @@ class ConstructionsTable(val cityScreen: CityScreen) : Table(CameraStageBaseScre
|
|||||||
if(unit.requiredResource != null)
|
if(unit.requiredResource != null)
|
||||||
buttonText += "\n"+"Consumes 1 [${unit.requiredResource}]".tr()
|
buttonText += "\n"+"Consumes 1 [${unit.requiredResource}]".tr()
|
||||||
|
|
||||||
val productionButton = getProductionButton(unit,
|
val productionButton = getConstructionButton(unit,
|
||||||
buttonText,
|
buttonText,
|
||||||
unit.getRejectionReason(cityConstructions))
|
unit.getRejectionReason(cityConstructions))
|
||||||
units.add(productionButton)
|
units.add(productionButton)
|
||||||
@ -149,7 +151,7 @@ class ConstructionsTable(val cityScreen: CityScreen) : Table(CameraStageBaseScre
|
|||||||
var buttonText = building.name.tr() + turnOrTurns(turnsToBuilding)
|
var buttonText = building.name.tr() + turnOrTurns(turnsToBuilding)
|
||||||
if(building.requiredResource != null)
|
if(building.requiredResource != null)
|
||||||
buttonText += "\n"+"Consumes 1 [${building.requiredResource}]".tr()
|
buttonText += "\n"+"Consumes 1 [${building.requiredResource}]".tr()
|
||||||
val productionTextButton = getProductionButton(building,
|
val productionTextButton = getConstructionButton(building,
|
||||||
buttonText,
|
buttonText,
|
||||||
building.getRejectionReason(cityConstructions)
|
building.getRejectionReason(cityConstructions)
|
||||||
)
|
)
|
||||||
@ -160,7 +162,7 @@ class ConstructionsTable(val cityScreen: CityScreen) : Table(CameraStageBaseScre
|
|||||||
|
|
||||||
for (specialConstruction in PerpetualConstruction.perpetualConstructionsMap.values
|
for (specialConstruction in PerpetualConstruction.perpetualConstructionsMap.values
|
||||||
.filter { it.shouldBeDisplayed(cityConstructions) }) {
|
.filter { it.shouldBeDisplayed(cityConstructions) }) {
|
||||||
specialConstructions += getProductionButton(specialConstruction,
|
specialConstructions += getConstructionButton(specialConstruction,
|
||||||
"Produce [${specialConstruction.name}]".tr()
|
"Produce [${specialConstruction.name}]".tr()
|
||||||
+ specialConstruction.getProductionTooltip(city))
|
+ specialConstruction.getProductionTooltip(city))
|
||||||
}
|
}
|
||||||
@ -230,39 +232,55 @@ class ConstructionsTable(val cityScreen: CityScreen) : Table(CameraStageBaseScre
|
|||||||
Color.BROWN.cpy().lerp(Color.WHITE, 0.5f), Color.WHITE)
|
Color.BROWN.cpy().lerp(Color.WHITE, 0.5f), Color.WHITE)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun getProductionButton(construction: IConstruction, buttonText: String, rejectionReason: String = ""): Table {
|
|
||||||
val pickProductionButton = Table()
|
|
||||||
|
|
||||||
pickProductionButton.align(Align.left).pad(5f)
|
private fun getConstructionButton(construction: IConstruction, buttonText: String, rejectionReason: String = ""): Table {
|
||||||
pickProductionButton.background = ImageGetter.getBackground(Color.BLACK)
|
val pickConstructionButton = Table()
|
||||||
pickProductionButton.touchable = Touchable.enabled
|
|
||||||
|
pickConstructionButton.align(Align.left).pad(5f)
|
||||||
|
pickConstructionButton.background = ImageGetter.getBackground(Color.BLACK)
|
||||||
|
pickConstructionButton.touchable = Touchable.enabled
|
||||||
|
|
||||||
if (!isSelectedQueueEntry() && cityScreen.selectedConstruction != null && cityScreen.selectedConstruction == construction) {
|
if (!isSelectedQueueEntry() && cityScreen.selectedConstruction != null && cityScreen.selectedConstruction == construction) {
|
||||||
pickProductionButton.background = ImageGetter.getBackground(Color.GREEN.cpy().lerp(Color.BLACK, 0.5f))
|
pickConstructionButton.background = ImageGetter.getBackground(Color.GREEN.cpy().lerp(Color.BLACK, 0.5f))
|
||||||
}
|
}
|
||||||
|
|
||||||
pickProductionButton.add(getProgressBar(construction.name)).padRight(5f)
|
pickConstructionButton.add(getProgressBar(construction.name)).padRight(5f)
|
||||||
pickProductionButton.add(ImageGetter.getConstructionImage(construction.name).surroundWithCircle(40f)).padRight(10f)
|
pickConstructionButton.add(ImageGetter.getConstructionImage(construction.name).surroundWithCircle(40f)).padRight(10f)
|
||||||
pickProductionButton.add(buttonText.toLabel()).expandX().fillX().left().row()
|
pickConstructionButton.add(buttonText.toLabel()).expandX().fillX()
|
||||||
|
|
||||||
|
if(!cannotAddConstructionToQueue(construction, cityScreen.city, cityScreen.city.cityConstructions)) {
|
||||||
|
val addToQueueButton = ImageGetter.getImage("OtherIcons/New").apply { color = Color.BLACK }.surroundWithCircle(40f)
|
||||||
|
addToQueueButton.onClick { addConstructionToQueue(construction, cityScreen.city.cityConstructions) }
|
||||||
|
pickConstructionButton.add(addToQueueButton)
|
||||||
|
}
|
||||||
|
pickConstructionButton.row()
|
||||||
|
|
||||||
// no rejection reason means we can build it!
|
// no rejection reason means we can build it!
|
||||||
if(rejectionReason != "") {
|
if(rejectionReason != "") {
|
||||||
pickProductionButton.color = Color.GRAY
|
pickConstructionButton.color = Color.GRAY
|
||||||
pickProductionButton.add(rejectionReason.toLabel(Color.RED).apply{ setWrap(true)} )
|
pickConstructionButton.add(rejectionReason.toLabel(Color.RED).apply{ wrap = true } )
|
||||||
.colspan(pickProductionButton.columns).fillX().left().padTop(2f)
|
.colspan(pickConstructionButton.columns).fillX().left().padTop(2f)
|
||||||
}
|
}
|
||||||
pickProductionButton.onClick {
|
pickConstructionButton.onClick {
|
||||||
cityScreen.selectedConstruction = construction
|
cityScreen.selectedConstruction = construction
|
||||||
cityScreen.selectedTile = null
|
cityScreen.selectedTile = null
|
||||||
selectedQueueEntry = -1
|
selectedQueueEntry = -1
|
||||||
cityScreen.update()
|
cityScreen.update()
|
||||||
}
|
}
|
||||||
|
|
||||||
return pickProductionButton
|
return pickConstructionButton
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun isSelectedQueueEntry(): Boolean = selectedQueueEntry >= 0
|
private fun isSelectedQueueEntry(): Boolean = selectedQueueEntry >= 0
|
||||||
|
|
||||||
|
fun cannotAddConstructionToQueue(construction:IConstruction, city:CityInfo, cityConstructions:CityConstructions): Boolean {
|
||||||
|
return cityConstructions.isQueueFull()
|
||||||
|
|| !cityConstructions.getConstruction(construction.name).isBuildable(cityConstructions)
|
||||||
|
|| !cityScreen.canChangeState
|
||||||
|
|| construction is PerpetualConstruction && cityConstructions.isBeingConstructedOrEnqueued(construction.name)
|
||||||
|
|| city.isPuppet
|
||||||
|
}
|
||||||
|
|
||||||
private fun getQueueButton(construction: IConstruction?): TextButton {
|
private fun getQueueButton(construction: IConstruction?): TextButton {
|
||||||
val city = cityScreen.city
|
val city = cityScreen.city
|
||||||
val cityConstructions = city.cityConstructions
|
val cityConstructions = city.cityConstructions
|
||||||
@ -283,19 +301,10 @@ class ConstructionsTable(val cityScreen: CityScreen) : Table(CameraStageBaseScre
|
|||||||
} else {
|
} else {
|
||||||
button = "Add to queue".toTextButton()
|
button = "Add to queue".toTextButton()
|
||||||
if (construction == null
|
if (construction == null
|
||||||
|| cityConstructions.isQueueFull()
|
|| cannotAddConstructionToQueue(construction, city, cityConstructions)) {
|
||||||
|| !cityConstructions.getConstruction(construction.name).isBuildable(cityConstructions)
|
|
||||||
|| !cityScreen.canChangeState
|
|
||||||
|| construction is PerpetualConstruction && cityConstructions.isBeingConstructedOrEnqueued(construction.name)
|
|
||||||
|| city.isPuppet) {
|
|
||||||
button.disable()
|
button.disable()
|
||||||
} else {
|
} else {
|
||||||
button.onClick {
|
button.onClick { addConstructionToQueue(construction, cityConstructions) }
|
||||||
cityConstructions.addToQueue(construction.name)
|
|
||||||
if (!construction.shouldBeDisplayed(cityConstructions)) cityScreen.selectedConstruction = null
|
|
||||||
cityScreen.update()
|
|
||||||
cityScreen.game.settings.addCompletedTutorialTask("Pick construction")
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -303,6 +312,13 @@ class ConstructionsTable(val cityScreen: CityScreen) : Table(CameraStageBaseScre
|
|||||||
return button
|
return button
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun addConstructionToQueue(construction:IConstruction, cityConstructions: CityConstructions) {
|
||||||
|
cityConstructions.addToQueue(construction.name)
|
||||||
|
if (!construction.shouldBeDisplayed(cityConstructions)) cityScreen.selectedConstruction = null
|
||||||
|
cityScreen.update()
|
||||||
|
cityScreen.game.settings.addCompletedTutorialTask("Pick construction")
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
fun purchaseConstruction(construction: IConstruction) {
|
fun purchaseConstruction(construction: IConstruction) {
|
||||||
val city = cityScreen.city
|
val city = cityScreen.city
|
||||||
@ -327,8 +343,8 @@ class ConstructionsTable(val cityScreen: CityScreen) : Table(CameraStageBaseScre
|
|||||||
|
|
||||||
val button = "".toTextButton()
|
val button = "".toTextButton()
|
||||||
|
|
||||||
if (construction == null || construction is PerpetualConstruction || (!construction.canBePurchased() && !city.civInfo.gameInfo.gameParameters.godMode)
|
if (construction == null || construction is PerpetualConstruction ||
|
||||||
) {
|
(!construction.canBePurchased() && !city.civInfo.gameInfo.gameParameters.godMode)) {
|
||||||
// fully disable a "buy" button only for "priceless" buildings such as wonders
|
// fully disable a "buy" button only for "priceless" buildings such as wonders
|
||||||
// for all other cases, the price should be displayed
|
// for all other cases, the price should be displayed
|
||||||
button.setText("Buy".tr())
|
button.setText("Buy".tr())
|
||||||
|
Loading…
x
Reference in New Issue
Block a user