pokeemerald/src/mystery_gift.c

1704 lines
42 KiB
C
Raw Normal View History

2019-03-30 18:14:00 +01:00
#include "global.h"
#include "main.h"
#include "text.h"
#include "task.h"
#include "alloc.h"
#include "gpu_regs.h"
#include "scanline_effect.h"
#include "text_window.h"
#include "bg.h"
#include "window.h"
2019-03-30 19:36:52 +01:00
#include "strings.h"
2019-03-30 18:14:00 +01:00
#include "text_window.h"
#include "menu.h"
#include "palette.h"
#include "constants/songs.h"
#include "sound.h"
#include "mystery_gift.h"
2019-03-30 19:36:52 +01:00
#include "union_room.h"
#include "title_screen.h"
#include "ereader_screen.h"
#include "international_string_util.h"
#include "list_menu.h"
2019-03-31 01:04:30 +01:00
#include "string_util.h"
2019-03-31 17:16:19 +02:00
#include "mevent.h"
#include "mevent_801BAAC.h"
2019-03-31 18:27:36 +02:00
#include "save.h"
2019-03-31 21:50:25 +02:00
#include "link.h"
#include "mevent_server_ish.h"
#include "event_data.h"
#include "link_rfu.h"
#include "mevent_news.h"
#include "mevent_server.h"
2019-03-30 18:14:00 +01:00
void bgid_upload_textbox_1(u8 bgId);
2019-03-30 19:36:52 +01:00
void task_add_00_mystery_gift(void);
2019-03-31 18:55:27 +02:00
void task00_mystery_gift(u8 taskId);
2019-03-30 19:36:52 +01:00
2019-04-01 00:59:52 +02:00
EWRAM_DATA u8 sDownArrowCounterAndYCoordIdx[8] = {};
EWRAM_DATA bool8 gGiftIsFromEReader = FALSE;
2019-03-30 18:14:00 +01:00
2019-04-01 00:59:52 +02:00
static const u16 gUnkTextboxBorderPal[] = INCBIN_U16("graphics/interface/unk_textbox_border.gbapal");
static const u32 gUnkTextboxBorderGfx[] = INCBIN_U32("graphics/interface/unk_textbox_border.4bpp.lz");
2019-03-30 18:14:00 +01:00
2019-03-31 18:55:27 +02:00
struct MysteryGiftTaskData
{
2019-04-01 00:59:52 +02:00
u16 curPromptWindowId;
2019-03-31 18:55:27 +02:00
u16 unk2;
u16 unk4;
u16 unk6;
2019-04-01 00:59:52 +02:00
u8 state;
u8 textState;
2019-03-31 18:55:27 +02:00
u8 unkA;
u8 unkB;
2019-04-01 00:59:52 +02:00
u8 IsCardOrNews;
u8 source;
u8 prevPromptWindowId;
u8 * buffer;
2019-03-31 18:55:27 +02:00
};
2019-04-01 00:59:52 +02:00
static const struct BgTemplate sBGTemplates[] = {
2019-03-30 18:14:00 +01:00
{
.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
}
};
2019-04-01 00:59:52 +02:00
static const struct WindowTemplate sMainWindows[] = {
2019-03-30 18:14:00 +01:00
{
.bg = 0x00,
.tilemapLeft = 0x00,
.tilemapTop = 0x00,
.width = 0x1e,
.height = 0x02,
.paletteNum = 0x0c,
.baseBlock = 0x0013
}, {
.bg = 0x00,
.tilemapLeft = 0x01,
.tilemapTop = 0x0f,
.width = 0x1c,
.height = 0x04,
.paletteNum = 0x0c,
.baseBlock = 0x004f
}, {
.bg = 0x00,
.tilemapLeft = 0x00,
.tilemapTop = 0x0f,
.width = 0x1e,
.height = 0x05,
.paletteNum = 0x0d,
.baseBlock = 0x004f
}, {
0xFF
}
};
2019-04-01 00:59:52 +02:00
static const struct WindowTemplate sWindowTemplate_PromptYesOrNo_Width28 = {
2019-03-30 18:14:00 +01:00
.bg = 0x00,
.tilemapLeft = 0x01,
.tilemapTop = 0x0f,
.width = 0x1c,
.height = 0x04,
.paletteNum = 0x0c,
.baseBlock = 0x00e5
};
2019-04-01 00:59:52 +02:00
static const struct WindowTemplate sWindowTemplate_PromptYesOrNo_Width20 = {
2019-03-30 18:14:00 +01:00
.bg = 0x00,
.tilemapLeft = 0x01,
.tilemapTop = 0x0f,
.width = 0x14,
.height = 0x04,
.paletteNum = 0x0c,
.baseBlock = 0x00e5
};
2019-04-01 00:59:52 +02:00
static const struct WindowTemplate sMysteryGiftMenuWindowTemplate = {
2019-03-30 18:14:00 +01:00
.bg = 0x00,
.tilemapLeft = 0x01,
.tilemapTop = 0x0f,
.width = 0x13,
.height = 0x04,
.paletteNum = 0x0c,
.baseBlock = 0x00e5
};
2019-04-01 00:59:52 +02:00
static const struct WindowTemplate sWindowTemplate_ThreeOptions = {
2019-03-30 18:14:00 +01:00
.bg = 0x00,
.tilemapLeft = 0x08,
.tilemapTop = 0x06,
.width = 0x0e,
.height = 0x06,
.paletteNum = 0x0c,
.baseBlock = 0x0155
};
2019-04-01 00:59:52 +02:00
static const struct WindowTemplate sWindowTemplate_YesNoBox = {
2019-03-30 18:14:00 +01:00
.bg = 0x00,
.tilemapLeft = 0x17,
.tilemapTop = 0x0f,
.width = 0x06,
.height = 0x04,
.paletteNum = 0x0c,
.baseBlock = 0x0155
};
2019-04-01 00:59:52 +02:00
static const struct WindowTemplate sWindowTemplate_7by8 = {
2019-03-30 18:14:00 +01:00
.bg = 0x00,
.tilemapLeft = 0x16,
.tilemapTop = 0x0b,
.width = 0x07,
.height = 0x08,
.paletteNum = 0x0c,
.baseBlock = 0x0155
};
2019-04-01 00:59:52 +02:00
static const struct WindowTemplate sWindowTemplate_7by6 = {
2019-03-30 18:14:00 +01:00
.bg = 0x00,
.tilemapLeft = 0x16,
.tilemapTop = 0x0d,
.width = 0x07,
.height = 0x06,
.paletteNum = 0x0c,
.baseBlock = 0x0155
};
2019-04-01 00:59:52 +02:00
static const struct WindowTemplate sWindowTemplate_7by4 = {
2019-03-30 18:14:00 +01:00
.bg = 0x00,
.tilemapLeft = 0x16,
.tilemapTop = 0x0f,
.width = 0x07,
.height = 0x04,
.paletteNum = 0x0c,
.baseBlock = 0x0155
};
2019-04-01 00:59:52 +02:00
static const struct ListMenuItem sListMenuItems_CardsOrNews[] = {
2019-03-30 19:36:52 +01:00
{ gText_WonderCards, 0 },
{ gText_WonderNews, 1 },
{ gText_Exit3, -2 }
};
2019-04-01 00:59:52 +02:00
static const struct ListMenuItem sListMenuItems_WirelessOrFriend[] = {
2019-03-30 19:36:52 +01:00
{ gText_WirelessCommunication, 0 },
{ gText_Friend2, 1 },
{ gText_Cancel2, -2 }
};
2019-04-01 00:59:52 +02:00
static const struct ListMenuTemplate sListMenuTemplate_ThreeOptions = {
2019-03-30 19:36:52 +01:00
.items = NULL,
.moveCursorFunc = ListMenuDefaultCursorMoveFunc,
.itemPrintFunc = NULL,
.totalItems = 3,
.maxShowed = 3,
.windowId = 0,
.header_X = 0,
.item_X = 8,
.cursor_X = 0,
.upText_Y = 1,
.cursorPal = 2,
.fillValue = 1,
.cursorShadowPal = 3,
.lettersSpacing = 0,
.itemVerticalPadding = 0,
.scrollMultiple = 0,
.fontId = 1,
.cursorKind = 0
};
2019-04-01 00:59:52 +02:00
static const struct ListMenuItem sListMenuItems_ReceiveSendToss[] = {
2019-03-30 19:36:52 +01:00
{ gText_Receive, 0 },
{ gText_Send, 1 },
{ gText_Toss, 2 },
{ gText_Cancel2, -2 }
};
2019-04-01 00:59:52 +02:00
static const struct ListMenuItem sListMenuItems_ReceiveToss[] = {
2019-03-30 19:36:52 +01:00
{ gText_Receive, 0 },
{ gText_Toss, 2 },
{ gText_Cancel2, -2 }
};
2019-04-01 00:59:52 +02:00
static const struct ListMenuItem sListMenuItems_ReceiveSend[] = {
2019-03-30 19:36:52 +01:00
{ gText_Receive, 0 },
{ gText_Send, 1 },
{ gText_Cancel2, -2 }
};
2019-04-01 00:59:52 +02:00
static const struct ListMenuItem sListMenuItems_Receive[] = {
2019-03-30 19:36:52 +01:00
{ gText_Receive, 0 },
{ gText_Cancel2, -2 }
};
2019-04-01 00:59:52 +02:00
static const struct ListMenuTemplate sListMenu_ReceiveSendToss = {
.items = sListMenuItems_ReceiveSendToss,
2019-03-30 19:36:52 +01:00
.moveCursorFunc = ListMenuDefaultCursorMoveFunc,
.itemPrintFunc = NULL,
.totalItems = 4,
.maxShowed = 4,
.windowId = 0,
.header_X = 0,
.item_X = 8,
.cursor_X = 0,
.upText_Y = 1,
.cursorPal = 2,
.fillValue = 1,
.cursorShadowPal = 3,
.lettersSpacing = 0,
.itemVerticalPadding = 0,
.scrollMultiple = 0,
.fontId = 1,
.cursorKind = 0
};
2019-04-01 00:59:52 +02:00
static const struct ListMenuTemplate sListMenu_ReceiveToss = {
.items = sListMenuItems_ReceiveToss,
2019-03-30 19:36:52 +01:00
.moveCursorFunc = ListMenuDefaultCursorMoveFunc,
.itemPrintFunc = NULL,
.totalItems = 3,
.maxShowed = 3,
.windowId = 0,
.header_X = 0,
.item_X = 8,
.cursor_X = 0,
.upText_Y = 1,
.cursorPal = 2,
.fillValue = 1,
.cursorShadowPal = 3,
.lettersSpacing = 0,
.itemVerticalPadding = 0,
.scrollMultiple = 0,
.fontId = 1,
.cursorKind = 0
};
2019-04-01 00:59:52 +02:00
static const struct ListMenuTemplate sListMenu_ReceiveSend = {
.items = sListMenuItems_ReceiveSend,
2019-03-30 19:36:52 +01:00
.moveCursorFunc = ListMenuDefaultCursorMoveFunc,
.itemPrintFunc = NULL,
.totalItems = 3,
.maxShowed = 3,
.windowId = 0,
.header_X = 0,
.item_X = 8,
.cursor_X = 0,
.upText_Y = 1,
.cursorPal = 2,
.fillValue = 1,
.cursorShadowPal = 3,
.lettersSpacing = 0,
.itemVerticalPadding = 0,
.scrollMultiple = 0,
.fontId = 1,
.cursorKind = 0
};
2019-04-01 00:59:52 +02:00
static const struct ListMenuTemplate sListMenu_Receive = {
.items = sListMenuItems_Receive,
2019-03-30 19:36:52 +01:00
.moveCursorFunc = ListMenuDefaultCursorMoveFunc,
.itemPrintFunc = NULL,
.totalItems = 2,
.maxShowed = 2,
.windowId = 0,
.header_X = 0,
.item_X = 8,
.cursor_X = 0,
.upText_Y = 1,
.cursorPal = 2,
.fillValue = 1,
.cursorShadowPal = 3,
.lettersSpacing = 0,
.itemVerticalPadding = 0,
.scrollMultiple = 0,
.fontId = 1,
.cursorKind = 0
};
2019-04-01 00:59:52 +02:00
static const u8 *const Unref_082F0710[] = {
2019-03-30 19:36:52 +01:00
gText_VarietyOfEventsImportedWireless,
gText_WonderCardsInPossession,
gText_ReadNewsThatArrived,
gText_ReturnToTitle
};
2019-04-01 00:59:52 +02:00
ALIGNED(2) const u8 sMG_Ereader_TextColor_1[] = { 0, 1, 2 };
ALIGNED(2) const u8 sMG_Ereader_TextColor_1_Copy[] = { 0, 1, 2 };
ALIGNED(2) const u8 sMG_Ereader_TextColor_2[] = { 1, 2, 3 };
2019-03-30 19:36:52 +01:00
2019-04-01 00:59:52 +02:00
void vblankcb_mystery_gift_e_reader_run(void)
2019-03-30 18:14:00 +01:00
{
ProcessSpriteCopyRequests();
LoadOam();
TransferPlttBuffer();
}
2019-04-01 00:59:52 +02:00
void c2_mystery_gift_e_reader_run(void)
2019-03-30 18:14:00 +01:00
{
RunTasks();
RunTextPrinters();
AnimateSprites();
BuildOamBuffer();
}
2019-04-01 00:59:52 +02:00
bool32 HandleMysteryGiftOrEReaderSetup(s32 mg_or_ereader)
2019-03-30 18:14:00 +01:00
{
switch (gMain.state)
{
case 0:
SetVBlankCallback(NULL);
ResetPaletteFade();
ResetSpriteData();
FreeAllSpritePalettes();
ResetTasks();
ScanlineEffect_Stop();
ResetBgsAndClearDma3BusyFlags(0);
2019-04-01 00:59:52 +02:00
InitBgsFromTemplates(0, sBGTemplates, ARRAY_COUNT(sBGTemplates));
2019-03-30 18:14:00 +01:00
ChangeBgX(0, 0, 0);
ChangeBgY(0, 0, 0);
ChangeBgX(1, 0, 0);
ChangeBgY(1, 0, 0);
ChangeBgX(2, 0, 0);
ChangeBgY(2, 0, 0);
ChangeBgX(3, 0, 0);
ChangeBgY(3, 0, 0);
SetBgTilemapBuffer(3, Alloc(0x800));
SetBgTilemapBuffer(2, Alloc(0x800));
SetBgTilemapBuffer(1, Alloc(0x800));
SetBgTilemapBuffer(0, Alloc(0x800));
bgid_upload_textbox_1(3);
2019-04-01 00:59:52 +02:00
InitWindows(sMainWindows);
2019-03-30 18:14:00 +01:00
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(gUnkTextboxBorderPal, 0, 0x20);
LoadPalette(stdpal_get(2), 0xd0, 0x20);
2019-04-01 00:59:52 +02:00
Menu_LoadStdPalAt(0xC0);
2019-03-30 18:14:00 +01:00
LoadUserWindowBorderGfx(0, 0xA, 0xE0);
LoadUserWindowBorderGfx_(0, 0x1, 0xF0);
FillBgTilemapBufferRect(0, 0x000, 0, 0, 32, 32, 0x11);
FillBgTilemapBufferRect(1, 0x000, 0, 0, 32, 32, 0x11);
FillBgTilemapBufferRect(2, 0x000, 0, 0, 32, 32, 0x11);
2019-04-01 00:59:52 +02:00
MG_DrawCheckerboardPattern(3);
PrintMysteryGiftOrEReaderTopMenu(mg_or_ereader, 0);
2019-03-30 18:14:00 +01:00
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_OKURIMONO);
2019-04-01 00:59:52 +02:00
SetVBlankCallback(vblankcb_mystery_gift_e_reader_run);
2019-03-30 18:14:00 +01:00
EnableInterrupts(INTR_FLAG_VBLANK | INTR_FLAG_VCOUNT | INTR_FLAG_TIMER3 | INTR_FLAG_SERIAL);
return TRUE;
}
return FALSE;
}
2019-03-30 19:36:52 +01:00
void c2_mystery_gift(void)
{
2019-04-01 00:59:52 +02:00
if (HandleMysteryGiftOrEReaderSetup(0))
2019-03-30 19:36:52 +01:00
{
2019-04-01 00:59:52 +02:00
SetMainCallback2(c2_mystery_gift_e_reader_run);
gGiftIsFromEReader = FALSE;
2019-03-30 19:36:52 +01:00
task_add_00_mystery_gift();
}
RunTasks();
}
2019-04-01 00:59:52 +02:00
void c2_ereader(void)
2019-03-30 19:36:52 +01:00
{
2019-04-01 00:59:52 +02:00
if (HandleMysteryGiftOrEReaderSetup(1))
2019-03-30 19:36:52 +01:00
{
2019-04-01 00:59:52 +02:00
SetMainCallback2(c2_mystery_gift_e_reader_run);
gGiftIsFromEReader = TRUE;
task_add_00_ereader();
2019-03-30 19:36:52 +01:00
}
}
2019-04-01 00:59:52 +02:00
void MainCB_FreeAllBuffersAndReturnToInitTitleScreen(void)
2019-03-30 19:36:52 +01:00
{
2019-04-01 00:59:52 +02:00
gGiftIsFromEReader = FALSE;
2019-03-30 19:36:52 +01:00
FreeAllWindowBuffers();
Free(GetBgTilemapBuffer(0));
Free(GetBgTilemapBuffer(1));
Free(GetBgTilemapBuffer(2));
Free(GetBgTilemapBuffer(3));
SetMainCallback2(CB2_InitTitleScreen);
}
2019-04-01 00:59:52 +02:00
void PrintMysteryGiftOrEReaderTopMenu(bool8 mg_or_ereader, bool32 usePickOkCancel)
2019-03-30 19:36:52 +01:00
{
const u8 * header;
const u8 * options;
FillWindowPixelBuffer(0, 0);
2019-04-01 00:59:52 +02:00
if (mg_or_ereader == 0)
2019-03-30 19:36:52 +01:00
{
header = gText_MysteryGift;
options = !usePickOkCancel ? gText_PickOKExit : gText_PickOKCancel;
}
else
{
header = gJPText_MysteryGift;
options = gJPText_DecideStop;
}
2019-04-01 00:59:52 +02:00
AddTextPrinterParameterized4(0, 1, 4, 1, 0, 0, sMG_Ereader_TextColor_1, -1, header);
AddTextPrinterParameterized4(0, 0, GetStringRightAlignXOffset(0, options, 0xDE), 1, 0, 0, sMG_Ereader_TextColor_1, -1, options);
2019-03-30 19:36:52 +01:00
CopyWindowToVram(0, 2);
PutWindowTilemap(0);
}
2019-04-01 00:59:52 +02:00
void MG_DrawTextBorder(u8 windowId)
2019-03-30 19:36:52 +01:00
{
2019-04-01 00:59:52 +02:00
DrawTextBorderOuter(windowId, 0x01, 0xF);
2019-03-30 19:36:52 +01:00
}
2019-04-01 00:59:52 +02:00
void MG_DrawCheckerboardPattern(u32 bg)
2019-03-30 19:36:52 +01:00
{
s32 i = 0, j;
FillBgTilemapBufferRect(bg, 0x003, 0, 0, 32, 2, 0x11);
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, 0x11);
}
else
{
FillBgTilemapBufferRect(bg, 2, j, i + 2, 1, 1, 0x11);
}
}
}
}
2019-03-31 01:04:30 +01:00
2019-04-01 00:59:52 +02:00
void ClearScreenInBg0(bool32 ignoreTopTwoRows)
2019-03-31 01:04:30 +01:00
{
2019-04-01 00:59:52 +02:00
switch (ignoreTopTwoRows)
2019-03-31 01:04:30 +01:00
{
case 0:
FillBgTilemapBufferRect(0, 0, 0, 0, 32, 32, 0x11);
break;
case 1:
FillBgTilemapBufferRect(0, 0, 0, 2, 32, 30, 0x11);
break;
}
CopyBgTilemapBufferToVram(0);
}
2019-04-01 00:59:52 +02:00
void AddTextPrinterToWindow1(const u8 *str)
2019-03-31 01:04:30 +01:00
{
StringExpandPlaceholders(gStringVar4, str);
FillWindowPixelBuffer(1, 0x11);
2019-04-01 00:59:52 +02:00
AddTextPrinterParameterized4(1, 1, 0, 1, 0, 0, sMG_Ereader_TextColor_2, 0, gStringVar4);
DrawTextBorderOuter(1, 0x001, 0xF);
2019-03-31 01:04:30 +01:00
PutWindowTilemap(1);
CopyWindowToVram(1, 3);
}
2019-04-01 00:59:52 +02:00
static void ClearTextWindow(void)
2019-03-31 01:04:30 +01:00
{
rbox_fill_rectangle(1);
ClearWindowTilemap(1);
CopyWindowToVram(1, 1);
}
2019-04-01 00:59:52 +02:00
bool32 MG_PrintTextOnWindow1AndWaitButton(u8 *textState, const u8 *str)
2019-03-31 01:04:30 +01:00
{
switch (*textState)
{
case 0:
2019-04-01 00:59:52 +02:00
AddTextPrinterToWindow1(str);
2019-03-31 01:04:30 +01:00
goto inc;
case 1:
2019-04-01 00:59:52 +02:00
DrawDownArrow(1, 0xD0, 0x14, 1, FALSE, &sDownArrowCounterAndYCoordIdx[0], &sDownArrowCounterAndYCoordIdx[1]);
2019-03-31 01:04:30 +01:00
if (({gMain.newKeys & (A_BUTTON | B_BUTTON);}))
{
inc:
(*textState)++;
}
break;
case 2:
2019-04-01 00:59:52 +02:00
DrawDownArrow(1, 0xD0, 0x14, 1, TRUE, &sDownArrowCounterAndYCoordIdx[0], &sDownArrowCounterAndYCoordIdx[1]);
2019-03-31 01:04:30 +01:00
*textState = 0;
2019-04-01 00:59:52 +02:00
ClearTextWindow();
2019-03-31 01:04:30 +01:00
return TRUE;
case 0xFF:
*textState = 2;
break;
}
return FALSE;
}
2019-04-01 00:59:52 +02:00
static void HideDownArrow(void)
2019-03-31 01:04:30 +01:00
{
2019-04-01 00:59:52 +02:00
DrawDownArrow(1, 0xD0, 0x14, 1, FALSE, &sDownArrowCounterAndYCoordIdx[0], &sDownArrowCounterAndYCoordIdx[1]);
2019-03-31 01:04:30 +01:00
}
2019-04-01 00:59:52 +02:00
static void ShowDownArrow(void)
2019-03-31 01:04:30 +01:00
{
2019-04-01 00:59:52 +02:00
DrawDownArrow(1, 0xD0, 0x14, 1, TRUE, &sDownArrowCounterAndYCoordIdx[0], &sDownArrowCounterAndYCoordIdx[1]);
2019-03-31 01:04:30 +01:00
}
2019-04-01 00:59:52 +02:00
bool32 unref_HideDownArrowAndWaitButton(u8 * textState)
2019-03-31 01:04:30 +01:00
{
switch (*textState)
{
case 0:
2019-04-01 00:59:52 +02:00
HideDownArrow();
2019-03-31 01:04:30 +01:00
if (({gMain.newKeys & (A_BUTTON | B_BUTTON);}))
{
(*textState)++;
}
break;
case 1:
2019-04-01 00:59:52 +02:00
ShowDownArrow();
2019-03-31 01:04:30 +01:00
*textState = 0;
return TRUE;
}
return FALSE;
}
2019-04-01 00:59:52 +02:00
static bool32 PrintStringAndWait2Seconds(u8 * counter, const u8 * str)
2019-03-31 01:04:30 +01:00
{
if (*counter == 0)
{
2019-04-01 00:59:52 +02:00
AddTextPrinterToWindow1(str);
2019-03-31 01:04:30 +01:00
}
if (++(*counter) > 120)
{
*counter = 0;
2019-04-01 00:59:52 +02:00
ClearTextWindow();
2019-03-31 01:04:30 +01:00
return TRUE;
}
else
{
return FALSE;
}
}
2019-04-01 00:59:52 +02:00
static u32 MysteryGift_HandleThreeOptionMenu(u8 * unused0, u16 * unused1, u8 whichMenu)
2019-03-31 01:04:30 +01:00
{
2019-04-01 00:59:52 +02:00
struct ListMenuTemplate listMenuTemplate = sListMenuTemplate_ThreeOptions;
struct WindowTemplate windowTemplate = sWindowTemplate_ThreeOptions;
s32 width;
s32 response;
2019-03-31 01:04:30 +01:00
2019-04-01 00:59:52 +02:00
if (whichMenu == 0)
2019-03-31 01:04:30 +01:00
{
2019-04-01 00:59:52 +02:00
listMenuTemplate.items = sListMenuItems_CardsOrNews;
2019-03-31 01:04:30 +01:00
}
else
{
2019-04-01 00:59:52 +02:00
listMenuTemplate.items = sListMenuItems_WirelessOrFriend;
2019-03-31 01:04:30 +01:00
}
2019-04-01 00:59:52 +02:00
width = Intl_GetListMenuWidth(&listMenuTemplate);
if (width & 1)
2019-03-31 01:04:30 +01:00
{
2019-04-01 00:59:52 +02:00
width++;
2019-03-31 01:04:30 +01:00
}
2019-04-01 00:59:52 +02:00
windowTemplate.width = width;
if (width < 30)
2019-03-31 01:04:30 +01:00
{
2019-04-01 00:59:52 +02:00
windowTemplate.tilemapLeft = (30 - width) / 2;
2019-03-31 01:04:30 +01:00
}
else
{
windowTemplate.tilemapLeft = 0;
}
2019-04-01 00:59:52 +02:00
response = DoMysteryGiftListMenu(&windowTemplate, &listMenuTemplate, 1, 0x00A, 0xE0);
if (response != -1)
2019-03-31 01:04:30 +01:00
{
ClearWindowTilemap(2);
CopyWindowToVram(2, 1);
}
2019-04-01 00:59:52 +02:00
return response;
2019-03-31 01:04:30 +01:00
}
2019-03-31 16:33:27 +02:00
2019-04-01 00:59:52 +02:00
s8 mevent_message_print_and_prompt_yes_no(u8 * textState, u16 * windowId, bool8 yesNoBoxPlacement, const u8 * str)
2019-03-31 16:33:27 +02:00
{
struct WindowTemplate windowTemplate;
s8 input;
switch (*textState)
{
case 0:
StringExpandPlaceholders(gStringVar4, str);
2019-04-01 00:59:52 +02:00
if (yesNoBoxPlacement == 0)
2019-03-31 16:33:27 +02:00
{
2019-04-01 00:59:52 +02:00
*windowId = AddWindow(&sWindowTemplate_PromptYesOrNo_Width28);
2019-03-31 16:33:27 +02:00
}
else
{
2019-04-01 00:59:52 +02:00
*windowId = AddWindow(&sWindowTemplate_PromptYesOrNo_Width20);
2019-03-31 16:33:27 +02:00
}
FillWindowPixelBuffer(*windowId, 0x11);
2019-04-01 00:59:52 +02:00
AddTextPrinterParameterized4(*windowId, 1, 0, 1, 0, 0, sMG_Ereader_TextColor_2, 0, gStringVar4);
DrawTextBorderOuter(*windowId, 0x001, 0x0F);
2019-03-31 16:33:27 +02:00
CopyWindowToVram(*windowId, 2);
PutWindowTilemap(*windowId);
(*textState)++;
break;
case 1:
2019-04-01 00:59:52 +02:00
windowTemplate = sWindowTemplate_YesNoBox;
if (yesNoBoxPlacement == 0)
2019-03-31 16:33:27 +02:00
{
windowTemplate.tilemapTop = 9;
}
else
{
windowTemplate.tilemapTop = 15;
}
CreateYesNoMenu(&windowTemplate, 10, 14, 0);
(*textState)++;
break;
case 2:
input = Menu_ProcessInputNoWrapClearOnChoose();
if (input == -1 || input == 0 || input == 1)
{
*textState = 0;
rbox_fill_rectangle(*windowId);
ClearWindowTilemap(*windowId);
CopyWindowToVram(*windowId, 1);
RemoveWindow(*windowId);
return input;
}
break;
case 0xFF:
*textState = 0;
rbox_fill_rectangle(*windowId);
ClearWindowTilemap(*windowId);
CopyWindowToVram(*windowId, 1);
RemoveWindow(*windowId);
return -1;
}
return -2;
}
2019-03-31 17:16:19 +02:00
2019-04-01 00:59:52 +02:00
static s32 HandleMysteryGiftListMenu(u8 * textState, u16 * windowId, bool32 cannotToss, bool32 cannotSend)
2019-03-31 17:16:19 +02:00
{
struct WindowTemplate windowTemplate;
s32 input;
switch (*textState)
{
case 0:
2019-04-01 00:59:52 +02:00
if (cannotToss == 0)
2019-03-31 17:16:19 +02:00
{
StringExpandPlaceholders(gStringVar4, gText_WhatToDoWithCards);
}
else
{
StringExpandPlaceholders(gStringVar4, gText_WhatToDoWithNews);
}
2019-04-01 00:59:52 +02:00
*windowId = AddWindow(&sMysteryGiftMenuWindowTemplate);
2019-03-31 17:16:19 +02:00
FillWindowPixelBuffer(*windowId, 0x11);
2019-04-01 00:59:52 +02:00
AddTextPrinterParameterized4(*windowId, 1, 0, 1, 0, 0, sMG_Ereader_TextColor_2, 0, gStringVar4);
DrawTextBorderOuter(*windowId, 0x001, 0x0F);
2019-03-31 17:16:19 +02:00
CopyWindowToVram(*windowId, 2);
PutWindowTilemap(*windowId);
(*textState)++;
break;
case 1:
2019-04-01 00:59:52 +02:00
windowTemplate = sWindowTemplate_YesNoBox;
if (cannotSend)
2019-03-31 17:16:19 +02:00
{
2019-04-01 00:59:52 +02:00
if (cannotToss == 0)
2019-03-31 17:16:19 +02:00
{
2019-04-01 00:59:52 +02:00
input = DoMysteryGiftListMenu(&sWindowTemplate_7by6, &sListMenu_ReceiveToss, 1, 0x00A, 0xE0);
2019-03-31 17:16:19 +02:00
}
else
{
2019-04-01 00:59:52 +02:00
input = DoMysteryGiftListMenu(&sWindowTemplate_7by4, &sListMenu_Receive, 1, 0x00A, 0xE0);
2019-03-31 17:16:19 +02:00
}
}
else
{
2019-04-01 00:59:52 +02:00
if (cannotToss == 0)
2019-03-31 17:16:19 +02:00
{
2019-04-01 00:59:52 +02:00
input = DoMysteryGiftListMenu(&sWindowTemplate_7by8, &sListMenu_ReceiveSendToss, 1, 0x00A, 0xE0);
2019-03-31 17:16:19 +02:00
}
else
{
2019-04-01 00:59:52 +02:00
input = DoMysteryGiftListMenu(&sWindowTemplate_7by6, &sListMenu_ReceiveSend, 1, 0x00A, 0xE0);
2019-03-31 17:16:19 +02:00
}
}
if (input != -1)
{
*textState = 0;
rbox_fill_rectangle(*windowId);
ClearWindowTilemap(*windowId);
CopyWindowToVram(*windowId, 1);
RemoveWindow(*windowId);
return input;
}
break;
case 0xFF:
*textState = 0;
rbox_fill_rectangle(*windowId);
ClearWindowTilemap(*windowId);
CopyWindowToVram(*windowId, 1);
RemoveWindow(*windowId);
return -2;
}
return -1;
}
2019-04-01 00:59:52 +02:00
static bool32 ValidateCardOrNews(bool32 cardOrNews)
2019-03-31 17:16:19 +02:00
{
2019-04-01 00:59:52 +02:00
if (cardOrNews == 0)
2019-03-31 17:16:19 +02:00
{
2019-04-01 00:59:52 +02:00
return ValidateReceivedWonderCard();
2019-03-31 17:16:19 +02:00
}
else
{
2019-04-01 00:59:52 +02:00
return ValidateReceivedWonderNews();
2019-03-31 17:16:19 +02:00
}
}
2019-04-01 00:59:52 +02:00
static bool32 HandleLoadWonderCardOrNews(u8 * state, bool32 cardOrNews)
2019-03-31 17:16:19 +02:00
{
2019-03-31 18:27:36 +02:00
s32 v0;
2019-03-31 17:16:19 +02:00
switch (*state)
{
case 0:
2019-04-01 00:59:52 +02:00
if (cardOrNews == 0)
2019-03-31 17:16:19 +02:00
{
2019-04-01 00:59:52 +02:00
InitWonderCardResources(sav1_get_mevent_buffer_1(), sav1_get_mevent_buffer_2());
2019-03-31 17:16:19 +02:00
}
else
{
2019-04-01 00:59:52 +02:00
InitWonderNewsResources(sav1_get_mevent_buffer_0());
2019-03-31 17:16:19 +02:00
}
(*state)++;
2019-03-31 18:27:36 +02:00
break;
2019-03-31 17:16:19 +02:00
case 1:
2019-04-01 00:59:52 +02:00
if (cardOrNews == 0)
2019-03-31 17:16:19 +02:00
{
2019-04-01 00:59:52 +02:00
v0 = FadeToWonderCardMenu();
2019-03-31 18:27:36 +02:00
check:
if (v0 != 0)
2019-03-31 17:16:19 +02:00
{
2019-03-31 18:27:36 +02:00
goto done;
2019-03-31 17:16:19 +02:00
}
2019-03-31 18:27:36 +02:00
break;
2019-03-31 17:16:19 +02:00
}
else
{
2019-04-01 00:59:52 +02:00
v0 = FadeToWonderNewsMenu();
2019-03-31 18:27:36 +02:00
goto check;
}
done:
*state = 0;
return TRUE;
}
return FALSE;
}
2019-04-01 00:59:52 +02:00
static bool32 DestroyNewsOrCard(bool32 cardOrNews)
2019-03-31 18:27:36 +02:00
{
2019-04-01 00:59:52 +02:00
if (cardOrNews == 0)
2019-03-31 18:27:36 +02:00
{
2019-04-01 00:59:52 +02:00
DestroyWonderCard();
2019-03-31 18:27:36 +02:00
}
else
{
2019-04-01 00:59:52 +02:00
DestroyWonderNews();
2019-03-31 18:27:36 +02:00
}
return TRUE;
}
2019-04-01 00:59:52 +02:00
static bool32 TearDownCardOrNews_ReturnToTopMenu(bool32 cardOrNews, bool32 arg1)
2019-03-31 18:27:36 +02:00
{
2019-04-01 00:59:52 +02:00
if (cardOrNews == 0)
2019-03-31 18:27:36 +02:00
{
2019-04-01 00:59:52 +02:00
if (FadeOutFromWonderCard(arg1) != 0)
2019-03-31 18:27:36 +02:00
{
2019-04-01 00:59:52 +02:00
DestroyWonderCardResources();
2019-03-31 18:27:36 +02:00
return TRUE;
}
else
{
return FALSE;
}
}
else
{
2019-04-01 00:59:52 +02:00
if (FadeOutFromWonderNews(arg1) != 0)
2019-03-31 18:27:36 +02:00
{
2019-04-01 00:59:52 +02:00
DestroyWonderNewsResources();
2019-03-31 18:27:36 +02:00
return TRUE;
}
else
{
return FALSE;
}
}
}
2019-04-01 00:59:52 +02:00
static s32 mevent_message_prompt_discard(u8 * textState, u16 * windowId, bool32 cardOrNews)
2019-03-31 18:27:36 +02:00
{
2019-04-01 00:59:52 +02:00
if (cardOrNews == 0)
2019-03-31 18:27:36 +02:00
{
2019-04-01 00:59:52 +02:00
return mevent_message_print_and_prompt_yes_no(textState, windowId, TRUE, gText_IfThrowAwayCardEventWontHappen);
2019-03-31 18:27:36 +02:00
}
else
{
2019-04-01 00:59:52 +02:00
return mevent_message_print_and_prompt_yes_no(textState, windowId, TRUE, gText_OkayToDiscardNews);
2019-03-31 18:27:36 +02:00
}
}
2019-04-01 00:59:52 +02:00
static bool32 mevent_message_was_thrown_away(u8 * textState, bool32 cardOrNews)
2019-03-31 18:27:36 +02:00
{
2019-04-01 00:59:52 +02:00
if (cardOrNews == 0)
2019-03-31 18:27:36 +02:00
{
2019-04-01 00:59:52 +02:00
return MG_PrintTextOnWindow1AndWaitButton(textState, gText_WonderCardThrownAway);
2019-03-31 18:27:36 +02:00
}
else
{
2019-04-01 00:59:52 +02:00
return MG_PrintTextOnWindow1AndWaitButton(textState, gText_WonderNewsThrownAway);
2019-03-31 18:27:36 +02:00
}
}
2019-04-01 00:59:52 +02:00
static bool32 mevent_save_game(u8 * state)
2019-03-31 18:27:36 +02:00
{
switch (*state)
{
case 0:
2019-04-01 00:59:52 +02:00
AddTextPrinterToWindow1(gText_DataWillBeSaved);
2019-03-31 18:27:36 +02:00
(*state)++;
break;
case 1:
TrySavingData(0);
(*state)++;
break;
case 2:
2019-04-01 00:59:52 +02:00
AddTextPrinterToWindow1(gText_SaveCompletedPressA);
2019-03-31 18:27:36 +02:00
(*state)++;
break;
case 3:
if (({gMain.newKeys & (A_BUTTON | B_BUTTON);}))
{
(*state)++;
2019-03-31 17:16:19 +02:00
}
2019-03-31 18:27:36 +02:00
break;
case 4:
2019-03-31 17:16:19 +02:00
*state = 0;
2019-04-01 00:59:52 +02:00
ClearTextWindow();
2019-03-31 17:16:19 +02:00
return TRUE;
}
return FALSE;
2019-03-31 18:27:36 +02:00
}
2019-03-31 18:36:48 +02:00
2019-04-01 00:59:52 +02:00
static const u8 * mevent_message(u32 * a0, u8 a1, u8 cardOrNews, u32 msgId)
2019-03-31 18:36:48 +02:00
{
const u8 * msg = NULL;
*a0 = 0;
2019-04-01 00:59:52 +02:00
switch (msgId)
2019-03-31 18:36:48 +02:00
{
case 0:
*a0 = 0;
msg = gText_NothingSentOver;
break;
case 1:
*a0 = 0;
msg = gText_RecordUploadedViaWireless;
break;
case 2:
*a0 = 1;
2019-04-01 00:59:52 +02:00
msg = cardOrNews == 0 ? gText_WonderCardReceived : gText_WonderCardReceivedFrom;
2019-03-31 18:36:48 +02:00
break;
case 3:
*a0 = 1;
2019-04-01 00:59:52 +02:00
msg = cardOrNews == 0 ? gText_WonderNewsReceived : gText_WonderNewsReceivedFrom;
2019-03-31 18:36:48 +02:00
break;
case 4:
*a0 = 1;
msg = gText_NewStampReceived;
break;
case 5:
*a0 = 0;
msg = gText_AlreadyHadCard;
break;
case 6:
*a0 = 0;
msg = gText_AlreadyHadStamp;
break;
case 7:
*a0 = 0;
msg = gText_AlreadyHadNews;
break;
case 8:
*a0 = 0;
msg = gText_NoMoreRoomForStamps;
break;
case 9:
*a0 = 0;
msg = gText_CommunicationCanceled;
break;
case 10:
*a0 = 0;
msg = a1 == 0 ? gText_CantAcceptCardFromTrainer : gText_CantAcceptNewsFromTrainer;
break;
case 11:
*a0 = 0;
msg = gText_CommunicationError;
break;
case 12:
*a0 = 1;
msg = gText_NewTrainerReceived;
break;
case 13:
*a0 = 1;
break;
case 14:
*a0 = 0;
break;
}
return msg;
}
2019-03-31 18:55:27 +02:00
2019-04-01 00:59:52 +02:00
static bool32 PrintMGSuccessMessage(u8 * state, const u8 * arg1, u16 * arg2)
2019-03-31 18:55:27 +02:00
{
switch (*state)
{
case 0:
if (arg1 != NULL)
{
2019-04-01 00:59:52 +02:00
AddTextPrinterToWindow1(arg1);
2019-03-31 18:55:27 +02:00
}
PlayFanfare(MUS_FANFA4);
*arg2 = 0;
(*state)++;
break;
case 1:
if (++(*arg2) > 0xF0)
{
(*state)++;
}
break;
case 2:
if (IsFanfareTaskInactive())
{
*state = 0;
2019-04-01 00:59:52 +02:00
ClearTextWindow();
2019-03-31 18:55:27 +02:00
return TRUE;
}
break;
}
return FALSE;
}
2019-04-01 00:59:52 +02:00
static const u8 * mevent_message_stamp_card_etc_send_status(u32 * a0, u8 unused, u32 msgId)
2019-03-31 18:55:27 +02:00
{
const u8 * result = gText_CommunicationError;
*a0 = 0;
2019-04-01 00:59:52 +02:00
switch (msgId)
2019-03-31 18:55:27 +02:00
{
case 0:
result = gText_NothingSentOver;
break;
case 1:
result = gText_RecordUploadedViaWireless;
break;
case 2:
result = gText_WonderCardSentTo;
*a0 = 1;
break;
case 3:
result = gText_WonderNewsSentTo;
*a0 = 1;
break;
case 4:
result = gText_StampSentTo;
break;
case 5:
result = gText_OtherTrainerHasCard;
break;
case 6:
result = gText_OtherTrainerHasStamp;
break;
case 7:
result = gText_OtherTrainerHasNews;
break;
case 8:
result = gText_NoMoreRoomForStamps;
break;
case 9:
result = gText_OtherTrainerCanceled;
break;
case 10:
result = gText_CantSendGiftToTrainer;
break;
case 11:
result = gText_CommunicationError;
break;
case 12:
result = gText_GiftSentTo;
break;
case 13:
result = gText_GiftSentTo;
break;
case 14:
result = gText_CantSendGiftToTrainer;
break;
}
return result;
}
2019-04-01 00:59:52 +02:00
static bool32 PrintMGSendStatus(u8 * state, u16 * arg1, u8 arg2, u32 msgId)
2019-03-31 18:55:27 +02:00
{
u32 flag;
2019-04-01 00:59:52 +02:00
const u8 * str = mevent_message_stamp_card_etc_send_status(&flag, arg2, msgId);
2019-03-31 18:55:27 +02:00
if (flag)
{
2019-04-01 00:59:52 +02:00
return PrintMGSuccessMessage(state, str, arg1);
2019-03-31 18:55:27 +02:00
}
else
{
2019-04-01 00:59:52 +02:00
return MG_PrintTextOnWindow1AndWaitButton(state, str);
2019-03-31 18:55:27 +02:00
}
}
void task_add_00_mystery_gift(void)
{
u8 taskId = CreateTask(task00_mystery_gift, 0);
struct MysteryGiftTaskData * data = (void *)gTasks[taskId].data;
2019-04-01 00:59:52 +02:00
data->state = 0;
data->textState = 0;
2019-03-31 18:55:27 +02:00
data->unkA = 0;
data->unkB = 0;
2019-04-01 00:59:52 +02:00
data->IsCardOrNews = 0;
data->source = 0;
data->curPromptWindowId = 0;
2019-03-31 18:55:27 +02:00
data->unk2 = 0;
data->unk4 = 0;
data->unk6 = 0;
2019-04-01 00:59:52 +02:00
data->prevPromptWindowId = 0;
data->buffer = AllocZeroed(0x40);
2019-03-31 21:50:25 +02:00
}
void task00_mystery_gift(u8 taskId)
{
struct MysteryGiftTaskData * data = (void *)gTasks[taskId].data;
u32 sp0;
const u8 * r1;
2019-04-01 00:59:52 +02:00
switch (data->state)
2019-03-31 21:50:25 +02:00
{
case 0:
2019-04-01 00:59:52 +02:00
data->state = 1;
2019-03-31 21:50:25 +02:00
break;
case 1:
2019-04-01 00:59:52 +02:00
switch (MysteryGift_HandleThreeOptionMenu(&data->textState, &data->curPromptWindowId, FALSE))
2019-03-31 21:50:25 +02:00
{
case 0:
2019-04-01 00:59:52 +02:00
data->IsCardOrNews = 0;
if (ValidateReceivedWonderCard() == TRUE)
2019-03-31 21:50:25 +02:00
{
2019-04-01 00:59:52 +02:00
data->state = 18;
2019-03-31 21:50:25 +02:00
}
else
{
2019-04-01 00:59:52 +02:00
data->state = 2;
2019-03-31 21:50:25 +02:00
}
break;
case 1:
2019-04-01 00:59:52 +02:00
data->IsCardOrNews = 1;
if (ValidateReceivedWonderNews() == TRUE)
2019-03-31 21:50:25 +02:00
{
2019-04-01 00:59:52 +02:00
data->state = 18;
2019-03-31 21:50:25 +02:00
}
else
{
2019-04-01 00:59:52 +02:00
data->state = 2;
2019-03-31 21:50:25 +02:00
}
break;
case -2u:
2019-04-01 00:59:52 +02:00
data->state = 37;
2019-03-31 21:50:25 +02:00
break;
}
break;
case 2:
{
2019-04-01 00:59:52 +02:00
if (data->IsCardOrNews == 0)
2019-03-31 21:50:25 +02:00
{
2019-04-01 00:59:52 +02:00
if (MG_PrintTextOnWindow1AndWaitButton(&data->textState, gText_DontHaveCardNewOneInput))
2019-03-31 21:50:25 +02:00
{
2019-04-01 00:59:52 +02:00
data->state = 3;
PrintMysteryGiftOrEReaderTopMenu(0, 1);
2019-03-31 21:50:25 +02:00
}
}
else
{
2019-04-01 00:59:52 +02:00
if (MG_PrintTextOnWindow1AndWaitButton(&data->textState, gText_DontHaveNewsNewOneInput))
2019-03-31 21:50:25 +02:00
{
2019-04-01 00:59:52 +02:00
data->state = 3;
PrintMysteryGiftOrEReaderTopMenu(0, 1);
2019-03-31 21:50:25 +02:00
}
}
break;
}
case 3:
2019-04-01 00:59:52 +02:00
if (data->IsCardOrNews == 0)
2019-03-31 21:50:25 +02:00
{
2019-04-01 00:59:52 +02:00
AddTextPrinterToWindow1(gText_WhereShouldCardBeAccessed);
2019-03-31 21:50:25 +02:00
}
else
{
2019-04-01 00:59:52 +02:00
AddTextPrinterToWindow1(gText_WhereShouldNewsBeAccessed);
2019-03-31 21:50:25 +02:00
}
2019-04-01 00:59:52 +02:00
data->state = 4;
2019-03-31 21:50:25 +02:00
break;
case 4:
2019-04-01 00:59:52 +02:00
switch (MysteryGift_HandleThreeOptionMenu(&data->textState, &data->curPromptWindowId, TRUE))
2019-03-31 21:50:25 +02:00
{
case 0:
2019-04-01 00:59:52 +02:00
ClearTextWindow();
data->state = 5;
data->source = 0;
2019-03-31 21:50:25 +02:00
break;
case 1:
2019-04-01 00:59:52 +02:00
ClearTextWindow();
data->state = 5;
data->source = 1;
2019-03-31 21:50:25 +02:00
break;
case -2u:
2019-04-01 00:59:52 +02:00
ClearTextWindow();
if (ValidateCardOrNews(data->IsCardOrNews))
2019-03-31 21:50:25 +02:00
{
2019-04-01 00:59:52 +02:00
data->state = 18;
2019-03-31 21:50:25 +02:00
}
else
{
2019-04-01 00:59:52 +02:00
data->state = 0;
PrintMysteryGiftOrEReaderTopMenu(0, 0);
2019-03-31 21:50:25 +02:00
}
break;
}
break;
case 5:
{
register u8 eos asm("r1");
gStringVar1[0] = (eos = EOS);
gStringVar2[0] = eos;
gStringVar3[0] = eos;
}
2019-04-01 00:59:52 +02:00
switch (data->IsCardOrNews)
2019-03-31 21:50:25 +02:00
{
case 0:
2019-04-01 00:59:52 +02:00
if (data->source == 1)
2019-03-31 21:50:25 +02:00
{
2019-04-01 00:59:52 +02:00
MEvent_CreateTask_CardOrNewsWithFriend(0x15);
2019-03-31 21:50:25 +02:00
}
2019-04-01 00:59:52 +02:00
else if (data->source == 0)
2019-03-31 21:50:25 +02:00
{
2019-04-01 00:59:52 +02:00
MEvent_CreateTask_CardOrNewsOverWireless(0x15);
2019-03-31 21:50:25 +02:00
}
break;
case 1:
2019-04-01 00:59:52 +02:00
if (data->source == 1)
2019-03-31 21:50:25 +02:00
{
2019-04-01 00:59:52 +02:00
MEvent_CreateTask_CardOrNewsWithFriend(0x16);
2019-03-31 21:50:25 +02:00
}
2019-04-01 00:59:52 +02:00
else if (data->source == 0)
2019-03-31 21:50:25 +02:00
{
2019-04-01 00:59:52 +02:00
MEvent_CreateTask_CardOrNewsOverWireless(0x16);
2019-03-31 21:50:25 +02:00
}
break;
}
2019-04-01 00:59:52 +02:00
data->state = 6;
2019-03-31 21:50:25 +02:00
break;
case 6:
if (gReceivedRemoteLinkPlayers != 0)
{
2019-04-01 00:59:52 +02:00
ClearScreenInBg0(TRUE);
data->state = 7;
mevent_srv_ish_do_init(data->IsCardOrNews);
2019-03-31 21:50:25 +02:00
}
else if (gSpecialVar_Result == 5)
{
2019-04-01 00:59:52 +02:00
ClearScreenInBg0(TRUE);
data->state = 3;
2019-03-31 21:50:25 +02:00
}
break;
case 7:
2019-04-01 00:59:52 +02:00
AddTextPrinterToWindow1(gText_Communicating);
data->state = 8;
2019-03-31 21:50:25 +02:00
break;
case 8:
2019-04-01 00:59:52 +02:00
switch (mevent_srv_ish_do_exec(&data->curPromptWindowId))
2019-03-31 21:50:25 +02:00
{
case 6:
task_add_05_task_del_08FA224_when_no_RfuFunc();
2019-04-01 00:59:52 +02:00
data->prevPromptWindowId = data->curPromptWindowId;
data->state = 13;
2019-03-31 21:50:25 +02:00
break;
case 5:
2019-04-01 00:59:52 +02:00
memcpy(data->buffer, mevent_srv_ish_get_buffer(), 0x40);
mevent_srv_ish_inc_flag();
2019-03-31 21:50:25 +02:00
break;
case 3:
2019-04-01 00:59:52 +02:00
data->state = 10;
2019-03-31 21:50:25 +02:00
break;
case 2:
2019-04-01 00:59:52 +02:00
data->state = 9;
2019-03-31 21:50:25 +02:00
break;
case 4:
2019-04-01 00:59:52 +02:00
data->state = 11;
2019-03-31 21:50:25 +02:00
StringCopy(gStringVar1, gLinkPlayers[0].name);
break;
}
break;
case 9:
2019-04-01 00:59:52 +02:00
switch ((u32)mevent_message_print_and_prompt_yes_no(&data->textState, &data->curPromptWindowId, FALSE, mevent_srv_ish_get_buffer()))
2019-03-31 21:50:25 +02:00
{
case 0:
2019-04-01 00:59:52 +02:00
mevent_srv_ish_set_param(0);
mevent_srv_ish_inc_flag();
data->state = 7;
2019-03-31 21:50:25 +02:00
break;
case 1:
2019-04-01 00:59:52 +02:00
mevent_srv_ish_set_param(1);
mevent_srv_ish_inc_flag();
data->state = 7;
2019-03-31 21:50:25 +02:00
break;
case -1u:
2019-04-01 00:59:52 +02:00
mevent_srv_ish_set_param(1);
mevent_srv_ish_inc_flag();
data->state = 7;
2019-03-31 21:50:25 +02:00
break;
}
break;
case 10:
2019-04-01 00:59:52 +02:00
if (MG_PrintTextOnWindow1AndWaitButton(&data->textState, mevent_srv_ish_get_buffer()))
2019-03-31 21:50:25 +02:00
{
2019-04-01 00:59:52 +02:00
mevent_srv_ish_inc_flag();
data->state = 7;
2019-03-31 21:50:25 +02:00
}
break;
case 11:
2019-04-01 00:59:52 +02:00
switch ((u32)mevent_message_print_and_prompt_yes_no(&data->textState, &data->curPromptWindowId, FALSE, gText_ThrowAwayWonderCard))
2019-03-31 21:50:25 +02:00
{
case 0:
2019-04-01 00:59:52 +02:00
if (CheckReceivedGiftFromWonderCard() == TRUE)
2019-03-31 21:50:25 +02:00
{
2019-04-01 00:59:52 +02:00
data->state = 12;
2019-03-31 21:50:25 +02:00
}
else
{
2019-04-01 00:59:52 +02:00
mevent_srv_ish_set_param(0);
mevent_srv_ish_inc_flag();
data->state = 7;
2019-03-31 21:50:25 +02:00
}
break;
case 1:
2019-04-01 00:59:52 +02:00
mevent_srv_ish_set_param(1);
mevent_srv_ish_inc_flag();
data->state = 7;
2019-03-31 21:50:25 +02:00
break;
case -1u:
2019-04-01 00:59:52 +02:00
mevent_srv_ish_set_param(1);
mevent_srv_ish_inc_flag();
data->state = 7;
2019-03-31 21:50:25 +02:00
break;
}
break;
case 12:
2019-04-01 00:59:52 +02:00
switch ((u32)mevent_message_print_and_prompt_yes_no(&data->textState, &data->curPromptWindowId, FALSE, gText_HaventReceivedCardsGift))
2019-03-31 21:50:25 +02:00
{
case 0:
2019-04-01 00:59:52 +02:00
mevent_srv_ish_set_param(0);
mevent_srv_ish_inc_flag();
data->state = 7;
2019-03-31 21:50:25 +02:00
break;
case 1:
2019-04-01 00:59:52 +02:00
mevent_srv_ish_set_param(1);
mevent_srv_ish_inc_flag();
data->state = 7;
2019-03-31 21:50:25 +02:00
break;
case -1u:
2019-04-01 00:59:52 +02:00
mevent_srv_ish_set_param(1);
mevent_srv_ish_inc_flag();
data->state = 7;
2019-03-31 21:50:25 +02:00
break;
}
break;
case 13:
if (gReceivedRemoteLinkPlayers == 0)
{
2019-04-01 00:59:52 +02:00
DestroyWirelessStatusIndicatorSprite();
data->state = 14;
2019-03-31 21:50:25 +02:00
}
break;
case 14:
2019-04-01 00:59:52 +02:00
if (PrintStringAndWait2Seconds(&data->textState, gText_CommunicationCompleted))
2019-03-31 21:50:25 +02:00
{
2019-04-01 00:59:52 +02:00
if (data->source == 1)
2019-03-31 21:50:25 +02:00
{
StringCopy(gStringVar1, gLinkPlayers[0].name);
}
2019-04-01 00:59:52 +02:00
data->state = 15;
2019-03-31 21:50:25 +02:00
}
break;
case 15:
{
register bool32 flag asm("r1");
2019-04-01 00:59:52 +02:00
r1 = mevent_message(&sp0, data->IsCardOrNews, data->source, data->prevPromptWindowId);
2019-03-31 21:50:25 +02:00
if (r1 == NULL)
{
2019-04-01 00:59:52 +02:00
r1 = data->buffer;
2019-03-31 21:50:25 +02:00
}
if (sp0)
{
2019-04-01 00:59:52 +02:00
flag = PrintMGSuccessMessage(&data->textState, r1, &data->curPromptWindowId);
2019-03-31 21:50:25 +02:00
}
else
{
2019-04-01 00:59:52 +02:00
flag = MG_PrintTextOnWindow1AndWaitButton(&data->textState, r1);
2019-03-31 21:50:25 +02:00
}
if (flag)
{
2019-04-01 00:59:52 +02:00
if (data->prevPromptWindowId == 3)
2019-03-31 21:50:25 +02:00
{
2019-04-01 00:59:52 +02:00
if (data->source == 1)
2019-03-31 21:50:25 +02:00
{
2019-04-01 00:59:52 +02:00
GenerateRandomNews(1);
2019-03-31 21:50:25 +02:00
}
else
{
2019-04-01 00:59:52 +02:00
GenerateRandomNews(2);
2019-03-31 21:50:25 +02:00
}
}
if (sp0 == 0)
{
2019-04-01 00:59:52 +02:00
data->state = 0;
PrintMysteryGiftOrEReaderTopMenu(0, 0);
2019-03-31 21:50:25 +02:00
}
else
{
2019-04-01 00:59:52 +02:00
data->state = 17;
2019-03-31 21:50:25 +02:00
}
}
break;
}
case 16:
2019-04-01 00:59:52 +02:00
if (MG_PrintTextOnWindow1AndWaitButton(&data->textState, gText_CommunicationError))
2019-03-31 21:50:25 +02:00
{
2019-04-01 00:59:52 +02:00
data->state = 0;
PrintMysteryGiftOrEReaderTopMenu(0, 0);
2019-03-31 21:50:25 +02:00
}
break;
case 17:
2019-04-01 00:59:52 +02:00
if (mevent_save_game(&data->textState))
2019-03-31 21:50:25 +02:00
{
2019-04-01 00:59:52 +02:00
data->state = 18;
2019-03-31 21:50:25 +02:00
}
break;
case 18:
2019-04-01 00:59:52 +02:00
if (HandleLoadWonderCardOrNews(&data->textState, data->IsCardOrNews))
2019-03-31 21:50:25 +02:00
{
2019-04-01 00:59:52 +02:00
data->state = 20;
2019-03-31 21:50:25 +02:00
}
break;
case 20:
2019-04-01 00:59:52 +02:00
if (data->IsCardOrNews == 0)
2019-03-31 21:50:25 +02:00
{
if (({gMain.newKeys & A_BUTTON;}))
{
2019-04-01 00:59:52 +02:00
data->state = 21;
2019-03-31 21:50:25 +02:00
}
if (({gMain.newKeys & B_BUTTON;}))
{
2019-04-01 00:59:52 +02:00
data->state = 27;
2019-03-31 21:50:25 +02:00
}
}
else
{
2019-04-01 00:59:52 +02:00
switch (MENews_GetInput(gMain.newKeys))
2019-03-31 21:50:25 +02:00
{
case 0:
2019-04-01 00:59:52 +02:00
MENews_RemoveScrollIndicatorArrowPair();
data->state = 21;
2019-03-31 21:50:25 +02:00
break;
case 1:
2019-04-01 00:59:52 +02:00
data->state = 27;
2019-03-31 21:50:25 +02:00
break;
}
}
break;
case 21:
{
u32 result;
2019-04-01 00:59:52 +02:00
if (data->IsCardOrNews == 0)
2019-03-31 21:50:25 +02:00
{
2019-04-01 00:59:52 +02:00
if (WonderCard_Test_Unk_08_6())
2019-03-31 21:50:25 +02:00
{
2019-04-01 00:59:52 +02:00
result = HandleMysteryGiftListMenu(&data->textState, &data->curPromptWindowId, data->IsCardOrNews, FALSE);
2019-03-31 21:50:25 +02:00
}
else
{
2019-04-01 00:59:52 +02:00
result = HandleMysteryGiftListMenu(&data->textState, &data->curPromptWindowId, data->IsCardOrNews, TRUE);
2019-03-31 21:50:25 +02:00
}
}
else
{
2019-04-01 00:59:52 +02:00
if (WonderNews_Test_Unk_02())
2019-03-31 21:50:25 +02:00
{
2019-04-01 00:59:52 +02:00
result = HandleMysteryGiftListMenu(&data->textState, &data->curPromptWindowId, data->IsCardOrNews, FALSE);
2019-03-31 21:50:25 +02:00
}
else
{
2019-04-01 00:59:52 +02:00
result = HandleMysteryGiftListMenu(&data->textState, &data->curPromptWindowId, data->IsCardOrNews, TRUE);
2019-03-31 21:50:25 +02:00
}
}
switch (result)
{
case 0:
2019-04-01 00:59:52 +02:00
data->state = 28;
2019-03-31 21:50:25 +02:00
break;
case 1:
2019-04-01 00:59:52 +02:00
data->state = 29;
2019-03-31 21:50:25 +02:00
break;
case 2:
2019-04-01 00:59:52 +02:00
data->state = 22;
2019-03-31 21:50:25 +02:00
break;
case -2u:
2019-04-01 00:59:52 +02:00
if (data->IsCardOrNews == 1)
2019-03-31 21:50:25 +02:00
{
2019-04-01 00:59:52 +02:00
MENews_AddScrollIndicatorArrowPair();
2019-03-31 21:50:25 +02:00
}
2019-04-01 00:59:52 +02:00
data->state = 20;
2019-03-31 21:50:25 +02:00
break;
}
break;
}
case 22:
2019-04-01 00:59:52 +02:00
switch (mevent_message_prompt_discard(&data->textState, &data->curPromptWindowId, data->IsCardOrNews))
2019-03-31 21:50:25 +02:00
{
case 0:
2019-04-01 00:59:52 +02:00
if (data->IsCardOrNews == 0 && CheckReceivedGiftFromWonderCard() == TRUE)
2019-03-31 21:50:25 +02:00
{
2019-04-01 00:59:52 +02:00
data->state = 23;
2019-03-31 21:50:25 +02:00
}
else
{
2019-04-01 00:59:52 +02:00
data->state = 24;
2019-03-31 21:50:25 +02:00
}
break;
case 1:
2019-04-01 00:59:52 +02:00
data->state = 21;
2019-03-31 21:50:25 +02:00
break;
case -1:
2019-04-01 00:59:52 +02:00
data->state = 21;
2019-03-31 21:50:25 +02:00
break;
}
break;
case 23:
2019-04-01 00:59:52 +02:00
switch ((u32)mevent_message_print_and_prompt_yes_no(&data->textState, &data->curPromptWindowId, TRUE, gText_HaventReceivedGiftOkayToDiscard))
2019-03-31 21:50:25 +02:00
{
case 0:
2019-04-01 00:59:52 +02:00
data->state = 24;
2019-03-31 21:50:25 +02:00
break;
case 1:
2019-04-01 00:59:52 +02:00
data->state = 21;
2019-03-31 21:50:25 +02:00
break;
case -1u:
2019-04-01 00:59:52 +02:00
data->state = 21;
2019-03-31 21:50:25 +02:00
break;
}
break;
case 24:
2019-04-01 00:59:52 +02:00
if (TearDownCardOrNews_ReturnToTopMenu(data->IsCardOrNews, 1))
2019-03-31 21:50:25 +02:00
{
2019-04-01 00:59:52 +02:00
DestroyNewsOrCard(data->IsCardOrNews);
data->state = 25;
2019-03-31 21:50:25 +02:00
}
break;
case 25:
2019-04-01 00:59:52 +02:00
if (mevent_save_game(&data->textState))
2019-03-31 21:50:25 +02:00
{
2019-04-01 00:59:52 +02:00
data->state = 26;
2019-03-31 21:50:25 +02:00
}
break;
case 26:
2019-04-01 00:59:52 +02:00
if (mevent_message_was_thrown_away(&data->textState, data->IsCardOrNews))
2019-03-31 21:50:25 +02:00
{
2019-04-01 00:59:52 +02:00
data->state = 0;
PrintMysteryGiftOrEReaderTopMenu(0, 0);
2019-03-31 21:50:25 +02:00
}
break;
case 27:
2019-04-01 00:59:52 +02:00
if (TearDownCardOrNews_ReturnToTopMenu(data->IsCardOrNews, 0))
2019-03-31 21:50:25 +02:00
{
2019-04-01 00:59:52 +02:00
data->state = 0;
2019-03-31 21:50:25 +02:00
}
break;
case 28:
2019-04-01 00:59:52 +02:00
if (TearDownCardOrNews_ReturnToTopMenu(data->IsCardOrNews, 1))
2019-03-31 21:50:25 +02:00
{
2019-04-01 00:59:52 +02:00
data->state = 3;
2019-03-31 21:50:25 +02:00
}
break;
case 29:
2019-04-01 00:59:52 +02:00
if (TearDownCardOrNews_ReturnToTopMenu(data->IsCardOrNews, 1))
2019-03-31 21:50:25 +02:00
{
2019-04-01 00:59:52 +02:00
switch (data->IsCardOrNews)
2019-03-31 21:50:25 +02:00
{
case 0:
2019-04-01 00:59:52 +02:00
MEvent_CreateTask_Leader(21);
2019-03-31 21:50:25 +02:00
break;
case 1:
2019-04-01 00:59:52 +02:00
MEvent_CreateTask_Leader(22);
2019-03-31 21:50:25 +02:00
break;
}
2019-04-01 00:59:52 +02:00
data->source = 1;
data->state = 30;
2019-03-31 21:50:25 +02:00
}
break;
case 30:
if (gReceivedRemoteLinkPlayers != 0)
{
2019-04-01 00:59:52 +02:00
ClearScreenInBg0(1);
data->state = 31;
2019-03-31 21:50:25 +02:00
}
else if (gSpecialVar_Result == 5)
{
2019-04-01 00:59:52 +02:00
ClearScreenInBg0(1);
data->state = 18;
2019-03-31 21:50:25 +02:00
}
break;
case 31:
{
register u8 eos asm("r1");
gStringVar1[0] = (eos = EOS);
gStringVar2[0] = eos;
gStringVar3[0] = eos;
}
2019-04-01 00:59:52 +02:00
if (data->IsCardOrNews == 0)
2019-03-31 21:50:25 +02:00
{
2019-04-01 00:59:52 +02:00
AddTextPrinterToWindow1(gText_SendingWonderCard);
2019-03-31 21:50:25 +02:00
mevent_srv_new_wcard();
}
else
{
2019-04-01 00:59:52 +02:00
AddTextPrinterToWindow1(gText_SendingWonderNews);
2019-03-31 21:50:25 +02:00
mevent_srv_init_wnews();
}
2019-04-01 00:59:52 +02:00
data->state = 32;
2019-03-31 21:50:25 +02:00
break;
case 32:
2019-04-01 00:59:52 +02:00
if (mevent_srv_common_do_exec(&data->curPromptWindowId) == 3)
2019-03-31 21:50:25 +02:00
{
2019-04-01 00:59:52 +02:00
data->prevPromptWindowId = data->curPromptWindowId;
data->state = 33;
2019-03-31 21:50:25 +02:00
}
break;
case 33:
task_add_05_task_del_08FA224_when_no_RfuFunc();
StringCopy(gStringVar1, gLinkPlayers[1].name);
2019-04-01 00:59:52 +02:00
data->state = 34;
2019-03-31 21:50:25 +02:00
break;
case 34:
if (gReceivedRemoteLinkPlayers == 0)
{
2019-04-01 00:59:52 +02:00
DestroyWirelessStatusIndicatorSprite();
data->state = 35;
2019-03-31 21:50:25 +02:00
}
break;
case 35:
2019-04-01 00:59:52 +02:00
if (PrintMGSendStatus(&data->textState, &data->curPromptWindowId, data->source, data->prevPromptWindowId))
2019-03-31 21:50:25 +02:00
{
2019-04-01 00:59:52 +02:00
if (data->source == 1 && data->prevPromptWindowId == 3)
2019-03-31 21:50:25 +02:00
{
2019-04-01 00:59:52 +02:00
GenerateRandomNews(3);
data->state = 17;
2019-03-31 21:50:25 +02:00
}
else
{
2019-04-01 00:59:52 +02:00
data->state = 0;
PrintMysteryGiftOrEReaderTopMenu(0, 0);
2019-03-31 21:50:25 +02:00
}
}
break;
case 36:
2019-04-01 00:59:52 +02:00
if (MG_PrintTextOnWindow1AndWaitButton(&data->textState, gText_CommunicationError))
2019-03-31 21:50:25 +02:00
{
2019-04-01 00:59:52 +02:00
data->state = 0;
PrintMysteryGiftOrEReaderTopMenu(0, 0);
2019-03-31 21:50:25 +02:00
}
break;
case 37:
CloseLink();
2019-04-01 00:59:52 +02:00
Free(data->buffer);
2019-03-31 21:50:25 +02:00
DestroyTask(taskId);
2019-04-01 00:59:52 +02:00
SetMainCallback2(MainCB_FreeAllBuffersAndReturnToInitTitleScreen);
2019-03-31 21:50:25 +02:00
break;
}
2019-03-31 18:55:27 +02:00
}
2019-04-01 00:59:52 +02:00
u16 GetMysteryGiftBaseBlock(void)
{
return 0x1A9;
}
void bgid_upload_textbox_1(u8 bgId)
{
DecompressAndLoadBgGfxUsingHeap(bgId, gUnkTextboxBorderGfx, 0x100, 0, 0);
}