mirror of
https://github.com/curioustorvald/Terrarum.git
synced 2026-06-10 02:24:05 +09:00
inventory wallet view
This commit is contained in:
BIN
assets/graphics/fonts/inventory_wallet_numbers.tga
LFS
Normal file
BIN
assets/graphics/fonts/inventory_wallet_numbers.tga
LFS
Normal file
Binary file not shown.
@@ -183,6 +183,13 @@ public class AppLoader implements ApplicationListener {
|
|||||||
public static TerrarumController gamepad = null;
|
public static TerrarumController gamepad = null;
|
||||||
public static float gamepadDeadzone = 0.2f;
|
public static float gamepadDeadzone = 0.2f;
|
||||||
|
|
||||||
|
public static boolean inDeadzone(TerrarumController controller, int axis) {
|
||||||
|
float ax = controller.getAxis(axis);
|
||||||
|
float zero = (axis < 4) ? getConfigFloatArray("gamepadaxiszeropoints")[axis] : 0f;
|
||||||
|
|
||||||
|
return Math.abs(ax - zero) < gamepadDeadzone;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* For the events depends on rendering frame (e.g. flicker on post-hit invincibility)
|
* For the events depends on rendering frame (e.g. flicker on post-hit invincibility)
|
||||||
*/
|
*/
|
||||||
@@ -752,6 +759,21 @@ public class AppLoader implements ApplicationListener {
|
|||||||
return ((int[]) cfg);
|
return ((int[]) cfg);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static float[] getConfigFloatArray(String key) {
|
||||||
|
Object cfg = getConfigMaster(key);
|
||||||
|
if (cfg instanceof JsonArray) {
|
||||||
|
JsonArray jsonArray = ((JsonArray) cfg).getAsJsonArray();
|
||||||
|
//return IntArray(jsonArray.size(), { i -> jsonArray[i].asInt })
|
||||||
|
float[] floatArray = new float[jsonArray.size()];
|
||||||
|
for (int i = 0; i < jsonArray.size(); i++) {
|
||||||
|
floatArray[i] = jsonArray.get(i).getAsInt();
|
||||||
|
}
|
||||||
|
return floatArray;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
return ((float[]) cfg);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get config from config file. If the entry does not exist, get from defaults; if the entry is not in the default, NullPointerException will be thrown
|
* Get config from config file. If the entry does not exist, get from defaults; if the entry is not in the default, NullPointerException will be thrown
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -53,6 +53,9 @@ object DefaultConfig {
|
|||||||
jsonObject.addProperty("gamepadtriggeraxis", 4) // positive: LT, negative: RT (xbox pad)
|
jsonObject.addProperty("gamepadtriggeraxis", 4) // positive: LT, negative: RT (xbox pad)
|
||||||
jsonObject.addProperty("gamepadtriggeraxis2", 5) // just in case... (RT)
|
jsonObject.addProperty("gamepadtriggeraxis2", 5) // just in case... (RT)
|
||||||
|
|
||||||
|
val axesZeroPoints = JsonArray(); axesZeroPoints.add(0f); axesZeroPoints.add(0f); axesZeroPoints.add(0f); axesZeroPoints.add(0f)
|
||||||
|
jsonObject.add("gamepadaxiszeropoints", axesZeroPoints) // to accomodate shifted zero point of analog stick
|
||||||
|
|
||||||
jsonObject.addProperty("gamepadlabelstyle", "msxb360") // "nwii", "logitech", "sonyps", "msxb360", "generic"
|
jsonObject.addProperty("gamepadlabelstyle", "msxb360") // "nwii", "logitech", "sonyps", "msxb360", "generic"
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -5,7 +5,6 @@ import com.badlogic.gdx.graphics.Color
|
|||||||
import com.jme3.math.FastMath
|
import com.jme3.math.FastMath
|
||||||
import net.torvald.spriteanimation.HasAssembledSprite
|
import net.torvald.spriteanimation.HasAssembledSprite
|
||||||
import net.torvald.terrarum.*
|
import net.torvald.terrarum.*
|
||||||
import net.torvald.terrarum.AppLoader.gamepadDeadzone
|
|
||||||
import net.torvald.terrarum.gameactors.*
|
import net.torvald.terrarum.gameactors.*
|
||||||
import net.torvald.terrarum.gameactors.faction.Faction
|
import net.torvald.terrarum.gameactors.faction.Faction
|
||||||
import net.torvald.terrarum.gameworld.GameWorld
|
import net.torvald.terrarum.gameworld.GameWorld
|
||||||
@@ -225,7 +224,7 @@ open class ActorHumanoid(
|
|||||||
isRightDown = Gdx.input.isKeyPressed(AppLoader.getConfigInt("keyright"))
|
isRightDown = Gdx.input.isKeyPressed(AppLoader.getConfigInt("keyright"))
|
||||||
isJumpDown = Gdx.input.isKeyPressed(AppLoader.getConfigInt("keyjump"))
|
isJumpDown = Gdx.input.isKeyPressed(AppLoader.getConfigInt("keyjump"))
|
||||||
|
|
||||||
val gamepad = (Terrarum.ingame as Ingame).ingameController.gamepad
|
val gamepad = AppLoader.gamepad
|
||||||
|
|
||||||
if (gamepad != null) {
|
if (gamepad != null) {
|
||||||
axisX = gamepad.getAxis(AppLoader.getConfigInt("gamepadaxislx"))
|
axisX = gamepad.getAxis(AppLoader.getConfigInt("gamepadaxislx"))
|
||||||
@@ -234,10 +233,10 @@ open class ActorHumanoid(
|
|||||||
axisRY = gamepad.getAxis(AppLoader.getConfigInt("gamepadaxisry"))
|
axisRY = gamepad.getAxis(AppLoader.getConfigInt("gamepadaxisry"))
|
||||||
|
|
||||||
// deadzonning
|
// deadzonning
|
||||||
if (Math.abs(axisX) < AppLoader.gamepadDeadzone) axisX = 0f
|
if (AppLoader.inDeadzone(gamepad, AppLoader.getConfigInt("gamepadaxislx"))) axisX = 0f
|
||||||
if (Math.abs(axisY) < AppLoader.gamepadDeadzone) axisY = 0f
|
if (AppLoader.inDeadzone(gamepad, AppLoader.getConfigInt("gamepadaxisly"))) axisY = 0f
|
||||||
if (Math.abs(axisRX) < AppLoader.gamepadDeadzone) axisRX = 0f
|
if (AppLoader.inDeadzone(gamepad, AppLoader.getConfigInt("gamepadaxisrx"))) axisRX = 0f
|
||||||
if (Math.abs(axisRY) < AppLoader.gamepadDeadzone) axisRY = 0f
|
if (AppLoader.inDeadzone(gamepad, AppLoader.getConfigInt("gamepadaxisry"))) axisRY = 0f
|
||||||
|
|
||||||
isJumpDown = Gdx.input.isKeyPressed(AppLoader.getConfigInt("keyjump")) ||
|
isJumpDown = Gdx.input.isKeyPressed(AppLoader.getConfigInt("keyjump")) ||
|
||||||
gamepad.getButton(AppLoader.getConfigInt("gamepadltrigger"))
|
gamepad.getButton(AppLoader.getConfigInt("gamepadltrigger"))
|
||||||
@@ -252,7 +251,7 @@ open class ActorHumanoid(
|
|||||||
}
|
}
|
||||||
|
|
||||||
private inline val hasController: Boolean
|
private inline val hasController: Boolean
|
||||||
get() = if (isGamer) (Terrarum.ingame as Ingame).ingameController.hasGamepad
|
get() = if (isGamer) AppLoader.gamepad != null
|
||||||
else true
|
else true
|
||||||
|
|
||||||
private fun processInput(delta: Float) {
|
private fun processInput(delta: Float) {
|
||||||
@@ -266,7 +265,7 @@ open class ActorHumanoid(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
// ↑F, ↑S
|
// ↑F, ↑S
|
||||||
if (isWalkingH && !isLeftDown && !isRightDown && axisX.abs() < gamepadDeadzone) {
|
if (isWalkingH && !isLeftDown && !isRightDown && axisX == 0f) {
|
||||||
walkHStop()
|
walkHStop()
|
||||||
prevHMoveKey = KEY_NULL
|
prevHMoveKey = KEY_NULL
|
||||||
}
|
}
|
||||||
@@ -280,7 +279,7 @@ open class ActorHumanoid(
|
|||||||
}
|
}
|
||||||
// ↑E
|
// ↑E
|
||||||
// ↑D
|
// ↑D
|
||||||
if (isNoClip && !isUpDown && !isDownDown && axisY.abs() < gamepadDeadzone) {
|
if (isNoClip && !isUpDown && !isDownDown && axisY == 0f) {
|
||||||
walkVStop()
|
walkVStop()
|
||||||
prevVMoveKey = KEY_NULL
|
prevVMoveKey = KEY_NULL
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -49,7 +49,6 @@ class UIInventoryFull(
|
|||||||
internal val catArrangement: IntArray = intArrayOf(9,6,7,1,0,2,3,4,5,8)
|
internal val catArrangement: IntArray = intArrayOf(9,6,7,1,0,2,3,4,5,8)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
private val SP = "${0x3000.toChar()}${0x3000.toChar()}"
|
private val SP = "${0x3000.toChar()}${0x3000.toChar()}"
|
||||||
val listControlHelp: String
|
val listControlHelp: String
|
||||||
get() = if (AppLoader.environment == RunningEnvironment.PC)
|
get() = if (AppLoader.environment == RunningEnvironment.PC)
|
||||||
@@ -398,6 +397,20 @@ class UIInventoryFull(
|
|||||||
isEncumbered = actor.inventory.isEncumbered
|
isEncumbered = actor.inventory.isEncumbered
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun Int.fastLen(): Int {
|
||||||
|
return if (this < 0) 1 + this.unaryMinus().fastLen()
|
||||||
|
else if (this < 10) 1
|
||||||
|
else if (this < 100) 2
|
||||||
|
else if (this < 1000) 3
|
||||||
|
else if (this < 10000) 4
|
||||||
|
else if (this < 100000) 5
|
||||||
|
else if (this < 1000000) 6
|
||||||
|
else if (this < 10000000) 7
|
||||||
|
else if (this < 100000000) 8
|
||||||
|
else if (this < 1000000000) 9
|
||||||
|
else 10
|
||||||
|
}
|
||||||
|
|
||||||
override fun dispose() {
|
override fun dispose() {
|
||||||
categoryBar.dispose()
|
categoryBar.dispose()
|
||||||
itemList.dispose()
|
itemList.dispose()
|
||||||
|
|||||||
@@ -14,6 +14,7 @@ import net.torvald.terrarum.modulebasegame.ui.ItemSlotImageFactory.CELLCOLOUR_BL
|
|||||||
import net.torvald.terrarum.modulebasegame.ui.ItemSlotImageFactory.CELLCOLOUR_BLACK_ACTIVE
|
import net.torvald.terrarum.modulebasegame.ui.ItemSlotImageFactory.CELLCOLOUR_BLACK_ACTIVE
|
||||||
import net.torvald.terrarum.ui.UIItem
|
import net.torvald.terrarum.ui.UIItem
|
||||||
import net.torvald.terrarum.ui.UIItemImageButton
|
import net.torvald.terrarum.ui.UIItemImageButton
|
||||||
|
import net.torvald.terrarumsansbitmap.gdx.TextureRegionPack
|
||||||
import java.util.*
|
import java.util.*
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -82,6 +83,9 @@ class UIItemInventoryDynamicList(
|
|||||||
|
|
||||||
val defaultTextColour = Color(0xeaeaea_ff.toInt())
|
val defaultTextColour = Color(0xeaeaea_ff.toInt())
|
||||||
|
|
||||||
|
private val walletFont = TextureRegionPack("./assets/graphics/fonts/inventory_wallet_numbers.tga", 20, 9)
|
||||||
|
private var walletText = ""
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
const val listGap = 8
|
const val listGap = 8
|
||||||
const val horizontalCells = 11
|
const val horizontalCells = 11
|
||||||
@@ -246,6 +250,16 @@ class UIItemInventoryDynamicList(
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// draw wallet text
|
||||||
|
batch.color = Color.WHITE
|
||||||
|
walletText.forEachIndexed { index, it ->
|
||||||
|
batch.draw(
|
||||||
|
walletFont.get(0, it - '0'),
|
||||||
|
gridModeButtons[0].posX.toFloat(), // scroll button size: 20px, font width: 20 px
|
||||||
|
gridModeButtons[0].posY + height - index * walletFont.tileH.toFloat()
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
super.render(batch, camera)
|
super.render(batch, camera)
|
||||||
|
|
||||||
oldPosX = posX
|
oldPosX = posX
|
||||||
@@ -347,6 +361,13 @@ class UIItemInventoryDynamicList(
|
|||||||
itemPageCount = (inventorySortList.size.toFloat() / items.size.toFloat()).ceilInt()
|
itemPageCount = (inventorySortList.size.toFloat() / items.size.toFloat()).ceilInt()
|
||||||
|
|
||||||
|
|
||||||
|
// ¤ 42g
|
||||||
|
// ¤ 6969g
|
||||||
|
// ¤ 2147483647g
|
||||||
|
// g is read as "grave" /ɡraːv/ or /ɡɹeɪv/, because it isn't gram.
|
||||||
|
walletText = "<;?" + inventory.wallet.toString().padStart(4, '?') + ":"
|
||||||
|
|
||||||
|
|
||||||
rebuildList = false
|
rebuildList = false
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -356,6 +377,7 @@ class UIItemInventoryDynamicList(
|
|||||||
gridModeButtons.forEach { it.dispose() }
|
gridModeButtons.forEach { it.dispose() }
|
||||||
scrollUpButton.dispose()
|
scrollUpButton.dispose()
|
||||||
scrollDownButton.dispose()
|
scrollDownButton.dispose()
|
||||||
|
walletFont.dispose()
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun touchDown(screenX: Int, screenY: Int, pointer: Int, button: Int): Boolean {
|
override fun touchDown(screenX: Int, screenY: Int, pointer: Int, button: Int): Boolean {
|
||||||
|
|||||||
Reference in New Issue
Block a user