pokeemerald/src/battle_pyramid_bag.c

1611 lines
49 KiB
C
Raw Normal View History

2018-08-15 06:56:11 +02:00
#include "global.h"
2018-11-13 23:28:46 +01:00
#include "battle.h"
2018-08-15 06:56:11 +02:00
#include "battle_controllers.h"
2018-11-13 23:28:46 +01:00
#include "battle_pyramid_bag.h"
2018-08-15 06:56:11 +02:00
#include "bg.h"
2018-11-13 23:28:46 +01:00
#include "decompress.h"
#include "event_data.h"
2018-08-15 06:56:11 +02:00
#include "field_effect.h"
#include "field_weather.h"
2018-11-13 23:28:46 +01:00
#include "graphics.h"
2018-08-15 06:56:11 +02:00
#include "gpu_regs.h"
2018-11-13 23:28:46 +01:00
#include "international_string_util.h"
#include "item.h"
#include "item_icon.h"
#include "item_menu.h"
#include "item_use.h"
#include "list_menu.h"
#include "mail.h"
#include "main.h"
#include "malloc.h"
2018-08-15 06:56:11 +02:00
#include "menu.h"
#include "menu_helpers.h"
#include "overworld.h"
#include "palette.h"
#include "party_menu.h"
2018-11-13 23:28:46 +01:00
#include "task.h"
#include "text_window.h"
2018-08-15 06:56:11 +02:00
#include "scanline_effect.h"
#include "script.h"
2018-11-13 23:28:46 +01:00
#include "sound.h"
2018-08-30 15:01:07 +02:00
#include "string_util.h"
#include "strings.h"
#include "constants/items.h"
2018-08-15 06:56:11 +02:00
#include "constants/rgb.h"
2018-08-30 15:01:07 +02:00
#include "constants/songs.h"
2018-08-15 06:56:11 +02:00
2021-04-23 00:49:54 +02:00
#define TAG_SCROLL_ARROW 2910
#define TAG_PYRAMID_BAG 4132
#define TAG_ITEM_ICON 4133
#define TAG_ITEM_ICON_ALT 4134
#define POS_NONE ((u8)-1)
enum {
WIN_LIST,
WIN_INFO,
WIN_MSG,
WIN_TOSS_NUM,
};
EWRAM_DATA struct PyramidBagMenu *gPyramidBagMenu = NULL;
EWRAM_DATA struct PyramidBagMenuState gPyramidBagMenuState = {0};
static void Task_HandlePyramidBagInput(u8);
static void Task_ChooseItemsToTossFromPyramidBag(u8);
static void Task_ClosePyramidBag(u8);
static void Task_BeginItemSwap(u8);
static void OpenContextMenu(u8);
static void TryCloseBagToGiveItem(u8);
static void HandleMenuActionInput_2x2(u8);
static void HandleMenuActionInput_SingleRow(u8);
static void Task_WaitCloseErrorMessage(u8);
static void SetTaskToMainPyramidBagInputHandler(u8);
static void AskConfirmToss(u8);
static void Task_ChooseHowManyToToss(u8);
static void Task_TossItem(u8);
static void ShowCantHoldMessage(u8);
static void PerformItemSwap(u8);
static void Task_ItemSwapHandleInput(u8);
static void CancelItemSwap(u8);
2018-08-30 20:10:57 +02:00
static void SetBagItemsListTemplate(void);
2021-04-23 00:49:54 +02:00
static void CB2_LoadPyramidBagMenu(void);
static void InitPyramidBagBgs(void);
static void AddScrollArrows(void);
static void CreatePyramidBagInputTask(void);
static void InitPyramidBagScroll(void);
static void InitPyramidBagWindows(void);
static void CreatePyramidBagSprite(void);
2021-04-11 22:23:10 +02:00
static void CreateSwapLine(void);
2021-04-23 00:49:54 +02:00
static void LoadPyramidBagPalette(void);
static void ShakePyramidBag(void);
static void ShowNumToToss(void);
2019-12-22 01:01:38 +01:00
static void CloseBattlePyramidBagTextWindow(void);
2021-04-23 00:49:54 +02:00
static bool8 LoadPyramidBagGfx(void);
static bool8 LoadPyramidBagMenu(void);
static void ShowItemIcon(u16, u8);
static void CopyBagItemName(u8 *, u16);
static void FreeItemIconSpriteByAltId(u8);
static void PrintItemDescription(s32);
static void PrintSelectorArrowAtPos(u8, u8);
2021-10-30 22:47:37 +02:00
static void PyramidBagPrint(u8, const u8 *, u8, u8, u8, u8, u8, u8);
static void PyramidBagPrint_Quantity(u8, const u8 *, u8, u8, u8, u8, u8, u8);
2021-04-23 00:49:54 +02:00
static u8 OpenMenuActionWindowById(u8);
static void CloseMenuActionWindowById(u8);
static void PrintMenuActionText_SingleRow(u8);
static void PrintMenuActionText_MultiRow(u8, u8, u8);
static bool8 IsValidMenuAction(s8);
static void CreatePyramidBagYesNo(u8, const struct YesNoFuncTable *);
static void DrawTossNumberWindow(u8);
static void UpdateSwapLinePos(u8);
static void SetSwapLineInvisibility(bool8);
static void SpriteCB_BagWaitForShake(struct Sprite *);
static void BagAction_UseOnField(u8);
static void BagAction_Toss(u8);
static void BagAction_Give(u8);
static void BagAction_Cancel(u8);
static void BagAction_UseInBattle(u8);
static void BagCursorMoved(s32, bool8, struct ListMenu *);
static void PrintItemQuantity(u8 windowId, u32 itemId, u8 y);
2021-04-23 00:49:54 +02:00
static void TossItem(u8);
static void DontTossItem(u8);
static const struct BgTemplate sBgTemplates[] =
2018-08-30 20:10:57 +02: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
},
};
2021-04-23 00:49:54 +02:00
static const struct ListMenuTemplate sListMenuTemplate =
2018-08-30 20:10:57 +02:00
{
.items = NULL,
2021-04-23 00:49:54 +02:00
.moveCursorFunc = BagCursorMoved,
2018-08-30 20:10:57 +02:00
.itemPrintFunc = PrintItemQuantity,
.totalItems = 0,
.maxShowed = 0,
2021-04-23 00:49:54 +02:00
.windowId = WIN_LIST,
2018-08-30 20:10:57 +02:00
.header_X = 0,
.item_X = 8,
.cursor_X = 0,
.upText_Y = 1,
.cursorPal = 2,
.fillValue = 0,
.cursorShadowPal = 3,
.lettersSpacing = 0,
.itemVerticalPadding = 0,
.scrollMultiple = LIST_NO_MULTIPLE_SCROLL,
2021-10-30 22:47:37 +02:00
.fontId = FONT_NARROW,
2018-08-30 20:10:57 +02:00
.cursorKind = 0
};
2021-04-23 00:49:54 +02:00
enum {
ACTION_USE_FIELD,
ACTION_TOSS,
ACTION_GIVE,
ACTION_CANCEL,
ACTION_USE_BATTLE,
ACTION_DUMMY,
};
2018-08-30 20:10:57 +02:00
static const struct MenuAction sMenuActions[] =
{
[ACTION_USE_FIELD] = { gMenuText_Use, BagAction_UseOnField },
[ACTION_TOSS] = { gMenuText_Toss, BagAction_Toss },
[ACTION_GIVE] = { gMenuText_Give, BagAction_Give },
[ACTION_CANCEL] = { gText_Cancel2, BagAction_Cancel },
[ACTION_USE_BATTLE] = { gMenuText_Use, BagAction_UseInBattle },
[ACTION_DUMMY] = { gText_EmptyString2, NULL },
};
2021-04-23 00:49:54 +02:00
static const u8 sMenuActionIds_Field[] = {ACTION_USE_FIELD, ACTION_GIVE, ACTION_TOSS, ACTION_CANCEL};
static const u8 sMenuActionIds_ChooseToss[] = {ACTION_TOSS, ACTION_CANCEL};
static const u8 sMenuActionIds_Battle[] = {ACTION_USE_BATTLE, ACTION_CANCEL};
static const u8 sMenuActionIds_BattleCannotUse[] = {ACTION_CANCEL};
2018-08-30 20:10:57 +02:00
static const struct YesNoFuncTable sYesNoTossFuncions =
{
TossItem, DontTossItem
};
2021-04-23 00:49:54 +02:00
enum {
COLORID_DARK_GRAY,
COLORID_LIGHT_GRAY,
COLORID_WHITE_BG,
COLORID_NONE = 0xFF
};
static const u8 sTextColors[][3] =
2018-08-30 20:10:57 +02:00
{
2021-04-23 00:49:54 +02:00
[COLORID_DARK_GRAY] = {TEXT_COLOR_TRANSPARENT, TEXT_COLOR_DARK_GRAY, TEXT_COLOR_LIGHT_GRAY},
[COLORID_LIGHT_GRAY] = {TEXT_COLOR_TRANSPARENT, TEXT_COLOR_LIGHT_GRAY, TEXT_COLOR_WHITE},
[COLORID_WHITE_BG] = {TEXT_COLOR_WHITE, TEXT_COLOR_DARK_GRAY, TEXT_COLOR_LIGHT_GRAY}, // Unused
2018-08-30 20:10:57 +02:00
};
2021-04-23 00:49:54 +02:00
static const struct WindowTemplate sWindowTemplates[] =
2018-08-30 20:10:57 +02:00
{
2021-04-23 00:49:54 +02:00
[WIN_LIST] = {
2018-10-27 00:53:07 +02:00
.bg = 0,
.tilemapLeft = 14,
.tilemapTop = 2,
.width = 15,
.height = 16,
.paletteNum = 15,
.baseBlock = 30
},
2021-04-23 00:49:54 +02:00
[WIN_INFO] = {
2018-10-27 00:53:07 +02:00
.bg = 0,
.tilemapLeft = 0,
.tilemapTop = 13,
.width = 14,
.height = 6,
.paletteNum = 15,
.baseBlock = 270
},
2021-04-23 00:49:54 +02:00
[WIN_MSG] = {
2018-10-27 00:53:07 +02:00
.bg = 1,
.tilemapLeft = 2,
.tilemapTop = 15,
.width = 27,
.height = 4,
.paletteNum = 15,
.baseBlock = 354
},
2021-04-23 00:49:54 +02:00
[WIN_TOSS_NUM] = {
2018-10-27 00:53:07 +02:00
.bg = 1,
.tilemapLeft = 24,
.tilemapTop = 17,
.width = 5,
.height = 2,
.paletteNum = 15,
.baseBlock = 462
},
2018-08-30 20:10:57 +02:00
DUMMY_WIN_TEMPLATE,
};
2021-04-23 00:49:54 +02:00
enum {
MENU_WIN_1x1,
MENU_WIN_1x2,
MENU_WIN_2x2,
MENU_WIN_2x3,
MENU_WIN_YESNO,
};
static const struct WindowTemplate sWindowTemplates_MenuActions[] =
2018-08-30 20:10:57 +02:00
{
2021-04-23 00:49:54 +02:00
[MENU_WIN_1x1] = {
2018-10-27 00:53:07 +02:00
.bg = 1,
.tilemapLeft = 22,
.tilemapTop = 17,
.width = 7,
.height = 2,
.paletteNum = 15,
.baseBlock = 472
},
2021-04-23 00:49:54 +02:00
[MENU_WIN_1x2] = {
2018-10-27 00:53:07 +02:00
.bg = 1,
.tilemapLeft = 22,
.tilemapTop = 15,
.width = 7,
.height = 4,
.paletteNum = 15,
.baseBlock = 472
},
2021-04-23 00:49:54 +02:00
[MENU_WIN_2x2] = {
2018-10-27 00:53:07 +02:00
.bg = 1,
.tilemapLeft = 15,
.tilemapTop = 15,
.width = 14,
.height = 4,
.paletteNum = 15,
.baseBlock = 472
},
2021-04-23 00:49:54 +02:00
[MENU_WIN_2x3] = { // Unused
2018-10-27 00:53:07 +02:00
.bg = 1,
.tilemapLeft = 15,
.tilemapTop = 13,
.width = 14,
.height = 6,
.paletteNum = 15,
.baseBlock = 472
},
2021-04-23 00:49:54 +02:00
[MENU_WIN_YESNO] = {
2018-10-27 00:53:07 +02:00
.bg = 1,
.tilemapLeft = 24,
.tilemapTop = 15,
.width = 5,
.height = 4,
.paletteNum = 15,
.baseBlock = 472
},
2018-08-30 20:10:57 +02:00
};
2021-04-23 00:49:54 +02:00
static const struct OamData sOamData_PyramidBag =
2018-09-06 02:24:11 +02:00
{
.y = 0,
.affineMode = ST_OAM_AFFINE_NORMAL,
.objMode = ST_OAM_OBJ_NORMAL,
2018-09-06 02:24:11 +02:00
.mosaic = 0,
.bpp = ST_OAM_4BPP,
.shape = SPRITE_SHAPE(64x64),
2018-09-06 02:24:11 +02:00
.x = 0,
.matrixNum = 0,
.size = SPRITE_SIZE(64x64),
2018-09-06 02:24:11 +02:00
.tileNum = 0,
.priority = 1,
.paletteNum = 0,
.affineParam = 0,
};
2021-04-23 00:49:54 +02:00
static const union AnimCmd sAnim_PyramidBag[] =
2018-09-06 02:24:11 +02:00
{
ANIMCMD_FRAME(0, 4),
ANIMCMD_END,
};
2021-04-23 00:49:54 +02:00
static const union AnimCmd * const sAnims_PyramidBag[] =
2018-09-06 02:24:11 +02:00
{
2021-04-23 00:49:54 +02:00
sAnim_PyramidBag,
2018-08-30 20:10:57 +02:00
};
2021-04-23 00:49:54 +02:00
static const union AffineAnimCmd sAffineAnim_PyramidBag_Still[] =
2018-09-06 02:24:11 +02:00
{
AFFINEANIMCMD_FRAME(256, 256, 0, 0),
AFFINEANIMCMD_END,
};
2021-04-23 00:49:54 +02:00
static const union AffineAnimCmd sAffineAnim_PyramidBag_Shake[] =
2018-09-06 02:24:11 +02:00
{
AFFINEANIMCMD_FRAME(0, 0, 254, 2),
AFFINEANIMCMD_FRAME(0, 0, 2, 4),
AFFINEANIMCMD_FRAME(0, 0, 254, 4),
AFFINEANIMCMD_FRAME(0, 0, 2, 2),
AFFINEANIMCMD_END,
};
2021-04-23 00:49:54 +02:00
enum {
ANIM_BAG_STILL,
ANIM_BAG_SHAKE,
};
static const union AffineAnimCmd * const sAffineAnims_PyramidBag[] =
2018-09-06 02:24:11 +02:00
{
2021-04-23 00:49:54 +02:00
[ANIM_BAG_STILL] = sAffineAnim_PyramidBag_Still,
[ANIM_BAG_SHAKE] = sAffineAnim_PyramidBag_Shake,
2018-09-06 02:24:11 +02:00
};
2021-10-26 22:52:23 +02:00
static const struct CompressedSpriteSheet sSpriteSheet_PyramidBag = {gBattlePyramidBag_Gfx, 0x0800, TAG_PYRAMID_BAG};
2018-09-06 02:24:11 +02:00
2021-04-23 00:49:54 +02:00
static const struct SpriteTemplate sSpriteTemplate_PyramidBag =
2018-09-06 02:24:11 +02:00
{
2021-04-23 00:49:54 +02:00
.tileTag = TAG_PYRAMID_BAG,
.paletteTag = TAG_PYRAMID_BAG,
.oam = &sOamData_PyramidBag,
.anims = sAnims_PyramidBag,
2018-09-06 02:24:11 +02:00
.images = NULL,
2021-04-23 00:49:54 +02:00
.affineAnims = sAffineAnims_PyramidBag,
2018-09-06 02:24:11 +02:00
.callback = SpriteCallbackDummy
};
2018-08-15 06:56:11 +02:00
2019-02-07 03:01:29 +01:00
void InitBattlePyramidBagCursorPosition(void)
2018-08-15 06:56:11 +02:00
{
2021-04-23 00:49:54 +02:00
gPyramidBagMenuState.cursorPosition = 0;
gPyramidBagMenuState.scrollPosition = 0;
2018-08-15 06:56:11 +02:00
}
2018-08-30 20:10:57 +02:00
void CB2_PyramidBagMenuFromStartMenu(void)
2018-08-15 06:56:11 +02:00
{
2021-04-23 00:49:54 +02:00
GoToBattlePyramidBagMenu(PYRAMIDBAG_LOC_FIELD, CB2_ReturnToFieldWithOpenMenu);
2018-08-15 06:56:11 +02:00
}
2021-04-23 00:49:54 +02:00
// Unused, CB2_BagMenuFromBattle is used instead
static void OpenBattlePyramidBagInBattle(void)
2018-08-15 06:56:11 +02:00
{
2021-04-23 00:49:54 +02:00
GoToBattlePyramidBagMenu(PYRAMIDBAG_LOC_BATTLE, CB2_SetUpReshowBattleScreenAfterMenu2);
2018-08-15 06:56:11 +02:00
}
2021-04-23 00:49:54 +02:00
// If the player finishes a round at the Battle Pyramid with insufficient space in their
// Pyramid Bag to store the party's held items, they may choose items to toss in order to
// make room.
2019-12-11 09:28:55 +01:00
void ChooseItemsToTossFromPyramidBag(void)
2018-08-15 06:56:11 +02:00
{
ScriptContext2_Enable();
2019-12-15 17:42:50 +01:00
FadeScreen(FADE_TO_BLACK, 0);
2019-12-11 09:28:55 +01:00
CreateTask(Task_ChooseItemsToTossFromPyramidBag, 10);
2018-08-15 06:56:11 +02:00
}
2019-12-11 09:28:55 +01:00
static void Task_ChooseItemsToTossFromPyramidBag(u8 taskId)
2018-08-15 06:56:11 +02:00
{
if (!gPaletteFade.active)
{
2018-12-27 23:30:47 +01:00
CleanupOverworldWindowsAndTilemaps();
2019-10-18 01:22:03 +02:00
gFieldCallback2 = CB2_FadeFromPartyMenu;
2021-04-23 00:49:54 +02:00
GoToBattlePyramidBagMenu(PYRAMIDBAG_LOC_CHOOSE_TOSS, CB2_ReturnToField);
2018-08-15 06:56:11 +02:00
DestroyTask(taskId);
}
}
2019-10-18 01:22:03 +02:00
void CB2_ReturnToPyramidBagMenu(void)
2018-08-15 06:56:11 +02:00
{
2021-08-03 08:17:01 +02:00
GoToBattlePyramidBagMenu(PYRAMIDBAG_LOC_PREV, gPyramidBagMenuState.exitCallback);
2018-08-15 06:56:11 +02:00
}
2021-08-03 08:17:01 +02:00
void GoToBattlePyramidBagMenu(u8 location, void (*exitCallback)(void))
2018-08-15 06:56:11 +02:00
{
2021-04-23 00:49:54 +02:00
gPyramidBagMenu = AllocZeroed(sizeof(*gPyramidBagMenu));
2018-08-15 06:56:11 +02:00
2021-04-23 00:49:54 +02:00
if (location != PYRAMIDBAG_LOC_PREV)
gPyramidBagMenuState.location = location;
2018-08-15 06:56:11 +02:00
2021-08-03 08:17:01 +02:00
if (exitCallback != NULL)
gPyramidBagMenuState.exitCallback = exitCallback;
2018-08-15 06:56:11 +02:00
2021-08-03 08:17:01 +02:00
gPyramidBagMenu->newScreenCallback = NULL;
2021-04-23 00:49:54 +02:00
gPyramidBagMenu->toSwapPos = POS_NONE;
gPyramidBagMenu->scrollIndicatorsTaskId = TASK_NONE;
2018-08-30 15:01:07 +02:00
2021-04-23 00:49:54 +02:00
memset(gPyramidBagMenu->spriteIds, SPRITE_NONE, sizeof(gPyramidBagMenu->spriteIds));
memset(gPyramidBagMenu->windowIds, WINDOW_NONE, sizeof(gPyramidBagMenu->windowIds));
2018-08-15 06:56:11 +02:00
2021-04-23 00:49:54 +02:00
SetMainCallback2(CB2_LoadPyramidBagMenu);
2018-08-15 06:56:11 +02:00
}
2021-04-23 00:49:54 +02:00
static void CB2_PyramidBag(void)
2018-08-15 06:56:11 +02:00
{
RunTasks();
AnimateSprites();
BuildOamBuffer();
DoScheduledBgTilemapCopiesToVram();
2018-08-15 06:56:11 +02:00
UpdatePaletteFade();
}
2021-04-23 00:49:54 +02:00
static void VBlankCB_PyramidBag(void)
2018-08-15 06:56:11 +02:00
{
LoadOam();
ProcessSpriteCopyRequests();
TransferPlttBuffer();
}
2021-04-23 00:49:54 +02:00
static void CB2_LoadPyramidBagMenu(void)
2018-08-15 06:56:11 +02:00
{
while (MenuHelpers_ShouldWaitForLinkRecv() != TRUE
&& LoadPyramidBagMenu() != TRUE
&& MenuHelpers_IsLinkActive() != TRUE);
2018-08-15 06:56:11 +02:00
}
2021-04-23 00:49:54 +02:00
static bool8 LoadPyramidBagMenu(void)
2018-08-15 06:56:11 +02:00
{
switch (gMain.state)
{
case 0:
SetVBlankHBlankCallbacksToNull();
ClearScheduledBgCopiesToVram();
2018-08-15 06:56:11 +02:00
gMain.state++;
break;
case 1:
ScanlineEffect_Stop();
gMain.state++;
break;
case 2:
FreeAllSpritePalettes();
gMain.state++;
break;
case 3:
ResetPaletteFade();
gPaletteFade.bufferTransferDisabled = TRUE;
gMain.state++;
break;
case 4:
ResetSpriteData();
gMain.state++;
break;
case 5:
if (!MenuHelpers_IsLinkActive())
2018-08-15 06:56:11 +02:00
ResetTasks();
gMain.state++;
break;
case 6:
2021-04-23 00:49:54 +02:00
InitPyramidBagBgs();
gPyramidBagMenu->state = 0;
2018-08-15 06:56:11 +02:00
gMain.state++;
break;
case 7:
2021-04-23 00:49:54 +02:00
if (LoadPyramidBagGfx())
2018-08-15 06:56:11 +02:00
gMain.state++;
break;
case 8:
2021-04-23 00:49:54 +02:00
InitPyramidBagWindows();
2018-08-15 06:56:11 +02:00
gMain.state++;
break;
case 9:
2021-04-23 00:49:54 +02:00
UpdatePyramidBagList();
UpdatePyramidBagCursorPos();
InitPyramidBagScroll();
2018-08-15 06:56:11 +02:00
gMain.state++;
break;
case 10:
2018-08-30 15:01:07 +02:00
SetBagItemsListTemplate();
2018-08-15 06:56:11 +02:00
gMain.state++;
break;
case 11:
2021-04-23 00:49:54 +02:00
CreatePyramidBagInputTask();
2018-08-15 06:56:11 +02:00
gMain.state++;
break;
case 12:
2021-04-23 00:49:54 +02:00
CreatePyramidBagSprite();
2018-08-15 06:56:11 +02:00
gMain.state++;
break;
case 13:
2021-04-23 00:49:54 +02:00
AddScrollArrows();
2018-08-15 06:56:11 +02:00
gMain.state++;
break;
case 14:
2021-04-11 22:23:10 +02:00
CreateSwapLine();
2018-08-15 06:56:11 +02:00
gMain.state++;
break;
case 15:
2021-04-23 00:49:54 +02:00
BlendPalettes(PALETTES_ALL, 16, 0);
2018-08-15 06:56:11 +02:00
gMain.state++;
break;
case 16:
2021-04-23 00:49:54 +02:00
BeginNormalPaletteFade(PALETTES_ALL, 0, 16, 0, RGB_BLACK);
2018-08-15 06:56:11 +02:00
gPaletteFade.bufferTransferDisabled = FALSE;
gMain.state++;
break;
default:
2021-04-23 00:49:54 +02:00
SetVBlankCallback(VBlankCB_PyramidBag);
SetMainCallback2(CB2_PyramidBag);
2018-08-15 06:56:11 +02:00
return TRUE;
}
return FALSE;
}
2021-04-23 00:49:54 +02:00
static void InitPyramidBagBgs(void)
2018-08-15 06:56:11 +02:00
{
ResetVramOamAndBgCntRegs();
ResetBgsAndClearDma3BusyFlags(0);
2021-04-23 00:49:54 +02:00
InitBgsFromTemplates(0, sBgTemplates, ARRAY_COUNT(sBgTemplates));
SetBgTilemapBuffer(2, gPyramidBagMenu->tilemapBuffer);
2018-08-15 06:56:11 +02:00
ResetAllBgsCoordinates();
2020-05-14 10:37:09 +02:00
ScheduleBgCopyTilemapToVram(2);
2018-08-15 06:56:11 +02:00
SetGpuReg(REG_OFFSET_DISPCNT, DISPCNT_MODE_0 |
2018-08-30 15:01:07 +02:00
DISPCNT_OBJ_1D_MAP |
2018-08-15 06:56:11 +02:00
DISPCNT_OBJ_ON);
ShowBg(0);
ShowBg(1);
ShowBg(2);
SetGpuReg(REG_OFFSET_BLDCNT, 0);
}
2018-08-30 15:01:07 +02:00
2021-04-23 00:49:54 +02:00
static bool8 LoadPyramidBagGfx(void)
2018-08-30 15:01:07 +02:00
{
2021-04-23 00:49:54 +02:00
switch (gPyramidBagMenu->state)
2018-08-30 15:01:07 +02:00
{
case 0:
2020-05-14 10:37:09 +02:00
ResetTempTileDataBuffers();
DecompressAndCopyTileDataToVram(2, gBagScreen_Gfx, 0, 0, 0);
2021-04-23 00:49:54 +02:00
gPyramidBagMenu->state++;
2018-08-30 15:01:07 +02:00
break;
case 1:
2020-05-14 10:37:09 +02:00
if (FreeTempTileDataBuffersIfPossible() != TRUE)
2018-08-30 15:01:07 +02:00
{
2021-10-26 22:52:23 +02:00
LZDecompressWram(gBattlePyramidBagTilemap, gPyramidBagMenu->tilemapBuffer);
2021-04-23 00:49:54 +02:00
gPyramidBagMenu->state++;
2018-08-30 15:01:07 +02:00
}
break;
case 2:
2021-10-26 22:52:23 +02:00
LoadCompressedPalette(gBattlePyramidBagInterface_Pal, 0, 32);
2021-04-23 00:49:54 +02:00
gPyramidBagMenu->state++;
2018-08-30 15:01:07 +02:00
break;
case 3:
2021-04-23 00:49:54 +02:00
LoadCompressedSpriteSheet(&sSpriteSheet_PyramidBag);
gPyramidBagMenu->state++;
2018-08-30 15:01:07 +02:00
break;
case 4:
2021-04-23 00:49:54 +02:00
LoadPyramidBagPalette();
gPyramidBagMenu->state++;
2018-08-30 15:01:07 +02:00
break;
default:
2021-04-11 22:23:10 +02:00
LoadListMenuSwapLineGfx();
2021-04-23 00:49:54 +02:00
gPyramidBagMenu->state = 0;
2018-08-30 15:01:07 +02:00
return TRUE;
}
return FALSE;
}
2018-08-30 20:10:57 +02:00
static void SetBagItemsListTemplate(void)
2018-08-30 15:01:07 +02:00
{
u16 i;
2021-04-23 00:49:54 +02:00
u16 *itemIds = gSaveBlock2Ptr->frontier.pyramidBag.itemId[gSaveBlock2Ptr->frontier.lvlMode];
2018-08-30 15:01:07 +02:00
2021-04-23 00:49:54 +02:00
for (i = 0; i < gPyramidBagMenu->listMenuCount - 1; i++)
2018-08-30 15:01:07 +02:00
{
2021-04-23 00:49:54 +02:00
CopyBagItemName(gPyramidBagMenu->itemStrings[i], itemIds[i]);
gPyramidBagMenu->bagListItems[i].name = gPyramidBagMenu->itemStrings[i];
gPyramidBagMenu->bagListItems[i].id = i;
2018-08-30 15:01:07 +02:00
}
2021-04-23 00:49:54 +02:00
StringCopy(gPyramidBagMenu->itemStrings[i], gText_CloseBag);
gPyramidBagMenu->bagListItems[i].name = gPyramidBagMenu->itemStrings[i];
gPyramidBagMenu->bagListItems[i].id = LIST_CANCEL;
gMultiuseListMenuTemplate = sListMenuTemplate;
gMultiuseListMenuTemplate.totalItems = gPyramidBagMenu->listMenuCount;
gMultiuseListMenuTemplate.items = gPyramidBagMenu->bagListItems;
gMultiuseListMenuTemplate.maxShowed = gPyramidBagMenu->listMenuMaxShown;
2018-08-30 15:01:07 +02:00
}
2021-04-23 00:49:54 +02:00
static void CopyBagItemName(u8 *dst, u16 itemId)
2018-08-30 15:01:07 +02:00
{
if (ItemId_GetPocket(itemId) == POCKET_BERRIES)
{
ConvertIntToDecimalStringN(gStringVar1, ITEM_TO_BERRY(itemId), STR_CONV_MODE_LEADING_ZEROS, 2);
CopyItemName(itemId, gStringVar2);
2021-08-03 08:17:01 +02:00
StringExpandPlaceholders(dst, gText_NumberItem_TMBerry);
2018-08-30 15:01:07 +02:00
}
else
{
CopyItemName(itemId, dst);
}
}
2021-04-23 00:49:54 +02:00
static void BagCursorMoved(s32 itemIndex, bool8 onInit, struct ListMenu *list)
2018-08-30 15:01:07 +02:00
{
if (onInit != TRUE)
{
PlaySE(SE_SELECT);
2021-04-23 00:49:54 +02:00
ShakePyramidBag();
2018-08-30 15:01:07 +02:00
}
2021-04-23 00:49:54 +02:00
if (gPyramidBagMenu->toSwapPos == POS_NONE)
2018-08-30 15:01:07 +02:00
{
2021-04-23 00:49:54 +02:00
FreeItemIconSpriteByAltId(gPyramidBagMenu->isAltIcon ^ 1);
if (itemIndex != LIST_CANCEL)
2021-04-23 00:49:54 +02:00
ShowItemIcon(gSaveBlock2Ptr->frontier.pyramidBag.itemId[gSaveBlock2Ptr->frontier.lvlMode][itemIndex], gPyramidBagMenu->isAltIcon);
2018-08-30 15:01:07 +02:00
else
2021-04-23 00:49:54 +02:00
ShowItemIcon(0xFFFF, gPyramidBagMenu->isAltIcon); // Show exit arrow if on Cancel
gPyramidBagMenu->isAltIcon ^= 1;
2018-08-30 15:01:07 +02:00
PrintItemDescription(itemIndex);
}
}
static void PrintItemQuantity(u8 windowId, u32 itemIndex, u8 y)
2018-08-30 15:01:07 +02:00
{
s32 xAlign;
if (itemIndex == LIST_CANCEL)
2018-08-30 15:01:07 +02:00
return;
2021-04-23 00:49:54 +02:00
if (gPyramidBagMenu->toSwapPos != POS_NONE)
2018-08-30 15:01:07 +02:00
{
2021-04-23 00:49:54 +02:00
// Performing a swap. Keep a gray selector arrow on the position to swap to
// and erase the selector arrow anywhere else
if (gPyramidBagMenu->toSwapPos == (u8)(itemIndex))
PrintSelectorArrowAtPos(y, COLORID_LIGHT_GRAY);
2018-08-30 15:01:07 +02:00
else
2021-04-23 00:49:54 +02:00
PrintSelectorArrowAtPos(y, COLORID_NONE);
2018-08-30 15:01:07 +02:00
}
2021-04-23 00:49:54 +02:00
2018-08-30 15:01:07 +02:00
ConvertIntToDecimalStringN(gStringVar1,
gSaveBlock2Ptr->frontier.pyramidBag.quantity[gSaveBlock2Ptr->frontier.lvlMode][itemIndex],
STR_CONV_MODE_RIGHT_ALIGN,
2);
StringExpandPlaceholders(gStringVar4, gText_xVar1);
2021-10-30 22:47:37 +02:00
xAlign = GetStringRightAlignXOffset(FONT_NARROW, gStringVar4, 119);
PyramidBagPrint_Quantity(windowId, gStringVar4, xAlign, y, 0, 0, TEXT_SKIP_DRAW, COLORID_DARK_GRAY);
2018-08-30 15:01:07 +02:00
}
2018-08-30 20:10:57 +02:00
static void PrintItemDescription(s32 listMenuId)
2018-08-30 15:01:07 +02:00
{
const u8 *desc;
if (listMenuId != LIST_CANCEL)
2018-08-30 15:01:07 +02:00
{
desc = ItemId_GetDescription(gSaveBlock2Ptr->frontier.pyramidBag.itemId[gSaveBlock2Ptr->frontier.lvlMode][listMenuId]);
}
else
{
2021-04-23 00:49:54 +02:00
StringCopy(gStringVar1, gPyramidBagMenu_ReturnToStrings[gPyramidBagMenuState.location]);
2018-08-30 15:01:07 +02:00
StringExpandPlaceholders(gStringVar4, gText_ReturnToVar1);
desc = gStringVar4;
}
2021-04-23 00:49:54 +02:00
FillWindowPixelBuffer(WIN_INFO, PIXEL_FILL(0));
2021-10-30 22:47:37 +02:00
PyramidBagPrint(WIN_INFO, desc, 3, 0, 0, 1, 0, COLORID_DARK_GRAY);
2018-08-30 15:01:07 +02:00
}
2021-04-23 00:49:54 +02:00
static void AddScrollArrows(void)
2018-08-30 15:01:07 +02:00
{
2021-04-23 00:49:54 +02:00
if (gPyramidBagMenu->scrollIndicatorsTaskId == TASK_NONE)
gPyramidBagMenu->scrollIndicatorsTaskId = AddScrollIndicatorArrowPairParameterized(SCROLL_ARROW_UP, 172, 12, 148,
gPyramidBagMenu->listMenuCount - gPyramidBagMenu->listMenuMaxShown,
TAG_SCROLL_ARROW, TAG_SCROLL_ARROW,
2021-04-23 00:49:54 +02:00
&gPyramidBagMenuState.scrollPosition);
2018-08-30 15:01:07 +02:00
}
2018-08-30 20:10:57 +02:00
static void RemoveScrollArrow(void)
2018-08-30 15:01:07 +02:00
{
2021-04-23 00:49:54 +02:00
if (gPyramidBagMenu->scrollIndicatorsTaskId != TASK_NONE)
2018-08-30 15:01:07 +02:00
{
2021-04-23 00:49:54 +02:00
RemoveScrollIndicatorArrowPair(gPyramidBagMenu->scrollIndicatorsTaskId);
gPyramidBagMenu->scrollIndicatorsTaskId = TASK_NONE;
2018-08-30 15:01:07 +02:00
}
}
2021-04-23 00:49:54 +02:00
#define tListTaskId data[0]
#define tListPos data[1]
#define tQuantity data[2]
#define tNumToToss data[8]
static void CreatePyramidBagInputTask(void)
2018-08-30 15:01:07 +02:00
{
u8 taskId = CreateTask(Task_HandlePyramidBagInput, 0);
s16 *data = gTasks[taskId].data;
2021-04-23 00:49:54 +02:00
tListTaskId = ListMenuInit(&gMultiuseListMenuTemplate, gPyramidBagMenuState.scrollPosition, gPyramidBagMenuState.cursorPosition);
2018-08-30 15:01:07 +02:00
}
2018-08-30 20:10:57 +02:00
static void SwapItems(u8 id1, u8 id2)
2018-08-30 15:01:07 +02:00
{
u16 temp;
u16 *itemIds = gSaveBlock2Ptr->frontier.pyramidBag.itemId[gSaveBlock2Ptr->frontier.lvlMode];
u8 *quantities = gSaveBlock2Ptr->frontier.pyramidBag.quantity[gSaveBlock2Ptr->frontier.lvlMode];
SWAP(itemIds[id1], itemIds[id2], temp);
SWAP(quantities[id1], quantities[id2], temp);
}
2018-08-30 20:10:57 +02:00
static void MovePyramidBagItemSlotInList(u8 from, u8 to)
2018-08-30 15:01:07 +02:00
{
u16 *itemIds = gSaveBlock2Ptr->frontier.pyramidBag.itemId[gSaveBlock2Ptr->frontier.lvlMode];
u8 *quantities = gSaveBlock2Ptr->frontier.pyramidBag.quantity[gSaveBlock2Ptr->frontier.lvlMode];
if (from != to)
{
s16 i;
u16 firstSlotItemId = itemIds[from];
u8 firstSlotQuantity = quantities[from];
if (to > from)
{
to--;
for (i = from; i < to; i++)
{
itemIds[i] = itemIds[i + 1];
quantities[i] = quantities[i + 1];
}
}
else
{
for (i = from; i > to; i--)
{
itemIds[i] = itemIds[i - 1];
quantities[i] = quantities[i - 1];
}
}
itemIds[to] = firstSlotItemId;
quantities[to] = firstSlotQuantity;
}
}
2018-08-30 20:10:57 +02:00
static void CompactItems(void)
2018-08-30 15:01:07 +02:00
{
u8 i, j;
u16 *itemIds = gSaveBlock2Ptr->frontier.pyramidBag.itemId[gSaveBlock2Ptr->frontier.lvlMode];
u8 *quantities = gSaveBlock2Ptr->frontier.pyramidBag.quantity[gSaveBlock2Ptr->frontier.lvlMode];
for (i = 0; i < PYRAMID_BAG_ITEMS_COUNT; i++)
{
2021-04-23 00:49:54 +02:00
if (itemIds[i] == ITEM_NONE || quantities[i] == 0)
2018-08-30 15:01:07 +02:00
{
2021-04-23 00:49:54 +02:00
itemIds[i] = ITEM_NONE;
2018-08-30 15:01:07 +02:00
quantities[i] = 0;
}
}
for (i = 0; i < PYRAMID_BAG_ITEMS_COUNT - 1; i++)
{
for (j = i + 1; j < PYRAMID_BAG_ITEMS_COUNT; j++)
{
2021-04-23 00:49:54 +02:00
if (itemIds[i] == ITEM_NONE || quantities[i] == 0)
2018-08-30 15:01:07 +02:00
SwapItems(i, j);
}
}
}
2021-04-23 00:49:54 +02:00
void UpdatePyramidBagList(void)
2018-08-30 15:01:07 +02:00
{
u16 i;
u16 *itemIds = gSaveBlock2Ptr->frontier.pyramidBag.itemId[gSaveBlock2Ptr->frontier.lvlMode];
CompactItems();
2021-04-23 00:49:54 +02:00
gPyramidBagMenu->listMenuCount = 0;
2018-08-30 15:01:07 +02:00
for (i = 0; i < PYRAMID_BAG_ITEMS_COUNT; i++)
{
2021-04-23 00:49:54 +02:00
if (itemIds[i] != ITEM_NONE)
gPyramidBagMenu->listMenuCount++;
2018-08-30 15:01:07 +02:00
}
2021-04-23 00:49:54 +02:00
gPyramidBagMenu->listMenuCount++;
if (gPyramidBagMenu->listMenuCount > 8)
gPyramidBagMenu->listMenuMaxShown = 8;
2018-08-30 15:01:07 +02:00
else
2021-04-23 00:49:54 +02:00
gPyramidBagMenu->listMenuMaxShown = gPyramidBagMenu->listMenuCount;
2018-08-30 15:01:07 +02:00
}
2021-04-23 00:49:54 +02:00
void UpdatePyramidBagCursorPos(void)
2018-08-30 15:01:07 +02:00
{
2021-04-23 00:49:54 +02:00
if (gPyramidBagMenuState.scrollPosition != 0 && gPyramidBagMenuState.scrollPosition + gPyramidBagMenu->listMenuMaxShown > gPyramidBagMenu->listMenuCount)
gPyramidBagMenuState.scrollPosition = gPyramidBagMenu->listMenuCount - gPyramidBagMenu->listMenuMaxShown;
if (gPyramidBagMenuState.scrollPosition + gPyramidBagMenuState.cursorPosition >= gPyramidBagMenu->listMenuCount)
2018-08-30 15:01:07 +02:00
{
2021-04-23 00:49:54 +02:00
if (gPyramidBagMenu->listMenuCount == 0)
gPyramidBagMenuState.cursorPosition = 0;
2018-08-30 15:01:07 +02:00
else
2021-04-23 00:49:54 +02:00
gPyramidBagMenuState.cursorPosition = gPyramidBagMenu->listMenuCount - 1;
2018-08-30 15:01:07 +02:00
}
}
2021-04-23 00:49:54 +02:00
static void InitPyramidBagScroll(void)
2018-08-30 15:01:07 +02:00
{
u8 i;
2021-04-23 00:49:54 +02:00
if (gPyramidBagMenuState.cursorPosition > 4)
2018-08-30 15:01:07 +02:00
{
2021-04-23 00:49:54 +02:00
for (i = 0; i <= gPyramidBagMenuState.cursorPosition - 4; i++)
2018-08-30 15:01:07 +02:00
{
2021-04-23 00:49:54 +02:00
if (gPyramidBagMenuState.scrollPosition + gPyramidBagMenu->listMenuMaxShown == gPyramidBagMenu->listMenuCount)
2018-08-30 15:01:07 +02:00
break;
2021-04-23 00:49:54 +02:00
gPyramidBagMenuState.cursorPosition--;
gPyramidBagMenuState.scrollPosition++;
2018-08-30 15:01:07 +02:00
}
}
}
2021-04-23 00:49:54 +02:00
static void PrintSelectorArrow(u8 listMenuTaskId, u8 colorId)
2018-08-30 15:01:07 +02:00
{
u8 y = ListMenuGetYCoordForPrintingArrowCursor(listMenuTaskId);
2021-04-23 00:49:54 +02:00
PrintSelectorArrowAtPos(y, colorId);
2018-08-30 15:01:07 +02:00
}
2021-04-23 00:49:54 +02:00
static void PrintSelectorArrowAtPos(u8 y, u8 colorId)
2018-08-30 15:01:07 +02:00
{
2021-04-23 00:49:54 +02:00
if (colorId == COLORID_NONE) // If 'no color', erase arrow
2021-10-30 22:47:37 +02:00
FillWindowPixelRect(WIN_LIST, PIXEL_FILL(0), 0, y, GetMenuCursorDimensionByFont(FONT_NORMAL, 0), GetMenuCursorDimensionByFont(FONT_NORMAL, 1));
2018-08-30 15:01:07 +02:00
else
2021-10-30 22:47:37 +02:00
PyramidBagPrint(WIN_LIST, gText_SelectorArrow2, 0, y, 0, 0, 0, colorId);
2018-08-30 15:01:07 +02:00
}
2021-04-23 00:49:54 +02:00
void CloseBattlePyramidBag(u8 taskId)
2018-08-30 15:01:07 +02:00
{
2021-04-23 00:49:54 +02:00
BeginNormalPaletteFade(PALETTES_ALL, 0, 0, 16, RGB_BLACK);
gTasks[taskId].func = Task_ClosePyramidBag;
2018-08-30 15:01:07 +02:00
}
2021-04-23 00:49:54 +02:00
static void Task_ClosePyramidBag(u8 taskId)
2018-08-30 15:01:07 +02:00
{
s16 *data = gTasks[taskId].data;
if (!gPaletteFade.active)
{
2021-04-23 00:49:54 +02:00
DestroyListMenuTask(tListTaskId, &gPyramidBagMenuState.scrollPosition, &gPyramidBagMenuState.cursorPosition);
2021-08-03 08:17:01 +02:00
// If ready for a new screen (e.g. party menu for giving an item) go to that screen
// Otherwise exit the bag and use callback set up when the bag was first opened
if (gPyramidBagMenu->newScreenCallback != NULL)
SetMainCallback2(gPyramidBagMenu->newScreenCallback);
2018-08-30 15:01:07 +02:00
else
2021-08-03 08:17:01 +02:00
SetMainCallback2(gPyramidBagMenuState.exitCallback);
2018-08-30 20:10:57 +02:00
RemoveScrollArrow();
2018-08-30 15:01:07 +02:00
ResetSpriteData();
FreeAllSpritePalettes();
FreeAllWindowBuffers();
2021-04-23 00:49:54 +02:00
Free(gPyramidBagMenu);
2018-08-30 15:01:07 +02:00
DestroyTask(taskId);
}
}
2018-08-30 20:10:57 +02:00
static void Task_HandlePyramidBagInput(u8 taskId)
2018-08-30 15:01:07 +02:00
{
s16 *data = gTasks[taskId].data;
if (MenuHelpers_ShouldWaitForLinkRecv() == TRUE || gPaletteFade.active)
2021-04-23 00:49:54 +02:00
return;
if (JOY_NEW(SELECT_BUTTON))
2018-08-30 15:01:07 +02:00
{
2021-04-23 00:49:54 +02:00
if (gPyramidBagMenuState.location != PYRAMIDBAG_LOC_PARTY)
2018-08-30 15:01:07 +02:00
{
2021-04-23 00:49:54 +02:00
ListMenuGetScrollAndRow(tListTaskId, &gPyramidBagMenuState.scrollPosition, &gPyramidBagMenuState.cursorPosition);
if (gPyramidBagMenuState.scrollPosition + gPyramidBagMenuState.cursorPosition != gPyramidBagMenu->listMenuCount - 1)
2018-08-30 15:01:07 +02:00
{
2021-04-23 00:49:54 +02:00
PlaySE(SE_SELECT);
Task_BeginItemSwap(taskId);
2018-08-30 15:01:07 +02:00
}
}
2021-04-23 00:49:54 +02:00
}
else
{
s32 listId = ListMenu_ProcessInput(tListTaskId);
ListMenuGetScrollAndRow(tListTaskId, &gPyramidBagMenuState.scrollPosition, &gPyramidBagMenuState.cursorPosition);
switch (listId)
2018-08-30 15:01:07 +02:00
{
2021-04-23 00:49:54 +02:00
case LIST_NOTHING_CHOSEN:
break;
case LIST_CANCEL:
PlaySE(SE_SELECT);
gSpecialVar_ItemId = ITEM_NONE;
CloseBattlePyramidBag(taskId);
break;
default:
PlaySE(SE_SELECT);
gSpecialVar_ItemId = gSaveBlock2Ptr->frontier.pyramidBag.itemId[gSaveBlock2Ptr->frontier.lvlMode][listId];
tListPos = listId;
tQuantity = gSaveBlock2Ptr->frontier.pyramidBag.quantity[gSaveBlock2Ptr->frontier.lvlMode][listId];
if (gPyramidBagMenuState.location == PYRAMIDBAG_LOC_PARTY)
TryCloseBagToGiveItem(taskId);
else
OpenContextMenu(taskId);
break;
2018-08-30 15:01:07 +02:00
}
}
}
2021-04-23 00:49:54 +02:00
static void OpenContextMenu(u8 taskId)
2018-08-30 15:01:07 +02:00
{
s16 *data = gTasks[taskId].data;
2018-08-30 20:10:57 +02:00
RemoveScrollArrow();
2021-04-23 00:49:54 +02:00
PrintSelectorArrow(tListTaskId, COLORID_LIGHT_GRAY);
switch (gPyramidBagMenuState.location)
2018-08-30 15:01:07 +02:00
{
default:
2021-04-23 00:49:54 +02:00
// case PYRAMIDBAG_LOC_FIELD:
// case PYRAMIDBAG_LOC_PARTY:
2021-04-23 00:49:54 +02:00
gPyramidBagMenu->menuActionIds = sMenuActionIds_Field;
gPyramidBagMenu->menuActionsCount = ARRAY_COUNT(sMenuActionIds_Field);
2018-08-30 15:01:07 +02:00
break;
2021-04-23 00:49:54 +02:00
case PYRAMIDBAG_LOC_BATTLE:
2018-08-30 15:01:07 +02:00
if (ItemId_GetBattleUsage(gSpecialVar_ItemId))
{
2021-04-23 00:49:54 +02:00
gPyramidBagMenu->menuActionIds = sMenuActionIds_Battle;
gPyramidBagMenu->menuActionsCount = ARRAY_COUNT(sMenuActionIds_Battle);
2018-08-30 15:01:07 +02:00
}
else
{
2021-04-23 00:49:54 +02:00
gPyramidBagMenu->menuActionIds = sMenuActionIds_BattleCannotUse;
gPyramidBagMenu->menuActionsCount = ARRAY_COUNT(sMenuActionIds_BattleCannotUse);
2018-08-30 15:01:07 +02:00
}
break;
2021-04-23 00:49:54 +02:00
case PYRAMIDBAG_LOC_CHOOSE_TOSS:
gPyramidBagMenu->menuActionIds = sMenuActionIds_ChooseToss;
gPyramidBagMenu->menuActionsCount = ARRAY_COUNT(sMenuActionIds_ChooseToss);
2018-08-30 15:01:07 +02:00
break;
}
CopyItemName(gSpecialVar_ItemId, gStringVar1);
StringExpandPlaceholders(gStringVar4, gText_Var1IsSelected);
2021-04-23 00:49:54 +02:00
FillWindowPixelBuffer(WIN_INFO, PIXEL_FILL(0));
2021-10-30 22:47:37 +02:00
PyramidBagPrint(WIN_INFO, gStringVar4, 3, 0, 0, 1, 0, COLORID_DARK_GRAY);
2021-04-23 00:49:54 +02:00
if (gPyramidBagMenu->menuActionsCount == 1)
PrintMenuActionText_SingleRow(OpenMenuActionWindowById(MENU_WIN_1x1));
else if (gPyramidBagMenu->menuActionsCount == 2)
PrintMenuActionText_SingleRow(OpenMenuActionWindowById(MENU_WIN_1x2));
2018-08-30 15:01:07 +02:00
else
2021-04-23 00:49:54 +02:00
PrintMenuActionText_MultiRow(OpenMenuActionWindowById(MENU_WIN_2x2), 2, 2);
2018-08-30 15:01:07 +02:00
2021-04-23 00:49:54 +02:00
if (gPyramidBagMenu->menuActionsCount == 2 * 2) // Assumes any non 2x2 menu is single-row
gTasks[taskId].func = HandleMenuActionInput_2x2;
2018-08-30 15:01:07 +02:00
else
2021-04-23 00:49:54 +02:00
gTasks[taskId].func = HandleMenuActionInput_SingleRow;
2018-08-30 15:01:07 +02:00
}
2021-04-23 00:49:54 +02:00
static void PrintMenuActionText_SingleRow(u8 windowId)
2018-08-30 15:01:07 +02:00
{
2021-11-04 04:20:59 +01:00
PrintMenuActionTexts(windowId, FONT_NARROW, 8, 1, 0, 0x10, gPyramidBagMenu->menuActionsCount, sMenuActions, gPyramidBagMenu->menuActionIds);
2021-11-03 21:06:58 +01:00
InitMenuInUpperLeftCornerNormal(windowId, gPyramidBagMenu->menuActionsCount, 0);
2018-08-30 15:01:07 +02:00
}
2021-04-23 00:49:54 +02:00
static void PrintMenuActionText_MultiRow(u8 windowId, u8 horizontalCount, u8 verticalCount)
2018-08-30 15:01:07 +02:00
{
2021-10-30 22:47:37 +02:00
PrintMenuActionGrid(windowId, FONT_NARROW, 8, 1, 56, horizontalCount, verticalCount, sMenuActions, gPyramidBagMenu->menuActionIds);
2021-04-23 00:49:54 +02:00
InitMenuActionGrid(windowId, 56, horizontalCount, verticalCount, 0);
2018-08-30 15:01:07 +02:00
}
2021-04-23 00:49:54 +02:00
static void HandleMenuActionInput_SingleRow(u8 taskId)
2018-08-30 15:01:07 +02:00
{
if (MenuHelpers_ShouldWaitForLinkRecv() != TRUE)
2018-08-30 15:01:07 +02:00
{
2018-11-05 21:45:54 +01:00
s32 id = Menu_ProcessInputNoWrap();
2018-08-30 15:01:07 +02:00
switch (id)
{
2019-02-02 11:04:38 +01:00
case MENU_NOTHING_CHOSEN:
2018-08-30 15:01:07 +02:00
break;
2019-02-02 11:04:38 +01:00
case MENU_B_PRESSED:
2018-08-30 15:01:07 +02:00
PlaySE(SE_SELECT);
2018-08-30 20:10:57 +02:00
sMenuActions[ACTION_CANCEL].func.void_u8(taskId);
2018-08-30 15:01:07 +02:00
break;
default:
PlaySE(SE_SELECT);
2021-04-23 00:49:54 +02:00
if (sMenuActions[gPyramidBagMenu->menuActionIds[id]].func.void_u8 != NULL)
sMenuActions[gPyramidBagMenu->menuActionIds[id]].func.void_u8(taskId);
2018-08-30 15:01:07 +02:00
break;
}
}
}
2021-04-23 00:49:54 +02:00
static void HandleMenuActionInput_2x2(u8 taskId)
2018-08-30 15:01:07 +02:00
{
if (MenuHelpers_ShouldWaitForLinkRecv() != TRUE)
2018-08-30 15:01:07 +02:00
{
2018-12-16 21:10:01 +01:00
s8 id = Menu_GetCursorPos();
2020-09-05 03:11:55 +02:00
if (JOY_NEW(DPAD_UP))
2018-08-30 15:01:07 +02:00
{
2018-08-30 21:28:03 +02:00
if (id > 0 && IsValidMenuAction(id - 2))
2018-08-30 15:01:07 +02:00
{
PlaySE(SE_SELECT);
2021-11-04 04:20:59 +01:00
ChangeMenuGridCursorPosition(MENU_CURSOR_DELTA_NONE, MENU_CURSOR_DELTA_UP);
2018-08-30 15:01:07 +02:00
}
}
2020-09-05 03:11:55 +02:00
else if (JOY_NEW(DPAD_DOWN))
2018-08-30 15:01:07 +02:00
{
2021-04-23 00:49:54 +02:00
if (id < gPyramidBagMenu->menuActionsCount - 2 && IsValidMenuAction(id + 2))
2018-08-30 15:01:07 +02:00
{
PlaySE(SE_SELECT);
2021-11-04 04:20:59 +01:00
ChangeMenuGridCursorPosition(MENU_CURSOR_DELTA_NONE, MENU_CURSOR_DELTA_DOWN);
2018-08-30 15:01:07 +02:00
}
}
2020-09-05 03:11:55 +02:00
else if (JOY_NEW(DPAD_LEFT) || GetLRKeysPressed() == MENU_L_PRESSED)
2018-08-30 15:01:07 +02:00
{
2018-08-30 21:28:03 +02:00
if (id & 1 && IsValidMenuAction(id - 1))
2018-08-30 15:01:07 +02:00
{
PlaySE(SE_SELECT);
2021-11-04 04:20:59 +01:00
ChangeMenuGridCursorPosition(MENU_CURSOR_DELTA_LEFT, MENU_CURSOR_DELTA_NONE);
2018-08-30 15:01:07 +02:00
}
}
2020-09-05 03:11:55 +02:00
else if (JOY_NEW(DPAD_RIGHT) || GetLRKeysPressed() == MENU_R_PRESSED)
2018-08-30 15:01:07 +02:00
{
2018-08-30 21:28:03 +02:00
if (!(id & 1) && IsValidMenuAction(id + 1))
2018-08-30 15:01:07 +02:00
{
PlaySE(SE_SELECT);
2021-11-04 04:20:59 +01:00
ChangeMenuGridCursorPosition(MENU_CURSOR_DELTA_RIGHT, MENU_CURSOR_DELTA_NONE);
2018-08-30 15:01:07 +02:00
}
}
2020-09-05 03:11:55 +02:00
else if (JOY_NEW(A_BUTTON))
2018-08-30 15:01:07 +02:00
{
PlaySE(SE_SELECT);
2021-04-23 00:49:54 +02:00
if (sMenuActions[gPyramidBagMenu->menuActionIds[id]].func.void_u8 != NULL)
sMenuActions[gPyramidBagMenu->menuActionIds[id]].func.void_u8(taskId);
2018-08-30 15:01:07 +02:00
}
2020-09-05 03:11:55 +02:00
else if (JOY_NEW(B_BUTTON))
2018-08-30 15:01:07 +02:00
{
PlaySE(SE_SELECT);
2018-08-30 20:10:57 +02:00
sMenuActions[ACTION_CANCEL].func.void_u8(taskId);
2018-08-30 15:01:07 +02:00
}
}
}
2018-08-30 21:28:03 +02:00
static bool8 IsValidMenuAction(s8 actionTableId)
2018-08-30 15:01:07 +02:00
{
2018-08-30 20:10:57 +02:00
if (actionTableId < 0)
2018-08-30 15:01:07 +02:00
return FALSE;
2021-04-23 00:49:54 +02:00
else if (actionTableId > gPyramidBagMenu->menuActionsCount)
2018-08-30 15:01:07 +02:00
return FALSE;
2021-04-23 00:49:54 +02:00
else if (gPyramidBagMenu->menuActionIds[actionTableId] == ACTION_DUMMY)
2018-08-30 15:01:07 +02:00
return FALSE;
else
return TRUE;
}
2021-04-23 00:49:54 +02:00
static void CloseMenuActionWindow(void)
2018-08-30 15:01:07 +02:00
{
2021-04-23 00:49:54 +02:00
if (gPyramidBagMenu->menuActionsCount == 1)
CloseMenuActionWindowById(MENU_WIN_1x1);
else if (gPyramidBagMenu->menuActionsCount == 2)
CloseMenuActionWindowById(MENU_WIN_1x2);
2018-08-30 15:01:07 +02:00
else
2021-04-23 00:49:54 +02:00
CloseMenuActionWindowById(MENU_WIN_2x2);
2018-08-30 15:01:07 +02:00
}
2018-08-30 20:10:57 +02:00
static void BagAction_UseOnField(u8 taskId)
2018-08-30 15:01:07 +02:00
{
u8 pocketId = ItemId_GetPocket(gSpecialVar_ItemId);
if (pocketId == POCKET_KEY_ITEMS
|| pocketId == POCKET_POKE_BALLS
|| pocketId == POCKET_TM_HM
|| ItemIsMail(gSpecialVar_ItemId) == TRUE)
{
2021-04-23 00:49:54 +02:00
CloseMenuActionWindow();
2019-12-22 01:01:38 +01:00
DisplayItemMessageInBattlePyramid(taskId, gText_DadsAdvice, Task_CloseBattlePyramidBagMessage);
2018-08-30 15:01:07 +02:00
}
else if (ItemId_GetFieldFunc(gSpecialVar_ItemId) != NULL)
{
2021-04-23 00:49:54 +02:00
CloseMenuActionWindow();
FillWindowPixelBuffer(WIN_INFO, PIXEL_FILL(0));
2020-05-14 10:37:09 +02:00
ScheduleBgCopyTilemapToVram(0);
2018-08-30 15:01:07 +02:00
ItemId_GetFieldFunc(gSpecialVar_ItemId)(taskId);
}
}
2018-08-30 20:10:57 +02:00
static void BagAction_Cancel(u8 taskId)
2018-08-30 15:01:07 +02:00
{
s16 *data = gTasks[taskId].data;
2021-04-23 00:49:54 +02:00
CloseMenuActionWindow();
PrintItemDescription(tListPos);
2020-05-14 10:37:09 +02:00
ScheduleBgCopyTilemapToVram(0);
ScheduleBgCopyTilemapToVram(1);
2021-04-23 00:49:54 +02:00
PrintSelectorArrow(tListTaskId, COLORID_DARK_GRAY);
2018-08-30 20:10:57 +02:00
SetTaskToMainPyramidBagInputHandler(taskId);
2018-08-30 15:01:07 +02:00
}
2018-08-30 20:10:57 +02:00
static void SetTaskToMainPyramidBagInputHandler(u8 taskId)
2018-08-30 15:01:07 +02:00
{
2021-04-23 00:49:54 +02:00
AddScrollArrows();
2018-08-30 15:01:07 +02:00
gTasks[taskId].func = Task_HandlePyramidBagInput;
}
2018-08-30 20:10:57 +02:00
static void BagAction_Toss(u8 taskId)
2018-08-30 15:01:07 +02:00
{
s16 *data = gTasks[taskId].data;
2021-04-23 00:49:54 +02:00
CloseMenuActionWindow();
tNumToToss = 1;
if (tQuantity == 1)
2018-08-30 15:01:07 +02:00
{
2021-04-23 00:49:54 +02:00
AskConfirmToss(taskId);
2018-08-30 15:01:07 +02:00
}
else
{
CopyItemName(gSpecialVar_ItemId, gStringVar1);
StringExpandPlaceholders(gStringVar4, gText_TossHowManyVar1s);
2021-04-23 00:49:54 +02:00
FillWindowPixelBuffer(WIN_INFO, PIXEL_FILL(0));
2021-10-30 22:47:37 +02:00
PyramidBagPrint(WIN_INFO, gStringVar4, 3, 0, 0, 1, 0, COLORID_DARK_GRAY);
2021-04-23 00:49:54 +02:00
ShowNumToToss();
gTasks[taskId].func = Task_ChooseHowManyToToss;
2018-08-30 15:01:07 +02:00
}
}
2021-04-23 00:49:54 +02:00
static void AskConfirmToss(u8 taskId)
2018-08-30 15:01:07 +02:00
{
s16 *data = gTasks[taskId].data;
CopyItemName(gSpecialVar_ItemId, gStringVar1);
2021-04-23 00:49:54 +02:00
ConvertIntToDecimalStringN(gStringVar2, tNumToToss, STR_CONV_MODE_LEFT_ALIGN, 2);
2018-08-30 15:01:07 +02:00
StringExpandPlaceholders(gStringVar4, gText_ConfirmTossItems);
2021-04-23 00:49:54 +02:00
FillWindowPixelBuffer(WIN_INFO, PIXEL_FILL(0));
2021-10-30 22:47:37 +02:00
PyramidBagPrint(WIN_INFO, gStringVar4, 3, 0, 0, 1, 0, COLORID_DARK_GRAY);
2021-04-23 00:49:54 +02:00
CreatePyramidBagYesNo(taskId, &sYesNoTossFuncions);
2018-08-30 15:01:07 +02:00
}
2018-08-30 20:10:57 +02:00
static void DontTossItem(u8 taskId)
2018-08-30 15:01:07 +02:00
{
s16 *data = gTasks[taskId].data;
2021-04-23 00:49:54 +02:00
PrintItemDescription(tListPos);
PrintSelectorArrow(tListTaskId, COLORID_DARK_GRAY);
2018-08-30 20:10:57 +02:00
SetTaskToMainPyramidBagInputHandler(taskId);
2018-08-30 15:01:07 +02:00
}
2021-04-23 00:49:54 +02:00
static void ShowNumToToss(void)
2018-08-30 15:01:07 +02:00
{
s32 x;
ConvertIntToDecimalStringN(gStringVar1, 1, STR_CONV_MODE_LEADING_ZEROS, 2);
StringExpandPlaceholders(gStringVar4, gText_xVar1);
2021-04-23 00:49:54 +02:00
DrawTossNumberWindow(WIN_TOSS_NUM);
2021-10-30 22:47:37 +02:00
x = GetStringCenterAlignXOffset(FONT_NORMAL, gStringVar4, 0x28);
AddTextPrinterParameterized(WIN_TOSS_NUM, FONT_NORMAL, gStringVar4, x, 2, 0, NULL);
2018-08-30 15:01:07 +02:00
}
2021-04-23 00:49:54 +02:00
static void UpdateNumToToss(s16 num)
2018-08-30 15:01:07 +02:00
{
s32 x;
2021-04-23 00:49:54 +02:00
ConvertIntToDecimalStringN(gStringVar1, num, STR_CONV_MODE_LEADING_ZEROS, 2);
2018-08-30 15:01:07 +02:00
StringExpandPlaceholders(gStringVar4, gText_xVar1);
2021-10-30 22:47:37 +02:00
x = GetStringCenterAlignXOffset(FONT_NORMAL, gStringVar4, 0x28);
AddTextPrinterParameterized(WIN_TOSS_NUM, FONT_NORMAL, gStringVar4, x, 2, 0, NULL);
2018-08-30 15:01:07 +02:00
}
2021-04-23 00:49:54 +02:00
static void Task_ChooseHowManyToToss(u8 taskId)
2018-08-30 15:01:07 +02:00
{
s16 *data = gTasks[taskId].data;
2021-04-23 00:49:54 +02:00
if (AdjustQuantityAccordingToDPadInput(&tNumToToss, tQuantity) == TRUE)
2018-08-30 15:01:07 +02:00
{
2021-04-23 00:49:54 +02:00
UpdateNumToToss(tNumToToss);
2018-08-30 15:01:07 +02:00
}
2020-09-05 03:11:55 +02:00
else if (JOY_NEW(A_BUTTON))
2018-08-30 15:01:07 +02:00
{
2021-04-23 00:49:54 +02:00
// Toss
2018-08-30 15:01:07 +02:00
PlaySE(SE_SELECT);
2022-07-25 20:59:14 +02:00
ClearStdWindowAndFrameToTransparent(WIN_TOSS_NUM, FALSE);
2021-04-23 00:49:54 +02:00
ClearWindowTilemap(WIN_TOSS_NUM);
2020-05-14 10:37:09 +02:00
ScheduleBgCopyTilemapToVram(1);
2021-04-23 00:49:54 +02:00
AskConfirmToss(taskId);
2018-08-30 15:01:07 +02:00
}
2020-09-05 03:11:55 +02:00
else if (JOY_NEW(B_BUTTON))
2018-08-30 15:01:07 +02:00
{
2021-04-23 00:49:54 +02:00
// Cancel tossing
2018-08-30 15:01:07 +02:00
PlaySE(SE_SELECT);
2022-07-25 20:59:14 +02:00
ClearStdWindowAndFrameToTransparent(WIN_TOSS_NUM, FALSE);
2021-04-23 00:49:54 +02:00
ClearWindowTilemap(WIN_TOSS_NUM);
2020-05-14 10:37:09 +02:00
ScheduleBgCopyTilemapToVram(1);
2018-08-30 20:10:57 +02:00
DontTossItem(taskId);
2018-08-30 15:01:07 +02:00
}
}
2018-08-30 20:10:57 +02:00
static void TossItem(u8 taskId)
2018-08-30 15:01:07 +02:00
{
s16 *data = gTasks[taskId].data;
CopyItemName(gSpecialVar_ItemId, gStringVar1);
2021-04-23 00:49:54 +02:00
ConvertIntToDecimalStringN(gStringVar2, tNumToToss, STR_CONV_MODE_LEFT_ALIGN, 2);
2018-08-30 15:01:07 +02:00
StringExpandPlaceholders(gStringVar4, gText_ThrewAwayVar2Var1s);
2021-04-23 00:49:54 +02:00
FillWindowPixelBuffer(WIN_INFO, PIXEL_FILL(0));
2021-10-30 22:47:37 +02:00
PyramidBagPrint(WIN_INFO, gStringVar4, 3, 0, 0, 1, 0, COLORID_DARK_GRAY);
2021-04-23 00:49:54 +02:00
gTasks[taskId].func = Task_TossItem;
2018-08-30 15:01:07 +02:00
}
2021-04-23 00:49:54 +02:00
static void Task_TossItem(u8 taskId)
2018-08-30 15:01:07 +02:00
{
s16 *data = gTasks[taskId].data;
2021-04-23 00:49:54 +02:00
u16 *scrollOffset = &gPyramidBagMenuState.scrollPosition;
u16 *selectedRow = &gPyramidBagMenuState.cursorPosition;
2018-08-30 15:01:07 +02:00
2020-09-05 03:11:55 +02:00
if (JOY_NEW(A_BUTTON | B_BUTTON))
2018-08-30 15:01:07 +02:00
{
PlaySE(SE_SELECT);
2021-04-23 00:49:54 +02:00
RemovePyramidBagItem(gSpecialVar_ItemId, tNumToToss);
DestroyListMenuTask(tListTaskId, scrollOffset, selectedRow);
UpdatePyramidBagList();
UpdatePyramidBagCursorPos();
2018-08-30 15:01:07 +02:00
SetBagItemsListTemplate();
2021-04-23 00:49:54 +02:00
tListTaskId = ListMenuInit(&gMultiuseListMenuTemplate, *scrollOffset, *selectedRow);
2020-05-14 10:37:09 +02:00
ScheduleBgCopyTilemapToVram(0);
2018-08-30 20:10:57 +02:00
SetTaskToMainPyramidBagInputHandler(taskId);
2018-08-30 15:01:07 +02:00
}
}
2018-08-30 20:10:57 +02:00
static void BagAction_Give(u8 taskId)
2018-08-30 15:01:07 +02:00
{
2021-04-23 00:49:54 +02:00
CloseMenuActionWindow();
2018-08-30 15:01:07 +02:00
if (ItemIsMail(gSpecialVar_ItemId) == TRUE)
{
2021-04-23 00:49:54 +02:00
DisplayItemMessageInBattlePyramid(taskId, gText_CantWriteMail, Task_WaitCloseErrorMessage);
2018-08-30 15:01:07 +02:00
}
else if (!ItemId_GetImportance(gSpecialVar_ItemId))
{
2021-08-03 08:17:01 +02:00
gPyramidBagMenu->newScreenCallback = CB2_ChooseMonToGiveItem;
2021-04-23 00:49:54 +02:00
CloseBattlePyramidBag(taskId);
2018-08-30 15:01:07 +02:00
}
else
{
2021-04-23 00:49:54 +02:00
ShowCantHoldMessage(taskId);
2018-08-30 15:01:07 +02:00
}
}
2021-04-23 00:49:54 +02:00
static void ShowCantHoldMessage(u8 taskId)
2018-08-30 15:01:07 +02:00
{
CopyItemName(gSpecialVar_ItemId, gStringVar1);
StringExpandPlaceholders(gStringVar4, gText_Var1CantBeHeld);
2021-04-23 00:49:54 +02:00
DisplayItemMessageInBattlePyramid(taskId, gStringVar4, Task_WaitCloseErrorMessage);
2018-08-30 15:01:07 +02:00
}
2021-04-23 00:49:54 +02:00
static void Task_WaitCloseErrorMessage(u8 taskId)
2018-08-30 15:01:07 +02:00
{
2020-09-05 03:11:55 +02:00
if (JOY_NEW(A_BUTTON))
2018-08-30 15:01:07 +02:00
{
PlaySE(SE_SELECT);
2019-12-22 01:01:38 +01:00
Task_CloseBattlePyramidBagMessage(taskId);
2018-08-30 15:01:07 +02:00
}
}
2019-12-22 01:01:38 +01:00
void Task_CloseBattlePyramidBagMessage(u8 taskId)
2018-08-30 15:01:07 +02:00
{
s16 *data = gTasks[taskId].data;
2019-12-22 01:01:38 +01:00
CloseBattlePyramidBagTextWindow();
2021-04-23 00:49:54 +02:00
PrintItemDescription(tListPos);
PrintSelectorArrow(tListTaskId, COLORID_DARK_GRAY);
2018-08-30 20:10:57 +02:00
SetTaskToMainPyramidBagInputHandler(taskId);
2018-08-30 15:01:07 +02:00
}
2021-04-23 00:49:54 +02:00
static void TryCloseBagToGiveItem(u8 taskId)
2018-08-30 15:01:07 +02:00
{
2021-04-23 00:49:54 +02:00
if (!IsWritingMailAllowed(gSpecialVar_ItemId))
DisplayItemMessageInBattlePyramid(taskId, gText_CantWriteMail, Task_WaitCloseErrorMessage);
2018-08-30 15:01:07 +02:00
else if (!ItemId_GetImportance(gSpecialVar_ItemId))
2021-04-23 00:49:54 +02:00
CloseBattlePyramidBag(taskId);
2018-08-30 15:01:07 +02:00
else
2021-04-23 00:49:54 +02:00
ShowCantHoldMessage(taskId);
2018-08-30 15:01:07 +02:00
}
2018-08-30 20:10:57 +02:00
static void BagAction_UseInBattle(u8 taskId)
2018-08-30 15:01:07 +02:00
{
if (ItemId_GetBattleFunc(gSpecialVar_ItemId) != NULL)
{
2021-04-23 00:49:54 +02:00
CloseMenuActionWindow();
2018-08-30 15:01:07 +02:00
ItemId_GetBattleFunc(gSpecialVar_ItemId)(taskId);
}
}
2018-08-30 20:10:57 +02:00
static void Task_BeginItemSwap(u8 taskId)
2018-08-30 15:01:07 +02:00
{
s16 *data = gTasks[taskId].data;
2021-04-23 00:49:54 +02:00
tListPos = gPyramidBagMenuState.scrollPosition + gPyramidBagMenuState.cursorPosition;
gPyramidBagMenu->toSwapPos = tListPos;
ListMenuSetUnkIndicatorsStructField(tListTaskId, 0x10, 1);
CopyItemName(gSaveBlock2Ptr->frontier.pyramidBag.itemId[gSaveBlock2Ptr->frontier.lvlMode][tListPos], gStringVar1);
2018-08-30 15:01:07 +02:00
StringExpandPlaceholders(gStringVar4, gText_MoveVar1Where);
2021-04-23 00:49:54 +02:00
FillWindowPixelBuffer(WIN_INFO, PIXEL_FILL(0));
2021-10-30 22:47:37 +02:00
PyramidBagPrint(WIN_INFO, gStringVar4, 3, 0, 0, 1, 0, COLORID_DARK_GRAY);
2021-04-23 00:49:54 +02:00
PrintSelectorArrow(tListTaskId, COLORID_LIGHT_GRAY);
UpdateSwapLinePos(tListPos);
2018-08-30 20:10:57 +02:00
gTasks[taskId].func = Task_ItemSwapHandleInput;
2018-08-30 15:01:07 +02:00
}
2018-08-30 20:10:57 +02:00
static void Task_ItemSwapHandleInput(u8 taskId)
2018-08-30 15:01:07 +02:00
{
s16 *data = gTasks[taskId].data;
if (MenuHelpers_ShouldWaitForLinkRecv() != TRUE)
2018-08-30 15:01:07 +02:00
{
2020-09-05 03:11:55 +02:00
if (JOY_NEW(SELECT_BUTTON))
2018-08-30 15:01:07 +02:00
{
PlaySE(SE_SELECT);
2021-04-23 00:49:54 +02:00
ListMenuGetScrollAndRow(tListTaskId, &gPyramidBagMenuState.scrollPosition, &gPyramidBagMenuState.cursorPosition);
2018-08-30 20:10:57 +02:00
PerformItemSwap(taskId);
2018-08-30 15:01:07 +02:00
}
else
{
2021-04-23 00:49:54 +02:00
s32 id = ListMenu_ProcessInput(tListTaskId);
ListMenuGetScrollAndRow(tListTaskId, &gPyramidBagMenuState.scrollPosition, &gPyramidBagMenuState.cursorPosition);
2021-04-11 22:23:10 +02:00
SetSwapLineInvisibility(FALSE);
2021-04-23 00:49:54 +02:00
UpdateSwapLinePos(gPyramidBagMenuState.cursorPosition);
2018-08-30 15:01:07 +02:00
switch (id)
{
case LIST_NOTHING_CHOSEN:
break;
case LIST_CANCEL:
2018-08-30 15:01:07 +02:00
PlaySE(SE_SELECT);
2020-09-05 03:11:55 +02:00
if (JOY_NEW(A_BUTTON))
2018-08-30 20:10:57 +02:00
PerformItemSwap(taskId);
2018-08-30 15:01:07 +02:00
else
2021-04-23 00:49:54 +02:00
CancelItemSwap(taskId);
2018-08-30 15:01:07 +02:00
break;
default:
PlaySE(SE_SELECT);
2018-08-30 20:10:57 +02:00
PerformItemSwap(taskId);
2018-08-30 15:01:07 +02:00
break;
}
}
}
}
2018-08-30 20:10:57 +02:00
static void PerformItemSwap(u8 taskId)
2018-08-30 15:01:07 +02:00
{
s16 *data = gTasks[taskId].data;
2021-04-23 00:49:54 +02:00
u16 *scrollOffset = &gPyramidBagMenuState.scrollPosition;
u16 *selectedRow = &gPyramidBagMenuState.cursorPosition;
u16 swapPos = *scrollOffset + *selectedRow;
2018-08-30 15:01:07 +02:00
2021-04-23 00:49:54 +02:00
if (tListPos == swapPos || tListPos == swapPos - 1)
2018-08-30 15:01:07 +02:00
{
2021-04-23 00:49:54 +02:00
CancelItemSwap(taskId);
2018-08-30 15:01:07 +02:00
}
else
{
2021-04-23 00:49:54 +02:00
MovePyramidBagItemSlotInList(tListPos, swapPos);
gPyramidBagMenu->toSwapPos = POS_NONE;
2021-04-11 22:23:10 +02:00
SetSwapLineInvisibility(TRUE);
2021-04-23 00:49:54 +02:00
DestroyListMenuTask(tListTaskId, scrollOffset, selectedRow);
if (tListPos < swapPos)
gPyramidBagMenuState.cursorPosition--;
2018-08-30 15:01:07 +02:00
SetBagItemsListTemplate();
2021-04-23 00:49:54 +02:00
tListTaskId = ListMenuInit(&gMultiuseListMenuTemplate, *scrollOffset, *selectedRow);
2018-08-30 20:10:57 +02:00
SetTaskToMainPyramidBagInputHandler(taskId);
2018-08-30 15:01:07 +02:00
}
}
2021-04-23 00:49:54 +02:00
static void CancelItemSwap(u8 taskId)
2018-08-30 15:01:07 +02:00
{
s16 *data = gTasks[taskId].data;
2021-04-23 00:49:54 +02:00
u16 *scrollOffset = &gPyramidBagMenuState.scrollPosition;
u16 *selectedRow = &gPyramidBagMenuState.cursorPosition;
2018-08-30 15:01:07 +02:00
2021-04-23 00:49:54 +02:00
gPyramidBagMenu->toSwapPos = POS_NONE;
2021-04-11 22:23:10 +02:00
SetSwapLineInvisibility(TRUE);
2021-04-23 00:49:54 +02:00
DestroyListMenuTask(tListTaskId, scrollOffset, selectedRow);
if (tListPos < *scrollOffset + *selectedRow)
gPyramidBagMenuState.cursorPosition--;
2018-08-30 15:01:07 +02:00
SetBagItemsListTemplate();
2021-04-23 00:49:54 +02:00
tListTaskId = ListMenuInit(&gMultiuseListMenuTemplate, *scrollOffset, *selectedRow);
2018-08-30 20:10:57 +02:00
SetTaskToMainPyramidBagInputHandler(taskId);
2018-08-30 15:01:07 +02:00
}
2019-10-18 01:22:03 +02:00
void TryStoreHeldItemsInPyramidBag(void)
2018-08-30 15:01:07 +02:00
{
u8 i;
struct Pokemon *party = gPlayerParty;
u16 *newItems = Alloc(PYRAMID_BAG_ITEMS_COUNT * sizeof(u16));
u8 *newQuantities = Alloc(PYRAMID_BAG_ITEMS_COUNT * sizeof(u8));
u16 heldItem;
memcpy(newItems, gSaveBlock2Ptr->frontier.pyramidBag.itemId[gSaveBlock2Ptr->frontier.lvlMode], PYRAMID_BAG_ITEMS_COUNT * sizeof(u16));
memcpy(newQuantities, gSaveBlock2Ptr->frontier.pyramidBag.quantity[gSaveBlock2Ptr->frontier.lvlMode], PYRAMID_BAG_ITEMS_COUNT * sizeof(u8));
for (i = 0; i < FRONTIER_PARTY_SIZE; i++)
2018-08-30 15:01:07 +02:00
{
heldItem = GetMonData(&party[i], MON_DATA_HELD_ITEM);
2019-10-18 01:22:03 +02:00
if (heldItem != ITEM_NONE && !AddBagItem(heldItem, 1))
2018-08-30 15:01:07 +02:00
{
2019-10-18 01:22:03 +02:00
// Cant store party held items in pyramid bag because bag is full
2018-08-30 15:01:07 +02:00
memcpy(gSaveBlock2Ptr->frontier.pyramidBag.itemId[gSaveBlock2Ptr->frontier.lvlMode], newItems, PYRAMID_BAG_ITEMS_COUNT * sizeof(u16));
memcpy(gSaveBlock2Ptr->frontier.pyramidBag.quantity[gSaveBlock2Ptr->frontier.lvlMode], newQuantities, PYRAMID_BAG_ITEMS_COUNT * sizeof(u8));
Free(newItems);
Free(newQuantities);
gSpecialVar_Result = 1;
return;
}
}
2019-10-18 01:22:03 +02:00
heldItem = ITEM_NONE;
for (i = 0; i < FRONTIER_PARTY_SIZE; i++)
2018-08-30 15:01:07 +02:00
SetMonData(&party[i], MON_DATA_HELD_ITEM, &heldItem);
gSpecialVar_Result = 0;
Free(newItems);
Free(newQuantities);
}
2021-04-23 00:49:54 +02:00
static void InitPyramidBagWindows(void)
2018-08-30 15:01:07 +02:00
{
u8 i;
2021-04-23 00:49:54 +02:00
InitWindows(sWindowTemplates);
2018-08-30 15:01:07 +02:00
DeactivateAllTextPrinters();
LoadUserWindowBorderGfx(0, 0x1, 0xE0);
LoadMessageBoxGfx(0, 0xA, 0xD0);
2021-10-26 22:52:23 +02:00
LoadPalette(gStandardMenuPalette, 0xF0, 0x20);
2018-08-30 15:01:07 +02:00
2021-04-23 00:49:54 +02:00
for (i = 0; i < ARRAY_COUNT(sWindowTemplates); i++)
FillWindowPixelBuffer(i, PIXEL_FILL(0));
2018-08-30 15:01:07 +02:00
2021-04-23 00:49:54 +02:00
PutWindowTilemap(WIN_LIST);
PutWindowTilemap(WIN_INFO);
2020-05-14 10:37:09 +02:00
ScheduleBgCopyTilemapToVram(0);
ScheduleBgCopyTilemapToVram(1);
2018-08-30 15:01:07 +02:00
}
2021-10-30 22:47:37 +02:00
static void PyramidBagPrint(u8 windowId, const u8 *src, u8 x, u8 y, u8 letterSpacing, u8 lineSpacing, u8 speed, u8 colorTableId)
2018-08-30 15:01:07 +02:00
{
2021-10-30 22:47:37 +02:00
AddTextPrinterParameterized4(windowId, FONT_NORMAL, x, y, letterSpacing, lineSpacing, sTextColors[colorTableId], speed, src);
2018-08-30 15:01:07 +02:00
}
2021-10-30 22:47:37 +02:00
static void PyramidBagPrint_Quantity(u8 windowId, const u8 *src, u8 x, u8 y, u8 letterSpacing, u8 lineSpacing, u8 speed, u8 colorTableId)
2018-08-30 15:01:07 +02:00
{
2021-10-30 22:47:37 +02:00
AddTextPrinterParameterized4(windowId, FONT_NARROW, x, y, letterSpacing, lineSpacing, sTextColors[colorTableId], speed, src);
2018-08-30 15:01:07 +02:00
}
2021-04-23 00:49:54 +02:00
static void DrawTossNumberWindow(u8 windowId)
2018-08-30 15:01:07 +02:00
{
2022-07-25 20:59:14 +02:00
DrawStdFrameWithCustomTileAndPalette(windowId, FALSE, 1, 0xE);
2020-05-14 10:37:09 +02:00
ScheduleBgCopyTilemapToVram(1);
2018-08-30 15:01:07 +02:00
}
2021-04-23 00:49:54 +02:00
// Unused
static u8 GetMenuActionWindowId(u8 windowArrayId)
2018-08-30 15:01:07 +02:00
{
2021-04-23 00:49:54 +02:00
return gPyramidBagMenu->windowIds[windowArrayId];
2018-08-30 15:01:07 +02:00
}
2021-04-23 00:49:54 +02:00
static u8 OpenMenuActionWindowById(u8 windowArrayId)
2018-08-30 15:01:07 +02:00
{
2021-04-23 00:49:54 +02:00
u8 *windowId = &gPyramidBagMenu->windowIds[windowArrayId];
2021-02-20 00:36:48 +01:00
if (*windowId == WINDOW_NONE)
2018-08-30 15:01:07 +02:00
{
2021-04-23 00:49:54 +02:00
*windowId = AddWindow(&sWindowTemplates_MenuActions[windowArrayId]);
DrawStdFrameWithCustomTileAndPalette(*windowId, FALSE, 1, 0xE);
2020-05-14 10:37:09 +02:00
ScheduleBgCopyTilemapToVram(1);
2018-08-30 15:01:07 +02:00
}
return *windowId;
}
2021-04-23 00:49:54 +02:00
static void CloseMenuActionWindowById(u8 windowArrayId)
2018-08-30 15:01:07 +02:00
{
2021-04-23 00:49:54 +02:00
u8 *windowId = &gPyramidBagMenu->windowIds[windowArrayId];
2021-02-20 00:36:48 +01:00
if (*windowId != WINDOW_NONE)
2018-08-30 15:01:07 +02:00
{
ClearStdWindowAndFrameToTransparent(*windowId, FALSE);
2018-08-30 15:01:07 +02:00
ClearWindowTilemap(*windowId);
RemoveWindow(*windowId);
2020-05-14 10:37:09 +02:00
ScheduleBgCopyTilemapToVram(1);
2021-02-20 00:36:48 +01:00
*windowId = WINDOW_NONE;
2018-08-30 15:01:07 +02:00
}
}
2018-08-30 20:10:57 +02:00
2021-04-23 00:49:54 +02:00
static void CreatePyramidBagYesNo(u8 taskId, const struct YesNoFuncTable *yesNoTable)
2018-08-30 20:10:57 +02:00
{
2021-04-23 00:49:54 +02:00
CreateYesNoMenuWithCallbacks(taskId, &sWindowTemplates_MenuActions[MENU_WIN_YESNO], 1, 0, 2, 1, 0xE, yesNoTable);
2018-08-30 20:10:57 +02:00
}
void DisplayItemMessageInBattlePyramid(u8 taskId, const u8 *str, void (*callback)(u8 taskId))
{
2021-04-23 00:49:54 +02:00
FillWindowPixelBuffer(WIN_MSG, PIXEL_FILL(1));
2021-10-30 22:47:37 +02:00
DisplayMessageAndContinueTask(taskId, WIN_MSG, 0xA, 0xD, FONT_NORMAL, GetPlayerTextSpeedDelay(), str, callback);
2020-05-14 10:37:09 +02:00
ScheduleBgCopyTilemapToVram(1);
2018-08-30 20:10:57 +02:00
}
2019-12-22 01:01:38 +01:00
static void CloseBattlePyramidBagTextWindow(void)
2018-08-30 20:10:57 +02:00
{
2021-04-23 00:49:54 +02:00
ClearDialogWindowAndFrameToTransparent(WIN_MSG, FALSE);
// This ClearWindowTilemap call is redundant, since ClearDialogWindowAndFrameToTransparent already calls it.
2021-04-23 00:49:54 +02:00
ClearWindowTilemap(WIN_MSG);
2020-05-14 10:37:09 +02:00
ScheduleBgCopyTilemapToVram(1);
2018-08-30 20:10:57 +02:00
}
2021-04-23 00:49:54 +02:00
static void FreeItemIconSprite(u8 spriteArrId)
2018-08-30 20:10:57 +02:00
{
2021-04-23 00:49:54 +02:00
u8 *spriteId = &gPyramidBagMenu->spriteIds[spriteArrId];
2021-02-20 06:30:37 +01:00
if (*spriteId != SPRITE_NONE)
2018-08-30 20:10:57 +02:00
{
2021-04-23 00:49:54 +02:00
// spriteArrId is PBAG_SPRITE_ITEM_ICON / PBAG_SPRITE_ITEM_ICON_ALT here (1-2)
// so tag will be TAG_ITEM_ICON / TAG_ITEM_ICON_ALT
FreeSpriteTilesByTag(TAG_ITEM_ICON - 1 + spriteArrId);
FreeSpritePaletteByTag(TAG_ITEM_ICON - 1 + spriteArrId);
2018-08-30 20:10:57 +02:00
FreeSpriteOamMatrix(&gSprites[*spriteId]);
DestroySprite(&gSprites[*spriteId]);
2021-02-20 06:30:37 +01:00
*spriteId = SPRITE_NONE;
2018-08-30 20:10:57 +02:00
}
}
2021-04-23 00:49:54 +02:00
static void LoadPyramidBagPalette(void)
2018-08-30 20:10:57 +02:00
{
struct SpritePalette spritePalette;
u16 *palPtr = Alloc(0x40);
2021-10-26 22:52:23 +02:00
LZDecompressWram(gBattlePyramidBag_Pal, palPtr);
2018-08-30 20:10:57 +02:00
spritePalette.data = palPtr + (gSaveBlock2Ptr->frontier.lvlMode * 16);
2021-04-23 00:49:54 +02:00
spritePalette.tag = TAG_PYRAMID_BAG;
2018-08-30 20:10:57 +02:00
LoadSpritePalette(&spritePalette);
Free(palPtr);
}
2021-04-23 00:49:54 +02:00
static void CreatePyramidBagSprite(void)
2018-08-30 20:10:57 +02:00
{
2021-04-23 00:49:54 +02:00
u8 *spriteId = &gPyramidBagMenu->spriteIds[PBAG_SPRITE_BAG];
*spriteId = CreateSprite(&sSpriteTemplate_PyramidBag, 68, 56, 0);
2018-08-30 20:10:57 +02:00
}
2021-04-23 00:49:54 +02:00
static void ShakePyramidBag(void)
2018-08-30 20:10:57 +02:00
{
2021-04-23 00:49:54 +02:00
struct Sprite *sprite = &gSprites[gPyramidBagMenu->spriteIds[PBAG_SPRITE_BAG]];
2018-08-30 20:10:57 +02:00
if (sprite->affineAnimEnded)
{
2021-04-23 00:49:54 +02:00
StartSpriteAffineAnim(sprite, ANIM_BAG_SHAKE);
sprite->callback = SpriteCB_BagWaitForShake;
2018-08-30 20:10:57 +02:00
}
}
2021-04-23 00:49:54 +02:00
static void SpriteCB_BagWaitForShake(struct Sprite *sprite)
2018-08-30 20:10:57 +02:00
{
if (sprite->affineAnimEnded)
{
2021-04-23 00:49:54 +02:00
StartSpriteAffineAnim(sprite, ANIM_BAG_STILL);
2018-08-30 20:10:57 +02:00
sprite->callback = SpriteCallbackDummy;
}
}
2021-04-23 00:49:54 +02:00
static void ShowItemIcon(u16 itemId, bool8 isAlt)
2018-08-30 20:10:57 +02:00
{
u8 itemSpriteId;
2021-04-23 00:49:54 +02:00
u8 *spriteId = &gPyramidBagMenu->spriteIds[isAlt + PBAG_SPRITE_ITEM_ICON];
2021-02-20 06:30:37 +01:00
if (*spriteId == SPRITE_NONE)
2018-08-30 20:10:57 +02:00
{
2021-04-23 00:49:54 +02:00
FreeSpriteTilesByTag(TAG_ITEM_ICON + isAlt);
FreeSpritePaletteByTag(TAG_ITEM_ICON + isAlt);
itemSpriteId = AddItemIconSprite(TAG_ITEM_ICON + isAlt, TAG_ITEM_ICON + isAlt, itemId);
2018-08-30 20:10:57 +02:00
if (itemSpriteId != MAX_SPRITES)
{
*spriteId = itemSpriteId;
2021-07-07 15:11:52 +02:00
gSprites[itemSpriteId].x2 = 24;
gSprites[itemSpriteId].y2 = 88;
2018-08-30 20:10:57 +02:00
}
}
}
2021-04-23 00:49:54 +02:00
static void FreeItemIconSpriteByAltId(bool8 isAlt)
2018-08-30 20:10:57 +02:00
{
2021-04-23 00:49:54 +02:00
FreeItemIconSprite(isAlt + PBAG_SPRITE_ITEM_ICON);
2018-08-30 20:10:57 +02:00
}
2021-04-11 22:23:10 +02:00
static void CreateSwapLine(void)
2018-08-30 20:10:57 +02:00
{
2021-04-23 00:49:54 +02:00
CreateSwapLineSprites(&gPyramidBagMenu->spriteIds[PBAG_SPRITE_SWAP_LINE_START], NUM_SWAP_LINE_SPRITES);
2018-08-30 20:10:57 +02:00
}
2021-04-11 22:23:10 +02:00
static void SetSwapLineInvisibility(bool8 invisible)
2018-08-30 20:10:57 +02:00
{
2021-04-23 00:49:54 +02:00
SetSwapLineSpritesInvisibility(&gPyramidBagMenu->spriteIds[PBAG_SPRITE_SWAP_LINE_START], NUM_SWAP_LINE_SPRITES, invisible);
2018-08-30 20:10:57 +02:00
}
2021-04-11 22:23:10 +02:00
static void UpdateSwapLinePos(u8 y)
2018-08-30 20:10:57 +02:00
{
2021-08-21 17:04:28 +02:00
UpdateSwapLineSpritesPos(&gPyramidBagMenu->spriteIds[PBAG_SPRITE_SWAP_LINE_START], NUM_SWAP_LINE_SPRITES | SWAP_LINE_HAS_MARGIN, 120, (y + 1) * 16);
2018-08-30 20:10:57 +02:00
}