inventory wallet view

This commit is contained in:
minjaesong
2019-02-11 18:02:52 +09:00
parent b9fbacad14
commit 9031ff0c2a
6 changed files with 72 additions and 10 deletions

Binary file not shown.

View File

@@ -183,6 +183,13 @@ public class AppLoader implements ApplicationListener {
public static TerrarumController gamepad = null;
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)
*/
@@ -752,6 +759,21 @@ public class AppLoader implements ApplicationListener {
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
*/

View File

@@ -53,6 +53,9 @@ object DefaultConfig {
jsonObject.addProperty("gamepadtriggeraxis", 4) // positive: LT, negative: RT (xbox pad)
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"

View File

@@ -5,7 +5,6 @@ import com.badlogic.gdx.graphics.Color
import com.jme3.math.FastMath
import net.torvald.spriteanimation.HasAssembledSprite
import net.torvald.terrarum.*
import net.torvald.terrarum.AppLoader.gamepadDeadzone
import net.torvald.terrarum.gameactors.*
import net.torvald.terrarum.gameactors.faction.Faction
import net.torvald.terrarum.gameworld.GameWorld
@@ -225,7 +224,7 @@ open class ActorHumanoid(
isRightDown = Gdx.input.isKeyPressed(AppLoader.getConfigInt("keyright"))
isJumpDown = Gdx.input.isKeyPressed(AppLoader.getConfigInt("keyjump"))
val gamepad = (Terrarum.ingame as Ingame).ingameController.gamepad
val gamepad = AppLoader.gamepad
if (gamepad != null) {
axisX = gamepad.getAxis(AppLoader.getConfigInt("gamepadaxislx"))
@@ -234,10 +233,10 @@ open class ActorHumanoid(
axisRY = gamepad.getAxis(AppLoader.getConfigInt("gamepadaxisry"))
// deadzonning
if (Math.abs(axisX) < AppLoader.gamepadDeadzone) axisX = 0f
if (Math.abs(axisY) < AppLoader.gamepadDeadzone) axisY = 0f
if (Math.abs(axisRX) < AppLoader.gamepadDeadzone) axisRX = 0f
if (Math.abs(axisRY) < AppLoader.gamepadDeadzone) axisRY = 0f
if (AppLoader.inDeadzone(gamepad, AppLoader.getConfigInt("gamepadaxislx"))) axisX = 0f
if (AppLoader.inDeadzone(gamepad, AppLoader.getConfigInt("gamepadaxisly"))) axisY = 0f
if (AppLoader.inDeadzone(gamepad, AppLoader.getConfigInt("gamepadaxisrx"))) axisRX = 0f
if (AppLoader.inDeadzone(gamepad, AppLoader.getConfigInt("gamepadaxisry"))) axisRY = 0f
isJumpDown = Gdx.input.isKeyPressed(AppLoader.getConfigInt("keyjump")) ||
gamepad.getButton(AppLoader.getConfigInt("gamepadltrigger"))
@@ -252,7 +251,7 @@ open class ActorHumanoid(
}
private inline val hasController: Boolean
get() = if (isGamer) (Terrarum.ingame as Ingame).ingameController.hasGamepad
get() = if (isGamer) AppLoader.gamepad != null
else true
private fun processInput(delta: Float) {
@@ -266,7 +265,7 @@ open class ActorHumanoid(
}
}
// ↑F, ↑S
if (isWalkingH && !isLeftDown && !isRightDown && axisX.abs() < gamepadDeadzone) {
if (isWalkingH && !isLeftDown && !isRightDown && axisX == 0f) {
walkHStop()
prevHMoveKey = KEY_NULL
}
@@ -280,7 +279,7 @@ open class ActorHumanoid(
}
// ↑E
// ↑D
if (isNoClip && !isUpDown && !isDownDown && axisY.abs() < gamepadDeadzone) {
if (isNoClip && !isUpDown && !isDownDown && axisY == 0f) {
walkVStop()
prevVMoveKey = KEY_NULL
}

View File

@@ -49,7 +49,6 @@ class UIInventoryFull(
internal val catArrangement: IntArray = intArrayOf(9,6,7,1,0,2,3,4,5,8)
private val SP = "${0x3000.toChar()}${0x3000.toChar()}"
val listControlHelp: String
get() = if (AppLoader.environment == RunningEnvironment.PC)
@@ -398,6 +397,20 @@ class UIInventoryFull(
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() {
categoryBar.dispose()
itemList.dispose()

View File

@@ -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.ui.UIItem
import net.torvald.terrarum.ui.UIItemImageButton
import net.torvald.terrarumsansbitmap.gdx.TextureRegionPack
import java.util.*
/**
@@ -82,6 +83,9 @@ class UIItemInventoryDynamicList(
val defaultTextColour = Color(0xeaeaea_ff.toInt())
private val walletFont = TextureRegionPack("./assets/graphics/fonts/inventory_wallet_numbers.tga", 20, 9)
private var walletText = ""
companion object {
const val listGap = 8
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)
oldPosX = posX
@@ -347,6 +361,13 @@ class UIItemInventoryDynamicList(
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
}
@@ -356,6 +377,7 @@ class UIItemInventoryDynamicList(
gridModeButtons.forEach { it.dispose() }
scrollUpButton.dispose()
scrollDownButton.dispose()
walletFont.dispose()
}
override fun touchDown(screenX: Int, screenY: Int, pointer: Int, button: Int): Boolean {