All diplomacy now done from a separate screen

This commit is contained in:
Yair Morgenstern 2018-08-02 14:59:53 +03:00
parent 023c4cd1c6
commit bf9e06445c
8 changed files with 117 additions and 70 deletions

View file

@ -21,7 +21,7 @@ android {
applicationId "com.unciv.game"
minSdkVersion 14
targetSdkVersion 26
versionCode 109
versionCode 110
versionName "2.6.11"
}
buildTypes {

View file

@ -19,8 +19,8 @@ class TradeLogic(val otherCivilization: CivilizationInfo){
fun getAvailableOffers(civInfo: CivilizationInfo, otherCivilization: CivilizationInfo): TradeOffersList {
val offers = TradeOffersList()
if(civInfo.isAtWarWith(otherCivilization))
offers.add(TradeOffer("Peace Treaty", TradeType.Treaty, 20, 1))
// if(civInfo.isAtWarWith(otherCivilization))
// offers.add(TradeOffer("Peace Treaty", TradeType.Treaty, 20, 1))
for(entry in civInfo.getCivResources().filterNot { it.key.resourceType == ResourceType.Bonus }) {
val resourceTradeType = if(entry.key.resourceType== ResourceType.Luxury) TradeType.Luxury_Resource
else TradeType.Strategic_Resource

View file

@ -0,0 +1,41 @@
package com.unciv.ui.trade
import com.badlogic.gdx.scenes.scene2d.Stage
import com.badlogic.gdx.scenes.scene2d.ui.Table
import com.unciv.logic.trade.TradeLogic
import com.unciv.ui.utils.CameraStageBaseScreen
import com.unciv.ui.utils.tr
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()
}
}

View file

@ -1,4 +1,4 @@
package com.unciv.ui
package com.unciv.ui.trade
import com.badlogic.gdx.scenes.scene2d.ui.ScrollPane
import com.badlogic.gdx.scenes.scene2d.ui.Table

View file

@ -0,0 +1,56 @@
package com.unciv.ui.trade
import com.badlogic.gdx.scenes.scene2d.ui.SplitPane
import com.badlogic.gdx.scenes.scene2d.ui.Table
import com.badlogic.gdx.scenes.scene2d.ui.TextButton
import com.unciv.UnCivGame
import com.unciv.logic.civilization.CivilizationInfo
import com.unciv.ui.utils.CameraStageBaseScreen
import com.unciv.ui.utils.addClickListener
import com.unciv.ui.utils.center
import com.unciv.ui.utils.tr
class DiplomacyScreen():CameraStageBaseScreen(){
init{
val rightSideTable = Table()
val leftSideTable = Table()
val splitPane = SplitPane(rightSideTable,leftSideTable,false, skin)
splitPane.setSplitAmount(0.2f)
val playerCiv = UnCivGame.Current.gameInfo.getPlayerCivilization()
for(civ in UnCivGame.Current.gameInfo.civilizations
.filterNot { it.isDefeated() || it.isPlayerCivilization() || it.isBarbarianCivilization() }){
if(!playerCiv.diplomacy.containsKey(civ.civName)) continue
val tb = TextButton("Trade with [${civ.civName}]".tr(),skin)
tb.addClickListener { leftSideTable.clear(); leftSideTable.add(TradeTable(civ,stage)) }
rightSideTable.add(tb).pad(10f).row()
}
splitPane.setFillParent(true)
stage.addActor(splitPane)
val closeButton = TextButton("Close".tr(), skin)
closeButton.addClickListener { UnCivGame.Current.setWorldScreen() }
closeButton.y = stage.height - closeButton.height - 5
stage.addActor(closeButton) // This must come after the split pane so it will be above, that the button will be clickable
}
}
class TradeScreen(otherCivilization: CivilizationInfo) : CameraStageBaseScreen(){
init {
val closeButton = TextButton("Close".tr(), skin)
closeButton.addClickListener { UnCivGame.Current.setWorldScreen() }
closeButton.y = stage.height - closeButton.height - 5
stage.addActor(closeButton)
val generalTable = TradeTable(otherCivilization, stage)
generalTable.center(stage)
stage.addActor(generalTable)
}
}

View file

@ -1,37 +1,18 @@
package com.unciv.ui
package com.unciv.ui.trade
import com.badlogic.gdx.scenes.scene2d.Stage
import com.badlogic.gdx.scenes.scene2d.ui.Label
import com.badlogic.gdx.scenes.scene2d.ui.Table
import com.badlogic.gdx.scenes.scene2d.ui.TextButton
import com.unciv.UnCivGame
import com.unciv.logic.civilization.CivilizationInfo
import com.unciv.logic.trade.TradeLogic
import com.unciv.ui.utils.CameraStageBaseScreen
import com.unciv.ui.utils.addClickListener
import com.unciv.ui.utils.center
import com.unciv.ui.utils.tr
class TradeScreen(otherCivilization: CivilizationInfo) : CameraStageBaseScreen(){
init {
val closeButton = TextButton("Close".tr(), skin)
closeButton.addClickListener { UnCivGame.Current.setWorldScreen() }
closeButton.y = stage.height - closeButton.height - 5
stage.addActor(closeButton)
val generalTable = TradeTable(otherCivilization,stage)
generalTable.center(stage)
stage.addActor(generalTable)
}
}
class TradeTable(val otherCivilization: CivilizationInfo, stage: Stage):Table(CameraStageBaseScreen.skin){
class TradeTable(val otherCivilization: CivilizationInfo, stage: Stage): Table(CameraStageBaseScreen.skin){
var tradeLogic = TradeLogic(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
val tradeText = Label("What do you have in mind?".tr(), CameraStageBaseScreen.skin)
val offerButton = TextButton("Offer trade".tr(), CameraStageBaseScreen.skin)
@ -61,7 +42,7 @@ class TradeTable(val otherCivilization: CivilizationInfo, stage: Stage):Table(Ca
else if(offerButton.text.toString() == "Accept".tr()){
tradeLogic.acceptTrade()
tradeLogic = TradeLogic(otherCivilization)
offerColumnsTable = OfferColumnsTable(tradeLogic,stage){onChange()}
offerColumnsTable = OfferColumnsTable(tradeLogic, stage) { onChange() }
offerColumnsTableWrapper.clear()
offerColumnsTableWrapper.add(offerColumnsTable)
tradeText.setText("Pleasure doing business with you!".tr())
@ -82,39 +63,4 @@ class TradeTable(val otherCivilization: CivilizationInfo, stage: Stage):Table(Ca
tradeText.setText("What do you have in mind?".tr())
}
}
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()
}
}

View file

@ -9,10 +9,10 @@ import com.unciv.UnCivGame
import com.unciv.logic.GameSaver
import com.unciv.logic.civilization.CivilizationInfo
import com.unciv.models.gamebasics.tile.ResourceType
import com.unciv.ui.TradeScreen
import com.unciv.ui.pickerscreens.GreatPersonPickerScreen
import com.unciv.ui.pickerscreens.PolicyPickerScreen
import com.unciv.ui.pickerscreens.TechPickerScreen
import com.unciv.ui.trade.DiplomacyScreen
import com.unciv.ui.utils.*
import com.unciv.ui.worldscreen.bottombar.WorldScreenBottomBar
import com.unciv.ui.worldscreen.unit.UnitActionsTable
@ -112,12 +112,15 @@ class WorldScreen : CameraStageBaseScreen() {
private fun updateTradeButtons() {
tradeButtons.clear()
for(civ in gameInfo.civilizations.filterNot { it.isDefeated() || it.isPlayerCivilization() || it.isBarbarianCivilization() }){
if(!civInfo.diplomacy.containsKey(civ.civName)) continue
val tb = TextButton("Trade with [${civ.civName}]".tr(),skin)
tb.addClickListener { UnCivGame.Current.screen = TradeScreen(civ) }
tradeButtons.add(tb).row()
}
val btn = TextButton("Diplomacy",skin)
btn.addClickListener { UnCivGame.Current.screen = DiplomacyScreen() }
// for(civ in gameInfo.civilizations.filterNot { it.isDefeated() || it.isPlayerCivilization() || it.isBarbarianCivilization() }){
// if(!civInfo.diplomacy.containsKey(civ.civName)) continue
// val tb = TextButton("Trade with [${civ.civName}]".tr(),skin)
// tb.addClickListener { UnCivGame.Current.screen = TradeScreen(civ) }
// tradeButtons.add(tb).row()
// }
tradeButtons.add(btn)
tradeButtons.pack()
tradeButtons.y = techButton.y -20 - tradeButtons.height

View file

@ -1,5 +1,6 @@
package com.unciv.ui.worldscreen.bottombar
import com.badlogic.gdx.graphics.Color
import com.badlogic.gdx.scenes.scene2d.ui.Label
import com.badlogic.gdx.scenes.scene2d.ui.Table
import com.badlogic.gdx.scenes.scene2d.ui.TextButton
@ -116,7 +117,7 @@ class BattleTable(val worldScreen: WorldScreen): Table() {
}
row().pad(5f)
val attackButton = TextButton("Attack", skin)
val attackButton = TextButton("Attack".tr(), skin).apply { color= Color.RED }
attacker.unit.getDistanceToTiles()