mouse buttons now configurable

Former-commit-id: 789b34a0a80553afc7fa7f563ffa33350310ac21
Former-commit-id: 8b3687ee15aa53fb6decb8480ebdf6897b5cce61
This commit is contained in:
Song Minjae
2016-12-30 23:28:06 +09:00
parent 4837962ff5
commit 720a5c8440
5 changed files with 31 additions and 20 deletions

View File

@@ -6,6 +6,8 @@ import com.google.gson.JsonObject
import net.torvald.terrarum.gamecontroller.Key
/**
* Keys must be all lowercase
*
* Created by minjaesong on 16-03-12.
*/
object DefaultConfig {
@@ -31,10 +33,10 @@ object DefaultConfig {
jsonObject.addProperty("joypadldown", 6)
jsonObject.addProperty("joypadrdown", 7) // logitech indices
jsonObject.addProperty("joypadlstickx", 0)
jsonObject.addProperty("joypadlsticky", 1)
jsonObject.addProperty("joypadrstickx", 2)
jsonObject.addProperty("joypadrsticky", 3) // logitech indices
jsonObject.addProperty("joypadlstickx", 3)
jsonObject.addProperty("joypadlsticky", 2)
jsonObject.addProperty("joypadrstickx", 1)
jsonObject.addProperty("joypadrsticky", 0) // logitech indices
jsonObject.addProperty("joypadlabelstyle", "generic") // "nwii", "logitech", "sonyps", "msxb360", "generic"
@@ -64,6 +66,10 @@ object DefaultConfig {
val keyquickbars = JsonArray(); for (i in 2..11) keyquickbars.add(i) // NUM_1 to NUM_0
jsonObject.add("keyquickbars", keyquickbars)
jsonObject.addProperty("mouseprimary", 0) // left mouse
jsonObject.addProperty("mousesecondary", 1) // right mouse
jsonObject.addProperty("pcgamepadenv", "console")
jsonObject.addProperty("safetywarning", true)

View File

@@ -200,10 +200,10 @@ open class ActorHumanoid(birth: GameDate, death: GameDate? = null)
isJumpDown = isFuncDown(input, EnumKeyFunc.JUMP)
if (Terrarum.controller != null) {
axisX = Terrarum.controller!!.getAxisValue(3)
axisY = Terrarum.controller!!.getAxisValue(2)
axisRX = Terrarum.controller!!.getAxisValue(1)
axisRY = Terrarum.controller!!.getAxisValue(0)
axisX = Terrarum.controller!!.getAxisValue(Terrarum.getConfigInt("joypadlstickx"))
axisY = Terrarum.controller!!.getAxisValue(Terrarum.getConfigInt("joypadlsticky"))
axisRX = Terrarum.controller!!.getAxisValue(Terrarum.getConfigInt("joypadrstickx"))
axisRY = Terrarum.controller!!.getAxisValue(Terrarum.getConfigInt("joypadrsticky"))
// deadzonning
if (Math.abs(axisX) < Terrarum.CONTROLLER_DEADZONE) axisX = 0f
@@ -239,18 +239,17 @@ open class ActorHumanoid(birth: GameDate, death: GameDate? = null)
///////////////////
// MOUSE CONTROL //
///////////////////
// PRIMARY/SECONDARY IS FIXED TO LEFT/RIGHT BUTTON //
/**
* Primary Use
*/
// Left mouse
if (isGamer && input.isMouseButtonDown(Input.MOUSE_LEFT_BUTTON)) {
if (isGamer && isFuncDown(input, EnumKeyFunc.HAND_PRIMARY)) {
(itemEquipped[EquipPosition.HAND_GRIP] ?: nullItem).primaryUse(gc, delta)
}
// Right mouse
if (isGamer && input.isMouseButtonDown(Input.MOUSE_RIGHT_BUTTON)) {
if (isGamer && isFuncDown(input, EnumKeyFunc.HAND_SECONDARY)) {
(itemEquipped[EquipPosition.HAND_GRIP] ?: nullItem).secondaryUse(gc, delta)
}
@@ -294,11 +293,11 @@ open class ActorHumanoid(birth: GameDate, death: GameDate? = null)
// ↑F, ↓S
if (isRightDown && !isLeftDown) {
walkHorizontal(false, AXIS_KEYBOARD)
prevHMoveKey = KeyMap.getKeyCode(EnumKeyFunc.MOVE_RIGHT)
prevHMoveKey = KeyMap[EnumKeyFunc.MOVE_RIGHT]
} // ↓F, ↑S
else if (isLeftDown && !isRightDown) {
walkHorizontal(true, AXIS_KEYBOARD)
prevHMoveKey = KeyMap.getKeyCode(EnumKeyFunc.MOVE_LEFT)
prevHMoveKey = KeyMap[EnumKeyFunc.MOVE_LEFT]
} // ↓F, ↓S
/*else if (isLeftDown && isRightDown) {
if (prevHMoveKey == KeyMap.getKeyCode(EnumKeyFunc.MOVE_LEFT)) {
@@ -322,11 +321,11 @@ open class ActorHumanoid(birth: GameDate, death: GameDate? = null)
// ↑E, ↓D
if (isDownDown && !isUpDown) {
walkVertical(false, AXIS_KEYBOARD)
prevVMoveKey = KeyMap.getKeyCode(EnumKeyFunc.MOVE_DOWN)
prevVMoveKey = KeyMap[EnumKeyFunc.MOVE_DOWN]
} // ↓E, ↑D
else if (isUpDown && !isDownDown) {
walkVertical(true, AXIS_KEYBOARD)
prevVMoveKey = KeyMap.getKeyCode(EnumKeyFunc.MOVE_UP)
prevVMoveKey = KeyMap[EnumKeyFunc.MOVE_UP]
} // ↓E, ↓D
/*else if (isUpDown && isDownDown) {
if (prevVMoveKey == KeyMap.getKeyCode(EnumKeyFunc.MOVE_UP)) {
@@ -500,7 +499,10 @@ open class ActorHumanoid(birth: GameDate, death: GameDate? = null)
}
private fun isFuncDown(input: Input, fn: EnumKeyFunc): Boolean {
return input.isKeyDown(KeyMap.getKeyCode(fn))
return if (fn == EnumKeyFunc.HAND_PRIMARY || fn == EnumKeyFunc.HAND_SECONDARY)
input.isMouseButtonDown(KeyMap[fn])
else
input.isKeyDown(KeyMap[fn])
}
fun isNoClip(): Boolean {

View File

@@ -5,5 +5,6 @@ package net.torvald.terrarum.gamecontroller
*/
enum class EnumKeyFunc {
UI_CONSOLE, UI_BASIC_INFO,
MOVE_LEFT, MOVE_RIGHT, MOVE_UP, MOVE_DOWN, JUMP
MOVE_LEFT, MOVE_RIGHT, MOVE_UP, MOVE_DOWN, JUMP,
HAND_PRIMARY, HAND_SECONDARY
}

View File

@@ -138,7 +138,7 @@ object GameController {
}
private fun keyPressedByCode(key: Int, fn: EnumKeyFunc): Boolean {
return KeyMap.getKeyCode(fn) == key
return KeyMap[fn] == key
}
}

View File

@@ -18,13 +18,15 @@ object KeyMap {
map_code.put(EnumKeyFunc.JUMP, Terrarum.getConfigInt("keyjump"))
map_code.put(EnumKeyFunc.UI_CONSOLE, Key.GRAVE)
map_code.put(EnumKeyFunc.UI_BASIC_INFO, Key.F3)
map_code.put(EnumKeyFunc.HAND_PRIMARY, Terrarum.getConfigInt("mousePrimary"))
map_code.put(EnumKeyFunc.HAND_SECONDARY, Terrarum.getConfigInt("mouseSecondary"))
}
fun getKeyCode(fn: EnumKeyFunc): Int {
operator fun get(fn: EnumKeyFunc): Int {
return map_code[fn]!!
}
fun set(func: EnumKeyFunc, key: Int) {
operator fun set(func: EnumKeyFunc, key: Int) {
map_code.put(func, key)
}