Tile map now pans to chosen tile, instead of "flashing" there - makes the map feel more connected and helps you understand where you are IMHO

This commit is contained in:
Yair Morgenstern 2019-02-14 22:21:26 +02:00
parent a9c181f314
commit 0fab01e393
4 changed files with 20 additions and 3 deletions

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.9 KiB

After

Width:  |  Height:  |  Size: 2 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 864 KiB

After

Width:  |  Height:  |  Size: 864 KiB

View file

@ -5,6 +5,7 @@ import com.badlogic.gdx.math.Vector2
import com.badlogic.gdx.scenes.scene2d.Actor import com.badlogic.gdx.scenes.scene2d.Actor
import com.badlogic.gdx.scenes.scene2d.Group import com.badlogic.gdx.scenes.scene2d.Group
import com.badlogic.gdx.scenes.scene2d.InputEvent import com.badlogic.gdx.scenes.scene2d.InputEvent
import com.badlogic.gdx.scenes.scene2d.actions.FloatAction
import com.badlogic.gdx.scenes.scene2d.ui.ScrollPane import com.badlogic.gdx.scenes.scene2d.ui.ScrollPane
import com.badlogic.gdx.scenes.scene2d.utils.ActorGestureListener import com.badlogic.gdx.scenes.scene2d.utils.ActorGestureListener
import com.unciv.UnCivGame import com.unciv.UnCivGame
@ -245,12 +246,25 @@ class TileMapHolder(internal val worldScreen: WorldScreen, internal val tileMap:
val tileGroup = tileGroups.values.first { it.tileInfo.position == vector } val tileGroup = tileGroups.values.first { it.tileInfo.position == vector }
selectedTile = tileGroup.tileInfo selectedTile = tileGroup.tileInfo
worldScreen.bottomBar.unitTable.tileSelected(selectedTile!!) worldScreen.bottomBar.unitTable.tileSelected(selectedTile!!)
val originalScrollX = scrollX
val originalScrollY = scrollY
// We want to center on the middle of TG (TG.getX()+TG.getWidth()/2) // We want to center on the middle of TG (TG.getX()+TG.getWidth()/2)
// and so the scroll position (== filter the screen starts) needs to be half a screen away // and so the scroll position (== filter the screen starts) needs to be half a screen away
scrollX = tileGroup.x + tileGroup.width / 2 - worldScreen.stage.width / 2 val finalScrollX = tileGroup.x + tileGroup.width / 2 - worldScreen.stage.width / 2
// Here it's the same, only the Y axis is inverted - when at 0 we're at the top, not bottom - so we invert it back. // Here it's the same, only the Y axis is inverted - when at 0 we're at the top, not bottom - so we invert it back.
scrollY = maxY - (tileGroup.y + tileGroup.width / 2 - worldScreen.stage.height / 2) val finalScrollY = maxY - (tileGroup.y + tileGroup.width / 2 - worldScreen.stage.height / 2)
addAction(object : FloatAction(0f,1f,0.4f){
override fun update(percent: Float) {
scrollX = finalScrollX*percent + originalScrollX * (1-percent)
scrollY = finalScrollY*percent + originalScrollY*(1-percent)
updateVisualScroll() updateVisualScroll()
}
})
worldScreen.shouldUpdate=true worldScreen.shouldUpdate=true
} }

View file

@ -0,0 +1,3 @@
a156c2bf-1745-41ce-9f4a-669ff23f2996
For editing the endty in the LibGDX website