Clean up shop.c

This commit is contained in:
GriffinR 2022-09-22 13:32:35 -04:00
parent ecb75ee514
commit 1107ff954d
10 changed files with 178 additions and 176 deletions

View File

@ -477,7 +477,10 @@
#define ITEM_OLD_SEA_MAP 376
#define ITEMS_COUNT 377
#define ITEM_FIELD_ARROW ITEMS_COUNT
// A special item id associated with "Cancel"/"Exit" etc. in a list of items or decorations
// Its icon is defined at ITEMS_COUNT as the "return to field" arrow
#define ITEM_LIST_END 0xFFFF
// Range of berries given out by various NPCS
#define FIRST_BERRY_MASTER_BERRY ITEM_POMEG_BERRY

View File

@ -3,47 +3,6 @@
extern EWRAM_DATA struct ItemSlot gMartPurchaseHistory[3];
enum
{
MART_TYPE_NORMAL, // normal mart
MART_TYPE_DECOR,
MART_TYPE_DECOR2,
};
// shop view window NPC info enum
enum
{
OBJ_EVENT_ID,
X_COORD,
Y_COORD,
ANIM_NUM,
LAYER_TYPE
};
struct MartInfo
{
/*0x0*/ void (*callback)(void);
/*0x4*/ const struct MenuAction *menuActions;
/*0x8*/ const u16 *itemList;
/*0xC*/ u16 itemCount;
/*0xE*/ u8 windowId;
/*0xF*/ u8 martType;
};
struct ShopData
{
/*0x0000*/ u16 tilemapBuffers[4][0x400];
/*0x2000*/ u32 totalCost;
/*0x2004*/ u16 itemsShowed;
/*0x2006*/ u16 selectedRow;
/*0x2008*/ u16 scrollOffset;
/*0x200A*/ u8 maxQuantity;
/*0x200B*/ u8 scrollIndicatorsTaskId;
/*0x200C*/ u8 iconSlot;
/*0x200D*/ u8 itemSpriteIds[2];
/*0x2010*/ s16 viewportObjects[OBJECT_EVENTS_COUNT][5];
};
void CreatePokemartMenu(const u16 *);
void CreateDecorationShop1Menu(const u16 *);
void CreateDecorationShop2Menu(const u16 *);

View File

@ -645,7 +645,7 @@ static void BagCursorMoved(s32 itemIndex, bool8 onInit, struct ListMenu *list)
if (itemIndex != LIST_CANCEL)
ShowItemIcon(gSaveBlock2Ptr->frontier.pyramidBag.itemId[gSaveBlock2Ptr->frontier.lvlMode][itemIndex], gPyramidBagMenu->isAltIcon);
else
ShowItemIcon(0xFFFF, gPyramidBagMenu->isAltIcon); // Show exit arrow if on Cancel
ShowItemIcon(ITEM_LIST_END, gPyramidBagMenu->isAltIcon); // Show exit arrow if on Cancel
gPyramidBagMenu->isAltIcon ^= 1;
PrintItemDescription(itemIndex);
}

View File

@ -10,7 +10,7 @@ static const u16 sFrontierExchangeCorner_Decor1[] =
DECOR_CYNDAQUIL_DOLL,
DECOR_CHIKORITA_DOLL,
DECOR_TOTODILE_DOLL,
0xFFFF
ITEM_LIST_END
};
static const u16 sFrontierExchangeCorner_Decor2[] =
@ -20,7 +20,7 @@ static const u16 sFrontierExchangeCorner_Decor2[] =
DECOR_VENUSAUR_DOLL,
DECOR_CHARIZARD_DOLL,
DECOR_BLASTOISE_DOLL,
0xFFFF
ITEM_LIST_END
};
static const u16 sFrontierExchangeCorner_Vitamins[] =
@ -31,7 +31,7 @@ static const u16 sFrontierExchangeCorner_Vitamins[] =
ITEM_ZINC,
ITEM_CARBOS,
ITEM_HP_UP,
0xFFFF
ITEM_LIST_END
};
static const u16 sFrontierExchangeCorner_HoldItems[] =
@ -45,7 +45,7 @@ static const u16 sFrontierExchangeCorner_HoldItems[] =
ITEM_KINGS_ROCK,
ITEM_FOCUS_BAND,
ITEM_SCOPE_LENS,
0xFFFF
ITEM_LIST_END
};
static const u8 *const sFrontierExchangeCorner_Decor1Descriptions[] =

View File

@ -1,4 +1,4 @@
const u32 *const gItemIconTable[][2] =
const u32 *const gItemIconTable[ITEMS_COUNT + 1][2] =
{
[ITEM_NONE] = {gItemIcon_QuestionMark, gItemIconPalette_QuestionMark},
// Pokeballs
@ -402,5 +402,5 @@ const u32 *const gItemIconTable[][2] =
[ITEM_MAGMA_EMBLEM] = {gItemIcon_MagmaEmblem, gItemIconPalette_MagmaEmblem},
[ITEM_OLD_SEA_MAP] = {gItemIcon_OldSeaMap, gItemIconPalette_OldSeaMap},
// Return to field arrow
[ITEM_FIELD_ARROW] = {gItemIcon_ReturnToFieldArrow, gItemIconPalette_ReturnToFieldArrow},
[ITEMS_COUNT] = {gItemIcon_ReturnToFieldArrow, gItemIconPalette_ReturnToFieldArrow},
};

