From d86fd5d5fef8e8b2836b3f764ce10f78ac0a4b3d Mon Sep 17 00:00:00 2001 From: minjaesong Date: Wed, 13 Jul 2022 01:08:38 +0900 Subject: [PATCH] chest ui: chest names are centered around the cells --- src/net/torvald/terrarum/IngameInstance.kt | 3 +- .../torvald/terrarum/gameitems/GameItem.kt | 2 +- .../gameactors/FixtureStorageChest.kt | 29 +++++++++++-------- .../modulebasegame/gameitems/BlockBase.kt | 1 + 4 files changed, 21 insertions(+), 14 deletions(-) diff --git a/src/net/torvald/terrarum/IngameInstance.kt b/src/net/torvald/terrarum/IngameInstance.kt index 6d8852c5b..0e16bd54a 100644 --- a/src/net/torvald/terrarum/IngameInstance.kt +++ b/src/net/torvald/terrarum/IngameInstance.kt @@ -340,7 +340,8 @@ open class IngameInstance(val batch: FlippingSpriteBatch, val isMultiplayer: Boo } /** - * Check for duplicates, append actor and sort the list + * Queue an actor to be added into the world. The actors will be added on the next update-frame and then the queue will be cleared. + * If the actor is null, this function will do nothing. */ open fun queueActorAddition(actor: Actor?) { if (actor == null) return diff --git a/src/net/torvald/terrarum/gameitems/GameItem.kt b/src/net/torvald/terrarum/gameitems/GameItem.kt index abdce512b..36f0641c7 100644 --- a/src/net/torvald/terrarum/gameitems/GameItem.kt +++ b/src/net/torvald/terrarum/gameitems/GameItem.kt @@ -363,7 +363,7 @@ abstract class GameItem(val originalID: ItemID) : Comparable, Cloneabl /** * @param actor actor to check the reach - * @param action returns true if the action was successfully performed + * @param action returns non-negative integer if the action was successfully performed * @return an amount to remove from the inventory (>= 0); -1 if the action failed or not in interactable range */ fun mouseInInteractableRange(actor: ActorWithBody, action: () -> Long): Long { diff --git a/src/net/torvald/terrarum/modulebasegame/gameactors/FixtureStorageChest.kt b/src/net/torvald/terrarum/modulebasegame/gameactors/FixtureStorageChest.kt index edb4220f4..594bf517d 100644 --- a/src/net/torvald/terrarum/modulebasegame/gameactors/FixtureStorageChest.kt +++ b/src/net/torvald/terrarum/modulebasegame/gameactors/FixtureStorageChest.kt @@ -4,6 +4,7 @@ import com.badlogic.gdx.graphics.Camera import com.badlogic.gdx.graphics.Color import com.badlogic.gdx.graphics.g2d.SpriteBatch import net.torvald.terrarum.* +import net.torvald.terrarum.App.gamepadLabelStart import net.torvald.terrarum.TerrarumAppConfiguration.TILE_SIZE import net.torvald.terrarum.gameactors.AVKey import net.torvald.terrarum.gameitems.GameItem @@ -22,6 +23,7 @@ import net.torvald.terrarum.modulebasegame.ui.UIItemInventoryItemGrid.Companion. import net.torvald.terrarum.ui.Toolkit import net.torvald.terrarum.ui.UICanvas import net.torvald.terrarumsansbitmap.gdx.TextureRegionPack +import net.torvald.unicode.getKeycapPC /** * Created by minjaesong on 2019-07-08. @@ -215,6 +217,13 @@ internal class UIStorageChest : UICanvas( private val thisOffsetX = UIInventoryFull.INVENTORY_CELLS_OFFSET_X() - halfSlotOffset private val thisOffsetX2 = thisOffsetX + (listGap + UIItemInventoryElemWide.height) * 7 private val thisOffsetY = UIInventoryFull.INVENTORY_CELLS_OFFSET_Y() + private val cellsWidth = (listGap + UIItemInventoryElemWide.height) * 6 - listGap + + private val controlHelp: String + get() = if (App.environment == RunningEnvironment.PC) + "${getKeycapPC(App.getConfigInt("control_key_inventory"))} ${Lang["GAME_ACTION_CLOSE"]}" + else + "$gamepadLabelStart ${Lang["GAME_ACTION_CLOSE"]} " override fun renderUI(batch: SpriteBatch, camera: Camera) { // background fill @@ -233,7 +242,7 @@ internal class UIStorageChest : UICanvas( // encumbrance meter val encumbranceText = Lang["GAME_INVENTORY_ENCUMBRANCE"] val chestName = chestNameFun() - val chestNameXpos = itemListChest.posX + 6f + val playerName = INGAME.actorNowPlaying!!.actorValue.getAsString(AVKey.NAME).orEmpty().let { it.ifBlank { Lang["GAME_INVENTORY"] } } val encumbBarXPos = itemListPlayer.posX + itemListPlayer.width - weightBarWidth val encumbBarTextXPos = encumbBarXPos - 6 - App.fontGame.getWidth(encumbranceText) val yEnd = -UIInventoryFull.YPOS_CORRECTION + (App.scr.height + internalHeight).div(2).toFloat() // directly copied from UIInventoryFull.yEnd @@ -243,10 +252,7 @@ internal class UIStorageChest : UICanvas( // encumbrance bar background batch.color = encumbBack - Toolkit.fillArea(batch, - encumbBarXPos, encumbBarYPos, - weightBarWidth, controlHelpHeight - 6f - ) + Toolkit.fillArea(batch, encumbBarXPos, encumbBarYPos, weightBarWidth, controlHelpHeight - 6f) // encumbrance bar batch.color = encumbCol Toolkit.fillArea(batch, @@ -260,16 +266,15 @@ internal class UIStorageChest : UICanvas( // chest name text batch.color = Color.WHITE - App.fontGame.draw(batch, chestName, thisOffsetX + 2, thisOffsetY - 30) - App.fontGame.draw(batch, Lang["GAME_INVENTORY"], thisOffsetX2 + 2, thisOffsetY - 30) + App.fontGame.draw(batch, chestName, thisOffsetX + (cellsWidth - App.fontGame.getWidth(chestName)) / 2, thisOffsetY - 30) + App.fontGame.draw(batch, playerName, thisOffsetX2 + (cellsWidth - App.fontGame.getWidth(playerName)) / 2, thisOffsetY - 30) + + // control hint + App.fontGame.draw(batch, controlHelp, thisOffsetX + 2f, encumbBarYPos - 3) // encumb text batch.color = Color.WHITE - App.fontGame.draw(batch, encumbranceText, encumbBarTextXPos, encumbBarYPos - 3f + - if (App.fontGame.getWidth(chestName) + 2 + chestNameXpos >= encumbBarTextXPos) - App.fontGame.lineHeight - else 0f - ) + App.fontGame.draw(batch, encumbranceText, encumbBarTextXPos, encumbBarYPos - 3f) } override fun doOpening(delta: Float) { diff --git a/src/net/torvald/terrarum/modulebasegame/gameitems/BlockBase.kt b/src/net/torvald/terrarum/modulebasegame/gameitems/BlockBase.kt index d9a97bd22..fce025dac 100644 --- a/src/net/torvald/terrarum/modulebasegame/gameitems/BlockBase.kt +++ b/src/net/torvald/terrarum/modulebasegame/gameitems/BlockBase.kt @@ -120,6 +120,7 @@ object BlockBase { world.setWireGraphOf(ox, oy, item, antivec or otherNodeCnx) } + // TODO: take ROUNDWORLD into account on node connection fun wireStartPrimaryUse(actor: ActorWithBody, gameItem: GameItem, delta: Float) = mouseInInteractableRange(actor) { val itemID = gameItem.originalID