Disabled all (hopefully) state-changing actions when it's not the player's turn

This commit is contained in:
Yair Morgenstern
2019-08-05 06:28:39 +03:00
parent 5c02281023
commit 786c157ba9
8 changed files with 59 additions and 47 deletions

View File

@ -47,7 +47,7 @@ class UnCivGame(val version: String) : Game() {
} }
fun loadGame(gameName:String){ fun loadGame(gameName:String){
loadGame(GameSaver().loadGame( gameName)) loadGame(GameSaver().loadGame(gameName))
} }
fun startNewGame() { fun startNewGame() {

View File

@ -39,7 +39,8 @@ class PolicyPickerScreen(internal val civInfo: CivilizationInfo) : PickerScreen(
} }
else game.screen = PolicyPickerScreen(civInfo) // update policies else game.screen = PolicyPickerScreen(civInfo) // update policies
} }
if(!UnCivGame.Current.worldScreen.isPlayersTurn())
rightSideButton.disable()
topTable.row().pad(30f) topTable.row().pad(30f)

View File

@ -99,9 +99,11 @@ class TechPickerScreen(internal val civInfo: CivilizationInfo, centerOnTech: Tec
else civTech.techsToResearch = tempTechsToResearch else civTech.techsToResearch = tempTechsToResearch
game.setWorldScreen() game.setWorldScreen()
game.worldScreen.shouldUpdate=true game.worldScreen.shouldUpdate = true
dispose() dispose()
} }
if(!UnCivGame.Current.worldScreen.isPlayersTurn())
rightSideButton.disable()
displayTutorials("TechPickerScreen") displayTutorials("TechPickerScreen")

View File

