Skip to content

Commit f8f69d2

Browse files
committed
fix input processors order of event handling:
stages consume inputs even when not visible, so had to be moved out of the input processor list when are hidden
1 parent 0f0c499 commit f8f69d2

File tree

2 files changed

+63
-46
lines changed

2 files changed

+63
-46
lines changed

cake/core/src/main/java/org/demoth/cake/Cake.kt

Lines changed: 62 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,10 @@ import com.badlogic.gdx.InputProcessor
77
import com.badlogic.gdx.scenes.scene2d.ui.Skin
88
import com.badlogic.gdx.utils.ScreenUtils
99
import com.badlogic.gdx.utils.viewport.StretchViewport
10-
import jake2.qcommon.*
10+
import jake2.qcommon.Com
11+
import jake2.qcommon.Defines
1112
import jake2.qcommon.Defines.*
13+
import jake2.qcommon.Globals
1214
import jake2.qcommon.exec.Cbuf
1315
import jake2.qcommon.exec.Cmd
1416
import jake2.qcommon.exec.Cmd.getArguments
@@ -74,49 +76,7 @@ class Cake : KtxApplicationAdapter, KtxInputAdapter {
7476
// and put into the console when it's ready
7577
consoleStage = ConsoleStage(viewport)
7678

77-
Gdx.input.inputProcessor = InputMultiplexer(
78-
this, // global input processor to control console and menu
79-
consoleStage,
80-
menuStage,
81-
// delegate the rest to the current 3d screen
82-
object: InputProcessor {
83-
override fun keyDown(keycode: Int): Boolean {
84-
return game3dScreen?.keyDown(keycode) ?: false
85-
}
86-
87-
override fun keyUp(keycode: Int): Boolean {
88-
return game3dScreen?.keyUp(keycode) ?: false
89-
}
90-
91-
override fun keyTyped(character: Char): Boolean {
92-
return game3dScreen?.keyTyped(character) ?: false
93-
}
94-
95-
override fun touchDown(screenX: Int, screenY: Int, pointer: Int, button: Int): Boolean {
96-
return game3dScreen?.touchDown(screenX, screenY, pointer, button) ?: false
97-
}
98-
99-
override fun touchUp(screenX: Int, screenY: Int, pointer: Int, button: Int): Boolean {
100-
return game3dScreen?.touchUp(screenX, screenY, pointer, button) ?: false
101-
}
102-
103-
override fun touchCancelled(screenX: Int, screenY: Int, pointer: Int, button: Int): Boolean {
104-
return game3dScreen?.touchCancelled(screenX, screenY, pointer, button) ?: false
105-
}
106-
107-
override fun touchDragged(screenX: Int, screenY: Int, pointer: Int): Boolean {
108-
return game3dScreen?.touchDragged(screenX, screenY, pointer) ?: false
109-
}
110-
111-
override fun mouseMoved(screenX: Int, screenY: Int): Boolean {
112-
return game3dScreen?.mouseMoved(screenX, screenY) ?: false
113-
}
114-
115-
override fun scrolled(amountX: Float, amountY: Float): Boolean {
116-
return game3dScreen?.scrolled(amountX, amountY) ?: false
117-
}
118-
}
119-
)
79+
updateInputHandlers(false, true, false)
12080

12181

12282
Cmd.AddCommand("quit") {
@@ -191,6 +151,62 @@ class Cake : KtxApplicationAdapter, KtxInputAdapter {
191151
}
192152
}
193153

154+
private fun updateInputHandlers(console: Boolean, menu: Boolean, game: Boolean) {
155+
val handlers = ArrayList<InputProcessor>()
156+
if (console) {
157+
handlers.add(consoleStage)
158+
}
159+
if (menu) {
160+
handlers.add(menuStage)
161+
}
162+
// delegate the rest to the current 3d screen
163+
if (game) {
164+
handlers.add(
165+
object : InputProcessor {
166+
override fun keyDown(keycode: Int): Boolean {
167+
return game3dScreen?.keyDown(keycode) ?: false
168+
}
169+
170+
override fun keyUp(keycode: Int): Boolean {
171+
return game3dScreen?.keyUp(keycode) ?: false
172+
}
173+
174+
override fun keyTyped(character: Char): Boolean {
175+
return game3dScreen?.keyTyped(character) ?: false
176+
}
177+
178+
override fun touchDown(screenX: Int, screenY: Int, pointer: Int, button: Int): Boolean {
179+
return game3dScreen?.touchDown(screenX, screenY, pointer, button) ?: false
180+
}
181+
182+
override fun touchUp(screenX: Int, screenY: Int, pointer: Int, button: Int): Boolean {
183+
return game3dScreen?.touchUp(screenX, screenY, pointer, button) ?: false
184+
}
185+
186+
override fun touchCancelled(screenX: Int, screenY: Int, pointer: Int, button: Int): Boolean {
187+
return game3dScreen?.touchCancelled(screenX, screenY, pointer, button) ?: false
188+
}
189+
190+
override fun touchDragged(screenX: Int, screenY: Int, pointer: Int): Boolean {
191+
return game3dScreen?.touchDragged(screenX, screenY, pointer) ?: false
192+
}
193+
194+
override fun mouseMoved(screenX: Int, screenY: Int): Boolean {
195+
return game3dScreen?.mouseMoved(screenX, screenY) ?: false
196+
}
197+
198+
override fun scrolled(amountX: Float, amountY: Float): Boolean {
199+
return game3dScreen?.scrolled(amountX, amountY) ?: false
200+
}
201+
}
202+
)
203+
}
204+
Gdx.input.inputProcessor = InputMultiplexer(
205+
this, // global input processor to control console and menu
206+
*handlers.toTypedArray()
207+
)
208+
}
209+
194210
override fun render() {
195211
val deltaSeconds = Gdx.graphics.deltaTime
196212
Globals.curtime += (deltaSeconds * 1000f).toInt() // todo: get rid of globals!
@@ -252,15 +268,15 @@ class Cake : KtxApplicationAdapter, KtxInputAdapter {
252268
if (consoleVisible) {
253269
consoleStage.focus()
254270
}
255-
return true
256271
}
257272
Input.Keys.ESCAPE -> {
258273
consoleVisible = false
259274
menuVisible = !menuVisible
260-
return true
261275
}
262276
else -> return false
263277
}
278+
updateInputHandlers(consoleVisible, menuVisible, game3dScreen != null)
279+
return true
264280
}
265281

266282
override fun dispose() {

cake/core/src/main/kotlin/org/demoth/cake/modelviewer/BspLoader.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ class BspLoader(val gameDir: String) {
3636
instance
3737
}
3838
*/
39+
TODO()
3940
}
4041

4142
fun loadBspModels(file: File): List<Model> {

0 commit comments

Comments
 (0)