Show replay after 5 rounds and don't reveal where player is on the map. (#9216)

This commit is contained in:
WhoIsJohannes
2023-04-18 00:11:31 +02:00
committed by GitHub
parent 92ad0495f2
commit 9ba5497ce4
3 changed files with 27 additions and 37 deletions

View File

@ -1,24 +1,24 @@
package com.unciv.ui.screens.victoryscreen package com.unciv.ui.screens.victoryscreen
import com.badlogic.gdx.graphics.g2d.Batch
import com.badlogic.gdx.scenes.scene2d.Group import com.badlogic.gdx.scenes.scene2d.Group
import com.unciv.UncivGame
import com.unciv.logic.civilization.Civilization import com.unciv.logic.civilization.Civilization
import com.unciv.logic.map.TileMap import com.unciv.logic.map.TileMap
import com.unciv.ui.screens.worldscreen.minimap.MinimapTile import com.unciv.ui.screens.worldscreen.minimap.MinimapTile
import com.unciv.ui.screens.worldscreen.minimap.MinimapTileUtil import com.unciv.ui.screens.worldscreen.minimap.MinimapTileUtil
import kotlin.math.min import kotlin.math.min
import kotlin.math.sqrt
// Mostly copied from MiniMap // Mostly copied from MiniMap
class ReplayMap(val tileMap: TileMap) : Group() { class ReplayMap(
val tileMap: TileMap,
val viewingCiv: Civilization,
private val replayMapWidth: Float,
private val replayMapHeight: Float
) : Group() {
private val tileLayer = Group() private val tileLayer = Group()
private val minimapTiles: List<MinimapTile> private val minimapTiles: List<MinimapTile>
init { init {
// don't try to resize rotate etc - this table has a LOT of children so that's valuable
// render time!
isTransform = false
val tileSize = calcTileSize() val tileSize = calcTileSize()
minimapTiles = createReplayMap(tileSize) minimapTiles = createReplayMap(tileSize)
val tileExtension = MinimapTileUtil.spreadOutMinimapTiles(tileLayer, minimapTiles, tileSize) val tileExtension = MinimapTileUtil.spreadOutMinimapTiles(tileLayer, minimapTiles, tileSize)
@ -35,32 +35,24 @@ class ReplayMap(val tileMap: TileMap) : Group() {
} }
private fun calcTileSize(): Float { private fun calcTileSize(): Float {
val mapIsNotRectangular = val height = viewingCiv.exploredRegion.getHeight().toFloat()
tileMap.mapParameters.shape != com.unciv.logic.map.MapShape.rectangular val width = viewingCiv.exploredRegion.getWidth().toFloat()
val tileRows = with(tileMap.mapParameters.mapSize) { return min(
if (mapIsNotRectangular) radius * 2 + 1 else height replayMapHeight / (height + 1.5f) / sqrt(3f) * 4f, // 1.5 - padding, hex height = sqrt(3) / 2 * d / 2 -> d = height / sqrt(3) * 2 * 2
} replayMapWidth / (width + 0.5f) / 0.75f // 0.5 - padding, hex width = 0.75 * d -> d = width / 0.75
val tileColumns = with(tileMap.mapParameters.mapSize) { )
if (mapIsNotRectangular) radius * 2 + 1 else width
}
// 200 is about how much space we need for the top navigation and close button at the
// bottom.
val tileSizeToFitHeight = (UncivGame.Current.worldScreen!!.stage.height - 200) / tileRows
val tileSizeToFitWidth = UncivGame.Current.worldScreen!!.stage.width / tileColumns
return min(tileSizeToFitHeight, tileSizeToFitWidth)
} }
private fun createReplayMap(tileSize: Float): List<MinimapTile> { private fun createReplayMap(tileSize: Float): List<MinimapTile> {
val tiles = ArrayList<MinimapTile>() val tiles = ArrayList<MinimapTile>()
for (tile in tileMap.values) { for (tile in tileMap.values.filter { it.isExplored(viewingCiv) }) {
val minimapTile = MinimapTile(tile, tileSize) {} val minimapTile = MinimapTile(tile, tileSize) {}
tiles.add(minimapTile) tiles.add(minimapTile)
} }
return tiles return tiles
} }
fun update(turn: Int) {
fun update(turn: Int, viewingCiv: Civilization) {
val viewingCivIsDefeated = viewingCiv.gameInfo.victoryData != null || !viewingCiv.isAlive() val viewingCivIsDefeated = viewingCiv.gameInfo.victoryData != null || !viewingCiv.isAlive()
for (minimapTile in minimapTiles) { for (minimapTile in minimapTiles) {
val isVisible = viewingCivIsDefeated || viewingCiv.hasExplored(minimapTile.tile) val isVisible = viewingCivIsDefeated || viewingCiv.hasExplored(minimapTile.tile)
@ -71,7 +63,4 @@ class ReplayMap(val tileMap: TileMap) : Group() {
} }
} }
} }
// For debugging purposes
override fun draw(batch: Batch?, parentAlpha: Float) = super.draw(batch, parentAlpha)
} }

