mirror of
https://github.com/yairm210/Unciv.git
synced 2025-09-30 07:21:34 -04: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:
parent
ad9f22e88c
commit
cefd50ea57
@ -391,7 +391,7 @@ BuildingIcons/Paper Maker
|
|||||||
index: -1
|
index: -1
|
||||||
BuildingIcons/Pentagon
|
BuildingIcons/Pentagon
|
||||||
rotate: false
|
rotate: false
|
||||||
xy: 1938, 926
|
xy: 1836, 824
|
||||||
size: 100, 100
|
size: 100, 100
|
||||||
orig: 100, 100
|
orig: 100, 100
|
||||||
offset: 0, 0
|
offset: 0, 0
|
||||||
@ -790,28 +790,28 @@ ImprovementIcons/Quarry
|
|||||||
index: -1
|
index: -1
|
||||||
ImprovementIcons/Railroad
|
ImprovementIcons/Railroad
|
||||||
rotate: false
|
rotate: false
|
||||||
xy: 898, 724
|
xy: 694, 622
|
||||||
size: 100, 100
|
size: 100, 100
|
||||||
orig: 100, 100
|
orig: 100, 100
|
||||||
offset: 0, 0
|
offset: 0, 0
|
||||||
index: -1
|
index: -1
|
||||||
TileSets/Default/Railroad
|
TileSets/Default/Railroad
|
||||||
rotate: false
|
rotate: false
|
||||||
xy: 898, 724
|
xy: 694, 622
|
||||||
size: 100, 100
|
size: 100, 100
|
||||||
orig: 100, 100
|
orig: 100, 100
|
||||||
offset: 0, 0
|
offset: 0, 0
|
||||||
index: -1
|
index: -1
|
||||||
TileSets/FantasyHex/Railroad
|
TileSets/FantasyHex/Railroad
|
||||||
rotate: false
|
rotate: false
|
||||||
xy: 898, 724
|
xy: 694, 622
|
||||||
size: 100, 100
|
size: 100, 100
|
||||||
orig: 100, 100
|
orig: 100, 100
|
||||||
offset: 0, 0
|
offset: 0, 0
|
||||||
index: -1
|
index: -1
|
||||||
TileSets/ThorfMaps/Railroad
|
TileSets/ThorfMaps/Railroad
|
||||||
rotate: false
|
rotate: false
|
||||||
xy: 898, 724
|
xy: 694, 622
|
||||||
size: 100, 100
|
size: 100, 100
|
||||||
orig: 100, 100
|
orig: 100, 100
|
||||||
offset: 0, 0
|
offset: 0, 0
|
||||||
@ -909,7 +909,7 @@ OtherIcons/MenuIcon
|
|||||||
index: -1
|
index: -1
|
||||||
OtherIcons/Pentagon
|
OtherIcons/Pentagon
|
||||||
rotate: false
|
rotate: false
|
||||||
xy: 1836, 824
|
xy: 1938, 926
|
||||||
size: 100, 100
|
size: 100, 100
|
||||||
orig: 100, 100
|
orig: 100, 100
|
||||||
offset: 0, 0
|
offset: 0, 0
|
||||||
@ -1966,7 +1966,7 @@ TechIcons/Radio
|
|||||||
index: -1
|
index: -1
|
||||||
TechIcons/Railroad
|
TechIcons/Railroad
|
||||||
rotate: false
|
rotate: false
|
||||||
xy: 694, 622
|
xy: 898, 724
|
||||||
size: 100, 100
|
size: 100, 100
|
||||||
orig: 100, 100
|
orig: 100, 100
|
||||||
offset: 0, 0
|
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){
|
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 ourAvailableOffers = getAvailableOffers(ourCivilization,otherCivilization)
|
||||||
val theirAvailableOffers = getAvailableOffers(otherCivilization,ourCivilization)
|
val theirAvailableOffers = getAvailableOffers(otherCivilization,ourCivilization)
|
||||||
val currentTrade = Trade()
|
val currentTrade = Trade()
|
||||||
|
@ -14,4 +14,10 @@ class TradeOffersList: ArrayList<TradeOffer>(){
|
|||||||
return true
|
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.CameraStageBaseScreen
|
||||||
import com.unciv.ui.utils.addSeparator
|
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,
|
val ourAvailableOffersTable = OffersListScroll { tradeLogic.currentTrade.ourOffers.add(it); onChange() }
|
||||||
tradeLogic.theirAvailableOffers, tradeLogic.currentTrade.theirOffers) { onChange() }
|
val ourOffersTable = OffersListScroll { tradeLogic.currentTrade.ourOffers.add(it.copy(amount = -it.amount)); onChange() }
|
||||||
val ourOffersTable = OffersList(tradeLogic.currentTrade.ourOffers, tradeLogic.ourAvailableOffers,
|
val theirOffersTable = OffersListScroll { tradeLogic.currentTrade.theirOffers.add(it.copy(amount = -it.amount)); onChange() }
|
||||||
tradeLogic.currentTrade.theirOffers, tradeLogic.theirAvailableOffers) { onChange() }
|
val theirAvailableOffersTable = OffersListScroll { tradeLogic.currentTrade.theirOffers.add(it); 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() }
|
|
||||||
|
|
||||||
init {
|
init {
|
||||||
defaults().pad(5f)
|
defaults().pad(5f)
|
||||||
@ -35,13 +32,13 @@ class OfferColumnsTable(tradeLogic: TradeLogic, stage: Stage, onChange: ()->Unit
|
|||||||
add(ourOffersTable).size(columnWidth,stage.height/5)
|
add(ourOffersTable).size(columnWidth,stage.height/5)
|
||||||
add(theirOffersTable).size(columnWidth,stage.height/5)
|
add(theirOffersTable).size(columnWidth,stage.height/5)
|
||||||
pack()
|
pack()
|
||||||
|
update()
|
||||||
}
|
}
|
||||||
|
|
||||||
fun update() {
|
fun update() {
|
||||||
ourAvailableOffersTable.update()
|
ourAvailableOffersTable.update(tradeLogic.ourAvailableOffers.without(tradeLogic.currentTrade.ourOffers))
|
||||||
ourOffersTable.update()
|
ourOffersTable.update(tradeLogic.currentTrade.ourOffers)
|
||||||
theirAvailableOffersTable.update()
|
theirOffersTable.update(tradeLogic.currentTrade.theirOffers)
|
||||||
theirOffersTable.update()
|
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.ScrollPane
|
||||||
import com.badlogic.gdx.scenes.scene2d.ui.Table
|
import com.badlogic.gdx.scenes.scene2d.ui.Table
|
||||||
import com.badlogic.gdx.scenes.scene2d.ui.TextButton
|
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.TradeOffersList
|
||||||
import com.unciv.logic.trade.TradeType
|
import com.unciv.logic.trade.TradeType
|
||||||
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 com.unciv.ui.utils.onClick
|
||||||
import kotlin.math.min
|
import kotlin.math.min
|
||||||
|
|
||||||
class OffersList(val offers: TradeOffersList, val correspondingOffers: TradeOffersList,
|
class OffersListScroll(val onOfferClicked: (TradeOffer) -> Unit) : ScrollPane(null) {
|
||||||
val otherCivOffers: TradeOffersList, val otherCivCorrespondingOffers: TradeOffersList,
|
|
||||||
val onChange: () -> Unit) : ScrollPane(null) {
|
|
||||||
val table = Table(CameraStageBaseScreen.skin).apply { defaults().pad(5f) }
|
val table = Table(CameraStageBaseScreen.skin).apply { defaults().pad(5f) }
|
||||||
val tradesToNotHaveNumbers = listOf(Technology, City,
|
val tradesToNotHaveNumbers = listOf(Technology, City,
|
||||||
Introduction, Treaty, WarDeclaration)
|
Introduction, Treaty, WarDeclaration)
|
||||||
|
|
||||||
val expanderTabs = HashMap<TradeType, ExpanderTab>()
|
val expanderTabs = HashMap<TradeType, ExpanderTab>()
|
||||||
|
|
||||||
init {
|
fun update(offersToDisplay:TradeOffersList) {
|
||||||
|
table.clear()
|
||||||
|
expanderTabs.clear()
|
||||||
|
|
||||||
for (offertype in values()) {
|
for (offertype in values()) {
|
||||||
val labelName = when(offertype){
|
val labelName = when(offertype){
|
||||||
Gold, Gold_Per_Turn, Treaty,Introduction -> ""
|
Gold, Gold_Per_Turn, Treaty,Introduction -> ""
|
||||||
@ -32,21 +34,15 @@ class OffersList(val offers: TradeOffersList, val correspondingOffers: TradeOffe
|
|||||||
WarDeclaration -> "Declarations of war"
|
WarDeclaration -> "Declarations of war"
|
||||||
City -> "Cities"
|
City -> "Cities"
|
||||||
}
|
}
|
||||||
val offersOfType = offers.filter { it.type == offertype }
|
val offersOfType = offersToDisplay.filter { it.type == offertype }
|
||||||
if (labelName!="" && offersOfType.any()) {
|
if (labelName!="" && offersOfType.any()) {
|
||||||
expanderTabs[offertype] = ExpanderTab(labelName, CameraStageBaseScreen.skin)
|
expanderTabs[offertype] = ExpanderTab(labelName, CameraStageBaseScreen.skin)
|
||||||
expanderTabs[offertype]!!.close()
|
|
||||||
expanderTabs[offertype]!!.innerTable.defaults().pad(5f)
|
expanderTabs[offertype]!!.innerTable.defaults().pad(5f)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
update()
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
fun update() {
|
|
||||||
table.clear()
|
|
||||||
for (offertype in values()) {
|
for (offertype in values()) {
|
||||||
val offersOfType = offers.filter { it.type == offertype }
|
val offersOfType = offersToDisplay.filter { it.type == offertype }
|
||||||
|
|
||||||
if (expanderTabs.containsKey(offertype)) {
|
if (expanderTabs.containsKey(offertype)) {
|
||||||
expanderTabs[offertype]!!.innerTable.clear()
|
expanderTabs[offertype]!!.innerTable.clear()
|
||||||
@ -64,15 +60,7 @@ class OffersList(val offers: TradeOffersList, val correspondingOffers: TradeOffe
|
|||||||
if (offer.amount > 0)
|
if (offer.amount > 0)
|
||||||
tradeButton.onClick {
|
tradeButton.onClick {
|
||||||
val amountTransferred = min(amountPerClick, offer.amount)
|
val amountTransferred = min(amountPerClick, offer.amount)
|
||||||
offers += offer.copy(amount = -amountTransferred)
|
onOfferClicked(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()
|
|
||||||
}
|
}
|
||||||
else tradeButton.disable() // for instance we have negative gold
|
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()
|
val currentPlayerCiv = otherCivilization.gameInfo.getCurrentPlayerCivilization()
|
||||||
var tradeLogic = TradeLogic(currentPlayerCiv,otherCivilization)
|
var tradeLogic = TradeLogic(currentPlayerCiv,otherCivilization)
|
||||||
var offerColumnsTable = OfferColumnsTable(tradeLogic, stage) { onChange() }
|
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 tradeText = Label(otherCivilization.getTranslatedNation().neutralLetsHearIt.random().tr(), CameraStageBaseScreen.skin)
|
||||||
val offerButton = TextButton("Offer trade".tr(), CameraStageBaseScreen.skin)
|
val offerButton = TextButton("Offer trade".tr(), CameraStageBaseScreen.skin)
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user