mirror of
https://github.com/yairm210/Unciv.git
synced 2025-01-28 00:20:49 +07:00
Show replay after 5 rounds and don't reveal where player is on the map. (#9216)
This commit is contained in:
parent
92ad0495f2
commit
9ba5497ce4
@ -1,24 +1,24 @@
|
||||
package com.unciv.ui.screens.victoryscreen
|
||||
|
||||
import com.badlogic.gdx.graphics.g2d.Batch
|
||||
import com.badlogic.gdx.scenes.scene2d.Group
|
||||
import com.unciv.UncivGame
|
||||
import com.unciv.logic.civilization.Civilization
|
||||
import com.unciv.logic.map.TileMap
|
||||
import com.unciv.ui.screens.worldscreen.minimap.MinimapTile
|
||||
import com.unciv.ui.screens.worldscreen.minimap.MinimapTileUtil
|
||||
import kotlin.math.min
|
||||
import kotlin.math.sqrt
|
||||
|
||||
// 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 minimapTiles: List<MinimapTile>
|
||||
|
||||
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()
|
||||
minimapTiles = createReplayMap(tileSize)
|
||||
val tileExtension = MinimapTileUtil.spreadOutMinimapTiles(tileLayer, minimapTiles, tileSize)
|
||||
@ -35,32 +35,24 @@ class ReplayMap(val tileMap: TileMap) : Group() {
|
||||
}
|
||||
|
||||
private fun calcTileSize(): Float {
|
||||
val mapIsNotRectangular =
|
||||
tileMap.mapParameters.shape != com.unciv.logic.map.MapShape.rectangular
|
||||
val tileRows = with(tileMap.mapParameters.mapSize) {
|
||||
if (mapIsNotRectangular) radius * 2 + 1 else height
|
||||
}
|
||||
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)
|
||||
val height = viewingCiv.exploredRegion.getHeight().toFloat()
|
||||
val width = viewingCiv.exploredRegion.getWidth().toFloat()
|
||||
return min(
|
||||
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
|
||||
)
|
||||
}
|
||||
|
||||
private fun createReplayMap(tileSize: Float): List<MinimapTile> {
|
||||
val tiles = ArrayList<MinimapTile>()
|
||||
for (tile in tileMap.values) {
|
||||
for (tile in tileMap.values.filter { it.isExplored(viewingCiv) }) {
|
||||
val minimapTile = MinimapTile(tile, tileSize) {}
|
||||
tiles.add(minimapTile)
|
||||
}
|
||||
return tiles
|
||||
}
|
||||
|
||||
|
||||
fun update(turn: Int, viewingCiv: Civilization) {
|
||||
fun update(turn: Int) {
|
||||
val viewingCivIsDefeated = viewingCiv.gameInfo.victoryData != null || !viewingCiv.isAlive()
|
||||
for (minimapTile in minimapTiles) {
|
||||
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)
|
||||
}
|
||||
|
@ -73,13 +73,9 @@ class VictoryScreen(
|
||||
!playerCiv.isSpectator()
|
||||
&& playerCiv.gameInfo.victoryData == null
|
||||
&& playerCiv.isAlive()
|
||||
// We show the replay after 50 turns. This is quite an arbitrary number, but
|
||||
// we don't want to leak the starting position right away (assuming we don't
|
||||
// condense the replay map in a similar way to the minimap (ie. it fills
|
||||
// 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
|
||||
// We show the replay after 5 turns. This is to ensure that the replay
|
||||
// slider doesn't look weird.
|
||||
&& playerCiv.gameInfo.turns < 5
|
||||
};
|
||||
abstract fun getContent(worldScreen: WorldScreen): Table
|
||||
open fun isHidden(playerCiv: Civilization) = false
|
||||
|
@ -19,15 +19,14 @@ class VictoryScreenReplay(
|
||||
worldScreen: WorldScreen
|
||||
) : Table(BaseScreen.skin), TabbedPager.IPageExtensions {
|
||||
private val gameInfo = worldScreen.gameInfo
|
||||
private val viewingCiv = worldScreen.viewingCiv
|
||||
|
||||
private val finalTurn = gameInfo.turns
|
||||
private var replayTimer : Timer.Task? = null
|
||||
private val replayMap = ReplayMap(gameInfo.tileMap)
|
||||
|
||||
private val header = Table()
|
||||
|
||||
private val yearLabel = "".toLabel()
|
||||
private val slider: UncivSlider
|
||||
private val replayMap: ReplayMap
|
||||
private val playImage = ImageGetter.getImage("OtherIcons/ForwardArrow")
|
||||
private val pauseImage = ImageGetter.getImage("OtherIcons/Pause")
|
||||
private val playPauseButton = Container(pauseImage)
|
||||
@ -48,6 +47,12 @@ class VictoryScreenReplay(
|
||||
tipType = UncivSlider.TipType.None,
|
||||
onChange = this::sliderChanged
|
||||
)
|
||||
replayMap = ReplayMap(
|
||||
gameInfo.tileMap,
|
||||
worldScreen.viewingCiv,
|
||||
worldScreen.stage.width - 50,
|
||||
worldScreen.stage.height - 250
|
||||
)
|
||||
|
||||
playImage.setSize(24f)
|
||||
pauseImage.setSize(24f)
|
||||
@ -111,7 +116,7 @@ class VictoryScreenReplay(
|
||||
)
|
||||
)
|
||||
slider.value = turn.toFloat()
|
||||
replayMap.update(turn, viewingCiv)
|
||||
replayMap.update(turn)
|
||||
if (turn == finalTurn) resetTimer()
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user