View File

@ -73,13 +73,9 @@ class VictoryScreen(
!playerCiv.isSpectator() !playerCiv.isSpectator()
&& playerCiv.gameInfo.victoryData == null && playerCiv.gameInfo.victoryData == null
&& playerCiv.isAlive() && playerCiv.isAlive()
// We show the replay after 50 turns. This is quite an arbitrary number, but // We show the replay after 5 turns. This is to ensure that the replay
// we don't want to leak the starting position right away (assuming we don't // slider doesn't look weird.
// condense the replay map in a similar way to the minimap (ie. it fills && playerCiv.gameInfo.turns < 5
// to only the discovered area) and probably before 50 turns not much
// interesting would happen anyway in the replay and the slider might feel
// weird, too.
&& playerCiv.gameInfo.turns < 50
}; };
abstract fun getContent(worldScreen: WorldScreen): Table abstract fun getContent(worldScreen: WorldScreen): Table
open fun isHidden(playerCiv: Civilization) = false open fun isHidden(playerCiv: Civilization) = false

View File

@ -19,15 +19,14 @@ class VictoryScreenReplay(
worldScreen: WorldScreen worldScreen: WorldScreen
) : Table(BaseScreen.skin), TabbedPager.IPageExtensions { ) : Table(BaseScreen.skin), TabbedPager.IPageExtensions {
private val gameInfo = worldScreen.gameInfo private val gameInfo = worldScreen.gameInfo
private val viewingCiv = worldScreen.viewingCiv
private val finalTurn = gameInfo.turns private val finalTurn = gameInfo.turns
private var replayTimer : Timer.Task? = null private var replayTimer : Timer.Task? = null
private val replayMap = ReplayMap(gameInfo.tileMap)
private val header = Table() private val header = Table()
private val yearLabel = "".toLabel() private val yearLabel = "".toLabel()
private val slider: UncivSlider private val slider: UncivSlider
private val replayMap: ReplayMap
private val playImage = ImageGetter.getImage("OtherIcons/ForwardArrow") private val playImage = ImageGetter.getImage("OtherIcons/ForwardArrow")
private val pauseImage = ImageGetter.getImage("OtherIcons/Pause") private val pauseImage = ImageGetter.getImage("OtherIcons/Pause")
private val playPauseButton = Container(pauseImage) private val playPauseButton = Container(pauseImage)
@ -48,6 +47,12 @@ class VictoryScreenReplay(
tipType = UncivSlider.TipType.None, tipType = UncivSlider.TipType.None,
onChange = this::sliderChanged onChange = this::sliderChanged
) )
replayMap = ReplayMap(
gameInfo.tileMap,
worldScreen.viewingCiv,
worldScreen.stage.width - 50,
worldScreen.stage.height - 250
)
playImage.setSize(24f) playImage.setSize(24f)
pauseImage.setSize(24f) pauseImage.setSize(24f)
@ -111,7 +116,7 @@ class VictoryScreenReplay(
) )
) )
slider.value = turn.toFloat() slider.value = turn.toFloat()
replayMap.update(turn, viewingCiv) replayMap.update(turn)
if (turn == finalTurn) resetTimer() if (turn == finalTurn) resetTimer()
} }