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

@@ -3,7 +3,6 @@ package net.torvald.terrarum
import com.badlogic.gdx.Input import com.badlogic.gdx.Input
import com.google.gson.JsonArray import com.google.gson.JsonArray
import com.google.gson.JsonObject import com.google.gson.JsonObject
import net.torvald.terrarum.gamecontroller.Key
/** /**
* Keys must be all lowercase * Keys must be all lowercase
@@ -52,14 +51,14 @@ object DefaultConfig {
jsonObject.addProperty("keydown", Input.Keys.D) jsonObject.addProperty("keydown", Input.Keys.D)
jsonObject.addProperty("keyright", Input.Keys.F) jsonObject.addProperty("keyright", Input.Keys.F)
jsonObject.addProperty("keymovementaux", Input.Keys.A) // movement-auxiliary, or hookshot jsonObject.addProperty("keymovementaux", Input.Keys.W) // movement-auxiliary, or hookshot
jsonObject.addProperty("keyinventory", Input.Keys.W) jsonObject.addProperty("keyinventory", Input.Keys.Q)
jsonObject.addProperty("keyinteract", Input.Keys.R) jsonObject.addProperty("keyinteract", Input.Keys.R)
jsonObject.addProperty("keyclose", Input.Keys.C) jsonObject.addProperty("keyclose", Input.Keys.C)
jsonObject.addProperty("keygamemenu", Input.Keys.TAB) jsonObject.addProperty("keygamemenu", Input.Keys.TAB)
jsonObject.addProperty("keyquicksel", Key.CAPS_LOCK) // pie menu jsonObject.addProperty("keyquicksel", Input.Keys.A) // pie menu (A) because GDX does not read CapsLock
val keyquickselalt = JsonArray(); keyquickselalt.add(Input.Keys.BACKSPACE); keyquickselalt.add(Key.L_COMMAND); keyquickselalt.add(Input.Keys.CONTROL_LEFT) val keyquickselalt = JsonArray(); keyquickselalt.add(Input.Keys.BACKSPACE); keyquickselalt.add(Input.Keys.CONTROL_LEFT)
// Colemak, Workman and some typers use CapsLock as Backspace, Apple-JIS and HHKB has Control in place of CapsLock and often re-assigned to Command // Colemak, Workman and some typers use CapsLock as Backspace, Apple-JIS and HHKB has Control in place of CapsLock and often re-assigned to Command
// so these keys are treated as the same. // so these keys are treated as the same.
// FOR ~~FUCKS~~ERGONOMICS' SAKE DON'T USE CTRL AND ALT AS A KEY! // FOR ~~FUCKS~~ERGONOMICS' SAKE DON'T USE CTRL AND ALT AS A KEY!

View File

@@ -1,6 +1,7 @@
package net.torvald.terrarum package net.torvald.terrarum
import com.badlogic.gdx.Gdx import com.badlogic.gdx.Gdx
import com.badlogic.gdx.Input
import com.badlogic.gdx.Screen import com.badlogic.gdx.Screen
import com.badlogic.gdx.graphics.* import com.badlogic.gdx.graphics.*
import com.badlogic.gdx.graphics.g2d.SpriteBatch import com.badlogic.gdx.graphics.g2d.SpriteBatch
@@ -14,7 +15,6 @@ import net.torvald.terrarum.console.*
import net.torvald.terrarum.gameactors.* import net.torvald.terrarum.gameactors.*
import net.torvald.terrarum.gameactors.physicssolver.CollisionSolver import net.torvald.terrarum.gameactors.physicssolver.CollisionSolver
import net.torvald.terrarum.gamecontroller.GameController import net.torvald.terrarum.gamecontroller.GameController
import net.torvald.terrarum.gamecontroller.Key
import net.torvald.terrarum.gamecontroller.KeyToggler import net.torvald.terrarum.gamecontroller.KeyToggler
import net.torvald.terrarum.gameworld.GameWorld import net.torvald.terrarum.gameworld.GameWorld
import net.torvald.terrarum.gameworld.WorldSimulator import net.torvald.terrarum.gameworld.WorldSimulator
@@ -31,7 +31,6 @@ import java.util.concurrent.locks.ReentrantLock
import javax.swing.JOptionPane import javax.swing.JOptionPane
import com.badlogic.gdx.graphics.OrthographicCamera import com.badlogic.gdx.graphics.OrthographicCamera
import com.badlogic.gdx.graphics.glutils.ShapeRenderer
import net.torvald.random.HQRNG import net.torvald.random.HQRNG
import net.torvald.terrarum.ui.* import net.torvald.terrarum.ui.*
import net.torvald.terrarum.worldgenerator.RoguelikeRandomiser import net.torvald.terrarum.worldgenerator.RoguelikeRandomiser
@@ -82,8 +81,8 @@ class StateInGameGDX(val batch: SpriteBatch) : Screen {
private val useShader: Boolean = false private val useShader: Boolean = false
private val shaderProgram = 0 private val shaderProgram = 0
val KEY_LIGHTMAP_RENDER = Key.F7 val KEY_LIGHTMAP_RENDER = Input.Keys.F7
val KEY_LIGHTMAP_SMOOTH = Key.F8 val KEY_LIGHTMAP_SMOOTH = Input.Keys.F8
@@ -181,6 +180,9 @@ class StateInGameGDX(val batch: SpriteBatch) : Screen {
fun enter() { fun enter() {
Gdx.input.inputProcessor = GameController
initViewPort(Gdx.graphics.width, Gdx.graphics.height, Gdx.graphics.width.toFloat() / Gdx.graphics.height.toFloat()) initViewPort(Gdx.graphics.width, Gdx.graphics.height, Gdx.graphics.width.toFloat() / Gdx.graphics.height.toFloat())
@@ -498,9 +500,6 @@ class StateInGameGDX(val batch: SpriteBatch) : Screen {
} }
println("Player: (${player?.hitbox?.centeredX}, ${player?.hitbox?.centeredY})")
///////////////////////////// /////////////////////////////
// draw map related stuffs // // draw map related stuffs //

View File

@@ -1,11 +1,10 @@
package net.torvald.terrarum package net.torvald.terrarum
import com.badlogic.gdx.Input
import com.badlogic.gdx.graphics.Color import com.badlogic.gdx.graphics.Color
import com.badlogic.gdx.graphics.Texture
import com.badlogic.gdx.graphics.g2d.SpriteBatch import com.badlogic.gdx.graphics.g2d.SpriteBatch
import com.badlogic.gdx.graphics.g2d.TextureRegion import com.badlogic.gdx.graphics.g2d.TextureRegion
import net.torvald.colourutil.CIELabUtil.darkerLab import net.torvald.colourutil.CIELabUtil.darkerLab
import net.torvald.terrarum.gamecontroller.Key
import net.torvald.terrarum.itemproperties.GameItem import net.torvald.terrarum.itemproperties.GameItem
import net.torvald.terrarum.ui.UIInventory import net.torvald.terrarum.ui.UIInventory
import net.torvald.terrarum.ui.UIItem import net.torvald.terrarum.ui.UIItem
@@ -122,10 +121,10 @@ class UIItemInventoryElem(
} }
} }
override fun keyPressed(key: Int, c: Char) { override fun keyDown(keycode: Int): Boolean {
if (item != null && TerrarumGDX.ingame != null && key in Key.NUM_1..Key.NUM_0) { if (item != null && TerrarumGDX.ingame != null && keycode in Input.Keys.NUM_1..Input.Keys.NUM_0) {
val inventory = TerrarumGDX.ingame!!.player?.inventory val inventory = TerrarumGDX.ingame!!.player?.inventory
val slot = key - Key.NUM_1 val slot = if (keycode == Input.Keys.NUM_0) 9 else keycode - Input.Keys.NUM_1
val currentSlotItem = inventory?.getQuickBar(slot) val currentSlotItem = inventory?.getQuickBar(slot)
@@ -145,18 +144,24 @@ class UIItemInventoryElem(
} }
} }
} }
return true
} }
override fun keyReleased(key: Int, c: Char) { override fun keyUp(keycode: Int): Boolean {
return false
} }
override fun mouseMoved(oldx: Int, oldy: Int, newx: Int, newy: Int) { override fun mouseMoved(screenX: Int, screenY: Int): Boolean {
return false
} }
override fun mouseDragged(oldx: Int, oldy: Int, newx: Int, newy: Int) { override fun touchDragged(screenX: Int, screenY: Int, pointer: Int): Boolean {
return false
} }
override fun mousePressed(button: Int, x: Int, y: Int) {
override fun touchDown(screenX: Int, screenY: Int, pointer: Int, button: Int): Boolean {
if (item != null && TerrarumGDX.ingame != null) { if (item != null && TerrarumGDX.ingame != null) {
// equip da shit // equip da shit
@@ -172,17 +177,16 @@ class UIItemInventoryElem(
} }
inventoryUI.rebuildList() inventoryUI.rebuildList()
return true
} }
override fun mouseReleased(button: Int, x: Int, y: Int) {
override fun touchUp(screenX: Int, screenY: Int, pointer: Int, button: Int): Boolean {
return false
} }
override fun mouseWheelMoved(change: Int) { override fun scrolled(amount: Int): Boolean {
} return false
override fun controllerButtonPressed(controller: Int, button: Int) {
}
override fun controllerButtonReleased(controller: Int, button: Int) {
} }
} }

View File

@@ -333,14 +333,19 @@ open class ActorHumanoid(birth: GameDate, death: GameDate? = null)
} }
override fun keyPressed(key: Int, c: Char) { override fun keyDown(keycode: Int): Boolean {
// quickslot (quickbar) // quickslot (quickbar)
val quickbarKeys = TerrarumGDX.getConfigIntArray("keyquickbars") val quickbarKeys = TerrarumGDX.getConfigIntArray("keyquickbars")
if (key in quickbarKeys) { if (keycode in quickbarKeys) {
actorValue[AVKey.__PLAYER_QUICKSLOTSEL] = quickbarKeys.indexOf(key) actorValue[AVKey.__PLAYER_QUICKSLOTSEL] = quickbarKeys.indexOf(keycode)
} }
return true
} }
/** /**
* This code directly controls VELOCITY for walking, called walkX and walkY. * This code directly controls VELOCITY for walking, called walkX and walkY.
* *

View File

@@ -12,5 +12,5 @@ abstract class ActorWithBody(renderOrder: RenderOrder) : Actor(renderOrder) {
open val hitbox = Hitbox(0.0, 0.0, 0.0, 0.0) open val hitbox = Hitbox(0.0, 0.0, 0.0, 0.0)
abstract fun drawBody(batch: SpriteBatch) abstract fun drawBody(batch: SpriteBatch)
abstract fun drawGlow(batch: SpriteBatch) abstract fun drawGlow(batch: SpriteBatch)
open var tooltipText = "" open var tooltipText: String? = null // null: display nothing
} }

View File

@@ -541,11 +541,11 @@ open class ActorWithPhysics(renderOrder: RenderOrder, val immobileBody: Boolean
fun debug1(wut: Any?) { fun debug1(wut: Any?) {
// vvvvv set it true to make debug print work // vvvvv set it true to make debug print work
if (true) println(wut) if (false) println(wut)
} }
fun debug2(wut: Any?) { fun debug2(wut: Any?) {
// vvvvv set it true to make debug print work // vvvvv set it true to make debug print work
if (true) println(wut) if (false) println(wut)
} }
fun debug3(wut: Any?) { fun debug3(wut: Any?) {
// vvvvv set it true to make debug print work // vvvvv set it true to make debug print work
@@ -553,7 +553,7 @@ open class ActorWithPhysics(renderOrder: RenderOrder, val immobileBody: Boolean
} }
fun debug4(wut: Any?) { fun debug4(wut: Any?) {
// vvvvv set it true to make debug print work // vvvvv set it true to make debug print work
if (true) println(wut) if (false) println(wut)
} }
fun Double.modTile() = this.toInt().div(TILE_SIZE).times(TILE_SIZE) fun Double.modTile() = this.toInt().div(TILE_SIZE).times(TILE_SIZE)
fun Double.modTileDelta() = this - this.modTile() fun Double.modTileDelta() = this - this.modTile()
@@ -616,7 +616,7 @@ open class ActorWithPhysics(renderOrder: RenderOrder, val immobileBody: Boolean
} }
// collision detected // collision detected
else { else {
println("== Collision step: $collidingStep / $ccdSteps") debug1("== Collision step: $collidingStep / $ccdSteps")
val newHitbox = hitbox.reassign(sixteenStep[collidingStep]) val newHitbox = hitbox.reassign(sixteenStep[collidingStep])
@@ -629,14 +629,14 @@ open class ActorWithPhysics(renderOrder: RenderOrder, val immobileBody: Boolean
// fixme UP and RIGHT && LEFT and DOWN bug // fixme UP and RIGHT && LEFT and DOWN bug
println("Collision type: $selfCollisionStatus") debug1("Collision type: $selfCollisionStatus")
affectingTiles.forEach { affectingTiles.forEach {
val tileCoord = LandUtil.resolveBlockAddr(it) val tileCoord = LandUtil.resolveBlockAddr(it)
println("affectign tile: ${tileCoord.first}, ${tileCoord.second}") debug1("affectign tile: ${tileCoord.first}, ${tileCoord.second}")
} }
when (selfCollisionStatus) { when (selfCollisionStatus) {
0 -> { println("[ActorWithPhysics] Contradiction -- collision detected by CCD, but isWalled() says otherwise") } 0 -> { debug1("[ActorWithPhysics] Contradiction -- collision detected by CCD, but isWalled() says otherwise") }
5 -> { zeroX = true } 5 -> { zeroX = true }
10 -> { zeroY = true } 10 -> { zeroY = true }
15 -> { newHitbox.reassign(sixteenStep[0]); zeroX = true; zeroY = true } 15 -> { newHitbox.reassign(sixteenStep[0]); zeroX = true; zeroY = true }
@@ -647,13 +647,13 @@ open class ActorWithPhysics(renderOrder: RenderOrder, val immobileBody: Boolean
2, 7 -> { newHitbox.translatePosY( - newHitbox.endY.modTileDelta()) ; bounceY = true } 2, 7 -> { newHitbox.translatePosY( - newHitbox.endY.modTileDelta()) ; bounceY = true }
// two-side collision // two-side collision
3 -> { 3 -> {
println("translateX: ${(TILE_SIZE - newHitbox.startX.modTileDelta()).rem(TILE_SIZE)}") debug1("translateX: ${(TILE_SIZE - newHitbox.startX.modTileDelta()).rem(TILE_SIZE)}")
newHitbox.translatePosX((TILE_SIZE - newHitbox.startX.modTileDelta()).rem(TILE_SIZE)) newHitbox.translatePosX((TILE_SIZE - newHitbox.startX.modTileDelta()).rem(TILE_SIZE))
newHitbox.translatePosY( - newHitbox.endY.modTileDelta()) newHitbox.translatePosY( - newHitbox.endY.modTileDelta())
bounceX = true; bounceY = true bounceX = true; bounceY = true
} }
6 -> { 6 -> {
println("translateX: ${( - newHitbox.endX.modTileDelta())}") debug1("translateX: ${( - newHitbox.endX.modTileDelta())}")
newHitbox.translatePosX( - newHitbox.endX.modTileDelta()) newHitbox.translatePosX( - newHitbox.endX.modTileDelta())
newHitbox.translatePosY( - newHitbox.endY.modTileDelta()) newHitbox.translatePosY( - newHitbox.endY.modTileDelta())
bounceX = true; bounceY = true bounceX = true; bounceY = true
@@ -664,7 +664,7 @@ open class ActorWithPhysics(renderOrder: RenderOrder, val immobileBody: Boolean
bounceX = true; bounceY = true bounceX = true; bounceY = true
} }
12 -> { 12 -> {
println("translateY: ${(TILE_SIZE - newHitbox.startY.modTileDelta()).rem(TILE_SIZE)}") debug1("translateY: ${(TILE_SIZE - newHitbox.startY.modTileDelta()).rem(TILE_SIZE)}")
newHitbox.translatePosX( - newHitbox.endX.modTileDelta()) newHitbox.translatePosX( - newHitbox.endX.modTileDelta())
newHitbox.translatePosY((TILE_SIZE - newHitbox.startY.modTileDelta()).rem(TILE_SIZE)) newHitbox.translatePosY((TILE_SIZE - newHitbox.startY.modTileDelta()).rem(TILE_SIZE))
bounceX = true; bounceY = true bounceX = true; bounceY = true
@@ -672,7 +672,7 @@ open class ActorWithPhysics(renderOrder: RenderOrder, val immobileBody: Boolean
} }
if (selfCollisionStatus in listOf(3,6,9,12)) { if (selfCollisionStatus in listOf(3,6,9,12)) {
println("twoside collision $selfCollisionStatus") debug1("twoside collision $selfCollisionStatus")
} }
@@ -702,7 +702,8 @@ open class ActorWithPhysics(renderOrder: RenderOrder, val immobileBody: Boolean
// vvvv hack (supposed to be 1.0) vvv 50% hack // vvvv hack (supposed to be 1.0) vvv 50% hack
val collisionDamage = mass * (vectorSum.magnitude / (10.0 / TerrarumGDX.TARGET_FPS).sqr()) / fallDamageDampening.sqr() * GAME_TO_SI_ACC val collisionDamage = mass * (vectorSum.magnitude / (10.0 / TerrarumGDX.TARGET_FPS).sqr()) / fallDamageDampening.sqr() * GAME_TO_SI_ACC
// kg * m / s^2 (mass * acceleration), acceleration -> (vectorMagn / (0.01)^2).gameToSI() // kg * m / s^2 (mass * acceleration), acceleration -> (vectorMagn / (0.01)^2).gameToSI()
if (collisionDamage != 0.0) println("Collision damage: $collisionDamage N") if (collisionDamage != 0.0) debug1("Collision damage: $collisionDamage N")
// FIXME instead of 0.5mv^2, we can model after "change of velocity (aka accel)", just as in real-life; big change of accel on given unit time is what kills
// grounded = true // grounded = true

View File

@@ -9,7 +9,6 @@ package net.torvald.terrarum.gameactors
interface Controllable { interface Controllable {
fun processInput(delta: Float) fun processInput(delta: Float)
fun keyDown(keycode: Int): Boolean
fun keyPressed(key: Int, c: Char)
} }

View File

@@ -33,5 +33,5 @@ class TapestryObject(pixmap: Pixmap, val artName: String, val artAuthor: String)
super.drawBody(batch) super.drawBody(batch)
} }
override var tooltipText: String = "$artName\n$artAuthor" override var tooltipText: String? = "$artName\n$artAuthor"
} }

View File

@@ -1,6 +1,9 @@
package net.torvald.terrarum.gamecontroller package net.torvald.terrarum.gamecontroller
import com.badlogic.gdx.Gdx 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.worlddrawer.FeaturesDrawer
import net.torvald.terrarum.TerrarumGDX import net.torvald.terrarum.TerrarumGDX
import net.torvald.terrarum.gameactors.* import net.torvald.terrarum.gameactors.*
@@ -10,7 +13,9 @@ import net.torvald.terrarum.worlddrawer.WorldCamera
/** /**
* Created by minjaesong on 15-12-31. * Created by minjaesong on 15-12-31.
*/ */
object GameController { object GameController : InputAdapter() {
private val ingame = TerrarumGDX.ingame!! 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) { if (ingame.canPlayerControl) {
ingame.player?.keyPressed(key, c) ingame.player?.keyDown(keycode)
} }
if (TerrarumGDX.getConfigIntArray("keyquickselalt").contains(key) if (TerrarumGDX.getConfigIntArray("keyquickselalt").contains(keycode)
|| key == TerrarumGDX.getConfigInt("keyquicksel")) { || keycode == TerrarumGDX.getConfigInt("keyquicksel")) {
ingame.uiPieMenu.setAsOpen() ingame.uiPieMenu.setAsOpen()
ingame.uiQuickBar.setAsClose() 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) { override fun keyUp(keycode: Int): Boolean {
if (TerrarumGDX.getConfigIntArray("keyquickselalt").contains(keycode)
if (TerrarumGDX.getConfigIntArray("keyquickselalt").contains(key) || keycode == TerrarumGDX.getConfigInt("keyquicksel")) {
|| key == TerrarumGDX.getConfigInt("keyquicksel")) {
ingame.uiPieMenu.setAsClose() ingame.uiPieMenu.setAsClose()
ingame.uiQuickBar.setAsOpen() 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) { override fun keyTyped(character: Char): Boolean {
ingame.uiContainer.forEach { it.mouseMoved(oldx, oldy, newx, newy) } // for MouseControlled UIcanvases ingame.uiContainer.forEach { it.keyTyped(character) }
return true
} }
fun mouseDragged(oldx: Int, oldy: Int, newx: Int, newy: Int) { override fun mouseMoved(screenX: Int, screenY: Int): Boolean {
ingame.uiContainer.forEach { it.mouseDragged(oldx, oldy, newx, newy) } // for MouseControlled UIcanvases ingame.uiContainer.forEach { it.mouseMoved(screenX, screenY) }
return true
} }
fun mousePressed(button: Int, x: Int, y: Int) { override fun touchUp(screenX: Int, screenY: Int, pointer: Int, button: Int): Boolean {
ingame.uiContainer.forEach { it.mousePressed(button, x, y) } // for MouseControlled UIcanvases
}
fun mouseReleased(button: Int, x: Int, y: Int) {
if (TerrarumGDX.ingame != null) { if (TerrarumGDX.ingame != null) {
val ingame = TerrarumGDX.ingame!! val ingame = TerrarumGDX.ingame!!
// don't separate Player from this! Physics will break, esp. airborne manoeuvre // 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) { override fun scrolled(amount: Int): Boolean {
ingame.uiContainer.forEach { it.mouseWheelMoved(change) } // for MouseControlled UIcanvases ingame.uiContainer.forEach { it.scrolled(amount) }
return true
} }
fun controllerButtonPressed(controller: Int, button: Int) { override fun touchDragged(screenX: Int, screenY: Int, pointer: Int): Boolean {
ingame.uiContainer.forEach { it.controllerButtonPressed(controller, button) } // for GamepadControlled UIcanvases ingame.uiContainer.forEach { it.touchDragged(screenX, screenY, pointer) }
return true
} }
fun controllerButtonReleased(controller: Int, button: Int) { override fun touchDown(screenX: Int, screenY: Int, pointer: Int, button: Int): Boolean {
ingame.uiContainer.forEach { it.controllerButtonReleased(controller, button) } // for GamepadControlled UIcanvases 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. * Created by minjaesong on 16-01-15.
*/ */
@Deprecated("Use Gdx.Input.Keys") @Deprecated("Use Gdx.Input.Keys")
object Key { object DeprecatedAsFuckKey {
val RETURN = 28 val RETURN = 28
val BACKSPACE = 14 val BACKSPACE = 14
@@ -44,16 +44,16 @@ object Key {
val F11 = 87 val F11 = 87
val F12 = 88 val F12 = 88
val NUM_1 = 2 val NUM_1 = 8
val NUM_2 = 3 val NUM_2 = 9
val NUM_3 = 4 val NUM_3 = 10
val NUM_4 = 5 val NUM_4 = 11
val NUM_5 = 6 val NUM_5 = 12
val NUM_6 = 7 val NUM_6 = 13
val NUM_7 = 8 val NUM_7 = 14
val NUM_8 = 9 val NUM_8 = 15
val NUM_9 = 10 val NUM_9 = 16
val NUM_0 = 11 val NUM_0 = 7
// JInput is QWERTY-based // JInput is QWERTY-based
val Q = 16 val Q = 16

View File

@@ -1,6 +1,7 @@
package net.torvald.terrarum.ui package net.torvald.terrarum.ui
import com.badlogic.gdx.Gdx import com.badlogic.gdx.Gdx
import com.badlogic.gdx.Input
import com.badlogic.gdx.graphics.Color import com.badlogic.gdx.graphics.Color
import com.badlogic.gdx.graphics.g2d.SpriteBatch import com.badlogic.gdx.graphics.g2d.SpriteBatch
import net.torvald.dataclass.HistoryArray import net.torvald.dataclass.HistoryArray
@@ -9,7 +10,6 @@ import net.torvald.terrarum.TerrarumGDX
import net.torvald.terrarum.console.Authenticator import net.torvald.terrarum.console.Authenticator
import net.torvald.terrarum.console.CommandInterpreter import net.torvald.terrarum.console.CommandInterpreter
import net.torvald.terrarum.fillRect import net.torvald.terrarum.fillRect
import net.torvald.terrarum.gamecontroller.Key
/** /**
@@ -80,60 +80,59 @@ class ConsoleWindow : UICanvas, KeyControlled {
} }
override fun keyPressed(key: Int, c: Char) { override fun keyDown(key: Int): Boolean {
// history // history
if (key == Key.UP && historyIndex < commandHistory.history.size) if (key == Input.Keys.UP && historyIndex < commandHistory.history.size)
historyIndex++ historyIndex++
else if (key == Key.DOWN && historyIndex >= 0) else if (key == Input.Keys.DOWN && historyIndex >= 0)
historyIndex-- historyIndex--
else if (key != Key.UP && key != Key.DOWN) else if (key != Input.Keys.UP && key != Input.Keys.DOWN)
historyIndex = -1 historyIndex = -1
// execute // execute
if (key == Key.RETURN && commandInputPool!!.isNotEmpty()) { if (key == Input.Keys.ENTER && commandInputPool!!.isNotEmpty()) {
commandHistory.add(commandInputPool!!.toString()) commandHistory.add(commandInputPool!!.toString())
executeCommand() executeCommand()
commandInputPool = StringBuilder() commandInputPool = StringBuilder()
} }
// erase last letter // erase last letter
else if (key == Key.BACKSPACE && commandInputPool!!.isNotEmpty()) { else if (key == Input.Keys.BACKSPACE && commandInputPool!!.isNotEmpty()) {
commandInputPool!!.deleteCharAt(commandInputPool!!.length - 1) commandInputPool!!.deleteCharAt(commandInputPool!!.length - 1)
} }
// append acceptable letter
else if (key >= 2 && key <= 13
|| key >= 16 && key <= 27
|| key >= 30 && key <= 40
|| key >= 44 && key <= 53
|| commandInputPool!!.length > 0 && key == 57) {
commandInputPool!!.append(c)
inputCursorPos += 1
}
// scroll // scroll
else if (key == Key.UP || key == Key.DOWN) { else if (key == Input.Keys.UP || key == Input.Keys.DOWN) {
// create new stringbuilder // create new stringbuilder
commandInputPool = StringBuilder() commandInputPool = StringBuilder()
if (historyIndex >= 0) // just leave blank if index is -1 if (historyIndex >= 0) // just leave blank if index is -1
commandInputPool!!.append(commandHistory[historyIndex] ?: "") commandInputPool!!.append(commandHistory[historyIndex] ?: "")
} }
// delete input // delete input
else if (key == Key.DELETE) { else if (key == Input.Keys.BACKSPACE) {
commandInputPool = StringBuilder() commandInputPool = StringBuilder()
} }
// message scroll up // message scroll up
else if (key == Key.PGUP) { else if (key == Input.Keys.PAGE_UP) {
setDisplayPos(-MESSAGES_DISPLAY_COUNT + 1) setDisplayPos(-MESSAGES_DISPLAY_COUNT + 1)
} }
// message scroll down // message scroll down
else if (key == Key.PGDN) { else if (key == Input.Keys.PAGE_DOWN) {
setDisplayPos(MESSAGES_DISPLAY_COUNT - 1) setDisplayPos(MESSAGES_DISPLAY_COUNT - 1)
} }
return true
} }
override fun keyReleased(key: Int, c: Char) { override fun keyTyped(character: Char): Boolean {
commandInputPool!!.append(character)
inputCursorPos += 1
return true
} }
override fun keyUp(keycode: Int): Boolean {
return false
}
private fun executeCommand() { private fun executeCommand() {
CommandInterpreter.execute(commandInputPool!!.toString()) CommandInterpreter.execute(commandInputPool!!.toString())
@@ -205,12 +204,6 @@ class ConsoleWindow : UICanvas, KeyControlled {
openingTimeCounter = 0f openingTimeCounter = 0f
} }
override fun controllerButtonPressed(controller: Int, button: Int) {
}
override fun controllerButtonReleased(controller: Int, button: Int) {
}
override fun processInput(delta: Float) { override fun processInput(delta: Float) {
} }
} }

View File

@@ -4,8 +4,7 @@ package net.torvald.terrarum.ui
* Created by minjaesong on 16-03-06. * Created by minjaesong on 16-03-06.
*/ */
interface KeyControlled { interface KeyControlled {
fun keyPressed(key: Int, c: Char) fun keyDown(keycode: Int): Boolean
fun keyReleased(key: Int, c: Char) fun keyUp(keycode: Int): Boolean
fun controllerButtonPressed(controller: Int, button: Int) fun keyTyped(character: Char): Boolean
fun controllerButtonReleased(controller: Int, button: Int)
} }

View File

@@ -4,9 +4,9 @@ package net.torvald.terrarum.ui
* Created by minjaesong on 16-03-06. * Created by minjaesong on 16-03-06.
*/ */
interface MouseControlled { interface MouseControlled {
fun mouseMoved(oldx: Int, oldy: Int, newx: Int, newy: Int) fun mouseMoved(screenX: Int, screenY: Int): Boolean
fun mouseDragged(oldx: Int, oldy: Int, newx: Int, newy: Int) fun touchDragged(screenX: Int, screenY: Int, pointer: Int): Boolean
fun mousePressed(button: Int, x: Int, y: Int) fun touchDown(screenX: Int, screenY: Int, pointer: Int, button: Int): Boolean
fun mouseReleased(button: Int, x: Int, y: Int) fun touchUp(screenX: Int, screenY: Int, pointer: Int, button: Int): Boolean
fun mouseWheelMoved(change: Int) fun scrolled(amount: Int): Boolean
} }

View File

@@ -209,58 +209,66 @@ class UIHandler(val UI: UICanvas,
} }
} }
fun keyPressed(key: Int, c: Char) { fun keyDown(keycode: Int): Boolean {
if (isVisible && UI is KeyControlled) { if (isVisible && UI is KeyControlled) {
UI.keyPressed(key, c) return UI.keyDown(keycode)
} }
return false
} }
fun keyReleased(key: Int, c: Char) { fun keyUp(keycode: Int): Boolean {
if (isVisible && UI is KeyControlled) { if (isVisible && UI is KeyControlled) {
UI.keyReleased(key, c) return UI.keyUp(keycode)
} }
return false
} }
fun mouseMoved(oldx: Int, oldy: Int, newx: Int, newy: Int) { fun keyTyped(char: Char): Boolean {
if (isVisible && UI is MouseControlled) {
UI.mouseMoved(oldx, oldy, newx, newy)
}
}
fun mouseDragged(oldx: Int, oldy: Int, newx: Int, newy: Int) {
if (isVisible && UI is MouseControlled) {
UI.mouseDragged(oldx, oldy, newx, newy)
}
}
fun mousePressed(button: Int, x: Int, y: Int) {
if (isVisible && UI is MouseControlled) {
UI.mousePressed(button, x, y)
}
}
fun mouseReleased(button: Int, x: Int, y: Int) {
if (isVisible && UI is MouseControlled) {
UI.mouseReleased(button, x, y)
}
}
fun mouseWheelMoved(change: Int) {
if (isVisible && UI is MouseControlled) {
UI.mouseWheelMoved(change)
}
}
fun controllerButtonPressed(controller: Int, button: Int) {
if (isVisible && UI is KeyControlled) { if (isVisible && UI is KeyControlled) {
UI.controllerButtonPressed(controller, button) return UI.keyTyped(char)
}
return false
}
fun mouseMoved(screenX: Int, screenY: Int) {
if (isVisible && UI is MouseControlled) {
UI.mouseMoved(screenX, screenY)
} }
} }
fun controllerButtonReleased(controller: Int, button: Int) { fun touchDragged(screenX: Int, screenY: Int, pointer: Int): Boolean {
if (isVisible && UI is KeyControlled) { if (isVisible && UI is MouseControlled) {
UI.controllerButtonReleased(controller, button) UI.touchDragged(screenX, screenY, pointer)
} }
return false
}
fun touchDown(screenX: Int, screenY: Int, pointer: Int, button: Int): Boolean {
if (isVisible && UI is MouseControlled) {
UI.touchDown(screenX, screenY, pointer, button)
}
return false
}
fun touchUp(screenX: Int, screenY: Int, pointer: Int, button: Int): Boolean {
if (isVisible && UI is MouseControlled) {
UI.touchUp(screenX, screenY, pointer, button)
}
return false
}
fun scrolled(amount: Int): Boolean {
if (isVisible && UI is MouseControlled) {
UI.scrolled(amount)
}
return false
} }
// constant UI can't take control // constant UI can't take control

View File

@@ -315,40 +315,47 @@ class UIInventory(
UICanvas.endClosingPopOut(handler, UICanvas.Companion.Position.LEFT) UICanvas.endClosingPopOut(handler, UICanvas.Companion.Position.LEFT)
} }
override fun keyPressed(key: Int, c: Char) { override fun mouseMoved(screenX: Int, screenY: Int): Boolean {
items.forEach { if (it.mouseUp) it.keyPressed(key, c) } TODO("not implemented") //To change body of created functions use File | Settings | File Templates.
}
override fun keyDown(keycode: Int): Boolean {
items.forEach { if (it.mouseUp) it.keyDown(keycode) }
shutUpAndRebuild() shutUpAndRebuild()
return true
} }
override fun mouseMoved(oldx: Int, oldy: Int, newx: Int, newy: Int) { override fun keyUp(keycode: Int): Boolean {
} items.forEach { if (it.mouseUp) it.keyUp(keycode) }
override fun keyReleased(key: Int, c: Char) {
items.forEach { if (it.mouseUp) it.keyReleased(key, c) }
shutUpAndRebuild() shutUpAndRebuild()
return true
} }
override fun mouseDragged(oldx: Int, oldy: Int, newx: Int, newy: Int) { override fun keyTyped(character: Char): Boolean {
return false
} }
override fun controllerButtonPressed(controller: Int, button: Int) { override fun touchDragged(screenX: Int, screenY: Int, pointer: Int): Boolean {
items.forEach { if (it.mouseUp) it.controllerButtonPressed(controller, button) } return false
shutUpAndRebuild()
} }
override fun mousePressed(button: Int, x: Int, y: Int) { override fun touchDown(screenX: Int, screenY: Int, pointer: Int, button: Int): Boolean {
items.forEach { if (it.mouseUp) it.mousePressed(button, x, y) } items.forEach { if (it.mouseUp) it.touchDown(screenX, screenY, pointer, button) }
return true
} }
override fun controllerButtonReleased(controller: Int, button: Int) { override fun touchUp(screenX: Int, screenY: Int, pointer: Int, button: Int): Boolean {
items.forEach { if (it.mouseUp) it.controllerButtonReleased(controller, button) } items.forEach { if (it.mouseUp) it.touchUp(screenX, screenY, pointer, button) }
shutUpAndRebuild()
return true
} }
override fun mouseReleased(button: Int, x: Int, y: Int) { override fun scrolled(amount: Int): Boolean {
items.forEach { if (it.mouseUp) it.mouseReleased(button, x, y) } return false
} }
override fun mouseWheelMoved(change: Int) {
}
} }

View File

@@ -32,17 +32,14 @@ abstract class UIItem(var parentUI: UICanvas) { // do not replace parentUI to UI
abstract fun render(batch: SpriteBatch) abstract fun render(batch: SpriteBatch)
// keyboard controlled // keyboard controlled
abstract fun keyPressed(key: Int, c: Char) abstract fun keyDown(keycode: Int): Boolean
abstract fun keyReleased(key: Int, c: Char) abstract fun keyUp(keycode: Int): Boolean
// mouse controlled // mouse controlled
abstract fun mouseMoved(oldx: Int, oldy: Int, newx: Int, newy: Int) abstract fun mouseMoved(screenX: Int, screenY: Int): Boolean
abstract fun mouseDragged(oldx: Int, oldy: Int, newx: Int, newy: Int) abstract fun touchDragged(screenX: Int, screenY: Int, pointer: Int): Boolean
abstract fun mousePressed(button: Int, x: Int, y: Int) abstract fun touchDown(screenX: Int, screenY: Int, pointer: Int, button: Int): Boolean
abstract fun mouseReleased(button: Int, x: Int, y: Int) abstract fun touchUp(screenX: Int, screenY: Int, pointer: Int, button: Int): Boolean
abstract fun mouseWheelMoved(change: Int) abstract fun scrolled(amount: Int): Boolean
// gamepad controlled
abstract fun controllerButtonPressed(controller: Int, button: Int)
abstract fun controllerButtonReleased(controller: Int, button: Int)
} }

View File

@@ -42,39 +42,31 @@ class UIItemImageGallery(
} }
} }
override fun keyPressed(key: Int, c: Char) { override fun keyDown(keycode: Int): Boolean {
throw UnsupportedOperationException("not implemented") //To change body of created functions use File | Settings | File Templates. TODO("not implemented") //To change body of created functions use File | Settings | File Templates.
} }
override fun keyReleased(key: Int, c: Char) { override fun keyUp(keycode: Int): Boolean {
throw UnsupportedOperationException("not implemented") //To change body of created functions use File | Settings | File Templates. TODO("not implemented") //To change body of created functions use File | Settings | File Templates.
} }
override fun mouseMoved(oldx: Int, oldy: Int, newx: Int, newy: Int) { override fun mouseMoved(screenX: Int, screenY: Int): Boolean {
throw UnsupportedOperationException("not implemented") //To change body of created functions use File | Settings | File Templates. TODO("not implemented") //To change body of created functions use File | Settings | File Templates.
} }
override fun mouseDragged(oldx: Int, oldy: Int, newx: Int, newy: Int) { override fun touchDragged(screenX: Int, screenY: Int, pointer: Int): Boolean {
throw UnsupportedOperationException("not implemented") //To change body of created functions use File | Settings | File Templates. TODO("not implemented") //To change body of created functions use File | Settings | File Templates.
} }
override fun mousePressed(button: Int, x: Int, y: Int) { override fun touchDown(screenX: Int, screenY: Int, pointer: Int, button: Int): Boolean {
throw UnsupportedOperationException("not implemented") //To change body of created functions use File | Settings | File Templates. TODO("not implemented") //To change body of created functions use File | Settings | File Templates.
} }
override fun mouseReleased(button: Int, x: Int, y: Int) { override fun touchUp(screenX: Int, screenY: Int, pointer: Int, button: Int): Boolean {
throw UnsupportedOperationException("not implemented") //To change body of created functions use File | Settings | File Templates. TODO("not implemented") //To change body of created functions use File | Settings | File Templates.
} }
override fun mouseWheelMoved(change: Int) { override fun scrolled(amount: Int): Boolean {
throw UnsupportedOperationException("not implemented") //To change body of created functions use File | Settings | File Templates. TODO("not implemented") //To change body of created functions use File | Settings | File Templates.
}
override fun controllerButtonPressed(controller: Int, button: Int) {
throw UnsupportedOperationException("not implemented") //To change body of created functions use File | Settings | File Templates.
}
override fun controllerButtonReleased(controller: Int, button: Int) {
throw UnsupportedOperationException("not implemented") //To change body of created functions use File | Settings | File Templates.
} }
} }

