-
Notifications
You must be signed in to change notification settings - Fork 1
/
ONScripterLabel_event.cpp
1186 lines (1061 loc) · 38.4 KB
/
ONScripterLabel_event.cpp
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
/* -*- C++ -*-
*
* ONScripterLabel_event.cpp - Event handler of ONScripter
*
* Copyright (c) 2001-2007 Ogapee. All rights reserved.
*
*
* 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
*/
#include "ONScripterLabel.h"
#ifdef LINUX
#include <sys/types.h>
#include <sys/wait.h>
#endif
#define ONS_TIMER_EVENT (SDL_USEREVENT)
#define ONS_SOUND_EVENT (SDL_USEREVENT+1)
#define ONS_CDAUDIO_EVENT (SDL_USEREVENT+2)
#define ONS_MIDI_EVENT (SDL_USEREVENT+3)
#define ONS_WAVE_EVENT (SDL_USEREVENT+4)
#define ONS_MUSIC_EVENT (SDL_USEREVENT+5)
// This sets up the fadeout event flag for use in mp3 fadeout. Recommend for integration. [Seung Park, 20060621]
#ifdef INSANI
#define ONS_FADE_EVENT (SDL_USEREVENT+6)
#endif
#define EDIT_MODE_PREFIX "[EDIT MODE] "
#define EDIT_SELECT_STRING "MP3 vol (m) SE vol (s) Voice vol (v) Numeric variable (n)"
static SDL_TimerID timer_id = NULL;
SDL_TimerID timer_cdaudio_id = NULL;
// This block does two things: it sets up the timer id for mp3 fadeout, and it also sets up a timer id for midi looping --
// the reason we have a separate midi loop timer id here is that on Mac OS X, looping midis via SDL will cause SDL itself
// to hard crash after the first play. So, we work around that by manually causing the midis to loop. This OS X midi
// workaround is the work of Ben Carter. Recommend for integration. [Seung Park, 20060621]
#ifdef INSANI
SDL_TimerID timer_mp3fadeout_id = NULL;
#ifdef MACOSX
SDL_TimerID timer_midi_id = NULL;
#endif
#endif
bool ext_music_play_once_flag = false;
extern long decodeOggVorbis(OVInfo *ovi, unsigned char *buf_dst, long len, bool do_rate_conversion);
/* **************************************** *
* Callback functions
* **************************************** */
extern "C" void mp3callback( void *userdata, Uint8 *stream, int len )
{
if ( SMPEG_playAudio( (SMPEG*)userdata, stream, len ) == 0 ){
SDL_Event event;
event.type = ONS_SOUND_EVENT;
SDL_PushEvent(&event);
}
}
extern "C" void oggcallback( void *userdata, Uint8 *stream, int len )
{
if (decodeOggVorbis((OVInfo*)userdata, stream, len, true) == 0){
SDL_Event event;
event.type = ONS_SOUND_EVENT;
SDL_PushEvent(&event);
}
}
extern "C" Uint32 SDLCALL timerCallback( Uint32 interval, void *param )
{
SDL_RemoveTimer( timer_id );
timer_id = NULL;
SDL_Event event;
event.type = ONS_TIMER_EVENT;
SDL_PushEvent( &event );
return interval;
}
extern "C" Uint32 cdaudioCallback( Uint32 interval, void *param )
{
SDL_RemoveTimer( timer_cdaudio_id );
timer_cdaudio_id = NULL;
SDL_Event event;
event.type = ONS_CDAUDIO_EVENT;
SDL_PushEvent( &event );
return interval;
}
// Pushes the mp3 fadeout event onto the stack. Part of our mp3 fadeout enabling patch. Recommend for integration. [Seung Park, 20060621]
#ifdef INSANI
extern "C" Uint32 SDLCALL mp3fadeoutCallback( Uint32 interval, void *param )
{
SDL_Event event;
event.type = ONS_FADE_EVENT;
SDL_PushEvent( &event );
return interval;
}
#endif
/* **************************************** *
* OS Dependent Input Translation
* **************************************** */
SDLKey transKey(SDLKey key)
{
#ifdef IPODLINUX
switch(key){
case SDLK_m: key = SDLK_UP; break; /* Menu */
case SDLK_d: key = SDLK_DOWN; break; /* Play/Pause */
case SDLK_f: key = SDLK_RIGHT; break; /* Fast forward */
case SDLK_w: key = SDLK_LEFT; break; /* Rewind */
case SDLK_RETURN: key = SDLK_RETURN; break; /* Action */
case SDLK_h: key = SDLK_ESCAPE; break; /* Hold */
case SDLK_r: key = SDLK_UNKNOWN; break; /* Wheel clockwise */
case SDLK_l: key = SDLK_UNKNOWN; break; /* Wheel counterclockwise */
default: break;
}
#endif
return key;
}
SDLKey transJoystickButton(Uint8 button)
{
#ifdef PSP
SDLKey button_map[] = { SDLK_ESCAPE, /* TRIANGLE */
SDLK_RETURN, /* CIRCLE */
SDLK_SPACE, /* CROSS */
SDLK_RCTRL, /* SQUARE */
SDLK_o, /* LTRIGGER */
SDLK_s, /* RTRIGGER */
SDLK_DOWN, /* DOWN */
SDLK_LEFT, /* LEFT */
SDLK_UP, /* UP */
SDLK_RIGHT, /* RIGHT */
SDLK_0, /* SELECT */
SDLK_a, /* START */
SDLK_UNKNOWN,/* HOME */ /* kernel mode only */
SDLK_UNKNOWN,/* HOLD */};
return button_map[button];
#endif
return SDLK_UNKNOWN;
}
SDL_KeyboardEvent transJoystickAxis(SDL_JoyAxisEvent &jaxis)
{
static int old_axis=-1;
SDL_KeyboardEvent event;
SDLKey axis_map[] = {SDLK_LEFT, /* AL-LEFT */
SDLK_RIGHT, /* AL-RIGHT */
SDLK_UP, /* AL-UP */
SDLK_DOWN /* AL-DOWN */};
int axis = ((3200 > jaxis.value) && (jaxis.value > -3200) ? -1 :
(jaxis.axis * 2 + (jaxis.value>0 ? 1 : 0) ));
if (axis != old_axis){
if (axis == -1){
event.type = SDL_KEYUP;
event.keysym.sym = axis_map[old_axis];
}
else{
event.type = SDL_KEYDOWN;
event.keysym.sym = axis_map[axis];
}
old_axis = axis;
}
else{
event.keysym.sym = SDLK_UNKNOWN;
}
return event;
}
void ONScripterLabel::flushEventSub( SDL_Event &event )
{
if ( event.type == ONS_SOUND_EVENT ){
if ( music_play_loop_flag ||
(cd_play_loop_flag && !cdaudio_flag ) ){
stopBGM( true );
if (music_file_name)
playSound(music_file_name, SOUND_OGG_STREAMING|SOUND_MP3, true);
else
playCDAudio();
}
else{
stopBGM( false );
}
}
// The event handler for the mp3 fadeout event itself. Simply sets the volume of the mp3 being played lower and lower until it's 0,
// and until the requisite mp3 fadeout time has passed. Recommend for integration. [Seung Park, 20060621]
#ifdef INSANI
else if ( event.type == ONS_FADE_EVENT ){
if (skip_flag || draw_one_page_flag || ctrl_pressed_status || skip_to_wait ) {
mp3fadeout_duration = 0;
if ( mp3_sample ) SMPEG_setvolume( mp3_sample, 0 );
}
Uint32 tmp = SDL_GetTicks() - mp3fadeout_start;
if ( tmp < mp3fadeout_duration ) {
tmp = mp3fadeout_duration - tmp;
tmp *= music_volume;
tmp /= mp3fadeout_duration;
if ( mp3_sample ) SMPEG_setvolume( mp3_sample, tmp );
} else {
SDL_RemoveTimer( timer_mp3fadeout_id );
timer_mp3fadeout_id = NULL;
event_mode &= ~WAIT_TIMER_MODE;
stopBGM( false );
advancePhase();
}
}
#endif
else if ( event.type == ONS_CDAUDIO_EVENT ){
if ( cd_play_loop_flag ){
stopBGM( true );
playCDAudio();
}
else{
stopBGM( false );
}
}
else if ( event.type == ONS_MIDI_EVENT ){
#if defined(MACOSX) && defined(INSANI)
if (!Mix_PlayingMusic())
{
ext_music_play_once_flag = !midi_play_loop_flag;
Mix_FreeMusic( midi_info );
playMIDI(midi_play_loop_flag);
}
#else
ext_music_play_once_flag = !midi_play_loop_flag;
Mix_FreeMusic( midi_info );
playMIDI(midi_play_loop_flag);
#endif
}
else if ( event.type == ONS_MUSIC_EVENT ){
ext_music_play_once_flag = !music_play_loop_flag;
Mix_FreeMusic(music_info);
playExternalMusic(music_play_loop_flag);
}
else if ( event.type == ONS_WAVE_EVENT ){ // for processing btntim2 and automode correctly
if ( wave_sample[event.user.code] ){
Mix_FreeChunk( wave_sample[event.user.code] );
wave_sample[event.user.code] = NULL;
if (event.user.code == MIX_LOOPBGM_CHANNEL0 &&
loop_bgm_name[1] &&
wave_sample[MIX_LOOPBGM_CHANNEL1])
Mix_PlayChannel(MIX_LOOPBGM_CHANNEL1,
wave_sample[MIX_LOOPBGM_CHANNEL1], -1);
}
}
}
void ONScripterLabel::flushEvent()
{
SDL_Event event;
while( SDL_PollEvent( &event ) )
flushEventSub( event );
}
void ONScripterLabel::startTimer( int count )
{
int duration = proceedAnimation();
if ( duration > 0 && duration < count ){
resetRemainingTime( duration );
advancePhase( duration );
remaining_time = count;
}
else{
advancePhase( count );
remaining_time = 0;
}
event_mode |= WAIT_TIMER_MODE;
}
void ONScripterLabel::advancePhase( int count )
{
if ( timer_id != NULL ){
SDL_RemoveTimer( timer_id );
}
if (count > 0){
timer_id = SDL_AddTimer( count, timerCallback, NULL );
if (timer_id != NULL) return;
}
SDL_Event event;
event.type = ONS_TIMER_EVENT;
SDL_PushEvent( &event );
}
void midiCallback( int sig )
{
#ifdef LINUX
int status;
wait( &status );
#endif
if ( !ext_music_play_once_flag ){
SDL_Event event;
event.type = ONS_MIDI_EVENT;
SDL_PushEvent(&event);
}
}
// Pushes the midi loop event onto the stack. Part of a workaround for ONScripter
// crashing in Mac OS X after a midi is looped for the first time. Recommend for
// integration. This is the work of Ben Carter. [Seung Park, 20060621]
#if defined(MACOSX) && defined(INSANI)
extern "C" Uint32 midiSDLCallback( Uint32 interval, void *param )
{
SDL_Event event;
event.type = ONS_MIDI_EVENT;
SDL_PushEvent( &event );
return interval;
}
#endif
extern "C" void waveCallback( int channel )
{
SDL_Event event;
event.type = ONS_WAVE_EVENT;
event.user.code = channel;
SDL_PushEvent(&event);
}
void musicCallback( int sig )
{
#ifdef LINUX
int status;
wait( &status );
#endif
if ( !ext_music_play_once_flag ){
SDL_Event event;
event.type = ONS_MUSIC_EVENT;
SDL_PushEvent(&event);
}
}
void ONScripterLabel::trapHandler()
{
trap_mode = TRAP_NONE;
setCurrentLabel( trap_dist );
readToken();
stopAnimation( clickstr_state );
event_mode = IDLE_EVENT_MODE;
advancePhase();
}
/* **************************************** *
* Event handlers
* **************************************** */
void ONScripterLabel::mouseMoveEvent( SDL_MouseMotionEvent *event )
{
current_button_state.x = event->x;
current_button_state.y = event->y;
if ( event_mode & WAIT_BUTTON_MODE )
mouseOverCheck( current_button_state.x, current_button_state.y );
}
void ONScripterLabel::mousePressEvent( SDL_MouseButtonEvent *event )
{
if ( variable_edit_mode ) return;
if ( automode_flag ){
automode_flag = false;
if (event_mode & (WAIT_TEXT_MODE | WAIT_TEXTOUT_MODE)){
remaining_time = -1;
} else {
remaining_time = 0;
}
return;
}
if ( event->button == SDL_BUTTON_RIGHT &&
trap_mode & TRAP_RIGHT_CLICK ){
trapHandler();
return;
}
else if ( event->button == SDL_BUTTON_LEFT &&
trap_mode & TRAP_LEFT_CLICK ){
trapHandler();
return;
}
current_button_state.x = event->x;
current_button_state.y = event->y;
current_button_state.down_flag = false;
skip_flag = false;
if ( event->button == SDL_BUTTON_RIGHT &&
event->type == SDL_MOUSEBUTTONUP &&
(rmode_flag && event_mode & WAIT_TEXT_MODE ||
event_mode & WAIT_BUTTON_MODE) ){
current_button_state.button = -1;
volatile_button_state.button = -1;
if (event_mode & WAIT_TEXT_MODE){
if (root_rmenu_link.next)
system_menu_mode = SYSTEM_MENU;
else
system_menu_mode = SYSTEM_WINDOWERASE;
}
}
else if ( event->button == SDL_BUTTON_LEFT &&
( event->type == SDL_MOUSEBUTTONUP || btndown_flag ) ){
current_button_state.button = current_over_button;
volatile_button_state.button = current_over_button;
#ifdef INSANI
//fprintf(stderr, "event_mode = %d\n", event_mode);
if ( event_mode & WAIT_TEXTOUT_MODE) {
skip_in_text=1;
}
if ( skip_to_wait ) skip_to_wait=0;
#endif
if ( event->type == SDL_MOUSEBUTTONDOWN )
current_button_state.down_flag = true;
}
#if SDL_VERSION_ATLEAST(1, 2, 5)
else if (event->button == SDL_BUTTON_WHEELUP &&
(event_mode & WAIT_TEXT_MODE ||
usewheel_flag && event_mode & WAIT_BUTTON_MODE ||
system_menu_mode == SYSTEM_LOOKBACK)){
current_button_state.button = -2;
volatile_button_state.button = -2;
if (event_mode & WAIT_TEXT_MODE) system_menu_mode = SYSTEM_LOOKBACK;
}
else if ( event->button == SDL_BUTTON_WHEELDOWN &&
(enable_wheeldown_advance_flag && event_mode & WAIT_TEXT_MODE ||
usewheel_flag && event_mode & WAIT_BUTTON_MODE||
system_menu_mode == SYSTEM_LOOKBACK ) ){
if (event_mode & WAIT_TEXT_MODE){
current_button_state.button = 0;
volatile_button_state.button = 0;
}
else{
current_button_state.button = -3;
volatile_button_state.button = -3;
}
}
#endif
else return;
if (event_mode & (WAIT_INPUT_MODE | WAIT_BUTTON_MODE)){
playClickVoice();
stopAnimation( clickstr_state );
advancePhase();
}
}
void ONScripterLabel::variableEditMode( SDL_KeyboardEvent *event )
{
int i;
char *var_name, var_index[12];
switch ( event->keysym.sym ) {
case SDLK_m:
if ( variable_edit_mode != EDIT_SELECT_MODE ) return;
variable_edit_mode = EDIT_MP3_VOLUME_MODE;
variable_edit_num = music_volume;
break;
case SDLK_s:
if ( variable_edit_mode != EDIT_SELECT_MODE ) return;
variable_edit_mode = EDIT_SE_VOLUME_MODE;
variable_edit_num = se_volume;
break;
case SDLK_v:
if ( variable_edit_mode != EDIT_SELECT_MODE ) return;
variable_edit_mode = EDIT_VOICE_VOLUME_MODE;
variable_edit_num = voice_volume;
break;
case SDLK_n:
if ( variable_edit_mode != EDIT_SELECT_MODE ) return;
variable_edit_mode = EDIT_VARIABLE_INDEX_MODE;
variable_edit_num = 0;
break;
case SDLK_9: case SDLK_KP9: variable_edit_num = variable_edit_num * 10 + 9; break;
case SDLK_8: case SDLK_KP8: variable_edit_num = variable_edit_num * 10 + 8; break;
case SDLK_7: case SDLK_KP7: variable_edit_num = variable_edit_num * 10 + 7; break;
case SDLK_6: case SDLK_KP6: variable_edit_num = variable_edit_num * 10 + 6; break;
case SDLK_5: case SDLK_KP5: variable_edit_num = variable_edit_num * 10 + 5; break;
case SDLK_4: case SDLK_KP4: variable_edit_num = variable_edit_num * 10 + 4; break;
case SDLK_3: case SDLK_KP3: variable_edit_num = variable_edit_num * 10 + 3; break;
case SDLK_2: case SDLK_KP2: variable_edit_num = variable_edit_num * 10 + 2; break;
case SDLK_1: case SDLK_KP1: variable_edit_num = variable_edit_num * 10 + 1; break;
case SDLK_0: case SDLK_KP0: variable_edit_num = variable_edit_num * 10 + 0; break;
case SDLK_MINUS: case SDLK_KP_MINUS:
if ( variable_edit_mode == EDIT_VARIABLE_NUM_MODE && variable_edit_num == 0 ) variable_edit_sign = -1;
break;
case SDLK_BACKSPACE:
if ( variable_edit_num ) variable_edit_num /= 10;
else if ( variable_edit_sign == -1 ) variable_edit_sign = 1;
break;
case SDLK_RETURN: case SDLK_KP_ENTER:
switch( variable_edit_mode ){
case EDIT_VARIABLE_INDEX_MODE:
variable_edit_index = variable_edit_num;
variable_edit_num = script_h.variable_data[ variable_edit_index ].num;
if ( variable_edit_num < 0 ){
variable_edit_num = -variable_edit_num;
variable_edit_sign = -1;
}
else{
variable_edit_sign = 1;
}
break;
case EDIT_VARIABLE_NUM_MODE:
script_h.setNumVariable( variable_edit_index, variable_edit_sign * variable_edit_num );
break;
case EDIT_MP3_VOLUME_MODE:
music_volume = variable_edit_num;
if ( mp3_sample ) SMPEG_setvolume( mp3_sample, music_volume );
break;
case EDIT_SE_VOLUME_MODE:
se_volume = variable_edit_num;
for ( i=1 ; i<ONS_MIX_CHANNELS ; i++ )
if ( wave_sample[i] ) Mix_Volume( i, se_volume * 128 / 100 );
if ( wave_sample[MIX_LOOPBGM_CHANNEL0] ) Mix_Volume( MIX_LOOPBGM_CHANNEL0, se_volume * 128 / 100 );
if ( wave_sample[MIX_LOOPBGM_CHANNEL1] ) Mix_Volume( MIX_LOOPBGM_CHANNEL1, se_volume * 128 / 100 );
break;
case EDIT_VOICE_VOLUME_MODE:
voice_volume = variable_edit_num;
if ( wave_sample[0] ) Mix_Volume( 0, se_volume * 128 / 100 );
default:
break;
}
if ( variable_edit_mode == EDIT_VARIABLE_INDEX_MODE )
variable_edit_mode = EDIT_VARIABLE_NUM_MODE;
else
variable_edit_mode = EDIT_SELECT_MODE;
break;
case SDLK_ESCAPE:
if ( variable_edit_mode == EDIT_SELECT_MODE ){
variable_edit_mode = NOT_EDIT_MODE;
SDL_WM_SetCaption( DEFAULT_WM_TITLE, DEFAULT_WM_ICON );
SDL_Delay( 100 );
SDL_WM_SetCaption( wm_title_string, wm_icon_string );
return;
}
variable_edit_mode = EDIT_SELECT_MODE;
default:
break;
}
if ( variable_edit_mode == EDIT_SELECT_MODE ){
sprintf( wm_edit_string, "%s%s", EDIT_MODE_PREFIX, EDIT_SELECT_STRING );
}
else if ( variable_edit_mode == EDIT_VARIABLE_INDEX_MODE ) {
sprintf( wm_edit_string, "%s%s%d", EDIT_MODE_PREFIX, "Variable Index? %", variable_edit_sign * variable_edit_num );
}
else if ( variable_edit_mode >= EDIT_VARIABLE_NUM_MODE ){
int p=0;
switch( variable_edit_mode ){
case EDIT_VARIABLE_NUM_MODE:
sprintf( var_index, "%%%d", variable_edit_index );
var_name = var_index; p = script_h.variable_data[ variable_edit_index ].num; break;
case EDIT_MP3_VOLUME_MODE:
var_name = "MP3 Volume"; p = music_volume; break;
case EDIT_VOICE_VOLUME_MODE:
var_name = "Voice Volume"; p = voice_volume; break;
case EDIT_SE_VOLUME_MODE:
var_name = "Sound effect Volume"; p = se_volume; break;
default:
var_name = "";
}
sprintf( wm_edit_string, "%sCurrent %s=%d New value? %s%d",
EDIT_MODE_PREFIX, var_name, p, (variable_edit_sign==1)?"":"-", variable_edit_num );
}
SDL_WM_SetCaption( wm_edit_string, wm_icon_string );
}
void ONScripterLabel::shiftCursorOnButton( int diff )
{
int num = 0;
ButtonLink *button = root_button_link.next;
while (button) { button = button->next; ++num; }
shortcut_mouse_line += diff;
if (shortcut_mouse_line < 0) shortcut_mouse_line = num - 1;
else if (shortcut_mouse_line >= num) shortcut_mouse_line = 0;
button = root_button_link.next;
for (int i = 0; i < shortcut_mouse_line; ++i) button = button->next;
if (button) {
int x = button->select_rect.x;
int y = button->select_rect.y;
if (x < 0) x = 0;
else if (x >= screen_width) x = screen_width - 1;
if (y < 0) y = 0;
else if (y >= screen_height) y = screen_height - 1;
SDL_WarpMouse(x, y);
}
}
void ONScripterLabel::keyDownEvent( SDL_KeyboardEvent *event )
{
switch ( event->keysym.sym ) {
case SDLK_RCTRL:
ctrl_pressed_status |= 0x01;
goto ctrl_pressed;
case SDLK_LCTRL:
ctrl_pressed_status |= 0x02;
goto ctrl_pressed;
case SDLK_RSHIFT:
shift_pressed_status |= 0x01;
break;
case SDLK_LSHIFT:
shift_pressed_status |= 0x02;
break;
default:
break;
}
return;
ctrl_pressed:
current_button_state.button = 0;
volatile_button_state.button = 0;
playClickVoice();
stopAnimation( clickstr_state );
advancePhase();
return;
}
void ONScripterLabel::keyUpEvent( SDL_KeyboardEvent *event )
{
switch ( event->keysym.sym ) {
case SDLK_RCTRL:
ctrl_pressed_status &= ~0x01;
break;
case SDLK_LCTRL:
ctrl_pressed_status &= ~0x02;
break;
case SDLK_RSHIFT:
shift_pressed_status &= ~0x01;
break;
case SDLK_LSHIFT:
shift_pressed_status &= ~0x02;
break;
default:
break;
}
}
void ONScripterLabel::keyPressEvent( SDL_KeyboardEvent *event )
{
current_button_state.button = 0;
current_button_state.down_flag = false;
if ( automode_flag ){
automode_flag = false;
if (event_mode & (WAIT_TEXT_MODE | WAIT_TEXTOUT_MODE)){
remaining_time = -1;
} else {
remaining_time = 0;
}
return;
}
if ( event->type == SDL_KEYUP ){
if ( variable_edit_mode ){
variableEditMode( event );
return;
}
if ( edit_flag && event->keysym.sym == SDLK_z ){
variable_edit_mode = EDIT_SELECT_MODE;
variable_edit_sign = 1;
variable_edit_num = 0;
sprintf( wm_edit_string, "%s%s", EDIT_MODE_PREFIX, EDIT_SELECT_STRING );
SDL_WM_SetCaption( wm_edit_string, wm_icon_string );
}
}
if (event->type == SDL_KEYUP &&
(event->keysym.sym == SDLK_RETURN ||
event->keysym.sym == SDLK_KP_ENTER ||
event->keysym.sym == SDLK_SPACE ||
event->keysym.sym == SDLK_s))
skip_flag = false;
if ( shift_pressed_status && event->keysym.sym == SDLK_q && current_mode == NORMAL_MODE ){
endCommand();
}
if ( (trap_mode & TRAP_LEFT_CLICK) &&
(event->keysym.sym == SDLK_RETURN ||
event->keysym.sym == SDLK_KP_ENTER ||
event->keysym.sym == SDLK_SPACE ) ){
trapHandler();
return;
}
else if ( (trap_mode & TRAP_RIGHT_CLICK) &&
(event->keysym.sym == SDLK_ESCAPE) ){
trapHandler();
return;
}
if ( event_mode & WAIT_BUTTON_MODE &&
((event->type == SDL_KEYUP || btndown_flag) &&
(!getenter_flag && event->keysym.sym == SDLK_RETURN ||
!getenter_flag && event->keysym.sym == SDLK_KP_ENTER ) ||
(spclclk_flag || !useescspc_flag) && event->keysym.sym == SDLK_SPACE) ){
if ( event->keysym.sym == SDLK_RETURN ||
event->keysym.sym == SDLK_KP_ENTER ||
spclclk_flag && event->keysym.sym == SDLK_SPACE ){
current_button_state.button = current_over_button;
volatile_button_state.button = current_over_button;
if ( event->type == SDL_KEYDOWN )
current_button_state.down_flag = true;
}
else{
current_button_state.button = 0;
volatile_button_state.button = 0;
}
playClickVoice();
stopAnimation( clickstr_state );
advancePhase();
return;
}
if ( event->type == SDL_KEYDOWN ) return;
if ( ( event_mode & (WAIT_INPUT_MODE | WAIT_BUTTON_MODE) ) &&
( autoclick_time == 0 || (event_mode & WAIT_BUTTON_MODE)) ){
if ( !useescspc_flag && event->keysym.sym == SDLK_ESCAPE){
current_button_state.button = -1;
if (rmode_flag && event_mode & WAIT_TEXT_MODE){
if (root_rmenu_link.next)
system_menu_mode = SYSTEM_MENU;
else
system_menu_mode = SYSTEM_WINDOWERASE;
}
}
else if ( useescspc_flag && event->keysym.sym == SDLK_ESCAPE ){
current_button_state.button = -10;
}
else if ( !spclclk_flag && useescspc_flag && event->keysym.sym == SDLK_SPACE ){
current_button_state.button = -11;
}
else if ((!getcursor_flag && event->keysym.sym == SDLK_LEFT ||
event->keysym.sym == SDLK_h) &&
(event_mode & WAIT_TEXT_MODE ||
usewheel_flag && !getcursor_flag && event_mode & WAIT_BUTTON_MODE ||
system_menu_mode == SYSTEM_LOOKBACK)){
current_button_state.button = -2;
volatile_button_state.button = -2;
if (event_mode & WAIT_TEXT_MODE) system_menu_mode = SYSTEM_LOOKBACK;
}
else if ((!getcursor_flag && event->keysym.sym == SDLK_RIGHT ||
event->keysym.sym == SDLK_l) &&
(enable_wheeldown_advance_flag && event_mode & WAIT_TEXT_MODE ||
usewheel_flag && event_mode & WAIT_BUTTON_MODE||
system_menu_mode == SYSTEM_LOOKBACK)){
if (event_mode & WAIT_TEXT_MODE){
current_button_state.button = 0;
volatile_button_state.button = 0;
}
else{
current_button_state.button = -3;
volatile_button_state.button = -3;
}
}
else if ((!getcursor_flag && event->keysym.sym == SDLK_UP ||
event->keysym.sym == SDLK_k ||
event->keysym.sym == SDLK_p) &&
event_mode & WAIT_BUTTON_MODE){
shiftCursorOnButton(1);
return;
}
else if ((!getcursor_flag && event->keysym.sym == SDLK_DOWN ||
event->keysym.sym == SDLK_j ||
event->keysym.sym == SDLK_n) &&
event_mode & WAIT_BUTTON_MODE){
shiftCursorOnButton(-1);
return;
}
else if ( getpageup_flag && event->keysym.sym == SDLK_PAGEUP ){
current_button_state.button = -12;
}
else if ( getpagedown_flag && event->keysym.sym == SDLK_PAGEDOWN ){
current_button_state.button = -13;
}
else if ( getenter_flag && event->keysym.sym == SDLK_RETURN ||
getenter_flag && event->keysym.sym == SDLK_KP_ENTER ){
current_button_state.button = -19;
}
else if ( gettab_flag && event->keysym.sym == SDLK_TAB ){
current_button_state.button = -20;
}
else if ( getcursor_flag && event->keysym.sym == SDLK_UP ){
current_button_state.button = -40;
}
else if ( getcursor_flag && event->keysym.sym == SDLK_RIGHT ){
current_button_state.button = -41;
}
else if ( getcursor_flag && event->keysym.sym == SDLK_DOWN ){
current_button_state.button = -42;
}
else if ( getcursor_flag && event->keysym.sym == SDLK_LEFT ){
current_button_state.button = -43;
}
else if ( getinsert_flag && event->keysym.sym == SDLK_INSERT ){
current_button_state.button = -50;
}
else if ( getzxc_flag && event->keysym.sym == SDLK_z ){
current_button_state.button = -51;
}
else if ( getzxc_flag && event->keysym.sym == SDLK_x ){
current_button_state.button = -52;
}
else if ( getzxc_flag && event->keysym.sym == SDLK_c ){
current_button_state.button = -53;
}
else if ( getfunction_flag ){
if ( event->keysym.sym == SDLK_F1 )
current_button_state.button = -21;
else if ( event->keysym.sym == SDLK_F2 )
current_button_state.button = -22;
else if ( event->keysym.sym == SDLK_F3 )
current_button_state.button = -23;
else if ( event->keysym.sym == SDLK_F4 )
current_button_state.button = -24;
else if ( event->keysym.sym == SDLK_F5 )
current_button_state.button = -25;
else if ( event->keysym.sym == SDLK_F6 )
current_button_state.button = -26;
else if ( event->keysym.sym == SDLK_F7 )
current_button_state.button = -27;
else if ( event->keysym.sym == SDLK_F8 )
current_button_state.button = -28;
else if ( event->keysym.sym == SDLK_F9 )
current_button_state.button = -29;
else if ( event->keysym.sym == SDLK_F10 )
current_button_state.button = -30;
else if ( event->keysym.sym == SDLK_F11 )
current_button_state.button = -31;
else if ( event->keysym.sym == SDLK_F12 )
current_button_state.button = -32;
}
if ( current_button_state.button != 0 ){
volatile_button_state.button = current_button_state.button;
stopAnimation( clickstr_state );
advancePhase();
return;
}
}
if ( event_mode & WAIT_INPUT_MODE && !key_pressed_flag &&
( autoclick_time == 0 || (event_mode & WAIT_BUTTON_MODE)) ){
if (event->keysym.sym == SDLK_RETURN ||
event->keysym.sym == SDLK_KP_ENTER ||
event->keysym.sym == SDLK_SPACE ){
key_pressed_flag = true;
playClickVoice();
stopAnimation( clickstr_state );
advancePhase();
}
}
if ( event_mode & (WAIT_INPUT_MODE | WAIT_TEXTBTN_MODE) &&
!key_pressed_flag ){
if (event->keysym.sym == SDLK_s && !automode_flag ){
skip_flag = true;
printf("toggle skip to true\n");
key_pressed_flag = true;
stopAnimation( clickstr_state );
advancePhase();
}
else if (event->keysym.sym == SDLK_o){
draw_one_page_flag = !draw_one_page_flag;
printf("toggle draw one page flag to %s\n", (draw_one_page_flag?"true":"false") );
if ( draw_one_page_flag ){
stopAnimation( clickstr_state );
advancePhase();
}
}
else if ( event->keysym.sym == SDLK_a && mode_ext_flag && !automode_flag ){
automode_flag = true;
skip_flag = false;
printf("change to automode\n");
key_pressed_flag = true;
stopAnimation( clickstr_state );
advancePhase();
}
else if ( event->keysym.sym == SDLK_0 ){
if (++text_speed_no > 2) text_speed_no = 0;
sentence_font.wait_time = -1;
}
else if ( event->keysym.sym == SDLK_1 ){
text_speed_no = 0;
sentence_font.wait_time = -1;
}
else if ( event->keysym.sym == SDLK_2 ){
text_speed_no = 1;
sentence_font.wait_time = -1;
}
else if ( event->keysym.sym == SDLK_3 ){
text_speed_no = 2;
sentence_font.wait_time = -1;
}
}
if ( event_mode & ( WAIT_INPUT_MODE | WAIT_BUTTON_MODE ) ){
if ( event->keysym.sym == SDLK_f ){
if ( fullscreen_mode ) menu_windowCommand();
else menu_fullCommand();
}
}
#ifdef INSANI
if ( event_mode & WAIT_SLEEP_MODE) {
if (event->keysym.sym == SDLK_s )
{
skip_to_wait = 1;
skip_flag = false;
key_pressed_flag = true;
}
}
if (skip_to_wait == 1 &&
(event->keysym.sym == SDLK_RETURN ||
event->keysym.sym == SDLK_KP_ENTER ||
event->keysym.sym == SDLK_SPACE )) {
skip_to_wait = 0;
key_pressed_flag = true;
}
#endif
}
void ONScripterLabel::timerEvent( void )
{
timerEventTop:
int ret;
if ( event_mode & WAIT_TIMER_MODE ){
int duration = proceedAnimation();
if ( duration == 0 ||
( remaining_time >= 0 &&
remaining_time-duration <= 0 ) ){
bool end_flag = true;
bool loop_flag = false;
if ( remaining_time >= 0 ){
remaining_time = -1;
if ( event_mode & WAIT_VOICE_MODE && wave_sample[0] ){
end_flag = false;
if ( duration > 0 ){
resetRemainingTime( duration );
advancePhase( duration );
}
}
else{