mirror of
https://github.com/curioustorvald/Terrarum.git
synced 2026-06-11 02:54:04 +09:00
new minimap working and not working
This commit is contained in:
@@ -294,7 +294,7 @@ class UIInventoryFull(
|
||||
|
||||
override fun endClosing(delta: Float) {
|
||||
INGAME.setTooltipMessage(null) // required!
|
||||
MinimapComposer.revalidateAll()
|
||||
// MinimapComposer.revalidateAll()
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -5,12 +5,17 @@ import com.badlogic.gdx.Input
|
||||
import com.badlogic.gdx.graphics.*
|
||||
import com.badlogic.gdx.graphics.g2d.SpriteBatch
|
||||
import com.badlogic.gdx.graphics.glutils.FrameBuffer
|
||||
import com.badlogic.gdx.utils.GdxRuntimeException
|
||||
import net.torvald.terrarum.*
|
||||
import net.torvald.terrarum.TerrarumAppConfiguration.TILE_SIZE
|
||||
import net.torvald.terrarum.blockstats.MinimapComposer
|
||||
import net.torvald.terrarum.blockstats.MinimapComposer.MINIMAP_TILE_HEIGHT
|
||||
import net.torvald.terrarum.blockstats.MinimapComposer.MINIMAP_TILE_WIDTH
|
||||
import net.torvald.terrarum.modulebasegame.ui.UIInventoryFull.Companion.INVENTORY_CELLS_OFFSET_Y
|
||||
import net.torvald.terrarum.modulebasegame.ui.UIInventoryFull.Companion.INVENTORY_CELLS_UI_HEIGHT
|
||||
import net.torvald.terrarum.ui.Toolkit
|
||||
import net.torvald.terrarum.ui.UICanvas
|
||||
import kotlin.math.roundToInt
|
||||
|
||||
class UIInventoryMinimap(val full: UIInventoryFull) : UICanvas() {
|
||||
|
||||
@@ -30,17 +35,25 @@ class UIInventoryMinimap(val full: UIInventoryFull) : UICanvas() {
|
||||
override var openCloseTime = 0.0f
|
||||
|
||||
private var minimapZoom = 1f
|
||||
private var minimapPanX = -MinimapComposer.totalWidth / 2f
|
||||
private var minimapPanY = -MinimapComposer.totalHeight / 2f
|
||||
private var minimapPanX: Float = INGAME.actorNowPlaying?.intTilewiseHitbox?.centeredX?.toFloat() ?: (INGAME.world.width / 2f)
|
||||
private var minimapPanY: Float = INGAME.actorNowPlaying?.intTilewiseHitbox?.centeredY?.toFloat() ?: (INGAME.world.height / 2f)
|
||||
|
||||
private var minimapTranslateX: Float = 0f
|
||||
private var minimapTranslateY: Float = 0f
|
||||
|
||||
private val minimapFBO = FrameBuffer(Pixmap.Format.RGBA8888, MINIMAP_WIDTH.toInt(), MINIMAP_HEIGHT.toInt(), false)
|
||||
private val minimapCamera = OrthographicCamera(MINIMAP_WIDTH, MINIMAP_HEIGHT)
|
||||
|
||||
private var minimapRerenderTimer = 0f
|
||||
private val minimapRerenderInterval = .5f
|
||||
private val minimapRerenderInterval = 5f // seconds
|
||||
|
||||
private var dragStatus = 0
|
||||
|
||||
private var renderTextures = Array(MinimapComposer.pixmaps.size) { Texture(16, 16, Pixmap.Format.RGBA8888) }
|
||||
|
||||
override fun updateUI(delta: Float) {
|
||||
MinimapComposer.setWorld(INGAME.world)
|
||||
MinimapComposer.update()
|
||||
// MinimapComposer.update()
|
||||
minimapRerenderTimer += Gdx.graphics.deltaTime
|
||||
}
|
||||
|
||||
@@ -53,8 +66,18 @@ class UIInventoryMinimap(val full: UIInventoryFull) : UICanvas() {
|
||||
// if left click is down and cursor is in the map area
|
||||
if (Terrarum.mouseDown &&
|
||||
Terrarum.mouseScreenY in cellOffY..cellOffY + INVENTORY_CELLS_UI_HEIGHT) {
|
||||
minimapPanX += Terrarum.mouseDeltaX * 2f / minimapZoom
|
||||
minimapPanY += Terrarum.mouseDeltaY * 2f / minimapZoom
|
||||
val mdx = Terrarum.mouseDeltaX * 2f / minimapZoom
|
||||
val mdy = Terrarum.mouseDeltaY * 2f / minimapZoom
|
||||
|
||||
minimapPanX += mdx
|
||||
minimapPanY += mdy
|
||||
minimapTranslateX += mdx
|
||||
minimapTranslateY += mdy
|
||||
|
||||
dragStatus = 1
|
||||
}
|
||||
else if (dragStatus == 1 && !Terrarum.mouseDown) {
|
||||
dragStatus = 2
|
||||
}
|
||||
|
||||
|
||||
@@ -66,8 +89,8 @@ class UIInventoryMinimap(val full: UIInventoryFull) : UICanvas() {
|
||||
}
|
||||
if (Gdx.input.isKeyPressed(Input.Keys.NUM_3)) {
|
||||
minimapZoom = 1f
|
||||
minimapPanX = -MinimapComposer.totalWidth / 2f
|
||||
minimapPanY = -MinimapComposer.totalHeight / 2f
|
||||
minimapPanX = INGAME.actorNowPlaying?.intTilewiseHitbox?.centeredX?.toFloat() ?: (INGAME.world.width / 2f)
|
||||
minimapPanY = INGAME.actorNowPlaying?.intTilewiseHitbox?.centeredY?.toFloat() ?: (INGAME.world.height / 2f)
|
||||
}
|
||||
|
||||
|
||||
@@ -86,19 +109,18 @@ class UIInventoryMinimap(val full: UIInventoryFull) : UICanvas() {
|
||||
// render minimap
|
||||
batch.end()
|
||||
|
||||
if (minimapRerenderTimer >= minimapRerenderInterval) {
|
||||
if (dragStatus == 2 || minimapRerenderTimer >= minimapRerenderInterval) {
|
||||
dragStatus = 0
|
||||
minimapRerenderTimer = 0f
|
||||
MinimapComposer.requestRender()
|
||||
|
||||
MinimapComposer.queueRender(minimapPanX.roundToInt(), minimapPanY.roundToInt())
|
||||
|
||||
minimapTranslateX = 0f
|
||||
minimapTranslateY = 0f
|
||||
}
|
||||
|
||||
MinimapComposer.renderToBackground()
|
||||
|
||||
minimapFBO.inActionF(minimapCamera, batch) {
|
||||
// whatever.
|
||||
MinimapComposer.tempTex.dispose()
|
||||
MinimapComposer.tempTex = Texture(MinimapComposer.minimap)
|
||||
MinimapComposer.tempTex.setFilter(Texture.TextureFilter.Linear, Texture.TextureFilter.Nearest)
|
||||
|
||||
batch.inUse {
|
||||
|
||||
// [ 1 0 0 ] [ s 0 0 ] [ s 0 0 ]
|
||||
@@ -107,27 +129,36 @@ class UIInventoryMinimap(val full: UIInventoryFull) : UICanvas() {
|
||||
//
|
||||
// https://www.wolframalpha.com/input/?i=%7B%7B1,0,0%7D,%7B0,1,0%7D,%7Bp_x,p_y,1%7D%7D+*+%7B%7Bs,0,0%7D,%7B0,s,0%7D,%7Bw%2F2,h%2F2,1%7D%7D
|
||||
|
||||
val tx = minimapPanX * minimapZoom + 0.5f * MINIMAP_WIDTH
|
||||
val ty = minimapPanY * minimapZoom + 0.5f * MINIMAP_HEIGHT
|
||||
|
||||
// sky background
|
||||
batch.color = MINIMAP_SKYCOL
|
||||
Toolkit.fillArea(batch, 0f, 0f, MINIMAP_WIDTH, MINIMAP_HEIGHT)
|
||||
// the actual image
|
||||
batch.color = Color.WHITE
|
||||
batch.draw(MinimapComposer.tempTex, tx, ty, MinimapComposer.totalWidth * minimapZoom, MinimapComposer.totalHeight * minimapZoom)
|
||||
|
||||
MinimapComposer.pixmaps.forEachIndexed { index, pixmap ->
|
||||
renderTextures[index].dispose()
|
||||
renderTextures[index] = Texture(pixmap)
|
||||
|
||||
val ix = index % 3; val iy = index / 3
|
||||
|
||||
val ox = (ix - 1) * MINIMAP_TILE_WIDTH
|
||||
val oy = (iy - 1) * MINIMAP_TILE_HEIGHT
|
||||
|
||||
val tx = (minimapTranslateX - ox) * minimapZoom + 0.5f * MINIMAP_WIDTH
|
||||
val ty = (minimapTranslateY - oy) * minimapZoom + 0.5f * MINIMAP_HEIGHT
|
||||
|
||||
batch.color = Color.WHITE
|
||||
batch.draw(renderTextures[index], tx, ty, MINIMAP_TILE_WIDTH * minimapZoom, MINIMAP_TILE_HEIGHT * minimapZoom)
|
||||
}
|
||||
}
|
||||
}
|
||||
batch.begin()
|
||||
|
||||
if (debugvals) {
|
||||
App.fontSmallNumbers.draw(batch, "$minimapPanX, $minimapPanY; x$minimapZoom", (width - MINIMAP_WIDTH) / 2, -10f + cellOffY)
|
||||
}
|
||||
|
||||
val minimapDrawX = (width - MINIMAP_WIDTH) / 2
|
||||
val minimapDrawY = (height - cellOffY - App.scr.tvSafeGraphicsHeight - MINIMAP_HEIGHT - 72) / 2 + cellOffY * 1f
|
||||
|
||||
if (debugvals) {
|
||||
App.fontSmallNumbers.draw(batch, "$minimapPanX, $minimapPanY; x$minimapZoom", minimapDrawX, minimapDrawY - 16f)
|
||||
}
|
||||
|
||||
batch.color = Color.WHITE
|
||||
batch.projectionMatrix = camera.combined
|
||||
|
||||
@@ -153,5 +184,6 @@ class UIInventoryMinimap(val full: UIInventoryFull) : UICanvas() {
|
||||
|
||||
override fun dispose() {
|
||||
minimapFBO.dispose()
|
||||
renderTextures.forEach { try { it.dispose() } catch (e: GdxRuntimeException) {} }
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user