-
-
Notifications
You must be signed in to change notification settings - Fork 78
/
title.cpp
1892 lines (1590 loc) · 49.4 KB
/
title.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
#include <filesystem>
#include <stdio.h>
#include <ctype.h>
#include <cstring>
#include <memory>
#include "base/zc_alleg.h"
#include "base/qrs.h"
#include "base/packfile.h"
#include "base/dmap.h"
#include "base/misctypes.h"
#include "base/zdefs.h"
#include "zc/zelda.h"
#include "base/zsys.h"
#include "qst.h"
#include "tiles.h"
#include "pal.h"
#include "base/gui.h"
#include "zc/title.h"
#include "zc/ffscript.h"
#include "zc/saves.h"
#include "zc/render.h"
#include "dialog/info.h"
#include "zinfo.h"
#include <fmt/format.h>
#ifdef __EMSCRIPTEN__
#include "base/emscripten_utils.h"
#endif
#ifdef _MSC_VER
#define strupr _strupr
#define stricmp _stricmp
#endif
extern int32_t loadlast;
extern int32_t skipcont;
extern FFScript FFCore;
extern zcmodule moduledata;
bool load_custom_game(int32_t file);
static bool chosecustomquest = false;
/***********************************/
/**** Game Selection Screens *****/
/***********************************/
static void select_mode()
{
textout_ex(scrollbuf,get_zc_font(font_zfont),"REGISTER YOUR NAME",48,152,1,0);
textout_ex(scrollbuf,get_zc_font(font_zfont),"COPY FILE",48,168,1,0);
textout_ex(scrollbuf,get_zc_font(font_zfont),"DELETE FILE",48,184,1,0);
}
static void register_mode()
{
textout_ex(scrollbuf,get_zc_font(font_zfont),"REGISTER YOUR NAME",48,152,CSET(2)+3,0);
}
static void copy_mode()
{
textout_ex(scrollbuf,get_zc_font(font_zfont),"COPY FILE",48,168,CSET(2)+3,0);
}
static void delete_mode()
{
textout_ex(scrollbuf,get_zc_font(font_zfont),"DELETE FILE",48,184,CSET(2)+3,0);
}
static void framerect(BITMAP* dest, int32_t x, int32_t y, int32_t w, int32_t h, int32_t c)
{
BITMAP* temp = create_bitmap_ex(8, dest->w, dest->h);
clear_bitmap(temp);
rect(temp, x, y, x+w-1, y+h-1,c);
rect(temp, x+1, y+1, x+w-2, y+h-2,c);
temp->line[y][x] = 0;
temp->line[y][x+w-1] = 0;
temp->line[y+h-1][x] = 0;
temp->line[y+h-1][x+w-1] = 0;
masked_blit(temp, dest, x, y, x, y, w, h);
destroy_bitmap(temp);
}
static void selectscreen()
{
FFCore.kb_typing_mode = false;
if (get_qr(qr_OLD_SCRIPT_VOLUME))
{
if (FFCore.coreflags & FFCORE_SCRIPTED_MIDI_VOLUME)
{
Z_scripterrlog("Trying to restore master MIDI volume to: %d\n", FFCore.usr_midi_volume);
midi_volume = FFCore.usr_midi_volume;
//master_volume(-1,FFCore.usr_midi_volume);
}
if (FFCore.coreflags & FFCORE_SCRIPTED_DIGI_VOLUME)
{
digi_volume = FFCore.usr_digi_volume;
//master_volume((int32_t)(FFCore.usr_digi_volume),1);
}
if (FFCore.coreflags & FFCORE_SCRIPTED_MUSIC_VOLUME)
{
emusic_volume = (int32_t)FFCore.usr_music_volume;
}
if (FFCore.coreflags & FFCORE_SCRIPTED_SFX_VOLUME)
{
sfx_volume = (int32_t)FFCore.usr_sfx_volume;
}
}
if ( FFCore.coreflags&FFCORE_SCRIPTED_PANSTYLE )
{
pan_style = (int32_t)FFCore.usr_panstyle;
}
FFCore.skip_ending_credits = 0;
// text_mode(0);
init_NES_mode();
loadfullpal();
loadlvlpal(1);
Bwpn = -1, Awpn = -1, Xwpn = -1, Ywpn = -1; //the subsreen values
clear_bitmap(scrollbuf);
framerect(scrollbuf, 27, 51, 26*8-6, 20*8-6,0x03);
textout_ex(scrollbuf,get_zc_font(font_zfont),"- S E L E C T -",64,24,1,0); //could be in module at some point
textout_ex(scrollbuf,get_zc_font(font_zfont)," NAME ",80,48,1,0);
textout_ex(scrollbuf,get_zc_font(font_zfont)," LIFE ",152,48,1,0);
select_mode();
RAMpal[CSET(9)+1]=NESpal(0x15);
RAMpal[CSET(9)+2]=NESpal(0x27);
RAMpal[CSET(9)+3]=NESpal(0x30);
RAMpal[CSET(13)+1]=NESpal(0x30);
}
static byte left_arrow_str[] = {132,0};
static byte right_arrow_str[] = {133,0};
static void list_save(gamedata_header* header, int32_t save_num, int32_t ypos)
{
bool r = refreshpal;
byte quest = header->quest;
game->set_maxlife(header->maxlife);
game->set_life(header->maxlife);
game->set_hp_per_heart(header->hp_per_heart_container);
//wpnsbuf[iwQuarterHearts].tile = moduledata.select_screen_tiles[sels_heart_tile];
//Setting the cset does nothing, because it lifemeter() uses overtile8()
//Modules should set the cset manually.
//wpnsbuf[iwQuarterHearts].csets = moduledata.select_screen_tile_csets[sels_heart_tilettile_cset];
//boogie!
lifemeter(framebuf,144,ypos+((game->get_maxlife()>16*(header->hp_per_heart_container))?8:0),8,0);
textout_ex(framebuf,get_zc_font(font_zfont),header->name.c_str(),72,ypos+16,1,0);
if(quest)
textprintf_ex(framebuf,get_zc_font(font_zfont),72,ypos+24,1,0,"%5d",header->deaths);
if ( moduledata.select_screen_tiles[draw_hero_first])
overtile16(framebuf,moduledata.select_screen_tiles[sels_herotile],48,ypos+17,((unsigned)moduledata.select_screen_tile_csets[sels_hero_cset] < 15 ) ? moduledata.select_screen_tile_csets[sels_hero_cset] : (save_num%3)+10,0);
if(quest==1)
{
//hardcoded quest icons -- move to module
//overtile16(framebuf,41,56,ypos+14,9,0); //put sword on second quests
if ( moduledata.select_screen_tiles[sels_tile_questicon_1A] > 0 )
overtile16(framebuf,moduledata.select_screen_tiles[sels_tile_questicon_1A],moduledata.select_screen_tiles[sels_tile_questicon_1A_X],ypos+14,moduledata.select_screen_tile_csets[sels_tile_questicon_1A_cset],0);
if ( moduledata.select_screen_tiles[sels_tile_questicon_1B] > 0 )
overtile16(framebuf,moduledata.select_screen_tiles[sels_tile_questicon_1B],moduledata.select_screen_tiles[sels_tile_questicon_1B_X],ypos+14,moduledata.select_screen_tile_csets[sels_tile_questicon_1B_cset],0);
}
if(quest==2)
{
//hardcoded quest icons -- move to module
//overtile16(framebuf,41,56,ypos+14,9,0); //put sword on second quests
if ( moduledata.select_screen_tiles[sels_tile_questicon_2A] > 0 )
overtile16(framebuf,moduledata.select_screen_tiles[sels_tile_questicon_2A],moduledata.select_screen_tiles[sels_tile_questicon_2A_X],ypos+14,moduledata.select_screen_tile_csets[sels_tile_questicon_2A_cset],0);
if ( moduledata.select_screen_tiles[sels_tile_questicon_2B] > 0 )
overtile16(framebuf,moduledata.select_screen_tiles[sels_tile_questicon_2B],moduledata.select_screen_tiles[sels_tile_questicon_2B_X],ypos+14,moduledata.select_screen_tile_csets[sels_tile_questicon_2B_cset],0);
}
if(quest==3)
{
//overtile16(framebuf,41,56,ypos+14,9,0); //put sword on second quests
//overtile16(framebuf,41,41,ypos+14,9,0); //put sword on third quests
if ( moduledata.select_screen_tiles[sels_tile_questicon_3A] > 0 )
overtile16(framebuf,moduledata.select_screen_tiles[sels_tile_questicon_3A],moduledata.select_screen_tiles[sels_tile_questicon_3A_X],ypos+14,moduledata.select_screen_tile_csets[sels_tile_questicon_3A_cset],0);
if ( moduledata.select_screen_tiles[sels_tile_questicon_3B] > 0 )
overtile16(framebuf,moduledata.select_screen_tiles[sels_tile_questicon_3B],moduledata.select_screen_tiles[sels_tile_questicon_3B_X],ypos+14,moduledata.select_screen_tile_csets[sels_tile_questicon_3B_cset],0);
}
if(quest==4)
{
//overtile16(framebuf,176,52,ypos+14,0,1); //dust pile
//overtile16(framebuf,175,52,ypos+14,9,0); //triforce
if ( moduledata.select_screen_tiles[sels_tile_questicon_4A] > 0 )
overtile16(framebuf,moduledata.select_screen_tiles[sels_tile_questicon_4A],moduledata.select_screen_tiles[sels_tile_questicon_4A_X],ypos+14,moduledata.select_screen_tile_csets[sels_tile_questicon_4A_cset],0);
if ( moduledata.select_screen_tiles[sels_tile_questicon_4B] > 0 )
overtile16(framebuf,moduledata.select_screen_tiles[sels_tile_questicon_4B],moduledata.select_screen_tiles[sels_tile_questicon_4B_X],ypos+14,moduledata.select_screen_tile_csets[sels_tile_questicon_4B_cset],0);
}
if(quest==5)
{
//overtile16(framebuf,176,52,ypos+14,0,1); //dust pile
//overtile16(framebuf,175,52,ypos+14,9,0); //triforce
if ( moduledata.select_screen_tiles[sels_tile_questicon_5A] > 0 )
overtile16(framebuf,moduledata.select_screen_tiles[sels_tile_questicon_5A],moduledata.select_screen_tiles[sels_tile_questicon_5A_X],ypos+14,moduledata.select_screen_tile_csets[sels_tile_questicon_5A_cset],0);
if ( moduledata.select_screen_tiles[sels_tile_questicon_5B] > 0 )
overtile16(framebuf,moduledata.select_screen_tiles[sels_tile_questicon_5B],moduledata.select_screen_tiles[sels_tile_questicon_5B_X],ypos+14,moduledata.select_screen_tile_csets[sels_tile_questicon_5B_cset],0);
}
if(quest==6)
{
//overtile16(framebuf,176,52,ypos+14,0,1); //dust pile
//overtile16(framebuf,175,52,ypos+14,9,0); //triforce
if ( moduledata.select_screen_tiles[sels_tile_questicon_6A] > 0 )
overtile16(framebuf,moduledata.select_screen_tiles[sels_tile_questicon_6A],moduledata.select_screen_tiles[sels_tile_questicon_6A_X],ypos+14,moduledata.select_screen_tile_csets[sels_tile_questicon_6A_cset],0);
if ( moduledata.select_screen_tiles[sels_tile_questicon_6B] > 0 )
overtile16(framebuf,moduledata.select_screen_tiles[sels_tile_questicon_6B],moduledata.select_screen_tiles[sels_tile_questicon_6B_X],ypos+14,moduledata.select_screen_tile_csets[sels_tile_questicon_6B_cset],0);
}
if(quest==7)
{
//overtile16(framebuf,176,52,ypos+14,0,1); //dust pile
//overtile16(framebuf,175,52,ypos+14,9,0); //triforce
if ( moduledata.select_screen_tiles[sels_tile_questicon_7A] > 0 )
overtile16(framebuf,moduledata.select_screen_tiles[sels_tile_questicon_7A],moduledata.select_screen_tiles[sels_tile_questicon_7A_X],ypos+14,moduledata.select_screen_tile_csets[sels_tile_questicon_7A_cset],0);
if ( moduledata.select_screen_tiles[sels_tile_questicon_7B] > 0 )
overtile16(framebuf,moduledata.select_screen_tiles[sels_tile_questicon_7B],moduledata.select_screen_tiles[sels_tile_questicon_7B_X],ypos+14,moduledata.select_screen_tile_csets[sels_tile_questicon_7B_cset],0);
}
if(quest==8)
{
//overtile16(framebuf,176,52,ypos+14,0,1); //dust pile
//overtile16(framebuf,175,52,ypos+14,9,0); //triforce
if ( moduledata.select_screen_tiles[sels_tile_questicon_8A] > 0 )
overtile16(framebuf,moduledata.select_screen_tiles[sels_tile_questicon_8A],moduledata.select_screen_tiles[sels_tile_questicon_8A_X],ypos+14,moduledata.select_screen_tile_csets[sels_tile_questicon_8A_cset],0);
if ( moduledata.select_screen_tiles[sels_tile_questicon_8B] > 0 )
overtile16(framebuf,moduledata.select_screen_tiles[sels_tile_questicon_8B],moduledata.select_screen_tiles[sels_tile_questicon_8B_X],ypos+14,moduledata.select_screen_tile_csets[sels_tile_questicon_8B_cset],0);
}
if(quest==9)
{
//overtile16(framebuf,176,52,ypos+14,0,1); //dust pile
//overtile16(framebuf,175,52,ypos+14,9,0); //triforce
if ( moduledata.select_screen_tiles[sels_tile_questicon_9A] > 0 )
overtile16(framebuf,moduledata.select_screen_tiles[sels_tile_questicon_9A],moduledata.select_screen_tiles[sels_tile_questicon_9A_X],ypos+14,moduledata.select_screen_tile_csets[sels_tile_questicon_9A_cset],0);
if ( moduledata.select_screen_tiles[sels_tile_questicon_9B] > 0 )
overtile16(framebuf,moduledata.select_screen_tiles[sels_tile_questicon_9B],moduledata.select_screen_tiles[sels_tile_questicon_9B_X],ypos+14,moduledata.select_screen_tile_csets[sels_tile_questicon_9B_cset],0);
}
if(quest==10)
{
//overtile16(framebuf,176,52,ypos+14,0,1); //dust pile
//overtile16(framebuf,175,52,ypos+14,9,0); //triforce
if ( moduledata.select_screen_tiles[sels_tile_questicon_10A] > 0 )
overtile16(framebuf,moduledata.select_screen_tiles[sels_tile_questicon_10A],moduledata.select_screen_tiles[sels_tile_questicon_10A_X],ypos+14,moduledata.select_screen_tile_csets[sels_tile_questicon_10A_cset],0);
if ( moduledata.select_screen_tiles[sels_tile_questicon_10B] > 0 )
overtile16(framebuf,moduledata.select_screen_tiles[sels_tile_questicon_10B],moduledata.select_screen_tiles[sels_tile_questicon_10B_X],ypos+14,moduledata.select_screen_tile_csets[sels_tile_questicon_10B_cset],0);
}
textprintf_ex(framebuf,get_zc_font(font_zfont),72,ypos+16,1,0,"%s",header->name.c_str());
byte *hold = newtilebuf[0].data;
byte holdformat=newtilebuf[0].format;
newtilebuf[0].format=tf4Bit;
newtilebuf[0].data = header->icon;
overtile16(framebuf,(moduledata.select_screen_tiles[sels_herotile] > 1 && quest > 0 && quest < 255 ) ? moduledata.select_screen_tiles[sels_herotile] : 0,48,ypos+17,
((unsigned)moduledata.select_screen_tile_csets[sels_hero_cset] < 15 && quest > 0 && quest < 255 ) ? (unsigned)moduledata.select_screen_tile_csets[sels_hero_cset] < 15 :
(save_num%3)+10,0); //hero
newtilebuf[0].format=holdformat;
newtilebuf[0].data = hold;
hold = colordata;
colordata = header->pal;
//if ( moduledata.select_screen_tile_csets[change_cset_on_quest_3] ) loadpalset((save_num%3)+10,0); //quest number changes the palette -- move to module
loadpalset((save_num%3)+10,0); //quest number changes the palette -- move to module?
colordata = hold;
textout_ex(framebuf,get_zc_font(font_zfont),"-",136,ypos+16,1,0);
refreshpal = r;
}
static void list_saves()
{
// Fourth Quest turns the menu red.
bool red = false;
// First, make sure the presently listed quests are loaded.
int savecnt = saves_count();
for(int32_t i=0; i<3; i++)
{
int j = listpos+i;
if (j < savecnt)
saves_get_slot(j);
}
// Check if any loaded quests is the 4th quest.
for(int32_t i=0; i<savecnt; i++)
{
if (saves_is_slot_loaded(i) && saves_get_slot(i)->header->quest == 4)
{
red = true;
break;
}
}
loadpalset(0,red ? pSprite(spPILE) : 0);
for(int32_t i=0; i<3; i++)
{
if (listpos+i < savecnt)
list_save(saves_get_slot(listpos+i)->header, listpos+i, i*24+56);
}
// Draw the arrows above the lifemeter!
if(savecnt>3)
{
if(listpos>=3)
textout_ex(framebuf,get_zc_font(font_zfont),(char *)left_arrow_str,96,60,3,0);
if(listpos+3<savecnt)
textout_ex(framebuf,get_zc_font(font_zfont),(char *)right_arrow_str,176,60,3,0);
textprintf_ex(framebuf,get_zc_font(font_zfont),112,60,3,0,"%2d - %-2d",listpos+1,listpos+3);
}
}
static void draw_cursor(int32_t pos,int32_t mode)
{
int32_t cs = (mode==3)?13:9;
if(pos<3)
overtile8(framebuf,0,40,pos*24+77,cs,0);
else
overtile8(framebuf,0,40,(pos-3)*16+153,cs,0);
}
static bool register_name()
{
int s = saves_count();
if ( moduledata.refresh_title_screen ) //refresh
{
selectscreen();
moduledata.refresh_title_screen = 0;
}
int32_t NameEntryMode2=NameEntryMode;
gamedata* new_game = new gamedata();
new_game->set_maxlife(3*16);
new_game->set_life(3*16);
new_game->set_maxbombs(8);
new_game->set_continue_dmap(0);
new_game->set_continue_scrn(0xFF);
listpos=((saves_count())/3)*3;
// clear_bitmap(framebuf);
rectfill(framebuf,32,56,223,151,0);
list_saves();
blit(framebuf,scrollbuf,0,0,0,0,256,224);
int32_t pos=s%3;
int32_t y=((NameEntryMode2>0)?0:(pos*24))+72;
int32_t x=0;
int32_t spos=0;
char name[9];
memset(name,0,9);
register_mode();
clear_keybuf();
SystemKeys=(NameEntryMode2>0);
refreshpal=true;
bool done=false;
bool cancel=false;
if (!load_qstpath.empty()) {
new_game->header.qstpath = load_qstpath;
std::string filename = get_filename(load_qstpath.c_str());
filename.erase(remove(filename.begin(), filename.end(), ' '), filename.end());
auto len = filename.find(".qst", 0);
len = zc_min(len, 8);
strcpy(name, filename.substr(0, len).c_str());
x = strlen(name);
}
int32_t letter_grid_x=(NameEntryMode2==2)?34:44;
int32_t letter_grid_y=120;
int32_t letter_grid_offset=(NameEntryMode2==2)?10:8;
int32_t letter_grid_width=(NameEntryMode2==2)?16:11;
int32_t letter_grid_height=(NameEntryMode2==2)?6:4;
int32_t letter_grid_spacing=(NameEntryMode2==2)?12:16;
const char *simple_grid="ABCDEFGHIJKLMNOPQRSTUVWXYZ-.,!'&.0123456789 ";
const char *complete_grid=" !\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~ ";
if(NameEntryMode2>0)
{
//int32_t pos=file%3;
BITMAP *info = create_bitmap_ex(8,168,32);
clear_bitmap(info);
blit(framebuf,info,40,pos*24+70,0,0,168,26);
rectfill(info,40,0,168,1,0);
rectfill(info,0,24,39,25,0);
rectfill(info,0,0,7,15,0);
rectfill(framebuf,40,64,216,192,0);
rectfill(framebuf,96,60,183,67,0);
int32_t i=pos*24+70;
do
{
blit(info,framebuf,0,0,40,i,168,32);
advanceframe(true);
i-=pos+pos;
}
while(pos && i>=70);
clear_bitmap(framebuf);
framerect(framebuf, 27, 51, 26*8-6, 8*8-6,0x03);
textout_ex(framebuf,get_zc_font(font_zfont)," NAME ",80,48,1,0);
textout_ex(framebuf,get_zc_font(font_zfont)," LIFE ",152,48,1,0);
blit(info,framebuf,0,0,40,70,168,32);
destroy_bitmap(info);
framerect(framebuf, letter_grid_x-letter_grid_offset+3, letter_grid_y-letter_grid_offset+3,
((NameEntryMode2==2)?26:23)*8-6, ((NameEntryMode2==2)?11:9)*8-6,0x03);
if(NameEntryMode2==1)
{
textout_ex(framebuf,get_zc_font(font_zfont),"A B C D E F G H I J K",letter_grid_x,letter_grid_y,1,-1);
textout_ex(framebuf,get_zc_font(font_zfont),"L M N O P Q R S T U V",letter_grid_x,letter_grid_y+16,1,-1);
textout_ex(framebuf,get_zc_font(font_zfont),"W X Y Z - . , ! ' & .",letter_grid_x,letter_grid_y+32,1,-1);
textout_ex(framebuf,get_zc_font(font_zfont),"0 1 2 3 4 5 6 7 8 9 ",letter_grid_x,letter_grid_y+48,1,-1);
}
else
{
textout_ex(framebuf,get_zc_font(font_zfont)," \" $ & ( * , .",letter_grid_x, letter_grid_y, 1,-1);
textout_ex(framebuf,get_zc_font(font_zfont), "! # % ' ) + - /",letter_grid_x+12,letter_grid_y, 1,-1);
textout_ex(framebuf,get_zc_font(font_zfont),"0 2 4 6 8 : < >", letter_grid_x, letter_grid_y+12,1,-1);
textout_ex(framebuf,get_zc_font(font_zfont), "1 3 5 7 9 ; = ?",letter_grid_x+12,letter_grid_y+12,1,-1);
textout_ex(framebuf,get_zc_font(font_zfont),"@ B D F H J L N", letter_grid_x, letter_grid_y+24,1,-1);
textout_ex(framebuf,get_zc_font(font_zfont), "A C E G I K M O",letter_grid_x+12,letter_grid_y+24,1,-1);
textout_ex(framebuf,get_zc_font(font_zfont),"P R T V X Z \\ ^",letter_grid_x, letter_grid_y+36,1,-1);
textout_ex(framebuf,get_zc_font(font_zfont), "Q S U W Y [ ] _",letter_grid_x+12,letter_grid_y+36,1,-1);
textout_ex(framebuf,get_zc_font(font_zfont),"` b d f h j l n", letter_grid_x, letter_grid_y+48,1,-1);
textout_ex(framebuf,get_zc_font(font_zfont), "a c e g i k m o",letter_grid_x+12,letter_grid_y+48,1,-1);
textout_ex(framebuf,get_zc_font(font_zfont),"p r t v x z | ~", letter_grid_x, letter_grid_y+60,1,-1);
textout_ex(framebuf,get_zc_font(font_zfont), "q s u w y { }", letter_grid_x+12,letter_grid_y+60,1,-1);
}
advanceframe(true);
blit(framebuf,scrollbuf,0,0,0,0,256,224);
}
int32_t grid_x=0;
int32_t grid_y=0;
do
{
if(NameEntryMode2>0)
{
spos = grid_y*letter_grid_width+grid_x;
load_control_state();
if(rLeft())
{
--grid_x;
if(grid_x<0)
{
grid_x=letter_grid_width-1;
--grid_y;
if(grid_y<0)
{
grid_y=letter_grid_height-1;
}
}
sfx(WAV_CHIME);
}
else if(rRight())
{
++grid_x;
if(grid_x>=letter_grid_width)
{
grid_x=0;
++grid_y;
if(grid_y>=letter_grid_height)
{
grid_y=0;
}
}
sfx(WAV_CHIME);
}
else if(rUp())
{
--grid_y;
if(grid_y<0)
{
grid_y=letter_grid_height-1;
}
sfx(WAV_CHIME);
}
else if(rDown())
{
++grid_y;
if(grid_y>=letter_grid_height)
{
grid_y=0;
}
sfx(WAV_CHIME);
}
else if(rBbtn())
{
if(x<8 && name[zc_min(x,7)])
{
++x;
sfx(WAV_CHIME);
}
if(x>=8)
{
x=0;
}
}
else if(rAbtn())
{
name[zc_min(x,7)]=(NameEntryMode2==2)?complete_grid[spos]:simple_grid[spos];
++x;
if(x>=8)
{
x=0;
}
sfx(WAV_PLACE);
}
else if(rSbtn())
{
done=true;
int32_t ltrs=0;
for(int32_t i=0; i<8; i++)
{
if(name[i]!=' ' && name[i]!=0)
{
++ltrs;
}
}
if(!ltrs)
{
cancel=true;
}
}
}
else
{
#ifdef __EMSCRIPTEN__
// Allow gamepad to submit name.
poll_joystick();
load_control_state();
if(rSbtn())
{
done = true;
break;
}
#endif
if(keypressed())
{
int32_t k=readkey();
if(isprint(k&255))
{
name[zc_min(x,7)]=k&0xFF;
if(x<8)
{
++x;
}
sfx(WAV_PLACE);
}
else
{
switch(k>>8)
{
case KEY_LEFT:
if(x>0)
{
if(x==8)
{
x=6;
}
else
{
--x;
}
sfx(WAV_CHIME);
}
break;
case KEY_RIGHT:
if(x<8 && name[zc_min(x,7)])
{
++x;
sfx(WAV_CHIME);
}
break;
case KEY_ENTER:
case KEY_ENTER_PAD:
{
done=true;
int32_t ltrs=0;
for(int32_t i=0; i<8; i++)
{
if(name[i]!=' ' && name[i]!=0)
{
++ltrs;
}
}
if(!ltrs)
{
cancel=true;
}
}
break;
case KEY_BACKSPACE:
if(x>0)
{
--x;
for(int32_t i=zc_min(x,7); i<8; i++)
{
name[i]=name[i+1];
}
sfx(WAV_OUCH);
}
break;
case KEY_DEL:
for(int32_t i=zc_min(x,7); i<8; i++)
{
name[i]=name[i+1];
}
sfx(WAV_OUCH);
break;
case KEY_ESC:
x=-1;
done=true;
while(key[KEY_ESC])
{
poll_keyboard();
/* do nothing */
rest(1);
}
break;
}
}
}
}
new_game->set_name(name);
blit(scrollbuf,framebuf,0,0,0,0,256,224);
list_save(&new_game->header, s, 56+((NameEntryMode2>0)?0:(pos*24)));
int32_t x2=letter_grid_x + grid_x*letter_grid_spacing;
int32_t y2=letter_grid_y + grid_y*letter_grid_spacing;
if(frame&8)
{
int32_t tx=(zc_min(x,7)<<3)+72;
for(int32_t dy=0; dy<8; dy++)
{
for(int32_t dx=0; dx<8; dx++)
{
if(framebuf->line[y+dy][tx+dx]==0)
{
framebuf->line[y+dy][tx+dx]=CSET(9)+1;
}
if(NameEntryMode2>0)
{
if(framebuf->line[y2+dy][x2+dx]==0)
{
framebuf->line[y2+dy][x2+dx]=CSET(9)+1;
}
}
}
}
}
draw_cursor((NameEntryMode2>0)?0:pos,0);
advanceframe(true);
/*
if(rBbtn())
{
x=-1;
done=true;
}
*/
}
while(!done && !Quit);
if(x<0 || cancel)
{
done=false;
}
if(done)
{
int32_t quest=1;
char buf[9];
strcpy(buf,name);
strupr(buf);
for ( byte q = 1; q < moduledata.max_quest_files; q++)
{
if(!stricmp(buf,moduledata.skipnames[q]))
{
zprint2("Quest %d '%s'\n",q+1,moduledata.skipnames[q]);
quest=q+1;
break;
}
}
/*
if(!stricmp(buf,moduledata.skipnames[1]))
quest=2;
if(!stricmp(buf,moduledata.skipnames[2]))
quest=3;
if(!stricmp(buf,moduledata.skipnames[3]))
quest=4;
if(!stricmp(buf,moduledata.skipnames[4])) // This is what BigJoe wanted. I have no problem with it.
quest=5;
*/
new_game->set_quest(quest);
game->header.qstpath.clear();
byte qst_num = byte(quest-1);
int32_t ret = (qst_num < moduledata.max_quest_files) ? load_quest(new_game) : qe_no_qst;
if(ret==qe_OK)
{
new_game->set_maxlife(zinit.hc*zinit.hp_per_heart);
new_game->set_life(zinit.hc*zinit.hp_per_heart);
new_game->set_hp_per_heart(zinit.hp_per_heart);
selectscreen(); // refresh palette
if (!saves_create_slot(new_game))
{
cancel = true;
InfoDialog("Error creating save", ":(").show();
}
else
{
ringcolor(false);
}
}
else
{
ringcolor(true);
cancel = true;
}
//setPackfilePassword(NULL);
new_game->set_timevalid(1);
}
if (x<0 || cancel)
{
delete new_game;
new_game = nullptr;
}
// std::string filename_prefix = fmt::format("{}-{}", save->title, save->header.name);
// sanitize(filename_prefix);
// return create_new_file_path(replay_file_dir, filename_prefix, REPLAY_EXTENSION).string();
listpos=((saves_count()-1)/3)*3;
SystemKeys=true;
selectscreen();
list_saves();
select_mode();
return done && new_game != nullptr;
}
static bool copy_file(int32_t file)
{
int savecnt = saves_count();
if (file < savecnt)
{
saves_copy(file);
listpos=((saves_count()-1)/3)*3;
sfx(WAV_SCALE);
select_mode();
return true;
}
return false;
}
static bool delete_save(int32_t file)
{
int savecnt = saves_count();
if (file < savecnt)
{
saves_delete(file);
--savecnt;
if(listpos>savecnt-1)
listpos=zc_max(listpos-3,0);
sfx(WAV_OUCH);
select_mode();
return true;
}
return false;
}
/** game mode stuff **/
DIALOG gamemode_dlg[] =
{
// (dialog proc) (x) (y) (w) (h) (fg) (bg) (key) (flags) (d1) (d2) (dp) (dp2) (dp3)
{ jwin_win_proc, 40, 44, 240, 180, 0, 0, 0, D_EXIT, 0, 0, (void *) "Select Custom Quest", NULL, NULL },
// 1
{ jwin_button_proc, 205, 76, 61, 21, 0, 0, 'b', D_EXIT, 0, 0, (void *) "&Browse", NULL, NULL },
{ jwin_textbox_proc, 55, 78, 140, 16, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
{ jwin_text_proc, 76, 106, 64, 8, vc(0), vc(11), 0, 0, 0, 0, (void *) "Info:", NULL, NULL },
{ jwin_textbox_proc, 76, 118, 168, 60, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
// 5
{ jwin_button_proc, 90, 191, 61, 21, 0, 0, 'k', D_EXIT, 0, 0, (void *) "O&K", NULL, NULL },
{ jwin_button_proc, 170, 191, 61, 21, 0, 0, 27, D_EXIT, 0, 0, (void *) "Cancel", NULL, NULL },
{ d_timer_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
{ NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL }
};
static int32_t get_quest_info(zquestheader *header,char *str)
{
if(strlen(get_filename(qstpath)) == 0)
{
str[0]=0;
return 0;
}
int32_t error;
PACKFILE* f = open_quest_file(&error, qstpath, false);
if (!f)
{
strcpy(str,"Error: Unable to open file");
return 0;
}
int32_t ret = readheader(f, header);
pack_fclose(f);
clear_quest_tmpfile();
switch(ret)
{
case 0:
break;
case qe_invalid:
strcpy(str,"Error: Invalid quest file");
return 0;
case qe_version:
strcpy(str,"Error: Invalid version");
return 0;
case qe_obsolete:
strcpy(str,"Error: Obsolete version");
return 0;
case qe_silenterr:
return 0;
}
strcpy(str,"Title:\n");
strcat(str,header->title);
strcat(str,"\n\nAuthor:\n");
strcat(str,header->author);
return 1;
}
bool load_custom_game(int32_t file)
{
auto save = saves_get_slot(file);
if (!save->header->has_played)
{
if (chosecustomquest || standalone_mode)
{
chosecustomquest = false;
return true;
}
}
return false;
}
int32_t custom_game(int32_t file)
{
if (!only_qstpath.empty())
{
strcpy(qstpath, only_qstpath.c_str());
chosecustomquest = true;
return true;
}
zquestheader h;
char infostr[200];
char path[2048];
int32_t ret=0;
int32_t focus_obj = 1; //Fixes the issue where the button tied to the enter key is stuck on 'browse'.
auto header = saves_get_slot(file)->header;
if (is_relative_filename(header->qstpath.c_str()))
{
sprintf(qstpath, "%s%s", qstdir, header->qstpath.c_str());
}
else
{
sprintf(qstpath, "%s", header->qstpath.c_str());
}
char relpath[2048];
relativize_path(relpath, qstpath);
gamemode_dlg[0].dp2 = get_zc_font(font_lfont);
gamemode_dlg[2].dp = relpath;//get_filename(qstpath);
if(get_quest_info(&h,infostr)==0)
{
gamemode_dlg[4].dp = infostr;
gamemode_dlg[5].flags = D_DISABLED;
}
else
{
gamemode_dlg[4].dp = infostr;
gamemode_dlg[5].flags = D_EXIT;
}
if(byte(header->quest-1) < moduledata.max_quest_files)
strcpy(qstpath,qstdir);
gamemode_dlg[2].d1 = gamemode_dlg[4].d1 = 0;
gamemode_dlg[2].d2 = gamemode_dlg[4].d2 = 0;
enter_sys_pal();
clear_keybuf();
large_dialog(gamemode_dlg);
bool customized = false;
while((ret=do_zqdialog(gamemode_dlg,focus_obj))==1)
{
blit(screen,tmp_scr,scrx,scry,0,0,320,240);
int32_t sel=0;
static EXT_LIST list[] =
{
{ (char *)"ZC Quests (*.qst)", (char *)"qst" },
{ NULL, NULL }