View File

@@ -82,30 +82,31 @@ class UIItemTextButton(
} }
} }
override fun keyPressed(key: Int, c: Char) { override fun keyDown(keycode: Int): Boolean {
return false
} }
override fun keyReleased(key: Int, c: Char) { override fun keyUp(keycode: Int): Boolean {
return false
} }
override fun mouseMoved(oldx: Int, oldy: Int, newx: Int, newy: Int) { override fun mouseMoved(screenX: Int, screenY: Int): Boolean {
return false
} }
override fun mouseDragged(oldx: Int, oldy: Int, newx: Int, newy: Int) { override fun touchDragged(screenX: Int, screenY: Int, pointer: Int): Boolean {
return false
} }
override fun mousePressed(button: Int, x: Int, y: Int) { override fun touchDown(screenX: Int, screenY: Int, pointer: Int, button: Int): Boolean {
return false
} }
override fun mouseReleased(button: Int, x: Int, y: Int) { override fun touchUp(screenX: Int, screenY: Int, pointer: Int, button: Int): Boolean {
return false
} }
override fun mouseWheelMoved(change: Int) { override fun scrolled(amount: Int): Boolean {
} return false
override fun controllerButtonPressed(controller: Int, button: Int) {
}
override fun controllerButtonReleased(controller: Int, button: Int) {
} }
} }

