mirror of
https://github.com/yairm210/Unciv.git
synced 2025-07-16 18:59:15 +07:00
Fix scroll to wonder in the map editor (#7154)
* Fix scroll to wonder in the map editor * Fix blink always happening
This commit is contained in:
@ -1,5 +1,6 @@
|
||||
package com.unciv.ui.mapeditor
|
||||
|
||||
import com.badlogic.gdx.math.Interpolation
|
||||
import com.badlogic.gdx.math.Vector2
|
||||
import com.badlogic.gdx.scenes.scene2d.Action
|
||||
import com.badlogic.gdx.scenes.scene2d.EventListener
|
||||
@ -8,6 +9,7 @@ import com.badlogic.gdx.scenes.scene2d.InputListener
|
||||
import com.badlogic.gdx.scenes.scene2d.Stage
|
||||
import com.badlogic.gdx.scenes.scene2d.Touchable
|
||||
import com.badlogic.gdx.scenes.scene2d.actions.Actions
|
||||
import com.badlogic.gdx.scenes.scene2d.actions.FloatAction
|
||||
import com.unciv.UncivGame
|
||||
import com.unciv.logic.HexMath
|
||||
import com.unciv.logic.map.TileInfo
|
||||
@ -122,10 +124,33 @@ class EditorMapHolder(
|
||||
return null
|
||||
}
|
||||
|
||||
/**
|
||||
* Copy-pasted from [com.unciv.ui.worldscreen.WorldMapHolder.setCenterPosition]
|
||||
* TODO remove code duplication
|
||||
*/
|
||||
fun setCenterPosition(vector: Vector2, blink: Boolean = false) {
|
||||
val tileGroup = allTileGroups.firstOrNull { it.tileInfo.position == vector } ?: return
|
||||
scrollX = tileGroup.x + tileGroup.width / 2 - width / 2
|
||||
scrollY = maxY - (tileGroup.y + tileGroup.width / 2 - height / 2)
|
||||
|
||||
val originalScrollX = scrollX
|
||||
val originalScrollY = scrollY
|
||||
|
||||
val finalScrollX = tileGroup.x + tileGroup.width / 2
|
||||
|
||||
/** The Y axis of [scrollY] is inverted - when at 0 we're at the top, not bottom - so we invert it back. */
|
||||
val finalScrollY = maxY - (tileGroup.y + tileGroup.width / 2)
|
||||
|
||||
if (finalScrollX == originalScrollX && finalScrollY == originalScrollY) return
|
||||
|
||||
val action = object : FloatAction(0f, 1f, 0.4f) {
|
||||
override fun update(percent: Float) {
|
||||
scrollX = finalScrollX * percent + originalScrollX * (1 - percent)
|
||||
scrollY = finalScrollY * percent + originalScrollY * (1 - percent)
|
||||
updateVisualScroll()
|
||||
}
|
||||
}
|
||||
action.interpolation = Interpolation.sine
|
||||
addAction(action)
|
||||
|
||||
if (!blink) return
|
||||
|
||||
removeAction(blinkAction) // so we don't have multiple blinks at once
|
||||
|
Reference in New Issue
Block a user