mirror of
https://github.com/curioustorvald/Terrarum.git
synced 2026-06-09 18:14:06 +09:00
mouse buttons now configurable
Former-commit-id: 789b34a0a80553afc7fa7f563ffa33350310ac21 Former-commit-id: 8b3687ee15aa53fb6decb8480ebdf6897b5cce61
This commit is contained in:
@@ -6,6 +6,8 @@ import com.google.gson.JsonObject
|
|||||||
import net.torvald.terrarum.gamecontroller.Key
|
import net.torvald.terrarum.gamecontroller.Key
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* Keys must be all lowercase
|
||||||
|
*
|
||||||
* Created by minjaesong on 16-03-12.
|
* Created by minjaesong on 16-03-12.
|
||||||
*/
|
*/
|
||||||
object DefaultConfig {
|
object DefaultConfig {
|
||||||
@@ -31,10 +33,10 @@ object DefaultConfig {
|
|||||||
jsonObject.addProperty("joypadldown", 6)
|
jsonObject.addProperty("joypadldown", 6)
|
||||||
jsonObject.addProperty("joypadrdown", 7) // logitech indices
|
jsonObject.addProperty("joypadrdown", 7) // logitech indices
|
||||||
|
|
||||||
jsonObject.addProperty("joypadlstickx", 0)
|
jsonObject.addProperty("joypadlstickx", 3)
|
||||||
jsonObject.addProperty("joypadlsticky", 1)
|
jsonObject.addProperty("joypadlsticky", 2)
|
||||||
jsonObject.addProperty("joypadrstickx", 2)
|
jsonObject.addProperty("joypadrstickx", 1)
|
||||||
jsonObject.addProperty("joypadrsticky", 3) // logitech indices
|
jsonObject.addProperty("joypadrsticky", 0) // logitech indices
|
||||||
|
|
||||||
jsonObject.addProperty("joypadlabelstyle", "generic") // "nwii", "logitech", "sonyps", "msxb360", "generic"
|
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
|
val keyquickbars = JsonArray(); for (i in 2..11) keyquickbars.add(i) // NUM_1 to NUM_0
|
||||||
jsonObject.add("keyquickbars", keyquickbars)
|
jsonObject.add("keyquickbars", keyquickbars)
|
||||||
|
|
||||||
|
jsonObject.addProperty("mouseprimary", 0) // left mouse
|
||||||
|
jsonObject.addProperty("mousesecondary", 1) // right mouse
|
||||||
|
|
||||||
|
|
||||||
jsonObject.addProperty("pcgamepadenv", "console")
|
jsonObject.addProperty("pcgamepadenv", "console")
|
||||||
|
|
||||||
jsonObject.addProperty("safetywarning", true)
|
jsonObject.addProperty("safetywarning", true)
|
||||||
|
|||||||
@@ -200,10 +200,10 @@ open class ActorHumanoid(birth: GameDate, death: GameDate? = null)
|
|||||||
isJumpDown = isFuncDown(input, EnumKeyFunc.JUMP)
|
isJumpDown = isFuncDown(input, EnumKeyFunc.JUMP)
|
||||||
|
|
||||||
if (Terrarum.controller != null) {
|
if (Terrarum.controller != null) {
|
||||||
axisX = Terrarum.controller!!.getAxisValue(3)
|
axisX = Terrarum.controller!!.getAxisValue(Terrarum.getConfigInt("joypadlstickx"))
|
||||||
axisY = Terrarum.controller!!.getAxisValue(2)
|
axisY = Terrarum.controller!!.getAxisValue(Terrarum.getConfigInt("joypadlsticky"))
|
||||||
axisRX = Terrarum.controller!!.getAxisValue(1)
|
axisRX = Terrarum.controller!!.getAxisValue(Terrarum.getConfigInt("joypadrstickx"))
|
||||||
axisRY = Terrarum.controller!!.getAxisValue(0)
|
axisRY = Terrarum.controller!!.getAxisValue(Terrarum.getConfigInt("joypadrsticky"))
|
||||||
|
|
||||||
// deadzonning
|
// deadzonning
|
||||||
if (Math.abs(axisX) < Terrarum.CONTROLLER_DEADZONE) axisX = 0f
|
if (Math.abs(axisX) < Terrarum.CONTROLLER_DEADZONE) axisX = 0f
|
||||||
@@ -239,18 +239,17 @@ open class ActorHumanoid(birth: GameDate, death: GameDate? = null)
|
|||||||
///////////////////
|
///////////////////
|
||||||
// MOUSE CONTROL //
|
// MOUSE CONTROL //
|
||||||
///////////////////
|
///////////////////
|
||||||
// PRIMARY/SECONDARY IS FIXED TO LEFT/RIGHT BUTTON //
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Primary Use
|
* Primary Use
|
||||||
*/
|
*/
|
||||||
// Left mouse
|
// 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)
|
(itemEquipped[EquipPosition.HAND_GRIP] ?: nullItem).primaryUse(gc, delta)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Right mouse
|
// 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)
|
(itemEquipped[EquipPosition.HAND_GRIP] ?: nullItem).secondaryUse(gc, delta)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -294,11 +293,11 @@ open class ActorHumanoid(birth: GameDate, death: GameDate? = null)
|
|||||||
// ↑F, ↓S
|
// ↑F, ↓S
|
||||||
if (isRightDown && !isLeftDown) {
|
if (isRightDown && !isLeftDown) {
|
||||||
walkHorizontal(false, AXIS_KEYBOARD)
|
walkHorizontal(false, AXIS_KEYBOARD)
|
||||||
prevHMoveKey = KeyMap.getKeyCode(EnumKeyFunc.MOVE_RIGHT)
|
prevHMoveKey = KeyMap[EnumKeyFunc.MOVE_RIGHT]
|
||||||
} // ↓F, ↑S
|
} // ↓F, ↑S
|
||||||
else if (isLeftDown && !isRightDown) {
|
else if (isLeftDown && !isRightDown) {
|
||||||
walkHorizontal(true, AXIS_KEYBOARD)
|
walkHorizontal(true, AXIS_KEYBOARD)
|
||||||
prevHMoveKey = KeyMap.getKeyCode(EnumKeyFunc.MOVE_LEFT)
|
prevHMoveKey = KeyMap[EnumKeyFunc.MOVE_LEFT]
|
||||||
} // ↓F, ↓S
|
} // ↓F, ↓S
|
||||||
/*else if (isLeftDown && isRightDown) {
|
/*else if (isLeftDown && isRightDown) {
|
||||||
if (prevHMoveKey == KeyMap.getKeyCode(EnumKeyFunc.MOVE_LEFT)) {
|
if (prevHMoveKey == KeyMap.getKeyCode(EnumKeyFunc.MOVE_LEFT)) {
|
||||||
@@ -322,11 +321,11 @@ open class ActorHumanoid(birth: GameDate, death: GameDate? = null)
|
|||||||
// ↑E, ↓D
|
// ↑E, ↓D
|
||||||
if (isDownDown && !isUpDown) {
|
if (isDownDown && !isUpDown) {
|
||||||
walkVertical(false, AXIS_KEYBOARD)
|
walkVertical(false, AXIS_KEYBOARD)
|
||||||
prevVMoveKey = KeyMap.getKeyCode(EnumKeyFunc.MOVE_DOWN)
|
prevVMoveKey = KeyMap[EnumKeyFunc.MOVE_DOWN]
|
||||||
} // ↓E, ↑D
|
} // ↓E, ↑D
|
||||||
else if (isUpDown && !isDownDown) {
|
else if (isUpDown && !isDownDown) {
|
||||||
walkVertical(true, AXIS_KEYBOARD)
|
walkVertical(true, AXIS_KEYBOARD)
|
||||||
prevVMoveKey = KeyMap.getKeyCode(EnumKeyFunc.MOVE_UP)
|
prevVMoveKey = KeyMap[EnumKeyFunc.MOVE_UP]
|
||||||
} // ↓E, ↓D
|
} // ↓E, ↓D
|
||||||
/*else if (isUpDown && isDownDown) {
|
/*else if (isUpDown && isDownDown) {
|
||||||
if (prevVMoveKey == KeyMap.getKeyCode(EnumKeyFunc.MOVE_UP)) {
|
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 {
|
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 {
|
fun isNoClip(): Boolean {
|
||||||
|
|||||||
@@ -5,5 +5,6 @@ package net.torvald.terrarum.gamecontroller
|
|||||||
*/
|
*/
|
||||||
enum class EnumKeyFunc {
|
enum class EnumKeyFunc {
|
||||||
UI_CONSOLE, UI_BASIC_INFO,
|
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
|
||||||
}
|
}
|
||||||
@@ -138,7 +138,7 @@ object GameController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun keyPressedByCode(key: Int, fn: EnumKeyFunc): Boolean {
|
private fun keyPressedByCode(key: Int, fn: EnumKeyFunc): Boolean {
|
||||||
return KeyMap.getKeyCode(fn) == key
|
return KeyMap[fn] == key
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -18,13 +18,15 @@ object KeyMap {
|
|||||||
map_code.put(EnumKeyFunc.JUMP, Terrarum.getConfigInt("keyjump"))
|
map_code.put(EnumKeyFunc.JUMP, Terrarum.getConfigInt("keyjump"))
|
||||||
map_code.put(EnumKeyFunc.UI_CONSOLE, Key.GRAVE)
|
map_code.put(EnumKeyFunc.UI_CONSOLE, Key.GRAVE)
|
||||||
map_code.put(EnumKeyFunc.UI_BASIC_INFO, Key.F3)
|
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]!!
|
return map_code[fn]!!
|
||||||
}
|
}
|
||||||
|
|
||||||
fun set(func: EnumKeyFunc, key: Int) {
|
operator fun set(func: EnumKeyFunc, key: Int) {
|
||||||
map_code.put(func, key)
|
map_code.put(func, key)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user