forked from exult/exult
-
Notifications
You must be signed in to change notification settings - Fork 0
/
cheat_screen.cc
4384 lines (3806 loc) · 105 KB
/
cheat_screen.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
* Copyright (C) 2000-2022 The Exult Team
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#ifdef HAVE_CONFIG_H
# include <config.h>
#endif
// Disable the gcc warning because we cannot fix it in SDL's headers
#if defined(__GNUC__)
# pragma GCC diagnostic push
# pragma GCC diagnostic ignored "-Wold-style-cast"
#endif
#include "cheat_screen.h"
#include "Configuration.h"
#include "Gump_manager.h"
#include "actors.h"
#include "cheat.h"
#include "chunks.h"
#include "exult.h"
#include "files/U7file.h"
#include "font.h"
#include "game.h"
#include "gameclk.h"
#include "gamemap.h"
#include "gamewin.h"
#include "gump_utils.h"
#include "ignore_unused_variable_warning.h"
#include "imagewin.h"
#include "miscinf.h"
#include "party.h"
#include "schedule.h"
#include "touchui.h"
#include "ucmachine.h"
#include "version.h"
#include "vgafile.h"
#include <cstring>
// #define TEST_MOBILE 1
static const Uint32 EXSDL_TOUCH_MOUSEID = SDL_TOUCH_MOUSEID;
// renable the warning that was disabled above
#if defined(__GNUC__)
# pragma GCC diagnostic pop
#endif
const char* CheatScreen::schedules[33] = {
"Combat", "Hor. Pace", "Ver. Pace", "Talk", "Dance", "Eat",
"Farm", "Tend Shop", "Miner", "Hound", "Stand", "Loiter",
"Wander", "Blacksmith", "Sleep", "Wait", "Major Sit", "Graze",
"Bake", "Sew", "Shy", "Lab", "Thief", "Waiter",
"Special", "Kid Games", "Eat at Inn", "Duel", "Preach", "Patrol",
"Desk Work", "Follow Avt", "Move2Sched"};
const char* CheatScreen::flag_names[64] = {
"invisible", // 0x00
"asleep", // 0x01
"charmed", // 0x02
"cursed", // 0x03
"dead", // 0x04
nullptr, // 0x05
"in_party", // 0x06
"paralyzed", // 0x07
"poisoned", // 0x08
"protection", // 0x09
"on_moving_barge", // 0x0A
"okay_to_take", // 0x0B
"might", // 0x0C
"immunities", // 0x0D
"cant_die", // 0x0E
"in_action", // 0x0F
"dont_move/bg_dont_render", // 0x10
"si_on_moving_barge", // 0x11
"is_temporary", // 0x12
nullptr, // 0x13
"sailor", // 0x14
"okay_to_land", // 0x15
"dont_render/bg_dont_move", // 0x16
"in_dungeon", // 0x17
nullptr, // 0x18
"confused", // 0x19
"in_motion", // 0x1A
nullptr, // 0x1B
"met", // 0x1C
"tournament", // 0x1D
"si_zombie", // 0x1E
"no_spell_casting", // 0x1F
"polymorph", // 0x20
"tattooed", // 0x21
"read", // 0x22
"petra", // 0x23
"si_lizard_king", // 0x24
"freeze", // 0x25
"naked", // 0x26
nullptr, // 0x27
nullptr, // 0x28
nullptr, // 0x29
nullptr, // 0x2A
nullptr, // 0x2B
nullptr, // 0x2C
nullptr, // 0x2D
nullptr, // 0x2E
nullptr, // 0x2F
nullptr, // 0x30
nullptr, // 0x31
nullptr, // 0x32
nullptr, // 0x33
nullptr, // 0x34
nullptr, // 0x35
nullptr, // 0x36
nullptr, // 0x37
nullptr, // 0x38
nullptr, // 0x39
nullptr, // 0x3A
nullptr, // 0x3B
nullptr, // 0x3C
nullptr, // 0x3D
nullptr, // 0x3E
nullptr, // 0x3F
};
const char* CheatScreen::alignments[4] = {"Neutral", "Good", "Evil", "Chaotic"};
int CheatScreen::Get_highest_map() {
if (highest_map != INT_MIN) {
return highest_map;
}
int n = 0;
int next;
while ((next = Find_next_map(n + 1, 10)) != -1) {
n = next;
}
highest_map = n;
return n;
}
void CheatScreen::show_screen() {
gwin = Game_window::get_instance();
ibuf = gwin->get_win()->get_ib8();
if (!font) {
// Try to get the Font form Blackgate first because it looks better than
// the SI one
font = std::make_shared<Font>();
if (font->load(U7MAINSHP_FLX, 9, 1) != 0) {
font.reset();
}
}
// Get the font for this game if don't already have it
if (!font) {
font = fontManager.get_font("MENU_FONT");
}
clock = gwin->get_clock();
maxx = gwin->get_width();
#if defined(__IPHONEOS__) || defined(ANDROID) || defined(TEST_MOBILE)
maxy = 200;
#else
maxy = gwin->get_height();
#endif
centerx = maxx / 2;
centery = maxy / 2;
if (touchui != nullptr) {
touchui->hideGameControls();
SDL_StartTextInput();
}
// Pause the game
gwin->get_tqueue()->pause(SDL_GetTicks());
const str_int_pair& pal_tuple_static = game->get_resource("palettes/0");
const str_int_pair& pal_tuple_patch
= game->get_resource("palettes/patch/0");
pal.load(pal_tuple_static.str, pal_tuple_patch.str, pal_tuple_static.num);
pal.apply();
// std::memset(highlighttable.colors, 1, sizeof(highlighttable.colors));
// highlighttable.colors[0] = 0;
// highlighttable.colors[255] = 255;
const int remaps[] = {
5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5 - 1,
};
pal.Generate_remap_xformtable(highlighttable.colors, remaps);
const int hoverremaps[] = {
1, 1, 1, 1, 1, 6, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 - 1,
};
pal.Generate_remap_xformtable(hovertable.colors, hoverremaps);
ClearState clear(state);
Mouse::mouse->hide();
Mouse::Mouse_shapes saveshape = Mouse::mouse->get_shape();
Mouse::mouse->set_shape(Mouse::hand);
buttons_down.clear();
// Start the loop
NormalLoop();
Mouse::mouse->set_shape(saveshape);
Mouse::mouse->hide();
gwin->paint();
Mouse::mouse->show();
// Resume the game clock
gwin->get_tqueue()->resume(SDL_GetTicks());
// Reset the palette
clock->reset_palette();
if (touchui != nullptr) {
Gump_manager* gumpman = gwin->get_gump_man();
if (!gumpman->gump_mode()) {
touchui->showGameControls();
}
if (SDL_IsTextInputActive()) {
SDL_StopTextInput();
}
}
}
//
// DISPLAYS
//
//
// Shared
//
void CheatScreen::SharedPrompt() {
char buf[64];
#if defined(__IPHONEOS__) || defined(ANDROID) || defined(TEST_MOBILE)
const int prompt = 81;
const int promptmes = 90;
const int offsetx = 15;
#else
const int prompt = maxy - 18;
const int promptmes = maxy - 9;
const int offsetx = 0;
#endif
font->paint_text_fixedwidth(ibuf, "Select->", offsetx, prompt, 8);
// Special handling for arrows when not doing text input
const char* input = state.input;
if (state.GetMode() < CP_ChooseNPC && !input[1]
&& (*input == '<' || *input == '>' || *input == '^' || *input == 'V')) {
PaintArrow(64 + offsetx, prompt, *input);
input = " ";
}
if (input && std::strlen(input)) {
font->paint_text_fixedwidth(ibuf, input, 64 + offsetx, prompt, 8);
font->paint_text_fixedwidth(
ibuf, "_", 64 + offsetx + int(std::strlen(input)) * 8, prompt,
8);
} else {
font->paint_text_fixedwidth(ibuf, "_", 64 + offsetx, prompt, 8);
}
// Clear the input
if (state.GetMode() < CP_ChooseNPC) {
state.input[0] = 0;
}
// ...and Prompt Message
switch (state.GetMode()) {
default:
case CP_Command:
font->paint_text_fixedwidth(
ibuf, "Enter Command.", offsetx, promptmes, 8);
break;
case CP_HitKey:
font->paint_text_fixedwidth(ibuf, "Hit a key.", offsetx, promptmes, 8);
break;
case CP_NotAvail:
font->paint_text_fixedwidth(
ibuf, "Not yet available. Hit a key.", offsetx, promptmes, 8);
break;
case CP_InvalidNPC:
font->paint_text_fixedwidth(
ibuf, "Invalid NPC. Hit a key", offsetx, promptmes, 8);
break;
case CP_InvalidCom:
font->paint_text_fixedwidth(
ibuf, "Invalid Command. Hit a key.", offsetx, promptmes, 8);
break;
case CP_Canceled:
font->paint_text_fixedwidth(
ibuf, "Canceled. Hit a key.", offsetx, promptmes, 8);
break;
case CP_ClockSet:
font->paint_text_fixedwidth(
ibuf, "Clock Set. Hit a key.", offsetx, promptmes, 8);
break;
case CP_InvalidTime:
font->paint_text_fixedwidth(
ibuf, "Invalid Time. Hit a key.", offsetx, promptmes, 8);
break;
case CP_InvalidShape:
font->paint_text_fixedwidth(
ibuf, "Invalid Shape. Hit a key.", offsetx, promptmes, 8);
break;
case CP_InvalidValue:
font->paint_text_fixedwidth(
ibuf, "Invalid Value. Hit a key.", offsetx, promptmes, 8);
break;
case CP_Created:
font->paint_text_fixedwidth(
ibuf, "Item Created. Hit a key.", offsetx, promptmes, 8);
break;
case CP_ShapeSet:
font->paint_text_fixedwidth(
ibuf, "Shape Set. Hit a key.", offsetx, promptmes, 8);
break;
case CP_ValueSet:
font->paint_text_fixedwidth(
ibuf, "Clock Set. Hit a key.", offsetx, promptmes, 8);
break;
case CP_NameSet:
font->paint_text_fixedwidth(
ibuf, "Name Changed. Hit a key.", offsetx, promptmes, 8);
break;
case CP_WrongShapeFile:
font->paint_text_fixedwidth(
ibuf, "Wrong shape file. Must be SHAPES.VGA.", offsetx,
promptmes, 8);
break;
case CP_ChooseNPC:
font->paint_text_fixedwidth(
ibuf, "Which NPC? (ESC to cancel.)", offsetx, promptmes, 8);
break;
case CP_EnterValue:
font->paint_text_fixedwidth(
ibuf, "Enter Value. (ESC to cancel.)", offsetx, promptmes, 8);
break;
case CP_CustomValue:
if (state.custom_prompt) {
font->paint_text_fixedwidth(
ibuf, state.custom_prompt, offsetx, promptmes, 8);
}
break;
case CP_EnterValueNoCancel:
font->paint_text_fixedwidth(
ibuf, "Enter Value.", offsetx, promptmes, 8);
break;
case CP_Minute:
font->paint_text_fixedwidth(
ibuf, "Enter Minute. (ESC to cancel.)", offsetx, promptmes, 8);
break;
case CP_Hour:
font->paint_text_fixedwidth(
ibuf, "Enter Hour. (ESC to cancel.)", offsetx, promptmes, 8);
break;
case CP_Day:
font->paint_text_fixedwidth(
ibuf, "Enter Day. (ESC to cancel.)", offsetx, promptmes, 8);
break;
case CP_Shape:
snprintf(
buf, std::size(buf),
"Enter Shape Max %i (B=Browse or ESC=Cancel)",
Shape_manager::get_instance()->get_shapes().get_num_shapes()
- 1);
font->paint_text_fixedwidth(ibuf, buf, offsetx, promptmes, 8);
break;
case CP_Activity:
font->paint_text_fixedwidth(
ibuf, "Enter Activity 0-31. (ESC to cancel.)", offsetx,
promptmes, 8);
break;
case CP_XCoord:
snprintf(
buf, sizeof(buf), "Enter X Coord. Max %i (ESC to cancel)",
c_num_tiles);
font->paint_text_fixedwidth(ibuf, buf, offsetx, promptmes, 8);
break;
case CP_YCoord:
snprintf(
buf, sizeof(buf), "Enter Y Coord. Max %i (ESC to cancel)",
c_num_tiles);
font->paint_text_fixedwidth(ibuf, buf, offsetx, promptmes, 8);
break;
case CP_Lift:
font->paint_text_fixedwidth(
ibuf, "Enter Lift. (ESC to cancel)", offsetx, promptmes, 8);
break;
case CP_GFlagNum: {
snprintf(
buf, sizeof(buf), "Enter Global Flag 0-%d. (ESC to cancel)",
c_last_gflag);
font->paint_text_fixedwidth(ibuf, buf, offsetx, promptmes, 8);
break;
}
case CP_NFlagNum:
font->paint_text_fixedwidth(
ibuf, "Enter NPC Flag 0-63. (ESC to cancel)", offsetx,
promptmes, 8);
break;
case CP_TempNum:
font->paint_text_fixedwidth(
ibuf, "Enter Temperature 0-63. (ESC to cancel)", offsetx,
promptmes, 8);
break;
case CP_NLatitude:
font->paint_text_fixedwidth(
ibuf, "Enter Latitude. Max 113 (ESC to cancel)", offsetx,
promptmes, 8);
break;
case CP_SLatitude:
font->paint_text_fixedwidth(
ibuf, "Enter Latitude. Max 193 (ESC to cancel)", offsetx,
promptmes, 8);
break;
case CP_WLongitude:
font->paint_text_fixedwidth(
ibuf, "Enter Longitude. Max 93 (ESC to cancel)", offsetx,
promptmes, 8);
break;
case CP_ELongitude:
font->paint_text_fixedwidth(
ibuf, "Enter Longitude. Max 213 (ESC to cancel)", offsetx,
promptmes, 8);
break;
case CP_Name:
font->paint_text_fixedwidth(
ibuf, "Enter a new Name...", offsetx, promptmes, 8);
break;
case CP_NorthSouth:
font->paint_text_fixedwidth(
ibuf, "Latitude [N]orth or [S]outh?", offsetx, promptmes, 8);
break;
case CP_WestEast:
font->paint_text_fixedwidth(
ibuf, "Longitude [W]est or [E]ast?", offsetx, promptmes, 8);
break;
case CP_HexXCoord:
snprintf(
buf, sizeof(buf), "Enter X Coord. Max %04x (ESC to cancel)",
c_num_tiles);
font->paint_text_fixedwidth(ibuf, buf, offsetx, promptmes, 8);
break;
case CP_HexYCoord:
snprintf(
buf, sizeof(buf), "Enter Y Coord. Max %04x (ESC to cancel)",
c_num_tiles);
font->paint_text_fixedwidth(ibuf, buf, offsetx, promptmes, 8);
break;
}
}
static int SDLScanCodeToInt(SDL_Keycode sym) {
switch (sym) {
case SDLK_KP_0:
return '0';
case SDLK_KP_1:
return '1';
case SDLK_KP_2:
return '2';
case SDLK_KP_3:
return '3';
case SDLK_KP_4:
return '4';
case SDLK_KP_5:
return '5';
case SDLK_KP_6:
return '6';
case SDLK_KP_7:
return '7';
case SDLK_KP_8:
return '8';
case SDLK_KP_9:
return '9';
default:
return SDLK_ESCAPE;
}
}
static void resizeline(float& axis1, float delta1, float& axis2) {
float slope = axis2 / axis1;
axis1 += delta1;
axis2 = axis1 * slope;
}
bool CheatScreen::SharedInput() {
SDL_Event event;
// Do repaint after 100 ms to allow for time dependant effects. 10 FPS seems
// more that adequate for Cheat Screen If anyone needs to do smooth animaion
// the can change this
auto repainttime = SDL_GetTicks() + 100;
Mouse::mouse->hide(); // Turn off mouse.
std::memset(&event, 0, sizeof(event));
while (SDL_GetTicks() < repainttime) {
Delay();
if (state.highlighttime && state.highlighttime < SDL_GetTicks()) {
state.highlight = 0;
state.highlighttime = 0;
}
// How far finger needs to move for swipe to be interpreted as an a
// cursor key input)
bool do_swipe = std::abs(state.swipe_dx) > swipe_threshold
|| std::abs(state.swipe_dy) > swipe_threshold;
if (!do_swipe && state.last_swipe
&& ((state.last_swipe + 200) < SDL_GetTicks())) {
// zero out swipe state if it's been longer that 200ms since last
// event recieved and it's shorter than the threshold
state.last_swipe = 0;
state.swipe_dx = 0;
state.swipe_dy = 0;
}
Mouse::mouse_update = false;
while (do_swipe || SDL_PollEvent(&event)) {
int gx, gy;
SDL_Keycode simulate_key = SDLK_UNKNOWN;
//
if (do_swipe) {
float ax = 0, ay = 0;
ay = std::abs(state.swipe_dy);
ax = std::abs(state.swipe_dx);
CERR("Doing swipe ay: " << ay << " ax:" << ax);
// More vertical motion or More Horizontal
// perfectly diagonal motion will be treated as horizontal
if (ay > ax) {
// Swipe up the screen
if (state.swipe_dy < -swipe_threshold) {
simulate_key = SDLK_UP;
resizeline(
state.swipe_dy, +swipe_threshold,
state.swipe_dx);
// Swipe Down the screen
} else if (state.swipe_dy > swipe_threshold) {
simulate_key = SDLK_DOWN;
resizeline(
state.swipe_dy, -swipe_threshold,
state.swipe_dx);
}
} else {
// swipe right to left
if (state.swipe_dx < -swipe_threshold) {
simulate_key = SDLK_LEFT;
resizeline(
state.swipe_dx, +swipe_threshold,
state.swipe_dy);
// Swipe left to right
} else if (state.swipe_dx > swipe_threshold) {
simulate_key = SDLK_RIGHT;
resizeline(
state.swipe_dx, -swipe_threshold,
state.swipe_dy);
}
}
} else {
CERR("event.type= " << event.type);
switch (event.type) {
case SDL_QUIT: {
CERR("SDL_QUIT");
ImageBufferPaintable screenshot;
if (gwin->get_gump_man()->okay_to_quit(&screenshot)) {
throw quit_exception();
}
} break;
case SDL_FINGERDOWN: {
CERR("SDL_FINGERDOWN");
buttons_down.insert(button_down_finger);
if ((!Mouse::use_touch_input)
&& (event.tfinger.fingerId != 0)) {
Mouse::use_touch_input = true;
}
break;
}
case SDL_FINGERUP: {
CERR("SDL_FINGERUP");
// Get iterator for first instance of button_down_finger and
// erase it from the collection
auto it = buttons_down.find(button_down_finger);
if (it != buttons_down.end()) {
buttons_down.erase(it);
}
} break;
// Finger swiping converts to cursor keys
case SDL_FINGERMOTION: {
gwin->get_win()->screen_to_game(
event.button.x, event.button.y,
gwin->get_fastmouse(), gx, gy);
static int numFingers = 0;
SDL_Finger* finger0
= SDL_GetTouchFinger(event.tfinger.touchId, 0);
if (finger0) {
numFingers
= SDL_GetNumTouchFingers(event.tfinger.touchId);
}
CERR("numFingers " << numFingers);
// Will allow single finger swipes
if (numFingers > 0) {
// Hide on screen keyboard if we are swiping
if (SDL_IsTextInputActive()) {
SDL_StopTextInput();
}
// Accuulate the deltas onto
// thevector
state.swipe_dx += event.tfinger.dx;
state.swipe_dy += event.tfinger.dy;
// set last swipe value to now
state.last_swipe = SDL_GetTicks();
}
} break;
// Mousewheel scrolling with SDL2.
case SDL_MOUSEWHEEL: {
CERR("SDL_MOUSEWHEEL");
if (event.wheel.y > 0) {
simulate_key = SDLK_LEFT;
} else if (event.wheel.y < 0) {
simulate_key = SDLK_RIGHT;
}
} break;
case SDL_MOUSEMOTION: {
CERR("SDL_MOUSEMOTION");
if (Mouse::use_touch_input
&& event.motion.which != EXSDL_TOUCH_MOUSEID) {
Mouse::use_touch_input = false;
}
gwin->get_win()->screen_to_game(
event.motion.x, event.motion.y,
gwin->get_fastmouse(), gx, gy);
Mouse::mouse->move(gx, gy);
Mouse::mouse_update = true;
} break;
// return;
case SDL_MOUSEBUTTONDOWN: {
gwin->get_win()->screen_to_game(
event.button.x, event.button.y,
gwin->get_fastmouse(), gx, gy);
CERR("SDL_MOUSEBUTTONDOWN( " << gx << " , " << gy << " )");
buttons_down.insert(event.button.button);
if (event.button.button == 1) {
simulate_key = CheckHotspots(gx, gy);
if (!simulate_key) {
// Double click detection
if (event.button.clicks >= 2) {
simulate_key = SDLK_RETURN;
}
CERR("window size( " << gwin->get_width() << " , "
<< gwin->get_height() << " )");
// Touch on the cheat screen will bring up the
// keyboard but not if the tap was within a 20 pixel
// border on the edge of the game screen)
if (SDL_IsTextInputActive()) {
SDL_StopTextInput();
} else if (
gx > 20 && gy > 20
&& gx < (gwin->get_width() - 20)
&& gy < (gwin->get_height() - 20)) {
SDL_StartTextInput();
}
}
}
} break;
case SDL_MOUSEBUTTONUP: {
buttons_down.erase(event.button.button);
} break;
case SDL_KEYDOWN: {
buttons_down.insert(int(event.key.keysym.sym));
} break;
case SDL_KEYUP: {
buttons_down.erase(int(event.key.keysym.sym));
} break;
default:
break;
}
}
if (simulate_key) {
std::memset(&event, 0, sizeof(event));
event.type = SDL_KEYDOWN;
event.key.keysym.sym = simulate_key;
CERR("simmulate key " << event.key.keysym.sym);
// Simulated keys automatically execute the command if possible
if (state.GetMode() >= CP_HitKey
&& state.GetMode() <= CP_WrongShapeFile) {
state.SetMode(CP_Command, true);
}
}
if (event.type != SDL_KEYDOWN) {
continue;
}
const SDL_Keysym& key = event.key.keysym;
if (key.sym == SDLK_ESCAPE) {
std::memset(state.input, 0, sizeof(state.input));
// If current mode is needing to press a key return to command
if (state.GetMode() >= CP_HitKey
&& state.GetMode() <= CP_WrongShapeFile) {
state.command = 0;
state.SetMode(CP_Command, true);
return false;
}
// Escape will cancel current mode
else if (state.GetMode() != CP_Command) {
state.command = key.sym;
state.SetMode(CP_Canceled, true);
return false;
}
}
if ((key.sym == SDLK_s) && (key.mod & KMOD_ALT)
&& (key.mod & KMOD_CTRL)) {
make_screenshot(true);
return false;
}
if (state.GetMode() == CP_NorthSouth) {
if (!state.input[0] && (key.sym == 'n' || key.sym == 's')) {
state.input[0] = char(key.sym);
state.activate = true;
}
} else if (state.GetMode() == CP_WestEast) {
if (!state.input[0] && (key.sym == 'w' || key.sym == 'e')) {
state.input[0] = char(key.sym);
state.activate = true;
}
} else if (
state.GetMode() >= CP_HexXCoord
&& state.GetMode() <= CP_HexYCoord) { // Want hex input
// Activate (if possible)
if (key.sym == SDLK_RETURN || key.sym == SDLK_KP_ENTER) {
state.activate = true;
// increment/decrement
} else if (key.sym == SDLK_LEFT || key.sym == SDLK_RIGHT) {
char* end = nullptr;
long value = std::strtol(state.input, &end, 16);
if (state.val_max < state.val_min) {
std::swap(state.val_max, state.val_min);
}
if (end == state.input + strlen(state.input)) {
if (key.sym == SDLK_LEFT && value != state.val_min) {
value = std::max(value - 1, state.val_min);
} else if (
key.sym == SDLK_RIGHT
&& value != state.val_max) {
value = std::min(value + 1, state.val_max);
}
if (value < 0) {
snprintf(
state.input, std::size(state.input), "-%lx",
-value);
} else {
snprintf(
state.input, std::size(state.input), "%lx",
value);
}
}
} else if (
(key.sym == '-' || key.sym == SDLK_KP_MINUS)
&& !state.input[0]) {
state.input[0] = '-';
} else if (
key.sym < 256 && key.sym >= 0
&& std::isxdigit(key.sym)) {
const size_t curlen = std::strlen(state.input);
if (curlen < (std::size(state.input) - 1)) {
state.input[curlen] = char(std::tolower(key.sym));
state.input[curlen + 1] = 0;
}
} else if (
(key.sym >= SDLK_KP_1 && key.sym <= SDLK_KP_9)
|| key.sym == SDLK_KP_0) {
const size_t curlen = std::strlen(state.input);
if (curlen < (std::size(state.input) - 1)) {
const int sym = SDLScanCodeToInt(key.sym);
state.input[curlen] = char(sym);
state.input[curlen + 1] = 0;
}
} else if (key.sym == SDLK_BACKSPACE) {
const size_t curlen = std::strlen(state.input);
if (curlen) {
state.input[curlen - 1] = 0;
}
}
} else if (state.GetMode() == CP_Name) { // Want Text input
if (key.sym == SDLK_RETURN || key.sym == SDLK_KP_ENTER) {
state.activate = true;
} else if (
(key.sym < 256 && key.sym >= 0 && std::isalnum(key.sym))
|| key.sym == ' ') {
const size_t curlen = std::strlen(state.input);
char chr = key.sym;
if (key.mod & KMOD_SHIFT) {
chr = static_cast<char>(
std::toupper(static_cast<unsigned char>(chr)));
}
if (curlen < (std::size(state.input) - 1)) {
state.input[curlen] = chr;
state.input[curlen + 1] = 0;
}
} else if (key.sym == SDLK_BACKSPACE) {
const size_t curlen = std::strlen(state.input);
if (curlen) {
state.input[curlen - 1] = 0;
}
}
} else if (state.GetMode() >= CP_ChooseNPC) { // Need to grab
// numerical
// input Browse shape
if (state.GetMode() == CP_Shape && !state.input[0]
&& key.sym == 'b') {
cheat.shape_browser();
state.input[0] = 'b';
state.activate = true;
}
if (key.sym == SDLK_LEFT || key.sym == SDLK_RIGHT) {
char* end = nullptr;
long value = std::strtol(state.input, &end, 10);
if (state.val_max < state.val_min) {
std::swap(state.val_max, state.val_min);
}
if (end == state.input + strlen(state.input)) {
if (key.sym == SDLK_LEFT && value != state.val_min) {
value = std::max(value - 1, state.val_min);
} else if (
key.sym == SDLK_RIGHT
&& value != state.val_max) {
value = std::min(value + 1, state.val_max);
}
snprintf(
state.input, std::size(state.input) - 1, "%ld",
value);
}
}
// Activate (if possible)
else if (key.sym == SDLK_RETURN || key.sym == SDLK_KP_ENTER) {
state.activate = true;
} else if (
(key.sym == '-' || key.sym == SDLK_KP_MINUS)
&& !state.input[0]) {
state.input[0] = '-';
} else if (
key.sym < 256 && key.sym >= 0
&& std::isdigit(key.sym)) {
const size_t curlen = std::strlen(state.input);
if (curlen < (std::size(state.input) - 1)) {
state.input[curlen] = key.sym;
state.input[curlen + 1] = 0;
}
} else if (
(key.sym >= SDLK_KP_1 && key.sym <= SDLK_KP_9)
|| key.sym == SDLK_KP_0) {
const size_t curlen = std::strlen(state.input);
if (curlen < (std::size(state.input) - 1)) {
const int sym = SDLScanCodeToInt(key.sym);
state.input[curlen] = sym;
state.input[curlen + 1] = 0;
}
} else if (key.sym == SDLK_BACKSPACE) {
const auto curlen = std::strlen(state.input);
if (curlen) {
state.input[curlen - 1] = 0;
}
}
} else {
char c = key.sym;
// Translate arrow key into the characters we use for arrows
switch (key.sym) {
case SDLK_UP: {
c = '^';
} break;
case SDLK_DOWN: {
c = 'V';
} break;
case SDLK_RIGHT: {
c = '>';
} break;
case SDLK_LEFT: {
c = '<';
} break;
default: {
} break;
}
// Set input to the typed character so it is shown with the
// prompt
std::memset(state.input, 0, sizeof(state.input));
state.input[0] = c;
state.input[1] = 0;
if (state.GetMode()) { // Just want a key pressed
state.SetMode(CP_Command, true);
state.command = 0;
} else { // Need the key pressed
state.command = key.sym;
state.highlighttime = SDL_GetTicks() + 1000;
state.highlight = state.command;
return true;
}
}
return false;
}
gwin->rotatecolours();
Mouse::mouse->show(); // Re-display mouse.
if (gwin->show() || Mouse::mouse_update) {
Mouse::mouse->blit_dirty();
}
Mouse::mouse->hide(); // Need to immediately turn off here to prevent
// flickering after repaint of whole screen
}
return false;
}
void CheatScreen::SharedMenu() {
#if defined(__IPHONEOS__) || defined(ANDROID) || defined(TEST_MOBILE)
const int offsetx = 15;
// const int offsety1 = 73;
// const int offsety2 = 55;
// const int offsetx1 = 160;
// const int offsety4 = 36;
const int offsety5 = 72;
#else
const int offsetx = 0;