mirror of
https://github.com/yairm210/Unciv.git
synced 2025-07-16 02:40:41 +07:00
Resolved #3600 - multiplayer game reloading and screen resize no longer reset map zoom and position
This commit is contained in:
1
.gitignore
vendored
1
.gitignore
vendored
@ -138,3 +138,4 @@ android/assets/mods/
|
|||||||
android/assets/SaveFiles/
|
android/assets/SaveFiles/
|
||||||
android/assets/GameSettingsOld.json
|
android/assets/GameSettingsOld.json
|
||||||
android/assets/scenarios/
|
android/assets/scenarios/
|
||||||
|
android/assets/MultiplayerGames/
|
||||||
|
@ -129,10 +129,6 @@ class UncivGame(parameters: UncivGameParameters) : Game() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun loadGame(gameName: String) {
|
|
||||||
loadGame(GameSaver.loadGameByName(gameName))
|
|
||||||
}
|
|
||||||
|
|
||||||
fun startMusic() {
|
fun startMusic() {
|
||||||
if (settings.musicVolume < 0.01) return
|
if (settings.musicVolume < 0.01) return
|
||||||
|
|
||||||
|
@ -14,6 +14,7 @@ import com.badlogic.gdx.scenes.scene2d.ui.Table
|
|||||||
import com.badlogic.gdx.scenes.scene2d.ui.TextButton
|
import com.badlogic.gdx.scenes.scene2d.ui.TextButton
|
||||||
import com.badlogic.gdx.utils.Align
|
import com.badlogic.gdx.utils.Align
|
||||||
import com.unciv.Constants
|
import com.unciv.Constants
|
||||||
|
import com.unciv.logic.GameInfo
|
||||||
import com.unciv.logic.GameSaver
|
import com.unciv.logic.GameSaver
|
||||||
import com.unciv.logic.civilization.CivilizationInfo
|
import com.unciv.logic.civilization.CivilizationInfo
|
||||||
import com.unciv.logic.civilization.diplomacy.DiplomaticStatus
|
import com.unciv.logic.civilization.diplomacy.DiplomaticStatus
|
||||||
@ -44,7 +45,7 @@ class WorldScreen(val viewingCiv:CivilizationInfo) : CameraStageBaseScreen() {
|
|||||||
|
|
||||||
var isPlayersTurn = viewingCiv == gameInfo.currentPlayerCiv // todo this should be updated when passing turns
|
var isPlayersTurn = viewingCiv == gameInfo.currentPlayerCiv // todo this should be updated when passing turns
|
||||||
var selectedCiv = viewingCiv // Selected civilization, used in spectator and replay mode, equals viewingCiv in ordinary games
|
var selectedCiv = viewingCiv // Selected civilization, used in spectator and replay mode, equals viewingCiv in ordinary games
|
||||||
var fogOfWar = true
|
private var fogOfWar = true
|
||||||
val canChangeState = isPlayersTurn && !viewingCiv.isSpectator()
|
val canChangeState = isPlayersTurn && !viewingCiv.isSpectator()
|
||||||
private var waitingForAutosave = false
|
private var waitingForAutosave = false
|
||||||
|
|
||||||
@ -143,7 +144,7 @@ class WorldScreen(val viewingCiv:CivilizationInfo) : CameraStageBaseScreen() {
|
|||||||
if (gameInfo.gameParameters.isOnlineMultiplayer && !gameInfo.isUpToDate)
|
if (gameInfo.gameParameters.isOnlineMultiplayer && !gameInfo.isUpToDate)
|
||||||
isPlayersTurn = false // until we're up to date, don't let the player do anything
|
isPlayersTurn = false // until we're up to date, don't let the player do anything
|
||||||
|
|
||||||
if (gameInfo.gameParameters.isOnlineMultiplayer && !isPlayersTurn) {
|
if (gameInfo.gameParameters.isOnlineMultiplayer && !isPlayersTurn && !gameInfo.isUpToDate) {
|
||||||
// restart the timer
|
// restart the timer
|
||||||
stopMultiPlayerRefresher()
|
stopMultiPlayerRefresher()
|
||||||
|
|
||||||
@ -249,7 +250,7 @@ class WorldScreen(val viewingCiv:CivilizationInfo) : CameraStageBaseScreen() {
|
|||||||
} else { //else we found it is the player's turn again, turn off polling and load turn
|
} else { //else we found it is the player's turn again, turn off polling and load turn
|
||||||
stopMultiPlayerRefresher()
|
stopMultiPlayerRefresher()
|
||||||
latestGame.isUpToDate = true
|
latestGame.isUpToDate = true
|
||||||
Gdx.app.postRunnable { game.loadGame(latestGame) }
|
Gdx.app.postRunnable { createNewWorldScreen(latestGame) }
|
||||||
}
|
}
|
||||||
|
|
||||||
} catch (ex: Exception) {
|
} catch (ex: Exception) {
|
||||||
@ -446,11 +447,11 @@ class WorldScreen(val viewingCiv:CivilizationInfo) : CameraStageBaseScreen() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun updateSelectedCiv() {
|
private fun updateSelectedCiv() {
|
||||||
if (bottomUnitTable.selectedUnit != null)
|
when {
|
||||||
selectedCiv = bottomUnitTable.selectedUnit!!.civInfo
|
bottomUnitTable.selectedUnit != null -> selectedCiv = bottomUnitTable.selectedUnit!!.civInfo
|
||||||
else if (bottomUnitTable.selectedCity != null)
|
bottomUnitTable.selectedCity != null -> selectedCiv = bottomUnitTable.selectedCity!!.civInfo
|
||||||
selectedCiv = bottomUnitTable.selectedCity!!.civInfo
|
else -> viewingCiv
|
||||||
else viewingCiv
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun createFogOfWarButton(): TextButton {
|
private fun createFogOfWarButton(): TextButton {
|
||||||
@ -479,6 +480,24 @@ class WorldScreen(val viewingCiv:CivilizationInfo) : CameraStageBaseScreen() {
|
|||||||
return nextTurnButton
|
return nextTurnButton
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
fun createNewWorldScreen(gameInfo:GameInfo) {
|
||||||
|
|
||||||
|
game.gameInfo = gameInfo
|
||||||
|
val newWorldScreen = WorldScreen(gameInfo.getPlayerToViewAs())
|
||||||
|
newWorldScreen.mapHolder.scrollX = mapHolder.scrollX
|
||||||
|
newWorldScreen.mapHolder.scrollY = mapHolder.scrollY
|
||||||
|
newWorldScreen.mapHolder.scaleX = mapHolder.scaleX
|
||||||
|
newWorldScreen.mapHolder.scaleY = mapHolder.scaleY
|
||||||
|
newWorldScreen.mapHolder.updateVisualScroll()
|
||||||
|
|
||||||
|
newWorldScreen.selectedCiv = gameInfo.getCivilization(selectedCiv.civName)
|
||||||
|
newWorldScreen.fogOfWar = fogOfWar
|
||||||
|
|
||||||
|
game.worldScreen = newWorldScreen
|
||||||
|
game.setWorldScreen()
|
||||||
|
}
|
||||||
|
|
||||||
private fun nextTurn() {
|
private fun nextTurn() {
|
||||||
isPlayersTurn = false
|
isPlayersTurn = false
|
||||||
shouldUpdate = true
|
shouldUpdate = true
|
||||||
@ -518,26 +537,12 @@ class WorldScreen(val viewingCiv:CivilizationInfo) : CameraStageBaseScreen() {
|
|||||||
// do this on main thread - it's the only one that has a GL context to create images from
|
// do this on main thread - it's the only one that has a GL context to create images from
|
||||||
Gdx.app.postRunnable {
|
Gdx.app.postRunnable {
|
||||||
|
|
||||||
fun createNewWorldScreen() {
|
|
||||||
val newWorldScreen = WorldScreen(gameInfoClone.getPlayerToViewAs())
|
|
||||||
newWorldScreen.mapHolder.scrollX = mapHolder.scrollX
|
|
||||||
newWorldScreen.mapHolder.scrollY = mapHolder.scrollY
|
|
||||||
newWorldScreen.mapHolder.scaleX = mapHolder.scaleX
|
|
||||||
newWorldScreen.mapHolder.scaleY = mapHolder.scaleY
|
|
||||||
newWorldScreen.mapHolder.updateVisualScroll()
|
|
||||||
|
|
||||||
newWorldScreen.selectedCiv = gameInfoClone.getCivilization(selectedCiv.civName)
|
|
||||||
newWorldScreen.fogOfWar = fogOfWar
|
|
||||||
|
|
||||||
game.worldScreen = newWorldScreen
|
|
||||||
game.setWorldScreen()
|
|
||||||
}
|
|
||||||
|
|
||||||
if (gameInfoClone.currentPlayerCiv.civName != viewingCiv.civName
|
if (gameInfoClone.currentPlayerCiv.civName != viewingCiv.civName
|
||||||
&& !gameInfoClone.gameParameters.isOnlineMultiplayer)
|
&& !gameInfoClone.gameParameters.isOnlineMultiplayer)
|
||||||
game.setScreen(PlayerReadyScreen(gameInfoClone.getCurrentPlayerCivilization()))
|
game.setScreen(PlayerReadyScreen(gameInfoClone.getCurrentPlayerCivilization()))
|
||||||
else {
|
else {
|
||||||
createNewWorldScreen()
|
createNewWorldScreen(gameInfoClone)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (shouldAutoSave) {
|
if (shouldAutoSave) {
|
||||||
@ -612,10 +617,8 @@ class WorldScreen(val viewingCiv:CivilizationInfo) : CameraStageBaseScreen() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
override fun resize(width: Int, height: Int) {
|
override fun resize(width: Int, height: Int) {
|
||||||
if (stage.viewport.screenWidth != width || stage.viewport.screenHeight != height) {
|
if (stage.viewport.screenWidth != width || stage.viewport.screenHeight != height)
|
||||||
game.worldScreen = WorldScreen(viewingCiv) // start over.
|
createNewWorldScreen(gameInfo) // start over
|
||||||
game.setWorldScreen()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -630,8 +633,8 @@ class WorldScreen(val viewingCiv:CivilizationInfo) : CameraStageBaseScreen() {
|
|||||||
}
|
}
|
||||||
// topBar.selectedCivLabel.setText(Gdx.graphics.framesPerSecond) // for framerate testing
|
// topBar.selectedCivLabel.setText(Gdx.graphics.framesPerSecond) // for framerate testing
|
||||||
|
|
||||||
var scrollPos = Vector2(mapHolder.scrollX, mapHolder.scrollY);
|
val scrollPos = Vector2(mapHolder.scrollX, mapHolder.scrollY)
|
||||||
var viewScale = Vector2(mapHolder.scaleX, mapHolder.scaleY);
|
val viewScale = Vector2(mapHolder.scaleX, mapHolder.scaleY)
|
||||||
minimapWrapper.minimap.updateScrollPosistion(scrollPos, viewScale)
|
minimapWrapper.minimap.updateScrollPosistion(scrollPos, viewScale)
|
||||||
|
|
||||||
super.render(delta)
|
super.render(delta)
|
||||||
|
Reference in New Issue
Block a user