summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorPikalaxALT <pikalaxalt@gmail.com>2019-04-25 17:44:25 -0400
committerPikalaxALT <pikalaxalt@gmail.com>2019-04-25 17:44:25 -0400
commitd3057e7ae686750f561a6b23552a072f53dd8f63 (patch)
tree435ee775183c8620530ada7c30c447b3ba7f284e /src
parent6cebd1f85311b1aa7321eb141521686d21bd091c (diff)
through HandleLoadWonderCardOrNews
Diffstat (limited to 'src')
-rw-r--r--src/menews_jisan.c2
-rw-r--r--src/mevent.c24
-rw-r--r--src/mevent_8145654.c8
-rw-r--r--src/mevent_server.c4
-rw-r--r--src/mystery_gift_menu.c211
-rw-r--r--src/script.c4
6 files changed, 225 insertions, 28 deletions
diff --git a/src/menews_jisan.c b/src/menews_jisan.c
index 530762990..c6413b7b2 100644
--- a/src/menews_jisan.c
+++ b/src/menews_jisan.c
@@ -59,7 +59,7 @@ u16 sub_8146CE8(void)
struct MysteryEventStruct *r4 = sub_8143D94();
u16 r5;
- if (!sub_806E2BC() || !sub_8143E1C())
+ if (!sub_806E2BC() || !ValidateReceivedWonderCard())
return 0;
r5 = sub_8146E0C(r4);
diff --git a/src/mevent.c b/src/mevent.c
index 9ea4714ee..9d110616f 100644
--- a/src/mevent.c
+++ b/src/mevent.c
@@ -490,12 +490,12 @@ void sub_8143D24(void)
sub_80BDE28();
}
-struct MEventBuffer_3120_Sub * sub_8143D58(void)
+struct MEventBuffer_3120_Sub * GetSavedWonderNews(void)
{
return &gSaveBlock1Ptr->unk_3120.buffer_000.data;
}
-struct MEventBuffer_32E0_Sub * sav1_get_mevent_buffer_1(void)
+struct MEventBuffer_32E0_Sub * GetSavedWonderCard(void)
{
return &gSaveBlock1Ptr->unk_3120.buffer_1c0.data;
}
@@ -530,7 +530,7 @@ bool32 sub_8143DC8(const struct MEventBuffer_3120_Sub * src)
return TRUE;
}
-bool32 sub_8143E1C(void)
+bool32 ValidateReceivedWonderCard(void)
{
if (CalcCRC16WithTable((void *)&gSaveBlock1Ptr->unk_3120.buffer_000.data, sizeof(struct MEventBuffer_3120_Sub)) != gSaveBlock1Ptr->unk_3120.buffer_000.crc)
return FALSE;
@@ -556,7 +556,7 @@ bool32 sub_8143E78(void)
void sub_8143E9C(void)
{
- CpuFill32(0, sub_8143D58(), sizeof(gSaveBlock1Ptr->unk_3120.buffer_000.data));
+ CpuFill32(0, GetSavedWonderNews(), sizeof(gSaveBlock1Ptr->unk_3120.buffer_000.data));
gSaveBlock1Ptr->unk_3120.buffer_000.crc = 0;
}
@@ -570,7 +570,7 @@ bool32 sub_8143EF4(const u8 * src)
{
const u8 * r5 = (const u8 *)&gSaveBlock1Ptr->unk_3120.buffer_000.data;
u32 i;
- if (!sub_8143E1C())
+ if (!ValidateReceivedWonderCard())
return FALSE;
for (i = 0; i < sizeof(struct MEventBuffer_3120_Sub); i++)
{
@@ -606,7 +606,7 @@ bool32 sub_8143F68(const struct MEventBuffer_32E0_Sub * data)
return TRUE;
}
-bool32 sub_8143FC8(void)
+bool32 ValidateReceivedWonderNews(void)
{
if (gSaveBlock1Ptr->unk_3120.buffer_1c0.crc != CalcCRC16WithTable((void *)&gSaveBlock1Ptr->unk_3120.buffer_1c0.data, sizeof(struct MEventBuffer_32E0_Sub)))
return FALSE;
@@ -654,7 +654,7 @@ void sub_81440B4(void)
u16 sub_81440E8(void)
{
- if (sub_8143FC8())
+ if (ValidateReceivedWonderNews())
return gSaveBlock1Ptr->unk_3120.buffer_1c0.data.unk_00;
return 0;
}
@@ -721,7 +721,7 @@ bool32 sub_81441F0(const u16 * data)
s32 sub_8144218(void)
{
struct MEventBuffer_32E0_Sub * data;
- if (!sub_8143FC8())
+ if (!ValidateReceivedWonderNews())
return 0;
data = &gSaveBlock1Ptr->unk_3120.buffer_1c0.data;
if (data->unk_08_0 != 1)
@@ -759,11 +759,11 @@ void sub_81442CC(struct MEventStruct_Unk1442CC * data)
data->unk_08 = 1;
data->unk_0C = 1;
data->unk_10 = 1;
- if (sub_8143FC8())
+ if (ValidateReceivedWonderNews())
{
- data->unk_14 = sav1_get_mevent_buffer_1()->unk_00;
+ data->unk_14 = GetSavedWonderCard()->unk_00;
data->unk_20 = *sav1_get_mevent_buffer_2();
- data->unk_44 = sav1_get_mevent_buffer_1()->unk_09;
+ data->unk_44 = GetSavedWonderCard()->unk_09;
}
else
data->unk_14 = 0;
@@ -945,7 +945,7 @@ bool32 sub_81446D0(u16 a0)
gUnknown_203F3BC = FALSE;
if (a0 == 0)
return FALSE;
- if (!sub_8143FC8())
+ if (!ValidateReceivedWonderNews())
return FALSE;
if (gSaveBlock1Ptr->unk_3120.buffer_1c0.data.unk_00 != a0)
return FALSE;
diff --git a/src/mevent_8145654.c b/src/mevent_8145654.c
index 7d5cc8897..e17eda2c4 100644
--- a/src/mevent_8145654.c
+++ b/src/mevent_8145654.c
@@ -126,7 +126,7 @@ const struct UnkStruct_8467FB8 gUnknown_8467FB8[8] = {
{1, 0, 0, 7, gUnknown_8467A7C, gUnknown_8467CAC, gUnknown_846716C}
};
-bool32 sub_8145654(struct MEventBuffer_32E0_Sub * r5, struct MEventBuffer_3430_Sub * r6)
+bool32 InitWonderCardResources(struct MEventBuffer_32E0_Sub * r5, struct MEventBuffer_3430_Sub * r6)
{
if (r5 == NULL || r6 == NULL)
return FALSE;
@@ -155,7 +155,7 @@ void sub_81456F0(void)
}
}
-s32 sub_814571C(void)
+s32 FadeToWonderCardMenu(void)
{
if (gUnknown_203F3C8 == NULL)
return -1;
@@ -508,7 +508,7 @@ const struct UnkStruct_8467FB8 gUnknown_8468720[] = {
{1, 0, 0, 0, gUnknown_84685B4, gUnknown_8468644, gUnknown_84680A0}
};
-bool32 sub_8146288(const struct MEventBuffer_3120_Sub * a0)
+bool32 InitWonderNewsResources(const struct MEventBuffer_3120_Sub * a0)
{
if (a0 == NULL)
return FALSE;
@@ -533,7 +533,7 @@ void sub_81462EC(void)
}
}
-s32 sub_8146318(void)
+s32 FadeToWonderNewsMenu(void)
{
if (gUnknown_203F3CC == NULL)
return -1;
diff --git a/src/mevent_server.c b/src/mevent_server.c
index 5e384ae0b..1443e7007 100644
--- a/src/mevent_server.c
+++ b/src/mevent_server.c
@@ -526,12 +526,12 @@ static u32 common_mainseq_4(struct mevent_srv_common * svr)
break;
case 26:
AGB_ASSERT_EX(cmd->flag == FALSE && cmd->parameter == NULL, "C:/WORK/POKeFRLG/src/pm_lgfr_ose/source/mevent_server.c", 506);
- memcpy(svr->mevent_32e0, sav1_get_mevent_buffer_1(), 332);
+ memcpy(svr->mevent_32e0, GetSavedWonderCard(), 332);
sub_814410C(svr->mevent_32e0);
break;
case 27:
AGB_ASSERT_EX(cmd->flag == FALSE && cmd->parameter == NULL, "C:/WORK/POKeFRLG/src/pm_lgfr_ose/source/mevent_server.c", 512);
- memcpy(svr->mevent_3120, sub_8143D58(), 444);
+ memcpy(svr->mevent_3120, GetSavedWonderNews(), 444);
break;
case 28:
AGB_ASSERT_EX(cmd->flag == FALSE && cmd->parameter == NULL, "C:/WORK/POKeFRLG/src/pm_lgfr_ose/source/mevent_server.c", 517);
diff --git a/src/mystery_gift_menu.c b/src/mystery_gift_menu.c
index b0d00035c..f7bf7a207 100644
--- a/src/mystery_gift_menu.c
+++ b/src/mystery_gift_menu.c
@@ -17,15 +17,9 @@
#include "list_menu.h"
#include "link_rfu.h"
#include "string_util.h"
+#include "mevent.h"
#include "constants/songs.h"
-extern const struct WindowTemplate sWindowTemplate_ThreeOptions;
-extern const struct ListMenuItem sListMenuItems_CardsOrNews[];
-extern const struct ListMenuItem sListMenuItems_WirelessOrFriend[];
-extern const struct ListMenuTemplate sListMenuTemplate_ThreeOptions;
-extern const struct TextColor sMG_Ereader_TextColor_1;
-extern const struct TextColor sMG_Ereader_TextColor_2;
-
EWRAM_DATA u8 sDownArrowCounterAndYCoordIdx[8] = {};
EWRAM_DATA bool8 gGiftIsFromEReader = FALSE;
@@ -117,6 +111,24 @@ static const struct WindowTemplate sMainWindows[] = {
}
};
+extern const struct WindowTemplate sWindowTemplate_PromptYesOrNo_Width28;
+extern const struct WindowTemplate sWindowTemplate_PromptYesOrNo_Width20;
+extern const struct WindowTemplate sMysteryGiftMenuWindowTemplate;
+extern const struct WindowTemplate sWindowTemplate_ThreeOptions;
+extern const struct WindowTemplate sWindowTemplate_YesNoBox;
+extern const struct WindowTemplate sWindowTemplate_7by8;
+extern const struct WindowTemplate sWindowTemplate_7by6;
+extern const struct WindowTemplate sWindowTemplate_7by4;
+extern const struct ListMenuItem sListMenuItems_CardsOrNews[];
+extern const struct ListMenuItem sListMenuItems_WirelessOrFriend[];
+extern const struct ListMenuTemplate sListMenuTemplate_ThreeOptions;
+extern const struct ListMenuTemplate sListMenu_ReceiveSendToss;
+extern const struct ListMenuTemplate sListMenu_ReceiveToss;
+extern const struct ListMenuTemplate sListMenu_ReceiveSend;
+extern const struct ListMenuTemplate sListMenu_Receive;
+extern const struct TextColor sMG_Ereader_TextColor_1;
+extern const struct TextColor sMG_Ereader_TextColor_2;
+
void vblankcb_mystery_gift_e_reader_run(void)
{
ProcessSpriteCopyRequests();
@@ -236,6 +248,8 @@ extern const u8 gUnknown_841EDCA[];
extern const u8 gUnknown_841EDBD[];
extern const u8 gUnknown_841DE50[];
extern const u8 gUnknown_841DE51[];
+extern const u8 gText_WhatToDoWithCards[];
+extern const u8 gText_WhatToDoWithNews[];
void PrintMysteryGiftOrEReaderTopMenu(bool8 mg_or_ereader, bool32 usePickOkCancel)
{
@@ -426,5 +440,188 @@ u32 MysteryGift_HandleThreeOptionMenu(u8 * unused0, u16 * unused1, u8 whichMenu)
return response;
}
+s8 mevent_message_print_and_prompt_yes_no(u8 * textState, u16 * windowId, bool8 yesNoBoxPlacement, const u8 * str)
+{
+ struct WindowTemplate windowTemplate;
+ s8 input;
+
+ switch (*textState)
+ {
+ case 0:
+ StringExpandPlaceholders(gStringVar4, str);
+ if (yesNoBoxPlacement == 0)
+ {
+ *windowId = AddWindow(&sWindowTemplate_PromptYesOrNo_Width28);
+ }
+ else
+ {
+ *windowId = AddWindow(&sWindowTemplate_PromptYesOrNo_Width20);
+ }
+ FillWindowPixelBuffer(*windowId, 0x11);
+ AddTextPrinterParametrized2(*windowId, 2, 0, 2, 0, 2, &sMG_Ereader_TextColor_2, 0, gStringVar4);
+ DrawTextBorderOuter(*windowId, 0x001, 0x0F);
+ CopyWindowToVram(*windowId, 2);
+ PutWindowTilemap(*windowId);
+ (*textState)++;
+ break;
+ case 1:
+ windowTemplate = sWindowTemplate_YesNoBox;
+ if (yesNoBoxPlacement == 0)
+ {
+ windowTemplate.tilemapTop = 9;
+ }
+ else
+ {
+ windowTemplate.tilemapTop = 15;
+ }
+ sub_810FF60(&windowTemplate, 2, 0, 2, 10, 14, 0);
+ (*textState)++;
+ break;
+ case 2:
+ input = ProcessMenuInputNoWrap_();
+ 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;
+}
+
+s32 HandleMysteryGiftListMenu(u8 * textState, u16 * windowId, bool32 cannotToss, bool32 cannotSend)
+{
+ struct WindowTemplate windowTemplate;
+ s32 input;
+
+ switch (*textState)
+ {
+ case 0:
+ if (cannotToss == 0)
+ {
+ StringExpandPlaceholders(gStringVar4, gText_WhatToDoWithCards);
+ }
+ else
+ {
+ StringExpandPlaceholders(gStringVar4, gText_WhatToDoWithNews);
+ }
+ *windowId = AddWindow(&sMysteryGiftMenuWindowTemplate);
+ FillWindowPixelBuffer(*windowId, 0x11);
+ AddTextPrinterParametrized2(*windowId, 2, 0, 2, 0, 2, &sMG_Ereader_TextColor_2, 0, gStringVar4);
+ DrawTextBorderOuter(*windowId, 0x001, 0x0F);
+ CopyWindowToVram(*windowId, 2);
+ PutWindowTilemap(*windowId);
+ (*textState)++;
+ break;
+ case 1:
+ windowTemplate = sWindowTemplate_YesNoBox;
+ if (cannotSend)
+ {
+ if (cannotToss == 0)
+ {
+ input = DoMysteryGiftListMenu(&sWindowTemplate_7by6, &sListMenu_ReceiveToss, 1, 0x00A, 0xE0);
+ }
+ else
+ {
+ input = DoMysteryGiftListMenu(&sWindowTemplate_7by4, &sListMenu_Receive, 1, 0x00A, 0xE0);
+ }
+ }
+ else
+ {
+ if (cannotToss == 0)
+ {
+ input = DoMysteryGiftListMenu(&sWindowTemplate_7by8, &sListMenu_ReceiveSendToss, 1, 0x00A, 0xE0);
+ }
+ else
+ {
+ input = DoMysteryGiftListMenu(&sWindowTemplate_7by6, &sListMenu_ReceiveSend, 1, 0x00A, 0xE0);
+ }
+ }
+ 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;
+}
+
+bool32 ValidateCardOrNews(bool32 cardOrNews)
+{
+ if (cardOrNews == 0)
+ {
+ return ValidateReceivedWonderNews();
+ }
+ else
+ {
+ return ValidateReceivedWonderCard();
+ }
+}
+
+bool32 HandleLoadWonderCardOrNews(u8 * state, bool32 cardOrNews)
+{
+ s32 v0;
+
+ switch (*state)
+ {
+ case 0:
+ if (cardOrNews == 0)
+ {
+ InitWonderCardResources(GetSavedWonderCard(), sav1_get_mevent_buffer_2());
+ }
+ else
+ {
+ InitWonderNewsResources(GetSavedWonderNews());
+ }
+ (*state)++;
+ break;
+ case 1:
+ if (cardOrNews == 0)
+ {
+ v0 = FadeToWonderCardMenu();
+ check:
+ if (v0 != 0)
+ {
+ goto done;
+ }
+ break;
+ }
+ else
+ {
+ v0 = FadeToWonderNewsMenu();
+ goto check;
+ }
+ done:
+ *state = 0;
+ return TRUE;
+ }
+
+ return FALSE;
+}
diff --git a/src/script.c b/src/script.c
index d7246752c..c9e2d2c9d 100644
--- a/src/script.c
+++ b/src/script.c
@@ -9,7 +9,7 @@ extern u8 gUnknown_203ADFA;
extern void sub_80CBDE8(void); // field_specials
extern u16 CalcCRC16WithTable(u8 *data, int length); // util
-extern bool32 sub_8143FC8(void); // mevent
+extern bool32 ValidateReceivedWonderNews(void); // mevent
enum
{
@@ -525,7 +525,7 @@ bool32 sub_8069DFC(void)
u8 *sub_8069E48(void)
{
struct RamScriptData *scriptData = &gSaveBlock1Ptr->ramScript.data;
- if (!sub_8143FC8())
+ if (!ValidateReceivedWonderNews())
return NULL;
if (scriptData->magic != RAM_SCRIPT_MAGIC)
return NULL;