mirror of
https://github.com/curioustorvald/Terrarum.git
synced 2026-03-08 12:51:51 +09:00
control helpers for smelter
This commit is contained in:
@@ -87,4 +87,5 @@ object ControlPresets {
|
||||
|
||||
return (presets[presetName] ?: throw IllegalStateException("No such keyboard preset: $presetName")).getOrDefault(label, App.getConfigInt(label))
|
||||
}
|
||||
|
||||
}
|
||||
@@ -67,15 +67,14 @@ internal class UIInventoryCells(
|
||||
min(UIInventoryCells.weightBarWidth, max(1f, UIInventoryCells.weightBarWidth * encumbrancePerc)),
|
||||
UIInventoryFull.controlHelpHeight - 6f
|
||||
)
|
||||
// debug text
|
||||
batch.color = Color.LIGHT_GRAY
|
||||
if (App.IS_DEVELOPMENT_BUILD) {
|
||||
App.fontSmallNumbers.draw(
|
||||
batch,
|
||||
"${actorInventory.capacity}/${actorInventory.maxCapacity}",
|
||||
encumbBarTextXPos,
|
||||
encumbBarYPos + UIInventoryFull.controlHelpHeight - 4f
|
||||
)
|
||||
|
||||
// tooltip
|
||||
if (Terrarum.mouseScreenX.toFloat() in encumbBarXPos..encumbBarXPos+UIInventoryCells.weightBarWidth && Terrarum.mouseScreenY.toFloat() in encumbBarYPos..encumbBarYPos+UIInventoryFull.controlHelpHeight - 6f) {
|
||||
INGAME.setTooltipMessage("${actorInventory.capacity}/${actorInventory.maxCapacity}")
|
||||
tooltipShowing[10001] = true
|
||||
}
|
||||
else {
|
||||
tooltipShowing[10001] = false
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -114,6 +114,10 @@ object UIItemInventoryCellCommonRes {
|
||||
Toolkit.Theme.COL_CELL_FILL
|
||||
)
|
||||
|
||||
/**
|
||||
* Special hash values:
|
||||
* - 10001: Encumbrance bar
|
||||
*/
|
||||
val tooltipShowing = HashMap<Long, Boolean>() // Long: `hash` field on UIItemInventoryItemGrid
|
||||
}
|
||||
|
||||
|
||||
@@ -17,6 +17,7 @@ import net.torvald.terrarum.ui.UIItemCatBar.Companion.FILTER_CAT_ALL
|
||||
import net.torvald.terrarum.ui.UIItemInventoryElemWide.Companion.UNIQUE_ITEM_HAS_NO_AMOUNT
|
||||
import net.torvald.terrarumsansbitmap.gdx.TextureRegionPack
|
||||
import net.torvald.unicode.getKeycapPC
|
||||
import net.torvald.unicode.getMouseButton
|
||||
import kotlin.math.roundToInt
|
||||
import kotlin.math.roundToLong
|
||||
|
||||
@@ -189,6 +190,13 @@ class UISmelterBasic(val smelter: FixtureSmelterBasic) : UICanvas(
|
||||
emptyCellIcon = smelterCellIcons.get(1, 0),
|
||||
keyDownFun = { _, _, _, _, _ -> },
|
||||
touchDownFun = { _, _, button, _, self ->
|
||||
if (clickedOn != 0) {
|
||||
clickedOn = 0
|
||||
oreItemSlot.forceHighlighted = false
|
||||
fireboxItemSlot.forceHighlighted = false
|
||||
itemListUpdate()
|
||||
}
|
||||
|
||||
if (smelter.productItem != null) {
|
||||
val removeCount = if (button == App.getConfigInt("config_mouseprimary"))
|
||||
smelter.productItem!!.qty
|
||||
@@ -287,11 +295,46 @@ class UISmelterBasic(val smelter: FixtureSmelterBasic) : UICanvas(
|
||||
return true
|
||||
}
|
||||
|
||||
private val controlHelp: String
|
||||
get() = if (App.environment == RunningEnvironment.PC)
|
||||
"${getKeycapPC(ControlPresets.getKey("control_key_inventory"))} ${Lang["GAME_ACTION_CLOSE"]}"
|
||||
private val SP = "\u3000"
|
||||
private val controlHelpForSmelter = listOf(
|
||||
// no slot selected
|
||||
{ if (App.environment == RunningEnvironment.PC)
|
||||
"${getKeycapPC(ControlPresets.getKey("control_key_inventory"))} ${Lang["GAME_ACTION_CLOSE"]}$SP" +
|
||||
"${getMouseButton(App.getConfigInt("config_mouseprimary"))} ${Lang["GAME_ACTION_SELECT_SLOT"]}"
|
||||
else
|
||||
"${App.gamepadLabelStart} ${Lang["GAME_ACTION_CLOSE"]}"
|
||||
"${App.gamepadLabelStart} ${Lang["GAME_ACTION_CLOSE"]}" },
|
||||
// ore slot
|
||||
{ if (App.environment == RunningEnvironment.PC)
|
||||
"${getKeycapPC(ControlPresets.getKey("control_key_inventory"))} ${Lang["GAME_ACTION_CLOSE"]}$SP" +
|
||||
"${getMouseButton(App.getConfigInt("config_mouseprimary"))} ${Lang["GAME_ACTION_TAKE_ALL_CONT"]}$SP" +
|
||||
"${getMouseButton(App.getConfigInt("config_mousesecondary"))} ${Lang["GAME_ACTION_TAKE_ONE_CONT"]}"
|
||||
else
|
||||
"${App.gamepadLabelStart} ${Lang["GAME_ACTION_CLOSE"]}" },
|
||||
// firebox slot
|
||||
{ if (App.environment == RunningEnvironment.PC)
|
||||
"${getKeycapPC(ControlPresets.getKey("control_key_inventory"))} ${Lang["GAME_ACTION_CLOSE"]}$SP" +
|
||||
"${getMouseButton(App.getConfigInt("config_mouseprimary"))} ${Lang["GAME_ACTION_TAKE_ALL_CONT"]}$SP" +
|
||||
"${getMouseButton(App.getConfigInt("config_mousesecondary"))} ${Lang["GAME_ACTION_TAKE_ONE_CONT"]}"
|
||||
else
|
||||
"${App.gamepadLabelStart} ${Lang["GAME_ACTION_CLOSE"]}" }
|
||||
)
|
||||
|
||||
private val controlHelpForInventory = listOf(
|
||||
// no slot selected
|
||||
{ "" },
|
||||
// ore slot
|
||||
{ if (App.environment == RunningEnvironment.PC)
|
||||
"${getMouseButton(App.getConfigInt("config_mouseprimary"))} ${Lang["GAME_ACTION_PUT_ALL_CONT"]}$SP" +
|
||||
"${getMouseButton(App.getConfigInt("config_mousesecondary"))} ${Lang["GAME_ACTION_PUT_ONE_CONT"]}"
|
||||
else
|
||||
"${App.gamepadLabelStart} ${Lang["GAME_ACTION_CLOSE"]}" },
|
||||
// firebox slot
|
||||
{ if (App.environment == RunningEnvironment.PC)
|
||||
"${getMouseButton(App.getConfigInt("config_mouseprimary"))} ${Lang["GAME_ACTION_PUT_ALL_CONT"]}$SP" +
|
||||
"${getMouseButton(App.getConfigInt("config_mousesecondary"))} ${Lang["GAME_ACTION_PUT_ONE_CONT"]}"
|
||||
else
|
||||
"${App.gamepadLabelStart} ${Lang["GAME_ACTION_CLOSE"]}" }
|
||||
)
|
||||
|
||||
override fun renderUI(frameDelta: Float, batch: SpriteBatch, camera: OrthographicCamera) {
|
||||
batch.color = backdropColour
|
||||
@@ -307,14 +350,30 @@ class UISmelterBasic(val smelter: FixtureSmelterBasic) : UICanvas(
|
||||
// control hints
|
||||
batch.color = Color.WHITE
|
||||
val controlHintXPos = leftPanelX + 2f
|
||||
val controlHintXPos2 = playerThings.posX + 2f
|
||||
blendNormalStraightAlpha(batch)
|
||||
App.fontGame.draw(batch, controlHelp, controlHintXPos, UIInventoryFull.yEnd - 20)
|
||||
App.fontGame.draw(batch, controlHelpForSmelter[clickedOn](), controlHintXPos, UIInventoryFull.yEnd - 20)
|
||||
|
||||
// deal with the text that is too long
|
||||
val encumbBarXPos = playerThings.posX + playerThings.width - UIInventoryCells.weightBarWidth + 36
|
||||
val encumbBarYPos = UIInventoryFull.yEnd - 20 + 3f
|
||||
|
||||
val tr = controlHelpForInventory[clickedOn]()
|
||||
val trLen = App.fontGame.getWidth(tr)
|
||||
val encumbTextX = encumbBarXPos - 6 - App.fontGame.getWidth(Lang["GAME_INVENTORY_ENCUMBRANCE"])
|
||||
if (controlHintXPos2 + trLen + 4 >= encumbTextX) {
|
||||
tr.split(SP).forEachIndexed { index, s ->
|
||||
App.fontGame.draw(batch, s, controlHintXPos2, UIInventoryFull.yEnd - 20 + 20 * index)
|
||||
}
|
||||
}
|
||||
else {
|
||||
App.fontGame.draw(batch, controlHelpForInventory[clickedOn](), controlHintXPos2, UIInventoryFull.yEnd - 20)
|
||||
}
|
||||
|
||||
|
||||
|
||||
if (INGAME.actorNowPlaying != null) {
|
||||
//draw player encumb
|
||||
val encumbBarXPos = playerThings.posX + playerThings.width - UIInventoryCells.weightBarWidth + 36
|
||||
val encumbBarYPos = UIInventoryFull.yEnd - 20 + 3f
|
||||
UIInventoryCells.drawEncumbranceBar(batch, encumbBarXPos, encumbBarYPos, encumbrancePerc, INGAME.actorNowPlaying!!.inventory)
|
||||
}
|
||||
|
||||
|
||||
@@ -71,6 +71,13 @@ fun getKeycapPC(c: Char) = when (c.uppercaseChar()) {
|
||||
else -> throw IllegalArgumentException("Not in range: ${c.code - 32}")
|
||||
}
|
||||
fun getKeycapPC(keycode: Int) = getKeycapPC(com.badlogic.gdx.Input.Keys.toString(keycode)[0])
|
||||
fun getMouseButton(button: Int) = when (button) {
|
||||
0 -> KEYCAP_LEFT_MOUSE
|
||||
1 -> KEYCAP_RIGHT_MOUSE
|
||||
2 -> KEYCAP_WHEEL
|
||||
else -> throw IllegalArgumentException("Unknown mouse button: $button")
|
||||
}
|
||||
|
||||
fun getKeycapConsole(c: Char) = when (c.uppercaseChar()) {
|
||||
in ' '..'_' -> (0xE040 + c.code - 32).toChar()
|
||||
else -> throw IllegalArgumentException("Not in range: ${c.code - 32}")
|
||||
|
||||
Reference in New Issue
Block a user