From 0004240c526babfbcc364db066e76f4dded85c7c Mon Sep 17 00:00:00 2001 From: minjaesong Date: Wed, 18 Oct 2017 03:52:11 +0900 Subject: [PATCH] somehow fixed a consolewin bug - It would read a key even if it's closed --- assets/modules/basegame/blocks/blocks.csv | 7 +- .../gamecontroller/IngameController.kt | 2 +- src/net/torvald/terrarum/ui/ConsoleWindow.kt | 2 + src/net/torvald/terrarum/ui/UICanvas.kt | 2 + src/net/torvald/terrarum/ui/UIHandler.kt | 85 ++++++++++++++++++- .../worlddrawer/LightmapRendererNew.kt | 8 +- 6 files changed, 98 insertions(+), 8 deletions(-) diff --git a/assets/modules/basegame/blocks/blocks.csv b/assets/modules/basegame/blocks/blocks.csv index 92f15eaac..5fcd72c26 100644 --- a/assets/modules/basegame/blocks/blocks.csv +++ b/assets/modules/basegame/blocks/blocks.csv @@ -56,9 +56,9 @@ "177"; "177";"BLOCK_TORCH_FROST" ;"0.0312";"0.0312";"0.0312";"0.0312"; "1"; "N/A";"fxtr"; "0"; "0"; "1"; "0";"0.3048";"0.4848";"1.0000";"0.0000"; "0"; "1"; "N/A"; "0";"16" "192"; "176";"BLOCK_TORCH" ;"0.0312";"0.0312";"0.0312";"0.0312"; "1"; "N/A";"fxtr"; "0"; "0"; "1"; "0";"0.0000";"0.0000";"0.0000";"0.0000"; "0"; "0"; "N/A"; "0";"16" "193"; "177";"BLOCK_TORCH_FROST" ;"0.0312";"0.0312";"0.0312";"0.0312"; "1"; "N/A";"fxtr"; "0"; "0"; "1"; "0";"0.0000";"0.0000";"0.0000";"0.0000"; "0"; "0"; "N/A"; "0";"16" - "208"; "208";"BLOCK_ILLUMINATOR_WHITE" ;"0.0312";"0.0312";"0.0312";"0.0312"; "1"; "N/A";"glas"; "0"; "1"; "0"; "1";"0.8916";"0.9304";"0.9148";"0.0000"; "0"; "0"; "N/A"; "0";"16" + "208"; "208";"BLOCK_ILLUMINATOR_WHITE" ;"0.0312";"0.0312";"0.0312";"0.0312"; "1"; "N/A";"glas"; "0"; "1"; "0"; "1";"0.9270";"0.9414";"0.8519";"0.0000"; "0"; "0"; "N/A"; "0";"16" "209"; "209";"BLOCK_ILLUMINATOR_YELLOW" ;"0.0312";"0.0312";"0.0312";"0.0312"; "1"; "N/A";"glas"; "0"; "1"; "0"; "1";"1.0000";"0.8408";"0.0000";"0.0000"; "0"; "0"; "N/A"; "0";"16" - "210"; "210";"BLOCK_ILLUMINATOR_ORANGE" ;"0.0312";"0.0312";"0.0312";"0.0312"; "1"; "N/A";"glas"; "0"; "1"; "0"; "1";"1.0000";"0.6100";"0.0000";"0.0000"; "0"; "0"; "N/A"; "0";"16" + "210"; "210";"BLOCK_ILLUMINATOR_ORANGE" ;"0.0312";"0.0312";"0.0312";"0.0312"; "1"; "N/A";"glas"; "0"; "1"; "0"; "1";"1.0000";"0.5294";"0.0000";"0.0000"; "0"; "0"; "N/A"; "0";"16" "211"; "211";"BLOCK_ILLUMINATOR_RED" ;"0.0312";"0.0312";"0.0312";"0.0312"; "1"; "N/A";"glas"; "0"; "1"; "0"; "1";"0.9188";"0.0000";"0.0000";"0.0000"; "0"; "0"; "N/A"; "0";"16" "212"; "212";"BLOCK_ILLUMINATOR_FUCHSIA" ;"0.0312";"0.0312";"0.0312";"0.0312"; "1"; "N/A";"glas"; "0"; "1"; "0"; "1";"0.9188";"0.0000";"0.7156";"0.0000"; "0"; "0"; "N/A"; "0";"16" "213"; "213";"BLOCK_ILLUMINATOR_PURPLE" ;"0.0312";"0.0312";"0.0312";"0.0312"; "1"; "N/A";"glas"; "0"; "1"; "0"; "1";"0.7156";"0.0000";"0.9188";"0.0000"; "0"; "0"; "N/A"; "0";"16" @@ -159,7 +159,8 @@ ## Illuminators ## -# Illuminator white: RGB(228,238,234), simulation of a halophosphate FL lamp (If you want high CRI lamp, collect a daylight!) +# Illuminator white: Mercury Lamp; CIELAB of (94, -5.131, 10.613), which is made out of CIEXYZ of (0.947638, 1.146481, 0.482263), measured with ColorMunki Spectrometer (If you want high CRI lamp, collect a daylight!) +# Illuminator orange: Sodium Lamp; CIE xy of (0.5375, 0.4153), CIEXYZ of (352.531139, 272.379377, 30.980339), measured with ColorMunki Spectrometer # Defalut torch : Y 64 x 0.55183 y 0.40966 (Planckian ~1 770 K); real candlelight colour taken from Spyder5 colorimeter (for I couldn't afford i1DisplayPro/Colormunki) # Sunstone: Artificial sunlight, change colour over time in sync with sunlight. The light is set by game's code. # Sunlight capacitor: daylight at noon. Set by game's code. diff --git a/src/net/torvald/terrarum/gamecontroller/IngameController.kt b/src/net/torvald/terrarum/gamecontroller/IngameController.kt index f72dc2cef..630f3ff80 100644 --- a/src/net/torvald/terrarum/gamecontroller/IngameController.kt +++ b/src/net/torvald/terrarum/gamecontroller/IngameController.kt @@ -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 } diff --git a/src/net/torvald/terrarum/ui/ConsoleWindow.kt b/src/net/torvald/terrarum/ui/ConsoleWindow.kt index 5652ef4b4..f5796827b 100644 --- a/src/net/torvald/terrarum/ui/ConsoleWindow.kt +++ b/src/net/torvald/terrarum/ui/ConsoleWindow.kt @@ -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 diff --git a/src/net/torvald/terrarum/ui/UICanvas.kt b/src/net/torvald/terrarum/ui/UICanvas.kt index 02689a6c0..3af1723d8 100644 --- a/src/net/torvald/terrarum/ui/UICanvas.kt +++ b/src/net/torvald/terrarum/ui/UICanvas.kt @@ -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( diff --git a/src/net/torvald/terrarum/ui/UIHandler.kt b/src/net/torvald/terrarum/ui/UIHandler.kt index 65fd1db49..9d1afe30d 100644 --- a/src/net/torvald/terrarum/ui/UIHandler.kt +++ b/src/net/torvald/terrarum/ui/UIHandler.kt @@ -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, 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, 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, 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, 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, amount: Int): Boolean { + if (isVisible) { + uiItems.forEach { it.scrolled(amount) } + subUIs.forEach { it.scrolled(amount) } + return true + } + else { + return false + } + } + fun keyDown(uiItems: List, keycode: Int): Boolean { + if (isVisible) { + uiItems.forEach { it.keyDown(keycode) } + subUIs.forEach { it.keyDown(keycode) } + return true + } + else { + return false + } + } + fun keyUp(uiItems: List, keycode: Int): Boolean { + if (isVisible) { + uiItems.forEach { it.keyUp(keycode) } + subUIs.forEach { it.keyUp(keycode) } + return true + } + else { + return false + } + } + fun keyTyped(uiItems: List, character: Char): Boolean { + if (isVisible) { + //uiItems.forEach { it.keyTyped(character) } + subUIs.forEach { it.keyTyped(character) } + return true + } + else { + return false + } + } } diff --git a/src/net/torvald/terrarum/worlddrawer/LightmapRendererNew.kt b/src/net/torvald/terrarum/worlddrawer/LightmapRendererNew.kt index ac9c7a94a..30c737d71 100644 --- a/src/net/torvald/terrarum/worlddrawer/LightmapRendererNew.kt +++ b/src/net/torvald/terrarum/worlddrawer/LightmapRendererNew.kt @@ -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)