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

@@ -5,7 +5,6 @@ import org.luaj.vm2.Globals
import org.luaj.vm2.LuaTable
import org.luaj.vm2.LuaValue
import org.luaj.vm2.lib.OneArgFunction
import net.torvald.terrarum.gamecontroller.Key
import net.torvald.terrarum.virtualcomputer.computer.TerrarumComputer
/**
@@ -13,38 +12,5 @@ import net.torvald.terrarum.virtualcomputer.computer.TerrarumComputer
*/
class Input(globals: Globals, computer: TerrarumComputer) {
init {
globals["input"] = LuaTable()
globals["input"]["isKeyDown"] = IsKeyDown(computer)
// input.readLine defined in ROMLIB
}
companion object {
val keys_alt = intArrayOf(Key.L_ALT, Key.L_COMMAND)
val keys_caps = intArrayOf(Key.CAPS_LOCK, Key.BACKSPACE, Key.L_CONTROL)
}
class IsKeyDown(val host: TerrarumComputer) : OneArgFunction() {
override fun call(keyCode: LuaValue): LuaValue {
val key = keyCode.checkint()
// L_Alt and L_COMMAND are homogeneous
if (keys_alt.contains(key)) {
for (k in keys_alt) {
val down = Gdx.input.isKeyPressed(k)
if (down) return LuaValue.valueOf(true)
}
}
// Caps, Backspace, L_Control, for Colemak and HHKB
if (keys_caps.contains(key)) {
for (k in keys_caps) {
val down = Gdx.input.isKeyPressed(k)
if (down) return LuaValue.valueOf(true)
}
}
return LuaValue.valueOf(Gdx.input.isKeyPressed(keyCode.checkint()))
}
}
}

View File

@@ -3,7 +3,6 @@ package net.torvald.terrarum.virtualcomputer.terminal
import net.torvald.terrarum.blendMul
import net.torvald.terrarum.gameactors.DecodeTapestry
import net.torvald.terrarum.gameactors.abs
import net.torvald.terrarum.gamecontroller.Key
import net.torvald.terrarum.virtualcomputer.computer.TerrarumComputer
import java.util.*

View File

@@ -10,40 +10,43 @@ import net.torvald.terrarum.virtualcomputer.terminal.Terminal
* Created by minjaesong on 16-09-08.
*/
class UITextTerminal(val terminal: Terminal) : UICanvas, KeyControlled, MouseControlled {
override fun mouseMoved(oldx: Int, oldy: Int, newx: Int, newy: Int) {
throw UnsupportedOperationException("not implemented") //To change body of created functions use File | Settings | File Templates.
override fun keyDown(keycode: Int): Boolean {
return false
}
override fun keyPressed(key: Int, c: Char) {
throw UnsupportedOperationException("not implemented") //To change body of created functions use File | Settings | File Templates.
override fun mouseMoved(screenX: Int, screenY: Int): Boolean {
return false
}
override fun keyReleased(key: Int, c: Char) {
throw UnsupportedOperationException("not implemented") //To change body of created functions use File | Settings | File Templates.
override fun keyUp(keycode: Int): Boolean {
return false
}
override fun mouseDragged(oldx: Int, oldy: Int, newx: Int, newy: Int) {
throw UnsupportedOperationException("not implemented") //To change body of created functions use File | Settings | File Templates.
override fun touchDragged(screenX: Int, screenY: Int, pointer: Int): Boolean {
return false
}
override fun controllerButtonPressed(controller: Int, button: Int) {
override fun keyTyped(character: Char): Boolean {
return false
}
override fun controllerButtonReleased(controller: Int, button: Int) {
override fun touchDown(screenX: Int, screenY: Int, pointer: Int, button: Int): Boolean {
return false
}
override fun touchUp(screenX: Int, screenY: Int, pointer: Int, button: Int): Boolean {
return false
}
override fun scrolled(amount: Int): Boolean {
return false
}
override var width: Int = terminal.displayW// + some
override var height: Int = terminal.displayH// + frame
override fun mousePressed(button: Int, x: Int, y: Int) {
// monitor on/off, reset switch
}
override fun mouseReleased(button: Int, x: Int, y: Int) {
}
override fun mouseWheelMoved(change: Int) {
}
/**
* Usage: (in StateInGame:) uiHandlerField.ui.handler = uiHandlerField