@@ -7,8 +7,10 @@ import com.badlogic.gdx.InputProcessor
7
7
import com.badlogic.gdx.scenes.scene2d.ui.Skin
8
8
import com.badlogic.gdx.utils.ScreenUtils
9
9
import com.badlogic.gdx.utils.viewport.StretchViewport
10
- import jake2.qcommon.*
10
+ import jake2.qcommon.Com
11
+ import jake2.qcommon.Defines
11
12
import jake2.qcommon.Defines.*
13
+ import jake2.qcommon.Globals
12
14
import jake2.qcommon.exec.Cbuf
13
15
import jake2.qcommon.exec.Cmd
14
16
import jake2.qcommon.exec.Cmd.getArguments
@@ -74,49 +76,7 @@ class Cake : KtxApplicationAdapter, KtxInputAdapter {
74
76
// and put into the console when it's ready
75
77
consoleStage = ConsoleStage (viewport)
76
78
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 )
120
80
121
81
122
82
Cmd .AddCommand (" quit" ) {
@@ -191,6 +151,62 @@ class Cake : KtxApplicationAdapter, KtxInputAdapter {
191
151
}
192
152
}
193
153
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
+
194
210
override fun render () {
195
211
val deltaSeconds = Gdx .graphics.deltaTime
196
212
Globals .curtime + = (deltaSeconds * 1000f ).toInt() // todo: get rid of globals!
@@ -252,15 +268,15 @@ class Cake : KtxApplicationAdapter, KtxInputAdapter {
252
268
if (consoleVisible) {
253
269
consoleStage.focus()
254
270
}
255
- return true
256
271
}
257
272
Input .Keys .ESCAPE -> {
258
273
consoleVisible = false
259
274
menuVisible = ! menuVisible
260
- return true
261
275
}
262
276
else -> return false
263
277
}
278
+ updateInputHandlers(consoleVisible, menuVisible, game3dScreen != null )
279
+ return true
264
280
}
265
281
266
282
override fun dispose () {
0 commit comments