Special diplomacy window for city states.

This commit is contained in:
Duan Tao
2019-05-05 20:04:33 +08:00
committed by Yair Morgenstern
parent 1865f53c42
commit 4d3e04baa0
7 changed files with 35 additions and 10 deletions

View File

@ -133,6 +133,7 @@ class CivilizationInfo {
fun isCurrentPlayer() = gameInfo.getCurrentPlayerCivilization()==this
fun isBarbarianCivilization() = civName=="Barbarians"
fun isCityState(): Boolean = getNation().isCityState()
fun getCityStateType(): CityStateType = getNation().cityStateType!!
fun isMajorCiv() = !isBarbarianCivilization() && !isCityState()
fun getStatsForNextTurn():Stats = getStatMapForNextTurn().values.toList().reduce{a,b->a+b}

View File

@ -53,7 +53,7 @@ class DiplomacyManager() {
* As for why it's String and not DiplomaticModifier see FlagsCountdown comment */
var diplomaticModifiers = HashMap<String,Float>()
/** For city states */
/** For city-states */
var influence = 0f
fun clone(): DiplomacyManager {

View File

@ -211,7 +211,7 @@ class Building : NamedStats(), IConstruction{
return "Wonder is being built elsewhere"
if(civInfo.isCityState())
return "No world wonders for city state"
return "No world wonders for city-states"
}
@ -225,7 +225,7 @@ class Building : NamedStats(), IConstruction{
if (civInfo.cities.any {it!=construction.cityInfo && it.cityConstructions.isBeingConstructed(name) })
return "Wonder is being built elsewhere"
if(civInfo.isCityState())
return "No world wonders for city state"
return "No world wonders for city-states"
}
if (requiredBuilding != null && !construction.containsBuildingOrEquivalent(requiredBuilding!!))

View File

@ -36,7 +36,7 @@ class Nation : INamed {
return colorFromRGB(secondaryColor!![0], secondaryColor!![1], secondaryColor!![2])
}
fun isCityState()=cityStateType != null
fun isCityState()= cityStateType != null
lateinit var cities: List<String>
}

View File

@ -132,7 +132,7 @@ class BaseUnit : INamed, IConstruction, ICivilopedia {
if (uniqueTo!=null && uniqueTo!=civInfo.civName) return "Unique to $uniqueTo"
if (GameBasics.Units.values.any { it.uniqueTo==civInfo.civName && it.replaces==name }) return "Our unique unit replaces this"
if (requiredResource!=null && !civInfo.hasResource(requiredResource!!)) return "Requires $requiredResource"
if (name == Constants.settler && civInfo.isCityState()) return "No settler for city state"
if (name == Constants.settler && civInfo.isCityState()) return "No settler for city-states"
return ""
}

View File

@ -6,13 +6,16 @@ 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.CityStateType
import com.unciv.logic.civilization.CivilizationInfo
import com.unciv.logic.civilization.diplomacy.DiplomaticModifiers
import com.unciv.logic.civilization.diplomacy.RelationshipLevel
import com.unciv.models.gamebasics.tr
import com.unciv.models.stats.Stat
import com.unciv.ui.utils.*
import com.unciv.ui.worldscreen.optionstable.PopupTable
import com.unciv.ui.worldscreen.optionstable.YesNoPopupTable
import javax.xml.soap.Text
class DiplomacyScreen:CameraStageBaseScreen() {
@ -68,20 +71,41 @@ class DiplomacyScreen:CameraStageBaseScreen() {
return tradeTable
}
fun giveGoldGift(otherCiv: CivilizationInfo) {
val currentPlayerCiv = UnCivGame.Current.gameInfo.getCurrentPlayerCivilization()
currentPlayerCiv.gold -= 50
otherCiv.getDiplomacyManager(currentPlayerCiv).influence += 5
rightSideTable.clear()
rightSideTable.add(getDiplomacyTable(otherCiv))
}
private fun getDiplomacyTable(otherCiv: CivilizationInfo): Table {
val currentPlayerCiv = UnCivGame.Current.gameInfo.getCurrentPlayerCivilization()
val diplomacyTable = Table()
diplomacyTable.defaults().pad(10f)
val leaderName: String
if (otherCiv.isCityState()) {
leaderName = "City state [" + otherCiv.civName + "]"
leaderName = "City-state of [" + otherCiv.civName + "]"
diplomacyTable.add(leaderName.toLabel()).row()
diplomacyTable.add(("Type : " + otherCiv.getCityStateType().toString()).toLabel()).row()
diplomacyTable.add(("Influence : " + otherCiv.getDiplomacyManager(currentPlayerCiv).influence.toInt().toString()).toLabel()).row()
if (otherCiv.getDiplomacyManager(currentPlayerCiv).influence > 60) {
if (otherCiv.getCityStateType() == CityStateType.Cultured) {
diplomacyTable.add(("Providing " + (5.0f * currentPlayerCiv.getEra().ordinal).toString() + " culture each turn").toLabel())
}
}
} else {
leaderName = "[" + otherCiv.getNation().leaderName + "] of [" + otherCiv.civName + "]"
diplomacyTable.add(leaderName.toLabel())
}
diplomacyTable.add(leaderName.toLabel())
diplomacyTable.addSeparator()
if(!otherCiv.isCityState()) {
if(otherCiv.isCityState()) {
val giftButton = TextButton("Give 50 gold".tr(), skin)
giftButton.onClick{ giveGoldGift(otherCiv) }
diplomacyTable.add(giftButton).row()
if (currentPlayerCiv.gold < 1) giftButton.disable()
} else {
val tradeButton = TextButton("Trade".tr(), skin)
tradeButton.onClick { setTrade(otherCiv) }
diplomacyTable.add(tradeButton).row()
@ -104,7 +128,7 @@ class DiplomacyScreen:CameraStageBaseScreen() {
val responsePopup = PopupTable(this)
val otherCivLeaderName: String
if (otherCiv.isCityState()) {
otherCivLeaderName = "City state [" + otherCiv.civName + "]"
otherCivLeaderName = "City-state [" + otherCiv.civName + "]"
} else {
otherCivLeaderName = "[" + otherCiv.getNation().leaderName + "] of [" + otherCiv.civName + "]"
}

View File

@ -21,7 +21,7 @@ class AlertPopup(val worldScreen: WorldScreen, val popupAlert: PopupAlert): Popu
fun addLeaderName(translatedNation: Nation){
val otherCivLeaderName: String
if (translatedNation.isCityState()) {
otherCivLeaderName = "City state [${translatedNation.getNameTranslation()}]".tr()
otherCivLeaderName = "City-state [${translatedNation.getNameTranslation()}]".tr()
} else {
otherCivLeaderName = "[${translatedNation.leaderName}] of [${translatedNation.getNameTranslation()}]".tr()
}