mirror of
https://github.com/yairm210/Unciv.git
synced 2025-08-04 09:09:21 +07:00
Pending trades (#8681)
* Added pending trade offers to the trade overview screen * Fixed offer trade button state * Fixed space * Small fixes
This commit is contained in:
@ -1235,6 +1235,8 @@ Maintenance =
|
||||
Transportation upkeep =
|
||||
Unit upkeep =
|
||||
Trades =
|
||||
Current trades =
|
||||
Pending trades =
|
||||
Score =
|
||||
Units =
|
||||
Unit Supply =
|
||||
|
@ -36,7 +36,8 @@ enum class EmpireOverviewCategories(
|
||||
Trades("StatIcons/Acquire", 'T', Align.top,
|
||||
fun (viewingPlayer: Civilization, overviewScreen: EmpireOverviewScreen, _: EmpireOverviewTabPersistableData?)
|
||||
= TradesOverviewTab(viewingPlayer, overviewScreen),
|
||||
fun (viewingPlayer: Civilization) = viewingPlayer.diplomacy.values.all { it.trades.isEmpty() }.toState()),
|
||||
fun (viewingPlayer: Civilization) =
|
||||
(viewingPlayer.diplomacy.values.all { it.trades.isEmpty()} && !viewingPlayer.diplomacy.values.any{it.otherCiv().tradeRequests.any { it.requestingCiv == viewingPlayer.civName }}).toState()),
|
||||
Units("OtherIcons/Shield", 'U', Align.topLeft,
|
||||
fun (viewingPlayer: Civilization, overviewScreen: EmpireOverviewScreen, persistedData: EmpireOverviewTabPersistableData?)
|
||||
= UnitOverviewTab(viewingPlayer, overviewScreen, persistedData),
|
||||
|
@ -1,6 +1,7 @@
|
||||
package com.unciv.ui.overviewscreen
|
||||
|
||||
import com.badlogic.gdx.scenes.scene2d.ui.Table
|
||||
import com.unciv.Constants
|
||||
import com.unciv.logic.civilization.Civilization
|
||||
import com.unciv.logic.trade.Trade
|
||||
import com.unciv.logic.trade.TradeOffersList
|
||||
@ -15,7 +16,15 @@ class TradesOverviewTab(
|
||||
|
||||
init {
|
||||
defaults().pad(10f)
|
||||
val diplomacies = viewingPlayer.diplomacy.values.filter { it.trades.isNotEmpty() }
|
||||
val diplomaciesWithPendingTrade = viewingPlayer.diplomacy.values.filter { it.otherCiv().tradeRequests.any { it.requestingCiv == viewingPlayer.civName } }
|
||||
if (diplomaciesWithPendingTrade.isNotEmpty())
|
||||
add("Pending trades".toLabel(fontSize = Constants.headingFontSize)).padTop(10f).row()
|
||||
for (diplomacy in diplomaciesWithPendingTrade) {
|
||||
for (tradeRequest in diplomacy.otherCiv().tradeRequests.filter { it.requestingCiv == viewingPlayer.civName })
|
||||
add(createTradeTable(tradeRequest.trade.reverse(), diplomacy.otherCiv())).row()
|
||||
}
|
||||
|
||||
val diplomaciesWithExistingTrade = viewingPlayer.diplomacy.values.filter { it.trades.isNotEmpty() }
|
||||
.sortedWith { diplomacyManager1, diplomacyManager2 ->
|
||||
val d1OffersFromFirstTrade = diplomacyManager1.trades.first().ourOffers
|
||||
val d2OffersFromFirstTrade = diplomacyManager2.trades.first().ourOffers
|
||||
@ -27,7 +36,9 @@ class TradesOverviewTab(
|
||||
else -> -1
|
||||
}
|
||||
}
|
||||
for (diplomacy in diplomacies) {
|
||||
if (diplomaciesWithExistingTrade.isNotEmpty())
|
||||
add("Current trades".toLabel(fontSize = Constants.headingFontSize)).padTop(10f).row()
|
||||
for (diplomacy in diplomaciesWithExistingTrade) {
|
||||
for (trade in diplomacy.trades)
|
||||
add(createTradeTable(trade, diplomacy.otherCiv())).row()
|
||||
}
|
||||
|
@ -712,6 +712,7 @@ class DiplomacyScreen(
|
||||
tradeTable.tradeLogic.currentTrade.theirOffers.add(peaceTreaty)
|
||||
tradeTable.tradeLogic.currentTrade.ourOffers.add(peaceTreaty)
|
||||
tradeTable.offerColumnsTable.update()
|
||||
tradeTable.enableOfferButton(true)
|
||||
}
|
||||
|
||||
if (isNotPlayersTurn()) negotiatePeaceButton.disable()
|
||||
@ -757,6 +758,7 @@ class DiplomacyScreen(
|
||||
tradeTable.tradeLogic.theirAvailableOffers.add(researchAgreement)
|
||||
tradeTable.tradeLogic.theirAvailableOffers.add(goldCostOfSignResearchAgreement)
|
||||
tradeTable.offerColumnsTable.update()
|
||||
tradeTable.enableOfferButton(true)
|
||||
}
|
||||
if (isNotPlayersTurn()) researchAgreementButton.disable()
|
||||
return researchAgreementButton
|
||||
|
@ -16,7 +16,7 @@ class TradeTable(private val otherCivilization: Civilization, stage: DiplomacySc
|
||||
var offerColumnsTable = OfferColumnsTable(tradeLogic, stage) { onChange() }
|
||||
// This is so that after a trade has been traded, we can switch out the offersToDisplay to start anew - this is the easiest way
|
||||
private var offerColumnsTableWrapper = Table()
|
||||
private val offerButton = "Offer trade".toTextButton().apply { isEnabled = false }
|
||||
private val offerButton = "Offer trade".toTextButton()
|
||||
|
||||
private fun isTradeOffered() = otherCivilization.tradeRequests.any { it.requestingCiv == currentPlayerCiv.civName }
|
||||
|
||||
@ -39,7 +39,7 @@ class TradeTable(private val otherCivilization: Civilization, stage: DiplomacySc
|
||||
}
|
||||
|
||||
if (isTradeOffered()) offerButton.setText("Retract offer".tr())
|
||||
else offerButton.setText("Offer trade".tr())
|
||||
else offerButton.apply { isEnabled = false }.setText("Offer trade".tr())
|
||||
|
||||
offerButton.onClick {
|
||||
if(isTradeOffered()) {
|
||||
@ -66,4 +66,7 @@ class TradeTable(private val otherCivilization: Civilization, stage: DiplomacySc
|
||||
offerButton.isEnabled = !(tradeLogic.currentTrade.theirOffers.size == 0 && tradeLogic.currentTrade.ourOffers.size == 0)
|
||||
}
|
||||
|
||||
fun enableOfferButton(isEnabled: Boolean) {
|
||||
offerButton.isEnabled = isEnabled
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user