From c6bc6281652030aebc890eb24320ddacafd08277 Mon Sep 17 00:00:00 2001 From: minjaesong Date: Wed, 22 Dec 2021 16:00:21 +0900 Subject: [PATCH] finally working floating head on the minimap --- .../terrarum/blockstats/MinimapComposer.kt | 27 +------- .../modulebasegame/ui/UIInventoryMinimap.kt | 65 +++++++++++++------ src/net/torvald/terrarum/ui/Toolkit.kt | 4 ++ 3 files changed, 51 insertions(+), 45 deletions(-) diff --git a/src/net/torvald/terrarum/blockstats/MinimapComposer.kt b/src/net/torvald/terrarum/blockstats/MinimapComposer.kt index 13a2250de..1a7b21cd5 100644 --- a/src/net/torvald/terrarum/blockstats/MinimapComposer.kt +++ b/src/net/torvald/terrarum/blockstats/MinimapComposer.kt @@ -110,8 +110,6 @@ object MinimapComposer : Disposable { val tlx = x - (MINIMAP_TILE_WIDTH / 2) val tly = y - (MINIMAP_TILE_HEIGHT / 2) -// printdbg(this, "queue render - c($x,$y), tl($tlx,$tlx)") - // make the queueing work // enqueue first spiralIndices.forEachIndexed { index, i -> @@ -124,27 +122,6 @@ object MinimapComposer : Disposable { // printdbg(this, "Queueing tilemap update ($tx,$ty) from queue[$i]") } - // consume the queue - /*for (k in currentThreads.indices) { - if (currentThreads[k].state == Thread.State.TERMINATED && !updaterQueue.isEmpty) { - currentThreads[k] = Thread(updaterQueue.removeFirst(), "MinimapLivetilePainter") - printdbg(this, "Consuming from queue; queue size now: ${updaterQueue.size}") - } - if (currentThreads[k].state == Thread.State.NEW) { - currentThreads[k].start() - } - }*/ - - - /*updaterQueue.forEachIndexed { k, runnable -> - if (runnable != null) { - currentThreads[k] = Thread(runnable, "MinimapLivetilePainter") - printdbg(this, "Consuming from queue[$k]") - currentThreads[k].start() - } - }*/ - - threadExecutor.renew() threadExecutor.submitAll(updaterQueue.filterNotNull()) Thread { threadExecutor.join() }.start() @@ -180,8 +157,8 @@ object MinimapComposer : Disposable { oobColBtm else if (colTerr.a > 0.1f) colTerr else colWall - if (index % 2 == 1) outCol.lerp(Color.BLACK, 0.2f) - else if (index != (SQUARE_SIZE.sqr() - 1) / 2) outCol.lerp(Color.FIREBRICK, 0.12f) +// if (index % 2 == 1) outCol.lerp(Color.BLACK, 0.2f) +// else if (index != (SQUARE_SIZE.sqr() - 1) / 2) outCol.lerp(Color.FIREBRICK, 0.12f) pixmap.blending = Pixmap.Blending.None pixmap.setColor(outCol) diff --git a/src/net/torvald/terrarum/modulebasegame/ui/UIInventoryMinimap.kt b/src/net/torvald/terrarum/modulebasegame/ui/UIInventoryMinimap.kt index 08b4aa529..ab13c523f 100644 --- a/src/net/torvald/terrarum/modulebasegame/ui/UIInventoryMinimap.kt +++ b/src/net/torvald/terrarum/modulebasegame/ui/UIInventoryMinimap.kt @@ -8,6 +8,7 @@ import com.badlogic.gdx.graphics.glutils.FrameBuffer import com.badlogic.gdx.utils.GdxRuntimeException import net.torvald.terrarum.* import net.torvald.terrarum.App.printdbg +import net.torvald.terrarum.TerrarumAppConfiguration.TILE_SIZEF import net.torvald.terrarum.blockstats.MinimapComposer import net.torvald.terrarum.blockstats.MinimapComposer.MINIMAP_TILE_HEIGHT import net.torvald.terrarum.blockstats.MinimapComposer.MINIMAP_TILE_WIDTH @@ -33,7 +34,7 @@ class UIInventoryMinimap(val full: UIInventoryFull) : UICanvas() { val MINIMAP_SKYCOL = Color(0x88bbddff.toInt()) } - private val debugvals = true +// private val debugvals = true override var width: Int = Toolkit.drawWidth override var height: Int = App.scr.height @@ -68,6 +69,7 @@ class UIInventoryMinimap(val full: UIInventoryFull) : UICanvas() { override fun renderUI(batch: SpriteBatch, camera: Camera) { blendNormal(batch) val cellOffY = INVENTORY_CELLS_OFFSET_Y() + val worldWidth = INGAME.world.width var mdx = 0f var mdy = 0f @@ -93,7 +95,7 @@ class UIInventoryMinimap(val full: UIInventoryFull) : UICanvas() { minimapDrawOffX += mdx minimapDrawOffY += mdy - minimapPanX = minimapPanX fmod INGAME.world.width.toFloat() + minimapPanX = minimapPanX fmod worldWidth.toFloat() dragStatus = 1 } @@ -173,45 +175,68 @@ class UIInventoryMinimap(val full: UIInventoryFull) : UICanvas() { } - ((INGAME.actorContainerInactive + INGAME.actorContainerActive).filter { it is IngamePlayer } as List).forEach { + ((INGAME.actorContainerInactive + INGAME.actorContainerActive + listOf(INGAME.actorNowPlaying)).filterIsInstance()).forEach { it.getSpriteHead()?.let { t -> - val ox = 0.5f * MINIMAP_TILE_WIDTH - val oy = 0.5f * MINIMAP_TILE_HEIGHT + val sf = it.scale.toFloat() + val headHeight = 6 + val ox = MINIMAP_TILE_WIDTH / 2f + val oy = MINIMAP_TILE_HEIGHT / 2f val tx = (minimapDrawOffX - ox) val ty = (minimapDrawOffY - oy) - val worldPos = it.intTilewiseHitbox - val cw = it.scale.toFloat() * t.regionWidth - val ch = it.scale.toFloat() * t.regionHeight - val cx = worldPos.centeredX.round().toFloat() - val cy = worldPos.startY.round().toFloat() + val worldPos = it.hitbox + val cw = t.regionWidth * sf + val ch = t.regionHeight * sf + val cx = worldPos.centeredX.div(TILE_SIZEF).round().toFloat() + val cy = worldPos.startY.plus(headHeight * sf).div(TILE_SIZEF).round().toFloat() val dx = cx - oldPanX val dy = cy - oldPanY - // tx/ty corresponds to world coord minimapPanXY + // drawing "crosshair" + val x1 = (tx + dx + MINIMAP_TILE_WIDTH / 2f) * minimapZoom + MINIMAP_HALFW + val x2 = (tx + dx + worldWidth + MINIMAP_TILE_WIDTH / 2f) * minimapZoom + MINIMAP_HALFW + val x3 = (tx + dx - worldWidth + MINIMAP_TILE_WIDTH / 2f) * minimapZoom + MINIMAP_HALFW + val y = (ty + dy + MINIMAP_TILE_HEIGHT / 2f) * minimapZoom + MINIMAP_HALFH - val x = (tx + dx) * minimapZoom + MINIMAP_HALFW - val y = (ty + dy) * minimapZoom + MINIMAP_HALFH + // how do I actually centre the head? + val doffx = -cw / 2f + val doffy = -ch / 2f - printdbg(this, "map pan: ($minimapPanX,$minimapPanY);draw pos: ($x,$y)") + // throwing three static images instead of one won't hurt anything + if (it.sprite?.flipHorizontal == false) { + batch.draw(t, x1 + doffx, y + doffy, cw, ch) + batch.draw(t, x2 + doffx, y + doffy, cw, ch) + batch.draw(t, x3 + doffx, y + doffy, cw, ch) + } + else { + batch.draw(t, x1 + doffx + cw, y + doffy, -cw, ch) + batch.draw(t, x2 + doffx + cw, y + doffy, -cw, ch) + batch.draw(t, x3 + doffx + cw, y + doffy, -cw, ch) + } - if (it.sprite?.flipHorizontal == false) - batch.draw(CommonResourcePool.getAsTextureRegion("test_texture"), x, y, cw, ch) - else - batch.draw(CommonResourcePool.getAsTextureRegion("test_texture"), x + cw, y, -cw, ch) + /* + val xi = x.roundToInt() + val yi = y.roundToInt() + batch.color = Color.LIME + Toolkit.drawBoxBorder(batch, x + doffx, y + doffy, cw, ch) + batch.color = Color.CORAL + Toolkit.drawStraightLine(batch, xi-10, yi, xi+10, 1, false) + Toolkit.drawStraightLine(batch, xi, yi-10, yi+10, 1, true) + */ } } } } batch.begin() + batch.color = Color.WHITE + val minimapDrawX = (width - MINIMAP_WIDTH) / 2 val minimapDrawY = (height - cellOffY - App.scr.tvSafeGraphicsHeight - MINIMAP_HEIGHT - 72) / 2 + cellOffY * 1f - if (debugvals) { + if (App.IS_DEVELOPMENT_BUILD) { App.fontSmallNumbers.draw(batch, "Pan: ($minimapPanX,$minimapPanY) old ($oldPanX,$oldPanY); Trans: ($minimapDrawOffX,$minimapDrawOffY); x$minimapZoom", minimapDrawX, minimapDrawY - 16f) } - batch.color = Color.WHITE batch.projectionMatrix = camera.combined // border diff --git a/src/net/torvald/terrarum/ui/Toolkit.kt b/src/net/torvald/terrarum/ui/Toolkit.kt index 2075a8c00..373d56b04 100644 --- a/src/net/torvald/terrarum/ui/Toolkit.kt +++ b/src/net/torvald/terrarum/ui/Toolkit.kt @@ -9,6 +9,7 @@ import com.badlogic.gdx.utils.Disposable import net.torvald.random.HQRNG import net.torvald.terrarum.* import net.torvald.terrarumsansbitmap.gdx.TextureRegionPack +import kotlin.math.roundToInt /** @@ -119,6 +120,9 @@ object Toolkit : Disposable { fillArea(batch, x, y, thickness, otherEnd - y) } + fun drawBoxBorder(batch: SpriteBatch, x: Float, y: Float, w: Float, h: Float) = + drawBoxBorder(batch, x.roundToInt(), y.roundToInt(), w.roundToInt(), h.roundToInt()) + /** * Parameters are THAT OF THE BOX, the border will be drawn OUTSIDE of the params you specified! */