From 0bb565fdc689499bbaa712a8635dbe4b6ca1ec96 Mon Sep 17 00:00:00 2001 From: SimonCeder <63475501+SimonCeder@users.noreply.github.com> Date: Wed, 22 Sep 2021 19:21:41 +0200 Subject: [PATCH] Can't trade resources from other trades or city-states (#5252) * can't trade resources from city-states * display untradeable sources in trade screen * Update template.properties template string * Update Swedish.properties * Spelling, better buttons --- .../jsons/translations/Swedish.properties | 2 ++ .../jsons/translations/template.properties | 2 ++ .../logic/civilization/CivilizationInfo.kt | 18 +++++++++++++++++- core/src/com/unciv/logic/trade/TradeLogic.kt | 5 +++-- core/src/com/unciv/logic/trade/TradeOffer.kt | 9 ++++++++- .../com/unciv/ui/trade/OfferColumnsTable.kt | 6 ++++-- .../src/com/unciv/ui/trade/OffersListScroll.kt | 9 ++++++--- 7 files changed, 42 insertions(+), 9 deletions(-) diff --git a/android/assets/jsons/translations/Swedish.properties b/android/assets/jsons/translations/Swedish.properties index 93b5c77f3b..583ae5d477 100644 --- a/android/assets/jsons/translations/Swedish.properties +++ b/android/assets/jsons/translations/Swedish.properties @@ -246,6 +246,8 @@ Our items = Våra artiklar Our trade offer = Vårat handelserbjudande [otherCiv]'s trade offer = [otherCiv]s handelserbjudande [otherCiv]'s items = [otherCiv]s artiklar ++[amount] untradable copy = +[amount] ohandelsbar kopia ++[amount] untradable copies = +[amount] ohandelsbara kopior Pleasure doing business with you! = Angenämt att göra affärer med er! I think not. = Jag skulle inte tro det. That is acceptable. = Det är godtagbart. diff --git a/android/assets/jsons/translations/template.properties b/android/assets/jsons/translations/template.properties index f51a0167f7..cb05da8023 100644 --- a/android/assets/jsons/translations/template.properties +++ b/android/assets/jsons/translations/template.properties @@ -247,6 +247,8 @@ Our items = Our trade offer = [otherCiv]'s trade offer = [otherCiv]'s items = ++[amount] untradable copy = ++[amount] untradable copies = Pleasure doing business with you! = I think not. = That is acceptable. = diff --git a/core/src/com/unciv/logic/civilization/CivilizationInfo.kt b/core/src/com/unciv/logic/civilization/CivilizationInfo.kt index 349c5ce6e9..b3640505c1 100644 --- a/core/src/com/unciv/logic/civilization/CivilizationInfo.kt +++ b/core/src/com/unciv/logic/civilization/CivilizationInfo.kt @@ -272,8 +272,24 @@ class CivilizationInfo { fun getCivResources(): ResourceSupplyList { val newResourceSupplyList = ResourceSupplyList() - for (resourceSupply in detailedCivResources) + for (resourceSupply in detailedCivResources) { newResourceSupplyList.add(resourceSupply.resource, resourceSupply.amount, "All") + } + return newResourceSupplyList + } + + // Preserves some origins for resources so we can separate them for trades + fun getCivResourcesWithOriginsForTrade(): ResourceSupplyList { + val newResourceSupplyList = ResourceSupplyList() + for (resourceSupply in detailedCivResources) { + // If we got it from another trade or from a CS, preserve the origin + if ((resourceSupply.origin == "City-States" || resourceSupply.origin == "Trade") && resourceSupply.amount > 0) { + newResourceSupplyList.add(resourceSupply.resource, resourceSupply.amount, resourceSupply.origin) + newResourceSupplyList.add(resourceSupply.resource, 0, "Tradable") // Still add an empty "tradable" entry so it shows up in the list + } + else + newResourceSupplyList.add(resourceSupply.resource, resourceSupply.amount, "Tradable") + } return newResourceSupplyList } diff --git a/core/src/com/unciv/logic/trade/TradeLogic.kt b/core/src/com/unciv/logic/trade/TradeLogic.kt index 39f99db8fc..a7d926b342 100644 --- a/core/src/com/unciv/logic/trade/TradeLogic.kt +++ b/core/src/com/unciv/logic/trade/TradeLogic.kt @@ -26,8 +26,9 @@ class TradeLogic(val ourCivilization:CivilizationInfo, val otherCivilization: Ci offers.add(TradeOffer(Constants.openBorders, TradeType.Agreement)) } - for (entry in civInfo.getCivResources() - .filterNot { it.resource.resourceType == ResourceType.Bonus }) { + for (entry in civInfo.getCivResourcesWithOriginsForTrade() + .filterNot { it.resource.resourceType == ResourceType.Bonus } + .filter { it.origin == "Tradable" } ) { val resourceTradeType = if (entry.resource.resourceType == ResourceType.Luxury) TradeType.Luxury_Resource else TradeType.Strategic_Resource offers.add(TradeOffer(entry.resource.name, resourceTradeType, entry.amount)) diff --git a/core/src/com/unciv/logic/trade/TradeOffer.kt b/core/src/com/unciv/logic/trade/TradeOffer.kt index 698bdc5a2c..d341c0b6d0 100644 --- a/core/src/com/unciv/logic/trade/TradeOffer.kt +++ b/core/src/com/unciv/logic/trade/TradeOffer.kt @@ -6,6 +6,7 @@ import com.unciv.models.metadata.GameSpeed import com.unciv.models.translations.tr import com.unciv.ui.utils.Fonts import com.unciv.logic.trade.TradeType.TradeTypeNumberType +import com.unciv.models.ruleset.tile.ResourceSupply data class TradeOffer(val name:String, val type:TradeType, var amount:Int = 1, var duration: Int = -1) { @@ -35,7 +36,7 @@ data class TradeOffer(val name:String, val type:TradeType, var amount:Int = 1, v && offer.amount == amount } - fun getOfferText(): String { + fun getOfferText(untradable: Int = 0): String { var offerText = when(type){ TradeType.WarDeclaration -> "Declare war on [$name]" TradeType.Introduction -> "Introduction to [$name]" @@ -48,6 +49,12 @@ data class TradeOffer(val name:String, val type:TradeType, var amount:Int = 1, v if (duration > 0) offerText += "\n" + duration + Fonts.turn + if (untradable == 1) { + offerText += "\n" + "+[${untradable}] untradable copy".tr() + } else if (untradable > 1) { + offerText += "\n" + "+[${untradable}] untradable copies".tr() + } + return offerText } } diff --git a/core/src/com/unciv/ui/trade/OfferColumnsTable.kt b/core/src/com/unciv/ui/trade/OfferColumnsTable.kt index 82e705d243..1b616c5d9d 100644 --- a/core/src/com/unciv/ui/trade/OfferColumnsTable.kt +++ b/core/src/com/unciv/ui/trade/OfferColumnsTable.kt @@ -71,10 +71,12 @@ class OfferColumnsTable(private val tradeLogic: TradeLogic, val screen: Diplomac fun update() { val ourFilteredOffers = tradeLogic.ourAvailableOffers.without(tradeLogic.currentTrade.ourOffers) val theirFilteredOffers = tradeLogic.theirAvailableOffers.without(tradeLogic.currentTrade.theirOffers) - ourAvailableOffersTable.update(ourFilteredOffers, tradeLogic.theirAvailableOffers) + val ourUntradables = tradeLogic.ourCivilization.getCivResourcesWithOriginsForTrade().filterNot { it.origin == "Tradable" } + val theirUntradables = tradeLogic.otherCivilization.getCivResourcesWithOriginsForTrade().filterNot { it.origin == "Tradable" } + ourAvailableOffersTable.update(ourFilteredOffers, tradeLogic.theirAvailableOffers, ourUntradables) ourOffersTable.update(tradeLogic.currentTrade.ourOffers, tradeLogic.theirAvailableOffers) theirOffersTable.update(tradeLogic.currentTrade.theirOffers, tradeLogic.ourAvailableOffers) - theirAvailableOffersTable.update(theirFilteredOffers, tradeLogic.ourAvailableOffers) + theirAvailableOffersTable.update(theirFilteredOffers, tradeLogic.ourAvailableOffers, theirUntradables) } private fun openGoldSelectionPopup(offer: TradeOffer, ourOffers: TradeOffersList, maxGold: Int) { diff --git a/core/src/com/unciv/ui/trade/OffersListScroll.kt b/core/src/com/unciv/ui/trade/OffersListScroll.kt index 79ab3d38d0..3d87401450 100644 --- a/core/src/com/unciv/ui/trade/OffersListScroll.kt +++ b/core/src/com/unciv/ui/trade/OffersListScroll.kt @@ -8,6 +8,7 @@ import com.unciv.logic.trade.TradeOffer import com.unciv.logic.trade.TradeOffersList import com.unciv.logic.trade.TradeType import com.unciv.logic.trade.TradeType.* +import com.unciv.models.ruleset.tile.ResourceSupply import com.unciv.models.translations.tr import com.unciv.ui.utils.* import kotlin.math.min @@ -30,8 +31,9 @@ class OffersListScroll( /** * @param offersToDisplay The offers which should be displayed as buttons * @param otherOffers The list of other side's offers to compare with whether these offers are unique + * @param untradableOffers Things we got from sources that we can't trade on, displayed for completeness */ - fun update(offersToDisplay:TradeOffersList, otherOffers: TradeOffersList) { + fun update(offersToDisplay:TradeOffersList, otherOffers: TradeOffersList, untradableOffers: List = emptyList()) { table.clear() expanderTabs.clear() @@ -64,7 +66,7 @@ class OffersListScroll( } for (offer in offersOfType) { - val tradeButton = offer.getOfferText().toTextButton() + val tradeButton = offer.getOfferText(untradableOffers.filter { it.resource.name == offer.name }.sumOf { it.amount }).toTextButton() val amountPerClick = if (offer.type == Gold) 50 else 1 @@ -86,7 +88,8 @@ class OffersListScroll( if (expanderTabs.containsKey(offerType)) expanderTabs[offerType]!!.innerTable.add(tradeButton).row() - else table.add(tradeButton).row() + else + table.add(tradeButton).row() } } actor = table