Rev 5000 | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
4386 | terminx | 1 | /* |
2 | * |
||
3 | * Designed by Emile Belanger |
||
4 | * |
||
5 | */ |
||
6 | |||
7 | #include <stdlib.h> |
||
8 | #include <stdio.h> |
||
9 | #include <string.h> |
||
10 | #include <jni.h> |
||
11 | #include <android/log.h> |
||
12 | |||
13 | #include "SDL_scancode.h" |
||
4434 | terminx | 14 | #include "SDL_main.h" |
4386 | terminx | 15 | |
16 | #include "TouchControlsContainer.h" |
||
4434 | terminx | 17 | #include "JNITouchControlsUtils.h" |
18 | |||
4440 | terminx | 19 | #ifdef GP_LIC |
20 | #include "s-setup/s-setup.h" |
||
21 | #endif |
||
22 | |||
4989 | terminx | 23 | extern "C" { |
4529 | terminx | 24 | #define DEFAULT_FADE_FRAMES 10 |
25 | |||
4989 | terminx | 26 | extern void SDL_Android_Init(JNIEnv *env, jclass cls); |
27 | extern char const *G_GetStringFromSavegame(const char *filename, int type); |
||
28 | extern int32_t G_GetScreenshotFromSavegame(const char *filename, char *pal, char *data); |
||
29 | |||
4386 | terminx | 30 | #include "in_android.h" |
4433 | terminx | 31 | #include "../function.h" |
4386 | terminx | 32 | |
33 | #include "../GL/gl.h" |
||
34 | |||
4989 | terminx | 35 | // Copied from build.h, which didnt include here |
36 | enum rendmode_t |
||
37 | { |
||
4440 | terminx | 38 | REND_CLASSIC, |
39 | REND_POLYMOST = 3, |
||
40 | REND_POLYMER |
||
41 | }; |
||
42 | |||
4989 | terminx | 43 | enum dukeinv_t |
44 | { |
||
45 | GET_STEROIDS, // 0 |
||
46 | GET_SHIELD, |
||
47 | GET_SCUBA, |
||
48 | GET_HOLODUKE, |
||
49 | GET_JETPACK, |
||
50 | GET_DUMMY1, // 5 |
||
51 | GET_ACCESS, |
||
52 | GET_HEATS, |
||
53 | GET_DUMMY2, |
||
54 | GET_FIRSTAID, |
||
55 | GET_BOOTS, // 10 |
||
56 | GET_MAX |
||
57 | }; |
||
58 | |||
59 | |||
4386 | terminx | 60 | #ifndef LOGI |
4989 | terminx | 61 | #define LOGI(...) ((void)__android_log_print(ANDROID_LOG_INFO, "DUKE", __VA_ARGS__)) |
4386 | terminx | 62 | #define LOGW(...) ((void)__android_log_print(ANDROID_LOG_WARN, "DUKE", __VA_ARGS__)) |
4989 | terminx | 63 | #define LOGE(...) ((void)__android_log_print(ANDROID_LOG_ERROR, "DUKE", __VA_ARGS__)) |
4386 | terminx | 64 | #endif |
65 | |||
4989 | terminx | 66 | #define REND_SOFT 0 |
67 | #define REND_GL 1 |
||
4386 | terminx | 68 | |
4436 | terminx | 69 | droidsysinfo_t droidinfo; |
70 | |||
4386 | terminx | 71 | static int curRenderer; |
72 | |||
4693 | terminx | 73 | static bool hideTouchControls = true; |
74 | static int weaponWheelVisible = false; |
||
75 | |||
76 | |||
4386 | terminx | 77 | static int controlsCreated = 0; |
78 | touchcontrols::TouchControlsContainer controlsContainer; |
||
79 | |||
5066 | terminx | 80 | touchcontrols::TouchControls *tcBlankTap; |
81 | touchcontrols::TouchControls *tcYesNo; |
||
82 | touchcontrols::TouchControls *tcMenuMain; |
||
83 | touchcontrols::TouchControls *tcGameMain; |
||
84 | touchcontrols::TouchControls *tcGameWeapons; |
||
85 | // touchcontrols::TouchControls *tcInventory; |
||
86 | touchcontrols::TouchControls *tcAutomap; |
||
4386 | terminx | 87 | |
88 | |||
89 | touchcontrols::TouchJoy *touchJoyLeft; |
||
90 | touchcontrols::WheelSelect *weaponWheel; |
||
91 | |||
4989 | terminx | 92 | extern JNIEnv *env_; |
93 | JavaVM *jvm_; |
||
4386 | terminx | 94 | |
4989 | terminx | 95 | touchcontrols::Button *inv_buttons[GET_MAX]; |
96 | |||
5066 | terminx | 97 | std::string obbPath, gamePath; |
5000 | terminx | 98 | |
4386 | terminx | 99 | void openGLStart() |
100 | { |
||
4434 | terminx | 101 | if (curRenderer == REND_GL) |
102 | { |
||
103 | glPushMatrix(); |
||
4386 | terminx | 104 | |
4434 | terminx | 105 | glMatrixMode(GL_PROJECTION); |
106 | glLoadIdentity(); |
||
4989 | terminx | 107 | glOrthof(0, droidinfo.screen_width, droidinfo.screen_height, 0, 0, 1); |
4386 | terminx | 108 | |
4989 | terminx | 109 | // glClearColor(1.0f, 1.0f, 0.0f, 1.0f); |
110 | // glClear(GL_COLOR_BUFFER_BIT); |
||
111 | // LOGI("openGLStart"); |
||
4434 | terminx | 112 | glDisable(GL_ALPHA_TEST); |
113 | glDisable(GL_DEPTH_TEST); |
||
114 | glDisable(GL_FOG); |
||
115 | glEnable(GL_TEXTURE_2D); |
||
4989 | terminx | 116 | glEnable(GL_BLEND); |
4386 | terminx | 117 | |
4989 | terminx | 118 | glColor4f(1, 1, 1, 1); |
4386 | terminx | 119 | |
4434 | terminx | 120 | glDisableClientState(GL_COLOR_ARRAY); |
121 | glEnableClientState(GL_VERTEX_ARRAY); |
||
4989 | terminx | 122 | glEnableClientState(GL_TEXTURE_COORD_ARRAY); |
4386 | terminx | 123 | |
4434 | terminx | 124 | glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); |
4386 | terminx | 125 | |
4434 | terminx | 126 | glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); |
4386 | terminx | 127 | |
4434 | terminx | 128 | glDisable(GL_CULL_FACE); |
4386 | terminx | 129 | |
4434 | terminx | 130 | glMatrixMode(GL_MODELVIEW); |
4386 | terminx | 131 | |
4989 | terminx | 132 | // nanoPushState(); |
4434 | terminx | 133 | } |
4989 | terminx | 134 | /* |
135 | else // software mode |
||
4434 | terminx | 136 | { |
137 | glDisable(GL_ALPHA_TEST); |
||
138 | glDisableClientState(GL_COLOR_ARRAY); |
||
139 | glEnableClientState(GL_VERTEX_ARRAY); |
||
4989 | terminx | 140 | glEnableClientState(GL_TEXTURE_COORD_ARRAY); |
4434 | terminx | 141 | glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); |
4989 | terminx | 142 | glEnable(GL_BLEND); |
4434 | terminx | 143 | glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); |
144 | glEnable(GL_TEXTURE_2D); |
||
145 | glDisable(GL_CULL_FACE); |
||
146 | glMatrixMode(GL_MODELVIEW); |
||
147 | } |
||
4989 | terminx | 148 | */ |
4386 | terminx | 149 | } |
150 | |||
151 | void openGLEnd() |
||
152 | { |
||
4434 | terminx | 153 | if (curRenderer == REND_GL) |
154 | { |
||
4989 | terminx | 155 | // glPopMatrix(); |
156 | // nanoPopState(); |
||
4434 | terminx | 157 | glPopMatrix(); |
158 | } |
||
4989 | terminx | 159 | /* |
160 | else // Software mode |
||
4434 | terminx | 161 | { |
162 | glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE); |
||
163 | glMatrixMode(GL_MODELVIEW); |
||
164 | } |
||
4989 | terminx | 165 | */ |
4386 | terminx | 166 | } |
167 | |||
168 | void gameSettingsButton(int state) |
||
169 | { |
||
4434 | terminx | 170 | if (state == 1) |
171 | { |
||
172 | showTouchSettings(); |
||
173 | } |
||
4386 | terminx | 174 | } |
175 | |||
4989 | terminx | 176 | // Because there is no Frame(), we need to check back to java each frame to see if the app hase paused |
4386 | terminx | 177 | |
4989 | terminx | 178 | /* |
4386 | terminx | 179 | static jclass NativeLibClass = 0; |
180 | static jmethodID checkPauseMethod = 0; |
||
4434 | terminx | 181 | |
4386 | terminx | 182 | void swapBuffers() |
183 | { |
||
4434 | terminx | 184 | if (NativeLibClass == 0) |
185 | { |
||
4989 | terminx | 186 | NativeLibClass = env_->FindClass("com/voidpoint/duke3d/engine/NativeLib"); |
4434 | terminx | 187 | checkPauseMethod = env_->GetStaticMethodID(NativeLibClass, "swapBuffers", "()V"); |
188 | } |
||
189 | env_->CallStaticVoidMethod(NativeLibClass, checkPauseMethod); |
||
4386 | terminx | 190 | } |
4989 | terminx | 191 | */ |
4386 | terminx | 192 | |
4989 | terminx | 193 | // This is a bit of a hack, if the weapon wheel was selected, then an inv chosen instead, we need to cancel the weapon |
194 | // selection |
||
195 | // NOT needed actually, weapon wheel disabled before is get finger up anyway |
||
196 | // static bool invWasSelected = false; |
||
4693 | terminx | 197 | |
198 | void showWeaponsInventory(bool show) |
||
199 | { |
||
200 | if (show) |
||
201 | { |
||
4989 | terminx | 202 | for (int n = 0; n < 10; n++) |
4693 | terminx | 203 | weaponWheel->setSegmentEnabled(n, (PortableRead(READ_WEAPONS) >> n) & 0x1); |
204 | |||
4989 | terminx | 205 | // Show inventory buttons |
4693 | terminx | 206 | tcGameWeapons->setAllButtonsEnable(true); |
207 | |||
4989 | terminx | 208 | tcGameWeapons->fade(touchcontrols::FADE_IN, 5); // fade in |
4693 | terminx | 209 | weaponWheelVisible = true; |
210 | } |
||
4989 | terminx | 211 | else // hide |
4693 | terminx | 212 | { |
213 | tcGameWeapons->setAllButtonsEnable(false); |
||
214 | weaponWheel->setTapMode(false); |
||
215 | weaponWheelVisible = false; |
||
216 | } |
||
217 | } |
||
218 | |||
4433 | terminx | 219 | void gameButton(int state, int code) |
4386 | terminx | 220 | { |
4433 | terminx | 221 | switch (code) |
222 | { |
||
4989 | terminx | 223 | case gamefunc_Fire: |
224 | if (state && PortableRead(READ_SOMETHINGONPLAYER)) |
||
225 | { |
||
226 | PortableAction(1, gamefunc_Quick_Kick); |
||
227 | PortableAction(0, gamefunc_Quick_Kick); |
||
228 | } |
||
229 | else PortableAction(state, code); |
||
230 | break; |
||
4386 | terminx | 231 | |
4989 | terminx | 232 | case KEY_SHOW_KBRD: |
233 | if (state) |
||
234 | toggleKeyboard(); |
||
4433 | terminx | 235 | |
4989 | terminx | 236 | PortableKeyEvent(state, SDL_SCANCODE_GRAVE, 0); |
237 | break; |
||
4433 | terminx | 238 | |
4989 | terminx | 239 | case KEY_QUICK_CMD: |
240 | if (state == 1) |
||
241 | showCustomCommands(); |
||
242 | break; |
||
4433 | terminx | 243 | |
4989 | terminx | 244 | case KEY_SHOW_INVEN: |
245 | if (state) |
||
4693 | terminx | 246 | { |
4989 | terminx | 247 | if (!weaponWheelVisible) |
248 | { |
||
249 | weaponWheel->setTapMode(true); |
||
250 | showWeaponsInventory(true); |
||
251 | } |
||
252 | else |
||
253 | showWeaponsInventory(false); |
||
4693 | terminx | 254 | } |
4989 | terminx | 255 | break; |
4433 | terminx | 256 | |
4989 | terminx | 257 | case KEY_QUICK_SAVE: |
258 | LOGI("QUICK SAVE"); |
||
259 | PortableKeyEvent(state, SDL_SCANCODE_F6, 0); |
||
260 | break; |
||
4433 | terminx | 261 | |
4989 | terminx | 262 | case KEY_QUICK_LOAD: |
263 | LOGI("QUICK LOAD"); |
||
264 | PortableKeyEvent(state, SDL_SCANCODE_F9, 0); |
||
265 | break; |
||
4433 | terminx | 266 | |
4989 | terminx | 267 | default: PortableAction(state, code); break; |
4433 | terminx | 268 | } |
4386 | terminx | 269 | } |
270 | |||
4989 | terminx | 271 | void automapButton(int state, int code) { PortableAction(state, code); } |
4386 | terminx | 272 | |
4989 | terminx | 273 | void inventoryButton(int state, int code) |
4386 | terminx | 274 | { |
4989 | terminx | 275 | PortableAction(state, code); |
4434 | terminx | 276 | if (state == 0) |
277 | { |
||
4989 | terminx | 278 | // Inventory chosen, hide them and wheel |
4693 | terminx | 279 | showWeaponsInventory(false); |
4434 | terminx | 280 | } |
4386 | terminx | 281 | } |
282 | |||
4989 | terminx | 283 | void menuButton(int state, int code) { PortableKeyEvent(state, code, code); } |
284 | |||
285 | void menuMouse(int action, float x, float y, float dx, float dy) |
||
4386 | terminx | 286 | { |
4989 | terminx | 287 | // PortableMouse(dx,dy); |
288 | PortableMouseMenu(x * droidinfo.screen_width, y * droidinfo.screen_height); |
||
289 | |||
290 | if (action == MULTITOUCHMOUSE_DOWN || action == MULTITOUCHMOUSE_UP) |
||
291 | PortableMouseMenuButton(action == MULTITOUCHMOUSE_DOWN, 0); |
||
4386 | terminx | 292 | } |
293 | |||
4989 | terminx | 294 | void blankTapButton(int state, int code) |
4386 | terminx | 295 | { |
4989 | terminx | 296 | if (PortableRead(READ_IS_DEAD)) // if the player is dead we need to send a 'open' button |
4433 | terminx | 297 | { |
4693 | terminx | 298 | if (state) |
4529 | terminx | 299 | { |
4693 | terminx | 300 | PortableAction(1, gamefunc_Open); |
301 | PortableAction(0, gamefunc_Open); |
||
4529 | terminx | 302 | } |
303 | } |
||
4989 | terminx | 304 | else // everything else send a return key |
305 | PortableKeyEvent(state, SDL_SCANCODE_RETURN, 0); |
||
4693 | terminx | 306 | } |
307 | |||
4989 | terminx | 308 | void weaponWheelSelected(int enabled) { showWeaponsInventory(enabled ? true : false); } |
4433 | terminx | 309 | |
4386 | terminx | 310 | void weaponWheelChosen(int segment) |
311 | { |
||
4989 | terminx | 312 | // LOGI("weaponWheel %d",segment); |
313 | if (segment == -1 && droidinput.quickSelectWeapon) |
||
314 | segment = PortableRead(READ_LASTWEAPON); |
||
4433 | terminx | 315 | |
4989 | terminx | 316 | if (segment != -1) |
4693 | terminx | 317 | PortableAction(2, gamefunc_Weapon_1 + segment); |
4386 | terminx | 318 | } |
319 | |||
320 | void left_double_tap(int state) |
||
321 | { |
||
4989 | terminx | 322 | // LOGI("L double %d, droidinput.left_double_action = %d",state,droidinput.left_double_action); |
4439 | terminx | 323 | if (droidinput.left_double_action != -1) |
324 | PortableAction(state, droidinput.left_double_action); |
||
4386 | terminx | 325 | } |
326 | |||
327 | void right_double_tap(int state) |
||
328 | { |
||
4989 | terminx | 329 | // LOGTOUCH("R double %d",state); |
4439 | terminx | 330 | if (droidinput.right_double_action != -1) |
331 | PortableAction(state, droidinput.right_double_action); |
||
4386 | terminx | 332 | } |
333 | |||
4434 | terminx | 334 | void mouseMove(int action, float x, float y, float dx, float dy) |
4386 | terminx | 335 | { |
4989 | terminx | 336 | // LOGI(" mouse dx = %f, dy = %f",dx,dy); |
4434 | terminx | 337 | if (weaponWheelVisible) |
338 | return; |
||
339 | |||
4989 | terminx | 340 | float const scale = .1f; |
4434 | terminx | 341 | |
4989 | terminx | 342 | PortableLook(dx * droidinput.yaw_sens * scale, -dy * droidinput.pitch_sens * scale * (droidinput.invertLook ? -1.f : 1.f)); |
4386 | terminx | 343 | } |
344 | |||
4989 | terminx | 345 | void automap_multitouch_mouse_move(int action, float x, float y, float dx, float dy) |
4693 | terminx | 346 | { |
347 | if (action == MULTITOUCHMOUSE_MOVE) |
||
4989 | terminx | 348 | PortableAutomapControl(0, dx, dy); |
4693 | terminx | 349 | else if (action == MULTITOUCHMOUSE_ZOOM) |
4989 | terminx | 350 | PortableAutomapControl(x, 0, 0); |
4693 | terminx | 351 | } |
352 | |||
4434 | terminx | 353 | void left_stick(float joy_x, float joy_y, float mouse_x, float mouse_y) |
4386 | terminx | 354 | { |
4989 | terminx | 355 | // LOGI("left_stick joy_x = %f, joy_y = %f",joy_x,joy_y); |
356 | PortableMove(joy_y * droidinput.forward_sens, -joy_x * droidinput.strafe_sens); |
||
4386 | terminx | 357 | } |
358 | |||
4989 | terminx | 359 | /* |
4434 | terminx | 360 | void right_stick(float joy_x, float joy_y, float mouse_x, float mouse_y) |
4386 | terminx | 361 | { |
4434 | terminx | 362 | mouseMove(0, joy_x, joy_y, mouse_x, mouse_y); |
4386 | terminx | 363 | } |
4989 | terminx | 364 | */ |
4386 | terminx | 365 | |
366 | void setHideSticks(bool v) |
||
367 | { |
||
4989 | terminx | 368 | if (touchJoyLeft) |
369 | touchJoyLeft->setHideGraphics(v); |
||
4386 | terminx | 370 | } |
371 | |||
372 | void touchSettingsButton(int state) |
||
373 | { |
||
4529 | terminx | 374 | /* |
4433 | terminx | 375 | int32_t paused = PortableRead(READ_PAUSED); |
376 | |||
4434 | terminx | 377 | //We wanna pause the game when doing settings |
378 | if (state && !paused || !state && paused) |
||
379 | { |
||
4436 | terminx | 380 | PortableKeyEvent(2, SDL_SCANCODE_PAUSE, 0); |
4434 | terminx | 381 | } |
4529 | terminx | 382 | */ |
4386 | terminx | 383 | } |
384 | |||
5000 | terminx | 385 | void initControls(int width, int height, const char *graphics_path) |
4386 | terminx | 386 | { |
4434 | terminx | 387 | touchcontrols::GLScaleWidth = (float)width; |
5000 | terminx | 388 | touchcontrols::GLScaleHeight = (float)-height; |
4386 | terminx | 389 | |
5000 | terminx | 390 | LOGI("initControls %d x %d,x path = %s", width, height, graphics_path); |
4386 | terminx | 391 | |
4434 | terminx | 392 | if (!controlsCreated) |
393 | { |
||
394 | LOGI("creating controls"); |
||
4386 | terminx | 395 | |
4434 | terminx | 396 | touchcontrols::setGraphicsBasePath(graphics_path); |
4386 | terminx | 397 | |
4989 | terminx | 398 | controlsContainer.openGL_start.connect(sigc::ptr_fun(&openGLStart)); |
399 | controlsContainer.openGL_end.connect(sigc::ptr_fun(&openGLEnd)); |
||
400 | controlsContainer.signal_settings.connect(sigc::ptr_fun(&touchSettingsButton)); |
||
4386 | terminx | 401 | |
4989 | terminx | 402 | tcBlankTap = new touchcontrols::TouchControls("blank_tap", false, false); |
403 | tcYesNo = new touchcontrols::TouchControls("yes_no", false, false); |
||
404 | tcMenuMain = new touchcontrols::TouchControls("menu", false, false); |
||
405 | tcGameMain = new touchcontrols::TouchControls("game", false, true, 1, true); |
||
406 | tcGameWeapons = new touchcontrols::TouchControls("weapons", false, true, 1, false); |
||
407 | tcAutomap = new touchcontrols::TouchControls("automap", false, false); |
||
4693 | terminx | 408 | // tcInventory = new touchcontrols::TouchControls("inventory", false,true,1,false); |
4386 | terminx | 409 | |
4529 | terminx | 410 | ///////////////////////// BLANK TAP SCREEN ////////////////////// |
4386 | terminx | 411 | |
4989 | terminx | 412 | // One button on whole screen with no graphic, send a return key |
413 | tcBlankTap->addControl(new touchcontrols::Button("whole_screen", touchcontrols::RectF(0, 0, 26, 16), |
||
414 | "" /*std::string("test")*/, SDL_SCANCODE_RETURN)); |
||
415 | tcBlankTap->signal_button.connect(sigc::ptr_fun(&blankTapButton)); // Just reuse the menuButton function |
||
4386 | terminx | 416 | |
4529 | terminx | 417 | |
418 | ///////////////////////// YES NO SCREEN ///////////////////// |
||
419 | |||
4989 | terminx | 420 | tcYesNo->addControl( |
5000 | terminx | 421 | new touchcontrols::Button("enter", touchcontrols::RectF(16, 9, 18, 11), "yes", SDL_SCANCODE_RETURN)); |
4989 | terminx | 422 | tcYesNo->addControl( |
5000 | terminx | 423 | new touchcontrols::Button("esc", touchcontrols::RectF(8, 9, 10, 11), "no", SDL_SCANCODE_ESCAPE)); |
4989 | terminx | 424 | tcYesNo->signal_button.connect(sigc::ptr_fun(&menuButton)); // Just reuse the menuButton function |
4529 | terminx | 425 | |
426 | |||
427 | ///////////////////////// MAIN MENU SCREEN ///////////////////// |
||
428 | |||
4989 | terminx | 429 | /* |
430 | tcMenuMain->addControl(new touchcontrols::Button("down_arrow", touchcontrols::RectF(22,14,24,16), |
||
431 | "arrow_down", SDL_SCANCODE_DOWN, true)); //Repeating buttons |
||
432 | tcMenuMain->addControl(new touchcontrols::Button("up_arrow", touchcontrols::RectF(22,12,24,14), "arrow_up", |
||
433 | SDL_SCANCODE_UP, true)); |
||
434 | tcMenuMain->addControl(new touchcontrols::Button("left_arrow", touchcontrols::RectF(20,14,22,16), |
||
435 | "arrow_left", SDL_SCANCODE_LEFT, true)); |
||
436 | tcMenuMain->addControl(new touchcontrols::Button("right_arrow", touchcontrols::RectF(24,14,26,16), |
||
437 | "arrow_right", SDL_SCANCODE_RIGHT, true)); |
||
438 | tcMenuMain->addControl(new touchcontrols::Button("enter", touchcontrols::RectF(0,14,2,16), "enter", |
||
439 | SDL_SCANCODE_RETURN)); |
||
440 | tcMenuMain->setAlpha(1); |
||
4693 | terminx | 441 | */ |
4386 | terminx | 442 | |
5000 | terminx | 443 | tcMenuMain->addControl(new touchcontrols::Button("arrow_left", touchcontrols::RectF(0, 2, 2, 4), "arrow_left", |
444 | SDL_SCANCODE_ESCAPE)); |
||
445 | tcMenuMain->signal_button.connect(sigc::ptr_fun(&menuButton)); |
||
446 | |||
4989 | terminx | 447 | touchcontrols::MultitouchMouse *mouseMenu = |
448 | new touchcontrols::MultitouchMouse("mouse", touchcontrols::RectF(0, 0, 26, 16), ""); |
||
449 | mouseMenu->setHideGraphics(true); |
||
450 | tcMenuMain->addControl(mouseMenu); |
||
451 | mouseMenu->signal_action.connect(sigc::ptr_fun(&menuMouse)); |
||
4386 | terminx | 452 | |
4989 | terminx | 453 | touchcontrols::Button *console_button = new touchcontrols::Button( |
454 | "keyboard", "Development console", touchcontrols::RectF(8, 0, 10, 2), "keyboard", KEY_SHOW_KBRD, false, true); |
||
4693 | terminx | 455 | |
4989 | terminx | 456 | tcMenuMain->addControl(console_button); |
4693 | terminx | 457 | |
4529 | terminx | 458 | //////////////////////////// GAME SCREEN ///////////////////// |
4989 | terminx | 459 | tcGameMain->setAlpha(droidinput.gameControlsAlpha); |
460 | controlsContainer.editButtonAlpha = droidinput.gameControlsAlpha; |
||
5000 | terminx | 461 | |
4989 | terminx | 462 | tcGameMain->addControl( |
5000 | terminx | 463 | new touchcontrols::Button("game_menu", touchcontrols::RectF(0, 0, 2, 2), "settings_bars", MENU_BACK)); |
464 | |||
465 | tcGameMain->addControl( |
||
4989 | terminx | 466 | new touchcontrols::Button("use", touchcontrols::RectF(20, 4, 23, 7), "use", gamefunc_Open)); |
467 | tcGameMain->addControl( |
||
468 | new touchcontrols::Button("attack", touchcontrols::RectF(20, 7, 23, 10), "fire2", gamefunc_Fire)); |
||
469 | tcGameMain->addControl( |
||
470 | new touchcontrols::Button("jump", touchcontrols::RectF(23, 6, 26, 9), "jump", gamefunc_Jump)); |
||
471 | tcGameMain->addControl( |
||
472 | new touchcontrols::Button("crouch", touchcontrols::RectF(24, 12, 26, 14), "crouch", gamefunc_Crouch)); |
||
473 | tcGameMain->addControl(new touchcontrols::Button("kick", "Mighty Foot", touchcontrols::RectF(23, 3, 26, 6), |
||
474 | "boot", gamefunc_Quick_Kick, false, true)); |
||
4386 | terminx | 475 | |
4989 | terminx | 476 | touchcontrols::Button *map_button = new touchcontrols::Button( |
477 | "map", "Overhead map", touchcontrols::RectF(6, 0, 8, 2), "map", gamefunc_Map, false, true); |
||
4693 | terminx | 478 | tcGameMain->addControl(map_button); |
4989 | terminx | 479 | tcGameMain->addControl(new touchcontrols::Button("show_inventory", "Inventory", |
480 | touchcontrols::RectF(24, 0, 26, 2), "inv", KEY_SHOW_INVEN)); |
||
481 | tcGameMain->addControl(new touchcontrols::Button("next_weapon", "Next weapon", touchcontrols::RectF(0, 3, 3, 5), |
||
482 | "next_weap", gamefunc_Next_Weapon, false, true)); |
||
483 | tcGameMain->addControl(new touchcontrols::Button("prev_weapon", "Previous weapon", |
||
484 | touchcontrols::RectF(0, 5, 3, 7), "prev_weap", |
||
485 | gamefunc_Previous_Weapon, false, true)); |
||
486 | tcGameMain->addControl(new touchcontrols::Button("quick_save", "Save game", touchcontrols::RectF(22, 0, 24, 2), |
||
487 | "save", KEY_QUICK_SAVE, false, true)); |
||
488 | tcGameMain->addControl(new touchcontrols::Button("quick_load", "Load game", touchcontrols::RectF(20, 0, 22, 2), |
||
489 | "load", KEY_QUICK_LOAD, false, true)); |
||
4386 | terminx | 490 | |
4989 | terminx | 491 | tcGameMain->addControl(console_button); |
4434 | terminx | 492 | /* |
4989 | terminx | 493 | //quick actions binds |
494 | tcGameMain->addControl(new |
||
495 | touchcontrols::Button("quick_key_1",touchcontrols::RectF(4,3,6,5),"quick_key_1",KEY_QUICK_KEY1,false,true)); |
||
496 | tcGameMain->addControl(new |
||
497 | touchcontrols::Button("quick_key_2",touchcontrols::RectF(6,3,8,5),"quick_key_2",KEY_QUICK_KEY2,false,true)); |
||
498 | tcGameMain->addControl(new |
||
499 | touchcontrols::Button("quick_key_3",touchcontrols::RectF(8,3,10,5),"quick_key_3",KEY_QUICK_KEY3,false,true)); |
||
500 | tcGameMain->addControl(new |
||
501 | touchcontrols::Button("quick_key_4",touchcontrols::RectF(10,3,12,5),"quick_key_4",KEY_QUICK_KEY4,false,true)); |
||
4529 | terminx | 502 | */ |
4989 | terminx | 503 | // Left stick |
504 | touchJoyLeft = new touchcontrols::TouchJoy("stick", touchcontrols::RectF(0, 7, 8, 16), "strafe_arrow"); |
||
4434 | terminx | 505 | tcGameMain->addControl(touchJoyLeft); |
4989 | terminx | 506 | touchJoyLeft->signal_move.connect(sigc::ptr_fun(&left_stick)); |
507 | touchJoyLeft->signal_double_tap.connect(sigc::ptr_fun(&left_double_tap)); |
||
4386 | terminx | 508 | |
4989 | terminx | 509 | // Right stick (not used) |
510 | // touchJoyRight = new touchcontrols::TouchJoy("touch",touchcontrols::RectF(17,7,26,16),"look_arrow"); |
||
511 | // tcGameMain->addControl(touchJoyRight); |
||
512 | // touchJoyRight->signal_move.connect(sigc::ptr_fun(&right_stick) ); |
||
513 | // touchJoyRight->signal_double_tap.connect(sigc::ptr_fun(&right_double_tap) ); |
||
514 | // touchJoyRight->setEnabled(false); |
||
4386 | terminx | 515 | |
516 | |||
4989 | terminx | 517 | // Mouse look for whole screen |
518 | touchcontrols::Mouse *mouse = new touchcontrols::Mouse("mouse", touchcontrols::RectF(3, 0, 26, 16), ""); |
||
4434 | terminx | 519 | mouse->signal_action.connect(sigc::ptr_fun(&mouseMove)); |
4989 | terminx | 520 | mouse->signal_double_tap.connect(sigc::ptr_fun(&right_double_tap)); |
4386 | terminx | 521 | |
4434 | terminx | 522 | mouse->setHideGraphics(true); |
523 | tcGameMain->addControl(mouse); |
||
4386 | terminx | 524 | |
4989 | terminx | 525 | tcGameMain->signal_button.connect(sigc::ptr_fun(&gameButton)); |
526 | tcGameMain->signal_settingsButton.connect(sigc::ptr_fun(&gameSettingsButton)); |
||
4386 | terminx | 527 | |
4693 | terminx | 528 | ///////////////////////// AUTO MAP SCREEN /////////////////////// |
4386 | terminx | 529 | |
4693 | terminx | 530 | |
4989 | terminx | 531 | // Automap |
532 | touchcontrols::MultitouchMouse *multimouse = |
||
533 | new touchcontrols::MultitouchMouse("gamemouse", touchcontrols::RectF(0, 0, 26, 16), ""); |
||
4693 | terminx | 534 | multimouse->setHideGraphics(true); |
535 | tcAutomap->addControl(multimouse); |
||
4989 | terminx | 536 | multimouse->signal_action.connect(sigc::ptr_fun(&automap_multitouch_mouse_move)); |
4693 | terminx | 537 | tcAutomap->addControl(map_button); |
4989 | terminx | 538 | tcAutomap->signal_button.connect(sigc::ptr_fun(&gameButton)); |
4693 | terminx | 539 | tcAutomap->setAlpha(0.5); |
540 | |||
4989 | terminx | 541 | // Now inventory in the weapons control group! |
4693 | terminx | 542 | |
4989 | terminx | 543 | inv_buttons[GET_JETPACK] = new touchcontrols::Button("jetpack", touchcontrols::RectF(0, 3, 2, 5), "jetpack", |
544 | gamefunc_Jetpack, false, false, true); |
||
545 | inv_buttons[GET_FIRSTAID] = new touchcontrols::Button("medkit", touchcontrols::RectF(0, 5, 2, 7), "medkit", |
||
546 | gamefunc_MedKit, false, false, true); |
||
547 | inv_buttons[GET_HEATS] = new touchcontrols::Button("nightv", touchcontrols::RectF(0, 7, 2, 9), "nightvision", |
||
548 | gamefunc_NightVision, false, false, true); |
||
549 | inv_buttons[GET_HOLODUKE] = new touchcontrols::Button("holoduke", touchcontrols::RectF(0, 9, 2, 11), "holoduke", |
||
550 | gamefunc_Holo_Duke, false, false, true); |
||
551 | inv_buttons[GET_STEROIDS] = new touchcontrols::Button("steroids", touchcontrols::RectF(0, 11, 2, 13), |
||
552 | "steroids", gamefunc_Steroids, false, false, true); |
||
4693 | terminx | 553 | |
4989 | terminx | 554 | tcGameWeapons->addControl(inv_buttons[GET_JETPACK]); |
555 | tcGameWeapons->addControl(inv_buttons[GET_FIRSTAID]); |
||
556 | tcGameWeapons->addControl(inv_buttons[GET_HEATS]); |
||
557 | tcGameWeapons->addControl(inv_buttons[GET_HOLODUKE]); |
||
558 | tcGameWeapons->addControl(inv_buttons[GET_STEROIDS]); |
||
559 | // Inventory are the only buttons so safe to do this |
||
560 | tcGameWeapons->signal_button.connect(sigc::ptr_fun(&inventoryButton)); |
||
4693 | terminx | 561 | |
4989 | terminx | 562 | // Weapons |
563 | weaponWheel = new touchcontrols::WheelSelect("weapon_wheel", touchcontrols::RectF(7, 2, 19, 14), |
||
564 | "weapon_wheel_orange_blank", 10); |
||
565 | weaponWheel->signal_selected.connect(sigc::ptr_fun(&weaponWheelChosen)); |
||
4434 | terminx | 566 | weaponWheel->signal_enabled.connect(sigc::ptr_fun(&weaponWheelSelected)); |
567 | tcGameWeapons->addControl(weaponWheel); |
||
4529 | terminx | 568 | tcGameWeapons->setAlpha(0.9); |
4386 | terminx | 569 | |
4529 | terminx | 570 | ///////////////////////////////////////////////////////////// |
571 | |||
572 | |||
4434 | terminx | 573 | controlsContainer.addControlGroup(tcMenuMain); |
574 | controlsContainer.addControlGroup(tcGameMain); |
||
4693 | terminx | 575 | // controlsContainer.addControlGroup(tcInventory);//Need to be above tcGameMain incase buttons over stick |
4434 | terminx | 576 | controlsContainer.addControlGroup(tcGameWeapons); |
4693 | terminx | 577 | controlsContainer.addControlGroup(tcAutomap); |
4529 | terminx | 578 | controlsContainer.addControlGroup(tcYesNo); |
579 | controlsContainer.addControlGroup(tcBlankTap); |
||
4434 | terminx | 580 | controlsCreated = 1; |
4386 | terminx | 581 | |
4989 | terminx | 582 | tcGameMain->setAlpha(droidinput.gameControlsAlpha); |
583 | controlsContainer.editButtonAlpha = droidinput.gameControlsAlpha; |
||
584 | tcGameWeapons->setAlpha(droidinput.gameControlsAlpha); |
||
585 | tcMenuMain->setAlpha(droidinput.gameControlsAlpha); |
||
4529 | terminx | 586 | |
5000 | terminx | 587 | tcGameMain->setXMLFile(gamePath + "/control_layout_main.xml"); |
588 | tcGameWeapons->setXMLFile(gamePath + "/control_layout_weapons.xml"); |
||
589 | tcAutomap->setXMLFile(gamePath + "/control_layout_automap.xml"); |
||
4693 | terminx | 590 | // tcInventory->setXMLFile((std::string)graphics_path + "/inventory.xml"); |
4386 | terminx | 591 | |
4693 | terminx | 592 | setControlsContainer(&controlsContainer); |
4434 | terminx | 593 | } |
594 | else |
||
595 | LOGI("NOT creating controls"); |
||
4386 | terminx | 596 | |
4989 | terminx | 597 | // controlsContainer.initGL(); |
4386 | terminx | 598 | } |
599 | |||
4529 | terminx | 600 | void updateTouchScreenMode(touchscreemode_t mode) |
601 | { |
||
4693 | terminx | 602 | // LOGI("updateTouchScreenModeA %d",mode); |
4440 | terminx | 603 | |
4989 | terminx | 604 | static touchscreemode_t lastMode = TOUCH_SCREEN_BLANK; |
4529 | terminx | 605 | |
4989 | terminx | 606 | if (mode != lastMode) |
607 | { |
||
608 | // first disable the last screen and fade out is necessary |
||
609 | switch (lastMode) |
||
610 | { |
||
611 | case TOUCH_SCREEN_BLANK: // Does not exist yet break; |
||
612 | case TOUCH_SCREEN_BLANK_TAP: |
||
613 | tcBlankTap->resetOutput(); |
||
614 | tcBlankTap->setEnabled(false); // Dont fade out as no graphics |
||
615 | break; |
||
616 | case TOUCH_SCREEN_YES_NO: |
||
617 | tcYesNo->resetOutput(); |
||
618 | tcYesNo->fade(touchcontrols::FADE_OUT, DEFAULT_FADE_FRAMES); |
||
619 | break; |
||
620 | case TOUCH_SCREEN_MENU: |
||
621 | tcMenuMain->resetOutput(); |
||
622 | tcMenuMain->fade(touchcontrols::FADE_OUT, DEFAULT_FADE_FRAMES); |
||
623 | break; |
||
624 | case TOUCH_SCREEN_GAME: |
||
625 | tcGameMain->resetOutput(); |
||
4529 | terminx | 626 | |
4989 | terminx | 627 | tcGameMain->fade(touchcontrols::FADE_OUT, DEFAULT_FADE_FRAMES); |
628 | tcGameWeapons->setEnabled(false); |
||
629 | break; |
||
630 | case TOUCH_SCREEN_AUTOMAP: |
||
631 | tcAutomap->resetOutput(); |
||
632 | tcAutomap->fade(touchcontrols::FADE_OUT, DEFAULT_FADE_FRAMES); |
||
633 | break; |
||
634 | case TOUCH_SCREEN_CONSOLE: break; |
||
4529 | terminx | 635 | } |
636 | |||
4989 | terminx | 637 | // Enable the current new screen |
638 | switch (mode) |
||
639 | { |
||
640 | case TOUCH_SCREEN_BLANK: // Does not exist yet break; |
||
641 | case TOUCH_SCREEN_BLANK_TAP: tcBlankTap->setEnabled(true); break; |
||
642 | case TOUCH_SCREEN_YES_NO: |
||
643 | tcYesNo->setEnabled(true); |
||
644 | tcYesNo->fade(touchcontrols::FADE_IN, DEFAULT_FADE_FRAMES); |
||
645 | break; |
||
646 | case TOUCH_SCREEN_MENU: |
||
647 | tcMenuMain->setEnabled(true); |
||
648 | tcMenuMain->fade(touchcontrols::FADE_IN, DEFAULT_FADE_FRAMES); |
||
4693 | terminx | 649 | |
4989 | terminx | 650 | // This is a bit of a hack, we need to enable the inventory buttons so they can be edited, they will not |
651 | // be seen anyway |
||
652 | showWeaponsInventory(true); |
||
653 | break; |
||
654 | case TOUCH_SCREEN_GAME: |
||
655 | tcGameMain->setEnabled(true); |
||
656 | tcGameMain->fade(touchcontrols::FADE_IN, DEFAULT_FADE_FRAMES); |
||
657 | tcGameWeapons->setEnabled(true); |
||
658 | showWeaponsInventory(false); |
||
659 | break; |
||
660 | case TOUCH_SCREEN_AUTOMAP: |
||
661 | tcAutomap->setEnabled(true); |
||
662 | tcAutomap->fade(touchcontrols::FADE_IN, DEFAULT_FADE_FRAMES); |
||
663 | break; |
||
664 | case TOUCH_SCREEN_CONSOLE: break; |
||
4529 | terminx | 665 | } |
666 | |||
667 | lastMode = mode; |
||
668 | } |
||
669 | |||
4989 | terminx | 670 | int inv = PortableRead(READ_INVENTORY); |
671 | |||
672 | for (int i = 0; i < GET_MAX; ++i) |
||
673 | if (inv_buttons[i]) |
||
674 | inv_buttons[i]->setAlpha(tcGameWeapons->getFadedAlpha() * ((inv & (1 << i)) ? 1.f : 0.3f)); |
||
4529 | terminx | 675 | } |
676 | |||
677 | |||
4440 | terminx | 678 | #ifdef GP_LIC |
679 | #define GP_LIC_INC 1 |
||
680 | #include "s-setup/gp_lic_include.h" |
||
681 | #endif |
||
682 | |||
4989 | terminx | 683 | extern char videomodereset; |
684 | extern int mobile_halted; |
||
685 | |||
4386 | terminx | 686 | void frameControls() |
687 | { |
||
4989 | terminx | 688 | if (mobile_halted) return; |
689 | |||
4433 | terminx | 690 | static int loadedGLImages = 0; |
691 | |||
4989 | terminx | 692 | if (videomodereset) |
693 | { |
||
694 | loadedGLImages = -1; |
||
695 | return; |
||
696 | } |
||
4529 | terminx | 697 | |
4989 | terminx | 698 | // We need to do this here now because duke loads a new gl context |
4693 | terminx | 699 | |
4989 | terminx | 700 | if (loadedGLImages <= 0) |
4434 | terminx | 701 | { |
4989 | terminx | 702 | controlsContainer.initGL(loadedGLImages == -1); |
4434 | terminx | 703 | loadedGLImages = 1; |
704 | } |
||
4386 | terminx | 705 | |
4989 | terminx | 706 | // LOGI("frameControls"); |
707 | |||
4434 | terminx | 708 | curRenderer = (PortableRead(READ_RENDERER) != REND_CLASSIC); |
4386 | terminx | 709 | |
4529 | terminx | 710 | updateTouchScreenMode((touchscreemode_t)PortableRead(READ_SCREEN_MODE)); |
711 | |||
4989 | terminx | 712 | setHideSticks(droidinput.hideStick); |
4386 | terminx | 713 | |
4989 | terminx | 714 | if (tcGameMain) |
715 | { |
||
716 | tcGameMain->setAlpha(droidinput.gameControlsAlpha); |
||
717 | controlsContainer.editButtonAlpha = droidinput.gameControlsAlpha; |
||
718 | tcGameWeapons->setAlpha(droidinput.gameControlsAlpha); |
||
719 | tcMenuMain->setAlpha(droidinput.gameControlsAlpha); |
||
720 | // tcInventory->setAlpha(droidinput.gameControlsAlpha); |
||
721 | } |
||
722 | |||
4434 | terminx | 723 | controlsContainer.draw(); |
4440 | terminx | 724 | |
725 | #ifdef GP_LIC |
||
4529 | terminx | 726 | #undef GP_LIC_INC |
4440 | terminx | 727 | #define GP_LIC_INC 2 |
728 | #include "s-setup/gp_lic_include.h" |
||
729 | #endif |
||
4386 | terminx | 730 | } |
731 | |||
4989 | terminx | 732 | void setTouchSettings(int other) |
4386 | terminx | 733 | { |
4436 | terminx | 734 | // TODO: defined names for these values |
735 | hideTouchControls = other & 0x80000000 ? true : false; |
||
4529 | terminx | 736 | |
4989 | terminx | 737 | // keep in sync with Duke3d/res/values/strings.xml |
738 | int doubletap_options[5] = { -1, gamefunc_Quick_Kick, gamefunc_AutoRun, gamefunc_MedKit, gamefunc_Jetpack }; |
||
4386 | terminx | 739 | |
4989 | terminx | 740 | droidinput.left_double_action = doubletap_options[((other >> 4) & 0xF)]; |
741 | droidinput.right_double_action = doubletap_options[((other >> 8) & 0xF)]; |
||
4386 | terminx | 742 | |
4989 | terminx | 743 | LOGI("setTouchSettings left_double_action = %d", droidinput.left_double_action); |
4386 | terminx | 744 | } |
745 | |||
4989 | terminx | 746 | #define EXPORT_ME __NDK_FPABI__ __attribute__((visibility("default"))) |
4386 | terminx | 747 | |
4989 | terminx | 748 | JNIEnv *env_; |
4386 | terminx | 749 | |
4989 | terminx | 750 | int argc = 1; |
751 | const char *argv[32]; |
||
4386 | terminx | 752 | |
5000 | terminx | 753 | static inline const char *getGamePath() { return gamePath.c_str(); } |
4386 | terminx | 754 | |
4989 | terminx | 755 | jint EXPORT_ME Java_com_voidpoint_duke3d_engine_NativeLib_init(JNIEnv *env, jobject thiz, jstring graphics_dir, |
756 | jint audio_rate, jint audio_buffer_size, |
||
757 | jobjectArray argsArray, jint renderer, |
||
758 | jstring jduke3d_path) |
||
4386 | terminx | 759 | { |
4434 | terminx | 760 | env_ = env; |
4386 | terminx | 761 | |
4440 | terminx | 762 | #ifdef GP_LIC |
4529 | terminx | 763 | getGlobalClasses(env_); |
4440 | terminx | 764 | #endif |
765 | |||
4436 | terminx | 766 | droidinfo.audio_sample_rate = audio_rate; |
767 | droidinfo.audio_buffer_size = audio_buffer_size; |
||
4386 | terminx | 768 | |
4989 | terminx | 769 | // curRenderer = renderer; |
4434 | terminx | 770 | curRenderer = REND_GL; |
4386 | terminx | 771 | |
4434 | terminx | 772 | argv[0] = "eduke32"; |
4989 | terminx | 773 | int argCount = (env)->GetArrayLength(argsArray); |
774 | LOGI("argCount = %d", argCount); |
||
775 | for (int i = 0; i < argCount; i++) |
||
776 | { |
||
777 | jstring string = (jstring)(env)->GetObjectArrayElement(argsArray, i); |
||
778 | argv[argc] = (char *)(env)->GetStringUTFChars(string, 0); |
||
779 | LOGI("arg = %s", argv[argc]); |
||
4434 | terminx | 780 | argc++; |
781 | } |
||
4386 | terminx | 782 | |
5000 | terminx | 783 | gamePath = std::string(env->GetStringUTFChars(jduke3d_path, NULL)); |
4386 | terminx | 784 | |
4989 | terminx | 785 | // Change working dir, save games etc |
4434 | terminx | 786 | // FIXME: potentially conflicts with chdirs in -game_dir support |
787 | chdir(getGamePath()); |
||
788 | char timidity_env[512]; |
||
4386 | terminx | 789 | |
4989 | terminx | 790 | sprintf(timidity_env, "TIMIDITY_CFG=%s/../timidity.cfg", getGamePath()); |
4434 | terminx | 791 | putenv(timidity_env); |
4386 | terminx | 792 | |
4989 | terminx | 793 | LOGI("duke3d_path = %s", getGamePath()); |
4386 | terminx | 794 | |
4989 | terminx | 795 | const char *p = env->GetStringUTFChars(graphics_dir, NULL); |
5000 | terminx | 796 | obbPath = std::string(p); |
4386 | terminx | 797 | |
5000 | terminx | 798 | LOGI("obbPath = %s", obbPath.c_str()); |
4386 | terminx | 799 | |
5000 | terminx | 800 | initControls(droidinfo.screen_width, droidinfo.screen_height, (obbPath + "/assets/").c_str()); |
801 | |||
4434 | terminx | 802 | PortableInit(argc, argv); |
4529 | terminx | 803 | |
4434 | terminx | 804 | return 0; |
4386 | terminx | 805 | } |
806 | |||
807 | |||
4989 | terminx | 808 | jint EXPORT_ME Java_com_voidpoint_duke3d_engine_NativeLib_frame(JNIEnv *env, jobject thiz) |
4386 | terminx | 809 | { |
4989 | terminx | 810 | LOGI("Java_com_voidpoint_duke3d_engine_NativeLib_frame"); |
4386 | terminx | 811 | |
4989 | terminx | 812 | // frameControls(); |
4434 | terminx | 813 | return 0; |
4386 | terminx | 814 | } |
815 | |||
4989 | terminx | 816 | __attribute__((visibility("default"))) jint JNI_OnLoad(JavaVM *vm, void *reserved) |
4386 | terminx | 817 | { |
4434 | terminx | 818 | LOGI("JNI_OnLoad"); |
819 | setTCJNIEnv(vm); |
||
820 | jvm_ = vm; |
||
821 | return JNI_VERSION_1_4; |
||
4386 | terminx | 822 | } |
823 | |||
824 | |||
825 | void EXPORT_ME |
||
4989 | terminx | 826 | Java_com_voidpoint_duke3d_engine_NativeLib_keypress(JNIEnv *env, jobject obj, jint down, jint keycode, jint unicode) |
4386 | terminx | 827 | { |
4989 | terminx | 828 | LOGI("keypress %d", keycode); |
4434 | terminx | 829 | if (controlsContainer.isEditing()) |
830 | { |
||
4989 | terminx | 831 | if (down && (keycode == SDL_SCANCODE_ESCAPE)) |
4434 | terminx | 832 | controlsContainer.finishEditing(); |
4436 | terminx | 833 | return; |
4434 | terminx | 834 | } |
4436 | terminx | 835 | |
4989 | terminx | 836 | PortableKeyEvent(down, keycode, unicode); |
4386 | terminx | 837 | } |
838 | |||
839 | |||
4989 | terminx | 840 | void EXPORT_ME Java_com_voidpoint_duke3d_engine_NativeLib_touchEvent(JNIEnv *env, jobject obj, jint action, jint pid, |
841 | jfloat x, jfloat y) |
||
4386 | terminx | 842 | { |
4989 | terminx | 843 | // LOGI("TOUCHED"); |
844 | controlsContainer.processPointer(action, pid, x, y); |
||
4386 | terminx | 845 | } |
846 | |||
847 | |||
4989 | terminx | 848 | void EXPORT_ME Java_com_voidpoint_duke3d_engine_NativeLib_doAction(JNIEnv *env, jobject obj, jint state, jint action) |
4386 | terminx | 849 | { |
4989 | terminx | 850 | LOGI("doAction %d %d", state, action); |
4434 | terminx | 851 | |
4989 | terminx | 852 | // gamepadButtonPressed(); |
4434 | terminx | 853 | if (hideTouchControls && tcGameMain) |
854 | { |
||
855 | if (tcGameMain->isEnabled()) |
||
856 | tcGameMain->animateOut(30); |
||
857 | |||
858 | if (tcGameWeapons->isEnabled()) |
||
859 | tcGameWeapons->animateOut(30); |
||
860 | } |
||
861 | |||
4989 | terminx | 862 | PortableAction(state, action); |
4386 | terminx | 863 | } |
864 | |||
4989 | terminx | 865 | void EXPORT_ME Java_com_voidpoint_duke3d_engine_NativeLib_analogFwd(JNIEnv *env, jobject obj, jfloat v) |
4386 | terminx | 866 | { |
4440 | terminx | 867 | PortableMove(v, NAN); |
4386 | terminx | 868 | } |
869 | |||
4989 | terminx | 870 | void EXPORT_ME Java_com_voidpoint_duke3d_engine_NativeLib_analogSide(JNIEnv *env, jobject obj, jfloat v) |
4386 | terminx | 871 | { |
4440 | terminx | 872 | PortableMove(NAN, v); |
4386 | terminx | 873 | } |
874 | |||
4989 | terminx | 875 | void EXPORT_ME Java_com_voidpoint_duke3d_engine_NativeLib_analogPitch(JNIEnv *env, jobject obj, jint mode, jfloat v) |
4386 | terminx | 876 | { |
4440 | terminx | 877 | PortableLookJoystick(NAN, v); |
4386 | terminx | 878 | } |
879 | |||
4989 | terminx | 880 | void EXPORT_ME Java_com_voidpoint_duke3d_engine_NativeLib_analogYaw(JNIEnv *env, jobject obj, jint mode, jfloat v) |
4386 | terminx | 881 | { |
4440 | terminx | 882 | PortableLookJoystick(v, NAN); |
4386 | terminx | 883 | } |
884 | |||
4989 | terminx | 885 | void EXPORT_ME |
886 | Java_com_voidpoint_duke3d_engine_NativeLib_setTouchSettings(JNIEnv *env, jobject obj, int other) |
||
4386 | terminx | 887 | { |
4989 | terminx | 888 | setTouchSettings(other); |
4386 | terminx | 889 | } |
890 | |||
4989 | terminx | 891 | void EXPORT_ME Java_com_voidpoint_duke3d_engine_NativeLib_resetTouchSettings(JNIEnv *env, jobject obj) |
4386 | terminx | 892 | { |
4434 | terminx | 893 | controlsContainer.resetDefaults(); |
4386 | terminx | 894 | } |
895 | |||
896 | std::string quickCommandString; |
||
4989 | terminx | 897 | |
898 | jint EXPORT_ME Java_com_voidpoint_duke3d_engine_NativeLib_quickCommand(JNIEnv *env, jobject obj, jstring command) |
||
4386 | terminx | 899 | { |
4989 | terminx | 900 | const char *p = env->GetStringUTFChars(command, NULL); |
901 | quickCommandString = std::string(p) + "\n"; |
||
4434 | terminx | 902 | env->ReleaseStringUTFChars(command, p); |
903 | PortableCommand(quickCommandString.c_str()); |
||
4386 | terminx | 904 | } |
905 | |||
906 | void EXPORT_ME |
||
4989 | terminx | 907 | Java_com_voidpoint_duke3d_engine_NativeLib_setScreenSize(JNIEnv *env, jobject thiz, jint width, jint height) |
4386 | terminx | 908 | { |
4436 | terminx | 909 | droidinfo.screen_width = width; |
910 | droidinfo.screen_height = height; |
||
4386 | terminx | 911 | } |
912 | |||
4989 | terminx | 913 | void EXPORT_ME Java_org_libsdl_app_SDLActivity_nativeInit(JNIEnv *env, jclass cls) |
4386 | terminx | 914 | { |
4434 | terminx | 915 | /* This interface could expand with ABI negotiation, calbacks, etc. */ |
916 | SDL_Android_Init(env, cls); |
||
917 | SDL_SetMainReady(); |
||
918 | // SDL_EventState(SDL_TEXTINPUT,SDL_ENABLE); |
||
4386 | terminx | 919 | } |
920 | |||
4989 | terminx | 921 | jstring EXPORT_ME |
922 | Java_com_voidpoint_duke3d_engine_NativeLib_getSavetext(JNIEnv *env, jobject obj, jstring jfile, jint type) |
||
923 | { |
||
924 | const char *p = env->GetStringUTFChars(jfile, NULL); |
||
925 | |||
926 | jstring ret = env->NewStringUTF(G_GetStringFromSavegame(p, type)); |
||
927 | env->ReleaseStringUTFChars(jfile, p); |
||
928 | |||
929 | return ret; |
||
930 | } |
||
931 | |||
932 | jint EXPORT_ME Java_com_voidpoint_duke3d_engine_NativeLib_getScreenshot(JNIEnv *env, jobject obj, jstring jfile, |
||
933 | jobject jpal, jobject jdataOut) |
||
934 | { |
||
935 | const char *p = env->GetStringUTFChars(jfile, NULL); |
||
936 | |||
937 | jbyte *bb = (jbyte *)env->GetDirectBufferAddress(jdataOut); |
||
938 | jbyte *pb = (jbyte *)env->GetDirectBufferAddress(jpal); |
||
939 | |||
940 | int ret = G_GetScreenshotFromSavegame(p, (char *)pb, (char *)bb); |
||
941 | |||
942 | env->ReleaseStringUTFChars(jfile, p); |
||
943 | return ret; |
||
944 | } |
||
945 | |||
4440 | terminx | 946 | #ifdef GP_LIC |
4529 | terminx | 947 | #undef GP_LIC_INC |
4440 | terminx | 948 | #define GP_LIC_INC 3 |
949 | #include "s-setup/gp_lic_include.h" |
||
950 | #endif |
||
4386 | terminx | 951 | } |