Display scroll position on minimap (#3593)

This commit is contained in:
Johannes Schreiber
2021-02-14 10:48:57 +01:00
committed by GitHub
parent f2af128546
commit 1e981abe53
5 changed files with 32 additions and 0 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

View File

@ -410,6 +410,13 @@ OtherIcons/Crosshair
orig: 100, 100 orig: 100, 100
offset: 0, 0 offset: 0, 0
index: -1 index: -1
OtherIcons/Camera
rotate: false
xy: 500, 500
size: 100, 100
orig: 100, 100
offset: 0, 0
index: -1
OtherIcons/DisbandUnit OtherIcons/DisbandUnit
rotate: false rotate: false
xy: 1503, 1730 xy: 1503, 1730

Binary file not shown.

Before

Width:  |  Height:  |  Size: 874 KiB

After

Width:  |  Height:  |  Size: 856 KiB

View File

@ -2,8 +2,10 @@ package com.unciv.ui.worldscreen
import com.badlogic.gdx.graphics.Color import com.badlogic.gdx.graphics.Color
import com.badlogic.gdx.graphics.g2d.Batch import com.badlogic.gdx.graphics.g2d.Batch
import com.badlogic.gdx.math.MathUtils
import com.badlogic.gdx.math.Vector2 import com.badlogic.gdx.math.Vector2
import com.badlogic.gdx.scenes.scene2d.Group import com.badlogic.gdx.scenes.scene2d.Group
import com.badlogic.gdx.scenes.scene2d.Touchable
import com.badlogic.gdx.scenes.scene2d.ui.Image import com.badlogic.gdx.scenes.scene2d.ui.Image
import com.badlogic.gdx.scenes.scene2d.ui.Table import com.badlogic.gdx.scenes.scene2d.ui.Table
import com.badlogic.gdx.utils.Align import com.badlogic.gdx.utils.Align
@ -21,6 +23,7 @@ import kotlin.math.min
class Minimap(val mapHolder: WorldMapHolder) : Table(){ class Minimap(val mapHolder: WorldMapHolder) : Table(){
private val allTiles = Group() private val allTiles = Group()
private val tileImages = HashMap<TileInfo, Image>() private val tileImages = HashMap<TileInfo, Image>()
private val scrollPosistionIndicator = ImageGetter.getImage("OtherIcons/Camera")
init { init {
isTransform = false // don't try to resize rotate etc - this table has a LOT of children so that's valuable render time! isTransform = false // don't try to resize rotate etc - this table has a LOT of children so that's valuable render time!
@ -65,10 +68,28 @@ class Minimap(val mapHolder: WorldMapHolder) : Table(){
// so we zero out the starting position of the whole board so they will be displayed as well // so we zero out the starting position of the whole board so they will be displayed as well
allTiles.setSize(topX - bottomX, topY - bottomY) allTiles.setSize(topX - bottomX, topY - bottomY)
scrollPosistionIndicator.touchable = Touchable.disabled
allTiles.addActor(scrollPosistionIndicator)
add(allTiles) add(allTiles)
layout() layout()
} }
fun updateScrollPosistion(scrollPos: Vector2, scale: Vector2){
val scrollPosistionIndicatorBaseScale = Vector2(allTiles.width / mapHolder.maxX, allTiles.height / mapHolder.maxY)
scrollPosistionIndicator.scaleX = scrollPosistionIndicatorBaseScale.x * 10f * max(2f - scale.x, 0.25f)
scrollPosistionIndicator.scaleY = scrollPosistionIndicatorBaseScale.y * 10f * max(2f - scale.y, 0.25f)
val scrollPositionIndicatorOffset = Vector2(-50f * scrollPosistionIndicator.scaleX, 125f + (50f * (1-scrollPosistionIndicator.scaleY)))
val scrollPosOnMinimap = Vector2((scrollPos.x / mapHolder.maxX) * allTiles.width, (scrollPos.y / mapHolder.maxY) * allTiles.height)
scrollPosOnMinimap.x = MathUtils.clamp(scrollPosOnMinimap.x, -scrollPositionIndicatorOffset.x, allTiles.width + scrollPositionIndicatorOffset.x)
scrollPosOnMinimap.y = MathUtils.clamp(scrollPosOnMinimap.y, -scrollPositionIndicatorOffset.x, scrollPositionIndicatorOffset.y)
scrollPosistionIndicator.setPosition(scrollPositionIndicatorOffset.x + scrollPosOnMinimap.x, scrollPositionIndicatorOffset.y - scrollPosOnMinimap.y)
}
private class CivAndImage(val civInfo: CivilizationInfo, val image: IconCircleGroup) private class CivAndImage(val civInfo: CivilizationInfo, val image: IconCircleGroup)
private val cityIcons = HashMap<TileInfo, CivAndImage>() private val cityIcons = HashMap<TileInfo, CivAndImage>()

View File

@ -630,6 +630,10 @@ 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);
var viewScale = Vector2(mapHolder.scaleX, mapHolder.scaleY);
minimapWrapper.minimap.updateScrollPosistion(scrollPos, viewScale)
super.render(delta) super.render(delta)
} }