mirror of
https://github.com/yairm210/Unciv.git
synced 2025-03-12 10:59:55 +07:00
Add looping minimap viewport if worldwrap enabled (#5349)
The viewport now also appears on the other side of the minimap when viewing the border of the world with worldwrap enabled.
This commit is contained in:
parent
88bcf5d514
commit
c3242f37f2
@ -27,7 +27,7 @@ import kotlin.math.min
|
|||||||
class Minimap(val mapHolder: WorldMapHolder, minimapSize: Int) : Table(){
|
class Minimap(val mapHolder: WorldMapHolder, minimapSize: Int) : Table(){
|
||||||
private val allTiles = Group()
|
private val allTiles = Group()
|
||||||
private val tileImages = HashMap<TileInfo, Image>()
|
private val tileImages = HashMap<TileInfo, Image>()
|
||||||
private val scrollPositionIndicator = ClippingImage(ImageGetter.getDrawable("OtherIcons/Camera"))
|
private val scrollPositionIndicators = ArrayList<ClippingImage>()
|
||||||
|
|
||||||
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!
|
||||||
@ -81,8 +81,17 @@ class Minimap(val mapHolder: WorldMapHolder, minimapSize: Int) : 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)
|
||||||
|
|
||||||
scrollPositionIndicator.touchable = Touchable.disabled
|
scrollPositionIndicators.add(ClippingImage(ImageGetter.getDrawable("OtherIcons/Camera")))
|
||||||
allTiles.addActor(scrollPositionIndicator)
|
// If we are continuous scrolling (world wrap), add another 2 scrollPositionIndicators which
|
||||||
|
// get drawn at proper offsets to simulate looping
|
||||||
|
if (mapHolder.continuousScrollingX) {
|
||||||
|
scrollPositionIndicators.add(ClippingImage(ImageGetter.getDrawable("OtherIcons/Camera")))
|
||||||
|
scrollPositionIndicators.add(ClippingImage(ImageGetter.getDrawable("OtherIcons/Camera")))
|
||||||
|
}
|
||||||
|
for (indicator in scrollPositionIndicators) {
|
||||||
|
indicator.touchable = Touchable.disabled
|
||||||
|
allTiles.addActor(indicator)
|
||||||
|
}
|
||||||
|
|
||||||
add(allTiles)
|
add(allTiles)
|
||||||
layout()
|
layout()
|
||||||
@ -111,7 +120,15 @@ class Minimap(val mapHolder: WorldMapHolder, minimapSize: Int) : Table(){
|
|||||||
val worldViewport = Vector2(mapHolder.scrollX, mapHolder.scrollY).centeredRectangle(worldVisibleArea)
|
val worldViewport = Vector2(mapHolder.scrollX, mapHolder.scrollY).centeredRectangle(worldVisibleArea)
|
||||||
val miniViewport = worldViewport.invertY(mapHolder.maxY) * worldToMiniFactor
|
val miniViewport = worldViewport.invertY(mapHolder.maxY) * worldToMiniFactor
|
||||||
// This _could_ place parts of the 'camera' icon outside the minimap if it were a standard Image, thus the ClippingImage helper class
|
// This _could_ place parts of the 'camera' icon outside the minimap if it were a standard Image, thus the ClippingImage helper class
|
||||||
scrollPositionIndicator.setViewport(miniViewport)
|
scrollPositionIndicators[0].setViewport(miniViewport)
|
||||||
|
|
||||||
|
// If world wrap enabled, draw another 2 viewports at proper offset to simulate wrapping
|
||||||
|
if (scrollPositionIndicators.size != 1) {
|
||||||
|
miniViewport.x -= allTiles.width
|
||||||
|
scrollPositionIndicators[1].setViewport(miniViewport)
|
||||||
|
miniViewport.x += allTiles.width * 2
|
||||||
|
scrollPositionIndicators[2].setViewport(miniViewport)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private class CivAndImage(val civInfo: CivilizationInfo, val image: IconCircleGroup)
|
private class CivAndImage(val civInfo: CivilizationInfo, val image: IconCircleGroup)
|
||||||
|
Loading…
Reference in New Issue
Block a user