diff --git a/gflib/bg.c b/gflib/bg.c index 283a87ce0..fd72f2d24 100644 --- a/gflib/bg.c +++ b/gflib/bg.c @@ -553,14 +553,14 @@ s32 ChangeBgX(u8 bg, s32 value, u8 op) switch (op) { - case 0: + case BG_COORD_SET: default: sGpuBgConfigs2[bg].bg_x = value; break; - case 1: + case BG_COORD_ADD: sGpuBgConfigs2[bg].bg_x += value; break; - case 2: + case BG_COORD_SUB: sGpuBgConfigs2[bg].bg_x -= value; break; } @@ -633,14 +633,14 @@ s32 ChangeBgY(u8 bg, s32 value, u8 op) switch (op) { - case 0: + case BG_COORD_SET: default: sGpuBgConfigs2[bg].bg_y = value; break; - case 1: + case BG_COORD_ADD: sGpuBgConfigs2[bg].bg_y += value; break; - case 2: + case BG_COORD_SUB: sGpuBgConfigs2[bg].bg_y -= value; break; } @@ -703,14 +703,14 @@ s32 ChangeBgY_ScreenOff(u8 bg, s32 value, u8 op) switch (op) { - case 0: + case BG_COORD_SET: default: sGpuBgConfigs2[bg].bg_y = value; break; - case 1: + case BG_COORD_ADD: sGpuBgConfigs2[bg].bg_y += value; break; - case 2: + case BG_COORD_SUB: sGpuBgConfigs2[bg].bg_y -= value; break; } diff --git a/gflib/bg.h b/gflib/bg.h index 60327eab3..310790368 100644 --- a/gflib/bg.h +++ b/gflib/bg.h @@ -31,6 +31,12 @@ enum { BG_TYPE_NONE = 0xFFFF }; +enum { + BG_COORD_SET, + BG_COORD_ADD, + BG_COORD_SUB, +}; + struct BgTemplate { u16 bg:2; // 0x1, 0x2 -> 0x3 diff --git a/graphics/wonder_transfers/wonder_card_1.bin b/graphics/wonder_card/bg1.bin similarity index 100% rename from graphics/wonder_transfers/wonder_card_1.bin rename to graphics/wonder_card/bg1.bin diff --git a/graphics/wonder_transfers/wonder_card_1.png b/graphics/wonder_card/bg1.png similarity index 100% rename from graphics/wonder_transfers/wonder_card_1.png rename to graphics/wonder_card/bg1.png diff --git a/graphics/wonder_transfers/wonder_card_2.bin b/graphics/wonder_card/bg2.bin similarity index 100% rename from graphics/wonder_transfers/wonder_card_2.bin rename to graphics/wonder_card/bg2.bin diff --git a/graphics/wonder_transfers/wonder_card_2.png b/graphics/wonder_card/bg2.png similarity index 100% rename from graphics/wonder_transfers/wonder_card_2.png rename to graphics/wonder_card/bg2.png diff --git a/graphics/wonder_transfers/wonder_card_3.bin b/graphics/wonder_card/bg3.bin similarity index 100% rename from graphics/wonder_transfers/wonder_card_3.bin rename to graphics/wonder_card/bg3.bin diff --git a/graphics/wonder_transfers/wonder_card_3.png b/graphics/wonder_card/bg3.png similarity index 100% rename from graphics/wonder_transfers/wonder_card_3.png rename to graphics/wonder_card/bg3.png diff --git a/graphics/wonder_transfers/wonder_card_4.png b/graphics/wonder_card/bg4.png similarity index 100% rename from graphics/wonder_transfers/wonder_card_4.png rename to graphics/wonder_card/bg4.png diff --git a/graphics/wonder_transfers/wonder_card_5.png b/graphics/wonder_card/bg5.png similarity index 100% rename from graphics/wonder_transfers/wonder_card_5.png rename to graphics/wonder_card/bg5.png diff --git a/graphics/wonder_transfers/wonder_card_6.png b/graphics/wonder_card/bg6.png similarity index 100% rename from graphics/wonder_transfers/wonder_card_6.png rename to graphics/wonder_card/bg6.png diff --git a/graphics/wonder_transfers/wonder_card_7.bin b/graphics/wonder_card/bg7.bin similarity index 100% rename from graphics/wonder_transfers/wonder_card_7.bin rename to graphics/wonder_card/bg7.bin diff --git a/graphics/wonder_transfers/wonder_card_7.png b/graphics/wonder_card/bg7.png similarity index 100% rename from graphics/wonder_transfers/wonder_card_7.png rename to graphics/wonder_card/bg7.png diff --git a/graphics/wonder_transfers/wonder_card_8.bin b/graphics/wonder_card/bg8.bin similarity index 100% rename from graphics/wonder_transfers/wonder_card_8.bin rename to graphics/wonder_card/bg8.bin diff --git a/graphics/wonder_transfers/wonder_card_8.png b/graphics/wonder_card/bg8.png similarity index 100% rename from graphics/wonder_transfers/wonder_card_8.png rename to graphics/wonder_card/bg8.png diff --git a/graphics/wonder_transfers/wonder_card_shadow.png b/graphics/wonder_card/icon_shadow.png similarity index 100% rename from graphics/wonder_transfers/wonder_card_shadow.png rename to graphics/wonder_card/icon_shadow.png diff --git a/graphics/wonder_transfers/wonder_card_shadow_1.pal b/graphics/wonder_card/icon_shadow_1.pal similarity index 100% rename from graphics/wonder_transfers/wonder_card_shadow_1.pal rename to graphics/wonder_card/icon_shadow_1.pal diff --git a/graphics/wonder_transfers/wonder_card_shadow_2.pal b/graphics/wonder_card/icon_shadow_2.pal similarity index 100% rename from graphics/wonder_transfers/wonder_card_shadow_2.pal rename to graphics/wonder_card/icon_shadow_2.pal diff --git a/graphics/wonder_transfers/wonder_card_shadow_3.pal b/graphics/wonder_card/icon_shadow_3.pal similarity index 100% rename from graphics/wonder_transfers/wonder_card_shadow_3.pal rename to graphics/wonder_card/icon_shadow_3.pal diff --git a/graphics/wonder_transfers/wonder_card_shadow_4.pal b/graphics/wonder_card/icon_shadow_4.pal similarity index 100% rename from graphics/wonder_transfers/wonder_card_shadow_4.pal rename to graphics/wonder_card/icon_shadow_4.pal diff --git a/graphics/wonder_transfers/wonder_card_shadow_5.pal b/graphics/wonder_card/icon_shadow_5.pal similarity index 100% rename from graphics/wonder_transfers/wonder_card_shadow_5.pal rename to graphics/wonder_card/icon_shadow_5.pal diff --git a/graphics/wonder_transfers/wonder_card_shadow_6.pal b/graphics/wonder_card/icon_shadow_6.pal similarity index 100% rename from graphics/wonder_transfers/wonder_card_shadow_6.pal rename to graphics/wonder_card/icon_shadow_6.pal diff --git a/graphics/wonder_transfers/wonder_card_shadow_7.pal b/graphics/wonder_card/icon_shadow_7.pal similarity index 100% rename from graphics/wonder_transfers/wonder_card_shadow_7.pal rename to graphics/wonder_card/icon_shadow_7.pal diff --git a/graphics/wonder_transfers/wonder_card_shadow_8.pal b/graphics/wonder_card/icon_shadow_8.pal similarity index 100% rename from graphics/wonder_transfers/wonder_card_shadow_8.pal rename to graphics/wonder_card/icon_shadow_8.pal diff --git a/graphics/wonder_transfers/wonder_news_1.bin b/graphics/wonder_news/bg1.bin similarity index 100% rename from graphics/wonder_transfers/wonder_news_1.bin rename to graphics/wonder_news/bg1.bin diff --git a/graphics/wonder_transfers/wonder_news_1.png b/graphics/wonder_news/bg1.png similarity index 100% rename from graphics/wonder_transfers/wonder_news_1.png rename to graphics/wonder_news/bg1.png diff --git a/graphics/wonder_transfers/wonder_news_2.bin b/graphics/wonder_news/bg2.bin similarity index 100% rename from graphics/wonder_transfers/wonder_news_2.bin rename to graphics/wonder_news/bg2.bin diff --git a/graphics/wonder_transfers/wonder_news_2.png b/graphics/wonder_news/bg2.png similarity index 100% rename from graphics/wonder_transfers/wonder_news_2.png rename to graphics/wonder_news/bg2.png diff --git a/graphics/wonder_transfers/wonder_news_3.bin b/graphics/wonder_news/bg3.bin similarity index 100% rename from graphics/wonder_transfers/wonder_news_3.bin rename to graphics/wonder_news/bg3.bin diff --git a/graphics/wonder_transfers/wonder_news_3.png b/graphics/wonder_news/bg3.png similarity index 100% rename from graphics/wonder_transfers/wonder_news_3.png rename to graphics/wonder_news/bg3.png diff --git a/graphics/wonder_transfers/wonder_news_7.bin b/graphics/wonder_news/bg7.bin similarity index 100% rename from graphics/wonder_transfers/wonder_news_7.bin rename to graphics/wonder_news/bg7.bin diff --git a/graphics/wonder_transfers/wonder_news_7.png b/graphics/wonder_news/bg7.png similarity index 100% rename from graphics/wonder_transfers/wonder_news_7.png rename to graphics/wonder_news/bg7.png diff --git a/graphics/wonder_transfers/wonder_news_8.bin b/graphics/wonder_news/bg8.bin similarity index 100% rename from graphics/wonder_transfers/wonder_news_8.bin rename to graphics/wonder_news/bg8.bin diff --git a/graphics/wonder_transfers/wonder_news_8.png b/graphics/wonder_news/bg8.png similarity index 100% rename from graphics/wonder_transfers/wonder_news_8.png rename to graphics/wonder_news/bg8.png diff --git a/include/constants/global.h b/include/constants/global.h index 1cece7975..518fe6bad 100644 --- a/include/constants/global.h +++ b/include/constants/global.h @@ -87,6 +87,8 @@ #define MOVE_NAME_LENGTH 12 #define NUM_QUESTIONNAIRE_WORDS 4 #define QUIZ_QUESTION_LEN 9 +#define WONDER_CARD_TEXT_LENGTH 40 +#define WONDER_NEWS_TEXT_LENGTH 40 #define MALE 0 #define FEMALE 1 diff --git a/include/constants/mevent.h b/include/constants/mevent.h index 25bbcdf36..3478816fd 100644 --- a/include/constants/mevent.h +++ b/include/constants/mevent.h @@ -12,4 +12,7 @@ #define REQUIRED_CARD_BATTLES 3 +// Number of different types/colors of Wonder Card and News backgrounds +#define NUM_WONDER_BGS 8 + #endif //GUARD_MEVENT_H diff --git a/include/global.h b/include/global.h index d14aa60f4..f8bb24da7 100644 --- a/include/global.h +++ b/include/global.h @@ -849,9 +849,9 @@ struct MysteryEventStruct { u16 unk_00; u8 unk_02; - u8 unk_03; - u8 unk_04[40]; - u8 unk_2C[10][40]; + u8 bgType; + u8 unk_04[WONDER_NEWS_TEXT_LENGTH]; + u8 unk_2C[10][WONDER_NEWS_TEXT_LENGTH]; }; struct WonderNewsSaveStruct @@ -866,14 +866,14 @@ struct MysteryEventStruct u16 unk_02; u32 unk_04; u8 unk_08_0:2; - u8 unk_08_2:4; + u8 bgType:4; u8 unk_08_6:2; u8 unk_09; - u8 unk_0A[40]; - u8 unk_32[40]; - u8 unk_5A[4][40]; - u8 unk_FA[40]; - u8 unk_122[40]; + u8 unk_0A[WONDER_CARD_TEXT_LENGTH]; + u8 unk_32[WONDER_CARD_TEXT_LENGTH]; + u8 unk_5A[4][WONDER_CARD_TEXT_LENGTH]; + u8 unk_FA[WONDER_CARD_TEXT_LENGTH]; + u8 unk_122[WONDER_CARD_TEXT_LENGTH]; }; struct WonderCardSaveStruct diff --git a/include/mevent_801BAAC.h b/include/mevent_801BAAC.h deleted file mode 100644 index d76bc92c2..000000000 --- a/include/mevent_801BAAC.h +++ /dev/null @@ -1,16 +0,0 @@ -#ifndef GUARD_MEVENT_801BAAC_H -#define GUARD_MEVENT_801BAAC_H - -bool32 InitWonderCardResources(struct WonderCard * r5, struct MEventBuffer_3430_Sub * r6); -bool32 InitWonderNewsResources(const struct WonderNews * a0); -s32 FadeToWonderCardMenu(void); -s32 FadeToWonderNewsMenu(void); -s32 FadeOutFromWonderCard(bool32 flag); -void DestroyWonderCardResources(void); -s32 FadeOutFromWonderNews(bool32 flag); -void DestroyWonderNewsResources(void); -u32 MENews_GetInput(u16 input); -void MENews_AddScrollIndicatorArrowPair(void); -void MENews_RemoveScrollIndicatorArrowPair(void); - -#endif //GUARD_MEVENT_801BAAC_H diff --git a/include/wonder_transfer.h b/include/wonder_transfer.h new file mode 100644 index 000000000..65b475725 --- /dev/null +++ b/include/wonder_transfer.h @@ -0,0 +1,24 @@ +#ifndef GUARD_WONDER_TRANSFER_H +#define GUARD_WONDER_TRANSFER_H + +enum { + NEWS_INPUT_A, + NEWS_INPUT_B, + NEWS_INPUT_SCROLL_UP, + NEWS_INPUT_SCROLL_DOWN, + NEWS_INPUT_NONE = 0xFF +}; + +bool32 WonderCard_Init(struct WonderCard * card, struct MEventBuffer_3430_Sub * r6); +bool32 WonderNews_Init(const struct WonderNews * news); +s32 WonderCard_Enter(void); +s32 WonderNews_Enter(void); +s32 WonderCard_Exit(bool32 flag); +s32 WonderNews_Exit(bool32 flag); +void WonderCard_Destroy(void); +void WonderNews_Destroy(void); +u32 WonderNews_GetInput(u16 input); +void WonderNews_AddScrollIndicatorArrowPair(void); +void WonderNews_RemoveScrollIndicatorArrowPair(void); + +#endif //GUARD_WONDER_TRANSFER_H diff --git a/ld_script.txt b/ld_script.txt index 218c6d3a5..14feda1c0 100644 --- a/ld_script.txt +++ b/ld_script.txt @@ -68,7 +68,7 @@ SECTIONS { src/wireless_communication_status_screen.o(.text); src/union_room_battle.o(.text); src/mevent2.o(.text); - src/mevent_801BAAC.o(.text); + src/wonder_transfer.o(.text); src/mevent_server.o(.text); src/mevent_client.o(.text); src/mevent_server_helpers.o(.text); @@ -454,7 +454,7 @@ SECTIONS { src/wireless_communication_status_screen.o(.rodata); src/union_room_battle.o(.rodata); src/mevent2.o(.rodata); - src/mevent_801BAAC.o(.rodata); + src/wonder_transfer.o(.rodata); src/mevent_server.o(.rodata); src/mevent_client.o(.rodata); src/mevent_scripts.o(.rodata); diff --git a/src/mevent2.c b/src/mevent2.c index d2c020858..c7035ae8f 100755 --- a/src/mevent2.c +++ b/src/mevent2.c @@ -16,7 +16,7 @@ static EWRAM_DATA bool32 gUnknown_02022C70 = FALSE; static void sub_801B180(void); static void s_DestroyWonderNews(void); static bool32 sub_801B114(const struct WonderNews *data); -static bool32 sub_801B2CC(const struct WonderCard *data); +static bool32 ValidateWonderCardData(const struct WonderCard *data); static void sub_801B330(void); static void sub_801B368(void); static void sub_801B9F8(void); @@ -140,7 +140,7 @@ bool32 sub_801B21C(const struct WonderCard *data) { struct MEventBuffer_3430_Sub *r2; struct WonderCard *r1; - if (!sub_801B2CC(data)) + if (!ValidateWonderCardData(data)) return FALSE; DestroyWonderCard(); @@ -156,7 +156,7 @@ bool32 ValidateReceivedWonderCard(void) { if (gSaveBlock1Ptr->unk_322C.wonderCard.crc != CalcCRC16WithTable((void *)&gSaveBlock1Ptr->unk_322C.wonderCard.data, sizeof(struct WonderCard))) return FALSE; - if (!sub_801B2CC(&gSaveBlock1Ptr->unk_322C.wonderCard.data)) + if (!ValidateWonderCardData(&gSaveBlock1Ptr->unk_322C.wonderCard.data)) return FALSE; if (!ValidateSavedRamScript()) return FALSE; @@ -164,7 +164,7 @@ bool32 ValidateReceivedWonderCard(void) return TRUE; } -static bool32 sub_801B2CC(const struct WonderCard *data) +static bool32 ValidateWonderCardData(const struct WonderCard *data) { if (data->unk_00 == 0) return FALSE; @@ -172,7 +172,7 @@ static bool32 sub_801B2CC(const struct WonderCard *data) return FALSE; if (!(data->unk_08_6 == 0 || data->unk_08_6 == 1 || data->unk_08_6 == 2)) return FALSE; - if (data->unk_08_2 > 7) + if (data->bgType >= NUM_WONDER_BGS) return FALSE; if (data->unk_09 > 7) return FALSE; diff --git a/src/mevent_801BAAC.c b/src/mevent_801BAAC.c deleted file mode 100644 index a3e6ee0b6..000000000 --- a/src/mevent_801BAAC.c +++ /dev/null @@ -1,826 +0,0 @@ -#include "global.h" -#include "bg.h" -#include "gpu_regs.h" -#include "palette.h" -#include "decompress.h" -#include "malloc.h" -#include "menu.h" -#include "pokemon_icon.h" -#include "union_room.h" -#include "list_menu.h" -#include "text_window.h" -#include "string_util.h" -#include "link_rfu.h" -#include "mevent.h" -#include "mystery_gift.h" -#include "constants/rgb.h" - -struct UnkStruct_8467FB8 -{ - u8 textPal1:4; - u8 textPal2:4; - u8 textPal3:4; - u8 textPal4:4; - const u32 * tiles; - const u32 * map; - const u16 * pal; -}; - -struct UnkStruct_203F3C8_02DC -{ - u8 unk_00; - u8 unk_01[41]; - u8 unk_42[4]; -}; - -struct UnkStruct_203F3C8 -{ - /*0000*/ struct WonderCard unk_0000; - /*014c*/ struct MEventBuffer_3430_Sub unk_014C; - /*0170*/ const struct UnkStruct_8467FB8 * unk_0170; - /*0174*/ u8 unk_0174; - /*0175*/ u8 unk_0175; - /*0176*/ u16 unk_0176[3]; - /*017C*/ u8 unk_017C; - /*017D*/ u8 unk_017D[7][2]; - /*018B*/ u8 unk_018B[41]; - /*01B4*/ u8 unk_01B4[41]; - /*01DD*/ u8 unk_01DD[7]; - /*01E4*/ u8 unk_01E4[4][41]; - /*0288*/ u8 unk_0288[41]; - /*02B1*/ u8 unk_02B1[41]; - /*02DC*/ struct UnkStruct_203F3C8_02DC unk_02DC[8]; - /*045C*/ u8 buffer_045C[0x1000]; -}; - -EWRAM_DATA struct UnkStruct_203F3C8 * sWonderCardData = NULL; - -void sub_801BEF8(void); -void sub_801C178(u8 whichWindow); -void sub_801C4C0(void); -void sub_801C61C(void); - -extern const struct OamData gOamData_AffineOff_ObjNormal_32x16; - -const u8 sTextColorTable[][3] = { - {TEXT_COLOR_TRANSPARENT, TEXT_COLOR_DARK_GRAY, TEXT_COLOR_LIGHT_GRAY}, - {TEXT_COLOR_TRANSPARENT, TEXT_COLOR_WHITE, TEXT_COLOR_DARK_GRAY} -}; -const u8 ALIGNED(4) gUnknown_082F0E18[3] = {7, 4, 7}; -const struct WindowTemplate gUnknown_082F0E1C[] = { - { - .bg = 1, - .tilemapLeft = 1, - .tilemapTop = 1, - .width = 25, - .height = 4, - .paletteNum = 2, - .baseBlock = 0x029c - }, { - .bg = 1, - .tilemapLeft = 1, - .tilemapTop = 6, - .width = 28, - .height = 8, - .paletteNum = 2, - .baseBlock = 0x01bc - }, { - .bg = 1, - .tilemapLeft = 1, - .tilemapTop = 14, - .width = 28, - .height = 5, - .paletteNum = 2, - .baseBlock = 0x0130 - } -}; - -const u16 gWonderCardBgPal1[] = INCBIN_U16("graphics/wonder_transfers/wonder_card_1.gbapal"); -const u16 gWonderCardBgPal2[] = INCBIN_U16("graphics/wonder_transfers/wonder_card_2.gbapal"); -const u16 gWonderCardBgPal3[] = INCBIN_U16("graphics/wonder_transfers/wonder_card_3.gbapal"); -const u16 gWonderCardBgPal4[] = INCBIN_U16("graphics/wonder_transfers/wonder_card_4.gbapal"); -const u16 gWonderCardBgPal5[] = INCBIN_U16("graphics/wonder_transfers/wonder_card_5.gbapal"); -const u16 gWonderCardBgPal6[] = INCBIN_U16("graphics/wonder_transfers/wonder_card_6.gbapal"); -const u16 gWonderCardBgPal7[] = INCBIN_U16("graphics/wonder_transfers/wonder_card_7.gbapal"); -const u16 gWonderCardBgPal8[] = INCBIN_U16("graphics/wonder_transfers/wonder_card_8.gbapal"); -const u32 gWonderCardBgGfx1[] = INCBIN_U32("graphics/wonder_transfers/wonder_card_1.4bpp.lz"); -const u32 gWonderCardBgTilemap1[] = INCBIN_U32("graphics/wonder_transfers/wonder_card_1.bin.lz"); -const u32 gWonderCardBgGfx2[] = INCBIN_U32("graphics/wonder_transfers/wonder_card_2.4bpp.lz"); -const u32 gWonderCardBgTilemap2[] = INCBIN_U32("graphics/wonder_transfers/wonder_card_2.bin.lz"); -const u32 gWonderCardBgGfx3[] = INCBIN_U32("graphics/wonder_transfers/wonder_card_3.4bpp.lz"); -const u32 gWonderCardBgTilemap3[] = INCBIN_U32("graphics/wonder_transfers/wonder_card_3.bin.lz"); -const u32 gWonderCardBgGfx7[] = INCBIN_U32("graphics/wonder_transfers/wonder_card_7.4bpp.lz"); -const u32 gWonderCardBgTilemap7[] = INCBIN_U32("graphics/wonder_transfers/wonder_card_7.bin.lz"); -const u32 gWonderCardBgGfx8[] = INCBIN_U32("graphics/wonder_transfers/wonder_card_8.4bpp.lz"); -const u32 gWonderCardBgTilemap8[] = INCBIN_U32("graphics/wonder_transfers/wonder_card_8.bin.lz"); -const u16 gWonderCardShadowPal1[] = INCBIN_U16("graphics/wonder_transfers/wonder_card_shadow_1.gbapal"); -const u16 gWonderCardShadowPal2[] = INCBIN_U16("graphics/wonder_transfers/wonder_card_shadow_2.gbapal"); -const u16 gWonderCardShadowPal3[] = INCBIN_U16("graphics/wonder_transfers/wonder_card_shadow_3.gbapal"); -const u16 gWonderCardShadowPal4[] = INCBIN_U16("graphics/wonder_transfers/wonder_card_shadow_4.gbapal"); -const u16 gWonderCardShadowPal5[] = INCBIN_U16("graphics/wonder_transfers/wonder_card_shadow_5.gbapal"); -const u16 gWonderCardShadowPal6[] = INCBIN_U16("graphics/wonder_transfers/wonder_card_shadow_6.gbapal"); -const u16 gWonderCardShadowPal7[] = INCBIN_U16("graphics/wonder_transfers/wonder_card_shadow_7.gbapal"); -const u16 gWonderCardShadowPal8[] = INCBIN_U16("graphics/wonder_transfers/wonder_card_shadow_8.gbapal"); -const u32 gWonderCardShadowGfx[] = INCBIN_U32("graphics/wonder_transfers/wonder_card_shadow.4bpp.lz"); - -const struct CompressedSpriteSheet gUnknown_082F1D00 = { - gWonderCardShadowGfx, 0x100, 0x8000 -}; -const struct SpritePalette gUnknown_082F1D08[] = { - {gWonderCardShadowPal1, 0x8000}, - {gWonderCardShadowPal2, 0x8000}, - {gWonderCardShadowPal3, 0x8000}, - {gWonderCardShadowPal4, 0x8000}, - {gWonderCardShadowPal5, 0x8000}, - {gWonderCardShadowPal6, 0x8000}, - {gWonderCardShadowPal7, 0x8000}, - {gWonderCardShadowPal8, 0x8000} -}; -const struct SpriteTemplate gUnknown_082F1D48 = { - 0x8000, 0x8000, &gOamData_AffineOff_ObjNormal_32x16, gDummySpriteAnimTable, NULL, gDummySpriteAffineAnimTable, SpriteCallbackDummy -}; -const struct UnkStruct_8467FB8 gUnknown_082F1D60[8] = { - {1, 0, 0, 0, gWonderCardBgGfx1, gWonderCardBgTilemap1, gWonderCardBgPal1}, - {1, 0, 0, 1, gWonderCardBgGfx2, gWonderCardBgTilemap2, gWonderCardBgPal2}, - {1, 0, 0, 2, gWonderCardBgGfx3, gWonderCardBgTilemap3, gWonderCardBgPal3}, - {1, 0, 0, 3, gWonderCardBgGfx3, gWonderCardBgTilemap3, gWonderCardBgPal4}, - {1, 0, 0, 4, gWonderCardBgGfx3, gWonderCardBgTilemap3, gWonderCardBgPal5}, - {1, 0, 0, 5, gWonderCardBgGfx3, gWonderCardBgTilemap3, gWonderCardBgPal6}, - {1, 0, 0, 6, gWonderCardBgGfx7, gWonderCardBgTilemap7, gWonderCardBgPal7}, - {1, 0, 0, 7, gWonderCardBgGfx8, gWonderCardBgTilemap8, gWonderCardBgPal8} -}; - -bool32 InitWonderCardResources(struct WonderCard * r5, struct MEventBuffer_3430_Sub * r6) -{ - if (r5 == NULL || r6 == NULL) - return FALSE; - sWonderCardData = AllocZeroed(sizeof(struct UnkStruct_203F3C8)); - if (sWonderCardData == NULL) - return FALSE; - sWonderCardData->unk_0000 = *r5; - sWonderCardData->unk_014C = *r6; - if (sWonderCardData->unk_0000.unk_08_2 >= ARRAY_COUNT(gUnknown_082F1D60)) - sWonderCardData->unk_0000.unk_08_2 = 0; - if (sWonderCardData->unk_0000.unk_08_0 >= ARRAY_COUNT(gUnknown_082F0E18)) - sWonderCardData->unk_0000.unk_08_0 = 0; - if (sWonderCardData->unk_0000.unk_09 > ARRAY_COUNT(sWonderCardData->unk_017D)) - sWonderCardData->unk_0000.unk_09 = 0; - sWonderCardData->unk_0170 = &gUnknown_082F1D60[sWonderCardData->unk_0000.unk_08_2]; - return TRUE; -} - -void DestroyWonderCardResources(void) -{ - if (sWonderCardData != NULL) - { - *sWonderCardData = (struct UnkStruct_203F3C8){}; - Free(sWonderCardData); - sWonderCardData = NULL; - } -} - -s32 FadeToWonderCardMenu(void) -{ - if (sWonderCardData == NULL) - return -1; - switch(sWonderCardData->unk_0174) - { - case 0: - BeginNormalPaletteFade(PALETTES_ALL, 0, 0, 16, RGB_BLACK); - break; - case 1: - if (UpdatePaletteFade()) - return 0; - break; - case 2: - FillBgTilemapBufferRect_Palette0(0, 0x000, 0, 0, 30, 20); - FillBgTilemapBufferRect_Palette0(1, 0x000, 0, 0, 30, 20); - FillBgTilemapBufferRect_Palette0(2, 0x000, 0, 0, 30, 20); - CopyBgTilemapBufferToVram(0); - CopyBgTilemapBufferToVram(1); - CopyBgTilemapBufferToVram(2); - DecompressAndCopyTileDataToVram(2, sWonderCardData->unk_0170->tiles, 0, 0x008, 0); - sWonderCardData->unk_0176[0] = AddWindow(&gUnknown_082F0E1C[0]); - sWonderCardData->unk_0176[1] = AddWindow(&gUnknown_082F0E1C[1]); - sWonderCardData->unk_0176[2] = AddWindow(&gUnknown_082F0E1C[2]); - break; - case 3: - if (FreeTempTileDataBuffersIfPossible()) - return 0; - LoadPalette(GetTextWindowPalette(1), 0x20, 0x20); - gPaletteFade.bufferTransferDisabled = TRUE; - LoadPalette(sWonderCardData->unk_0170->pal, 0x10, 0x20); - LZ77UnCompWram(sWonderCardData->unk_0170->map, sWonderCardData->buffer_045C); - CopyRectToBgTilemapBufferRect(2, sWonderCardData->buffer_045C, 0, 0, 30, 20, 0, 0, 30, 20, 1, 0x008, 0); - CopyBgTilemapBufferToVram(2); - break; - case 4: - sub_801BEF8(); - break; - case 5: - sub_801C178(0); - sub_801C178(1); - sub_801C178(2); - CopyBgTilemapBufferToVram(1); - break; - case 6: - LoadMonIconPalettes(); - break; - case 7: - ShowBg(1); - ShowBg(2); - gPaletteFade.bufferTransferDisabled = FALSE; - sub_801C4C0(); - BeginNormalPaletteFade(PALETTES_ALL, 0, 16, 0, RGB_BLACK); - UpdatePaletteFade(); - break; - default: - if (UpdatePaletteFade()) - return 0; - sWonderCardData->unk_0174 = 0; - return 1; - } - ++sWonderCardData->unk_0174; - return 0; -} - -s32 FadeOutFromWonderCard(bool32 flag) -{ - if (sWonderCardData == NULL) - return -1; - switch (sWonderCardData->unk_0174) - { - case 0: - BeginNormalPaletteFade(PALETTES_ALL, 0, 0, 16, RGB_BLACK); - break; - case 1: - if (UpdatePaletteFade()) - return 0; - break; - case 2: - FillBgTilemapBufferRect_Palette0(0, 0x000, 0, 0, 30, 20); - FillBgTilemapBufferRect_Palette0(1, 0x000, 0, 0, 30, 20); - FillBgTilemapBufferRect_Palette0(2, 0x000, 0, 0, 30, 20); - CopyBgTilemapBufferToVram(0); - CopyBgTilemapBufferToVram(1); - CopyBgTilemapBufferToVram(2); - break; - case 3: - HideBg(1); - HideBg(2); - RemoveWindow(sWonderCardData->unk_0176[2]); - RemoveWindow(sWonderCardData->unk_0176[1]); - RemoveWindow(sWonderCardData->unk_0176[0]); - break; - case 4: - sub_801C61C(); - FreeMonIconPalettes(); - break; - case 5: - PrintMysteryGiftOrEReaderTopMenu(gGiftIsFromEReader, flag); - CopyBgTilemapBufferToVram(0); - BeginNormalPaletteFade(PALETTES_ALL, 0, 16, 0, RGB_BLACK); - break; - default: - if (UpdatePaletteFade()) - return 0; - sWonderCardData->unk_0174 = 0; - return 1; - } - ++sWonderCardData->unk_0174; - return 0; -} - -void sub_801BEF8(void) -{ - u16 i = 0; - u16 r6; - u16 sp0[3] = {0, 0, 0}; - - memcpy(sWonderCardData->unk_018B, sWonderCardData->unk_0000.unk_0A, 40); - sWonderCardData->unk_018B[40] = EOS; - memcpy(sWonderCardData->unk_01B4, sWonderCardData->unk_0000.unk_32, 40); - sWonderCardData->unk_01B4[40] = EOS; - if (sWonderCardData->unk_0000.unk_04 > 999999) - sWonderCardData->unk_0000.unk_04 = 999999; - ConvertIntToDecimalStringN(sWonderCardData->unk_01DD, sWonderCardData->unk_0000.unk_04, STR_CONV_MODE_LEFT_ALIGN, 6); - for (i = 0; i < 4; i++) - { - memcpy(sWonderCardData->unk_01E4[i], sWonderCardData->unk_0000.unk_5A[i], 40); - sWonderCardData->unk_01E4[i][40] = EOS; - } - memcpy(sWonderCardData->unk_0288, sWonderCardData->unk_0000.unk_FA, 40); - sWonderCardData->unk_0288[40] = EOS; - switch (sWonderCardData->unk_0000.unk_08_0) - { - case 0: - memcpy(sWonderCardData->unk_02B1, sWonderCardData->unk_0000.unk_122, 40); - sWonderCardData->unk_02B1[40] = EOS; - break; - case 1: - sWonderCardData->unk_02B1[00] = EOS; - break; - case 2: - sWonderCardData->unk_02B1[00] = EOS; - sp0[0] = sWonderCardData->unk_014C.unk_00 < 999 ? sWonderCardData->unk_014C.unk_00 : 999; - sp0[1] = sWonderCardData->unk_014C.unk_02 < 999 ? sWonderCardData->unk_014C.unk_02 : 999; - sp0[2] = sWonderCardData->unk_014C.unk_04 < 999 ? sWonderCardData->unk_014C.unk_04 : 999; - for (i = 0; i < 8; i++) - { - memset(sWonderCardData->unk_02DC[i].unk_42, EOS, 4); - memset(sWonderCardData->unk_02DC[i].unk_01, EOS, 41); - } - for (i = 0, r6 = 0; i < 40; i++) - { - if (sWonderCardData->unk_0000.unk_122[i] != 0xF7) - { - sWonderCardData->unk_02DC[sWonderCardData->unk_0175].unk_01[r6] = sWonderCardData->unk_0000.unk_122[i]; - r6++; - } - else - { - u8 r3 = sWonderCardData->unk_0000.unk_122[i + 1]; - if (r3 > 2) - { - i += 2; - } - else - { - ConvertIntToDecimalStringN(sWonderCardData->unk_02DC[sWonderCardData->unk_0175].unk_42, sp0[r3], STR_CONV_MODE_LEADING_ZEROS, 3); - sWonderCardData->unk_02DC[sWonderCardData->unk_0175].unk_00 = sWonderCardData->unk_0000.unk_122[i + 2]; - sWonderCardData->unk_0175++; - if (sWonderCardData->unk_0175 > 7) - break; - r6 = 0; - i += 2; - } - } - } - } -} - -void sub_801C178(u8 whichWindow) -{ - s8 sp0C = 0; - s32 windowId = sWonderCardData->unk_0176[whichWindow]; - PutWindowTilemap(windowId); - FillWindowPixelBuffer(windowId, 0); - switch (whichWindow) - { - case 0: - { - s32 x; - AddTextPrinterParameterized3(windowId, 3, 0, 1, sTextColorTable[sWonderCardData->unk_0170->textPal1], 0, sWonderCardData->unk_018B); - x = 160 - GetStringWidth(3, sWonderCardData->unk_01B4, GetFontAttribute(3, 2)); - if (x < 0) - x = 0; - AddTextPrinterParameterized3(windowId, 3, x, 17, sTextColorTable[sWonderCardData->unk_0170->textPal1], 0, sWonderCardData->unk_01B4); - if (sWonderCardData->unk_0000.unk_04 != 0) - { - AddTextPrinterParameterized3(windowId, 1, 166, 17, sTextColorTable[sWonderCardData->unk_0170->textPal1], 0, sWonderCardData->unk_01DD); - } - break; - } - case 1: - for (; sp0C < 4; sp0C++) - { - AddTextPrinterParameterized3(windowId, 3, 0, 16 * sp0C + 2, sTextColorTable[sWonderCardData->unk_0170->textPal2], 0, sWonderCardData->unk_01E4[sp0C]); - } - break; - case 2: - AddTextPrinterParameterized3(windowId, 3, 0, gUnknown_082F0E18[sWonderCardData->unk_0000.unk_08_0], sTextColorTable[sWonderCardData->unk_0170->textPal3], 0, sWonderCardData->unk_0288); - if (sWonderCardData->unk_0000.unk_08_0 != 2) - { - AddTextPrinterParameterized3(windowId, 3, 0, 16 + gUnknown_082F0E18[sWonderCardData->unk_0000.unk_08_0], sTextColorTable[sWonderCardData->unk_0170->textPal3], 0, sWonderCardData->unk_02B1); - } - else - { - s32 x = 0; - s32 y = gUnknown_082F0E18[sWonderCardData->unk_0000.unk_08_0] + 16; - s32 spacing = GetFontAttribute(3, 2); - for (; sp0C < sWonderCardData->unk_0175; sp0C++) - { - AddTextPrinterParameterized3(windowId, 3, x, y, sTextColorTable[sWonderCardData->unk_0170->textPal3], 0, sWonderCardData->unk_02DC[sp0C].unk_01); - if (sWonderCardData->unk_02DC[sp0C].unk_42[0] != EOS) - { - x += GetStringWidth(3, sWonderCardData->unk_02DC[sp0C].unk_01, spacing); - AddTextPrinterParameterized3(windowId, 3, x, y, sTextColorTable[sWonderCardData->unk_0170->textPal3], 0, sWonderCardData->unk_02DC[sp0C].unk_42); - x += GetStringWidth(3, sWonderCardData->unk_02DC[sp0C].unk_42, spacing) + sWonderCardData->unk_02DC[sp0C].unk_00; - } - } - } - break; - } - CopyWindowToVram(windowId, 3); -} - -void sub_801C4C0(void) -{ - u8 r7 = 0; - sWonderCardData->unk_017C = 0xFF; - if (sWonderCardData->unk_014C.unk_06 != SPECIES_NONE) - { - sWonderCardData->unk_017C = CreateMonIconNoPersonality(GetIconSpeciesNoPersonality(sWonderCardData->unk_014C.unk_06), SpriteCallbackDummy, 0xDC, 0x14, 0, FALSE); - gSprites[sWonderCardData->unk_017C].oam.priority = 2; - } - if (sWonderCardData->unk_0000.unk_09 != 0 && sWonderCardData->unk_0000.unk_08_0 == 1) - { - LoadCompressedSpriteSheetUsingHeap(&gUnknown_082F1D00); - LoadSpritePalette(&gUnknown_082F1D08[sWonderCardData->unk_0170->textPal4]); - for (; r7 < sWonderCardData->unk_0000.unk_09; r7++) - { - sWonderCardData->unk_017D[r7][0] = 0xFF; - sWonderCardData->unk_017D[r7][1] = 0xFF; - sWonderCardData->unk_017D[r7][0] = CreateSprite(&gUnknown_082F1D48, 0xd8 - 32 * r7, 0x90, 8); - if (sWonderCardData->unk_014C.unk_08[0][r7] != 0) - { - sWonderCardData->unk_017D[r7][1] = CreateMonIconNoPersonality(GetIconSpeciesNoPersonality(sWonderCardData->unk_014C.unk_08[0][r7]), SpriteCallbackDummy, 0xd8 - 32 * r7, 0x88, 0, 0); - } - } - } -} - -void sub_801C61C(void) -{ - u8 r6 = 0; - if (sWonderCardData->unk_017C != 0xFF) - FreeAndDestroyMonIconSprite(&gSprites[sWonderCardData->unk_017C]); - if (sWonderCardData->unk_0000.unk_09 != 0 && sWonderCardData->unk_0000.unk_08_0 == 1) - { - for (; r6 < sWonderCardData->unk_0000.unk_09; r6++) - { - if (sWonderCardData->unk_017D[r6][0] != 0xFF) - { - DestroySprite(&gSprites[sWonderCardData->unk_017D[r6][0]]); - } - if (sWonderCardData->unk_017D[r6][1] != 0xFF) - { - FreeAndDestroyMonIconSprite(&gSprites[sWonderCardData->unk_017D[r6][1]]); - } - } - FreeSpriteTilesByTag(0x8000); - FreeSpritePaletteByTag(0x8000); - } -} - -struct UnkStruct_203F3CC -{ - /*0000*/ struct WonderNews unk_0000; - /*01bc*/ const struct UnkStruct_8467FB8 * unk_01BC; - /*01c0*/ u8 unk_01C0_0:1; - u8 unk_01C0_1:7; - /*01c1*/ u8 unk_01C1; - /*01c2*/ u8 unk_01C2_0:1; - u8 unk_01C2_1:7; - /*01c3*/ u8 unk_01C3_0:1; - u8 unk_01C3_1:7; - /*01c4*/ u16 unk_01C4; - /*01c6*/ u16 unk_01C6; - /*01c8*/ u16 unk_01C8[2]; - /*01cc*/ u8 filler_01CC[2]; - /*01ce*/ u8 unk_01CE[41]; - /*01f7*/ u8 unk_01F7[10][41]; - /*0394*/ struct ScrollArrowsTemplate unk_0394; - /*03a4*/ u8 buffer_03A4[0x1000]; -}; - -EWRAM_DATA struct UnkStruct_203F3CC * sWonderNewsData = NULL; - -void sub_801CDCC(void); -void sub_801CE7C(void); -void sub_801CFA4(void); - -const u8 gUnknown_082F1DE0[][3] = { - {0, 2, 3}, - {0, 1, 2} -}; -const struct WindowTemplate gUnknown_082F1DE8[] = { - { - .bg = 0, - .tilemapLeft = 1, - .tilemapTop = 0, - .width = 28, - .height = 3, - .paletteNum = 2, - .baseBlock = 0x2AC - }, { - .bg = 2, - .tilemapLeft = 1, - .tilemapTop = 3, - .width = 28, - .height = 20, - .paletteNum = 2, - .baseBlock = 0x07C - } -}; -const struct ScrollArrowsTemplate gUnknown_082F1DF8 = { - 0x02, 0xe8, 0x18, 0x03, 0xe8, 0x98, - 0x0000, 0x0002, 0x1000, 0x1000, 0x0 -}; -const u16 gWonderNewsPal1[] = INCBIN_U16("graphics/wonder_transfers/wonder_news_1.gbapal"); -const u16 gWonderNewsPal7[] = INCBIN_U16("graphics/wonder_transfers/wonder_news_7.gbapal"); -const u16 gWonderNewsPal8[] = INCBIN_U16("graphics/wonder_transfers/wonder_news_8.gbapal"); -const u32 gWonderNewsGfx1[] = INCBIN_U32("graphics/wonder_transfers/wonder_news_1.4bpp.lz"); -const u32 gWonderNewsTilemap1[] = INCBIN_U32("graphics/wonder_transfers/wonder_news_1.bin.lz"); -const u32 gWonderNewsGfx2[] = INCBIN_U32("graphics/wonder_transfers/wonder_news_2.4bpp.lz"); -const u32 gWonderNewsTilemap2[] = INCBIN_U32("graphics/wonder_transfers/wonder_news_2.bin.lz"); -const u32 gWonderNewsGfx3[] = INCBIN_U32("graphics/wonder_transfers/wonder_news_3.4bpp.lz"); -const u32 gWonderNewsTilemap3[] = INCBIN_U32("graphics/wonder_transfers/wonder_news_3.bin.lz"); -const u32 gWonderNewsGfx7[] = INCBIN_U32("graphics/wonder_transfers/wonder_news_7.4bpp.lz"); -const u32 gWonderNewsTilemap7[] = INCBIN_U32("graphics/wonder_transfers/wonder_news_7.bin.lz"); -const u32 gWonderNewsGfx8[] = INCBIN_U32("graphics/wonder_transfers/wonder_news_8.4bpp.lz"); -const u32 gWonderNewsTilemap8[] = INCBIN_U32("graphics/wonder_transfers/wonder_news_8.bin.lz"); - -const struct UnkStruct_8467FB8 gUnknown_082F24C8[] = { - {1, 0, 0, 0, gWonderNewsGfx1, gWonderNewsTilemap1, gWonderNewsPal1}, - {1, 0, 0, 0, gWonderNewsGfx2, gWonderNewsTilemap2, gWonderCardBgPal2}, - {1, 0, 0, 0, gWonderNewsGfx3, gWonderNewsTilemap3, gWonderCardBgPal3}, - {1, 0, 0, 0, gWonderNewsGfx3, gWonderNewsTilemap3, gWonderCardBgPal4}, - {1, 0, 0, 0, gWonderNewsGfx3, gWonderNewsTilemap3, gWonderCardBgPal5}, - {1, 0, 0, 0, gWonderNewsGfx3, gWonderNewsTilemap3, gWonderCardBgPal6}, - {1, 0, 0, 0, gWonderNewsGfx7, gWonderNewsTilemap7, gWonderNewsPal7}, - {1, 0, 0, 0, gWonderNewsGfx8, gWonderNewsTilemap8, gWonderNewsPal8} -}; - -bool32 InitWonderNewsResources(const struct WonderNews * a0) -{ - if (a0 == NULL) - return FALSE; - sWonderNewsData = AllocZeroed(sizeof(struct UnkStruct_203F3CC)); - if (sWonderNewsData == NULL) - return FALSE; - sWonderNewsData->unk_0000 = *a0; - if (sWonderNewsData->unk_0000.unk_03 >= ARRAY_COUNT(gUnknown_082F24C8)) - sWonderNewsData->unk_0000.unk_03 = 0; - sWonderNewsData->unk_01BC = &gUnknown_082F24C8[sWonderNewsData->unk_0000.unk_03]; - sWonderNewsData->unk_01C1 = 0xFF; - return TRUE; -} - -void DestroyWonderNewsResources(void) -{ - if (sWonderNewsData != NULL) - { - *sWonderNewsData = (struct UnkStruct_203F3CC){}; - Free(sWonderNewsData); - sWonderNewsData = NULL; - } -} - -s32 FadeToWonderNewsMenu(void) -{ - if (sWonderNewsData == NULL) - return -1; - - switch (sWonderNewsData->unk_01C0_1) - { - case 0: - BeginNormalPaletteFade(PALETTES_ALL, 0, 0, 16, RGB_BLACK); - break; - case 1: - if (UpdatePaletteFade()) - return 0; - ChangeBgY(0, 0, 0); - ChangeBgY(1, 0, 0); - ChangeBgY(2, 0, 0); - ChangeBgY(3, 0, 0); - SetGpuReg(REG_OFFSET_WIN0H, WIN_RANGE(0, DISPLAY_WIDTH)); - SetGpuReg(REG_OFFSET_WIN0V, WIN_RANGE(26, 152)); - SetGpuReg(REG_OFFSET_WININ, WININ_WIN0_BG_ALL | WININ_WIN0_OBJ); - SetGpuReg(REG_OFFSET_WINOUT, WINOUT_WIN01_BG0 | WINOUT_WIN01_BG1 | WINOUT_WIN01_BG3 | WINOUT_WIN01_OBJ); - SetGpuRegBits(REG_OFFSET_DISPCNT, DISPCNT_WIN0_ON); - break; - case 2: - FillBgTilemapBufferRect_Palette0(0, 0x000, 0, 0, 30, 20); - FillBgTilemapBufferRect_Palette0(1, 0x000, 0, 0, 30, 20); - FillBgTilemapBufferRect_Palette0(2, 0x000, 0, 0, 30, 20); - FillBgTilemapBufferRect_Palette0(3, 0x000, 0, 0, 30, 20); - CopyBgTilemapBufferToVram(0); - CopyBgTilemapBufferToVram(1); - CopyBgTilemapBufferToVram(2); - CopyBgTilemapBufferToVram(3); - DecompressAndCopyTileDataToVram(3, sWonderNewsData->unk_01BC->tiles, 0, 8, 0); - sWonderNewsData->unk_01C8[0] = AddWindow(&gUnknown_082F1DE8[0]); - sWonderNewsData->unk_01C8[1] = AddWindow(&gUnknown_082F1DE8[1]); - break; - case 3: - if (FreeTempTileDataBuffersIfPossible()) - return 0; - LoadPalette(GetTextWindowPalette(1), 0x20, 0x20); - gPaletteFade.bufferTransferDisabled = TRUE; - LoadPalette(sWonderNewsData->unk_01BC->pal, 0x10, 0x20); - LZ77UnCompWram(sWonderNewsData->unk_01BC->map, sWonderNewsData->buffer_03A4); - CopyRectToBgTilemapBufferRect(1, sWonderNewsData->buffer_03A4, 0, 0, 30, 3, 0, 0, 30, 3, 1, 8, 0); - CopyRectToBgTilemapBufferRect(3, sWonderNewsData->buffer_03A4, 0, 3, 30, 23, 0, 3, 30, 23, 1, 8, 0); - CopyBgTilemapBufferToVram(1); - CopyBgTilemapBufferToVram(3); - break; - case 4: - sub_801CDCC(); - break; - case 5: - sub_801CE7C(); - CopyBgTilemapBufferToVram(0); - CopyBgTilemapBufferToVram(2); - break; - case 6: - ShowBg(1); - ShowBg(2); - ShowBg(3); - gPaletteFade.bufferTransferDisabled = FALSE; - sWonderNewsData->unk_01C1 = AddScrollIndicatorArrowPair(&sWonderNewsData->unk_0394, &sWonderNewsData->unk_01C6); - BeginNormalPaletteFade(PALETTES_ALL, 0, 16, 0, RGB_BLACK); - UpdatePaletteFade(); - break; - default: - if (UpdatePaletteFade()) - return 0; - sWonderNewsData->unk_01C0_1 = 0; - return 1; - } - - ++sWonderNewsData->unk_01C0_1; - return 0; -} - -s32 FadeOutFromWonderNews(bool32 flag) -{ - if (sWonderNewsData == NULL) - return -1; - switch (sWonderNewsData->unk_01C0_1) - { - case 0: - BeginNormalPaletteFade(PALETTES_ALL, 0, 0, 16, RGB_BLACK); - break; - case 1: - if (UpdatePaletteFade()) - return 0; - ChangeBgY(2, 0, 0); - SetGpuReg(REG_OFFSET_WIN0H, 0); - SetGpuReg(REG_OFFSET_WIN0V, 0); - SetGpuReg(REG_OFFSET_WININ, 0); - SetGpuReg(REG_OFFSET_WINOUT, 0); - ClearGpuRegBits(REG_OFFSET_DISPCNT, DISPCNT_WIN0_ON); - break; - case 2: - FillBgTilemapBufferRect_Palette0(0, 0x000, 0, 0, 30, 20); - FillBgTilemapBufferRect_Palette0(1, 0x000, 0, 0, 30, 20); - FillBgTilemapBufferRect_Palette0(2, 0x000, 0, 0, 30, 24); - FillBgTilemapBufferRect_Palette0(3, 0x000, 0, 0, 30, 24); - CopyBgTilemapBufferToVram(0); - CopyBgTilemapBufferToVram(1); - CopyBgTilemapBufferToVram(2); - CopyBgTilemapBufferToVram(3); - break; - case 3: - HideBg(1); - HideBg(2); - RemoveWindow(sWonderNewsData->unk_01C8[1]); - RemoveWindow(sWonderNewsData->unk_01C8[0]); - break; - case 4: - ChangeBgY(2, 0, 0); - ChangeBgY(3, 0, 0); - if (sWonderNewsData->unk_01C1 != 0xFF) - { - RemoveScrollIndicatorArrowPair(sWonderNewsData->unk_01C1); - sWonderNewsData->unk_01C1 = 0xFF; - } - break; - case 5: - PrintMysteryGiftOrEReaderTopMenu(gGiftIsFromEReader, flag); - MG_DrawCheckerboardPattern(3); - CopyBgTilemapBufferToVram(0); - CopyBgTilemapBufferToVram(3); - BeginNormalPaletteFade(PALETTES_ALL, 0, 16, 0, RGB_BLACK); - break; - default: - if (UpdatePaletteFade()) - return 0; - sWonderNewsData->unk_01C0_1 = 0; - return 1; - } - ++sWonderNewsData->unk_01C0_1; - return 0; -} - -void MENews_RemoveScrollIndicatorArrowPair(void) -{ - if (!sWonderNewsData->unk_01C0_0 && sWonderNewsData->unk_01C1 != 0xFF) - { - RemoveScrollIndicatorArrowPair(sWonderNewsData->unk_01C1); - sWonderNewsData->unk_01C1 = 0xFF; - sWonderNewsData->unk_01C0_0 = TRUE; - } -} - - -void MENews_AddScrollIndicatorArrowPair(void) -{ - if (sWonderNewsData->unk_01C0_0) - { - sWonderNewsData->unk_01C1 = AddScrollIndicatorArrowPair(&sWonderNewsData->unk_0394, &sWonderNewsData->unk_01C6); - sWonderNewsData->unk_01C0_0 = FALSE; - } -} - -u32 MENews_GetInput(u16 input) -{ - if (sWonderNewsData->unk_01C2_0) - { - sub_801CFA4(); - return 0xFF; - } - switch (input) - { - case A_BUTTON: - return 0; - case B_BUTTON: - return 1; - case DPAD_UP: - if (sWonderNewsData->unk_01C6 == 0) - return 0xFF; - if (sWonderNewsData->unk_01C0_0) - return 0xFF; - sWonderNewsData->unk_01C3_0 = FALSE; - break; - case DPAD_DOWN: - if (sWonderNewsData->unk_01C6 == sWonderNewsData->unk_01C4) - return 0xFF; - if (sWonderNewsData->unk_01C0_0) - return 0xFF; - sWonderNewsData->unk_01C3_0 = TRUE; - break; - default: - return 0xFF; - } - sWonderNewsData->unk_01C2_0 = TRUE; - sWonderNewsData->unk_01C2_1 = 2; - sWonderNewsData->unk_01C3_1 = 0; - if (sWonderNewsData->unk_01C3_0 == FALSE) - return 2; - else - return 3; -} - -void sub_801CDCC(void) -{ - u8 i = 0; - memcpy(sWonderNewsData->unk_01CE, sWonderNewsData->unk_0000.unk_04, 40); - sWonderNewsData->unk_01CE[40] = EOS; - for (; i < 10; ++i) - { - memcpy(sWonderNewsData->unk_01F7[i], sWonderNewsData->unk_0000.unk_2C[i], 40); - sWonderNewsData->unk_01F7[i][40] = EOS; - if (i > 7 && sWonderNewsData->unk_01F7[i][0] != EOS) - ++sWonderNewsData->unk_01C4; - } - sWonderNewsData->unk_0394 = gUnknown_082F1DF8; - sWonderNewsData->unk_0394.fullyDownThreshold = sWonderNewsData->unk_01C4; -} - -void sub_801CE7C(void) -{ - u8 i = 0; - s32 x; - PutWindowTilemap(sWonderNewsData->unk_01C8[0]); - PutWindowTilemap(sWonderNewsData->unk_01C8[1]); - FillWindowPixelBuffer(sWonderNewsData->unk_01C8[0], 0); - FillWindowPixelBuffer(sWonderNewsData->unk_01C8[1], 0); - x = (0xe0 - GetStringWidth(3, sWonderNewsData->unk_01CE, GetFontAttribute(3, 2))) / 2; - if (x < 0) - x = 0; - AddTextPrinterParameterized3(sWonderNewsData->unk_01C8[0], 3, x, 6, gUnknown_082F1DE0[sWonderNewsData->unk_01BC->textPal1], 0, sWonderNewsData->unk_01CE); - for (; i < 10; ++i) - { - AddTextPrinterParameterized3(sWonderNewsData->unk_01C8[1], 3, 0, 16 * i + 2, gUnknown_082F1DE0[sWonderNewsData->unk_01BC->textPal2], 0, sWonderNewsData->unk_01F7[i]); - } - CopyWindowToVram(sWonderNewsData->unk_01C8[0], 3); - CopyWindowToVram(sWonderNewsData->unk_01C8[1], 3); -} - -void sub_801CFA4(void) -{ - u16 r4 = sWonderNewsData->unk_01C2_1; - r4 <<= 8; - if (sWonderNewsData->unk_01C3_0) - { - ChangeBgY(2, r4, 1); - ChangeBgY(3, r4, 1); - } - else - { - ChangeBgY(2, r4, 2); - ChangeBgY(3, r4, 2); - } - sWonderNewsData->unk_01C3_1 += sWonderNewsData->unk_01C2_1; - if (sWonderNewsData->unk_01C3_1 > 15) - { - if (sWonderNewsData->unk_01C3_0) - ++sWonderNewsData->unk_01C6; - else - --sWonderNewsData->unk_01C6; - sWonderNewsData->unk_01C2_0 = FALSE; - sWonderNewsData->unk_01C3_1 = 0; - } -} diff --git a/src/mystery_gift.c b/src/mystery_gift.c index 6ae6a9534..4ff4aebf0 100644 --- a/src/mystery_gift.c +++ b/src/mystery_gift.c @@ -22,7 +22,7 @@ #include "list_menu.h" #include "string_util.h" #include "mevent.h" -#include "mevent_801BAAC.h" +#include "wonder_transfer.h" #include "save.h" #include "link.h" #include "mevent_client.h" @@ -119,9 +119,8 @@ static const struct WindowTemplate sMainWindows[] = { .height = 0x05, .paletteNum = 0x0d, .baseBlock = 0x004f - }, { - 0xFF - } + }, + DUMMY_WIN_TEMPLATE }; static const struct WindowTemplate sWindowTemplate_PromptYesOrNo_Width28 = { @@ -730,24 +729,16 @@ static s32 HandleMysteryGiftListMenu(u8 * textState, u16 * windowId, bool32 cann 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) { @@ -774,13 +765,9 @@ static s32 HandleMysteryGiftListMenu(u8 * textState, u16 * windowId, bool32 cann static bool32 ValidateCardOrNews(bool32 cardOrNews) { if (cardOrNews == 0) - { return ValidateReceivedWonderCard(); - } else - { return ValidateReceivedWonderNews(); - } } static bool32 HandleLoadWonderCardOrNews(u8 * state, bool32 cardOrNews) @@ -789,29 +776,21 @@ static bool32 HandleLoadWonderCardOrNews(u8 * state, bool32 cardOrNews) { case 0: if (cardOrNews == 0) - { - InitWonderCardResources(GetSavedWonderCard(), sav1_get_mevent_buffer_2()); - } + WonderCard_Init(GetSavedWonderCard(), sav1_get_mevent_buffer_2()); else - { - InitWonderNewsResources(GetSavedWonderNews()); - } + WonderNews_Init(GetSavedWonderNews()); (*state)++; break; case 1: if (cardOrNews == 0) { - if (!FadeToWonderCardMenu()) - { + if (!WonderCard_Enter()) return FALSE; - } } else { - if (!FadeToWonderNewsMenu()) - { + if (!WonderNews_Enter()) return FALSE; - } } *state = 0; return TRUE; @@ -823,13 +802,9 @@ static bool32 HandleLoadWonderCardOrNews(u8 * state, bool32 cardOrNews) static bool32 DestroyNewsOrCard(bool32 cardOrNews) { if (cardOrNews == 0) - { DestroyWonderCard(); - } else - { DestroyWonderNews(); - } return TRUE; } @@ -837,9 +812,9 @@ static bool32 TearDownCardOrNews_ReturnToTopMenu(bool32 cardOrNews, bool32 arg1) { if (cardOrNews == 0) { - if (FadeOutFromWonderCard(arg1) != 0) + if (WonderCard_Exit(arg1) != 0) { - DestroyWonderCardResources(); + WonderCard_Destroy(); return TRUE; } else @@ -849,9 +824,9 @@ static bool32 TearDownCardOrNews_ReturnToTopMenu(bool32 cardOrNews, bool32 arg1) } else { - if (FadeOutFromWonderNews(arg1) != 0) + if (WonderNews_Exit(arg1) != 0) { - DestroyWonderNewsResources(); + WonderNews_Destroy(); return TRUE; } else @@ -864,25 +839,17 @@ static bool32 TearDownCardOrNews_ReturnToTopMenu(bool32 cardOrNews, bool32 arg1) static s32 mevent_message_prompt_discard(u8 * textState, u16 * windowId, bool32 cardOrNews) { if (cardOrNews == 0) - { return mevent_message_print_and_prompt_yes_no(textState, windowId, TRUE, gText_IfThrowAwayCardEventWontHappen); - } else - { return mevent_message_print_and_prompt_yes_no(textState, windowId, TRUE, gText_OkayToDiscardNews); - } } static bool32 mevent_message_was_thrown_away(u8 * textState, bool32 cardOrNews) { if (cardOrNews == 0) - { return MG_PrintTextOnWindow1AndWaitButton(textState, gText_WonderCardThrownAway); - } else - { return MG_PrintTextOnWindow1AndWaitButton(textState, gText_WonderNewsThrownAway); - } } static bool32 mevent_save_game(u8 * state) @@ -992,18 +959,14 @@ static bool32 PrintMGSuccessMessage(u8 * state, const u8 * arg1, u16 * arg2) { case 0: if (arg1 != NULL) - { AddTextPrinterToWindow1(arg1); - } PlayFanfare(MUS_OBTAIN_ITEM); *arg2 = 0; (*state)++; break; case 1: - if (++(*arg2) > 0xF0) - { + if (++(*arg2) > 240) (*state)++; - } break; case 2: if (IsFanfareTaskInactive()) @@ -1079,13 +1042,9 @@ static bool32 PrintMGSendStatus(u8 * state, u16 * arg1, u8 arg2, u32 msgId) u32 flag; const u8 * str = mevent_message_stamp_card_etc_send_status(&flag, arg2, msgId); if (flag) - { return PrintMGSuccessMessage(state, str, arg1); - } else - { return MG_PrintTextOnWindow1AndWaitButton(state, str); - } } void task_add_00_mystery_gift(void) @@ -1123,24 +1082,16 @@ void task00_mystery_gift(u8 taskId) case 0: data->IsCardOrNews = 0; if (ValidateReceivedWonderCard() == TRUE) - { data->state = 18; - } else - { data->state = 2; - } break; case 1: data->IsCardOrNews = 1; if (ValidateReceivedWonderNews() == TRUE) - { data->state = 18; - } else - { data->state = 2; - } break; case -2u: data->state = 37; @@ -1169,13 +1120,9 @@ void task00_mystery_gift(u8 taskId) } case 3: if (data->IsCardOrNews == 0) - { AddTextPrinterToWindow1(gText_WhereShouldCardBeAccessed); - } else - { AddTextPrinterToWindow1(gText_WhereShouldNewsBeAccessed); - } data->state = 4; break; case 4: @@ -1214,23 +1161,15 @@ void task00_mystery_gift(u8 taskId) { case 0: if (data->source == 1) - { MEvent_CreateTask_CardOrNewsWithFriend(ACTIVITY_WONDER_CARD); - } else if (data->source == 0) - { MEvent_CreateTask_CardOrNewsOverWireless(ACTIVITY_WONDER_CARD); - } break; case 1: if (data->source == 1) - { MEvent_CreateTask_CardOrNewsWithFriend(ACTIVITY_WONDER_NEWS); - } else if (data->source == 0) - { MEvent_CreateTask_CardOrNewsOverWireless(ACTIVITY_WONDER_NEWS); - } break; } data->state = 6; @@ -1364,38 +1303,26 @@ void task00_mystery_gift(u8 taskId) if (PrintStringAndWait2Seconds(&data->textState, gText_CommunicationCompleted)) { if (data->source == 1) - { StringCopy(gStringVar1, gLinkPlayers[0].name); - } data->state = 15; } break; case 15: r1 = mevent_message(&sp0, data->IsCardOrNews, data->source, data->prevPromptWindowId); if (r1 == NULL) - { r1 = data->buffer; - } if (sp0) - { flag = PrintMGSuccessMessage(&data->textState, r1, &data->curPromptWindowId); - } else - { flag = MG_PrintTextOnWindow1AndWaitButton(&data->textState, r1); - } if (flag) { if (data->prevPromptWindowId == 3) { if (data->source == 1) - { GenerateRandomNews(1); - } else - { GenerateRandomNews(2); - } } if (!sp0) { @@ -1417,37 +1344,29 @@ void task00_mystery_gift(u8 taskId) break; case 17: if (mevent_save_game(&data->textState)) - { data->state = 18; - } break; case 18: if (HandleLoadWonderCardOrNews(&data->textState, data->IsCardOrNews)) - { data->state = 20; - } break; case 20: if (data->IsCardOrNews == 0) { - if (({JOY_NEW(A_BUTTON);})) - { + if (JOY_NEW(A_BUTTON)) data->state = 21; - } - if (({JOY_NEW(B_BUTTON);})) - { + if (JOY_NEW(B_BUTTON)) data->state = 27; - } } else { - switch (MENews_GetInput(gMain.newKeys)) + switch (WonderNews_GetInput(gMain.newKeys)) { - case 0: - MENews_RemoveScrollIndicatorArrowPair(); + case NEWS_INPUT_A: + WonderNews_RemoveScrollIndicatorArrowPair(); data->state = 21; break; - case 1: + case NEWS_INPUT_B: data->state = 27; break; } @@ -1459,24 +1378,16 @@ void task00_mystery_gift(u8 taskId) if (data->IsCardOrNews == 0) { if (WonderCard_Test_Unk_08_6()) - { result = HandleMysteryGiftListMenu(&data->textState, &data->curPromptWindowId, data->IsCardOrNews, FALSE); - } else - { result = HandleMysteryGiftListMenu(&data->textState, &data->curPromptWindowId, data->IsCardOrNews, TRUE); - } } else { if (WonderNews_Test_Unk_02()) - { result = HandleMysteryGiftListMenu(&data->textState, &data->curPromptWindowId, data->IsCardOrNews, FALSE); - } else - { result = HandleMysteryGiftListMenu(&data->textState, &data->curPromptWindowId, data->IsCardOrNews, TRUE); - } } switch (result) { @@ -1491,9 +1402,7 @@ void task00_mystery_gift(u8 taskId) break; case -2u: if (data->IsCardOrNews == 1) - { - MENews_AddScrollIndicatorArrowPair(); - } + WonderNews_AddScrollIndicatorArrowPair(); data->state = 20; break; } @@ -1504,13 +1413,9 @@ void task00_mystery_gift(u8 taskId) { case 0: if (data->IsCardOrNews == 0 && CheckReceivedGiftFromWonderCard() == TRUE) - { data->state = 23; - } else - { data->state = 24; - } break; case 1: data->state = 21; @@ -1543,9 +1448,7 @@ void task00_mystery_gift(u8 taskId) break; case 25: if (mevent_save_game(&data->textState)) - { data->state = 26; - } break; case 26: if (mevent_message_was_thrown_away(&data->textState, data->IsCardOrNews)) @@ -1556,15 +1459,11 @@ void task00_mystery_gift(u8 taskId) break; case 27: if (TearDownCardOrNews_ReturnToTopMenu(data->IsCardOrNews, 0)) - { data->state = 0; - } break; case 28: if (TearDownCardOrNews_ReturnToTopMenu(data->IsCardOrNews, 1)) - { data->state = 3; - } break; case 29: if (TearDownCardOrNews_ReturnToTopMenu(data->IsCardOrNews, 1)) diff --git a/src/wonder_transfer.c b/src/wonder_transfer.c new file mode 100644 index 000000000..1928ba12e --- /dev/null +++ b/src/wonder_transfer.c @@ -0,0 +1,870 @@ +#include "global.h" +#include "bg.h" +#include "gpu_regs.h" +#include "palette.h" +#include "decompress.h" +#include "malloc.h" +#include "menu.h" +#include "pokemon_icon.h" +#include "union_room.h" +#include "list_menu.h" +#include "text_window.h" +#include "string_util.h" +#include "link_rfu.h" +#include "mevent.h" +#include "mystery_gift.h" +#include "wonder_transfer.h" +#include "constants/rgb.h" +#include "constants/mevent.h" + +struct WonderGraphics +{ + u8 textPal1:4; + u8 textPal2:4; + u8 textPal3:4; + u8 textPal4:4; + const u32 * tiles; + const u32 * map; + const u16 * pal; +}; + +//====================== +// Wonder Cards +//====================== + +enum { + CARD_WIN_0, + CARD_WIN_1, + CARD_WIN_2, + CARD_WIN_COUNT +}; + +#define TAG_ICON_SHADOW 0x8000 + +struct UnkStruct_203F3C8_02DC +{ + u8 unk_00; + u8 unk_01[WONDER_CARD_TEXT_LENGTH + 1]; + u8 unk_42[4]; +}; + +struct WonderCardData +{ + /*0000*/ struct WonderCard card; + /*014c*/ struct MEventBuffer_3430_Sub unk_014C; + /*0170*/ const struct WonderGraphics * gfx; + /*0174*/ u8 enterExitState; + /*0175*/ u8 unk_0175; + /*0176*/ u16 windowIds[CARD_WIN_COUNT]; + /*017C*/ u8 monIconSpriteId; + /*017D*/ u8 unk_017D[7][2]; + /*018B*/ u8 unk_018B[WONDER_CARD_TEXT_LENGTH + 1]; + /*01B4*/ u8 unk_01B4[WONDER_CARD_TEXT_LENGTH + 1]; + /*01DD*/ u8 unk_01DD[7]; + /*01E4*/ u8 unk_01E4[4][WONDER_CARD_TEXT_LENGTH + 1]; + /*0288*/ u8 unk_0288[WONDER_CARD_TEXT_LENGTH + 1]; + /*02B1*/ u8 unk_02B1[WONDER_CARD_TEXT_LENGTH + 1]; + /*02DC*/ struct UnkStruct_203F3C8_02DC unk_02DC[8]; + /*045C*/ u8 buffer_045C[0x1000]; +}; + +EWRAM_DATA static struct WonderCardData * sWonderCardData = NULL; + +static void BufferCardText(void); +static void DrawCardWindow(u8 whichWindow); +static void CreateCardSprites(void); +static void DestroyCardSprites(void); + +extern const struct OamData gOamData_AffineOff_ObjNormal_32x16; + +static const u8 sCard_TextColorTable[][3] = { + {TEXT_COLOR_TRANSPARENT, TEXT_COLOR_DARK_GRAY, TEXT_COLOR_LIGHT_GRAY}, + {TEXT_COLOR_TRANSPARENT, TEXT_COLOR_WHITE, TEXT_COLOR_DARK_GRAY} +}; +const u8 ALIGNED(4) sCard_TextYOffsets[3] = {7, 4, 7}; +static const struct WindowTemplate sCard_WindowTemplates[] = { + [CARD_WIN_0] = { + .bg = 1, + .tilemapLeft = 1, + .tilemapTop = 1, + .width = 25, + .height = 4, + .paletteNum = 2, + .baseBlock = 0x029c + }, + [CARD_WIN_1] = { + .bg = 1, + .tilemapLeft = 1, + .tilemapTop = 6, + .width = 28, + .height = 8, + .paletteNum = 2, + .baseBlock = 0x01bc + }, + [CARD_WIN_2] = { + .bg = 1, + .tilemapLeft = 1, + .tilemapTop = 14, + .width = 28, + .height = 5, + .paletteNum = 2, + .baseBlock = 0x0130 + } +}; + +static const u16 sWonderCardBgPal1[] = INCBIN_U16("graphics/wonder_card/bg1.gbapal"); +static const u16 sWonderCardBgPal2[] = INCBIN_U16("graphics/wonder_card/bg2.gbapal"); +static const u16 sWonderCardBgPal3[] = INCBIN_U16("graphics/wonder_card/bg3.gbapal"); +static const u16 sWonderCardBgPal4[] = INCBIN_U16("graphics/wonder_card/bg4.gbapal"); +static const u16 sWonderCardBgPal5[] = INCBIN_U16("graphics/wonder_card/bg5.gbapal"); +static const u16 sWonderCardBgPal6[] = INCBIN_U16("graphics/wonder_card/bg6.gbapal"); +static const u16 sWonderCardBgPal7[] = INCBIN_U16("graphics/wonder_card/bg7.gbapal"); +static const u16 sWonderCardBgPal8[] = INCBIN_U16("graphics/wonder_card/bg8.gbapal"); +static const u32 sWonderCardBgGfx1[] = INCBIN_U32("graphics/wonder_card/bg1.4bpp.lz"); +static const u32 sWonderCardBgTilemap1[] = INCBIN_U32("graphics/wonder_card/bg1.bin.lz"); +static const u32 sWonderCardBgGfx2[] = INCBIN_U32("graphics/wonder_card/bg2.4bpp.lz"); +static const u32 sWonderCardBgTilemap2[] = INCBIN_U32("graphics/wonder_card/bg2.bin.lz"); +static const u32 sWonderCardBgGfx3[] = INCBIN_U32("graphics/wonder_card/bg3.4bpp.lz"); +static const u32 sWonderCardBgTilemap3[] = INCBIN_U32("graphics/wonder_card/bg3.bin.lz"); +static const u32 sWonderCardBgGfx7[] = INCBIN_U32("graphics/wonder_card/bg7.4bpp.lz"); +static const u32 sWonderCardBgTilemap7[] = INCBIN_U32("graphics/wonder_card/bg7.bin.lz"); +static const u32 sWonderCardBgGfx8[] = INCBIN_U32("graphics/wonder_card/bg8.4bpp.lz"); +static const u32 sWonderCardBgTilemap8[] = INCBIN_U32("graphics/wonder_card/bg8.bin.lz"); +static const u16 sIconShadowPal1[] = INCBIN_U16("graphics/wonder_card/icon_shadow_1.gbapal"); +static const u16 sIconShadowPal2[] = INCBIN_U16("graphics/wonder_card/icon_shadow_2.gbapal"); +static const u16 sIconShadowPal3[] = INCBIN_U16("graphics/wonder_card/icon_shadow_3.gbapal"); +static const u16 sIconShadowPal4[] = INCBIN_U16("graphics/wonder_card/icon_shadow_4.gbapal"); +static const u16 sIconShadowPal5[] = INCBIN_U16("graphics/wonder_card/icon_shadow_5.gbapal"); +static const u16 sIconShadowPal6[] = INCBIN_U16("graphics/wonder_card/icon_shadow_6.gbapal"); +static const u16 sIconShadowPal7[] = INCBIN_U16("graphics/wonder_card/icon_shadow_7.gbapal"); +static const u16 sIconShadowPal8[] = INCBIN_U16("graphics/wonder_card/icon_shadow_8.gbapal"); +static const u32 sIconShadowGfx[] = INCBIN_U32("graphics/wonder_card/icon_shadow.4bpp.lz"); + +static const struct CompressedSpriteSheet sSpriteSheet_IconShadow = { + sIconShadowGfx, 0x100, TAG_ICON_SHADOW +}; + +static const struct SpritePalette sSpritePalettes_IconShadow[] = { + {sIconShadowPal1, TAG_ICON_SHADOW}, + {sIconShadowPal2, TAG_ICON_SHADOW}, + {sIconShadowPal3, TAG_ICON_SHADOW}, + {sIconShadowPal4, TAG_ICON_SHADOW}, + {sIconShadowPal5, TAG_ICON_SHADOW}, + {sIconShadowPal6, TAG_ICON_SHADOW}, + {sIconShadowPal7, TAG_ICON_SHADOW}, + {sIconShadowPal8, TAG_ICON_SHADOW} +}; + +static const struct SpriteTemplate sSpriteTemplate_IconShadow = { + .tileTag = TAG_ICON_SHADOW, + .paletteTag = TAG_ICON_SHADOW, + .oam = &gOamData_AffineOff_ObjNormal_32x16, + .anims = gDummySpriteAnimTable, + .images = NULL, + .affineAnims = gDummySpriteAffineAnimTable, + .callback = SpriteCallbackDummy +}; + +static const struct WonderGraphics sCardGraphics[NUM_WONDER_BGS] = { + {.textPal1 = 1, .textPal2 = 0, .textPal3 = 0, .textPal4 = 0, .tiles = sWonderCardBgGfx1, .map = sWonderCardBgTilemap1, .pal = sWonderCardBgPal1}, + {.textPal1 = 1, .textPal2 = 0, .textPal3 = 0, .textPal4 = 1, .tiles = sWonderCardBgGfx2, .map = sWonderCardBgTilemap2, .pal = sWonderCardBgPal2}, + {.textPal1 = 1, .textPal2 = 0, .textPal3 = 0, .textPal4 = 2, .tiles = sWonderCardBgGfx3, .map = sWonderCardBgTilemap3, .pal = sWonderCardBgPal3}, + {.textPal1 = 1, .textPal2 = 0, .textPal3 = 0, .textPal4 = 3, .tiles = sWonderCardBgGfx3, .map = sWonderCardBgTilemap3, .pal = sWonderCardBgPal4}, + {.textPal1 = 1, .textPal2 = 0, .textPal3 = 0, .textPal4 = 4, .tiles = sWonderCardBgGfx3, .map = sWonderCardBgTilemap3, .pal = sWonderCardBgPal5}, + {.textPal1 = 1, .textPal2 = 0, .textPal3 = 0, .textPal4 = 5, .tiles = sWonderCardBgGfx3, .map = sWonderCardBgTilemap3, .pal = sWonderCardBgPal6}, + {.textPal1 = 1, .textPal2 = 0, .textPal3 = 0, .textPal4 = 6, .tiles = sWonderCardBgGfx7, .map = sWonderCardBgTilemap7, .pal = sWonderCardBgPal7}, + {.textPal1 = 1, .textPal2 = 0, .textPal3 = 0, .textPal4 = 7, .tiles = sWonderCardBgGfx8, .map = sWonderCardBgTilemap8, .pal = sWonderCardBgPal8} +}; + +bool32 WonderCard_Init(struct WonderCard * card, struct MEventBuffer_3430_Sub * r6) +{ + if (card == NULL || r6 == NULL) + return FALSE; + sWonderCardData = AllocZeroed(sizeof(*sWonderCardData)); + if (sWonderCardData == NULL) + return FALSE; + sWonderCardData->card = *card; + sWonderCardData->unk_014C = *r6; + if (sWonderCardData->card.bgType >= ARRAY_COUNT(sCardGraphics)) + sWonderCardData->card.bgType = 0; + if (sWonderCardData->card.unk_08_0 >= ARRAY_COUNT(sCard_TextYOffsets)) + sWonderCardData->card.unk_08_0 = 0; + if (sWonderCardData->card.unk_09 > ARRAY_COUNT(sWonderCardData->unk_017D)) + sWonderCardData->card.unk_09 = 0; + sWonderCardData->gfx = &sCardGraphics[sWonderCardData->card.bgType]; + return TRUE; +} + +void WonderCard_Destroy(void) +{ + if (sWonderCardData != NULL) + { + *sWonderCardData = (struct WonderCardData){}; + Free(sWonderCardData); + sWonderCardData = NULL; + } +} + +s32 WonderCard_Enter(void) +{ + if (sWonderCardData == NULL) + return -1; + switch(sWonderCardData->enterExitState) + { + case 0: + BeginNormalPaletteFade(PALETTES_ALL, 0, 0, 16, RGB_BLACK); + break; + case 1: + if (UpdatePaletteFade()) + return 0; + break; + case 2: + FillBgTilemapBufferRect_Palette0(0, 0x000, 0, 0, 30, 20); + FillBgTilemapBufferRect_Palette0(1, 0x000, 0, 0, 30, 20); + FillBgTilemapBufferRect_Palette0(2, 0x000, 0, 0, 30, 20); + CopyBgTilemapBufferToVram(0); + CopyBgTilemapBufferToVram(1); + CopyBgTilemapBufferToVram(2); + DecompressAndCopyTileDataToVram(2, sWonderCardData->gfx->tiles, 0, 0x008, 0); + sWonderCardData->windowIds[CARD_WIN_0] = AddWindow(&sCard_WindowTemplates[CARD_WIN_0]); + sWonderCardData->windowIds[CARD_WIN_1] = AddWindow(&sCard_WindowTemplates[CARD_WIN_1]); + sWonderCardData->windowIds[CARD_WIN_2] = AddWindow(&sCard_WindowTemplates[CARD_WIN_2]); + break; + case 3: + if (FreeTempTileDataBuffersIfPossible()) + return 0; + LoadPalette(GetTextWindowPalette(1), 0x20, 0x20); + gPaletteFade.bufferTransferDisabled = TRUE; + LoadPalette(sWonderCardData->gfx->pal, 0x10, 0x20); + LZ77UnCompWram(sWonderCardData->gfx->map, sWonderCardData->buffer_045C); + CopyRectToBgTilemapBufferRect(2, sWonderCardData->buffer_045C, 0, 0, 30, 20, 0, 0, 30, 20, 1, 0x008, 0); + CopyBgTilemapBufferToVram(2); + break; + case 4: + BufferCardText(); + break; + case 5: + DrawCardWindow(CARD_WIN_0); + DrawCardWindow(CARD_WIN_1); + DrawCardWindow(CARD_WIN_2); + CopyBgTilemapBufferToVram(1); + break; + case 6: + LoadMonIconPalettes(); + break; + case 7: + ShowBg(1); + ShowBg(2); + gPaletteFade.bufferTransferDisabled = FALSE; + CreateCardSprites(); + BeginNormalPaletteFade(PALETTES_ALL, 0, 16, 0, RGB_BLACK); + UpdatePaletteFade(); + break; + default: + if (UpdatePaletteFade()) + return 0; + sWonderCardData->enterExitState = 0; + return 1; + } + ++sWonderCardData->enterExitState; + return 0; +} + +s32 WonderCard_Exit(bool32 flag) +{ + if (sWonderCardData == NULL) + return -1; + switch (sWonderCardData->enterExitState) + { + case 0: + BeginNormalPaletteFade(PALETTES_ALL, 0, 0, 16, RGB_BLACK); + break; + case 1: + if (UpdatePaletteFade()) + return 0; + break; + case 2: + FillBgTilemapBufferRect_Palette0(0, 0x000, 0, 0, 30, 20); + FillBgTilemapBufferRect_Palette0(1, 0x000, 0, 0, 30, 20); + FillBgTilemapBufferRect_Palette0(2, 0x000, 0, 0, 30, 20); + CopyBgTilemapBufferToVram(0); + CopyBgTilemapBufferToVram(1); + CopyBgTilemapBufferToVram(2); + break; + case 3: + HideBg(1); + HideBg(2); + RemoveWindow(sWonderCardData->windowIds[CARD_WIN_2]); + RemoveWindow(sWonderCardData->windowIds[CARD_WIN_1]); + RemoveWindow(sWonderCardData->windowIds[CARD_WIN_0]); + break; + case 4: + DestroyCardSprites(); + FreeMonIconPalettes(); + break; + case 5: + PrintMysteryGiftOrEReaderTopMenu(gGiftIsFromEReader, flag); + CopyBgTilemapBufferToVram(0); + BeginNormalPaletteFade(PALETTES_ALL, 0, 16, 0, RGB_BLACK); + break; + default: + if (UpdatePaletteFade()) + return 0; + sWonderCardData->enterExitState = 0; + return 1; + } + ++sWonderCardData->enterExitState; + return 0; +} + +static void BufferCardText(void) +{ + u16 i = 0; + u16 r6; + u16 sp0[3] = {0, 0, 0}; + + memcpy(sWonderCardData->unk_018B, sWonderCardData->card.unk_0A, WONDER_CARD_TEXT_LENGTH); + sWonderCardData->unk_018B[WONDER_CARD_TEXT_LENGTH] = EOS; + memcpy(sWonderCardData->unk_01B4, sWonderCardData->card.unk_32, WONDER_CARD_TEXT_LENGTH); + sWonderCardData->unk_01B4[WONDER_CARD_TEXT_LENGTH] = EOS; + if (sWonderCardData->card.unk_04 > 999999) + sWonderCardData->card.unk_04 = 999999; + ConvertIntToDecimalStringN(sWonderCardData->unk_01DD, sWonderCardData->card.unk_04, STR_CONV_MODE_LEFT_ALIGN, 6); + for (i = 0; i < 4; i++) + { + memcpy(sWonderCardData->unk_01E4[i], sWonderCardData->card.unk_5A[i], WONDER_CARD_TEXT_LENGTH); + sWonderCardData->unk_01E4[i][WONDER_CARD_TEXT_LENGTH] = EOS; + } + memcpy(sWonderCardData->unk_0288, sWonderCardData->card.unk_FA, WONDER_CARD_TEXT_LENGTH); + sWonderCardData->unk_0288[WONDER_CARD_TEXT_LENGTH] = EOS; + switch (sWonderCardData->card.unk_08_0) + { + case 0: + memcpy(sWonderCardData->unk_02B1, sWonderCardData->card.unk_122, WONDER_CARD_TEXT_LENGTH); + sWonderCardData->unk_02B1[WONDER_CARD_TEXT_LENGTH] = EOS; + break; + case 1: + sWonderCardData->unk_02B1[0] = EOS; + break; + case 2: + sWonderCardData->unk_02B1[0] = EOS; + sp0[0] = sWonderCardData->unk_014C.unk_00 < 999 ? sWonderCardData->unk_014C.unk_00 : 999; + sp0[1] = sWonderCardData->unk_014C.unk_02 < 999 ? sWonderCardData->unk_014C.unk_02 : 999; + sp0[2] = sWonderCardData->unk_014C.unk_04 < 999 ? sWonderCardData->unk_014C.unk_04 : 999; + for (i = 0; i < 8; i++) + { + memset(sWonderCardData->unk_02DC[i].unk_42, EOS, sizeof(sWonderCardData->unk_02DC[i].unk_42)); + memset(sWonderCardData->unk_02DC[i].unk_01, EOS, sizeof(sWonderCardData->unk_02DC[i].unk_01)); + } + for (i = 0, r6 = 0; i < WONDER_CARD_TEXT_LENGTH; i++) + { + if (sWonderCardData->card.unk_122[i] != CHAR_DYNAMIC) + { + sWonderCardData->unk_02DC[sWonderCardData->unk_0175].unk_01[r6] = sWonderCardData->card.unk_122[i]; + r6++; + } + else + { + u8 r3 = sWonderCardData->card.unk_122[i + 1]; + if (r3 > 2) + { + i += 2; + } + else + { + ConvertIntToDecimalStringN(sWonderCardData->unk_02DC[sWonderCardData->unk_0175].unk_42, sp0[r3], STR_CONV_MODE_LEADING_ZEROS, 3); + sWonderCardData->unk_02DC[sWonderCardData->unk_0175].unk_00 = sWonderCardData->card.unk_122[i + 2]; + sWonderCardData->unk_0175++; + if (sWonderCardData->unk_0175 > 7) + break; + r6 = 0; + i += 2; + } + } + } + } +} + +static void DrawCardWindow(u8 whichWindow) +{ + s8 sp0C = 0; + s32 windowId = sWonderCardData->windowIds[whichWindow]; + PutWindowTilemap(windowId); + FillWindowPixelBuffer(windowId, 0); + switch (whichWindow) + { + case CARD_WIN_0: + { + s32 x; + AddTextPrinterParameterized3(windowId, 3, 0, 1, sCard_TextColorTable[sWonderCardData->gfx->textPal1], 0, sWonderCardData->unk_018B); + x = 160 - GetStringWidth(3, sWonderCardData->unk_01B4, GetFontAttribute(3, FONTATTR_LETTER_SPACING)); + if (x < 0) + x = 0; + AddTextPrinterParameterized3(windowId, 3, x, 17, sCard_TextColorTable[sWonderCardData->gfx->textPal1], 0, sWonderCardData->unk_01B4); + if (sWonderCardData->card.unk_04 != 0) + AddTextPrinterParameterized3(windowId, 1, 166, 17, sCard_TextColorTable[sWonderCardData->gfx->textPal1], 0, sWonderCardData->unk_01DD); + break; + } + case CARD_WIN_1: + for (; sp0C < 4; sp0C++) + AddTextPrinterParameterized3(windowId, 3, 0, 16 * sp0C + 2, sCard_TextColorTable[sWonderCardData->gfx->textPal2], 0, sWonderCardData->unk_01E4[sp0C]); + break; + case CARD_WIN_2: + AddTextPrinterParameterized3(windowId, 3, 0, sCard_TextYOffsets[sWonderCardData->card.unk_08_0], sCard_TextColorTable[sWonderCardData->gfx->textPal3], 0, sWonderCardData->unk_0288); + if (sWonderCardData->card.unk_08_0 != 2) + { + AddTextPrinterParameterized3(windowId, 3, 0, 16 + sCard_TextYOffsets[sWonderCardData->card.unk_08_0], sCard_TextColorTable[sWonderCardData->gfx->textPal3], 0, sWonderCardData->unk_02B1); + } + else + { + s32 x = 0; + s32 y = sCard_TextYOffsets[sWonderCardData->card.unk_08_0] + 16; + s32 spacing = GetFontAttribute(3, FONTATTR_LETTER_SPACING); + for (; sp0C < sWonderCardData->unk_0175; sp0C++) + { + AddTextPrinterParameterized3(windowId, 3, x, y, sCard_TextColorTable[sWonderCardData->gfx->textPal3], 0, sWonderCardData->unk_02DC[sp0C].unk_01); + if (sWonderCardData->unk_02DC[sp0C].unk_42[0] != EOS) + { + x += GetStringWidth(3, sWonderCardData->unk_02DC[sp0C].unk_01, spacing); + AddTextPrinterParameterized3(windowId, 3, x, y, sCard_TextColorTable[sWonderCardData->gfx->textPal3], 0, sWonderCardData->unk_02DC[sp0C].unk_42); + x += GetStringWidth(3, sWonderCardData->unk_02DC[sp0C].unk_42, spacing) + sWonderCardData->unk_02DC[sp0C].unk_00; + } + } + } + break; + } + CopyWindowToVram(windowId, 3); +} + +static void CreateCardSprites(void) +{ + u8 r7 = 0; + sWonderCardData->monIconSpriteId = SPRITE_NONE; + if (sWonderCardData->unk_014C.unk_06 != SPECIES_NONE) + { + sWonderCardData->monIconSpriteId = CreateMonIconNoPersonality(GetIconSpeciesNoPersonality(sWonderCardData->unk_014C.unk_06), SpriteCallbackDummy, 220, 20, 0, FALSE); + gSprites[sWonderCardData->monIconSpriteId].oam.priority = 2; + } + if (sWonderCardData->card.unk_09 != 0 && sWonderCardData->card.unk_08_0 == 1) + { + LoadCompressedSpriteSheetUsingHeap(&sSpriteSheet_IconShadow); + LoadSpritePalette(&sSpritePalettes_IconShadow[sWonderCardData->gfx->textPal4]); + for (; r7 < sWonderCardData->card.unk_09; r7++) + { + sWonderCardData->unk_017D[r7][0] = SPRITE_NONE; + sWonderCardData->unk_017D[r7][1] = SPRITE_NONE; + sWonderCardData->unk_017D[r7][0] = CreateSprite(&sSpriteTemplate_IconShadow, 216 - 32 * r7, 144, 8); + if (sWonderCardData->unk_014C.unk_08[0][r7] != SPECIES_NONE) + sWonderCardData->unk_017D[r7][1] = CreateMonIconNoPersonality(GetIconSpeciesNoPersonality(sWonderCardData->unk_014C.unk_08[0][r7]), + SpriteCallbackDummy, + 216 - 32 * r7, + 136, 0, 0); + } + } +} + +static void DestroyCardSprites(void) +{ + u8 r6 = 0; + if (sWonderCardData->monIconSpriteId != SPRITE_NONE) + FreeAndDestroyMonIconSprite(&gSprites[sWonderCardData->monIconSpriteId]); + if (sWonderCardData->card.unk_09 != 0 && sWonderCardData->card.unk_08_0 == 1) + { + for (; r6 < sWonderCardData->card.unk_09; r6++) + { + if (sWonderCardData->unk_017D[r6][0] != SPRITE_NONE) + DestroySprite(&gSprites[sWonderCardData->unk_017D[r6][0]]); + if (sWonderCardData->unk_017D[r6][1] != SPRITE_NONE) + FreeAndDestroyMonIconSprite(&gSprites[sWonderCardData->unk_017D[r6][1]]); + } + FreeSpriteTilesByTag(TAG_ICON_SHADOW); + FreeSpritePaletteByTag(TAG_ICON_SHADOW); + } +} + +//====================== +// Wonder News +//====================== + +enum { + NEWS_WIN_0, + NEWS_WIN_1, + NEWS_WIN_COUNT +}; + +#define TAG_ARROWS 0x1000 + +struct WonderNewsData +{ + /*0000*/ struct WonderNews news; + /*01bc*/ const struct WonderGraphics * gfx; + /*01c0*/ u8 arrowsRemoved:1; + u8 enterExitState:7; + /*01c1*/ u8 arrowTaskId; + /*01c2*/ bool8 scrolling:1; + u8 scrollIncrement:7; + /*01c3*/ bool8 scrollingDown:1; + u8 scrollTotal:7; + /*01c4*/ u16 scrollEnd; + /*01c6*/ u16 scrollOffset; + /*01c8*/ u16 windowIds[NEWS_WIN_COUNT]; + /*01cc*/ u8 filler_01CC[2]; + /*01ce*/ u8 unk_01CE[WONDER_NEWS_TEXT_LENGTH + 1]; + /*01f7*/ u8 unk_01F7[10][WONDER_NEWS_TEXT_LENGTH + 1]; + /*0394*/ struct ScrollArrowsTemplate arrowsTemplate; + /*03a4*/ u8 buffer_03A4[0x1000]; +}; + +EWRAM_DATA static struct WonderNewsData * sWonderNewsData = NULL; + +static void BufferNewsText(void); +static void DrawNewsWindows(void); +static void UpdateNewsScroll(void); + +static const u8 sNews_TextColorTable[][3] = { + {TEXT_COLOR_TRANSPARENT, TEXT_COLOR_DARK_GRAY, TEXT_COLOR_LIGHT_GRAY}, + {TEXT_COLOR_TRANSPARENT, TEXT_COLOR_WHITE, TEXT_COLOR_DARK_GRAY} +}; + +static const struct WindowTemplate sNews_WindowTemplates[] = { + [NEWS_WIN_0] = { + .bg = 0, + .tilemapLeft = 1, + .tilemapTop = 0, + .width = 28, + .height = 3, + .paletteNum = 2, + .baseBlock = 0x2AC + }, + [NEWS_WIN_1] = { + .bg = 2, + .tilemapLeft = 1, + .tilemapTop = 3, + .width = 28, + .height = 20, + .paletteNum = 2, + .baseBlock = 0x07C + } +}; + +static const struct ScrollArrowsTemplate sNews_ArrowsTemplate = { + .firstArrowType = SCROLL_ARROW_UP, + .firstX = 232, + .firstY = 24, + .secondArrowType = SCROLL_ARROW_DOWN, + .secondX = 232, + .secondY = 152, + .fullyUpThreshold = 0, + .fullyDownThreshold = 2, + .tileTag = TAG_ARROWS, + .palTag = TAG_ARROWS, + .palNum = 0 +}; + +static const u16 sWonderNewsPal1[] = INCBIN_U16("graphics/wonder_news/bg1.gbapal"); +static const u16 sWonderNewsPal7[] = INCBIN_U16("graphics/wonder_news/bg7.gbapal"); +static const u16 sWonderNewsPal8[] = INCBIN_U16("graphics/wonder_news/bg8.gbapal"); +static const u32 sWonderNewsGfx1[] = INCBIN_U32("graphics/wonder_news/bg1.4bpp.lz"); +static const u32 sWonderNewsTilemap1[] = INCBIN_U32("graphics/wonder_news/bg1.bin.lz"); +static const u32 sWonderNewsGfx2[] = INCBIN_U32("graphics/wonder_news/bg2.4bpp.lz"); +static const u32 sWonderNewsTilemap2[] = INCBIN_U32("graphics/wonder_news/bg2.bin.lz"); +static const u32 sWonderNewsGfx3[] = INCBIN_U32("graphics/wonder_news/bg3.4bpp.lz"); +static const u32 sWonderNewsTilemap3[] = INCBIN_U32("graphics/wonder_news/bg3.bin.lz"); +static const u32 sWonderNewsGfx7[] = INCBIN_U32("graphics/wonder_news/bg7.4bpp.lz"); +static const u32 sWonderNewsTilemap7[] = INCBIN_U32("graphics/wonder_news/bg7.bin.lz"); +static const u32 sWonderNewsGfx8[] = INCBIN_U32("graphics/wonder_news/bg8.4bpp.lz"); +static const u32 sWonderNewsTilemap8[] = INCBIN_U32("graphics/wonder_news/bg8.bin.lz"); + +static const struct WonderGraphics sNewsGraphics[NUM_WONDER_BGS] = { + {1, 0, 0, 0, sWonderNewsGfx1, sWonderNewsTilemap1, sWonderNewsPal1}, + {1, 0, 0, 0, sWonderNewsGfx2, sWonderNewsTilemap2, sWonderCardBgPal2}, + {1, 0, 0, 0, sWonderNewsGfx3, sWonderNewsTilemap3, sWonderCardBgPal3}, + {1, 0, 0, 0, sWonderNewsGfx3, sWonderNewsTilemap3, sWonderCardBgPal4}, + {1, 0, 0, 0, sWonderNewsGfx3, sWonderNewsTilemap3, sWonderCardBgPal5}, + {1, 0, 0, 0, sWonderNewsGfx3, sWonderNewsTilemap3, sWonderCardBgPal6}, + {1, 0, 0, 0, sWonderNewsGfx7, sWonderNewsTilemap7, sWonderNewsPal7}, + {1, 0, 0, 0, sWonderNewsGfx8, sWonderNewsTilemap8, sWonderNewsPal8} +}; + +bool32 WonderNews_Init(const struct WonderNews * news) +{ + if (news == NULL) + return FALSE; + sWonderNewsData = AllocZeroed(sizeof(*sWonderNewsData)); + if (sWonderNewsData == NULL) + return FALSE; + sWonderNewsData->news = *news; + if (sWonderNewsData->news.bgType >= ARRAY_COUNT(sNewsGraphics)) + sWonderNewsData->news.bgType = 0; + sWonderNewsData->gfx = &sNewsGraphics[sWonderNewsData->news.bgType]; + sWonderNewsData->arrowTaskId = TASK_NONE; + return TRUE; +} + +void WonderNews_Destroy(void) +{ + if (sWonderNewsData != NULL) + { + *sWonderNewsData = (struct WonderNewsData){}; + Free(sWonderNewsData); + sWonderNewsData = NULL; + } +} + +s32 WonderNews_Enter(void) +{ + if (sWonderNewsData == NULL) + return -1; + + switch (sWonderNewsData->enterExitState) + { + case 0: + BeginNormalPaletteFade(PALETTES_ALL, 0, 0, 16, RGB_BLACK); + break; + case 1: + if (UpdatePaletteFade()) + return 0; + ChangeBgY(0, 0, 0); + ChangeBgY(1, 0, 0); + ChangeBgY(2, 0, 0); + ChangeBgY(3, 0, 0); + SetGpuReg(REG_OFFSET_WIN0H, WIN_RANGE(0, DISPLAY_WIDTH)); + SetGpuReg(REG_OFFSET_WIN0V, WIN_RANGE(26, 152)); + SetGpuReg(REG_OFFSET_WININ, WININ_WIN0_BG_ALL | WININ_WIN0_OBJ); + SetGpuReg(REG_OFFSET_WINOUT, WINOUT_WIN01_BG0 | WINOUT_WIN01_BG1 | WINOUT_WIN01_BG3 | WINOUT_WIN01_OBJ); + SetGpuRegBits(REG_OFFSET_DISPCNT, DISPCNT_WIN0_ON); + break; + case 2: + FillBgTilemapBufferRect_Palette0(0, 0x000, 0, 0, 30, 20); + FillBgTilemapBufferRect_Palette0(1, 0x000, 0, 0, 30, 20); + FillBgTilemapBufferRect_Palette0(2, 0x000, 0, 0, 30, 20); + FillBgTilemapBufferRect_Palette0(3, 0x000, 0, 0, 30, 20); + CopyBgTilemapBufferToVram(0); + CopyBgTilemapBufferToVram(1); + CopyBgTilemapBufferToVram(2); + CopyBgTilemapBufferToVram(3); + DecompressAndCopyTileDataToVram(3, sWonderNewsData->gfx->tiles, 0, 8, 0); + sWonderNewsData->windowIds[NEWS_WIN_0] = AddWindow(&sNews_WindowTemplates[NEWS_WIN_0]); + sWonderNewsData->windowIds[NEWS_WIN_1] = AddWindow(&sNews_WindowTemplates[NEWS_WIN_1]); + break; + case 3: + if (FreeTempTileDataBuffersIfPossible()) + return 0; + LoadPalette(GetTextWindowPalette(1), 0x20, 0x20); + gPaletteFade.bufferTransferDisabled = TRUE; + LoadPalette(sWonderNewsData->gfx->pal, 0x10, 0x20); + LZ77UnCompWram(sWonderNewsData->gfx->map, sWonderNewsData->buffer_03A4); + CopyRectToBgTilemapBufferRect(1, sWonderNewsData->buffer_03A4, 0, 0, 30, 3, 0, 0, 30, 3, 1, 8, 0); + CopyRectToBgTilemapBufferRect(3, sWonderNewsData->buffer_03A4, 0, 3, 30, 23, 0, 3, 30, 23, 1, 8, 0); + CopyBgTilemapBufferToVram(1); + CopyBgTilemapBufferToVram(3); + break; + case 4: + BufferNewsText(); + break; + case 5: + DrawNewsWindows(); + CopyBgTilemapBufferToVram(0); + CopyBgTilemapBufferToVram(2); + break; + case 6: + ShowBg(1); + ShowBg(2); + ShowBg(3); + gPaletteFade.bufferTransferDisabled = FALSE; + sWonderNewsData->arrowTaskId = AddScrollIndicatorArrowPair(&sWonderNewsData->arrowsTemplate, &sWonderNewsData->scrollOffset); + BeginNormalPaletteFade(PALETTES_ALL, 0, 16, 0, RGB_BLACK); + UpdatePaletteFade(); + break; + default: + if (UpdatePaletteFade()) + return 0; + sWonderNewsData->enterExitState = 0; + return 1; + } + + ++sWonderNewsData->enterExitState; + return 0; +} + +s32 WonderNews_Exit(bool32 flag) +{ + if (sWonderNewsData == NULL) + return -1; + switch (sWonderNewsData->enterExitState) + { + case 0: + BeginNormalPaletteFade(PALETTES_ALL, 0, 0, 16, RGB_BLACK); + break; + case 1: + if (UpdatePaletteFade()) + return 0; + ChangeBgY(2, 0, 0); + SetGpuReg(REG_OFFSET_WIN0H, 0); + SetGpuReg(REG_OFFSET_WIN0V, 0); + SetGpuReg(REG_OFFSET_WININ, 0); + SetGpuReg(REG_OFFSET_WINOUT, 0); + ClearGpuRegBits(REG_OFFSET_DISPCNT, DISPCNT_WIN0_ON); + break; + case 2: + FillBgTilemapBufferRect_Palette0(0, 0x000, 0, 0, 30, 20); + FillBgTilemapBufferRect_Palette0(1, 0x000, 0, 0, 30, 20); + FillBgTilemapBufferRect_Palette0(2, 0x000, 0, 0, 30, 24); + FillBgTilemapBufferRect_Palette0(3, 0x000, 0, 0, 30, 24); + CopyBgTilemapBufferToVram(0); + CopyBgTilemapBufferToVram(1); + CopyBgTilemapBufferToVram(2); + CopyBgTilemapBufferToVram(3); + break; + case 3: + HideBg(1); + HideBg(2); + RemoveWindow(sWonderNewsData->windowIds[NEWS_WIN_1]); + RemoveWindow(sWonderNewsData->windowIds[NEWS_WIN_0]); + break; + case 4: + ChangeBgY(2, 0, 0); + ChangeBgY(3, 0, 0); + if (sWonderNewsData->arrowTaskId != TASK_NONE) + { + RemoveScrollIndicatorArrowPair(sWonderNewsData->arrowTaskId); + sWonderNewsData->arrowTaskId = TASK_NONE; + } + break; + case 5: + PrintMysteryGiftOrEReaderTopMenu(gGiftIsFromEReader, flag); + MG_DrawCheckerboardPattern(3); + CopyBgTilemapBufferToVram(0); + CopyBgTilemapBufferToVram(3); + BeginNormalPaletteFade(PALETTES_ALL, 0, 16, 0, RGB_BLACK); + break; + default: + if (UpdatePaletteFade()) + return 0; + sWonderNewsData->enterExitState = 0; + return 1; + } + ++sWonderNewsData->enterExitState; + return 0; +} + +void WonderNews_RemoveScrollIndicatorArrowPair(void) +{ + if (!sWonderNewsData->arrowsRemoved && sWonderNewsData->arrowTaskId != TASK_NONE) + { + RemoveScrollIndicatorArrowPair(sWonderNewsData->arrowTaskId); + sWonderNewsData->arrowTaskId = TASK_NONE; + sWonderNewsData->arrowsRemoved = TRUE; + } +} + + +void WonderNews_AddScrollIndicatorArrowPair(void) +{ + if (sWonderNewsData->arrowsRemoved) + { + sWonderNewsData->arrowTaskId = AddScrollIndicatorArrowPair(&sWonderNewsData->arrowsTemplate, &sWonderNewsData->scrollOffset); + sWonderNewsData->arrowsRemoved = FALSE; + } +} + +u32 WonderNews_GetInput(u16 input) +{ + if (sWonderNewsData->scrolling) + { + UpdateNewsScroll(); + return NEWS_INPUT_NONE; + } + switch (input) + { + case A_BUTTON: + return NEWS_INPUT_A; + case B_BUTTON: + return NEWS_INPUT_B; + case DPAD_UP: + if (sWonderNewsData->scrollOffset == 0) + return NEWS_INPUT_NONE; + if (sWonderNewsData->arrowsRemoved) + return NEWS_INPUT_NONE; + sWonderNewsData->scrollingDown = FALSE; + break; + case DPAD_DOWN: + if (sWonderNewsData->scrollOffset == sWonderNewsData->scrollEnd) + return NEWS_INPUT_NONE; + if (sWonderNewsData->arrowsRemoved) + return NEWS_INPUT_NONE; + sWonderNewsData->scrollingDown = TRUE; + break; + default: + return NEWS_INPUT_NONE; + } + + // Init scroll + sWonderNewsData->scrolling = TRUE; + sWonderNewsData->scrollIncrement = 2; + sWonderNewsData->scrollTotal = 0; + if (!sWonderNewsData->scrollingDown) + return NEWS_INPUT_SCROLL_UP; + else + return NEWS_INPUT_SCROLL_DOWN; +} + +static void BufferNewsText(void) +{ + u8 i = 0; + memcpy(sWonderNewsData->unk_01CE, sWonderNewsData->news.unk_04, WONDER_NEWS_TEXT_LENGTH); + sWonderNewsData->unk_01CE[WONDER_NEWS_TEXT_LENGTH] = EOS; + for (; i < 10; ++i) + { + memcpy(sWonderNewsData->unk_01F7[i], sWonderNewsData->news.unk_2C[i], WONDER_NEWS_TEXT_LENGTH); + sWonderNewsData->unk_01F7[i][WONDER_NEWS_TEXT_LENGTH] = EOS; + if (i > 7 && sWonderNewsData->unk_01F7[i][0] != EOS) + ++sWonderNewsData->scrollEnd; + } + sWonderNewsData->arrowsTemplate = sNews_ArrowsTemplate; + sWonderNewsData->arrowsTemplate.fullyDownThreshold = sWonderNewsData->scrollEnd; +} + +static void DrawNewsWindows(void) +{ + u8 i = 0; + s32 x; + PutWindowTilemap(sWonderNewsData->windowIds[NEWS_WIN_0]); + PutWindowTilemap(sWonderNewsData->windowIds[NEWS_WIN_1]); + FillWindowPixelBuffer(sWonderNewsData->windowIds[NEWS_WIN_0], 0); + FillWindowPixelBuffer(sWonderNewsData->windowIds[NEWS_WIN_1], 0); + x = (224 - GetStringWidth(3, sWonderNewsData->unk_01CE, GetFontAttribute(3, FONTATTR_LETTER_SPACING))) / 2; + if (x < 0) + x = 0; + AddTextPrinterParameterized3(sWonderNewsData->windowIds[NEWS_WIN_0], 3, x, 6, sNews_TextColorTable[sWonderNewsData->gfx->textPal1], 0, sWonderNewsData->unk_01CE); + for (; i < 10; ++i) + AddTextPrinterParameterized3(sWonderNewsData->windowIds[NEWS_WIN_1], 3, 0, 16 * i + 2, sNews_TextColorTable[sWonderNewsData->gfx->textPal2], 0, sWonderNewsData->unk_01F7[i]); + CopyWindowToVram(sWonderNewsData->windowIds[NEWS_WIN_0], 3); + CopyWindowToVram(sWonderNewsData->windowIds[NEWS_WIN_1], 3); +} + +static void UpdateNewsScroll(void) +{ + u16 bgMove = sWonderNewsData->scrollIncrement; + bgMove *= 256; + if (sWonderNewsData->scrollingDown) + { + ChangeBgY(2, bgMove, BG_COORD_ADD); + ChangeBgY(3, bgMove, BG_COORD_ADD); + } + else + { + ChangeBgY(2, bgMove, BG_COORD_SUB); + ChangeBgY(3, bgMove, BG_COORD_SUB); + } + sWonderNewsData->scrollTotal += sWonderNewsData->scrollIncrement; + if (sWonderNewsData->scrollTotal > 15) + { + if (sWonderNewsData->scrollingDown) + ++sWonderNewsData->scrollOffset; + else + --sWonderNewsData->scrollOffset; + sWonderNewsData->scrolling = FALSE; + sWonderNewsData->scrollTotal = 0; + } +} diff --git a/sym_ewram.txt b/sym_ewram.txt index 88c4461cb..360a91d32 100644 --- a/sym_ewram.txt +++ b/sym_ewram.txt @@ -14,7 +14,7 @@ .include "src/wireless_communication_status_screen.o" .include "src/union_room_battle.o" .include "src/mevent2.o" - .include "src/mevent_801BAAC.o" + .include "src/wonder_transfer.o" .include "src/mevent_server.o" .include "src/mevent_client.o" .include "src/union_room_chat.o"