mirror of
https://github.com/curioustorvald/Terrarum.git
synced 2026-03-08 04:41:51 +09:00
somehow fixed a consolewin bug
- It would read a key even if it's closed
This commit is contained in:
@@ -100,7 +100,7 @@ class IngameController(val ingame: Ingame) : InputAdapter() {
|
||||
}
|
||||
|
||||
override fun keyTyped(character: Char): Boolean {
|
||||
ingame.uiContainer.forEach { it.keyTyped(character) }
|
||||
ingame.uiContainer.forEach { if (it.isVisible) it.keyTyped(character) }
|
||||
return true
|
||||
}
|
||||
|
||||
|
||||
@@ -125,6 +125,8 @@ class ConsoleWindow : UICanvas() {
|
||||
val acceptedChars = "1234567890-=qwfpgjluy;[]\\arstdhneio'zxcvbkm,./!@#$%^&*()_+QWFPGJLUY:{}|ARSTDHNEIO\"ZXCVBKM<>? ".toSet()
|
||||
|
||||
override fun keyTyped(character: Char): Boolean {
|
||||
println("[ConsoleWindow] Key typed event; isVisible = $isVisible")
|
||||
|
||||
if (character in acceptedChars) {
|
||||
commandInputPool!!.append(character)
|
||||
inputCursorPos += 1
|
||||
|
||||
@@ -12,6 +12,8 @@ import net.torvald.terrarum.gameactors.roundInt
|
||||
/**
|
||||
* UIItems must be added manually at the init!
|
||||
*
|
||||
* FIXME: Bad design!!
|
||||
*
|
||||
* Created by minjaesong on 2015-12-31.
|
||||
*/
|
||||
abstract class UICanvas(
|
||||
|
||||
@@ -104,7 +104,7 @@ class UIHandler(//var UI: UICanvas,
|
||||
if (closeFired && openCloseCounter > 9) closeFired = false
|
||||
|
||||
|
||||
if (isVisible || alwaysVisible) {
|
||||
if (isVisible) {
|
||||
ui.updateUI(delta)
|
||||
}
|
||||
|
||||
@@ -153,7 +153,7 @@ class UIHandler(//var UI: UICanvas,
|
||||
|
||||
fun render(ui: UICanvas, batch: SpriteBatch, camera: Camera) {
|
||||
|
||||
if (isVisible || alwaysVisible) {
|
||||
if (isVisible) {
|
||||
// camera SHOULD BE CENTERED to HALFX and HALFY (see StateInGame) //
|
||||
|
||||
|
||||
@@ -255,4 +255,85 @@ class UIHandler(//var UI: UICanvas,
|
||||
fun setCameraPosition(batch: SpriteBatch, camera: Camera, newX: Float, newY: Float) {
|
||||
Ingame.setCameraPosition(batch, camera, newX, newY)
|
||||
}
|
||||
|
||||
fun mouseMoved(uiItems: List<UIItem>, screenX: Int, screenY: Int): Boolean {
|
||||
if (isVisible) {
|
||||
uiItems.forEach { it.mouseMoved(screenX, screenY) }
|
||||
subUIs.forEach { it.mouseMoved(screenX, screenY) }
|
||||
return true
|
||||
}
|
||||
else {
|
||||
return false
|
||||
}
|
||||
}
|
||||
fun touchDragged(uiItems: List<UIItem>, screenX: Int, screenY: Int, pointer: Int): Boolean {
|
||||
if (isVisible) {
|
||||
uiItems.forEach { it.touchDragged(screenX, screenY, pointer) }
|
||||
subUIs.forEach { it.touchDragged(screenX, screenY, pointer) }
|
||||
return true
|
||||
}
|
||||
else {
|
||||
return false
|
||||
}
|
||||
}
|
||||
fun touchDown(uiItems: List<UIItem>, screenX: Int, screenY: Int, pointer: Int, button: Int): Boolean {
|
||||
if (isVisible) {
|
||||
uiItems.forEach { it.touchDown(screenX, screenY, pointer, button) }
|
||||
subUIs.forEach { it.touchDown(screenX, screenY, pointer, button) }
|
||||
return true
|
||||
}
|
||||
else {
|
||||
return false
|
||||
}
|
||||
}
|
||||
fun touchUp(uiItems: List<UIItem>, screenX: Int, screenY: Int, pointer: Int, button: Int): Boolean {
|
||||
if (isVisible) {
|
||||
uiItems.forEach { it.touchUp(screenX, screenY, pointer, button) }
|
||||
subUIs.forEach { it.touchUp(screenX, screenY, pointer, button) }
|
||||
return true
|
||||
}
|
||||
else {
|
||||
return false
|
||||
}
|
||||
}
|
||||
fun scrolled(uiItems: List<UIItem>, amount: Int): Boolean {
|
||||
if (isVisible) {
|
||||
uiItems.forEach { it.scrolled(amount) }
|
||||
subUIs.forEach { it.scrolled(amount) }
|
||||
return true
|
||||
}
|
||||
else {
|
||||
return false
|
||||
}
|
||||
}
|
||||
fun keyDown(uiItems: List<UIItem>, keycode: Int): Boolean {
|
||||
if (isVisible) {
|
||||
uiItems.forEach { it.keyDown(keycode) }
|
||||
subUIs.forEach { it.keyDown(keycode) }
|
||||
return true
|
||||
}
|
||||
else {
|
||||
return false
|
||||
}
|
||||
}
|
||||
fun keyUp(uiItems: List<UIItem>, keycode: Int): Boolean {
|
||||
if (isVisible) {
|
||||
uiItems.forEach { it.keyUp(keycode) }
|
||||
subUIs.forEach { it.keyUp(keycode) }
|
||||
return true
|
||||
}
|
||||
else {
|
||||
return false
|
||||
}
|
||||
}
|
||||
fun keyTyped(uiItems: List<UIItem>, character: Char): Boolean {
|
||||
if (isVisible) {
|
||||
//uiItems.forEach { it.keyTyped(character) }
|
||||
subUIs.forEach { it.keyTyped(character) }
|
||||
return true
|
||||
}
|
||||
else {
|
||||
return false
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -561,10 +561,14 @@ object LightmapRenderer {
|
||||
}
|
||||
|
||||
|
||||
fun resize(width: Int, height: Int) {
|
||||
fun resize(screenW: Int, screenH: Int) {
|
||||
// make sure the BlocksDrawer is resized first!
|
||||
|
||||
lightBuffer = Pixmap(BlocksDrawer.tilesInHorizontal, BlocksDrawer.tilesInVertical, Pixmap.Format.RGBA8888)
|
||||
// copied from BlocksDrawer, duh!
|
||||
val tilesInHorizontal = (screenW.toFloat() / TILE_SIZE).ceilInt() + 1
|
||||
val tilesInVertical = (screenH.toFloat() / TILE_SIZE).ceilInt() + 1
|
||||
|
||||
lightBuffer = Pixmap(tilesInHorizontal, tilesInVertical, Pixmap.Format.RGBA8888)
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user