Construction button creation moved to DTO for later refactoring

This commit is contained in:
Yair Morgenstern
2021-01-15 14:38:12 +02:00
parent d91f4752e0
commit ab262da205

View File

@ -140,9 +140,9 @@ class ConstructionsTable(val cityScreen: CityScreen) : Table(CameraStageBaseScre
if (unit.requiredResource != null)
buttonText += "\n" + "Consumes 1 [${unit.requiredResource}]".tr()
val productionButton = getConstructionButton(unit,
val productionButton = getConstructionButton(ConstructionButtonDTO(unit,
buttonText,
unit.getRejectionReason(cityConstructions))
unit.getRejectionReason(cityConstructions)))
units.add(productionButton)
}
@ -151,10 +151,10 @@ class ConstructionsTable(val cityScreen: CityScreen) : Table(CameraStageBaseScre
var buttonText = building.name.tr() + turnOrTurns(turnsToBuilding)
if (building.requiredResource != null)
buttonText += "\n" + "Consumes 1 [${building.requiredResource}]".tr()
val productionTextButton = getConstructionButton(building,
val productionTextButton = getConstructionButton(ConstructionButtonDTO(building,
buttonText,
building.getRejectionReason(cityConstructions)
)
))
when {
building.isWonder -> buildableWonders += productionTextButton
building.isNationalWonder -> buildableNationalWonders += productionTextButton
@ -164,9 +164,9 @@ class ConstructionsTable(val cityScreen: CityScreen) : Table(CameraStageBaseScre
for (specialConstruction in PerpetualConstruction.perpetualConstructionsMap.values
.filter { it.shouldBeDisplayed(cityConstructions) }) {
specialConstructions += getConstructionButton(specialConstruction,
specialConstructions += getConstructionButton(ConstructionButtonDTO(specialConstruction,
"Produce [${specialConstruction.name}]".tr()
+ specialConstruction.getProductionTooltip(city))
+ specialConstruction.getProductionTooltip(city)))
}
availableConstructionsTable.addCategory("Units", units, constructionsQueueTable.width)
@ -234,8 +234,9 @@ class ConstructionsTable(val cityScreen: CityScreen) : Table(CameraStageBaseScre
Color.BROWN.cpy().lerp(Color.WHITE, 0.5f), Color.WHITE)
}
private fun getConstructionButton(construction: IConstruction, buttonText: String, rejectionReason: String = ""): Table {
class ConstructionButtonDTO(val construction: IConstruction, val buttonText: String, val rejectionReason: String = "")
private fun getConstructionButton(constructionButtonDTO: ConstructionButtonDTO): Table {
val construction = constructionButtonDTO.construction
val pickConstructionButton = Table()
pickConstructionButton.align(Align.left).pad(5f)
@ -248,7 +249,7 @@ class ConstructionsTable(val cityScreen: CityScreen) : Table(CameraStageBaseScre
pickConstructionButton.add(getProgressBar(construction.name)).padRight(5f)
pickConstructionButton.add(ImageGetter.getConstructionImage(construction.name).surroundWithCircle(40f)).padRight(10f)
pickConstructionButton.add(buttonText.toLabel()).expandX().fillX()
pickConstructionButton.add(constructionButtonDTO.buttonText.toLabel()).expandX().fillX()
if (!cannotAddConstructionToQueue(construction, cityScreen.city, cityScreen.city.cityConstructions)) {
val addToQueueButton = ImageGetter.getImage("OtherIcons/New").apply { color = Color.BLACK }.surroundWithCircle(40f)
@ -258,9 +259,9 @@ class ConstructionsTable(val cityScreen: CityScreen) : Table(CameraStageBaseScre
pickConstructionButton.row()
// no rejection reason means we can build it!
if(rejectionReason != "") {
if (constructionButtonDTO.rejectionReason != "") {
pickConstructionButton.color = Color.GRAY
pickConstructionButton.add(rejectionReason.toLabel(Color.RED).apply{ wrap = true } )
pickConstructionButton.add(constructionButtonDTO.rejectionReason.toLabel(Color.RED).apply { wrap = true })
.colspan(pickConstructionButton.columns).fillX().left().padTop(2f)
}
pickConstructionButton.onClick {