pokeemerald/src/move_relearner.c

977 lines
32 KiB
C
Raw Normal View History

#include "global.h"
#include "main.h"
#include "battle.h"
#include "bg.h"
#include "contest_effect.h"
2019-04-04 23:53:06 +02:00
#include "data.h"
#include "event_data.h"
#include "field_screen_effect.h"
#include "gpu_regs.h"
2019-03-05 02:56:39 +01:00
#include "move_relearner.h"
#include "list_menu.h"
#include "malloc.h"
#include "menu.h"
#include "menu_helpers.h"
#include "menu_specialized.h"
#include "overworld.h"
#include "palette.h"
#include "pokemon_summary_screen.h"
#include "script.h"
#include "sound.h"
#include "sprite.h"
#include "string_util.h"
#include "strings.h"
#include "task.h"
#include "constants/rgb.h"
#include "constants/songs.h"
/*
2019-03-05 02:56:39 +01:00
* Move relearner state machine
* ------------------------
*
2019-03-05 02:56:39 +01:00
* Entry point: TeachMoveRelearnerMove
*
2019-03-05 02:56:39 +01:00
* TeachMoveRelearnerMove
* Task_WaitForFadeOut
* CB2_InitLearnMove
* - Creates moveDisplayArrowTask to listen to right/left buttons.
* - Creates moveListScrollArrowTask to listen to up/down buttons.
2019-03-05 02:56:39 +01:00
* - Whenever the selected move changes (and once on init), the MoveRelearnerCursorCallback
2019-03-08 08:10:44 +01:00
* is called (see sMoveRelearnerMovesListTemplate). That callback will reload the contest
* display and battle display windows for the new move. Both are always loaded in
* memory, but only the currently active one is copied to VRAM. The exception to this
2019-03-05 02:56:39 +01:00
* is the appeal and jam hearts, which are sprites. MoveRelearnerShowHideHearts is called
* while reloading the contest display to control them.
2019-03-05 02:56:39 +01:00
* DoMoveRelearnerMain: MENU_STATE_FADE_TO_BLACK
* DoMoveRelearnerMain: MENU_STATE_WAIT_FOR_FADE
* - Go to MENU_STATE_IDLE_BATTLE_MODE
*
2019-03-05 02:56:39 +01:00
* DoMoveRelearnerMain: MENU_STATE_SETUP_BATTLE_MODE
* DoMoveRelearnerMain: MENU_STATE_IDLE_BATTLE_MODE
* - If the player selected a move (pressed A), go to MENU_STATE_PRINT_TEACH_MOVE_PROMPT.
* - If the player cancelled (pressed B), go to MENU_STATE_PRINT_GIVE_UP_PROMPT.
* - If the player pressed left or right, swap the move display window to contest mode,
* and go to MENU_STATE_SETUP_CONTEST_MODE.
*
2019-03-05 02:56:39 +01:00
* DoMoveRelearnerMain: MENU_STATE_SETUP_CONTEST_MODE
* DoMoveRelearnerMain: MENU_STATE_IDLE_CONTEST_MODE
* - If the player selected a move, go to MENU_STATE_PRINT_TEACH_MOVE_PROMPT.
* - If the player cancelled, go to MENU_STATE_PRINT_GIVE_UP_PROMPT
* - If the player pressed left or right, swap the move display window to battle mode,
* and go to MENU_STATE_SETUP_BATTLE_MODE.
*
2019-03-05 02:56:39 +01:00
* DoMoveRelearnerMain: MENU_STATE_PRINT_TEACH_MOVE_PROMPT
* DoMoveRelearnerMain: MENU_STATE_TEACH_MOVE_CONFIRM
* - Wait for the player to confirm.
* - If cancelled, go to either MENU_STATE_SETUP_BATTLE_MODE or MENU_STATE_SETUP_CONTEST_MODE.
* - If confirmed and the pokemon had an empty move slot, set VAR_0x8004 to TRUE and go to
* MENU_STATE_PRINT_TEXT_THEN_FANFARE.
* - If confirmed and the pokemon doesn't have an empty move slot, go to
* MENU_STATE_PRINT_TRYING_TO_LEARN_PROMPT.
*
2019-03-05 02:56:39 +01:00
* DoMoveRelearnerMain: MENU_STATE_PRINT_TRYING_TO_LEARN_PROMPT
* DoMoveRelearnerMain: MENU_STATE_WAIT_FOR_TRYING_TO_LEARN
* DoMoveRelearnerMain: MENU_STATE_CONFIRM_DELETE_OLD_MOVE
* - If the player confirms, go to MENU_STATE_PRINT_WHICH_MOVE_PROMPT.
* - If the player cancels, go to MENU_STATE_PRINT_STOP_TEACHING
*
2019-03-05 02:56:39 +01:00
* DoMoveRelearnerMain: MENU_STATE_PRINT_STOP_TEACHING
* DoMoveRelearnerMain: MENU_STATE_WAIT_FOR_STOP_TEACHING
* DoMoveRelearnerMain: MENU_STATE_CONFIRM_STOP_TEACHING
* - If the player confirms, go to MENU_STATE_CHOOSE_SETUP_STATE.
* - If the player cancels, go back to MENU_STATE_PRINT_TRYING_TO_LEARN_PROMPT.
*
2019-03-05 02:56:39 +01:00
* DoMoveRelearnerMain: MENU_STATE_PRINT_WHICH_MOVE_PROMPT
* DoMoveRelearnerMain: MENU_STATE_SHOW_MOVE_SUMMARY_SCREEN
* - Go to ShowSelectMovePokemonSummaryScreen. When done, control returns to
* CB2_InitLearnMoveReturnFromSelectMove.
*
2019-03-05 02:56:39 +01:00
* DoMoveRelearnerMain: MENU_STATE_DOUBLE_FANFARE_FORGOT_MOVE
* DoMoveRelearnerMain: MENU_STATE_PRINT_TEXT_THEN_FANFARE
* DoMoveRelearnerMain: MENU_STATE_WAIT_FOR_FANFARE
* DoMoveRelearnerMain: MENU_STATE_WAIT_FOR_A_BUTTON
* DoMoveRelearnerMain: MENU_STATE_FADE_AND_RETURN
* DoMoveRelearnerMain: MENU_STATE_RETURN_TO_FIELD
* - Clean up and go to CB2_ReturnToField.
*
2019-03-05 02:56:39 +01:00
* DoMoveRelearnerMain: MENU_STATE_PRINT_GIVE_UP_PROMPT
* DoMoveRelearnerMain: MENU_STATE_GIVE_UP_CONFIRM
* - If the player confirms, go to MENU_STATE_FADE_AND_RETURN, and set VAR_0x8004 to FALSE.
* - If the player cancels, go to either MENU_STATE_SETUP_BATTLE_MODE or
* MENU_STATE_SETUP_CONTEST_MODE.
*
* CB2_InitLearnMoveReturnFromSelectMove:
* - Do most of the same stuff as CB2_InitLearnMove.
2019-03-05 02:56:39 +01:00
* DoMoveRelearnerMain: MENU_STATE_FADE_FROM_SUMMARY_SCREEN
* DoMoveRelearnerMain: MENU_STATE_TRY_OVERWRITE_MOVE
* - If any of the pokemon's existing moves were chosen, overwrite the move and
* go to MENU_STATE_DOUBLE_FANFARE_FORGOT_MOVE and set VAR_0x8004 to TRUE.
* - If the chosen move is the one the player selected before the summary screen,
* go to MENU_STATE_PRINT_STOP_TEACHING.
*
*/
#define MENU_STATE_FADE_TO_BLACK 0
#define MENU_STATE_WAIT_FOR_FADE 1
#define MENU_STATE_UNREACHABLE 2
#define MENU_STATE_SETUP_BATTLE_MODE 3
#define MENU_STATE_IDLE_BATTLE_MODE 4
#define MENU_STATE_SETUP_CONTEST_MODE 5
#define MENU_STATE_IDLE_CONTEST_MODE 6
// State 7 is skipped.
#define MENU_STATE_PRINT_TEACH_MOVE_PROMPT 8
#define MENU_STATE_TEACH_MOVE_CONFIRM 9
// States 10 and 11 are skipped.
#define MENU_STATE_PRINT_GIVE_UP_PROMPT 12
#define MENU_STATE_GIVE_UP_CONFIRM 13
#define MENU_STATE_FADE_AND_RETURN 14
#define MENU_STATE_RETURN_TO_FIELD 15
#define MENU_STATE_PRINT_TRYING_TO_LEARN_PROMPT 16
#define MENU_STATE_WAIT_FOR_TRYING_TO_LEARN 17
#define MENU_STATE_CONFIRM_DELETE_OLD_MOVE 18
#define MENU_STATE_PRINT_WHICH_MOVE_PROMPT 19
#define MENU_STATE_SHOW_MOVE_SUMMARY_SCREEN 20
// States 21, 22, and 23 are skipped.
#define MENU_STATE_PRINT_STOP_TEACHING 24
#define MENU_STATE_WAIT_FOR_STOP_TEACHING 25
#define MENU_STATE_CONFIRM_STOP_TEACHING 26
#define MENU_STATE_CHOOSE_SETUP_STATE 27
#define MENU_STATE_FADE_FROM_SUMMARY_SCREEN 28
#define MENU_STATE_TRY_OVERWRITE_MOVE 29
#define MENU_STATE_DOUBLE_FANFARE_FORGOT_MOVE 30
#define MENU_STATE_PRINT_TEXT_THEN_FANFARE 31
#define MENU_STATE_WAIT_FOR_FANFARE 32
#define MENU_STATE_WAIT_FOR_A_BUTTON 33
// The different versions of hearts are selected using animation
// commands.
#define APPEAL_HEART_EMPTY 0
#define APPEAL_HEART_FULL 1
#define JAM_HEART_EMPTY 2
#define JAM_HEART_FULL 3
2020-08-29 01:02:20 +02:00
#define MAX_RELEARNER_MOVES (MAX_LEVEL_UP_MOVES > 25 ? MAX_LEVEL_UP_MOVES : 25)
static EWRAM_DATA struct
{
u8 state;
2020-08-29 01:09:17 +02:00
u8 heartSpriteIds[16]; /*0x001*/
2020-08-29 01:02:20 +02:00
u16 movesToLearn[MAX_RELEARNER_MOVES]; /*0x01A*/
2020-08-29 01:09:17 +02:00
u8 partyMon; /*0x044*/
u8 moveSlot; /*0x045*/
2020-08-29 01:02:20 +02:00
struct ListMenuItem menuItems[MAX_RELEARNER_MOVES]; /*0x0E8*/
2020-08-29 01:09:17 +02:00
u8 numMenuChoices; /*0x110*/
u8 numToShowAtOnce; /*0x111*/
u8 moveListMenuTask; /*0x112*/
u8 moveListScrollArrowTask; /*0x113*/
u8 moveDisplayArrowTask; /*0x114*/
u16 scrollOffset; /*0x116*/
2019-03-05 02:56:39 +01:00
} *sMoveRelearnerStruct = {0};
static EWRAM_DATA struct {
u16 listOffset;
u16 listRow;
bool8 showContestInfo;
2019-03-05 02:56:39 +01:00
} sMoveRelearnerMenuSate = {0};
2019-03-05 02:56:39 +01:00
static const u16 sMoveRelearnerPaletteData[] = INCBIN_U16("graphics/interface/ui_learn_move.gbapal");
// The arrow sprites in this spritesheet aren't used. The scroll-arrow system provides its own
// arrow sprites.
2019-03-05 02:56:39 +01:00
static const u8 sMoveRelearnerSpriteSheetData[] = INCBIN_U8("graphics/interface/ui_learn_move.4bpp");
static const struct OamData sHeartSpriteOamData =
{
.y = 0,
.affineMode = ST_OAM_AFFINE_OFF,
.objMode = ST_OAM_OBJ_NORMAL,
.mosaic = 0,
.bpp = ST_OAM_4BPP,
.shape = SPRITE_SHAPE(8x8),
.x = 0,
.matrixNum = 0,
.size = SPRITE_SIZE(8x8),
.tileNum = 0,
.priority = 0,
.paletteNum = 0,
.affineParam = 0,
};
static const struct OamData sUnusedOam1 =
{
.y = 0,
.affineMode = ST_OAM_AFFINE_OFF,
.objMode = ST_OAM_OBJ_NORMAL,
.mosaic = 0,
.bpp = ST_OAM_4BPP,
.shape = SPRITE_SHAPE(8x16),
.x = 0,
.matrixNum = 0,
.size = SPRITE_SIZE(8x16),
.tileNum = 0,
.priority = 0,
.paletteNum = 0,
.affineParam = 0,
};
static const struct OamData sUnusedOam2 =
{
.y = 0,
.affineMode = ST_OAM_AFFINE_OFF,
.objMode = ST_OAM_OBJ_NORMAL,
.mosaic = 0,
.bpp = ST_OAM_4BPP,
.shape = SPRITE_SHAPE(16x8),
.x = 0,
.matrixNum = 0,
.size = SPRITE_SIZE(16x8),
.tileNum = 0,
.priority = 0,
.paletteNum = 0,
.affineParam = 0,
};
2019-03-05 02:56:39 +01:00
static const struct SpriteSheet sMoveRelearnerSpriteSheet =
{
2019-03-05 02:56:39 +01:00
.data = sMoveRelearnerSpriteSheetData,
.size = 0x180,
.tag = 5525
};
2019-03-05 02:56:39 +01:00
static const struct SpritePalette sMoveRelearnerPalette =
{
2019-03-05 02:56:39 +01:00
.data = sMoveRelearnerPaletteData,
.tag = 5526
};
static const struct ScrollArrowsTemplate sDisplayModeArrowsTemplate =
{
.firstArrowType = SCROLL_ARROW_LEFT,
.firstX = 27,
.firstY = 16,
.secondArrowType = SCROLL_ARROW_RIGHT,
.secondX = 117,
.secondY = 16,
.fullyUpThreshold = -1,
.fullyDownThreshold = -1,
.tileTag = 5325,
.palTag = 5325,
.palNum = 0,
};
static const struct ScrollArrowsTemplate sMoveListScrollArrowsTemplate =
{
.firstArrowType = SCROLL_ARROW_UP,
.firstX = 192,
.firstY = 8,
.secondArrowType = SCROLL_ARROW_DOWN,
.secondX = 192,
.secondY = 104,
.fullyUpThreshold = 0,
.fullyDownThreshold = 0,
.tileTag = 5425,
.palTag = 5425,
.palNum = 0,
};
static const union AnimCmd sHeartSprite_AppealEmptyFrame[] =
{
ANIMCMD_FRAME(8, 5, FALSE, FALSE),
ANIMCMD_END
};
static const union AnimCmd sHeartSprite_AppealFullFrame[] =
{
ANIMCMD_FRAME(9, 5, FALSE, FALSE),
ANIMCMD_END
};
static const union AnimCmd sHeartSprite_JamEmptyFrame[] =
{
ANIMCMD_FRAME(10, 5, FALSE, FALSE),
ANIMCMD_END
};
static const union AnimCmd sHeartSprite_JamFullFrame[] =
{
ANIMCMD_FRAME(11, 5, FALSE, FALSE),
ANIMCMD_END
};
static const union AnimCmd *const sHeartSpriteAnimationCommands[] =
{
[APPEAL_HEART_EMPTY] = sHeartSprite_AppealEmptyFrame,
[APPEAL_HEART_FULL] = sHeartSprite_AppealFullFrame,
[JAM_HEART_EMPTY] = sHeartSprite_JamEmptyFrame,
[JAM_HEART_FULL] = sHeartSprite_JamFullFrame,
};
static const struct SpriteTemplate sConstestMoveHeartSprite =
{
.tileTag = 5525,
.paletteTag = 5526,
.oam = &sHeartSpriteOamData,
.anims = sHeartSpriteAnimationCommands,
.images = NULL,
.affineAnims = gDummySpriteAffineAnimTable,
.callback = SpriteCallbackDummy
};
2019-03-05 02:56:39 +01:00
static const struct BgTemplate sMoveRelearnerMenuBackgroundTemplates[] =
{
{
.bg = 0,
.charBaseIndex = 0,
.mapBaseIndex = 31,
.screenSize = 0,
.paletteMode = 0,
.priority = 0,
.baseTile = 0,
},
{
.bg = 1,
.charBaseIndex = 0,
.mapBaseIndex = 30,
.screenSize = 0,
.paletteMode = 0,
.priority = 1,
.baseTile = 0,
},
};
2019-03-05 02:56:39 +01:00
static void DoMoveRelearnerMain(void);
static void CreateLearnableMovesList(void);
static void CreateUISprites(void);
2019-03-05 02:56:39 +01:00
static void CB2_MoveRelearnerMain(void);
static void Task_WaitForFadeOut(u8 taskId);
static void CB2_InitLearnMove(void);
static void CB2_InitLearnMoveReturnFromSelectMove(void);
2019-03-05 02:56:39 +01:00
static void InitMoveRelearnerBackgroundLayers(void);
static void AddScrollArrows(void);
static void HandleInput(u8);
static void ShowTeachMoveText(u8);
static s32 GetCurrentSelectedMove(void);
2019-03-05 02:56:39 +01:00
static void FreeMoveRelearnerResources(void);
static void RemoveScrollArrows(void);
static void HideHeartSpritesAndShowTeachMoveText(bool8);
2019-03-05 02:56:39 +01:00
static void VBlankCB_MoveRelearner(void)
{
LoadOam();
ProcessSpriteCopyRequests();
TransferPlttBuffer();
}
// Script arguments: The pokemon to teach is in VAR_0x8004
2019-03-05 02:56:39 +01:00
void TeachMoveRelearnerMove(void)
{
ScriptContext2_Enable();
CreateTask(Task_WaitForFadeOut, 10);
// Fade to black
BeginNormalPaletteFade(0xFFFFFFFF, 0, 0, 0x10, RGB_BLACK);
}
static void Task_WaitForFadeOut(u8 taskId)
{
if (!gPaletteFade.active)
{
SetMainCallback2(CB2_InitLearnMove);
2019-12-17 09:24:44 +01:00
gFieldCallback = FieldCB_ContinueScriptHandleMusic;
DestroyTask(taskId);
}
}
static void CB2_InitLearnMove(void)
{
ResetSpriteData();
FreeAllSpritePalettes();
ResetTasks();
ClearScheduledBgCopiesToVram();
2019-03-05 02:56:39 +01:00
sMoveRelearnerStruct = AllocZeroed(sizeof(*sMoveRelearnerStruct));
sMoveRelearnerStruct->partyMon = gSpecialVar_0x8004;
SetVBlankCallback(VBlankCB_MoveRelearner);
2019-03-05 02:56:39 +01:00
InitMoveRelearnerBackgroundLayers();
InitMoveRelearnerWindows(FALSE);
2019-03-05 02:56:39 +01:00
sMoveRelearnerMenuSate.listOffset = 0;
sMoveRelearnerMenuSate.listRow = 0;
sMoveRelearnerMenuSate.showContestInfo = FALSE;
CreateLearnableMovesList();
2019-03-05 02:56:39 +01:00
LoadSpriteSheet(&sMoveRelearnerSpriteSheet);
LoadSpritePalette(&sMoveRelearnerPalette);
CreateUISprites();
2019-03-05 02:56:39 +01:00
sMoveRelearnerStruct->moveListMenuTask = ListMenuInit(&gMultiuseListMenuTemplate, sMoveRelearnerMenuSate.listOffset, sMoveRelearnerMenuSate.listRow);
FillPalette(RGB_BLACK, 0, 2);
2019-03-05 02:56:39 +01:00
SetMainCallback2(CB2_MoveRelearnerMain);
}
static void CB2_InitLearnMoveReturnFromSelectMove(void)
{
ResetSpriteData();
FreeAllSpritePalettes();
ResetTasks();
ClearScheduledBgCopiesToVram();
2019-03-05 02:56:39 +01:00
sMoveRelearnerStruct = AllocZeroed(sizeof(*sMoveRelearnerStruct));
sMoveRelearnerStruct->state = MENU_STATE_FADE_FROM_SUMMARY_SCREEN;
sMoveRelearnerStruct->partyMon = gSpecialVar_0x8004;
sMoveRelearnerStruct->moveSlot = gSpecialVar_0x8005;
SetVBlankCallback(VBlankCB_MoveRelearner);
InitMoveRelearnerBackgroundLayers();
InitMoveRelearnerWindows(sMoveRelearnerMenuSate.showContestInfo);
CreateLearnableMovesList();
2019-03-05 02:56:39 +01:00
LoadSpriteSheet(&sMoveRelearnerSpriteSheet);
LoadSpritePalette(&sMoveRelearnerPalette);
CreateUISprites();
2019-03-05 02:56:39 +01:00
sMoveRelearnerStruct->moveListMenuTask = ListMenuInit(&gMultiuseListMenuTemplate, sMoveRelearnerMenuSate.listOffset, sMoveRelearnerMenuSate.listRow);
FillPalette(RGB_BLACK, 0, 2);
2019-03-05 02:56:39 +01:00
SetMainCallback2(CB2_MoveRelearnerMain);
}
2019-03-05 02:56:39 +01:00
static void InitMoveRelearnerBackgroundLayers(void)
{
ResetVramOamAndBgCntRegs();
ResetBgsAndClearDma3BusyFlags(0);
2019-03-05 02:56:39 +01:00
InitBgsFromTemplates(0, sMoveRelearnerMenuBackgroundTemplates, ARRAY_COUNT(sMoveRelearnerMenuBackgroundTemplates));
ResetAllBgsCoordinates();
SetGpuReg(REG_OFFSET_DISPCNT, DISPCNT_MODE_0 |
DISPCNT_OBJ_1D_MAP |
DISPCNT_OBJ_ON);
ShowBg(0);
ShowBg(1);
SetGpuReg(REG_OFFSET_BLDCNT, 0);
}
2019-03-05 02:56:39 +01:00
static void CB2_MoveRelearnerMain(void)
{
2019-03-05 02:56:39 +01:00
DoMoveRelearnerMain();
RunTasks();
AnimateSprites();
BuildOamBuffer();
DoScheduledBgTilemapCopiesToVram();
UpdatePaletteFade();
}
static void FormatAndPrintText(const u8 *src)
{
StringExpandPlaceholders(gStringVar4, src);
2019-03-05 02:56:39 +01:00
MoveRelearnerPrintText(gStringVar4);
}
// See the state machine doc at the top of the file.
2019-03-05 02:56:39 +01:00
static void DoMoveRelearnerMain(void)
{
2019-03-05 02:56:39 +01:00
switch (sMoveRelearnerStruct->state)
{
case MENU_STATE_FADE_TO_BLACK:
2019-03-05 02:56:39 +01:00
sMoveRelearnerStruct->state++;
HideHeartSpritesAndShowTeachMoveText(FALSE);
BeginNormalPaletteFade(0xFFFFFFFF, 0, 16, 0, RGB_BLACK);
break;
case MENU_STATE_WAIT_FOR_FADE:
if (!gPaletteFade.active)
{
2019-03-05 02:56:39 +01:00
sMoveRelearnerStruct->state = MENU_STATE_IDLE_BATTLE_MODE;
}
break;
case MENU_STATE_UNREACHABLE:
2019-03-05 02:56:39 +01:00
sMoveRelearnerStruct->state++;
break;
case MENU_STATE_SETUP_BATTLE_MODE:
HideHeartSpritesAndShowTeachMoveText(FALSE);
2019-03-05 02:56:39 +01:00
sMoveRelearnerStruct->state++;
AddScrollArrows();
break;
case MENU_STATE_IDLE_BATTLE_MODE:
HandleInput(FALSE);
break;
case MENU_STATE_SETUP_CONTEST_MODE:
ShowTeachMoveText(FALSE);
2019-03-05 02:56:39 +01:00
sMoveRelearnerStruct->state++;
AddScrollArrows();
break;
case MENU_STATE_IDLE_CONTEST_MODE:
HandleInput(TRUE);
break;
case MENU_STATE_PRINT_TEACH_MOVE_PROMPT:
2019-03-05 02:56:39 +01:00
if (!MoveRelearnerRunTextPrinters())
{
2019-03-05 02:56:39 +01:00
MoveRelearnerCreateYesNoMenu();
sMoveRelearnerStruct->state++;
}
break;
case MENU_STATE_TEACH_MOVE_CONFIRM:
{
s8 selection = Menu_ProcessInputNoWrapClearOnChoose();
if (selection == 0)
{
2019-10-18 01:22:03 +02:00
if (GiveMoveToMon(&gPlayerParty[sMoveRelearnerStruct->partyMon], GetCurrentSelectedMove()) != MON_HAS_MAX_MOVES)
{
2019-03-05 02:56:39 +01:00
FormatAndPrintText(gText_MoveRelearnerPkmnLearnedMove);
gSpecialVar_0x8004 = TRUE;
2019-03-05 02:56:39 +01:00
sMoveRelearnerStruct->state = MENU_STATE_PRINT_TEXT_THEN_FANFARE;
}
else
{
2019-03-05 02:56:39 +01:00
sMoveRelearnerStruct->state = MENU_STATE_PRINT_TRYING_TO_LEARN_PROMPT;
}
}
else if (selection == MENU_B_PRESSED || selection == 1)
{
2019-03-05 02:56:39 +01:00
if (sMoveRelearnerMenuSate.showContestInfo == FALSE)
{
2019-03-05 02:56:39 +01:00
sMoveRelearnerStruct->state = MENU_STATE_SETUP_BATTLE_MODE;
}
2019-03-05 02:56:39 +01:00
else if (sMoveRelearnerMenuSate.showContestInfo == TRUE)
{
2019-03-05 02:56:39 +01:00
sMoveRelearnerStruct->state = MENU_STATE_SETUP_CONTEST_MODE;
}
}
}
break;
case MENU_STATE_PRINT_GIVE_UP_PROMPT:
2019-03-05 02:56:39 +01:00
if (!MoveRelearnerRunTextPrinters())
{
2019-03-05 02:56:39 +01:00
MoveRelearnerCreateYesNoMenu();
sMoveRelearnerStruct->state++;
}
break;
case MENU_STATE_GIVE_UP_CONFIRM:
{
s8 selection = Menu_ProcessInputNoWrapClearOnChoose();
if (selection == 0)
{
gSpecialVar_0x8004 = FALSE;
2019-03-05 02:56:39 +01:00
sMoveRelearnerStruct->state = MENU_STATE_FADE_AND_RETURN;
}
else if (selection == -1 || selection == 1)
{
2019-03-05 02:56:39 +01:00
if (sMoveRelearnerMenuSate.showContestInfo == FALSE)
{
2019-03-05 02:56:39 +01:00
sMoveRelearnerStruct->state = MENU_STATE_SETUP_BATTLE_MODE;
}
2019-03-05 02:56:39 +01:00
else if (sMoveRelearnerMenuSate.showContestInfo == TRUE)
{
2019-03-05 02:56:39 +01:00
sMoveRelearnerStruct->state = MENU_STATE_SETUP_CONTEST_MODE;
}
}
}
break;
case MENU_STATE_PRINT_TRYING_TO_LEARN_PROMPT:
2019-03-05 02:56:39 +01:00
FormatAndPrintText(gText_MoveRelearnerPkmnTryingToLearnMove);
sMoveRelearnerStruct->state++;
break;
case MENU_STATE_WAIT_FOR_TRYING_TO_LEARN:
2019-03-05 02:56:39 +01:00
if (!MoveRelearnerRunTextPrinters())
{
2019-03-05 02:56:39 +01:00
MoveRelearnerCreateYesNoMenu();
sMoveRelearnerStruct->state = MENU_STATE_CONFIRM_DELETE_OLD_MOVE;
}
break;
case MENU_STATE_CONFIRM_DELETE_OLD_MOVE:
{
s8 var = Menu_ProcessInputNoWrapClearOnChoose();
if (var == 0)
{
2019-03-05 02:56:39 +01:00
FormatAndPrintText(gText_MoveRelearnerWhichMoveToForget);
sMoveRelearnerStruct->state = MENU_STATE_PRINT_WHICH_MOVE_PROMPT;
}
else if (var == -1 || var == 1)
{
2019-03-05 02:56:39 +01:00
sMoveRelearnerStruct->state = MENU_STATE_PRINT_STOP_TEACHING;
}
}
break;
case MENU_STATE_PRINT_STOP_TEACHING:
StringCopy(gStringVar2, gMoveNames[GetCurrentSelectedMove()]);
2019-03-05 02:56:39 +01:00
FormatAndPrintText(gText_MoveRelearnerStopTryingToTeachMove);
sMoveRelearnerStruct->state++;
break;
case MENU_STATE_WAIT_FOR_STOP_TEACHING:
2019-03-05 02:56:39 +01:00
if (!MoveRelearnerRunTextPrinters())
{
2019-03-05 02:56:39 +01:00
MoveRelearnerCreateYesNoMenu();
sMoveRelearnerStruct->state++;
}
break;
case MENU_STATE_CONFIRM_STOP_TEACHING:
{
s8 var = Menu_ProcessInputNoWrapClearOnChoose();
if (var == 0)
{
2019-03-05 02:56:39 +01:00
sMoveRelearnerStruct->state = MENU_STATE_CHOOSE_SETUP_STATE;
}
else if (var == MENU_B_PRESSED || var == 1)
{
// What's the point? It gets set to MENU_STATE_PRINT_TRYING_TO_LEARN_PROMPT, anyway.
2019-03-05 02:56:39 +01:00
if (sMoveRelearnerMenuSate.showContestInfo == FALSE)
{
2019-03-05 02:56:39 +01:00
sMoveRelearnerStruct->state = MENU_STATE_SETUP_BATTLE_MODE;
}
2019-03-05 02:56:39 +01:00
else if (sMoveRelearnerMenuSate.showContestInfo == TRUE)
{
2019-03-05 02:56:39 +01:00
sMoveRelearnerStruct->state = MENU_STATE_SETUP_CONTEST_MODE;
}
2019-03-05 02:56:39 +01:00
sMoveRelearnerStruct->state = MENU_STATE_PRINT_TRYING_TO_LEARN_PROMPT;
}
}
break;
case MENU_STATE_CHOOSE_SETUP_STATE:
2019-03-05 02:56:39 +01:00
if (!MoveRelearnerRunTextPrinters())
{
FillWindowPixelBuffer(3, 0x11);
2019-03-05 02:56:39 +01:00
if (sMoveRelearnerMenuSate.showContestInfo == FALSE)
{
2019-03-05 02:56:39 +01:00
sMoveRelearnerStruct->state = MENU_STATE_SETUP_BATTLE_MODE;
}
2019-03-05 02:56:39 +01:00
else if (sMoveRelearnerMenuSate.showContestInfo == TRUE)
{
2019-03-05 02:56:39 +01:00
sMoveRelearnerStruct->state = MENU_STATE_SETUP_CONTEST_MODE;
}
}
break;
case MENU_STATE_PRINT_WHICH_MOVE_PROMPT:
2019-03-05 02:56:39 +01:00
if (!MoveRelearnerRunTextPrinters())
{
2019-03-05 02:56:39 +01:00
sMoveRelearnerStruct->state = MENU_STATE_SHOW_MOVE_SUMMARY_SCREEN;
BeginNormalPaletteFade(0xFFFFFFFF, 0, 0, 16, RGB_BLACK);
}
break;
case MENU_STATE_SHOW_MOVE_SUMMARY_SCREEN:
if (!gPaletteFade.active)
{
2019-03-05 02:56:39 +01:00
ShowSelectMovePokemonSummaryScreen(gPlayerParty, sMoveRelearnerStruct->partyMon, gPlayerPartyCount - 1, CB2_InitLearnMoveReturnFromSelectMove, GetCurrentSelectedMove());
FreeMoveRelearnerResources();
}
break;
case 21:
2019-03-05 02:56:39 +01:00
if (!MoveRelearnerRunTextPrinters())
{
2019-03-05 02:56:39 +01:00
sMoveRelearnerStruct->state = MENU_STATE_FADE_AND_RETURN;
}
break;
case 22:
BeginNormalPaletteFade(0xFFFFFFFF, 0, 16, 0, RGB_BLACK);
break;
case MENU_STATE_FADE_AND_RETURN:
BeginNormalPaletteFade(0xFFFFFFFF, 0, 0, 16, RGB_BLACK);
2019-03-05 02:56:39 +01:00
sMoveRelearnerStruct->state++;
break;
case MENU_STATE_RETURN_TO_FIELD:
if (!gPaletteFade.active)
{
2019-03-05 02:56:39 +01:00
FreeMoveRelearnerResources();
SetMainCallback2(CB2_ReturnToField);
}
break;
case MENU_STATE_FADE_FROM_SUMMARY_SCREEN:
BeginNormalPaletteFade(0xFFFFFFFF, 0, 16, 0, RGB_BLACK);
2019-03-05 02:56:39 +01:00
sMoveRelearnerStruct->state++;
if (sMoveRelearnerMenuSate.showContestInfo == FALSE)
{
HideHeartSpritesAndShowTeachMoveText(TRUE);
}
2019-03-05 02:56:39 +01:00
else if (sMoveRelearnerMenuSate.showContestInfo == TRUE)
{
ShowTeachMoveText(TRUE);
}
RemoveScrollArrows();
CopyWindowToVram(3, 2);
break;
case MENU_STATE_TRY_OVERWRITE_MOVE:
if (!gPaletteFade.active)
{
2019-03-05 02:56:39 +01:00
if (sMoveRelearnerStruct->moveSlot == MAX_MON_MOVES)
{
2019-03-05 02:56:39 +01:00
sMoveRelearnerStruct->state = MENU_STATE_PRINT_STOP_TEACHING;
}
else
{
2019-03-05 02:56:39 +01:00
u16 moveId = GetMonData(&gPlayerParty[sMoveRelearnerStruct->partyMon], MON_DATA_MOVE1 + sMoveRelearnerStruct->moveSlot);
StringCopy(gStringVar3, gMoveNames[moveId]);
2019-03-05 02:56:39 +01:00
RemoveMonPPBonus(&gPlayerParty[sMoveRelearnerStruct->partyMon], sMoveRelearnerStruct->moveSlot);
SetMonMoveSlot(&gPlayerParty[sMoveRelearnerStruct->partyMon], GetCurrentSelectedMove(), sMoveRelearnerStruct->moveSlot);
StringCopy(gStringVar2, gMoveNames[GetCurrentSelectedMove()]);
2019-03-05 02:56:39 +01:00
FormatAndPrintText(gText_MoveRelearnerAndPoof);
sMoveRelearnerStruct->state = MENU_STATE_DOUBLE_FANFARE_FORGOT_MOVE;
gSpecialVar_0x8004 = TRUE;
}
}
break;
case MENU_STATE_DOUBLE_FANFARE_FORGOT_MOVE:
2019-03-05 02:56:39 +01:00
if (!MoveRelearnerRunTextPrinters())
{
2019-03-05 02:56:39 +01:00
FormatAndPrintText(gText_MoveRelearnerPkmnForgotMoveAndLearnedNew);
sMoveRelearnerStruct->state = MENU_STATE_PRINT_TEXT_THEN_FANFARE;
2020-08-21 00:02:00 +02:00
PlayFanfare(MUS_LEVEL_UP);
}
break;
case MENU_STATE_PRINT_TEXT_THEN_FANFARE:
2019-03-05 02:56:39 +01:00
if (!MoveRelearnerRunTextPrinters())
{
2020-08-21 00:02:00 +02:00
PlayFanfare(MUS_LEVEL_UP);
2019-03-05 02:56:39 +01:00
sMoveRelearnerStruct->state = MENU_STATE_WAIT_FOR_FANFARE;
}
break;
case MENU_STATE_WAIT_FOR_FANFARE:
if (IsFanfareTaskInactive())
{
2019-03-05 02:56:39 +01:00
sMoveRelearnerStruct->state = MENU_STATE_WAIT_FOR_A_BUTTON;
}
break;
case MENU_STATE_WAIT_FOR_A_BUTTON:
if (gMain.newKeys & A_BUTTON)
{
PlaySE(SE_SELECT);
2019-03-05 02:56:39 +01:00
sMoveRelearnerStruct->state = MENU_STATE_FADE_AND_RETURN;
}
break;
}
}
2019-03-05 02:56:39 +01:00
static void FreeMoveRelearnerResources(void)
{
RemoveScrollArrows();
2019-03-05 02:56:39 +01:00
DestroyListMenuTask(sMoveRelearnerStruct->moveListMenuTask, &sMoveRelearnerMenuSate.listOffset, &sMoveRelearnerMenuSate.listRow);
FreeAllWindowBuffers();
2019-03-05 02:56:39 +01:00
FREE_AND_SET_NULL(sMoveRelearnerStruct);
ResetSpriteData();
FreeAllSpritePalettes();
}
2019-03-05 02:56:39 +01:00
// Note: The hearts are already made invisible by MoveRelearnerShowHideHearts,
// which is called whenever the cursor in either list changes.
static void HideHeartSpritesAndShowTeachMoveText(bool8 onlyHideSprites)
{
s32 i;
for (i = 0; i < 16; i++)
{
2019-03-05 02:56:39 +01:00
gSprites[sMoveRelearnerStruct->heartSpriteIds[i]].invisible = TRUE;
}
if (!onlyHideSprites)
{
StringExpandPlaceholders(gStringVar4, gText_TeachWhichMoveToPkmn);
FillWindowPixelBuffer(3, 0x11);
AddTextPrinterParameterized(3, 1, gStringVar4, 0, 1, 0, NULL);
}
}
static void HandleInput(bool8 showContest)
{
2019-03-05 02:56:39 +01:00
s32 itemId = ListMenu_ProcessInput(sMoveRelearnerStruct->moveListMenuTask);
ListMenuGetScrollAndRow(sMoveRelearnerStruct->moveListMenuTask, &sMoveRelearnerMenuSate.listOffset, &sMoveRelearnerMenuSate.listRow);
switch (itemId)
{
case LIST_NOTHING_CHOSEN:
2019-10-18 01:22:03 +02:00
if (!(gMain.newKeys & (DPAD_LEFT | DPAD_RIGHT)) && !GetLRKeysPressed())
{
break;
}
PlaySE(SE_SELECT);
if (showContest == FALSE)
{
PutWindowTilemap(1);
2019-03-05 02:56:39 +01:00
sMoveRelearnerStruct->state = MENU_STATE_SETUP_CONTEST_MODE;
sMoveRelearnerMenuSate.showContestInfo = TRUE;
}
else
{
PutWindowTilemap(0);
2019-03-05 02:56:39 +01:00
sMoveRelearnerStruct->state = MENU_STATE_SETUP_BATTLE_MODE;
sMoveRelearnerMenuSate.showContestInfo = FALSE;
}
2020-05-14 10:37:09 +02:00
ScheduleBgCopyTilemapToVram(1);
2019-03-05 02:56:39 +01:00
MoveRelearnerShowHideHearts(GetCurrentSelectedMove());
break;
case LIST_CANCEL:
PlaySE(SE_SELECT);
RemoveScrollArrows();
2019-03-05 02:56:39 +01:00
sMoveRelearnerStruct->state = MENU_STATE_PRINT_GIVE_UP_PROMPT;
StringExpandPlaceholders(gStringVar4, gText_MoveRelearnerGiveUp);
MoveRelearnerPrintText(gStringVar4);
break;
default:
PlaySE(SE_SELECT);
RemoveScrollArrows();
2019-03-05 02:56:39 +01:00
sMoveRelearnerStruct->state = MENU_STATE_PRINT_TEACH_MOVE_PROMPT;
StringCopy(gStringVar2, gMoveNames[itemId]);
2019-03-05 02:56:39 +01:00
StringExpandPlaceholders(gStringVar4, gText_MoveRelearnerTeachMoveConfirm);
MoveRelearnerPrintText(gStringVar4);
break;
}
}
static s32 GetCurrentSelectedMove(void)
{
2019-03-05 02:56:39 +01:00
return sMoveRelearnerStruct->menuItems[sMoveRelearnerMenuSate.listRow + sMoveRelearnerMenuSate.listOffset].id;
}
// Theory: This used to make the heart sprites visible again (i.e.
// this was the inverse of HideHeartsAndShowTeachMoveText), but the
// code was commented out. The bool argument would have been named
// "justShowHearts." The code for showing/hiding the heards was moved
2019-03-05 02:56:39 +01:00
// to MoveRelearnerShowHideHearts, which is called whenever a new move is
// selected and whenever the display mode changes.
static void ShowTeachMoveText(bool8 shouldDoNothingInstead)
{
if (shouldDoNothingInstead == FALSE)
{
StringExpandPlaceholders(gStringVar4, gText_TeachWhichMoveToPkmn);
FillWindowPixelBuffer(3, 0x11);
AddTextPrinterParameterized(3, 1, gStringVar4, 0, 1, 0, NULL);
}
}
static void CreateUISprites(void)
{
int i;
2019-03-05 02:56:39 +01:00
sMoveRelearnerStruct->moveDisplayArrowTask = 0xFF;
sMoveRelearnerStruct->moveListScrollArrowTask = 0xFF;
AddScrollArrows();
// These are the appeal hearts.
for (i = 0; i < 8; i++)
{
2019-03-05 02:56:39 +01:00
sMoveRelearnerStruct->heartSpriteIds[i] = CreateSprite(&sConstestMoveHeartSprite, (i - (i / 4) * 4) * 8 + 104, (i / 4) * 8 + 36, 0);
}
// These are the jam harts.
// The animation is used to toggle between full/empty heart sprites.
for (i = 0; i < 8; i++)
{
2019-03-05 02:56:39 +01:00
sMoveRelearnerStruct->heartSpriteIds[i + 8] = CreateSprite(&sConstestMoveHeartSprite, (i - (i / 4) * 4) * 8 + 104, (i / 4) * 8 + 52, 0);
StartSpriteAnim(&gSprites[sMoveRelearnerStruct->heartSpriteIds[i + 8]], 2);
}
for (i = 0; i < 16; i++)
{
2019-03-05 02:56:39 +01:00
gSprites[sMoveRelearnerStruct->heartSpriteIds[i]].invisible = TRUE;
}
}
static void AddScrollArrows(void)
{
2019-03-05 02:56:39 +01:00
if (sMoveRelearnerStruct->moveDisplayArrowTask == 0xFF)
{
2019-03-05 02:56:39 +01:00
sMoveRelearnerStruct->moveDisplayArrowTask = AddScrollIndicatorArrowPair(&sDisplayModeArrowsTemplate, &sMoveRelearnerStruct->scrollOffset);
}
2019-03-05 02:56:39 +01:00
if (sMoveRelearnerStruct->moveListScrollArrowTask == 0xFF)
{
gTempScrollArrowTemplate = sMoveListScrollArrowsTemplate;
2019-03-05 02:56:39 +01:00
gTempScrollArrowTemplate.fullyDownThreshold = sMoveRelearnerStruct->numMenuChoices - sMoveRelearnerStruct->numToShowAtOnce;
sMoveRelearnerStruct->moveListScrollArrowTask = AddScrollIndicatorArrowPair(&gTempScrollArrowTemplate, &sMoveRelearnerMenuSate.listOffset);
}
}
static void RemoveScrollArrows(void)
{
2019-03-05 02:56:39 +01:00
if (sMoveRelearnerStruct->moveDisplayArrowTask != 0xFF)
{
2019-03-05 02:56:39 +01:00
RemoveScrollIndicatorArrowPair(sMoveRelearnerStruct->moveDisplayArrowTask);
sMoveRelearnerStruct->moveDisplayArrowTask = 0xFF;
}
2019-03-05 02:56:39 +01:00
if (sMoveRelearnerStruct->moveListScrollArrowTask != 0xFF)
{
2019-03-05 02:56:39 +01:00
RemoveScrollIndicatorArrowPair(sMoveRelearnerStruct->moveListScrollArrowTask);
sMoveRelearnerStruct->moveListScrollArrowTask = 0xFF;
}
}
static void CreateLearnableMovesList(void)
{
s32 i;
u8 nickname[POKEMON_NAME_LENGTH + 1];
2019-03-05 02:56:39 +01:00
sMoveRelearnerStruct->numMenuChoices = GetMoveRelearnerMoves(&gPlayerParty[sMoveRelearnerStruct->partyMon], sMoveRelearnerStruct->movesToLearn);
2019-03-05 02:56:39 +01:00
for (i = 0; i < sMoveRelearnerStruct->numMenuChoices; i++)
{
2019-03-05 02:56:39 +01:00
sMoveRelearnerStruct->menuItems[i].name = gMoveNames[sMoveRelearnerStruct->movesToLearn[i]];
sMoveRelearnerStruct->menuItems[i].id = sMoveRelearnerStruct->movesToLearn[i];
}
2019-03-05 02:56:39 +01:00
GetMonData(&gPlayerParty[sMoveRelearnerStruct->partyMon], MON_DATA_NICKNAME, nickname);
StringCopy10(gStringVar1, nickname);
2019-03-05 02:56:39 +01:00
sMoveRelearnerStruct->menuItems[sMoveRelearnerStruct->numMenuChoices].name = gText_Cancel;
sMoveRelearnerStruct->menuItems[sMoveRelearnerStruct->numMenuChoices].id = LIST_CANCEL;
sMoveRelearnerStruct->numMenuChoices++;
sMoveRelearnerStruct->numToShowAtOnce = LoadMoveRelearnerMovesList(sMoveRelearnerStruct->menuItems, sMoveRelearnerStruct->numMenuChoices);
}
2019-03-05 02:56:39 +01:00
void MoveRelearnerShowHideHearts(s32 moveId)
{
u16 numHearts;
u16 i;
2019-03-05 02:56:39 +01:00
if (!sMoveRelearnerMenuSate.showContestInfo || moveId == LIST_CANCEL)
{
for (i = 0; i < 16; i++)
{
2019-03-05 02:56:39 +01:00
gSprites[sMoveRelearnerStruct->heartSpriteIds[i]].invisible = TRUE;
}
}
else
{
numHearts = (u8)(gContestEffects[gContestMoves[moveId].effect].appeal / 10);
if (numHearts == 0xFF)
{
numHearts = 0;
}
for (i = 0; i < 8; i++)
{
if (i < numHearts)
{
2019-03-05 02:56:39 +01:00
StartSpriteAnim(&gSprites[sMoveRelearnerStruct->heartSpriteIds[i]], 1);
}
else
{
2019-03-05 02:56:39 +01:00
StartSpriteAnim(&gSprites[sMoveRelearnerStruct->heartSpriteIds[i]], 0);
}
2019-03-05 02:56:39 +01:00
gSprites[sMoveRelearnerStruct->heartSpriteIds[i]].invisible = FALSE;
}
numHearts = (u8)(gContestEffects[gContestMoves[moveId].effect].jam / 10);
if (numHearts == 0xFF)
{
numHearts = 0;
}
for (i = 0; i < 8; i++)
{
if (i < numHearts)
{
2019-03-05 02:56:39 +01:00
StartSpriteAnim(&gSprites[sMoveRelearnerStruct->heartSpriteIds[i + 8]], 3);
}
else
{
2019-03-05 02:56:39 +01:00
StartSpriteAnim(&gSprites[sMoveRelearnerStruct->heartSpriteIds[i + 8]], 2);
}
2019-03-05 02:56:39 +01:00
gSprites[sMoveRelearnerStruct->heartSpriteIds[i + 8]].invisible = FALSE;
}
}
}