pokeemerald/src/item_menu.c

2599 lines
83 KiB
C
Raw Normal View History

2018-01-30 19:19:37 +01:00
#include "global.h"
2018-03-04 18:41:07 +01:00
#include "item_menu.h"
2018-02-09 03:00:28 +01:00
#include "battle.h"
#include "battle_controllers.h"
2019-02-08 00:41:44 +01:00
#include "battle_pyramid.h"
2018-10-30 22:17:03 +01:00
#include "frontier_util.h"
2019-10-18 01:22:03 +02:00
#include "battle_pyramid_bag.h"
2018-02-09 03:00:28 +01:00
#include "berry_tag_screen.h"
2018-01-30 19:19:37 +01:00
#include "bg.h"
2019-04-04 23:53:06 +02:00
#include "data.h"
2018-01-30 19:19:37 +01:00
#include "decompress.h"
#include "event_data.h"
#include "event_object_movement.h"
2021-08-03 08:17:01 +02:00
#include "event_scripts.h"
2018-02-05 05:47:47 +01:00
#include "field_player_avatar.h"
2018-02-09 03:00:28 +01:00
#include "field_specials.h"
#include "graphics.h"
2018-01-30 19:19:37 +01:00
#include "gpu_regs.h"
#include "international_string_util.h"
#include "item.h"
2018-02-09 03:00:28 +01:00
#include "item_menu_icons.h"
#include "item_use.h"
#include "lilycove_lady.h"
2018-01-30 19:19:37 +01:00
#include "list_menu.h"
2018-02-05 05:47:47 +01:00
#include "link.h"
#include "mail.h"
2018-01-30 19:19:37 +01:00
#include "main.h"
#include "malloc.h"
2018-02-05 05:47:47 +01:00
#include "map_name_popup.h"
2018-01-30 19:19:37 +01:00
#include "menu.h"
#include "money.h"
2018-02-05 05:47:47 +01:00
#include "overworld.h"
2018-01-30 19:19:37 +01:00
#include "palette.h"
2018-02-09 03:00:28 +01:00
#include "party_menu.h"
#include "player_pc.h"
2018-02-05 05:47:47 +01:00
#include "pokemon.h"
2018-02-09 03:00:28 +01:00
#include "pokemon_summary_screen.h"
2018-01-31 06:03:52 +01:00
#include "scanline_effect.h"
2018-02-05 05:47:47 +01:00
#include "script.h"
2018-02-09 03:00:28 +01:00
#include "shop.h"
2018-01-30 19:19:37 +01:00
#include "sound.h"
#include "sprite.h"
2018-02-09 03:00:28 +01:00
#include "strings.h"
2018-01-30 19:19:37 +01:00
#include "string_util.h"
#include "task.h"
2018-02-05 05:47:47 +01:00
#include "text_window.h"
2018-01-30 19:19:37 +01:00
#include "menu_helpers.h"
#include "window.h"
2018-10-14 17:00:41 +02:00
#include "apprentice.h"
2018-11-12 14:35:56 +01:00
#include "battle_pike.h"
2021-08-03 08:17:01 +02:00
#include "constants/items.h"
2019-04-04 23:05:46 +02:00
#include "constants/rgb.h"
2021-08-03 08:17:01 +02:00
#include "constants/songs.h"
2018-11-01 21:31:10 +01:00
2021-08-03 08:17:01 +02:00
#define TAG_POCKET_SCROLL_ARROW 110
#define TAG_BAG_SCROLL_ARROW 111
// The buffer for the bag item list needs to be large enough to hold the maximum
// number of item slots that could fit in a single pocket, + 1 for Cancel.
// This constant picks the max of the existing pocket sizes.
// By default, the largest pocket is BAG_TMHM_COUNT at 64.
#define MAX_POCKET_ITEMS ((max(BAG_TMHM_COUNT, \
max(BAG_BERRIES_COUNT, \
max(BAG_ITEMS_COUNT, \
max(BAG_KEYITEMS_COUNT, \
BAG_POKEBALLS_COUNT))))) + 1)
// Up to 8 item slots can be visible at a time
#define MAX_ITEMS_SHOWN 8
enum {
2020-08-28 19:31:58 +02:00
SWITCH_POCKET_NONE,
SWITCH_POCKET_LEFT,
SWITCH_POCKET_RIGHT
};
2021-08-03 08:17:01 +02:00
enum {
ACTION_USE,
ACTION_TOSS,
ACTION_REGISTER,
ACTION_GIVE,
ACTION_CANCEL,
2021-08-03 08:17:01 +02:00
ACTION_BATTLE_USE,
ACTION_CHECK,
ACTION_WALK,
ACTION_DESELECT,
ACTION_CHECK_TAG,
ACTION_CONFIRM,
ACTION_SHOW,
ACTION_GIVE_FAVOR_LADY,
ACTION_CONFIRM_QUIZ_LADY,
ACTION_DUMMY,
2021-08-03 08:17:01 +02:00
};
enum {
WIN_ITEM_LIST,
WIN_DESCRIPTION,
WIN_POCKET_NAME,
WIN_TMHM_INFO_ICONS,
WIN_TMHM_INFO,
WIN_MESSAGE, // Identical to ITEMWIN_MESSAGE. Unused?
};
// Item list ID for toSwapPos to indicate an item is not currently being swapped
#define NOT_SWAPPING 0xFF
struct ListBuffer1 {
struct ListMenuItem subBuffers[MAX_POCKET_ITEMS];
};
struct ListBuffer2 {
s8 name[MAX_POCKET_ITEMS][ITEM_NAME_LENGTH + 10];
};
struct TempWallyBag {
struct ItemSlot bagPocket_Items[BAG_ITEMS_COUNT];
struct ItemSlot bagPocket_PokeBalls[BAG_POKEBALLS_COUNT];
u16 cursorPosition[POCKETS_COUNT];
u16 scrollPosition[POCKETS_COUNT];
u16 unused;
u16 pocket;
};
static void CB2_Bag(void);
static bool8 SetupBagMenu(void);
static void BagMenu_InitBGs(void);
static bool8 LoadBagMenu_Graphics(void);
static void LoadBagMenuTextWindows(void);
static void AllocateBagItemListBuffers(void);
static void LoadBagItemListBuffers(u8);
static void PrintPocketNames(const u8 *, const u8 *);
2021-08-03 08:17:01 +02:00
static void CopyPocketNameToWindow(u32);
static void DrawPocketIndicatorSquare(u8, bool8);
static void CreatePocketScrollArrowPair(void);
static void CreatePocketSwitchArrowPair(void);
static void DestroyPocketSwitchArrowPair(void);
static void PrepareTMHMMoveWindow(void);
static bool8 IsWallysBag(void);
static void Task_WallyTutorialBagMenu(u8);
static void Task_BagMenu_HandleInput(u8);
static void GetItemName(s8 *, u16);
2021-08-03 08:17:01 +02:00
static void PrintItemDescription(int);
static void BagMenu_PrintCursorAtPos(u8, u8);
static void BagMenu_Print(u8, u8, const u8 *, u8, u8, u8, u8, u8, u8);
2021-08-03 08:17:01 +02:00
static void Task_CloseBagMenu(u8);
static u8 AddItemMessageWindow(u8);
static void RemoveItemMessageWindow(u8);
static void ReturnToItemList(u8);
static void PrintItemQuantity(u8, s16);
2020-08-28 19:31:58 +02:00
static u8 BagMenu_AddWindow(u8);
static u8 GetSwitchBagPocketDirection(void);
2021-08-03 08:17:01 +02:00
static void SwitchBagPocket(u8, s16, bool16);
2020-08-28 19:31:58 +02:00
static bool8 CanSwapItems(void);
2021-08-03 08:17:01 +02:00
static void StartItemSwap(u8 taskId);
static void Task_SwitchBagPocket(u8);
2020-08-28 19:31:58 +02:00
static void Task_HandleSwappingItemsInput(u8);
2021-08-03 08:17:01 +02:00
static void DoItemSwap(u8);
static void CancelItemSwap(u8);
static void PrintTMHMMoveData(u16);
static void PrintContextMenuItems(u8);
static void PrintContextMenuItemGrid(u8, u8, u8);
static void Task_ItemContext_SingleRow(u8);
static void Task_ItemContext_MultipleRows(u8);
static bool8 IsValidContextMenuPos(s8);
static void BagMenu_RemoveWindow(u8);
static void PrintThereIsNoPokemon(u8);
static void Task_ChooseHowManyToToss(u8);
static void AskTossItems(u8);
static void Task_RemoveItemFromBag(u8);
static void ItemMenu_Cancel(u8);
static void HandleErrorMessage(u8);
static void PrintItemCantBeHeld(u8);
2020-08-28 19:31:58 +02:00
static void DisplayCurrentMoneyWindow(void);
static void DisplaySellItemPriceAndConfirm(u8);
2021-08-03 08:17:01 +02:00
static void InitSellHowManyInput(u8);
static void AskSellItems(u8);
2020-08-28 19:31:58 +02:00
static void RemoveMoneyWindow(void);
2021-08-03 08:17:01 +02:00
static void Task_ChooseHowManyToSell(u8);
static void SellItem(u8);
static void WaitAfterItemSell(u8);
static void TryDepositItem(u8);
2020-08-28 19:31:58 +02:00
static void Task_ChooseHowManyToDeposit(u8 taskId);
2021-08-03 08:17:01 +02:00
static void WaitDepositErrorMessage(u8);
static void CB2_ApprenticeExitBagMenu(void);
static void CB2_FavorLadyExitBagMenu(void);
static void CB2_QuizLadyExitBagMenu(void);
static void UpdatePocketItemLists(void);
static void InitPocketListPositions(void);
static void InitPocketScrollPositions(void);
static u8 CreateBagInputHandlerTask(u8);
static void DrawItemListBgRow(u8);
2022-07-29 17:15:33 +02:00
static void BagMenu_MoveCursorCallback(s32, bool8, struct ListMenu *);
2021-08-03 08:17:01 +02:00
static void BagMenu_ItemPrintCallback(u8, u32, u8);
static void ItemMenu_UseOutOfBattle(u8);
static void ItemMenu_Toss(u8);
static void ItemMenu_Register(u8);
static void ItemMenu_Give(u8);
static void ItemMenu_Cancel(u8);
static void ItemMenu_UseInBattle(u8);
static void ItemMenu_CheckTag(u8);
static void ItemMenu_Show(u8);
static void ItemMenu_GiveFavorLady(u8);
static void ItemMenu_ConfirmQuizLady(u8);
static void Task_ItemContext_Normal(u8);
static void Task_ItemContext_GiveToParty(u8);
static void Task_ItemContext_Sell(u8);
static void Task_ItemContext_Deposit(u8);
static void Task_ItemContext_GiveToPC(u8);
static void ConfirmToss(u8);
static void CancelToss(u8);
static void ConfirmSell(u8);
static void CancelSell(u8);
2018-02-12 19:59:42 +01:00
2020-05-14 10:37:09 +02:00
static const struct BgTemplate sBgTemplates_ItemMenu[] =
2018-09-02 15:49:29 +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,
},
2018-02-12 19:59:42 +01:00
};
2018-02-14 01:12:17 +01:00
2018-12-15 19:08:13 +01:00
static const struct ListMenuTemplate sItemListMenu =
2018-09-02 15:49:29 +02:00
{
.items = NULL,
.moveCursorFunc = BagMenu_MoveCursorCallback,
2020-05-14 10:37:09 +02:00
.itemPrintFunc = BagMenu_ItemPrintCallback,
2018-09-02 15:49:29 +02:00
.totalItems = 0,
.maxShowed = 0,
.windowId = 0,
.header_X = 0,
.item_X = 8,
.cursor_X = 0,
.upText_Y = 1,
.cursorPal = 1,
.fillValue = 0,
.cursorShadowPal = 3,
.lettersSpacing = 0,
.itemVerticalPadding = 0,
2022-11-09 21:14:41 +01:00
.scrollMultiple = LIST_NO_MULTIPLE_SCROLL,
2021-10-30 22:47:37 +02:00
.fontId = FONT_NARROW,
2022-11-09 21:14:41 +01:00
.cursorKind = CURSOR_BLACK_ARROW
2018-02-12 19:59:42 +01:00
};
2020-05-14 10:37:09 +02:00
static const struct MenuAction sItemMenuActions[] = {
2021-08-03 08:17:01 +02:00
[ACTION_USE] = {gMenuText_Use, ItemMenu_UseOutOfBattle},
[ACTION_TOSS] = {gMenuText_Toss, ItemMenu_Toss},
[ACTION_REGISTER] = {gMenuText_Register, ItemMenu_Register},
[ACTION_GIVE] = {gMenuText_Give, ItemMenu_Give},
[ACTION_CANCEL] = {gText_Cancel2, ItemMenu_Cancel},
[ACTION_BATTLE_USE] = {gMenuText_Use, ItemMenu_UseInBattle},
[ACTION_CHECK] = {gMenuText_Check, ItemMenu_UseOutOfBattle},
[ACTION_WALK] = {gMenuText_Walk, ItemMenu_UseOutOfBattle},
[ACTION_DESELECT] = {gMenuText_Deselect, ItemMenu_Register},
[ACTION_CHECK_TAG] = {gMenuText_CheckTag, ItemMenu_CheckTag},
[ACTION_CONFIRM] = {gMenuText_Confirm, Task_FadeAndCloseBagMenu},
[ACTION_SHOW] = {gMenuText_Show, ItemMenu_Show},
[ACTION_GIVE_FAVOR_LADY] = {gMenuText_Give2, ItemMenu_GiveFavorLady},
[ACTION_CONFIRM_QUIZ_LADY] = {gMenuText_Confirm, ItemMenu_ConfirmQuizLady},
[ACTION_DUMMY] = {gText_EmptyString2, NULL}
2018-02-12 19:59:42 +01:00
};
2020-05-14 10:37:09 +02:00
// these are all 2D arrays with a width of 2 but are represented as 1D arrays
2021-08-03 08:17:01 +02:00
// ACTION_DUMMY is used to represent blank spaces
2020-05-14 10:37:09 +02:00
static const u8 sContextMenuItems_ItemsPocket[] = {
2021-08-03 08:17:01 +02:00
ACTION_USE, ACTION_GIVE,
ACTION_TOSS, ACTION_CANCEL
2018-02-12 19:59:42 +01:00
};
2020-05-14 10:37:09 +02:00
static const u8 sContextMenuItems_KeyItemsPocket[] = {
2021-08-03 08:17:01 +02:00
ACTION_USE, ACTION_REGISTER,
ACTION_DUMMY, ACTION_CANCEL
2020-05-14 10:37:09 +02:00
};
static const u8 sContextMenuItems_BallsPocket[] = {
2021-08-03 08:17:01 +02:00
ACTION_GIVE, ACTION_DUMMY,
ACTION_TOSS, ACTION_CANCEL
2020-05-14 10:37:09 +02:00
};
static const u8 sContextMenuItems_TmHmPocket[] = {
2021-08-03 08:17:01 +02:00
ACTION_USE, ACTION_GIVE,
ACTION_DUMMY, ACTION_CANCEL
2020-05-14 10:37:09 +02:00
};
static const u8 sContextMenuItems_BerriesPocket[] = {
2021-08-03 08:17:01 +02:00
ACTION_CHECK_TAG, ACTION_DUMMY,
ACTION_USE, ACTION_GIVE,
ACTION_TOSS, ACTION_CANCEL
2020-05-14 10:37:09 +02:00
};
static const u8 sContextMenuItems_BattleUse[] = {
2021-08-03 08:17:01 +02:00
ACTION_BATTLE_USE, ACTION_CANCEL
2020-05-14 10:37:09 +02:00
};
static const u8 sContextMenuItems_Give[] = {
2021-08-03 08:17:01 +02:00
ACTION_GIVE, ACTION_CANCEL
2020-05-14 10:37:09 +02:00
};
static const u8 sContextMenuItems_Cancel[] = {
2021-08-03 08:17:01 +02:00
ACTION_CANCEL
2020-05-14 10:37:09 +02:00
};
static const u8 sContextMenuItems_BerryBlenderCrush[] = {
2021-08-03 08:17:01 +02:00
ACTION_CONFIRM, ACTION_CHECK_TAG,
ACTION_DUMMY, ACTION_CANCEL
2020-05-14 10:37:09 +02:00
};
static const u8 sContextMenuItems_Apprentice[] = {
2021-08-03 08:17:01 +02:00
ACTION_SHOW, ACTION_CANCEL
2020-05-14 10:37:09 +02:00
};
2018-02-12 19:59:42 +01:00
2020-05-14 10:37:09 +02:00
static const u8 sContextMenuItems_FavorLady[] = {
2021-08-03 08:17:01 +02:00
ACTION_GIVE_FAVOR_LADY, ACTION_CANCEL
2020-05-14 10:37:09 +02:00
};
2018-02-12 19:59:42 +01:00
2020-05-14 10:37:09 +02:00
static const u8 sContextMenuItems_QuizLady[] = {
2021-08-03 08:17:01 +02:00
ACTION_CONFIRM_QUIZ_LADY, ACTION_CANCEL
2020-05-14 10:37:09 +02:00
};
2018-02-12 19:59:42 +01:00
2021-08-03 08:17:01 +02:00
static const TaskFunc sContextMenuFuncs[] = {
[ITEMMENULOCATION_FIELD] = Task_ItemContext_Normal,
[ITEMMENULOCATION_BATTLE] = Task_ItemContext_Normal,
[ITEMMENULOCATION_PARTY] = Task_ItemContext_GiveToParty,
2020-05-14 10:37:09 +02:00
[ITEMMENULOCATION_SHOP] = Task_ItemContext_Sell,
[ITEMMENULOCATION_BERRY_TREE] = Task_FadeAndCloseBagMenu,
2021-08-03 08:17:01 +02:00
[ITEMMENULOCATION_BERRY_BLENDER_CRUSH] = Task_ItemContext_Normal,
2020-05-14 10:37:09 +02:00
[ITEMMENULOCATION_ITEMPC] = Task_ItemContext_Deposit,
2021-08-03 08:17:01 +02:00
[ITEMMENULOCATION_FAVOR_LADY] = Task_ItemContext_Normal,
[ITEMMENULOCATION_QUIZ_LADY] = Task_ItemContext_Normal,
[ITEMMENULOCATION_APPRENTICE] = Task_ItemContext_Normal,
2020-05-14 10:37:09 +02:00
[ITEMMENULOCATION_WALLY] = NULL,
2021-08-03 08:17:01 +02:00
[ITEMMENULOCATION_PCBOX] = Task_ItemContext_GiveToPC
2020-05-14 10:37:09 +02:00
};
2021-08-03 08:17:01 +02:00
static const struct YesNoFuncTable sYesNoTossFunctions = {ConfirmToss, CancelToss};
2020-05-14 10:37:09 +02:00
2021-08-03 08:17:01 +02:00
static const struct YesNoFuncTable sYesNoSellItemFunctions = {ConfirmSell, CancelSell};
2020-05-14 10:37:09 +02:00
static const struct ScrollArrowsTemplate sBagScrollArrowsTemplate = {
.firstArrowType = SCROLL_ARROW_LEFT,
.firstX = 28,
.firstY = 16,
.secondArrowType = SCROLL_ARROW_RIGHT,
.secondX = 100,
.secondY = 16,
.fullyUpThreshold = -1,
.fullyDownThreshold = -1,
2021-08-03 08:17:01 +02:00
.tileTag = TAG_BAG_SCROLL_ARROW,
.palTag = TAG_BAG_SCROLL_ARROW,
2020-05-14 10:37:09 +02:00
.palNum = 0,
};
static const u8 sRegisteredSelect_Gfx[] = INCBIN_U8("graphics/bag/select_button.4bpp");
2018-02-12 19:59:42 +01:00
2021-08-03 08:17:01 +02:00
enum {
COLORID_NORMAL,
COLORID_POCKET_NAME,
COLORID_GRAY_CURSOR,
COLORID_UNUSED,
COLORID_TMHM_INFO,
COLORID_NONE = 0xFF
};
2018-12-15 19:08:13 +01:00
static const u8 sFontColorTable[][3] = {
2021-08-03 08:17:01 +02:00
// bgColor, textColor, shadowColor
[COLORID_NORMAL] = {TEXT_COLOR_TRANSPARENT, TEXT_COLOR_WHITE, TEXT_COLOR_LIGHT_GRAY},
[COLORID_POCKET_NAME] = {TEXT_COLOR_TRANSPARENT, TEXT_COLOR_WHITE, TEXT_COLOR_RED},
[COLORID_GRAY_CURSOR] = {TEXT_COLOR_TRANSPARENT, TEXT_COLOR_LIGHT_GRAY, TEXT_COLOR_GREEN},
[COLORID_UNUSED] = {TEXT_COLOR_DARK_GRAY, TEXT_COLOR_WHITE, TEXT_COLOR_LIGHT_GRAY},
[COLORID_TMHM_INFO] = {TEXT_COLOR_TRANSPARENT, TEXT_DYNAMIC_COLOR_5, TEXT_DYNAMIC_COLOR_1}
2018-02-12 19:59:42 +01:00
};
2021-08-03 08:17:01 +02:00
static const struct WindowTemplate sDefaultBagWindows[] =
2018-09-02 15:49:29 +02:00
{
2021-08-03 08:17:01 +02:00
[WIN_ITEM_LIST] = {
2018-10-27 00:53:07 +02:00
.bg = 0,
2018-09-02 15:49:29 +02:00
.tilemapLeft = 14,
.tilemapTop = 2,
.width = 15,
.height = 16,
.paletteNum = 1,
.baseBlock = 0x27,
},
2021-08-03 08:17:01 +02:00
[WIN_DESCRIPTION] = {
2018-10-27 00:53:07 +02:00
.bg = 0,
2018-09-02 15:49:29 +02:00
.tilemapLeft = 0,
.tilemapTop = 13,
.width = 14,
.height = 6,
.paletteNum = 1,
.baseBlock = 0x117,
},
2021-08-03 08:17:01 +02:00
[WIN_POCKET_NAME] = {
2018-10-27 00:53:07 +02:00
.bg = 0,
2018-09-02 15:49:29 +02:00
.tilemapLeft = 4,
.tilemapTop = 1,
.width = 8,
.height = 2,
.paletteNum = 1,
.baseBlock = 0x1A1,
},
2021-08-03 08:17:01 +02:00
[WIN_TMHM_INFO_ICONS] = {
2018-10-27 00:53:07 +02:00
.bg = 0,
2018-09-02 15:49:29 +02:00
.tilemapLeft = 1,
.tilemapTop = 13,
.width = 5,
.height = 6,
.paletteNum = 12,
.baseBlock = 0x16B,
},
2021-08-03 08:17:01 +02:00
[WIN_TMHM_INFO] = {
2018-10-27 00:53:07 +02:00
.bg = 0,
2018-09-02 15:49:29 +02:00
.tilemapLeft = 7,
.tilemapTop = 13,
.width = 4,
.height = 6,
.paletteNum = 12,
.baseBlock = 0x189,
},
2021-08-03 08:17:01 +02:00
[WIN_MESSAGE] = {
2018-10-27 00:53:07 +02:00
.bg = 1,
2018-09-02 15:49:29 +02:00
.tilemapLeft = 2,
.tilemapTop = 15,
.width = 27,
.height = 4,
.paletteNum = 15,
.baseBlock = 0x1B1,
},
DUMMY_WIN_TEMPLATE,
2018-02-12 19:59:42 +01:00
};
2021-08-03 08:17:01 +02:00
static const struct WindowTemplate sContextMenuWindowTemplates[] =
2018-09-02 15:49:29 +02:00
{
2021-08-03 08:17:01 +02:00
[ITEMWIN_1x1] = {
2018-10-27 00:53:07 +02:00
.bg = 1,
2018-09-02 15:49:29 +02:00
.tilemapLeft = 22,
.tilemapTop = 17,
.width = 7,
.height = 2,
.paletteNum = 15,
.baseBlock = 0x21D,
},
2021-08-03 08:17:01 +02:00
[ITEMWIN_1x2] = {
2018-10-27 00:53:07 +02:00
.bg = 1,
2018-09-02 15:49:29 +02:00
.tilemapLeft = 22,
.tilemapTop = 15,
.width = 7,
.height = 4,
.paletteNum = 15,
.baseBlock = 0x21D,
},
2021-08-03 08:17:01 +02:00
[ITEMWIN_2x2] = {
2018-10-27 00:53:07 +02:00
.bg = 1,
2018-09-02 15:49:29 +02:00
.tilemapLeft = 15,
.tilemapTop = 15,
.width = 14,
.height = 4,
.paletteNum = 15,
.baseBlock = 0x21D,
},
2021-08-03 08:17:01 +02:00
[ITEMWIN_2x3] = {
2018-10-27 00:53:07 +02:00
.bg = 1,
2018-09-02 15:49:29 +02:00
.tilemapLeft = 15,
.tilemapTop = 13,
.width = 14,
.height = 6,
.paletteNum = 15,
.baseBlock = 0x21D,
},
2021-08-03 08:17:01 +02:00
[ITEMWIN_MESSAGE] = {
2018-10-27 00:53:07 +02:00
.bg = 1,
2018-09-02 15:49:29 +02:00
.tilemapLeft = 2,
.tilemapTop = 15,
.width = 27,
.height = 4,
.paletteNum = 15,
.baseBlock = 0x1B1,
},
2021-08-03 08:17:01 +02:00
[ITEMWIN_YESNO_LOW] = { // Yes/No tucked in corner, for toss confirm
2018-10-27 00:53:07 +02:00
.bg = 1,
2018-09-02 15:49:29 +02:00
.tilemapLeft = 24,
.tilemapTop = 15,
.width = 5,
.height = 4,
.paletteNum = 15,
.baseBlock = 0x21D,
},
2021-08-03 08:17:01 +02:00
[ITEMWIN_YESNO_HIGH] = { // Yes/No higher up, positioned above a lower message box
2018-10-27 00:53:07 +02:00
.bg = 1,
2018-09-02 15:49:29 +02:00
.tilemapLeft = 21,
.tilemapTop = 9,
.width = 5,
.height = 4,
.paletteNum = 15,
.baseBlock = 0x21D,
},
2021-08-03 08:17:01 +02:00
[ITEMWIN_QUANTITY] = { // Used for quantity of items to Toss/Deposit
2018-10-27 00:53:07 +02:00
.bg = 1,
2018-09-02 15:49:29 +02:00
.tilemapLeft = 24,
.tilemapTop = 17,
.width = 5,
.height = 2,
.paletteNum = 15,
.baseBlock = 0x21D,
},
2021-08-03 08:17:01 +02:00
[ITEMWIN_QUANTITY_WIDE] = { // Used for quantity and price of items to Sell
2018-10-27 00:53:07 +02:00
.bg = 1,
2018-09-02 15:49:29 +02:00
.tilemapLeft = 18,
.tilemapTop = 11,
.width = 10,
.height = 2,
.paletteNum = 15,
.baseBlock = 0x245,
},
2021-08-03 08:17:01 +02:00
[ITEMWIN_MONEY] = {
2018-10-27 00:53:07 +02:00
.bg = 1,
2018-09-02 15:49:29 +02:00
.tilemapLeft = 1,
.tilemapTop = 1,
.width = 10,
.height = 2,
.paletteNum = 15,
.baseBlock = 0x231,
},
2018-02-12 19:59:42 +01:00
};
2021-08-03 08:17:01 +02:00
EWRAM_DATA struct BagMenu *gBagMenu = 0;
EWRAM_DATA struct BagPosition gBagPosition = {0};
2018-12-15 19:08:13 +01:00
static EWRAM_DATA struct ListBuffer1 *sListBuffer1 = 0;
static EWRAM_DATA struct ListBuffer2 *sListBuffer2 = 0;
2018-02-12 19:59:42 +01:00
EWRAM_DATA u16 gSpecialVar_ItemId = 0;
2021-08-03 08:17:01 +02:00
static EWRAM_DATA struct TempWallyBag *sTempWallyBag = 0;
2018-01-30 19:19:37 +01:00
void ResetBagScrollPositions(void)
{
2021-08-03 08:17:01 +02:00
gBagPosition.pocket = ITEMS_POCKET;
memset(gBagPosition.cursorPosition, 0, sizeof(gBagPosition.cursorPosition));
memset(gBagPosition.scrollPosition, 0, sizeof(gBagPosition.scrollPosition));
2018-01-30 19:19:37 +01:00
}
void CB2_BagMenuFromStartMenu(void)
{
2020-05-14 10:37:09 +02:00
GoToBagMenu(ITEMMENULOCATION_FIELD, POCKETS_COUNT, CB2_ReturnToFieldWithOpenMenu);
2018-01-30 19:19:37 +01:00
}
2020-05-14 10:37:09 +02:00
void CB2_BagMenuFromBattle(void)
2018-01-30 19:19:37 +01:00
{
if (!InBattlePyramid())
2020-05-14 10:37:09 +02:00
GoToBagMenu(ITEMMENULOCATION_BATTLE, POCKETS_COUNT, CB2_SetUpReshowBattleScreenAfterMenu2);
2018-01-30 19:19:37 +01:00
else
2021-04-23 00:49:54 +02:00
GoToBattlePyramidBagMenu(PYRAMIDBAG_LOC_BATTLE, CB2_SetUpReshowBattleScreenAfterMenu2);
2018-01-30 19:19:37 +01:00
}
2020-08-23 00:20:22 +02:00
// Choosing berry to plant
2018-01-30 19:19:37 +01:00
void CB2_ChooseBerry(void)
{
2020-05-14 10:37:09 +02:00
GoToBagMenu(ITEMMENULOCATION_BERRY_TREE, BERRIES_POCKET, CB2_ReturnToFieldContinueScript);
2018-01-30 19:19:37 +01:00
}
2020-08-23 00:20:22 +02:00
// Choosing berry for Berry Blender or Berry Crush
void ChooseBerryForMachine(void (*exitCallback)(void))
2018-01-30 19:19:37 +01:00
{
2020-08-23 00:20:22 +02:00
GoToBagMenu(ITEMMENULOCATION_BERRY_BLENDER_CRUSH, BERRIES_POCKET, exitCallback);
2018-01-30 19:19:37 +01:00
}
void CB2_GoToSellMenu(void)
{
2020-05-14 10:37:09 +02:00
GoToBagMenu(ITEMMENULOCATION_SHOP, POCKETS_COUNT, CB2_ExitSellMenu);
2018-01-30 19:19:37 +01:00
}
2020-05-14 10:37:09 +02:00
void CB2_GoToItemDepositMenu(void)
2018-01-30 19:19:37 +01:00
{
2021-04-25 18:07:08 +02:00
GoToBagMenu(ITEMMENULOCATION_ITEMPC, POCKETS_COUNT, CB2_PlayerPCExitBagMenu);
2018-01-30 19:19:37 +01:00
}
2019-11-19 17:36:38 +01:00
void ApprenticeOpenBagMenu(void)
2018-01-30 19:19:37 +01:00
{
2020-05-14 10:37:09 +02:00
GoToBagMenu(ITEMMENULOCATION_APPRENTICE, POCKETS_COUNT, CB2_ApprenticeExitBagMenu);
2019-11-20 23:36:52 +01:00
gSpecialVar_0x8005 = ITEM_NONE;
gSpecialVar_Result = FALSE;
2018-01-30 19:19:37 +01:00
}
2019-08-06 02:37:09 +02:00
void FavorLadyOpenBagMenu(void)
2018-01-30 19:19:37 +01:00
{
2020-05-14 10:37:09 +02:00
GoToBagMenu(ITEMMENULOCATION_FAVOR_LADY, POCKETS_COUNT, CB2_FavorLadyExitBagMenu);
2019-11-20 23:36:52 +01:00
gSpecialVar_Result = FALSE;
2018-01-30 19:19:37 +01:00
}
2019-08-06 02:37:09 +02:00
void QuizLadyOpenBagMenu(void)
2018-01-30 19:19:37 +01:00
{
2020-05-14 10:37:09 +02:00
GoToBagMenu(ITEMMENULOCATION_QUIZ_LADY, POCKETS_COUNT, CB2_QuizLadyExitBagMenu);
2019-11-20 23:36:52 +01:00
gSpecialVar_Result = FALSE;
2018-01-30 19:19:37 +01:00
}
2021-08-03 08:17:01 +02:00
void GoToBagMenu(u8 location, u8 pocket, void ( *exitCallback)())
2018-01-30 19:19:37 +01:00
{
2021-08-03 08:17:01 +02:00
gBagMenu = AllocZeroed(sizeof(*gBagMenu));
2020-05-14 10:37:09 +02:00
if (gBagMenu == NULL)
2018-02-09 03:00:28 +01:00
{
2021-08-03 08:17:01 +02:00
// Alloc failed, exit
SetMainCallback2(exitCallback);
2018-02-09 03:00:28 +01:00
}
2018-01-30 19:19:37 +01:00
else
{
2020-05-14 10:37:09 +02:00
if (location != ITEMMENULOCATION_LAST)
2021-08-03 08:17:01 +02:00
gBagPosition.location = location;
if (exitCallback)
gBagPosition.exitCallback = exitCallback;
2020-05-14 10:37:09 +02:00
if (pocket < POCKETS_COUNT)
2021-08-03 08:17:01 +02:00
gBagPosition.pocket = pocket;
if (gBagPosition.location == ITEMMENULOCATION_BERRY_TREE ||
gBagPosition.location == ITEMMENULOCATION_BERRY_BLENDER_CRUSH)
2020-05-14 10:37:09 +02:00
gBagMenu->pocketSwitchDisabled = TRUE;
2021-08-03 08:17:01 +02:00
gBagMenu->newScreenCallback = NULL;
gBagMenu->toSwapPos = NOT_SWAPPING;
2021-02-20 05:22:26 +01:00
gBagMenu->pocketScrollArrowsTask = TASK_NONE;
gBagMenu->pocketSwitchArrowsTask = TASK_NONE;
2021-08-03 08:17:01 +02:00
memset(gBagMenu->spriteIds, SPRITE_NONE, sizeof(gBagMenu->spriteIds));
memset(gBagMenu->windowIds, WINDOW_NONE, sizeof(gBagMenu->windowIds));
2018-01-30 19:19:37 +01:00
SetMainCallback2(CB2_Bag);
}
}
2020-05-14 10:37:09 +02:00
void CB2_BagMenuRun(void)
2018-01-30 19:19:37 +01:00
{
RunTasks();
AnimateSprites();
BuildOamBuffer();
DoScheduledBgTilemapCopiesToVram();
2018-01-30 19:19:37 +01:00
UpdatePaletteFade();
}
2020-05-14 10:37:09 +02:00
void VBlankCB_BagMenuRun(void)
2018-01-30 19:19:37 +01:00
{
LoadOam();
ProcessSpriteCopyRequests();
TransferPlttBuffer();
}
2021-08-03 08:17:01 +02:00
#define tListTaskId data[0]
#define tListPosition data[1]
#define tQuantity data[2]
#define tNeverRead data[3]
#define tItemCount data[8]
#define tMsgWindowId data[10]
#define tPocketSwitchDir data[11]
#define tPocketSwitchTimer data[12]
#define tPocketSwitchState data[13]
2020-03-08 05:03:21 +01:00
2021-08-03 08:17:01 +02:00
static void CB2_Bag(void)
2018-01-30 19:19:37 +01:00
{
while(MenuHelpers_ShouldWaitForLinkRecv() != TRUE && SetupBagMenu() != TRUE && MenuHelpers_IsLinkActive() != TRUE)
2021-08-03 08:17:01 +02:00
{};
2018-01-30 19:19:37 +01:00
}
2021-08-03 08:17:01 +02:00
static bool8 SetupBagMenu(void)
2018-01-30 19:19:37 +01:00
{
u8 taskId;
switch (gMain.state)
{
case 0:
SetVBlankHBlankCallbacksToNull();
ClearScheduledBgCopiesToVram();
2018-01-30 19:19:37 +01: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:
gMain.state++;
break;
case 6:
if (!MenuHelpers_IsLinkActive())
2018-01-30 19:19:37 +01:00
ResetTasks();
gMain.state++;
break;
case 7:
BagMenu_InitBGs();
2020-05-14 10:37:09 +02:00
gBagMenu->graphicsLoadState = 0;
2018-01-30 19:19:37 +01:00
gMain.state++;
break;
case 8:
if (!LoadBagMenu_Graphics())
2018-01-30 19:19:37 +01:00
break;
gMain.state++;
break;
case 9:
2021-08-03 08:17:01 +02:00
LoadBagMenuTextWindows();
2018-01-30 19:19:37 +01:00
gMain.state++;
break;
case 10:
2021-08-03 08:17:01 +02:00
UpdatePocketItemLists();
InitPocketListPositions();
InitPocketScrollPositions();
2018-01-30 19:19:37 +01:00
gMain.state++;
break;
case 11:
AllocateBagItemListBuffers();
2018-01-30 19:19:37 +01:00
gMain.state++;
break;
case 12:
2021-08-03 08:17:01 +02:00
LoadBagItemListBuffers(gBagPosition.pocket);
2018-01-30 19:19:37 +01:00
gMain.state++;
break;
case 13:
2021-08-03 08:17:01 +02:00
PrintPocketNames(gPocketNamesStringsTable[gBagPosition.pocket], 0);
CopyPocketNameToWindow(0);
DrawPocketIndicatorSquare(gBagPosition.pocket, TRUE);
2018-01-30 19:19:37 +01:00
gMain.state++;
break;
case 14:
2021-08-03 08:17:01 +02:00
taskId = CreateBagInputHandlerTask(gBagPosition.location);
gTasks[taskId].tListTaskId = ListMenuInit(&gMultiuseListMenuTemplate, gBagPosition.scrollPosition[gBagPosition.pocket], gBagPosition.cursorPosition[gBagPosition.pocket]);
gTasks[taskId].tNeverRead = 0;
2020-03-08 05:03:21 +01:00
gTasks[taskId].tItemCount = 0;
2018-01-30 19:19:37 +01:00
gMain.state++;
break;
case 15:
2021-08-03 08:17:01 +02:00
AddBagVisualSprite(gBagPosition.pocket);
2018-01-30 19:19:37 +01:00
gMain.state++;
break;
case 16:
2021-04-11 22:23:10 +02:00
CreateItemMenuSwapLine();
2018-01-30 19:19:37 +01:00
gMain.state++;
break;
case 17:
2020-05-14 10:37:09 +02:00
CreatePocketScrollArrowPair();
CreatePocketSwitchArrowPair();
2018-01-30 19:19:37 +01:00
gMain.state++;
break;
case 18:
2021-08-03 08:17:01 +02:00
PrepareTMHMMoveWindow();
2018-01-30 19:19:37 +01:00
gMain.state++;
break;
case 19:
2021-02-24 17:01:02 +01:00
BlendPalettes(PALETTES_ALL, 16, 0);
2018-01-30 19:19:37 +01:00
gMain.state++;
break;
case 20:
2021-02-24 17:01:02 +01:00
BeginNormalPaletteFade(PALETTES_ALL, 0, 16, 0, RGB_BLACK);
2018-01-30 19:19:37 +01:00
gPaletteFade.bufferTransferDisabled = FALSE;
gMain.state++;
break;
default:
2020-05-14 10:37:09 +02:00
SetVBlankCallback(VBlankCB_BagMenuRun);
SetMainCallback2(CB2_BagMenuRun);
2018-01-30 19:19:37 +01:00
return TRUE;
}
return FALSE;
}
2021-08-03 08:17:01 +02:00
static void BagMenu_InitBGs(void)
2018-01-30 19:19:37 +01:00
{
ResetVramOamAndBgCntRegs();
2021-08-03 08:17:01 +02:00
memset(gBagMenu->tilemapBuffer, 0, sizeof(gBagMenu->tilemapBuffer));
2018-01-30 19:19:37 +01:00
ResetBgsAndClearDma3BusyFlags(0);
InitBgsFromTemplates(0, sBgTemplates_ItemMenu, ARRAY_COUNT(sBgTemplates_ItemMenu));
SetBgTilemapBuffer(2, gBagMenu->tilemapBuffer);
2018-01-30 19:19:37 +01:00
ResetAllBgsCoordinates();
2020-05-14 10:37:09 +02:00
ScheduleBgCopyTilemapToVram(2);
2018-02-12 19:59:42 +01:00
SetGpuReg(REG_OFFSET_DISPCNT, DISPCNT_OBJ_ON | DISPCNT_OBJ_1D_MAP);
2018-01-30 19:19:37 +01:00
ShowBg(0);
ShowBg(1);
ShowBg(2);
SetGpuReg(REG_OFFSET_BLDCNT, 0);
}
2021-08-03 08:17:01 +02:00
static bool8 LoadBagMenu_Graphics(void)
2018-01-30 19:19:37 +01:00
{
2020-05-14 10:37:09 +02:00
switch (gBagMenu->graphicsLoadState)
2018-01-30 19:19:37 +01:00
{
2021-08-03 08:17:01 +02:00
case 0:
ResetTempTileDataBuffers();
DecompressAndCopyTileDataToVram(2, gBagScreen_Gfx, 0, 0, 0);
gBagMenu->graphicsLoadState++;
break;
case 1:
if (FreeTempTileDataBuffersIfPossible() != TRUE)
{
LZDecompressWram(gBagScreen_GfxTileMap, gBagMenu->tilemapBuffer);
2020-05-14 10:37:09 +02:00
gBagMenu->graphicsLoadState++;
2021-08-03 08:17:01 +02:00
}
break;
case 2:
if (!IsWallysBag() && gSaveBlock2Ptr->playerGender != MALE)
2022-08-19 17:32:00 +02:00
LoadCompressedPalette(gBagScreenFemale_Pal, BG_PLTT_ID(0), 2 * PLTT_SIZE_4BPP);
2021-08-03 08:17:01 +02:00
else
2022-08-19 17:32:00 +02:00
LoadCompressedPalette(gBagScreenMale_Pal, BG_PLTT_ID(0), 2 * PLTT_SIZE_4BPP);
2021-08-03 08:17:01 +02:00
gBagMenu->graphicsLoadState++;
break;
case 3:
if (IsWallysBag() == TRUE || gSaveBlock2Ptr->playerGender == MALE)
LoadCompressedSpriteSheet(&gBagMaleSpriteSheet);
else
LoadCompressedSpriteSheet(&gBagFemaleSpriteSheet);
gBagMenu->graphicsLoadState++;
break;
case 4:
LoadCompressedSpritePalette(&gBagPaletteTable);
gBagMenu->graphicsLoadState++;
break;
default:
LoadListMenuSwapLineGfx();
gBagMenu->graphicsLoadState = 0;
return TRUE;
2018-01-30 19:19:37 +01:00
}
return FALSE;
}
2021-08-03 08:17:01 +02:00
static u8 CreateBagInputHandlerTask(u8 location)
2018-01-30 19:19:37 +01:00
{
u8 taskId;
2020-05-14 10:37:09 +02:00
if (location == ITEMMENULOCATION_WALLY)
2018-01-30 19:19:37 +01:00
taskId = CreateTask(Task_WallyTutorialBagMenu, 0);
else
2020-05-14 10:37:09 +02:00
taskId = CreateTask(Task_BagMenu_HandleInput, 0);
2018-01-30 19:19:37 +01:00
return taskId;
}
2021-08-03 08:17:01 +02:00
static void AllocateBagItemListBuffers(void)
2018-01-30 19:19:37 +01:00
{
2021-08-03 08:17:01 +02:00
sListBuffer1 = Alloc(sizeof(*sListBuffer1));
sListBuffer2 = Alloc(sizeof(*sListBuffer2));
2018-01-30 19:19:37 +01:00
}
2021-08-03 08:17:01 +02:00
static void LoadBagItemListBuffers(u8 pocketId)
2018-01-30 19:19:37 +01:00
{
u16 i;
struct BagPocket *pocket = &gBagPockets[pocketId];
struct ListMenuItem *subBuffer;
2018-02-14 01:12:17 +01:00
if (!gBagMenu->hideCloseBagText)
2018-01-30 19:19:37 +01:00
{
for (i = 0; i < gBagMenu->numItemStacks[pocketId] - 1; i++)
2018-01-30 19:19:37 +01:00
{
GetItemName(sListBuffer2->name[i], pocket->itemSlots[i].itemId);
2018-12-15 19:08:13 +01:00
subBuffer = sListBuffer1->subBuffers;
subBuffer[i].name = sListBuffer2->name[i];
2018-01-30 19:19:37 +01:00
subBuffer[i].id = i;
}
2018-12-15 19:08:13 +01:00
StringCopy(sListBuffer2->name[i], gText_CloseBag);
subBuffer = sListBuffer1->subBuffers;
subBuffer[i].name = sListBuffer2->name[i];
2020-05-14 10:37:09 +02:00
subBuffer[i].id = LIST_CANCEL;
2018-01-30 19:19:37 +01:00
}
else
{
for (i = 0; i < gBagMenu->numItemStacks[pocketId]; i++)
2018-01-30 19:19:37 +01:00
{
GetItemName(sListBuffer2->name[i], pocket->itemSlots[i].itemId);
2018-12-15 19:08:13 +01:00
subBuffer = sListBuffer1->subBuffers;
subBuffer[i].name = sListBuffer2->name[i];
2018-01-30 19:19:37 +01:00
subBuffer[i].id = i;
}
}
2018-12-15 19:08:13 +01:00
gMultiuseListMenuTemplate = sItemListMenu;
gMultiuseListMenuTemplate.totalItems = gBagMenu->numItemStacks[pocketId];
2018-12-15 19:08:13 +01:00
gMultiuseListMenuTemplate.items = sListBuffer1->subBuffers;
gMultiuseListMenuTemplate.maxShowed = gBagMenu->numShownItems[pocketId];
2018-01-30 19:19:37 +01:00
}
2021-08-03 08:17:01 +02:00
static void GetItemName(s8 *dest, u16 itemId)
2018-01-30 19:19:37 +01:00
{
2021-08-03 08:17:01 +02:00
switch (gBagPosition.pocket)
2018-01-30 19:19:37 +01:00
{
2021-08-03 08:17:01 +02:00
case TMHM_POCKET:
StringCopy(gStringVar2, gMoveNames[ItemIdToBattleMoveId(itemId)]);
if (itemId >= ITEM_HM01)
{
// Get HM number
ConvertIntToDecimalStringN(gStringVar1, itemId - ITEM_HM01 + 1, STR_CONV_MODE_LEADING_ZEROS, 1);
StringExpandPlaceholders(dest, gText_NumberItem_HM);
}
else
{
// Get TM number
ConvertIntToDecimalStringN(gStringVar1, itemId - ITEM_TM01 + 1, STR_CONV_MODE_LEADING_ZEROS, 2);
StringExpandPlaceholders(dest, gText_NumberItem_TMBerry);
}
break;
case BERRIES_POCKET:
ConvertIntToDecimalStringN(gStringVar1, itemId - FIRST_BERRY_INDEX + 1, STR_CONV_MODE_LEADING_ZEROS, 2);
CopyItemName(itemId, gStringVar2);
StringExpandPlaceholders(dest, gText_NumberItem_TMBerry);
break;
default:
CopyItemName(itemId, dest);
break;
2018-01-30 19:19:37 +01:00
}
}
2021-08-03 08:17:01 +02:00
static void BagMenu_MoveCursorCallback(s32 itemIndex, bool8 onInit, struct ListMenu *list)
2018-01-30 19:19:37 +01:00
{
2020-05-14 10:37:09 +02:00
if (onInit != TRUE)
2018-01-30 19:19:37 +01:00
{
PlaySE(SE_SELECT);
2020-05-14 10:37:09 +02:00
ShakeBagSprite();
2018-01-30 19:19:37 +01:00
}
2021-08-03 08:17:01 +02:00
if (gBagMenu->toSwapPos == NOT_SWAPPING)
2018-01-30 19:19:37 +01:00
{
2020-05-14 10:37:09 +02:00
RemoveBagItemIconSprite(gBagMenu->itemIconSlot ^ 1);
if (itemIndex != LIST_CANCEL)
2021-08-03 08:17:01 +02:00
AddBagItemIconSprite(BagGetItemIdByPocketPosition(gBagPosition.pocket + 1, itemIndex), gBagMenu->itemIconSlot);
2018-01-30 19:19:37 +01:00
else
2022-09-22 19:32:35 +02:00
AddBagItemIconSprite(ITEM_LIST_END, gBagMenu->itemIconSlot);
2020-05-14 10:37:09 +02:00
gBagMenu->itemIconSlot ^= 1;
if (!gBagMenu->inhibitItemDescriptionPrint)
2021-08-03 08:17:01 +02:00
PrintItemDescription(itemIndex);
2018-01-30 19:19:37 +01:00
}
}
2021-08-03 08:17:01 +02:00
static void BagMenu_ItemPrintCallback(u8 windowId, u32 itemIndex, u8 y)
2018-01-30 19:19:37 +01:00
{
u16 itemId;
u16 itemQuantity;
int offset;
2020-05-14 10:37:09 +02:00
if (itemIndex != LIST_CANCEL)
2018-01-30 19:19:37 +01:00
{
2021-08-03 08:17:01 +02:00
if (gBagMenu->toSwapPos != NOT_SWAPPING)
2018-01-30 19:19:37 +01:00
{
2021-08-03 08:17:01 +02:00
// Swapping items, draw cursor at original item's location
if (gBagMenu->toSwapPos == (u8)itemIndex)
BagMenu_PrintCursorAtPos(y, COLORID_GRAY_CURSOR);
2018-01-30 19:19:37 +01:00
else
2021-08-03 08:17:01 +02:00
BagMenu_PrintCursorAtPos(y, COLORID_NONE);
2018-01-30 19:19:37 +01:00
}
2020-05-14 10:37:09 +02:00
2021-08-03 08:17:01 +02:00
itemId = BagGetItemIdByPocketPosition(gBagPosition.pocket + 1, itemIndex);
itemQuantity = BagGetQuantityByPocketPosition(gBagPosition.pocket + 1, itemIndex);
2020-05-14 10:37:09 +02:00
2021-08-03 08:17:01 +02:00
// Draw HM icon
if (itemId >= ITEM_HM01 && itemId <= ITEM_HM08)
2020-05-14 10:37:09 +02:00
BlitBitmapToWindow(windowId, gBagMenuHMIcon_Gfx, 8, y - 1, 16, 16);
2021-08-03 08:17:01 +02:00
if (gBagPosition.pocket == BERRIES_POCKET)
2018-01-30 19:19:37 +01:00
{
2021-08-03 08:17:01 +02:00
// Print berry quantity
2020-09-25 17:18:52 +02:00
ConvertIntToDecimalStringN(gStringVar1, itemQuantity, STR_CONV_MODE_RIGHT_ALIGN, BERRY_CAPACITY_DIGITS);
2018-01-30 19:19:37 +01:00
StringExpandPlaceholders(gStringVar4, gText_xVar1);
2021-10-30 22:47:37 +02:00
offset = GetStringRightAlignXOffset(FONT_NARROW, gStringVar4, 119);
BagMenu_Print(windowId, FONT_NARROW, gStringVar4, offset, y, 0, 0, TEXT_SKIP_DRAW, COLORID_NORMAL);
2018-01-30 19:19:37 +01:00
}
2021-08-03 08:17:01 +02:00
else if (gBagPosition.pocket != KEYITEMS_POCKET && ItemId_GetImportance(itemId) == FALSE)
2018-01-30 19:19:37 +01:00
{
2021-08-03 08:17:01 +02:00
// Print item quantity
2020-09-25 17:18:52 +02:00
ConvertIntToDecimalStringN(gStringVar1, itemQuantity, STR_CONV_MODE_RIGHT_ALIGN, BAG_ITEM_CAPACITY_DIGITS);
2018-01-30 19:19:37 +01:00
StringExpandPlaceholders(gStringVar4, gText_xVar1);
2021-10-30 22:47:37 +02:00
offset = GetStringRightAlignXOffset(FONT_NARROW, gStringVar4, 119);
BagMenu_Print(windowId, FONT_NARROW, gStringVar4, offset, y, 0, 0, TEXT_SKIP_DRAW, COLORID_NORMAL);
2018-01-30 19:19:37 +01:00
}
else
{
2021-08-03 08:17:01 +02:00
// Print registered icon
if (gSaveBlock1Ptr->registeredItem != ITEM_NONE && gSaveBlock1Ptr->registeredItem == itemId)
2020-05-14 10:37:09 +02:00
BlitBitmapToWindow(windowId, sRegisteredSelect_Gfx, 96, y - 1, 24, 16);
2018-01-30 19:19:37 +01:00
}
}
}
2021-08-03 08:17:01 +02:00
static void PrintItemDescription(int itemIndex)
2018-01-30 19:19:37 +01:00
{
const u8 *str;
2020-05-14 10:37:09 +02:00
if (itemIndex != LIST_CANCEL)
2018-02-09 03:00:28 +01:00
{
2021-08-03 08:17:01 +02:00
str = ItemId_GetDescription(BagGetItemIdByPocketPosition(gBagPosition.pocket + 1, itemIndex));
2018-02-09 03:00:28 +01:00
}
2018-01-30 19:19:37 +01:00
else
{
2021-08-03 08:17:01 +02:00
// Print 'Cancel' description
StringCopy(gStringVar1, gBagMenu_ReturnToStrings[gBagPosition.location]);
2018-02-09 03:00:28 +01:00
StringExpandPlaceholders(gStringVar4, gText_ReturnToVar1);
2018-01-30 19:19:37 +01:00
str = gStringVar4;
}
2021-08-03 08:17:01 +02:00
FillWindowPixelBuffer(WIN_DESCRIPTION, PIXEL_FILL(0));
2021-10-30 22:47:37 +02:00
BagMenu_Print(WIN_DESCRIPTION, FONT_NORMAL, str, 3, 1, 0, 0, 0, COLORID_NORMAL);
2018-01-30 19:19:37 +01:00
}
2021-08-03 08:17:01 +02:00
static void BagMenu_PrintCursor(u8 listTaskId, u8 colorIndex)
2018-01-30 19:19:37 +01:00
{
2021-08-03 08:17:01 +02:00
BagMenu_PrintCursorAtPos(ListMenuGetYCoordForPrintingArrowCursor(listTaskId), colorIndex);
2018-01-30 19:19:37 +01:00
}
2021-08-03 08:17:01 +02:00
static void BagMenu_PrintCursorAtPos(u8 y, u8 colorIndex)
2018-01-30 19:19:37 +01:00
{
2021-08-03 08:17:01 +02:00
if (colorIndex == COLORID_NONE)
2021-10-30 22:47:37 +02:00
FillWindowPixelRect(WIN_ITEM_LIST, PIXEL_FILL(0), 0, y, GetMenuCursorDimensionByFont(FONT_NORMAL, 0), GetMenuCursorDimensionByFont(FONT_NORMAL, 1));
2018-01-30 19:19:37 +01:00
else
2021-10-30 22:47:37 +02:00
BagMenu_Print(WIN_ITEM_LIST, FONT_NORMAL, gText_SelectorArrow2, 0, y, 0, 0, 0, colorIndex);
2018-01-30 19:19:37 +01:00
}
2021-08-03 08:17:01 +02:00
static void CreatePocketScrollArrowPair(void)
2018-01-30 19:19:37 +01:00
{
2021-02-20 05:22:26 +01:00
if (gBagMenu->pocketScrollArrowsTask == TASK_NONE)
2020-05-14 10:37:09 +02:00
gBagMenu->pocketScrollArrowsTask = AddScrollIndicatorArrowPairParameterized(
SCROLL_ARROW_UP,
172,
12,
148,
2021-08-03 08:17:01 +02:00
gBagMenu->numItemStacks[gBagPosition.pocket] - gBagMenu->numShownItems[gBagPosition.pocket],
TAG_POCKET_SCROLL_ARROW,
TAG_POCKET_SCROLL_ARROW,
&gBagPosition.scrollPosition[gBagPosition.pocket]);
2018-01-30 19:19:37 +01:00
}
2020-05-14 10:37:09 +02:00
void BagDestroyPocketScrollArrowPair(void)
2018-01-30 19:19:37 +01:00
{
2021-02-20 05:22:26 +01:00
if (gBagMenu->pocketScrollArrowsTask != TASK_NONE)
2018-01-30 19:19:37 +01:00
{
2020-05-14 10:37:09 +02:00
RemoveScrollIndicatorArrowPair(gBagMenu->pocketScrollArrowsTask);
2021-02-20 05:22:26 +01:00
gBagMenu->pocketScrollArrowsTask = TASK_NONE;
2018-01-30 19:19:37 +01:00
}
2021-08-03 08:17:01 +02:00
DestroyPocketSwitchArrowPair();
2018-01-30 19:19:37 +01:00
}
2021-08-03 08:17:01 +02:00
static void CreatePocketSwitchArrowPair(void)
2018-01-30 19:19:37 +01:00
{
2021-02-20 05:22:26 +01:00
if (gBagMenu->pocketSwitchDisabled != TRUE && gBagMenu->pocketSwitchArrowsTask == TASK_NONE)
2021-08-03 08:17:01 +02:00
gBagMenu->pocketSwitchArrowsTask = AddScrollIndicatorArrowPair(&sBagScrollArrowsTemplate, &gBagPosition.pocketSwitchArrowPos);
2018-01-30 19:19:37 +01:00
}
2021-08-03 08:17:01 +02:00
static void DestroyPocketSwitchArrowPair(void)
2018-01-30 19:19:37 +01:00
{
2021-02-20 05:22:26 +01:00
if (gBagMenu->pocketSwitchArrowsTask != TASK_NONE)
2018-01-30 19:19:37 +01:00
{
2020-05-14 10:37:09 +02:00
RemoveScrollIndicatorArrowPair(gBagMenu->pocketSwitchArrowsTask);
2021-02-20 05:22:26 +01:00
gBagMenu->pocketSwitchArrowsTask = TASK_NONE;
2018-01-30 19:19:37 +01:00
}
}
2021-08-03 08:17:01 +02:00
static void FreeBagMenu(void)
2018-01-30 19:19:37 +01:00
{
2018-12-15 19:08:13 +01:00
Free(sListBuffer2);
Free(sListBuffer1);
2018-01-30 19:19:37 +01:00
FreeAllWindowBuffers();
Free(gBagMenu);
2018-01-30 19:19:37 +01:00
}
void Task_FadeAndCloseBagMenu(u8 taskId)
2018-01-30 19:19:37 +01:00
{
2021-02-24 17:01:02 +01:00
BeginNormalPaletteFade(PALETTES_ALL, 0, 0, 16, RGB_BLACK);
2021-08-03 08:17:01 +02:00
gTasks[taskId].func = Task_CloseBagMenu;
2018-01-30 19:19:37 +01:00
}
2021-08-03 08:17:01 +02:00
static void Task_CloseBagMenu(u8 taskId)
2018-01-30 19:19:37 +01:00
{
s16 *data = gTasks[taskId].data;
2018-01-30 19:19:37 +01:00
if (!gPaletteFade.active)
{
2021-08-03 08:17:01 +02:00
DestroyListMenuTask(tListTaskId, &gBagPosition.scrollPosition[gBagPosition.pocket], &gBagPosition.cursorPosition[gBagPosition.pocket]);
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 (gBagMenu->newScreenCallback != NULL)
SetMainCallback2(gBagMenu->newScreenCallback);
2018-01-30 19:19:37 +01:00
else
2021-08-03 08:17:01 +02:00
SetMainCallback2(gBagPosition.exitCallback);
2020-05-14 10:37:09 +02:00
BagDestroyPocketScrollArrowPair();
2018-01-30 19:19:37 +01:00
ResetSpriteData();
FreeAllSpritePalettes();
2021-08-03 08:17:01 +02:00
FreeBagMenu();
2018-01-30 19:19:37 +01:00
DestroyTask(taskId);
}
}
void UpdatePocketItemList(u8 pocketId)
2018-01-30 19:19:37 +01:00
{
u16 i;
struct BagPocket *pocket = &gBagPockets[pocketId];
switch (pocketId)
{
2021-08-03 08:17:01 +02:00
case TMHM_POCKET:
case BERRIES_POCKET:
SortBerriesOrTMHMs(pocket);
break;
default:
CompactItemsInBagPocket(pocket);
break;
2018-01-30 19:19:37 +01:00
}
2020-05-14 10:37:09 +02:00
gBagMenu->numItemStacks[pocketId] = 0;
2020-05-14 10:37:09 +02:00
2018-01-30 19:19:37 +01:00
for (i = 0; i < pocket->capacity && pocket->itemSlots[i].itemId; i++)
gBagMenu->numItemStacks[pocketId]++;
2018-12-15 19:08:13 +01:00
if (!gBagMenu->hideCloseBagText)
gBagMenu->numItemStacks[pocketId]++;
2018-12-15 19:08:13 +01:00
2021-08-03 08:17:01 +02:00
if (gBagMenu->numItemStacks[pocketId] > MAX_ITEMS_SHOWN)
gBagMenu->numShownItems[pocketId] = MAX_ITEMS_SHOWN;
2018-01-30 19:19:37 +01:00
else
gBagMenu->numShownItems[pocketId] = gBagMenu->numItemStacks[pocketId];
2018-01-30 19:19:37 +01:00
}
2021-08-03 08:17:01 +02:00
static void UpdatePocketItemLists(void)
2018-01-30 19:19:37 +01:00
{
u8 i;
2018-12-10 10:32:00 +01:00
for (i = 0; i < POCKETS_COUNT; i++)
UpdatePocketItemList(i);
2018-01-30 19:19:37 +01:00
}
2021-08-03 08:17:01 +02:00
void UpdatePocketListPosition(u8 pocketId)
2018-01-30 19:19:37 +01:00
{
SetCursorWithinListBounds(&gBagPosition.scrollPosition[pocketId], &gBagPosition.cursorPosition[pocketId], gBagMenu->numShownItems[pocketId], gBagMenu->numItemStacks[pocketId]);
2018-01-30 19:19:37 +01:00
}
2021-08-03 08:17:01 +02:00
static void InitPocketListPositions(void)
2018-01-30 19:19:37 +01:00
{
u8 i;
2018-12-10 10:32:00 +01:00
for (i = 0; i < POCKETS_COUNT; i++)
2021-08-03 08:17:01 +02:00
UpdatePocketListPosition(i);
2018-01-30 19:19:37 +01:00
}
2021-08-03 08:17:01 +02:00
static void InitPocketScrollPositions(void)
2018-01-30 19:19:37 +01:00
{
u8 i;
2018-12-10 10:32:00 +01:00
for (i = 0; i < POCKETS_COUNT; i++)
2021-08-03 08:17:01 +02:00
SetCursorScrollWithinListBounds(&gBagPosition.scrollPosition[i], &gBagPosition.cursorPosition[i], gBagMenu->numShownItems[i], gBagMenu->numItemStacks[i], MAX_ITEMS_SHOWN);
2018-01-30 19:19:37 +01:00
}
2018-12-15 19:08:13 +01:00
u8 GetItemListPosition(u8 pocketId)
2018-01-30 19:19:37 +01:00
{
2021-08-03 08:17:01 +02:00
return gBagPosition.scrollPosition[pocketId] + gBagPosition.cursorPosition[pocketId];
2018-01-30 19:19:37 +01:00
}
2020-05-14 10:37:09 +02:00
void DisplayItemMessage(u8 taskId, u8 fontId, const u8 *str, void (*callback)(u8 taskId))
2018-01-30 19:19:37 +01:00
{
s16 *data = gTasks[taskId].data;
2018-02-14 01:12:17 +01:00
2021-08-03 08:17:01 +02:00
tMsgWindowId = AddItemMessageWindow(ITEMWIN_MESSAGE);
FillWindowPixelBuffer(tMsgWindowId, PIXEL_FILL(1));
DisplayMessageAndContinueTask(taskId, tMsgWindowId, 10, 13, fontId, GetPlayerTextSpeedDelay(), str, callback);
2020-05-14 10:37:09 +02:00
ScheduleBgCopyTilemapToVram(1);
2018-01-30 19:19:37 +01:00
}
2021-08-03 08:17:01 +02:00
void CloseItemMessage(u8 taskId)
2018-01-30 19:19:37 +01:00
{
s16 *data = gTasks[taskId].data;
u16 *scrollPos = &gBagPosition.scrollPosition[gBagPosition.pocket];
u16 *cursorPos = &gBagPosition.cursorPosition[gBagPosition.pocket];
2021-08-03 08:17:01 +02:00
RemoveItemMessageWindow(ITEMWIN_MESSAGE);
DestroyListMenuTask(tListTaskId, scrollPos, cursorPos);
UpdatePocketItemList(gBagPosition.pocket);
UpdatePocketListPosition(gBagPosition.pocket);
LoadBagItemListBuffers(gBagPosition.pocket);
tListTaskId = ListMenuInit(&gMultiuseListMenuTemplate, *scrollPos, *cursorPos);
2020-05-14 10:37:09 +02:00
ScheduleBgCopyTilemapToVram(0);
2021-08-03 08:17:01 +02:00
ReturnToItemList(taskId);
2018-01-30 19:19:37 +01:00
}
2021-08-03 08:17:01 +02:00
static void AddItemQuantityWindow(u8 windowType)
2018-01-30 19:19:37 +01:00
{
2021-08-03 08:17:01 +02:00
PrintItemQuantity(BagMenu_AddWindow(windowType), 1);
2018-01-30 19:19:37 +01:00
}
2021-08-03 08:17:01 +02:00
static void PrintItemQuantity(u8 windowId, s16 quantity)
2018-01-30 19:19:37 +01:00
{
2021-08-03 08:17:01 +02:00
u8 numDigits = (gBagPosition.pocket == BERRIES_POCKET) ? BERRY_CAPACITY_DIGITS : BAG_ITEM_CAPACITY_DIGITS;
ConvertIntToDecimalStringN(gStringVar1, quantity, STR_CONV_MODE_LEADING_ZEROS, numDigits);
2018-01-30 19:19:37 +01:00
StringExpandPlaceholders(gStringVar4, gText_xVar1);
2021-10-30 22:47:37 +02:00
AddTextPrinterParameterized(windowId, FONT_NORMAL, gStringVar4, GetStringCenterAlignXOffset(FONT_NORMAL, gStringVar4, 0x28), 2, 0, 0);
2018-01-30 19:19:37 +01:00
}
2021-08-03 08:17:01 +02:00
// Prints the quantity of items to be sold and the amount that would be earned
static void PrintItemSoldAmount(int windowId, int numSold, int moneyEarned)
2018-01-30 19:19:37 +01:00
{
2021-08-03 08:17:01 +02:00
u8 numDigits = (gBagPosition.pocket == BERRIES_POCKET) ? BERRY_CAPACITY_DIGITS : BAG_ITEM_CAPACITY_DIGITS;
2019-09-30 21:53:24 +02:00
ConvertIntToDecimalStringN(gStringVar1, numSold, STR_CONV_MODE_LEADING_ZEROS, numDigits);
2018-01-30 19:19:37 +01:00
StringExpandPlaceholders(gStringVar4, gText_xVar1);
AddTextPrinterParameterized(windowId, FONT_NORMAL, gStringVar4, 0, 1, TEXT_SKIP_DRAW, 0);
2019-09-30 21:53:24 +02:00
PrintMoneyAmount(windowId, 38, 1, moneyEarned, 0);
2018-01-30 19:19:37 +01:00
}
2021-08-03 08:17:01 +02:00
static void Task_BagMenu_HandleInput(u8 taskId)
2018-01-30 19:19:37 +01:00
{
s16 *data = gTasks[taskId].data;
u16 *scrollPos = &gBagPosition.scrollPosition[gBagPosition.pocket];
u16 *cursorPos = &gBagPosition.cursorPosition[gBagPosition.pocket];
2020-05-14 10:37:09 +02:00
s32 listPosition;
if (MenuHelpers_ShouldWaitForLinkRecv() != TRUE && !gPaletteFade.active)
2018-01-30 19:19:37 +01:00
{
switch (GetSwitchBagPocketDirection())
{
2021-08-03 08:17:01 +02:00
case SWITCH_POCKET_LEFT:
SwitchBagPocket(taskId, MENU_CURSOR_DELTA_LEFT, FALSE);
return;
case SWITCH_POCKET_RIGHT:
SwitchBagPocket(taskId, MENU_CURSOR_DELTA_RIGHT, FALSE);
return;
default:
if (JOY_NEW(SELECT_BUTTON))
{
if (CanSwapItems() == TRUE)
2018-01-30 19:19:37 +01:00
{
2021-08-03 08:17:01 +02:00
ListMenuGetScrollAndRow(tListTaskId, scrollPos, cursorPos);
if ((*scrollPos + *cursorPos) != gBagMenu->numItemStacks[gBagPosition.pocket] - 1)
2020-05-14 10:37:09 +02:00
{
2021-08-03 08:17:01 +02:00
PlaySE(SE_SELECT);
StartItemSwap(taskId);
2020-05-14 10:37:09 +02:00
}
2018-01-30 19:19:37 +01:00
}
2021-08-03 08:17:01 +02:00
return;
}
break;
2018-01-30 19:19:37 +01:00
}
2020-05-14 10:37:09 +02:00
2021-08-03 08:17:01 +02:00
listPosition = ListMenu_ProcessInput(tListTaskId);
ListMenuGetScrollAndRow(tListTaskId, scrollPos, cursorPos);
2020-05-14 10:37:09 +02:00
switch (listPosition)
2018-01-30 19:19:37 +01:00
{
2021-08-03 08:17:01 +02:00
case LIST_NOTHING_CHOSEN:
break;
case LIST_CANCEL:
if (gBagPosition.location == ITEMMENULOCATION_BERRY_BLENDER_CRUSH)
{
PlaySE(SE_FAILURE);
2020-05-14 10:37:09 +02:00
break;
2021-08-03 08:17:01 +02:00
}
PlaySE(SE_SELECT);
gSpecialVar_ItemId = ITEM_NONE;
gTasks[taskId].func = Task_FadeAndCloseBagMenu;
break;
default: // A_BUTTON
PlaySE(SE_SELECT);
BagDestroyPocketScrollArrowPair();
BagMenu_PrintCursor(tListTaskId, COLORID_GRAY_CURSOR);
tListPosition = listPosition;
tQuantity = BagGetQuantityByPocketPosition(gBagPosition.pocket + 1, listPosition);
gSpecialVar_ItemId = BagGetItemIdByPocketPosition(gBagPosition.pocket + 1, listPosition);
sContextMenuFuncs[gBagPosition.location](taskId);
break;
2018-01-30 19:19:37 +01:00
}
}
2018-01-30 22:12:40 +01:00
}
2021-08-03 08:17:01 +02:00
static void ReturnToItemList(u8 taskId)
2018-01-30 22:12:40 +01:00
{
2020-05-14 10:37:09 +02:00
CreatePocketScrollArrowPair();
CreatePocketSwitchArrowPair();
2021-08-03 08:17:01 +02:00
ClearWindowTilemap(WIN_TMHM_INFO_ICONS);
ClearWindowTilemap(WIN_TMHM_INFO);
PutWindowTilemap(WIN_DESCRIPTION);
2020-05-14 10:37:09 +02:00
ScheduleBgCopyTilemapToVram(0);
gTasks[taskId].func = Task_BagMenu_HandleInput;
2018-01-30 22:12:40 +01:00
}
2018-02-01 02:22:51 +01:00
2020-08-28 19:31:58 +02:00
static u8 GetSwitchBagPocketDirection(void)
2018-02-01 02:22:51 +01:00
{
u8 LRKeys;
2020-05-14 10:37:09 +02:00
if (gBagMenu->pocketSwitchDisabled)
2020-08-28 19:31:58 +02:00
return SWITCH_POCKET_NONE;
2019-10-18 01:22:03 +02:00
LRKeys = GetLRKeysPressed();
2021-08-03 08:17:01 +02:00
if (JOY_NEW(DPAD_LEFT) || LRKeys == MENU_L_PRESSED)
2018-02-01 02:22:51 +01:00
{
PlaySE(SE_SELECT);
2020-08-28 19:31:58 +02:00
return SWITCH_POCKET_LEFT;
2018-02-01 02:22:51 +01:00
}
2021-08-03 08:17:01 +02:00
if (JOY_NEW(DPAD_RIGHT) || LRKeys == MENU_R_PRESSED)
2018-02-01 02:22:51 +01:00
{
PlaySE(SE_SELECT);
2020-08-28 19:31:58 +02:00
return SWITCH_POCKET_RIGHT;
2018-02-01 02:22:51 +01:00
}
2020-08-28 19:31:58 +02:00
return SWITCH_POCKET_NONE;
2018-02-01 02:22:51 +01:00
}
2020-08-28 19:31:58 +02:00
static void ChangeBagPocketId(u8 *bagPocketId, s8 deltaBagPocketId)
2018-02-01 02:22:51 +01:00
{
2021-08-03 08:17:01 +02:00
if (deltaBagPocketId == MENU_CURSOR_DELTA_RIGHT && *bagPocketId == POCKETS_COUNT - 1)
2018-02-01 02:22:51 +01:00
*bagPocketId = 0;
2021-08-03 08:17:01 +02:00
else if (deltaBagPocketId == MENU_CURSOR_DELTA_LEFT && *bagPocketId == 0)
2018-12-10 10:32:00 +01:00
*bagPocketId = POCKETS_COUNT - 1;
2018-02-01 02:22:51 +01:00
else
*bagPocketId += deltaBagPocketId;
}
2021-08-03 08:17:01 +02:00
static void SwitchBagPocket(u8 taskId, s16 deltaBagPocketId, bool16 skipEraseList)
2018-02-01 02:22:51 +01:00
{
s16 *data = gTasks[taskId].data;
2021-08-03 08:17:01 +02:00
u8 newPocket;
2018-02-01 02:22:51 +01:00
2021-08-03 08:17:01 +02:00
tPocketSwitchState = 0;
tPocketSwitchTimer = 0;
tPocketSwitchDir = deltaBagPocketId;
if (!skipEraseList)
2018-02-01 02:22:51 +01:00
{
2021-08-03 08:17:01 +02:00
ClearWindowTilemap(WIN_ITEM_LIST);
ClearWindowTilemap(WIN_DESCRIPTION);
DestroyListMenuTask(tListTaskId, &gBagPosition.scrollPosition[gBagPosition.pocket], &gBagPosition.cursorPosition[gBagPosition.pocket]);
2020-05-14 10:37:09 +02:00
ScheduleBgCopyTilemapToVram(0);
2021-08-03 08:17:01 +02:00
gSprites[gBagMenu->spriteIds[ITEMMENUSPRITE_ITEM + (gBagMenu->itemIconSlot ^ 1)]].invisible = TRUE;
2020-05-14 10:37:09 +02:00
BagDestroyPocketScrollArrowPair();
2018-02-01 02:22:51 +01:00
}
2021-08-03 08:17:01 +02:00
newPocket = gBagPosition.pocket;
ChangeBagPocketId(&newPocket, deltaBagPocketId);
2020-08-28 19:31:58 +02:00
if (deltaBagPocketId == MENU_CURSOR_DELTA_RIGHT)
2018-02-01 02:22:51 +01:00
{
2021-08-03 08:17:01 +02:00
PrintPocketNames(gPocketNamesStringsTable[gBagPosition.pocket], gPocketNamesStringsTable[newPocket]);
CopyPocketNameToWindow(0);
2018-02-01 02:22:51 +01:00
}
else
{
2021-08-03 08:17:01 +02:00
PrintPocketNames(gPocketNamesStringsTable[newPocket], gPocketNamesStringsTable[gBagPosition.pocket]);
CopyPocketNameToWindow(8);
2018-02-01 02:22:51 +01:00
}
2021-08-03 08:17:01 +02:00
DrawPocketIndicatorSquare(gBagPosition.pocket, FALSE);
DrawPocketIndicatorSquare(newPocket, TRUE);
2018-02-01 02:22:51 +01:00
FillBgTilemapBufferRect_Palette0(2, 11, 14, 2, 15, 16);
2020-05-14 10:37:09 +02:00
ScheduleBgCopyTilemapToVram(2);
2022-05-27 02:18:52 +02:00
SetBagVisualPocketId(newPocket, TRUE);
2021-08-03 08:17:01 +02:00
RemoveBagSprite(ITEMMENUSPRITE_BALL);
2018-03-04 18:41:07 +01:00
AddSwitchPocketRotatingBallSprite(deltaBagPocketId);
2021-08-03 08:17:01 +02:00
SetTaskFuncWithFollowupFunc(taskId, Task_SwitchBagPocket, gTasks[taskId].func);
2018-02-01 02:22:51 +01:00
}
2021-08-03 08:17:01 +02:00
static void Task_SwitchBagPocket(u8 taskId)
2018-02-01 02:22:51 +01:00
{
s16 *data = gTasks[taskId].data;
2018-02-14 01:12:17 +01:00
if (!MenuHelpers_IsLinkActive() && !IsWallysBag())
2018-02-01 02:22:51 +01:00
{
switch (GetSwitchBagPocketDirection())
{
2021-08-03 08:17:01 +02:00
case SWITCH_POCKET_LEFT:
ChangeBagPocketId(&gBagPosition.pocket, tPocketSwitchDir);
SwitchTaskToFollowupFunc(taskId);
SwitchBagPocket(taskId, MENU_CURSOR_DELTA_LEFT, TRUE);
return;
case SWITCH_POCKET_RIGHT:
ChangeBagPocketId(&gBagPosition.pocket, tPocketSwitchDir);
SwitchTaskToFollowupFunc(taskId);
SwitchBagPocket(taskId, MENU_CURSOR_DELTA_RIGHT, TRUE);
return;
2018-02-01 02:22:51 +01:00
}
}
2021-08-03 08:17:01 +02:00
switch (tPocketSwitchState)
2018-02-01 02:22:51 +01:00
{
2021-08-03 08:17:01 +02:00
case 0:
DrawItemListBgRow(tPocketSwitchTimer);
if (!(++tPocketSwitchTimer & 1))
{
if (tPocketSwitchDir == MENU_CURSOR_DELTA_RIGHT)
CopyPocketNameToWindow((u8)(tPocketSwitchTimer >> 1));
else
CopyPocketNameToWindow((u8)(8 - (tPocketSwitchTimer >> 1)));
}
if (tPocketSwitchTimer == 16)
tPocketSwitchState++;
break;
case 1:
ChangeBagPocketId(&gBagPosition.pocket, tPocketSwitchDir);
LoadBagItemListBuffers(gBagPosition.pocket);
tListTaskId = ListMenuInit(&gMultiuseListMenuTemplate, gBagPosition.scrollPosition[gBagPosition.pocket], gBagPosition.cursorPosition[gBagPosition.pocket]);
PutWindowTilemap(WIN_DESCRIPTION);
PutWindowTilemap(WIN_POCKET_NAME);
ScheduleBgCopyTilemapToVram(0);
CreatePocketScrollArrowPair();
CreatePocketSwitchArrowPair();
SwitchTaskToFollowupFunc(taskId);
2018-02-01 02:22:51 +01:00
}
}
2018-02-05 05:47:47 +01:00
2021-08-03 08:17:01 +02:00
// The background of the item list is a lighter color than the surrounding menu
// When the pocket is switched this lighter background is redrawn row by row
static void DrawItemListBgRow(u8 y)
2018-02-05 05:47:47 +01:00
{
2021-08-03 08:17:01 +02:00
FillBgTilemapBufferRect_Palette0(2, 17, 14, y + 2, 15, 1);
2020-05-14 10:37:09 +02:00
ScheduleBgCopyTilemapToVram(2);
2018-02-05 05:47:47 +01:00
}
2020-08-28 19:31:58 +02:00
static void DrawPocketIndicatorSquare(u8 x, bool8 isCurrentPocket)
2018-02-05 05:47:47 +01:00
{
2020-08-28 19:31:58 +02:00
if (!isCurrentPocket)
2018-02-05 05:47:47 +01:00
FillBgTilemapBufferRect_Palette0(2, 0x1017, x + 5, 3, 1, 1);
else
FillBgTilemapBufferRect_Palette0(2, 0x102B, x + 5, 3, 1, 1);
2020-05-14 10:37:09 +02:00
ScheduleBgCopyTilemapToVram(2);
2018-02-05 05:47:47 +01:00
}
2020-08-28 19:31:58 +02:00
static bool8 CanSwapItems(void)
2018-02-05 05:47:47 +01:00
{
2021-08-03 08:17:01 +02:00
// Swaps can only be done from the field or in battle (as opposed to while selling items, for example)
if (gBagPosition.location == ITEMMENULOCATION_FIELD
2021-08-03 08:17:01 +02:00
|| gBagPosition.location == ITEMMENULOCATION_BATTLE)
2018-02-05 05:47:47 +01:00
{
2021-08-03 08:17:01 +02:00
// TMHMs and berries are numbered, and so may not be swapped
if (gBagPosition.pocket != TMHM_POCKET
2021-08-03 08:17:01 +02:00
&& gBagPosition.pocket != BERRIES_POCKET)
2018-02-05 05:47:47 +01:00
return TRUE;
}
return FALSE;
}
2021-08-03 08:17:01 +02:00
static void StartItemSwap(u8 taskId)
2018-02-05 05:47:47 +01:00
{
s16 *data = gTasks[taskId].data;
2018-02-14 01:12:17 +01:00
2021-08-03 08:17:01 +02:00
ListMenuSetUnkIndicatorsStructField(tListTaskId, 16, 1);
tListPosition = gBagPosition.scrollPosition[gBagPosition.pocket] + gBagPosition.cursorPosition[gBagPosition.pocket];
gBagMenu->toSwapPos = tListPosition;
CopyItemName(BagGetItemIdByPocketPosition(gBagPosition.pocket + 1, tListPosition), gStringVar1);
2018-02-05 05:47:47 +01:00
StringExpandPlaceholders(gStringVar4, gText_MoveVar1Where);
2021-08-03 08:17:01 +02:00
FillWindowPixelBuffer(WIN_DESCRIPTION, PIXEL_FILL(0));
2021-10-30 22:47:37 +02:00
BagMenu_Print(WIN_DESCRIPTION, FONT_NORMAL, gStringVar4, 3, 1, 0, 0, 0, COLORID_NORMAL);
2021-08-03 08:17:01 +02:00
UpdateItemMenuSwapLinePos(tListPosition);
DestroyPocketSwitchArrowPair();
BagMenu_PrintCursor(tListTaskId, COLORID_GRAY_CURSOR);
2020-08-28 19:31:58 +02:00
gTasks[taskId].func = Task_HandleSwappingItemsInput;
2018-02-05 05:47:47 +01:00
}
2020-08-28 19:31:58 +02:00
static void Task_HandleSwappingItemsInput(u8 taskId)
2018-02-05 05:47:47 +01:00
{
s16 *data = gTasks[taskId].data;
2018-02-14 01:12:17 +01:00
if (MenuHelpers_ShouldWaitForLinkRecv() != TRUE)
2018-02-05 05:47:47 +01:00
{
2020-09-05 03:11:55 +02:00
if (JOY_NEW(SELECT_BUTTON))
2018-02-05 05:47:47 +01:00
{
PlaySE(SE_SELECT);
2021-08-03 08:17:01 +02:00
ListMenuGetScrollAndRow(tListTaskId, &gBagPosition.scrollPosition[gBagPosition.pocket], &gBagPosition.cursorPosition[gBagPosition.pocket]);
DoItemSwap(taskId);
2018-02-05 05:47:47 +01:00
}
else
{
2021-08-03 08:17:01 +02:00
s32 input = ListMenu_ProcessInput(tListTaskId);
ListMenuGetScrollAndRow(tListTaskId, &gBagPosition.scrollPosition[gBagPosition.pocket], &gBagPosition.cursorPosition[gBagPosition.pocket]);
2021-04-11 22:23:10 +02:00
SetItemMenuSwapLineInvisibility(FALSE);
2021-08-03 08:17:01 +02:00
UpdateItemMenuSwapLinePos(gBagPosition.cursorPosition[gBagPosition.pocket]);
2019-02-02 11:04:38 +01:00
switch (input)
2018-02-05 05:47:47 +01:00
{
2021-08-03 08:17:01 +02:00
case LIST_NOTHING_CHOSEN:
break;
case LIST_CANCEL:
PlaySE(SE_SELECT);
if (JOY_NEW(A_BUTTON))
DoItemSwap(taskId);
else
CancelItemSwap(taskId);
break;
default:
PlaySE(SE_SELECT);
DoItemSwap(taskId);
break;
2018-02-05 05:47:47 +01:00
}
}
}
}
2021-08-03 08:17:01 +02:00
static void DoItemSwap(u8 taskId)
2018-02-05 05:47:47 +01:00
{
s16 *data = gTasks[taskId].data;
u16 *scrollPos = &gBagPosition.scrollPosition[gBagPosition.pocket];
u16 *cursorPos = &gBagPosition.cursorPosition[gBagPosition.pocket];
2018-02-09 03:00:28 +01:00
u16 realPos = (*scrollPos + *cursorPos);
2018-02-14 01:12:17 +01:00
2021-08-03 08:17:01 +02:00
if (tListPosition == realPos || tListPosition == realPos - 1)
{
// Position is the same as the original, cancel
CancelItemSwap(taskId);
}
2018-02-05 05:47:47 +01:00
else
{
2021-08-03 08:17:01 +02:00
MoveItemSlotInList(gBagPockets[gBagPosition.pocket].itemSlots, tListPosition, realPos);
gBagMenu->toSwapPos = NOT_SWAPPING;
DestroyListMenuTask(tListTaskId, scrollPos, cursorPos);
if (tListPosition < realPos)
gBagPosition.cursorPosition[gBagPosition.pocket]--;
LoadBagItemListBuffers(gBagPosition.pocket);
tListTaskId = ListMenuInit(&gMultiuseListMenuTemplate, *scrollPos, *cursorPos);
2021-04-11 22:23:10 +02:00
SetItemMenuSwapLineInvisibility(TRUE);
2020-05-14 10:37:09 +02:00
CreatePocketSwitchArrowPair();
gTasks[taskId].func = Task_BagMenu_HandleInput;
2018-02-05 05:47:47 +01:00
}
}
2021-08-03 08:17:01 +02:00
static void CancelItemSwap(u8 taskId)
2018-02-05 05:47:47 +01:00
{
s16 *data = gTasks[taskId].data;
u16 *scrollPos = &gBagPosition.scrollPosition[gBagPosition.pocket];
u16 *cursorPos = &gBagPosition.cursorPosition[gBagPosition.pocket];
2021-08-03 08:17:01 +02:00
gBagMenu->toSwapPos = NOT_SWAPPING;
DestroyListMenuTask(tListTaskId, scrollPos, cursorPos);
if (tListPosition < *scrollPos + *cursorPos)
gBagPosition.cursorPosition[gBagPosition.pocket]--;
LoadBagItemListBuffers(gBagPosition.pocket);
tListTaskId = ListMenuInit(&gMultiuseListMenuTemplate, *scrollPos, *cursorPos);
2021-04-11 22:23:10 +02:00
SetItemMenuSwapLineInvisibility(TRUE);
2020-05-14 10:37:09 +02:00
CreatePocketSwitchArrowPair();
gTasks[taskId].func = Task_BagMenu_HandleInput;
2018-02-05 05:47:47 +01:00
}
2021-08-03 08:17:01 +02:00
static void OpenContextMenu(u8 taskId)
2018-02-05 05:47:47 +01:00
{
2021-08-03 08:17:01 +02:00
switch (gBagPosition.location)
2018-02-05 05:47:47 +01:00
{
2021-08-03 08:17:01 +02:00
case ITEMMENULOCATION_BATTLE:
case ITEMMENULOCATION_WALLY:
if (ItemId_GetBattleUsage(gSpecialVar_ItemId))
{
gBagMenu->contextMenuItemsPtr = sContextMenuItems_BattleUse;
gBagMenu->contextMenuNumItems = ARRAY_COUNT(sContextMenuItems_BattleUse);
}
else
{
gBagMenu->contextMenuItemsPtr = sContextMenuItems_Cancel;
gBagMenu->contextMenuNumItems = ARRAY_COUNT(sContextMenuItems_Cancel);
}
break;
case ITEMMENULOCATION_BERRY_BLENDER_CRUSH:
gBagMenu->contextMenuItemsPtr = sContextMenuItems_BerryBlenderCrush;
gBagMenu->contextMenuNumItems = ARRAY_COUNT(sContextMenuItems_BerryBlenderCrush);
break;
case ITEMMENULOCATION_APPRENTICE:
if (!ItemId_GetImportance(gSpecialVar_ItemId) && gSpecialVar_ItemId != ITEM_ENIGMA_BERRY_E_READER)
2021-08-03 08:17:01 +02:00
{
gBagMenu->contextMenuItemsPtr = sContextMenuItems_Apprentice;
gBagMenu->contextMenuNumItems = ARRAY_COUNT(sContextMenuItems_Apprentice);
}
else
{
gBagMenu->contextMenuItemsPtr = sContextMenuItems_Cancel;
gBagMenu->contextMenuNumItems = ARRAY_COUNT(sContextMenuItems_Cancel);
}
break;
case ITEMMENULOCATION_FAVOR_LADY:
if (!ItemId_GetImportance(gSpecialVar_ItemId) && gSpecialVar_ItemId != ITEM_ENIGMA_BERRY_E_READER)
2021-08-03 08:17:01 +02:00
{
gBagMenu->contextMenuItemsPtr = sContextMenuItems_FavorLady;
gBagMenu->contextMenuNumItems = ARRAY_COUNT(sContextMenuItems_FavorLady);
}
else
{
gBagMenu->contextMenuItemsPtr = sContextMenuItems_Cancel;
gBagMenu->contextMenuNumItems = ARRAY_COUNT(sContextMenuItems_Cancel);
}
break;
case ITEMMENULOCATION_QUIZ_LADY:
if (!ItemId_GetImportance(gSpecialVar_ItemId) && gSpecialVar_ItemId != ITEM_ENIGMA_BERRY_E_READER)
2021-08-03 08:17:01 +02:00
{
gBagMenu->contextMenuItemsPtr = sContextMenuItems_QuizLady;
gBagMenu->contextMenuNumItems = ARRAY_COUNT(sContextMenuItems_QuizLady);
}
else
{
gBagMenu->contextMenuItemsPtr = sContextMenuItems_Cancel;
gBagMenu->contextMenuNumItems = ARRAY_COUNT(sContextMenuItems_Cancel);
}
break;
case ITEMMENULOCATION_PARTY:
case ITEMMENULOCATION_SHOP:
case ITEMMENULOCATION_BERRY_TREE:
case ITEMMENULOCATION_ITEMPC:
default:
if (MenuHelpers_IsLinkActive() == TRUE || InUnionRoom() == TRUE)
2021-08-03 08:17:01 +02:00
{
if (gBagPosition.pocket == KEYITEMS_POCKET || !IsHoldingItemAllowed(gSpecialVar_ItemId))
2018-02-05 05:47:47 +01:00
{
2020-05-14 10:37:09 +02:00
gBagMenu->contextMenuItemsPtr = sContextMenuItems_Cancel;
gBagMenu->contextMenuNumItems = ARRAY_COUNT(sContextMenuItems_Cancel);
2018-02-05 05:47:47 +01:00
}
else
{
2021-08-03 08:17:01 +02:00
gBagMenu->contextMenuItemsPtr = sContextMenuItems_Give;
gBagMenu->contextMenuNumItems = ARRAY_COUNT(sContextMenuItems_Give);
2018-02-05 05:47:47 +01:00
}
2021-08-03 08:17:01 +02:00
}
else
{
switch (gBagPosition.pocket)
2018-02-05 05:47:47 +01:00
{
2021-08-03 08:17:01 +02:00
case ITEMS_POCKET:
gBagMenu->contextMenuItemsPtr = gBagMenu->contextMenuItemsBuffer;
gBagMenu->contextMenuNumItems = ARRAY_COUNT(sContextMenuItems_ItemsPocket);
memcpy(&gBagMenu->contextMenuItemsBuffer, &sContextMenuItems_ItemsPocket, sizeof(sContextMenuItems_ItemsPocket));
if (ItemIsMail(gSpecialVar_ItemId) == TRUE)
gBagMenu->contextMenuItemsBuffer[0] = ACTION_CHECK;
break;
case KEYITEMS_POCKET:
gBagMenu->contextMenuItemsPtr = gBagMenu->contextMenuItemsBuffer;
gBagMenu->contextMenuNumItems = ARRAY_COUNT(sContextMenuItems_KeyItemsPocket);
memcpy(&gBagMenu->contextMenuItemsBuffer, &sContextMenuItems_KeyItemsPocket, sizeof(sContextMenuItems_KeyItemsPocket));
if (gSaveBlock1Ptr->registeredItem == gSpecialVar_ItemId)
gBagMenu->contextMenuItemsBuffer[1] = ACTION_DESELECT;
if (gSpecialVar_ItemId == ITEM_MACH_BIKE || gSpecialVar_ItemId == ITEM_ACRO_BIKE)
2018-02-05 05:47:47 +01:00
{
2021-08-03 08:17:01 +02:00
if (TestPlayerAvatarFlags(PLAYER_AVATAR_FLAG_MACH_BIKE | PLAYER_AVATAR_FLAG_ACRO_BIKE))
gBagMenu->contextMenuItemsBuffer[0] = ACTION_WALK;
2018-02-05 05:47:47 +01:00
}
2021-08-03 08:17:01 +02:00
break;
case BALLS_POCKET:
gBagMenu->contextMenuItemsPtr = sContextMenuItems_BallsPocket;
gBagMenu->contextMenuNumItems = ARRAY_COUNT(sContextMenuItems_BallsPocket);
break;
case TMHM_POCKET:
gBagMenu->contextMenuItemsPtr = sContextMenuItems_TmHmPocket;
gBagMenu->contextMenuNumItems = ARRAY_COUNT(sContextMenuItems_TmHmPocket);
break;
case BERRIES_POCKET:
gBagMenu->contextMenuItemsPtr = sContextMenuItems_BerriesPocket;
gBagMenu->contextMenuNumItems = ARRAY_COUNT(sContextMenuItems_BerriesPocket);
break;
2018-02-05 05:47:47 +01:00
}
2021-08-03 08:17:01 +02:00
}
2018-02-05 05:47:47 +01:00
}
2021-08-03 08:17:01 +02:00
if (gBagPosition.pocket == TMHM_POCKET)
2018-02-05 05:47:47 +01:00
{
2021-08-03 08:17:01 +02:00
ClearWindowTilemap(WIN_DESCRIPTION);
2018-02-05 05:47:47 +01:00
PrintTMHMMoveData(gSpecialVar_ItemId);
2021-08-03 08:17:01 +02:00
PutWindowTilemap(WIN_TMHM_INFO_ICONS);
PutWindowTilemap(WIN_TMHM_INFO);
2020-05-14 10:37:09 +02:00
ScheduleBgCopyTilemapToVram(0);
2018-02-05 05:47:47 +01:00
}
else
{
CopyItemName(gSpecialVar_ItemId, gStringVar1);
StringExpandPlaceholders(gStringVar4, gText_Var1IsSelected);
2021-08-03 08:17:01 +02:00
FillWindowPixelBuffer(WIN_DESCRIPTION, PIXEL_FILL(0));
2021-10-30 22:47:37 +02:00
BagMenu_Print(WIN_DESCRIPTION, FONT_NORMAL, gStringVar4, 3, 1, 0, 0, 0, COLORID_NORMAL);
}
2020-05-14 10:37:09 +02:00
if (gBagMenu->contextMenuNumItems == 1)
2021-08-03 08:17:01 +02:00
PrintContextMenuItems(BagMenu_AddWindow(ITEMWIN_1x1));
2020-05-14 10:37:09 +02:00
else if (gBagMenu->contextMenuNumItems == 2)
2021-08-03 08:17:01 +02:00
PrintContextMenuItems(BagMenu_AddWindow(ITEMWIN_1x2));
2020-05-14 10:37:09 +02:00
else if (gBagMenu->contextMenuNumItems == 4)
2021-08-03 08:17:01 +02:00
PrintContextMenuItemGrid(BagMenu_AddWindow(ITEMWIN_2x2), 2, 2);
2018-02-05 05:47:47 +01:00
else
2021-08-03 08:17:01 +02:00
PrintContextMenuItemGrid(BagMenu_AddWindow(ITEMWIN_2x3), 2, 3);
2018-02-05 05:47:47 +01:00
}
2021-08-03 08:17:01 +02:00
static void PrintContextMenuItems(u8 windowId)
2018-02-05 05:47:47 +01:00
{
2021-11-04 04:20:59 +01:00
PrintMenuActionTexts(windowId, FONT_NARROW, 8, 1, 0, 16, gBagMenu->contextMenuNumItems, sItemMenuActions, gBagMenu->contextMenuItemsPtr);
2021-11-03 21:06:58 +01:00
InitMenuInUpperLeftCornerNormal(windowId, gBagMenu->contextMenuNumItems, 0);
2018-02-05 05:47:47 +01:00
}
2021-08-03 08:17:01 +02:00
static void PrintContextMenuItemGrid(u8 windowId, u8 columns, u8 rows)
2018-02-05 05:47:47 +01:00
{
2021-10-30 22:47:37 +02:00
PrintMenuActionGrid(windowId, FONT_NARROW, 8, 1, 56, columns, rows, sItemMenuActions, gBagMenu->contextMenuItemsPtr);
2021-08-03 08:17:01 +02:00
InitMenuActionGrid(windowId, 56, columns, rows, 0);
2018-02-05 05:47:47 +01:00
}
2021-08-03 08:17:01 +02:00
static void Task_ItemContext_Normal(u8 taskId)
2018-02-05 05:47:47 +01:00
{
2020-05-14 10:37:09 +02:00
OpenContextMenu(taskId);
2021-08-03 08:17:01 +02:00
// Context menu width is never greater than 2 columns, so if
// there are more than 2 items then there are multiple rows
2020-05-14 10:37:09 +02:00
if (gBagMenu->contextMenuNumItems <= 2)
2021-08-03 08:17:01 +02:00
gTasks[taskId].func = Task_ItemContext_SingleRow;
2018-02-05 05:47:47 +01:00
else
2021-08-03 08:17:01 +02:00
gTasks[taskId].func = Task_ItemContext_MultipleRows;
2018-02-05 05:47:47 +01:00
}
2021-08-03 08:17:01 +02:00
static void Task_ItemContext_SingleRow(u8 taskId)
2018-02-05 05:47:47 +01:00
{
if (MenuHelpers_ShouldWaitForLinkRecv() != TRUE)
2018-02-05 05:47:47 +01:00
{
2020-05-14 10:37:09 +02:00
s8 selection = Menu_ProcessInputNoWrap();
switch (selection)
2018-02-05 05:47:47 +01:00
{
2021-08-03 08:17:01 +02:00
case MENU_NOTHING_CHOSEN:
break;
case MENU_B_PRESSED:
PlaySE(SE_SELECT);
sItemMenuActions[ACTION_CANCEL].func.void_u8(taskId);
break;
default:
PlaySE(SE_SELECT);
sItemMenuActions[gBagMenu->contextMenuItemsPtr[selection]].func.void_u8(taskId);
break;
2018-02-05 05:47:47 +01:00
}
}
}
2021-08-03 08:17:01 +02:00
static void Task_ItemContext_MultipleRows(u8 taskId)
2018-02-05 05:47:47 +01:00
{
if (MenuHelpers_ShouldWaitForLinkRecv() != TRUE)
2018-02-05 05:47:47 +01:00
{
2018-12-16 21:10:01 +01:00
s8 cursorPos = Menu_GetCursorPos();
2020-09-05 03:11:55 +02:00
if (JOY_NEW(DPAD_UP))
2018-02-05 05:47:47 +01:00
{
2021-08-03 08:17:01 +02:00
if (cursorPos > 0 && IsValidContextMenuPos(cursorPos - 2))
2018-02-05 05:47:47 +01:00
{
PlaySE(SE_SELECT);
2021-11-04 04:20:59 +01:00
ChangeMenuGridCursorPosition(MENU_CURSOR_DELTA_NONE, MENU_CURSOR_DELTA_UP);
2018-02-05 05:47:47 +01:00
}
}
2020-09-05 03:11:55 +02:00
else if (JOY_NEW(DPAD_DOWN))
2018-02-05 05:47:47 +01:00
{
2021-08-03 08:17:01 +02:00
if (cursorPos < (gBagMenu->contextMenuNumItems - 2) && IsValidContextMenuPos(cursorPos + 2))
2018-02-05 05:47:47 +01:00
{
PlaySE(SE_SELECT);
2021-11-04 04:20:59 +01:00
ChangeMenuGridCursorPosition(MENU_CURSOR_DELTA_NONE, MENU_CURSOR_DELTA_DOWN);
2018-02-05 05:47:47 +01:00
}
}
2021-08-03 08:17:01 +02:00
else if (JOY_NEW(DPAD_LEFT) || GetLRKeysPressed() == MENU_L_PRESSED)
2018-02-05 05:47:47 +01:00
{
2021-08-03 08:17:01 +02:00
if ((cursorPos & 1) && IsValidContextMenuPos(cursorPos - 1))
2018-02-05 05:47:47 +01:00
{
PlaySE(SE_SELECT);
2021-11-04 04:20:59 +01:00
ChangeMenuGridCursorPosition(MENU_CURSOR_DELTA_LEFT, MENU_CURSOR_DELTA_NONE);
2018-02-05 05:47:47 +01:00
}
}
2021-08-03 08:17:01 +02:00
else if (JOY_NEW(DPAD_RIGHT) || GetLRKeysPressed() == MENU_R_PRESSED)
2018-02-05 05:47:47 +01:00
{
2021-08-03 08:17:01 +02:00
if (!(cursorPos & 1) && IsValidContextMenuPos(cursorPos + 1))
2018-02-05 05:47:47 +01:00
{
PlaySE(SE_SELECT);
2021-11-04 04:20:59 +01:00
ChangeMenuGridCursorPosition(MENU_CURSOR_DELTA_RIGHT, MENU_CURSOR_DELTA_NONE);
2018-02-05 05:47:47 +01:00
}
}
2020-09-05 03:11:55 +02:00
else if (JOY_NEW(A_BUTTON))
2018-02-05 05:47:47 +01:00
{
PlaySE(SE_SELECT);
2020-05-14 10:37:09 +02:00
sItemMenuActions[gBagMenu->contextMenuItemsPtr[cursorPos]].func.void_u8(taskId);
2018-02-05 05:47:47 +01:00
}
2020-09-05 03:11:55 +02:00
else if (JOY_NEW(B_BUTTON))
2018-02-05 05:47:47 +01:00
{
PlaySE(SE_SELECT);
2021-08-03 08:17:01 +02:00
sItemMenuActions[ACTION_CANCEL].func.void_u8(taskId);
2018-02-05 05:47:47 +01:00
}
}
}
2021-08-03 08:17:01 +02:00
static bool8 IsValidContextMenuPos(s8 cursorPos)
2018-02-05 05:47:47 +01:00
{
2021-08-03 08:17:01 +02:00
if (cursorPos < 0)
2018-02-05 05:47:47 +01:00
return FALSE;
2021-08-03 08:17:01 +02:00
if (cursorPos > gBagMenu->contextMenuNumItems)
2018-02-05 05:47:47 +01:00
return FALSE;
2021-08-03 08:17:01 +02:00
if (gBagMenu->contextMenuItemsPtr[cursorPos] == ACTION_DUMMY)
2018-02-05 05:47:47 +01:00
return FALSE;
return TRUE;
}
2021-08-03 08:17:01 +02:00
static void RemoveContextWindow(void)
2018-02-05 05:47:47 +01:00
{
2020-05-14 10:37:09 +02:00
if (gBagMenu->contextMenuNumItems == 1)
2021-08-03 08:17:01 +02:00
BagMenu_RemoveWindow(ITEMWIN_1x1);
2020-05-14 10:37:09 +02:00
else if (gBagMenu->contextMenuNumItems == 2)
2021-08-03 08:17:01 +02:00
BagMenu_RemoveWindow(ITEMWIN_1x2);
2020-05-14 10:37:09 +02:00
else if (gBagMenu->contextMenuNumItems == 4)
2021-08-03 08:17:01 +02:00
BagMenu_RemoveWindow(ITEMWIN_2x2);
2018-02-05 05:47:47 +01:00
else
2021-08-03 08:17:01 +02:00
BagMenu_RemoveWindow(ITEMWIN_2x3);
2018-02-05 05:47:47 +01:00
}
2021-08-03 08:17:01 +02:00
static void ItemMenu_UseOutOfBattle(u8 taskId)
2018-02-05 05:47:47 +01:00
{
if (ItemId_GetFieldFunc(gSpecialVar_ItemId))
{
2021-08-03 08:17:01 +02:00
RemoveContextWindow();
2021-01-19 11:49:20 +01:00
if (CalculatePlayerPartyCount() == 0 && ItemId_GetType(gSpecialVar_ItemId) == ITEM_USE_PARTY_MENU)
2021-08-03 08:17:01 +02:00
{
PrintThereIsNoPokemon(taskId);
}
2018-02-05 05:47:47 +01:00
else
{
2021-08-03 08:17:01 +02:00
FillWindowPixelBuffer(WIN_DESCRIPTION, PIXEL_FILL(0));
2020-05-14 10:37:09 +02:00
ScheduleBgCopyTilemapToVram(0);
2021-08-03 08:17:01 +02:00
if (gBagPosition.pocket != BERRIES_POCKET)
2018-02-05 05:47:47 +01:00
ItemId_GetFieldFunc(gSpecialVar_ItemId)(taskId);
else
ItemUseOutOfBattle_Berry(taskId);
2018-02-05 05:47:47 +01:00
}
}
}
2021-08-03 08:17:01 +02:00
static void ItemMenu_Toss(u8 taskId)
2018-02-05 05:47:47 +01:00
{
s16 *data = gTasks[taskId].data;
2018-02-14 01:12:17 +01:00
2021-08-03 08:17:01 +02:00
RemoveContextWindow();
2020-03-08 05:03:21 +01:00
tItemCount = 1;
2021-08-03 08:17:01 +02:00
if (tQuantity == 1)
2018-02-09 03:00:28 +01:00
{
2021-08-03 08:17:01 +02:00
AskTossItems(taskId);
2018-02-09 03:00:28 +01:00
}
2018-02-05 05:47:47 +01:00
else
{
CopyItemName(gSpecialVar_ItemId, gStringVar1);
StringExpandPlaceholders(gStringVar4, gText_TossHowManyVar1s);
2021-08-03 08:17:01 +02:00
FillWindowPixelBuffer(WIN_DESCRIPTION, PIXEL_FILL(0));
2021-10-30 22:47:37 +02:00
BagMenu_Print(WIN_DESCRIPTION, FONT_NORMAL, gStringVar4, 3, 1, 0, 0, 0, COLORID_NORMAL);
2021-08-03 08:17:01 +02:00
AddItemQuantityWindow(ITEMWIN_QUANTITY);
2018-02-05 05:47:47 +01:00
gTasks[taskId].func = Task_ChooseHowManyToToss;
}
}
2021-08-03 08:17:01 +02:00
static void AskTossItems(u8 taskId)
2018-02-05 05:47:47 +01:00
{
s16 *data = gTasks[taskId].data;
2018-02-14 01:12:17 +01:00
2018-02-05 05:47:47 +01:00
CopyItemName(gSpecialVar_ItemId, gStringVar1);
2020-09-25 17:18:52 +02:00
ConvertIntToDecimalStringN(gStringVar2, tItemCount, STR_CONV_MODE_LEFT_ALIGN, MAX_ITEM_DIGITS);
2018-02-05 05:47:47 +01:00
StringExpandPlaceholders(gStringVar4, gText_ConfirmTossItems);
2021-08-03 08:17:01 +02:00
FillWindowPixelBuffer(WIN_DESCRIPTION, PIXEL_FILL(0));
2021-10-30 22:47:37 +02:00
BagMenu_Print(WIN_DESCRIPTION, FONT_NORMAL, gStringVar4, 3, 1, 0, 0, 0, COLORID_NORMAL);
2021-08-03 08:17:01 +02:00
BagMenu_YesNo(taskId, ITEMWIN_YESNO_LOW, &sYesNoTossFunctions);
2018-02-05 05:47:47 +01:00
}
2021-08-03 08:17:01 +02:00
static void CancelToss(u8 taskId)
2018-02-05 05:47:47 +01:00
{
s16 *data = gTasks[taskId].data;
2018-02-14 01:12:17 +01:00
2021-08-03 08:17:01 +02:00
PrintItemDescription(tListPosition);
BagMenu_PrintCursor(tListTaskId, COLORID_NORMAL);
ReturnToItemList(taskId);
2018-02-05 05:47:47 +01:00
}
2021-08-03 08:17:01 +02:00
static void Task_ChooseHowManyToToss(u8 taskId)
2018-02-05 05:47:47 +01:00
{
s16 *data = gTasks[taskId].data;
2018-02-14 01:12:17 +01:00
2021-08-03 08:17:01 +02:00
if (AdjustQuantityAccordingToDPadInput(&tItemCount, tQuantity) == TRUE)
2018-02-09 03:00:28 +01:00
{
2021-08-03 08:17:01 +02:00
PrintItemQuantity(gBagMenu->windowIds[ITEMWIN_QUANTITY], tItemCount);
2018-02-09 03:00:28 +01:00
}
2020-09-05 03:11:55 +02:00
else if (JOY_NEW(A_BUTTON))
2018-02-05 05:47:47 +01:00
{
PlaySE(SE_SELECT);
2021-08-03 08:17:01 +02:00
BagMenu_RemoveWindow(ITEMWIN_QUANTITY);
AskTossItems(taskId);
2018-02-05 05:47:47 +01:00
}
2020-09-05 03:11:55 +02:00
else if (JOY_NEW(B_BUTTON))
2018-02-05 05:47:47 +01:00
{
PlaySE(SE_SELECT);
2021-08-03 08:17:01 +02:00
BagMenu_RemoveWindow(ITEMWIN_QUANTITY);
CancelToss(taskId);
2018-02-05 05:47:47 +01:00
}
}
2021-08-03 08:17:01 +02:00
static void ConfirmToss(u8 taskId)
2018-02-05 05:47:47 +01:00
{
s16 *data = gTasks[taskId].data;
2018-02-14 01:12:17 +01:00
2018-02-05 05:47:47 +01:00
CopyItemName(gSpecialVar_ItemId, gStringVar1);
2020-09-25 17:18:52 +02:00
ConvertIntToDecimalStringN(gStringVar2, tItemCount, STR_CONV_MODE_LEFT_ALIGN, MAX_ITEM_DIGITS);
2018-02-05 05:47:47 +01:00
StringExpandPlaceholders(gStringVar4, gText_ThrewAwayVar2Var1s);
2021-08-03 08:17:01 +02:00
FillWindowPixelBuffer(WIN_DESCRIPTION, PIXEL_FILL(0));
2021-10-30 22:47:37 +02:00
BagMenu_Print(WIN_DESCRIPTION, FONT_NORMAL, gStringVar4, 3, 1, 0, 0, 0, COLORID_NORMAL);
2021-08-03 08:17:01 +02:00
gTasks[taskId].func = Task_RemoveItemFromBag;
2018-02-05 05:47:47 +01:00
}
2021-08-03 08:17:01 +02:00
// Remove selected item(s) from the bag and update list
// For when items are tossed or deposited
static void Task_RemoveItemFromBag(u8 taskId)
2018-02-05 05:47:47 +01:00
{
s16 *data = gTasks[taskId].data;
u16 *scrollPos = &gBagPosition.scrollPosition[gBagPosition.pocket];
u16 *cursorPos = &gBagPosition.cursorPosition[gBagPosition.pocket];
2018-02-14 01:12:17 +01:00
2020-09-05 03:11:55 +02:00
if (JOY_NEW(A_BUTTON | B_BUTTON))
2018-02-05 05:47:47 +01:00
{
PlaySE(SE_SELECT);
2020-03-08 05:03:21 +01:00
RemoveBagItem(gSpecialVar_ItemId, tItemCount);
2021-08-03 08:17:01 +02:00
DestroyListMenuTask(tListTaskId, scrollPos, cursorPos);
UpdatePocketItemList(gBagPosition.pocket);
UpdatePocketListPosition(gBagPosition.pocket);
LoadBagItemListBuffers(gBagPosition.pocket);
tListTaskId = ListMenuInit(&gMultiuseListMenuTemplate, *scrollPos, *cursorPos);
2020-05-14 10:37:09 +02:00
ScheduleBgCopyTilemapToVram(0);
2021-08-03 08:17:01 +02:00
ReturnToItemList(taskId);
2018-02-05 05:47:47 +01:00
}
}
2021-08-03 08:17:01 +02:00
static void ItemMenu_Register(u8 taskId)
2018-02-05 05:47:47 +01:00
{
s16 *data = gTasks[taskId].data;
u16 *scrollPos = &gBagPosition.scrollPosition[gBagPosition.pocket];
u16 *cursorPos = &gBagPosition.cursorPosition[gBagPosition.pocket];
2018-02-14 01:12:17 +01:00
2018-02-05 05:47:47 +01:00
if (gSaveBlock1Ptr->registeredItem == gSpecialVar_ItemId)
gSaveBlock1Ptr->registeredItem = ITEM_NONE;
2018-02-05 05:47:47 +01:00
else
gSaveBlock1Ptr->registeredItem = gSpecialVar_ItemId;
2021-08-03 08:17:01 +02:00
DestroyListMenuTask(tListTaskId, scrollPos, cursorPos);
LoadBagItemListBuffers(gBagPosition.pocket);
tListTaskId = ListMenuInit(&gMultiuseListMenuTemplate, *scrollPos, *cursorPos);
2020-05-14 10:37:09 +02:00
ScheduleBgCopyTilemapToVram(0);
2018-02-05 05:47:47 +01:00
ItemMenu_Cancel(taskId);
}
2021-08-03 08:17:01 +02:00
static void ItemMenu_Give(u8 taskId)
2018-02-05 05:47:47 +01:00
{
2021-08-03 08:17:01 +02:00
RemoveContextWindow();
2021-04-23 00:49:54 +02:00
if (!IsWritingMailAllowed(gSpecialVar_ItemId))
2018-02-09 03:00:28 +01:00
{
2021-10-30 22:47:37 +02:00
DisplayItemMessage(taskId, FONT_NORMAL, gText_CantWriteMail, HandleErrorMessage);
2018-02-09 03:00:28 +01:00
}
2018-04-29 13:36:26 +02:00
else if (!ItemId_GetImportance(gSpecialVar_ItemId))
2018-02-05 05:47:47 +01:00
{
if (CalculatePlayerPartyCount() == 0)
2021-08-03 08:17:01 +02:00
{
PrintThereIsNoPokemon(taskId);
}
2018-02-05 05:47:47 +01:00
else
{
2021-08-03 08:17:01 +02:00
gBagMenu->newScreenCallback = CB2_ChooseMonToGiveItem;
Task_FadeAndCloseBagMenu(taskId);
2018-02-05 05:47:47 +01:00
}
}
else
2018-02-09 03:00:28 +01:00
{
2021-08-03 08:17:01 +02:00
PrintItemCantBeHeld(taskId);
2018-02-09 03:00:28 +01:00
}
2018-02-05 05:47:47 +01:00
}
2021-08-03 08:17:01 +02:00
static void PrintThereIsNoPokemon(u8 taskId)
2018-02-05 05:47:47 +01:00
{
2021-10-30 22:47:37 +02:00
DisplayItemMessage(taskId, FONT_NORMAL, gText_NoPokemon, HandleErrorMessage);
2018-02-05 05:47:47 +01:00
}
2021-08-03 08:17:01 +02:00
static void PrintItemCantBeHeld(u8 taskId)
2018-02-05 05:47:47 +01:00
{
CopyItemName(gSpecialVar_ItemId, gStringVar1);
StringExpandPlaceholders(gStringVar4, gText_Var1CantBeHeld);
2021-10-30 22:47:37 +02:00
DisplayItemMessage(taskId, FONT_NORMAL, gStringVar4, HandleErrorMessage);
2018-02-05 05:47:47 +01:00
}
2021-08-03 08:17:01 +02:00
static void HandleErrorMessage(u8 taskId)
2018-02-05 05:47:47 +01:00
{
2020-09-05 03:11:55 +02:00
if (JOY_NEW(A_BUTTON))
2018-02-05 05:47:47 +01:00
{
PlaySE(SE_SELECT);
2021-08-03 08:17:01 +02:00
CloseItemMessage(taskId);
2018-02-05 05:47:47 +01:00
}
}
2021-08-03 08:17:01 +02:00
static void ItemMenu_CheckTag(u8 taskId)
2018-02-05 05:47:47 +01:00
{
2021-08-03 08:17:01 +02:00
gBagMenu->newScreenCallback = DoBerryTagScreen;
Task_FadeAndCloseBagMenu(taskId);
2018-02-05 05:47:47 +01:00
}
2021-08-03 08:17:01 +02:00
static void ItemMenu_Cancel(u8 taskId)
2018-02-05 05:47:47 +01:00
{
s16 *data = gTasks[taskId].data;
2018-02-14 01:12:17 +01:00
2021-08-03 08:17:01 +02:00
RemoveContextWindow();
PrintItemDescription(tListPosition);
2020-05-14 10:37:09 +02:00
ScheduleBgCopyTilemapToVram(0);
ScheduleBgCopyTilemapToVram(1);
2021-08-03 08:17:01 +02:00
BagMenu_PrintCursor(tListTaskId, COLORID_NORMAL);
ReturnToItemList(taskId);
2018-02-05 05:47:47 +01:00
}
2021-08-03 08:17:01 +02:00
static void ItemMenu_UseInBattle(u8 taskId)
2018-02-05 05:47:47 +01:00
{
if (ItemId_GetBattleFunc(gSpecialVar_ItemId))
{
2021-08-03 08:17:01 +02:00
RemoveContextWindow();
2018-02-05 05:47:47 +01:00
ItemId_GetBattleFunc(gSpecialVar_ItemId)(taskId);
}
}
void CB2_ReturnToBagMenuPocket(void)
2018-02-05 05:47:47 +01:00
{
2020-05-14 10:37:09 +02:00
GoToBagMenu(ITEMMENULOCATION_LAST, POCKETS_COUNT, NULL);
2018-02-05 05:47:47 +01:00
}
2021-08-03 08:17:01 +02:00
static void Task_ItemContext_GiveToParty(u8 taskId)
2018-02-05 05:47:47 +01:00
{
2021-04-23 00:49:54 +02:00
if (!IsWritingMailAllowed(gSpecialVar_ItemId))
2018-02-09 03:00:28 +01:00
{
2021-10-30 22:47:37 +02:00
DisplayItemMessage(taskId, FONT_NORMAL, gText_CantWriteMail, HandleErrorMessage);
2018-02-09 03:00:28 +01:00
}
2021-08-03 08:17:01 +02:00
else if (!IsHoldingItemAllowed(gSpecialVar_ItemId))
2018-02-05 05:47:47 +01:00
{
CopyItemName(gSpecialVar_ItemId, gStringVar1);
StringExpandPlaceholders(gStringVar4, gText_Var1CantBeHeldHere);
2021-10-30 22:47:37 +02:00
DisplayItemMessage(taskId, FONT_NORMAL, gStringVar4, HandleErrorMessage);
2018-02-05 05:47:47 +01:00
}
2021-08-03 08:17:01 +02:00
else if (gBagPosition.pocket != KEYITEMS_POCKET && !ItemId_GetImportance(gSpecialVar_ItemId))
2018-02-05 05:47:47 +01:00
{
Task_FadeAndCloseBagMenu(taskId);
2018-02-05 05:47:47 +01:00
}
else
2018-02-09 03:00:28 +01:00
{
2021-08-03 08:17:01 +02:00
PrintItemCantBeHeld(taskId);
2018-02-09 03:00:28 +01:00
}
2018-02-05 05:47:47 +01:00
}
2021-08-03 08:17:01 +02:00
// Selected item to give to a Pokémon in PC storage
static void Task_ItemContext_GiveToPC(u8 taskId)
2018-02-05 05:47:47 +01:00
{
if (ItemIsMail(gSpecialVar_ItemId) == TRUE)
2021-10-30 22:47:37 +02:00
DisplayItemMessage(taskId, FONT_NORMAL, gText_CantWriteMail, HandleErrorMessage);
2021-08-03 08:17:01 +02:00
else if (gBagPosition.pocket != KEYITEMS_POCKET && !ItemId_GetImportance(gSpecialVar_ItemId))
gTasks[taskId].func = Task_FadeAndCloseBagMenu;
2018-02-05 05:47:47 +01:00
else
2021-08-03 08:17:01 +02:00
PrintItemCantBeHeld(taskId);
2018-02-05 05:47:47 +01:00
}
2021-08-03 08:17:01 +02:00
#define tUsingRegisteredKeyItem data[3] // See usage in item_use.c
2018-02-05 05:47:47 +01:00
bool8 UseRegisteredKeyItemOnField(void)
{
u8 taskId;
2018-02-14 01:12:17 +01:00
if (InUnionRoom() == TRUE || InBattlePyramid() || InBattlePike() || InMultiPartnerRoom() == TRUE)
2018-02-05 05:47:47 +01:00
return FALSE;
2018-02-09 03:00:28 +01:00
HideMapNamePopUpWindow();
2021-11-04 04:02:06 +01:00
ChangeBgY_ScreenOff(0, 0, BG_COORD_SET);
2018-02-09 03:00:28 +01:00
if (gSaveBlock1Ptr->registeredItem != ITEM_NONE)
2018-02-05 05:47:47 +01:00
{
2018-02-09 03:00:28 +01:00
if (CheckBagHasItem(gSaveBlock1Ptr->registeredItem, 1) == TRUE)
2018-02-05 05:47:47 +01:00
{
LockPlayerFieldControls();
FreezeObjectEvents();
PlayerFreeze();
2021-10-26 19:27:20 +02:00
StopPlayerAvatar();
2018-02-09 03:00:28 +01:00
gSpecialVar_ItemId = gSaveBlock1Ptr->registeredItem;
taskId = CreateTask(ItemId_GetFieldFunc(gSaveBlock1Ptr->registeredItem), 8);
gTasks[taskId].tUsingRegisteredKeyItem = TRUE;
2018-02-09 03:00:28 +01:00
return TRUE;
2018-02-05 05:47:47 +01:00
}
2018-02-09 03:00:28 +01:00
else
{
2018-02-09 03:00:28 +01:00
gSaveBlock1Ptr->registeredItem = ITEM_NONE;
}
2018-02-05 05:47:47 +01:00
}
ScriptContext_SetupScript(EventScript_SelectWithoutRegisteredItem);
2018-02-05 05:47:47 +01:00
return TRUE;
}
#undef tUsingRegisteredKeyItem
2021-08-03 08:17:01 +02:00
static void Task_ItemContext_Sell(u8 taskId)
2018-02-05 05:47:47 +01:00
{
s16 *data = gTasks[taskId].data;
2018-02-14 01:12:17 +01:00
2018-04-29 13:36:26 +02:00
if (ItemId_GetPrice(gSpecialVar_ItemId) == 0)
2018-02-05 05:47:47 +01:00
{
CopyItemName(gSpecialVar_ItemId, gStringVar2);
StringExpandPlaceholders(gStringVar4, gText_CantBuyKeyItem);
2021-10-30 22:47:37 +02:00
DisplayItemMessage(taskId, FONT_NORMAL, gStringVar4, CloseItemMessage);
2018-02-05 05:47:47 +01:00
}
2018-02-14 01:12:17 +01:00
else
2018-02-05 05:47:47 +01:00
{
2020-03-08 05:03:21 +01:00
tItemCount = 1;
2021-08-03 08:17:01 +02:00
if (tQuantity == 1)
2018-02-05 05:47:47 +01:00
{
2020-03-08 05:03:21 +01:00
DisplayCurrentMoneyWindow();
DisplaySellItemPriceAndConfirm(taskId);
2018-02-05 05:47:47 +01:00
}
else
{
CopyItemName(gSpecialVar_ItemId, gStringVar2);
StringExpandPlaceholders(gStringVar4, gText_HowManyToSell);
2021-10-30 22:47:37 +02:00
DisplayItemMessage(taskId, FONT_NORMAL, gStringVar4, InitSellHowManyInput);
2018-02-05 05:47:47 +01:00
}
}
}
2020-08-28 19:31:58 +02:00
static void DisplaySellItemPriceAndConfirm(u8 taskId)
2018-02-05 05:47:47 +01:00
{
s16 *data = gTasks[taskId].data;
2018-02-14 01:12:17 +01:00
2020-03-08 05:03:21 +01:00
ConvertIntToDecimalStringN(gStringVar1, (ItemId_GetPrice(gSpecialVar_ItemId) / 2) * tItemCount, STR_CONV_MODE_LEFT_ALIGN, 6);
2018-02-05 05:47:47 +01:00
StringExpandPlaceholders(gStringVar4, gText_ICanPayVar1);
2021-10-30 22:47:37 +02:00
DisplayItemMessage(taskId, FONT_NORMAL, gStringVar4, AskSellItems);
2018-02-05 05:47:47 +01:00
}
2021-08-03 08:17:01 +02:00
static void AskSellItems(u8 taskId)
2018-02-05 05:47:47 +01:00
{
2021-08-03 08:17:01 +02:00
BagMenu_YesNo(taskId, ITEMWIN_YESNO_HIGH, &sYesNoSellItemFunctions);
2018-02-05 05:47:47 +01:00
}
2021-08-03 08:17:01 +02:00
static void CancelSell(u8 taskId)
2018-02-05 05:47:47 +01:00
{
s16 *data = gTasks[taskId].data;
2018-02-14 01:12:17 +01:00
2020-08-28 19:31:58 +02:00
RemoveMoneyWindow();
2021-08-03 08:17:01 +02:00
RemoveItemMessageWindow(ITEMWIN_MESSAGE);
BagMenu_PrintCursor(tListTaskId, COLORID_NORMAL);
ReturnToItemList(taskId);
2018-02-05 05:47:47 +01:00
}
2021-08-03 08:17:01 +02:00
static void InitSellHowManyInput(u8 taskId)
2018-02-05 05:47:47 +01:00
{
s16 *data = gTasks[taskId].data;
2021-08-03 08:17:01 +02:00
u8 windowId = BagMenu_AddWindow(ITEMWIN_QUANTITY_WIDE);
2018-02-14 01:12:17 +01:00
2020-03-08 05:03:21 +01:00
PrintItemSoldAmount(windowId, 1, (ItemId_GetPrice(gSpecialVar_ItemId) / 2) * tItemCount);
DisplayCurrentMoneyWindow();
2021-08-03 08:17:01 +02:00
gTasks[taskId].func = Task_ChooseHowManyToSell;
2018-02-05 05:47:47 +01:00
}
2021-08-03 08:17:01 +02:00
static void Task_ChooseHowManyToSell(u8 taskId)
2018-02-05 05:47:47 +01:00
{
s16 *data = gTasks[taskId].data;
2018-02-14 01:12:17 +01:00
2021-08-03 08:17:01 +02:00
if (AdjustQuantityAccordingToDPadInput(&tItemCount, tQuantity) == TRUE)
2018-02-09 03:00:28 +01:00
{
2021-08-03 08:17:01 +02:00
PrintItemSoldAmount(gBagMenu->windowIds[ITEMWIN_QUANTITY_WIDE], tItemCount, (ItemId_GetPrice(gSpecialVar_ItemId) / 2) * tItemCount);
2018-02-09 03:00:28 +01:00
}
2020-09-05 03:11:55 +02:00
else if (JOY_NEW(A_BUTTON))
2018-02-05 05:47:47 +01:00
{
PlaySE(SE_SELECT);
2021-08-03 08:17:01 +02:00
BagMenu_RemoveWindow(ITEMWIN_QUANTITY_WIDE);
2020-03-08 05:03:21 +01:00
DisplaySellItemPriceAndConfirm(taskId);
2018-02-05 05:47:47 +01:00
}
2020-09-05 03:11:55 +02:00
else if (JOY_NEW(B_BUTTON))
2018-02-05 05:47:47 +01:00
{
PlaySE(SE_SELECT);
2021-08-03 08:17:01 +02:00
BagMenu_PrintCursor(tListTaskId, COLORID_NORMAL);
2020-08-28 19:31:58 +02:00
RemoveMoneyWindow();
2021-08-03 08:17:01 +02:00
BagMenu_RemoveWindow(ITEMWIN_QUANTITY_WIDE);
RemoveItemMessageWindow(ITEMWIN_MESSAGE);
ReturnToItemList(taskId);
2018-02-05 05:47:47 +01:00
}
}
2021-08-03 08:17:01 +02:00
static void ConfirmSell(u8 taskId)
2018-02-05 05:47:47 +01:00
{
s16 *data = gTasks[taskId].data;
2018-02-14 01:12:17 +01:00
2018-02-05 05:47:47 +01:00
CopyItemName(gSpecialVar_ItemId, gStringVar2);
2020-03-08 05:03:21 +01:00
ConvertIntToDecimalStringN(gStringVar1, (ItemId_GetPrice(gSpecialVar_ItemId) / 2) * tItemCount, STR_CONV_MODE_LEFT_ALIGN, 6);
2018-02-05 05:47:47 +01:00
StringExpandPlaceholders(gStringVar4, gText_TurnedOverVar1ForVar2);
2021-10-30 22:47:37 +02:00
DisplayItemMessage(taskId, FONT_NORMAL, gStringVar4, SellItem);
2018-02-05 05:47:47 +01:00
}
2021-08-03 08:17:01 +02:00
static void SellItem(u8 taskId)
2018-02-05 05:47:47 +01:00
{
s16 *data = gTasks[taskId].data;
u16 *scrollPos = &gBagPosition.scrollPosition[gBagPosition.pocket];
u16 *cursorPos = &gBagPosition.cursorPosition[gBagPosition.pocket];
2018-02-14 01:12:17 +01:00
2020-08-21 00:02:00 +02:00
PlaySE(SE_SHOP);
2020-03-08 05:03:21 +01:00
RemoveBagItem(gSpecialVar_ItemId, tItemCount);
AddMoney(&gSaveBlock1Ptr->money, (ItemId_GetPrice(gSpecialVar_ItemId) / 2) * tItemCount);
2021-08-03 08:17:01 +02:00
DestroyListMenuTask(tListTaskId, scrollPos, cursorPos);
UpdatePocketItemList(gBagPosition.pocket);
UpdatePocketListPosition(gBagPosition.pocket);
LoadBagItemListBuffers(gBagPosition.pocket);
tListTaskId = ListMenuInit(&gMultiuseListMenuTemplate, *scrollPos, *cursorPos);
BagMenu_PrintCursor(tListTaskId, COLORID_GRAY_CURSOR);
PrintMoneyAmountInMoneyBox(gBagMenu->windowIds[ITEMWIN_MONEY], GetMoney(&gSaveBlock1Ptr->money), 0);
gTasks[taskId].func = WaitAfterItemSell;
2018-02-05 05:47:47 +01:00
}
2021-08-03 08:17:01 +02:00
static void WaitAfterItemSell(u8 taskId)
2018-02-05 05:47:47 +01:00
{
2020-09-05 03:11:55 +02:00
if (JOY_NEW(A_BUTTON | B_BUTTON))
2018-02-05 05:47:47 +01:00
{
PlaySE(SE_SELECT);
2020-08-28 19:31:58 +02:00
RemoveMoneyWindow();
2021-08-03 08:17:01 +02:00
CloseItemMessage(taskId);
2018-02-05 05:47:47 +01:00
}
}
2021-08-03 08:17:01 +02:00
static void Task_ItemContext_Deposit(u8 taskId)
2018-02-05 05:47:47 +01:00
{
s16 *data = gTasks[taskId].data;
2018-02-14 01:12:17 +01:00
2020-03-08 05:03:21 +01:00
tItemCount = 1;
2021-08-03 08:17:01 +02:00
if (tQuantity == 1)
2018-02-09 03:00:28 +01:00
{
2021-08-03 08:17:01 +02:00
TryDepositItem(taskId);
2018-02-09 03:00:28 +01:00
}
2018-02-05 05:47:47 +01:00
else
{
CopyItemName(gSpecialVar_ItemId, gStringVar1);
StringExpandPlaceholders(gStringVar4, gText_DepositHowManyVar1);
2021-08-03 08:17:01 +02:00
FillWindowPixelBuffer(WIN_DESCRIPTION, PIXEL_FILL(0));
2021-10-30 22:47:37 +02:00
BagMenu_Print(WIN_DESCRIPTION, FONT_NORMAL, gStringVar4, 3, 1, 0, 0, 0, COLORID_NORMAL);
2021-08-03 08:17:01 +02:00
AddItemQuantityWindow(ITEMWIN_QUANTITY);
2020-08-28 19:31:58 +02:00
gTasks[taskId].func = Task_ChooseHowManyToDeposit;
2018-02-05 05:47:47 +01:00
}
}
2020-08-28 19:31:58 +02:00
static void Task_ChooseHowManyToDeposit(u8 taskId)
2018-02-05 05:47:47 +01:00
{
s16 *data = gTasks[taskId].data;
2018-02-14 01:12:17 +01:00
2021-08-03 08:17:01 +02:00
if (AdjustQuantityAccordingToDPadInput(&tItemCount, tQuantity) == TRUE)
2018-02-09 03:00:28 +01:00
{
2021-08-03 08:17:01 +02:00
PrintItemQuantity(gBagMenu->windowIds[ITEMWIN_QUANTITY], tItemCount);
2018-02-09 03:00:28 +01:00
}
2020-09-05 03:11:55 +02:00
else if (JOY_NEW(A_BUTTON))
2018-02-05 05:47:47 +01:00
{
PlaySE(SE_SELECT);
2021-08-03 08:17:01 +02:00
BagMenu_RemoveWindow(ITEMWIN_QUANTITY);
TryDepositItem(taskId);
2018-02-05 05:47:47 +01:00
}
2020-09-05 03:11:55 +02:00
else if (JOY_NEW(B_BUTTON))
2018-02-05 05:47:47 +01:00
{
PlaySE(SE_SELECT);
2021-08-03 08:17:01 +02:00
PrintItemDescription(tListPosition);
BagMenu_PrintCursor(tListTaskId, COLORID_NORMAL);
BagMenu_RemoveWindow(ITEMWIN_QUANTITY);
ReturnToItemList(taskId);
2018-02-05 05:47:47 +01:00
}
}
2021-08-03 08:17:01 +02:00
static void TryDepositItem(u8 taskId)
2018-02-05 05:47:47 +01:00
{
s16 *data = gTasks[taskId].data;
2018-02-14 01:12:17 +01:00
2021-08-03 08:17:01 +02:00
FillWindowPixelBuffer(WIN_DESCRIPTION, PIXEL_FILL(0));
2018-04-29 13:36:26 +02:00
if (ItemId_GetImportance(gSpecialVar_ItemId))
2018-02-05 05:47:47 +01:00
{
2021-08-03 08:17:01 +02:00
// Can't deposit important items
2021-10-30 22:47:37 +02:00
BagMenu_Print(WIN_DESCRIPTION, FONT_NORMAL, gText_CantStoreImportantItems, 3, 1, 0, 0, 0, COLORID_NORMAL);
2021-08-03 08:17:01 +02:00
gTasks[taskId].func = WaitDepositErrorMessage;
2018-02-05 05:47:47 +01:00
}
2020-03-08 05:03:21 +01:00
else if (AddPCItem(gSpecialVar_ItemId, tItemCount) == TRUE)
2018-02-05 05:47:47 +01:00
{
2021-08-03 08:17:01 +02:00
// Successfully deposited
2018-02-05 05:47:47 +01:00
CopyItemName(gSpecialVar_ItemId, gStringVar1);
2020-09-25 17:18:52 +02:00
ConvertIntToDecimalStringN(gStringVar2, tItemCount, STR_CONV_MODE_LEFT_ALIGN, MAX_ITEM_DIGITS);
2018-02-05 05:47:47 +01:00
StringExpandPlaceholders(gStringVar4, gText_DepositedVar2Var1s);
2021-10-30 22:47:37 +02:00
BagMenu_Print(WIN_DESCRIPTION, FONT_NORMAL, gStringVar4, 3, 1, 0, 0, 0, COLORID_NORMAL);
2021-08-03 08:17:01 +02:00
gTasks[taskId].func = Task_RemoveItemFromBag;
2018-02-05 05:47:47 +01:00
}
else
{
2021-08-03 08:17:01 +02:00
// No room to deposit
2021-10-30 22:47:37 +02:00
BagMenu_Print(WIN_DESCRIPTION, FONT_NORMAL, gText_NoRoomForItems, 3, 1, 0, 0, 0, COLORID_NORMAL);
2021-08-03 08:17:01 +02:00
gTasks[taskId].func = WaitDepositErrorMessage;
2018-02-05 05:47:47 +01:00
}
}
2021-08-03 08:17:01 +02:00
static void WaitDepositErrorMessage(u8 taskId)
2018-02-05 05:47:47 +01:00
{
s16 *data = gTasks[taskId].data;
2018-02-14 01:12:17 +01:00
2020-09-05 03:11:55 +02:00
if (JOY_NEW(A_BUTTON | B_BUTTON))
2018-02-05 05:47:47 +01:00
{
PlaySE(SE_SELECT);
2021-08-03 08:17:01 +02:00
PrintItemDescription(tListPosition);
BagMenu_PrintCursor(tListTaskId, COLORID_NORMAL);
ReturnToItemList(taskId);
2018-02-05 05:47:47 +01:00
}
}
2021-08-03 08:17:01 +02:00
static bool8 IsWallysBag(void)
2018-02-05 05:47:47 +01:00
{
2021-08-03 08:17:01 +02:00
if (gBagPosition.location == ITEMMENULOCATION_WALLY)
2018-02-05 05:47:47 +01:00
return TRUE;
return FALSE;
}
2021-08-03 08:17:01 +02:00
static void PrepareBagForWallyTutorial(void)
2018-02-05 05:47:47 +01:00
{
u32 i;
2018-02-14 01:12:17 +01:00
2021-08-03 08:17:01 +02:00
sTempWallyBag = AllocZeroed(sizeof(*sTempWallyBag));
2020-02-04 12:42:25 +01:00
memcpy(sTempWallyBag->bagPocket_Items, gSaveBlock1Ptr->bagPocket_Items, sizeof(gSaveBlock1Ptr->bagPocket_Items));
memcpy(sTempWallyBag->bagPocket_PokeBalls, gSaveBlock1Ptr->bagPocket_PokeBalls, sizeof(gSaveBlock1Ptr->bagPocket_PokeBalls));
2021-08-03 08:17:01 +02:00
sTempWallyBag->pocket = gBagPosition.pocket;
for (i = 0; i < POCKETS_COUNT; i++)
2018-02-05 05:47:47 +01:00
{
2021-08-03 08:17:01 +02:00
sTempWallyBag->cursorPosition[i] = gBagPosition.cursorPosition[i];
sTempWallyBag->scrollPosition[i] = gBagPosition.scrollPosition[i];
2018-02-05 05:47:47 +01:00
}
2020-02-04 12:24:39 +01:00
ClearItemSlots(gSaveBlock1Ptr->bagPocket_Items, BAG_ITEMS_COUNT);
ClearItemSlots(gSaveBlock1Ptr->bagPocket_PokeBalls, BAG_POKEBALLS_COUNT);
2018-02-05 05:47:47 +01:00
ResetBagScrollPositions();
}
2021-08-03 08:17:01 +02:00
static void RestoreBagAfterWallyTutorial(void)
2018-02-05 05:47:47 +01:00
{
u32 i;
2018-02-14 01:12:17 +01:00
2020-02-04 12:42:25 +01:00
memcpy(gSaveBlock1Ptr->bagPocket_Items, sTempWallyBag->bagPocket_Items, sizeof(sTempWallyBag->bagPocket_Items));
memcpy(gSaveBlock1Ptr->bagPocket_PokeBalls, sTempWallyBag->bagPocket_PokeBalls, sizeof(sTempWallyBag->bagPocket_PokeBalls));
2021-08-03 08:17:01 +02:00
gBagPosition.pocket = sTempWallyBag->pocket;
for (i = 0; i < POCKETS_COUNT; i++)
2018-02-05 05:47:47 +01:00
{
2021-08-03 08:17:01 +02:00
gBagPosition.cursorPosition[i] = sTempWallyBag->cursorPosition[i];
gBagPosition.scrollPosition[i] = sTempWallyBag->scrollPosition[i];
2018-02-05 05:47:47 +01:00
}
2020-02-04 12:42:25 +01:00
Free(sTempWallyBag);
2018-02-05 05:47:47 +01:00
}
void DoWallyTutorialBagMenu(void)
{
PrepareBagForWallyTutorial();
AddBagItem(ITEM_POTION, 1);
AddBagItem(ITEM_POKE_BALL, 1);
2020-05-14 10:37:09 +02:00
GoToBagMenu(ITEMMENULOCATION_WALLY, ITEMS_POCKET, CB2_SetUpReshowBattleScreenAfterMenu2);
2018-02-05 05:47:47 +01:00
}
2021-08-03 08:17:01 +02:00
#define tTimer data[8]
#define WALLY_BAG_DELAY 102 // The number of frames between each action Wally takes in the bag
static void Task_WallyTutorialBagMenu(u8 taskId)
2018-02-05 05:47:47 +01:00
{
s16 *data = gTasks[taskId].data;
2018-02-14 01:12:17 +01:00
2018-02-05 05:47:47 +01:00
if (!gPaletteFade.active)
{
2021-08-03 08:17:01 +02:00
switch (tTimer)
2018-02-05 05:47:47 +01:00
{
2021-08-03 08:17:01 +02:00
case WALLY_BAG_DELAY * 1:
PlaySE(SE_SELECT);
SwitchBagPocket(taskId, MENU_CURSOR_DELTA_RIGHT, FALSE);
tTimer++;
break;
case WALLY_BAG_DELAY * 2:
PlaySE(SE_SELECT);
BagMenu_PrintCursor(tListTaskId, COLORID_GRAY_CURSOR);
gSpecialVar_ItemId = ITEM_POKE_BALL;
OpenContextMenu(taskId);
tTimer++;
break;
case WALLY_BAG_DELAY * 3:
PlaySE(SE_SELECT);
RemoveContextWindow();
DestroyListMenuTask(tListTaskId, 0, 0);
RestoreBagAfterWallyTutorial();
Task_FadeAndCloseBagMenu(taskId);
break;
default:
tTimer++;
break;
2018-02-05 05:47:47 +01:00
}
}
}
2021-08-03 08:17:01 +02:00
#undef tTimer
2020-03-08 05:03:21 +01:00
2021-08-03 08:17:01 +02:00
// This action is used to show the Apprentice an item when
// they ask what item they should make their Pokémon hold
static void ItemMenu_Show(u8 taskId)
2018-02-05 05:47:47 +01:00
{
gSpecialVar_0x8005 = gSpecialVar_ItemId;
2021-08-03 08:17:01 +02:00
gSpecialVar_Result = TRUE;
RemoveContextWindow();
Task_FadeAndCloseBagMenu(taskId);
2018-02-05 05:47:47 +01:00
}
2021-08-03 08:17:01 +02:00
static void CB2_ApprenticeExitBagMenu(void)
2018-02-05 05:47:47 +01:00
{
gFieldCallback = Apprentice_ScriptContext_Enable;
2018-02-14 01:12:17 +01:00
SetMainCallback2(CB2_ReturnToField);
2018-02-05 05:47:47 +01:00
}
2021-08-03 08:17:01 +02:00
static void ItemMenu_GiveFavorLady(u8 taskId)
2018-02-05 05:47:47 +01:00
{
RemoveBagItem(gSpecialVar_ItemId, 1);
2021-08-03 08:17:01 +02:00
gSpecialVar_Result = TRUE;
RemoveContextWindow();
Task_FadeAndCloseBagMenu(taskId);
2018-02-05 05:47:47 +01:00
}
2021-08-03 08:17:01 +02:00
static void CB2_FavorLadyExitBagMenu(void)
2018-02-05 05:47:47 +01:00
{
2019-08-06 02:37:09 +02:00
gFieldCallback = FieldCallback_FavorLadyEnableScriptContexts;
2018-02-14 01:12:17 +01:00
SetMainCallback2(CB2_ReturnToField);
2018-02-05 05:47:47 +01:00
}
2021-08-03 08:17:01 +02:00
// This action is used to confirm which item to use as
// a prize for a custom quiz with the Lilycove Quiz Lady
static void ItemMenu_ConfirmQuizLady(u8 taskId)
2018-02-05 05:47:47 +01:00
{
2021-08-03 08:17:01 +02:00
gSpecialVar_Result = TRUE;
RemoveContextWindow();
Task_FadeAndCloseBagMenu(taskId);
2018-02-05 05:47:47 +01:00
}
2021-08-03 08:17:01 +02:00
static void CB2_QuizLadyExitBagMenu(void)
2018-02-05 05:47:47 +01:00
{
2019-08-06 02:37:09 +02:00
gFieldCallback = FieldCallback_QuizLadyEnableScriptContexts;
2018-02-14 01:12:17 +01:00
SetMainCallback2(CB2_ReturnToField);
2018-02-05 05:47:47 +01:00
}
2021-08-03 08:17:01 +02:00
static void PrintPocketNames(const u8 *pocketName1, const u8 *pocketName2)
2018-02-05 05:47:47 +01:00
{
2021-08-03 08:17:01 +02:00
struct WindowTemplate window = {0};
2018-02-05 05:47:47 +01:00
u16 windowId;
int offset;
2018-02-14 01:12:17 +01:00
2018-02-05 05:47:47 +01:00
window.width = 16;
window.height = 2;
windowId = AddWindow(&window);
FillWindowPixelBuffer(windowId, PIXEL_FILL(0));
2021-10-30 22:47:37 +02:00
offset = GetStringCenterAlignXOffset(FONT_NORMAL, pocketName1, 0x40);
BagMenu_Print(windowId, FONT_NORMAL, pocketName1, offset, 1, 0, 0, TEXT_SKIP_DRAW, COLORID_POCKET_NAME);
2018-02-05 05:47:47 +01:00
if (pocketName2)
{
2021-10-30 22:47:37 +02:00
offset = GetStringCenterAlignXOffset(FONT_NORMAL, pocketName2, 0x40);
BagMenu_Print(windowId, FONT_NORMAL, pocketName2, offset + 0x40, 1, 0, 0, TEXT_SKIP_DRAW, COLORID_POCKET_NAME);
2018-02-05 05:47:47 +01:00
}
CpuCopy32((u8 *)GetWindowAttribute(windowId, WINDOW_TILE_DATA), gBagMenu->pocketNameBuffer, sizeof(gBagMenu->pocketNameBuffer));
2018-02-05 05:47:47 +01:00
RemoveWindow(windowId);
}
2021-08-03 08:17:01 +02:00
static void CopyPocketNameToWindow(u32 a)
2018-02-05 05:47:47 +01:00
{
2021-08-03 08:17:01 +02:00
u8 (* tileDataBuffer)[32][32];
u8 *windowTileData;
2018-02-05 05:47:47 +01:00
int b;
if (a > 8)
a = 8;
2021-08-03 08:17:01 +02:00
tileDataBuffer = &gBagMenu->pocketNameBuffer;
windowTileData = (u8 *)GetWindowAttribute(2, WINDOW_TILE_DATA);
2021-08-03 08:17:01 +02:00
CpuCopy32(tileDataBuffer[0][a], windowTileData, 0x100); // Top half of pocket name
2018-02-05 05:47:47 +01:00
b = a + 16;
2021-08-03 08:17:01 +02:00
CpuCopy32(tileDataBuffer[0][b], windowTileData + 0x100, 0x100); // Bottom half of pocket name
2021-11-03 20:29:18 +01:00
CopyWindowToVram(WIN_POCKET_NAME, COPYWIN_GFX);
2018-02-05 05:47:47 +01:00
}
2021-08-03 08:17:01 +02:00
static void LoadBagMenuTextWindows(void)
2018-02-05 05:47:47 +01:00
{
u8 i;
2018-02-14 01:12:17 +01:00
2020-05-14 10:37:09 +02:00
InitWindows(sDefaultBagWindows);
2018-02-05 05:47:47 +01:00
DeactivateAllTextPrinters();
2022-08-19 17:32:00 +02:00
LoadUserWindowBorderGfx(0, 1, BG_PLTT_ID(14));
LoadMessageBoxGfx(0, 10, BG_PLTT_ID(13));
ListMenuLoadStdPalAt(BG_PLTT_ID(12), 1);
LoadPalette(&gStandardMenuPalette, BG_PLTT_ID(15), PLTT_SIZE_4BPP);
2021-08-03 08:17:01 +02:00
for (i = 0; i <= WIN_POCKET_NAME; i++)
2018-02-05 05:47:47 +01:00
{
FillWindowPixelBuffer(i, PIXEL_FILL(0));
2018-02-05 05:47:47 +01:00
PutWindowTilemap(i);
}
2020-05-14 10:37:09 +02:00
ScheduleBgCopyTilemapToVram(0);
ScheduleBgCopyTilemapToVram(1);
2018-02-05 05:47:47 +01:00
}
2021-08-03 08:17:01 +02:00
static void BagMenu_Print(u8 windowId, u8 fontId, const u8 *str, u8 left, u8 top, u8 letterSpacing, u8 lineSpacing, u8 speed, u8 colorIndex)
2018-02-05 05:47:47 +01:00
{
2020-05-14 10:37:09 +02:00
AddTextPrinterParameterized4(windowId, fontId, left, top, letterSpacing, lineSpacing, sFontColorTable[colorIndex], speed, str);
2018-02-05 05:47:47 +01:00
}
2021-08-03 08:17:01 +02:00
// Unused
static u8 BagMenu_GetWindowId(u8 windowType)
2018-02-05 05:47:47 +01:00
{
2021-08-03 08:17:01 +02:00
return gBagMenu->windowIds[windowType];
2018-02-14 01:12:17 +01:00
}
2018-02-05 05:47:47 +01:00
2021-08-03 08:17:01 +02:00
static u8 BagMenu_AddWindow(u8 windowType)
2018-02-05 05:47:47 +01:00
{
2021-08-03 08:17:01 +02:00
u8 *windowId = &gBagMenu->windowIds[windowType];
if (*windowId == WINDOW_NONE)
2018-02-05 05:47:47 +01:00
{
2021-08-03 08:17:01 +02:00
*windowId = AddWindow(&sContextMenuWindowTemplates[windowType]);
2022-07-25 20:59:14 +02:00
DrawStdFrameWithCustomTileAndPalette(*windowId, FALSE, 1, 14);
2020-05-14 10:37:09 +02:00
ScheduleBgCopyTilemapToVram(1);
2018-02-05 05:47:47 +01:00
}
2021-08-03 08:17:01 +02:00
return *windowId;
2018-02-05 05:47:47 +01:00
}
2021-08-03 08:17:01 +02:00
static void BagMenu_RemoveWindow(u8 windowType)
2018-02-05 05:47:47 +01:00
{
2021-08-03 08:17:01 +02:00
u8 *windowId = &gBagMenu->windowIds[windowType];
if (*windowId != WINDOW_NONE)
2018-02-05 05:47:47 +01:00
{
2021-08-03 08:17:01 +02:00
ClearStdWindowAndFrameToTransparent(*windowId, FALSE);
ClearWindowTilemap(*windowId);
RemoveWindow(*windowId);
2020-05-14 10:37:09 +02:00
ScheduleBgCopyTilemapToVram(1);
2021-08-03 08:17:01 +02:00
*windowId = WINDOW_NONE;
2018-02-05 05:47:47 +01:00
}
}
2021-08-03 08:17:01 +02:00
static u8 AddItemMessageWindow(u8 windowType)
2018-02-05 05:47:47 +01:00
{
2021-08-03 08:17:01 +02:00
u8 *windowId = &gBagMenu->windowIds[windowType];
if (*windowId == WINDOW_NONE)
*windowId = AddWindow(&sContextMenuWindowTemplates[windowType]);
return *windowId;
2018-02-05 05:47:47 +01:00
}
2021-08-03 08:17:01 +02:00
static void RemoveItemMessageWindow(u8 windowType)
2018-02-05 05:47:47 +01:00
{
2021-08-03 08:17:01 +02:00
u8 *windowId = &gBagMenu->windowIds[windowType];
if (*windowId != WINDOW_NONE)
2018-02-05 05:47:47 +01:00
{
2021-08-03 08:17:01 +02:00
ClearDialogWindowAndFrameToTransparent(*windowId, FALSE);
// This ClearWindowTilemap call is redundant, since ClearDialogWindowAndFrameToTransparent already calls it.
2021-08-03 08:17:01 +02:00
ClearWindowTilemap(*windowId);
RemoveWindow(*windowId);
2020-05-14 10:37:09 +02:00
ScheduleBgCopyTilemapToVram(1);
2021-08-03 08:17:01 +02:00
*windowId = WINDOW_NONE;
2018-02-05 05:47:47 +01:00
}
}
2021-08-03 08:17:01 +02:00
void BagMenu_YesNo(u8 taskId, u8 windowType, const struct YesNoFuncTable *funcTable)
2018-02-05 05:47:47 +01:00
{
2021-08-03 08:17:01 +02:00
CreateYesNoMenuWithCallbacks(taskId, &sContextMenuWindowTemplates[windowType], 1, 0, 2, 1, 14, funcTable);
2018-02-05 05:47:47 +01:00
}
2020-08-28 19:31:58 +02:00
static void DisplayCurrentMoneyWindow(void)
2018-02-05 05:47:47 +01:00
{
2021-08-03 08:17:01 +02:00
u8 windowId = BagMenu_AddWindow(ITEMWIN_MONEY);
2018-02-05 05:47:47 +01:00
PrintMoneyAmountInMoneyBoxWithBorder(windowId, 1, 14, GetMoney(&gSaveBlock1Ptr->money));
AddMoneyLabelObject(19, 11);
}
2020-08-28 19:31:58 +02:00
static void RemoveMoneyWindow(void)
2018-02-05 05:47:47 +01:00
{
2021-08-03 08:17:01 +02:00
BagMenu_RemoveWindow(ITEMWIN_MONEY);
2018-02-05 05:47:47 +01:00
RemoveMoneyLabelObject();
}
2021-08-03 08:17:01 +02:00
static void PrepareTMHMMoveWindow(void)
2018-02-05 05:47:47 +01:00
{
2021-08-03 08:17:01 +02:00
FillWindowPixelBuffer(WIN_TMHM_INFO_ICONS, PIXEL_FILL(0));
BlitMenuInfoIcon(WIN_TMHM_INFO_ICONS, MENU_INFO_ICON_TYPE, 0, 0);
BlitMenuInfoIcon(WIN_TMHM_INFO_ICONS, MENU_INFO_ICON_POWER, 0, 12);
BlitMenuInfoIcon(WIN_TMHM_INFO_ICONS, MENU_INFO_ICON_ACCURACY, 0, 24);
BlitMenuInfoIcon(WIN_TMHM_INFO_ICONS, MENU_INFO_ICON_PP, 0, 36);
2021-11-03 20:29:18 +01:00
CopyWindowToVram(WIN_TMHM_INFO_ICONS, COPYWIN_GFX);
2018-02-05 05:47:47 +01:00
}
2021-08-03 08:17:01 +02:00
static void PrintTMHMMoveData(u16 itemId)
2018-02-05 05:47:47 +01:00
{
u8 i;
u16 moveId;
const u8 *text;
2018-02-14 01:12:17 +01:00
2021-08-03 08:17:01 +02:00
FillWindowPixelBuffer(WIN_TMHM_INFO, PIXEL_FILL(0));
2018-02-05 05:47:47 +01:00
if (itemId == ITEM_NONE)
{
2018-02-12 19:59:42 +01:00
for (i = 0; i < 4; i++)
BagMenu_Print(WIN_TMHM_INFO, FONT_NORMAL, gText_ThreeDashes, 7, i * 12, 0, 0, TEXT_SKIP_DRAW, COLORID_TMHM_INFO);
2021-11-03 20:29:18 +01:00
CopyWindowToVram(WIN_TMHM_INFO, COPYWIN_GFX);
2018-02-05 05:47:47 +01:00
}
else
{
moveId = ItemIdToBattleMoveId(itemId);
2021-08-03 08:17:01 +02:00
BlitMenuInfoIcon(WIN_TMHM_INFO, gBattleMoves[moveId].type + 1, 0, 0);
2021-08-03 08:17:01 +02:00
// Print TMHM power
2018-02-05 05:47:47 +01:00
if (gBattleMoves[moveId].power <= 1)
2018-02-09 03:00:28 +01:00
{
2018-02-05 05:47:47 +01:00
text = gText_ThreeDashes;
2018-02-09 03:00:28 +01:00
}
2018-02-05 05:47:47 +01:00
else
{
2019-09-30 21:43:44 +02:00
ConvertIntToDecimalStringN(gStringVar1, gBattleMoves[moveId].power, STR_CONV_MODE_RIGHT_ALIGN, 3);
2018-02-05 05:47:47 +01:00
text = gStringVar1;
}
BagMenu_Print(WIN_TMHM_INFO, FONT_NORMAL, text, 7, 12, 0, 0, TEXT_SKIP_DRAW, COLORID_TMHM_INFO);
2021-08-03 08:17:01 +02:00
// Print TMHM accuracy
2018-02-05 05:47:47 +01:00
if (gBattleMoves[moveId].accuracy == 0)
2018-02-09 03:00:28 +01:00
{
2018-02-05 05:47:47 +01:00
text = gText_ThreeDashes;
2018-02-09 03:00:28 +01:00
}
2018-02-05 05:47:47 +01:00
else
{
2019-09-30 21:43:44 +02:00
ConvertIntToDecimalStringN(gStringVar1, gBattleMoves[moveId].accuracy, STR_CONV_MODE_RIGHT_ALIGN, 3);
2018-02-05 05:47:47 +01:00
text = gStringVar1;
}
BagMenu_Print(WIN_TMHM_INFO, FONT_NORMAL, text, 7, 24, 0, 0, TEXT_SKIP_DRAW, COLORID_TMHM_INFO);
2021-08-03 08:17:01 +02:00
// Print TMHM pp
2019-09-30 21:43:44 +02:00
ConvertIntToDecimalStringN(gStringVar1, gBattleMoves[moveId].pp, STR_CONV_MODE_RIGHT_ALIGN, 3);
BagMenu_Print(WIN_TMHM_INFO, FONT_NORMAL, gStringVar1, 7, 36, 0, 0, TEXT_SKIP_DRAW, COLORID_TMHM_INFO);
2021-08-03 08:17:01 +02:00
2021-11-03 20:29:18 +01:00
CopyWindowToVram(WIN_TMHM_INFO, COPYWIN_GFX);
2018-02-05 05:47:47 +01:00
}
}