View File

@ -2919,7 +2919,7 @@ static void FillFrontierExchangeCornerWindowAndItemIcon(u16 menu, u16 selection)
{
case SCROLL_MULTI_BF_EXCHANGE_CORNER_DECOR_VENDOR_1:
AddTextPrinterParameterized2(0, FONT_NORMAL, sFrontierExchangeCorner_Decor1Descriptions[selection], 0, NULL, TEXT_COLOR_DARK_GRAY, TEXT_COLOR_WHITE, TEXT_COLOR_LIGHT_GRAY);
if (sFrontierExchangeCorner_Decor1[selection] == 0xFFFF)
if (sFrontierExchangeCorner_Decor1[selection] == ITEM_LIST_END)
{
ShowFrontierExchangeCornerItemIcon(sFrontierExchangeCorner_Decor1[selection]);
}
@ -2932,7 +2932,7 @@ static void FillFrontierExchangeCornerWindowAndItemIcon(u16 menu, u16 selection)
break;
case SCROLL_MULTI_BF_EXCHANGE_CORNER_DECOR_VENDOR_2:
AddTextPrinterParameterized2(0, FONT_NORMAL, sFrontierExchangeCorner_Decor2Descriptions[selection], 0, NULL, TEXT_COLOR_DARK_GRAY, TEXT_COLOR_WHITE, TEXT_COLOR_LIGHT_GRAY);
if (sFrontierExchangeCorner_Decor2[selection] == 0xFFFF)
if (sFrontierExchangeCorner_Decor2[selection] == ITEM_LIST_END)
{
ShowFrontierExchangeCornerItemIcon(sFrontierExchangeCorner_Decor2[selection]);
}

View File

@ -159,8 +159,8 @@ u8 AddCustomItemIconSprite(const struct SpriteTemplate *customSpriteTemplate, u1
const void *GetItemIconPicOrPalette(u16 itemId, u8 which)
{
if (itemId == 0xFFFF)
itemId = ITEM_FIELD_ARROW;
if (itemId == ITEM_LIST_END)
itemId = ITEMS_COUNT; // Use last icon, the "return to field" arrow
else if (itemId >= ITEMS_COUNT)
itemId = 0;

View File

@ -937,7 +937,7 @@ static void BagMenu_MoveCursorCallback(s32 itemIndex, bool8 onInit, struct ListM
if (itemIndex != LIST_CANCEL)
AddBagItemIconSprite(BagGetItemIdByPocketPosition(gBagPosition.pocket + 1, itemIndex), gBagMenu->itemIconSlot);
else
AddBagItemIconSprite(-1, gBagMenu->itemIconSlot);
AddBagItemIconSprite(ITEM_LIST_END, gBagMenu->itemIconSlot);
gBagMenu->itemIconSlot ^= 1;
if (!gBagMenu->inhibitItemDescriptionPrint)
PrintItemDescription(itemIndex);

View File

@ -1015,7 +1015,7 @@ static void ItemStorage_MoveCursor(s32 id, bool8 onInit, struct ListMenu *list)
if (id != LIST_CANCEL)
ItemStorage_DrawItemIcon(gSaveBlock1Ptr->pcItems[id].itemId);
else
ItemStorage_DrawItemIcon(MSG_GO_BACK_TO_PREV);
ItemStorage_DrawItemIcon(ITEM_LIST_END);
ItemStorage_PrintDescription(id);
}
}

View File

@ -42,10 +42,72 @@
#define TAG_SCROLL_ARROW 2100
#define TAG_ITEM_ICON_BASE 2110
#define MAX_ITEMS_SHOWN 8
enum {
WIN_BUY_SELL_QUIT,
WIN_BUY_QUIT,
};
enum {
WIN_MONEY,
WIN_ITEM_LIST,
WIN_ITEM_DESCRIPTION,
WIN_QUANTITY_IN_BAG,
WIN_QUANTITY_PRICE,
WIN_MESSAGE,
};
enum {
COLORID_NORMAL, // Item descriptions, quantity in bag, and quantity/price
COLORID_ITEM_LIST, // The text in the item list, and the cursor normally
COLORID_GRAY_CURSOR, // When the cursor has selected an item to purchase
};
enum {
MART_TYPE_NORMAL,
MART_TYPE_DECOR,
MART_TYPE_DECOR2,
};
// shop view window NPC info enum
enum
{
OBJ_EVENT_ID,
X_COORD,
Y_COORD,
ANIM_NUM,
LAYER_TYPE
};
struct MartInfo
{
void (*callback)(void);
const struct MenuAction *menuActions;
const u16 *itemList;
u16 itemCount;
u8 windowId;
u8 martType;
};
struct ShopData
{
u16 tilemapBuffers[4][0x400];
u32 totalCost;
u16 itemsShowed;
u16 selectedRow;
u16 scrollOffset;
u8 maxQuantity;
u8 scrollIndicatorsTaskId;
u8 iconSlot;
u8 itemSpriteIds[2];
s16 viewportObjects[OBJECT_EVENTS_COUNT][5];
};
static EWRAM_DATA struct MartInfo sMartInfo = {0};
static EWRAM_DATA struct ShopData *sShopData = NULL;
static EWRAM_DATA struct ListMenuItem *sListMenuItems = NULL;
static EWRAM_DATA u8 (*sItemNames)[16] = {0};
static EWRAM_DATA u8 (*sItemNames)[ITEM_NAME_LENGTH + 2] = {0};
static EWRAM_DATA u8 sPurchaseHistoryId = 0;
EWRAM_DATA struct ItemSlot gMartPurchaseHistory[SMARTSHOPPER_NUM_ITEMS] = {0};
@ -114,7 +176,7 @@ static const struct MenuAction sShopMenuActions_BuyQuit[] =
static const struct WindowTemplate sShopMenuWindowTemplates[] =
{
{
[WIN_BUY_SELL_QUIT] = {
.bg = 0,
.tilemapLeft = 2,
.tilemapTop = 1,
@ -123,7 +185,8 @@ static const struct WindowTemplate sShopMenuWindowTemplates[] =
.paletteNum = 15,
.baseBlock = 0x0008,
},
{
// Separate shop menu window for decorations, which can't be sold
[WIN_BUY_QUIT] = {
.bg = 0,
.tilemapLeft = 2,
.tilemapTop = 1,
@ -141,7 +204,7 @@ static const struct ListMenuTemplate sShopBuyMenuListTemplate =
.itemPrintFunc = BuyMenuPrintPriceInList,
.totalItems = 0,
.maxShowed = 0,
.windowId = 1,
.windowId = WIN_ITEM_LIST,
.header_X = 0,
.item_X = 8,
.cursor_X = 0,
@ -198,7 +261,7 @@ static const struct BgTemplate sShopBuyMenuBgTemplates[] =
static const struct WindowTemplate sShopBuyMenuWindowTemplates[] =
{
{
[WIN_MONEY] = {
.bg = 0,
.tilemapLeft = 1,
.tilemapTop = 1,
@ -207,7 +270,7 @@ static const struct WindowTemplate sShopBuyMenuWindowTemplates[] =
.paletteNum = 15,
.baseBlock = 0x001E,
},
{
[WIN_ITEM_LIST] = {
.bg = 0,
.tilemapLeft = 14,
.tilemapTop = 2,
@ -216,7 +279,7 @@ static const struct WindowTemplate sShopBuyMenuWindowTemplates[] =
.paletteNum = 15,
.baseBlock = 0x0032,
},
{
[WIN_ITEM_DESCRIPTION] = {
.bg = 0,
.tilemapLeft = 0,
.tilemapTop = 13,
@ -225,7 +288,7 @@ static const struct WindowTemplate sShopBuyMenuWindowTemplates[] =
.paletteNum = 15,
.baseBlock = 0x0122,
},
{
[WIN_QUANTITY_IN_BAG] = {
.bg = 0,
.tilemapLeft = 1,
.tilemapTop = 11,
@ -234,7 +297,7 @@ static const struct WindowTemplate sShopBuyMenuWindowTemplates[] =
.paletteNum = 15,
.baseBlock = 0x0176,
},
{
[WIN_QUANTITY_PRICE] = {
.bg = 0,
.tilemapLeft = 18,
.tilemapTop = 11,
@ -243,7 +306,7 @@ static const struct WindowTemplate sShopBuyMenuWindowTemplates[] =
.paletteNum = 15,
.baseBlock = 0x018E,
},
{
[WIN_MESSAGE] = {
.bg = 0,
.tilemapLeft = 2,
.tilemapTop = 15,
@ -268,9 +331,9 @@ static const struct WindowTemplate sShopBuyMenuYesNoWindowTemplates =
static const u8 sShopBuyMenuTextColors[][3] =
{
{1, 2, 3},
{0, 2, 3},
{0, 3, 2}
[COLORID_NORMAL] = {1, 2, 3},
[COLORID_ITEM_LIST] = {0, 2, 3},
[COLORID_GRAY_CURSOR] = {0, 3, 2},
};
static u8 CreateShopMenu(u8 martType)
@ -282,8 +345,7 @@ static u8 CreateShopMenu(u8 martType)
if (martType == MART_TYPE_NORMAL)
{
struct WindowTemplate winTemplate;
winTemplate = sShopMenuWindowTemplates[0];
struct WindowTemplate winTemplate = sShopMenuWindowTemplates[WIN_BUY_SELL_QUIT];
winTemplate.width = GetMaxWidthInMenuTable(sShopMenuActions_BuySellQuit, ARRAY_COUNT(sShopMenuActions_BuySellQuit));
sMartInfo.windowId = AddWindow(&winTemplate);
sMartInfo.menuActions = sShopMenuActions_BuySellQuit;
@ -291,8 +353,7 @@ static u8 CreateShopMenu(u8 martType)
}
else
{
struct WindowTemplate winTemplate;
winTemplate = sShopMenuWindowTemplates[1];
struct WindowTemplate winTemplate = sShopMenuWindowTemplates[WIN_BUY_QUIT];
winTemplate.width = GetMaxWidthInMenuTable(sShopMenuActions_BuyQuit, ARRAY_COUNT(sShopMenuActions_BuyQuit));
sMartInfo.windowId = AddWindow(&winTemplate);
sMartInfo.menuActions = sShopMenuActions_BuyQuit;
@ -320,6 +381,7 @@ static void SetShopItemsForSale(const u16 *items)
sMartInfo.itemList = items;
sMartInfo.itemCount = 0;
// Read items until ITEM_NONE / DECOR_NONE is reached
while (sMartInfo.itemList[i])
{
sMartInfo.itemCount++;
@ -344,11 +406,17 @@ static void Task_ShopMenu(u8 taskId)
}
}
#define tItemCount data[1]
#define tItemId data[5]
#define tListTaskId data[7]
#define tCallbackHi data[8]
#define tCallbackLo data[9]
static void Task_HandleShopMenuBuy(u8 taskId)
{
s16 *data = gTasks[taskId].data;
data[8] = (u32)CB2_InitBuyMenu >> 16;
data[9] = (u32)CB2_InitBuyMenu;
tCallbackHi = (u32)CB2_InitBuyMenu >> 16;
tCallbackLo = (u32)CB2_InitBuyMenu;
gTasks[taskId].func = Task_GoToBuyOrSellMenu;
FadeScreen(FADE_TO_BLACK, 0);
}
@ -356,8 +424,8 @@ static void Task_HandleShopMenuBuy(u8 taskId)
static void Task_HandleShopMenuSell(u8 taskId)
{
s16 *data = gTasks[taskId].data;
data[8] = (u32)CB2_GoToSellMenu >> 16;
data[9] = (u32)CB2_GoToSellMenu;
tCallbackHi = (u32)CB2_GoToSellMenu >> 16;
tCallbackLo = (u32)CB2_GoToSellMenu;
gTasks[taskId].func = Task_GoToBuyOrSellMenu;
FadeScreen(FADE_TO_BLACK, 0);
}
@ -386,7 +454,7 @@ static void Task_GoToBuyOrSellMenu(u8 taskId)
if (!gPaletteFade.active)
{
DestroyTask(taskId);
SetMainCallback2((void *)((u16)data[8] << 16 | (u16)data[9]));
SetMainCallback2((void *)((u16)tCallbackHi << 16 | (u16)tCallbackLo));
}
}
@ -429,10 +497,6 @@ static void VBlankCB_BuyMenu(void)
TransferPlttBuffer();
}
#define tItemCount data[1]
#define tItemId data[5]
#define tListTaskId data[7]
static void CB2_InitBuyMenu(void)
{
u8 taskId;
@ -472,8 +536,8 @@ static void CB2_InitBuyMenu(void)
BuyMenuAddScrollIndicatorArrows();
taskId = CreateTask(Task_BuyMenu, 8);
gTasks[taskId].tListTaskId = ListMenuInit(&gMultiuseListMenuTemplate, 0, 0);
BlendPalettes(PALETTES_ALL, 0x10, RGB_BLACK);
BeginNormalPaletteFade(PALETTES_ALL, 0, 0x10, 0, RGB_BLACK);
BlendPalettes(PALETTES_ALL, 16, RGB_BLACK);
BeginNormalPaletteFade(PALETTES_ALL, 0, 16, 0, RGB_BLACK);
SetVBlankCallback(VBlankCB_BuyMenu);
SetMainCallback2(CB2_BuyMenu);
break;
@ -504,8 +568,8 @@ static void BuyMenuBuildListMenuTemplate(void)
gMultiuseListMenuTemplate = sShopBuyMenuListTemplate;
gMultiuseListMenuTemplate.items = sListMenuItems;
gMultiuseListMenuTemplate.totalItems = sMartInfo.itemCount + 1;
if (gMultiuseListMenuTemplate.totalItems > 8)
gMultiuseListMenuTemplate.maxShowed = 8;
if (gMultiuseListMenuTemplate.totalItems > MAX_ITEMS_SHOWN)
gMultiuseListMenuTemplate.maxShowed = MAX_ITEMS_SHOWN;
else
gMultiuseListMenuTemplate.maxShowed = gMultiuseListMenuTemplate.totalItems;
@ -532,7 +596,7 @@ static void BuyMenuPrintItemDescriptionAndShowItemIcon(s32 item, bool8 onInit, s
if (item != LIST_CANCEL)
BuyMenuAddItemIcon(item, sShopData->iconSlot);
else
BuyMenuAddItemIcon(-1, sShopData->iconSlot);
BuyMenuAddItemIcon(ITEM_LIST_END, sShopData->iconSlot);
BuyMenuRemoveItemIcon(item, sShopData->iconSlot ^ 1);
sShopData->iconSlot ^= 1;
@ -548,8 +612,8 @@ static void BuyMenuPrintItemDescriptionAndShowItemIcon(s32 item, bool8 onInit, s
description = gText_QuitShopping;
}
FillWindowPixelBuffer(2, PIXEL_FILL(0));
BuyMenuPrint(2, description, 3, 1, 0, 0);
FillWindowPixelBuffer(WIN_ITEM_DESCRIPTION, PIXEL_FILL(0));
BuyMenuPrint(WIN_ITEM_DESCRIPTION, description, 3, 1, 0, COLORID_NORMAL);
}
static void BuyMenuPrintPriceInList(u8 windowId, u32 itemId, u8 y)
@ -576,21 +640,21 @@ static void BuyMenuPrintPriceInList(u8 windowId, u32 itemId, u8 y)
}
StringExpandPlaceholders(gStringVar4, gText_PokedollarVar1);
x = GetStringRightAlignXOffset(FONT_NARROW, gStringVar4, 0x78);
AddTextPrinterParameterized4(windowId, FONT_NARROW, x, y, 0, 0, sShopBuyMenuTextColors[1], TEXT_SKIP_DRAW, gStringVar4);
x = GetStringRightAlignXOffset(FONT_NARROW, gStringVar4, 120);
AddTextPrinterParameterized4(windowId, FONT_NARROW, x, y, 0, 0, sShopBuyMenuTextColors[COLORID_ITEM_LIST], TEXT_SKIP_DRAW, gStringVar4);
}
}
static void BuyMenuAddScrollIndicatorArrows(void)
{
if (sShopData->scrollIndicatorsTaskId == TASK_NONE && sMartInfo.itemCount + 1 > 8)
if (sShopData->scrollIndicatorsTaskId == TASK_NONE && sMartInfo.itemCount + 1 > MAX_ITEMS_SHOWN)
{
sShopData->scrollIndicatorsTaskId = AddScrollIndicatorArrowPairParameterized(
SCROLL_ARROW_UP,
172,
12,
148,
sMartInfo.itemCount - 7,
sMartInfo.itemCount - (MAX_ITEMS_SHOWN - 1),
TAG_SCROLL_ARROW,
TAG_SCROLL_ARROW,
&sShopData->scrollOffset);
@ -609,7 +673,7 @@ static void BuyMenuRemoveScrollIndicatorArrows(void)
static void BuyMenuPrintCursor(u8 scrollIndicatorsTaskId, u8 colorSet)
{
u8 y = ListMenuGetYCoordForPrintingArrowCursor(scrollIndicatorsTaskId);
BuyMenuPrint(1, gText_SelectorArrow2, 0, y, 0, colorSet);
BuyMenuPrint(WIN_ITEM_LIST, gText_SelectorArrow2, 0, y, 0, colorSet);
}
static void BuyMenuAddItemIcon(u16 item, u8 iconSlot)
@ -619,7 +683,7 @@ static void BuyMenuAddItemIcon(u16 item, u8 iconSlot)
if (*spriteIdPtr != SPRITE_NONE)
return;
if (sMartInfo.martType == MART_TYPE_NORMAL || item == 0xFFFF)
if (sMartInfo.martType == MART_TYPE_NORMAL || item == ITEM_LIST_END)
{
spriteId = AddItemIconSprite(iconSlot + TAG_ITEM_ICON_BASE, iconSlot + TAG_ITEM_ICON_BASE, item);
if (spriteId != MAX_SPRITES)
@ -683,11 +747,11 @@ static void BuyMenuInitWindows(void)
{
InitWindows(sShopBuyMenuWindowTemplates);
DeactivateAllTextPrinters();
LoadUserWindowBorderGfx(0, 1, 0xD0);
LoadMessageBoxGfx(0, 0xA, 0xE0);
PutWindowTilemap(0);
PutWindowTilemap(1);
PutWindowTilemap(2);
LoadUserWindowBorderGfx(WIN_MONEY, 1, 0xD0);
LoadMessageBoxGfx(WIN_MONEY, 0xA, 0xE0);
PutWindowTilemap(WIN_MONEY);
PutWindowTilemap(WIN_ITEM_LIST);
PutWindowTilemap(WIN_ITEM_DESCRIPTION);
}
static void BuyMenuPrint(u8 windowId, const u8 *text, u8 x, u8 y, s8 speed, u8 colorSet)
@ -697,7 +761,7 @@ static void BuyMenuPrint(u8 windowId, const u8 *text, u8 x, u8 y, s8 speed, u8 c
static void BuyMenuDisplayMessage(u8 taskId, const u8 *text, TaskFunc callback)
{
DisplayMessageAndContinueTask(taskId, 5, 10, 14, FONT_NORMAL, GetPlayerTextSpeedDelay(), text, callback);
DisplayMessageAndContinueTask(taskId, WIN_MESSAGE, 10, 14, FONT_NORMAL, GetPlayerTextSpeedDelay(), text, callback);
ScheduleBgCopyTilemapToVram(0);
}
@ -706,7 +770,7 @@ static void BuyMenuDrawGraphics(void)
BuyMenuDrawMapGraphics();
BuyMenuCopyMenuBgToBg1TilemapBuffer();
AddMoneyLabelObject(19, 11);
PrintMoneyAmountInMoneyBoxWithBorder(0, 1, 13, GetMoney(&gSaveBlock1Ptr->money));
PrintMoneyAmountInMoneyBoxWithBorder(WIN_MONEY, 1, 13, GetMoney(&gSaveBlock1Ptr->money));
ScheduleBgCopyTilemapToVram(0);
ScheduleBgCopyTilemapToVram(1);
ScheduleBgCopyTilemapToVram(2);
@ -722,10 +786,8 @@ static void BuyMenuDrawMapGraphics(void)
static void BuyMenuDrawMapBg(void)
{
s16 i;
s16 j;
s16 x;
s16 y;
s16 i, j;
s16 x, y;
const struct MapLayout *mapLayout;
u16 metatile;
u8 metatileLayerType;
@ -746,13 +808,9 @@ static void BuyMenuDrawMapBg(void)
metatileLayerType = METATILE_LAYER_TYPE_COVERED;
if (metatile < NUM_METATILES_IN_PRIMARY)
{
BuyMenuDrawMapMetatile(i, j, (u16 *)mapLayout->primaryTileset->metatiles + metatile * 8, metatileLayerType);
}
else
{
BuyMenuDrawMapMetatile(i, j, (u16 *)mapLayout->secondaryTileset->metatiles + ((metatile - NUM_METATILES_IN_PRIMARY) * 8), metatileLayerType);
}
}
}
}
@ -794,11 +852,13 @@ static void BuyMenuCollectObjectEventData(void)
s16 facingY;
u8 y;
u8 x;
u8 r8 = 0;
u8 numObjects = 0;
GetXYCoordsOneStepInFrontOfPlayer(&facingX, &facingY);
for (y = 0; y < OBJECT_EVENTS_COUNT; y++)
sShopData->viewportObjects[y][OBJ_EVENT_ID] = OBJECT_EVENTS_COUNT;
for (y = 0; y < 5; y++)
{
for (x = 0; x < 7; x++)
@ -807,28 +867,28 @@ static void BuyMenuCollectObjectEventData(void)
if (objEventId != OBJECT_EVENTS_COUNT)
{
sShopData->viewportObjects[r8][OBJ_EVENT_ID] = objEventId;
sShopData->viewportObjects[r8][X_COORD] = x;
sShopData->viewportObjects[r8][Y_COORD] = y;
sShopData->viewportObjects[r8][LAYER_TYPE] = MapGridGetMetatileLayerTypeAt(facingX - 4 + x, facingY - 2 + y);
sShopData->viewportObjects[numObjects][OBJ_EVENT_ID] = objEventId;
sShopData->viewportObjects[numObjects][X_COORD] = x;
sShopData->viewportObjects[numObjects][Y_COORD] = y;
sShopData->viewportObjects[numObjects][LAYER_TYPE] = MapGridGetMetatileLayerTypeAt(facingX - 4 + x, facingY - 2 + y);
switch (gObjectEvents[objEventId].facingDirection)
{
case DIR_SOUTH:
sShopData->viewportObjects[r8][ANIM_NUM] = 0;
break;
case DIR_NORTH:
sShopData->viewportObjects[r8][ANIM_NUM] = 1;
break;
case DIR_WEST:
sShopData->viewportObjects[r8][ANIM_NUM] = 2;
break;
case DIR_EAST:
default:
sShopData->viewportObjects[r8][ANIM_NUM] = 3;
break;
case DIR_SOUTH:
sShopData->viewportObjects[numObjects][ANIM_NUM] = ANIM_STD_FACE_SOUTH;
break;
case DIR_NORTH:
sShopData->viewportObjects[numObjects][ANIM_NUM] = ANIM_STD_FACE_NORTH;
break;
case DIR_WEST:
sShopData->viewportObjects[numObjects][ANIM_NUM] = ANIM_STD_FACE_WEST;
break;
case DIR_EAST:
default:
sShopData->viewportObjects[numObjects][ANIM_NUM] = ANIM_STD_FACE_EAST;
break;
}
r8++;
numObjects++;
}
}
}
@ -867,13 +927,9 @@ static void BuyMenuDrawObjectEvents(void)
static bool8 BuyMenuCheckIfObjectEventOverlapsMenuBg(s16 *object)
{
if (!BuyMenuCheckForOverlapWithMenuBg(object[X_COORD], object[Y_COORD] + 2) && object[LAYER_TYPE] != METATILE_LAYER_TYPE_COVERED)
{
return TRUE;
}
else
{
return FALSE;
}
}
static void BuyMenuCopyMenuBgToBg1TilemapBuffer(void)
@ -885,9 +941,7 @@ static void BuyMenuCopyMenuBgToBg1TilemapBuffer(void)
for (i = 0; i < 1024; i++)
{
if (src[i] != 0)
{
dest[i] = src[i] + 0xC3E3;
}
}
}
@ -901,9 +955,7 @@ static bool8 BuyMenuCheckForOverlapWithMenuBg(int x, int y)
metatile[offset2 + offset1 + 32] == 0 &&
metatile[offset2 + offset1 + 1] == 0 &&
metatile[offset2 + offset1 + 33] == 0)
{
return TRUE;
}
return FALSE;
}
@ -928,18 +980,14 @@ static void Task_BuyMenu(u8 taskId)
default:
PlaySE(SE_SELECT);
tItemId = itemId;
ClearWindowTilemap(2);
ClearWindowTilemap(WIN_ITEM_DESCRIPTION);
BuyMenuRemoveScrollIndicatorArrows();
BuyMenuPrintCursor(tListTaskId, 2);
BuyMenuPrintCursor(tListTaskId, COLORID_GRAY_CURSOR);
if (sMartInfo.martType == MART_TYPE_NORMAL)
{
sShopData->totalCost = (ItemId_GetPrice(itemId) >> IsPokeNewsActive(POKENEWS_SLATEPORT));
}
else
{
sShopData->totalCost = gDecorations[itemId].price;
}
if (!IsEnoughMoney(&gSaveBlock1Ptr->money, sShopData->totalCost))
{
@ -985,25 +1033,21 @@ static void Task_BuyHowManyDialogueInit(u8 taskId)
u16 quantityInBag = CountTotalItemQuantityInBag(tItemId);
u16 maxQuantity;
DrawStdFrameWithCustomTileAndPalette(3, FALSE, 1, 13);
DrawStdFrameWithCustomTileAndPalette(WIN_QUANTITY_IN_BAG, FALSE, 1, 13);
ConvertIntToDecimalStringN(gStringVar1, quantityInBag, STR_CONV_MODE_RIGHT_ALIGN, MAX_ITEM_DIGITS + 1);
StringExpandPlaceholders(gStringVar4, gText_InBagVar1);
BuyMenuPrint(3, gStringVar4, 0, 1, 0, 0);
BuyMenuPrint(WIN_QUANTITY_IN_BAG, gStringVar4, 0, 1, 0, COLORID_NORMAL);
tItemCount = 1;
DrawStdFrameWithCustomTileAndPalette(4, FALSE, 1, 13);
DrawStdFrameWithCustomTileAndPalette(WIN_QUANTITY_PRICE, FALSE, 1, 13);
BuyMenuPrintItemQuantityAndPrice(taskId);
ScheduleBgCopyTilemapToVram(0);
maxQuantity = GetMoney(&gSaveBlock1Ptr->money) / sShopData->totalCost;
if (maxQuantity > MAX_BAG_ITEM_CAPACITY)
{
sShopData->maxQuantity = MAX_BAG_ITEM_CAPACITY;
}
else
{
sShopData->maxQuantity = maxQuantity;
}
gTasks[taskId].func = Task_BuyHowManyDialogueHandleInput;
}
@ -1022,11 +1066,11 @@ static void Task_BuyHowManyDialogueHandleInput(u8 taskId)
if (JOY_NEW(A_BUTTON))
{
PlaySE(SE_SELECT);
ClearStdWindowAndFrameToTransparent(4, FALSE);
ClearStdWindowAndFrameToTransparent(3, FALSE);
ClearWindowTilemap(4);
ClearWindowTilemap(3);
PutWindowTilemap(1);
ClearStdWindowAndFrameToTransparent(WIN_QUANTITY_PRICE, FALSE);
ClearStdWindowAndFrameToTransparent(WIN_QUANTITY_IN_BAG, FALSE);
ClearWindowTilemap(WIN_QUANTITY_PRICE);
ClearWindowTilemap(WIN_QUANTITY_IN_BAG);
PutWindowTilemap(WIN_ITEM_LIST);
CopyItemName(tItemId, gStringVar1);
ConvertIntToDecimalStringN(gStringVar2, tItemCount, STR_CONV_MODE_LEFT_ALIGN, BAG_ITEM_CAPACITY_DIGITS);
ConvertIntToDecimalStringN(gStringVar3, sShopData->totalCost, STR_CONV_MODE_LEFT_ALIGN, 6);
@ -1035,10 +1079,10 @@ static void Task_BuyHowManyDialogueHandleInput(u8 taskId)
else if (JOY_NEW(B_BUTTON))
{
PlaySE(SE_SELECT);
ClearStdWindowAndFrameToTransparent(4, FALSE);
ClearStdWindowAndFrameToTransparent(3, FALSE);
ClearWindowTilemap(4);
ClearWindowTilemap(3);
ClearStdWindowAndFrameToTransparent(WIN_QUANTITY_PRICE, FALSE);
ClearStdWindowAndFrameToTransparent(WIN_QUANTITY_IN_BAG, FALSE);
ClearWindowTilemap(WIN_QUANTITY_PRICE);
ClearWindowTilemap(WIN_QUANTITY_IN_BAG);
BuyMenuReturnToItemList(taskId);
}
}
@ -1053,7 +1097,7 @@ static void BuyMenuTryMakePurchase(u8 taskId)
{
s16 *data = gTasks[taskId].data;
PutWindowTilemap(1);
PutWindowTilemap(WIN_ITEM_LIST);
if (sMartInfo.martType == MART_TYPE_NORMAL)
{
@ -1088,16 +1132,12 @@ static void BuyMenuSubtractMoney(u8 taskId)
IncrementGameStat(GAME_STAT_SHOPPED);
RemoveMoney(&gSaveBlock1Ptr->money, sShopData->totalCost);
PlaySE(SE_SHOP);
PrintMoneyAmountInMoneyBox(0, GetMoney(&gSaveBlock1Ptr->money), 0);
PrintMoneyAmountInMoneyBox(WIN_MONEY, GetMoney(&gSaveBlock1Ptr->money), 0);
if (sMartInfo.martType == MART_TYPE_NORMAL)
{
gTasks[taskId].func = Task_ReturnToItemListAfterItemPurchase;
}
else
{
gTasks[taskId].func = Task_ReturnToItemListAfterDecorationPurchase;
}
}
static void Task_ReturnToItemListAfterItemPurchase(u8 taskId)
@ -1107,14 +1147,12 @@ static void Task_ReturnToItemListAfterItemPurchase(u8 taskId)
if (JOY_NEW(A_BUTTON | B_BUTTON))
{
PlaySE(SE_SELECT);
if (tItemId == ITEM_POKE_BALL && tItemCount > 9 && AddBagItem(ITEM_PREMIER_BALL, 1) == TRUE)
{
// Purchasing 10+ Poke Balls gets the player a Premier Ball
if (tItemId == ITEM_POKE_BALL && tItemCount >= 10 && AddBagItem(ITEM_PREMIER_BALL, 1) == TRUE)
BuyMenuDisplayMessage(taskId, gText_ThrowInPremierBall, BuyMenuReturnToItemList);
}
else
{
BuyMenuReturnToItemList(taskId);
}
}
}
@ -1131,10 +1169,10 @@ static void BuyMenuReturnToItemList(u8 taskId)
{
s16 *data = gTasks[taskId].data;
ClearDialogWindowAndFrameToTransparent(5, FALSE);
BuyMenuPrintCursor(tListTaskId, 1);
PutWindowTilemap(1);
PutWindowTilemap(2);
ClearDialogWindowAndFrameToTransparent(WIN_MESSAGE, FALSE);
BuyMenuPrintCursor(tListTaskId, COLORID_ITEM_LIST);
PutWindowTilemap(WIN_ITEM_LIST);
PutWindowTilemap(WIN_ITEM_DESCRIPTION);
ScheduleBgCopyTilemapToVram(0);
BuyMenuAddScrollIndicatorArrows();
gTasks[taskId].func = Task_BuyMenu;
@ -1144,11 +1182,11 @@ static void BuyMenuPrintItemQuantityAndPrice(u8 taskId)
{
s16 *data = gTasks[taskId].data;
FillWindowPixelBuffer(4, PIXEL_FILL(1));
PrintMoneyAmount(4, 38, 1, sShopData->totalCost, TEXT_SKIP_DRAW);
FillWindowPixelBuffer(WIN_QUANTITY_PRICE, PIXEL_FILL(1));
PrintMoneyAmount(WIN_QUANTITY_PRICE, 38, 1, sShopData->totalCost, TEXT_SKIP_DRAW);
ConvertIntToDecimalStringN(gStringVar1, tItemCount, STR_CONV_MODE_LEADING_ZEROS, BAG_ITEM_CAPACITY_DIGITS);
StringExpandPlaceholders(gStringVar4, gText_xVar1);
BuyMenuPrint(4, gStringVar4, 0, 1, 0, 0);
BuyMenuPrint(WIN_QUANTITY_PRICE, gStringVar4, 0, 1, 0, COLORID_NORMAL);
}
static void ExitBuyMenu(u8 taskId)
@ -1204,6 +1242,8 @@ static void RecordItemPurchase(u8 taskId)
#undef tItemCount
#undef tItemId
#undef tListTaskId
#undef tCallbackHi
#undef tCallbackLo
void CreatePokemartMenu(const u16 *itemsForSale)
{