keyboard control ported to GDX (at least as much as I can right now)

This commit is contained in:
minjaesong
2017-07-01 18:31:00 +09:00
parent 54c643b35e
commit e2da14da8a
25 changed files with 298 additions and 327 deletions

View File

@@ -1,6 +1,9 @@
package net.torvald.terrarum.gamecontroller
import com.badlogic.gdx.Gdx
import com.badlogic.gdx.InputAdapter
import com.badlogic.gdx.scenes.scene2d.InputEvent
import com.badlogic.gdx.scenes.scene2d.InputListener
import net.torvald.terrarum.worlddrawer.FeaturesDrawer
import net.torvald.terrarum.TerrarumGDX
import net.torvald.terrarum.gameactors.*
@@ -10,7 +13,9 @@ import net.torvald.terrarum.worlddrawer.WorldCamera
/**
* Created by minjaesong on 15-12-31.
*/
object GameController {
object GameController : InputAdapter() {
private val ingame = TerrarumGDX.ingame!!
@@ -83,48 +88,48 @@ object GameController {
/////////////////////
}
fun keyPressed(key: Int, c: Char) {
override fun keyDown(keycode: Int): Boolean {
if (ingame.canPlayerControl) {
ingame.player?.keyPressed(key, c)
ingame.player?.keyDown(keycode)
}
if (TerrarumGDX.getConfigIntArray("keyquickselalt").contains(key)
|| key == TerrarumGDX.getConfigInt("keyquicksel")) {
if (TerrarumGDX.getConfigIntArray("keyquickselalt").contains(keycode)
|| keycode == TerrarumGDX.getConfigInt("keyquicksel")) {
ingame.uiPieMenu.setAsOpen()
ingame.uiQuickBar.setAsClose()
}
ingame.uiContainer.forEach { it.keyPressed(key, c) } // for KeyboardControlled UIcanvases
ingame.uiContainer.forEach { it.keyDown(keycode) } // for KeyboardControlled UIcanvases
return true
}
fun keyReleased(key: Int, c: Char) {
if (TerrarumGDX.getConfigIntArray("keyquickselalt").contains(key)
|| key == TerrarumGDX.getConfigInt("keyquicksel")) {
override fun keyUp(keycode: Int): Boolean {
if (TerrarumGDX.getConfigIntArray("keyquickselalt").contains(keycode)
|| keycode == TerrarumGDX.getConfigInt("keyquicksel")) {
ingame.uiPieMenu.setAsClose()
ingame.uiQuickBar.setAsOpen()
}
ingame.uiContainer.forEach { it.keyReleased(key, c) } // for KeyboardControlled UIcanvases
ingame.uiContainer.forEach { it.keyUp(keycode) } // for KeyboardControlled UIcanvases
return true
}
fun mouseMoved(oldx: Int, oldy: Int, newx: Int, newy: Int) {
ingame.uiContainer.forEach { it.mouseMoved(oldx, oldy, newx, newy) } // for MouseControlled UIcanvases
override fun keyTyped(character: Char): Boolean {
ingame.uiContainer.forEach { it.keyTyped(character) }
return true
}
fun mouseDragged(oldx: Int, oldy: Int, newx: Int, newy: Int) {
ingame.uiContainer.forEach { it.mouseDragged(oldx, oldy, newx, newy) } // for MouseControlled UIcanvases
override fun mouseMoved(screenX: Int, screenY: Int): Boolean {
ingame.uiContainer.forEach { it.mouseMoved(screenX, screenY) }
return true
}
fun mousePressed(button: Int, x: Int, y: Int) {
ingame.uiContainer.forEach { it.mousePressed(button, x, y) } // for MouseControlled UIcanvases
}
fun mouseReleased(button: Int, x: Int, y: Int) {
override fun touchUp(screenX: Int, screenY: Int, pointer: Int, button: Int): Boolean {
if (TerrarumGDX.ingame != null) {
val ingame = TerrarumGDX.ingame!!
// don't separate Player from this! Physics will break, esp. airborne manoeuvre
@@ -142,39 +147,25 @@ object GameController {
}
ingame.uiContainer.forEach { it.mouseReleased(button, x, y) } // for MouseControlled UIcanvases
ingame.uiContainer.forEach { it.touchUp(screenX, screenY, pointer, button) } // for MouseControlled UIcanvases
}
return true
}
fun mouseWheelMoved(change: Int) {
ingame.uiContainer.forEach { it.mouseWheelMoved(change) } // for MouseControlled UIcanvases
override fun scrolled(amount: Int): Boolean {
ingame.uiContainer.forEach { it.scrolled(amount) }
return true
}
fun controllerButtonPressed(controller: Int, button: Int) {
ingame.uiContainer.forEach { it.controllerButtonPressed(controller, button) } // for GamepadControlled UIcanvases
override fun touchDragged(screenX: Int, screenY: Int, pointer: Int): Boolean {
ingame.uiContainer.forEach { it.touchDragged(screenX, screenY, pointer) }
return true
}
fun controllerButtonReleased(controller: Int, button: Int) {
ingame.uiContainer.forEach { it.controllerButtonReleased(controller, button) } // for GamepadControlled UIcanvases
override fun touchDown(screenX: Int, screenY: Int, pointer: Int, button: Int): Boolean {
ingame.uiContainer.forEach { it.touchDown(screenX, screenY, pointer, button) }
return true
}
}
/* // Use TerrarumGDX.*
/** position of the mouse (pixelwise) relative to the world (also, currently pointing world-wise coordinate, if the world coordinate is pixel-wise) */
val GameContainer.mouseX: Double
get() = GameController.mouseX.toDouble()
/** position of the mouse (pixelwise) relative to the world (also, currently pointing world-wise coordinate, if the world coordinate is pixel-wise) */
val GameContainer.mouseY: Double
get() = GameController.mouseY.toDouble()
/** currently pointing tile coordinate */
val GameContainer.mouseTileX: Int
get() = GameController.mouseTileX
/** currently pointing tile coordinate */
val GameContainer.mouseTileY: Int
get() = GameController.mouseTileY
val GameContainer.mouseScreenX: Int
get() = Terrarum.appgc.input.mouseX
val GameContainer.mouseScreenY: Int
get() = Terrarum.appgc.input.mouseY*/

View File

@@ -4,7 +4,7 @@ package net.torvald.terrarum.gamecontroller
* Created by minjaesong on 16-01-15.
*/
@Deprecated("Use Gdx.Input.Keys")
object Key {
object DeprecatedAsFuckKey {
val RETURN = 28
val BACKSPACE = 14
@@ -44,16 +44,16 @@ object Key {
val F11 = 87
val F12 = 88
val NUM_1 = 2
val NUM_2 = 3
val NUM_3 = 4
val NUM_4 = 5
val NUM_5 = 6
val NUM_6 = 7
val NUM_7 = 8
val NUM_8 = 9
val NUM_9 = 10
val NUM_0 = 11
val NUM_1 = 8
val NUM_2 = 9
val NUM_3 = 10
val NUM_4 = 11
val NUM_5 = 12
val NUM_6 = 13
val NUM_7 = 14
val NUM_8 = 15
val NUM_9 = 16
val NUM_0 = 7
// JInput is QWERTY-based
val Q = 16