pokeemerald/src/item_menu.c

2421 lines
70 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"
#include "constants/items.h"
#include "constants/songs.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"
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"
#include "string.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"
2019-04-04 23:05:46 +02:00
#include "constants/rgb.h"
2018-11-01 21:31:10 +01:00
2018-01-30 19:19:37 +01:00
void GoToBagMenu(u8 bagMenuType, u8 pocketId, void ( *postExitMenuMainCallback2)());
void CB2_Bag(void);
bool8 SetupBagMenu(void);
void BagMenu_InitBGs(void);
bool8 LoadBagMenu_Graphics(void);
void SetupBagMenu_Textboxes(void);
void AllocateBagItemListBuffers(void);
void LoadBagItemListBuffers(u8);
void BagMenu_PrintPocketNames(const u8*, const u8*);
void BagMenu_CopyPocketNameToWindow(u32);
void BagMenu_DrawPocketIndicatorSquare(u8, u8);
2018-01-30 19:19:37 +01:00
void bag_menu_add_pocket_scroll_arrow_indicators_maybe(void);
void bag_menu_add_list_scroll_arrow_indicators_maybe(void);
void BagMenu_PrepareTMHMMoveWindow(void);
2018-01-30 19:19:37 +01:00
bool8 IsWallysBag(void);
void Task_WallyTutorialBagMenu(u8);
void Task_BagMenu(u8);
void GetItemName(s8*, u16);
2018-01-30 19:19:37 +01:00
u16 ItemIdToBattleMoveId(u16);
u16 BagGetItemIdByPocketPosition(u8, u16);
void BagMenu_PrintDescription(int);
void BagMenu_PrintCursor(u8, u8);
void BagMenu_Print(u8, u8, const u8*, u8, u8, u8, u8, u8, u8);
2018-04-29 13:36:26 +02:00
bool8 ItemId_GetImportance(u16);
2018-01-30 19:19:37 +01:00
u16 BagGetQuantityByPocketPosition(u8, u16);
void sub_81AB89C(void);
void TaskCloseBagMenu_2(u8);
2018-01-30 19:19:37 +01:00
u8 AddItemMessageWindow(u8);
void bag_menu_RemoveBagItem_message_window(u8);
void set_callback3_to_bag(u8);
void PrintItemDepositAmount(u8, s16);
u8 BagMenu_AddWindow(u8);
2018-01-30 19:19:37 +01:00
u8 GetSwitchBagPocketDirection(void);
2018-02-01 02:22:51 +01:00
void SwitchBagPocket(u8, s16, u16);
2018-01-30 19:19:37 +01:00
bool8 sub_81AC2C0(void);
void BagMenu_SwapItems(u8);
2018-02-01 02:22:51 +01:00
void sub_81AC10C(u8);
2018-02-05 05:47:47 +01:00
void sub_81AC3C0(u8);
void sub_81AC498(u8);
void sub_81AC590(u8);
void PrintTMHMMoveData(u16);
void sub_81ACAF8(u8);
void sub_81ACB54(u8, u8, u8);
void Task_HandleInBattleItemMenuInput(u8);
void Task_HandleOutOfBattleItemMenuInput(u8);
bool8 sub_81ACDFC(s8);
void BagMenu_RemoveWindow(u8);
void BagMenu_PrintThereIsNoPokemon(u8);
2018-02-05 05:47:47 +01:00
void Task_ChooseHowManyToToss(u8);
void BagMenu_TossItems(u8);
void BagMenu_YesNo(u8, u8, const struct YesNoFuncTable*);
2018-02-05 05:47:47 +01:00
void Task_ActuallyToss(u8);
void ItemMenu_Cancel(u8);
void sub_81AD350(u8);
void BagMenu_PrintItemCantBeHeld(u8);
2018-02-05 05:47:47 +01:00
void bag_menu_AddMoney_window(void);
void sub_81AD680(u8);
void sub_81AD730(u8);
void sub_81AD6E4(u8);
void bag_menu_remove_money_window(void);
void bag_menu_RemoveBagItem_message_window(u8);
void sub_81AD794(u8);
void sub_81AD8C8(u8);
void sub_81AD9C0(u8);
void sub_81ADB14(u8);
void sub_81ADA7C(u8);
void sub_81ADC0C(u8);
2019-11-19 17:36:38 +01:00
void CB2_ApprenticeExitBagMenu(void);
2019-08-06 02:37:09 +02:00
void CB2_FavorLadyExitBagMenu(void);
void CB2_QuizLadyExitBagMenu(void);
2018-02-09 03:00:28 +01:00
void sub_81ABA6C(void);
2018-12-15 19:08:13 +01:00
static void SetPocketListPositions(void);
2018-02-09 03:00:28 +01:00
void sub_81ABAE0(void);
u8 sub_81AB1F0(u8);
void sub_81AC23C(u8);
void BagMenu_MoveCursorCallback(s32 a, bool8 b, struct ListMenu*);
2019-07-19 02:46:00 +02:00
void PrintItemQuantityPlusGFX(u8 rboxId, s32 item_index_in_pocket, u8 a);
2018-02-12 19:59:42 +01:00
void ItemMenu_UseOutOfBattle(u8 taskId);
void ItemMenu_Toss(u8 taskId);
void ItemMenu_Register(u8 taskId);
void ItemMenu_Give(u8 taskId);
void ItemMenu_Cancel(u8 taskId);
void ItemMenu_UseInBattle(u8 taskId);
void ItemMenu_CheckTag(u8 taskId);
void unknown_ItemMenu_Confirm(u8 taskId);
void unknown_ItemMenu_Show(u8 taskId);
void unknown_ItemMenu_Give2(u8 taskId);
void unknown_ItemMenu_Confirm2(u8 taskId);
void unknown_item_menu_type(u8 taskId);
void item_menu_type_2(u8 taskId);
void DisplaySellItemAskString(u8 taskId);
void DisplayDepositItemAskString(u8 taskId);
2018-02-12 19:59:42 +01:00
void item_menu_type_b(u8 taskId);
void BagMenu_ConfirmToss(u8 taskId);
void BagMenu_CancelToss(u8 taskId);
void BagMenu_ConfirmSell(u8 taskId);
void BagMenu_CancelSell(u8 taskId);
2018-02-12 19:59:42 +01:00
// .rodata
2018-12-15 19:08:13 +01:00
static const struct BgTemplate sBgTemplates_ItemMenu[3] =
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,
.itemPrintFunc = PrintItemQuantityPlusGFX,
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,
.scrollMultiple = 0,
.fontId = 7,
.cursorKind = 0
2018-02-12 19:59:42 +01:00
};
const struct MenuAction sItemMenuActions[] = {
2018-02-14 01:12:17 +01:00
{gMenuText_Use, ItemMenu_UseOutOfBattle},
{gMenuText_Toss, ItemMenu_Toss},
{gMenuText_Register, ItemMenu_Register},
2018-02-12 19:59:42 +01:00
{gMenuText_Give, ItemMenu_Give},
{gText_Cancel2, ItemMenu_Cancel},
{gMenuText_Use, ItemMenu_UseInBattle},
{gMenuText_Check, ItemMenu_UseOutOfBattle},
{gMenuText_Walk, ItemMenu_UseOutOfBattle},
{gMenuText_Deselect, ItemMenu_Register},
{gMenuText_CheckTag, ItemMenu_CheckTag},
{gMenuText_Confirm, unknown_ItemMenu_Confirm},
{gMenuText_Show, unknown_ItemMenu_Show},
{gMenuText_Give2, unknown_ItemMenu_Give2},
{gMenuText_Confirm, unknown_ItemMenu_Confirm2},
{gText_EmptyString2, NULL}
};
const u8 gUnknown_0861402C[] = {0, 3, 1, 4};
const u8 gUnknown_08614030[] = {0, 2, 14, 4};
const u8 gUnknown_08614034[] = {3, 14, 1, 4};
const u8 gUnknown_08614038[] = {0, 3, 14, 4};
const u8 gUnknown_0861403C[] = {9, 14, 0, 3, 1, 4};
const u8 gUnknown_08614042[] = {5, 4};
const u8 gUnknown_08614044[] = {3, 4};
const u8 gUnknown_08614046 = 4;
const u8 gUnknown_08614047[] = {10, 9, 14, 4};
const u8 gUnknown_0861404B[] = {11, 4};
const u8 gUnknown_0861404D[] = {12, 4};
const u8 gUnknown_0861404F[] = {13, 4};
const TaskFunc gUnknown_08614054[] = {
unknown_item_menu_type,
unknown_item_menu_type,
item_menu_type_2,
DisplaySellItemAskString,
2018-02-12 19:59:42 +01:00
unknown_ItemMenu_Confirm,
unknown_item_menu_type,
DisplayDepositItemAskString,
2018-02-12 19:59:42 +01:00
unknown_item_menu_type,
unknown_item_menu_type,
unknown_item_menu_type,
NULL,
item_menu_type_b
};
const struct YesNoFuncTable sYesNoTossFunctions = {BagMenu_ConfirmToss, BagMenu_CancelToss};
2018-02-12 19:59:42 +01:00
const struct YesNoFuncTable sYesNoSellItemFunctions = {BagMenu_ConfirmSell, BagMenu_CancelSell};
2018-02-12 19:59:42 +01:00
const struct ScrollArrowsTemplate gBagScrollArrowsTemplate = {SCROLL_ARROW_LEFT, 0x1C, 16, SCROLL_ARROW_RIGHT, 100, 16, -1, -1, 0x6F, 0x6F, 0};
2018-02-12 19:59:42 +01:00
const u8 gUnknown_086140A4[] = INCBIN_U8("graphics/interface/select_button.4bpp");
2018-12-15 19:08:13 +01:00
static const u8 sFontColorTable[][3] = {
// bgColor, textColor, shadowColor
2018-02-14 01:12:17 +01:00
{0, 1, 3},
2018-02-12 19:59:42 +01:00
{0, 1, 4},
{0, 3, 6},
{2, 1, 3},
{0, 14, 10}
};
2018-09-02 15:49:29 +02:00
const struct WindowTemplate gUnknown_08614174[] =
{
2018-12-15 19:08:13 +01:00
{ // Item names
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,
},
2018-12-15 19:08:13 +01:00
{ // 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,
},
2018-12-15 19:08:13 +01:00
{ // 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,
},
2018-12-15 19:08:13 +01:00
{ // TM/HM 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,
},
2018-12-15 19:08:13 +01:00
{// TM/HM 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,
},
2018-12-15 19:08:13 +01:00
{ // Field message box
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
};
2018-09-02 15:49:29 +02:00
const struct WindowTemplate gUnknown_086141AC[] =
{
{
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,
},
{
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,
},
{
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,
},
{
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,
},
{
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,
},
{
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,
},
{
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,
},
{
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,
},
{
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,
},
{
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
};
// .text
struct ListBuffer1 {
struct ListMenuItem subBuffers[65];
};
struct ListBuffer2 {
s8 name[65][24];
};
struct TempWallyStruct {
struct ItemSlot bagPocket_Items[30];
struct ItemSlot bagPocket_PokeBalls[16];
2018-12-10 10:32:00 +01:00
u16 cursorPosition[POCKETS_COUNT];
u16 scrollPosition[POCKETS_COUNT];
2018-02-12 19:59:42 +01:00
u8 filler[0x2];
u16 pocket;
};
EWRAM_DATA struct BagMenuStruct *gBagMenu = 0;
EWRAM_DATA struct BagStruct gBagPositionStruct = {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;
2018-12-15 19:08:13 +01:00
static EWRAM_DATA struct TempWallyStruct *gUnknown_0203CE80 = 0;
2018-02-12 19:59:42 +01:00
2018-12-15 19:08:13 +01:00
extern u8 *const gPocketNamesStringsTable[];
2018-01-30 19:19:37 +01:00
extern u8* gReturnToXStringsTable[];
extern const u8 EventScript_SelectWithoutRegisteredItem[];
2018-02-12 20:06:52 +01:00
extern const u16 gUnknown_0860F074[];
2018-01-30 19:19:37 +01:00
void ResetBagScrollPositions(void)
{
gBagPositionStruct.pocket = ITEMS_POCKET;
memset(gBagPositionStruct.cursorPosition, 0, 10);
memset(gBagPositionStruct.scrollPosition, 0, 10);
2018-01-30 19:19:37 +01:00
}
void CB2_BagMenuFromStartMenu(void)
{
2018-12-10 17:39:57 +01:00
GoToBagMenu(RETURN_LOCATION_FIELD, POCKETS_COUNT, CB2_ReturnToFieldWithOpenMenu);
2018-01-30 19:19:37 +01:00
}
void sub_81AABB0(void)
{
if (!InBattlePyramid())
2019-10-18 01:22:03 +02:00
GoToBagMenu(RETURN_LOCATION_BATTLE, POCKETS_COUNT, CB2_SetUpReshowBattleScreenAfterMenu2);
2018-01-30 19:19:37 +01:00
else
2019-10-18 01:22:03 +02:00
GoToBattlePyramidBagMenu(1, CB2_SetUpReshowBattleScreenAfterMenu2);
2018-01-30 19:19:37 +01:00
}
void CB2_ChooseBerry(void)
{
2018-12-10 17:39:57 +01:00
GoToBagMenu(RETURN_LOCATION_FIELD_2, BERRIES_POCKET, CB2_ReturnToFieldContinueScript);
2018-01-30 19:19:37 +01:00
}
void ChooseBerrySetCallback(void (*callback)(void))
2018-01-30 19:19:37 +01:00
{
2018-12-10 17:39:57 +01:00
GoToBagMenu(RETURN_LOCATION_FIELD_3, BERRIES_POCKET, callback);
2018-01-30 19:19:37 +01:00
}
void CB2_GoToSellMenu(void)
{
2018-12-10 17:39:57 +01:00
GoToBagMenu(RETURN_LOCATION_SHOP, POCKETS_COUNT, CB2_ExitSellMenu);
2018-01-30 19:19:37 +01:00
}
void sub_81AAC14(void)
{
2018-12-10 17:39:57 +01:00
GoToBagMenu(RETURN_LOCATION_PC, POCKETS_COUNT, sub_816B31C);
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
{
2019-11-19 17:36:38 +01:00
GoToBagMenu(RETURN_LOCATION_FIELD_6, 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
{
2019-08-06 02:37:09 +02:00
GoToBagMenu(RETURN_LOCATION_FIELD_4, 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
{
2019-08-06 02:37:09 +02:00
GoToBagMenu(RETURN_LOCATION_FIELD_5, POCKETS_COUNT, CB2_QuizLadyExitBagMenu);
2019-11-20 23:36:52 +01:00
gSpecialVar_Result = FALSE;
2018-01-30 19:19:37 +01:00
}
void GoToBagMenu(u8 bagMenuType, u8 pocketId, void ( *postExitMenuMainCallback2)())
{
u8 temp;
gBagMenu = AllocZeroed(sizeof(struct BagMenuStruct));
if (gBagMenu == 0)
2018-02-09 03:00:28 +01:00
{
2018-01-30 19:19:37 +01:00
SetMainCallback2(postExitMenuMainCallback2);
2018-02-09 03:00:28 +01:00
}
2018-01-30 19:19:37 +01:00
else
{
2018-12-10 17:39:57 +01:00
if (bagMenuType != RETURN_LOCATION_UNCHANGED)
gBagPositionStruct.location = bagMenuType;
2018-01-30 19:19:37 +01:00
if (postExitMenuMainCallback2)
gBagPositionStruct.bagCallback = postExitMenuMainCallback2;
2018-12-10 17:39:57 +01:00
if (pocketId < POCKETS_COUNT)
gBagPositionStruct.pocket = pocketId;
temp = gBagPositionStruct.location - (POCKETS_COUNT - 1);
2018-01-30 19:19:37 +01:00
if (temp <= 1)
gBagMenu->unk81B = 1;
gBagMenu->mainCallback2 = 0;
gBagMenu->unk81A = 0xFF;
gBagMenu->unk81E = -1;
gBagMenu->unk81F = -1;
memset(gBagMenu->spriteId, 0xFF, sizeof(gBagMenu->spriteId));
memset(gBagMenu->windowPointers, 0xFF, 10);
2018-01-30 19:19:37 +01:00
SetMainCallback2(CB2_Bag);
}
}
void c2_bag_3(void)
{
RunTasks();
AnimateSprites();
BuildOamBuffer();
do_scheduled_bg_tilemap_copies_to_vram();
UpdatePaletteFade();
}
void vblank_cb_bag_menu(void)
{
LoadOam();
ProcessSpriteCopyRequests();
TransferPlttBuffer();
}
void CB2_Bag(void)
{
while(sub_81221EC() != TRUE && SetupBagMenu() != TRUE && sub_81221AC() != TRUE) {};
2018-01-30 19:19:37 +01:00
}
bool8 SetupBagMenu(void)
2018-01-30 19:19:37 +01:00
{
u32 index;
u8 taskId;
switch (gMain.state)
{
case 0:
SetVBlankHBlankCallbacksToNull();
clear_scheduled_bg_copies_to_vram();
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 (sub_81221AC() == FALSE)
ResetTasks();
gMain.state++;
break;
case 7:
BagMenu_InitBGs();
gBagMenu->unk834 = 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:
SetupBagMenu_Textboxes();
2018-01-30 19:19:37 +01:00
gMain.state++;
break;
case 10:
sub_81ABA6C();
2018-12-15 19:08:13 +01:00
SetPocketListPositions();
2018-01-30 19:19:37 +01:00
sub_81ABAE0();
gMain.state++;
break;
case 11:
AllocateBagItemListBuffers();
2018-01-30 19:19:37 +01:00
gMain.state++;
break;
case 12:
LoadBagItemListBuffers(gBagPositionStruct.pocket);
2018-01-30 19:19:37 +01:00
gMain.state++;
break;
case 13:
BagMenu_PrintPocketNames(gPocketNamesStringsTable[gBagPositionStruct.pocket], 0);
BagMenu_CopyPocketNameToWindow(0);
BagMenu_DrawPocketIndicatorSquare(gBagPositionStruct.pocket, 1);
2018-01-30 19:19:37 +01:00
gMain.state++;
break;
case 14:
taskId = sub_81AB1F0(gBagPositionStruct.location);
gTasks[taskId].data[0] = ListMenuInit(&gMultiuseListMenuTemplate, gBagPositionStruct.scrollPosition[gBagPositionStruct.pocket], gBagPositionStruct.cursorPosition[gBagPositionStruct.pocket]);
2018-01-30 19:19:37 +01:00
gTasks[taskId].data[3] = 0;
gTasks[taskId].data[8] = 0;
gMain.state++;
break;
case 15:
AddBagVisualSprite(gBagPositionStruct.pocket);
2018-01-30 19:19:37 +01:00
gMain.state++;
break;
case 16:
sub_80D4FAC();
gMain.state++;
break;
case 17:
bag_menu_add_pocket_scroll_arrow_indicators_maybe();
bag_menu_add_list_scroll_arrow_indicators_maybe();
gMain.state++;
break;
case 18:
BagMenu_PrepareTMHMMoveWindow();
2018-01-30 19:19:37 +01:00
gMain.state++;
break;
case 19:
BlendPalettes(-1, 16, 0);
gMain.state++;
break;
case 20:
2019-04-04 23:05:46 +02:00
BeginNormalPaletteFade(0xFFFFFFFF, 0, 16, 0, RGB_BLACK);
2018-01-30 19:19:37 +01:00
gPaletteFade.bufferTransferDisabled = FALSE;
gMain.state++;
break;
default:
SetVBlankCallback(vblank_cb_bag_menu);
SetMainCallback2(c2_bag_3);
return TRUE;
}
return FALSE;
}
void BagMenu_InitBGs(void)
2018-01-30 19:19:37 +01:00
{
ResetVramOamAndBgCntRegs();
memset(gBagMenu->tilemapBuffer, 0, 0x800);
2018-01-30 19:19:37 +01:00
ResetBgsAndClearDma3BusyFlags(0);
2018-12-15 19:08:13 +01:00
InitBgsFromTemplates(0, sBgTemplates_ItemMenu, 3);
SetBgTilemapBuffer(2, gBagMenu->tilemapBuffer);
2018-01-30 19:19:37 +01:00
ResetAllBgsCoordinates();
schedule_bg_copy_tilemap_to_vram(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);
}
bool8 LoadBagMenu_Graphics(void)
2018-01-30 19:19:37 +01:00
{
switch (gBagMenu->unk834)
2018-01-30 19:19:37 +01:00
{
case 0:
reset_temp_tile_data_buffers();
decompress_and_copy_tile_data_to_vram(2, gBagScreen_Gfx, 0, 0, 0);
gBagMenu->unk834++;
2018-01-30 19:19:37 +01:00
break;
case 1:
if (free_temp_tile_data_buffers_if_possible() != TRUE)
{
LZDecompressWram(gBagScreen_GfxTileMap, gBagMenu->tilemapBuffer);
gBagMenu->unk834++;
2018-01-30 19:19:37 +01:00
}
break;
case 2:
if (!IsWallysBag() && gSaveBlock2Ptr->playerGender != MALE)
LoadCompressedPalette(gBagScreenFemale_Pal, 0, 0x40);
else
LoadCompressedPalette(gBagScreenMale_Pal, 0, 0x40);
gBagMenu->unk834++;
2018-01-30 19:19:37 +01:00
break;
case 3:
if (IsWallysBag() == TRUE || gSaveBlock2Ptr->playerGender == MALE)
LoadCompressedSpriteSheet(&gBagMaleSpriteSheet);
2018-01-30 19:19:37 +01:00
else
LoadCompressedSpriteSheet(&gBagFemaleSpriteSheet);
gBagMenu->unk834++;
2018-01-30 19:19:37 +01:00
break;
case 4:
LoadCompressedSpritePalette(&gBagPaletteTable);
gBagMenu->unk834++;
2018-01-30 19:19:37 +01:00
break;
default:
LoadListMenuArrowsGfx();
gBagMenu->unk834 = 0;
2018-01-30 19:19:37 +01:00
return TRUE;
}
return FALSE;
}
u8 sub_81AB1F0(u8 a)
{
u8 taskId;
if (a == 10)
taskId = CreateTask(Task_WallyTutorialBagMenu, 0);
else
taskId = CreateTask(Task_BagMenu, 0);
return taskId;
}
void AllocateBagItemListBuffers(void)
2018-01-30 19:19:37 +01:00
{
2018-12-15 19:08:13 +01:00
sListBuffer1 = Alloc(sizeof(struct ListBuffer1));
sListBuffer2 = Alloc(sizeof(struct ListBuffer2));
2018-01-30 19:19:37 +01:00
}
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];
2018-01-30 19:19:37 +01:00
subBuffer[i].id = -2;
}
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
}
void GetItemName(s8 *dest, u16 itemId)
2018-01-30 19:19:37 +01:00
{
switch (gBagPositionStruct.pocket)
2018-01-30 19:19:37 +01:00
{
2018-12-10 10:32:00 +01:00
case TMHM_POCKET:
2018-01-30 19:19:37 +01:00
StringCopy(gStringVar2, gMoveNames[ItemIdToBattleMoveId(itemId)]);
if (itemId >= ITEM_HM01)
{
2019-09-30 21:43:44 +02:00
ConvertIntToDecimalStringN(gStringVar1, itemId - ITEM_HM01 + 1, STR_CONV_MODE_LEADING_ZEROS, 1);
2018-01-30 19:19:37 +01:00
StringExpandPlaceholders(dest, gText_ClearTo11Var1Clear5Var2);
}
else
{
2019-09-30 21:43:44 +02:00
ConvertIntToDecimalStringN(gStringVar1, itemId - ITEM_TM01 + 1, STR_CONV_MODE_LEADING_ZEROS, 2);
2019-12-10 19:48:20 +01:00
StringExpandPlaceholders(dest, gText_NumberVar1Clear7Var2);
2018-01-30 19:19:37 +01:00
}
break;
2018-12-10 10:32:00 +01:00
case BERRIES_POCKET:
2019-09-30 21:43:44 +02:00
ConvertIntToDecimalStringN(gStringVar1, itemId - ITEM_CHERI_BERRY + 1, STR_CONV_MODE_LEADING_ZEROS, 2);
2018-01-30 19:19:37 +01:00
CopyItemName(itemId, gStringVar2);
2019-12-10 19:48:20 +01:00
StringExpandPlaceholders(dest, gText_NumberVar1Clear7Var2);
2018-01-30 19:19:37 +01:00
break;
default:
CopyItemName(itemId, dest);
break;
}
}
void BagMenu_MoveCursorCallback(s32 a, bool8 b, struct ListMenu *unused)
2018-01-30 19:19:37 +01:00
{
if (b != 1)
{
PlaySE(SE_SELECT);
ShakeBagVisual();
}
if (gBagMenu->unk81A == 0xFF)
2018-01-30 19:19:37 +01:00
{
RemoveBagItemIconSprite(1 ^ gBagMenu->unk81B_1);
2018-01-30 19:19:37 +01:00
if (a != -2)
AddBagItemIconSprite(BagGetItemIdByPocketPosition(gBagPositionStruct.pocket + 1, a), gBagMenu->unk81B_1);
2018-01-30 19:19:37 +01:00
else
AddBagItemIconSprite(-1, gBagMenu->unk81B_1);
gBagMenu->unk81B_1 ^= 1;
if (!gBagMenu->unk81B_3)
BagMenu_PrintDescription(a);
2018-01-30 19:19:37 +01:00
}
}
2019-07-19 02:46:00 +02:00
void PrintItemQuantityPlusGFX(u8 rboxId, s32 item_index_in_pocket, u8 a)
2018-01-30 19:19:37 +01:00
{
u16 itemId;
u16 itemQuantity;
bool8 unique;
int offset;
if (item_index_in_pocket != -2)
{
if (gBagMenu->unk81A != 0xFF)
2018-01-30 19:19:37 +01:00
{
if (gBagMenu->unk81A == (u8)item_index_in_pocket)
BagMenu_PrintCursor(a, 2);
2018-01-30 19:19:37 +01:00
else
BagMenu_PrintCursor(a, -1);
2018-01-30 19:19:37 +01:00
}
itemId = BagGetItemIdByPocketPosition(gBagPositionStruct.pocket + 1, item_index_in_pocket);
itemQuantity = BagGetQuantityByPocketPosition(gBagPositionStruct.pocket + 1, item_index_in_pocket);
if (itemId >= ITEM_HM01 && itemId <= ITEM_HM08)
2018-01-30 19:19:37 +01:00
BlitBitmapToWindow(rboxId, gBagMenuHMIcon_Gfx, 8, a - 1, 16, 16);
if (gBagPositionStruct.pocket == BERRIES_POCKET)
2018-01-30 19:19:37 +01:00
{
2019-09-30 21:43:44 +02:00
ConvertIntToDecimalStringN(gStringVar1, itemQuantity, STR_CONV_MODE_RIGHT_ALIGN, 3);
2018-01-30 19:19:37 +01:00
StringExpandPlaceholders(gStringVar4, gText_xVar1);
offset = GetStringRightAlignXOffset(7, gStringVar4, 0x77);
BagMenu_Print(rboxId, 7, gStringVar4, offset, a, 0, 0, -1, 0);
2018-01-30 19:19:37 +01:00
}
else if (gBagPositionStruct.pocket != KEYITEMS_POCKET && (unique = ItemId_GetImportance(itemId)) == FALSE)
2018-01-30 19:19:37 +01:00
{
2019-09-30 21:43:44 +02:00
ConvertIntToDecimalStringN(gStringVar1, itemQuantity, STR_CONV_MODE_RIGHT_ALIGN, 2);
2018-01-30 19:19:37 +01:00
StringExpandPlaceholders(gStringVar4, gText_xVar1);
offset = GetStringRightAlignXOffset(7, gStringVar4, 0x77);
BagMenu_Print(rboxId, 7, gStringVar4, offset, a, unique, unique, -1, unique);
2018-01-30 19:19:37 +01:00
}
else
{
if (gSaveBlock1Ptr->registeredItem && gSaveBlock1Ptr->registeredItem == itemId)
BlitBitmapToWindow(rboxId, gUnknown_086140A4, 0x60, a - 1, 0x18, 16);
}
}
}
void BagMenu_PrintDescription(int a)
2018-01-30 19:19:37 +01:00
{
const u8 *str;
2018-01-30 19:19:37 +01:00
if (a != -2)
2018-02-09 03:00:28 +01:00
{
str = ItemId_GetDescription(BagGetItemIdByPocketPosition(gBagPositionStruct.pocket + 1, a));
2018-02-09 03:00:28 +01:00
}
2018-01-30 19:19:37 +01:00
else
{
StringCopy(gStringVar1, gReturnToXStringsTable[gBagPositionStruct.location]);
2018-02-09 03:00:28 +01:00
StringExpandPlaceholders(gStringVar4, gText_ReturnToVar1);
2018-01-30 19:19:37 +01:00
str = gStringVar4;
}
FillWindowPixelBuffer(1, PIXEL_FILL(0));
BagMenu_Print(1, 1, str, 3, 1, 0, 0, 0, 0);
2018-01-30 19:19:37 +01:00
}
void BagMenu_PrintCursor_(u8 a, u8 b)
2018-01-30 19:19:37 +01:00
{
BagMenu_PrintCursor(ListMenuGetYCoordForPrintingArrowCursor(a), b);
2018-01-30 19:19:37 +01:00
}
void BagMenu_PrintCursor(u8 a, u8 b)
2018-01-30 19:19:37 +01:00
{
if (b == 0xFF)
FillWindowPixelRect(0, PIXEL_FILL(0), 0, a, GetMenuCursorDimensionByFont(1, 0), GetMenuCursorDimensionByFont(1, 1));
2018-01-30 19:19:37 +01:00
else
BagMenu_Print(0, 1, gText_SelectorArrow2, 0, a, 0, 0, 0, b);
2018-01-30 19:19:37 +01:00
}
void bag_menu_add_pocket_scroll_arrow_indicators_maybe(void)
{
if (gBagMenu->unk81E == 0xFF)
gBagMenu->unk81E = AddScrollIndicatorArrowPairParameterized(SCROLL_ARROW_UP, 0xAC, 12, 0x94, gBagMenu->numItemStacks[gBagPositionStruct.pocket] - gBagMenu->numShownItems[gBagPositionStruct.pocket], 0x6E, 0x6E, &gBagPositionStruct.scrollPosition[gBagPositionStruct.pocket]);
2018-01-30 19:19:37 +01:00
}
void sub_81AB824(void)
{
if (gBagMenu->unk81E != 0xFF)
2018-01-30 19:19:37 +01:00
{
RemoveScrollIndicatorArrowPair(gBagMenu->unk81E);
gBagMenu->unk81E = 0xFF;
2018-01-30 19:19:37 +01:00
}
sub_81AB89C();
}
void bag_menu_add_list_scroll_arrow_indicators_maybe(void)
{
if (gBagMenu->unk81B != 1 && gBagMenu->unk81F == 0xFF)
gBagMenu->unk81F = AddScrollIndicatorArrowPair(&gBagScrollArrowsTemplate, &gBagPositionStruct.unk6);
2018-01-30 19:19:37 +01:00
}
void sub_81AB89C(void)
{
if (gBagMenu->unk81F != 0xFF)
2018-01-30 19:19:37 +01:00
{
RemoveScrollIndicatorArrowPair(gBagMenu->unk81F);
gBagMenu->unk81F = 0xFF;
2018-01-30 19:19:37 +01:00
}
}
void FreeBagItemListBuffers(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 unknown_ItemMenu_Confirm(u8 taskId)
{
2019-04-04 23:05:46 +02:00
BeginNormalPaletteFade(0xFFFFFFFF, 0, 0, 16, RGB_BLACK);
gTasks[taskId].func = TaskCloseBagMenu_2;
2018-01-30 19:19:37 +01:00
}
void TaskCloseBagMenu_2(u8 taskId)
2018-01-30 19:19:37 +01:00
{
s16* data = gTasks[taskId].data;
if (!gPaletteFade.active)
{
DestroyListMenuTask(data[0], &gBagPositionStruct.scrollPosition[gBagPositionStruct.pocket], &gBagPositionStruct.cursorPosition[gBagPositionStruct.pocket]);
if (gBagMenu->mainCallback2 != 0)
SetMainCallback2(gBagMenu->mainCallback2);
2018-01-30 19:19:37 +01:00
else
SetMainCallback2(gBagPositionStruct.bagCallback);
2018-01-30 19:19:37 +01:00
sub_81AB824();
ResetSpriteData();
FreeAllSpritePalettes();
FreeBagItemListBuffers();
2018-01-30 19:19:37 +01:00
DestroyTask(taskId);
}
}
void sub_81AB9A8(u8 pocketId)
{
u16 i;
struct BagPocket *pocket = &gBagPockets[pocketId];
switch (pocketId)
{
2018-12-10 10:32:00 +01:00
case TMHM_POCKET:
case BERRIES_POCKET:
2018-04-29 13:36:26 +02:00
SortBerriesOrTMHMs(pocket);
2018-01-30 19:19:37 +01:00
break;
default:
2018-04-29 13:36:26 +02:00
CompactItemsInBagPocket(pocket);
2018-01-30 19:19:37 +01:00
break;
}
gBagMenu->numItemStacks[pocketId] = 0;
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
if (gBagMenu->numItemStacks[pocketId] > 8)
gBagMenu->numShownItems[pocketId] = 8;
2018-01-30 19:19:37 +01:00
else
gBagMenu->numShownItems[pocketId] = gBagMenu->numItemStacks[pocketId];
2018-01-30 19:19:37 +01:00
}
void sub_81ABA6C(void)
{
u8 i;
2018-12-10 10:32:00 +01:00
for (i = 0; i < POCKETS_COUNT; i++)
2018-01-30 19:19:37 +01:00
sub_81AB9A8(i);
}
2018-12-15 19:08:13 +01:00
void SetInitialScrollAndCursorPositions(u8 pocketId)
2018-01-30 19:19:37 +01:00
{
sub_812225C(&gBagPositionStruct.scrollPosition[pocketId], &gBagPositionStruct.cursorPosition[pocketId], gBagMenu->numShownItems[pocketId], gBagMenu->numItemStacks[pocketId]);
2018-01-30 19:19:37 +01:00
}
2018-12-15 19:08:13 +01:00
static void SetPocketListPositions(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++)
2018-12-15 19:08:13 +01:00
SetInitialScrollAndCursorPositions(i);
2018-01-30 19:19:37 +01:00
}
void sub_81ABAE0(void)
{
u8 i;
2018-12-10 10:32:00 +01:00
for (i = 0; i < POCKETS_COUNT; i++)
sub_8122298(&gBagPositionStruct.scrollPosition[i], &gBagPositionStruct.cursorPosition[i], gBagMenu->numShownItems[i], gBagMenu->numItemStacks[i], 8);
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
{
return gBagPositionStruct.scrollPosition[pocketId] + gBagPositionStruct.cursorPosition[pocketId];
2018-01-30 19:19:37 +01:00
}
2018-02-12 19:59:42 +01: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
2018-01-30 19:19:37 +01:00
data[10] = AddItemMessageWindow(4);
FillWindowPixelBuffer(data[10], PIXEL_FILL(1));
2018-11-06 18:30:21 +01:00
DisplayMessageAndContinueTask(taskId, data[10], 10, 13, fontId, GetPlayerTextSpeedDelay(), str, callback);
2018-01-30 19:19:37 +01:00
schedule_bg_copy_tilemap_to_vram(1);
}
void BagMenu_InitListsMenu(u8 taskId)
2018-01-30 19:19:37 +01:00
{
s16* data = gTasks[taskId].data;
u16* scrollPos = &gBagPositionStruct.scrollPosition[gBagPositionStruct.pocket];
u16* cursorPos = &gBagPositionStruct.cursorPosition[gBagPositionStruct.pocket];
2018-01-30 19:19:37 +01:00
bag_menu_RemoveBagItem_message_window(4);
2018-03-02 16:34:31 +01:00
DestroyListMenuTask(data[0], scrollPos, cursorPos);
sub_81AB9A8(gBagPositionStruct.pocket);
SetInitialScrollAndCursorPositions(gBagPositionStruct.pocket);
LoadBagItemListBuffers(gBagPositionStruct.pocket);
2018-02-05 05:47:47 +01:00
data[0] = ListMenuInit(&gMultiuseListMenuTemplate, *scrollPos, *cursorPos);
2018-01-30 19:19:37 +01:00
schedule_bg_copy_tilemap_to_vram(0);
set_callback3_to_bag(taskId);
}
void sub_81ABC3C(u8 a)
{
PrintItemDepositAmount(BagMenu_AddWindow(a), 1);
2018-01-30 19:19:37 +01:00
}
2019-09-30 21:53:24 +02:00
void PrintItemDepositAmount(u8 windowId, s16 numDeposited)
2018-01-30 19:19:37 +01:00
{
2019-09-30 21:53:24 +02:00
u8 numDigits = (gBagPositionStruct.pocket == BERRIES_POCKET) ? 3 : 2;
ConvertIntToDecimalStringN(gStringVar1, numDeposited, STR_CONV_MODE_LEADING_ZEROS, numDigits);
2018-01-30 19:19:37 +01:00
StringExpandPlaceholders(gStringVar4, gText_xVar1);
2019-09-30 21:53:24 +02:00
AddTextPrinterParameterized(windowId, 1, gStringVar4, GetStringCenterAlignXOffset(1, gStringVar4, 0x28), 2, 0, 0);
2018-01-30 19:19:37 +01:00
}
2019-09-30 21:53:24 +02:00
void PrintItemSoldAmount(int windowId, int numSold, int moneyEarned)
2018-01-30 19:19:37 +01:00
{
2019-09-30 21:53:24 +02:00
u8 numDigits = (gBagPositionStruct.pocket == BERRIES_POCKET) ? 3 : 2;
ConvertIntToDecimalStringN(gStringVar1, numSold, STR_CONV_MODE_LEADING_ZEROS, numDigits);
2018-01-30 19:19:37 +01:00
StringExpandPlaceholders(gStringVar4, gText_xVar1);
2019-09-30 21:53:24 +02:00
AddTextPrinterParameterized(windowId, 1, gStringVar4, 0, 1, -1, 0);
PrintMoneyAmount(windowId, 38, 1, moneyEarned, 0);
2018-01-30 19:19:37 +01:00
}
2018-01-30 22:12:40 +01:00
void Task_BagMenu(u8 taskId)
2018-01-30 19:19:37 +01:00
{
s16* data = gTasks[taskId].data;
u16* scrollPos = &gBagPositionStruct.scrollPosition[gBagPositionStruct.pocket];
u16* cursorPos = &gBagPositionStruct.cursorPosition[gBagPositionStruct.pocket];
2018-01-30 19:19:37 +01:00
u16 select;
if (sub_81221EC() != TRUE && !gPaletteFade.active)
{
switch (GetSwitchBagPocketDirection())
{
case 1:
SwitchBagPocket(taskId, -1, 0);
return;
case 2:
SwitchBagPocket(taskId, 1, 0);
return;
}
if ((select = (gMain.newKeys & SELECT_BUTTON)))
{
2018-01-30 21:26:46 +01:00
if (sub_81AC2C0() == 1)
2018-01-30 19:19:37 +01:00
{
2018-03-02 16:34:31 +01:00
ListMenuGetScrollAndRow(data[0], scrollPos, cursorPos);
if ((*scrollPos + *cursorPos) != gBagMenu->numItemStacks[gBagPositionStruct.pocket] - 1)
2018-01-30 19:19:37 +01:00
{
PlaySE(SE_SELECT);
BagMenu_SwapItems(taskId);
2018-01-30 19:19:37 +01:00
}
}
return;
}
else
{
2019-02-02 11:04:38 +01:00
int listPosition = ListMenu_ProcessInput(data[0]);
2018-03-02 16:34:31 +01:00
ListMenuGetScrollAndRow(data[0], scrollPos, cursorPos);
2018-12-15 19:08:13 +01:00
switch (listPosition)
2018-01-30 19:19:37 +01:00
{
2018-12-15 19:08:13 +01:00
case LIST_NOTHING_CHOSEN:
2018-01-30 22:12:40 +01:00
break;
case LIST_CANCEL:
if (gBagPositionStruct.location == 5)
2018-01-30 21:26:46 +01:00
{
PlaySE(SE_HAZURE);
2018-01-30 22:12:40 +01:00
break;
2018-01-30 21:26:46 +01:00
}
2018-01-30 22:12:40 +01:00
PlaySE(SE_SELECT);
gSpecialVar_ItemId = select;
gTasks[taskId].func = unknown_ItemMenu_Confirm;
break;
2018-12-15 19:08:13 +01:00
default: // A_BUTTON
2018-01-30 19:19:37 +01:00
PlaySE(SE_SELECT);
sub_81AB824();
BagMenu_PrintCursor_(data[0], 2);
2018-12-15 19:08:13 +01:00
data[1] = listPosition;
data[2] = BagGetQuantityByPocketPosition(gBagPositionStruct.pocket + 1, listPosition);
gSpecialVar_ItemId = BagGetItemIdByPocketPosition(gBagPositionStruct.pocket + 1, listPosition);
gUnknown_08614054[gBagPositionStruct.location](taskId);
2018-02-09 03:00:28 +01:00
break;
2018-01-30 19:19:37 +01:00
}
}
}
2018-01-30 22:12:40 +01:00
}
void set_callback3_to_bag(u8 taskId)
{
bag_menu_add_pocket_scroll_arrow_indicators_maybe();
bag_menu_add_list_scroll_arrow_indicators_maybe();
ClearWindowTilemap(3);
ClearWindowTilemap(4);
PutWindowTilemap(1);
schedule_bg_copy_tilemap_to_vram(0);
gTasks[taskId].func = Task_BagMenu;
}
2018-02-01 02:22:51 +01:00
u8 GetSwitchBagPocketDirection(void)
{
u8 LRKeys;
if (gBagMenu->unk81B != 0)
2018-02-01 02:22:51 +01:00
return 0;
2019-10-18 01:22:03 +02:00
LRKeys = GetLRKeysPressed();
if ((gMain.newKeys & DPAD_LEFT) || LRKeys == MENU_L_PRESSED)
2018-02-01 02:22:51 +01:00
{
PlaySE(SE_SELECT);
return 1;
}
2019-10-18 01:22:03 +02:00
if ((gMain.newKeys & DPAD_RIGHT) || LRKeys == MENU_R_PRESSED)
2018-02-01 02:22:51 +01:00
{
PlaySE(SE_SELECT);
return 2;
}
return 0;
}
void ChangeBagPocketId(u8 *bagPocketId, s8 deltaBagPocketId)
{
2018-12-10 10:32:00 +01:00
if (deltaBagPocketId == 1 && *bagPocketId == POCKETS_COUNT - 1)
2018-02-01 02:22:51 +01:00
*bagPocketId = 0;
else if (deltaBagPocketId == -1 && *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;
}
void SwitchBagPocket(u8 taskId, s16 deltaBagPocketId, u16 a3)
{
s16* data = gTasks[taskId].data;
u8 pocketId;
data[13] = 0;
data[12] = 0;
data[11] = deltaBagPocketId;
if (a3 == 0)
{
ClearWindowTilemap(0);
ClearWindowTilemap(1);
DestroyListMenuTask(data[0], &gBagPositionStruct.scrollPosition[gBagPositionStruct.pocket], &gBagPositionStruct.cursorPosition[gBagPositionStruct.pocket]);
2018-02-01 02:22:51 +01:00
schedule_bg_copy_tilemap_to_vram(0);
gSprites[gBagMenu->spriteId[2 + (gBagMenu->unk81B_1 ^ 1)]].invisible = TRUE;
2018-02-01 02:22:51 +01:00
sub_81AB824();
}
pocketId = gBagPositionStruct.pocket;
2018-02-01 02:22:51 +01:00
ChangeBagPocketId(&pocketId, deltaBagPocketId);
if (deltaBagPocketId == 1)
{
BagMenu_PrintPocketNames(gPocketNamesStringsTable[gBagPositionStruct.pocket], gPocketNamesStringsTable[pocketId]);
BagMenu_CopyPocketNameToWindow(0);
2018-02-01 02:22:51 +01:00
}
else
{
BagMenu_PrintPocketNames(gPocketNamesStringsTable[pocketId], gPocketNamesStringsTable[gBagPositionStruct.pocket]);
BagMenu_CopyPocketNameToWindow(8);
2018-02-01 02:22:51 +01:00
}
BagMenu_DrawPocketIndicatorSquare(gBagPositionStruct.pocket, 0);
BagMenu_DrawPocketIndicatorSquare(pocketId, 1);
2018-02-01 02:22:51 +01:00
FillBgTilemapBufferRect_Palette0(2, 11, 14, 2, 15, 16);
schedule_bg_copy_tilemap_to_vram(2);
SetBagVisualPocketId(pocketId, 1);
2018-03-04 18:41:07 +01:00
RemoveBagSprite(1);
AddSwitchPocketRotatingBallSprite(deltaBagPocketId);
2018-02-01 02:22:51 +01:00
SetTaskFuncWithFollowupFunc(taskId, sub_81AC10C, gTasks[taskId].func);
}
void sub_81AC10C(u8 taskId)
{
s16* data = gTasks[taskId].data;
2018-02-14 01:12:17 +01:00
2018-02-01 02:22:51 +01:00
if (!sub_81221AC() && !IsWallysBag())
{
switch (GetSwitchBagPocketDirection())
{
case 1:
ChangeBagPocketId(&gBagPositionStruct.pocket, data[11]);
2018-02-01 02:22:51 +01:00
SwitchTaskToFollowupFunc(taskId);
SwitchBagPocket(taskId, -1, 1);
return;
case 2:
ChangeBagPocketId(&gBagPositionStruct.pocket, data[11]);
2018-02-01 02:22:51 +01:00
SwitchTaskToFollowupFunc(taskId);
SwitchBagPocket(taskId, 1, 1);
return;
}
}
switch (data[13])
{
case 0:
sub_81AC23C(data[12]);
if (!(++data[12] & 1))
{
if (data[11] == 1)
BagMenu_CopyPocketNameToWindow((u8)(data[12] >> 1));
2018-02-01 02:22:51 +01:00
else
BagMenu_CopyPocketNameToWindow((u8)(8 - (data[12] >> 1)));
2018-02-01 02:22:51 +01:00
}
if (data[12] == 16)
data[13]++;
break;
case 1:
ChangeBagPocketId(&gBagPositionStruct.pocket, data[11]);
LoadBagItemListBuffers(gBagPositionStruct.pocket);
data[0] = ListMenuInit(&gMultiuseListMenuTemplate, gBagPositionStruct.scrollPosition[gBagPositionStruct.pocket], gBagPositionStruct.cursorPosition[gBagPositionStruct.pocket]);
2018-02-01 02:22:51 +01:00
PutWindowTilemap(1);
PutWindowTilemap(2);
schedule_bg_copy_tilemap_to_vram(0);
bag_menu_add_pocket_scroll_arrow_indicators_maybe();
bag_menu_add_list_scroll_arrow_indicators_maybe();
SwitchTaskToFollowupFunc(taskId);
}
}
2018-02-05 05:47:47 +01:00
void sub_81AC23C(u8 a)
{
FillBgTilemapBufferRect_Palette0(2, 17, 14, a + 2, 15, 1);
schedule_bg_copy_tilemap_to_vram(2);
}
void BagMenu_DrawPocketIndicatorSquare(u8 x, u8 is_current_bag)
2018-02-05 05:47:47 +01:00
{
if (is_current_bag == 0)
FillBgTilemapBufferRect_Palette0(2, 0x1017, x + 5, 3, 1, 1);
else
FillBgTilemapBufferRect_Palette0(2, 0x102B, x + 5, 3, 1, 1);
schedule_bg_copy_tilemap_to_vram(2);
}
bool8 sub_81AC2C0(void)
{
if (gBagPositionStruct.location <= 1)
2018-02-05 05:47:47 +01:00
{
u8 temp = gBagPositionStruct.pocket - 2;
2018-02-05 05:47:47 +01:00
if (temp > 1)
return TRUE;
}
return FALSE;
}
void BagMenu_SwapItems(u8 taskId)
2018-02-05 05:47:47 +01:00
{
s16* data = gTasks[taskId].data;
2018-02-14 01:12:17 +01:00
2018-07-15 13:23:38 +02:00
ListMenuSetUnkIndicatorsStructField(data[0], 16, 1);
data[1] = gBagPositionStruct.scrollPosition[gBagPositionStruct.pocket] + gBagPositionStruct.cursorPosition[gBagPositionStruct.pocket];
gBagMenu->unk81A = data[1];
CopyItemName(BagGetItemIdByPocketPosition(gBagPositionStruct.pocket + 1, data[1]), gStringVar1);
2018-02-05 05:47:47 +01:00
StringExpandPlaceholders(gStringVar4, gText_MoveVar1Where);
FillWindowPixelBuffer(1, PIXEL_FILL(0));
BagMenu_Print(1, 1, gStringVar4, 3, 1, 0, 0, 0, 0);
2018-02-05 05:47:47 +01:00
sub_80D4FEC(data[1]);
sub_81AB89C();
BagMenu_PrintCursor_(data[0], 2);
2018-02-05 05:47:47 +01:00
gTasks[taskId].func = sub_81AC3C0;
}
void sub_81AC3C0(u8 taskId)
{
s16* data = gTasks[taskId].data;
2019-02-02 11:04:38 +01:00
int input;
2018-02-14 01:12:17 +01:00
2018-02-05 05:47:47 +01:00
if (sub_81221EC() != TRUE)
{
if (gMain.newKeys & SELECT_BUTTON)
{
PlaySE(SE_SELECT);
ListMenuGetScrollAndRow(data[0], &gBagPositionStruct.scrollPosition[gBagPositionStruct.pocket], &gBagPositionStruct.cursorPosition[gBagPositionStruct.pocket]);
2018-02-05 05:47:47 +01:00
sub_81AC498(taskId);
}
else
{
2019-02-02 11:04:38 +01:00
input = ListMenu_ProcessInput(data[0]);
ListMenuGetScrollAndRow(data[0], &gBagPositionStruct.scrollPosition[gBagPositionStruct.pocket], &gBagPositionStruct.cursorPosition[gBagPositionStruct.pocket]);
2018-02-05 05:47:47 +01:00
sub_80D4FC8(0);
sub_80D4FEC(gBagPositionStruct.cursorPosition[gBagPositionStruct.pocket]);
2019-02-02 11:04:38 +01:00
switch (input)
2018-02-05 05:47:47 +01:00
{
2019-02-02 11:04:38 +01:00
case LIST_NOTHING_CHOSEN:
2018-02-05 05:47:47 +01:00
break;
case LIST_CANCEL:
2018-02-05 05:47:47 +01:00
PlaySE(SE_SELECT);
if (gMain.newKeys & A_BUTTON)
sub_81AC498(taskId);
else
sub_81AC590(taskId);
break;
default:
PlaySE(SE_SELECT);
sub_81AC498(taskId);
}
}
}
}
void sub_81AC498(u8 taskId)
{
s16* data = gTasks[taskId].data;
u16* scrollPos = &gBagPositionStruct.scrollPosition[gBagPositionStruct.pocket];
u16* cursorPos = &gBagPositionStruct.cursorPosition[gBagPositionStruct.pocket];
2018-02-09 03:00:28 +01:00
u16 realPos = (*scrollPos + *cursorPos);
2018-02-14 01:12:17 +01:00
2018-02-05 05:47:47 +01:00
if (data[1] == realPos || data[1] == (realPos - 1))
sub_81AC590(taskId);
else
{
MoveItemSlotInList(gBagPockets[gBagPositionStruct.pocket].itemSlots, data[1], realPos);
gBagMenu->unk81A = -1;
2018-03-02 16:34:31 +01:00
DestroyListMenuTask(data[0], scrollPos, cursorPos);
2018-02-05 05:47:47 +01:00
if (data[1] < realPos)
gBagPositionStruct.cursorPosition[gBagPositionStruct.pocket]--;
LoadBagItemListBuffers(gBagPositionStruct.pocket);
2018-02-05 05:47:47 +01:00
data[0] = ListMenuInit(&gMultiuseListMenuTemplate, *scrollPos, *cursorPos);
sub_80D4FC8(1);
bag_menu_add_list_scroll_arrow_indicators_maybe();
gTasks[taskId].func = Task_BagMenu;
}
}
void sub_81AC590(u8 taskId)
{
s16* data = gTasks[taskId].data;
u16* scrollPos = &gBagPositionStruct.scrollPosition[gBagPositionStruct.pocket];
u16* cursorPos = &gBagPositionStruct.cursorPosition[gBagPositionStruct.pocket];
2018-02-14 01:12:17 +01:00
gBagMenu->unk81A = -1;
2018-03-02 16:34:31 +01:00
DestroyListMenuTask(data[0], scrollPos, cursorPos);
2018-02-05 05:47:47 +01:00
if (data[1] < (*scrollPos + *cursorPos))
gBagPositionStruct.cursorPosition[gBagPositionStruct.pocket]--;
LoadBagItemListBuffers(gBagPositionStruct.pocket);
2018-02-05 05:47:47 +01:00
data[0] = ListMenuInit(&gMultiuseListMenuTemplate, *scrollPos, *cursorPos);
sub_80D4FC8(1);
bag_menu_add_list_scroll_arrow_indicators_maybe();
gTasks[taskId].func = Task_BagMenu;
}
void sub_81AC644(u8 unused)
{
switch (gBagPositionStruct.location - 1)
2018-02-05 05:47:47 +01:00
{
case 0:
case 9:
if (ItemId_GetBattleUsage(gSpecialVar_ItemId))
{
gBagMenu->unk820 = gUnknown_08614042;
gBagMenu->unk828 = 2;
2018-02-05 05:47:47 +01:00
}
else
{
gBagMenu->unk820 = &gUnknown_08614046;
gBagMenu->unk828 = 1;
2018-02-05 05:47:47 +01:00
}
break;
case 4:
gBagMenu->unk820 = gUnknown_08614047;
gBagMenu->unk828 = 4;
2018-02-05 05:47:47 +01:00
break;
case 8:
2018-04-29 13:36:26 +02:00
if (!ItemId_GetImportance(gSpecialVar_ItemId) && gSpecialVar_ItemId != ITEM_ENIGMA_BERRY)
2018-02-05 05:47:47 +01:00
{
gBagMenu->unk820 = gUnknown_0861404B;
gBagMenu->unk828 = 2;
2018-02-05 05:47:47 +01:00
}
else
{
gBagMenu->unk820 = &gUnknown_08614046;
gBagMenu->unk828 = 1;
2018-02-05 05:47:47 +01:00
}
break;
case 6:
2018-04-29 13:36:26 +02:00
if (!ItemId_GetImportance(gSpecialVar_ItemId) && gSpecialVar_ItemId != ITEM_ENIGMA_BERRY)
2018-02-05 05:47:47 +01:00
{
gBagMenu->unk820 = gUnknown_0861404D;
gBagMenu->unk828 = 2;
2018-02-05 05:47:47 +01:00
}
else
{
gBagMenu->unk820 = &gUnknown_08614046;
gBagMenu->unk828 = 1;
2018-02-05 05:47:47 +01:00
}
break;
case 7:
2018-04-29 13:36:26 +02:00
if (!ItemId_GetImportance(gSpecialVar_ItemId) && gSpecialVar_ItemId != ITEM_ENIGMA_BERRY)
2018-02-05 05:47:47 +01:00
{
gBagMenu->unk820 = gUnknown_0861404F;
gBagMenu->unk828 = 2;
2018-02-05 05:47:47 +01:00
}
else
{
gBagMenu->unk820 = &gUnknown_08614046;
gBagMenu->unk828 = 1;
2018-02-05 05:47:47 +01:00
}
break;
case 1:
case 2:
case 3:
case 5:
default:
if (sub_81221AC() == TRUE || InUnionRoom() == TRUE)
{
if (gBagPositionStruct.pocket == KEYITEMS_POCKET || !sub_8122148(gSpecialVar_ItemId))
2018-02-05 05:47:47 +01:00
{
gBagMenu->unk820 = &gUnknown_08614046;
gBagMenu->unk828 = 1;
2018-02-05 05:47:47 +01:00
}
else
{
gBagMenu->unk820 = gUnknown_08614044;
gBagMenu->unk828 = 2;
2018-02-05 05:47:47 +01:00
}
}
else
{
switch (gBagPositionStruct.pocket)
2018-02-05 05:47:47 +01:00
{
2018-12-10 10:32:00 +01:00
case ITEMS_POCKET:
gBagMenu->unk820 = &gBagMenu->unk824;
gBagMenu->unk828 = 4;
memcpy(&gBagMenu->unk824, &gUnknown_0861402C, 4);
2018-02-05 05:47:47 +01:00
if (ItemIsMail(gSpecialVar_ItemId) == TRUE)
gBagMenu->unk824 = 6;
2018-02-05 05:47:47 +01:00
break;
2018-12-10 10:32:00 +01:00
case KEYITEMS_POCKET:
gBagMenu->unk820 = &gBagMenu->unk824;
gBagMenu->unk828 = 4;
memcpy(&gBagMenu->unk824, &gUnknown_08614030, 4);
2018-02-05 05:47:47 +01:00
if (gSaveBlock1Ptr->registeredItem == gSpecialVar_ItemId)
gBagMenu->unk825 = 8;
2018-02-05 05:47:47 +01:00
if (gSpecialVar_ItemId == ITEM_MACH_BIKE || gSpecialVar_ItemId == ITEM_ACRO_BIKE)
{
if (TestPlayerAvatarFlags(6))
gBagMenu->unk824 = 7;
2018-02-05 05:47:47 +01:00
}
break;
2018-12-10 10:32:00 +01:00
case BALLS_POCKET:
gBagMenu->unk820 = gUnknown_08614034;
gBagMenu->unk828 = 4;
2018-02-05 05:47:47 +01:00
break;
2018-12-10 10:32:00 +01:00
case TMHM_POCKET:
gBagMenu->unk820 = gUnknown_08614038;
gBagMenu->unk828 = 4;
2018-02-05 05:47:47 +01:00
break;
2018-12-10 10:32:00 +01:00
case BERRIES_POCKET:
gBagMenu->unk820 = gUnknown_0861403C;
gBagMenu->unk828 = 6;
2018-02-05 05:47:47 +01:00
break;
}
}
}
if (gBagPositionStruct.pocket == TMHM_POCKET)
2018-02-05 05:47:47 +01:00
{
ClearWindowTilemap(1);
PrintTMHMMoveData(gSpecialVar_ItemId);
PutWindowTilemap(3);
PutWindowTilemap(4);
schedule_bg_copy_tilemap_to_vram(0);
}
else
{
CopyItemName(gSpecialVar_ItemId, gStringVar1);
StringExpandPlaceholders(gStringVar4, gText_Var1IsSelected);
FillWindowPixelBuffer(1, PIXEL_FILL(0));
BagMenu_Print(1, 1, gStringVar4, 3, 1, 0, 0, 0, 0);
}
if (gBagMenu->unk828 == 1)
sub_81ACAF8(BagMenu_AddWindow(0));
else if (gBagMenu->unk828 == 2)
sub_81ACAF8(BagMenu_AddWindow(1));
else if (gBagMenu->unk828 == 4)
sub_81ACB54(BagMenu_AddWindow(2), 2, 2);
2018-02-05 05:47:47 +01:00
else
sub_81ACB54(BagMenu_AddWindow(3), 2, 3);
2018-02-05 05:47:47 +01:00
}
void sub_81ACAF8(u8 a)
{
AddItemMenuActionTextPrinters(a, 7, 8, 1, 0, 16, gBagMenu->unk828, sItemMenuActions, gBagMenu->unk820);
InitMenuInUpperLeftCornerPlaySoundWhenAPressed(a, gBagMenu->unk828, 0);
2018-02-05 05:47:47 +01:00
}
void sub_81ACB54(u8 a, u8 b, u8 c)
{
sub_8198DBC(a, 7, 8, 1, 0x38, b, c, sItemMenuActions, gBagMenu->unk820);
2018-02-05 05:47:47 +01:00
sub_8199944(a, 0x38, b, c, 0);
}
void unknown_item_menu_type(u8 taskId)
{
sub_81AC644(taskId);
if (gBagMenu->unk828 <= 2)
2018-02-05 05:47:47 +01:00
gTasks[taskId].func = Task_HandleInBattleItemMenuInput;
else
gTasks[taskId].func = Task_HandleOutOfBattleItemMenuInput;
}
void Task_HandleInBattleItemMenuInput(u8 taskId)
{
if (sub_81221EC() != TRUE)
{
2018-11-05 21:45:54 +01:00
s8 r4 = Menu_ProcessInputNoWrap();
2018-02-05 05:47:47 +01:00
switch (r4)
{
2019-02-02 11:04:38 +01:00
case MENU_NOTHING_CHOSEN:
2018-02-05 05:47:47 +01:00
break;
2019-02-02 11:04:38 +01:00
case MENU_B_PRESSED:
2018-02-05 05:47:47 +01:00
PlaySE(SE_SELECT);
sItemMenuActions[4].func.void_u8(taskId);
2018-02-05 05:47:47 +01:00
break;
default:
PlaySE(SE_SELECT);
sItemMenuActions[gBagMenu->unk820[r4]].func.void_u8(taskId);
2018-02-05 05:47:47 +01:00
break;
}
}
}
void Task_HandleOutOfBattleItemMenuInput(u8 taskId)
{
if (sub_81221EC() != TRUE)
{
2018-12-16 21:10:01 +01:00
s8 cursorPos = Menu_GetCursorPos();
2018-02-05 05:47:47 +01:00
if (gMain.newKeys & DPAD_UP)
{
if (cursorPos > 0 && sub_81ACDFC(cursorPos - 2))
{
PlaySE(SE_SELECT);
sub_8199134(0, -1);
}
}
else if (gMain.newKeys & DPAD_DOWN)
{
if (cursorPos < (gBagMenu->unk828 - 2) && sub_81ACDFC(cursorPos + 2))
2018-02-05 05:47:47 +01:00
{
PlaySE(SE_SELECT);
sub_8199134(0, 1);
}
}
2019-10-18 01:22:03 +02:00
else if ((gMain.newKeys & DPAD_LEFT) || GetLRKeysPressed() == MENU_L_PRESSED)
2018-02-05 05:47:47 +01:00
{
if ((cursorPos & 1) && sub_81ACDFC(cursorPos - 1))
{
PlaySE(SE_SELECT);
sub_8199134(-1, 0);
}
}
2019-10-18 01:22:03 +02:00
else if ((gMain.newKeys & DPAD_RIGHT) || GetLRKeysPressed() == MENU_R_PRESSED)
2018-02-05 05:47:47 +01:00
{
if (!(cursorPos & 1) && sub_81ACDFC(cursorPos + 1))
{
PlaySE(SE_SELECT);
sub_8199134(1, 0);
}
}
else if (gMain.newKeys & A_BUTTON)
{
PlaySE(SE_SELECT);
sItemMenuActions[gBagMenu->unk820[cursorPos]].func.void_u8(taskId);
2018-02-05 05:47:47 +01:00
}
else if (gMain.newKeys & B_BUTTON)
{
PlaySE(SE_SELECT);
sItemMenuActions[4].func.void_u8(taskId);
2018-02-05 05:47:47 +01:00
}
}
}
bool8 sub_81ACDFC(s8 a)
{
if (a < 0)
return FALSE;
if (a > gBagMenu->unk828)
2018-02-05 05:47:47 +01:00
return FALSE;
if (gBagMenu->unk820[a] == 14)
2018-02-05 05:47:47 +01:00
return FALSE;
return TRUE;
}
void BagMenu_RemoveSomeWindow(void)
2018-02-05 05:47:47 +01:00
{
if (gBagMenu->unk828 == 1)
BagMenu_RemoveWindow(0);
else if (gBagMenu->unk828 == 2)
2018-02-05 05:47:47 +01:00
{
BagMenu_RemoveWindow(1);
2018-02-05 05:47:47 +01:00
}
else if (gBagMenu->unk828 == 4)
2018-02-05 05:47:47 +01:00
{
BagMenu_RemoveWindow(2);
2018-02-05 05:47:47 +01:00
}
else
BagMenu_RemoveWindow(3);
2018-02-05 05:47:47 +01:00
}
void ItemMenu_UseOutOfBattle(u8 taskId)
{
if (ItemId_GetFieldFunc(gSpecialVar_ItemId))
{
BagMenu_RemoveSomeWindow();
2018-02-05 05:47:47 +01:00
if (CalculatePlayerPartyCount() == 0 && ItemId_GetType(gSpecialVar_ItemId) == 1)
BagMenu_PrintThereIsNoPokemon(taskId);
2018-02-05 05:47:47 +01:00
else
{
FillWindowPixelBuffer(1, PIXEL_FILL(0));
2018-02-05 05:47:47 +01:00
schedule_bg_copy_tilemap_to_vram(0);
if (gBagPositionStruct.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
}
}
}
void ItemMenu_Toss(u8 taskId)
{
s16* data = gTasks[taskId].data;
2018-02-14 01:12:17 +01:00
BagMenu_RemoveSomeWindow();
2018-02-05 05:47:47 +01:00
data[8] = 1;
if (data[2] == 1)
2018-02-09 03:00:28 +01:00
{
BagMenu_TossItems(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);
FillWindowPixelBuffer(1, PIXEL_FILL(0));
BagMenu_Print(1, 1, gStringVar4, 3, 1, 0, 0, 0, 0);
2018-02-05 05:47:47 +01:00
sub_81ABC3C(7);
gTasks[taskId].func = Task_ChooseHowManyToToss;
}
}
void BagMenu_TossItems(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);
2019-09-30 21:43:44 +02:00
ConvertIntToDecimalStringN(gStringVar2, data[8], STR_CONV_MODE_LEFT_ALIGN, 3);
2018-02-05 05:47:47 +01:00
StringExpandPlaceholders(gStringVar4, gText_ConfirmTossItems);
FillWindowPixelBuffer(1, PIXEL_FILL(0));
BagMenu_Print(1, 1, gStringVar4, 3, 1, 0, 0, 0, 0);
BagMenu_YesNo(taskId, 5, &sYesNoTossFunctions);
2018-02-05 05:47:47 +01:00
}
void BagMenu_CancelToss(u8 taskId)
2018-02-05 05:47:47 +01:00
{
s16* data = gTasks[taskId].data;
2018-02-14 01:12:17 +01:00
BagMenu_PrintDescription(data[1]);
BagMenu_PrintCursor_(data[0], 0);
2018-02-05 05:47:47 +01:00
set_callback3_to_bag(taskId);
}
void Task_ChooseHowManyToToss(u8 taskId)
{
s16* data = gTasks[taskId].data;
2018-02-14 01:12:17 +01:00
2018-02-05 05:47:47 +01:00
if (AdjustQuantityAccordingToDPadInput(&data[8], data[2]) == TRUE)
2018-02-09 03:00:28 +01:00
{
PrintItemDepositAmount(gBagMenu->unk817, data[8]);
2018-02-09 03:00:28 +01:00
}
2018-02-05 05:47:47 +01:00
else if (gMain.newKeys & A_BUTTON)
{
PlaySE(SE_SELECT);
BagMenu_RemoveWindow(7);
BagMenu_TossItems(taskId);
2018-02-05 05:47:47 +01:00
}
else if (gMain.newKeys & B_BUTTON)
{
PlaySE(SE_SELECT);
BagMenu_RemoveWindow(7);
BagMenu_CancelToss(taskId);
2018-02-05 05:47:47 +01:00
}
}
void BagMenu_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);
2019-09-30 21:43:44 +02:00
ConvertIntToDecimalStringN(gStringVar2, data[8], STR_CONV_MODE_LEFT_ALIGN, 3);
2018-02-05 05:47:47 +01:00
StringExpandPlaceholders(gStringVar4, gText_ThrewAwayVar2Var1s);
FillWindowPixelBuffer(1, PIXEL_FILL(0));
BagMenu_Print(1, 1, gStringVar4, 3, 1, 0, 0, 0, 0);
2018-02-05 05:47:47 +01:00
gTasks[taskId].func = Task_ActuallyToss;
}
void Task_ActuallyToss(u8 taskId)
{
s16* data = gTasks[taskId].data;
u16* scrollPos = &gBagPositionStruct.scrollPosition[gBagPositionStruct.pocket];
u16* cursorPos = &gBagPositionStruct.cursorPosition[gBagPositionStruct.pocket];
2018-02-14 01:12:17 +01:00
2018-02-05 05:47:47 +01:00
if (gMain.newKeys & (A_BUTTON | B_BUTTON))
{
PlaySE(SE_SELECT);
RemoveBagItem(gSpecialVar_ItemId, data[8]);
2018-03-02 16:34:31 +01:00
DestroyListMenuTask(data[0], scrollPos, cursorPos);
sub_81AB9A8(gBagPositionStruct.pocket);
SetInitialScrollAndCursorPositions(gBagPositionStruct.pocket);
LoadBagItemListBuffers(gBagPositionStruct.pocket);
2018-02-05 05:47:47 +01:00
data[0] = ListMenuInit(&gMultiuseListMenuTemplate, *scrollPos, *cursorPos);
schedule_bg_copy_tilemap_to_vram(0);
set_callback3_to_bag(taskId);
}
}
void ItemMenu_Register(u8 taskId)
{
s16* data = gTasks[taskId].data;
u16* scrollPos = &gBagPositionStruct.scrollPosition[gBagPositionStruct.pocket];
u16* cursorPos = &gBagPositionStruct.cursorPosition[gBagPositionStruct.pocket];
2018-02-14 01:12:17 +01:00
2018-02-05 05:47:47 +01:00
if (gSaveBlock1Ptr->registeredItem == gSpecialVar_ItemId)
gSaveBlock1Ptr->registeredItem = 0;
else
gSaveBlock1Ptr->registeredItem = gSpecialVar_ItemId;
2018-03-02 16:34:31 +01:00
DestroyListMenuTask(data[0], scrollPos, cursorPos);
LoadBagItemListBuffers(gBagPositionStruct.pocket);
2018-02-05 05:47:47 +01:00
data[0] = ListMenuInit(&gMultiuseListMenuTemplate, *scrollPos, *cursorPos);
schedule_bg_copy_tilemap_to_vram(0);
ItemMenu_Cancel(taskId);
}
void ItemMenu_Give(u8 taskId)
{
BagMenu_RemoveSomeWindow();
2018-02-05 05:47:47 +01:00
if (!itemid_80BF6D8_mail_related(gSpecialVar_ItemId))
2018-02-09 03:00:28 +01:00
{
2018-02-05 05:47:47 +01:00
DisplayItemMessage(taskId, 1, gText_CantWriteMail, sub_81AD350);
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)
BagMenu_PrintThereIsNoPokemon(taskId);
2018-02-05 05:47:47 +01:00
else
{
2019-10-18 01:22:03 +02:00
gBagMenu->mainCallback2 = CB2_ChooseMonToGiveItem;
2018-02-05 05:47:47 +01:00
unknown_ItemMenu_Confirm(taskId);
}
}
else
2018-02-09 03:00:28 +01:00
{
BagMenu_PrintItemCantBeHeld(taskId);
2018-02-09 03:00:28 +01:00
}
2018-02-05 05:47:47 +01:00
}
void BagMenu_PrintThereIsNoPokemon(u8 taskId)
2018-02-05 05:47:47 +01:00
{
DisplayItemMessage(taskId, 1, gText_NoPokemon, sub_81AD350);
}
void BagMenu_PrintItemCantBeHeld(u8 taskId)
2018-02-05 05:47:47 +01:00
{
CopyItemName(gSpecialVar_ItemId, gStringVar1);
StringExpandPlaceholders(gStringVar4, gText_Var1CantBeHeld);
DisplayItemMessage(taskId, 1, gStringVar4, sub_81AD350);
}
void sub_81AD350(u8 taskId)
{
if (gMain.newKeys & A_BUTTON)
{
PlaySE(SE_SELECT);
BagMenu_InitListsMenu(taskId);
2018-02-05 05:47:47 +01:00
}
}
void ItemMenu_CheckTag(u8 taskId)
{
gBagMenu->mainCallback2 = DoBerryTagScreen;
2018-02-05 05:47:47 +01:00
unknown_ItemMenu_Confirm(taskId);
}
void ItemMenu_Cancel(u8 taskId)
{
s16* data = gTasks[taskId].data;
2018-02-14 01:12:17 +01:00
BagMenu_RemoveSomeWindow();
BagMenu_PrintDescription(data[1]);
2018-02-05 05:47:47 +01:00
schedule_bg_copy_tilemap_to_vram(0);
schedule_bg_copy_tilemap_to_vram(1);
BagMenu_PrintCursor_(data[0], 0);
2018-02-05 05:47:47 +01:00
set_callback3_to_bag(taskId);
}
void ItemMenu_UseInBattle(u8 taskId)
{
if (ItemId_GetBattleFunc(gSpecialVar_ItemId))
{
BagMenu_RemoveSomeWindow();
2018-02-05 05:47:47 +01:00
ItemId_GetBattleFunc(gSpecialVar_ItemId)(taskId);
}
}
void bag_menu_mail_related(void)
{
2018-12-10 17:39:57 +01:00
GoToBagMenu(RETURN_LOCATION_UNCHANGED, POCKETS_COUNT, NULL);
2018-02-05 05:47:47 +01:00
}
void item_menu_type_2(u8 taskId)
{
if (!itemid_80BF6D8_mail_related(gSpecialVar_ItemId))
2018-02-09 03:00:28 +01:00
{
2018-02-05 05:47:47 +01:00
DisplayItemMessage(taskId, 1, gText_CantWriteMail, sub_81AD350);
2018-02-09 03:00:28 +01:00
}
2018-02-05 05:47:47 +01:00
else if (!sub_8122148(gSpecialVar_ItemId))
{
CopyItemName(gSpecialVar_ItemId, gStringVar1);
StringExpandPlaceholders(gStringVar4, gText_Var1CantBeHeldHere);
DisplayItemMessage(taskId, 1, gStringVar4, sub_81AD350);
}
else if (gBagPositionStruct.pocket != KEYITEMS_POCKET && !ItemId_GetImportance(gSpecialVar_ItemId))
2018-02-05 05:47:47 +01:00
{
unknown_ItemMenu_Confirm(taskId);
}
else
2018-02-09 03:00:28 +01:00
{
BagMenu_PrintItemCantBeHeld(taskId);
2018-02-09 03:00:28 +01:00
}
2018-02-05 05:47:47 +01:00
}
void item_menu_type_b(u8 taskId)
{
if (ItemIsMail(gSpecialVar_ItemId) == TRUE)
DisplayItemMessage(taskId, 1, gText_CantWriteMail, sub_81AD350);
else if (gBagPositionStruct.pocket != KEYITEMS_POCKET && !ItemId_GetImportance(gSpecialVar_ItemId))
2018-02-05 05:47:47 +01:00
gTasks[taskId].func = unknown_ItemMenu_Confirm;
else
BagMenu_PrintItemCantBeHeld(taskId);
2018-02-05 05:47:47 +01:00
}
bool8 UseRegisteredKeyItemOnField(void)
{
u8 taskId;
2018-02-14 01:12:17 +01:00
2018-02-05 05:47:47 +01:00
if (InUnionRoom() == TRUE || InBattlePyramid() || InBattlePike() || InMultiBattleRoom() == TRUE)
return FALSE;
2018-02-09 03:00:28 +01:00
HideMapNamePopUpWindow();
ChangeBgY_ScreenOff(0, 0, 0);
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
{
2018-02-09 03:00:28 +01:00
ScriptContext2_Enable();
FreezeEventObjects();
2018-02-09 03:00:28 +01:00
sub_808B864();
sub_808BCF4();
gSpecialVar_ItemId = gSaveBlock1Ptr->registeredItem;
taskId = CreateTask(ItemId_GetFieldFunc(gSaveBlock1Ptr->registeredItem), 8);
gTasks[taskId].data[3] = 1;
return TRUE;
2018-02-05 05:47:47 +01:00
}
2018-02-09 03:00:28 +01:00
else
gSaveBlock1Ptr->registeredItem = ITEM_NONE;
2018-02-05 05:47:47 +01:00
}
ScriptContext1_SetupScript(EventScript_SelectWithoutRegisteredItem);
2018-02-05 05:47:47 +01:00
return TRUE;
}
void DisplaySellItemAskString(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);
DisplayItemMessage(taskId, 1, gStringVar4, BagMenu_InitListsMenu);
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
{
data[8] = 1;
if (data[2] == 1)
{
bag_menu_AddMoney_window();
sub_81AD680(taskId);
}
else
{
CopyItemName(gSpecialVar_ItemId, gStringVar2);
StringExpandPlaceholders(gStringVar4, gText_HowManyToSell);
DisplayItemMessage(taskId, 1, gStringVar4, sub_81AD730);
}
}
}
void sub_81AD680(u8 taskId)
{
s16* data = gTasks[taskId].data;
2018-02-14 01:12:17 +01:00
2019-09-30 21:43:44 +02:00
ConvertIntToDecimalStringN(gStringVar1, (ItemId_GetPrice(gSpecialVar_ItemId) / 2) * data[8], STR_CONV_MODE_LEFT_ALIGN, 6);
2018-02-05 05:47:47 +01:00
StringExpandPlaceholders(gStringVar4, gText_ICanPayVar1);
DisplayItemMessage(taskId, 1, gStringVar4, sub_81AD6E4);
}
void sub_81AD6E4(u8 taskId)
{
BagMenu_YesNo(taskId, 6, &sYesNoSellItemFunctions);
2018-02-05 05:47:47 +01:00
}
void BagMenu_CancelSell(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
bag_menu_remove_money_window();
bag_menu_RemoveBagItem_message_window(4);
BagMenu_PrintCursor_(data[0], 0);
2018-02-05 05:47:47 +01:00
set_callback3_to_bag(taskId);
}
void sub_81AD730(u8 taskId)
{
s16* data = gTasks[taskId].data;
u8 windowId = BagMenu_AddWindow(8);
2018-02-14 01:12:17 +01:00
2019-09-30 21:53:24 +02:00
PrintItemSoldAmount(windowId, 1, (ItemId_GetPrice(gSpecialVar_ItemId) / 2) * data[8]);
2018-02-05 05:47:47 +01:00
bag_menu_AddMoney_window();
gTasks[taskId].func = sub_81AD794;
}
void sub_81AD794(u8 taskId)
{
s16* data = gTasks[taskId].data;
2018-02-14 01:12:17 +01:00
2018-02-05 05:47:47 +01:00
if (AdjustQuantityAccordingToDPadInput(&data[8], data[2]) == TRUE)
2018-02-09 03:00:28 +01:00
{
2019-09-30 21:53:24 +02:00
PrintItemSoldAmount(gBagMenu->unk818, data[8], (ItemId_GetPrice(gSpecialVar_ItemId) / 2) * data[8]);
2018-02-09 03:00:28 +01:00
}
2018-02-05 05:47:47 +01:00
else if (gMain.newKeys & A_BUTTON)
{
PlaySE(SE_SELECT);
BagMenu_RemoveWindow(8);
2018-02-05 05:47:47 +01:00
sub_81AD680(taskId);
}
else if (gMain.newKeys & B_BUTTON)
{
PlaySE(SE_SELECT);
BagMenu_PrintCursor_(data[0], 0);
2018-02-05 05:47:47 +01:00
bag_menu_remove_money_window();
BagMenu_RemoveWindow(8);
2018-02-05 05:47:47 +01:00
bag_menu_RemoveBagItem_message_window(4);
set_callback3_to_bag(taskId);
}
}
void BagMenu_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);
2019-09-30 21:43:44 +02:00
ConvertIntToDecimalStringN(gStringVar1, (ItemId_GetPrice(gSpecialVar_ItemId) / 2) * data[8], STR_CONV_MODE_LEFT_ALIGN, 6);
2018-02-05 05:47:47 +01:00
StringExpandPlaceholders(gStringVar4, gText_TurnedOverVar1ForVar2);
DisplayItemMessage(taskId, 1, gStringVar4, sub_81AD8C8);
}
void sub_81AD8C8(u8 taskId)
{
s16* data = gTasks[taskId].data;
u16* scrollPos = &gBagPositionStruct.scrollPosition[gBagPositionStruct.pocket];
u16* cursorPos = &gBagPositionStruct.cursorPosition[gBagPositionStruct.pocket];
2018-02-14 01:12:17 +01:00
2018-02-05 05:47:47 +01:00
PlaySE(SE_REGI);
RemoveBagItem(gSpecialVar_ItemId, data[8]);
2018-04-29 13:36:26 +02:00
AddMoney(&gSaveBlock1Ptr->money, (ItemId_GetPrice(gSpecialVar_ItemId) / 2) * data[8]);
2018-03-02 16:34:31 +01:00
DestroyListMenuTask(data[0], scrollPos, cursorPos);
sub_81AB9A8(gBagPositionStruct.pocket);
SetInitialScrollAndCursorPositions(gBagPositionStruct.pocket);
LoadBagItemListBuffers(gBagPositionStruct.pocket);
2018-02-05 05:47:47 +01:00
data[0] = ListMenuInit(&gMultiuseListMenuTemplate, *scrollPos, *cursorPos);
BagMenu_PrintCursor_(data[0], 2);
PrintMoneyAmountInMoneyBox(gBagMenu->unk819, GetMoney(&gSaveBlock1Ptr->money), 0);
2018-02-05 05:47:47 +01:00
gTasks[taskId].func = sub_81AD9C0;
}
void sub_81AD9C0(u8 taskId)
{
if (gMain.newKeys & (A_BUTTON | B_BUTTON))
{
PlaySE(SE_SELECT);
bag_menu_remove_money_window();
BagMenu_InitListsMenu(taskId);
2018-02-05 05:47:47 +01:00
}
}
void DisplayDepositItemAskString(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
data[8] = 1;
if (data[2] == 1)
2018-02-09 03:00:28 +01:00
{
2018-02-05 05:47:47 +01:00
sub_81ADB14(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);
FillWindowPixelBuffer(1, PIXEL_FILL(0));
BagMenu_Print(1, 1, gStringVar4, 3, 1, 0, 0, 0, 0);
2018-02-05 05:47:47 +01:00
sub_81ABC3C(7);
gTasks[taskId].func = sub_81ADA7C;
}
}
void sub_81ADA7C(u8 taskId)
{
s16* data = gTasks[taskId].data;
2018-02-14 01:12:17 +01:00
2018-02-05 05:47:47 +01:00
if (AdjustQuantityAccordingToDPadInput(&data[8], data[2]) == TRUE)
2018-02-09 03:00:28 +01:00
{
PrintItemDepositAmount(gBagMenu->unk817, data[8]);
2018-02-09 03:00:28 +01:00
}
2018-02-05 05:47:47 +01:00
else if (gMain.newKeys & A_BUTTON)
{
PlaySE(SE_SELECT);
BagMenu_RemoveWindow(7);
2018-02-05 05:47:47 +01:00
sub_81ADB14(taskId);
}
else if (gMain.newKeys & B_BUTTON)
{
PlaySE(SE_SELECT);
BagMenu_PrintDescription(data[1]);
BagMenu_PrintCursor_(data[0], 0);
BagMenu_RemoveWindow(7);
2018-02-05 05:47:47 +01:00
set_callback3_to_bag(taskId);
}
}
void sub_81ADB14(u8 taskId)
{
s16* data = gTasks[taskId].data;
2018-02-14 01:12:17 +01:00
FillWindowPixelBuffer(1, PIXEL_FILL(0));
2018-04-29 13:36:26 +02:00
if (ItemId_GetImportance(gSpecialVar_ItemId))
2018-02-05 05:47:47 +01:00
{
BagMenu_Print(1, 1, gText_CantStoreImportantItems, 3, 1, 0, 0, 0, 0);
2018-02-05 05:47:47 +01:00
gTasks[taskId].func = sub_81ADC0C;
}
else if (AddPCItem(gSpecialVar_ItemId, data[8]) == TRUE)
{
CopyItemName(gSpecialVar_ItemId, gStringVar1);
2019-09-30 21:43:44 +02:00
ConvertIntToDecimalStringN(gStringVar2, data[8], STR_CONV_MODE_LEFT_ALIGN, 3);
2018-02-05 05:47:47 +01:00
StringExpandPlaceholders(gStringVar4, gText_DepositedVar2Var1s);
BagMenu_Print(1, 1, gStringVar4, 3, 1, 0, 0, 0, 0);
2018-02-05 05:47:47 +01:00
gTasks[taskId].func = Task_ActuallyToss;
}
else
{
BagMenu_Print(1, 1, gText_NoRoomForItems, 3, 1, 0, 0, 0, 0);
2018-02-05 05:47:47 +01:00
gTasks[taskId].func = sub_81ADC0C;
}
}
void sub_81ADC0C(u8 taskId)
{
s16* data = gTasks[taskId].data;
2018-02-14 01:12:17 +01:00
2018-02-05 05:47:47 +01:00
if (gMain.newKeys & (A_BUTTON | B_BUTTON))
{
PlaySE(SE_SELECT);
BagMenu_PrintDescription(data[1]);
BagMenu_PrintCursor_(data[0], 0);
2018-02-05 05:47:47 +01:00
set_callback3_to_bag(taskId);
}
}
bool8 IsWallysBag(void)
{
if (gBagPositionStruct.location == 10)
2018-02-05 05:47:47 +01:00
return TRUE;
return FALSE;
}
void PrepareBagForWallyTutorial(void)
{
u32 i;
2018-02-14 01:12:17 +01:00
2018-02-07 20:22:49 +01:00
gUnknown_0203CE80 = AllocZeroed(sizeof(struct TempWallyStruct));
2018-02-05 05:47:47 +01:00
memcpy(gUnknown_0203CE80->bagPocket_Items, gSaveBlock1Ptr->bagPocket_Items, sizeof(gSaveBlock1Ptr->bagPocket_Items));
memcpy(gUnknown_0203CE80->bagPocket_PokeBalls, gSaveBlock1Ptr->bagPocket_PokeBalls, sizeof(gSaveBlock1Ptr->bagPocket_PokeBalls));
gUnknown_0203CE80->pocket = gBagPositionStruct.pocket;
2018-02-05 05:47:47 +01:00
for (i = 0; i <= 4; i++)
{
gUnknown_0203CE80->cursorPosition[i] = gBagPositionStruct.cursorPosition[i];
gUnknown_0203CE80->scrollPosition[i] = gBagPositionStruct.scrollPosition[i];
2018-02-05 05:47:47 +01:00
}
ClearItemSlots(gSaveBlock1Ptr->bagPocket_Items, 30);
ClearItemSlots(gSaveBlock1Ptr->bagPocket_PokeBalls, 16);
ResetBagScrollPositions();
}
void RestoreBagAfterWallyTutorial(void)
{
u32 i;
2018-02-14 01:12:17 +01:00
2018-02-05 05:47:47 +01:00
memcpy(gSaveBlock1Ptr->bagPocket_Items, gUnknown_0203CE80->bagPocket_Items, sizeof(gUnknown_0203CE80->bagPocket_Items));
memcpy(gSaveBlock1Ptr->bagPocket_PokeBalls, gUnknown_0203CE80->bagPocket_PokeBalls, sizeof(gUnknown_0203CE80->bagPocket_PokeBalls));
gBagPositionStruct.pocket = gUnknown_0203CE80->pocket;
2018-02-05 05:47:47 +01:00
for (i = 0; i <= 4; i++)
{
gBagPositionStruct.cursorPosition[i] = gUnknown_0203CE80->cursorPosition[i];
gBagPositionStruct.scrollPosition[i] = gUnknown_0203CE80->scrollPosition[i];
2018-02-05 05:47:47 +01:00
}
Free(gUnknown_0203CE80);
}
void DoWallyTutorialBagMenu(void)
{
PrepareBagForWallyTutorial();
AddBagItem(ITEM_POTION, 1);
AddBagItem(ITEM_POKE_BALL, 1);
2019-10-18 01:22:03 +02:00
GoToBagMenu(RETURN_LOCATION_BATTLE_2, ITEMS_POCKET, CB2_SetUpReshowBattleScreenAfterMenu2);
2018-02-05 05:47:47 +01:00
}
void Task_WallyTutorialBagMenu(u8 taskId)
{
s16* data = gTasks[taskId].data;
2018-02-14 01:12:17 +01:00
2018-02-05 05:47:47 +01:00
if (!gPaletteFade.active)
{
switch (data[8])
{
case 0x66:
PlaySE(SE_SELECT);
SwitchBagPocket(taskId, 1, 0);
data[8]++;
break;
case 0xCC:
PlaySE(SE_SELECT);
BagMenu_PrintCursor_(data[0], 2);
2018-02-05 05:47:47 +01:00
gSpecialVar_ItemId = ITEM_POKE_BALL;
sub_81AC644(taskId);
data[8]++;
break;
case 0x132:
PlaySE(SE_SELECT);
BagMenu_RemoveSomeWindow();
2018-03-02 16:34:31 +01:00
DestroyListMenuTask(data[0], 0, 0);
2018-02-05 05:47:47 +01:00
RestoreBagAfterWallyTutorial();
unknown_ItemMenu_Confirm(taskId);
break;
default:
data[8]++;
break;
}
}
}
void unknown_ItemMenu_Show(u8 taskId)
{
gSpecialVar_0x8005 = gSpecialVar_ItemId;
gSpecialVar_Result = 1;
BagMenu_RemoveSomeWindow();
2018-02-05 05:47:47 +01:00
unknown_ItemMenu_Confirm(taskId);
}
2019-11-19 17:36:38 +01:00
void CB2_ApprenticeExitBagMenu(void)
2018-02-05 05:47:47 +01:00
{
2018-10-14 17:00:41 +02:00
gFieldCallback = Apprentice_EnableBothScriptContexts;
2018-02-14 01:12:17 +01:00
SetMainCallback2(CB2_ReturnToField);
2018-02-05 05:47:47 +01:00
}
void unknown_ItemMenu_Give2(u8 taskId)
{
RemoveBagItem(gSpecialVar_ItemId, 1);
gSpecialVar_Result = 1;
BagMenu_RemoveSomeWindow();
2018-02-05 05:47:47 +01:00
unknown_ItemMenu_Confirm(taskId);
}
2019-08-06 02:37:09 +02:00
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
}
void unknown_ItemMenu_Confirm2(u8 taskId)
{
gSpecialVar_Result = 1;
BagMenu_RemoveSomeWindow();
2018-02-05 05:47:47 +01:00
unknown_ItemMenu_Confirm(taskId);
}
2019-08-06 02:37:09 +02:00
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
}
void BagMenu_PrintPocketNames(const u8 *pocketName1, const u8 *pocketName2)
2018-02-05 05:47:47 +01:00
{
struct WindowTemplate window = {0, 0, 0, 0, 0, 0, 0};
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));
2018-02-05 05:47:47 +01:00
offset = GetStringCenterAlignXOffset(1, pocketName1, 0x40);
BagMenu_Print(windowId, 1, pocketName1, offset, 1, 0, 0, -1, 1);
2018-02-05 05:47:47 +01:00
if (pocketName2)
{
offset = GetStringCenterAlignXOffset(1, pocketName2, 0x40);
BagMenu_Print(windowId, 1, pocketName2, offset + 0x40, 1, 0, 0, -1, 1);
2018-02-05 05:47:47 +01:00
}
CpuCopy32((u8*)GetWindowAttribute(windowId, WINDOW_TILE_DATA), gBagMenu->pocketNameBuffer, 0x400);
2018-02-05 05:47:47 +01:00
RemoveWindow(windowId);
}
void BagMenu_CopyPocketNameToWindow(u32 a)
2018-02-05 05:47:47 +01:00
{
u8 (* r4)[32][32];
u8* windowAttribute;
int b;
if (a > 8)
a = 8;
r4 = &gBagMenu->pocketNameBuffer;
2018-07-15 13:23:38 +02:00
windowAttribute = (u8*)GetWindowAttribute(2, WINDOW_TILE_DATA);
2018-02-05 05:47:47 +01:00
CpuCopy32(r4[0][a], windowAttribute, 0x100);
b = a + 16;
CpuCopy32(r4[0][b], windowAttribute + 0x100, 0x100);
CopyWindowToVram(2, 2);
}
void SetupBagMenu_Textboxes(void)
2018-02-05 05:47:47 +01:00
{
u8 i;
2018-02-14 01:12:17 +01:00
2018-02-05 05:47:47 +01:00
InitWindows(gUnknown_08614174);
DeactivateAllTextPrinters();
LoadUserWindowBorderGfx(0, 1, 0xE0);
LoadMessageBoxGfx(0, 10, 0xD0);
sub_819A2BC(0xC0, 1);
2018-02-05 05:47:47 +01:00
LoadPalette(&gUnknown_0860F074, 0xF0, 0x20);
2018-02-12 19:59:42 +01:00
for (i = 0; i < 3; i++)
2018-02-05 05:47:47 +01:00
{
FillWindowPixelBuffer(i, PIXEL_FILL(0));
2018-02-05 05:47:47 +01:00
PutWindowTilemap(i);
}
schedule_bg_copy_tilemap_to_vram(0);
schedule_bg_copy_tilemap_to_vram(1);
}
void BagMenu_Print(u8 windowId, u8 fontId, const u8 *str, u8 left, u8 top, u8 letterSpacing, u8 lineSpacing, u8 speed, u8 h)
2018-02-05 05:47:47 +01:00
{
2018-12-15 19:08:13 +01:00
AddTextPrinterParameterized4(windowId, fontId, left, top, letterSpacing, lineSpacing, sFontColorTable[h], speed, str);
2018-02-05 05:47:47 +01:00
}
u8 sub_81AE124(u8 a)
{
return gBagMenu->windowPointers[a];
2018-02-14 01:12:17 +01:00
}
2018-02-05 05:47:47 +01:00
u8 BagMenu_AddWindow(u8 a)
2018-02-05 05:47:47 +01:00
{
u8 *ptr = &gBagMenu->windowPointers[a];
if (*ptr == 0xFF)
2018-02-05 05:47:47 +01:00
{
*ptr = AddWindow(&gUnknown_086141AC[a]);
DrawStdFrameWithCustomTileAndPalette(*ptr, 0, 1, 14);
2018-02-05 05:47:47 +01:00
schedule_bg_copy_tilemap_to_vram(1);
}
return *ptr;
}
void BagMenu_RemoveWindow(u8 a)
2018-02-05 05:47:47 +01:00
{
u8 *ptr = &gBagMenu->windowPointers[a];
if (*ptr != 0xFF)
2018-02-05 05:47:47 +01:00
{
ClearStdWindowAndFrameToTransparent(*ptr, 0);
2018-02-05 05:47:47 +01:00
ClearWindowTilemap(*ptr);
RemoveWindow(*ptr);
schedule_bg_copy_tilemap_to_vram(1);
*ptr = 0xFF;
2018-02-05 05:47:47 +01:00
}
}
u8 AddItemMessageWindow(u8 a)
{
u8 *ptr = &gBagMenu->windowPointers[a];
if (*ptr == 0xFF)
2018-02-05 05:47:47 +01:00
*ptr = AddWindow(&gUnknown_086141AC[a]);
return *ptr;
}
void bag_menu_RemoveBagItem_message_window(u8 a)
{
u8 *ptr = &gBagMenu->windowPointers[a];
if (*ptr != 0xFF)
2018-02-05 05:47:47 +01:00
{
ClearDialogWindowAndFrameToTransparent(*ptr, FALSE);
// This ClearWindowTilemap call is redundant, since ClearDialogWindowAndFrameToTransparent already calls it.
2018-02-05 05:47:47 +01:00
ClearWindowTilemap(*ptr);
RemoveWindow(*ptr);
schedule_bg_copy_tilemap_to_vram(1);
*ptr = 0xFF;
2018-02-05 05:47:47 +01:00
}
}
void BagMenu_YesNo(u8 a, u8 b, const struct YesNoFuncTable *funcTable)
2018-02-05 05:47:47 +01:00
{
CreateYesNoMenuWithCallbacks(a, &gUnknown_086141AC[b], 1, 0, 2, 1, 14, funcTable);
}
void bag_menu_AddMoney_window(void)
{
u8 windowId = BagMenu_AddWindow(9);
2018-02-05 05:47:47 +01:00
PrintMoneyAmountInMoneyBoxWithBorder(windowId, 1, 14, GetMoney(&gSaveBlock1Ptr->money));
AddMoneyLabelObject(19, 11);
}
void bag_menu_remove_money_window(void)
{
BagMenu_RemoveWindow(9);
2018-02-05 05:47:47 +01:00
RemoveMoneyLabelObject();
}
void BagMenu_PrepareTMHMMoveWindow(void)
2018-02-05 05:47:47 +01:00
{
FillWindowPixelBuffer(3, PIXEL_FILL(0));
2018-02-05 05:47:47 +01:00
blit_move_info_icon(3, 19, 0, 0);
blit_move_info_icon(3, 20, 0, 12);
blit_move_info_icon(3, 21, 0, 24);
blit_move_info_icon(3, 22, 0, 36);
CopyWindowToVram(3, 2);
}
void PrintTMHMMoveData(u16 itemId)
{
u8 i;
u16 moveId;
2018-02-12 19:59:42 +01:00
const u8* text;
2018-02-14 01:12:17 +01:00
FillWindowPixelBuffer(4, 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(4, 1, gText_ThreeDashes, 7, i * 12, 0, 0, -1, 4);
2018-02-05 05:47:47 +01:00
CopyWindowToVram(4, 2);
}
else
{
moveId = ItemIdToBattleMoveId(itemId);
blit_move_info_icon(4, gBattleMoves[moveId].type + 1, 0, 0);
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(4, 1, text, 7, 12, 0, 0, -1, 4);
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(4, 1, text, 7, 24, 0, 0, -1, 4);
2019-09-30 21:43:44 +02:00
ConvertIntToDecimalStringN(gStringVar1, gBattleMoves[moveId].pp, STR_CONV_MODE_RIGHT_ALIGN, 3);
BagMenu_Print(4, 1, gStringVar1, 7, 36, 0, 0, -1, 4);
2018-02-05 05:47:47 +01:00
CopyWindowToVram(4, 2);
}
}