add: inventory minimap

This commit is contained in:
minjaesong
2020-09-18 11:09:33 +09:00
parent 0bf5baa7e0
commit 8929093432
3 changed files with 151 additions and 218 deletions

View File

@@ -31,8 +31,8 @@ internal class UIInventoryCells(
UIItemInventoryDynamicList(
full,
full.actor.inventory,
0 + (AppLoader.screenW - full.internalWidth) / 2,
107 + (AppLoader.screenH - full.internalHeight) / 2,
full.INVENTORY_CELLS_OFFSET_X,
full.INVENTORY_CELLS_OFFSET_Y,
full.CELLS_HOR, full.CELLS_VRT
)
@@ -43,7 +43,7 @@ internal class UIInventoryCells(
full.actor.inventory,
full.actor as ActorWithBody,
full.internalWidth - UIItemInventoryEquippedView.WIDTH + (AppLoader.screenW - full.internalWidth) / 2,
107 + (AppLoader.screenH - full.internalHeight) / 2
full.INVENTORY_CELLS_OFFSET_Y
)
init {

View File

@@ -29,8 +29,6 @@ class UIInventoryFull(
doNotWarnConstant: Boolean = false
) : UICanvas(toggleKeyLiteral, toggleButtonLiteral, customPositioning, doNotWarnConstant) {
private val debugvals = true
override var width: Int = AppLoader.screenW
override var height: Int = AppLoader.screenH
override var openCloseTime: Second = 0.0f
@@ -49,6 +47,7 @@ class UIInventoryFull(
val itemListHeight: Int = CELLS_VRT * UIItemInventoryElemSimple.height + (CELLS_VRT - 1) * net.torvald.terrarum.modulebasegame.ui.UIItemInventoryDynamicList.Companion.listGap
val INVENTORY_CELLS_UI_HEIGHT = CELLS_VRT * UIItemInventoryElemSimple.height + (CELLS_VRT - 1) * UIItemInventoryDynamicList.listGap
val INVENTORY_CELLS_OFFSET_X = 0 + (AppLoader.screenW - internalWidth) / 2
val INVENTORY_CELLS_OFFSET_Y = 107 + (AppLoader.screenH - internalHeight) / 2
init {
@@ -114,7 +113,7 @@ class UIInventoryFull(
)
private val transitionalMinimap = UIInventoryCells(this) // PLACEHOLDER
private val transitionalMinimap = UIInventoryMinimap(this) // PLACEHOLDER
private val transitionalItemCells = UIInventoryCells(this)
private val transitionalEscMenu = UIInventoryEscMenu(this)
private val transitionPanel = UIItemHorizontalFadeSlide(
@@ -127,19 +126,10 @@ class UIInventoryFull(
transitionalMinimap, transitionalItemCells, transitionalEscMenu
)
private val SCREEN_MINIMAP = 0f
private val SCREEN_INVENTORY = 1f
private val SCREEN_MENU = 2f
init {
addUIitem(categoryBar)
addUIitem(transitionPanel)
//itemList.let { addUIitem(it) }
//equipped.let { addUIitem(it) }
categoryBar.selectionChangeListener = { old, new ->
rebuildList()
@@ -164,29 +154,8 @@ class UIInventoryFull(
rebuildList()
}
categoryBar.update(delta)
transitionPanel.update(delta)
// update map while visible
/*if (currentScreenTransition > 1f + epsilon) {
MinimapComposer.setWorld(Terrarum.ingame!!.world)
MinimapComposer.update()
}*/
// update inventory while visible
/*if (currentScreenTransition in epsilon..2f - epsilon) {
itemList.update(delta)
equipped.update(delta)
}*/
// update menu while visible
/*if (currentScreenTransition < 1f - epsilon) {
gameMenuButtons.update(delta)
}*/
minimapRerenderTimer += Gdx.graphics.rawDeltaTime
}
private val gradStartCol = Color(0x404040_60)
@@ -199,18 +168,6 @@ class UIInventoryFull(
internal var yEnd = (AppLoader.screenH + internalHeight).div(2).toFloat()
private set
private var minimapRerenderTimer = 0f
private val minimapRerenderInterval = .5f
// TODO implemented on UIItemTransitionContainer
/*fun requestTransition(target: Int) {
if (!transitionOngoing) {
transitionRequested = true
transitionReqSource = currentScreenTransition.round()
transitionReqTarget = target.toFloat()
}
}*/
override fun renderUI(batch: SpriteBatch, camera: Camera) {
@@ -238,178 +195,8 @@ class UIInventoryFull(
// UI items
categoryBar.render(batch, camera)
transitionPanel.render(batch, camera)
// render map while visible
/*if (currentScreenTransition > 1f + epsilon) {
renderScreenMinimap(batch, camera)
if (debugvals) {
batch.color = Color.CORAL
AppLoader.fontSmallNumbers.draw(batch, "Map", 300f, 10f)
}
}*/
// render inventory while visible
/*if (currentScreenTransition in epsilon..2f - epsilon) {
renderScreenInventory(batch, camera)
if (debugvals) {
batch.color = Color.CHARTREUSE
AppLoader.fontSmallNumbers.draw(batch, "Inv", 350f, 10f)
}
}*/
// render menu while visible
/*if (currentScreenTransition < 1f - epsilon) {
renderScreenGamemenu(batch, camera)
if (debugvals) {
batch.color = Color.SKY
AppLoader.fontSmallNumbers.draw(batch, "Men", 400f, 10f)
}
}*/
/*if (debugvals) {
batch.color = Color.WHITE
AppLoader.fontSmallNumbers.draw(batch, "minimap:$minimapScrOffX", 500f, 0f)
AppLoader.fontSmallNumbers.draw(batch, "inven:$inventoryScrOffX", 500f, 10f)
AppLoader.fontSmallNumbers.draw(batch, "menu:$menuScrOffX", 500f, 20f)
}*/
}
private val epsilon = 0.001f
/**
* - 0 on inventory screen
* - +WIDTH on minimap screen
* - -WIDTH on gamemenu screen
*/
/*private val minimapScrOffX: Float
get() = (currentScreenTransition - 2f) * AppLoader.screenW / 2f
private val inventoryScrOffX: Float
get() = (currentScreenTransition - 1f) * AppLoader.screenW / 2f
private val menuScrOffX: Float
get() = (currentScreenTransition - 0f) * AppLoader.screenW / 2f
private val minimapScrOpacity: Float
get() = (currentScreenTransition - 2f).coerceIn(0f, 1f)
private val inventoryScrOpacity: Float
get() = (currentScreenTransition - 1f).coerceIn(0f, 1f)
private val menuScrOpacity: Float
get() = (currentScreenTransition - 0f).coerceIn(0f, 1f)*/
//private val MINIMAP_WIDTH = 800f
//private val MINIMAP_HEIGHT = itemList.height.toFloat()
//private val MINIMAP_SKYCOL = Color(0x88bbddff.toInt())
//private var minimapZoom = 1f
//private var minimapPanX = -MinimapComposer.totalWidth / 2f
//private var minimapPanY = -MinimapComposer.totalHeight / 2f
//private val MINIMAP_ZOOM_MIN = 0.5f
//private val MINIMAP_ZOOM_MAX = 8f
//private val minimapFBO = FrameBuffer(Pixmap.Format.RGBA8888, MINIMAP_WIDTH.toInt(), MINIMAP_HEIGHT.toInt(), false)
//private val minimapCamera = OrthographicCamera(MINIMAP_WIDTH, MINIMAP_HEIGHT)
// TODO put 3 bare sub-UIs into proper UIcanvas to handle the motherfucking opacity
// TODO not yet refactored
/*private fun renderScreenMinimap(batch: SpriteBatch, camera: Camera) {
blendNormal(batch)
// update map panning
if (currentScreenTransition >= 2f - epsilon) {
// if left click is down and cursor is in the map area
if (Gdx.input.isButtonPressed(AppLoader.getConfigInt("mouseprimary")) &&
Terrarum.mouseScreenY in itemList.posY..itemList.posY + itemList.height) {
minimapPanX += Terrarum.mouseDeltaX / minimapZoom
minimapPanY += Terrarum.mouseDeltaY / minimapZoom
}
if (Gdx.input.isKeyPressed(Input.Keys.NUM_1)) {
minimapZoom *= (1f / 1.02f)
}
if (Gdx.input.isKeyPressed(Input.Keys.NUM_2)) {
minimapZoom *= 1.02f
}
if (Gdx.input.isKeyPressed(Input.Keys.NUM_3)) {
minimapZoom = 1f
minimapPanX = -MinimapComposer.totalWidth / 2f
minimapPanY = -MinimapComposer.totalHeight / 2f
}
try {
//minimapPanX = minimapPanX.coerceIn(-(MinimapComposer.totalWidth * minimapZoom) + MINIMAP_WIDTH, 0f) // un-comment this line to constain the panning over x-axis
} catch (e: IllegalArgumentException) { }
try {
//minimapPanY = minimapPanY.coerceIn(-(MinimapComposer.totalHeight * minimapZoom) + MINIMAP_HEIGHT, 0f)
} catch (e: IllegalArgumentException) { }
minimapZoom = minimapZoom.coerceIn(MINIMAP_ZOOM_MIN, MINIMAP_ZOOM_MAX)
// make image to roll over for x-axis. This is for the ROUNDWORLD implementation, feel free to remove below.
}
// render minimap
batch.end()
if (minimapRerenderTimer >= minimapRerenderInterval) {
minimapRerenderTimer = 0f
MinimapComposer.requestRender()
}
MinimapComposer.renderToBackground()
minimapFBO.inAction(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 ]
// [ 0 1 0 ] x [ 0 s 0 ] = [ 0 s 0 ]
// [ px py 1 ] [ w/2 h/2 1 ] [ tx ty 1 ]
//
// 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
batch.fillRect(0f, 0f, MINIMAP_WIDTH, MINIMAP_HEIGHT)
// the actual image
batch.color = Color.WHITE
batch.draw(MinimapComposer.tempTex, tx, ty + MinimapComposer.totalHeight * minimapZoom, MinimapComposer.totalWidth * minimapZoom, -MinimapComposer.totalHeight * minimapZoom)
}
}
batch.begin()
if (debugvals) {
AppLoader.fontSmallNumbers.draw(batch, "$minimapPanX, $minimapPanY; x$minimapZoom", minimapScrOffX + (AppLoader.screenW - MINIMAP_WIDTH) / 2, -10f + itemList.posY)
}
batch.projectionMatrix = camera.combined
// 1px stroke
batch.color = Color.WHITE
batch.fillRect(-1 + minimapScrOffX + (AppLoader.screenW - MINIMAP_WIDTH) / 2, -1 + itemList.posY.toFloat(), 2 + MINIMAP_WIDTH, 2 + MINIMAP_HEIGHT)
// control hints
batch.color = Color.WHITE
AppLoader.fontGame.draw(batch, minimapControlHelp, offsetX + minimapScrOffX, yEnd - 20)
// the minimap
batch.draw(minimapFBO.colorBufferTexture, minimapScrOffX + (AppLoader.screenW - MINIMAP_WIDTH) / 2, itemList.posY.toFloat())
}*/
fun rebuildList() {
transitionalItemCells.rebuildList()
}

View File

@@ -0,0 +1,146 @@
package net.torvald.terrarum.modulebasegame.ui
import com.badlogic.gdx.Gdx
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 net.torvald.terrarum.*
import net.torvald.terrarum.blockstats.MinimapComposer
import net.torvald.terrarum.ui.UICanvas
class UIInventoryMinimap(val full: UIInventoryFull) : UICanvas() {
private val debugvals = true
override var width: Int = AppLoader.screenW
override var height: Int = AppLoader.screenH
override var openCloseTime = 0.0f
private val MINIMAP_WIDTH = 800f
private val MINIMAP_HEIGHT = full.INVENTORY_CELLS_UI_HEIGHT.toFloat()
private val MINIMAP_SKYCOL = Color(0x88bbddff.toInt())
private var minimapZoom = 1f
private var minimapPanX = -MinimapComposer.totalWidth / 2f
private var minimapPanY = -MinimapComposer.totalHeight / 2f
private val MINIMAP_ZOOM_MIN = 0.5f
private val MINIMAP_ZOOM_MAX = 8f
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
override fun updateUI(delta: Float) {
MinimapComposer.setWorld(Terrarum.ingame!!.world)
MinimapComposer.update()
minimapRerenderTimer += Gdx.graphics.rawDeltaTime
}
override fun renderUI(batch: SpriteBatch, camera: Camera) {
blendNormal(batch)
// update map panning
// if left click is down and cursor is in the map area
if (Gdx.input.isButtonPressed(AppLoader.getConfigInt("mouseprimary")) &&
Terrarum.mouseScreenY in full.INVENTORY_CELLS_OFFSET_Y..full.INVENTORY_CELLS_OFFSET_Y + full.INVENTORY_CELLS_UI_HEIGHT) {
minimapPanX += Terrarum.mouseDeltaX * 2f / minimapZoom
minimapPanY += Terrarum.mouseDeltaY * 2f / minimapZoom
}
if (Gdx.input.isKeyPressed(Input.Keys.NUM_1)) {
minimapZoom *= (1f / 1.02f)
}
if (Gdx.input.isKeyPressed(Input.Keys.NUM_2)) {
minimapZoom *= 1.02f
}
if (Gdx.input.isKeyPressed(Input.Keys.NUM_3)) {
minimapZoom = 1f
minimapPanX = -MinimapComposer.totalWidth / 2f
minimapPanY = -MinimapComposer.totalHeight / 2f
}
try {
//minimapPanX = minimapPanX.coerceIn(-(MinimapComposer.totalWidth * minimapZoom) + MINIMAP_WIDTH, 0f) // un-comment this line to constain the panning over x-axis
} catch (e: IllegalArgumentException) { }
try {
//minimapPanY = minimapPanY.coerceIn(-(MinimapComposer.totalHeight * minimapZoom) + MINIMAP_HEIGHT, 0f)
} catch (e: IllegalArgumentException) { }
minimapZoom = minimapZoom.coerceIn(MINIMAP_ZOOM_MIN, MINIMAP_ZOOM_MAX)
// make image to roll over for x-axis. This is for the ROUNDWORLD implementation, feel free to remove below.
// render minimap
batch.end()
if (minimapRerenderTimer >= minimapRerenderInterval) {
minimapRerenderTimer = 0f
MinimapComposer.requestRender()
}
MinimapComposer.renderToBackground()
minimapFBO.inAction(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 ]
// [ 0 1 0 ] x [ 0 s 0 ] = [ 0 s 0 ]
// [ px py 1 ] [ w/2 h/2 1 ] [ tx ty 1 ]
//
// 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
batch.fillRect(0f, 0f, MINIMAP_WIDTH, MINIMAP_HEIGHT)
// the actual image
batch.color = Color.WHITE
batch.draw(MinimapComposer.tempTex, tx, ty + MinimapComposer.totalHeight * minimapZoom, MinimapComposer.totalWidth * minimapZoom, -MinimapComposer.totalHeight * minimapZoom)
}
}
batch.begin()
if (debugvals) {
AppLoader.fontSmallNumbers.draw(batch, "$minimapPanX, $minimapPanY; x$minimapZoom", (AppLoader.screenW - MINIMAP_WIDTH) / 2, -10f + full.INVENTORY_CELLS_OFFSET_Y)
}
batch.projectionMatrix = camera.combined
// 1px stroke
batch.color = Color.WHITE
batch.fillRect((AppLoader.screenW - MINIMAP_WIDTH) / 2, -1 + full.INVENTORY_CELLS_OFFSET_Y.toFloat(), MINIMAP_WIDTH, 1f)
batch.fillRect((AppLoader.screenW - MINIMAP_WIDTH) / 2, full.INVENTORY_CELLS_OFFSET_Y + MINIMAP_HEIGHT, MINIMAP_WIDTH, 1f)
batch.fillRect(-1 + (AppLoader.screenW - MINIMAP_WIDTH) / 2, full.INVENTORY_CELLS_OFFSET_Y.toFloat(), 1f, MINIMAP_HEIGHT)
batch.fillRect((AppLoader.screenW - MINIMAP_WIDTH) / 2 + MINIMAP_WIDTH, full.INVENTORY_CELLS_OFFSET_Y.toFloat(), 1f, MINIMAP_HEIGHT)
// control hints
batch.color = Color.WHITE
AppLoader.fontGame.draw(batch, full.minimapControlHelp, full.offsetX, full.yEnd - 20)
// the minimap
batch.draw(minimapFBO.colorBufferTexture, (AppLoader.screenW - MINIMAP_WIDTH) / 2, full.INVENTORY_CELLS_OFFSET_Y.toFloat())
}
override fun doOpening(delta: Float) {}
override fun doClosing(delta: Float) {}
override fun endOpening(delta: Float) {}
override fun endClosing(delta: Float) {}
override fun dispose() {
minimapFBO.dispose()
}
}