forked from pret/pokeemerald
-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathmystery_gift_menu.c
1626 lines (1537 loc) · 47.1 KB
/
mystery_gift_menu.c
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 "global.h"
#include "main.h"
#include "text.h"
#include "task.h"
#include "malloc.h"
#include "gpu_regs.h"
#include "scanline_effect.h"
#include "text_window.h"
#include "bg.h"
#include "window.h"
#include "strings.h"
#include "text_window.h"
#include "menu.h"
#include "palette.h"
#include "constants/songs.h"
#include "sound.h"
#include "mystery_gift_menu.h"
#include "union_room.h"
#include "title_screen.h"
#include "ereader_screen.h"
#include "international_string_util.h"
#include "list_menu.h"
#include "string_util.h"
#include "mystery_gift.h"
#include "mystery_gift_view.h"
#include "save.h"
#include "link.h"
#include "mystery_gift_client.h"
#include "mystery_gift_server.h"
#include "event_data.h"
#include "link_rfu.h"
#include "wonder_news.h"
#include "constants/cable_club.h"
enum {
WIN_HEADER,
WIN_MSG,
WIN_UNK, // Cleared, but nothing is ever apparently rendered on it
};
#define LIST_MENU_TILE_NUM 10
#define LIST_MENU_PAL_NUM BG_PLTT_ID(14)
static void LoadMysteryGiftTextboxBorder(u8 bgId);
static void CreateMysteryGiftTask(void);
static void Task_MysteryGift(u8 taskId);
EWRAM_DATA static u8 sDownArrowCounterAndYCoordIdx[8] = {};
EWRAM_DATA bool8 gGiftIsFromEReader = FALSE;
static const u16 sTextboxBorder_Pal[] = INCBIN_U16("graphics/interface/mystery_gift_textbox_border.gbapal");
static const u32 sTextboxBorder_Gfx[] = INCBIN_U32("graphics/interface/mystery_gift_textbox_border.4bpp.lz");
struct MysteryGiftTaskData
{
u16 var; // Multipurpose
u16 unused1;
u16 unused2;
u16 unused3;
u8 state;
u8 textState;
u8 unused4;
u8 unused5;
bool8 isWonderNews;
bool8 sourceIsFriend;
u8 msgId;
u8 * clientMsg;
};
static const struct BgTemplate sBGTemplates[] = {
{
.bg = 0,
.charBaseIndex = 2,
.mapBaseIndex = 15,
.screenSize = 0,
.paletteMode = 0,
.priority = 0,
.baseTile = 0x000
}, {
.bg = 1,
.charBaseIndex = 0,
.mapBaseIndex = 14,
.screenSize = 0,
.paletteMode = 0,
.priority = 1,
.baseTile = 0x000
}, {
.bg = 2,
.charBaseIndex = 0,
.mapBaseIndex = 13,
.screenSize = 0,
.paletteMode = 0,
.priority = 2,
.baseTile = 0x000
}, {
.bg = 3,
.charBaseIndex = 0,
.mapBaseIndex = 12,
.screenSize = 0,
.paletteMode = 0,
.priority = 3,
.baseTile = 0x000
}
};
static const struct WindowTemplate sMainWindows[] = {
[WIN_HEADER] = {
.bg = 0,
.tilemapLeft = 0,
.tilemapTop = 0,
.width = DISPLAY_TILE_WIDTH,
.height = 2,
.paletteNum = 12,
.baseBlock = 0x0013
},
[WIN_MSG] = {
.bg = 0,
.tilemapLeft = 1,
.tilemapTop = 15,
.width = 28,
.height = 4,
.paletteNum = 12,
.baseBlock = 0x004f
},
[WIN_UNK] = {
.bg = 0,
.tilemapLeft = 0,
.tilemapTop = 15,
.width = DISPLAY_TILE_WIDTH,
.height = 5,
.paletteNum = 13,
.baseBlock = 0x004f
},
DUMMY_WIN_TEMPLATE
};
static const struct WindowTemplate sWindowTemplate_YesNoMsg_Wide = {
.bg = 0,
.tilemapLeft = 1,
.tilemapTop = 15,
.width = 28,
.height = 4,
.paletteNum = 12,
.baseBlock = 0x00e5
};
static const struct WindowTemplate sWindowTemplate_YesNoMsg = {
.bg = 0,
.tilemapLeft = 1,
.tilemapTop = 15,
.width = 20,
.height = 4,
.paletteNum = 12,
.baseBlock = 0x00e5
};
static const struct WindowTemplate sWindowTemplate_GiftSelect = {
.bg = 0,
.tilemapLeft = 1,
.tilemapTop = 15,
.width = 19,
.height = 4,
.paletteNum = 12,
.baseBlock = 0x00e5
};
static const struct WindowTemplate sWindowTemplate_ThreeOptions = {
.bg = 0,
.tilemapLeft = 8,
.tilemapTop = 6,
.width = 14,
.height = 6,
.paletteNum = 12,
.baseBlock = 0x0155
};
static const struct WindowTemplate sWindowTemplate_YesNoBox = {
.bg = 0,
.tilemapLeft = 23,
.tilemapTop = 15,
.width = 6,
.height = 4,
.paletteNum = 12,
.baseBlock = 0x0155
};
static const struct WindowTemplate sWindowTemplate_GiftSelect_3Options = {
.bg = 0,
.tilemapLeft = 22,
.tilemapTop = 11,
.width = 7,
.height = 8,
.paletteNum = 12,
.baseBlock = 0x0155
};
static const struct WindowTemplate sWindowTemplate_GiftSelect_2Options = {
.bg = 0,
.tilemapLeft = 22,
.tilemapTop = 13,
.width = 7,
.height = 6,
.paletteNum = 12,
.baseBlock = 0x0155
};
static const struct WindowTemplate sWindowTemplate_GiftSelect_1Option = {
.bg = 0,
.tilemapLeft = 22,
.tilemapTop = 15,
.width = 7,
.height = 4,
.paletteNum = 12,
.baseBlock = 0x0155
};
static const struct ListMenuItem sListMenuItems_CardsOrNews[] = {
{ gText_WonderCards, 0 },
{ gText_WonderNews, 1 },
{ gText_Exit3, LIST_CANCEL }
};
static const struct ListMenuItem sListMenuItems_WirelessOrFriend[] = {
{ gText_WirelessCommunication, 0 },
{ gText_Friend2, 1 },
{ gText_Cancel2, LIST_CANCEL }
};
static const struct ListMenuTemplate sListMenuTemplate_ThreeOptions = {
.items = NULL,
.moveCursorFunc = ListMenuDefaultCursorMoveFunc,
.itemPrintFunc = NULL,
.totalItems = 3,
.maxShowed = 3,
.windowId = 0, // Overwritten by DoMysteryGiftListMenu
.header_X = 0,
.item_X = 8,
.cursor_X = 0,
.upText_Y = 1,
.cursorPal = 2,
.fillValue = 1,
.cursorShadowPal = 3,
.lettersSpacing = 0,
.itemVerticalPadding = 0,
.scrollMultiple = LIST_NO_MULTIPLE_SCROLL,
.fontId = FONT_NORMAL,
.cursorKind = CURSOR_BLACK_ARROW
};
static const struct ListMenuItem sListMenuItems_ReceiveSendToss[] = {
{ gText_Receive, 0 },
{ gText_Send, 1 },
{ gText_Toss, 2 },
{ gText_Cancel2, LIST_CANCEL }
};
static const struct ListMenuItem sListMenuItems_ReceiveToss[] = {
{ gText_Receive, 0 },
{ gText_Toss, 2 },
{ gText_Cancel2, LIST_CANCEL }
};
static const struct ListMenuItem sListMenuItems_ReceiveSend[] = {
{ gText_Receive, 0 },
{ gText_Send, 1 },
{ gText_Cancel2, LIST_CANCEL }
};
static const struct ListMenuItem sListMenuItems_Receive[] = {
{ gText_Receive, 0 },
{ gText_Cancel2, LIST_CANCEL }
};
static const struct ListMenuTemplate sListMenu_ReceiveSendToss = {
.items = sListMenuItems_ReceiveSendToss,
.moveCursorFunc = ListMenuDefaultCursorMoveFunc,
.itemPrintFunc = NULL,
.totalItems = 4,
.maxShowed = 4,
.windowId = 0, // Overwritten by DoMysteryGiftListMenu
.header_X = 0,
.item_X = 8,
.cursor_X = 0,
.upText_Y = 1,
.cursorPal = 2,
.fillValue = 1,
.cursorShadowPal = 3,
.lettersSpacing = 0,
.itemVerticalPadding = 0,
.scrollMultiple = LIST_NO_MULTIPLE_SCROLL,
.fontId = FONT_NORMAL,
.cursorKind = CURSOR_BLACK_ARROW
};
static const struct ListMenuTemplate sListMenu_ReceiveToss = {
.items = sListMenuItems_ReceiveToss,
.moveCursorFunc = ListMenuDefaultCursorMoveFunc,
.itemPrintFunc = NULL,
.totalItems = 3,
.maxShowed = 3,
.windowId = 0, // Overwritten by DoMysteryGiftListMenu
.header_X = 0,
.item_X = 8,
.cursor_X = 0,
.upText_Y = 1,
.cursorPal = 2,
.fillValue = 1,
.cursorShadowPal = 3,
.lettersSpacing = 0,
.itemVerticalPadding = 0,
.scrollMultiple = LIST_NO_MULTIPLE_SCROLL,
.fontId = FONT_NORMAL,
.cursorKind = CURSOR_BLACK_ARROW
};
static const struct ListMenuTemplate sListMenu_ReceiveSend = {
.items = sListMenuItems_ReceiveSend,
.moveCursorFunc = ListMenuDefaultCursorMoveFunc,
.itemPrintFunc = NULL,
.totalItems = 3,
.maxShowed = 3,
.windowId = 0, // Overwritten by DoMysteryGiftListMenu
.header_X = 0,
.item_X = 8,
.cursor_X = 0,
.upText_Y = 1,
.cursorPal = 2,
.fillValue = 1,
.cursorShadowPal = 3,
.lettersSpacing = 0,
.itemVerticalPadding = 0,
.scrollMultiple = LIST_NO_MULTIPLE_SCROLL,
.fontId = FONT_NORMAL,
.cursorKind = CURSOR_BLACK_ARROW
};
static const struct ListMenuTemplate sListMenu_Receive = {
.items = sListMenuItems_Receive,
.moveCursorFunc = ListMenuDefaultCursorMoveFunc,
.itemPrintFunc = NULL,
.totalItems = 2,
.maxShowed = 2,
.windowId = 0, // Overwritten by DoMysteryGiftListMenu
.header_X = 0,
.item_X = 8,
.cursor_X = 0,
.upText_Y = 1,
.cursorPal = 2,
.fillValue = 1,
.cursorShadowPal = 3,
.lettersSpacing = 0,
.itemVerticalPadding = 0,
.scrollMultiple = LIST_NO_MULTIPLE_SCROLL,
.fontId = FONT_NORMAL,
.cursorKind = CURSOR_BLACK_ARROW
};
static const u8 *const sUnusedMenuTexts[] = {
gText_VarietyOfEventsImportedWireless,
gText_WonderCardsInPossession,
gText_ReadNewsThatArrived,
gText_ReturnToTitle
};
ALIGNED(2) static const u8 sTextColors_Header[] = { TEXT_COLOR_TRANSPARENT, TEXT_COLOR_WHITE, TEXT_COLOR_DARK_GRAY };
ALIGNED(2) static const u8 sTextColors_Header_Copy[] = { TEXT_COLOR_TRANSPARENT, TEXT_COLOR_WHITE, TEXT_COLOR_DARK_GRAY };
ALIGNED(2) static const u8 sMG_Ereader_TextColor_2[] = { TEXT_COLOR_WHITE, TEXT_COLOR_DARK_GRAY, TEXT_COLOR_LIGHT_GRAY };
static void VBlankCB_MysteryGiftEReader(void)
{
ProcessSpriteCopyRequests();
LoadOam();
TransferPlttBuffer();
}
void CB2_MysteryGiftEReader(void)
{
RunTasks();
RunTextPrinters();
AnimateSprites();
BuildOamBuffer();
}
static bool32 HandleMysteryGiftOrEReaderSetup(s32 isEReader)
{
switch (gMain.state)
{
case 0:
SetVBlankCallback(NULL);
ResetPaletteFade();
ResetSpriteData();
FreeAllSpritePalettes();
ResetTasks();
ScanlineEffect_Stop();
ResetBgsAndClearDma3BusyFlags(0);
InitBgsFromTemplates(0, sBGTemplates, ARRAY_COUNT(sBGTemplates));
ChangeBgX(0, 0, BG_COORD_SET);
ChangeBgY(0, 0, BG_COORD_SET);
ChangeBgX(1, 0, BG_COORD_SET);
ChangeBgY(1, 0, BG_COORD_SET);
ChangeBgX(2, 0, BG_COORD_SET);
ChangeBgY(2, 0, BG_COORD_SET);
ChangeBgX(3, 0, BG_COORD_SET);
ChangeBgY(3, 0, BG_COORD_SET);
SetBgTilemapBuffer(3, Alloc(BG_SCREEN_SIZE));
SetBgTilemapBuffer(2, Alloc(BG_SCREEN_SIZE));
SetBgTilemapBuffer(1, Alloc(BG_SCREEN_SIZE));
SetBgTilemapBuffer(0, Alloc(BG_SCREEN_SIZE));
LoadMysteryGiftTextboxBorder(3);
InitWindows(sMainWindows);
DeactivateAllTextPrinters();
ClearGpuRegBits(REG_OFFSET_DISPCNT, DISPCNT_WIN0_ON | DISPCNT_WIN1_ON);
SetGpuReg(REG_OFFSET_BLDCNT, 0);
SetGpuReg(REG_OFFSET_BLDALPHA, 0);
SetGpuReg(REG_OFFSET_BLDY, 0);
gMain.state++;
break;
case 1:
LoadPalette(sTextboxBorder_Pal, BG_PLTT_ID(0), PLTT_SIZE_4BPP);
LoadPalette(GetTextWindowPalette(2), BG_PLTT_ID(13), PLTT_SIZE_4BPP);
Menu_LoadStdPalAt(BG_PLTT_ID(12));
LoadUserWindowBorderGfx(0, 0xA, BG_PLTT_ID(14));
LoadUserWindowBorderGfx_(0, 0x1, BG_PLTT_ID(15));
FillBgTilemapBufferRect(0, 0x000, 0, 0, 32, 32, 17);
FillBgTilemapBufferRect(1, 0x000, 0, 0, 32, 32, 17);
FillBgTilemapBufferRect(2, 0x000, 0, 0, 32, 32, 17);
MG_DrawCheckerboardPattern(3);
PrintMysteryGiftOrEReaderHeader(isEReader, FALSE);
gMain.state++;
break;
case 2:
CopyBgTilemapBufferToVram(3);
CopyBgTilemapBufferToVram(2);
CopyBgTilemapBufferToVram(1);
CopyBgTilemapBufferToVram(0);
gMain.state++;
break;
case 3:
ShowBg(0);
ShowBg(3);
PlayBGM(MUS_RG_MYSTERY_GIFT);
SetVBlankCallback(VBlankCB_MysteryGiftEReader);
EnableInterrupts(INTR_FLAG_VBLANK | INTR_FLAG_VCOUNT | INTR_FLAG_TIMER3 | INTR_FLAG_SERIAL);
return TRUE;
}
return FALSE;
}
void CB2_InitMysteryGift(void)
{
if (HandleMysteryGiftOrEReaderSetup(FALSE))
{
SetMainCallback2(CB2_MysteryGiftEReader);
gGiftIsFromEReader = FALSE;
CreateMysteryGiftTask();
}
RunTasks();
}
void CB2_InitEReader(void)
{
if (HandleMysteryGiftOrEReaderSetup(TRUE))
{
SetMainCallback2(CB2_MysteryGiftEReader);
gGiftIsFromEReader = TRUE;
CreateEReaderTask();
}
}
void MainCB_FreeAllBuffersAndReturnToInitTitleScreen(void)
{
gGiftIsFromEReader = FALSE;
FreeAllWindowBuffers();
Free(GetBgTilemapBuffer(0));
Free(GetBgTilemapBuffer(1));
Free(GetBgTilemapBuffer(2));
Free(GetBgTilemapBuffer(3));
SetMainCallback2(CB2_InitTitleScreen);
}
// Print the text window at the top of the screen with the title and control instructions
void PrintMysteryGiftOrEReaderHeader(bool8 isEReader, bool32 useCancel)
{
const u8 * title;
const u8 * options;
FillWindowPixelBuffer(WIN_HEADER, 0);
if (!isEReader)
{
title = gText_MysteryGift;
options = !useCancel ? gText_PickOKExit : gText_PickOKCancel;
}
else
{
title = gJPText_MysteryGift;
options = gJPText_DecideStop;
}
AddTextPrinterParameterized4(WIN_HEADER, FONT_NORMAL, 4, 1, 0, 0, sTextColors_Header, TEXT_SKIP_DRAW, title);
AddTextPrinterParameterized4(WIN_HEADER, FONT_SMALL, GetStringRightAlignXOffset(FONT_SMALL, options, 0xDE), 1, 0, 0, sTextColors_Header, TEXT_SKIP_DRAW, options);
CopyWindowToVram(WIN_HEADER, COPYWIN_GFX);
PutWindowTilemap(WIN_HEADER);
}
void MG_DrawTextBorder(u8 windowId)
{
DrawTextBorderOuter(windowId, 0x01, 0xF);
}
void MG_DrawCheckerboardPattern(u32 bg)
{
s32 i = 0, j;
FillBgTilemapBufferRect(bg, 0x003, 0, 0, 32, 2, 17);
for (i = 0; i < 18; i++)
{
for (j = 0; j < 32; j++)
{
if ((i & 1) != (j & 1))
FillBgTilemapBufferRect(bg, 1, j, i + 2, 1, 1, 17);
else
FillBgTilemapBufferRect(bg, 2, j, i + 2, 1, 1, 17);
}
}
}
static void ClearScreenInBg0(bool32 ignoreTopTwoRows)
{
switch (ignoreTopTwoRows)
{
case 0:
FillBgTilemapBufferRect(0, 0, 0, 0, 32, 32, 17);
break;
case 1:
FillBgTilemapBufferRect(0, 0, 0, 2, 32, 30, 17);
break;
}
CopyBgTilemapBufferToVram(0);
}
void MG_AddMessageTextPrinter(const u8 *str)
{
StringExpandPlaceholders(gStringVar4, str);
FillWindowPixelBuffer(WIN_MSG, 0x11);
AddTextPrinterParameterized4(WIN_MSG, FONT_NORMAL, 0, 1, 0, 0, sMG_Ereader_TextColor_2, 0, gStringVar4);
DrawTextBorderOuter(WIN_MSG, 0x001, 0xF);
PutWindowTilemap(WIN_MSG);
CopyWindowToVram(WIN_MSG, COPYWIN_FULL);
}
static void ClearMessage(void)
{
rbox_fill_rectangle(WIN_MSG);
ClearWindowTilemap(WIN_MSG);
CopyWindowToVram(WIN_MSG, COPYWIN_MAP);
}
#define DOWN_ARROW_X 208
#define DOWN_ARROW_Y 20
bool32 PrintMysteryGiftMenuMessage(u8 *textState, const u8 *str)
{
switch (*textState)
{
case 0:
MG_AddMessageTextPrinter(str);
(*textState)++;
break;
case 1:
DrawDownArrow(WIN_MSG, DOWN_ARROW_X, DOWN_ARROW_Y, 1, FALSE, &sDownArrowCounterAndYCoordIdx[0], &sDownArrowCounterAndYCoordIdx[1]);
if (JOY_NEW(A_BUTTON | B_BUTTON))
(*textState)++;
break;
case 2:
DrawDownArrow(WIN_MSG, DOWN_ARROW_X, DOWN_ARROW_Y, 1, TRUE, &sDownArrowCounterAndYCoordIdx[0], &sDownArrowCounterAndYCoordIdx[1]);
*textState = 0;
ClearMessage();
return TRUE;
case 0xFF:
*textState = 2;
return FALSE;
}
return FALSE;
}
static void HideDownArrow(void)
{
DrawDownArrow(WIN_MSG, DOWN_ARROW_X, DOWN_ARROW_Y, 1, FALSE, &sDownArrowCounterAndYCoordIdx[0], &sDownArrowCounterAndYCoordIdx[1]);
}
static void ShowDownArrow(void)
{
DrawDownArrow(WIN_MSG, DOWN_ARROW_X, DOWN_ARROW_Y, 1, TRUE, &sDownArrowCounterAndYCoordIdx[0], &sDownArrowCounterAndYCoordIdx[1]);
}
static bool32 UNUSED HideDownArrowAndWaitButton(u8 * textState)
{
switch (*textState)
{
case 0:
HideDownArrow();
if (JOY_NEW(A_BUTTON | B_BUTTON))
(*textState)++;
break;
case 1:
ShowDownArrow();
*textState = 0;
return TRUE;
}
return FALSE;
}
static bool32 PrintStringAndWait2Seconds(u8 * counter, const u8 * str)
{
if (*counter == 0)
MG_AddMessageTextPrinter(str);
if (++(*counter) > 120)
{
*counter = 0;
ClearMessage();
return TRUE;
}
else
{
return FALSE;
}
}
static u32 MysteryGift_HandleThreeOptionMenu(u8 * unused0, u16 * unused1, u8 whichMenu)
{
struct ListMenuTemplate listMenuTemplate = sListMenuTemplate_ThreeOptions;
struct WindowTemplate windowTemplate = sWindowTemplate_ThreeOptions;
s32 width;
s32 response;
if (whichMenu == 0)
listMenuTemplate.items = sListMenuItems_CardsOrNews;
else
listMenuTemplate.items = sListMenuItems_WirelessOrFriend;
width = Intl_GetListMenuWidth(&listMenuTemplate);
if (width & 1)
width++;
windowTemplate.width = width;
if (width < DISPLAY_TILE_WIDTH)
windowTemplate.tilemapLeft = (DISPLAY_TILE_WIDTH - width) / 2;
else
windowTemplate.tilemapLeft = 0;
response = DoMysteryGiftListMenu(&windowTemplate, &listMenuTemplate, 1, LIST_MENU_TILE_NUM, LIST_MENU_PAL_NUM);
if (response != LIST_NOTHING_CHOSEN)
{
ClearWindowTilemap(WIN_UNK);
CopyWindowToVram(WIN_UNK, COPYWIN_MAP);
}
return response;
}
s8 DoMysteryGiftYesNo(u8 * textState, u16 * windowId, bool8 yesNoBoxPlacement, const u8 * str)
{
struct WindowTemplate windowTemplate;
s8 input;
switch (*textState)
{
case 0:
// Print question message
StringExpandPlaceholders(gStringVar4, str);
if (yesNoBoxPlacement == 0)
*windowId = AddWindow(&sWindowTemplate_YesNoMsg_Wide);
else
*windowId = AddWindow(&sWindowTemplate_YesNoMsg);
FillWindowPixelBuffer(*windowId, 0x11);
AddTextPrinterParameterized4(*windowId, FONT_NORMAL, 0, 1, 0, 0, sMG_Ereader_TextColor_2, 0, gStringVar4);
DrawTextBorderOuter(*windowId, 0x001, 0x0F);
CopyWindowToVram(*windowId, COPYWIN_GFX);
PutWindowTilemap(*windowId);
(*textState)++;
break;
case 1:
// Create Yes/No
windowTemplate = sWindowTemplate_YesNoBox;
if (yesNoBoxPlacement == 0)
windowTemplate.tilemapTop = 9;
else
windowTemplate.tilemapTop = 15;
CreateYesNoMenu(&windowTemplate, 10, 14, 0);
(*textState)++;
break;
case 2:
// Handle Yes/No input
input = Menu_ProcessInputNoWrapClearOnChoose();
if (input == MENU_B_PRESSED || input == 0 || input == 1)
{
*textState = 0;
rbox_fill_rectangle(*windowId);
ClearWindowTilemap(*windowId);
CopyWindowToVram(*windowId, COPYWIN_MAP);
RemoveWindow(*windowId);
return input;
}
break;
case 0xFF:
*textState = 0;
rbox_fill_rectangle(*windowId);
ClearWindowTilemap(*windowId);
CopyWindowToVram(*windowId, COPYWIN_MAP);
RemoveWindow(*windowId);
return MENU_B_PRESSED;
}
return MENU_NOTHING_CHOSEN;
}
// Handle the "Receive/Send/Toss" menu that appears when selecting Wonder Card/News
static s32 HandleGiftSelectMenu(u8 * textState, u16 * windowId, bool32 cannotToss, bool32 cannotSend)
{
struct WindowTemplate UNUSED windowTemplate;
s32 input;
switch (*textState)
{
case 0:
// Print menu message
if (!cannotToss)
StringExpandPlaceholders(gStringVar4, gText_WhatToDoWithCards);
else
StringExpandPlaceholders(gStringVar4, gText_WhatToDoWithNews);
*windowId = AddWindow(&sWindowTemplate_GiftSelect);
FillWindowPixelBuffer(*windowId, 0x11);
AddTextPrinterParameterized4(*windowId, FONT_NORMAL, 0, 1, 0, 0, sMG_Ereader_TextColor_2, 0, gStringVar4);
DrawTextBorderOuter(*windowId, 0x001, 0x0F);
CopyWindowToVram(*windowId, COPYWIN_GFX);
PutWindowTilemap(*windowId);
(*textState)++;
break;
case 1:
windowTemplate = sWindowTemplate_YesNoBox;
if (cannotSend)
{
if (!cannotToss)
input = DoMysteryGiftListMenu(&sWindowTemplate_GiftSelect_2Options, &sListMenu_ReceiveToss, 1, LIST_MENU_TILE_NUM, LIST_MENU_PAL_NUM);
else
input = DoMysteryGiftListMenu(&sWindowTemplate_GiftSelect_1Option, &sListMenu_Receive, 1, LIST_MENU_TILE_NUM, LIST_MENU_PAL_NUM);
}
else
{
if (!cannotToss)
input = DoMysteryGiftListMenu(&sWindowTemplate_GiftSelect_3Options, &sListMenu_ReceiveSendToss, 1, LIST_MENU_TILE_NUM, LIST_MENU_PAL_NUM);
else
input = DoMysteryGiftListMenu(&sWindowTemplate_GiftSelect_2Options, &sListMenu_ReceiveSend, 1, LIST_MENU_TILE_NUM, LIST_MENU_PAL_NUM);
}
if (input != LIST_NOTHING_CHOSEN)
{
*textState = 0;
rbox_fill_rectangle(*windowId);
ClearWindowTilemap(*windowId);
CopyWindowToVram(*windowId, COPYWIN_MAP);
RemoveWindow(*windowId);
return input;
}
break;
case 0xFF:
*textState = 0;
rbox_fill_rectangle(*windowId);
ClearWindowTilemap(*windowId);
CopyWindowToVram(*windowId, COPYWIN_MAP);
RemoveWindow(*windowId);
return LIST_CANCEL;
}
return LIST_NOTHING_CHOSEN;
}
static bool32 ValidateCardOrNews(bool32 isWonderNews)
{
if (!isWonderNews)
return ValidateSavedWonderCard();
else
return ValidateSavedWonderNews();
}
static bool32 HandleLoadWonderCardOrNews(u8 * state, bool32 isWonderNews)
{
switch (*state)
{
case 0:
if (!isWonderNews)
WonderCard_Init(GetSavedWonderCard(), GetSavedWonderCardMetadata());
else
WonderNews_Init(GetSavedWonderNews());
(*state)++;
break;
case 1:
if (!isWonderNews)
{
if (!WonderCard_Enter())
return FALSE;
}
else
{
if (!WonderNews_Enter())
return FALSE;
}
*state = 0;
return TRUE;
}
return FALSE;
}
static bool32 ClearSavedNewsOrCard(bool32 isWonderNews)
{
if (!isWonderNews)
ClearSavedWonderCardAndRelated();
else
ClearSavedWonderNewsAndRelated();
return TRUE;
}
static bool32 ExitWonderCardOrNews(bool32 isWonderNews, bool32 useCancel)
{
if (!isWonderNews)
{
if (WonderCard_Exit(useCancel))
{
WonderCard_Destroy();
return TRUE;
}
else
{
return FALSE;
}
}
else
{
if (WonderNews_Exit(useCancel))
{
WonderNews_Destroy();
return TRUE;
}
else
{
return FALSE;
}
}
}
static s32 AskDiscardGift(u8 * textState, u16 * windowId, bool32 isWonderNews)
{
if (!isWonderNews)
return DoMysteryGiftYesNo(textState, windowId, TRUE, gText_IfThrowAwayCardEventWontHappen);
else
return DoMysteryGiftYesNo(textState, windowId, TRUE, gText_OkayToDiscardNews);
}
static bool32 PrintThrownAway(u8 * textState, bool32 isWonderNews)
{
if (!isWonderNews)
return PrintMysteryGiftMenuMessage(textState, gText_WonderCardThrownAway);
else
return PrintMysteryGiftMenuMessage(textState, gText_WonderNewsThrownAway);
}
static bool32 SaveOnMysteryGiftMenu(u8 * state)
{
switch (*state)
{
case 0:
MG_AddMessageTextPrinter(gText_DataWillBeSaved);
(*state)++;
break;
case 1:
TrySavingData(SAVE_NORMAL);
(*state)++;
break;
case 2:
MG_AddMessageTextPrinter(gText_SaveCompletedPressA);
(*state)++;
break;
case 3:
if (JOY_NEW(A_BUTTON | B_BUTTON))
(*state)++;
break;
case 4:
*state = 0;
ClearMessage();
return TRUE;
}
return FALSE;
}
static const u8 * GetClientResultMessage(bool32 * successMsg, bool8 isWonderNews, bool8 sourceIsFriend, u32 msgId)
{
const u8 * msg = NULL;
*successMsg = FALSE;
switch (msgId)
{
case CLI_MSG_NOTHING_SENT:
*successMsg = FALSE;
msg = gText_NothingSentOver;
break;
case CLI_MSG_RECORD_UPLOADED:
*successMsg = FALSE;
msg = gText_RecordUploadedViaWireless;
break;
case CLI_MSG_CARD_RECEIVED:
*successMsg = TRUE;
msg = !sourceIsFriend ? gText_WonderCardReceived : gText_WonderCardReceivedFrom;
break;
case CLI_MSG_NEWS_RECEIVED:
*successMsg = TRUE;
msg = !sourceIsFriend ? gText_WonderNewsReceived : gText_WonderNewsReceivedFrom;
break;
case CLI_MSG_STAMP_RECEIVED:
*successMsg = TRUE;
msg = gText_NewStampReceived;
break;
case CLI_MSG_HAD_CARD:
*successMsg = FALSE;
msg = gText_AlreadyHadCard;
break;
case CLI_MSG_HAD_STAMP:
*successMsg = FALSE;
msg = gText_AlreadyHadStamp;
break;
case CLI_MSG_HAD_NEWS:
*successMsg = FALSE;
msg = gText_AlreadyHadNews;
break;
case CLI_MSG_NO_ROOM_STAMPS:
*successMsg = FALSE;
msg = gText_NoMoreRoomForStamps;
break;
case CLI_MSG_COMM_CANCELED:
*successMsg = FALSE;
msg = gText_CommunicationCanceled;
break;
case CLI_MSG_CANT_ACCEPT:
*successMsg = FALSE;
msg = !isWonderNews ? gText_CantAcceptCardFromTrainer : gText_CantAcceptNewsFromTrainer;
break;
case CLI_MSG_COMM_ERROR:
*successMsg = FALSE;
msg = gText_CommunicationError;
break;
case CLI_MSG_TRAINER_RECEIVED:
*successMsg = TRUE;
msg = gText_NewTrainerReceived;
break;
case CLI_MSG_BUFFER_SUCCESS:
*successMsg = TRUE;
// msg is NULL, use buffer
break;
case CLI_MSG_BUFFER_FAILURE:
*successMsg = FALSE;
// msg is NULL, use buffer
break;
}
return msg;
}
static bool32 PrintSuccessMessage(u8 * state, const u8 * msg, u16 * timer)
{
switch (*state)
{
case 0:
if (msg != NULL)
MG_AddMessageTextPrinter(msg);
PlayFanfare(MUS_OBTAIN_ITEM);
*timer = 0;
(*state)++;
break;
case 1:
if (++(*timer) > 240)
(*state)++;
break;
case 2:
if (IsFanfareTaskInactive())
{
*state = 0;
ClearMessage();
return TRUE;
}
break;
}
return FALSE;
}
static const u8 * GetServerResultMessage(bool32 * wonderSuccess, bool8 sourceIsFriend, u32 msgId)
{