diff options
author | PikalaxALT <pikalaxalt@gmail.com> | 2019-04-25 08:52:36 -0400 |
---|---|---|
committer | PikalaxALT <pikalaxalt@gmail.com> | 2019-04-25 08:52:36 -0400 |
commit | 9575eba4814cfa96ae863ea2716afecbf2565b71 (patch) | |
tree | a74daa44ab7ad88b83f0591cc21f03d6ea060463 /src | |
parent | 1a4867a4bf4427c45af7545adcabae58ee19eb6e (diff) |
start to port mystery gift from emerald
Diffstat (limited to 'src')
-rw-r--r-- | src/mystery_gift_menu.c | 188 |
1 files changed, 188 insertions, 0 deletions
diff --git a/src/mystery_gift_menu.c b/src/mystery_gift_menu.c new file mode 100644 index 000000000..7b7fd71a1 --- /dev/null +++ b/src/mystery_gift_menu.c @@ -0,0 +1,188 @@ +#include "global.h" +#include "palette.h" +#include "dma3.h" +#include "gpu_regs.h" +#include "bg.h" +#include "task.h" +#include "scanline_effect.h" +#include "malloc.h" +#include "text.h" +#include "window.h" +#include "text_window.h" +#include "new_menu_helpers.h" +#include "sound.h" +#include "mystery_gift_menu.h" +#include "link_rfu.h" +#include "constants/songs.h" + +EWRAM_DATA u8 sDownArrowCounterAndYCoordIdx[8] = {}; +EWRAM_DATA bool8 gGiftIsFromEReader = FALSE; + +static const u16 gUnkTextboxBorderPal[] = INCBIN_U16("graphics/interface/unk_textbox_border.gbapal"); +static const u32 gUnkTextboxBorderGfx[] = INCBIN_U32("graphics/interface/unk_textbox_border.4bpp.lz"); + +struct MysteryGiftTaskData +{ + u16 curPromptWindowId; + u16 unk2; + u16 unk4; + u16 unk6; + u8 state; + u8 textState; + u8 unkA; + u8 unkB; + u8 IsCardOrNews; + u8 source; + u8 prevPromptWindowId; + u8 * buffer; +}; + +static const struct BgTemplate sBGTemplates[] = { + { + .bg = 0, + .charBaseIndex = 2, + .mapBaseIndex = 15, + .screenSize = 0, + .paletteMode = 0, + .priority = 0, + .baseTile = 0x000 + }, { + .bg = 1, + .charBaseIndex = 0, + .mapBaseIndex = 14, + .screenSize = 0, + .paletteMode = 0, + .priority = 1, + .baseTile = 0x000 + }, { + .bg = 2, + .charBaseIndex = 0, + .mapBaseIndex = 13, + .screenSize = 0, + .paletteMode = 0, + .priority = 2, + .baseTile = 0x000 + }, { + .bg = 3, + .charBaseIndex = 0, + .mapBaseIndex = 12, + .screenSize = 0, + .paletteMode = 0, + .priority = 3, + .baseTile = 0x000 + } +}; + +static const struct WindowTemplate sMainWindows[] = { + { + .priority = 0x00, + .tilemapLeft = 0x00, + .tilemapTop = 0x00, + .width = 0x1e, + .height = 0x02, + .paletteNum = 0x0f, + .baseBlock = 0x0013 + }, { + .priority = 0x00, + .tilemapLeft = 0x01, + .tilemapTop = 0x0f, + .width = 0x1c, + .height = 0x04, + .paletteNum = 0x0f, + .baseBlock = 0x004f + }, { + .priority = 0x00, + .tilemapLeft = 0x00, + .tilemapTop = 0x0f, + .width = 0x1e, + .height = 0x05, + .paletteNum = 0x0d, + .baseBlock = 0x004f + }, { + 0xFF + } +}; + +void vblankcb_mystery_gift_e_reader_run(void) +{ + ProcessSpriteCopyRequests(); + LoadOam(); + TransferPlttBuffer(); +} + +void c2_mystery_gift_e_reader_run(void) +{ + RunTasks(); + RunTextPrinters(); + AnimateSprites(); + BuildOamBuffer(); +} + +bool32 HandleMysteryGiftOrEReaderSetup(s32 mg_or_ereader) +{ + switch (gMain.state) + { + case 0: + SetVBlankCallback(NULL); + ResetPaletteFade(); + ResetSpriteData(); + FreeAllSpritePalettes(); + ResetTasks(); + ScanlineEffect_Stop(); + ResetBgsAndClearDma3BusyFlags(1); + + InitBgsFromTemplates(0, sBGTemplates, ARRAY_COUNT(sBGTemplates)); + ChangeBgX(0, 0, 0); + ChangeBgY(0, 0, 0); + ChangeBgX(1, 0, 0); + ChangeBgY(1, 0, 0); + ChangeBgX(2, 0, 0); + ChangeBgY(2, 0, 0); + ChangeBgX(3, 0, 0); + ChangeBgY(3, 0, 0); + + SetBgTilemapBuffer(3, Alloc(0x800)); + SetBgTilemapBuffer(2, Alloc(0x800)); + SetBgTilemapBuffer(1, Alloc(0x800)); + SetBgTilemapBuffer(0, Alloc(0x800)); + + sub_814FE40(0, 10, 0xE0); + sub_814FDA0(0, 1, 0xF0); + sub_80F696C(3, gUnkTextboxBorderGfx, 0x100, 0, 0); + InitWindows(sMainWindows); + DeactivateAllTextPrinters(); + ClearGpuRegBits(REG_OFFSET_DISPCNT, DISPCNT_WIN0_ON | DISPCNT_WIN1_ON); + SetGpuReg(REG_OFFSET_BLDCNT, 0); + SetGpuReg(REG_OFFSET_BLDALPHA, 0); + SetGpuReg(REG_OFFSET_BLDY, 0); + gMain.state++; + break; + case 1: + LoadPalette(gUnkTextboxBorderPal, 0, 0x20); + LoadPalette(stdpal_get(2), 0xd0, 0x20); + FillBgTilemapBufferRect(0, 0x000, 0, 0, 32, 32, 0x11); + FillBgTilemapBufferRect(1, 0x000, 0, 0, 32, 32, 0x11); + FillBgTilemapBufferRect(2, 0x000, 0, 0, 32, 32, 0x11); + sub_8142420(); + sub_8142344(mg_or_ereader, 0); + gMain.state++; + break; + case 2: + CopyBgTilemapBufferToVram(3); + CopyBgTilemapBufferToVram(2); + CopyBgTilemapBufferToVram(1); + CopyBgTilemapBufferToVram(0); + gMain.state++; + break; + case 3: + ShowBg(0); + ShowBg(3); + PlayBGM(BGM_FRLG_MYSTERY_GIFT); + SetVBlankCallback(vblankcb_mystery_gift_e_reader_run); + EnableInterrupts(INTR_FLAG_VBLANK | INTR_FLAG_VCOUNT | INTR_FLAG_TIMER3 | INTR_FLAG_SERIAL); + return TRUE; + } + + return FALSE; +} + |