View File

@@ -169,30 +169,31 @@ class UIItemTextButtonList(
} }
} }
override fun keyPressed(key: Int, c: Char) { override fun keyDown(keycode: Int): Boolean {
return false
} }
override fun keyReleased(key: Int, c: Char) { override fun keyUp(keycode: Int): Boolean {
return false
} }
override fun mouseMoved(oldx: Int, oldy: Int, newx: Int, newy: Int) { override fun mouseMoved(screenX: Int, screenY: Int): Boolean {
return false
} }
override fun mouseDragged(oldx: Int, oldy: Int, newx: Int, newy: Int) { override fun touchDragged(screenX: Int, screenY: Int, pointer: Int): Boolean {
return false
} }
override fun mousePressed(button: Int, x: Int, y: Int) { override fun touchDown(screenX: Int, screenY: Int, pointer: Int, button: Int): Boolean {
return false
} }
override fun mouseReleased(button: Int, x: Int, y: Int) { override fun touchUp(screenX: Int, screenY: Int, pointer: Int, button: Int): Boolean {
return false
} }
override fun mouseWheelMoved(change: Int) { override fun scrolled(amount: Int): Boolean {
} return false
override fun controllerButtonPressed(controller: Int, button: Int) {
}
override fun controllerButtonReleased(controller: Int, button: Int) {
} }
} }

