mirror of
https://github.com/yairm210/Unciv.git
synced 2025-09-22 10:54:19 -04: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:
parent
d4b097b946
commit
7114a67d2c
@ -1235,6 +1235,8 @@ Maintenance =
|
|||||||
Transportation upkeep =
|
Transportation upkeep =
|
||||||
Unit upkeep =
|
Unit upkeep =
|
||||||
Trades =
|
Trades =
|
||||||
|
Current trades =
|
||||||
|
Pending trades =
|
||||||
Score =
|
Score =
|
||||||
Units =
|
Units =
|
||||||
Unit Supply =
|
Unit Supply =
|
||||||
|
@ -36,7 +36,8 @@ enum class EmpireOverviewCategories(
|
|||||||
Trades("StatIcons/Acquire", 'T', Align.top,
|
Trades("StatIcons/Acquire", 'T', Align.top,
|
||||||
fun (viewingPlayer: Civilization, overviewScreen: EmpireOverviewScreen, _: EmpireOverviewTabPersistableData?)
|
fun (viewingPlayer: Civilization, overviewScreen: EmpireOverviewScreen, _: EmpireOverviewTabPersistableData?)
|
||||||
= TradesOverviewTab(viewingPlayer, overviewScreen),
|
= 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,
|
Units("OtherIcons/Shield", 'U', Align.topLeft,
|
||||||
fun (viewingPlayer: Civilization, overviewScreen: EmpireOverviewScreen, persistedData: EmpireOverviewTabPersistableData?)
|
fun (viewingPlayer: Civilization, overviewScreen: EmpireOverviewScreen, persistedData: EmpireOverviewTabPersistableData?)
|
||||||
= UnitOverviewTab(viewingPlayer, overviewScreen, persistedData),
|
= UnitOverviewTab(viewingPlayer, overviewScreen, persistedData),
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
package com.unciv.ui.overviewscreen
|
package com.unciv.ui.overviewscreen
|
||||||
|
|
||||||
import com.badlogic.gdx.scenes.scene2d.ui.Table
|
import com.badlogic.gdx.scenes.scene2d.ui.Table
|
||||||
|
import com.unciv.Constants
|
||||||
import com.unciv.logic.civilization.Civilization
|
import com.unciv.logic.civilization.Civilization
|
||||||
import com.unciv.logic.trade.Trade
|
import com.unciv.logic.trade.Trade
|
||||||
import com.unciv.logic.trade.TradeOffersList
|
import com.unciv.logic.trade.TradeOffersList
|
||||||
@ -15,7 +16,15 @@ class TradesOverviewTab(
|
|||||||
|
|
||||||
init {
|
init {
|
||||||
defaults().pad(10f)
|
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 ->
|
.sortedWith { diplomacyManager1, diplomacyManager2 ->
|
||||||
val d1OffersFromFirstTrade = diplomacyManager1.trades.first().ourOffers
|
val d1OffersFromFirstTrade = diplomacyManager1.trades.first().ourOffers
|
||||||
val d2OffersFromFirstTrade = diplomacyManager2.trades.first().ourOffers
|
val d2OffersFromFirstTrade = diplomacyManager2.trades.first().ourOffers
|
||||||
@ -27,7 +36,9 @@ class TradesOverviewTab(
|
|||||||
else -> -1
|
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)
|
for (trade in diplomacy.trades)
|
||||||
add(createTradeTable(trade, diplomacy.otherCiv())).row()
|
add(createTradeTable(trade, diplomacy.otherCiv())).row()
|
||||||
}
|
}
|
||||||
|
@ -712,6 +712,7 @@ class DiplomacyScreen(
|
|||||||
tradeTable.tradeLogic.currentTrade.theirOffers.add(peaceTreaty)
|
tradeTable.tradeLogic.currentTrade.theirOffers.add(peaceTreaty)
|
||||||
tradeTable.tradeLogic.currentTrade.ourOffers.add(peaceTreaty)
|
tradeTable.tradeLogic.currentTrade.ourOffers.add(peaceTreaty)
|
||||||
tradeTable.offerColumnsTable.update()
|
tradeTable.offerColumnsTable.update()
|
||||||
|
tradeTable.enableOfferButton(true)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isNotPlayersTurn()) negotiatePeaceButton.disable()
|
if (isNotPlayersTurn()) negotiatePeaceButton.disable()
|
||||||
@ -757,6 +758,7 @@ class DiplomacyScreen(
|
|||||||
tradeTable.tradeLogic.theirAvailableOffers.add(researchAgreement)
|
tradeTable.tradeLogic.theirAvailableOffers.add(researchAgreement)
|
||||||
tradeTable.tradeLogic.theirAvailableOffers.add(goldCostOfSignResearchAgreement)
|
tradeTable.tradeLogic.theirAvailableOffers.add(goldCostOfSignResearchAgreement)
|
||||||
tradeTable.offerColumnsTable.update()
|
tradeTable.offerColumnsTable.update()
|
||||||
|
tradeTable.enableOfferButton(true)
|
||||||
}
|
}
|
||||||
if (isNotPlayersTurn()) researchAgreementButton.disable()
|
if (isNotPlayersTurn()) researchAgreementButton.disable()
|
||||||
return researchAgreementButton
|
return researchAgreementButton
|
||||||
|
@ -16,7 +16,7 @@ class TradeTable(private val otherCivilization: Civilization, stage: DiplomacySc
|
|||||||
var offerColumnsTable = OfferColumnsTable(tradeLogic, stage) { onChange() }
|
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
|
// 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 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 }
|
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())
|
if (isTradeOffered()) offerButton.setText("Retract offer".tr())
|
||||||
else offerButton.setText("Offer trade".tr())
|
else offerButton.apply { isEnabled = false }.setText("Offer trade".tr())
|
||||||
|
|
||||||
offerButton.onClick {
|
offerButton.onClick {
|
||||||
if(isTradeOffered()) {
|
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)
|
offerButton.isEnabled = !(tradeLogic.currentTrade.theirOffers.size == 0 && tradeLogic.currentTrade.ourOffers.size == 0)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun enableOfferButton(isEnabled: Boolean) {
|
||||||
|
offerButton.isEnabled = isEnabled
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user