Resolved #1162 - City button, resources and tech description in multiplayer now act according to the viewing civ, and not the current player - Thanks @lobraarbol!

This commit is contained in:
Yair Morgenstern
2019-10-06 19:21:47 +03:00
parent 69aecfe419
commit 3d992fc9ee
7 changed files with 27 additions and 26 deletions

View File

@ -21,8 +21,8 @@ android {
applicationId "com.unciv.app"
minSdkVersion 14
targetSdkVersion 29
versionCode 304
versionName "3.1.2"
versionCode 305
versionName "3.1.3"
}
// Had to add this crap for Travis to build, it wanted to sign the app

View File

@ -31,10 +31,10 @@ class Technology : ICivilopedia {
lineList += impimpString.tr()
}
val currentPlayerCiv = UnCivGame.Current.gameInfo.currentPlayer
val viewingCiv = UnCivGame.Current.worldScreen.viewingCiv
var enabledUnits = GameBasics.Units.values.filter {
it.requiredTech == name &&
(it.uniqueTo == null || it.uniqueTo == currentPlayerCiv)
(it.uniqueTo == null || it.uniqueTo == viewingCiv.civName)
}
val replacedUnits = enabledUnits.mapNotNull { it.replaces }
enabledUnits = enabledUnits.filter { it.name !in replacedUnits }
@ -46,7 +46,7 @@ class Technology : ICivilopedia {
var enabledBuildings = GameBasics.Buildings.values.filter {
it.requiredTech == name &&
(it.uniqueTo == null || it.uniqueTo == currentPlayerCiv)
(it.uniqueTo == null || it.uniqueTo == viewingCiv.civName)
}
val replacedBuildings = enabledBuildings.mapNotNull { it.replaces }
enabledBuildings = enabledBuildings.filter { it.name !in replacedBuildings }

View File

@ -38,7 +38,7 @@ class NewGameScreen: PickerScreen(){
rightSideButton.onClick {
if (newGameParameters.players.none { it.playerType == PlayerType.Human }) {
val noHumanPlayersPopup = PopupTable(this)
noHumanPlayersPopup.addGoodSizedLabel("No human players selected!").row()
noHumanPlayersPopup.addGoodSizedLabel("No human players selected!".tr()).row()
noHumanPlayersPopup.addCloseButton()
noHumanPlayersPopup.open()
return@onClick
@ -50,7 +50,7 @@ class NewGameScreen: PickerScreen(){
UUID.fromString(player.playerId)
} catch (ex: Exception) {
val invalidPlayerIdPopup = PopupTable(this)
invalidPlayerIdPopup.addGoodSizedLabel("Invalid player ID!").row()
invalidPlayerIdPopup.addGoodSizedLabel("Invalid player ID!".tr()).row()
invalidPlayerIdPopup.addCloseButton()
invalidPlayerIdPopup.open()
return@onClick

View File

@ -2,7 +2,6 @@ package com.unciv.ui.pickerscreens
import com.badlogic.gdx.Gdx
import com.badlogic.gdx.graphics.Color
import com.badlogic.gdx.scenes.scene2d.ui.Label
import com.badlogic.gdx.scenes.scene2d.ui.ScrollPane
import com.unciv.Constants
import com.unciv.UnCivGame
@ -13,7 +12,6 @@ import com.unciv.models.gamebasics.tech.Technology
import com.unciv.models.gamebasics.tr
import com.unciv.ui.utils.*
import java.util.*
import kotlin.collections.HashSet
class TechPickerScreen(internal val civInfo: CivilizationInfo, switchfromWorldScreen: Boolean = true, centerOnTech: Technology? = null) : PickerScreen() {

View File

@ -57,10 +57,12 @@ class CityButton(val city: CityInfo, internal val tileGroup: WorldTileGroup, ski
add(airUnitTable).row()
}
private fun belongsToViewingCiv() = city.civInfo == UnCivGame.Current.worldScreen.viewingCiv
private fun setButtonActions() {
val unitTable = tileGroup.worldScreen.bottomBar.unitTable
if (UnCivGame.Current.viewEntireMapForDebug || city.civInfo.isCurrentPlayer()) {
if (UnCivGame.Current.viewEntireMapForDebug || belongsToViewingCiv()) {
// So you can click anywhere on the button to go to the city
touchable = Touchable.childrenOnly
@ -119,7 +121,7 @@ class CityButton(val city: CityInfo, internal val tileGroup: WorldTileGroup, ski
val starImage = ImageGetter.getImage("OtherIcons/Star").apply { color = Color.LIGHT_GRAY }
iconTable.add(starImage).size(20f).pad(2f).padLeft(10f)
}
} else if (city.civInfo.isCurrentPlayer() && city.isConnectedToCapital()) {
} else if (belongsToViewingCiv() && city.isConnectedToCapital()) {
val connectionImage = ImageGetter.getStatIcon("CityConnection")
connectionImage.color = secondaryColor
iconTable.add(connectionImage).size(20f).pad(2f).padLeft(5f)
@ -131,7 +133,7 @@ class CityButton(val city: CityInfo, internal val tileGroup: WorldTileGroup, ski
iconTable.add(label).pad(10f) // sufficient horizontal padding
.fillY() // provide full-height clicking area
if (UnCivGame.Current.viewEntireMapForDebug || city.civInfo.isCurrentPlayer())
if (UnCivGame.Current.viewEntireMapForDebug || belongsToViewingCiv())
iconTable.add(getConstructionGroup(city.cityConstructions)).padRight(10f).padLeft(10f)
else if (city.civInfo.isMajorCiv()) {
val nationIcon = ImageGetter.getNationIcon(city.civInfo.nation.name)

View File

@ -86,7 +86,7 @@ open class TileGroup(var tileInfo: TileInfo, var tileSetStrings:TileSetStrings)
isTransform=false // performance helper - nothing here is rotated or scaled
}
//region init functions
private fun addCircleImage() {
circleImage.width = 50f
circleImage.height = 50f
@ -112,6 +112,7 @@ open class TileGroup(var tileInfo: TileInfo, var tileSetStrings:TileSetStrings)
crosshairImage.color = Color.WHITE.cpy().apply { a = 0.5f }
circleCrosshairFogLayerGroup.addActor(crosshairImage)
}
//endregion
fun showCrosshair() {
crosshairImage.isVisible = true
@ -430,7 +431,7 @@ open class TileGroup(var tileInfo: TileInfo, var tileSetStrings:TileSetStrings)
val shouldDisplayResource =
if(showEntireMap) tileInfo.resource!=null
else showResourcesAndImprovements
&& tileInfo.hasViewableResource(tileInfo.tileMap.gameInfo.getCurrentPlayerCivilization())
&& tileInfo.hasViewableResource(UnCivGame.Current.worldScreen.viewingCiv)
resourceImage!!.isVisible = shouldDisplayResource
}
}
@ -453,7 +454,7 @@ open class TileGroup(var tileInfo: TileInfo, var tileSetStrings:TileSetStrings)
// Instead of fading out the entire unit with its background, we just fade out its central icon,
// that way it remains much more visible on the map
if (!unit.isIdle() && unit.civInfo.isPlayerCivilization())
if (!unit.isIdle() && unit.civInfo == UnCivGame.Current.worldScreen.viewingCiv)
newImage.unitBaseImage.color.a = 0.5f
}
return newImage

View File

@ -172,7 +172,7 @@ class WorldScreen(val viewingCiv:CivilizationInfo) : CameraStageBaseScreen() {
topBar.update(viewingCiv)
updateTechButton(viewingCiv)
updateTechButton()
techPolicyandVictoryHolder.pack()
techPolicyandVictoryHolder.setPosition(10f, topBar.y - techPolicyandVictoryHolder.height - 5f)
updateDiplomacyButton(viewingCiv)
@ -242,15 +242,15 @@ class WorldScreen(val viewingCiv:CivilizationInfo) : CameraStageBaseScreen() {
diplomacyButtonWrapper.y = techPolicyandVictoryHolder.y -20 - diplomacyButtonWrapper.height
}
private fun updateTechButton(civInfo: CivilizationInfo) {
techButtonHolder.isVisible = civInfo.cities.isNotEmpty()
private fun updateTechButton() {
techButtonHolder.isVisible = viewingCiv.cities.isNotEmpty()
techButtonHolder.clearChildren()
val researchableTechs = GameBasics.Technologies.values.filter { !civInfo.tech.isResearched(it.name) && civInfo.tech.canBeResearched(it.name) }
if (civInfo.tech.currentTechnology() == null && researchableTechs.isEmpty())
civInfo.tech.techsToResearch.add(Constants.futureTech)
val researchableTechs = GameBasics.Technologies.values.filter { !viewingCiv.tech.isResearched(it.name) && viewingCiv.tech.canBeResearched(it.name) }
if (viewingCiv.tech.currentTechnology() == null && researchableTechs.isEmpty())
viewingCiv.tech.techsToResearch.add(Constants.futureTech)
if (civInfo.tech.currentTechnology() == null) {
if (viewingCiv.tech.currentTechnology() == null) {
val buttonPic = Table()
buttonPic.background = ImageGetter.getDrawable("OtherIcons/civTableBackground")
.tint(colorFromRGB(7, 46, 43))
@ -259,11 +259,11 @@ class WorldScreen(val viewingCiv:CivilizationInfo) : CameraStageBaseScreen() {
techButtonHolder.add(buttonPic)
}
else {
val currentTech = civInfo.tech.currentTechnologyName()!!
val innerButton = TechButton(currentTech,civInfo.tech)
val currentTech = viewingCiv.tech.currentTechnologyName()!!
val innerButton = TechButton(currentTech,viewingCiv.tech)
innerButton.color = colorFromRGB(7, 46, 43)
techButtonHolder.add(innerButton)
val turnsToTech = civInfo.tech.turnsToTech(currentTech)
val turnsToTech = viewingCiv.tech.turnsToTech(currentTech)
innerButton.text.setText(currentTech.tr() + "\r\n" + turnsToTech
+ (if(turnsToTech>1) " {turns}".tr() else " {turn}".tr()))
}