pokeemerald/src/starter_choose.c

673 lines
19 KiB
C
Raw Normal View History

2017-11-08 18:05:47 +01:00
#include "global.h"
#include "bg.h"
2019-04-04 23:53:06 +02:00
#include "data.h"
2018-09-06 01:47:29 +02:00
#include "decompress.h"
#include "event_data.h"
2017-11-08 18:05:47 +01:00
#include "gpu_regs.h"
2018-09-06 01:47:29 +02:00
#include "international_string_util.h"
2017-11-08 18:05:47 +01:00
#include "main.h"
#include "menu.h"
2018-09-06 01:47:29 +02:00
#include "palette.h"
2017-11-08 18:05:47 +01:00
#include "pokedex.h"
2018-09-06 01:47:29 +02:00
#include "pokemon.h"
2018-07-16 20:23:05 +02:00
#include "scanline_effect.h"
2018-09-06 01:47:29 +02:00
#include "sound.h"
#include "sprite.h"
#include "starter_choose.h"
2020-07-06 23:22:37 +02:00
#include "strings.h"
2018-09-06 01:47:29 +02:00
#include "task.h"
#include "text.h"
#include "text_window.h"
2018-08-19 01:06:10 +02:00
#include "trainer_pokemon_sprites.h"
2018-09-06 01:47:29 +02:00
#include "trig.h"
#include "window.h"
#include "constants/songs.h"
2019-04-04 23:05:46 +02:00
#include "constants/rgb.h"
2017-11-08 18:05:47 +01:00
#define STARTER_MON_COUNT 3
// Position of the sprite of the selected starter Pokemon
2020-07-06 23:22:37 +02:00
#define STARTER_PKMN_POS_X (DISPLAY_WIDTH / 2)
2017-11-08 18:05:47 +01:00
#define STARTER_PKMN_POS_Y 64
2020-07-06 23:22:37 +02:00
#define TAG_POKEBALL_SELECT 0x1000
#define TAG_STARTER_CIRCLE 0x1001
static void CB2_StarterChoose(void);
static void ClearStarterLabel(void);
static void Task_StarterChoose(u8 taskId);
static void Task_HandleStarterChooseInput(u8 taskId);
static void Task_WaitForStarterSprite(u8 taskId);
static void Task_AskConfirmStarter(u8 taskId);
static void Task_HandleConfirmStarterInput(u8 taskId);
static void Task_DeclineStarter(u8 taskId);
2017-11-08 18:05:47 +01:00
static void Task_MoveStarterChooseCursor(u8 taskId);
2020-07-06 23:22:37 +02:00
static void Task_CreateStarterLabel(u8 taskId);
2017-11-08 18:05:47 +01:00
static void CreateStarterPokemonLabel(u8 selection);
static u8 CreatePokemonFrontSprite(u16 species, u8 x, u8 y);
2020-07-06 23:22:37 +02:00
static void SpriteCB_SelectionHand(struct Sprite *sprite);
static void SpriteCB_Pokeball(struct Sprite *sprite);
static void SpriteCB_StarterPokemon(struct Sprite *sprite);
2017-11-08 18:05:47 +01:00
2020-07-06 23:22:37 +02:00
static u16 sStarterLabelWindowId;
2017-11-13 18:30:17 +01:00
2018-09-06 01:47:29 +02:00
const u16 gBirchBagGrassPal[][16] =
{
INCBIN_U16("graphics/starter_choose/birch_bag.gbapal"),
INCBIN_U16("graphics/starter_choose/birch_grass.gbapal"),
2018-09-06 01:47:29 +02:00
};
static const u16 sPokeballSelection_Pal[] = INCBIN_U16("graphics/starter_choose/pokeball_selection.gbapal");
static const u16 sStarterCircle_Pal[] = INCBIN_U16("graphics/starter_choose/starter_circle.gbapal");
const u32 gBirchBagTilemap[] = INCBIN_U32("graphics/starter_choose/birch_bag.bin.lz");
const u32 gBirchGrassTilemap[] = INCBIN_U32("graphics/starter_choose/birch_grass.bin.lz");
const u32 gBirchHelpGfx[] = INCBIN_U32("graphics/starter_choose/birch_help.4bpp.lz"); // Birch bag and grass combined
const u32 gPokeballSelection_Gfx[] = INCBIN_U32("graphics/starter_choose/pokeball_selection.4bpp.lz");
static const u32 sStarterCircle_Gfx[] = INCBIN_U32("graphics/starter_choose/starter_circle.4bpp.lz");
2018-09-06 01:47:29 +02:00
2020-07-06 23:22:37 +02:00
static const struct WindowTemplate sWindowTemplates[] =
2018-09-06 01:47:29 +02:00
{
{
2018-10-27 00:53:07 +02:00
.bg = 0,
2018-09-06 01:47:29 +02:00
.tilemapLeft = 3,
.tilemapTop = 15,
.width = 24,
.height = 4,
.paletteNum = 14,
.baseBlock = 0x0200
},
DUMMY_WIN_TEMPLATE,
};
2020-07-06 23:22:37 +02:00
static const struct WindowTemplate sWindowTemplate_ConfirmStarter =
2018-09-06 01:47:29 +02:00
{
2018-10-27 00:53:07 +02:00
.bg = 0,
2018-09-06 01:47:29 +02:00
.tilemapLeft = 24,
.tilemapTop = 9,
.width = 5,
.height = 4,
.paletteNum = 14,
.baseBlock = 0x0260
};
2020-07-06 23:22:37 +02:00
static const struct WindowTemplate sWindowTemplate_StarterLabel =
2018-09-06 01:47:29 +02:00
{
2018-10-27 00:53:07 +02:00
.bg = 0,
2018-09-06 01:47:29 +02:00
.tilemapLeft = 0,
.tilemapTop = 0,
.width = 13,
.height = 4,
.paletteNum = 14,
.baseBlock = 0x0274
};
static const u8 sPokeballCoords[STARTER_MON_COUNT][2] =
{
2019-12-10 19:48:20 +01:00
{60, 64},
{120, 88},
{180, 64},
2018-09-06 01:47:29 +02:00
};
2020-07-06 23:22:37 +02:00
static const u8 sStarterLabelCoords[STARTER_MON_COUNT][2] =
2018-09-06 01:47:29 +02:00
{
2019-12-10 19:48:20 +01:00
{0, 9},
{16, 10},
{8, 4},
2018-09-06 01:47:29 +02:00
};
static const u16 sStarterMon[STARTER_MON_COUNT] =
{
SPECIES_TREECKO,
SPECIES_TORCHIC,
SPECIES_MUDKIP,
};
2020-07-06 23:22:37 +02:00
static const struct BgTemplate sBgTemplates[3] =
2018-09-06 01:47:29 +02:00
{
{
.bg = 0,
.charBaseIndex = 2,
.mapBaseIndex = 31,
.screenSize = 0,
.paletteMode = 0,
.priority = 0,
.baseTile = 0
},
{
.bg = 2,
.charBaseIndex = 0,
.mapBaseIndex = 7,
.screenSize = 0,
.paletteMode = 0,
.priority = 3,
.baseTile = 0
},
{
.bg = 3,
.charBaseIndex = 0,
.mapBaseIndex = 6,
.screenSize = 0,
.paletteMode = 0,
.priority = 1,
.baseTile = 0
},
};
2021-04-10 04:39:34 +02:00
static const u8 sTextColors[] = {TEXT_COLOR_TRANSPARENT, TEXT_COLOR_WHITE, TEXT_COLOR_LIGHT_GRAY};
2018-09-06 01:47:29 +02:00
2020-07-06 23:22:37 +02:00
static const struct OamData sOam_Hand =
2018-09-06 01:47:29 +02:00
{
2021-04-15 08:04:01 +02:00
.y = DISPLAY_HEIGHT,
.affineMode = ST_OAM_AFFINE_OFF,
.objMode = ST_OAM_OBJ_NORMAL,
2022-07-30 03:27:39 +02:00
.mosaic = FALSE,
.bpp = ST_OAM_4BPP,
.shape = SPRITE_SHAPE(32x32),
2018-09-06 01:47:29 +02:00
.x = 0,
.matrixNum = 0,
.size = SPRITE_SIZE(32x32),
2018-09-06 01:47:29 +02:00
.tileNum = 0,
.priority = 1,
.paletteNum = 0,
.affineParam = 0,
};
2020-07-06 23:22:37 +02:00
static const struct OamData sOam_Pokeball =
2018-09-06 01:47:29 +02:00
{
2021-04-15 08:04:01 +02:00
.y = DISPLAY_HEIGHT,
.affineMode = ST_OAM_AFFINE_OFF,
.objMode = ST_OAM_OBJ_NORMAL,
2022-07-30 03:27:39 +02:00
.mosaic = FALSE,
.bpp = ST_OAM_4BPP,
.shape = SPRITE_SHAPE(32x32),
2018-09-06 01:47:29 +02:00
.x = 0,
.matrixNum = 0,
.size = SPRITE_SIZE(32x32),
2018-09-06 01:47:29 +02:00
.tileNum = 0,
.priority = 1,
.paletteNum = 0,
.affineParam = 0,
};
2020-07-06 23:22:37 +02:00
static const struct OamData sOam_StarterCircle =
2018-09-06 01:47:29 +02:00
{
2021-04-15 08:04:01 +02:00
.y = DISPLAY_HEIGHT,
.affineMode = ST_OAM_AFFINE_DOUBLE,
.objMode = ST_OAM_OBJ_NORMAL,
2022-07-30 03:27:39 +02:00
.mosaic = FALSE,
.bpp = ST_OAM_4BPP,
.shape = SPRITE_SHAPE(64x64),
2018-09-06 01:47:29 +02:00
.x = 0,
.matrixNum = 0,
.size = SPRITE_SIZE(64x64),
2018-09-06 01:47:29 +02:00
.tileNum = 0,
.priority = 1,
.paletteNum = 0,
.affineParam = 0,
};
2019-12-10 19:48:20 +01:00
static const u8 sCursorCoords[][2] =
2018-09-06 01:47:29 +02:00
{
2019-12-10 19:48:20 +01:00
{60, 32},
{120, 56},
{180, 32},
2018-09-06 01:47:29 +02:00
};
2020-07-06 23:22:37 +02:00
static const union AnimCmd sAnim_Hand[] =
2018-09-06 01:47:29 +02:00
{
ANIMCMD_FRAME(48, 30),
ANIMCMD_END,
};
2020-07-06 23:22:37 +02:00
static const union AnimCmd sAnim_Pokeball_Still[] =
2018-09-06 01:47:29 +02:00
{
ANIMCMD_FRAME(0, 30),
ANIMCMD_END,
};
2020-07-06 23:22:37 +02:00
static const union AnimCmd sAnim_Pokeball_Moving[] =
2018-09-06 01:47:29 +02:00
{
ANIMCMD_FRAME(16, 4),
ANIMCMD_FRAME(0, 4),
ANIMCMD_FRAME(32, 4),
ANIMCMD_FRAME(0, 4),
ANIMCMD_FRAME(16, 4),
ANIMCMD_FRAME(0, 4),
ANIMCMD_FRAME(32, 4),
ANIMCMD_FRAME(0, 4),
ANIMCMD_FRAME(0, 32),
ANIMCMD_FRAME(16, 8),
ANIMCMD_FRAME(0, 8),
ANIMCMD_FRAME(32, 8),
ANIMCMD_FRAME(0, 8),
ANIMCMD_FRAME(16, 8),
ANIMCMD_FRAME(0, 8),
ANIMCMD_FRAME(32, 8),
ANIMCMD_FRAME(0, 8),
ANIMCMD_JUMP(0),
};
2020-07-06 23:22:37 +02:00
static const union AnimCmd sAnim_StarterCircle[] =
2018-09-06 01:47:29 +02:00
{
ANIMCMD_FRAME(0, 8),
ANIMCMD_END,
};
2020-07-06 23:22:37 +02:00
static const union AnimCmd * const sAnims_Hand[] =
2018-09-06 01:47:29 +02:00
{
2020-07-06 23:22:37 +02:00
sAnim_Hand,
2018-09-06 01:47:29 +02:00
};
2020-07-06 23:22:37 +02:00
static const union AnimCmd * const sAnims_Pokeball[] =
2018-09-06 01:47:29 +02:00
{
2020-07-06 23:22:37 +02:00
sAnim_Pokeball_Still,
sAnim_Pokeball_Moving,
2018-09-06 01:47:29 +02:00
};
2020-07-06 23:22:37 +02:00
static const union AnimCmd * const sAnims_StarterCircle[] =
2018-09-06 01:47:29 +02:00
{
2020-07-06 23:22:37 +02:00
sAnim_StarterCircle,
2018-09-06 01:47:29 +02:00
};
2020-07-06 23:22:37 +02:00
static const union AffineAnimCmd sAffineAnim_StarterPokemon[] =
2018-09-06 01:47:29 +02:00
{
AFFINEANIMCMD_FRAME(16, 16, 0, 0),
AFFINEANIMCMD_FRAME(16, 16, 0, 15),
AFFINEANIMCMD_END,
};
2020-07-06 23:22:37 +02:00
static const union AffineAnimCmd sAffineAnim_StarterCircle[] =
2018-09-06 01:47:29 +02:00
{
AFFINEANIMCMD_FRAME(20, 20, 0, 0),
AFFINEANIMCMD_FRAME(20, 20, 0, 15),
AFFINEANIMCMD_END,
};
2020-07-06 23:22:37 +02:00
static const union AffineAnimCmd * const sAffineAnims_StarterPokemon = {sAffineAnim_StarterPokemon};
static const union AffineAnimCmd * const sAffineAnims_StarterCircle[] = {sAffineAnim_StarterCircle};
2018-09-06 01:47:29 +02:00
2020-07-06 23:22:37 +02:00
static const struct CompressedSpriteSheet sSpriteSheet_PokeballSelect[] =
2018-09-06 01:47:29 +02:00
{
{
2020-07-06 23:22:37 +02:00
.data = gPokeballSelection_Gfx,
.size = 0x0800,
2020-07-06 23:22:37 +02:00
.tag = TAG_POKEBALL_SELECT
},
{}
2018-09-06 01:47:29 +02:00
};
2020-07-06 23:22:37 +02:00
static const struct CompressedSpriteSheet sSpriteSheet_StarterCircle[] =
2018-09-06 01:47:29 +02:00
{
{
2020-07-06 23:22:37 +02:00
.data = sStarterCircle_Gfx,
.size = 0x0800,
2020-07-06 23:22:37 +02:00
.tag = TAG_STARTER_CIRCLE
},
{}
2018-09-06 01:47:29 +02:00
};
2020-07-06 23:22:37 +02:00
static const struct SpritePalette sSpritePalettes_StarterChoose[] =
2018-09-06 01:47:29 +02:00
{
{
2020-07-06 23:22:37 +02:00
.data = sPokeballSelection_Pal,
.tag = TAG_POKEBALL_SELECT
},
{
2020-07-06 23:22:37 +02:00
.data = sStarterCircle_Pal,
.tag = TAG_STARTER_CIRCLE
},
{},
2018-09-06 01:47:29 +02:00
};
static const struct SpriteTemplate sSpriteTemplate_Hand =
{
2020-07-06 23:22:37 +02:00
.tileTag = TAG_POKEBALL_SELECT,
.paletteTag = TAG_POKEBALL_SELECT,
.oam = &sOam_Hand,
.anims = sAnims_Hand,
2018-09-06 01:47:29 +02:00
.images = NULL,
.affineAnims = gDummySpriteAffineAnimTable,
2020-07-06 23:22:37 +02:00
.callback = SpriteCB_SelectionHand
2018-09-06 01:47:29 +02:00
};
2020-07-06 23:22:37 +02:00
static const struct SpriteTemplate sSpriteTemplate_Pokeball =
2018-09-06 01:47:29 +02:00
{
2020-07-06 23:22:37 +02:00
.tileTag = TAG_POKEBALL_SELECT,
.paletteTag = TAG_POKEBALL_SELECT,
.oam = &sOam_Pokeball,
.anims = sAnims_Pokeball,
2018-09-06 01:47:29 +02:00
.images = NULL,
.affineAnims = gDummySpriteAffineAnimTable,
2020-07-06 23:22:37 +02:00
.callback = SpriteCB_Pokeball
2018-09-06 01:47:29 +02:00
};
2020-07-06 23:22:37 +02:00
static const struct SpriteTemplate sSpriteTemplate_StarterCircle =
2018-09-06 01:47:29 +02:00
{
2020-07-06 23:22:37 +02:00
.tileTag = TAG_STARTER_CIRCLE,
.paletteTag = TAG_STARTER_CIRCLE,
.oam = &sOam_StarterCircle,
.anims = sAnims_StarterCircle,
2018-09-06 01:47:29 +02:00
.images = NULL,
2020-07-06 23:22:37 +02:00
.affineAnims = sAffineAnims_StarterCircle,
.callback = SpriteCB_StarterPokemon
2018-09-06 01:47:29 +02:00
};
// .text
2017-11-08 18:05:47 +01:00
u16 GetStarterPokemon(u16 chosenStarterId)
{
if (chosenStarterId > STARTER_MON_COUNT)
chosenStarterId = 0;
2017-11-13 18:30:17 +01:00
return sStarterMon[chosenStarterId];
2017-11-08 18:05:47 +01:00
}
static void VblankCB_StarterChoose(void)
{
LoadOam();
ProcessSpriteCopyRequests();
TransferPlttBuffer();
}
2020-07-06 23:22:37 +02:00
// Data for Task_StarterChoose
2017-11-08 18:05:47 +01:00
#define tStarterSelection data[0]
#define tPkmnSpriteId data[1]
#define tCircleSpriteId data[2]
2020-07-06 23:22:37 +02:00
// Data for sSpriteTemplate_Pokeball
#define sTaskId data[0]
#define sBallId data[1]
2017-11-08 18:05:47 +01:00
void CB2_ChooseStarter(void)
{
u8 taskId;
u8 spriteId;
SetVBlankCallback(NULL);
SetGpuReg(REG_OFFSET_DISPCNT, 0);
SetGpuReg(REG_OFFSET_BG3CNT, 0);
SetGpuReg(REG_OFFSET_BG2CNT, 0);
SetGpuReg(REG_OFFSET_BG1CNT, 0);
SetGpuReg(REG_OFFSET_BG0CNT, 0);
2021-11-04 04:02:06 +01:00
ChangeBgX(0, 0, BG_COORD_SET);
ChangeBgY(0, 0, BG_COORD_SET);
ChangeBgX(1, 0, BG_COORD_SET);
ChangeBgY(1, 0, BG_COORD_SET);
ChangeBgX(2, 0, BG_COORD_SET);
ChangeBgY(2, 0, BG_COORD_SET);
ChangeBgX(3, 0, BG_COORD_SET);
ChangeBgY(3, 0, BG_COORD_SET);
2017-11-08 18:05:47 +01:00
DmaFill16(3, 0, VRAM, VRAM_SIZE);
DmaFill32(3, 0, OAM, OAM_SIZE);
DmaFill16(3, 0, PLTT, PLTT_SIZE);
2018-10-21 09:24:57 +02:00
LZ77UnCompVram(gBirchHelpGfx, (void *)VRAM);
LZ77UnCompVram(gBirchBagTilemap, (void *)(BG_SCREEN_ADDR(6)));
LZ77UnCompVram(gBirchGrassTilemap, (void *)(BG_SCREEN_ADDR(7)));
2017-11-08 18:05:47 +01:00
ResetBgsAndClearDma3BusyFlags(0);
2020-07-06 23:22:37 +02:00
InitBgsFromTemplates(0, sBgTemplates, ARRAY_COUNT(sBgTemplates));
InitWindows(sWindowTemplates);
2017-11-08 18:05:47 +01:00
DeactivateAllTextPrinters();
2018-07-15 13:23:38 +02:00
LoadUserWindowBorderGfx(0, 0x2A8, 0xD0);
ClearScheduledBgCopiesToVram();
2018-01-16 18:59:06 +01:00
ScanlineEffect_Stop();
2017-11-08 18:05:47 +01:00
ResetTasks();
ResetSpriteData();
ResetPaletteFade();
FreeAllSpritePalettes();
2018-08-19 01:06:10 +02:00
ResetAllPicSprites();
2017-11-08 18:05:47 +01:00
LoadPalette(GetOverworldTextboxPalettePtr(), 0xE0, 0x20);
LoadPalette(gBirchBagGrassPal, 0, 0x40);
2020-07-06 23:22:37 +02:00
LoadCompressedSpriteSheet(&sSpriteSheet_PokeballSelect[0]);
LoadCompressedSpriteSheet(&sSpriteSheet_StarterCircle[0]);
LoadSpritePalettes(sSpritePalettes_StarterChoose);
2021-02-24 17:01:02 +01:00
BeginNormalPaletteFade(PALETTES_ALL, 0, 0x10, 0, RGB_BLACK);
2017-11-08 18:05:47 +01:00
EnableInterrupts(DISPSTAT_VBLANK);
SetVBlankCallback(VblankCB_StarterChoose);
2020-07-06 23:22:37 +02:00
SetMainCallback2(CB2_StarterChoose);
2017-11-08 18:05:47 +01:00
2020-07-06 23:22:37 +02:00
SetGpuReg(REG_OFFSET_WININ, WININ_WIN0_BG_ALL | WININ_WIN0_OBJ | WININ_WIN0_CLR);
SetGpuReg(REG_OFFSET_WINOUT, WINOUT_WIN01_BG_ALL | WINOUT_WIN01_OBJ);
2017-11-08 18:05:47 +01:00
SetGpuReg(REG_OFFSET_WIN0H, 0);
SetGpuReg(REG_OFFSET_WIN0V, 0);
2018-12-26 13:43:07 +01:00
SetGpuReg(REG_OFFSET_BLDCNT, BLDCNT_TGT1_BG1 | BLDCNT_TGT1_BG2 | BLDCNT_TGT1_BG3 | BLDCNT_TGT1_OBJ | BLDCNT_TGT1_BD | BLDCNT_EFFECT_DARKEN);
2017-11-08 18:05:47 +01:00
SetGpuReg(REG_OFFSET_BLDALPHA, 0);
SetGpuReg(REG_OFFSET_BLDY, 7);
SetGpuReg(REG_OFFSET_DISPCNT, DISPCNT_WIN0_ON | DISPCNT_OBJ_ON | DISPCNT_OBJ_1D_MAP);
ShowBg(0);
ShowBg(2);
ShowBg(3);
2020-07-06 23:22:37 +02:00
taskId = CreateTask(Task_StarterChoose, 0);
2017-11-08 18:05:47 +01:00
gTasks[taskId].tStarterSelection = 1;
// Create hand sprite
spriteId = CreateSprite(&sSpriteTemplate_Hand, 120, 56, 2);
2017-12-02 21:44:50 +01:00
gSprites[spriteId].data[0] = taskId;
2017-11-08 18:05:47 +01:00
// Create three Pokeball sprites
2020-07-06 23:22:37 +02:00
spriteId = CreateSprite(&sSpriteTemplate_Pokeball, sPokeballCoords[0][0], sPokeballCoords[0][1], 2);
gSprites[spriteId].sTaskId = taskId;
gSprites[spriteId].sBallId = 0;
2017-11-08 18:05:47 +01:00
2020-07-06 23:22:37 +02:00
spriteId = CreateSprite(&sSpriteTemplate_Pokeball, sPokeballCoords[1][0], sPokeballCoords[1][1], 2);
gSprites[spriteId].sTaskId = taskId;
gSprites[spriteId].sBallId = 1;
2017-11-08 18:05:47 +01:00
2020-07-06 23:22:37 +02:00
spriteId = CreateSprite(&sSpriteTemplate_Pokeball, sPokeballCoords[2][0], sPokeballCoords[2][1], 2);
gSprites[spriteId].sTaskId = taskId;
gSprites[spriteId].sBallId = 2;
2017-11-08 18:05:47 +01:00
2021-02-20 05:22:26 +01:00
sStarterLabelWindowId = WINDOW_NONE;
2017-11-08 18:05:47 +01:00
}
2020-07-06 23:22:37 +02:00
static void CB2_StarterChoose(void)
2017-11-08 18:05:47 +01:00
{
RunTasks();
AnimateSprites();
BuildOamBuffer();
DoScheduledBgTilemapCopiesToVram();
2017-11-08 18:05:47 +01:00
UpdatePaletteFade();
}
2020-07-06 23:22:37 +02:00
static void Task_StarterChoose(u8 taskId)
2017-11-08 18:05:47 +01:00
{
CreateStarterPokemonLabel(gTasks[taskId].tStarterSelection);
DrawStdFrameWithCustomTileAndPalette(0, FALSE, 0x2A8, 0xD);
2021-10-30 22:47:37 +02:00
AddTextPrinterParameterized(0, FONT_NORMAL, gText_BirchInTrouble, 0, 1, 0, NULL);
2017-11-08 18:05:47 +01:00
PutWindowTilemap(0);
2020-05-14 10:37:09 +02:00
ScheduleBgCopyTilemapToVram(0);
2020-07-06 23:22:37 +02:00
gTasks[taskId].func = Task_HandleStarterChooseInput;
2017-11-08 18:05:47 +01:00
}
2020-07-06 23:22:37 +02:00
static void Task_HandleStarterChooseInput(u8 taskId)
2017-11-08 18:05:47 +01:00
{
u8 selection = gTasks[taskId].tStarterSelection;
2020-07-06 23:22:37 +02:00
if (JOY_NEW(A_BUTTON))
2017-11-08 18:05:47 +01:00
{
u8 spriteId;
2020-07-06 23:22:37 +02:00
ClearStarterLabel();
2017-11-08 18:05:47 +01:00
// Create white circle background
2020-07-06 23:22:37 +02:00
spriteId = CreateSprite(&sSpriteTemplate_StarterCircle, sPokeballCoords[selection][0], sPokeballCoords[selection][1], 1);
2017-11-08 18:05:47 +01:00
gTasks[taskId].tCircleSpriteId = spriteId;
// Create Pokemon sprite
spriteId = CreatePokemonFrontSprite(GetStarterPokemon(gTasks[taskId].tStarterSelection), sPokeballCoords[selection][0], sPokeballCoords[selection][1]);
2020-07-06 23:22:37 +02:00
gSprites[spriteId].affineAnims = &sAffineAnims_StarterPokemon;
gSprites[spriteId].callback = SpriteCB_StarterPokemon;
2017-11-08 18:05:47 +01:00
gTasks[taskId].tPkmnSpriteId = spriteId;
2020-07-06 23:22:37 +02:00
gTasks[taskId].func = Task_WaitForStarterSprite;
2017-11-08 18:05:47 +01:00
}
2020-07-06 23:22:37 +02:00
else if (JOY_NEW(DPAD_LEFT) && selection > 0)
2017-11-08 18:05:47 +01:00
{
gTasks[taskId].tStarterSelection--;
gTasks[taskId].func = Task_MoveStarterChooseCursor;
}
2020-07-06 23:22:37 +02:00
else if (JOY_NEW(DPAD_RIGHT) && selection < STARTER_MON_COUNT - 1)
2017-11-08 18:05:47 +01:00
{
gTasks[taskId].tStarterSelection++;
gTasks[taskId].func = Task_MoveStarterChooseCursor;
}
}
2020-07-06 23:22:37 +02:00
static void Task_WaitForStarterSprite(u8 taskId)
2017-11-08 18:05:47 +01:00
{
if (gSprites[gTasks[taskId].tCircleSpriteId].affineAnimEnded &&
2021-07-07 15:11:52 +02:00
gSprites[gTasks[taskId].tCircleSpriteId].x == STARTER_PKMN_POS_X &&
gSprites[gTasks[taskId].tCircleSpriteId].y == STARTER_PKMN_POS_Y)
2017-11-08 18:05:47 +01:00
{
2020-07-06 23:22:37 +02:00
gTasks[taskId].func = Task_AskConfirmStarter;
2017-11-08 18:05:47 +01:00
}
}
2020-07-06 23:22:37 +02:00
static void Task_AskConfirmStarter(u8 taskId)
2017-11-08 18:05:47 +01:00
{
2021-11-07 19:54:44 +01:00
PlayCry_Normal(GetStarterPokemon(gTasks[taskId].tStarterSelection), 0);
FillWindowPixelBuffer(0, PIXEL_FILL(1));
2021-10-30 22:47:37 +02:00
AddTextPrinterParameterized(0, FONT_NORMAL, gText_ConfirmStarterChoice, 0, 1, 0, NULL);
2020-05-14 10:37:09 +02:00
ScheduleBgCopyTilemapToVram(0);
2020-07-06 23:22:37 +02:00
CreateYesNoMenu(&sWindowTemplate_ConfirmStarter, 0x2A8, 0xD, 0);
gTasks[taskId].func = Task_HandleConfirmStarterInput;
2017-11-08 18:05:47 +01:00
}
2020-07-06 23:22:37 +02:00
static void Task_HandleConfirmStarterInput(u8 taskId)
2017-11-08 18:05:47 +01:00
{
u8 spriteId;
2018-11-05 21:45:54 +01:00
switch (Menu_ProcessInputNoWrapClearOnChoose())
2017-11-08 18:05:47 +01:00
{
case 0: // YES
// Return the starter choice and exit.
gSpecialVar_Result = gTasks[taskId].tStarterSelection;
2018-08-19 01:06:10 +02:00
ResetAllPicSprites();
2017-11-08 18:05:47 +01:00
SetMainCallback2(gMain.savedCallback);
break;
case 1: // NO
2020-07-06 23:22:37 +02:00
case MENU_B_PRESSED:
2017-11-08 18:05:47 +01:00
PlaySE(SE_SELECT);
spriteId = gTasks[taskId].tPkmnSpriteId;
FreeOamMatrix(gSprites[spriteId].oam.matrixNum);
2018-08-19 01:06:10 +02:00
FreeAndDestroyMonPicSprite(spriteId);
2017-11-08 18:05:47 +01:00
spriteId = gTasks[taskId].tCircleSpriteId;
FreeOamMatrix(gSprites[spriteId].oam.matrixNum);
DestroySprite(&gSprites[spriteId]);
2020-07-06 23:22:37 +02:00
gTasks[taskId].func = Task_DeclineStarter;
2017-11-08 18:05:47 +01:00
break;
}
}
2020-07-06 23:22:37 +02:00
static void Task_DeclineStarter(u8 taskId)
2017-11-08 18:05:47 +01:00
{
2020-07-06 23:22:37 +02:00
gTasks[taskId].func = Task_StarterChoose;
2017-11-08 18:05:47 +01:00
}
static void CreateStarterPokemonLabel(u8 selection)
{
2019-12-10 19:48:20 +01:00
u8 categoryText[32];
2017-11-08 18:05:47 +01:00
struct WindowTemplate winTemplate;
const u8 *speciesName;
s32 width;
u8 labelLeft, labelRight, labelTop, labelBottom;
u16 species = GetStarterPokemon(selection);
2019-12-10 19:48:20 +01:00
CopyMonCategoryText(SpeciesToNationalPokedexNum(species), categoryText);
2017-11-08 18:05:47 +01:00
speciesName = gSpeciesNames[species];
2020-07-06 23:22:37 +02:00
winTemplate = sWindowTemplate_StarterLabel;
2019-12-10 19:48:20 +01:00
winTemplate.tilemapLeft = sStarterLabelCoords[selection][0];
winTemplate.tilemapTop = sStarterLabelCoords[selection][1];
2017-11-08 18:05:47 +01:00
2020-07-06 23:22:37 +02:00
sStarterLabelWindowId = AddWindow(&winTemplate);
FillWindowPixelBuffer(sStarterLabelWindowId, PIXEL_FILL(0));
2017-11-08 18:05:47 +01:00
2021-10-30 22:47:37 +02:00
width = GetStringCenterAlignXOffset(FONT_NARROW, categoryText, 0x68);
AddTextPrinterParameterized3(sStarterLabelWindowId, FONT_NARROW, width, 1, sTextColors, 0, categoryText);
2017-11-08 18:05:47 +01:00
2021-10-30 22:47:37 +02:00
width = GetStringCenterAlignXOffset(FONT_NORMAL, speciesName, 0x68);
AddTextPrinterParameterized3(sStarterLabelWindowId, FONT_NORMAL, width, 17, sTextColors, 0, speciesName);
2017-11-08 18:05:47 +01:00
2020-07-06 23:22:37 +02:00
PutWindowTilemap(sStarterLabelWindowId);
2020-05-14 10:37:09 +02:00
ScheduleBgCopyTilemapToVram(0);
2017-11-08 18:05:47 +01:00
2019-12-10 19:48:20 +01:00
labelLeft = sStarterLabelCoords[selection][0] * 8 - 4;
labelRight = (sStarterLabelCoords[selection][0] + 13) * 8 + 4;
labelTop = sStarterLabelCoords[selection][1] * 8;
labelBottom = (sStarterLabelCoords[selection][1] + 4) * 8;
2017-11-08 18:05:47 +01:00
SetGpuReg(REG_OFFSET_WIN0H, WIN_RANGE(labelLeft, labelRight));
SetGpuReg(REG_OFFSET_WIN0V, WIN_RANGE(labelTop, labelBottom));
}
2020-07-06 23:22:37 +02:00
static void ClearStarterLabel(void)
2017-11-08 18:05:47 +01:00
{
2020-07-06 23:22:37 +02:00
FillWindowPixelBuffer(sStarterLabelWindowId, PIXEL_FILL(0));
ClearWindowTilemap(sStarterLabelWindowId);
RemoveWindow(sStarterLabelWindowId);
2021-02-20 00:36:48 +01:00
sStarterLabelWindowId = WINDOW_NONE;
2017-11-08 18:05:47 +01:00
SetGpuReg(REG_OFFSET_WIN0H, 0);
SetGpuReg(REG_OFFSET_WIN0V, 0);
2020-05-14 10:37:09 +02:00
ScheduleBgCopyTilemapToVram(0);
2017-11-08 18:05:47 +01:00
}
static void Task_MoveStarterChooseCursor(u8 taskId)
{
2020-07-06 23:22:37 +02:00
ClearStarterLabel();
gTasks[taskId].func = Task_CreateStarterLabel;
2017-11-08 18:05:47 +01:00
}
2020-07-06 23:22:37 +02:00
static void Task_CreateStarterLabel(u8 taskId)
2017-11-08 18:05:47 +01:00
{
CreateStarterPokemonLabel(gTasks[taskId].tStarterSelection);
2020-07-06 23:22:37 +02:00
gTasks[taskId].func = Task_HandleStarterChooseInput;
2017-11-08 18:05:47 +01:00
}
static u8 CreatePokemonFrontSprite(u16 species, u8 x, u8 y)
{
u8 spriteId;
2021-10-18 07:39:07 +02:00
spriteId = CreateMonPicSprite_Affine(species, SHINY_ODDS, 0, MON_PIC_AFFINE_FRONT, x, y, 14, TAG_NONE);
2017-11-08 18:05:47 +01:00
gSprites[spriteId].oam.priority = 0;
return spriteId;
}
2020-07-06 23:22:37 +02:00
static void SpriteCB_SelectionHand(struct Sprite *sprite)
2017-11-08 18:05:47 +01:00
{
2020-07-06 23:22:37 +02:00
// Float up and down above selected pokeball
2021-07-07 15:11:52 +02:00
sprite->x = sCursorCoords[gTasks[sprite->data[0]].tStarterSelection][0];
sprite->y = sCursorCoords[gTasks[sprite->data[0]].tStarterSelection][1];
sprite->y2 = Sin(sprite->data[1], 8);
2017-12-02 21:44:50 +01:00
sprite->data[1] = (u8)(sprite->data[1]) + 4;
2017-11-08 18:05:47 +01:00
}
2020-07-06 23:22:37 +02:00
static void SpriteCB_Pokeball(struct Sprite *sprite)
2017-11-08 18:05:47 +01:00
{
2020-07-06 23:22:37 +02:00
// Animate pokeball if currently selected
if (gTasks[sprite->sTaskId].tStarterSelection == sprite->sBallId)
2017-11-08 18:05:47 +01:00
StartSpriteAnimIfDifferent(sprite, 1);
else
StartSpriteAnimIfDifferent(sprite, 0);
}
2020-07-06 23:22:37 +02:00
static void SpriteCB_StarterPokemon(struct Sprite *sprite)
2017-11-08 18:05:47 +01:00
{
2020-07-06 23:22:37 +02:00
// Move sprite to upper center of screen
2021-07-07 15:11:52 +02:00
if (sprite->x > STARTER_PKMN_POS_X)
sprite->x -= 4;
if (sprite->x < STARTER_PKMN_POS_X)
sprite->x += 4;
if (sprite->y > STARTER_PKMN_POS_Y)
sprite->y -= 2;
if (sprite->y < STARTER_PKMN_POS_Y)
sprite->y += 2;
2017-11-08 18:05:47 +01:00
}