-
Notifications
You must be signed in to change notification settings - Fork 0
/
ONScripterLabel_command.cpp
4547 lines (3753 loc) · 125 KB
/
ONScripterLabel_command.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_command.cpp - Command executer of ONScripter-EN
*
* Copyright (c) 2001-2011 Ogapee. All rights reserved.
* (original ONScripter, of which this is a fork).
*
* ogapee@aqua.dti2.ne.jp
*
* Copyright (c) 2007-2011 "Uncle" Mion Sonozaki
*
* UncleMion@gmail.com
*
* 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, see <http://www.gnu.org/licenses/>
* or write to the Free Software Foundation, Inc.,
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include "ONScripterLabel.h"
#include "graphics_resize.h"
#include "version.h"
#include <cstdio>
#include <sys/stat.h>
#include <sys/types.h>
#include <string.h>
#include <errno.h>
#ifdef WIN32
#include <direct.h>
#include <windows.h>
#include "SDL_syswm.h"
#endif
#ifdef MACOSX
#include "cocoa_url.h"
#include "cocoa_encoding.h"
#include "cocoa_alertbox.h"
#endif
#ifdef LINUX
#include <sys/wait.h>
#include <unistd.h>
#include <errno.h>
#endif
#define DEFAULT_CURSOR_WAIT ":l/3,160,2;cursor0.bmp"
#define DEFAULT_CURSOR_NEWPAGE ":l/3,160,2;cursor1.bmp"
#define CONTINUOUS_PLAY
extern SDL_TimerID timer_bgmfade_id;
extern "C" Uint32 SDLCALL bgmfadeCallback( Uint32 interval, void *param );
int ONScripterLabel::yesnoboxCommand()
{
//Mion: Currently we only support dialog boxes on Windows and Mac OS X.
// Any ideas on making dialog boxes for Linux etc.?
#if !defined(MACOSX) && !(defined(WIN32) && defined(USE_MESSAGEBOX))
if (!answer_dialog_with_yes_ok)
return RET_NOMATCH;
#endif
bool is_yesnobox = false;
if (script_h.isName( "yesnobox" )){
fprintf(stderr,"yesnobox: ");
is_yesnobox = true;
}
else if (script_h.isName( "okcancelbox" ))
fprintf(stderr,"okcancelbox: ");
script_h.readVariable();
script_h.pushVariable();
const char *buf = script_h.readStr();
char *msg = new char[strlen(buf)+1];
sprintf(msg,"%s",buf);
const char *title = script_h.readStr();
int res = 1;
if(!answer_dialog_with_yes_ok) {
//The OS X dialog box routines are crashing when in fullscreen mode,
//so let's switch to windowed mode just in case
menu_windowCommand();
#if defined(MACOSX)
bool selectedYes;
if(is_yesnobox) {
selectedYes = ONSCocoa::choicebox(title, msg, "Yes", "No", ONSCocoa::ENC_SJIS);
} else {
selectedYes = ONSCocoa::choicebox(title, msg, "OK", "Cancel", ONSCocoa::ENC_SJIS);
}
res = selectedYes ? 1 : 0;
#elif defined(WIN32) && defined(USE_MESSAGEBOX)
UINT mb_type = MB_OKCANCEL;
if (is_yesnobox)
mb_type = MB_YESNO;
HWND pwin = NULL;
SDL_SysWMinfo info;
SDL_VERSION(&info.version);
if (SDL_GetWMInfo(&info) == 1)
pwin = info.window;
res = MessageBox(pwin, msg, title, mb_type);
res = ((res == IDYES) || (res == IDOK)) ? 1 : 0;
#endif
}
script_h.setInt( &script_h.pushed_variable, res );
fprintf(stderr,"Got dialog '%s': '%s', returned value of %d\n",
title, msg, res);
delete[] msg;
return RET_CONTINUE;
}
int ONScripterLabel::waveCommand()
{
wave_play_loop_flag = false;
if (script_h.isName( "waveloop" ))
wave_play_loop_flag = true;
wavestopCommand();
setStr(&wave_file_name, script_h.readStr());
playSound(wave_file_name, SOUND_WAVE|SOUND_OGG, wave_play_loop_flag, MIX_WAVE_CHANNEL);
return RET_CONTINUE;
}
int ONScripterLabel::wavestopCommand()
{
if ( audio_open_flag && wave_sample[MIX_WAVE_CHANNEL] ){
Mix_Pause( MIX_WAVE_CHANNEL );
Mix_FreeChunk( wave_sample[MIX_WAVE_CHANNEL] );
wave_sample[MIX_WAVE_CHANNEL] = NULL;
}
setStr( &wave_file_name, NULL );
return RET_CONTINUE;
}
int ONScripterLabel::waittimerCommand()
{
int count = script_h.readInt() + internal_timer - SDL_GetTicks();
if (count < 0) count = 0;
event_mode = WAIT_TIMER_MODE;
waitEvent( count );
return RET_CONTINUE;
}
int ONScripterLabel::waitCommand()
{
//using insani's skippable wait concept (modified)
int count = script_h.readInt();
if( (skip_mode & (SKIP_NORMAL | SKIP_TO_WAIT)) || ctrl_pressed_status ) {
//Mion: instead of skipping entirely, let's do a shortened wait (safer)
if (count > 100) {
count = count / 10;
} else if (count > 10) {
count = 10;
}
}
if (count < 0) count = 0;
event_mode = WAIT_TIMER_MODE | WAIT_SLEEP_MODE;
waitEvent( count );
return RET_CONTINUE;
}
int ONScripterLabel::vspCommand()
{
leaveTextDisplayMode();
bool vsp2_flag = false;
if (script_h.isName("vsp2")) vsp2_flag = true;
int no = script_h.readInt();
int v = script_h.readInt();
bool visible = (v==1);
if (vsp2_flag){
if (sprite2_info[ no ].image_surface &&
(visible != sprite2_info[ no ].visible))
dirty_rect.add( sprite2_info[no].bounding_rect );
sprite2_info[ no ].visible = visible;
}
else {
if (sprite_info[ no ].image_surface &&
(visible != sprite_info[ no ].visible))
dirty_rect.add( sprite_info[no].pos );
sprite_info[ no ].visible = visible;
if ((v==0) && sprite_info[ no ].is_animatable){
sprite_info[ no ].current_cell = 0;
sprite_info[ no ].direction = 1;
}
}
return RET_CONTINUE;
}
int ONScripterLabel::voicevolCommand()
{
voice_volume = script_h.readInt();
if ( wave_sample[0] )
Mix_Volume( 0, !volume_on_flag? 0 : voice_volume * 128 / 100 );
channelvolumes[0] = voice_volume;
return RET_CONTINUE;
}
int ONScripterLabel::vCommand()
{
char buf[256];
sprintf(buf, "voice%c%s.wav", DELIMITER, script_h.getStringBuffer()+1);
playSound(buf, SOUND_WAVE|SOUND_OGG, false, MIX_WAVE_CHANNEL);
return RET_CONTINUE;
}
int ONScripterLabel::trapCommand()
{
if ( script_h.isName( "lr_trap" ) ){
trap_mode = TRAP_LEFT_CLICK | TRAP_RIGHT_CLICK;
}
else if ( script_h.isName( "r_trap" ) ){
trap_mode = TRAP_RIGHT_CLICK;
}
else if ( script_h.isName( "trap" ) ){
trap_mode = TRAP_LEFT_CLICK;
}
else{
printf("trapCommand: cmd [%s] not recognized\n", script_h.getStringBuffer() );
trap_mode = TRAP_NONE;
return RET_CONTINUE;
}
if ( script_h.compareString("off") ){
script_h.readName();
trap_mode = TRAP_NONE;
return RET_CONTINUE;
}
const char *buf = script_h.readLabel();
if ( buf[0] == '*' ){
setStr(&trap_dest, buf+1);
}
else{
printf("trapCommand: [%s] is not supported\n", buf );
}
return RET_CONTINUE;
}
int ONScripterLabel::transbtnCommand()
{
transbtn_flag = true;
return RET_CONTINUE;
}
int ONScripterLabel::textspeeddefaultCommand()
{
sentence_font.wait_time = -1;
return RET_CONTINUE;
}
int ONScripterLabel::textspeedCommand()
{
sentence_font.wait_time = script_h.readInt();
return RET_CONTINUE;
}
int ONScripterLabel::textshowCommand()
{
dirty_rect.fill( screen_width, screen_height );
refresh_window_text_mode = REFRESH_NORMAL_MODE | REFRESH_WINDOW_MODE | REFRESH_TEXT_MODE;
if (!setEffect(&window_effect, true, false))
while(doEffect(&window_effect, false));
return RET_CONTINUE;
}
int ONScripterLabel::textonCommand()
{
if (windowchip_sprite_no >= 0)
sprite_info[windowchip_sprite_no].visible = true;
enterTextDisplayMode();
text_on_flag = true;
return RET_CONTINUE;
}
int ONScripterLabel::textoffCommand()
{
if (windowchip_sprite_no >= 0)
sprite_info[windowchip_sprite_no].visible = false;
leaveTextDisplayMode(true);
refreshSurface(backup_surface, NULL, REFRESH_NORMAL_MODE);
text_on_flag = false;
return RET_CONTINUE;
}
int ONScripterLabel::texthideCommand()
{
dirty_rect.fill( screen_width, screen_height );
refresh_window_text_mode = REFRESH_NORMAL_MODE | REFRESH_WINDOW_MODE;
if (!setEffect(&window_effect, true, true))
while(doEffect(&window_effect, false));
return RET_CONTINUE;
}
int ONScripterLabel::textexbtnCommand()
{
int txtbtn_no = script_h.readInt();
const char *buf = script_h.readStr();
TextButtonInfoLink *info = text_button_info.next;
TextButtonInfoLink *found = NULL;
while (info) {
if (info->no == txtbtn_no)
found = info;
info = info->next;
}
if (found) {
ButtonLink *button = found->button;
while (button) {
button->exbtn_ctl = new char[ strlen( buf ) + 1 ];
strcpy( button->exbtn_ctl, buf );
button = button->same;
}
}
is_exbtn_enabled = true;
return RET_CONTINUE;
}
int ONScripterLabel::textclearCommand()
{
newPage( false );
return RET_CONTINUE;
}
int ONScripterLabel::textbtnstartCommand()
{
txtbtn_start_num = script_h.readInt();
return RET_CONTINUE;
}
int ONScripterLabel::textbtnoffCommand()
{
txtbtn_show = false;
return RET_CONTINUE;
}
int ONScripterLabel::texecCommand()
{
if ( textgosub_clickstr_state == CLICK_NEWPAGE ){
newPage( true );
clickstr_state = CLICK_NONE;
}
else if ( textgosub_clickstr_state == CLICK_WAITEOL ){
if ( !sentence_font.isLineEmpty() && !new_line_skip_flag ){
indent_offset = 0;
line_enter_status = 0;
current_page->add( 0x0a );
sentence_font.newLine();
}
}
return RET_CONTINUE;
}
int ONScripterLabel::tateyokoCommand()
{
int mode = script_h.readInt();
//don't perform this command while in a textgosub
bool in_textgosub = false;
if (textgosub_label) {
NestInfo *tmp_nest = last_nest_info;
while (tmp_nest) {
if (tmp_nest->textgosub_flag) {
in_textgosub = true;
break;
}
tmp_nest = tmp_nest->previous;
}
}
if (!in_textgosub)
sentence_font.setTateyokoMode( mode );
else
fprintf(stderr, "tateyoko: in textgosub, ignoring\n");
return RET_CONTINUE;
}
int ONScripterLabel::talCommand()
{
leaveTextDisplayMode();
char loc = script_h.readName()[0];
int no = -1, trans = 0;
if ( loc == 'l' ) no = 0;
else if ( loc == 'c' ) no = 1;
else if ( loc == 'r' ) no = 2;
if (no >= 0){
trans = script_h.readInt();
if (trans > 256) trans = 256;
else if (trans < 0 ) trans = 0;
tachi_info[ no ].trans = trans;
dirty_rect.add( tachi_info[ no ].pos );
}
EffectLink *el = parseEffect(true);
if (setEffect(el, true, true)) return RET_CONTINUE;
while (doEffect(el));
return RET_CONTINUE;
}
int ONScripterLabel::tablegotoCommand()
{
int count = 0;
int no = script_h.readInt();
while( script_h.getEndStatus() & ScriptHandler::END_COMMA ){
const char *buf = script_h.readLabel();
if ( count++ == no ){
setCurrentLabel( buf+1 );
break;
}
}
return RET_CONTINUE;
}
int ONScripterLabel::systemcallCommand()
{
system_menu_mode = getSystemCallNo( script_h.readName() );
//if (!rgosub_label)
executeSystemCall();
system_menu_mode = SYSTEM_NULL;
return RET_CONTINUE;
}
int ONScripterLabel::strspCommand()
{
leaveTextDisplayMode();
bool v=true;
if ( script_h.isName( "strsph" ) )
v = false;
int sprite_no = script_h.readInt();
AnimationInfo *ai = &sprite_info[sprite_no];
if ( ai->image_surface && ai->visible )
dirty_rect.add( ai->pos );
ai->remove();
setStr(&ai->file_name, script_h.readStr());
Fontinfo fi;
fi.is_newline_accepted = true;
ai->orig_pos.x = script_h.readInt();
ai->orig_pos.y = script_h.readInt();
UpdateAnimPosStretchXY(ai);
fi.num_xy[0] = script_h.readInt();
fi.num_xy[1] = script_h.readInt();
fi.font_size_xy[0] = script_h.readInt();
fi.font_size_xy[1] = script_h.readInt();
fi.pitch_xy[0] = script_h.readInt() + fi.font_size_xy[0];
fi.pitch_xy[1] = script_h.readInt() + fi.font_size_xy[1];
fi.is_bold = script_h.readInt()?true:false;
fi.is_shadow = script_h.readInt()?true:false;
char *buffer = script_h.getNext();
while(script_h.getEndStatus() & ScriptHandler::END_COMMA){
ai->num_of_cells++;
script_h.readStr();
}
if (ai->num_of_cells == 0){
ai->num_of_cells = 1;
ai->color_list = new uchar3[ai->num_of_cells];
ai->color_list[0][0] = ai->color_list[0][1] = ai->color_list[0][2] = 0xff;
}
else{
ai->color_list = new uchar3[ai->num_of_cells];
script_h.setCurrent(buffer);
for (int i=0 ; i<ai->num_of_cells ; i++)
readColor(&ai->color_list[i], readColorStr());
}
ai->trans_mode = AnimationInfo::TRANS_STRING;
ai->trans = 256;
ai->visible = v;
ai->is_single_line = false;
ai->is_tight_region = false;
setupAnimationInfo(ai, &fi);
if ( ai->visible )
dirty_rect.add( ai->pos );
return RET_CONTINUE;
}
int ONScripterLabel::stopCommand()
{
wavestopCommand();
//NScr doesn't stop loopbgm w/this cmd
return mp3stopCommand();
}
int ONScripterLabel::sp_rgb_gradationCommand()
{
leaveTextDisplayMode();
int no = script_h.readInt();
int upper_r = script_h.readInt();
int upper_g = script_h.readInt();
int upper_b = script_h.readInt();
int lower_r = script_h.readInt();
int lower_g = script_h.readInt();
int lower_b = script_h.readInt();
ONSBuf key_r = script_h.readInt();
ONSBuf key_g = script_h.readInt();
ONSBuf key_b = script_h.readInt();
Uint32 alpha = script_h.readInt();
AnimationInfo *si;
if (no == -1) si = &sentence_font_info;
else si = &sprite_info[no];
SDL_Surface *surface = si->image_surface;
if (surface == NULL) return RET_CONTINUE; //FIXME: alloc image instead?
SDL_PixelFormat *fmt = surface->format;
ONSBuf key_mask = (key_r >> fmt->Rloss) << fmt->Rshift |
(key_g >> fmt->Gloss) << fmt->Gshift |
(key_b >> fmt->Bloss) << fmt->Bshift;
ONSBuf rgb_mask = fmt->Rmask | fmt->Gmask | fmt->Bmask;
SDL_LockSurface(surface);
// check upper and lower bound
int i, j;
int upper_bound=0, lower_bound=0;
bool is_key_found = false;
for (i=0 ; i<surface->h ; i++){
ONSBuf *buf = (ONSBuf *)surface->pixels + surface->w * i;
for (j=0 ; j<surface->w ; j++, buf++){
if ((*buf & rgb_mask) == key_mask){
if (is_key_found == false){
is_key_found = true;
upper_bound = lower_bound = i;
}
else{
lower_bound = i;
}
break;
}
}
}
// replace pixels of the key-color with the specified color in gradation
for (i=upper_bound ; i<=lower_bound ; i++){
ONSBuf *buf = (ONSBuf *)surface->pixels + surface->w * i;
#ifdef BPP16
unsigned char *alphap = si->alpha_buf + surface->w * i;
#else
#if SDL_BYTEORDER == SDL_LIL_ENDIAN
unsigned char *alphap = (unsigned char *)buf + 3;
#else
unsigned char *alphap = (unsigned char *)buf;
#endif
#endif
Uint32 color = alpha << surface->format->Ashift;
if (upper_bound != lower_bound){
color |= (((lower_r - upper_r) * (i-upper_bound) / (lower_bound - upper_bound) + upper_r) >> fmt->Rloss) << fmt->Rshift;
color |= (((lower_g - upper_g) * (i-upper_bound) / (lower_bound - upper_bound) + upper_g) >> fmt->Gloss) << fmt->Gshift;
color |= (((lower_b - upper_b) * (i-upper_bound) / (lower_bound - upper_bound) + upper_b) >> fmt->Bloss) << fmt->Bshift;
}
else{
color |= (upper_r >> fmt->Rloss) << fmt->Rshift;
color |= (upper_g >> fmt->Gloss) << fmt->Gshift;
color |= (upper_b >> fmt->Bloss) << fmt->Bshift;
}
for (j=0 ; j<surface->w ; j++, buf++){
if ((*buf & rgb_mask) == key_mask){
*buf = color;
*alphap = alpha;
}
#ifdef BPP16
alphap++;
#else
alphap += 4;
#endif
}
}
SDL_UnlockSurface(surface);
if ( si->visible )
dirty_rect.add( si->pos );
return RET_CONTINUE;
}
int ONScripterLabel::spstrCommand()
{
decodeExbtnControl( script_h.readStr() );
return RET_CONTINUE;
}
int ONScripterLabel::spreloadCommand()
{
leaveTextDisplayMode();
int no = script_h.readInt();
AnimationInfo *si;
if (no == -1) si = &sentence_font_info;
else si = &sprite_info[no];
parseTaggedString( si );
setupAnimationInfo( si );
if ( si->visible )
dirty_rect.add( si->pos );
return RET_CONTINUE;
}
int ONScripterLabel::splitCommand()
{
script_h.readStr();
const char *save_buf = script_h.saveStringBuffer();
char delimiter = script_h.readStr()[0];
char *token = new char[strlen(save_buf)+1];
while( script_h.getEndStatus() & ScriptHandler::END_COMMA ){
unsigned int c=0;
while(save_buf[c] != delimiter && save_buf[c] != '\0'){
if (IS_TWO_BYTE(save_buf[c]))
c += 2;
else
c++;
}
memcpy( token, save_buf, c );
token[c] = '\0';
script_h.readVariable();
if ( script_h.current_variable.type & ScriptHandler::VAR_INT ||
script_h.current_variable.type & ScriptHandler::VAR_ARRAY ){
script_h.setInt( &script_h.current_variable, atoi(token) );
}
else if ( script_h.current_variable.type & ScriptHandler::VAR_STR ){
setStr( &script_h.getVariableData(script_h.current_variable.var_no).str, token );
}
save_buf += c;
if (save_buf[0] != '\0') save_buf++;
}
delete[] token;
return RET_CONTINUE;
}
int ONScripterLabel::spclclkCommand()
{
if ( !force_button_shortcut_flag )
spclclk_flag = true;
return RET_CONTINUE;
}
int ONScripterLabel::spbtnCommand()
{
bool cellcheck_flag = false;
if ( script_h.isName( "cellcheckspbtn" ) )
cellcheck_flag = true;
int sprite_no = script_h.readInt();
int no = script_h.readInt();
if ( cellcheck_flag ){
if ( sprite_info[ sprite_no ].num_of_cells < 2 ) return RET_CONTINUE;
}
else{
if ( sprite_info[ sprite_no ].num_of_cells == 0 ) return RET_CONTINUE;
}
ButtonLink *button = new ButtonLink();
root_button_link.insert( button );
button->button_type = ButtonLink::SPRITE_BUTTON;
button->sprite_no = sprite_no;
button->no = no;
if ( sprite_info[ sprite_no ].image_surface ||
sprite_info[ sprite_no ].trans_mode == AnimationInfo::TRANS_STRING )
{
button->image_rect = button->select_rect = sprite_info[ sprite_no ].pos;
}
return RET_CONTINUE;
}
int ONScripterLabel::skipoffCommand()
{
skip_mode &= ~SKIP_NORMAL;
return RET_CONTINUE;
}
#ifdef LINUX
int tryToLaunch(const char* command, const char* target)
{
if (!command || !target) return -1;
pid_t child = vfork();
if (child == -1) {
// Parent, failed
fprintf(stderr, "Could not open `%s': fork error: %s\n",
target, strerror(errno));
return 0;
}
else if (child) {
// Parent, success
int status;
waitpid(child, &status, 0);
if (WIFEXITED(status)) return WEXITSTATUS(status);
return -1;
}
else {
// Child
execlp(command, command, target, (char*) NULL);
_exit(255);
}
}
#endif
int ONScripterLabel::shellCommand()
{
#ifdef WIN32
const char *url = script_h.readStr();
HMODULE shdll = LoadLibrary("shell32");
if (shdll) {
typedef HINSTANCE (WINAPI *SHELLEXECUTE)(HWND, LPCSTR, LPCSTR, LPCSTR,
LPCSTR, int);
SHELLEXECUTE shexec =
SHELLEXECUTE(GetProcAddress(shdll, "ShellExecuteA"));
if (shexec) {
shexec(NULL, "open", url, NULL, NULL, SW_SHOW);
}
FreeLibrary(shdll);
}
#elif defined MACOSX
ONSCocoa::open_url(script_h.readStr(), ONSCocoa::ENC_SJIS);
#elif defined LINUX
// Linux/BSD/other Unixes don't provide standard APIs for this
// kind of thing, but there are various things we can try.
const char *url = script_h.readStr();
int status;
// First up is xdg-open, the freedesktop solution that's becoming
// standard in the Linux world, at least.
//
status = tryToLaunch("xdg-open", url);
switch (status) {
case 0: // Success
return RET_CONTINUE;
case 2: // File not found
fprintf(stderr, "Failed to open %s: xdg-error reports that it doesn't "
"exist\n", url);
return RET_CONTINUE;
case 255: // execlp() failed (e.g. xdg-open not present)
// Don't say anything.
break;
case 1: // Syntax error
case 3: // Required tool missing
case 4: // Action failed
case -1: // child didn't exit normally
default: // unknown problem
fprintf(stderr, "Open URL with xdg-open failed with status %d\n",
status);
}
// Failing that, try $BROWSER, or give up.
const char* browser = getenv("BROWSER");
if (browser) {
char* cmd = new char[strlen(browser) + strlen(url) + 8];
sprintf(cmd, "\"%s\" '%s' &", browser, url);
if (system(cmd) != 0)
fprintf(stderr, "Couldn't launch web browser `%s': check your "
"BROWSER setting.\n", browser);
delete[] cmd;
}
else {
fputs("Could not determine which web browser to use. "
"Please set BROWSER appropriately.\n", stderr);
}
#else
fprintf(stderr, "[shell] command not supported for this OS\n");
#endif
return RET_CONTINUE;
}
int ONScripterLabel::sevolCommand()
{
se_volume = script_h.readInt();
for ( int i=1 ; i<ONS_MIX_CHANNELS ; i++ ) {
if ( wave_sample[i] )
Mix_Volume( i, !volume_on_flag? 0 : se_volume * 128 / 100 );
channelvolumes[i] = se_volume;
}
if ( wave_sample[MIX_LOOPBGM_CHANNEL0] )
Mix_Volume( MIX_LOOPBGM_CHANNEL0, !volume_on_flag? 0 : se_volume * 128 / 100 );
if ( wave_sample[MIX_LOOPBGM_CHANNEL1] )
Mix_Volume( MIX_LOOPBGM_CHANNEL1, !volume_on_flag? 0 : se_volume * 128 / 100 );
return RET_CONTINUE;
}
void ONScripterLabel::setwindowCore()
{
sentence_font.ttf_font = NULL;
sentence_font.top_xy[0] = script_h.readInt();
sentence_font.top_xy[1] = script_h.readInt();
sentence_font.num_xy[0] = script_h.readInt();
sentence_font.num_xy[1] = script_h.readInt();
sentence_font.font_size_xy[0] = script_h.readInt();
sentence_font.font_size_xy[1] = script_h.readInt();
sentence_font.pitch_xy[0] = script_h.readInt() + sentence_font.font_size_xy[0];
sentence_font.pitch_xy[1] = script_h.readInt() + sentence_font.font_size_xy[1];
sentence_font.wait_time = script_h.readInt();
sentence_font.is_bold = script_h.readInt()?true:false;
sentence_font.is_shadow = script_h.readInt()?true:false;
bool is_color = false;
const char *buf;
if (allow_color_type_only) {
buf = script_h.readColor(&is_color);
if (!is_color)
buf = script_h.readStr();
} else {
buf = script_h.readStr();
if ( buf[0] == '#' ) is_color = true;
}
dirty_rect.add( sentence_font_info.pos );
if ( is_color ){
sentence_font_info.stale_image = true;
sentence_font.is_transparent = true;
readColor( &sentence_font.window_color, buf );
sentence_font_info.orig_pos.x = script_h.readInt();
sentence_font_info.orig_pos.y = script_h.readInt();
sentence_font_info.orig_pos.w = script_h.readInt() - sentence_font_info.orig_pos.x + 1;
sentence_font_info.orig_pos.h = script_h.readInt() - sentence_font_info.orig_pos.y + 1;
UpdateAnimPosStretchXY(&sentence_font_info);
UpdateAnimPosStretchWH(&sentence_font_info);
}
else{
sentence_font.is_transparent = false;
sentence_font_info.setImageName( buf );
parseTaggedString( &sentence_font_info );
#ifdef RCA_SCALE
setupAnimationInfo( &sentence_font_info, NULL, scr_stretch_x, scr_stretch_y );
#else
setupAnimationInfo( &sentence_font_info );
#endif
sentence_font_info.orig_pos.x = script_h.readInt();
sentence_font_info.orig_pos.y = script_h.readInt();
UpdateAnimPosStretchXY(&sentence_font_info);
sentence_font.window_color[0] = sentence_font.window_color[1] = sentence_font.window_color[2] = 0xff;
}
#ifdef RCA_SCALE
// Scale and reposition window size if screen is bigger than game
if (scr_stretch_x > 1.0) {
sentence_font.top_xy[0] = sentence_font.top_xy[0] * scr_stretch_x + 0.5;
# if 1
// Either increase number of characters on screen
sentence_font.num_xy[0] = sentence_font.num_xy[0] * scr_stretch_x + 0.5;
# else
// Or increase font size
sentence_font.pitch_xy[0] = sentence_font.pitch_xy[0] * scr_stretch_x + 0.5;
sentence_font.font_size_xy[0] = sentence_font.font_size_xy[0] * scr_stretch_x + 0.5;
# endif
}
if (scr_stretch_y > 1.0) {
sentence_font.top_xy[1] = sentence_font.top_xy[1] * scr_stretch_y + 0.5;
# if 1
// Either increase number of characters on screen
sentence_font.num_xy[1] = sentence_font.num_xy[1] * scr_stretch_y + 0.5;
# else
// Or increase font size
sentence_font.pitch_xy[1] = sentence_font.pitch_xy[1] * scr_stretch_y + 0.5;
sentence_font.font_size_xy[1] = sentence_font.font_size_xy[1] * scr_stretch_y + 0.5;
# endif
}
#endif //RCA_SCALE
}
int ONScripterLabel::setwindow3Command()
{
setwindowCore();
display_mode = DISPLAY_MODE_NORMAL;
flush( refreshMode(), &sentence_font_info.pos );
return RET_CONTINUE;
}
int ONScripterLabel::setwindow2Command()
{
bool is_color = false;
const char *buf;
if (allow_color_type_only) {
buf = script_h.readColor(&is_color);
if (!is_color)
buf = script_h.readStr();
} else {
buf = script_h.readStr();
if ( buf[0] == '#' ) is_color = true;
}
if ( is_color ){
sentence_font.is_transparent = true;
readColor( &sentence_font.window_color, buf );
}
else{
sentence_font.is_transparent = false;
sentence_font_info.setImageName( buf );
parseTaggedString( &sentence_font_info );
setupAnimationInfo( &sentence_font_info );
}
repaintCommand();
return RET_CONTINUE;
}
int ONScripterLabel::setwindowCommand()
{
setwindowCore();
lookbackflushCommand();
indent_offset = 0;
line_enter_status = 0;
page_enter_status = 0;
display_mode = DISPLAY_MODE_NORMAL;
flush( refreshMode(), &sentence_font_info.pos );
return RET_CONTINUE;
}
int ONScripterLabel::seteffectspeedCommand()
{
int no = script_h.readInt();