mirror of
https://github.com/curioustorvald/Terrarum.git
synced 2026-03-07 12:21:52 +09:00
control presets
This commit is contained in:
@@ -5,10 +5,7 @@ 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.App
|
||||
import net.torvald.terrarum.FlippingSpriteBatch
|
||||
import net.torvald.terrarum.blendNormalStraightAlpha
|
||||
import net.torvald.terrarum.inAction
|
||||
import net.torvald.terrarum.*
|
||||
import net.torvald.terrarum.langpack.Lang
|
||||
import net.torvald.terrarum.modulecomputers.gameactors.FixtureHomeComputer
|
||||
import net.torvald.terrarum.ui.Toolkit
|
||||
@@ -45,7 +42,7 @@ internal class UIHomeComputer : UICanvas(
|
||||
private val fbo = FrameBuffer(Pixmap.Format.RGBA8888, width, height, false)
|
||||
|
||||
private val controlHelp =
|
||||
"${getKeycapPC(App.getConfigInt("control_key_inventory"))} ${Lang["GAME_ACTION_CLOSE"]}\u3000 " +
|
||||
"${getKeycapPC(ControlPresets.getKey("control_key_inventory"))} ${Lang["GAME_ACTION_CLOSE"]}\u3000 " +
|
||||
"$KEYCAP_CTRL$KEYCAP_SHIFT$KEYCAP_T$KEYCAP_R Terminate\u3000" +
|
||||
"$KEYCAP_CTRL$KEYCAP_SHIFT$KEYCAP_R$KEYCAP_S Reset\u3000" +
|
||||
"$KEYCAP_CTRL$KEYCAP_SHIFT$KEYCAP_R$KEYCAP_Q SysRq"
|
||||
|
||||
90
src/net/torvald/terrarum/ControlPresets.kt
Normal file
90
src/net/torvald/terrarum/ControlPresets.kt
Normal file
@@ -0,0 +1,90 @@
|
||||
package net.torvald.terrarum
|
||||
|
||||
import com.badlogic.gdx.Input
|
||||
|
||||
/**
|
||||
* Created by minjaesong on 2023-08-24.
|
||||
*/
|
||||
object ControlPresets {
|
||||
|
||||
val wasd = hashMapOf<String, Int>(
|
||||
"control_key_up" to Input.Keys.W,
|
||||
"control_key_left" to Input.Keys.A,
|
||||
"control_key_down" to Input.Keys.S,
|
||||
"control_key_right" to Input.Keys.D,
|
||||
|
||||
"control_key_jump" to Input.Keys.SPACE,
|
||||
"control_key_movementaux" to Input.Keys.SHIFT_LEFT, // movement-auxiliary, or hookshot
|
||||
"control_key_inventory" to Input.Keys.Q,
|
||||
"control_key_interact" to Input.Keys.R,
|
||||
"control_key_discard" to Input.Keys.F,
|
||||
"control_key_close" to Input.Keys.X, // this or hard-coded ESC
|
||||
"control_key_zoom" to Input.Keys.Z,
|
||||
|
||||
"control_key_gamemenu" to Input.Keys.TAB,
|
||||
"control_key_crafting" to Input.Keys.E,
|
||||
"control_key_quicksel" to Input.Keys.CONTROL_LEFT, // pie menu is now LShift because CapsLock is actually used by the my bespoke keyboard input
|
||||
)
|
||||
|
||||
val esdf = hashMapOf<String, Int>(
|
||||
"control_key_up" to Input.Keys.E,
|
||||
"control_key_left" to Input.Keys.S,
|
||||
"control_key_down" to Input.Keys.D,
|
||||
"control_key_right" to Input.Keys.F, // ESDF Masterrace
|
||||
|
||||
"control_key_jump" to Input.Keys.SPACE,
|
||||
"control_key_movementaux" to Input.Keys.A, // movement-auxiliary, or hookshot
|
||||
"control_key_inventory" to Input.Keys.Q,
|
||||
"control_key_interact" to Input.Keys.R,
|
||||
"control_key_discard" to Input.Keys.T,
|
||||
"control_key_close" to Input.Keys.C, // this or hard-coded ESC
|
||||
"control_key_zoom" to Input.Keys.Z,
|
||||
|
||||
"control_key_gamemenu" to Input.Keys.TAB,
|
||||
"control_key_crafting" to Input.Keys.W,
|
||||
"control_key_quicksel" to Input.Keys.SHIFT_LEFT, // pie menu is now LShift because CapsLock is actually used by the my bespoke keyboard input
|
||||
)
|
||||
|
||||
val ijkl = hashMapOf<String, Int>(
|
||||
"control_key_up" to Input.Keys.I,
|
||||
"control_key_left" to Input.Keys.J,
|
||||
"control_key_down" to Input.Keys.K,
|
||||
"control_key_right" to Input.Keys.L,
|
||||
|
||||
"control_key_jump" to Input.Keys.SPACE,
|
||||
"control_key_movementaux" to Input.Keys.SEMICOLON, // movement-auxiliary, or hookshot
|
||||
"control_key_inventory" to Input.Keys.P,
|
||||
"control_key_interact" to Input.Keys.U,
|
||||
"control_key_discard" to Input.Keys.Y,
|
||||
"control_key_close" to Input.Keys.M, // this or hard-coded ESC
|
||||
"control_key_zoom" to Input.Keys.SLASH,
|
||||
|
||||
"control_key_gamemenu" to Input.Keys.LEFT_BRACKET,
|
||||
"control_key_crafting" to Input.Keys.O,
|
||||
"control_key_quicksel" to Input.Keys.APOSTROPHE, // pie menu is now LShift because CapsLock is actually used by the my bespoke keyboard input
|
||||
)
|
||||
|
||||
val empty = hashMapOf<String, Int>()
|
||||
|
||||
val presets = hashMapOf( // unordered
|
||||
"WASD" to wasd,
|
||||
"ESDF" to esdf,
|
||||
"IJKL" to ijkl,
|
||||
"Custom" to empty,
|
||||
)
|
||||
|
||||
val presetLabels = listOf( // ordered
|
||||
"WASD",
|
||||
"ESDF",
|
||||
"IJKL",
|
||||
"Custom",
|
||||
)
|
||||
|
||||
fun getKey(label: String?): Int {
|
||||
if (label == null) return -1
|
||||
|
||||
val presetName = App.getConfigString("control_preset_keyboard") ?: "Custom"
|
||||
|
||||
return (presets[presetName] ?: throw IllegalStateException("No such keyboard preset: $presetName")).getOrDefault(label, App.getConfigInt(label))
|
||||
}
|
||||
}
|
||||
@@ -31,6 +31,8 @@ object DefaultConfig {
|
||||
|
||||
"usexinput" to true, // when FALSE, LT+RT input on xbox controller is impossible
|
||||
|
||||
"control_preset_keyboard" to "WASD",
|
||||
|
||||
"control_gamepad_keyn" to 3,
|
||||
"control_gamepad_keyw" to 2,
|
||||
"control_gamepad_keys" to 0,
|
||||
|
||||
@@ -5,14 +5,11 @@ import com.badlogic.gdx.Input
|
||||
import com.badlogic.gdx.InputAdapter
|
||||
import com.badlogic.gdx.controllers.Controllers
|
||||
import com.badlogic.gdx.utils.GdxRuntimeException
|
||||
import net.torvald.terrarum.App
|
||||
import net.torvald.terrarum.*
|
||||
import net.torvald.terrarum.App.printdbg
|
||||
import net.torvald.terrarum.App.printdbgerr
|
||||
import net.torvald.terrarum.ItemCodex
|
||||
import net.torvald.terrarum.Terrarum
|
||||
import net.torvald.terrarum.TerrarumAppConfiguration.TILE_SIZE
|
||||
import net.torvald.terrarum.controller.TerrarumController
|
||||
import net.torvald.terrarum.floorToInt
|
||||
import net.torvald.terrarum.gameactors.AVKey
|
||||
import net.torvald.terrarum.gameitems.GameItem
|
||||
import net.torvald.terrarum.gameworld.fmod
|
||||
@@ -168,7 +165,7 @@ class IngameController(val terrarumIngame: TerrarumIngame) : InputAdapter() {
|
||||
|
||||
// pie menu
|
||||
if (App.getConfigIntArray("control_key_quickselalt").contains(keycode)
|
||||
|| keycode == App.getConfigInt("control_key_quicksel")) {
|
||||
|| keycode == ControlPresets.getKey("control_key_quicksel")) {
|
||||
terrarumIngame.uiPieMenu.setAsOpen()
|
||||
terrarumIngame.uiQuickBar.setAsClose()
|
||||
}
|
||||
@@ -194,7 +191,7 @@ class IngameController(val terrarumIngame: TerrarumIngame) : InputAdapter() {
|
||||
|
||||
private fun tKeyUp(keycode: Int): Boolean {
|
||||
if (App.getConfigIntArray("control_key_quickselalt").contains(keycode)
|
||||
|| keycode == App.getConfigInt("control_key_quicksel")) {
|
||||
|| keycode == ControlPresets.getKey("control_key_quicksel")) {
|
||||
terrarumIngame.uiPieMenu.setAsClose()
|
||||
terrarumIngame.uiQuickBar.setAsOpen()
|
||||
}
|
||||
|
||||
@@ -254,11 +254,11 @@ open class ActorHumanoid : ActorWithBody, Controllable, Pocketed, Factionable, L
|
||||
|
||||
private fun updateGamerControlBox() {
|
||||
if (isGamer) {
|
||||
isUpDown = Gdx.input.isKeyPressed(App.getConfigInt("control_key_up"))
|
||||
isLeftDown = Gdx.input.isKeyPressed(App.getConfigInt("control_key_left"))
|
||||
isDownDown = Gdx.input.isKeyPressed(App.getConfigInt("control_key_down"))
|
||||
isRightDown = Gdx.input.isKeyPressed(App.getConfigInt("control_key_right"))
|
||||
isJumpDown = Gdx.input.isKeyPressed(App.getConfigInt("control_key_jump"))
|
||||
isUpDown = Gdx.input.isKeyPressed(ControlPresets.getKey("control_key_up"))
|
||||
isLeftDown = Gdx.input.isKeyPressed(ControlPresets.getKey("control_key_left"))
|
||||
isDownDown = Gdx.input.isKeyPressed(ControlPresets.getKey("control_key_down"))
|
||||
isRightDown = Gdx.input.isKeyPressed(ControlPresets.getKey("control_key_right"))
|
||||
isJumpDown = Gdx.input.isKeyPressed(ControlPresets.getKey("control_key_jump"))
|
||||
|
||||
val gamepad = App.gamepad
|
||||
|
||||
@@ -268,7 +268,7 @@ open class ActorHumanoid : ActorWithBody, Controllable, Pocketed, Factionable, L
|
||||
axisRX = gamepad.getAxis(App.getConfigInt("control_gamepad_axisrx"))
|
||||
axisRY = gamepad.getAxis(App.getConfigInt("control_gamepad_axisry"))
|
||||
|
||||
isJumpDown = Gdx.input.isKeyPressed(App.getConfigInt("control_key_jump")) ||
|
||||
isJumpDown = Gdx.input.isKeyPressed(ControlPresets.getKey("control_key_jump")) ||
|
||||
gamepad.getButton(App.getConfigInt("control_gamepad_ltrigger"))
|
||||
}
|
||||
|
||||
@@ -348,11 +348,11 @@ open class ActorHumanoid : ActorWithBody, Controllable, Pocketed, Factionable, L
|
||||
// ↑F, ↓S
|
||||
if (isRightDown && !isLeftDown) {
|
||||
walkHorizontal(false, AXIS_KEYBOARD)
|
||||
prevHMoveKey = App.getConfigInt("control_key_right")
|
||||
prevHMoveKey = ControlPresets.getKey("control_key_right")
|
||||
} // ↓F, ↑S
|
||||
else if (isLeftDown && !isRightDown) {
|
||||
walkHorizontal(true, AXIS_KEYBOARD)
|
||||
prevHMoveKey = App.getConfigInt("control_key_left")
|
||||
prevHMoveKey = ControlPresets.getKey("control_key_left")
|
||||
} // ↓F, ↓S
|
||||
/*else if (isLeftDown && isRightDown) {
|
||||
if (prevHMoveKey == KeyMap.getKeyCode(EnumKeyFunc.MOVE_LEFT)) {
|
||||
@@ -376,11 +376,11 @@ open class ActorHumanoid : ActorWithBody, Controllable, Pocketed, Factionable, L
|
||||
// ↑E, ↓D
|
||||
if (isDownDown && !isUpDown) {
|
||||
walkVertical(false, AXIS_KEYBOARD)
|
||||
prevVMoveKey = App.getConfigInt("control_key_down")
|
||||
prevVMoveKey = ControlPresets.getKey("control_key_down")
|
||||
} // ↓E, ↑D
|
||||
else if (isUpDown && !isDownDown) {
|
||||
walkVertical(true, AXIS_KEYBOARD)
|
||||
prevVMoveKey = App.getConfigInt("control_key_up")
|
||||
prevVMoveKey = ControlPresets.getKey("control_key_up")
|
||||
} // ↓E, ↓D
|
||||
/*else if (isUpDown && isDownDown) {
|
||||
if (prevVMoveKey == KeyMap.getKeyCode(EnumKeyFunc.MOVE_UP)) {
|
||||
|
||||
@@ -46,7 +46,7 @@ class UIBasicInfo() : UICanvas() {
|
||||
ELuptimer += delta
|
||||
}
|
||||
|
||||
if (mouseUp || Gdx.input.isKeyPressed(App.getConfigInt("control_key_interact"))) {
|
||||
if (mouseUp || Gdx.input.isKeyPressed(ControlPresets.getKey("control_key_interact"))) {
|
||||
ELuptimer = 0f
|
||||
ELon = true
|
||||
}
|
||||
|
||||
@@ -78,7 +78,7 @@ class UICrafting(val full: UIInventoryFull) : UICanvas(), HasInventory {
|
||||
|
||||
private val controlHelp: String
|
||||
get() = if (App.environment == RunningEnvironment.PC)
|
||||
"${getKeycapPC(App.getConfigInt("control_key_inventory"))} ${Lang["GAME_ACTION_CLOSE"]}"
|
||||
"${getKeycapPC(ControlPresets.getKey("control_key_inventory"))} ${Lang["GAME_ACTION_CLOSE"]}"
|
||||
else
|
||||
"$gamepadLabelStart ${Lang["GAME_ACTION_CLOSE"]}\u3000 " +
|
||||
"$gamepadLabelLEFTRIGHT ${Lang["GAME_OBJECTIVE_MULTIPLIER"]}\u3000 " +
|
||||
|
||||
@@ -8,6 +8,7 @@ import com.badlogic.gdx.graphics.g2d.SpriteBatch
|
||||
import net.torvald.unicode.EMDASH
|
||||
import net.torvald.terrarum.App
|
||||
import net.torvald.terrarum.CommonResourcePool
|
||||
import net.torvald.terrarum.ControlPresets
|
||||
import net.torvald.terrarum.gamecontroller.*
|
||||
import net.torvald.terrarum.langpack.Lang
|
||||
import net.torvald.terrarum.linearSearch
|
||||
@@ -318,7 +319,7 @@ private class UIItemInputKeycap(
|
||||
else if (parent.shiftin && keysymsLow[1]?.isNotEmpty() == true) keysymsLow[1]
|
||||
else keysymsLow[0]) ?: ""
|
||||
|
||||
val keysym0: Array<String?> = if (KeyToggler.isOn(App.getConfigInt("control_key_toggleime"))) {
|
||||
val keysym0: Array<String?> = if (KeyToggler.isOn(ControlPresets.getKey("control_key_toggleime"))) {
|
||||
if (parent.highlayer == null) arrayOf(keysymLow,keysymLow,keysymLow,keysymLow)
|
||||
else {
|
||||
val keysyms = parent.highlayer!!.config.symbols
|
||||
|
||||
@@ -3,7 +3,6 @@ package net.torvald.terrarum.modulebasegame.ui
|
||||
import com.badlogic.gdx.graphics.Camera
|
||||
import com.badlogic.gdx.graphics.Color
|
||||
import com.badlogic.gdx.graphics.g2d.SpriteBatch
|
||||
import com.badlogic.gdx.graphics.glutils.ShapeRenderer
|
||||
import com.jme3.math.FastMath
|
||||
import net.torvald.terrarum.*
|
||||
import net.torvald.terrarum.App.*
|
||||
@@ -162,10 +161,10 @@ class UIInventoryFull(
|
||||
private val SP = "\u3000 "
|
||||
val listControlHelp: String
|
||||
get() = if (App.environment == RunningEnvironment.PC)
|
||||
"${getKeycapPC(App.getConfigInt("control_key_inventory"))} ${Lang["GAME_ACTION_CLOSE"]}$SP" +
|
||||
"${getKeycapPC(ControlPresets.getKey("control_key_inventory"))} ${Lang["GAME_ACTION_CLOSE"]}$SP" +
|
||||
"$KEYCAP_LEFT_MOUSE ${Lang["GAME_INVENTORY_USE"]}$SP" +
|
||||
"$KEYCAP_1$ENDASH\u2009$KEYCAP_0 ${Lang["GAME_INVENTORY_REGISTER"]}$SP" +
|
||||
"${getKeycapPC(App.getConfigInt("control_key_discard"))} ${Lang["GAME_INVENTORY_DROP"]}"
|
||||
"${getKeycapPC(ControlPresets.getKey("control_key_discard"))} ${Lang["GAME_INVENTORY_DROP"]}"
|
||||
else
|
||||
"$gamepadLabelStart ${Lang["GAME_ACTION_CLOSE"]}$SP" +
|
||||
"$gamepadLabelLT ${Lang["CONTEXT_ITEM_MAP"]}$SP" +
|
||||
@@ -175,7 +174,7 @@ class UIInventoryFull(
|
||||
"$gamepadLabelEast ${Lang["GAME_INVENTORY_DROP"]}"
|
||||
val minimapControlHelp: String
|
||||
get() = if (App.environment == RunningEnvironment.PC)
|
||||
"${getKeycapPC(App.getConfigInt("control_key_inventory"))} ${Lang["GAME_ACTION_CLOSE"]}$SP" +
|
||||
"${getKeycapPC(ControlPresets.getKey("control_key_inventory"))} ${Lang["GAME_ACTION_CLOSE"]}$SP" +
|
||||
"$KEYCAP_LEFT_MOUSE$KEYCAP_MOVE ${Lang["GAME_ACTION_MOVE_VERB"]}"
|
||||
else
|
||||
"$gamepadLabelStart ${Lang["GAME_ACTION_CLOSE"]}$SP" +
|
||||
@@ -183,7 +182,7 @@ class UIInventoryFull(
|
||||
"$gamepadLabelRT ${Lang["GAME_INVENTORY"]}"
|
||||
val gameMenuControlHelp: String
|
||||
get() = if (App.environment == RunningEnvironment.PC)
|
||||
"${getKeycapPC(App.getConfigInt("control_key_inventory"))} ${Lang["GAME_ACTION_CLOSE"]}"
|
||||
"${getKeycapPC(ControlPresets.getKey("control_key_inventory"))} ${Lang["GAME_ACTION_CLOSE"]}"
|
||||
else
|
||||
"$gamepadLabelStart ${Lang["GAME_ACTION_CLOSE"]}$SP" +
|
||||
"$gamepadLabelLT ${Lang["GAME_INVENTORY"]}"
|
||||
@@ -249,7 +248,7 @@ class UIInventoryFull(
|
||||
}
|
||||
|
||||
// allow "control_key_gamemenu" to open this UI and bring system menu immediately
|
||||
this.handler.toggleKeyExtra.add { App.getConfigInt("control_key_gamemenu") }
|
||||
this.handler.toggleKeyExtra.add("control_key_gamemenu" )
|
||||
this.handler.toggleKeyExtraAction.add {
|
||||
if (it.isClosed) {
|
||||
INGAME.setTooltipMessage(null)
|
||||
@@ -263,7 +262,7 @@ class UIInventoryFull(
|
||||
}
|
||||
|
||||
// allow "control_key_crafting" to open this UI and bring system menu immediately
|
||||
this.handler.toggleKeyExtra.add { App.getConfigInt("control_key_crafting") }
|
||||
this.handler.toggleKeyExtra.add("control_key_crafting")
|
||||
this.handler.toggleKeyExtraAction.add {
|
||||
if (it.isClosed) {
|
||||
INGAME.setTooltipMessage(null)
|
||||
|
||||
@@ -6,10 +6,7 @@ import com.badlogic.gdx.graphics.Camera
|
||||
import com.badlogic.gdx.graphics.Color
|
||||
import com.badlogic.gdx.graphics.g2d.SpriteBatch
|
||||
import com.badlogic.gdx.graphics.g2d.TextureRegion
|
||||
import net.torvald.terrarum.App
|
||||
import net.torvald.terrarum.CommonResourcePool
|
||||
import net.torvald.terrarum.DefaultConfig
|
||||
import net.torvald.terrarum.Terrarum
|
||||
import net.torvald.terrarum.*
|
||||
import net.torvald.terrarum.langpack.Lang
|
||||
import net.torvald.terrarum.ui.*
|
||||
|
||||
@@ -38,16 +35,16 @@ class UIKeyboardControlPanel(remoCon: UIRemoCon?) : UICanvas() {
|
||||
|
||||
private val keycaps = hashMapOf(
|
||||
Input.Keys.GRAVE to UIItemKeycap(this, 1, 1, null, oneu, ""),
|
||||
Input.Keys.NUM_1 to UIItemKeycap(this, 33,1, Input.Keys.NUM_1, oneu, "1,3"),
|
||||
Input.Keys.NUM_2 to UIItemKeycap(this, 65,1, Input.Keys.NUM_2, oneu, "2,3"),
|
||||
Input.Keys.NUM_3 to UIItemKeycap(this, 97,1, Input.Keys.NUM_3, oneu, "3,3"),
|
||||
Input.Keys.NUM_4 to UIItemKeycap(this, 129,1, Input.Keys.NUM_4, oneu, "4,3"),
|
||||
Input.Keys.NUM_5 to UIItemKeycap(this, 161,1, Input.Keys.NUM_5, oneu, "5,3"),
|
||||
Input.Keys.NUM_6 to UIItemKeycap(this, 193,1, Input.Keys.NUM_6, oneu, "6,3"),
|
||||
Input.Keys.NUM_7 to UIItemKeycap(this, 225,1, Input.Keys.NUM_7, oneu, "7,3"),
|
||||
Input.Keys.NUM_8 to UIItemKeycap(this, 257,1, Input.Keys.NUM_8, oneu, "8,3"),
|
||||
Input.Keys.NUM_9 to UIItemKeycap(this, 289,1, Input.Keys.NUM_9, oneu, "9,3"),
|
||||
Input.Keys.NUM_0 to UIItemKeycap(this, 321,1, Input.Keys.NUM_0, oneu, "0,3"),
|
||||
Input.Keys.NUM_1 to UIItemKeycap(this, 33,1, null, oneu, "1,3"),
|
||||
Input.Keys.NUM_2 to UIItemKeycap(this, 65,1, null, oneu, "2,3"),
|
||||
Input.Keys.NUM_3 to UIItemKeycap(this, 97,1, null, oneu, "3,3"),
|
||||
Input.Keys.NUM_4 to UIItemKeycap(this, 129,1, null, oneu, "4,3"),
|
||||
Input.Keys.NUM_5 to UIItemKeycap(this, 161,1, null, oneu, "5,3"),
|
||||
Input.Keys.NUM_6 to UIItemKeycap(this, 193,1, null, oneu, "6,3"),
|
||||
Input.Keys.NUM_7 to UIItemKeycap(this, 225,1, null, oneu, "7,3"),
|
||||
Input.Keys.NUM_8 to UIItemKeycap(this, 257,1, null, oneu, "8,3"),
|
||||
Input.Keys.NUM_9 to UIItemKeycap(this, 289,1, null, oneu, "9,3"),
|
||||
Input.Keys.NUM_0 to UIItemKeycap(this, 321,1, null, oneu, "0,3"),
|
||||
Input.Keys.MINUS to UIItemKeycap(this, 353,1, Input.Keys.MINUS, oneu, "10,3"),
|
||||
Input.Keys.EQUALS to UIItemKeycap(this, 385,1, Input.Keys.EQUALS, oneu, "11,3"),
|
||||
Input.Keys.BACKSPACE to UIItemKeycap(this, 417,1, Input.Keys.BACKSPACE, 60, "24,5"),
|
||||
@@ -106,13 +103,22 @@ class UIKeyboardControlPanel(remoCon: UIRemoCon?) : UICanvas() {
|
||||
) // end of keycaps
|
||||
|
||||
private val resetButtonWidth = 140
|
||||
private val buttonReset = UIItemTextButton(this,
|
||||
private val presetButtonWidth = 200
|
||||
/*private val buttonReset = UIItemTextButton(this,
|
||||
{ Lang["MENU_LABEL_RESET"] },
|
||||
kbx + (width - resetButtonWidth) / 2,
|
||||
kby + 162 + 16,
|
||||
resetButtonWidth,
|
||||
hasBorder = true,
|
||||
alignment = UIItemTextButton.Companion.Alignment.CENTRE
|
||||
)*/
|
||||
private val presetSelector = UIItemTextSelector(this,
|
||||
kbx + (width - presetButtonWidth) / 2,
|
||||
kby + 162 + 16,
|
||||
ControlPresets.presetLabels.map { { it } },
|
||||
ControlPresets.presetLabels.indexOf(App.getConfigString("control_preset_keyboard")),
|
||||
presetButtonWidth,
|
||||
clickToShowPalette = false,
|
||||
)
|
||||
|
||||
private val controlPalette = UIItemControlPaletteBaloon(this, (Toolkit.drawWidth - 500) / 2, kby + 227)
|
||||
@@ -122,9 +128,14 @@ class UIKeyboardControlPanel(remoCon: UIRemoCon?) : UICanvas() {
|
||||
keycaps.values.forEach { addUIitem(it) }
|
||||
updateKeycaps()
|
||||
|
||||
buttonReset.clickOnceListener = { x, y ->
|
||||
/*buttonReset.clickOnceListener = { x, y ->
|
||||
resetKeyConfig()
|
||||
updateKeycaps()
|
||||
}*/
|
||||
|
||||
presetSelector.selectionChangeListener = { index ->
|
||||
App.setConfig("control_preset_keyboard", ControlPresets.presetLabels[index])
|
||||
updateKeycaps()
|
||||
}
|
||||
|
||||
// addUIitem(keyboardLayoutSelection)
|
||||
@@ -153,18 +164,18 @@ class UIKeyboardControlPanel(remoCon: UIRemoCon?) : UICanvas() {
|
||||
private fun updateKeycaps() {
|
||||
keycaps.values.forEach { it.symbolControl = null }
|
||||
// read config and put icons. Item order irrelevant
|
||||
keycaps[App.getConfigInt("control_key_up")]?.symbolControl = Keebsym.UP
|
||||
keycaps[App.getConfigInt("control_key_left")]?.symbolControl = Keebsym.LEFT
|
||||
keycaps[App.getConfigInt("control_key_down")]?.symbolControl = Keebsym.DOWN
|
||||
keycaps[App.getConfigInt("control_key_right")]?.symbolControl = Keebsym.RIGHT
|
||||
keycaps[App.getConfigInt("control_key_jump")]?.symbolControl = Keebsym.JUMP
|
||||
keycaps[App.getConfigInt("control_key_zoom")]?.symbolControl = Keebsym.ZOOM
|
||||
keycaps[App.getConfigInt("control_key_inventory")]?.symbolControl = Keebsym.INVENTORY
|
||||
keycaps[App.getConfigInt("control_key_movementaux")]?.symbolControl = Keebsym.HOOK
|
||||
keycaps[App.getConfigInt("control_key_quicksel")]?.symbolControl = Keebsym.PIE
|
||||
keycaps[App.getConfigInt("control_key_gamemenu")]?.symbolControl = Keebsym.MENU
|
||||
keycaps[App.getConfigInt("control_key_toggleime")]?.symbolControl = Keebsym.IME()
|
||||
keycaps[App.getConfigInt("control_key_crafting")]?.symbolControl = Keebsym.CRAFTING
|
||||
keycaps[ControlPresets.getKey("control_key_up")]?.symbolControl = Keebsym.UP
|
||||
keycaps[ControlPresets.getKey("control_key_left")]?.symbolControl = Keebsym.LEFT
|
||||
keycaps[ControlPresets.getKey("control_key_down")]?.symbolControl = Keebsym.DOWN
|
||||
keycaps[ControlPresets.getKey("control_key_right")]?.symbolControl = Keebsym.RIGHT
|
||||
keycaps[ControlPresets.getKey("control_key_jump")]?.symbolControl = Keebsym.JUMP
|
||||
keycaps[ControlPresets.getKey("control_key_zoom")]?.symbolControl = Keebsym.ZOOM
|
||||
keycaps[ControlPresets.getKey("control_key_inventory")]?.symbolControl = Keebsym.INVENTORY
|
||||
keycaps[ControlPresets.getKey("control_key_movementaux")]?.symbolControl = Keebsym.HOOK
|
||||
keycaps[ControlPresets.getKey("control_key_quicksel")]?.symbolControl = Keebsym.PIE
|
||||
keycaps[ControlPresets.getKey("control_key_gamemenu")]?.symbolControl = Keebsym.MENU
|
||||
keycaps[ControlPresets.getKey("control_key_toggleime")]?.symbolControl = Keebsym.IME()
|
||||
keycaps[ControlPresets.getKey("control_key_crafting")]?.symbolControl = Keebsym.CRAFTING
|
||||
}
|
||||
|
||||
internal var keycapClicked = -13372
|
||||
@@ -177,14 +188,14 @@ class UIKeyboardControlPanel(remoCon: UIRemoCon?) : UICanvas() {
|
||||
override fun updateUI(delta: Float) {
|
||||
uiItems.forEach {
|
||||
it.update(delta)
|
||||
if (it is UIItemKeycap && it.mousePushed) {
|
||||
if (it is UIItemKeycap && it.mousePushed && ControlPresets.presetLabels[presetSelector.selection] == "Custom") {
|
||||
it.selected = true
|
||||
// println("key ${it.key}; selected = ${it.selected}")
|
||||
keycapClicked = it.key ?: -13372
|
||||
}
|
||||
}
|
||||
|
||||
buttonReset.update(delta)
|
||||
presetSelector.update(delta)
|
||||
|
||||
controlPalette.update(delta)
|
||||
}
|
||||
@@ -195,7 +206,7 @@ class UIKeyboardControlPanel(remoCon: UIRemoCon?) : UICanvas() {
|
||||
// batch.color = fillCol
|
||||
// Toolkit.fillArea(batch, drawX, drawY, width, height)
|
||||
uiItems.forEach { it.render(batch, camera) }
|
||||
buttonReset.render(batch, camera)
|
||||
presetSelector.render(batch, camera)
|
||||
|
||||
// title
|
||||
// todo show "Keyboard"/"Gamepad" accordingly
|
||||
@@ -216,6 +227,10 @@ class UIKeyboardControlPanel(remoCon: UIRemoCon?) : UICanvas() {
|
||||
}
|
||||
|
||||
fun setControlOf(key: Int, control: Int) {
|
||||
if (App.getConfigString("control_preset_keyboard") != "Custom") {
|
||||
System.err.println("[UIKeyboardControlPanel] cannot set a control if the preset is not 'Custom' (current preset: ${App.getConfigString("control_preset_keyboard")})")
|
||||
return
|
||||
}
|
||||
if (control >= 0) {
|
||||
val controlName = UIItemControlPaletteBaloon.indexToConfigKey[control]!!
|
||||
|
||||
@@ -249,13 +264,19 @@ class UIKeyboardControlPanel(remoCon: UIRemoCon?) : UICanvas() {
|
||||
|
||||
override fun touchDown(screenX: Int, screenY: Int, pointer: Int, button: Int): Boolean {
|
||||
super.touchDown(screenX, screenY, pointer, button)
|
||||
buttonReset.touchDown(screenX, screenY, pointer, button)
|
||||
presetSelector.touchDown(screenX, screenY, pointer, button)
|
||||
return true
|
||||
}
|
||||
|
||||
override fun touchUp(screenX: Int, screenY: Int, pointer: Int, button: Int): Boolean {
|
||||
super.touchUp(screenX, screenY, pointer, button)
|
||||
buttonReset.touchUp(screenX, screenY, pointer, button)
|
||||
presetSelector.touchUp(screenX, screenY, pointer, button)
|
||||
return true
|
||||
}
|
||||
|
||||
override fun scrolled(amountX: Float, amountY: Float): Boolean {
|
||||
super.scrolled(amountX, amountY)
|
||||
presetSelector.scrolled(amountX, amountY)
|
||||
return true
|
||||
}
|
||||
|
||||
|
||||
@@ -141,7 +141,7 @@ class UILoadDemoSavefiles(val remoCon: UIRemoCon) : Advanceable() {
|
||||
|
||||
private val controlHelp: String
|
||||
get() = if (App.environment == RunningEnvironment.PC)
|
||||
"${getKeycapPC(App.getConfigInt("control_key_up"))}${getKeycapPC(App.getConfigInt("control_key_down"))}" +
|
||||
"${getKeycapPC(ControlPresets.getKey("control_key_up"))}${getKeycapPC(ControlPresets.getKey("control_key_down"))}" +
|
||||
" ${Lang["MENU_CONTROLS_SCROLL"]}"
|
||||
else
|
||||
"${getKeycapConsole('R')} ${Lang["MENU_CONTROLS_SCROLL"]}"
|
||||
@@ -408,12 +408,12 @@ class UILoadDemoSavefiles(val remoCon: UIRemoCon) : Advanceable() {
|
||||
if (this.isVisible) {
|
||||
val cells = getCells()
|
||||
|
||||
if ((keycode == Input.Keys.UP || keycode == App.getConfigInt("control_key_up")) && scrollTarget > 0) {
|
||||
if ((keycode == Input.Keys.UP || keycode == ControlPresets.getKey("control_key_up")) && scrollTarget > 0) {
|
||||
scrollFrom = listScroll
|
||||
scrollTarget -= 1
|
||||
scrollAnimCounter = 0f
|
||||
}
|
||||
else if ((keycode == Input.Keys.DOWN || keycode == App.getConfigInt("control_key_down")) && scrollTarget < cells.size - savesVisible) {
|
||||
else if ((keycode == Input.Keys.DOWN || keycode == ControlPresets.getKey("control_key_down")) && scrollTarget < cells.size - savesVisible) {
|
||||
scrollFrom = listScroll
|
||||
scrollTarget += 1
|
||||
scrollAnimCounter = 0f
|
||||
|
||||
@@ -25,7 +25,7 @@ class UILoadList(val full: UILoadSavegame) : UICanvas() {
|
||||
|
||||
private val controlHelp: String
|
||||
get() = if (App.environment == RunningEnvironment.PC)
|
||||
"${getKeycapPC(App.getConfigInt("control_key_up"))}${getKeycapPC(App.getConfigInt("control_key_down"))}" +
|
||||
"${getKeycapPC(ControlPresets.getKey("control_key_up"))}${getKeycapPC(ControlPresets.getKey("control_key_down"))}" +
|
||||
" ${Lang["MENU_CONTROLS_SCROLL"]}"
|
||||
else
|
||||
"${getKeycapConsole('R')} ${Lang["MENU_CONTROLS_SCROLL"]}"
|
||||
@@ -249,12 +249,12 @@ class UILoadList(val full: UILoadSavegame) : UICanvas() {
|
||||
if (this.isVisible) {
|
||||
val cells = playerCells
|
||||
|
||||
if ((keycode == Input.Keys.UP || keycode == App.getConfigInt("control_key_up")) && scrollTarget > 0) {
|
||||
if ((keycode == Input.Keys.UP || keycode == ControlPresets.getKey("control_key_up")) && scrollTarget > 0) {
|
||||
scrollFrom = listScroll
|
||||
scrollTarget -= 1
|
||||
scrollAnimCounter = 0f
|
||||
}
|
||||
else if ((keycode == Input.Keys.DOWN || keycode == App.getConfigInt("control_key_down")) && scrollTarget < cells.size - savesVisible) {
|
||||
else if ((keycode == Input.Keys.DOWN || keycode == ControlPresets.getKey("control_key_down")) && scrollTarget < cells.size - savesVisible) {
|
||||
scrollFrom = listScroll
|
||||
scrollTarget += 1
|
||||
scrollAnimCounter = 0f
|
||||
|
||||
@@ -175,7 +175,7 @@ internal class UIStorageChest : UICanvas(
|
||||
|
||||
private val controlHelp: String
|
||||
get() = if (App.environment == RunningEnvironment.PC)
|
||||
"${getKeycapPC(App.getConfigInt("control_key_inventory"))} ${Lang["GAME_ACTION_CLOSE"]}"
|
||||
"${getKeycapPC(ControlPresets.getKey("control_key_inventory"))} ${Lang["GAME_ACTION_CLOSE"]}"
|
||||
else
|
||||
"${App.gamepadLabelStart} ${Lang["GAME_ACTION_CLOSE"]} "
|
||||
|
||||
|
||||
@@ -45,7 +45,7 @@ class UITierOneWatch() : UICanvas() {
|
||||
ELuptimer += delta
|
||||
}
|
||||
|
||||
if (mouseUp || Gdx.input.isKeyPressed(App.getConfigInt("control_key_interact"))) {
|
||||
if (mouseUp || Gdx.input.isKeyPressed(ControlPresets.getKey("control_key_interact"))) {
|
||||
ELuptimer = 0f
|
||||
ELon = true
|
||||
}
|
||||
|
||||
@@ -53,7 +53,7 @@ class UITitleModules(val remoCon: UIRemoCon) : UICanvas() {
|
||||
|
||||
private val controlHelp: String
|
||||
get() = if (App.environment == RunningEnvironment.PC)
|
||||
"${getKeycapPC(App.getConfigInt("control_key_up"))}${getKeycapPC(App.getConfigInt("control_key_down"))}" +
|
||||
"${getKeycapPC(ControlPresets.getKey("control_key_up"))}${getKeycapPC(ControlPresets.getKey("control_key_down"))}" +
|
||||
" ${Lang["MENU_CONTROLS_SCROLL"]}"
|
||||
else
|
||||
"${getKeycapConsole('R')} ${Lang["MENU_CONTROLS_SCROLL"]}"
|
||||
@@ -206,12 +206,12 @@ class UITitleModules(val remoCon: UIRemoCon) : UICanvas() {
|
||||
|
||||
override fun keyDown(keycode: Int): Boolean {
|
||||
if (this.isVisible) {
|
||||
if ((keycode == Input.Keys.UP || keycode == App.getConfigInt("control_key_up")) && scrollTarget > 0) {
|
||||
if ((keycode == Input.Keys.UP || keycode == ControlPresets.getKey("control_key_up")) && scrollTarget > 0) {
|
||||
scrollFrom = listScroll
|
||||
scrollTarget -= 1
|
||||
scrollAnimCounter = 0f
|
||||
}
|
||||
else if ((keycode == Input.Keys.DOWN || keycode == App.getConfigInt("control_key_down")) && scrollTarget < moduleCells.size - savesVisible) {
|
||||
else if ((keycode == Input.Keys.DOWN || keycode == ControlPresets.getKey("control_key_down")) && scrollTarget < moduleCells.size - savesVisible) {
|
||||
scrollFrom = listScroll
|
||||
scrollTarget += 1
|
||||
scrollAnimCounter = 0f
|
||||
|
||||
@@ -3,10 +3,7 @@ package net.torvald.terrarum.modulebasegame.ui
|
||||
import com.badlogic.gdx.graphics.Camera
|
||||
import com.badlogic.gdx.graphics.Color
|
||||
import com.badlogic.gdx.graphics.g2d.SpriteBatch
|
||||
import net.torvald.terrarum.App
|
||||
import net.torvald.terrarum.INGAME
|
||||
import net.torvald.terrarum.RunningEnvironment
|
||||
import net.torvald.terrarum.floorToInt
|
||||
import net.torvald.terrarum.*
|
||||
import net.torvald.terrarum.gameworld.WorldTime
|
||||
import net.torvald.terrarum.gameworld.WorldTime.Companion.MONTH_LENGTH
|
||||
import net.torvald.terrarum.langpack.Lang
|
||||
@@ -36,7 +33,7 @@ class UIWallCalendar : UICanvas(
|
||||
private val SP = "\u3000 "
|
||||
val controlHelp: String
|
||||
get() = if (App.environment == RunningEnvironment.PC)
|
||||
"${getKeycapPC(App.getConfigInt("control_key_inventory"))} ${Lang["GAME_ACTION_CLOSE"]}"
|
||||
"${getKeycapPC(ControlPresets.getKey("control_key_inventory"))} ${Lang["GAME_ACTION_CLOSE"]}"
|
||||
else
|
||||
"${App.gamepadLabelStart} ${Lang["GAME_ACTION_CLOSE"]}"
|
||||
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
package net.torvald.terrarum.modulebasegame.ui
|
||||
|
||||
import com.badlogic.gdx.graphics.Camera
|
||||
import com.badlogic.gdx.graphics.Color
|
||||
import com.badlogic.gdx.graphics.g2d.SpriteBatch
|
||||
import com.jme3.math.FastMath
|
||||
import net.torvald.terrarum.*
|
||||
@@ -54,7 +53,7 @@ class UIWorldPortal : UICanvas(
|
||||
private val SP = "\u3000 "
|
||||
val portalListingControlHelp: String
|
||||
get() = if (App.environment == RunningEnvironment.PC)
|
||||
"${getKeycapPC(App.getConfigInt("control_key_inventory"))} ${Lang["GAME_ACTION_CLOSE"]}"
|
||||
"${getKeycapPC(ControlPresets.getKey("control_key_inventory"))} ${Lang["GAME_ACTION_CLOSE"]}"
|
||||
else
|
||||
"${App.gamepadLabelStart} ${Lang["GAME_ACTION_CLOSE"]}" +
|
||||
"$SP${App.gamepadLabelLT} ${Lang["GAME_WORLD_SEARCH"]}" +
|
||||
|
||||
@@ -167,7 +167,7 @@ class UIWorldPortalCargo(val full: UIWorldPortal) : UICanvas(), HasInventory {
|
||||
|
||||
private val controlHelp: String
|
||||
get() = if (App.environment == RunningEnvironment.PC)
|
||||
"${getKeycapPC(App.getConfigInt("control_key_inventory"))} ${Lang["GAME_ACTION_CLOSE"]}"
|
||||
"${getKeycapPC(ControlPresets.getKey("control_key_inventory"))} ${Lang["GAME_ACTION_CLOSE"]}"
|
||||
else
|
||||
"${App.gamepadLabelStart} ${Lang["GAME_ACTION_CLOSE"]} "
|
||||
|
||||
|
||||
@@ -7,6 +7,7 @@ import com.badlogic.gdx.graphics.Color
|
||||
import com.badlogic.gdx.graphics.g2d.SpriteBatch
|
||||
import com.badlogic.gdx.utils.Disposable
|
||||
import net.torvald.terrarum.App
|
||||
import net.torvald.terrarum.ControlPresets
|
||||
import net.torvald.terrarum.FlippingSpriteBatch
|
||||
import net.torvald.terrarum.Terrarum
|
||||
import net.torvald.terrarum.gamecontroller.KeyToggler
|
||||
@@ -130,13 +131,13 @@ void main() {
|
||||
//UI.handler = this
|
||||
}
|
||||
|
||||
// getConfigInt(toggleKeyLiteral)
|
||||
val toggleKey: Int?; get() = App.getConfigInt(toggleKeyLiteral).let { if (it == -1) null else it } // to support in-screen keybind changing
|
||||
// getConfigInt(toggleButtonLiteral)
|
||||
val toggleButton: Int?; get() = App.getConfigInt(toggleButtonLiteral).let { if (it == -1) null else it } // to support in-screen keybind changing
|
||||
// ControlPresets.getKey(toggleKeyLiteral)
|
||||
val toggleKey: Int?; get() = ControlPresets.getKey(toggleKeyLiteral).let { if (it == -1) null else it } // to support in-screen keybind changing
|
||||
// ControlPresets.getKey(toggleButtonLiteral)
|
||||
val toggleButton: Int?; get() = ControlPresets.getKey(toggleButtonLiteral).let { if (it == -1) null else it } // to support in-screen keybind changing
|
||||
|
||||
|
||||
val toggleKeyExtra: ArrayList<() -> Int> = arrayListOf()
|
||||
val toggleKeyExtra: ArrayList<String> = arrayListOf()
|
||||
|
||||
/**
|
||||
* Takes a function that works with UIHandler.
|
||||
@@ -208,8 +209,8 @@ void main() {
|
||||
else uiTogglerFunctionDefault!!.invoke(this)
|
||||
}
|
||||
|
||||
toggleKeyExtra.forEachIndexed { index, getKey ->
|
||||
if (Gdx.input.isKeyJustPressed(getKey())) {
|
||||
toggleKeyExtra.forEachIndexed { index, control ->
|
||||
if (Gdx.input.isKeyJustPressed(ControlPresets.getKey(control))) {
|
||||
toggleKeyExtraAction[index].invoke(this)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -443,7 +443,7 @@ class UIItemTextLineInput(
|
||||
|
||||
if (!mouseDown) mouseLatched = false
|
||||
|
||||
imeOn = KeyToggler.isOn(App.getConfigInt("control_key_toggleime"))
|
||||
imeOn = KeyToggler.isOn(ControlPresets.getKey("control_key_toggleime"))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -468,7 +468,7 @@ class UIItemTextLineInput(
|
||||
endComposing()
|
||||
|
||||
imeOn = !imeOn
|
||||
KeyToggler.forceSet(App.getConfigInt("control_key_toggleime"), imeOn)
|
||||
KeyToggler.forceSet(ControlPresets.getKey("control_key_toggleime"), imeOn)
|
||||
}
|
||||
|
||||
private fun resetIME() {
|
||||
|
||||
Reference in New Issue
Block a user