pokeemerald/src/player_pc.c

1503 lines
46 KiB
C
Raw Normal View History

2018-03-12 09:26:20 +01:00
#include "global.h"
#include "constants/songs.h"
2018-03-15 11:37:24 +01:00
#include "bg.h"
2018-03-12 09:26:20 +01:00
#include "decoration.h"
#include "event_scripts.h"
#include "event_object_movement.h"
2018-12-08 22:05:11 +01:00
#include "field_screen_effect.h"
2018-03-12 09:26:20 +01:00
#include "field_weather.h"
#include "international_string_util.h"
#include "item.h"
2018-03-15 11:37:24 +01:00
#include "item_icon.h"
2018-03-12 09:26:20 +01:00
#include "item_menu.h"
#include "constants/items.h"
#include "list_menu.h"
2018-03-12 09:26:20 +01:00
#include "mail.h"
#include "main.h"
#include "malloc.h"
2018-03-12 09:26:20 +01:00
#include "menu.h"
#include "menu_helpers.h"
#include "overworld.h"
#include "palette.h"
2018-03-19 11:27:33 +01:00
#include "party_menu.h"
2018-03-12 09:26:20 +01:00
#include "player_pc.h"
#include "script.h"
#include "sound.h"
2018-03-15 11:37:24 +01:00
#include "sprite.h"
2018-03-12 09:26:20 +01:00
#include "string_util.h"
#include "strings.h"
#include "task.h"
#include "window.h"
#include "menu_specialized.h"
2018-03-12 09:26:20 +01:00
2021-04-25 18:07:08 +02:00
// Top level PC menu options
enum {
MENU_ITEMSTORAGE,
MENU_MAILBOX,
MENU_DECORATION,
MENU_TURNOFF
};
// Item storage menu options
enum {
MENU_WITHDRAW,
MENU_DEPOSIT,
MENU_TOSS,
MENU_EXIT
};
// Windows for the main menus (top level menu, and item storage menu)
enum {
WIN_MAIN_MENU,
WIN_MAIN_MENU_BEDROOM,
WIN_ITEM_STORAGE_MENU,
};
// Windows for item storage (while viewing the PC's item inventory)
enum {
2021-08-12 01:14:50 +02:00
ITEMPC_WIN_LIST,
ITEMPC_WIN_MESSAGE,
ITEMPC_WIN_ICON,
ITEMPC_WIN_TITLE,
ITEMPC_WIN_QUANTITY,
ITEMPC_WIN_YESNO,
ITEMPC_WIN_COUNT
2021-04-25 18:07:08 +02:00
};
// When showing the main list, the first window to this window are drawn
2021-08-12 01:14:50 +02:00
#define ITEMPC_WIN_LIST_END ITEMPC_WIN_TITLE
2021-04-25 18:07:08 +02:00
// Message IDs for Item Storage
enum {
MSG_SWITCH_WHICH_ITEM = 0xFFF7,
MSG_OKAY_TO_THROW_AWAY,
MSG_TOO_IMPORTANT,
MSG_NO_MORE_ROOM,
MSG_THREW_AWAY_ITEM,
MSG_HOW_MANY_TO_TOSS,
MSG_WITHDREW_ITEM,
MSG_HOW_MANY_TO_WITHDRAW,
MSG_GO_BACK_TO_PREV
};
#define TAG_ITEM_ICON 5110
#define TAG_SCROLL_ARROW 5112
// Item list ID for toSwapPos to indicate an item is not currently being swapped
#define NOT_SWAPPING 0xFF
#define SWAP_LINE_LENGTH 7
struct ItemStorageMenu
{
2021-04-25 18:07:08 +02:00
struct ListMenuItem listItems[PC_ITEMS_COUNT + 1];
u8 itemNames[PC_ITEMS_COUNT + 1][ITEM_NAME_LENGTH + 10];
2021-08-12 01:14:50 +02:00
u8 windowIds[ITEMPC_WIN_COUNT];
2021-04-25 18:07:08 +02:00
u8 toSwapPos;
2018-03-15 11:37:24 +01:00
u8 spriteId;
2021-04-25 18:07:08 +02:00
u8 swapLineSpriteIds[SWAP_LINE_LENGTH];
};
2018-03-19 11:27:33 +01:00
static void InitPlayerPCMenu(u8 taskId);
static void PlayerPCProcessMenuInput(u8 taskId);
static void InitItemStorageMenu(u8 taskId, u8 var);
static u8 GetMailboxMailCount(void);
2021-04-25 18:07:08 +02:00
static void Mailbox_CompactMailList(void);
2018-03-19 11:27:33 +01:00
static void Mailbox_DrawMailboxMenu(u8 taskId);
static void Mailbox_ProcessInput(u8 taskId);
static void Mailbox_PrintWhatToDoWithPlayerMailText(u8 taskId);
static void Mailbox_ReturnToPlayerPC(u8);
static void Mailbox_PrintMailOptions(u8 taskId);
static void Mailbox_MailOptionsProcessInput(u8 taskId);
static void PlayerPC_ItemStorage(u8 taskId);
static void PlayerPC_Mailbox(u8 taskId);
static void PlayerPC_Decoration(u8 var);
static void PlayerPC_TurnOff(u8 taskId);
static void Mailbox_DoMailMoveToBag(u8 taskId);
static void Mailbox_DoMailRead(u8 taskId);
static void Mailbox_MoveToBag(u8 taskId);
static void Mailbox_Give(u8 taskId);
static void Mailbox_Cancel(u8 taskId);
static void Mailbox_CancelMoveToBag(u8 taskId);
2021-04-25 18:07:08 +02:00
static void Mailbox_HandleConfirmMoveToBag(u8 taskId);
static void Mailbox_AskConfirmMoveToBag(u8 taskId);
2018-03-19 11:27:33 +01:00
static void Mailbox_DoGiveMailPokeMenu(u8 taskId);
static void Mailbox_NoPokemonForMail(u8 taskId);
static void Mailbox_FadeAndReadMail(u8 taskId);
static void Mailbox_ReturnToFieldFromReadMail(void);
2021-04-25 18:07:08 +02:00
static void Mailbox_ReshowAfterMail(void);
2018-03-19 11:27:33 +01:00
static void Mailbox_HandleReturnToProcessInput(u8 taskId);
2018-03-19 11:45:13 +01:00
static void Mailbox_UpdateMailListAfterDeposit(void);
2018-03-19 11:27:33 +01:00
static void ItemStorage_Withdraw(u8 taskId);
static void ItemStorage_Deposit(u8 taskId);
static void ItemStorage_Toss(u8 taskId);
static void ItemStorage_Exit(u8 taskId);
2021-04-25 18:07:08 +02:00
static void ItemStorage_TossItemYes(u8 taskId);
static void ItemStorage_TossItemNo(u8 taskId);
2018-03-19 11:27:33 +01:00
static void ItemStorageMenuPrint(const u8 *);
static void ItemStorageMenuProcessInput(u8 taskId);
2021-04-25 18:07:08 +02:00
static void SetPlayerPCListCount(u8);
2018-03-19 11:27:33 +01:00
static void ItemStorage_HandleReturnToProcessInput(u8 taskId);
2021-04-25 18:07:08 +02:00
static void ItemStorage_Enter(u8 taskId, bool8 toss);
static void ItemStorage_CreateListMenu(u8 taskId);
static void ItemStorage_ProcessInput(u8 taskId);
2018-03-19 11:27:33 +01:00
static void Task_ItemStorage_Deposit(u8 taskId);
2021-04-25 18:07:08 +02:00
static void ItemStorage_ReshowAfterBagMenu(void);
2018-03-19 11:27:33 +01:00
static void ItemStorage_DoItemWithdraw(u8 taskId);
static void ItemStorage_DoItemToss(u8 taskid);
static void ItemStorage_HandleQuantityRolling(u8 taskid);
2021-04-25 18:07:08 +02:00
static void ItemStorage_ExitItemList(u8 taskId);
static void ItemStorage_StartItemSwap(u8 taskId);
2018-03-19 11:27:33 +01:00
static void ItemStorage_DoItemAction(u8 taskId);
2021-04-25 18:07:08 +02:00
static void ItemStorage_FinishItemSwap(u8 taskId, bool8 a);
2018-03-19 11:27:33 +01:00
static void ItemStorage_HandleRemoveItem(u8 taskId);
2021-04-25 18:07:08 +02:00
static void ItemStorage_HandleErrorMessageInput(u8 taskId);
static void ItemStorage_ReturnToListInput(u8 taskId);
2018-03-19 11:27:33 +01:00
2021-04-25 18:07:08 +02:00
static const u8* ItemStorage_GetMessage(u16);
2018-03-19 11:27:33 +01:00
static void CopyItemName_PlayerPC(u8 *string, u16 itemId);
2021-04-25 18:07:08 +02:00
static void ItemStorage_Init(void);
static void ItemStorage_DrawSwapArrow(u8 y, u8, u8 speed);
static void ItemStorage_RemoveWindow(u8);
static void ItemStorage_UpdateSwapLinePos(u8);
static void ItemStorage_ProcessItemSwapInput(u8 taskId);
static void ItemStorage_EraseItemIcon(void);
static void ItemStorage_DrawItemIcon(u16 itemId);
static void ItemStorage_PrintDescription(s32 id);
static void ItemStorage_EraseMainMenu(u8 taskId);
2018-03-19 11:45:13 +01:00
static void ItemStorage_MoveCursor(s32 id, bool8 b, struct ListMenu * thisMenu);
static void ItemStorage_PrintMenuItem(u8 windowId, u32 id, u8 yOffset);
2018-03-19 11:27:33 +01:00
2021-04-25 18:07:08 +02:00
static EWRAM_DATA const u8 *sTopMenuOptionOrder = NULL;
static EWRAM_DATA u8 sTopMenuNumOptions = 0;
EWRAM_DATA struct PlayerPCItemPageStruct gPlayerPCItemPageInfo = {};
static EWRAM_DATA struct ItemStorageMenu *sItemStorageMenu = NULL;
2018-03-12 09:26:20 +01:00
2021-04-25 18:07:08 +02:00
static const u8 *const sItemStorage_OptionDescriptions[] =
2018-03-19 11:27:33 +01:00
{
2021-04-25 18:07:08 +02:00
[MENU_WITHDRAW] = gText_TakeOutItemsFromPC,
[MENU_DEPOSIT] = gText_StoreItemsInPC,
[MENU_TOSS] = gText_ThrowAwayItemsInPC,
[MENU_EXIT] = gText_GoBackPrevMenu,
2018-03-19 11:27:33 +01:00
};
2018-03-12 09:26:20 +01:00
2018-03-19 11:27:33 +01:00
static const struct MenuAction sPlayerPCMenuActions[] =
{
2021-04-25 18:07:08 +02:00
[MENU_ITEMSTORAGE] = { gText_ItemStorage, PlayerPC_ItemStorage },
[MENU_MAILBOX] = { gText_Mailbox, PlayerPC_Mailbox },
[MENU_DECORATION] = { gText_Decoration, PlayerPC_Decoration },
[MENU_TURNOFF] = { gText_TurnOff, PlayerPC_TurnOff }
2018-03-19 11:27:33 +01:00
};
2018-03-12 09:26:20 +01:00
2021-04-25 18:07:08 +02:00
static const u8 sBedroomPC_OptionOrder[] =
2018-03-19 11:27:33 +01:00
{
2021-04-25 18:07:08 +02:00
MENU_ITEMSTORAGE,
MENU_MAILBOX,
MENU_DECORATION,
MENU_TURNOFF
2018-03-19 11:27:33 +01:00
};
2021-04-25 18:07:08 +02:00
#define NUM_BEDROOM_PC_OPTIONS ARRAY_COUNT(sBedroomPC_OptionOrder)
2021-04-25 18:07:08 +02:00
static const u8 sPlayerPC_OptionOrder[] =
2018-03-19 11:27:33 +01:00
{
2021-04-25 18:07:08 +02:00
MENU_ITEMSTORAGE,
MENU_MAILBOX,
MENU_TURNOFF
2018-03-19 11:27:33 +01:00
};
2021-04-25 18:07:08 +02:00
#define NUM_PLAYER_PC_OPTIONS ARRAY_COUNT(sPlayerPC_OptionOrder)
2021-04-25 18:07:08 +02:00
static const struct MenuAction sItemStorage_MenuActions[] =
2018-03-19 11:27:33 +01:00
{
2021-04-25 18:07:08 +02:00
[MENU_WITHDRAW] = { gText_WithdrawItem, ItemStorage_Withdraw },
[MENU_DEPOSIT] = { gText_DepositItem, ItemStorage_Deposit },
[MENU_TOSS] = { gText_TossItem, ItemStorage_Toss },
[MENU_EXIT] = { gText_Cancel, ItemStorage_Exit }
2018-03-19 11:27:33 +01:00
};
2018-03-12 09:26:20 +01:00
2021-04-25 18:07:08 +02:00
static const struct ItemSlot sNewGamePCItems[] =
2018-03-19 11:27:33 +01:00
{
{ ITEM_POTION, 1 },
{ ITEM_NONE, 0 }
};
2018-03-19 11:27:33 +01:00
const struct MenuAction gMailboxMailOptions[] =
{
2021-04-25 18:07:08 +02:00
{ gText_Read, Mailbox_DoMailRead },
2018-03-19 11:27:33 +01:00
{ gText_MoveToBag, Mailbox_MoveToBag },
2021-04-25 18:07:08 +02:00
{ gText_Give2, Mailbox_Give },
{ gText_Cancel2, Mailbox_Cancel }
2018-03-19 11:27:33 +01:00
};
2018-03-12 09:26:20 +01:00
2021-04-25 18:07:08 +02:00
static const struct WindowTemplate sWindowTemplates_MainMenus[] =
2018-03-19 11:27:33 +01:00
{
2021-04-25 18:07:08 +02:00
[WIN_MAIN_MENU] = {
2018-10-27 00:53:07 +02:00
.bg = 0,
2018-09-02 18:53:52 +02:00
.tilemapLeft = 1,
.tilemapTop = 1,
.width = 9,
.height = 6,
.paletteNum = 15,
.baseBlock = 1
},
2021-04-25 18:07:08 +02:00
[WIN_MAIN_MENU_BEDROOM] = {
2018-10-27 00:53:07 +02:00
.bg = 0,
2018-09-02 18:53:52 +02:00
.tilemapLeft = 1,
.tilemapTop = 1,
.width = 9,
.height = 8,
.paletteNum = 15,
.baseBlock = 1
},
2021-04-25 18:07:08 +02:00
[WIN_ITEM_STORAGE_MENU] = {
2018-10-27 00:53:07 +02:00
.bg = 0,
2018-09-02 18:53:52 +02:00
.tilemapLeft = 1,
.tilemapTop = 1,
.width = 10,
.height = 8,
.paletteNum = 15,
.baseBlock = 1
}
2018-03-19 11:27:33 +01:00
};
2018-03-12 09:26:20 +01:00
2021-04-25 18:07:08 +02:00
static const struct YesNoFuncTable ItemTossYesNoFuncs =
2018-03-19 11:27:33 +01:00
{
2021-04-25 18:07:08 +02:00
ItemStorage_TossItemYes,
ItemStorage_TossItemNo
2018-03-19 11:27:33 +01:00
};
2018-03-12 09:26:20 +01:00
2021-04-25 18:07:08 +02:00
static const struct ListMenuTemplate sListMenuTemplate_ItemStorage =
2018-09-02 18:53:52 +02:00
{
.items = NULL,
.moveCursorFunc = ItemStorage_MoveCursor,
2021-04-25 18:07:08 +02:00
.itemPrintFunc = ItemStorage_PrintMenuItem,
2018-09-02 18:53:52 +02:00
.totalItems = 0,
.maxShowed = 0,
.windowId = 0,
.header_X = 0,
.item_X = 8,
.cursor_X = 0,
.upText_Y = 9,
.cursorPal = 2,
.fillValue = 1,
.cursorShadowPal = 3,
.lettersSpacing = FALSE,
.itemVerticalPadding = 0,
.scrollMultiple = FALSE,
.fontId = 7
2018-03-19 11:27:33 +01:00
};
2018-03-12 09:26:20 +01:00
2021-08-12 01:14:50 +02:00
static const struct WindowTemplate sWindowTemplates_ItemStorage[ITEMPC_WIN_COUNT] =
2018-03-19 11:27:33 +01:00
{
2021-08-12 01:14:50 +02:00
[ITEMPC_WIN_LIST] = {
2018-10-27 00:53:07 +02:00
.bg = 0,
2018-09-02 18:53:52 +02:00
.tilemapLeft = 16,
.tilemapTop = 1,
.width = 13,
.height = 18,
.paletteNum = 15,
.baseBlock = 0x0001
},
2021-08-12 01:14:50 +02:00
[ITEMPC_WIN_MESSAGE] = {
2018-10-27 00:53:07 +02:00
.bg = 0,
2018-09-02 18:53:52 +02:00
.tilemapLeft = 1,
.tilemapTop = 13,
.width = 13,
.height = 6,
.paletteNum = 15,
.baseBlock = 0x00EB
},
2021-08-12 01:14:50 +02:00
[ITEMPC_WIN_ICON] = {
2018-10-27 00:53:07 +02:00
.bg = 0,
2018-09-02 18:53:52 +02:00
.tilemapLeft = 1,
.tilemapTop = 8,
.width = 3,
.height = 3,
.paletteNum = 15,
.baseBlock = 0x0153
},
2021-08-12 01:14:50 +02:00
[ITEMPC_WIN_TITLE] = {
2018-10-27 00:53:07 +02:00
.bg = 0,
2018-09-02 18:53:52 +02:00
.tilemapLeft = 1,
.tilemapTop = 1,
.width = 13,
.height = 2,
.paletteNum = 15,
.baseBlock = 0x0139
},
2021-08-12 01:14:50 +02:00
[ITEMPC_WIN_QUANTITY] = {
2018-10-27 00:53:07 +02:00
.bg = 0,
2018-09-02 18:53:52 +02:00
.tilemapLeft = 8,
.tilemapTop = 9,
.width = 6,
.height = 2,
.paletteNum = 15,
.baseBlock = 0x015C
2021-04-25 18:07:08 +02:00
},
2021-08-12 01:14:50 +02:00
[ITEMPC_WIN_YESNO] = {
2021-04-25 18:07:08 +02:00
.bg = 0,
.tilemapLeft = 9,
.tilemapTop = 7,
.width = 5,
.height = 4,
.paletteNum = 15,
.baseBlock = 0x0168
2018-09-02 18:53:52 +02:00
}
2018-03-19 11:27:33 +01:00
};
2018-03-12 09:26:20 +01:00
2021-04-25 18:07:08 +02:00
static const u8 sSwapArrowTextColors[] = {TEXT_COLOR_WHITE, TEXT_COLOR_LIGHT_GRAY, TEXT_COLOR_DARK_GRAY};
2018-03-12 09:26:20 +01:00
2021-04-25 18:07:08 +02:00
// Macro below is likely a fakematch, equivalent to sNewGamePCItems[i].quantity
#define GET_QUANTITY(i) ((u16)((u16 *)sNewGamePCItems + 1)[i * 2])
2018-03-12 09:26:20 +01:00
void NewGameInitPCItems(void)
{
2021-04-25 18:07:08 +02:00
u8 i = 0;
ClearItemSlots(gSaveBlock1Ptr->pcItems, PC_ITEMS_COUNT);
for(; sNewGamePCItems[i].itemId != ITEM_NONE && GET_QUANTITY(i) &&
AddPCItem(sNewGamePCItems[i].itemId, GET_QUANTITY(i)) == TRUE; i++);
2018-03-12 09:26:20 +01:00
}
2021-04-25 18:07:08 +02:00
#undef GET_QUANTITY
2018-03-12 09:26:20 +01:00
void BedroomPC(void)
{
2021-04-25 18:07:08 +02:00
sTopMenuOptionOrder = sBedroomPC_OptionOrder;
sTopMenuNumOptions = NUM_BEDROOM_PC_OPTIONS;
2018-03-12 09:26:20 +01:00
DisplayItemMessageOnField(CreateTask(TaskDummy, 0), gText_WhatWouldYouLike, InitPlayerPCMenu);
}
void PlayerPC(void)
{
2021-04-25 18:07:08 +02:00
sTopMenuOptionOrder = sPlayerPC_OptionOrder;
sTopMenuNumOptions = NUM_PLAYER_PC_OPTIONS;
2018-03-12 09:26:20 +01:00
DisplayItemMessageOnField(CreateTask(TaskDummy, 0), gText_WhatWouldYouLike, InitPlayerPCMenu);
}
2021-04-25 18:07:08 +02:00
#define tUsedSlots data[1]
#define tQuantity data[2]
#define tInTossMenu data[3]
#define tWindowId data[4]
#define tListTaskId data[5]
2018-03-19 11:27:33 +01:00
static void InitPlayerPCMenu(u8 taskId)
2018-03-12 09:26:20 +01:00
{
u16 *data;
2018-03-12 09:26:20 +01:00
struct WindowTemplate windowTemplate;
data = gTasks[taskId].data;
2021-04-25 18:07:08 +02:00
if (sTopMenuNumOptions == NUM_PLAYER_PC_OPTIONS)
windowTemplate = sWindowTemplates_MainMenus[WIN_MAIN_MENU];
else // Bedroom PC
windowTemplate = sWindowTemplates_MainMenus[WIN_MAIN_MENU_BEDROOM];
windowTemplate.width = sub_81DB3D8(sPlayerPCMenuActions, sTopMenuOptionOrder, sTopMenuNumOptions);
tWindowId = AddWindow(&windowTemplate);
SetStandardWindowBorderStyle(tWindowId, 0);
sub_81995E4(tWindowId, sTopMenuNumOptions, sPlayerPCMenuActions, sTopMenuOptionOrder);
InitMenuInUpperLeftCornerPlaySoundWhenAPressed(tWindowId, sTopMenuNumOptions, 0);
2020-05-14 10:37:09 +02:00
ScheduleBgCopyTilemapToVram(0);
2018-03-12 09:26:20 +01:00
gTasks[taskId].func = PlayerPCProcessMenuInput;
}
2018-03-19 11:27:33 +01:00
static void PlayerPCProcessMenuInput(u8 taskId)
2018-03-12 09:26:20 +01:00
{
u16 *data;
2018-03-12 09:26:20 +01:00
s8 inputOptionId;
data = gTasks[taskId].data;
2021-04-25 18:07:08 +02:00
if (sTopMenuNumOptions > 3)
2018-11-05 21:45:54 +01:00
inputOptionId = Menu_ProcessInput();
2018-03-12 09:26:20 +01:00
else
2018-11-05 21:45:54 +01:00
inputOptionId = Menu_ProcessInputNoWrap();
2018-03-12 09:26:20 +01:00
2019-02-02 11:04:38 +01:00
switch (inputOptionId)
2018-03-12 09:26:20 +01:00
{
2021-04-25 18:07:08 +02:00
case MENU_NOTHING_CHOSEN:
break;
case MENU_B_PRESSED:
PlaySE(SE_SELECT);
ClearStdWindowAndFrameToTransparent(tWindowId, FALSE);
ClearWindowTilemap(tWindowId);
RemoveWindow(tWindowId);
ScheduleBgCopyTilemapToVram(0);
gTasks[taskId].func = PlayerPC_TurnOff;
break;
default:
ClearStdWindowAndFrameToTransparent(tWindowId, FALSE);
ClearWindowTilemap(tWindowId);
RemoveWindow(tWindowId);
ScheduleBgCopyTilemapToVram(0);
gTasks[taskId].func = sPlayerPCMenuActions[sTopMenuOptionOrder[inputOptionId]].func.void_u8;
break;
2018-03-12 09:26:20 +01:00
}
}
void ReshowPlayerPC(u8 var)
{
DisplayItemMessageOnField(var, gText_WhatWouldYouLike, InitPlayerPCMenu);
}
2018-03-19 11:27:33 +01:00
static void PlayerPC_ItemStorage(u8 taskId)
2018-03-12 09:26:20 +01:00
{
2021-04-25 18:07:08 +02:00
InitItemStorageMenu(taskId, MENU_WITHDRAW);
2018-03-12 09:26:20 +01:00
gTasks[taskId].func = ItemStorageMenuProcessInput;
}
2018-03-19 11:27:33 +01:00
static void PlayerPC_Mailbox(u8 taskId)
2018-03-12 09:26:20 +01:00
{
2021-04-25 18:07:08 +02:00
gPlayerPCItemPageInfo.count = GetMailboxMailCount();
2018-03-12 09:26:20 +01:00
2021-04-25 18:07:08 +02:00
if (gPlayerPCItemPageInfo.count == 0)
{
// Mailbox cannot be opened if no mail is in PC
2018-03-12 09:26:20 +01:00
DisplayItemMessageOnField(taskId, gText_NoMailHere, ReshowPlayerPC);
2021-04-25 18:07:08 +02:00
}
2018-03-12 09:26:20 +01:00
else
{
2021-04-25 18:07:08 +02:00
gPlayerPCItemPageInfo.cursorPos = 0;
gPlayerPCItemPageInfo.itemsAbove = 0;
gPlayerPCItemPageInfo.scrollIndicatorTaskId = TASK_NONE;
Mailbox_CompactMailList();
SetPlayerPCListCount(taskId);
if (MailboxMenu_Alloc(gPlayerPCItemPageInfo.count) == TRUE)
2018-03-12 09:26:20 +01:00
{
ClearDialogWindowAndFrame(0, 0);
2018-03-12 09:26:20 +01:00
Mailbox_DrawMailboxMenu(taskId);
gTasks[taskId].func = Mailbox_ProcessInput;
}
2021-04-25 18:07:08 +02:00
else
{
// Alloc failed, exit Mailbox
2018-03-12 09:26:20 +01:00
DisplayItemMessageOnField(taskId, gText_NoMailHere, ReshowPlayerPC);
2021-04-25 18:07:08 +02:00
}
2018-03-12 09:26:20 +01:00
}
}
static void PlayerPC_Decoration(u8 taskId)
2018-03-12 09:26:20 +01:00
{
DoPlayerRoomDecorationMenu(taskId);
2018-03-12 09:26:20 +01:00
}
2018-03-19 11:27:33 +01:00
static void PlayerPC_TurnOff(u8 taskId)
2018-03-12 09:26:20 +01:00
{
2021-04-25 18:07:08 +02:00
if (sTopMenuNumOptions == NUM_BEDROOM_PC_OPTIONS) // Flimsy way to determine if Bedroom PC is in use
2018-03-12 09:26:20 +01:00
{
if (gSaveBlock2Ptr->playerGender == MALE)
ScriptContext1_SetupScript(LittlerootTown_BrendansHouse_2F_EventScript_TurnOffPlayerPC);
2018-03-12 09:26:20 +01:00
else
ScriptContext1_SetupScript(LittlerootTown_MaysHouse_2F_EventScript_TurnOffPlayerPC);
2018-03-12 09:26:20 +01:00
}
else
{
EnableBothScriptContexts();
}
DestroyTask(taskId);
}
2018-03-19 11:27:33 +01:00
static void InitItemStorageMenu(u8 taskId, u8 var)
2018-03-12 09:26:20 +01:00
{
u16 *data;
2018-03-12 09:26:20 +01:00
struct WindowTemplate windowTemplate;
data = gTasks[taskId].data;
2021-04-25 18:07:08 +02:00
windowTemplate = sWindowTemplates_MainMenus[WIN_ITEM_STORAGE_MENU];
windowTemplate.width = GetMaxWidthInMenuTable(sItemStorage_MenuActions, ARRAY_COUNT(sItemStorage_MenuActions));
tWindowId = AddWindow(&windowTemplate);
SetStandardWindowBorderStyle(tWindowId, 0);
PrintMenuTable(tWindowId, ARRAY_COUNT(sItemStorage_MenuActions), sItemStorage_MenuActions);
InitMenuInUpperLeftCornerPlaySoundWhenAPressed(tWindowId, 4, var);
2020-05-14 10:37:09 +02:00
ScheduleBgCopyTilemapToVram(0);
2021-04-25 18:07:08 +02:00
ItemStorageMenuPrint(sItemStorage_OptionDescriptions[var]);
2018-03-12 09:26:20 +01:00
}
2018-03-19 11:27:33 +01:00
static void ItemStorageMenuPrint(const u8 *textPtr)
2018-03-12 09:26:20 +01:00
{
DrawDialogueFrame(0, 0);
AddTextPrinterParameterized(0, 1, textPtr, 0, 1, 0, 0);
2018-03-12 09:26:20 +01:00
}
2018-03-19 11:27:33 +01:00
static void ItemStorageMenuProcessInput(u8 taskId)
2018-03-12 09:26:20 +01:00
{
2021-04-25 18:07:08 +02:00
s8 oldPos, newPos;
2018-03-12 09:26:20 +01:00
s8 inputOptionId;
2021-04-25 18:07:08 +02:00
oldPos = Menu_GetCursorPos();
2018-11-05 21:45:54 +01:00
inputOptionId = Menu_ProcessInput();
2021-04-25 18:07:08 +02:00
newPos = Menu_GetCursorPos();
2019-02-02 11:04:38 +01:00
switch (inputOptionId)
2018-03-12 09:26:20 +01:00
{
2021-04-25 18:07:08 +02:00
case MENU_NOTHING_CHOSEN:
if (oldPos != newPos)
ItemStorageMenuPrint(sItemStorage_OptionDescriptions[newPos]);
break;
case MENU_B_PRESSED:
PlaySE(SE_SELECT);
ItemStorage_Exit(taskId);
break;
default:
PlaySE(SE_SELECT);
sItemStorage_MenuActions[inputOptionId].func.void_u8(taskId);
break;
2018-03-12 09:26:20 +01:00
}
}
2018-03-19 11:27:33 +01:00
static void ItemStorage_Deposit(u8 taskId)
2018-03-12 09:26:20 +01:00
{
gTasks[taskId].func = Task_ItemStorage_Deposit;
2019-12-15 17:42:50 +01:00
FadeScreen(FADE_TO_BLACK, 0);
2018-03-12 09:26:20 +01:00
}
2018-03-19 11:27:33 +01:00
static void Task_ItemStorage_Deposit(u8 taskId)
2018-03-12 09:26:20 +01:00
{
if (!gPaletteFade.active)
{
2018-12-27 23:30:47 +01:00
CleanupOverworldWindowsAndTilemaps();
2020-05-14 10:37:09 +02:00
CB2_GoToItemDepositMenu();
2018-03-12 09:26:20 +01:00
DestroyTask(taskId);
}
}
2021-04-25 18:07:08 +02:00
void CB2_PlayerPCExitBagMenu(void)
2018-03-12 09:26:20 +01:00
{
2021-04-25 18:07:08 +02:00
gFieldCallback = ItemStorage_ReshowAfterBagMenu;
2018-03-12 09:26:20 +01:00
SetMainCallback2(CB2_ReturnToField);
}
2021-04-25 18:07:08 +02:00
static void ItemStorage_ReshowAfterBagMenu(void)
2018-03-12 09:26:20 +01:00
{
2020-02-07 18:48:47 +01:00
LoadMessageBoxAndBorderGfx();
DrawDialogueFrame(0, 1);
2018-03-12 09:26:20 +01:00
InitItemStorageMenu(CreateTask(ItemStorage_HandleReturnToProcessInput, 0), 1);
2019-12-17 09:24:44 +01:00
FadeInFromBlack();
2018-03-12 09:26:20 +01:00
}
2018-03-19 11:27:33 +01:00
static void ItemStorage_HandleReturnToProcessInput(u8 taskId)
2018-03-12 09:26:20 +01:00
{
if (IsWeatherNotFadingIn() == TRUE)
2018-03-12 09:26:20 +01:00
gTasks[taskId].func = ItemStorageMenuProcessInput;
}
2018-03-19 11:27:33 +01:00
static void ItemStorage_Withdraw(u8 taskId)
2018-03-12 09:26:20 +01:00
{
s16 *data = gTasks[taskId].data;
2021-04-25 18:07:08 +02:00
tUsedSlots = CountUsedPCItemSlots();
if (tUsedSlots != 0)
{
ItemStorage_Enter(taskId, FALSE);
}
2018-03-12 09:26:20 +01:00
else
{
2021-04-25 18:07:08 +02:00
// Can't withdraw, no items in PC
ItemStorage_EraseMainMenu(taskId);
2018-03-12 09:26:20 +01:00
DisplayItemMessageOnField(taskId, gText_NoItems, PlayerPC_ItemStorage);
}
}
2018-03-19 11:27:33 +01:00
static void ItemStorage_Toss(u8 taskId)
2018-03-12 09:26:20 +01:00
{
s16 *data = gTasks[taskId].data;
2021-04-25 18:07:08 +02:00
tUsedSlots = CountUsedPCItemSlots();
if (tUsedSlots != 0)
{
ItemStorage_Enter(taskId, TRUE);
}
2018-03-12 09:26:20 +01:00
else
{
2021-04-25 18:07:08 +02:00
// Can't toss, no items in PC
ItemStorage_EraseMainMenu(taskId);
2018-03-12 09:26:20 +01:00
DisplayItemMessageOnField(taskId, gText_NoItems, PlayerPC_ItemStorage);
}
}
2021-04-25 18:07:08 +02:00
static void ItemStorage_Enter(u8 taskId, bool8 toss)
2018-03-12 09:26:20 +01:00
{
u16 *data = gTasks[taskId].data;
2018-03-12 09:26:20 +01:00
2021-04-25 18:07:08 +02:00
tInTossMenu = toss;
ItemStorage_EraseMainMenu(taskId);
gPlayerPCItemPageInfo.cursorPos = 0;
gPlayerPCItemPageInfo.itemsAbove = 0;
gPlayerPCItemPageInfo.scrollIndicatorTaskId = TASK_NONE;
SetPlayerPCListCount(taskId);
ItemStorage_Init();
2018-09-03 00:20:45 +02:00
FreeAndReserveObjectSpritePalettes();
2021-04-11 22:23:10 +02:00
LoadListMenuSwapLineGfx();
2021-04-25 18:07:08 +02:00
CreateSwapLineSprites(sItemStorageMenu->swapLineSpriteIds, SWAP_LINE_LENGTH);
ClearDialogWindowAndFrame(0,0);
2021-04-25 18:07:08 +02:00
gTasks[taskId].func = ItemStorage_CreateListMenu;
2018-03-12 09:26:20 +01:00
}
2018-03-19 11:27:33 +01:00
static void ItemStorage_Exit(u8 taskId)
2018-03-12 09:26:20 +01:00
{
2021-04-25 18:07:08 +02:00
ItemStorage_EraseMainMenu(taskId);
2018-03-12 09:26:20 +01:00
ReshowPlayerPC(taskId);
}
2021-04-25 18:07:08 +02:00
// Used by Item Storage and the Mailbox
static void SetPlayerPCListCount(u8 taskId)
2018-03-12 09:26:20 +01:00
{
2021-04-25 18:07:08 +02:00
if (gPlayerPCItemPageInfo.count > 7)
gPlayerPCItemPageInfo.pageItems = 8;
2018-03-12 09:26:20 +01:00
else
2021-04-25 18:07:08 +02:00
gPlayerPCItemPageInfo.pageItems = gPlayerPCItemPageInfo.count + 1;
2018-03-12 09:26:20 +01:00
}
2021-04-25 18:07:08 +02:00
static void ItemStorage_EraseMainMenu(u8 taskId)
2018-03-12 09:26:20 +01:00
{
u16 *data = gTasks[taskId].data;
2021-04-25 18:07:08 +02:00
ClearStdWindowAndFrameToTransparent(tWindowId, FALSE);
ClearWindowTilemap(tWindowId);
RemoveWindow(tWindowId);
2020-05-14 10:37:09 +02:00
ScheduleBgCopyTilemapToVram(0);
2018-03-12 09:26:20 +01:00
}
2018-03-19 11:27:33 +01:00
static u8 GetMailboxMailCount(void)
2018-03-12 09:26:20 +01:00
{
2021-04-25 18:07:08 +02:00
u8 mailInPC, i;
2018-03-12 09:26:20 +01:00
2021-04-25 18:07:08 +02:00
// Count mail in PC (by first skipping over mail in party)
for (mailInPC = 0, i = PARTY_SIZE; i < MAIL_COUNT; i++)
if (gSaveBlock1Ptr->mail[i].itemId != ITEM_NONE)
mailInPC++;
2018-03-12 09:26:20 +01:00
2021-04-25 18:07:08 +02:00
return mailInPC;
2018-03-12 09:26:20 +01:00
}
2021-04-25 18:07:08 +02:00
static void Mailbox_CompactMailList(void)
2018-03-12 09:26:20 +01:00
{
2021-04-25 18:07:08 +02:00
struct MailStruct temp;
2018-03-12 09:26:20 +01:00
u8 i, j;
2021-02-20 21:15:38 +01:00
for (i = PARTY_SIZE; i < MAIL_COUNT - 1; i++)
2018-03-12 09:26:20 +01:00
{
2021-02-20 21:15:38 +01:00
for (j = i + 1; j < MAIL_COUNT; j++)
2018-03-12 09:26:20 +01:00
{
2021-04-25 18:07:08 +02:00
if (gSaveBlock1Ptr->mail[i].itemId == ITEM_NONE)
SWAP(gSaveBlock1Ptr->mail[i], gSaveBlock1Ptr->mail[j], temp);
2018-03-12 09:26:20 +01:00
}
}
}
2018-03-19 11:27:33 +01:00
static void Mailbox_DrawMailboxMenu(u8 taskId)
2018-03-12 09:26:20 +01:00
{
2021-04-25 18:07:08 +02:00
u8 windowId = MailboxMenu_AddWindow(MAILBOXWIN_TITLE);
MailboxMenu_AddWindow(MAILBOXWIN_LIST);
AddTextPrinterParameterized(windowId, 1, gText_Mailbox, GetStringCenterAlignXOffset(1, gText_Mailbox, 0x40), 1, 0, NULL);
2020-05-14 10:37:09 +02:00
ScheduleBgCopyTilemapToVram(0);
2021-04-25 18:07:08 +02:00
gTasks[taskId].tListTaskId = MailboxMenu_CreateList(&gPlayerPCItemPageInfo);
MailboxMenu_AddScrollArrows(&gPlayerPCItemPageInfo);
2018-03-12 09:26:20 +01:00
}
2018-03-19 11:27:33 +01:00
static void Mailbox_ProcessInput(u8 taskId)
2018-03-12 09:26:20 +01:00
{
u16 *data = gTasks[taskId].data;
2018-11-28 21:08:22 +01:00
if (!gPaletteFade.active)
2018-03-12 09:26:20 +01:00
{
2021-04-25 18:07:08 +02:00
s32 inputOptionId = ListMenu_ProcessInput(tListTaskId);
ListMenuGetScrollAndRow(tListTaskId, &gPlayerPCItemPageInfo.itemsAbove, &gPlayerPCItemPageInfo.cursorPos);
2018-03-12 09:26:20 +01:00
2019-02-02 11:04:38 +01:00
switch (inputOptionId)
2018-03-12 09:26:20 +01:00
{
2021-04-25 18:07:08 +02:00
case LIST_NOTHING_CHOSEN:
break;
case LIST_CANCEL:
PlaySE(SE_SELECT);
RemoveScrollIndicatorArrowPair(gPlayerPCItemPageInfo.scrollIndicatorTaskId);
Mailbox_ReturnToPlayerPC(taskId);
break;
default:
// Selected mail, ask what to do with it
PlaySE(SE_SELECT);
MailboxMenu_RemoveWindow(MAILBOXWIN_TITLE);
MailboxMenu_RemoveWindow(MAILBOXWIN_LIST);
DestroyListMenuTask(tListTaskId, &gPlayerPCItemPageInfo.itemsAbove, &gPlayerPCItemPageInfo.cursorPos);
ScheduleBgCopyTilemapToVram(0);
RemoveScrollIndicatorArrowPair(gPlayerPCItemPageInfo.scrollIndicatorTaskId);
gTasks[taskId].func = Mailbox_PrintWhatToDoWithPlayerMailText;
break;
2018-03-12 09:26:20 +01:00
}
}
}
2018-03-19 11:27:33 +01:00
static void Mailbox_PrintWhatToDoWithPlayerMailText(u8 taskId)
2018-03-12 09:26:20 +01:00
{
2021-04-25 18:07:08 +02:00
StringCopy(gStringVar1, gSaveBlock1Ptr->mail[gPlayerPCItemPageInfo.itemsAbove + PARTY_SIZE + gPlayerPCItemPageInfo.cursorPos].playerName);
2021-02-20 21:15:38 +01:00
ConvertInternationalPlayerNameStripChar(gStringVar1, CHAR_SPACE);
2018-03-12 09:26:20 +01:00
StringExpandPlaceholders(gStringVar4, gText_WhatToDoWithVar1sMail);
DisplayItemMessageOnField(taskId, gStringVar4, Mailbox_PrintMailOptions);
2018-03-12 09:26:20 +01:00
}
2018-03-19 11:27:33 +01:00
static void Mailbox_ReturnToPlayerPC(u8 taskId)
2018-03-12 09:26:20 +01:00
{
s16 *data = gTasks[taskId].data;
2021-04-25 18:07:08 +02:00
MailboxMenu_RemoveWindow(MAILBOXWIN_TITLE);
MailboxMenu_RemoveWindow(MAILBOXWIN_LIST);
DestroyListMenuTask(tListTaskId, NULL, NULL);
2020-05-14 10:37:09 +02:00
ScheduleBgCopyTilemapToVram(0);
2021-04-25 18:07:08 +02:00
MailboxMenu_Free();
2018-03-12 09:26:20 +01:00
ReshowPlayerPC(taskId);
}
2018-03-19 11:27:33 +01:00
static void Mailbox_PrintMailOptions(u8 taskId)
2018-03-12 09:26:20 +01:00
{
2021-04-25 18:07:08 +02:00
u8 windowId = MailboxMenu_AddWindow(MAILBOXWIN_OPTIONS);
PrintMenuTable(windowId, ARRAY_COUNT(gMailboxMailOptions), gMailboxMailOptions);
InitMenuInUpperLeftCornerPlaySoundWhenAPressed(windowId, 4, 0);
2020-05-14 10:37:09 +02:00
ScheduleBgCopyTilemapToVram(0);
gTasks[taskId].func = Mailbox_MailOptionsProcessInput;
2018-03-12 09:26:20 +01:00
}
2018-03-19 11:27:33 +01:00
static void Mailbox_MailOptionsProcessInput(u8 taskId)
2018-03-12 09:26:20 +01:00
{
s8 inputOptionId = ProcessMenuInput_other();
2021-04-25 18:07:08 +02:00
switch (inputOptionId)
2018-03-12 09:26:20 +01:00
{
2021-04-25 18:07:08 +02:00
case MENU_NOTHING_CHOSEN:
break;
case MENU_B_PRESSED:
PlaySE(SE_SELECT);
Mailbox_Cancel(taskId);
break;
default:
PlaySE(SE_SELECT);
gMailboxMailOptions[inputOptionId].func.void_u8(taskId);
break;
2018-03-12 09:26:20 +01:00
}
}
2018-03-19 11:27:33 +01:00
static void Mailbox_DoMailRead(u8 taskId)
2018-03-12 09:26:20 +01:00
{
2019-12-15 17:42:50 +01:00
FadeScreen(FADE_TO_BLACK, 0);
gTasks[taskId].func = Mailbox_FadeAndReadMail;
2018-03-12 09:26:20 +01:00
}
2018-03-19 11:27:33 +01:00
static void Mailbox_FadeAndReadMail(u8 taskId)
2018-03-12 09:26:20 +01:00
{
2018-11-28 21:08:22 +01:00
if (!gPaletteFade.active)
2018-03-12 09:26:20 +01:00
{
2021-04-25 18:07:08 +02:00
MailboxMenu_Free();
2018-12-27 23:30:47 +01:00
CleanupOverworldWindowsAndTilemaps();
2021-04-25 18:07:08 +02:00
ReadMail(&gSaveBlock1Ptr->mail[gPlayerPCItemPageInfo.itemsAbove + PARTY_SIZE + gPlayerPCItemPageInfo.cursorPos], Mailbox_ReturnToFieldFromReadMail, TRUE);
2018-03-12 09:26:20 +01:00
DestroyTask(taskId);
}
}
2018-03-19 11:27:33 +01:00
static void Mailbox_ReturnToFieldFromReadMail(void)
2018-03-12 09:26:20 +01:00
{
2021-04-25 18:07:08 +02:00
gFieldCallback = Mailbox_ReshowAfterMail;
2018-03-12 09:26:20 +01:00
SetMainCallback2(CB2_ReturnToField);
}
2021-04-25 18:07:08 +02:00
static void Mailbox_ReshowAfterMail(void)
{
u8 taskId;
2020-02-07 18:48:47 +01:00
LoadMessageBoxAndBorderGfx();
taskId = CreateTask(Mailbox_HandleReturnToProcessInput, 0);
2021-04-25 18:07:08 +02:00
if (MailboxMenu_Alloc(gPlayerPCItemPageInfo.count) == TRUE)
Mailbox_DrawMailboxMenu(taskId);
else
DestroyTask(taskId);
2019-12-17 09:24:44 +01:00
FadeInFromBlack();
}
2018-03-19 11:27:33 +01:00
static void Mailbox_HandleReturnToProcessInput(u8 taskId)
{
2018-11-28 21:08:22 +01:00
if (IsWeatherNotFadingIn() == TRUE)
gTasks[taskId].func = Mailbox_ProcessInput;
}
2018-03-19 11:27:33 +01:00
static void Mailbox_MoveToBag(u8 taskId)
{
2021-04-25 18:07:08 +02:00
DisplayItemMessageOnField(taskId, gText_MessageWillBeLost, Mailbox_AskConfirmMoveToBag);
}
2021-04-25 18:07:08 +02:00
static void Mailbox_AskConfirmMoveToBag(u8 taskId)
{
2019-02-27 04:30:40 +01:00
DisplayYesNoMenuDefaultYes();
2021-04-25 18:07:08 +02:00
gTasks[taskId].func = Mailbox_HandleConfirmMoveToBag;
}
2021-04-25 18:07:08 +02:00
static void Mailbox_HandleConfirmMoveToBag(u8 taskId)
{
2021-04-25 18:07:08 +02:00
switch (Menu_ProcessInputNoWrapClearOnChoose())
{
2021-04-25 18:07:08 +02:00
case 0: // Yes
Mailbox_DoMailMoveToBag(taskId);
break;
case MENU_B_PRESSED:
PlaySE(SE_SELECT);
case 1: // No
Mailbox_CancelMoveToBag(taskId);
break;
case MENU_NOTHING_CHOSEN:
default:
break;
}
}
2018-03-19 11:27:33 +01:00
static void Mailbox_DoMailMoveToBag(u8 taskId)
{
2021-04-25 18:07:08 +02:00
struct MailStruct *mail = &gSaveBlock1Ptr->mail[gPlayerPCItemPageInfo.itemsAbove + PARTY_SIZE + gPlayerPCItemPageInfo.cursorPos];
if (!AddBagItem(mail->itemId, 1))
{
DisplayItemMessageOnField(taskId, gText_BagIsFull, Mailbox_Cancel);
}
else
{
DisplayItemMessageOnField(taskId, gText_MailToBagMessageErased, Mailbox_Cancel);
2021-04-25 18:07:08 +02:00
ClearMailStruct(mail);
Mailbox_CompactMailList();
gPlayerPCItemPageInfo.count--;
if (gPlayerPCItemPageInfo.count < (gPlayerPCItemPageInfo.pageItems + gPlayerPCItemPageInfo.itemsAbove) && gPlayerPCItemPageInfo.itemsAbove != 0)
gPlayerPCItemPageInfo.itemsAbove--;
SetPlayerPCListCount(taskId);
}
}
2018-03-19 11:27:33 +01:00
static void Mailbox_CancelMoveToBag(u8 taskId)
{
Mailbox_Cancel(taskId);
}
2018-03-19 11:27:33 +01:00
static void Mailbox_Give(u8 taskId)
{
2018-11-28 21:08:22 +01:00
if (CalculatePlayerPartyCount() == 0)
Mailbox_NoPokemonForMail(taskId);
else
{
2019-12-15 17:42:50 +01:00
FadeScreen(FADE_TO_BLACK, 0);
gTasks[taskId].func = Mailbox_DoGiveMailPokeMenu;
}
}
2018-03-19 11:27:33 +01:00
static void Mailbox_DoGiveMailPokeMenu(u8 taskId)
{
2018-11-28 21:08:22 +01:00
if (!gPaletteFade.active)
{
2021-04-25 18:07:08 +02:00
MailboxMenu_Free();
2018-12-27 23:30:47 +01:00
CleanupOverworldWindowsAndTilemaps();
2019-10-18 01:22:03 +02:00
ChooseMonToGiveMailFromMailbox();
DestroyTask(taskId);
}
}
void Mailbox_ReturnToMailListAfterDeposit(void)
{
gFieldCallback = Mailbox_UpdateMailListAfterDeposit;
SetMainCallback2(CB2_ReturnToField);
}
2018-03-19 11:27:33 +01:00
static void Mailbox_UpdateMailListAfterDeposit(void)
{
u8 taskId;
u8 prevCount;
taskId = CreateTask(Mailbox_HandleReturnToProcessInput, 0);
2021-04-25 18:07:08 +02:00
prevCount = gPlayerPCItemPageInfo.count;
gPlayerPCItemPageInfo.count = GetMailboxMailCount();
Mailbox_CompactMailList();
if (prevCount != gPlayerPCItemPageInfo.count && (gPlayerPCItemPageInfo.count < (gPlayerPCItemPageInfo.pageItems + gPlayerPCItemPageInfo.itemsAbove))
&& gPlayerPCItemPageInfo.itemsAbove != 0)
gPlayerPCItemPageInfo.itemsAbove--;
SetPlayerPCListCount(taskId);
2020-02-07 18:48:47 +01:00
LoadMessageBoxAndBorderGfx();
2021-04-25 18:07:08 +02:00
if (MailboxMenu_Alloc(gPlayerPCItemPageInfo.count) == TRUE)
Mailbox_DrawMailboxMenu(taskId);
else
DestroyTask(taskId);
2019-12-17 09:24:44 +01:00
FadeInFromBlack();
}
2018-03-19 11:27:33 +01:00
static void Mailbox_NoPokemonForMail(u8 taskId)
{
DisplayItemMessageOnField(taskId, gText_NoPokemon, Mailbox_Cancel);
}
2018-03-19 11:27:33 +01:00
static void Mailbox_Cancel(u8 taskId)
{
2021-04-25 18:07:08 +02:00
MailboxMenu_RemoveWindow(MAILBOXWIN_OPTIONS);
ClearDialogWindowAndFrame(0, 0);
Mailbox_DrawMailboxMenu(taskId);
2020-05-14 10:37:09 +02:00
ScheduleBgCopyTilemapToVram(0);
gTasks[taskId].func = Mailbox_ProcessInput;
}
2021-04-25 18:07:08 +02:00
static void ItemStorage_Init(void)
{
2021-04-25 18:07:08 +02:00
sItemStorageMenu = AllocZeroed(sizeof(*sItemStorageMenu));
2021-08-12 01:14:50 +02:00
memset(sItemStorageMenu->windowIds, WINDOW_NONE, ITEMPC_WIN_COUNT);
2021-04-25 18:07:08 +02:00
sItemStorageMenu->toSwapPos = NOT_SWAPPING;
sItemStorageMenu->spriteId = SPRITE_NONE;
}
2021-04-25 18:07:08 +02:00
static void ItemStorage_Free(void)
{
u32 i;
2021-08-12 01:14:50 +02:00
for (i = 0; i < ITEMPC_WIN_COUNT; i++)
2021-04-25 18:07:08 +02:00
ItemStorage_RemoveWindow(i);
Free(sItemStorageMenu);
}
2021-04-25 18:07:08 +02:00
static u8 ItemStorage_AddWindow(u8 i)
{
2021-04-25 18:07:08 +02:00
u8 *windowIdLoc = &sItemStorageMenu->windowIds[i];
2021-02-20 00:36:48 +01:00
if (*windowIdLoc == WINDOW_NONE)
{
2021-04-25 18:07:08 +02:00
*windowIdLoc = AddWindow(&sWindowTemplates_ItemStorage[i]);
DrawStdFrameWithCustomTileAndPalette(*windowIdLoc, FALSE, 0x214, 0xE);
2020-05-14 10:37:09 +02:00
ScheduleBgCopyTilemapToVram(0);
}
return *windowIdLoc;
}
2021-04-25 18:07:08 +02:00
static void ItemStorage_RemoveWindow(u8 i)
{
2021-04-25 18:07:08 +02:00
u8 *windowIdLoc = &sItemStorageMenu->windowIds[i];
2021-02-20 00:36:48 +01:00
if (*windowIdLoc != WINDOW_NONE)
{
ClearStdWindowAndFrameToTransparent(*windowIdLoc, FALSE);
ClearWindowTilemap(*windowIdLoc);
2020-05-14 10:37:09 +02:00
ScheduleBgCopyTilemapToVram(0);
RemoveWindow(*windowIdLoc);
2021-02-20 00:36:48 +01:00
*windowIdLoc = WINDOW_NONE;
}
}
2018-03-19 11:27:33 +01:00
void ItemStorage_RefreshListMenu(void)
{
u16 i;
2021-04-25 18:07:08 +02:00
// Copy item names for all entries but the last (which is Cancel)
for(i = 0; i < gPlayerPCItemPageInfo.count - 1; i++)
{
2021-04-25 18:07:08 +02:00
CopyItemName_PlayerPC(&sItemStorageMenu->itemNames[i][0], gSaveBlock1Ptr->pcItems[i].itemId);
sItemStorageMenu->listItems[i].name = &sItemStorageMenu->itemNames[i][0];
sItemStorageMenu->listItems[i].id = i;
}
2021-04-25 18:07:08 +02:00
// Set up Cancel entry
StringCopy(&sItemStorageMenu->itemNames[i][0], gText_Cancel2);
sItemStorageMenu->listItems[i].name = &sItemStorageMenu->itemNames[i][0];
sItemStorageMenu->listItems[i].id = LIST_CANCEL;
// Set list menu data
gMultiuseListMenuTemplate = sListMenuTemplate_ItemStorage;
2021-08-12 01:14:50 +02:00
gMultiuseListMenuTemplate.windowId = ItemStorage_AddWindow(ITEMPC_WIN_LIST);
2021-04-25 18:07:08 +02:00
gMultiuseListMenuTemplate.totalItems = gPlayerPCItemPageInfo.count;
gMultiuseListMenuTemplate.items = sItemStorageMenu->listItems;
gMultiuseListMenuTemplate.maxShowed = gPlayerPCItemPageInfo.pageItems;
}
2018-03-19 11:27:33 +01:00
void CopyItemName_PlayerPC(u8 *string, u16 itemId)
{
CopyItemName(itemId, string);
}
2021-04-25 18:07:08 +02:00
static void ItemStorage_MoveCursor(s32 id, bool8 onInit, struct ListMenu *list)
{
2021-04-25 18:07:08 +02:00
if (onInit != TRUE)
PlaySE(SE_SELECT);
2021-04-25 18:07:08 +02:00
if (sItemStorageMenu->toSwapPos == NOT_SWAPPING)
{
2021-04-25 18:07:08 +02:00
ItemStorage_EraseItemIcon();
if (id != LIST_CANCEL)
ItemStorage_DrawItemIcon(gSaveBlock1Ptr->pcItems[id].itemId);
else
2021-04-25 18:07:08 +02:00
ItemStorage_DrawItemIcon(MSG_GO_BACK_TO_PREV);
ItemStorage_PrintDescription(id);
}
}
2018-03-15 11:37:24 +01:00
static void ItemStorage_PrintMenuItem(u8 windowId, u32 id, u8 yOffset)
2018-03-15 11:37:24 +01:00
{
2021-04-25 18:07:08 +02:00
if (id != LIST_CANCEL)
2018-03-15 11:37:24 +01:00
{
2021-04-25 18:07:08 +02:00
if (sItemStorageMenu->toSwapPos != NOT_SWAPPING)
2018-03-15 11:37:24 +01:00
{
2021-04-25 18:07:08 +02:00
if (sItemStorageMenu->toSwapPos == (u8)id)
ItemStorage_DrawSwapArrow(yOffset, 0, TEXT_SPEED_FF);
2018-03-15 11:37:24 +01:00
else
2021-04-25 18:07:08 +02:00
ItemStorage_DrawSwapArrow(yOffset, 0xFF, TEXT_SPEED_FF);
2018-03-15 11:37:24 +01:00
}
ConvertIntToDecimalStringN(gStringVar1, gSaveBlock1Ptr->pcItems[id].quantity, STR_CONV_MODE_RIGHT_ALIGN, 3);
StringExpandPlaceholders(gStringVar4, gText_xVar1);
AddTextPrinterParameterized(windowId, 7, gStringVar4, GetStringRightAlignXOffset(7, gStringVar4, 104), yOffset, 0xFF, NULL);
2018-03-15 11:37:24 +01:00
}
}
2021-04-25 18:07:08 +02:00
static void ItemStorage_PrintDescription(s32 id)
2018-03-15 11:37:24 +01:00
{
const u8* description;
2021-08-12 01:14:50 +02:00
u8 windowId = sItemStorageMenu->windowIds[ITEMPC_WIN_MESSAGE];
2018-03-15 11:37:24 +01:00
2021-04-25 18:07:08 +02:00
// Get item description (or Cancel text)
if (id != LIST_CANCEL)
2018-03-15 11:37:24 +01:00
description = (u8 *)ItemId_GetDescription(gSaveBlock1Ptr->pcItems[id].itemId);
else
2021-04-25 18:07:08 +02:00
description = ItemStorage_GetMessage(MSG_GO_BACK_TO_PREV);
FillWindowPixelBuffer(windowId, PIXEL_FILL(1));
AddTextPrinterParameterized(windowId, 1, description, 0, 1, 0, NULL);
2018-03-15 11:37:24 +01:00
}
2021-04-25 18:07:08 +02:00
static void ItemStorage_AddScrollIndicator(void)
2018-03-15 11:37:24 +01:00
{
2021-04-25 18:07:08 +02:00
if (gPlayerPCItemPageInfo.scrollIndicatorTaskId == TASK_NONE)
gPlayerPCItemPageInfo.scrollIndicatorTaskId = AddScrollIndicatorArrowPairParameterized(SCROLL_ARROW_UP, 176, 12, 148,
gPlayerPCItemPageInfo.count - gPlayerPCItemPageInfo.pageItems,
TAG_SCROLL_ARROW,
TAG_SCROLL_ARROW,
&gPlayerPCItemPageInfo.itemsAbove);
2018-03-15 11:37:24 +01:00
}
2018-03-19 11:27:33 +01:00
static void ItemStorage_RemoveScrollIndicator(void)
2018-03-15 11:37:24 +01:00
{
2021-04-25 18:07:08 +02:00
if (gPlayerPCItemPageInfo.scrollIndicatorTaskId != TASK_NONE)
2018-03-15 11:37:24 +01:00
{
2021-04-25 18:07:08 +02:00
RemoveScrollIndicatorArrowPair(gPlayerPCItemPageInfo.scrollIndicatorTaskId);
gPlayerPCItemPageInfo.scrollIndicatorTaskId = TASK_NONE;
2018-03-15 11:37:24 +01:00
}
}
2021-04-25 18:07:08 +02:00
static void ItemStorage_SetSwapArrow(u8 listTaskId, u8 b, u8 speed)
2018-03-15 11:37:24 +01:00
{
2021-04-25 18:07:08 +02:00
ItemStorage_DrawSwapArrow(ListMenuGetYCoordForPrintingArrowCursor(listTaskId), b, speed);
2018-03-15 11:37:24 +01:00
}
2021-04-25 18:07:08 +02:00
static void ItemStorage_DrawSwapArrow(u8 y, u8 b, u8 speed)
2018-03-15 11:37:24 +01:00
{
2021-08-12 01:14:50 +02:00
u8 windowId = sItemStorageMenu->windowIds[ITEMPC_WIN_LIST];
2018-11-28 21:08:22 +01:00
if (b == 0xFF)
FillWindowPixelRect(windowId, PIXEL_FILL(1), 0, y, GetMenuCursorDimensionByFont(1, 0), GetMenuCursorDimensionByFont(1, 1));
2018-03-15 11:37:24 +01:00
else
2021-04-25 18:07:08 +02:00
AddTextPrinterParameterized4(windowId, 1, 0, y, 0, 0, sSwapArrowTextColors, speed, gText_SelectorArrow2);
2018-03-15 11:37:24 +01:00
}
2021-04-25 18:07:08 +02:00
static void ItemStorage_DrawItemIcon(u16 itemId)
2018-03-15 11:37:24 +01:00
{
u8 spriteId;
2021-04-25 18:07:08 +02:00
u8* spriteIdLoc = &sItemStorageMenu->spriteId;
2018-03-15 11:37:24 +01:00
2021-02-20 06:30:37 +01:00
if (*spriteIdLoc == SPRITE_NONE)
2018-03-15 11:37:24 +01:00
{
2021-04-25 18:07:08 +02:00
FreeSpriteTilesByTag(TAG_ITEM_ICON);
FreeSpritePaletteByTag(TAG_ITEM_ICON);
spriteId = AddItemIconSprite(TAG_ITEM_ICON, TAG_ITEM_ICON, itemId);
2018-11-28 21:08:22 +01:00
if (spriteId != MAX_SPRITES)
2018-03-15 11:37:24 +01:00
{
*spriteIdLoc = spriteId;
gSprites[spriteId].oam.priority = 0;
2021-07-07 15:11:52 +02:00
gSprites[spriteId].x2 = 24;
gSprites[spriteId].y2 = 80;
2018-03-15 11:37:24 +01:00
}
}
}
2021-04-25 18:07:08 +02:00
static void ItemStorage_EraseItemIcon(void)
2018-03-15 11:37:24 +01:00
{
2021-04-25 18:07:08 +02:00
u8* spriteIdLoc = &sItemStorageMenu->spriteId;
2021-02-20 06:30:37 +01:00
if (*spriteIdLoc != SPRITE_NONE)
2018-03-15 11:37:24 +01:00
{
2021-04-25 18:07:08 +02:00
FreeSpriteTilesByTag(TAG_ITEM_ICON);
FreeSpritePaletteByTag(TAG_ITEM_ICON);
DestroySprite(&gSprites[*spriteIdLoc]);
2021-02-20 06:30:37 +01:00
*spriteIdLoc = SPRITE_NONE;
2018-03-15 11:37:24 +01:00
}
}
2021-04-25 18:07:08 +02:00
static void ItemStorage_CompactList(void)
2018-03-15 11:37:24 +01:00
{
2018-04-29 13:36:26 +02:00
CompactPCItems();
2021-04-25 18:07:08 +02:00
SetItemListPerPageCount(gSaveBlock1Ptr->pcItems, PC_ITEMS_COUNT, &gPlayerPCItemPageInfo.pageItems, &gPlayerPCItemPageInfo.count, 8);
2018-03-15 11:37:24 +01:00
}
2021-04-25 18:07:08 +02:00
static void ItemStorage_CompactCursor(void)
2018-03-15 11:37:24 +01:00
{
2021-04-25 18:07:08 +02:00
SetCursorWithinListBounds(&gPlayerPCItemPageInfo.itemsAbove, &gPlayerPCItemPageInfo.cursorPos, gPlayerPCItemPageInfo.pageItems, gPlayerPCItemPageInfo.count);
2018-03-15 11:37:24 +01:00
}
2021-04-25 18:07:08 +02:00
static void ItemStorage_CreateListMenu(u8 taskId)
2018-03-15 11:37:24 +01:00
{
s16 *data;
bool32 toss;
u32 i, x;
const u8* text;
data = gTasks[taskId].data;
2021-08-12 01:14:50 +02:00
for (i = 0; i <= ITEMPC_WIN_LIST_END; i++)
2021-04-25 18:07:08 +02:00
ItemStorage_AddWindow(i);
toss = tInTossMenu;
2018-03-15 11:37:24 +01:00
text = gText_TossItem;
2018-11-28 21:08:22 +01:00
if (!toss)
2018-03-15 11:37:24 +01:00
text = gText_WithdrawItem;
x = GetStringCenterAlignXOffset(1, text, 104);
2021-08-12 01:14:50 +02:00
AddTextPrinterParameterized(sItemStorageMenu->windowIds[ITEMPC_WIN_TITLE], 1, text, x, 1, 0, NULL);
CopyWindowToVram(sItemStorageMenu->windowIds[ITEMPC_WIN_ICON], 2);
2021-04-25 18:07:08 +02:00
ItemStorage_CompactList();
ItemStorage_CompactCursor();
2018-03-19 11:27:33 +01:00
ItemStorage_RefreshListMenu();
2021-04-25 18:07:08 +02:00
tListTaskId = ListMenuInit(&gMultiuseListMenuTemplate, gPlayerPCItemPageInfo.itemsAbove, gPlayerPCItemPageInfo.cursorPos);
ItemStorage_AddScrollIndicator();
2020-05-14 10:37:09 +02:00
ScheduleBgCopyTilemapToVram(0);
2018-03-19 11:27:33 +01:00
gTasks[taskId].func = ItemStorage_ProcessInput;
2018-03-15 11:37:24 +01:00
}
2021-04-25 18:07:08 +02:00
static const u8* ItemStorage_GetMessage(u16 itemId)
2018-03-15 11:37:24 +01:00
{
const u8 *string;
switch(itemId)
{
2021-04-25 18:07:08 +02:00
case MSG_GO_BACK_TO_PREV:
string = gText_GoBackPrevMenu;
break;
case MSG_HOW_MANY_TO_WITHDRAW:
string = gText_WithdrawHowManyItems;
break;
case MSG_WITHDREW_ITEM:
string = gText_WithdrawXItems;
break;
case MSG_HOW_MANY_TO_TOSS:
string = gText_TossHowManyVar1s;
break;
case MSG_THREW_AWAY_ITEM:
string = gText_ThrewAwayVar2Var1s;
break;
case MSG_NO_MORE_ROOM:
string = gText_NoRoomInBag;
break;
case MSG_TOO_IMPORTANT:
string = gText_TooImportantToToss;
break;
case MSG_OKAY_TO_THROW_AWAY:
string = gText_ConfirmTossItems;
break;
case MSG_SWITCH_WHICH_ITEM:
string = gText_MoveVar1Where;
break;
default:
string = ItemId_GetDescription(itemId);
break;
2018-03-15 11:37:24 +01:00
}
return string;
}
2021-04-25 18:07:08 +02:00
static void ItemStorage_PrintMessage(const u8 *string)
2018-03-15 11:37:24 +01:00
{
2021-08-12 01:14:50 +02:00
u8 windowId = sItemStorageMenu->windowIds[ITEMPC_WIN_MESSAGE];
FillWindowPixelBuffer(windowId, PIXEL_FILL(1));
2018-03-15 11:37:24 +01:00
StringExpandPlaceholders(gStringVar4, string);
AddTextPrinterParameterized(windowId, 1, gStringVar4, 0, 1, 0, NULL);
2018-03-15 11:37:24 +01:00
}
2021-04-25 18:07:08 +02:00
// Process input while on the item storage's item list
2018-03-19 11:27:33 +01:00
static void ItemStorage_ProcessInput(u8 taskId)
2018-03-15 11:37:24 +01:00
{
2021-04-25 18:07:08 +02:00
s16 *data = gTasks[taskId].data;
if (JOY_NEW(SELECT_BUTTON))
2018-03-15 11:37:24 +01:00
{
2021-04-25 18:07:08 +02:00
// 'Select' starts input for swapping items if not on Cancel
ListMenuGetScrollAndRow(tListTaskId, &gPlayerPCItemPageInfo.itemsAbove, &gPlayerPCItemPageInfo.cursorPos);
if (gPlayerPCItemPageInfo.itemsAbove + gPlayerPCItemPageInfo.cursorPos != gPlayerPCItemPageInfo.count - 1)
2018-03-15 11:37:24 +01:00
{
PlaySE(SE_SELECT);
2021-04-25 18:07:08 +02:00
ItemStorage_StartItemSwap(taskId);
2018-03-15 11:37:24 +01:00
}
}
else
{
2021-04-25 18:07:08 +02:00
s32 id = ListMenu_ProcessInput(tListTaskId);
ListMenuGetScrollAndRow(tListTaskId, &gPlayerPCItemPageInfo.itemsAbove, &gPlayerPCItemPageInfo.cursorPos);
switch (id)
2018-03-15 11:37:24 +01:00
{
2019-02-02 11:04:38 +01:00
case LIST_NOTHING_CHOSEN:
2018-03-15 11:37:24 +01:00
break;
case LIST_CANCEL:
2018-03-15 11:37:24 +01:00
PlaySE(SE_SELECT);
2021-04-25 18:07:08 +02:00
ItemStorage_ExitItemList(taskId);
2018-03-15 11:37:24 +01:00
break;
default:
PlaySE(SE_SELECT);
2018-03-19 11:27:33 +01:00
ItemStorage_DoItemAction(taskId);
2018-03-15 11:37:24 +01:00
break;
}
}
}
2021-04-25 18:07:08 +02:00
static void ItemStorage_ReturnToMenuSelect(u8 taskId)
2018-03-15 11:37:24 +01:00
{
2021-04-25 18:07:08 +02:00
s16 *data = gTasks[taskId].data;
2018-11-28 21:08:22 +01:00
if (!IsDma3ManagerBusyWithBgCopy())
2018-03-15 11:37:24 +01:00
{
DrawDialogueFrame(0, 0);
2021-04-25 18:07:08 +02:00
// Select Withdraw/Toss by default depending on which was just exited
if (!tInTossMenu)
InitItemStorageMenu(taskId, MENU_WITHDRAW);
2018-03-15 11:37:24 +01:00
else
2021-04-25 18:07:08 +02:00
InitItemStorageMenu(taskId, MENU_TOSS);
2018-03-15 11:37:24 +01:00
gTasks[taskId].func = ItemStorageMenuProcessInput;
}
}
2021-04-25 18:07:08 +02:00
static void ItemStorage_ExitItemList(u8 taskId)
2018-03-15 11:37:24 +01:00
{
2021-04-25 18:07:08 +02:00
s16 *data = gTasks[taskId].data;
ItemStorage_EraseItemIcon();
2018-03-19 11:27:33 +01:00
ItemStorage_RemoveScrollIndicator();
2021-04-25 18:07:08 +02:00
DestroyListMenuTask(tListTaskId, NULL, NULL);
DestroySwapLineSprites(sItemStorageMenu->swapLineSpriteIds, SWAP_LINE_LENGTH);
ItemStorage_Free();
gTasks[taskId].func = ItemStorage_ReturnToMenuSelect;
2018-03-15 11:37:24 +01:00
}
2021-04-25 18:07:08 +02:00
static void ItemStorage_StartItemSwap(u8 taskId)
2018-03-16 11:31:11 +01:00
{
2021-04-25 18:07:08 +02:00
s16 *data = gTasks[taskId].data;
ListMenuSetUnkIndicatorsStructField(tListTaskId, 16, 1);
sItemStorageMenu->toSwapPos = gPlayerPCItemPageInfo.itemsAbove + gPlayerPCItemPageInfo.cursorPos;
ItemStorage_SetSwapArrow(tListTaskId, 0, 0);
ItemStorage_UpdateSwapLinePos(sItemStorageMenu->toSwapPos);
CopyItemName(gSaveBlock1Ptr->pcItems[sItemStorageMenu->toSwapPos].itemId, gStringVar1);
ItemStorage_PrintMessage(ItemStorage_GetMessage(MSG_SWITCH_WHICH_ITEM));
gTasks[taskId].func = ItemStorage_ProcessItemSwapInput;
2018-03-16 11:31:11 +01:00
}
2021-04-25 18:07:08 +02:00
static void ItemStorage_ProcessItemSwapInput(u8 taskId)
2018-03-16 11:31:11 +01:00
{
s16 *data;
s32 id;
data = gTasks[taskId].data;
if (JOY_NEW(SELECT_BUTTON))
2018-03-16 11:31:11 +01:00
{
2021-04-25 18:07:08 +02:00
ListMenuGetScrollAndRow(tListTaskId, &gPlayerPCItemPageInfo.itemsAbove, &gPlayerPCItemPageInfo.cursorPos);
ItemStorage_FinishItemSwap(taskId, FALSE);
2018-03-16 11:31:11 +01:00
return;
}
2021-04-25 18:07:08 +02:00
id = ListMenu_ProcessInput(tListTaskId);
ListMenuGetScrollAndRow(tListTaskId, &gPlayerPCItemPageInfo.itemsAbove, &gPlayerPCItemPageInfo.cursorPos);
SetSwapLineSpritesInvisibility(sItemStorageMenu->swapLineSpriteIds, SWAP_LINE_LENGTH, FALSE);
ItemStorage_UpdateSwapLinePos(gPlayerPCItemPageInfo.cursorPos);
switch (id)
2018-03-16 11:31:11 +01:00
{
2019-02-02 11:04:38 +01:00
case LIST_NOTHING_CHOSEN:
2018-03-16 11:31:11 +01:00
break;
case LIST_CANCEL:
if (JOY_NEW(A_BUTTON))
2021-04-25 18:07:08 +02:00
ItemStorage_FinishItemSwap(taskId, FALSE);
2018-03-16 11:31:11 +01:00
else
2021-04-25 18:07:08 +02:00
ItemStorage_FinishItemSwap(taskId, TRUE);
2018-03-16 11:31:11 +01:00
break;
default:
2021-04-25 18:07:08 +02:00
ItemStorage_FinishItemSwap(taskId, FALSE);
2018-03-16 11:31:11 +01:00
break;
}
}
2021-04-25 18:07:08 +02:00
static void ItemStorage_FinishItemSwap(u8 taskId, bool8 canceled)
2018-03-16 11:31:11 +01:00
{
2021-04-25 18:07:08 +02:00
s16 *data = gTasks[taskId].data;
u16 newPos = gPlayerPCItemPageInfo.itemsAbove + gPlayerPCItemPageInfo.cursorPos;
2018-03-16 11:31:11 +01:00
PlaySE(SE_SELECT);
2021-04-25 18:07:08 +02:00
DestroyListMenuTask(tListTaskId, &gPlayerPCItemPageInfo.itemsAbove, &gPlayerPCItemPageInfo.cursorPos);
if (!canceled && sItemStorageMenu->toSwapPos != newPos && sItemStorageMenu->toSwapPos != newPos - 1)
2018-03-16 11:31:11 +01:00
{
2021-04-25 18:07:08 +02:00
MoveItemSlotInList(gSaveBlock1Ptr->pcItems, sItemStorageMenu->toSwapPos, newPos);
ItemStorage_RefreshListMenu();
2018-03-16 11:31:11 +01:00
}
2021-04-25 18:07:08 +02:00
if (sItemStorageMenu->toSwapPos < newPos)
gPlayerPCItemPageInfo.cursorPos--;
SetSwapLineSpritesInvisibility(sItemStorageMenu->swapLineSpriteIds, SWAP_LINE_LENGTH, TRUE);
sItemStorageMenu->toSwapPos = NOT_SWAPPING;
tListTaskId = ListMenuInit(&gMultiuseListMenuTemplate, gPlayerPCItemPageInfo.itemsAbove, gPlayerPCItemPageInfo.cursorPos);
2020-05-14 10:37:09 +02:00
ScheduleBgCopyTilemapToVram(0);
2018-03-19 11:27:33 +01:00
gTasks[taskId].func = ItemStorage_ProcessInput;
2018-03-16 11:31:11 +01:00
}
2021-04-25 18:07:08 +02:00
static void ItemStorage_UpdateSwapLinePos(u8 y)
2018-03-16 11:31:11 +01:00
{
2021-04-25 18:07:08 +02:00
UpdateSwapLineSpritesPos(sItemStorageMenu->swapLineSpriteIds, SWAP_LINE_LENGTH, 128, (y+1) * 16);
2018-03-16 11:31:11 +01:00
}
2021-04-25 18:07:08 +02:00
static void ItemStorage_PrintItemQuantity(u8 windowId, u16 value, u32 mode, u8 x, u8 y, u8 n)
2018-03-16 11:31:11 +01:00
{
ConvertIntToDecimalStringN(gStringVar1, value, mode, n);
StringExpandPlaceholders(gStringVar4, gText_xVar1);
AddTextPrinterParameterized(windowId, 1, gStringVar4, GetStringCenterAlignXOffset(1, gStringVar4, 48), y, 0, NULL);
2018-03-16 11:31:11 +01:00
}
2021-04-25 18:07:08 +02:00
// Start an item Withdraw/Toss
2018-03-19 11:27:33 +01:00
static void ItemStorage_DoItemAction(u8 taskId)
2018-03-16 11:31:11 +01:00
{
2021-04-25 18:07:08 +02:00
s16 *data = gTasks[taskId].data;
u16 pos = gPlayerPCItemPageInfo.cursorPos + gPlayerPCItemPageInfo.itemsAbove;
2018-03-19 11:27:33 +01:00
ItemStorage_RemoveScrollIndicator();
2021-04-25 18:07:08 +02:00
tQuantity = 1;
if (!tInTossMenu)
2018-03-16 11:31:11 +01:00
{
2021-04-25 18:07:08 +02:00
if (gSaveBlock1Ptr->pcItems[pos].quantity == 1)
2018-03-16 11:31:11 +01:00
{
2021-04-25 18:07:08 +02:00
// Withdrawing 1 item, do it automatically
2018-03-19 11:27:33 +01:00
ItemStorage_DoItemWithdraw(taskId);
2018-03-16 11:31:11 +01:00
return;
}
2021-04-25 18:07:08 +02:00
// Withdrawing multiple items, show "how many" message
CopyItemName(gSaveBlock1Ptr->pcItems[pos].itemId, gStringVar1);
ItemStorage_PrintMessage(ItemStorage_GetMessage(MSG_HOW_MANY_TO_WITHDRAW));
2018-03-16 11:31:11 +01:00
}
else
{
2021-04-25 18:07:08 +02:00
if (gSaveBlock1Ptr->pcItems[pos].quantity == 1)
2018-03-16 11:31:11 +01:00
{
2021-04-25 18:07:08 +02:00
// Tossing 1 item, do it automatically
2018-03-19 11:27:33 +01:00
ItemStorage_DoItemToss(taskId);
2018-03-16 11:31:11 +01:00
return;
}
2021-04-25 18:07:08 +02:00
// Tossing multiple items, show "how many" message
CopyItemName(gSaveBlock1Ptr->pcItems[pos].itemId, gStringVar1);
ItemStorage_PrintMessage(ItemStorage_GetMessage(MSG_HOW_MANY_TO_TOSS));
2018-03-16 11:31:11 +01:00
}
2021-04-25 18:07:08 +02:00
// Set up "how many" prompt
2021-08-12 01:14:50 +02:00
ItemStorage_PrintItemQuantity(ItemStorage_AddWindow(ITEMPC_WIN_QUANTITY), tQuantity, STR_CONV_MODE_LEADING_ZEROS, 8, 1, 3);
2018-03-19 11:27:33 +01:00
gTasks[taskId].func = ItemStorage_HandleQuantityRolling;
2018-03-16 11:31:11 +01:00
}
2018-03-19 11:27:33 +01:00
static void ItemStorage_HandleQuantityRolling(u8 taskId)
2018-03-16 11:31:11 +01:00
{
2021-04-25 18:07:08 +02:00
s16 *data = gTasks[taskId].data;
u16 pos = gPlayerPCItemPageInfo.cursorPos + gPlayerPCItemPageInfo.itemsAbove;
2018-03-16 11:31:11 +01:00
2021-04-25 18:07:08 +02:00
if (AdjustQuantityAccordingToDPadInput(&tQuantity, gSaveBlock1Ptr->pcItems[pos].quantity) == TRUE)
{
2021-08-12 01:14:50 +02:00
ItemStorage_PrintItemQuantity(ItemStorage_AddWindow(ITEMPC_WIN_QUANTITY), tQuantity, STR_CONV_MODE_LEADING_ZEROS, 8, 1, 3);
2021-04-25 18:07:08 +02:00
}
2018-03-16 11:31:11 +01:00
else
{
if (JOY_NEW(A_BUTTON))
2018-03-16 11:31:11 +01:00
{
2021-04-25 18:07:08 +02:00
// Quantity confirmed, perform action
2018-03-16 11:31:11 +01:00
PlaySE(SE_SELECT);
2021-08-12 01:14:50 +02:00
ItemStorage_RemoveWindow(ITEMPC_WIN_QUANTITY);
2021-04-25 18:07:08 +02:00
if (!tInTossMenu)
2018-03-19 11:27:33 +01:00
ItemStorage_DoItemWithdraw(taskId);
2018-03-16 11:31:11 +01:00
else
2018-03-19 11:27:33 +01:00
ItemStorage_DoItemToss(taskId);
2018-03-16 11:31:11 +01:00
}
else if (JOY_NEW(B_BUTTON))
2018-03-16 11:31:11 +01:00
{
2021-04-25 18:07:08 +02:00
// Canceled action
2018-03-16 11:31:11 +01:00
PlaySE(SE_SELECT);
2021-08-12 01:14:50 +02:00
ItemStorage_RemoveWindow(ITEMPC_WIN_QUANTITY);
2021-04-25 18:07:08 +02:00
ItemStorage_PrintMessage(ItemStorage_GetMessage(gSaveBlock1Ptr->pcItems[pos].itemId));
ItemStorage_ReturnToListInput(taskId);
2018-03-16 11:31:11 +01:00
}
}
}
2018-03-19 11:27:33 +01:00
static void ItemStorage_DoItemWithdraw(u8 taskId)
2018-03-16 11:31:11 +01:00
{
2021-04-25 18:07:08 +02:00
s16 *data = gTasks[taskId].data;
u16 pos = gPlayerPCItemPageInfo.cursorPos + gPlayerPCItemPageInfo.itemsAbove;
2018-03-16 11:31:11 +01:00
2021-04-25 18:07:08 +02:00
if (AddBagItem(gSaveBlock1Ptr->pcItems[pos].itemId, tQuantity) == TRUE)
2018-03-16 11:31:11 +01:00
{
2021-04-25 18:07:08 +02:00
// Item withdrawn
CopyItemName(gSaveBlock1Ptr->pcItems[pos].itemId, gStringVar1);
ConvertIntToDecimalStringN(gStringVar2, tQuantity, STR_CONV_MODE_LEFT_ALIGN, 3);
ItemStorage_PrintMessage(ItemStorage_GetMessage(MSG_WITHDREW_ITEM));
2018-03-19 11:27:33 +01:00
gTasks[taskId].func = ItemStorage_HandleRemoveItem;
2018-03-16 11:31:11 +01:00
}
else
{
2021-04-25 18:07:08 +02:00
// No room to withdraw items
tQuantity = 0;
ItemStorage_PrintMessage(ItemStorage_GetMessage(MSG_NO_MORE_ROOM));
gTasks[taskId].func = ItemStorage_HandleErrorMessageInput;
2018-03-16 11:31:11 +01:00
}
}
2018-03-19 11:27:33 +01:00
static void ItemStorage_DoItemToss(u8 taskId)
2018-03-16 11:31:11 +01:00
{
2021-04-25 18:07:08 +02:00
s16 *data = gTasks[taskId].data;
u16 pos = gPlayerPCItemPageInfo.cursorPos + gPlayerPCItemPageInfo.itemsAbove;
2018-03-16 11:31:11 +01:00
2021-04-25 18:07:08 +02:00
if (!ItemId_GetImportance(gSaveBlock1Ptr->pcItems[pos].itemId))
2018-03-16 11:31:11 +01:00
{
2021-04-25 18:07:08 +02:00
// Show toss confirmation prompt
CopyItemName(gSaveBlock1Ptr->pcItems[pos].itemId, gStringVar1);
ConvertIntToDecimalStringN(gStringVar2, tQuantity, STR_CONV_MODE_LEFT_ALIGN, 3);
ItemStorage_PrintMessage(ItemStorage_GetMessage(MSG_OKAY_TO_THROW_AWAY));
2021-08-12 01:14:50 +02:00
CreateYesNoMenuWithCallbacks(taskId, &sWindowTemplates_ItemStorage[ITEMPC_WIN_YESNO], 1, 0, 1, 0x214, 0xE, &ItemTossYesNoFuncs);
2018-03-16 11:31:11 +01:00
}
else
{
2021-04-25 18:07:08 +02:00
// Can't toss important items
tQuantity = 0;
ItemStorage_PrintMessage(ItemStorage_GetMessage(MSG_TOO_IMPORTANT));
gTasks[taskId].func = ItemStorage_HandleErrorMessageInput;
2018-03-16 11:31:11 +01:00
}
}
2021-04-25 18:07:08 +02:00
static void ItemStorage_TossItemYes(u8 taskId)
2018-03-16 11:31:11 +01:00
{
2021-04-25 18:07:08 +02:00
ItemStorage_PrintMessage(ItemStorage_GetMessage(MSG_THREW_AWAY_ITEM));
2018-03-19 11:27:33 +01:00
gTasks[taskId].func = ItemStorage_HandleRemoveItem;
2018-03-16 11:31:11 +01:00
}
2021-04-25 18:07:08 +02:00
static void ItemStorage_TossItemNo(u8 taskId)
2018-03-16 11:31:11 +01:00
{
2021-04-25 18:07:08 +02:00
ItemStorage_PrintMessage(ItemStorage_GetMessage(gSaveBlock1Ptr->pcItems[gPlayerPCItemPageInfo.itemsAbove + gPlayerPCItemPageInfo.cursorPos].itemId));
ItemStorage_ReturnToListInput(taskId);
2018-03-16 11:31:11 +01:00
}
2021-04-25 18:07:08 +02:00
// Remove item from PC (was either Tossed or Withdrawn)
2018-03-19 11:27:33 +01:00
static void ItemStorage_HandleRemoveItem(u8 taskId)
2018-03-16 11:31:11 +01:00
{
2021-04-25 18:07:08 +02:00
s16 *data = gTasks[taskId].data;
if (JOY_NEW(A_BUTTON | B_BUTTON))
2018-03-16 11:31:11 +01:00
{
2021-04-25 18:07:08 +02:00
RemovePCItem(gPlayerPCItemPageInfo.cursorPos + gPlayerPCItemPageInfo.itemsAbove, tQuantity);
DestroyListMenuTask(tListTaskId, &gPlayerPCItemPageInfo.itemsAbove, &gPlayerPCItemPageInfo.cursorPos);
ItemStorage_CompactList();
ItemStorage_CompactCursor();
2018-03-19 11:27:33 +01:00
ItemStorage_RefreshListMenu();
2021-04-25 18:07:08 +02:00
tListTaskId = ListMenuInit(&gMultiuseListMenuTemplate, gPlayerPCItemPageInfo.itemsAbove, gPlayerPCItemPageInfo.cursorPos);
ItemStorage_ReturnToListInput(taskId);
2018-03-16 11:31:11 +01:00
}
}
2021-04-25 18:07:08 +02:00
static void ItemStorage_HandleErrorMessageInput(u8 taskId)
2018-03-16 11:31:11 +01:00
{
2021-04-25 18:07:08 +02:00
s16 *data = gTasks[taskId].data;
if (JOY_NEW(A_BUTTON | B_BUTTON))
2018-03-16 11:31:11 +01:00
{
2021-04-25 18:07:08 +02:00
ItemStorage_PrintMessage(ItemStorage_GetMessage(gSaveBlock1Ptr->pcItems[gPlayerPCItemPageInfo.itemsAbove + gPlayerPCItemPageInfo.cursorPos].itemId));
ItemStorage_ReturnToListInput(taskId);
2018-03-16 11:31:11 +01:00
}
}
2021-04-25 18:07:08 +02:00
static void ItemStorage_ReturnToListInput(u8 taskId)
2018-03-16 11:31:11 +01:00
{
2021-04-25 18:07:08 +02:00
ItemStorage_AddScrollIndicator();
2018-03-19 11:27:33 +01:00
gTasks[taskId].func = ItemStorage_ProcessInput;
2018-03-16 11:31:11 +01:00
}