View File

@@ -89,22 +89,29 @@ class UIQuickBar : UICanvas, MouseControlled {
handler!!.opacity = 0f handler!!.opacity = 0f
} }
override fun mouseMoved(oldx: Int, oldy: Int, newx: Int, newy: Int) { override fun mouseMoved(screenX: Int, screenY: Int): Boolean {
return false
} }
override fun mouseDragged(oldx: Int, oldy: Int, newx: Int, newy: Int) { override fun touchDragged(screenX: Int, screenY: Int, pointer: Int): Boolean {
return false
} }
override fun mousePressed(button: Int, x: Int, y: Int) { override fun touchDown(screenX: Int, screenY: Int, pointer: Int, button: Int): Boolean {
return false
} }
override fun mouseReleased(button: Int, x: Int, y: Int) { override fun touchUp(screenX: Int, screenY: Int, pointer: Int, button: Int): Boolean {
return false
} }
override fun mouseWheelMoved(change: Int) { override fun scrolled(amount: Int): Boolean {
selection = selection.plus(if (change > 1) 1 else if (change < -1) -1 else 0).fmod(SLOT_COUNT) selection = selection.plus(if (amount > 1) 1 else if (amount < -1) -1 else 0).fmod(SLOT_COUNT)
return true
} }
companion object { companion object {
val finalOpacity = 0.8f val finalOpacity = 0.8f

View File

@@ -5,7 +5,6 @@ import org.luaj.vm2.Globals
import org.luaj.vm2.LuaTable import org.luaj.vm2.LuaTable
import org.luaj.vm2.LuaValue import org.luaj.vm2.LuaValue
import org.luaj.vm2.lib.OneArgFunction import org.luaj.vm2.lib.OneArgFunction
import net.torvald.terrarum.gamecontroller.Key
import net.torvald.terrarum.virtualcomputer.computer.TerrarumComputer import net.torvald.terrarum.virtualcomputer.computer.TerrarumComputer
/** /**
@@ -13,38 +12,5 @@ import net.torvald.terrarum.virtualcomputer.computer.TerrarumComputer
*/ */
class Input(globals: Globals, 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.blendMul
import net.torvald.terrarum.gameactors.DecodeTapestry import net.torvald.terrarum.gameactors.DecodeTapestry
import net.torvald.terrarum.gameactors.abs import net.torvald.terrarum.gameactors.abs
import net.torvald.terrarum.gamecontroller.Key
import net.torvald.terrarum.virtualcomputer.computer.TerrarumComputer import net.torvald.terrarum.virtualcomputer.computer.TerrarumComputer
import java.util.* import java.util.*

View File

@@ -10,40 +10,43 @@ import net.torvald.terrarum.virtualcomputer.terminal.Terminal
* Created by minjaesong on 16-09-08. * Created by minjaesong on 16-09-08.
*/ */
class UITextTerminal(val terminal: Terminal) : UICanvas, KeyControlled, MouseControlled { 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) { override fun mouseMoved(screenX: Int, screenY: Int): Boolean {
throw UnsupportedOperationException("not implemented") //To change body of created functions use File | Settings | File Templates. return false
} }
override fun keyReleased(key: Int, c: Char) { override fun keyUp(keycode: Int): Boolean {
throw UnsupportedOperationException("not implemented") //To change body of created functions use File | Settings | File Templates. return false
} }
override fun mouseDragged(oldx: Int, oldy: Int, newx: Int, newy: Int) { override fun touchDragged(screenX: Int, screenY: Int, pointer: Int): Boolean {
throw UnsupportedOperationException("not implemented") //To change body of created functions use File | Settings | File Templates. 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 width: Int = terminal.displayW// + some
override var height: Int = terminal.displayH// + frame 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 * Usage: (in StateInGame:) uiHandlerField.ui.handler = uiHandlerField

View File

@@ -1,6 +1,7 @@
package net.torvald.terrarum.weather package net.torvald.terrarum.weather
import com.badlogic.gdx.Gdx import com.badlogic.gdx.Gdx
import com.badlogic.gdx.Input
import com.badlogic.gdx.graphics.Color import com.badlogic.gdx.graphics.Color
import com.badlogic.gdx.graphics.Texture import com.badlogic.gdx.graphics.Texture
import com.badlogic.gdx.graphics.g2d.SpriteBatch import com.badlogic.gdx.graphics.g2d.SpriteBatch
@@ -10,7 +11,6 @@ import net.torvald.colourutil.*
import net.torvald.random.HQRNG import net.torvald.random.HQRNG
import net.torvald.terrarum.* import net.torvald.terrarum.*
import net.torvald.terrarum.gameactors.ParticleTestRain import net.torvald.terrarum.gameactors.ParticleTestRain
import net.torvald.terrarum.gamecontroller.Key
import net.torvald.terrarum.gamecontroller.KeyToggler import net.torvald.terrarum.gamecontroller.KeyToggler
import net.torvald.terrarum.gameworld.WorldTime import net.torvald.terrarum.gameworld.WorldTime
import java.io.File import java.io.File
@@ -78,7 +78,7 @@ object WeatherMixer {
if (TerrarumGDX.ingame!!.player != null) { if (TerrarumGDX.ingame!!.player != null) {
// test rain toggled by F2 // test rain toggled by F2
if (KeyToggler.isOn(Key.F2)) { if (KeyToggler.isOn(Input.Keys.F2)) {
val playerPos = TerrarumGDX.ingame!!.player!!.centrePosPoint val playerPos = TerrarumGDX.ingame!!.player!!.centrePosPoint
kotlin.repeat(4) { kotlin.repeat(4) {
// 4 seems good // 4 seems good