Diplomacy: City State resource UI, improvement gift effect (#4782)

* CS Resources shown in Diplomacy linked

* CS Improvement gift updates resources immediately

* CS Improvement gift updates resources immediately - patch1
This commit is contained in:
SomeTroglodyte 2021-08-08 14:21:44 +02:00 committed by GitHub
parent b8fe46d057
commit 58a3dfdda3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 30 additions and 13 deletions

View File

@ -20,8 +20,10 @@ import com.unciv.models.ruleset.ModOptionsConstants
import com.unciv.models.ruleset.Quest import com.unciv.models.ruleset.Quest
import com.unciv.models.ruleset.tile.ResourceType import com.unciv.models.ruleset.tile.ResourceType
import com.unciv.models.translations.tr import com.unciv.models.translations.tr
import com.unciv.ui.civilopedia.CivilopediaScreen
import com.unciv.ui.tilegroups.CityButton import com.unciv.ui.tilegroups.CityButton
import com.unciv.ui.utils.* import com.unciv.ui.utils.*
import com.unciv.ui.utils.UncivTooltip.Companion.addTooltip
import kotlin.math.floor import kotlin.math.floor
import kotlin.math.roundToInt import kotlin.math.roundToInt
import com.unciv.ui.utils.AutoScrollPane as ScrollPane import com.unciv.ui.utils.AutoScrollPane as ScrollPane
@ -103,15 +105,26 @@ class DiplomacyScreen(val viewingCiv:CivilizationInfo):CameraStageBaseScreen() {
diplomacyTable.add("{Type}: {${otherCiv.cityStateType}}".toLabel()).row() diplomacyTable.add("{Type}: {${otherCiv.cityStateType}}".toLabel()).row()
diplomacyTable.add("{Personality}: {${otherCiv.cityStatePersonality}}".toLabel()).row() diplomacyTable.add("{Personality}: {${otherCiv.cityStatePersonality}}".toLabel()).row()
val resourcesTable = Table() if (otherCiv.detailedCivResources.any { it.resource.resourceType != ResourceType.Bonus }) {
resourcesTable.add("{Resources:} ".toLabel()).padRight(10f) val resourcesTable = Table()
for (supplyList in otherCiv.detailedCivResources) { resourcesTable.add("{Resources:} ".toLabel()).padRight(10f)
if (supplyList.resource.resourceType == ResourceType.Bonus) for (supplyList in otherCiv.detailedCivResources) {
continue if (supplyList.resource.resourceType == ResourceType.Bonus)
resourcesTable.add(ImageGetter.getResourceImage(supplyList.resource.name, 30f)).padRight(5f) continue
resourcesTable.add(supplyList.amount.toLabel()).padRight(20f) val name = supplyList.resource.name
val wrapper = Table()
val image = ImageGetter.getResourceImage(name, 30f)
wrapper.add(image).padRight(5f)
wrapper.add(supplyList.amount.toLabel())
resourcesTable.add(wrapper).padRight(20f)
wrapper.addTooltip(name, 18f)
wrapper.onClick {
val pedia = CivilopediaScreen(UncivGame.Current.gameInfo.ruleSet, link = "Resource/$name")
UncivGame.Current.setScreen(pedia)
}
}
diplomacyTable.add(resourcesTable).row()
} }
diplomacyTable.add(resourcesTable).row()
otherCiv.updateAllyCivForCityState() otherCiv.updateAllyCivForCityState()
val ally = otherCiv.getAllyCiv() val ally = otherCiv.getAllyCiv()
@ -196,7 +209,6 @@ class DiplomacyScreen(val viewingCiv:CivilizationInfo):CameraStageBaseScreen() {
improveTileButton.disable() improveTileButton.disable()
diplomacyTable.add(improveTileButton).row() diplomacyTable.add(improveTileButton).row()
if (otherCivDiplomacyManager.diplomaticStatus == DiplomaticStatus.Protector){ if (otherCivDiplomacyManager.diplomaticStatus == DiplomaticStatus.Protector){
val revokeProtectionButton = "Revoke Protection".toTextButton() val revokeProtectionButton = "Revoke Protection".toTextButton()
@ -285,16 +297,20 @@ class DiplomacyScreen(val viewingCiv:CivilizationInfo):CameraStageBaseScreen() {
val improvementGiftTable = getCityStateDiplomacyTableHeader(otherCiv) val improvementGiftTable = getCityStateDiplomacyTableHeader(otherCiv)
improvementGiftTable.addSeparator() improvementGiftTable.addSeparator()
val improvableTiles = otherCiv.getCapital().getImprovableTiles().filterNot {it.getTileResource().resourceType == ResourceType.Bonus}.toList() val improvableTiles = otherCiv.getCapital().getImprovableTiles()
.filterNot { it.getTileResource().resourceType == ResourceType.Bonus }.toList()
val tileImprovements = otherCiv.gameInfo.ruleSet.tileImprovements.filter { it.value.turnsToBuild != 0 } val tileImprovements = otherCiv.gameInfo.ruleSet.tileImprovements.filter { it.value.turnsToBuild != 0 }
for (improvableTile in improvableTiles){ for (improvableTile in improvableTiles){
for (tileImprovement in tileImprovements.values){ for (tileImprovement in tileImprovements.values){
if (improvableTile.canBuildImprovement(tileImprovement, otherCiv) && improvableTile.getTileResource().improvement == tileImprovement.name){ if (improvableTile.canBuildImprovement(tileImprovement, otherCiv) &&
improvableTile.getTileResource().improvement == tileImprovement.name) {
val improveTileButton = "Build [${tileImprovement}] on [${improvableTile.getTileResource()}] (200 Gold)".toTextButton() val improveTileButton = "Build [${tileImprovement}] on [${improvableTile.getTileResource()}] (200 Gold)".toTextButton()
improveTileButton.onClick { improveTileButton.onClick {
viewingCiv.giveGoldGift(otherCiv, 200) viewingCiv.addGold(-200)
improvableTile.stopWorkingOnImprovement()
improvableTile.improvement = tileImprovement.name improvableTile.improvement = tileImprovement.name
otherCiv.updateDetailedCivResources()
rightSideTable.clear() rightSideTable.clear()
rightSideTable.add(ScrollPane(getCityStateDiplomacyTable(otherCiv))) rightSideTable.add(ScrollPane(getCityStateDiplomacyTable(otherCiv)))
} }

View File

@ -30,7 +30,7 @@ fun Button.enable() {
touchable = Touchable.enabled touchable = Touchable.enabled
} }
/** Enable or disable a [Button] by setting its [touchable][Button.touchable] and [color][Button.color] properties, /** Enable or disable a [Button] by setting its [touchable][Button.touchable] and [color][Button.color] properties,
* or returns the corresponding state. * * or returns the corresponding state.
* *
* Do not confuse with Gdx' builtin [isDisabled][Button.isDisabled] property, * Do not confuse with Gdx' builtin [isDisabled][Button.isDisabled] property,
* which is more appropriate to toggle On/Off buttons, while this one is good for 'click-to-do-something' buttons. * which is more appropriate to toggle On/Off buttons, while this one is good for 'click-to-do-something' buttons.

View File

@ -152,6 +152,7 @@ class UncivTooltip <T: Actor>(
* *
* Tip is positioned over top right corner, slightly overshooting the receiver widget, longer tip [text]s will extend to the left. * Tip is positioned over top right corner, slightly overshooting the receiver widget, longer tip [text]s will extend to the left.
* *
* @param text Automatically translated tooltip text
* @param size _Vertical_ size of the entire Tooltip including background * @param size _Vertical_ size of the entire Tooltip including background
* @param always override requirement: presence of physical keyboard * @param always override requirement: presence of physical keyboard
*/ */