pokeemerald/src/field_region_map.c

219 lines
6.0 KiB
C
Raw Normal View History

2017-10-29 15:38:25 +01:00
#include "global.h"
2018-11-14 01:01:50 +01:00
#include "bg.h"
#include "gpu_regs.h"
#include "international_string_util.h"
2017-10-29 15:38:25 +01:00
#include "main.h"
#include "malloc.h"
2017-10-29 15:38:25 +01:00
#include "menu.h"
2018-11-14 01:01:50 +01:00
#include "palette.h"
2017-10-29 15:58:33 +01:00
#include "region_map.h"
2018-11-14 01:01:50 +01:00
#include "strings.h"
#include "text.h"
#include "text_window.h"
#include "window.h"
2019-04-04 23:05:46 +02:00
#include "constants/rgb.h"
2017-10-29 15:38:25 +01:00
2020-02-05 08:47:32 +01:00
/*
* This is the type of map shown when interacting with the metatiles for
* a wall-mounted Region Map (on the wall of the Pokemon Centers near the PC)
* It does not zoom, and pressing A or B closes the map
*
* For the region map in the pokenav, see pokenav_region_map.c
* For the region map in the pokedex, see pokdex_area_screen.c/pokedex_area_region_map.c
* For the fly map, and utility functions all of the maps use, see region_map.c
*/
2017-10-29 15:38:25 +01:00
// Static type declarations
// Static RAM declarations
static EWRAM_DATA struct {
2017-10-29 15:38:25 +01:00
MainCallback callback;
2020-02-05 08:47:32 +01:00
u32 unused;
2017-10-29 16:05:42 +01:00
struct RegionMap regionMap;
2017-10-29 15:58:33 +01:00
u16 state;
2017-11-01 01:58:47 +01:00
} *sFieldRegionMapHandler = NULL;
2017-10-29 15:38:25 +01:00
// Static ROM declarations
2017-11-01 01:58:47 +01:00
static void MCB2_InitRegionMapRegisters(void);
static void VBCB_FieldUpdateRegionMap(void);
static void MCB2_FieldUpdateRegionMap(void);
static void FieldUpdateRegionMap(void);
static void PrintRegionMapSecName(void);
2017-10-29 15:38:25 +01:00
// .rodata
2020-02-05 08:47:32 +01:00
static const struct BgTemplate sFieldRegionMapBgTemplates[] = {
{
.bg = 0,
.charBaseIndex = 0,
.mapBaseIndex = 31,
.screenSize = 0,
.paletteMode = 0,
.priority = 0,
.baseTile = 0
}, {
.bg = 2,
.charBaseIndex = 2,
.mapBaseIndex = 28,
.screenSize = 2,
.paletteMode = 1,
.priority = 2,
.baseTile = 0
}
};
2020-02-05 08:47:32 +01:00
static const struct WindowTemplate sFieldRegionMapWindowTemplates[] =
2018-09-02 18:53:52 +02:00
{
{
2018-10-27 00:53:07 +02:00
.bg = 0,
2018-09-02 18:53:52 +02:00
.tilemapLeft = 17,
.tilemapTop = 17,
.width = 12,
.height = 2,
.paletteNum = 15,
.baseBlock = 1
},
{
2018-10-27 00:53:07 +02:00
.bg = 0,
2018-09-02 18:53:52 +02:00
.tilemapLeft = 22,
.tilemapTop = 1,
.width = 7,
.height = 2,
.paletteNum = 15,
.baseBlock = 25
},
2017-11-13 03:13:18 +01:00
DUMMY_WIN_TEMPLATE
};
2017-10-29 15:38:25 +01:00
// .text
void FieldInitRegionMap(MainCallback callback)
2017-10-29 15:38:25 +01:00
{
SetVBlankCallback(NULL);
2017-11-01 01:58:47 +01:00
sFieldRegionMapHandler = malloc(sizeof(*sFieldRegionMapHandler));
sFieldRegionMapHandler->state = 0;
sFieldRegionMapHandler->callback = callback;
SetMainCallback2(MCB2_InitRegionMapRegisters);
2017-10-29 15:38:25 +01:00
}
2017-11-01 01:58:47 +01:00
static void MCB2_InitRegionMapRegisters(void)
2017-10-29 15:38:25 +01:00
{
SetGpuReg(REG_OFFSET_DISPCNT, 0);
SetGpuReg(REG_OFFSET_BG0HOFS, 0);
SetGpuReg(REG_OFFSET_BG0VOFS, 0);
SetGpuReg(REG_OFFSET_BG1HOFS, 0);
SetGpuReg(REG_OFFSET_BG1VOFS, 0);
SetGpuReg(REG_OFFSET_BG2HOFS, 0);
SetGpuReg(REG_OFFSET_BG2VOFS, 0);
SetGpuReg(REG_OFFSET_BG3HOFS, 0);
SetGpuReg(REG_OFFSET_BG3VOFS, 0);
ResetSpriteData();
FreeAllSpritePalettes();
ResetBgsAndClearDma3BusyFlags(0);
InitBgsFromTemplates(1, sFieldRegionMapBgTemplates, ARRAY_COUNT(sFieldRegionMapBgTemplates));
2020-02-05 08:47:32 +01:00
InitWindows(sFieldRegionMapWindowTemplates);
2017-10-29 15:38:25 +01:00
DeactivateAllTextPrinters();
2018-07-15 13:23:38 +02:00
LoadUserWindowBorderGfx(0, 0x27, 0xd0);
2017-10-29 15:38:25 +01:00
clear_scheduled_bg_copies_to_vram();
2017-11-01 01:58:47 +01:00
SetMainCallback2(MCB2_FieldUpdateRegionMap);
SetVBlankCallback(VBCB_FieldUpdateRegionMap);
2017-10-29 15:38:25 +01:00
}
2017-11-01 01:58:47 +01:00
static void VBCB_FieldUpdateRegionMap(void)
2017-10-29 15:38:25 +01:00
{
LoadOam();
ProcessSpriteCopyRequests();
TransferPlttBuffer();
}
2017-11-01 01:58:47 +01:00
static void MCB2_FieldUpdateRegionMap(void)
2017-10-29 15:38:25 +01:00
{
2017-11-01 01:58:47 +01:00
FieldUpdateRegionMap();
2017-10-29 15:38:25 +01:00
AnimateSprites();
BuildOamBuffer();
UpdatePaletteFade();
do_scheduled_bg_tilemap_copies_to_vram();
}
2017-10-29 15:58:33 +01:00
2017-11-01 01:58:47 +01:00
static void FieldUpdateRegionMap(void)
2017-10-29 15:58:33 +01:00
{
u8 offset;
2017-11-01 01:58:47 +01:00
switch (sFieldRegionMapHandler->state)
2017-10-29 15:58:33 +01:00
{
case 0:
2020-02-05 08:47:32 +01:00
InitRegionMap(&sFieldRegionMapHandler->regionMap, FALSE);
2017-11-01 01:58:47 +01:00
CreateRegionMapPlayerIcon(0, 0);
2017-10-30 13:39:39 +01:00
CreateRegionMapCursor(1, 1);
sFieldRegionMapHandler->state++;
2017-10-29 15:58:33 +01:00
break;
case 1:
DrawStdFrameWithCustomTileAndPalette(1, 0, 0x27, 0xd);
2017-10-29 15:58:33 +01:00
offset = GetStringCenterAlignXOffset(1, gText_Hoenn, 0x38);
AddTextPrinterParameterized(1, 1, gText_Hoenn, offset, 1, 0, NULL);
2017-10-29 15:58:33 +01:00
schedule_bg_copy_tilemap_to_vram(0);
DrawStdFrameWithCustomTileAndPalette(0, 0, 0x27, 0xd);
2017-11-01 01:58:47 +01:00
PrintRegionMapSecName();
2019-04-04 23:05:46 +02:00
BeginNormalPaletteFade(0xFFFFFFFF, 0, 16, 0, RGB_BLACK);
sFieldRegionMapHandler->state++;
2017-10-29 15:58:33 +01:00
break;
case 2:
SetGpuRegBits(REG_OFFSET_DISPCNT, DISPCNT_OBJ_1D_MAP | DISPCNT_OBJ_ON);
ShowBg(0);
ShowBg(2);
sFieldRegionMapHandler->state++;
2017-10-29 15:58:33 +01:00
break;
case 3:
if (!gPaletteFade.active)
{
sFieldRegionMapHandler->state++;
2017-10-29 15:58:33 +01:00
}
break;
case 4:
2020-02-05 08:47:32 +01:00
switch (DoRegionMapInputCallback())
2017-10-29 15:58:33 +01:00
{
2020-02-05 08:47:32 +01:00
case MAP_INPUT_MOVE_END:
2017-11-01 01:58:47 +01:00
PrintRegionMapSecName();
2017-10-29 15:58:33 +01:00
break;
2020-02-05 08:47:32 +01:00
case MAP_INPUT_A_BUTTON:
case MAP_INPUT_B_BUTTON:
sFieldRegionMapHandler->state++;
2017-10-29 15:58:33 +01:00
break;
}
break;
case 5:
2019-04-04 23:05:46 +02:00
BeginNormalPaletteFade(0xFFFFFFFF, 0, 0, 16, RGB_BLACK);
sFieldRegionMapHandler->state++;
2017-10-29 15:58:33 +01:00
break;
case 6:
if (!gPaletteFade.active)
{
2017-10-30 13:39:39 +01:00
FreeRegionMapIconResources();
2017-11-01 01:58:47 +01:00
SetMainCallback2(sFieldRegionMapHandler->callback);
if (sFieldRegionMapHandler != NULL)
2017-10-29 15:58:33 +01:00
{
2020-02-05 08:47:32 +01:00
FREE_AND_SET_NULL(sFieldRegionMapHandler);
2017-10-29 15:58:33 +01:00
}
FreeAllWindowBuffers();
}
break;
}
}
2017-10-29 16:05:42 +01:00
2017-11-01 01:58:47 +01:00
static void PrintRegionMapSecName(void)
2017-10-29 16:05:42 +01:00
{
2020-02-05 08:47:32 +01:00
if (sFieldRegionMapHandler->regionMap.mapSecType != MAPSECTYPE_NONE)
2017-10-29 16:05:42 +01:00
{
FillWindowPixelBuffer(0, PIXEL_FILL(1));
AddTextPrinterParameterized(0, 1, sFieldRegionMapHandler->regionMap.mapSecName, 0, 1, 0, NULL);
2017-10-29 16:05:42 +01:00
schedule_bg_copy_tilemap_to_vram(0);
}
else
{
FillWindowPixelBuffer(0, PIXEL_FILL(1));
2017-10-29 16:05:42 +01:00
CopyWindowToVram(0, 3);
}
}