pokeemerald/src/diploma.c

210 lines
5.3 KiB
C
Raw Normal View History

2017-10-08 04:54:32 +02:00
#include "global.h"
#include "diploma.h"
2017-10-08 04:54:32 +02:00
#include "palette.h"
#include "main.h"
#include "gpu_regs.h"
2018-01-29 17:47:12 +01:00
#include "scanline_effect.h"
2017-10-08 04:54:32 +02:00
#include "task.h"
#include "malloc.h"
2017-10-08 04:54:32 +02:00
#include "decompress.h"
#include "bg.h"
#include "window.h"
#include "string_util.h"
#include "text.h"
2018-10-27 00:53:07 +02:00
#include "overworld.h"
#include "menu.h"
2019-03-02 04:32:50 +01:00
#include "pokedex.h"
2019-04-04 23:05:46 +02:00
#include "constants/rgb.h"
2017-10-08 04:54:32 +02:00
2018-10-27 00:53:07 +02:00
extern const u8 gText_DexNational[];
extern const u8 gText_DexHoenn[];
extern const u8 gText_PokedexDiploma[];
2017-10-08 04:54:32 +02:00
static void MainCB2(void);
static void Task_DiplomaFadeIn(u8);
static void Task_DiplomaWaitForKeyPress(u8);
static void Task_DiplomaFadeOut(u8);
static void DisplayDiplomaText(void);
static void InitDiplomaBg(void);
static void InitDiplomaWindow(void);
static void PrintDiplomaText(u8 *, u8, u8);
2018-10-27 00:53:07 +02:00
EWRAM_DATA static u8 *sDiplomaTilemapPtr = NULL;
2017-10-08 04:54:32 +02:00
static void VBlankCB(void)
{
LoadOam();
ProcessSpriteCopyRequests();
TransferPlttBuffer();
}
static const u16 sDiplomaPalettes[][16] =
2017-10-08 04:54:32 +02:00
{
2022-01-14 18:29:30 +01:00
INCBIN_U16("graphics/diploma/national.gbapal"),
INCBIN_U16("graphics/diploma/hoenn.gbapal"),
2017-10-08 04:54:32 +02:00
};
2022-01-14 18:29:30 +01:00
static const u32 sDiplomaTilemap[] = INCBIN_U32("graphics/diploma/tilemap.bin.lz");
static const u32 sDiplomaTiles[] = INCBIN_U32("graphics/diploma/tiles.4bpp.lz");
2017-10-08 04:54:32 +02:00
void CB2_ShowDiploma(void)
{
SetVBlankCallback(NULL);
SetGpuReg(REG_OFFSET_DISPCNT, DISPCNT_MODE_0);
2021-04-15 09:00:01 +02:00
SetGpuReg(REG_OFFSET_BG3CNT, 0);
SetGpuReg(REG_OFFSET_BG2CNT, 0);
SetGpuReg(REG_OFFSET_BG1CNT, 0);
SetGpuReg(REG_OFFSET_BG0CNT, 0);
SetGpuReg(REG_OFFSET_BG3HOFS, 0);
SetGpuReg(REG_OFFSET_BG3VOFS, 0);
SetGpuReg(REG_OFFSET_BG2HOFS, 0);
SetGpuReg(REG_OFFSET_BG2VOFS, 0);
SetGpuReg(REG_OFFSET_BG1HOFS, 0);
SetGpuReg(REG_OFFSET_BG1VOFS, 0);
SetGpuReg(REG_OFFSET_BG0HOFS, 0);
SetGpuReg(REG_OFFSET_BG0VOFS, 0);
2017-10-08 04:54:32 +02:00
// why doesn't this one use the dma manager either?
DmaFill16(3, 0, VRAM, VRAM_SIZE);
DmaFill32(3, 0, OAM, OAM_SIZE);
DmaFill16(3, 0, PLTT, PLTT_SIZE);
2018-01-16 18:59:06 +01:00
ScanlineEffect_Stop();
2017-10-08 04:54:32 +02:00
ResetTasks();
ResetSpriteData();
ResetPaletteFade();
FreeAllSpritePalettes();
LoadPalette(sDiplomaPalettes, 0, 64);
sDiplomaTilemapPtr = malloc(0x1000);
2017-10-08 04:54:32 +02:00
InitDiplomaBg();
InitDiplomaWindow();
2020-05-14 10:37:09 +02:00
ResetTempTileDataBuffers();
DecompressAndCopyTileDataToVram(1, &sDiplomaTiles, 0, 0, 0);
while (FreeTempTileDataBuffersIfPossible())
2017-10-08 04:54:32 +02:00
;
2018-11-07 19:35:31 +01:00
LZDecompressWram(sDiplomaTilemap, sDiplomaTilemapPtr);
2017-10-08 04:54:32 +02:00
CopyBgTilemapBufferToVram(1);
DisplayDiplomaText();
BlendPalettes(PALETTES_ALL, 16, RGB_BLACK);
2021-02-24 17:01:02 +01:00
BeginNormalPaletteFade(PALETTES_ALL, 0, 16, 0, RGB_BLACK);
2017-10-08 04:54:32 +02:00
EnableInterrupts(1);
SetVBlankCallback(VBlankCB);
SetMainCallback2(MainCB2);
CreateTask(Task_DiplomaFadeIn, 0);
}
static void MainCB2(void)
{
RunTasks();
AnimateSprites();
BuildOamBuffer();
UpdatePaletteFade();
}
static void Task_DiplomaFadeIn(u8 taskId)
{
if (!gPaletteFade.active)
gTasks[taskId].func = Task_DiplomaWaitForKeyPress;
}
static void Task_DiplomaWaitForKeyPress(u8 taskId)
{
2020-09-05 03:11:55 +02:00
if (JOY_NEW(A_BUTTON | B_BUTTON))
2017-10-08 04:54:32 +02:00
{
2021-02-24 17:01:02 +01:00
BeginNormalPaletteFade(PALETTES_ALL, 0, 0, 16, RGB_BLACK);
2017-10-08 04:54:32 +02:00
gTasks[taskId].func = Task_DiplomaFadeOut;
}
}
static void Task_DiplomaFadeOut(u8 taskId)
{
if (!gPaletteFade.active)
{
Free(sDiplomaTilemapPtr);
2017-10-08 04:54:32 +02:00
FreeAllWindowBuffers();
DestroyTask(taskId);
2021-04-06 22:55:33 +02:00
SetMainCallback2(CB2_ReturnToFieldFadeFromBlack);
2017-10-08 04:54:32 +02:00
}
}
static void DisplayDiplomaText(void)
{
if (HasAllMons())
2017-10-08 04:54:32 +02:00
{
2021-04-15 09:00:01 +02:00
SetGpuReg(REG_OFFSET_BG1HOFS, DISPLAY_WIDTH + 16);
2017-10-08 04:54:32 +02:00
StringCopy(gStringVar1, gText_DexNational);
}
else
{
2021-04-15 09:00:01 +02:00
SetGpuReg(REG_OFFSET_BG1HOFS, 0);
2017-10-08 04:54:32 +02:00
StringCopy(gStringVar1, gText_DexHoenn);
}
StringExpandPlaceholders(gStringVar4, gText_PokedexDiploma);
PrintDiplomaText(gStringVar4, 0, 1);
PutWindowTilemap(0);
2021-11-03 20:29:18 +01:00
CopyWindowToVram(0, COPYWIN_FULL);
2017-10-08 04:54:32 +02:00
}
static const struct BgTemplate sDiplomaBgTemplates[2] =
2017-10-08 04:54:32 +02:00
{
{
.bg = 0,
.charBaseIndex = 1,
.mapBaseIndex = 31,
.screenSize = 0,
.paletteMode = 0,
.priority = 0,
.baseTile = 0,
},
{
.bg = 1,
.charBaseIndex = 0,
.mapBaseIndex = 6,
.screenSize = 1,
.paletteMode = 0,
.priority = 1,
.baseTile = 0,
},
};
static void InitDiplomaBg(void)
{
ResetBgsAndClearDma3BusyFlags(0);
InitBgsFromTemplates(0, sDiplomaBgTemplates, ARRAY_COUNT(sDiplomaBgTemplates));
SetBgTilemapBuffer(1, sDiplomaTilemapPtr);
2017-10-08 04:54:32 +02:00
SetGpuReg(REG_OFFSET_DISPCNT, DISPCNT_OBJ_ON | DISPCNT_OBJ_1D_MAP);
ShowBg(0);
ShowBg(1);
2021-04-15 09:00:01 +02:00
SetGpuReg(REG_OFFSET_BLDCNT, 0);
SetGpuReg(REG_OFFSET_BLDALPHA, 0);
SetGpuReg(REG_OFFSET_BLDY, 0);
2017-10-08 04:54:32 +02:00
}
static const struct WindowTemplate sDiplomaWinTemplates[2] =
2017-10-08 04:54:32 +02:00
{
{
2018-10-27 00:53:07 +02:00
.bg = 0,
2017-10-08 04:54:32 +02:00
.tilemapLeft = 5,
.tilemapTop = 2,
.width = 20,
.height = 16,
.paletteNum = 15,
.baseBlock = 1,
},
DUMMY_WIN_TEMPLATE,
};
static void InitDiplomaWindow(void)
{
InitWindows(sDiplomaWinTemplates);
2017-10-08 04:54:32 +02:00
DeactivateAllTextPrinters();
2021-10-26 22:52:23 +02:00
LoadPalette(gStandardMenuPalette, 0xF0, 0x20);
FillWindowPixelBuffer(0, PIXEL_FILL(0));
2017-10-08 04:54:32 +02:00
PutWindowTilemap(0);
}
static void PrintDiplomaText(u8 *text, u8 var1, u8 var2)
{
2018-02-07 03:37:54 +01:00
u8 color[3] = {0, 2, 3};
2017-10-08 04:54:32 +02:00
AddTextPrinterParameterized4(0, FONT_NORMAL, var1, var2, 0, 0, color, TEXT_SKIP_DRAW, text);
2017-10-08 04:54:32 +02:00
}