@ -28,6 +28,8 @@ class DiplomacyScreen:CameraStageBaseScreen() {
val leftSideTable = Table().apply { defaults().pad(10f) } val leftSideTable = Table().apply { defaults().pad(10f) }
val rightSideTable = Table() val rightSideTable = Table()
fun isNotPlayersTurn() = !UnCivGame.Current.worldScreen.isPlayersTurn()
init { init {
onBackButtonClicked { UnCivGame.Current.setWorldScreen() } onBackButtonClicked { UnCivGame.Current.setWorldScreen() }
val splitPane = SplitPane(ScrollPane(leftSideTable), rightSideTable, false, skin) val splitPane = SplitPane(ScrollPane(leftSideTable), rightSideTable, false, skin)
@ -93,15 +95,14 @@ class DiplomacyScreen:CameraStageBaseScreen() {
val diplomacyTable = Table() val diplomacyTable = Table()
diplomacyTable.defaults().pad(10f) diplomacyTable.defaults().pad(10f)
if (otherCiv.isCityState()) {
diplomacyTable.add(otherCiv.getNation().getLeaderDisplayName().toLabel()).row() diplomacyTable.add(otherCiv.getNation().getLeaderDisplayName().toLabel()).row()
diplomacyTable.add(("Type: " + otherCiv.getCityStateType().toString()).toLabel()).row() diplomacyTable.add(("Type: " + otherCiv.getCityStateType().toString()).toLabel()).row()
diplomacyTable.add(("Influence: " + otherCivDiplomacyManager.influence.toInt()+"/30").toLabel()).row() diplomacyTable.add(("Influence: " + otherCivDiplomacyManager.influence.toInt() + "/30").toLabel()).row()
diplomacyTable.add(getRelationshipTable(otherCivDiplomacyManager)).row() diplomacyTable.add(getRelationshipTable(otherCivDiplomacyManager)).row()
val friendBonusText = when(otherCiv.getCityStateType()) { val friendBonusText = when (otherCiv.getCityStateType()) {
CityStateType.Cultured -> "Provides [" + (3 * (currentPlayerCiv.getEra().ordinal+1)).toString() + "] culture at [30] Influence" CityStateType.Cultured -> "Provides [" + (3 * (currentPlayerCiv.getEra().ordinal + 1)).toString() + "] culture at [30] Influence"
CityStateType.Maritime -> "Provides 3 food in capital and 1 food in other cities at [30] Influence" CityStateType.Maritime -> "Provides 3 food in capital and 1 food in other cities at [30] Influence"
CityStateType.Mercantile -> "Provides 3 happiness at [30] Influence" CityStateType.Mercantile -> "Provides 3 happiness at [30] Influence"
CityStateType.Militaristic -> "Provides land units every 20 turns at [30] Influence" CityStateType.Militaristic -> "Provides land units every 20 turns at [30] Influence"
@ -113,30 +114,27 @@ class DiplomacyScreen:CameraStageBaseScreen() {
friendBonusLabel.setFontColor(Color.GREEN) friendBonusLabel.setFontColor(Color.GREEN)
val turnsToRelationshipChange = otherCivDiplomacyManager.influence.toInt() - 30 + 1 val turnsToRelationshipChange = otherCivDiplomacyManager.influence.toInt() - 30 + 1
diplomacyTable.add("Relationship changes in another [$turnsToRelationshipChange] turns".toLabel()).row() diplomacyTable.add("Relationship changes in another [$turnsToRelationshipChange] turns".toLabel()).row()
} } else
else
friendBonusLabel.setFontColor(Color.GRAY) friendBonusLabel.setFontColor(Color.GRAY)
} else {
diplomacyTable.add(otherCiv.getNation().getLeaderDisplayName().toLabel())
}
diplomacyTable.addSeparator() diplomacyTable.addSeparator()
val giftAmount = 250 val giftAmount = 250
val influenceAmount = giftAmount/10 val influenceAmount = giftAmount / 10
val giftButton = TextButton("Gift [$giftAmount] gold (+[$influenceAmount] influence)".tr(), skin) val giftButton = TextButton("Gift [$giftAmount] gold (+[$influenceAmount] influence)".tr(), skin)
giftButton.onClick{ giftButton.onClick {
currentPlayerCiv.giveGoldGift(otherCiv,giftAmount) currentPlayerCiv.giveGoldGift(otherCiv, giftAmount)
updateRightSide(otherCiv) updateRightSide(otherCiv)
} }
diplomacyTable.add(giftButton).row() diplomacyTable.add(giftButton).row()
if (currentPlayerCiv.gold < giftAmount ) giftButton.disable() if (currentPlayerCiv.gold < giftAmount || isNotPlayersTurn()) giftButton.disable()
val diplomacyManager = currentPlayerCiv.getDiplomacyManager(otherCiv) val diplomacyManager = currentPlayerCiv.getDiplomacyManager(otherCiv)
if (currentPlayerCiv.isAtWarWith(otherCiv)) { if (currentPlayerCiv.isAtWarWith(otherCiv)) {
val PeaceButton = TextButton("Negotiate Peace".tr(), skin) val peaceButton = TextButton("Negotiate Peace".tr(), skin)
PeaceButton.onClick { peaceButton.onClick {
YesNoPopupTable("Peace with [${otherCiv.civName}]?".tr(), { YesNoPopupTable("Peace with [${otherCiv.civName}]?".tr(), {
val tradeLogic = TradeLogic(currentPlayerCiv, otherCiv) val tradeLogic = TradeLogic(currentPlayerCiv, otherCiv)
tradeLogic.currentTrade.ourOffers.add(TradeOffer(Constants.peaceTreaty, TradeType.Treaty, 30)) tradeLogic.currentTrade.ourOffers.add(TradeOffer(Constants.peaceTreaty, TradeType.Treaty, 30))
@ -145,9 +143,11 @@ class DiplomacyScreen:CameraStageBaseScreen() {
updateLeftSideTable() updateLeftSideTable()
}, this) }, this)
} }
diplomacyTable.add(PeaceButton).row() diplomacyTable.add(peaceButton).row()
if(isNotPlayersTurn()) peaceButton.disable()
} else { } else {
val declareWarButton = getDeclareWarButton(diplomacyManager, otherCiv) val declareWarButton = getDeclareWarButton(diplomacyManager, otherCiv)
if(isNotPlayersTurn()) declareWarButton.disable()
diplomacyTable.add(declareWarButton).row() diplomacyTable.add(declareWarButton).row()
} }
@ -173,6 +173,7 @@ class DiplomacyScreen:CameraStageBaseScreen() {
val tradeButton = TextButton("Trade".tr(), skin) val tradeButton = TextButton("Trade".tr(), skin)
tradeButton.onClick { setTrade(otherCiv) } tradeButton.onClick { setTrade(otherCiv) }
diplomacyTable.add(tradeButton).row() diplomacyTable.add(tradeButton).row()
if(isNotPlayersTurn()) tradeButton.disable()
} }
else{ else{
val negotiatePeaceButton = TextButton("Negotiate Peace".tr(),skin) val negotiatePeaceButton = TextButton("Negotiate Peace".tr(),skin)
@ -183,7 +184,7 @@ class DiplomacyScreen:CameraStageBaseScreen() {
tradeTable.tradeLogic.currentTrade.ourOffers.add(peaceTreaty) tradeTable.tradeLogic.currentTrade.ourOffers.add(peaceTreaty)
tradeTable.offerColumnsTable.update() tradeTable.offerColumnsTable.update()
} }
if (otherCivDiplomacyManager.hasFlag(DiplomacyFlags.DeclaredWar)) if (isNotPlayersTurn() || otherCivDiplomacyManager.hasFlag(DiplomacyFlags.DeclaredWar))
negotiatePeaceButton.disable() // Can't trade for 10 turns after war was declared negotiatePeaceButton.disable() // Can't trade for 10 turns after war was declared
diplomacyTable.add(negotiatePeaceButton).row() diplomacyTable.add(negotiatePeaceButton).row()
@ -203,6 +204,7 @@ class DiplomacyScreen:CameraStageBaseScreen() {
setRightSideFlavorText(otherCiv,"May our nations forever remain united!","Indeed!") setRightSideFlavorText(otherCiv,"May our nations forever remain united!","Indeed!")
} }
diplomacyTable.add(declareFriendshipButton).row() diplomacyTable.add(declareFriendshipButton).row()
if(isNotPlayersTurn()) declareFriendshipButton.disable()
} }
if(!diplomacyManager.hasFlag(DiplomacyFlags.Denunceation) if(!diplomacyManager.hasFlag(DiplomacyFlags.Denunceation)
@ -213,10 +215,12 @@ class DiplomacyScreen:CameraStageBaseScreen() {
setRightSideFlavorText(otherCiv,"We will remember this.","Very well.") setRightSideFlavorText(otherCiv,"We will remember this.","Very well.")
} }
diplomacyTable.add(denounceButton).row() diplomacyTable.add(denounceButton).row()
if(isNotPlayersTurn()) denounceButton.disable()
} }
val declareWarButton = getDeclareWarButton(diplomacyManager, otherCiv) val declareWarButton = getDeclareWarButton(diplomacyManager, otherCiv)
diplomacyTable.add(declareWarButton).row() diplomacyTable.add(declareWarButton).row()
if(isNotPlayersTurn()) declareWarButton.disable()
} }
val demandsButton = TextButton("Demands".tr(),skin) val demandsButton = TextButton("Demands".tr(),skin)
@ -225,6 +229,7 @@ class DiplomacyScreen:CameraStageBaseScreen() {
rightSideTable.add(getDemandsTable(currentPlayerCiv,otherCiv)) rightSideTable.add(getDemandsTable(currentPlayerCiv,otherCiv))
} }
diplomacyTable.add(demandsButton).row() diplomacyTable.add(demandsButton).row()
if(isNotPlayersTurn()) demandsButton.disable()
if(!otherCiv.isPlayerCivilization()) { // human players make their own choices if(!otherCiv.isPlayerCivilization()) { // human players make their own choices
diplomacyTable.add(getRelationshipTable(otherCivDiplomacyManager)).row() diplomacyTable.add(getRelationshipTable(otherCivDiplomacyManager)).row()

View File

@ -53,6 +53,7 @@ class TileMapHolder(internal val worldScreen: WorldScreen, internal val tileMap:
onTileClicked(tileGroup.tileInfo) onTileClicked(tileGroup.tileInfo)
} }
override fun longPress(actor: Actor?, x: Float, y: Float): Boolean { override fun longPress(actor: Actor?, x: Float, y: Float): Boolean {
if(!worldScreen.isPlayersTurn()) return false // no long click when it's not your turn
return onTileLongClicked(tileGroup.tileInfo) return onTileLongClicked(tileGroup.tileInfo)
} }
@ -105,6 +106,7 @@ class TileMapHolder(internal val worldScreen: WorldScreen, internal val tileMap:
val newSelectedUnit = unitTable.selectedUnit val newSelectedUnit = unitTable.selectedUnit
if (previousSelectedUnit != null && previousSelectedUnit.getTile() != tileInfo if (previousSelectedUnit != null && previousSelectedUnit.getTile() != tileInfo
&& worldScreen.isPlayersTurn()
&& previousSelectedUnit.movement.canMoveTo(tileInfo) && previousSelectedUnit.movement.canReach(tileInfo)) { && previousSelectedUnit.movement.canMoveTo(tileInfo) && previousSelectedUnit.movement.canReach(tileInfo)) {
// this can take a long time, because of the unit-to-tile calculation needed, so we put it in a different thread // this can take a long time, because of the unit-to-tile calculation needed, so we put it in a different thread
addTileOverlaysWithUnitMovement(previousSelectedUnit, tileInfo) addTileOverlaysWithUnitMovement(previousSelectedUnit, tileInfo)

View File

@ -29,6 +29,7 @@ import com.unciv.ui.worldscreen.unit.UnitActionsTable
class WorldScreen(val currentPlayerCiv:CivilizationInfo) : CameraStageBaseScreen() { class WorldScreen(val currentPlayerCiv:CivilizationInfo) : CameraStageBaseScreen() {
val gameInfo = game.gameInfo val gameInfo = game.gameInfo
fun isPlayersTurn() = currentPlayerCiv == gameInfo.currentPlayerCiv
val tileMapHolder: TileMapHolder = TileMapHolder(this, gameInfo.tileMap) val tileMapHolder: TileMapHolder = TileMapHolder(this, gameInfo.tileMap)
val minimapWrapper = MinimapHolder(tileMapHolder) val minimapWrapper = MinimapHolder(tileMapHolder)

View File

@ -158,7 +158,7 @@ class BattleTable(val worldScreen: WorldScreen): Table() {
} }
} }
if (attackableEnemy == null) { if (!worldScreen.isPlayersTurn() || attackableEnemy == null) {
attackButton.disable() attackButton.disable()
attackButton.label.color = Color.GRAY attackButton.label.color = Color.GRAY
} }

View File

@ -59,6 +59,7 @@ class UnitActionsTable(val worldScreen: WorldScreen) : Table(){
fun update(unit: MapUnit?){ fun update(unit: MapUnit?){
clear() clear()
if (unit == null) return if (unit == null) return
if(!worldScreen.isPlayersTurn()) return // No actions when it's not your turn!
for (button in UnitActions().getUnitActions(unit, worldScreen).map { getUnitActionButton(it) }) for (button in UnitActions().getUnitActions(unit, worldScreen).map { getUnitActionButton(it) })
add(button).colspan(2).pad(5f).row() add(button).colspan(2).pad(5f).row()
pack() pack()