mirror of
https://github.com/yairm210/Unciv.git
synced 2025-07-04 15:27:50 +07:00
WorldScreen now accepts player as parameter - important for multiplayer so people could see their own map even when it's someone else's turn
This commit is contained in:
@ -2,6 +2,7 @@ package com.unciv
|
||||
|
||||
import com.badlogic.gdx.Game
|
||||
import com.badlogic.gdx.Gdx
|
||||
import com.badlogic.gdx.Input
|
||||
import com.unciv.logic.GameInfo
|
||||
import com.unciv.logic.GameSaver
|
||||
import com.unciv.models.gamebasics.GameBasics
|
||||
@ -26,7 +27,7 @@ class UnCivGame(val version: String) : Game() {
|
||||
|
||||
override fun create() {
|
||||
Current = this
|
||||
Gdx.input.isCatchBackKey=true
|
||||
Gdx.input.setCatchKey(Input.Keys.BACK, true)
|
||||
GameBasics.run { } // just to initialize the GameBasics
|
||||
settings = GameSaver().getGeneralSettings()
|
||||
if (GameSaver().getSave("Autosave").exists()) {
|
||||
@ -41,7 +42,7 @@ class UnCivGame(val version: String) : Game() {
|
||||
|
||||
fun loadGame(gameInfo:GameInfo){
|
||||
this.gameInfo = gameInfo
|
||||
worldScreen = WorldScreen()
|
||||
worldScreen = WorldScreen(gameInfo.currentPlayerCiv)
|
||||
setWorldScreen()
|
||||
}
|
||||
|
||||
@ -53,7 +54,7 @@ class UnCivGame(val version: String) : Game() {
|
||||
val newGame = GameStarter().startNewGame(GameParameters().apply { difficulty="Chieftain" })
|
||||
gameInfo = newGame
|
||||
|
||||
worldScreen = WorldScreen()
|
||||
worldScreen = WorldScreen(gameInfo.currentPlayerCiv)
|
||||
setWorldScreen()
|
||||
}
|
||||
|
||||
@ -76,7 +77,7 @@ class UnCivGame(val version: String) : Game() {
|
||||
return create()
|
||||
|
||||
if(::worldScreen.isInitialized) worldScreen.dispose() // I hope this will solve some of the many OuOfMemory exceptions...
|
||||
worldScreen = WorldScreen()
|
||||
worldScreen = WorldScreen(gameInfo.currentPlayerCiv)
|
||||
setWorldScreen()
|
||||
}
|
||||
|
||||
|
@ -4,6 +4,7 @@ import com.badlogic.gdx.math.Vector2
|
||||
import java.util.*
|
||||
import kotlin.math.abs
|
||||
import kotlin.math.max
|
||||
import kotlin.math.sqrt
|
||||
|
||||
class HexMath {
|
||||
|
||||
@ -24,8 +25,8 @@ class HexMath {
|
||||
|
||||
fun hex2WorldCoords(hexCoord: Vector2): Vector2 {
|
||||
// Distance between cells = 2* normal of triangle = 2* (sqrt(3)/2) = sqrt(3)
|
||||
val xVector = getVectorByClockHour(10).scl(Math.sqrt(3.0).toFloat())
|
||||
val yVector = getVectorByClockHour(2).scl(Math.sqrt(3.0).toFloat())
|
||||
val xVector = getVectorByClockHour(10).scl(sqrt(3.0).toFloat())
|
||||
val yVector = getVectorByClockHour(2).scl(sqrt(3.0).toFloat())
|
||||
return xVector.scl(hexCoord.x).add(yVector.scl(hexCoord.y))
|
||||
}
|
||||
|
||||
|
@ -16,13 +16,19 @@ import com.unciv.models.stats.Stats
|
||||
|
||||
class CityStats {
|
||||
|
||||
@Transient var baseStatList = LinkedHashMap<String, Stats>()
|
||||
@Transient var statPercentBonusList = LinkedHashMap<String, Stats>()
|
||||
@Transient var happinessList = LinkedHashMap<String, Float>()
|
||||
@Transient var foodEaten=0f
|
||||
@Transient
|
||||
var baseStatList = LinkedHashMap<String, Stats>()
|
||||
@Transient
|
||||
var statPercentBonusList = LinkedHashMap<String, Stats>()
|
||||
@Transient
|
||||
var happinessList = LinkedHashMap<String, Float>()
|
||||
@Transient
|
||||
var foodEaten = 0f
|
||||
|
||||
@Transient var currentCityStats: Stats = Stats() // This is so we won't have to calculate this multiple times - takes a lot of time, especially on phones
|
||||
@Transient lateinit var cityInfo: CityInfo
|
||||
@Transient
|
||||
var currentCityStats: Stats = Stats() // This is so we won't have to calculate this multiple times - takes a lot of time, especially on phones
|
||||
@Transient
|
||||
lateinit var cityInfo: CityInfo
|
||||
|
||||
//region pure fuctions
|
||||
private fun getStatsFromTiles(): Stats {
|
||||
@ -334,8 +340,10 @@ class CityStats {
|
||||
val newBaseStatList = LinkedHashMap<String, Stats>() // we don't edit the existing baseStatList directly, in order to avoid concurrency exceptions
|
||||
val civInfo = cityInfo.civInfo
|
||||
|
||||
newBaseStatList["Population"] = Stats().add(Stat.Science, cityInfo.population.population.toFloat())
|
||||
.add(Stat.Production, cityInfo.population.getFreePopulation().toFloat())
|
||||
newBaseStatList["Population"] = Stats().apply {
|
||||
science = cityInfo.population.population.toFloat()
|
||||
production = cityInfo.population.getFreePopulation().toFloat()
|
||||
}
|
||||
newBaseStatList["Tile yields"] = getStatsFromTiles()
|
||||
newBaseStatList["Specialists"] = getStatsFromSpecialists(cityInfo.population.specialists, civInfo.policies.adoptedPolicies)
|
||||
newBaseStatList["Trade routes"] = getStatsFromTradeRoute()
|
||||
@ -347,6 +355,7 @@ class CityStats {
|
||||
baseStatList = newBaseStatList
|
||||
}
|
||||
|
||||
|
||||
fun updateStatPercentBonusList(){
|
||||
val newStatPercentBonusList = LinkedHashMap<String,Stats>()
|
||||
newStatPercentBonusList["Golden Age"]=getStatPercentBonusesFromGoldenAge(cityInfo.civInfo.goldenAges.isGoldenAge())
|
||||
|
@ -308,7 +308,7 @@ class NewGameScreen: PickerScreen(){
|
||||
override fun render(delta: Float) {
|
||||
if(newGame!=null){
|
||||
game.gameInfo=newGame!!
|
||||
game.worldScreen = WorldScreen()
|
||||
game.worldScreen = WorldScreen(newGame!!.currentPlayerCiv)
|
||||
game.setWorldScreen()
|
||||
}
|
||||
super.render(delta)
|
||||
|
@ -271,14 +271,14 @@ open class TileGroup(var tileInfo: TileInfo, var tileSetStrings:TileSetStrings)
|
||||
|
||||
val civColor = tileInfo.getOwner()!!.getNation().getColor()
|
||||
for (neighbor in tileInfo.neighbors) {
|
||||
val neigborOwner = neighbor.getOwner()
|
||||
if (neigborOwner == tileOwner && borderImages.containsKey(neighbor)) // the neighbor used to not belong to us, but now it's ours
|
||||
val neighborOwner = neighbor.getOwner()
|
||||
if (neighborOwner == tileOwner && borderImages.containsKey(neighbor)) // the neighbor used to not belong to us, but now it's ours
|
||||
{
|
||||
for (image in borderImages[neighbor]!!)
|
||||
image.remove()
|
||||
borderImages.remove(neighbor)
|
||||
}
|
||||
if (neigborOwner != tileOwner && !borderImages.containsKey(neighbor)) { // there should be a border here but there isn't
|
||||
if (neighborOwner != tileOwner && !borderImages.containsKey(neighbor)) { // there should be a border here but there isn't
|
||||
|
||||
val relativeHexPosition = tileInfo.position.cpy().sub(neighbor.position)
|
||||
val relativeWorldPosition = HexMath().hex2WorldCoords(relativeHexPosition)
|
||||
|
@ -16,7 +16,7 @@ class PlayerReadyScreen(currentPlayerCiv: CivilizationInfo) : CameraStageBaseScr
|
||||
.setFontColor(currentPlayerCiv.getNation().getSecondaryColor()))
|
||||
|
||||
table.onClick {
|
||||
UnCivGame.Current.worldScreen = WorldScreen().apply {
|
||||
UnCivGame.Current.worldScreen = WorldScreen(currentPlayerCiv).apply {
|
||||
shouldUpdate = true
|
||||
}
|
||||
UnCivGame.Current.setWorldScreen()
|
||||
|
@ -27,9 +27,8 @@ import com.unciv.ui.worldscreen.bottombar.BattleTable
|
||||
import com.unciv.ui.worldscreen.bottombar.WorldScreenBottomBar
|
||||
import com.unciv.ui.worldscreen.unit.UnitActionsTable
|
||||
|
||||
class WorldScreen : CameraStageBaseScreen() {
|
||||
class WorldScreen(val currentPlayerCiv:CivilizationInfo) : CameraStageBaseScreen() {
|
||||
val gameInfo = game.gameInfo
|
||||
internal val currentPlayerCiv: CivilizationInfo = gameInfo.getCurrentPlayerCivilization()
|
||||
|
||||
val tileMapHolder: TileMapHolder = TileMapHolder(this, gameInfo.tileMap)
|
||||
val minimapWrapper = MinimapHolder(tileMapHolder)
|
||||
@ -319,7 +318,7 @@ class WorldScreen : CameraStageBaseScreen() {
|
||||
override fun resize(width: Int, height: Int) {
|
||||
if (stage.viewport.screenWidth != width || stage.viewport.screenHeight != height) {
|
||||
super.resize(width, height)
|
||||
game.worldScreen = WorldScreen() // start over.
|
||||
game.worldScreen = WorldScreen(currentPlayerCiv) // start over.
|
||||
game.setWorldScreen()
|
||||
}
|
||||
}
|
||||
|
@ -28,7 +28,7 @@ class Language(val language:String){
|
||||
}
|
||||
}
|
||||
|
||||
class WorldScreenOptionsTable(screen:WorldScreen) : PopupTable(screen){
|
||||
class WorldScreenOptionsTable(val worldScreen:WorldScreen) : PopupTable(worldScreen){
|
||||
var selectedLanguage: String = "English"
|
||||
|
||||
init {
|
||||
@ -142,7 +142,7 @@ class WorldScreenOptionsTable(screen:WorldScreen) : PopupTable(screen){
|
||||
override fun changed(event: ChangeEvent?, actor: Actor?) {
|
||||
UnCivGame.Current.settings.resolution = resolutionSelectBox.selected
|
||||
UnCivGame.Current.settings.save()
|
||||
UnCivGame.Current.worldScreen = WorldScreen()
|
||||
UnCivGame.Current.worldScreen = WorldScreen(worldScreen.currentPlayerCiv)
|
||||
UnCivGame.Current.setWorldScreen()
|
||||
WorldScreenOptionsTable(UnCivGame.Current.worldScreen)
|
||||
}
|
||||
@ -165,7 +165,7 @@ class WorldScreenOptionsTable(screen:WorldScreen) : PopupTable(screen){
|
||||
override fun changed(event: ChangeEvent?, actor: Actor?) {
|
||||
UnCivGame.Current.settings.tileSet = tileSetSelectBox.selected
|
||||
UnCivGame.Current.settings.save()
|
||||
UnCivGame.Current.worldScreen = WorldScreen()
|
||||
UnCivGame.Current.worldScreen = WorldScreen(worldScreen.currentPlayerCiv)
|
||||
UnCivGame.Current.setWorldScreen()
|
||||
WorldScreenOptionsTable(UnCivGame.Current.worldScreen)
|
||||
}
|
||||
@ -248,7 +248,7 @@ class WorldScreenOptionsTable(screen:WorldScreen) : PopupTable(screen){
|
||||
|
||||
CameraStageBaseScreen.resetFonts()
|
||||
|
||||
UnCivGame.Current.worldScreen = WorldScreen()
|
||||
UnCivGame.Current.worldScreen = WorldScreen(worldScreen.currentPlayerCiv)
|
||||
UnCivGame.Current.setWorldScreen()
|
||||
WorldScreenOptionsTable(UnCivGame.Current.worldScreen)
|
||||
}
|
||||
|
Reference in New Issue
Block a user