2017-12-10 19:02:51 +01:00
|
|
|
#include "global.h"
|
2019-09-09 03:07:54 +02:00
|
|
|
#include "malloc.h"
|
2017-12-16 00:08:23 +01:00
|
|
|
#include "battle.h"
|
|
|
|
#include "battle_controllers.h"
|
2018-11-14 01:01:50 +01:00
|
|
|
#include "battle_message.h"
|
|
|
|
#include "bg.h"
|
2017-12-16 00:08:23 +01:00
|
|
|
#include "decompress.h"
|
2018-11-14 01:01:50 +01:00
|
|
|
#include "event_data.h"
|
2018-12-24 00:02:29 +01:00
|
|
|
#include "field_screen_effect.h"
|
2018-11-14 01:01:50 +01:00
|
|
|
#include "gpu_regs.h"
|
|
|
|
#include "graphics.h"
|
2017-12-16 00:08:23 +01:00
|
|
|
#include "international_string_util.h"
|
|
|
|
#include "item.h"
|
2018-12-24 00:02:29 +01:00
|
|
|
#include "item_menu.h"
|
2017-12-16 15:10:29 +01:00
|
|
|
#include "lilycove_lady.h"
|
2018-11-14 01:01:50 +01:00
|
|
|
#include "list_menu.h"
|
|
|
|
#include "main.h"
|
|
|
|
#include "menu.h"
|
|
|
|
#include "menu_helpers.h"
|
2018-05-11 01:36:57 +02:00
|
|
|
#include "overworld.h"
|
2018-11-14 01:01:50 +01:00
|
|
|
#include "palette.h"
|
|
|
|
#include "pokeblock.h"
|
|
|
|
#include "pokemon.h"
|
|
|
|
#include "safari_zone.h"
|
|
|
|
#include "scanline_effect.h"
|
|
|
|
#include "sound.h"
|
|
|
|
#include "string_util.h"
|
|
|
|
#include "strings.h"
|
|
|
|
#include "task.h"
|
|
|
|
#include "text.h"
|
|
|
|
#include "text_window.h"
|
|
|
|
#include "constants/items.h"
|
|
|
|
#include "constants/songs.h"
|
2019-04-04 23:05:46 +02:00
|
|
|
#include "constants/rgb.h"
|
2017-12-16 00:08:23 +01:00
|
|
|
|
2017-12-16 15:10:29 +01:00
|
|
|
#define POKEBLOCK_MAX_FEEL 99
|
2017-12-16 00:08:23 +01:00
|
|
|
#define FIELD_E75_COUNT 7
|
|
|
|
|
|
|
|
struct PokeblockMenuStruct
|
|
|
|
{
|
|
|
|
u8 tilemap[0x800];
|
2017-12-16 15:10:29 +01:00
|
|
|
void (*callbackOnUse)(void);
|
|
|
|
const u8 *pokeblockOptionsIds;
|
2017-12-16 00:08:23 +01:00
|
|
|
u8 optionsNo;
|
|
|
|
u8 caseId;
|
|
|
|
u8 itemsNo;
|
|
|
|
u8 maxShowed;
|
|
|
|
struct ListMenuItem items[POKEBLOCKS_COUNT + 1];
|
|
|
|
u8 menuItemsStrings[POKEBLOCKS_COUNT + 1][0x20]; // + 1 because of STOW CASE item
|
|
|
|
u8 pokeblockCaseSpriteId;
|
|
|
|
u8 field_E75[FIELD_E75_COUNT];
|
|
|
|
u8 unkTaskId;
|
|
|
|
bool8 isSwapping;
|
|
|
|
s16 gfxState;
|
2017-12-16 15:12:55 +01:00
|
|
|
u8 unused[8];
|
2017-12-16 00:08:23 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
struct PokeblockSavedData
|
|
|
|
{
|
|
|
|
void (*callback)(void);
|
|
|
|
u16 lastItemPos;
|
|
|
|
u16 lastItemPage;
|
|
|
|
};
|
2017-12-10 19:02:51 +01:00
|
|
|
|
2017-12-11 16:52:28 +01:00
|
|
|
enum
|
|
|
|
{
|
|
|
|
PKBL_USE_ON_FIELD,
|
|
|
|
PKBL_TOSS,
|
|
|
|
PKBL_CANCEL,
|
|
|
|
PKBL_USE_IN_BATTLE,
|
|
|
|
PKBL_USE_ON_FEEDER,
|
|
|
|
PKBL_GIVE_TO_LADY
|
|
|
|
};
|
2017-12-10 19:02:51 +01:00
|
|
|
|
2017-12-16 00:08:23 +01:00
|
|
|
|
|
|
|
extern const u16 gUnknown_0860F074[];
|
|
|
|
|
2017-12-11 16:52:28 +01:00
|
|
|
// this file's functions
|
2017-12-16 15:10:29 +01:00
|
|
|
static void CB2_InitPokeblockMenu(void);
|
|
|
|
static bool8 InitPokeblockMenu(void);
|
2017-12-16 00:08:23 +01:00
|
|
|
static bool8 LoadPokeblockMenuGfx(void);
|
|
|
|
static void HandleInitBackgrounds(void);
|
|
|
|
static void HandleInitWindows(void);
|
2017-12-16 15:10:29 +01:00
|
|
|
static void SetMenuItemsCountAndMaxShowed(void);
|
|
|
|
static void sub_81362E0(void);
|
|
|
|
static void sub_8136344(void);
|
|
|
|
static void HandlePokeblockListMenuItems(void);
|
|
|
|
static void sub_81363BC(void);
|
2018-03-03 14:58:41 +01:00
|
|
|
static void MovePokeblockMenuCursor(s32 pkblId, bool8 arg1, struct ListMenu *arg2);
|
2017-12-16 00:08:23 +01:00
|
|
|
static void PutPokeblockInfoText(void);
|
2017-12-16 15:10:29 +01:00
|
|
|
static void HandlePokeblockMenuCursor(u16 cursorPos, u16 arg1);
|
2017-12-16 00:08:23 +01:00
|
|
|
static void PutPokeblockListMenuString(u8 *dst, u16 pkblId);
|
2017-12-16 15:10:29 +01:00
|
|
|
static void Task_HandlePokeblockMenuInput(u8 taskId);
|
|
|
|
static void PokeblockAction_UseOnField(u8 taskId);
|
|
|
|
static void PokeblockAction_Toss(u8 taskId);
|
|
|
|
static void PokeblockAction_Cancel(u8 taskId);
|
|
|
|
static void PokeblockAction_UseInBattle(u8 taskId);
|
|
|
|
static void PokeblockAction_UseOnPokeblockFeeder(u8 taskId);
|
|
|
|
static void PokeblockAction_GiveToContestLady(u8 taskId);
|
|
|
|
static void TossPokeblockChoice_Yes(u8 taskId);
|
|
|
|
static void TossPokeblockChoice_No(u8 taskId);
|
|
|
|
static void Task_FreeDataAndExitPokeblockCase(u8 taskId);
|
|
|
|
static void Task_HandlePokeblockOptionsInput(u8 taskId);
|
|
|
|
static void PutPokeblockOptionsWindow(u8 taskId);
|
2017-12-16 00:08:23 +01:00
|
|
|
static void Task_HandlePokeblocksSwapInput(u8 taskId);
|
|
|
|
static void sub_8136470(struct Sprite *sprite);
|
|
|
|
static void sub_8135FCC(s32 pkblId);
|
2017-12-16 15:10:29 +01:00
|
|
|
static void HandlePokeblocksSwap(u8 taskId, bool8 noSwap);
|
|
|
|
static void UsePokeblockOnField(void);
|
|
|
|
static void ReturnToPokeblockCaseOnField(void);
|
|
|
|
static void CreateTossPokeblockYesNoMenu(u8 taskId);
|
|
|
|
static void HandleErasePokeblock(u8 taskId);
|
2017-12-16 00:08:23 +01:00
|
|
|
|
|
|
|
// ram variables
|
2017-12-16 15:10:29 +01:00
|
|
|
EWRAM_DATA static struct PokeblockSavedData sSavedPokeblockData = {0};
|
|
|
|
EWRAM_DATA static struct PokeblockMenuStruct *sPokeblockMenu = NULL;
|
2017-12-11 16:52:28 +01:00
|
|
|
|
|
|
|
// const rom data
|
2020-07-17 02:12:12 +02:00
|
|
|
const s8 gPokeblockFlavorCompatibilityTable[NUM_NATURES * FLAVOR_COUNT] =
|
2017-12-11 16:52:28 +01:00
|
|
|
{
|
|
|
|
// Cool, Beauty, Cute, Smart, Tough
|
|
|
|
0, 0, 0, 0, 0, // Hardy
|
|
|
|
1, 0, 0, 0, -1, // Lonely
|
|
|
|
1, 0, -1, 0, 0, // Brave
|
|
|
|
1, -1, 0, 0, 0, // Adamant
|
|
|
|
1, 0, 0, -1, 0, // Naughty
|
|
|
|
-1, 0, 0, 0, 1, // Bold
|
|
|
|
0, 0, 0, 0, 0, // Docile
|
|
|
|
0, 0, -1, 0, 1, // Relaxed
|
|
|
|
0, -1, 0, 0, 1, // Impish
|
|
|
|
0, 0, 0, -1, 1, // Lax
|
|
|
|
-1, 0, 1, 0, 0, // Timid
|
|
|
|
0, 0, 1, 0, -1, // Hasty
|
|
|
|
0, 0, 0, 0, 0, // Serious
|
|
|
|
0, -1, 1, 0, 0, // Jolly
|
|
|
|
0, 0, 1, -1, 0, // Naive
|
|
|
|
-1, 1, 0, 0, 0, // Modest
|
|
|
|
0, 1, 0, 0, -1, // Mild
|
|
|
|
0, 1, -1, 0, 0, // Quiet
|
|
|
|
0, 0, 0, 0, 0, // Bashful
|
|
|
|
0, 1, 0, -1, 0, // Rash
|
|
|
|
-1, 0, 0, 1, 0, // Calm
|
|
|
|
0, 0, 0, 1, -1, // Gentle
|
|
|
|
0, 0, -1, 1, 0, // Sassy
|
|
|
|
0, -1, 0, 1, 0, // Careful
|
|
|
|
0, 0, 0, 0, 0 // Quirky
|
|
|
|
};
|
|
|
|
|
2017-12-16 00:08:23 +01:00
|
|
|
static const struct BgTemplate sBgTemplatesForPokeblockMenu[] =
|
2017-12-11 16:52:28 +01:00
|
|
|
{
|
|
|
|
{
|
|
|
|
.bg = 0,
|
|
|
|
.charBaseIndex = 0,
|
|
|
|
.mapBaseIndex = 31,
|
|
|
|
.screenSize = 0,
|
|
|
|
.paletteMode = 0,
|
|
|
|
.priority = 1,
|
|
|
|
.baseTile = 0
|
|
|
|
},
|
|
|
|
{
|
|
|
|
.bg = 1,
|
|
|
|
.charBaseIndex = 0,
|
|
|
|
.mapBaseIndex = 30,
|
|
|
|
.screenSize = 0,
|
|
|
|
.paletteMode = 0,
|
|
|
|
.priority = 0,
|
|
|
|
.baseTile = 0
|
|
|
|
},
|
|
|
|
{
|
|
|
|
.bg = 2,
|
|
|
|
.charBaseIndex = 3,
|
|
|
|
.mapBaseIndex = 29,
|
|
|
|
.screenSize = 0,
|
|
|
|
.paletteMode = 0,
|
|
|
|
.priority = 2,
|
|
|
|
.baseTile = 0
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
const u8 *const gPokeblockNames[] =
|
|
|
|
{
|
2020-08-24 20:52:33 +02:00
|
|
|
[PBLOCK_CLR_NONE] = NULL,
|
|
|
|
[PBLOCK_CLR_RED] = gText_RedPokeblock,
|
|
|
|
[PBLOCK_CLR_BLUE] = gText_BluePokeblock,
|
|
|
|
[PBLOCK_CLR_PINK] = gText_PinkPokeblock,
|
|
|
|
[PBLOCK_CLR_GREEN] = gText_GreenPokeblock,
|
|
|
|
[PBLOCK_CLR_YELLOW] = gText_YellowPokeblock,
|
|
|
|
[PBLOCK_CLR_PURPLE] = gText_PurplePokeblock,
|
|
|
|
[PBLOCK_CLR_INDIGO] = gText_IndigoPokeblock,
|
|
|
|
[PBLOCK_CLR_BROWN] = gText_BrownPokeblock,
|
|
|
|
[PBLOCK_CLR_LITE_BLUE] = gText_LiteBluePokeblock,
|
|
|
|
[PBLOCK_CLR_OLIVE] = gText_OlivePokeblock,
|
|
|
|
[PBLOCK_CLR_GRAY] = gText_GrayPokeblock,
|
|
|
|
[PBLOCK_CLR_BLACK] = gText_BlackPokeblock,
|
|
|
|
[PBLOCK_CLR_WHITE] = gText_WhitePokeblock,
|
|
|
|
[PBLOCK_CLR_GOLD] = gText_GoldPokeblock
|
2017-12-11 16:52:28 +01:00
|
|
|
};
|
|
|
|
|
2017-12-16 15:10:29 +01:00
|
|
|
static const struct MenuAction sPokeblockMenuActions[] =
|
2017-12-11 16:52:28 +01:00
|
|
|
{
|
|
|
|
{gMenuText_Use, PokeblockAction_UseOnField},
|
|
|
|
{gMenuText_Toss, PokeblockAction_Toss},
|
|
|
|
{gText_Cancel2, PokeblockAction_Cancel},
|
|
|
|
{gMenuText_Use, PokeblockAction_UseInBattle},
|
|
|
|
{gMenuText_Use, PokeblockAction_UseOnPokeblockFeeder},
|
|
|
|
{gMenuText_Give2, PokeblockAction_GiveToContestLady},
|
|
|
|
};
|
|
|
|
|
2017-12-16 15:10:29 +01:00
|
|
|
static const u8 sActionsOnField[] = {PKBL_USE_ON_FIELD, PKBL_TOSS, PKBL_CANCEL};
|
|
|
|
static const u8 sActionsInBattle[] = {PKBL_USE_IN_BATTLE, PKBL_CANCEL};
|
|
|
|
static const u8 sActionsOnPokeblockFeeder[] = {PKBL_USE_ON_FEEDER, PKBL_CANCEL};
|
|
|
|
static const u8 sActionsWhenGivingToLady[] = {PKBL_GIVE_TO_LADY, PKBL_CANCEL};
|
2017-12-11 16:52:28 +01:00
|
|
|
|
2017-12-16 15:10:29 +01:00
|
|
|
static const struct YesNoFuncTable sTossYesNoFuncTable = {TossPokeblockChoice_Yes, TossPokeblockChoice_No};
|
2017-12-11 16:52:28 +01:00
|
|
|
|
|
|
|
static const u8 sContestStatsMonData[] = {MON_DATA_COOL, MON_DATA_BEAUTY, MON_DATA_CUTE, MON_DATA_SMART, MON_DATA_TOUGH};
|
|
|
|
|
|
|
|
static const struct OamData sOamData_PokeblockCase =
|
|
|
|
{
|
|
|
|
.y = 0,
|
2019-12-04 21:25:13 +01:00
|
|
|
.affineMode = ST_OAM_AFFINE_OFF,
|
|
|
|
.objMode = ST_OAM_OBJ_NORMAL,
|
2017-12-11 16:52:28 +01:00
|
|
|
.mosaic = 0,
|
2019-12-04 21:25:13 +01:00
|
|
|
.bpp = ST_OAM_4BPP,
|
2019-03-11 08:12:15 +01:00
|
|
|
.shape = SPRITE_SHAPE(64x64),
|
2017-12-11 16:52:28 +01:00
|
|
|
.x = 0,
|
|
|
|
.matrixNum = 0,
|
2019-03-11 08:12:15 +01:00
|
|
|
.size = SPRITE_SIZE(64x64),
|
2017-12-11 16:52:28 +01:00
|
|
|
.tileNum = 0,
|
|
|
|
.priority = 2,
|
|
|
|
.paletteNum = 0,
|
|
|
|
.affineParam = 0,
|
|
|
|
};
|
|
|
|
|
|
|
|
static const union AnimCmd sSpriteAnim_PokeblockCase[] =
|
|
|
|
{
|
|
|
|
ANIMCMD_FRAME(0, 0),
|
|
|
|
ANIMCMD_END
|
|
|
|
};
|
|
|
|
|
|
|
|
static const union AnimCmd *const sSpriteAnimTable_PokeblockCase[] =
|
|
|
|
{
|
|
|
|
sSpriteAnim_PokeblockCase
|
|
|
|
};
|
|
|
|
|
2017-12-16 15:10:29 +01:00
|
|
|
static const union AffineAnimCmd sSpriteAffineAnim_85B26C8[] =
|
2017-12-11 16:52:28 +01:00
|
|
|
{
|
|
|
|
AFFINEANIMCMD_FRAME(0, 0, -2, 2),
|
|
|
|
AFFINEANIMCMD_FRAME(0, 0, 2, 4),
|
|
|
|
AFFINEANIMCMD_FRAME(0, 0, -2, 4),
|
|
|
|
AFFINEANIMCMD_FRAME(0, 0, 2, 2),
|
|
|
|
AFFINEANIMCMD_END
|
|
|
|
};
|
|
|
|
|
2017-12-16 15:10:29 +01:00
|
|
|
static const union AffineAnimCmd *const sSpriteAffineAnimTable_85B26F0[] =
|
2017-12-11 16:52:28 +01:00
|
|
|
{
|
2017-12-16 15:10:29 +01:00
|
|
|
sSpriteAffineAnim_85B26C8
|
2017-12-11 16:52:28 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
const struct CompressedSpriteSheet gPokeblockCase_SpriteSheet =
|
|
|
|
{
|
|
|
|
gMenuPokeblockDevice_Gfx, 0x800, GFX_TAG_POKEBLOCK_CASE
|
|
|
|
};
|
|
|
|
|
|
|
|
const struct CompressedSpritePalette gPokeblockCase_SpritePal =
|
|
|
|
{
|
|
|
|
gMenuPokeblockDevice_Pal, GFX_TAG_POKEBLOCK_CASE
|
|
|
|
};
|
|
|
|
|
2017-12-16 00:08:23 +01:00
|
|
|
static const struct SpriteTemplate sSpriteTemplate_PokeblockCase =
|
2017-12-11 16:52:28 +01:00
|
|
|
{
|
|
|
|
GFX_TAG_POKEBLOCK_CASE,
|
|
|
|
GFX_TAG_POKEBLOCK_CASE,
|
|
|
|
&sOamData_PokeblockCase,
|
|
|
|
sSpriteAnimTable_PokeblockCase,
|
|
|
|
NULL,
|
|
|
|
gDummySpriteAffineAnimTable,
|
|
|
|
SpriteCallbackDummy
|
|
|
|
};
|
|
|
|
|
2018-02-07 03:37:54 +01:00
|
|
|
static const u8 sTextColorInPokeblockMenu[3] = {0, 2, 3};
|
2017-12-11 16:52:28 +01:00
|
|
|
|
2017-12-16 15:10:29 +01:00
|
|
|
static const struct Pokeblock sFavoritePokeblocksTable[] =
|
2017-12-11 16:52:28 +01:00
|
|
|
{
|
|
|
|
{ PBLOCK_CLR_RED, 20, 0, 0, 0, 0, 20},
|
|
|
|
{ PBLOCK_CLR_BLUE, 0, 20, 0, 0, 0, 20},
|
|
|
|
{ PBLOCK_CLR_PINK, 0, 0, 20, 0, 0, 20},
|
|
|
|
{ PBLOCK_CLR_GREEN, 0, 0, 0, 20, 0, 20},
|
|
|
|
{ PBLOCK_CLR_YELLOW, 0, 0, 0, 0, 20, 20}
|
|
|
|
};
|
2017-12-16 00:08:23 +01:00
|
|
|
|
|
|
|
static const struct WindowTemplate sWindowTemplatesForPokeblockMenu[] =
|
|
|
|
{
|
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 = 2,
|
|
|
|
.tilemapTop = 1,
|
|
|
|
.width = 9,
|
|
|
|
.height = 2,
|
|
|
|
.paletteNum = 15,
|
|
|
|
.baseBlock = 0x1E
|
|
|
|
},
|
|
|
|
{
|
2018-10-27 00:53:07 +02:00
|
|
|
.bg = 0,
|
2018-09-02 18:53:52 +02:00
|
|
|
.tilemapLeft = 15,
|
|
|
|
.tilemapTop = 1,
|
|
|
|
.width = 14,
|
|
|
|
.height = 18,
|
|
|
|
.paletteNum = 15,
|
|
|
|
.baseBlock = 0x30
|
|
|
|
},
|
|
|
|
{
|
2018-10-27 00:53:07 +02:00
|
|
|
.bg = 0,
|
2018-09-02 18:53:52 +02:00
|
|
|
.tilemapLeft = 2,
|
|
|
|
.tilemapTop = 13,
|
|
|
|
.width = 5,
|
|
|
|
.height = 2,
|
|
|
|
.paletteNum = 15,
|
|
|
|
.baseBlock = 0x12C
|
|
|
|
},
|
|
|
|
{
|
2018-10-27 00:53:07 +02:00
|
|
|
.bg = 0,
|
2018-09-02 18:53:52 +02:00
|
|
|
.tilemapLeft = 2,
|
|
|
|
.tilemapTop = 15,
|
|
|
|
.width = 5,
|
|
|
|
.height = 2,
|
|
|
|
.paletteNum = 15,
|
|
|
|
.baseBlock = 0x136
|
|
|
|
},
|
|
|
|
{
|
2018-10-27 00:53:07 +02:00
|
|
|
.bg = 0,
|
2018-09-02 18:53:52 +02:00
|
|
|
.tilemapLeft = 2,
|
|
|
|
.tilemapTop = 17,
|
|
|
|
.width = 5,
|
|
|
|
.height = 2,
|
|
|
|
.paletteNum = 15,
|
|
|
|
.baseBlock = 0x140
|
|
|
|
},
|
|
|
|
{
|
2018-10-27 00:53:07 +02:00
|
|
|
.bg = 0,
|
2018-09-02 18:53:52 +02:00
|
|
|
.tilemapLeft = 8,
|
|
|
|
.tilemapTop = 13,
|
|
|
|
.width = 5,
|
|
|
|
.height = 2,
|
|
|
|
.paletteNum = 15,
|
|
|
|
.baseBlock = 0x14A
|
|
|
|
},
|
|
|
|
{
|
2018-10-27 00:53:07 +02:00
|
|
|
.bg = 0,
|
2018-09-02 18:53:52 +02:00
|
|
|
.tilemapLeft = 8,
|
|
|
|
.tilemapTop = 15,
|
|
|
|
.width = 5,
|
|
|
|
.height = 2,
|
|
|
|
.paletteNum = 15,
|
|
|
|
.baseBlock = 0x154
|
|
|
|
},
|
|
|
|
{
|
2018-10-27 00:53:07 +02:00
|
|
|
.bg = 0,
|
2018-09-02 18:53:52 +02:00
|
|
|
.tilemapLeft = 11,
|
|
|
|
.tilemapTop = 17,
|
|
|
|
.width = 2,
|
|
|
|
.height = 2,
|
|
|
|
.paletteNum = 15,
|
|
|
|
.baseBlock = 0x15E
|
|
|
|
},
|
|
|
|
{
|
2018-10-27 00:53:07 +02:00
|
|
|
.bg = 1,
|
2018-09-02 18:53:52 +02:00
|
|
|
.tilemapLeft = 7,
|
|
|
|
.tilemapTop = 5,
|
|
|
|
.width = 6,
|
|
|
|
.height = 6,
|
|
|
|
.paletteNum = 15,
|
|
|
|
.baseBlock = 0x162
|
|
|
|
},
|
|
|
|
{
|
2018-10-27 00:53:07 +02:00
|
|
|
.bg = 1,
|
2018-09-02 18:53:52 +02:00
|
|
|
.tilemapLeft = 7,
|
|
|
|
.tilemapTop = 7,
|
|
|
|
.width = 6,
|
|
|
|
.height = 4,
|
|
|
|
.paletteNum = 15,
|
|
|
|
.baseBlock = 0x186
|
|
|
|
},
|
|
|
|
{
|
2018-10-27 00:53:07 +02:00
|
|
|
.bg = 1,
|
2018-09-02 18:53:52 +02:00
|
|
|
.tilemapLeft = 2,
|
|
|
|
.tilemapTop = 15,
|
|
|
|
.width = 27,
|
|
|
|
.height = 4,
|
|
|
|
.paletteNum = 15,
|
|
|
|
.baseBlock = 0x19E
|
|
|
|
},
|
2017-12-16 00:08:23 +01:00
|
|
|
DUMMY_WIN_TEMPLATE
|
|
|
|
};
|
|
|
|
|
2018-09-02 18:53:52 +02:00
|
|
|
static const struct WindowTemplate sTossPkblockWindowTemplate =
|
|
|
|
{
|
2018-10-27 00:53:07 +02:00
|
|
|
.bg = 1,
|
2018-09-02 18:53:52 +02:00
|
|
|
.tilemapLeft = 21,
|
|
|
|
.tilemapTop = 9,
|
|
|
|
.width = 5,
|
|
|
|
.height = 4,
|
|
|
|
.paletteNum = 15,
|
|
|
|
.baseBlock = 0x20A
|
|
|
|
};
|
2017-12-16 00:08:23 +01:00
|
|
|
|
|
|
|
static const struct ListMenuTemplate sPokeblockListMenuTemplate =
|
|
|
|
{
|
|
|
|
.items = NULL,
|
|
|
|
.moveCursorFunc = MovePokeblockMenuCursor,
|
2018-07-15 13:23:38 +02:00
|
|
|
.itemPrintFunc = NULL,
|
2017-12-16 00:08:23 +01:00
|
|
|
.totalItems = 0,
|
|
|
|
.maxShowed = 0,
|
2018-03-02 16:34:31 +01:00
|
|
|
.windowId = 1,
|
2018-07-15 13:23:38 +02:00
|
|
|
.header_X = 0,
|
|
|
|
.item_X = 1,
|
2018-03-03 14:58:41 +01:00
|
|
|
.cursor_X = 0,
|
2017-12-16 00:08:23 +01:00
|
|
|
.upText_Y = 1,
|
2018-03-02 16:34:31 +01:00
|
|
|
.cursorPal = 2,
|
2018-03-03 14:58:41 +01:00
|
|
|
.fillValue = 0,
|
2018-03-02 16:34:31 +01:00
|
|
|
.cursorShadowPal = 3,
|
2018-03-03 14:58:41 +01:00
|
|
|
.lettersSpacing = 0,
|
2018-07-15 13:23:38 +02:00
|
|
|
.itemVerticalPadding = 0,
|
2018-03-02 16:34:31 +01:00
|
|
|
.scrollMultiple = LIST_MULTIPLE_SCROLL_DPAD,
|
2018-03-03 14:58:41 +01:00
|
|
|
.fontId = 1,
|
2017-12-16 00:08:23 +01:00
|
|
|
.cursorKind = 1
|
|
|
|
};
|
|
|
|
|
|
|
|
// code
|
|
|
|
void OpenPokeblockCase(u8 caseId, void (*callback)(void))
|
|
|
|
{
|
Undo PokeCodec's PRs
This commit undoes most of PokeCodec's PRs after the debate in chat. Some
harmless or completely superseded PRs have been left alone, as there is not
much benefit in attempting to undo them.
Reverts #1104, #1108, #1115, #1118, #1119, #1124, #1126, #1127, #1132, #1136,
#1137, #1139, #1140, #1144, #1148, #1149, #1150, #1153, #1155, #1177, #1179,
#1180, #1181, #1182 and #1183.
2020-09-13 09:22:50 +02:00
|
|
|
sPokeblockMenu = Alloc(sizeof(*sPokeblockMenu));
|
2017-12-16 00:08:23 +01:00
|
|
|
sPokeblockMenu->caseId = caseId;
|
2017-12-16 15:10:29 +01:00
|
|
|
sPokeblockMenu->callbackOnUse = NULL;
|
2021-02-20 05:22:26 +01:00
|
|
|
sPokeblockMenu->unkTaskId = TASK_NONE;
|
2017-12-16 00:08:23 +01:00
|
|
|
sPokeblockMenu->isSwapping = FALSE;
|
|
|
|
sSavedPokeblockData.callback = callback;
|
|
|
|
|
|
|
|
switch (sPokeblockMenu->caseId)
|
|
|
|
{
|
|
|
|
case PBLOCK_CASE_BATTLE:
|
2017-12-16 15:10:29 +01:00
|
|
|
sPokeblockMenu->pokeblockOptionsIds = sActionsInBattle;
|
2017-12-16 00:08:23 +01:00
|
|
|
sPokeblockMenu->optionsNo = ARRAY_COUNT(sActionsInBattle);
|
|
|
|
break;
|
|
|
|
case PBLOCK_CASE_FEEDER:
|
2017-12-16 15:10:29 +01:00
|
|
|
sPokeblockMenu->pokeblockOptionsIds = sActionsOnPokeblockFeeder;
|
2017-12-16 00:08:23 +01:00
|
|
|
sPokeblockMenu->optionsNo = ARRAY_COUNT(sActionsOnPokeblockFeeder);
|
|
|
|
break;
|
|
|
|
case PBLOCK_CASE_GIVE:
|
2017-12-16 15:10:29 +01:00
|
|
|
sPokeblockMenu->pokeblockOptionsIds = sActionsWhenGivingToLady;
|
2017-12-16 00:08:23 +01:00
|
|
|
sPokeblockMenu->optionsNo = ARRAY_COUNT(sActionsWhenGivingToLady);
|
|
|
|
break;
|
2019-12-22 01:01:38 +01:00
|
|
|
default: // PBLOCK_CASE_FIELD
|
2017-12-16 15:10:29 +01:00
|
|
|
sPokeblockMenu->pokeblockOptionsIds = sActionsOnField;
|
2017-12-16 00:08:23 +01:00
|
|
|
sPokeblockMenu->optionsNo = ARRAY_COUNT(sActionsOnField);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
SetMainCallback2(CB2_InitPokeblockMenu);
|
|
|
|
}
|
|
|
|
|
|
|
|
void OpenPokeblockCaseInBattle(void)
|
|
|
|
{
|
2019-10-18 01:22:03 +02:00
|
|
|
OpenPokeblockCase(PBLOCK_CASE_BATTLE, CB2_SetUpReshowBattleScreenAfterMenu2);
|
2017-12-16 00:08:23 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void OpenPokeblockCaseOnFeeder(void)
|
|
|
|
{
|
2018-02-14 00:58:22 +01:00
|
|
|
OpenPokeblockCase(PBLOCK_CASE_FEEDER, CB2_ReturnToField);
|
2017-12-16 00:08:23 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static void CB2_PokeblockMenu(void)
|
|
|
|
{
|
|
|
|
RunTasks();
|
|
|
|
AnimateSprites();
|
|
|
|
BuildOamBuffer();
|
2020-06-20 01:58:56 +02:00
|
|
|
DoScheduledBgTilemapCopiesToVram();
|
2017-12-16 00:08:23 +01:00
|
|
|
UpdatePaletteFade();
|
|
|
|
}
|
|
|
|
|
|
|
|
static void VBlankCB_PokeblockMenu(void)
|
|
|
|
{
|
|
|
|
LoadOam();
|
|
|
|
ProcessSpriteCopyRequests();
|
|
|
|
TransferPlttBuffer();
|
|
|
|
}
|
|
|
|
|
2017-12-16 15:10:29 +01:00
|
|
|
static void CB2_InitPokeblockMenu(void)
|
2017-12-16 00:08:23 +01:00
|
|
|
{
|
|
|
|
while (1)
|
|
|
|
{
|
2020-05-14 10:37:09 +02:00
|
|
|
if (MenuHelpers_CallLinkSomething() == TRUE)
|
2017-12-16 00:08:23 +01:00
|
|
|
break;
|
|
|
|
if (InitPokeblockMenu() == TRUE)
|
|
|
|
break;
|
2020-05-14 10:37:09 +02:00
|
|
|
if (MenuHelpers_LinkSomething() == TRUE)
|
2017-12-16 00:08:23 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-12-16 15:10:29 +01:00
|
|
|
static bool8 InitPokeblockMenu(void)
|
2017-12-16 00:08:23 +01:00
|
|
|
{
|
|
|
|
u8 taskId;
|
|
|
|
|
|
|
|
switch (gMain.state)
|
|
|
|
{
|
|
|
|
case 0:
|
|
|
|
SetVBlankHBlankCallbacksToNull();
|
2020-06-20 01:58:56 +02:00
|
|
|
ClearScheduledBgCopiesToVram();
|
2017-12-16 00:08:23 +01:00
|
|
|
gMain.state++;
|
|
|
|
break;
|
|
|
|
case 1:
|
2018-01-16 18:59:06 +01:00
|
|
|
ScanlineEffect_Stop();
|
2017-12-16 00:08:23 +01:00
|
|
|
gMain.state++;
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
FreeAllSpritePalettes();
|
|
|
|
gMain.state++;
|
|
|
|
break;
|
|
|
|
case 3:
|
|
|
|
ResetPaletteFade();
|
|
|
|
gPaletteFade.bufferTransferDisabled = 1;
|
|
|
|
gMain.state++;
|
|
|
|
break;
|
|
|
|
case 4:
|
|
|
|
ResetSpriteData();
|
|
|
|
gMain.state++;
|
|
|
|
break;
|
|
|
|
case 5:
|
|
|
|
if (sPokeblockMenu->caseId != PBLOCK_CASE_BATTLE)
|
|
|
|
ResetTasks();
|
|
|
|
gMain.state++;
|
|
|
|
break;
|
|
|
|
case 6:
|
|
|
|
HandleInitBackgrounds();
|
|
|
|
sPokeblockMenu->gfxState = 0;
|
|
|
|
gMain.state++;
|
|
|
|
break;
|
|
|
|
case 7:
|
|
|
|
if (!LoadPokeblockMenuGfx())
|
|
|
|
return FALSE;
|
|
|
|
gMain.state++;
|
|
|
|
break;
|
|
|
|
case 8:
|
|
|
|
SetMenuItemsCountAndMaxShowed();
|
|
|
|
sub_81362E0();
|
|
|
|
sub_8136344();
|
|
|
|
gMain.state++;
|
|
|
|
break;
|
|
|
|
case 9:
|
|
|
|
sPokeblockMenu->pokeblockCaseSpriteId = CreatePokeblockCaseSprite(56, 64, 0);
|
|
|
|
gMain.state++;
|
|
|
|
break;
|
|
|
|
case 10:
|
2018-03-15 11:37:24 +01:00
|
|
|
sub_8122344(sPokeblockMenu->field_E75, FIELD_E75_COUNT);
|
2017-12-16 00:08:23 +01:00
|
|
|
gMain.state++;
|
|
|
|
break;
|
|
|
|
case 11:
|
|
|
|
HandlePokeblockMenuCursor(sSavedPokeblockData.lastItemPos, 0x1005);
|
|
|
|
gMain.state++;
|
|
|
|
break;
|
|
|
|
case 12:
|
|
|
|
HandleInitWindows();
|
|
|
|
gMain.state++;
|
|
|
|
break;
|
|
|
|
case 13:
|
|
|
|
HandlePokeblockListMenuItems();
|
|
|
|
gMain.state++;
|
|
|
|
break;
|
|
|
|
case 14:
|
|
|
|
sub_81363BC();
|
|
|
|
gMain.state++;
|
|
|
|
break;
|
|
|
|
case 15:
|
|
|
|
taskId = CreateTask(Task_HandlePokeblockMenuInput, 0);
|
|
|
|
gTasks[taskId].data[0] = ListMenuInit(&gMultiuseListMenuTemplate, sSavedPokeblockData.lastItemPage, sSavedPokeblockData.lastItemPos);
|
|
|
|
gMain.state++;
|
|
|
|
break;
|
|
|
|
case 16:
|
|
|
|
PutPokeblockInfoText();
|
|
|
|
gMain.state++;
|
|
|
|
break;
|
|
|
|
case 17:
|
2021-02-24 17:01:02 +01:00
|
|
|
BlendPalettes(PALETTES_ALL, 0x10, 0);
|
2017-12-16 00:08:23 +01:00
|
|
|
gMain.state++;
|
|
|
|
break;
|
|
|
|
case 18:
|
2021-02-24 17:01:02 +01:00
|
|
|
BeginNormalPaletteFade(PALETTES_ALL, 0, 0x10, 0, RGB_BLACK);
|
2017-12-16 00:08:23 +01:00
|
|
|
gPaletteFade.bufferTransferDisabled = 0;
|
|
|
|
gMain.state++;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
SetVBlankCallback(VBlankCB_PokeblockMenu);
|
|
|
|
SetMainCallback2(CB2_PokeblockMenu);
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void HandleInitBackgrounds(void)
|
|
|
|
{
|
|
|
|
ResetVramOamAndBgCntRegs();
|
|
|
|
ResetBgsAndClearDma3BusyFlags(0);
|
|
|
|
InitBgsFromTemplates(0, sBgTemplatesForPokeblockMenu, ARRAY_COUNT(sBgTemplatesForPokeblockMenu));
|
|
|
|
SetBgTilemapBuffer(2, sPokeblockMenu->tilemap);
|
|
|
|
ResetAllBgsCoordinates();
|
2020-05-14 10:37:09 +02:00
|
|
|
ScheduleBgCopyTilemapToVram(2);
|
2017-12-16 00:08:23 +01:00
|
|
|
|
|
|
|
SetGpuReg(REG_OFFSET_DISPCNT, DISPCNT_OBJ_ON | DISPCNT_OBJ_1D_MAP);
|
|
|
|
|
|
|
|
ShowBg(0);
|
|
|
|
ShowBg(1);
|
|
|
|
ShowBg(2);
|
|
|
|
|
|
|
|
SetGpuReg(REG_OFFSET_BLDCNT, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool8 LoadPokeblockMenuGfx(void)
|
|
|
|
{
|
|
|
|
switch (sPokeblockMenu->gfxState)
|
|
|
|
{
|
|
|
|
case 0:
|
2020-05-14 10:37:09 +02:00
|
|
|
ResetTempTileDataBuffers();
|
|
|
|
DecompressAndCopyTileDataToVram(2, gMenuPokeblock_Gfx, 0, 0, 0);
|
2017-12-16 00:08:23 +01:00
|
|
|
sPokeblockMenu->gfxState++;
|
|
|
|
break;
|
|
|
|
case 1:
|
2020-05-14 10:37:09 +02:00
|
|
|
if (FreeTempTileDataBuffersIfPossible() != TRUE)
|
2017-12-16 00:08:23 +01:00
|
|
|
{
|
|
|
|
LZDecompressWram(gMenuPokeblock_Tilemap, sPokeblockMenu->tilemap);
|
|
|
|
sPokeblockMenu->gfxState++;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
LoadCompressedPalette(gMenuPokeblock_Pal, 0, 0xC0);
|
|
|
|
sPokeblockMenu->gfxState++;
|
|
|
|
break;
|
|
|
|
case 3:
|
2018-12-17 23:00:08 +01:00
|
|
|
LoadCompressedSpriteSheet(&gPokeblockCase_SpriteSheet);
|
2017-12-16 00:08:23 +01:00
|
|
|
sPokeblockMenu->gfxState++;
|
|
|
|
break;
|
|
|
|
case 4:
|
2018-12-17 23:00:08 +01:00
|
|
|
LoadCompressedSpritePalette(&gPokeblockCase_SpritePal);
|
2017-12-16 00:08:23 +01:00
|
|
|
sPokeblockMenu->gfxState++;
|
|
|
|
break;
|
|
|
|
case 5:
|
|
|
|
LoadListMenuArrowsGfx();
|
|
|
|
sPokeblockMenu->gfxState = 0;
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void HandleInitWindows(void)
|
|
|
|
{
|
|
|
|
u8 i;
|
|
|
|
|
|
|
|
InitWindows(sWindowTemplatesForPokeblockMenu);
|
|
|
|
DeactivateAllTextPrinters();
|
2018-07-15 13:23:38 +02:00
|
|
|
LoadUserWindowBorderGfx(0, 1, 0xE0);
|
2018-06-17 16:48:58 +02:00
|
|
|
LoadMessageBoxGfx(0, 0xA, 0xD0);
|
2017-12-16 00:08:23 +01:00
|
|
|
LoadPalette(gUnknown_0860F074, 0xF0, 0x20);
|
|
|
|
|
|
|
|
for (i = 0; i < ARRAY_COUNT(sWindowTemplatesForPokeblockMenu) - 1; i++)
|
|
|
|
{
|
2019-03-02 23:25:39 +01:00
|
|
|
FillWindowPixelBuffer(i, PIXEL_FILL(0));
|
2017-12-16 00:08:23 +01:00
|
|
|
}
|
|
|
|
|
2020-05-14 10:37:09 +02:00
|
|
|
ScheduleBgCopyTilemapToVram(0);
|
|
|
|
ScheduleBgCopyTilemapToVram(1);
|
2017-12-16 00:08:23 +01:00
|
|
|
}
|
|
|
|
|
2017-12-16 15:10:29 +01:00
|
|
|
static void PrintOnPokeblockWindow(u8 windowId, const u8 *string, s32 x)
|
2017-12-16 00:08:23 +01:00
|
|
|
{
|
2018-09-08 23:38:30 +02:00
|
|
|
AddTextPrinterParameterized4(windowId, 1, x, 1, 0, 0, sTextColorInPokeblockMenu, 0, string);
|
2017-12-16 00:08:23 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static void PutPokeblockInfoText(void)
|
|
|
|
{
|
|
|
|
u8 i;
|
|
|
|
|
2018-04-29 13:36:26 +02:00
|
|
|
const u8 *itemName = ItemId_GetName(ITEM_POKEBLOCK_CASE);
|
2017-12-16 00:08:23 +01:00
|
|
|
PrintOnPokeblockWindow(0, itemName, GetStringCenterAlignXOffset(1, itemName, 0x48));
|
|
|
|
|
|
|
|
PrintOnPokeblockWindow(2, gText_Spicy, 0);
|
|
|
|
PrintOnPokeblockWindow(3, gText_Dry, 0);
|
|
|
|
PrintOnPokeblockWindow(4, gText_Sweet, 0);
|
|
|
|
PrintOnPokeblockWindow(5, gText_Bitter, 0);
|
|
|
|
PrintOnPokeblockWindow(6, gText_Sour, 0);
|
|
|
|
|
|
|
|
for (i = 0; i < 8; i++)
|
|
|
|
{
|
|
|
|
PutWindowTilemap(i);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-12-16 15:10:29 +01:00
|
|
|
static void HandlePokeblockListMenuItems(void)
|
2017-12-16 00:08:23 +01:00
|
|
|
{
|
|
|
|
u16 i;
|
|
|
|
|
|
|
|
for (i = 0; i < sPokeblockMenu->itemsNo - 1; i++)
|
|
|
|
{
|
|
|
|
PutPokeblockListMenuString(sPokeblockMenu->menuItemsStrings[i], i);
|
|
|
|
sPokeblockMenu->items[i].name = sPokeblockMenu->menuItemsStrings[i];
|
|
|
|
sPokeblockMenu->items[i].id = i;
|
|
|
|
}
|
|
|
|
|
|
|
|
StringCopy(sPokeblockMenu->menuItemsStrings[i], gText_StowCase);
|
|
|
|
sPokeblockMenu->items[i].name = sPokeblockMenu->menuItemsStrings[i];
|
2019-03-03 08:50:40 +01:00
|
|
|
sPokeblockMenu->items[i].id = LIST_CANCEL;
|
2017-12-16 00:08:23 +01:00
|
|
|
|
|
|
|
gMultiuseListMenuTemplate = sPokeblockListMenuTemplate;
|
2018-03-03 14:58:41 +01:00
|
|
|
gMultiuseListMenuTemplate.fontId = 7;
|
2017-12-16 00:08:23 +01:00
|
|
|
gMultiuseListMenuTemplate.totalItems = sPokeblockMenu->itemsNo;
|
|
|
|
gMultiuseListMenuTemplate.items = sPokeblockMenu->items;
|
|
|
|
gMultiuseListMenuTemplate.maxShowed = sPokeblockMenu->maxShowed;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void PutPokeblockListMenuString(u8 *dst, u16 pkblId)
|
|
|
|
{
|
|
|
|
struct Pokeblock *pkblock = &gSaveBlock1Ptr->pokeblocks[pkblId];
|
|
|
|
u8 *txtPtr = StringCopy(dst, gPokeblockNames[pkblock->color]);
|
|
|
|
|
|
|
|
*(txtPtr++) = EXT_CTRL_CODE_BEGIN;
|
2020-08-11 05:50:49 +02:00
|
|
|
*(txtPtr++) = EXT_CTRL_CODE_SKIP;
|
2020-08-24 20:52:33 +02:00
|
|
|
*(txtPtr++) = CHAR_BLOCK_1;
|
2017-12-16 00:08:23 +01:00
|
|
|
|
|
|
|
ConvertIntToDecimalStringN(gStringVar1, GetHighestPokeblocksFlavorLevel(pkblock), STR_CONV_MODE_LEFT_ALIGN, 3);
|
|
|
|
StringExpandPlaceholders(txtPtr, gText_LvVar1);
|
|
|
|
}
|
|
|
|
|
2018-03-03 14:58:41 +01:00
|
|
|
static void MovePokeblockMenuCursor(s32 pkblId, bool8 arg1, struct ListMenu *arg2)
|
2017-12-16 00:08:23 +01:00
|
|
|
{
|
|
|
|
if (arg1 != TRUE)
|
|
|
|
{
|
|
|
|
PlaySE(SE_SELECT);
|
|
|
|
gSprites[sPokeblockMenu->pokeblockCaseSpriteId].callback = sub_8136470;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!sPokeblockMenu->isSwapping)
|
|
|
|
sub_8135FCC(pkblId);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void sub_8135FCC(s32 pkblId)
|
|
|
|
{
|
|
|
|
u8 i;
|
|
|
|
struct Pokeblock *pokeblock;
|
|
|
|
u16 rectTilemapSrc[2];
|
|
|
|
|
2019-03-02 23:25:39 +01:00
|
|
|
FillWindowPixelBuffer(7, PIXEL_FILL(0));
|
2017-12-16 00:08:23 +01:00
|
|
|
|
2019-03-03 08:50:40 +01:00
|
|
|
if (pkblId != LIST_CANCEL)
|
2017-12-16 00:08:23 +01:00
|
|
|
{
|
|
|
|
pokeblock = &gSaveBlock1Ptr->pokeblocks[pkblId];
|
|
|
|
rectTilemapSrc[0] = 0x17;
|
|
|
|
rectTilemapSrc[1] = 0x18;
|
|
|
|
for (i = 0; i < FLAVOR_COUNT; i++)
|
|
|
|
{
|
|
|
|
if (GetPokeblockData(pokeblock, PBLOCK_SPICY + i) > 0)
|
|
|
|
{
|
2021-03-30 23:38:09 +02:00
|
|
|
rectTilemapSrc[0] = (i << 12) + 0x17;
|
|
|
|
rectTilemapSrc[1] = (i << 12) + 0x18;
|
2017-12-16 00:08:23 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
rectTilemapSrc[0] = 0xF;
|
|
|
|
rectTilemapSrc[1] = 0xF;
|
|
|
|
}
|
|
|
|
CopyToBgTilemapBufferRect(2, rectTilemapSrc, (i / 3 * 6) + 1, (i % 3 * 2) + 13, 1, 2);
|
|
|
|
}
|
|
|
|
ConvertIntToDecimalStringN(gStringVar1, GetPokeblocksFeel(pokeblock), STR_CONV_MODE_RIGHT_ALIGN, 2);
|
|
|
|
PrintOnPokeblockWindow(7, gStringVar1, 4);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
rectTilemapSrc[0] = 0xF;
|
|
|
|
rectTilemapSrc[1] = 0xF;
|
|
|
|
|
|
|
|
for (i = 0; i < FLAVOR_COUNT; i++)
|
|
|
|
{
|
|
|
|
CopyToBgTilemapBufferRect(2, rectTilemapSrc, (i / 3 * 6) + 1, (i % 3 * 2) + 13, 1, 2);
|
|
|
|
}
|
|
|
|
CopyWindowToVram(7, 2);
|
|
|
|
}
|
|
|
|
|
2020-05-14 10:37:09 +02:00
|
|
|
ScheduleBgCopyTilemapToVram(0);
|
|
|
|
ScheduleBgCopyTilemapToVram(2);
|
2017-12-16 00:08:23 +01:00
|
|
|
}
|
|
|
|
|
2017-12-16 15:10:29 +01:00
|
|
|
static void HandlePokeblockMenuCursor(u16 cursorPos, u16 arg1)
|
2017-12-16 00:08:23 +01:00
|
|
|
{
|
|
|
|
FillBgTilemapBufferRect_Palette0(2, arg1, 0xF, (cursorPos * 2) + 1, 0xE, 2);
|
2020-05-14 10:37:09 +02:00
|
|
|
ScheduleBgCopyTilemapToVram(2);
|
2017-12-16 00:08:23 +01:00
|
|
|
}
|
|
|
|
|
2017-12-16 15:10:29 +01:00
|
|
|
static void CompactPokeblockSlots(void)
|
2017-12-16 00:08:23 +01:00
|
|
|
{
|
|
|
|
u16 i, j;
|
|
|
|
|
|
|
|
for (i = 0; i < POKEBLOCKS_COUNT - 1; i++)
|
|
|
|
{
|
|
|
|
for (j = i + 1; j < POKEBLOCKS_COUNT; j++)
|
|
|
|
{
|
2020-08-24 20:52:33 +02:00
|
|
|
if (gSaveBlock1Ptr->pokeblocks[i].color == PBLOCK_CLR_NONE)
|
2017-12-16 00:08:23 +01:00
|
|
|
{
|
|
|
|
struct Pokeblock temp = gSaveBlock1Ptr->pokeblocks[i];
|
|
|
|
gSaveBlock1Ptr->pokeblocks[i] = gSaveBlock1Ptr->pokeblocks[j];
|
|
|
|
gSaveBlock1Ptr->pokeblocks[j] = temp;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-12-16 15:10:29 +01:00
|
|
|
static void SwapSortPokeblocksInternalData(u32 id1, u32 id2)
|
2017-12-16 00:08:23 +01:00
|
|
|
{
|
|
|
|
s16 i, count;
|
|
|
|
struct Pokeblock *pokeblocks = gSaveBlock1Ptr->pokeblocks;
|
|
|
|
struct Pokeblock *copyPokeblock1;
|
|
|
|
|
|
|
|
if (id1 == id2)
|
|
|
|
return;
|
|
|
|
|
|
|
|
copyPokeblock1 = Alloc(sizeof(struct Pokeblock));
|
|
|
|
*copyPokeblock1 = pokeblocks[id1];
|
|
|
|
|
|
|
|
if (id2 > id1)
|
|
|
|
{
|
|
|
|
id2--;
|
|
|
|
for (count = id2, i = id1; i < count; i++)
|
|
|
|
pokeblocks[i] = pokeblocks[i + 1];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
for (count = id2, i = id1; i > count; i--)
|
|
|
|
pokeblocks[i] = pokeblocks[i - 1];
|
|
|
|
}
|
|
|
|
|
|
|
|
pokeblocks[id2] = *copyPokeblock1;
|
|
|
|
Free(copyPokeblock1);
|
|
|
|
}
|
|
|
|
|
|
|
|
void ResetPokeblockScrollPositions(void)
|
|
|
|
{
|
|
|
|
sSavedPokeblockData.lastItemPos = 0;
|
|
|
|
sSavedPokeblockData.lastItemPage = 0;
|
|
|
|
}
|
|
|
|
|
2017-12-16 15:10:29 +01:00
|
|
|
static void SetMenuItemsCountAndMaxShowed(void)
|
2017-12-16 00:08:23 +01:00
|
|
|
{
|
|
|
|
u16 i;
|
|
|
|
|
|
|
|
CompactPokeblockSlots();
|
|
|
|
|
|
|
|
for (sPokeblockMenu->itemsNo = 0, i = 0; i < POKEBLOCKS_COUNT; i++)
|
|
|
|
{
|
2020-08-24 20:52:33 +02:00
|
|
|
if (gSaveBlock1Ptr->pokeblocks[i].color != PBLOCK_CLR_NONE)
|
2017-12-16 00:08:23 +01:00
|
|
|
sPokeblockMenu->itemsNo++;
|
|
|
|
}
|
|
|
|
|
|
|
|
sPokeblockMenu->itemsNo++; // STOW CASE menu item
|
|
|
|
|
|
|
|
if (sPokeblockMenu->itemsNo > 9)
|
|
|
|
sPokeblockMenu->maxShowed = 9;
|
|
|
|
else
|
|
|
|
sPokeblockMenu->maxShowed = sPokeblockMenu->itemsNo;
|
|
|
|
}
|
|
|
|
|
2017-12-16 15:10:29 +01:00
|
|
|
static void sub_81362E0(void)
|
2017-12-16 00:08:23 +01:00
|
|
|
{
|
|
|
|
if (sSavedPokeblockData.lastItemPage != 0)
|
|
|
|
{
|
|
|
|
if (sSavedPokeblockData.lastItemPage + sPokeblockMenu->maxShowed > sPokeblockMenu->itemsNo)
|
|
|
|
sSavedPokeblockData.lastItemPage = sPokeblockMenu->itemsNo - sPokeblockMenu->maxShowed;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (sSavedPokeblockData.lastItemPage + sSavedPokeblockData.lastItemPos >= sPokeblockMenu->itemsNo)
|
|
|
|
{
|
|
|
|
if (sPokeblockMenu->itemsNo == 0)
|
|
|
|
sSavedPokeblockData.lastItemPos = 0;
|
|
|
|
else
|
|
|
|
sSavedPokeblockData.lastItemPos = sPokeblockMenu->itemsNo - 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-12-16 15:10:29 +01:00
|
|
|
static void sub_8136344(void)
|
2017-12-16 00:08:23 +01:00
|
|
|
{
|
|
|
|
if (sSavedPokeblockData.lastItemPos > 4)
|
|
|
|
{
|
|
|
|
u8 i;
|
|
|
|
|
|
|
|
for (i = 0;
|
2017-12-20 17:20:41 +01:00
|
|
|
(i < sSavedPokeblockData.lastItemPos - 4) && (sSavedPokeblockData.lastItemPage + sPokeblockMenu->maxShowed != sPokeblockMenu->itemsNo);
|
2017-12-16 00:08:23 +01:00
|
|
|
sSavedPokeblockData.lastItemPos--, sSavedPokeblockData.lastItemPage++, i++);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-12-16 15:10:29 +01:00
|
|
|
static void sub_81363BC(void)
|
2017-12-16 00:08:23 +01:00
|
|
|
{
|
2021-02-20 05:22:26 +01:00
|
|
|
if (sPokeblockMenu->unkTaskId == TASK_NONE)
|
2017-12-16 00:08:23 +01:00
|
|
|
{
|
2018-07-15 13:23:38 +02:00
|
|
|
sPokeblockMenu->unkTaskId = AddScrollIndicatorArrowPairParameterized(SCROLL_ARROW_UP, 0xB0, 8, 0x98, sPokeblockMenu->itemsNo - sPokeblockMenu->maxShowed,
|
2017-12-16 00:08:23 +01:00
|
|
|
0x456, 0x456, &sSavedPokeblockData.lastItemPage);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-12-16 15:10:29 +01:00
|
|
|
static void sub_8136418(void)
|
2017-12-16 00:08:23 +01:00
|
|
|
{
|
2021-02-20 05:22:26 +01:00
|
|
|
if (sPokeblockMenu->unkTaskId != TASK_NONE)
|
2017-12-16 00:08:23 +01:00
|
|
|
{
|
|
|
|
RemoveScrollIndicatorArrowPair(sPokeblockMenu->unkTaskId);
|
2021-02-20 05:22:26 +01:00
|
|
|
sPokeblockMenu->unkTaskId = TASK_NONE;
|
2017-12-16 00:08:23 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
u8 CreatePokeblockCaseSprite(s16 x, s16 y, u8 subpriority)
|
|
|
|
{
|
|
|
|
return CreateSprite(&sSpriteTemplate_PokeblockCase, x, y, subpriority);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void sub_8136470(struct Sprite *sprite)
|
|
|
|
{
|
|
|
|
if (sprite->data[0] > 1)
|
|
|
|
sprite->data[0] = 0;
|
|
|
|
|
|
|
|
switch (sprite->data[0])
|
|
|
|
{
|
|
|
|
case 0:
|
2019-12-05 03:00:45 +01:00
|
|
|
sprite->oam.affineMode = ST_OAM_AFFINE_NORMAL;
|
2017-12-16 00:08:23 +01:00
|
|
|
sprite->affineAnims = sSpriteAffineAnimTable_85B26F0;
|
|
|
|
InitSpriteAffineAnim(sprite);
|
|
|
|
sprite->data[0] = 1;
|
|
|
|
sprite->data[1] = 0;
|
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
if (++sprite->data[1] > 11)
|
|
|
|
{
|
2019-12-05 03:00:45 +01:00
|
|
|
sprite->oam.affineMode = ST_OAM_AFFINE_OFF;
|
2017-12-16 00:08:23 +01:00
|
|
|
sprite->data[0] = 0;
|
|
|
|
sprite->data[1] = 0;
|
|
|
|
FreeOamMatrix(sprite->oam.matrixNum);
|
|
|
|
sprite->callback = SpriteCallbackDummy;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-12-16 15:10:29 +01:00
|
|
|
static void FadePaletteAndSetTaskToClosePokeblockCase(u8 taskId)
|
2017-12-16 00:08:23 +01:00
|
|
|
{
|
2021-02-24 17:01:02 +01:00
|
|
|
BeginNormalPaletteFade(PALETTES_ALL, 0, 0, 0x10, RGB_BLACK);
|
2017-12-16 00:08:23 +01:00
|
|
|
gTasks[taskId].func = Task_FreeDataAndExitPokeblockCase;
|
|
|
|
}
|
|
|
|
|
2017-12-16 15:10:29 +01:00
|
|
|
static void Task_FreeDataAndExitPokeblockCase(u8 taskId)
|
2017-12-16 00:08:23 +01:00
|
|
|
{
|
|
|
|
s16 *data = gTasks[taskId].data;
|
|
|
|
|
|
|
|
if (!gPaletteFade.active)
|
|
|
|
{
|
|
|
|
if (sPokeblockMenu->caseId == PBLOCK_CASE_FEEDER || sPokeblockMenu->caseId == PBLOCK_CASE_GIVE)
|
2019-12-17 09:24:44 +01:00
|
|
|
gFieldCallback = FieldCB_ContinueScriptHandleMusic;
|
2017-12-16 00:08:23 +01:00
|
|
|
|
2018-03-02 16:34:31 +01:00
|
|
|
DestroyListMenuTask(data[0], &sSavedPokeblockData.lastItemPage, &sSavedPokeblockData.lastItemPos);
|
2017-12-16 00:08:23 +01:00
|
|
|
sub_8136418();
|
|
|
|
ResetSpriteData();
|
|
|
|
FreeAllSpritePalettes();
|
|
|
|
|
2017-12-16 15:10:29 +01:00
|
|
|
if (sPokeblockMenu->callbackOnUse != NULL)
|
|
|
|
SetMainCallback2(sPokeblockMenu->callbackOnUse);
|
2017-12-16 00:08:23 +01:00
|
|
|
else
|
|
|
|
SetMainCallback2(sSavedPokeblockData.callback);
|
|
|
|
|
|
|
|
FreeAllWindowBuffers();
|
|
|
|
Free(sPokeblockMenu);
|
|
|
|
DestroyTask(taskId);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-12-16 15:10:29 +01:00
|
|
|
static void Task_HandlePokeblockMenuInput(u8 taskId)
|
2017-12-16 00:08:23 +01:00
|
|
|
{
|
|
|
|
s16 *data = gTasks[taskId].data;
|
|
|
|
|
2020-05-14 10:37:09 +02:00
|
|
|
if (!gPaletteFade.active && MenuHelpers_CallLinkSomething() != TRUE)
|
2017-12-16 00:08:23 +01:00
|
|
|
{
|
2020-11-03 02:02:39 +01:00
|
|
|
if (JOY_NEW(SELECT_BUTTON))
|
2017-12-16 00:08:23 +01:00
|
|
|
{
|
2018-03-02 16:34:31 +01:00
|
|
|
ListMenuGetScrollAndRow(data[0], &sSavedPokeblockData.lastItemPage, &sSavedPokeblockData.lastItemPos);
|
2017-12-16 00:08:23 +01:00
|
|
|
if (sSavedPokeblockData.lastItemPage + sSavedPokeblockData.lastItemPos != sPokeblockMenu->itemsNo - 1)
|
|
|
|
{
|
|
|
|
PlaySE(SE_SELECT);
|
|
|
|
HandlePokeblockMenuCursor(sSavedPokeblockData.lastItemPos, 0x2005);
|
|
|
|
data[2] = sSavedPokeblockData.lastItemPage + sSavedPokeblockData.lastItemPos;
|
|
|
|
sPokeblockMenu->isSwapping = TRUE;
|
|
|
|
gTasks[taskId].func = Task_HandlePokeblocksSwapInput;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
u16 oldPosition = sSavedPokeblockData.lastItemPos;
|
2019-02-02 11:04:38 +01:00
|
|
|
s32 itemId = ListMenu_ProcessInput(data[0]);
|
2017-12-16 00:08:23 +01:00
|
|
|
|
2018-03-02 16:34:31 +01:00
|
|
|
ListMenuGetScrollAndRow(data[0], &sSavedPokeblockData.lastItemPage, &sSavedPokeblockData.lastItemPos);
|
2017-12-16 00:08:23 +01:00
|
|
|
if (oldPosition != sSavedPokeblockData.lastItemPos)
|
|
|
|
{
|
|
|
|
HandlePokeblockMenuCursor(oldPosition, 5);
|
|
|
|
HandlePokeblockMenuCursor(sSavedPokeblockData.lastItemPos, 0x1005);
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (itemId)
|
|
|
|
{
|
|
|
|
case LIST_NOTHING_CHOSEN:
|
|
|
|
break;
|
2019-03-03 08:50:40 +01:00
|
|
|
case LIST_CANCEL:
|
2017-12-16 00:08:23 +01:00
|
|
|
PlaySE(SE_SELECT);
|
2018-12-05 15:31:01 +01:00
|
|
|
gSpecialVar_Result = 0xFFFF;
|
2017-12-16 00:08:23 +01:00
|
|
|
gSpecialVar_ItemId = 0;
|
|
|
|
FadePaletteAndSetTaskToClosePokeblockCase(taskId);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
PlaySE(SE_SELECT);
|
|
|
|
gSpecialVar_ItemId = itemId;
|
|
|
|
PutPokeblockOptionsWindow(taskId);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void Task_HandlePokeblocksSwapInput(u8 taskId)
|
|
|
|
{
|
|
|
|
s16 *data = gTasks[taskId].data;
|
|
|
|
|
2020-05-14 10:37:09 +02:00
|
|
|
if (MenuHelpers_CallLinkSomething() == TRUE)
|
2017-12-16 00:08:23 +01:00
|
|
|
return;
|
|
|
|
|
2020-11-03 02:02:39 +01:00
|
|
|
if (JOY_NEW(SELECT_BUTTON))
|
2017-12-16 00:08:23 +01:00
|
|
|
{
|
|
|
|
PlaySE(SE_SELECT);
|
2018-03-02 16:34:31 +01:00
|
|
|
ListMenuGetScrollAndRow(data[0], &sSavedPokeblockData.lastItemPage, &sSavedPokeblockData.lastItemPos);
|
2017-12-16 00:08:23 +01:00
|
|
|
HandlePokeblocksSwap(taskId, FALSE);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
u16 i = sSavedPokeblockData.lastItemPage;
|
|
|
|
u16 var = sSavedPokeblockData.lastItemPos;
|
2019-02-02 11:04:38 +01:00
|
|
|
s32 itemId = ListMenu_ProcessInput(data[0]);
|
2017-12-16 00:08:23 +01:00
|
|
|
|
2018-03-02 16:34:31 +01:00
|
|
|
ListMenuGetScrollAndRow(data[0], &sSavedPokeblockData.lastItemPage, &sSavedPokeblockData.lastItemPos);
|
2017-12-16 00:08:23 +01:00
|
|
|
if (i != sSavedPokeblockData.lastItemPage || var != sSavedPokeblockData.lastItemPos)
|
|
|
|
{
|
|
|
|
for (i = 0; i < 9; i++)
|
|
|
|
{
|
|
|
|
var = i + sSavedPokeblockData.lastItemPage;
|
|
|
|
if (var == data[2])
|
|
|
|
HandlePokeblockMenuCursor(i, 0x2005);
|
|
|
|
else
|
|
|
|
HandlePokeblockMenuCursor(i, 5);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
sub_81223FC(sPokeblockMenu->field_E75, FIELD_E75_COUNT, 0);
|
|
|
|
sub_8122448(sPokeblockMenu->field_E75, FIELD_E75_COUNT, 0x80, (sSavedPokeblockData.lastItemPos * 16) + 8);
|
|
|
|
|
|
|
|
switch (itemId)
|
|
|
|
{
|
|
|
|
case LIST_NOTHING_CHOSEN:
|
|
|
|
break;
|
2019-03-03 08:50:40 +01:00
|
|
|
case LIST_CANCEL: // same id as STOW CASE field
|
2017-12-16 00:08:23 +01:00
|
|
|
PlaySE(SE_SELECT);
|
2020-11-03 02:02:39 +01:00
|
|
|
if (JOY_NEW(A_BUTTON))
|
2017-12-16 00:08:23 +01:00
|
|
|
HandlePokeblocksSwap(taskId, FALSE);
|
|
|
|
else
|
|
|
|
HandlePokeblocksSwap(taskId, TRUE);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
PlaySE(SE_SELECT);
|
|
|
|
HandlePokeblocksSwap(taskId, FALSE);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-12-16 15:10:29 +01:00
|
|
|
static void HandlePokeblocksSwap(u8 taskId, bool8 noSwap)
|
2017-12-16 00:08:23 +01:00
|
|
|
{
|
|
|
|
u8 i;
|
|
|
|
s16 *data = gTasks[taskId].data;
|
|
|
|
u16 swappedFromId = sSavedPokeblockData.lastItemPage + sSavedPokeblockData.lastItemPos;
|
|
|
|
|
|
|
|
sPokeblockMenu->isSwapping = FALSE;
|
2018-03-02 16:34:31 +01:00
|
|
|
DestroyListMenuTask(data[0], &sSavedPokeblockData.lastItemPage, &sSavedPokeblockData.lastItemPos);
|
2017-12-16 00:08:23 +01:00
|
|
|
|
|
|
|
if (!noSwap && data[2] != swappedFromId && data[2] != swappedFromId - 1)
|
|
|
|
{
|
|
|
|
SwapSortPokeblocksInternalData(data[2], swappedFromId);
|
|
|
|
HandlePokeblockListMenuItems();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (data[2] < swappedFromId)
|
|
|
|
sSavedPokeblockData.lastItemPos--;
|
|
|
|
|
|
|
|
data[0] = ListMenuInit(&gMultiuseListMenuTemplate, sSavedPokeblockData.lastItemPage, sSavedPokeblockData.lastItemPos);
|
2020-05-14 10:37:09 +02:00
|
|
|
ScheduleBgCopyTilemapToVram(0);
|
2017-12-16 00:08:23 +01:00
|
|
|
sub_81223FC(sPokeblockMenu->field_E75, FIELD_E75_COUNT, 1);
|
|
|
|
|
|
|
|
for (i = 0; i < 9; i++)
|
|
|
|
HandlePokeblockMenuCursor(i, 5);
|
|
|
|
|
|
|
|
HandlePokeblockMenuCursor(sSavedPokeblockData.lastItemPos, 0x1005);
|
|
|
|
gTasks[taskId].func = Task_HandlePokeblockMenuInput;
|
|
|
|
}
|
2017-12-16 15:10:29 +01:00
|
|
|
|
|
|
|
static void PutPokeblockOptionsWindow(u8 taskId)
|
|
|
|
{
|
|
|
|
s16 *data = gTasks[taskId].data;
|
|
|
|
|
|
|
|
if (sPokeblockMenu->optionsNo == 3)
|
|
|
|
data[1] = 8;
|
|
|
|
else
|
|
|
|
data[1] = 9;
|
|
|
|
|
|
|
|
sub_8136418();
|
2019-02-22 07:40:11 +01:00
|
|
|
DrawStdFrameWithCustomTileAndPalette(data[1], 0, 1, 0xE);
|
2017-12-16 15:10:29 +01:00
|
|
|
sub_81995E4(data[1], sPokeblockMenu->optionsNo, sPokeblockMenuActions, sPokeblockMenu->pokeblockOptionsIds);
|
|
|
|
InitMenuInUpperLeftCornerPlaySoundWhenAPressed(data[1], sPokeblockMenu->optionsNo, 0);
|
|
|
|
PutWindowTilemap(data[1]);
|
2020-05-14 10:37:09 +02:00
|
|
|
ScheduleBgCopyTilemapToVram(1);
|
2017-12-16 15:10:29 +01:00
|
|
|
|
|
|
|
gTasks[taskId].func = Task_HandlePokeblockOptionsInput;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void Task_HandlePokeblockOptionsInput(u8 taskId)
|
|
|
|
{
|
|
|
|
s8 itemId;
|
|
|
|
|
2020-05-14 10:37:09 +02:00
|
|
|
if (MenuHelpers_CallLinkSomething() == TRUE)
|
2017-12-16 15:10:29 +01:00
|
|
|
return;
|
|
|
|
|
2018-11-05 21:45:54 +01:00
|
|
|
itemId = Menu_ProcessInputNoWrap();
|
2017-12-16 15:10:29 +01:00
|
|
|
if (itemId == MENU_NOTHING_CHOSEN)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
else if (itemId == MENU_B_PRESSED)
|
|
|
|
{
|
|
|
|
PlaySE(SE_SELECT);
|
|
|
|
PokeblockAction_Cancel(taskId);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
PlaySE(SE_SELECT);
|
|
|
|
sPokeblockMenuActions[sPokeblockMenu->pokeblockOptionsIds[itemId]].func.void_u8(taskId);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void PokeblockAction_UseOnField(u8 taskId)
|
|
|
|
{
|
|
|
|
sPokeblockMenu->callbackOnUse = UsePokeblockOnField;
|
|
|
|
FadePaletteAndSetTaskToClosePokeblockCase(taskId);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void UsePokeblockOnField(void)
|
|
|
|
{
|
|
|
|
ChooseMonToGivePokeblock(&gSaveBlock1Ptr->pokeblocks[gSpecialVar_ItemId], ReturnToPokeblockCaseOnField);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void ReturnToPokeblockCaseOnField(void)
|
|
|
|
{
|
|
|
|
OpenPokeblockCase(PBLOCK_CASE_FIELD, sSavedPokeblockData.callback);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void PokeblockAction_Toss(u8 taskId)
|
|
|
|
{
|
|
|
|
s16 *data = gTasks[taskId].data;
|
|
|
|
|
2019-02-22 07:40:11 +01:00
|
|
|
ClearStdWindowAndFrameToTransparent(data[1], FALSE);
|
2017-12-16 15:10:29 +01:00
|
|
|
StringCopy(gStringVar1, gPokeblockNames[gSaveBlock1Ptr->pokeblocks[gSpecialVar_ItemId].color]);
|
|
|
|
StringExpandPlaceholders(gStringVar4, gText_ThrowAwayVar1);
|
2018-11-06 18:30:21 +01:00
|
|
|
DisplayMessageAndContinueTask(taskId, 10, 10, 13, 1, GetPlayerTextSpeedDelay(), gStringVar4, CreateTossPokeblockYesNoMenu);
|
2017-12-16 15:10:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static void CreateTossPokeblockYesNoMenu(u8 taskId)
|
|
|
|
{
|
|
|
|
CreateYesNoMenuWithCallbacks(taskId, &sTossPkblockWindowTemplate, 1, 0, 2, 1, 0xE, &sTossYesNoFuncTable);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void TossPokeblockChoice_Yes(u8 taskId)
|
|
|
|
{
|
|
|
|
StringExpandPlaceholders(gStringVar4, gText_Var1ThrownAway);
|
2018-11-06 18:30:21 +01:00
|
|
|
DisplayMessageAndContinueTask(taskId, 10, 10, 13, 1, GetPlayerTextSpeedDelay(), gStringVar4, HandleErasePokeblock);
|
2017-12-16 15:10:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static void HandleErasePokeblock(u8 taskId)
|
|
|
|
{
|
2020-11-03 02:02:39 +01:00
|
|
|
if (JOY_NEW(A_BUTTON | B_BUTTON))
|
2017-12-16 15:10:29 +01:00
|
|
|
{
|
|
|
|
s16 *data;
|
|
|
|
u16 *lastPage, *lastPos;
|
|
|
|
|
|
|
|
TryClearPokeblock(gSpecialVar_ItemId);
|
|
|
|
PlaySE(SE_SELECT);
|
|
|
|
|
|
|
|
lastPage = &sSavedPokeblockData.lastItemPage;
|
|
|
|
lastPos = &sSavedPokeblockData.lastItemPos;
|
|
|
|
data = gTasks[taskId].data;
|
|
|
|
|
2018-03-02 16:34:31 +01:00
|
|
|
DestroyListMenuTask(data[0], lastPage, lastPos);
|
2017-12-16 15:10:29 +01:00
|
|
|
HandlePokeblockMenuCursor(*lastPos, 5);
|
|
|
|
SetMenuItemsCountAndMaxShowed();
|
|
|
|
sub_81362E0();
|
|
|
|
HandlePokeblockListMenuItems();
|
|
|
|
data[0] = ListMenuInit(&gMultiuseListMenuTemplate, *lastPage, *lastPos);
|
|
|
|
HandlePokeblockMenuCursor(*lastPos, 0x1005);
|
2020-05-14 10:37:09 +02:00
|
|
|
ScheduleBgCopyTilemapToVram(0);
|
|
|
|
ScheduleBgCopyTilemapToVram(1);
|
2017-12-16 15:10:29 +01:00
|
|
|
TossPokeblockChoice_No(taskId);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void TossPokeblockChoice_No(u8 taskId)
|
|
|
|
{
|
2019-02-22 07:40:11 +01:00
|
|
|
ClearDialogWindowAndFrameToTransparent(10, FALSE);
|
2020-05-14 10:37:09 +02:00
|
|
|
ScheduleBgCopyTilemapToVram(1);
|
2017-12-16 15:10:29 +01:00
|
|
|
sub_81363BC();
|
|
|
|
gTasks[taskId].func = Task_HandlePokeblockMenuInput;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void PokeblockAction_UseInBattle(u8 taskId)
|
|
|
|
{
|
|
|
|
u8 nature = GetNature(&gEnemyParty[0]);
|
|
|
|
s16 gain = PokeblockGetGain(nature, &gSaveBlock1Ptr->pokeblocks[gSpecialVar_ItemId]);
|
|
|
|
StringCopy(gBattleTextBuff1, gPokeblockNames[gSaveBlock1Ptr->pokeblocks[gSpecialVar_ItemId].color]);
|
|
|
|
TryClearPokeblock(gSpecialVar_ItemId);
|
|
|
|
|
|
|
|
gSpecialVar_ItemId = gSaveBlock1Ptr->pokeblocks[gSpecialVar_ItemId].color << 8;
|
|
|
|
if (gain == 0)
|
|
|
|
gSpecialVar_ItemId += 1;
|
|
|
|
else if (gain > 0)
|
|
|
|
gSpecialVar_ItemId += 2;
|
|
|
|
else
|
|
|
|
gSpecialVar_ItemId += 3;
|
|
|
|
|
|
|
|
FadePaletteAndSetTaskToClosePokeblockCase(taskId);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void PokeblockAction_UseOnPokeblockFeeder(u8 taskId)
|
|
|
|
{
|
|
|
|
SafariZoneActivatePokeblockFeeder(gSpecialVar_ItemId);
|
|
|
|
StringCopy(gStringVar1, gPokeblockNames[gSaveBlock1Ptr->pokeblocks[gSpecialVar_ItemId].color]);
|
|
|
|
gSpecialVar_Result = gSpecialVar_ItemId;
|
|
|
|
TryClearPokeblock(gSpecialVar_ItemId);
|
|
|
|
gSpecialVar_ItemId = 0;
|
|
|
|
FadePaletteAndSetTaskToClosePokeblockCase(taskId);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void PokeblockAction_GiveToContestLady(u8 taskId)
|
|
|
|
{
|
|
|
|
gSpecialVar_0x8004 = GivePokeblockToContestLady(&gSaveBlock1Ptr->pokeblocks[gSpecialVar_ItemId]);
|
|
|
|
gSpecialVar_Result = gSpecialVar_ItemId;
|
|
|
|
TryClearPokeblock(gSpecialVar_ItemId);
|
|
|
|
gSpecialVar_ItemId = 0;
|
|
|
|
FadePaletteAndSetTaskToClosePokeblockCase(taskId);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void PokeblockAction_Cancel(u8 taskId)
|
|
|
|
{
|
|
|
|
s16 *data = gTasks[taskId].data;
|
|
|
|
|
2019-02-22 07:40:11 +01:00
|
|
|
ClearStdWindowAndFrameToTransparent(data[1], FALSE);
|
2020-05-14 10:37:09 +02:00
|
|
|
ScheduleBgCopyTilemapToVram(1);
|
2017-12-16 15:10:29 +01:00
|
|
|
sub_81363BC();
|
|
|
|
gTasks[taskId].func = Task_HandlePokeblockMenuInput;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void ClearPokeblock(u8 pkblId)
|
|
|
|
{
|
|
|
|
gSaveBlock1Ptr->pokeblocks[pkblId].color = 0;
|
|
|
|
gSaveBlock1Ptr->pokeblocks[pkblId].spicy = 0;
|
|
|
|
gSaveBlock1Ptr->pokeblocks[pkblId].dry = 0;
|
|
|
|
gSaveBlock1Ptr->pokeblocks[pkblId].sweet = 0;
|
|
|
|
gSaveBlock1Ptr->pokeblocks[pkblId].bitter = 0;
|
|
|
|
gSaveBlock1Ptr->pokeblocks[pkblId].sour = 0;
|
|
|
|
gSaveBlock1Ptr->pokeblocks[pkblId].feel = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void ClearPokeblocks(void)
|
|
|
|
{
|
|
|
|
u8 i;
|
|
|
|
|
|
|
|
for (i = 0; i < POKEBLOCKS_COUNT; i++)
|
|
|
|
ClearPokeblock(i);
|
|
|
|
}
|
|
|
|
|
|
|
|
u8 GetHighestPokeblocksFlavorLevel(const struct Pokeblock *pokeblock)
|
|
|
|
{
|
|
|
|
u8 i;
|
|
|
|
u8 maxFlavor = GetPokeblockData(pokeblock, PBLOCK_SPICY);
|
|
|
|
|
|
|
|
for (i = PBLOCK_SPICY; i < FLAVOR_COUNT; i++)
|
|
|
|
{
|
|
|
|
u8 currFlavor = GetPokeblockData(pokeblock, PBLOCK_SPICY + i);
|
|
|
|
if (maxFlavor < currFlavor)
|
|
|
|
maxFlavor = currFlavor;
|
|
|
|
}
|
|
|
|
|
|
|
|
return maxFlavor;
|
|
|
|
}
|
|
|
|
|
|
|
|
u8 GetPokeblocksFeel(const struct Pokeblock *pokeblock)
|
|
|
|
{
|
|
|
|
u8 feel = GetPokeblockData(pokeblock, PBLOCK_FEEL);
|
|
|
|
if (feel > POKEBLOCK_MAX_FEEL)
|
|
|
|
feel = POKEBLOCK_MAX_FEEL;
|
|
|
|
|
|
|
|
return feel;
|
|
|
|
}
|
|
|
|
|
|
|
|
s8 GetFirstFreePokeblockSlot(void)
|
|
|
|
{
|
|
|
|
u8 i;
|
|
|
|
|
|
|
|
for (i = 0; i < POKEBLOCKS_COUNT; i++)
|
|
|
|
{
|
2020-08-24 20:52:33 +02:00
|
|
|
if (gSaveBlock1Ptr->pokeblocks[i].color == PBLOCK_CLR_NONE)
|
2017-12-16 15:10:29 +01:00
|
|
|
return i;
|
|
|
|
}
|
|
|
|
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool32 AddPokeblock(const struct Pokeblock *pokeblock)
|
|
|
|
{
|
|
|
|
s8 slot = GetFirstFreePokeblockSlot();
|
|
|
|
|
|
|
|
if (slot == -1)
|
|
|
|
{
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
gSaveBlock1Ptr->pokeblocks[slot] = *pokeblock;
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool32 TryClearPokeblock(u8 pkblId)
|
|
|
|
{
|
2020-08-24 20:52:33 +02:00
|
|
|
if (gSaveBlock1Ptr->pokeblocks[pkblId].color == PBLOCK_CLR_NONE)
|
2017-12-16 15:10:29 +01:00
|
|
|
{
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
ClearPokeblock(pkblId);
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
s16 GetPokeblockData(const struct Pokeblock *pokeblock, u8 field)
|
|
|
|
{
|
|
|
|
if (field == PBLOCK_COLOR)
|
|
|
|
return pokeblock->color;
|
|
|
|
if (field == PBLOCK_SPICY)
|
|
|
|
return pokeblock->spicy;
|
|
|
|
if (field == PBLOCK_DRY)
|
|
|
|
return pokeblock->dry;
|
|
|
|
if (field == PBLOCK_SWEET)
|
|
|
|
return pokeblock->sweet;
|
|
|
|
if (field == PBLOCK_BITTER)
|
|
|
|
return pokeblock->bitter;
|
|
|
|
if (field == PBLOCK_SOUR)
|
|
|
|
return pokeblock->sour;
|
|
|
|
if (field == PBLOCK_FEEL)
|
|
|
|
return pokeblock->feel;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
s16 PokeblockGetGain(u8 nature, const struct Pokeblock *pokeblock)
|
|
|
|
{
|
|
|
|
u8 flavor;
|
|
|
|
s16 curGain, totalGain = 0;
|
|
|
|
|
|
|
|
for (flavor = 0; flavor < FLAVOR_COUNT; flavor++)
|
|
|
|
{
|
|
|
|
curGain = GetPokeblockData(pokeblock, flavor + PBLOCK_SPICY);
|
|
|
|
if (curGain > 0)
|
2020-07-17 02:12:12 +02:00
|
|
|
totalGain += curGain * gPokeblockFlavorCompatibilityTable[FLAVOR_COUNT * nature + flavor];
|
2017-12-16 15:10:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return totalGain;
|
|
|
|
}
|
|
|
|
|
|
|
|
void PokeblockCopyName(const struct Pokeblock *pokeblock, u8 *dest)
|
|
|
|
{
|
|
|
|
u8 color = GetPokeblockData(pokeblock, PBLOCK_COLOR);
|
|
|
|
StringCopy(dest, gPokeblockNames[color]);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool8 CopyMonFavoritePokeblockName(u8 nature, u8 *dest)
|
|
|
|
{
|
|
|
|
u8 i;
|
|
|
|
|
|
|
|
for (i = 0; i < FLAVOR_COUNT; i++)
|
|
|
|
{
|
|
|
|
if (PokeblockGetGain(nature, &sFavoritePokeblocksTable[i]) > 0)
|
|
|
|
{
|
|
|
|
StringCopy(dest, gPokeblockNames[i + 1]);
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
u8 GetPokeblocksFlavor(const struct Pokeblock *pokeblock)
|
|
|
|
{
|
|
|
|
s16 bestFlavor = 0;
|
|
|
|
s16 i;
|
|
|
|
|
|
|
|
for (i = 0; i < FLAVOR_COUNT; i++)
|
|
|
|
{
|
|
|
|
if (GetPokeblockData(pokeblock, bestFlavor + 1) < GetPokeblockData(pokeblock, i + 1))
|
|
|
|
bestFlavor = i;
|
|
|
|
}
|
|
|
|
|
|
|
|
return bestFlavor;
|
|
|
|
}
|