mirror of
https://github.com/yairm210/Unciv.git
synced 2025-07-05 07:49:17 +07:00
Trade now almost entirely separate from Trade Screen, so the Trade screen can become a Diplomacy screen!
This commit is contained in:
@ -21,8 +21,8 @@ android {
|
|||||||
applicationId "com.unciv.game"
|
applicationId "com.unciv.game"
|
||||||
minSdkVersion 14
|
minSdkVersion 14
|
||||||
targetSdkVersion 26
|
targetSdkVersion 26
|
||||||
versionCode 108
|
versionCode 109
|
||||||
versionName "2.6.10"
|
versionName "2.6.11"
|
||||||
}
|
}
|
||||||
buildTypes {
|
buildTypes {
|
||||||
release {
|
release {
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
package com.unciv.ui
|
package com.unciv.ui
|
||||||
|
|
||||||
|
import com.badlogic.gdx.scenes.scene2d.Stage
|
||||||
import com.badlogic.gdx.scenes.scene2d.ui.Label
|
import com.badlogic.gdx.scenes.scene2d.ui.Label
|
||||||
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
|
||||||
@ -13,46 +14,32 @@ import com.unciv.ui.utils.tr
|
|||||||
|
|
||||||
class TradeScreen(otherCivilization: CivilizationInfo) : CameraStageBaseScreen(){
|
class TradeScreen(otherCivilization: CivilizationInfo) : CameraStageBaseScreen(){
|
||||||
|
|
||||||
val tradeLogic = TradeLogic(otherCivilization)
|
|
||||||
val tradeTable = Table(skin)
|
|
||||||
val tradeText = Label("What do you have in mind?".tr(),skin)
|
|
||||||
val offerButton = TextButton("Offer trade".tr(),skin)
|
|
||||||
|
|
||||||
|
|
||||||
val onChange = {
|
|
||||||
update()
|
|
||||||
offerButton.setText("Offer trade".tr())
|
|
||||||
tradeText.setText("What do you have in mind?".tr())
|
|
||||||
}
|
|
||||||
|
|
||||||
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() }
|
|
||||||
|
|
||||||
init {
|
init {
|
||||||
val generalTable = Table()
|
|
||||||
val closeButton = TextButton("Close".tr(), skin)
|
val closeButton = TextButton("Close".tr(), skin)
|
||||||
closeButton.addClickListener { UnCivGame.Current.setWorldScreen() }
|
closeButton.addClickListener { UnCivGame.Current.setWorldScreen() }
|
||||||
closeButton.y = stage.height - closeButton.height - 5
|
closeButton.y = stage.height - closeButton.height - 5
|
||||||
stage.addActor(closeButton)
|
stage.addActor(closeButton)
|
||||||
|
|
||||||
|
|
||||||
tradeTable.add("Our items".tr())
|
val generalTable = TradeTable(otherCivilization,stage)
|
||||||
tradeTable.add("Our trade offer".tr())
|
generalTable.center(stage)
|
||||||
tradeTable.add("[${otherCivilization.civName}]'s trade offer".tr())
|
|
||||||
tradeTable.add("[${otherCivilization.civName}]'s items".tr()).row()
|
|
||||||
tradeTable.add(ourAvailableOffersTable).size(stage.width/5,stage.height*0.8f)
|
|
||||||
tradeTable.add(ourOffersTable).size(stage.width/5,stage.height*0.8f)
|
|
||||||
tradeTable.add(theirOffersTable).size(stage.width/5,stage.height*0.8f)
|
|
||||||
tradeTable.add(theirAvailableOffersTable).size(stage.width/5,stage.height*0.8f)
|
|
||||||
tradeTable.pack()
|
|
||||||
|
|
||||||
generalTable.add(tradeTable).row()
|
stage.addActor(generalTable)
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
class TradeTable(val otherCivilization: CivilizationInfo, stage: Stage):Table(CameraStageBaseScreen.skin){
|
||||||
|
var tradeLogic = TradeLogic(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
|
||||||
|
val tradeText = Label("What do you have in mind?".tr(), CameraStageBaseScreen.skin)
|
||||||
|
val offerButton = TextButton("Offer trade".tr(), CameraStageBaseScreen.skin)
|
||||||
|
|
||||||
|
|
||||||
|
init{
|
||||||
|
offerColumnsTableWrapper.add(offerColumnsTable)
|
||||||
|
add(offerColumnsTableWrapper).row()
|
||||||
|
|
||||||
val lowerTable = Table().apply { defaults().pad(10f) }
|
val lowerTable = Table().apply { defaults().pad(10f) }
|
||||||
|
|
||||||
@ -73,10 +60,11 @@ class TradeScreen(otherCivilization: CivilizationInfo) : CameraStageBaseScreen()
|
|||||||
}
|
}
|
||||||
else if(offerButton.text.toString() == "Accept".tr()){
|
else if(offerButton.text.toString() == "Accept".tr()){
|
||||||
tradeLogic.acceptTrade()
|
tradeLogic.acceptTrade()
|
||||||
val newTradeScreen = TradeScreen(otherCivilization)
|
tradeLogic = TradeLogic(otherCivilization)
|
||||||
newTradeScreen.tradeText.setText("Pleasure doing business with you!".tr())
|
offerColumnsTable = OfferColumnsTable(tradeLogic,stage){onChange()}
|
||||||
UnCivGame.Current.screen = newTradeScreen
|
offerColumnsTableWrapper.clear()
|
||||||
|
offerColumnsTableWrapper.add(offerColumnsTable)
|
||||||
|
tradeText.setText("Pleasure doing business with you!".tr())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -84,21 +72,49 @@ class TradeScreen(otherCivilization: CivilizationInfo) : CameraStageBaseScreen()
|
|||||||
|
|
||||||
lowerTable.pack()
|
lowerTable.pack()
|
||||||
lowerTable.y = 10f
|
lowerTable.y = 10f
|
||||||
generalTable.add(lowerTable)
|
add(lowerTable)
|
||||||
generalTable.pack()
|
pack()
|
||||||
generalTable.center(stage)
|
|
||||||
stage.addActor(generalTable)
|
|
||||||
|
|
||||||
|
|
||||||
update()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fun update(){
|
private fun onChange(){
|
||||||
ourAvailableOffersTable.update()
|
offerColumnsTable.update()
|
||||||
ourOffersTable.update()
|
offerButton.setText("Offer trade".tr())
|
||||||
theirAvailableOffersTable.update()
|
tradeText.setText("What do you have in mind?".tr())
|
||||||
theirOffersTable.update()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
class OfferColumnsTable(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() }
|
||||||
|
|
||||||
|
init {
|
||||||
|
add("Our items".tr())
|
||||||
|
add("Our trade offer".tr())
|
||||||
|
add("[${tradeLogic.otherCivilization.civName}]'s trade offer".tr())
|
||||||
|
add("[${tradeLogic.otherCivilization.civName}]'s items".tr()).row()
|
||||||
|
val columnWidth = stage.width / 5f
|
||||||
|
val columnHeight = stage.height * 0.8f
|
||||||
|
add(ourAvailableOffersTable).size(columnWidth,columnHeight)
|
||||||
|
add(ourOffersTable).size(columnWidth,columnHeight)
|
||||||
|
add(theirOffersTable).size(columnWidth,columnHeight)
|
||||||
|
add(theirAvailableOffersTable).size(columnWidth,columnHeight)
|
||||||
|
pack()
|
||||||
|
}
|
||||||
|
|
||||||
|
fun update() {
|
||||||
|
ourAvailableOffersTable.update()
|
||||||
|
ourOffersTable.update()
|
||||||
|
theirAvailableOffersTable.update()
|
||||||
|
theirOffersTable.update()
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
Reference in New Issue
Block a user