mirror of
https://github.com/yairm210/Unciv.git
synced 2025-07-22 13:49:54 +07:00
Trade table logic greatly simplified, now all trade displays are dependent only on the current trade in the TradeLogic - this paves the way for "inserting" trades into the trade table, which is required for AI-offered trades!
This commit is contained in:
@ -391,7 +391,7 @@ BuildingIcons/Paper Maker
|
||||
index: -1
|
||||
BuildingIcons/Pentagon
|
||||
rotate: false
|
||||
xy: 1938, 926
|
||||
xy: 1836, 824
|
||||
size: 100, 100
|
||||
orig: 100, 100
|
||||
offset: 0, 0
|
||||
@ -790,28 +790,28 @@ ImprovementIcons/Quarry
|
||||
index: -1
|
||||
ImprovementIcons/Railroad
|
||||
rotate: false
|
||||
xy: 898, 724
|
||||
xy: 694, 622
|
||||
size: 100, 100
|
||||
orig: 100, 100
|
||||
offset: 0, 0
|
||||
index: -1
|
||||
TileSets/Default/Railroad
|
||||
rotate: false
|
||||
xy: 898, 724
|
||||
xy: 694, 622
|
||||
size: 100, 100
|
||||
orig: 100, 100
|
||||
offset: 0, 0
|
||||
index: -1
|
||||
TileSets/FantasyHex/Railroad
|
||||
rotate: false
|
||||
xy: 898, 724
|
||||
xy: 694, 622
|
||||
size: 100, 100
|
||||
orig: 100, 100
|
||||
offset: 0, 0
|
||||
index: -1
|
||||
TileSets/ThorfMaps/Railroad
|
||||
rotate: false
|
||||
xy: 898, 724
|
||||
xy: 694, 622
|
||||
size: 100, 100
|
||||
orig: 100, 100
|
||||
offset: 0, 0
|
||||
@ -909,7 +909,7 @@ OtherIcons/MenuIcon
|
||||
index: -1
|
||||
OtherIcons/Pentagon
|
||||
rotate: false
|
||||
xy: 1836, 824
|
||||
xy: 1938, 926
|
||||
size: 100, 100
|
||||
orig: 100, 100
|
||||
offset: 0, 0
|
||||
@ -1966,7 +1966,7 @@ TechIcons/Radio
|
||||
index: -1
|
||||
TechIcons/Railroad
|
||||
rotate: false
|
||||
xy: 694, 622
|
||||
xy: 898, 724
|
||||
size: 100, 100
|
||||
orig: 100, 100
|
||||
offset: 0, 0
|
||||
|
Binary file not shown.
Before Width: | Height: | Size: 969 KiB After Width: | Height: | Size: 968 KiB |
@ -7,6 +7,7 @@ import com.unciv.models.gamebasics.tr
|
||||
|
||||
class TradeLogic(val ourCivilization:CivilizationInfo, val otherCivilization: CivilizationInfo){
|
||||
|
||||
/** Contains everything we could offer the other player, whether we've actually offered it or not */
|
||||
val ourAvailableOffers = getAvailableOffers(ourCivilization,otherCivilization)
|
||||
val theirAvailableOffers = getAvailableOffers(otherCivilization,ourCivilization)
|
||||
val currentTrade = Trade()
|
||||
|
@ -14,4 +14,10 @@ class TradeOffersList: ArrayList<TradeOffer>(){
|
||||
return true
|
||||
}
|
||||
|
||||
fun without(otherTradeOffersList: TradeOffersList): TradeOffersList {
|
||||
val tradeOffersListCopy = TradeOffersList()
|
||||
for(offer in this) tradeOffersListCopy.add(offer.copy())
|
||||
for(offer in otherTradeOffersList) tradeOffersListCopy.add(offer.copy(amount=-offer.amount))
|
||||
return tradeOffersListCopy
|
||||
}
|
||||
}
|
@ -7,16 +7,13 @@ import com.unciv.models.gamebasics.tr
|
||||
import com.unciv.ui.utils.CameraStageBaseScreen
|
||||
import com.unciv.ui.utils.addSeparator
|
||||
|
||||
class OfferColumnsTable(tradeLogic: TradeLogic, stage: Stage, onChange: ()->Unit): Table(CameraStageBaseScreen.skin) {
|
||||
/** This is the class that holds the 4 columns of the offers (ours/theirs/ offered/available) in trade */
|
||||
class OfferColumnsTable(val tradeLogic: TradeLogic, stage: Stage, onChange: ()->Unit): Table(CameraStageBaseScreen.skin) {
|
||||
|
||||
val ourAvailableOffersTable = OffersList(tradeLogic.ourAvailableOffers, tradeLogic.currentTrade.ourOffers,
|
||||
tradeLogic.theirAvailableOffers, tradeLogic.currentTrade.theirOffers) { onChange() }
|
||||
val ourOffersTable = OffersList(tradeLogic.currentTrade.ourOffers, tradeLogic.ourAvailableOffers,
|
||||
tradeLogic.currentTrade.theirOffers, tradeLogic.theirAvailableOffers) { onChange() }
|
||||
val theirOffersTable = OffersList(tradeLogic.currentTrade.theirOffers, tradeLogic.theirAvailableOffers,
|
||||
tradeLogic.currentTrade.ourOffers, tradeLogic.ourAvailableOffers) { onChange() }
|
||||
val theirAvailableOffersTable = OffersList(tradeLogic.theirAvailableOffers, tradeLogic.currentTrade.theirOffers,
|
||||
tradeLogic.ourAvailableOffers, tradeLogic.currentTrade.ourOffers) { onChange() }
|
||||
val ourAvailableOffersTable = OffersListScroll { tradeLogic.currentTrade.ourOffers.add(it); onChange() }
|
||||
val ourOffersTable = OffersListScroll { tradeLogic.currentTrade.ourOffers.add(it.copy(amount = -it.amount)); onChange() }
|
||||
val theirOffersTable = OffersListScroll { tradeLogic.currentTrade.theirOffers.add(it.copy(amount = -it.amount)); onChange() }
|
||||
val theirAvailableOffersTable = OffersListScroll { tradeLogic.currentTrade.theirOffers.add(it); onChange() }
|
||||
|
||||
init {
|
||||
defaults().pad(5f)
|
||||
@ -35,13 +32,13 @@ class OfferColumnsTable(tradeLogic: TradeLogic, stage: Stage, onChange: ()->Unit
|
||||
add(ourOffersTable).size(columnWidth,stage.height/5)
|
||||
add(theirOffersTable).size(columnWidth,stage.height/5)
|
||||
pack()
|
||||
update()
|
||||
}
|
||||
|
||||
fun update() {
|
||||
ourAvailableOffersTable.update()
|
||||
ourOffersTable.update()
|
||||
theirAvailableOffersTable.update()
|
||||
theirOffersTable.update()
|
||||
|
||||
ourAvailableOffersTable.update(tradeLogic.ourAvailableOffers.without(tradeLogic.currentTrade.ourOffers))
|
||||
ourOffersTable.update(tradeLogic.currentTrade.ourOffers)
|
||||
theirOffersTable.update(tradeLogic.currentTrade.theirOffers)
|
||||
theirAvailableOffersTable.update(tradeLogic.theirAvailableOffers.without(tradeLogic.currentTrade.theirOffers))
|
||||
}
|
||||
}
|
@ -3,6 +3,7 @@ package com.unciv.ui.trade
|
||||
import com.badlogic.gdx.scenes.scene2d.ui.ScrollPane
|
||||
import com.badlogic.gdx.scenes.scene2d.ui.Table
|
||||
import com.badlogic.gdx.scenes.scene2d.ui.TextButton
|
||||
import com.unciv.logic.trade.TradeOffer
|
||||
import com.unciv.logic.trade.TradeOffersList
|
||||
import com.unciv.logic.trade.TradeType
|
||||
import com.unciv.logic.trade.TradeType.*
|
||||
@ -13,16 +14,17 @@ import com.unciv.ui.utils.disable
|
||||
import com.unciv.ui.utils.onClick
|
||||
import kotlin.math.min
|
||||
|
||||
class OffersList(val offers: TradeOffersList, val correspondingOffers: TradeOffersList,
|
||||
val otherCivOffers: TradeOffersList, val otherCivCorrespondingOffers: TradeOffersList,
|
||||
val onChange: () -> Unit) : ScrollPane(null) {
|
||||
class OffersListScroll(val onOfferClicked: (TradeOffer) -> Unit) : ScrollPane(null) {
|
||||
val table = Table(CameraStageBaseScreen.skin).apply { defaults().pad(5f) }
|
||||
val tradesToNotHaveNumbers = listOf(Technology, City,
|
||||
Introduction, Treaty, WarDeclaration)
|
||||
|
||||
val expanderTabs = HashMap<TradeType, ExpanderTab>()
|
||||
|
||||
init {
|
||||
fun update(offersToDisplay:TradeOffersList) {
|
||||
table.clear()
|
||||
expanderTabs.clear()
|
||||
|
||||
for (offertype in values()) {
|
||||
val labelName = when(offertype){
|
||||
Gold, Gold_Per_Turn, Treaty,Introduction -> ""
|
||||
@ -32,21 +34,15 @@ class OffersList(val offers: TradeOffersList, val correspondingOffers: TradeOffe
|
||||
WarDeclaration -> "Declarations of war"
|
||||
City -> "Cities"
|
||||
}
|
||||
val offersOfType = offers.filter { it.type == offertype }
|
||||
val offersOfType = offersToDisplay.filter { it.type == offertype }
|
||||
if (labelName!="" && offersOfType.any()) {
|
||||
expanderTabs[offertype] = ExpanderTab(labelName, CameraStageBaseScreen.skin)
|
||||
expanderTabs[offertype]!!.close()
|
||||
expanderTabs[offertype]!!.innerTable.defaults().pad(5f)
|
||||
}
|
||||
}
|
||||
update()
|
||||
}
|
||||
|
||||
|
||||
fun update() {
|
||||
table.clear()
|
||||
for (offertype in values()) {
|
||||
val offersOfType = offers.filter { it.type == offertype }
|
||||
val offersOfType = offersToDisplay.filter { it.type == offertype }
|
||||
|
||||
if (expanderTabs.containsKey(offertype)) {
|
||||
expanderTabs[offertype]!!.innerTable.clear()
|
||||
@ -64,15 +60,7 @@ class OffersList(val offers: TradeOffersList, val correspondingOffers: TradeOffe
|
||||
if (offer.amount > 0)
|
||||
tradeButton.onClick {
|
||||
val amountTransferred = min(amountPerClick, offer.amount)
|
||||
offers += offer.copy(amount = -amountTransferred)
|
||||
correspondingOffers += offer.copy(amount = amountTransferred)
|
||||
if (offer.type == Treaty) { // this goes both ways, so it doesn't matter which side you click
|
||||
otherCivOffers += offer.copy(amount = -amountTransferred)
|
||||
otherCivCorrespondingOffers += offer.copy(amount = amountTransferred)
|
||||
}
|
||||
|
||||
onChange()
|
||||
update()
|
||||
onOfferClicked(offer.copy(amount = amountTransferred))
|
||||
}
|
||||
else tradeButton.disable() // for instance we have negative gold
|
||||
|
@ -15,7 +15,7 @@ class TradeTable(val otherCivilization: CivilizationInfo, stage: Stage, onTradeC
|
||||
val currentPlayerCiv = otherCivilization.gameInfo.getCurrentPlayerCivilization()
|
||||
var tradeLogic = TradeLogic(currentPlayerCiv,otherCivilization)
|
||||
var offerColumnsTable = OfferColumnsTable(tradeLogic, stage) { onChange() }
|
||||
var offerColumnsTableWrapper = Table() // This is so that after a trade has been traded, we can switch out the offers to start anew - this is the easiest way
|
||||
var offerColumnsTableWrapper = Table() // This is so that after a trade has been traded, we can switch out the offersToDisplay to start anew - this is the easiest way
|
||||
val tradeText = Label(otherCivilization.getTranslatedNation().neutralLetsHearIt.random().tr(), CameraStageBaseScreen.skin)
|
||||
val offerButton = TextButton("Offer trade".tr(), CameraStageBaseScreen.skin)
|
||||
|
||||
|
Reference in New Issue
Block a user