diff --git a/graphics/decorations/unk_85a6bb0.pal b/graphics/decorations/decoration_menu.pal similarity index 100% rename from graphics/decorations/unk_85a6bb0.pal rename to graphics/decorations/decoration_menu.pal diff --git a/include/decoration.h b/include/decoration.h index 0e6d6cfdd..eed930356 100644 --- a/include/decoration.h +++ b/include/decoration.h @@ -1,7 +1,8 @@ #ifndef GUARD_DECORATION_H #define GUARD_DECORATION_H -enum DecorPerm { +enum DecorationPermission +{ /* * The nomenclature here describes collision and placement permissions, in that order. */ @@ -9,13 +10,11 @@ enum DecorPerm { DECORPERM_PASS_FLOOR, DECORPERM_BEHIND_FLOOR, DECORPERM_NA_WALL, - DECORPERM_SPRITE + DECORPERM_SPRITE, }; -enum DecorShape { - /* - * Width-x-height - */ +enum DecorationShape +{ DECORSHAPE_1x1, DECORSHAPE_2x1, DECORSHAPE_3x1, // unused @@ -25,53 +24,52 @@ enum DecorShape { DECORSHAPE_1x3, // unused DECORSHAPE_2x4, DECORSHAPE_3x3, - DECORSHAPE_3x2 + DECORSHAPE_3x2, }; -enum DecorCat { - /* - * In which category you can find the decoration in the PC. - */ - /*0*/ DECORCAT_DESK, - /*1*/ DECORCAT_CHAIR, - /*2*/ DECORCAT_PLANT, - /*3*/ DECORCAT_ORNAMENT, - /*4*/ DECORCAT_MAT, - /*5*/ DECORCAT_POSTER, - /*6*/ DECORCAT_DOLL, - /*7*/ DECORCAT_CUSHION +enum DecorationCategory +{ + DECORCAT_DESK, + DECORCAT_CHAIR, + DECORCAT_PLANT, + DECORCAT_ORNAMENT, + DECORCAT_MAT, + DECORCAT_POSTER, + DECORCAT_DOLL, + DECORCAT_CUSHION, + DECORCAT_COUNT, }; struct Decoration { - /*0x00*/ u8 id; - /*0x01*/ u8 name[16]; - /*0x11*/ u8 permission; - /*0x12*/ u8 shape; - /*0x13*/ u8 category; - /*0x14*/ u16 price; - /*0x18*/ const u8 *description; - /*0x1c*/ const u16 *tiles; + u8 id; + u8 name[16]; + u8 permission; + u8 shape; + u8 category; + u16 price; + const u8 *description; + const u16 *tiles; }; -struct DecorPCPointers +struct DecorationPCContext { - /* 0x00 */ u8 *items; - /* 0x04 */ u8 *pos; - /* 0x08 */ u8 size; - /* 0x09 */ u8 isPlayerRoom; + u8 *items; + u8 *pos; + u8 size; + u8 isPlayerRoom; }; extern const struct Decoration gDecorations[]; -extern EWRAM_DATA u8 *gCurDecorInventoryItems; +extern EWRAM_DATA u8 *gCurDecorationItems; extern EWRAM_DATA u8 gCurDecorationIndex; -void sub_8126968(void); -void sub_8126AD8(u8 taskId); +void InitDecorationContextItems(void); +void DoSecretBaseDecorationMenu(u8 taskId); void ShowDecorationOnMap(u16 mapX, u16 mapY, u16 decor); -void sub_8126B2C(u8 taskId); -void sub_8127208(u8 taskId); -void sub_8127250(u8 *dest, u8 decorCat); +void DoPlayerRoomDecorationMenu(u8 taskId); +void ShowDecorationCategoriesWindow(u8 taskId); +void CopyDecorationCategoryName(u8 *dest, u8 decorCat); bool8 IsSelectedDecorInThePC(void); u8 AddDecorationIconObject(u8 decor, s16 x, s16 y, u8 priority, u16 tilesTag, u16 paletteTag); diff --git a/include/decoration_inventory.h b/include/decoration_inventory.h index 7539f7240..7362c2da2 100644 --- a/include/decoration_inventory.h +++ b/include/decoration_inventory.h @@ -11,13 +11,13 @@ extern struct DecorationInventory gDecorationInventories[]; void SetDecorationInventoriesPointers(void); void ClearDecorationInventories(void); -s8 GetFirstEmptyDecorSlot(u8 idx); +s8 GetFirstEmptyDecorSlot(u8 category); u8 CheckHasDecoration(u8); u8 DecorationAdd(u8); u8 DecorationCheckSpace(u8); s8 DecorationRemove(u8); -void CondenseDecorationCategoryN(u8); -u8 CountDecorationCategoryN(u8 idx); -u8 CountDecorations(void); +void CondenseDecorationsInCategory(u8 category); +u8 GetNumOwnedDecorationsInCategory(u8 category); +u8 GetNumOwnedDecorations(void); #endif // GUARD_DECORATION_INVENTORY_H diff --git a/include/gba/types.h b/include/gba/types.h index cb370c785..9f2594703 100644 --- a/include/gba/types.h +++ b/include/gba/types.h @@ -107,8 +107,8 @@ struct OamData #define SPRITE_SIZE_16x32 ((ST_OAM_SIZE_2 << 2) | (ST_OAM_V_RECTANGLE)) #define SPRITE_SIZE_32x64 ((ST_OAM_SIZE_3 << 2) | (ST_OAM_V_RECTANGLE)) -#define SPRITE_SIZE(dim) (SPRITE_SIZE_##dim >> 2) -#define SPRITE_SHAPE(dim) (SPRITE_SIZE_##dim & 0xFF) +#define SPRITE_SIZE(dim) ((SPRITE_SIZE_##dim >> 2) & 0x03) +#define SPRITE_SHAPE(dim) (SPRITE_SIZE_##dim & 0x03) struct BgAffineSrcData { diff --git a/include/menu_helpers.h b/include/menu_helpers.h index 63af4c731..3b6c13172 100644 --- a/include/menu_helpers.h +++ b/include/menu_helpers.h @@ -30,7 +30,7 @@ bool8 itemid_80BF6D8_mail_related(u16 itemId); bool8 sub_81221AC(void); bool8 sub_81221EC(void); void sub_812220C(struct ItemSlot *slots, u8 count, u8 *arg2, u8 *usedSlotsCount, u8 maxUsedSlotsCount); -void sub_812225C(u16 *arg0, u16 *arg1, u8 arg2, u8 arg3); +void sub_812225C(u16 *scrollOffset, u16 *cursorPos, u8 maxShownItems, u8 numItems); void sub_8122298(u16 *arg0, u16 *arg1, u8 arg2, u8 arg3, u8 arg4); void LoadListMenuArrowsGfx(void); void sub_8122344(u8 *spriteIds, u8 count); diff --git a/include/trader.h b/include/trader.h index c07ea81bd..25d72bd3b 100644 --- a/include/trader.h +++ b/include/trader.h @@ -6,7 +6,7 @@ #define GUARD_TRADER_H void sub_8133DA0(u8 taskId); -void sub_8133E1C(u8 taskId); +void ExitTraderMenu(u8 taskId); void TraderSetup(void); void Trader_ResetFlag(void); diff --git a/src/decoration.c b/src/decoration.c index 201fa74b1..0f6dd082b 100644 --- a/src/decoration.c +++ b/src/decoration.c @@ -1,84 +1,83 @@ #include "global.h" -#include "constants/decorations.h" -#include "decompress.h" #include "alloc.h" -#include "text.h" -#include "string_util.h" -#include "international_string_util.h" -#include "script.h" -#include "task.h" -#include "main.h" -#include "palette.h" -#include "constants/songs.h" -#include "overworld.h" -#include "fieldmap.h" -#include "metatile_behavior.h" -#include "field_weather.h" -#include "field_player_avatar.h" -#include "field_camera.h" -#include "field_screen_effect.h" -#include "event_object_movement.h" -#include "list_menu.h" -#include "menu_helpers.h" -#include "menu.h" -#include "sound.h" -#include "event_scripts.h" -#include "event_data.h" -#include "constants/region_map_sections.h" -#include "player_pc.h" -#include "strings.h" -#include "tv.h" -#include "secret_base.h" -#include "tilesets.h" -#include "item_icon.h" -#include "trader.h" -#include "constants/event_objects.h" -#include "decoration_inventory.h" +#include "decompress.h" #include "decoration.h" +#include "decoration_inventory.h" +#include "event_data.h" +#include "event_object_movement.h" +#include "event_scripts.h" +#include "field_camera.h" +#include "field_player_avatar.h" +#include "field_screen_effect.h" +#include "field_weather.h" +#include "fieldmap.h" #include "graphics.h" +#include "international_string_util.h" +#include "item_icon.h" +#include "list_menu.h" +#include "main.h" +#include "menu.h" +#include "menu_helpers.h" +#include "metatile_behavior.h" +#include "overworld.h" +#include "palette.h" +#include "player_pc.h" +#include "script.h" +#include "secret_base.h" +#include "sound.h" +#include "string_util.h" +#include "strings.h" +#include "task.h" +#include "text.h" +#include "tilesets.h" +#include "trader.h" +#include "tv.h" +#include "constants/decorations.h" +#include "constants/event_objects.h" +#include "constants/songs.h" +#include "constants/region_map_sections.h" -// Static type declarations +#define PLACE_DECORATION_SELECTOR_TAG 0xbe5 +#define PLACE_DECORATION_PLAYER_TAG 0x008 -#define OVERWORLD_PLACE_DECOR_SELECTOR_PAL_TAG 0xbe5 -#define OVERWORLD_PLACE_DECOR_PLAYER_PAL_TAG 0x008 - -struct DecorPCBuffer { +struct DecorationItemsMenu +{ struct ListMenuItem items[41]; u8 names[41][24]; - u8 unk_520; - u8 unk_521; - u8 unk_522; + u8 numMenuItems; + u8 maxShownItems; + u8 scrollIndicatorsTaskId; }; -struct PlaceDecorationGraphicsDataBuffer { - /*0x000; 0x0203a190*/ const struct Decoration *decoration; - /*0x004; 0x0203a194*/ u16 tiles[0x40]; - /*0x084; 0x0203a214*/ u8 image[0x800]; - /*0x884; 0x0203aa14*/ u16 palette[16]; +struct PlaceDecorationGraphicsDataBuffer +{ + const struct Decoration *decoration; + u16 tiles[0x40]; + u8 image[0x800]; + u16 palette[16]; }; -struct DecorRearrangementDataBuffer { +struct DecorRearrangementDataBuffer +{ u8 idx; u8 width; u8 height; u16 flagId; }; -// Static RAM declarations - -EWRAM_DATA u8 *gCurDecorInventoryItems = NULL; -EWRAM_DATA static u8 sSecretBasePCMenuCursorPos = 0; -EWRAM_DATA static u8 sCurDecorCatCount = 0; +EWRAM_DATA u8 *gCurDecorationItems = NULL; +EWRAM_DATA static u8 sDecorationActionsCursorPos = 0; +EWRAM_DATA static u8 sNumOwnedDecorationsInCurCategory = 0; EWRAM_DATA static u8 sSecretBaseItemsIndicesBuffer[16] = {}; EWRAM_DATA static u8 sPlayerRoomItemsIndicesBuffer[12] = {}; -EWRAM_DATA static u16 sSecretBasePCSelectDecorLineNo = 0; -EWRAM_DATA static u16 sSecretBasePCSelectDecorPageNo = 0; +EWRAM_DATA static u16 sDecorationsCursorPos = 0; +EWRAM_DATA static u16 sDecorationsScrollOffset = 0; EWRAM_DATA u8 gCurDecorationIndex = 0; EWRAM_DATA static u8 sCurDecorationCategory = DECORCAT_DESK; EWRAM_DATA static u32 filler_0203a174[2] = {}; -EWRAM_DATA struct DecorPCPointers gUnknown_0203A17C = {}; -EWRAM_DATA static u8 sDecorMenuWindowIndices[4] = {}; -EWRAM_DATA struct DecorPCBuffer *sDecorPCBuffer = NULL; +EWRAM_DATA struct DecorationPCContext gDecorationContext = {}; +EWRAM_DATA static u8 sDecorMenuWindowIds[4] = {}; +EWRAM_DATA static struct DecorationItemsMenu *sDecorationItemsMenu = NULL; EWRAM_DATA struct PlaceDecorationGraphicsDataBuffer sPlaceDecorationGraphicsDataBuffer = {}; EWRAM_DATA static u16 sCurDecorMapX = 0; EWRAM_DATA static u16 sCurDecorMapY = 0; @@ -89,38 +88,36 @@ EWRAM_DATA static struct OamData sDecorSelectorOam = {}; EWRAM_DATA static struct DecorRearrangementDataBuffer sDecorRearrangementDataBuffer[16] = {}; EWRAM_DATA static u8 sCurDecorSelectedInRearrangement = 0; -// Static ROM declarations - -void sub_8126B80(u8 taskId); -void sub_8126C08(void); -void SecretBasePC_Decorate(u8 taskId); -void SecretBasePC_PutAway(u8 taskId); -void SecretBasePC_Toss(u8 taskId); -void sub_8126DA4(u8 taskId); -void SecretBasePC_Cancel(u8 taskId); -void SecretBasePC_PrepMenuForSelectingStoredDecors(u8 taskId); -void sub_8126DFC(u8 taskId); -void sub_8126E8C(u8 taskId); -void sub_8126F68(u8 winid, u8 decorCat, u8 x, u8 y, bool8 flag, u8 speed); -void sub_8127058(u8 *str, bool8 flag); -void sub_8127088(u8 taskId); -void sub_81270E8(u8 taskId); -void sub_8127180(u8 taskId); -void sub_812719C(u8 taskId); -void sub_81271CC(u8 taskId); -void sub_8127268(u8 taskId); -void sub_8127454(u8 *dest, u16 decorId); -void sub_8127480(s32 a0, bool8 flag, struct ListMenu *menu); +static void HandleDecorationActionsMenuInput(u8 taskId); +static void PrintCurMainMenuDescription(void); +static void DecorationMenuAction_Decorate(u8 taskId); +static void DecorationMenuAction_PutAway(u8 taskId); +static void DecorationMenuAction_Toss(u8 taskId); +static void DecorationMenuAction_Cancel(u8 taskId); +static void ReturnToDecorationActionsAfterInvalidSelection(u8 taskId); +static void SecretBasePC_PrepMenuForSelectingStoredDecors(u8 taskId); +static void InitDecorationCategoriesWindow(u8 taskId); +static void PrintDecorationCategoryMenuItems(u8 taskId); +static void PrintDecorationCategoryMenuItem(u8 winid, u8 category, u8 x, u8 y, bool8 disabled, u8 speed); +static void ColorMenuItemString(u8 *str, bool8 disabled); +static void HandleDecorationCategoriesMenuInput(u8 taskId); +static void SelectDecorationCategory(u8 taskId); +static void ReturnToDecorationCategoriesAfterInvalidSelection(u8 taskId); +static void ExitDecorationCategoriesMenu(u8 taskId); +static void ReturnToActionsMenuFromCategories(u8 taskId); +static void ExitTraderDecorationMenu(u8 taskId); +static void CopyDecorationMenuItemName(u8 *dest, u16 decoration); +static void DecorationItemsMenu_OnCursorMove(s32 itemIndex, bool8 flag, struct ListMenu *menu); void sub_81274A0(u8 a0, s32 a1, u8 a2); -void sub_8127620(u8 taskId); -void sub_812764C(u8 taskId); -void sub_8127744(u32 a0); -void sub_81277A8(void); +static void ShowDecorationItemsWindow(u8 taskId); +static void HandleDecorationItemsMenuInput(u8 taskId); +static void PrintDecorationItemDescription(u32 itemIndex); +static void RemoveDecorationItemsOtherWindows(void); bool8 sub_81277BC(u8 idx); bool8 sub_81277E8(u8 idx); -void IdentifyOwnedDecorationsCurrentlyInUse(u8 taskId); -void sub_812759C(u8 taskId); -void sub_8127718(u8 decorCat); +static void IdentifyOwnedDecorationsCurrentlyInUse(u8 taskId); +static void InitDecorationItemsWindow(u8 taskId); +static void ShowDecorationCategorySummaryWindow(u8 category); void sub_8127A30(u8 taskId); void sub_8127A8C(u8 taskId); void sub_8127F68(u8 taskId); @@ -168,13 +165,12 @@ void sub_812A3D4(u8 taskId); void sub_812A458(u8 taskId); void sub_812A478(u8 taskId); -// .rodata - #include "data/decoration/tiles.h" #include "data/decoration/description.h" #include "data/decoration/header.h" -const u8 *const sDecorCatNames[] = { +static const u8 *const sDecorationCategoryNames[] = +{ gText_Desk, gText_Chair, gText_Plant, @@ -185,36 +181,42 @@ const u8 *const sDecorCatNames[] = { gText_Cushion }; -const struct MenuAction sSecretBasePCMenuActions[] = { +static const struct MenuAction sDecorationMainMenuActions[] = +{ { - gText_Decorate, {.void_u8=SecretBasePC_Decorate} - }, { - gText_PutAway, {.void_u8=SecretBasePC_PutAway} - }, { - gText_Toss2, {.void_u8=SecretBasePC_Toss} - }, { - gText_Cancel, {.void_u8=SecretBasePC_Cancel} - } + .text = gText_Decorate, + .func = { .void_u8 = DecorationMenuAction_Decorate }, + }, + { + .text = gText_PutAway, + .func = { .void_u8 = DecorationMenuAction_PutAway }, + }, + { + .text = gText_Toss2, + .func = { .void_u8 = DecorationMenuAction_Toss }, + }, + { + .text = gText_Cancel, + .func = { .void_u8 = DecorationMenuAction_Cancel }, + }, }; -const u8 *const sSecretBasePCMenuItemDescriptions[] = { +static const u8 *const sSecretBasePCMenuItemDescriptions[] = +{ gText_PutOutSelectedDecorItem, gText_StoreChosenDecorInPC, gText_ThrowAwayUnwantedDecors, gText_GoBackPrevMenu }; -void (*const SecretBasePC_SelectedDecorActions[][2])(u8 taskId) = { - { - sub_8127F68, sub_8127A8C - }, { - sub_812A3D4, sub_8127A8C - }, { - sub_8133DA0, sub_8127A8C - } +static const TaskFunc sSecretBasePC_SelectedDecorationActions[][2] = +{ + { sub_8127F68, sub_8127A8C }, + { sub_812A3D4, sub_8127A8C }, + { sub_8133DA0, sub_8127A8C }, }; -const struct WindowTemplate gUnknown_085A6B90[4] = +static const struct WindowTemplate sDecorationWindowTemplates[4] = { { .bg = 0, @@ -254,12 +256,12 @@ const struct WindowTemplate gUnknown_085A6B90[4] = } }; -const u16 gUnknown_085A6BB0[] = INCBIN_U16("graphics/decorations/unk_85a6bb0.gbapal"); +static const u16 sDecorationMenuPalette[] = INCBIN_U16("graphics/decorations/decoration_menu.gbapal"); -const struct ListMenuTemplate gUnknown_085A6BD0 = +static const struct ListMenuTemplate sDecorationItemsListMenuTemplate = { .items = NULL, - .moveCursorFunc = sub_8127480, + .moveCursorFunc = DecorationItemsMenu_OnCursorMove, .itemPrintFunc = sub_81274A0, .totalItems = 0, .maxShowed = 0, @@ -280,118 +282,140 @@ const struct ListMenuTemplate gUnknown_085A6BD0 = #include "data/decoration/icon.h" #include "data/decoration/tilemaps.h" -const struct { +static const struct { u8 shape; u8 size; - u8 x; - u8 y; -} gUnknown_085A7250[] = { - {0, 1, 0x78, 0x4e}, - {1, 2, 0x80, 0x4e}, - {1, 3, 0x90, 0x56}, - {1, 3, 0x90, 0x46}, - {0, 2, 0x80, 0x46}, - {2, 2, 0x78, 0x46}, - {2, 3, 0x80, 0x56}, - {2, 3, 0x80, 0x36}, - {0, 3, 0x90, 0x46}, - {1, 3, 0x90, 0x46} + u8 cameraX; + u8 cameraY; +} sDecorationMovementInfo[] = +{ + [DECORSHAPE_1x1] = {SPRITE_SHAPE(16x16), SPRITE_SIZE(16x16), 120, 78}, + [DECORSHAPE_2x1] = {SPRITE_SHAPE(32x16), SPRITE_SIZE(32x16), 128, 78}, + [DECORSHAPE_3x1] = {SPRITE_SHAPE(64x32), SPRITE_SIZE(64x32), 144, 86}, + [DECORSHAPE_4x2] = {SPRITE_SHAPE(64x32), SPRITE_SIZE(64x32), 144, 70}, + [DECORSHAPE_2x2] = {SPRITE_SHAPE(32x32), SPRITE_SIZE(32x32), 128, 70}, + [DECORSHAPE_1x2] = {SPRITE_SHAPE(16x32), SPRITE_SIZE(16x32), 120, 70}, + [DECORSHAPE_1x3] = {SPRITE_SHAPE(32x64), SPRITE_SIZE(32x64), 128, 86}, + [DECORSHAPE_2x4] = {SPRITE_SHAPE(32x64), SPRITE_SIZE(32x64), 128, 54}, + [DECORSHAPE_3x3] = {SPRITE_SHAPE(64x64), SPRITE_SIZE(64x64), 144, 70}, + [DECORSHAPE_3x2] = {SPRITE_SHAPE(64x32), SPRITE_SIZE(64x32), 144, 70}, }; -const union AnimCmd gUnknown_085A7278[] = { +static const union AnimCmd sDecorSelectorAnimCmd0[] = +{ ANIMCMD_FRAME(0, 0, FALSE, FALSE), ANIMCMD_END }; -const union AnimCmd *const sDecorSelectorAnims[] = { - gUnknown_085A7278 +static const union AnimCmd *const sDecorSelectorAnimCmds[] = { sDecorSelectorAnimCmd0 }; + +static const struct SpriteFrameImage sDecorSelectorSpriteFrameImages = +{ + .data = (const u8 *)&sPlaceDecorationGraphicsDataBuffer.image, + .size = 0x800, }; -const struct SpriteFrameImage sDecorSelectorSpriteFrameImages = { - (const u8 *)&sPlaceDecorationGraphicsDataBuffer.image, 0x800 -}; - -const struct SpriteTemplate sDecorSelectorSpriteTemplate = { +static const struct SpriteTemplate sDecorationSelectorSpriteTemplate = +{ 0xFFFF, - OVERWORLD_PLACE_DECOR_SELECTOR_PAL_TAG, + PLACE_DECORATION_SELECTOR_TAG, &sDecorSelectorOam, - sDecorSelectorAnims, + sDecorSelectorAnimCmds, &sDecorSelectorSpriteFrameImages, gDummySpriteAffineAnimTable, SpriteCallbackDummy }; -const struct SpriteTemplate sDecorWhilePlacingSpriteTemplate = { +const struct SpriteTemplate sDecorWhilePlacingSpriteTemplate = +{ 0x0000, 0x0000, &sDecorSelectorOam, - sDecorSelectorAnims, + sDecorSelectorAnimCmds, NULL, gDummySpriteAffineAnimTable, SpriteCallbackDummy }; -const struct SpritePalette gUnknown_085A72BC = { - (const u16 *)&sPlaceDecorationGraphicsDataBuffer.palette, OVERWORLD_PLACE_DECOR_SELECTOR_PAL_TAG +const struct SpritePalette gUnknown_085A72BC = +{ + .data = (const u16 *)&sPlaceDecorationGraphicsDataBuffer.palette, + .tag = PLACE_DECORATION_SELECTOR_TAG, }; -const struct YesNoFuncTable gUnknown_085A72C4 = { - sub_81289F0, - sub_8128FD8 +const struct YesNoFuncTable gUnknown_085A72C4 = +{ + .yesFunc = sub_81289F0, + .noFunc = sub_8128FD8, }; -const struct YesNoFuncTable gUnknown_085A72CC = { - sub_8128BA0, - sub_8128FD8 +const struct YesNoFuncTable gUnknown_085A72CC = +{ + .yesFunc = sub_8128BA0, + .noFunc = sub_8128FD8, }; -const struct YesNoFuncTable gUnknown_085A72D4[] = { +const struct YesNoFuncTable gUnknown_085A72D4[] = +{ { - sub_81283BC, - sub_8128414 - }, { - sub_8129BCC, - sub_8129BF8 + .yesFunc = sub_81283BC, + .noFunc = sub_8128414, + }, + { + .yesFunc = sub_8129BCC, + .noFunc = sub_8129BF8, } }; -const u8 gUnknown_085A72E4[] = { - 0x04, 0x04, 0x04, 0x04, 0x00, 0x03, 0x03, 0x00 +static const u8 sDecorationStandElevations[] = +{ + 4, 4, 4, 4, + 0, 3, 3, 0 }; -const u8 gUnknown_085A72EC[] = { - 0x04, 0x04, 0x04, 0x04, 0x00, 0x04, 0x03, 0x00 +static const u8 sDecorationSlideElevation[] = +{ + 4, 4, + 4, 4, + 0, 4, + 3, 0, }; const u16 gUnknown_085A72F4[] = { 0x04, 0x08, 0x10, 0x20, 0x10, 0x08, 0x10, 0x20, 0x40, 0x20 }; -const u16 Unknown_085A7308[] = INCBIN_U16("graphics/decorations/unk_85a7308.gbapal"); +const u16 gUnknown_085A7308[] = INCBIN_U16("graphics/decorations/unk_85a7308.gbapal"); -const u16 Unknown_085A7328[] = INCBIN_U16("graphics/decorations/unk_85a7328.gbapal"); +const u16 gUnknown_085A7328[] = INCBIN_U16("graphics/decorations/unk_85a7328.gbapal"); -const struct YesNoFuncTable gUnknown_085A7348 = { - sub_812A1C0, - sub_8129B34 +const struct YesNoFuncTable gUnknown_085A7348 = +{ + .yesFunc = sub_812A1C0, + .noFunc = sub_8129B34, }; -const struct YesNoFuncTable gUnknown_085A7350 = { - sub_812A210, - sub_8129B34 +const struct YesNoFuncTable gUnknown_085A7350 = +{ + .yesFunc = sub_812A210, + .noFunc = sub_8129B34, }; -const u8 Unknown_085A7358[] = INCBIN_U8("graphics/misc/decoration_unk_85a7358.4bpp"); +const u8 gUnknown_085A7358[] = INCBIN_U8("graphics/misc/decoration_unk_85a7358.4bpp"); -const struct SpritePalette gUnknown_085A73D8 = { - Unknown_085A7308, OVERWORLD_PLACE_DECOR_PLAYER_PAL_TAG +const struct SpritePalette gUnknown_085A73D8 = +{ + .data = gUnknown_085A7308, + .tag = PLACE_DECORATION_PLAYER_TAG, }; -const struct SpritePalette gUnknown_085A73E0 = { - Unknown_085A7328, OVERWORLD_PLACE_DECOR_PLAYER_PAL_TAG +const struct SpritePalette gUnknown_085A73E0 = +{ + .data = gUnknown_085A7328, + .tag = PLACE_DECORATION_PLAYER_TAG, }; -const struct OamData Unknown_085A73E8 = +const struct OamData gUnknown_085A73E8 = { .y = 0, .affineMode = ST_OAM_AFFINE_OFF, @@ -405,164 +429,163 @@ const struct OamData Unknown_085A73E8 = .paletteNum = 0, }; -const union AnimCmd Unknown_085A73F0[] = { +const union AnimCmd gUnknown_085A73F0[] = +{ ANIMCMD_FRAME(0, 0, 0), ANIMCMD_END }; -const union AnimCmd *const Unknown_085A73F8[] = { - Unknown_085A73F0 +const union AnimCmd *const gUnknown_085A73F8[] = +{ + gUnknown_085A73F0, }; -const struct SpriteFrameImage Unknown_085A73FC = { - Unknown_085A7358, 0x80 +const struct SpriteFrameImage gUnknown_085A73FC = +{ + .data = gUnknown_085A7358, + .size = 0x80, }; -const struct SpriteTemplate gUnknown_085A7404 = { +const struct SpriteTemplate gUnknown_085A7404 = +{ 0xFFFF, - OVERWORLD_PLACE_DECOR_PLAYER_PAL_TAG, - &Unknown_085A73E8, - Unknown_085A73F8, - &Unknown_085A73FC, + PLACE_DECORATION_PLAYER_TAG, + &gUnknown_085A73E8, + gUnknown_085A73F8, + &gUnknown_085A73FC, gDummySpriteAffineAnimTable, sub_812A36C }; -const struct YesNoFuncTable gUnknown_085A741C = { - sub_812A478, - sub_8127A30 +const struct YesNoFuncTable gUnknown_085A741C = +{ + .yesFunc = sub_812A478, + .noFunc = sub_8127A30, }; -// .text -void sub_8126968(void) +void InitDecorationContextItems(void) { - if (sCurDecorationCategory < 8) + if (sCurDecorationCategory < DECORCAT_COUNT) + gCurDecorationItems = gDecorationInventories[sCurDecorationCategory].items; + + if (gDecorationContext.isPlayerRoom == FALSE) { - gCurDecorInventoryItems = gDecorationInventories[sCurDecorationCategory].items; + gDecorationContext.items = gSaveBlock1Ptr->secretBases[0].decorations; + gDecorationContext.pos = gSaveBlock1Ptr->secretBases[0].decorationPositions; } - if (gUnknown_0203A17C.isPlayerRoom == FALSE) + + if (gDecorationContext.isPlayerRoom == TRUE) { - gUnknown_0203A17C.items = gSaveBlock1Ptr->secretBases[0].decorations; - gUnknown_0203A17C.pos = gSaveBlock1Ptr->secretBases[0].decorationPositions; - } - if (gUnknown_0203A17C.isPlayerRoom == TRUE) - { - gUnknown_0203A17C.items = gSaveBlock1Ptr->playerRoomDecor; - gUnknown_0203A17C.pos = gSaveBlock1Ptr->playerRoomDecorPos; + gDecorationContext.items = gSaveBlock1Ptr->playerRoomDecor; + gDecorationContext.pos = gSaveBlock1Ptr->playerRoomDecorPos; } } -u8 sub_81269D4(u8 idx) +static u8 AddDecorationWindow(u8 windowIndex) { - u8 *winidx; + u8 *windowId; struct WindowTemplate template; - winidx = &sDecorMenuWindowIndices[idx]; - if (idx == 0) + windowId = &sDecorMenuWindowIds[windowIndex]; + if (windowIndex == 0) { - template = gUnknown_085A6B90[0]; - template.width = GetMaxWidthInMenuTable(sSecretBasePCMenuActions, 4); + template = sDecorationWindowTemplates[0]; + template.width = GetMaxWidthInMenuTable(sDecorationMainMenuActions, ARRAY_COUNT(sDecorationMainMenuActions)); if (template.width > 18) - { template.width = 18; - } - *winidx = AddWindow(&template); + + *windowId = AddWindow(&template); } else { - *winidx = AddWindow(&gUnknown_085A6B90[idx]); + *windowId = AddWindow(&sDecorationWindowTemplates[windowIndex]); } - DrawStdFrameWithCustomTileAndPalette(*winidx, 0, 0x214, 0xe); + + DrawStdFrameWithCustomTileAndPalette(*windowId, FALSE, 0x214, 14); schedule_bg_copy_tilemap_to_vram(0); - return *winidx; + return *windowId; } -void sub_8126A58(u8 idx) +static void RemoveDecorationWindow(u8 windowIndex) { - ClearStdWindowAndFrameToTransparent(sDecorMenuWindowIndices[idx], FALSE); - ClearWindowTilemap(sDecorMenuWindowIndices[idx]); - RemoveWindow(sDecorMenuWindowIndices[idx]); + ClearStdWindowAndFrameToTransparent(sDecorMenuWindowIds[windowIndex], FALSE); + ClearWindowTilemap(sDecorMenuWindowIds[windowIndex]); + RemoveWindow(sDecorMenuWindowIds[windowIndex]); schedule_bg_copy_tilemap_to_vram(0); } -void sub_8126A88(void) +static void AddDecorationActionsWindow(void) { - u8 idx; - - idx = sub_81269D4(0); - PrintMenuTable(idx, 4, sSecretBasePCMenuActions); - InitMenuInUpperLeftCornerPlaySoundWhenAPressed(idx, 4, sSecretBasePCMenuCursorPos); + u8 windowId = AddDecorationWindow(0); + PrintMenuTable(windowId, 4, sDecorationMainMenuActions); + InitMenuInUpperLeftCornerPlaySoundWhenAPressed(windowId, 4, sDecorationActionsCursorPos); } -void sub_8126ABC(void) +static void InitDecorationActionsWindow(void) { - sSecretBasePCMenuCursorPos = 0; + sDecorationActionsCursorPos = 0; ScriptContext2_Enable(); - sub_8126A88(); - sub_8126C08(); + AddDecorationActionsWindow(); + PrintCurMainMenuDescription(); } -void sub_8126AD8(u8 taskId) +void DoSecretBaseDecorationMenu(u8 taskId) { - sub_8126ABC(); - gUnknown_0203A17C.items = gSaveBlock1Ptr->secretBases[0].decorations; - gUnknown_0203A17C.pos = gSaveBlock1Ptr->secretBases[0].decorationPositions; - gUnknown_0203A17C.size = sizeof(gSaveBlock1Ptr->secretBases[0].decorations); - gUnknown_0203A17C.isPlayerRoom = FALSE; - gTasks[taskId].func = sub_8126B80; + InitDecorationActionsWindow(); + gDecorationContext.items = gSaveBlock1Ptr->secretBases[0].decorations; + gDecorationContext.pos = gSaveBlock1Ptr->secretBases[0].decorationPositions; + gDecorationContext.size = sizeof(gSaveBlock1Ptr->secretBases[0].decorations); + gDecorationContext.isPlayerRoom = FALSE; + gTasks[taskId].func = HandleDecorationActionsMenuInput; } -void sub_8126B2C(u8 taskId) +void DoPlayerRoomDecorationMenu(u8 taskId) { - sub_8126ABC(); - gUnknown_0203A17C.items = gSaveBlock1Ptr->playerRoomDecor; - gUnknown_0203A17C.pos = gSaveBlock1Ptr->playerRoomDecorPos; - gUnknown_0203A17C.size = sizeof(gSaveBlock1Ptr->playerRoomDecor); - gUnknown_0203A17C.isPlayerRoom = TRUE; - gTasks[taskId].func = sub_8126B80; + InitDecorationActionsWindow(); + gDecorationContext.items = gSaveBlock1Ptr->playerRoomDecor; + gDecorationContext.pos = gSaveBlock1Ptr->playerRoomDecorPos; + gDecorationContext.size = sizeof(gSaveBlock1Ptr->playerRoomDecor); + gDecorationContext.isPlayerRoom = TRUE; + gTasks[taskId].func = HandleDecorationActionsMenuInput; } -void sub_8126B80(u8 taskId) +static void HandleDecorationActionsMenuInput(u8 taskId) { - u8 menuPos; - if (!gPaletteFade.active) { - menuPos = Menu_GetCursorPos(); + s8 menuPos = Menu_GetCursorPos(); switch (Menu_ProcessInput()) { - default: - PlaySE(SE_SELECT); - sSecretBasePCMenuActions[sSecretBasePCMenuCursorPos].func.void_u8(taskId); - break; - case MENU_NOTHING_CHOSEN: - sSecretBasePCMenuCursorPos = Menu_GetCursorPos(); - if ((s8)menuPos != sSecretBasePCMenuCursorPos) - { - sub_8126C08(); - } - break; - case MENU_B_PRESSED: - PlaySE(SE_SELECT); - SecretBasePC_Cancel(taskId); - break; + default: + PlaySE(SE_SELECT); + sDecorationMainMenuActions[sDecorationActionsCursorPos].func.void_u8(taskId); + break; + case MENU_NOTHING_CHOSEN: + sDecorationActionsCursorPos = Menu_GetCursorPos(); + if (menuPos != sDecorationActionsCursorPos) + PrintCurMainMenuDescription(); + break; + case MENU_B_PRESSED: + PlaySE(SE_SELECT); + DecorationMenuAction_Cancel(taskId); + break; } } } -void sub_8126C08(void) +static void PrintCurMainMenuDescription(void) { FillWindowPixelBuffer(0, PIXEL_FILL(1)); - AddTextPrinterParameterized2(0, 1, sSecretBasePCMenuItemDescriptions[sSecretBasePCMenuCursorPos], 0, 0, 2, 1, 3); + AddTextPrinterParameterized2(0, 1, sSecretBasePCMenuItemDescriptions[sDecorationActionsCursorPos], 0, 0, 2, 1, 3); } -void SecretBasePC_Decorate(u8 taskId) +static void DecorationMenuAction_Decorate(u8 taskId) { - if (CountDecorations() == 0) + if (GetNumOwnedDecorations() == 0) { StringExpandPlaceholders(gStringVar4, gText_NoDecorations); - DisplayItemMessageOnField(taskId, gStringVar4, sub_8126DA4); + DisplayItemMessageOnField(taskId, gStringVar4, ReturnToDecorationActionsAfterInvalidSelection); } else { @@ -572,16 +595,16 @@ void SecretBasePC_Decorate(u8 taskId) } } -void SecretBasePC_PutAway(u8 taskId) +static void DecorationMenuAction_PutAway(u8 taskId) { if (!sub_81299AC(taskId)) { StringExpandPlaceholders(gStringVar4, gText_NoDecorationsInUse); - DisplayItemMessageOnField(taskId, gStringVar4, sub_8126DA4); + DisplayItemMessageOnField(taskId, gStringVar4, ReturnToDecorationActionsAfterInvalidSelection); } else { - sub_8126A58(0); + RemoveDecorationWindow(0); ClearDialogWindowAndFrame(0, 0); FadeScreen(1, 0); gTasks[taskId].data[2] = 0; @@ -589,12 +612,12 @@ void SecretBasePC_PutAway(u8 taskId) } } -void SecretBasePC_Toss(u8 taskId) +static void DecorationMenuAction_Toss(u8 taskId) { - if (CountDecorations() == 0) + if (GetNumOwnedDecorations() == 0) { StringExpandPlaceholders(gStringVar4, gText_NoDecorations); - DisplayItemMessageOnField(taskId, gStringVar4, sub_8126DA4); + DisplayItemMessageOnField(taskId, gStringVar4, ReturnToDecorationActionsAfterInvalidSelection); } else { @@ -604,10 +627,10 @@ void SecretBasePC_Toss(u8 taskId) } } -void SecretBasePC_Cancel(u8 taskId) +static void DecorationMenuAction_Cancel(u8 taskId) { - sub_8126A58(0); - if (!gUnknown_0203A17C.isPlayerRoom) + RemoveDecorationWindow(0); + if (!gDecorationContext.isPlayerRoom) { ScriptContext1_SetupScript(gUnknown_0823B4E8); DestroyTask(taskId); @@ -618,260 +641,237 @@ void SecretBasePC_Cancel(u8 taskId) } } -void sub_8126DA4(u8 taskId) +static void ReturnToDecorationActionsAfterInvalidSelection(u8 taskId) { - sub_8126C08(); - gTasks[taskId].func = sub_8126B80; + PrintCurMainMenuDescription(); + gTasks[taskId].func = HandleDecorationActionsMenuInput; } -void SecretBasePC_PrepMenuForSelectingStoredDecors(u8 taskId) +static void SecretBasePC_PrepMenuForSelectingStoredDecors(u8 taskId) { - LoadPalette(gUnknown_085A6BB0, 0xd0, 0x20); + LoadPalette(sDecorationMenuPalette, 0xd0, 0x20); ClearDialogWindowAndFrame(0, 0); - sub_8126A58(0); - sub_8126DFC(taskId); + RemoveDecorationWindow(0); + InitDecorationCategoriesWindow(taskId); } -void sub_8126DFC(u8 taskId) +static void InitDecorationCategoriesWindow(u8 taskId) { - u8 winIdx; - - winIdx = sub_81269D4(1); - sub_8126E8C(taskId); - InitMenuInUpperLeftCornerPlaySoundWhenAPressed(winIdx, 9, sCurDecorationCategory); - gTasks[taskId].func = sub_8127088; + u8 windowId = AddDecorationWindow(1); + PrintDecorationCategoryMenuItems(taskId); + InitMenuInUpperLeftCornerPlaySoundWhenAPressed(windowId, DECORCAT_COUNT + 1, sCurDecorationCategory); + gTasks[taskId].func = HandleDecorationCategoriesMenuInput; } -void sub_8126E44(u8 taskId) +static void sub_8126E44(u8 taskId) { - FillWindowPixelBuffer(sDecorMenuWindowIndices[1], PIXEL_FILL(1)); - sub_8126E8C(taskId); - InitMenuInUpperLeftCornerPlaySoundWhenAPressed(sDecorMenuWindowIndices[1], 9, sCurDecorationCategory); - gTasks[taskId].func = sub_8127088; + FillWindowPixelBuffer(sDecorMenuWindowIds[1], PIXEL_FILL(1)); + PrintDecorationCategoryMenuItems(taskId); + InitMenuInUpperLeftCornerPlaySoundWhenAPressed(sDecorMenuWindowIds[1], DECORCAT_COUNT + 1, sCurDecorationCategory); + gTasks[taskId].func = HandleDecorationCategoriesMenuInput; } -void sub_8126E8C(u8 taskId) +static void PrintDecorationCategoryMenuItems(u8 taskId) { - s16 *data; - u8 r5; - bool8 r8; u8 i; - bool8 fl; + s16 *data = gTasks[taskId].data; + u8 windowId = sDecorMenuWindowIds[1]; + bool8 isPlayerRoom = gDecorationContext.isPlayerRoom; + bool8 shouldDisable = FALSE; + if (isPlayerRoom == TRUE && data[11] == 0) + shouldDisable = TRUE; - data = gTasks[taskId].data; - r5 = sDecorMenuWindowIndices[1]; - fl = gUnknown_0203A17C.isPlayerRoom; - r8 = FALSE; - if (fl == TRUE && data[11] == 0) + for (i = 0; i < DECORCAT_COUNT; i++) { - r8 = TRUE; - } - for (i = 0; i < 8; i ++) - { - if (r8 == TRUE && i != DECORCAT_DOLL && i != DECORCAT_CUSHION) - { - sub_8126F68(r5, i, 8, i << 4, TRUE, 0xFF); - } + // Only DOLL and CUSHION decorations are enabled when decorating the player's room. + if (shouldDisable == TRUE && i != DECORCAT_DOLL && i != DECORCAT_CUSHION) + PrintDecorationCategoryMenuItem(windowId, i, 8, i * 16, TRUE, TEXT_SPEED_FF); else - { - sub_8126F68(r5, i, 8, i << 4, FALSE, 0xFF); - } + PrintDecorationCategoryMenuItem(windowId, i, 8, i * 16, FALSE, TEXT_SPEED_FF); } - AddTextPrinterParameterized(r5, 1, gTasks[taskId].data[11] == 2 ? gText_Exit : gText_Cancel, 8, (i << 4) + 1, 0, 0); + + AddTextPrinterParameterized(windowId, 1, gTasks[taskId].data[11] == 2 ? gText_Exit : gText_Cancel, 8, i * 16 + 1, 0, NULL); schedule_bg_copy_tilemap_to_vram(0); } -void sub_8126F68(u8 winid, u8 decorCat, u8 x, u8 y, bool8 flag, u8 speed) +static void PrintDecorationCategoryMenuItem(u8 winid, u8 category, u8 x, u8 y, bool8 disabled, u8 speed) { u8 width; - u8 *strbuf; + u8 *str; - width = x == 8 ? 0x68 : 0x60; - y ++; - sub_8127058(gStringVar4, flag); - strbuf = StringLength(gStringVar4) + gStringVar4; - StringCopy(strbuf, sDecorCatNames[decorCat]); + width = x == 8 ? 104 : 96; + y++; + ColorMenuItemString(gStringVar4, disabled); + str = StringLength(gStringVar4) + gStringVar4; + StringCopy(str, sDecorationCategoryNames[category]); AddTextPrinterParameterized(winid, 1, gStringVar4, x, y, speed, NULL); - strbuf = ConvertIntToDecimalStringN(strbuf, CountDecorationCategoryN(decorCat), STR_CONV_MODE_RIGHT_ALIGN, 2); - *strbuf++ = CHAR_SLASH; - ConvertIntToDecimalStringN(strbuf, gDecorationInventories[decorCat].size, STR_CONV_MODE_RIGHT_ALIGN, 2); + str = ConvertIntToDecimalStringN(str, GetNumOwnedDecorationsInCategory(category), STR_CONV_MODE_RIGHT_ALIGN, 2); + *(str++) = CHAR_SLASH; + ConvertIntToDecimalStringN(str, gDecorationInventories[category].size, STR_CONV_MODE_RIGHT_ALIGN, 2); x = GetStringRightAlignXOffset(1, gStringVar4, width); AddTextPrinterParameterized(winid, 1, gStringVar4, x, y, speed, NULL); } -void sub_8127058(u8 *str, bool8 flag) +static void ColorMenuItemString(u8 *str, bool8 disabled) { StringCopy(str, gText_Color161Shadow161); - if (flag == TRUE) + if (disabled == TRUE) { - str[2] = 0x04; // RED - str[5] = 0x05; // LIGHT_RED + str[2] = 4; + str[5] = 5; } else { - str[2] = 0x02; // DARK_GREY - str[5] = 0x03; // LIGHT_GREY + str[2] = 2; + str[5] = 3; } } -void sub_8127088(u8 taskId) +static void HandleDecorationCategoriesMenuInput(u8 taskId) { - s8 input; - if (!gPaletteFade.active) { - input = Menu_ProcessInput(); + s8 input = Menu_ProcessInput(); switch (input) { - case MENU_B_PRESSED: - case 8: - PlaySE(SE_SELECT); - sub_812719C(taskId); - break; - case MENU_NOTHING_CHOSEN: - break; - default: - PlaySE(SE_SELECT); - sCurDecorationCategory = input; - sub_81270E8(taskId); - break; + case MENU_B_PRESSED: + case DECORCAT_COUNT: // CANCEL + PlaySE(SE_SELECT); + ExitDecorationCategoriesMenu(taskId); + break; + case MENU_NOTHING_CHOSEN: + break; + default: + PlaySE(SE_SELECT); + sCurDecorationCategory = input; + SelectDecorationCategory(taskId); + break; } } } -void sub_81270E8(u8 taskId) +static void SelectDecorationCategory(u8 taskId) { - sCurDecorCatCount = CountDecorationCategoryN(sCurDecorationCategory); - if (sCurDecorCatCount != 0) + sNumOwnedDecorationsInCurCategory = GetNumOwnedDecorationsInCategory(sCurDecorationCategory); + if (sNumOwnedDecorationsInCurCategory != 0) { - CondenseDecorationCategoryN(sCurDecorationCategory); - gCurDecorInventoryItems = gDecorationInventories[sCurDecorationCategory].items; + CondenseDecorationsInCategory(sCurDecorationCategory); + gCurDecorationItems = gDecorationInventories[sCurDecorationCategory].items; IdentifyOwnedDecorationsCurrentlyInUse(taskId); - sSecretBasePCSelectDecorPageNo = 0; - sSecretBasePCSelectDecorLineNo = 0; - gTasks[taskId].func = sub_8127620; + sDecorationsScrollOffset = 0; + sDecorationsCursorPos = 0; + gTasks[taskId].func = ShowDecorationItemsWindow; } else { - sub_8126A58(1); + RemoveDecorationWindow(1); StringExpandPlaceholders(gStringVar4, gText_NoDecorations); - DisplayItemMessageOnField(taskId, gStringVar4, sub_8127180); + DisplayItemMessageOnField(taskId, gStringVar4, ReturnToDecorationCategoriesAfterInvalidSelection); } } -void sub_8127180(u8 taskId) +static void ReturnToDecorationCategoriesAfterInvalidSelection(u8 taskId) { ClearDialogWindowAndFrame(0, 0); - sub_8126DFC(taskId); + InitDecorationCategoriesWindow(taskId); } -void sub_812719C(u8 taskId) +static void ExitDecorationCategoriesMenu(u8 taskId) { if (gTasks[taskId].data[11] != 2) - { - sub_81271CC(taskId); - } + ReturnToActionsMenuFromCategories(taskId); else - { - sub_8127268(taskId); - } + ExitTraderDecorationMenu(taskId); } -void sub_81271CC(u8 taskId) +static void ReturnToActionsMenuFromCategories(u8 taskId) { - sub_8126A58(1); - sub_8126A88(); + RemoveDecorationWindow(1); + AddDecorationActionsWindow(); DrawDialogueFrame(0, 0); - sub_8126C08(); - gTasks[taskId].func = sub_8126B80; + PrintCurMainMenuDescription(); + gTasks[taskId].func = HandleDecorationActionsMenuInput; } -void sub_8127208(u8 taskId) +void ShowDecorationCategoriesWindow(u8 taskId) { - LoadPalette(gUnknown_085A6BB0, 0xd0, 0x20); + LoadPalette(sDecorationMenuPalette, 0xd0, 0x20); ClearDialogWindowAndFrame(0, 0); gTasks[taskId].data[11] = 2; sCurDecorationCategory = DECORCAT_DESK; - sub_8126DFC(taskId); + InitDecorationCategoriesWindow(taskId); } -void sub_8127250(u8 *dest, u8 decorCat) +void CopyDecorationCategoryName(u8 *dest, u8 category) { - StringCopy(dest, sDecorCatNames[decorCat]); + StringCopy(dest, sDecorationCategoryNames[category]); } -void sub_8127268(u8 taskId) +static void ExitTraderDecorationMenu(u8 taskId) { - sub_8126A58(1); - sub_8133E1C(taskId); + RemoveDecorationWindow(1); + ExitTraderMenu(taskId); } -void sub_8127284(void) +static void InitDecorationItemsMenuLimits(void) { - sDecorPCBuffer->unk_520 = sCurDecorCatCount + 1; - if (sDecorPCBuffer->unk_520 > 8) - { - sDecorPCBuffer->unk_521 = 8; - } + sDecorationItemsMenu->numMenuItems = sNumOwnedDecorationsInCurCategory + 1; + if (sDecorationItemsMenu->numMenuItems > 8) + sDecorationItemsMenu->maxShownItems = 8; else - { - sDecorPCBuffer->unk_521 = sDecorPCBuffer->unk_520; - } + sDecorationItemsMenu->maxShownItems = sDecorationItemsMenu->numMenuItems; } -void sub_81272C8(void) +static void sub_81272C8(void) { - sub_812225C(&sSecretBasePCSelectDecorPageNo, &sSecretBasePCSelectDecorLineNo, sDecorPCBuffer->unk_521, sDecorPCBuffer->unk_520); + sub_812225C(&sDecorationsScrollOffset, &sDecorationsCursorPos, sDecorationItemsMenu->maxShownItems, sDecorationItemsMenu->numMenuItems); } -void sub_81272F8(void) +static void sub_81272F8(void) { - sub_8122298(&sSecretBasePCSelectDecorPageNo, &sSecretBasePCSelectDecorLineNo, sDecorPCBuffer->unk_521, sDecorPCBuffer->unk_520, 8); + sub_8122298(&sDecorationsScrollOffset, &sDecorationsCursorPos, sDecorationItemsMenu->maxShownItems, sDecorationItemsMenu->numMenuItems, 8); } -void sub_8127330(u8 taskId) +static void PrintDecorationItemMenuItems(u8 taskId) { s16 *data; u16 i; data = gTasks[taskId].data; - if ((sCurDecorationCategory < DECORCAT_DOLL || sCurDecorationCategory > DECORCAT_CUSHION) && gUnknown_0203A17C.isPlayerRoom == TRUE && data[11] == 0) - { - sub_8127058(gStringVar1, TRUE); - } + if ((sCurDecorationCategory < DECORCAT_DOLL || sCurDecorationCategory > DECORCAT_CUSHION) && gDecorationContext.isPlayerRoom == TRUE && data[11] == 0) + ColorMenuItemString(gStringVar1, TRUE); else + ColorMenuItemString(gStringVar1, FALSE); + + for (i = 0; i < sDecorationItemsMenu->numMenuItems - 1; i++) { - sub_8127058(gStringVar1, FALSE); + CopyDecorationMenuItemName(sDecorationItemsMenu->names[i], gCurDecorationItems[i]); + sDecorationItemsMenu->items[i].name = sDecorationItemsMenu->names[i]; + sDecorationItemsMenu->items[i].id = i; } - for (i = 0; i < sDecorPCBuffer->unk_520 - 1; i ++) - { - sub_8127454(sDecorPCBuffer->names[i], gCurDecorInventoryItems[i]); - sDecorPCBuffer->items[i].name = sDecorPCBuffer->names[i]; - sDecorPCBuffer->items[i].id = i; - } - StringCopy(sDecorPCBuffer->names[i], gText_Cancel); - sDecorPCBuffer->items[i].name = sDecorPCBuffer->names[i]; - sDecorPCBuffer->items[i].id = -2; - gMultiuseListMenuTemplate = gUnknown_085A6BD0; - gMultiuseListMenuTemplate.windowId = sDecorMenuWindowIndices[1]; - gMultiuseListMenuTemplate.totalItems = sDecorPCBuffer->unk_520; - gMultiuseListMenuTemplate.items = sDecorPCBuffer->items; - gMultiuseListMenuTemplate.maxShowed = sDecorPCBuffer->unk_521; + + StringCopy(sDecorationItemsMenu->names[i], gText_Cancel); + sDecorationItemsMenu->items[i].name = sDecorationItemsMenu->names[i]; + sDecorationItemsMenu->items[i].id = -2; + gMultiuseListMenuTemplate = sDecorationItemsListMenuTemplate; + gMultiuseListMenuTemplate.windowId = sDecorMenuWindowIds[1]; + gMultiuseListMenuTemplate.totalItems = sDecorationItemsMenu->numMenuItems; + gMultiuseListMenuTemplate.items = sDecorationItemsMenu->items; + gMultiuseListMenuTemplate.maxShowed = sDecorationItemsMenu->maxShownItems; } -void sub_8127454(u8 *dest, u16 decorId) +static void CopyDecorationMenuItemName(u8 *dest, u16 decoration) { StringCopy(dest, gStringVar1); - StringAppend(dest, gDecorations[decorId].name); + StringAppend(dest, gDecorations[decoration].name); } -void sub_8127480(s32 a0, bool8 flag, struct ListMenu *menu) +static void DecorationItemsMenu_OnCursorMove(s32 itemIndex, bool8 flag, struct ListMenu *menu) { if (flag != TRUE) - { PlaySE(SE_SELECT); - } - sub_8127744(a0); + + PrintDecorationItemDescription(itemIndex); } void sub_81274A0(u8 a0, s32 a1, u8 a2) @@ -889,53 +889,59 @@ void sub_81274A0(u8 a0, s32 a1, u8 a2) } } -void sub_8127500(void) +static void AddDecorationItemsScrollIndicators(void) { - if (sDecorPCBuffer->unk_522 == 0xFF) + if (sDecorationItemsMenu->scrollIndicatorsTaskId == 0xFF) { - sDecorPCBuffer->unk_522 = AddScrollIndicatorArrowPairParameterized(SCROLL_ARROW_UP, 0x3c, 0x0c, 0x94, sDecorPCBuffer->unk_520 - sDecorPCBuffer->unk_521, 0x6e, 0x6e, &sSecretBasePCSelectDecorPageNo); + sDecorationItemsMenu->scrollIndicatorsTaskId = AddScrollIndicatorArrowPairParameterized( + SCROLL_ARROW_UP, + 0x3c, + 0x0c, + 0x94, + sDecorationItemsMenu->numMenuItems - sDecorationItemsMenu->maxShownItems, + 0x6e, + 0x6e, + &sDecorationsScrollOffset); } } -void sub_8127554(void) +static void RemoveDecorationItemsScrollIndicators(void) { - if (sDecorPCBuffer->unk_522 != 0xFF) + if (sDecorationItemsMenu->scrollIndicatorsTaskId != 0xFF) { - RemoveScrollIndicatorArrowPair(sDecorPCBuffer->unk_522); - sDecorPCBuffer->unk_522 = 0xFF; + RemoveScrollIndicatorArrowPair(sDecorationItemsMenu->scrollIndicatorsTaskId); + sDecorationItemsMenu->scrollIndicatorsTaskId = 0xFF; } } void sub_8127580(u8 taskId) { - sub_81269D4(1); - sub_812759C(taskId); + AddDecorationWindow(1); + InitDecorationItemsWindow(taskId); } -void sub_812759C(u8 taskId) +static void InitDecorationItemsWindow(u8 taskId) { - s16 *data; - - data = gTasks[taskId].data; - sub_81269D4(3); - sub_8127718(sCurDecorationCategory); - sDecorPCBuffer = calloc(1, sizeof(struct DecorPCBuffer)); - sDecorPCBuffer->unk_522 = 0xFF; - sub_8127284(); + s16 *data = gTasks[taskId].data; + AddDecorationWindow(3); + ShowDecorationCategorySummaryWindow(sCurDecorationCategory); + sDecorationItemsMenu = AllocZeroed(sizeof(*sDecorationItemsMenu)); + sDecorationItemsMenu->scrollIndicatorsTaskId = 0xFF; + InitDecorationItemsMenuLimits(); sub_81272C8(); sub_81272F8(); - sub_8127330(taskId); - data[13] = ListMenuInit(&gMultiuseListMenuTemplate, sSecretBasePCSelectDecorPageNo, sSecretBasePCSelectDecorLineNo); - sub_8127500(); + PrintDecorationItemMenuItems(taskId); + data[13] = ListMenuInit(&gMultiuseListMenuTemplate, sDecorationsScrollOffset, sDecorationsCursorPos); + AddDecorationItemsScrollIndicators(); } -void sub_8127620(u8 taskId) +static void ShowDecorationItemsWindow(u8 taskId) { - sub_812759C(taskId); - gTasks[taskId].func = sub_812764C; + InitDecorationItemsWindow(taskId); + gTasks[taskId].func = HandleDecorationItemsMenuInput; } -void sub_812764C(u8 taskId) +static void HandleDecorationItemsMenuInput(u8 taskId) { s16 *data; s32 input; @@ -944,129 +950,125 @@ void sub_812764C(u8 taskId) if (!gPaletteFade.active) { input = ListMenu_ProcessInput(data[13]); - ListMenuGetScrollAndRow(data[13], &sSecretBasePCSelectDecorPageNo, &sSecretBasePCSelectDecorLineNo); + ListMenuGetScrollAndRow(data[13], &sDecorationsScrollOffset, &sDecorationsCursorPos); switch (input) { - case LIST_NOTHING_CHOSEN: - break; - case LIST_CANCEL: - PlaySE(SE_SELECT); - SecretBasePC_SelectedDecorActions[data[11]][1](taskId); - break; - default: - PlaySE(SE_SELECT); - gCurDecorationIndex = input; - sub_8127554(); - DestroyListMenuTask(data[13], &sSecretBasePCSelectDecorPageNo, &sSecretBasePCSelectDecorLineNo); - sub_8126A58(1); - sub_81277A8(); - free(sDecorPCBuffer); - SecretBasePC_SelectedDecorActions[data[11]][0](taskId); - break; + case LIST_NOTHING_CHOSEN: + break; + case LIST_CANCEL: + PlaySE(SE_SELECT); + sSecretBasePC_SelectedDecorationActions[data[11]][1](taskId); + break; + default: + PlaySE(SE_SELECT); + gCurDecorationIndex = input; + RemoveDecorationItemsScrollIndicators(); + DestroyListMenuTask(data[13], &sDecorationsScrollOffset, &sDecorationsCursorPos); + RemoveDecorationWindow(1); + RemoveDecorationItemsOtherWindows(); + free(sDecorationItemsMenu); + sSecretBasePC_SelectedDecorationActions[data[11]][0](taskId); + break; } } } -void sub_8127718(u8 decorCat) +static void ShowDecorationCategorySummaryWindow(u8 category) { - sub_8126F68(sub_81269D4(2), decorCat, 0, 0, 0, 0); + PrintDecorationCategoryMenuItem(AddDecorationWindow(2), category, 0, 0, 0, 0); } -void sub_8127744(u32 a0) +static void PrintDecorationItemDescription(u32 itemIndex) { - u8 winidx; - const u8 *txt; + u8 windowId; + const u8 *str; - winidx = sDecorMenuWindowIndices[3]; - FillWindowPixelBuffer(winidx, PIXEL_FILL(1)); - if (a0 >= sCurDecorCatCount) - { - txt = gText_GoBackPrevMenu; - } + windowId = sDecorMenuWindowIds[3]; + FillWindowPixelBuffer(windowId, PIXEL_FILL(1)); + if (itemIndex >= sNumOwnedDecorationsInCurCategory) + str = gText_GoBackPrevMenu; else - { - txt = gDecorations[gCurDecorInventoryItems[a0]].description; - } - AddTextPrinterParameterized(winidx, 1, txt, 0, 1, 0, 0); + str = gDecorations[gCurDecorationItems[itemIndex]].description; + + AddTextPrinterParameterized(windowId, 1, str, 0, 1, 0, 0); } -void sub_81277A8(void) +static void RemoveDecorationItemsOtherWindows(void) { - sub_8126A58(3); - sub_8126A58(2); + // Remove description and category summary windows + RemoveDecorationWindow(3); + RemoveDecorationWindow(2); } bool8 sub_81277BC(u8 idx) { u8 i; - - for (i = 0; i < 16; i ++) + for (i = 0; i < ARRAY_COUNT(sSecretBaseItemsIndicesBuffer); i++) { if (sSecretBaseItemsIndicesBuffer[i] == idx) - { return TRUE; - } } + return FALSE; } bool8 sub_81277E8(u8 idx) { u8 i; - - for (i = 0; i < 12; i ++) + for (i = 0; i < ARRAY_COUNT(sPlayerRoomItemsIndicesBuffer); i++) { if (sPlayerRoomItemsIndicesBuffer[i] == idx) - { return TRUE; - } } + return FALSE; } -void IdentifyOwnedDecorationsCurrentlyInUseInternal(u8 taskId) +static void IdentifyOwnedDecorationsCurrentlyInUseInternal(u8 taskId) { - u16 i; - u16 j; - u16 k; - u16 cnt; + u16 i, j, k; + u16 count; - cnt = 0; - memset(sSecretBaseItemsIndicesBuffer, 0, 16); - memset(sPlayerRoomItemsIndicesBuffer, 0, 12); - for (i = 0; i < 16; i ++) + count = 0; + memset(sSecretBaseItemsIndicesBuffer, 0, sizeof(sSecretBaseItemsIndicesBuffer)); + memset(sPlayerRoomItemsIndicesBuffer, 0, sizeof(sPlayerRoomItemsIndicesBuffer)); + + for (i = 0; i < ARRAY_COUNT(sSecretBaseItemsIndicesBuffer); i++) { if (gSaveBlock1Ptr->secretBases[0].decorations[i] != DECOR_NONE) { - for (j = 0; j < gDecorationInventories[sCurDecorationCategory].size; j ++) + for (j = 0; j < gDecorationInventories[sCurDecorationCategory].size; j++) { - if (gCurDecorInventoryItems[j] == gSaveBlock1Ptr->secretBases[0].decorations[i]) + if (gCurDecorationItems[j] == gSaveBlock1Ptr->secretBases[0].decorations[i]) { - for (k = 0; k < cnt && sSecretBaseItemsIndicesBuffer[k] != j + 1; k ++); - if (k == cnt) + for (k = 0; k < count && sSecretBaseItemsIndicesBuffer[k] != j + 1; k++) + ; + + if (k == count) { - sSecretBaseItemsIndicesBuffer[cnt] = j + 1; - cnt ++; + sSecretBaseItemsIndicesBuffer[count] = j + 1; + count++; break; } } } } } - cnt = 0; - for (i = 0; i < 12; i ++) + + count = 0; + for (i = 0; i < ARRAY_COUNT(sPlayerRoomItemsIndicesBuffer); i++) { if (gSaveBlock1Ptr->playerRoomDecor[i] != DECOR_NONE) { - for (j = 0; j < gDecorationInventories[sCurDecorationCategory].size; j ++) + for (j = 0; j < gDecorationInventories[sCurDecorationCategory].size; j++) { - if (gCurDecorInventoryItems[j] == gSaveBlock1Ptr->playerRoomDecor[i] && sub_81277BC(j + 1) != TRUE) + if (gCurDecorationItems[j] == gSaveBlock1Ptr->playerRoomDecor[i] && sub_81277BC(j + 1) != TRUE) { - for (k = 0; k < cnt && sPlayerRoomItemsIndicesBuffer[k] != j + 1; k ++); - if (k == cnt) + for (k = 0; k < count && sPlayerRoomItemsIndicesBuffer[k] != j + 1; k++); + if (k == count) { - sPlayerRoomItemsIndicesBuffer[cnt] = j + 1; - cnt ++; + sPlayerRoomItemsIndicesBuffer[count] = j + 1; + count++; break; } } @@ -1075,7 +1077,7 @@ void IdentifyOwnedDecorationsCurrentlyInUseInternal(u8 taskId) } } -void IdentifyOwnedDecorationsCurrentlyInUse(u8 taskId) +static void IdentifyOwnedDecorationsCurrentlyInUse(u8 taskId) { IdentifyOwnedDecorationsCurrentlyInUseInternal(taskId); } @@ -1083,24 +1085,25 @@ void IdentifyOwnedDecorationsCurrentlyInUse(u8 taskId) bool8 IsSelectedDecorInThePC(void) { u16 i; - for (i = 0; i < 16; i ++) + for (i = 0; i < ARRAY_COUNT(sSecretBaseItemsIndicesBuffer); i++) { - if (sSecretBaseItemsIndicesBuffer[i] == sSecretBasePCSelectDecorPageNo + sSecretBasePCSelectDecorLineNo + 1) - { + if (sSecretBaseItemsIndicesBuffer[i] == sDecorationsScrollOffset + sDecorationsCursorPos + 1) return FALSE; - } - if (i < 12 && sPlayerRoomItemsIndicesBuffer[i] == sSecretBasePCSelectDecorPageNo + sSecretBasePCSelectDecorLineNo + 1) + + if (i < ARRAY_COUNT(sPlayerRoomItemsIndicesBuffer) + && sPlayerRoomItemsIndicesBuffer[i] == sDecorationsScrollOffset + sDecorationsCursorPos + 1) { return FALSE; } } + return TRUE; } -void sub_8127A14(u8 taskId) +static void sub_8127A14(u8 taskId) { - sub_81269D4(1); - sub_8127620(taskId); + AddDecorationWindow(1); + ShowDecorationItemsWindow(taskId); } void sub_8127A30(u8 taskId) @@ -1114,20 +1117,18 @@ void sub_8127A5C(u8 taskId) if (gMain.newKeys & (A_BUTTON | B_BUTTON)) { ClearDialogWindowAndFrame(0, 0); - sub_81269D4(1); - sub_8127620(taskId); + AddDecorationWindow(1); + ShowDecorationItemsWindow(taskId); } } void sub_8127A8C(u8 taskId) { - s16 *data; - - data = gTasks[taskId].data; - sub_8127554(); - sub_81277A8(); + s16 *data = gTasks[taskId].data; + RemoveDecorationItemsScrollIndicators(); + RemoveDecorationItemsOtherWindows(); DestroyListMenuTask(data[13], NULL, NULL); - free(sDecorPCBuffer); + free(sDecorationItemsMenu); sub_8126E44(taskId); } @@ -1145,25 +1146,23 @@ void sub_8127B04(u8 taskId) WarpIntoMap(); } -u16 sub_8127B54(u8 decor, u8 a1) +static u16 GetDecorationElevation(u8 decoration, u8 tileIndex) { - u16 resp; - - resp = -1; - switch (decor) + u16 elevation = -1; + switch (decoration) { - case DECOR_STAND: - resp = gUnknown_085A72E4[a1] << 12; - return resp; - case DECOR_SLIDE: - resp = gUnknown_085A72EC[a1] << 12; - return resp; - default: - return resp; + case DECOR_STAND: + elevation = sDecorationStandElevations[tileIndex] << 12; + return elevation; + case DECOR_SLIDE: + elevation = sDecorationSlideElevation[tileIndex] << 12; + return elevation; + default: + return elevation; } } -void sub_8127B90(u16 mapX, u16 mapY, u8 decWidth, u8 decHeight, u16 decor) +static void ShowDecorationOnMap_(u16 mapX, u16 mapY, u8 decWidth, u8 decHeight, u16 decoration) { u16 i, j; s16 x, y; @@ -1178,60 +1177,60 @@ void sub_8127B90(u16 mapX, u16 mapY, u8 decWidth, u8 decHeight, u16 decor) for (i = 0; i < decWidth; i++) { x = mapX + i; - behavior = GetBehaviorByMetatileId(0x200 + gDecorations[decor].tiles[j * decWidth + i]); - if (MetatileBehavior_IsSecretBaseImpassable(behavior) == TRUE || (gDecorations[decor].permission != DECORPERM_PASS_FLOOR && (behavior >> 12))) + behavior = GetBehaviorByMetatileId(0x200 + gDecorations[decoration].tiles[j * decWidth + i]); + if (MetatileBehavior_IsSecretBaseImpassable(behavior) == TRUE || (gDecorations[decoration].permission != DECORPERM_PASS_FLOOR && (behavior >> 12))) impassableFlag = METATILE_COLLISION_MASK; else impassableFlag = 0; - if (gDecorations[decor].permission != DECORPERM_NA_WALL && MetatileBehavior_IsSecretBaseNorthWall(MapGridGetMetatileBehaviorAt(x, y)) == TRUE) + if (gDecorations[decoration].permission != DECORPERM_NA_WALL && MetatileBehavior_IsSecretBaseNorthWall(MapGridGetMetatileBehaviorAt(x, y)) == TRUE) posterSide = 1; else posterSide = 0; - elevation = sub_8127B54(gDecorations[decor].id, j * decWidth + i); + elevation = GetDecorationElevation(gDecorations[decoration].id, j * decWidth + i); if (elevation != 0xFFFF) - MapGridSetMetatileEntryAt(x, y, (gDecorations[decor].tiles[j * decWidth + i] + (0x200 | posterSide)) | impassableFlag | elevation); + MapGridSetMetatileEntryAt(x, y, (gDecorations[decoration].tiles[j * decWidth + i] + (0x200 | posterSide)) | impassableFlag | elevation); else - MapGridSetMetatileIdAt(x, y, (gDecorations[decor].tiles[j * decWidth + i] + (0x200 | posterSide)) | impassableFlag); + MapGridSetMetatileIdAt(x, y, (gDecorations[decoration].tiles[j * decWidth + i] + (0x200 | posterSide)) | impassableFlag); } } } -void ShowDecorationOnMap(u16 mapX, u16 mapY, u16 decor) +void ShowDecorationOnMap(u16 mapX, u16 mapY, u16 decoration) { - switch (gDecorations[decor].shape) + switch (gDecorations[decoration].shape) { - case DECORSHAPE_1x1: - sub_8127B90(mapX, mapY, 1, 1, decor); - break; - case DECORSHAPE_2x1: - sub_8127B90(mapX, mapY, 2, 1, decor); - break; - case DECORSHAPE_3x1: // unused - sub_8127B90(mapX, mapY, 3, 1, decor); - break; - case DECORSHAPE_4x2: - sub_8127B90(mapX, mapY, 4, 2, decor); - break; - case DECORSHAPE_2x2: - sub_8127B90(mapX, mapY, 2, 2, decor); - break; - case DECORSHAPE_1x2: - sub_8127B90(mapX, mapY, 1, 2, decor); - break; - case DECORSHAPE_1x3: // unused - sub_8127B90(mapX, mapY, 1, 3, decor); - break; - case DECORSHAPE_2x4: - sub_8127B90(mapX, mapY, 2, 4, decor); - break; - case DECORSHAPE_3x3: - sub_8127B90(mapX, mapY, 3, 3, decor); - break; - case DECORSHAPE_3x2: - sub_8127B90(mapX, mapY, 3, 2, decor); - break; + case DECORSHAPE_1x1: + ShowDecorationOnMap_(mapX, mapY, 1, 1, decoration); + break; + case DECORSHAPE_2x1: + ShowDecorationOnMap_(mapX, mapY, 2, 1, decoration); + break; + case DECORSHAPE_3x1: // unused + ShowDecorationOnMap_(mapX, mapY, 3, 1, decoration); + break; + case DECORSHAPE_4x2: + ShowDecorationOnMap_(mapX, mapY, 4, 2, decoration); + break; + case DECORSHAPE_2x2: + ShowDecorationOnMap_(mapX, mapY, 2, 2, decoration); + break; + case DECORSHAPE_1x2: + ShowDecorationOnMap_(mapX, mapY, 1, 2, decoration); + break; + case DECORSHAPE_1x3: // unused + ShowDecorationOnMap_(mapX, mapY, 1, 3, decoration); + break; + case DECORSHAPE_2x4: + ShowDecorationOnMap_(mapX, mapY, 2, 4, decoration); + break; + case DECORSHAPE_3x3: + ShowDecorationOnMap_(mapX, mapY, 3, 3, decoration); + break; + case DECORSHAPE_3x2: + ShowDecorationOnMap_(mapX, mapY, 3, 2, decoration); + break; } } @@ -1240,21 +1239,21 @@ void sub_8127E18(void) u8 i; u8 j; - for (i = 0; i < 14; i ++) + for (i = 0; i < 14; i++) { if (FlagGet(FLAG_DECORATION_1 + i) == TRUE) { FlagClear(FLAG_DECORATION_1 + i); - for (j = 0; j < gMapHeader.events->eventObjectCount; j ++) + for (j = 0; j < gMapHeader.events->eventObjectCount; j++) { if (gMapHeader.events->eventObjects[j].flagId == FLAG_DECORATION_1 + i) - { break; - } } + VarSet( VAR_OBJ_GFX_ID_0 + (gMapHeader.events->eventObjects[j].graphicsId - EVENT_OBJ_GFX_VAR_0), sPlaceDecorationGraphicsDataBuffer.decoration->tiles[0]); + gSpecialVar_0x8005 = gMapHeader.events->eventObjects[j].localId; gSpecialVar_0x8006 = sCurDecorMapX; gSpecialVar_0x8007 = sCurDecorMapY; @@ -1270,9 +1269,9 @@ bool8 sub_8127F38(void) { u16 i; - for (i = 0; i < gUnknown_0203A17C.size; i ++) + for (i = 0; i < gDecorationContext.size; i++) { - if (gUnknown_0203A17C.items[i] == DECOR_NONE) + if (gDecorationContext.items[i] == DECOR_NONE) { return TRUE; } @@ -1282,7 +1281,7 @@ bool8 sub_8127F38(void) void sub_8127F68(u8 taskId) { - if (gUnknown_0203A17C.isPlayerRoom == TRUE && sCurDecorationCategory != DECORCAT_DOLL && sCurDecorationCategory != DECORCAT_CUSHION) + if (gDecorationContext.isPlayerRoom == TRUE && sCurDecorationCategory != DECORCAT_DOLL && sCurDecorationCategory != DECORCAT_CUSHION) { StringExpandPlaceholders(gStringVar4, gText_CantPlaceInRoom); DisplayItemMessageOnField(taskId, gStringVar4, sub_8127A5C); @@ -1297,8 +1296,8 @@ void sub_8127F68(u8 taskId) } else { - ConvertIntToDecimalStringN(gStringVar1, gUnknown_0203A17C.size, STR_CONV_MODE_RIGHT_ALIGN, 2); - if (gUnknown_0203A17C.isPlayerRoom == FALSE) { + ConvertIntToDecimalStringN(gStringVar1, gDecorationContext.size, STR_CONV_MODE_RIGHT_ALIGN, 2); + if (gDecorationContext.isPlayerRoom == FALSE) { StringExpandPlaceholders(gStringVar4, gText_NoMoreDecorations); } else @@ -1328,7 +1327,7 @@ void sub_8128060(u8 taskId) break; case 1: gPaletteFade.bufferTransferDisabled = TRUE; - ConfigureCameraObjectForPlacingDecoration(&sPlaceDecorationGraphicsDataBuffer, gCurDecorInventoryItems[gCurDecorationIndex]); + ConfigureCameraObjectForPlacingDecoration(&sPlaceDecorationGraphicsDataBuffer, gCurDecorationItems[gCurDecorationIndex]); sub_812826C(taskId); SetUpPlacingDecorationPlayerAvatar(taskId, &sPlaceDecorationGraphicsDataBuffer); pal_fill_black(); @@ -1351,27 +1350,23 @@ void ConfigureCameraObjectForPlacingDecoration(struct PlaceDecorationGraphicsDat gFieldCamera.spriteId = gpu_pal_decompress_alloc_tag_and_upload(data, decor); gSprites[gFieldCamera.spriteId].oam.priority = 1; gSprites[gFieldCamera.spriteId].callback = sub_81292D0; - gSprites[gFieldCamera.spriteId].pos1.x = gUnknown_085A7250[data->decoration->shape].x; - gSprites[gFieldCamera.spriteId].pos1.y = gUnknown_085A7250[data->decoration->shape].y; + gSprites[gFieldCamera.spriteId].pos1.x = sDecorationMovementInfo[data->decoration->shape].cameraX; + gSprites[gFieldCamera.spriteId].pos1.y = sDecorationMovementInfo[data->decoration->shape].cameraY; } void SetUpPlacingDecorationPlayerAvatar(u8 taskId, struct PlaceDecorationGraphicsDataBuffer *data) { - u8 v0; + u8 x; - v0 = 16 * (u8)gTasks[taskId].data[5] + gUnknown_085A7250[data->decoration->shape].x - 8 * ((u8)gTasks[taskId].data[5] - 1); + x = 16 * (u8)gTasks[taskId].data[5] + sDecorationMovementInfo[data->decoration->shape].cameraX - 8 * ((u8)gTasks[taskId].data[5] - 1); if (data->decoration->shape == DECORSHAPE_3x1 || data->decoration->shape == DECORSHAPE_3x3 || data->decoration->shape == DECORSHAPE_3x2) - { - v0 -= 8; - } + x -= 8; + if (gSaveBlock2Ptr->playerGender == MALE) - { - sDecor_CameraSpriteObjectIdx2 = AddPseudoEventObject(0xC1, SpriteCallbackDummy, v0, 0x48, 0); - } + sDecor_CameraSpriteObjectIdx2 = AddPseudoEventObject(EVENT_OBJ_GFX_BRENDAN_DECORATING, SpriteCallbackDummy, x, 72, 0); else - { - sDecor_CameraSpriteObjectIdx2 = AddPseudoEventObject(0xC2, SpriteCallbackDummy, v0, 0x48, 0); - } + sDecor_CameraSpriteObjectIdx2 = AddPseudoEventObject(EVENT_OBJ_GFX_MAY_DECORATING, SpriteCallbackDummy, x, 72, 0); + gSprites[sDecor_CameraSpriteObjectIdx2].oam.priority = 1; DestroySprite(&gSprites[sDecor_CameraSpriteObjectIdx1]); sDecor_CameraSpriteObjectIdx1 = gFieldCamera.spriteId; @@ -1379,7 +1374,7 @@ void SetUpPlacingDecorationPlayerAvatar(u8 taskId, struct PlaceDecorationGraphic void sub_812826C(u8 taskId) { - switch (gDecorations[gCurDecorInventoryItems[gCurDecorationIndex]].shape) + switch (gDecorations[gCurDecorationItems[gCurDecorationIndex]].shape) { case DECORSHAPE_1x1: gTasks[taskId].data[5] = 1; @@ -1467,14 +1462,12 @@ bool8 sub_81284F4(u16 behaviorAt, const struct Decoration *decoration) if (MetatileBehavior_IsBlockDecoration(behaviorAt) != TRUE) { if (decoration->id == DECOR_SOLID_BOARD && MetatileBehavior_IsSecretBaseHole(behaviorAt) == TRUE) - { return TRUE; - } + if (MetatileBehavior_IsNormal(behaviorAt)) - { return TRUE; - } } + return FALSE; } @@ -1493,127 +1486,108 @@ bool8 sub_812853C(u8 taskId, const struct Decoration *decoration) switch (decoration->permission) { - case DECORPERM_SOLID_FLOOR: - case DECORPERM_PASS_FLOOR: - for (i=0; itiles[(mapY - 1 - i) * mapX + j]) & METATILE_ELEVATION_MASK; - if (!sub_81284F4(behaviorAt, decoration)) - { - return FALSE; - } - if (!sub_81284AC(taskId, curX, curY, behaviorBy)) - { - return FALSE; - } - behaviorAt = GetEventObjectIdByXYZ(curX, curY, 0); - if (behaviorAt != 0 && behaviorAt != 16) - { - return FALSE; - } - } - } - break; - case DECORPERM_BEHIND_FLOOR: - for (i=0; itiles[(mapY - 1 - i) * mapX + j]) & METATILE_ELEVATION_MASK; - if (!MetatileBehavior_IsNormal(behaviorAt) && !sub_8128484(behaviorAt, behaviorBy)) - { - return FALSE; - } - if (!sub_81284AC(taskId, curX, curY, behaviorBy)) - { - return FALSE; - } - if (GetEventObjectIdByXYZ(curX, curY, 0) != 16) - { - return FALSE; - } - } - } - curY = gTasks[taskId].data[1] - mapY + 1; - for (j=0; jtiles[j]) & METATILE_ELEVATION_MASK; - if (!MetatileBehavior_IsNormal(behaviorAt) && !MetatileBehavior_IsSecretBaseNorthWall(behaviorAt)) - { + behaviorBy = GetBehaviorByMetatileId(0x200 + decoration->tiles[(mapY - 1 - i) * mapX + j]) & METATILE_ELEVATION_MASK; + if (!sub_81284F4(behaviorAt, decoration)) return FALSE; - } + if (!sub_81284AC(taskId, curX, curY, behaviorBy)) - { return FALSE; - } + behaviorAt = GetEventObjectIdByXYZ(curX, curY, 0); if (behaviorAt != 0 && behaviorAt != 16) - { return FALSE; - } } - break; - case DECORPERM_NA_WALL: - for (i=0; ishape == DECORSHAPE_1x2) - { - if (!MetatileBehavior_HoldsLargeDecoration(behaviorAt)) - { - return FALSE; - } - } - else if (!MetatileBehavior_HoldsSmallDecoration(behaviorAt)) - { - if (!MetatileBehavior_HoldsLargeDecoration(behaviorAt)) - { - return FALSE; - } - } - if (GetEventObjectIdByXYZ(curX, curY, 0) != 16) - { + behaviorBy = GetBehaviorByMetatileId(0x200 + decoration->tiles[(mapY - 1 - i) * mapX + j]) & METATILE_ELEVATION_MASK; + if (!MetatileBehavior_IsNormal(behaviorAt) && !sub_8128484(behaviorAt, behaviorBy)) + return FALSE; + + if (!sub_81284AC(taskId, curX, curY, behaviorBy)) + return FALSE; + + if (GetEventObjectIdByXYZ(curX, curY, 0) != 16) return FALSE; - } } - break; + } + + curY = gTasks[taskId].data[1] - mapY + 1; + for (j = 0; j < mapX; j++) + { + curX = gTasks[taskId].data[0] + j; + behaviorAt = MapGridGetMetatileBehaviorAt(curX, curY); + behaviorBy = GetBehaviorByMetatileId(0x200 + decoration->tiles[j]) & METATILE_ELEVATION_MASK; + if (!MetatileBehavior_IsNormal(behaviorAt) && !MetatileBehavior_IsSecretBaseNorthWall(behaviorAt)) + return FALSE; + + if (!sub_81284AC(taskId, curX, curY, behaviorBy)) + return FALSE; + + behaviorAt = GetEventObjectIdByXYZ(curX, curY, 0); + if (behaviorAt != 0 && behaviorAt != 16) + return FALSE; + } + break; + case DECORPERM_NA_WALL: + for (i = 0; i < mapY; i++) + { + curY = gTasks[taskId].data[1] - i; + for (j = 0; j < mapX; j++) + { + curX = gTasks[taskId].data[0] + j; + if (!MetatileBehavior_IsSecretBaseNorthWall(MapGridGetMetatileBehaviorAt(curX, curY))) + return FALSE; + + if (MapGridGetMetatileIdAt(curX, curY + 1) == 0x28c) + return FALSE; + } + } + break; + case DECORPERM_SPRITE: + curY = gTasks[taskId].data[1]; + for (j = 0; j < mapX; j++) + { + curX = gTasks[taskId].data[0] + j; + behaviorAt = MapGridGetMetatileBehaviorAt(curX, curY); + if (decoration->shape == DECORSHAPE_1x2) + { + if (!MetatileBehavior_HoldsLargeDecoration(behaviorAt)) + return FALSE; + } + else if (!MetatileBehavior_HoldsSmallDecoration(behaviorAt)) + { + if (!MetatileBehavior_HoldsLargeDecoration(behaviorAt)) + return FALSE; + } + + if (GetEventObjectIdByXYZ(curX, curY, 0) != 16) + return FALSE; + } + break; } return TRUE; } void sub_8128950(u8 taskId) { - if (sub_812853C(taskId, &gDecorations[gCurDecorInventoryItems[gCurDecorationIndex]]) == TRUE) + if (sub_812853C(taskId, &gDecorations[gCurDecorationItems[gCurDecorationIndex]]) == TRUE) { StringExpandPlaceholders(gStringVar4, gText_PlaceItHere); DisplayItemMessageOnField(taskId, gStringVar4, sub_81289D0); @@ -1636,9 +1610,9 @@ void sub_81289F0(u8 taskId) { ClearDialogWindowAndFrame(0, 0); sub_8128AAC(taskId); - if (gDecorations[gCurDecorInventoryItems[gCurDecorationIndex]].permission != DECORPERM_SPRITE) + if (gDecorations[gCurDecorationItems[gCurDecorationIndex]].permission != DECORPERM_SPRITE) { - ShowDecorationOnMap(gTasks[taskId].data[0], gTasks[taskId].data[1], gCurDecorInventoryItems[gCurDecorationIndex]); + ShowDecorationOnMap(gTasks[taskId].data[0], gTasks[taskId].data[1], gCurDecorationItems[gCurDecorationIndex]); } else { @@ -1646,11 +1620,11 @@ void sub_81289F0(u8 taskId) sCurDecorMapY = gTasks[taskId].data[1] - 7; ScriptContext1_SetupScript(EventScript_275D1F); } + gSprites[sDecor_CameraSpriteObjectIdx1].pos1.y += 2; if (gMapHeader.regionMapSectionId == MAPSEC_SECRET_BASE) - { TV_PutSecretBaseVisitOnTheAir(); - } + sub_8128BBC(taskId); } @@ -1658,18 +1632,19 @@ void sub_8128AAC(u8 taskId) { u16 i; - for (i = 0; i < gUnknown_0203A17C.size; i ++) + for (i = 0; i < gDecorationContext.size; i++) { - if (gUnknown_0203A17C.items[i] == DECOR_NONE) + if (gDecorationContext.items[i] == DECOR_NONE) { - gUnknown_0203A17C.items[i] = gCurDecorInventoryItems[gCurDecorationIndex]; - gUnknown_0203A17C.pos[i] = ((gTasks[taskId].data[0] - 7) << 4) + (gTasks[taskId].data[1] - 7); + gDecorationContext.items[i] = gCurDecorationItems[gCurDecorationIndex]; + gDecorationContext.pos[i] = ((gTasks[taskId].data[0] - 7) << 4) + (gTasks[taskId].data[1] - 7); break; } } - if (!gUnknown_0203A17C.isPlayerRoom) + + if (!gDecorationContext.isPlayerRoom) { - for (i = 0; i < 16; i ++) + for (i = 0; i < 16; i++) { if (sSecretBaseItemsIndicesBuffer[i] == 0) { @@ -1680,7 +1655,7 @@ void sub_8128AAC(u8 taskId) } else { - for (i = 0; i < 12; i ++) + for (i = 0; i < 12; i++) { if (sPlayerRoomItemsIndicesBuffer[i] == 0) { @@ -1714,49 +1689,45 @@ void c1_overworld_prev_quest(u8 taskId) { switch (gTasks[taskId].data[2]) { - case 0: - ScriptContext2_Enable(); - if (!gPaletteFade.active) - { - sub_8127B04(taskId); - gTasks[taskId].data[2] = 1; - } - break; - case 1: - sub_812A3C8(); - FreeSpritePaletteByTag(OVERWORLD_PLACE_DECOR_SELECTOR_PAL_TAG); - gFieldCallback = sub_8128CD4; - SetMainCallback2(CB2_ReturnToField); - DestroyTask(taskId); - break; + case 0: + ScriptContext2_Enable(); + if (!gPaletteFade.active) + { + sub_8127B04(taskId); + gTasks[taskId].data[2] = 1; + } + break; + case 1: + sub_812A3C8(); + FreeSpritePaletteByTag(PLACE_DECORATION_SELECTOR_TAG); + gFieldCallback = sub_8128CD4; + SetMainCallback2(CB2_ReturnToField); + DestroyTask(taskId); + break; } } void sub_8128C64(u8 taskId) { - s16 *data; - - data = gTasks[taskId].data; + s16 *data = gTasks[taskId].data; switch (data[2]) { - case 0: - HideSecretBaseDecorationSprites(); - data[2] ++; - break; - case 1: - ScriptContext1_SetupScript(EventScript_275D0C); - data[2] ++; - break; - case 2: - ScriptContext2_Enable(); - data[2] ++; - break; - case 3: - if (IsWeatherNotFadingIn() == TRUE) - { - gTasks[taskId].func = sub_812764C; - } - break; + case 0: + HideSecretBaseDecorationSprites(); + data[2]++; + break; + case 1: + ScriptContext1_SetupScript(EventScript_275D0C); + data[2]++; + break; + case 2: + ScriptContext2_Enable(); + data[2]++; + break; + case 3: + if (IsWeatherNotFadingIn() == TRUE) + gTasks[taskId].func = HandleDecorationItemsMenuInput; + break; } } @@ -1773,41 +1744,40 @@ void sub_8128CD4(void) bool8 sub_8128D10(u8 taskId) { - s16 *data; - - data = gTasks[taskId].data; + s16 *data = gTasks[taskId].data; if (sDecorationLastDirectionMoved == DIR_SOUTH && data[1] - data[6] - 6 < 0) { - data[1] ++; + data[1]++; return FALSE; } + if (sDecorationLastDirectionMoved == DIR_NORTH && data[1] - 7 >= gMapHeader.mapLayout->height) { - data[1] --; + data[1]--; return FALSE; } + if (sDecorationLastDirectionMoved == DIR_WEST && data[0] - 7 < 0) { - data[0] ++; + data[0]++; return FALSE; } + if (sDecorationLastDirectionMoved == DIR_EAST && data[0] + data[5] - 8 >= gMapHeader.mapLayout->width) { - data[0] --; + data[0]--; return FALSE; } + return TRUE; } bool8 sub_8128DB4(void) { - u16 heldKeys; - - heldKeys = gMain.heldKeys & 0x0F0; + u16 heldKeys = gMain.heldKeys & DPAD_ANY; if (heldKeys != DPAD_UP && heldKeys != DPAD_DOWN && heldKeys != DPAD_LEFT && heldKeys != DPAD_RIGHT) - { return FALSE; - } + return TRUE; } @@ -1820,68 +1790,69 @@ void sub_8128DE0(void) void sub_8128E18(u8 taskId) { - s16 *data; - - data = gTasks[taskId].data; + s16 *data = gTasks[taskId].data; if (!gSprites[sDecor_CameraSpriteObjectIdx1].data[4]) { if (data[10] == 1) { gUnknown_085A72D4[data[12]].yesFunc(taskId); return; - } else if (data[10] == 2) + } + else if (data[10] == 2) { gUnknown_085A72D4[data[12]].noFunc(taskId); return; } - if ((gMain.heldKeys & 0x0F0) == DPAD_UP) + + if ((gMain.heldKeys & DPAD_ANY) == DPAD_UP) { sDecorationLastDirectionMoved = DIR_SOUTH; gSprites[sDecor_CameraSpriteObjectIdx1].data[2] = 0; gSprites[sDecor_CameraSpriteObjectIdx1].data[3] = -2; data[1]--; } - if ((gMain.heldKeys & 0x0F0) == DPAD_DOWN) + + if ((gMain.heldKeys & DPAD_ANY) == DPAD_DOWN) { sDecorationLastDirectionMoved = DIR_NORTH; gSprites[sDecor_CameraSpriteObjectIdx1].data[2] = 0; gSprites[sDecor_CameraSpriteObjectIdx1].data[3] = 2; data[1]++; } - if ((gMain.heldKeys & 0x0F0) == DPAD_LEFT) + + if ((gMain.heldKeys & DPAD_ANY) == DPAD_LEFT) { sDecorationLastDirectionMoved = DIR_WEST; gSprites[sDecor_CameraSpriteObjectIdx1].data[2] = -2; gSprites[sDecor_CameraSpriteObjectIdx1].data[3] = 0; data[0]--; } - if ((gMain.heldKeys & 0x0F0) == DPAD_RIGHT) + + if ((gMain.heldKeys & DPAD_ANY) == DPAD_RIGHT) { sDecorationLastDirectionMoved = DIR_EAST; gSprites[sDecor_CameraSpriteObjectIdx1].data[2] = 2; gSprites[sDecor_CameraSpriteObjectIdx1].data[3] = 0; data[0]++; } + if (!sub_8128DB4() || !sub_8128D10(taskId)) - { sub_8128DE0(); - } } + if (sDecorationLastDirectionMoved) { gSprites[sDecor_CameraSpriteObjectIdx1].data[4]++; gSprites[sDecor_CameraSpriteObjectIdx1].data[4] &= 7; } + if (!data[10]) { if (gMain.newKeys & A_BUTTON) - { data[10] = A_BUTTON; - } + if (gMain.newKeys & B_BUTTON) - { data[10] = B_BUTTON; - } } } @@ -1896,9 +1867,7 @@ void sub_8128FD8(u8 taskId) void sub_8129020(u8 taskId) { if (gMain.newKeys & A_BUTTON || gMain.newKeys & B_BUTTON) - { sub_8128FD8(taskId); - } } void sub_8129048(struct PlaceDecorationGraphicsDataBuffer *data) @@ -1919,49 +1888,46 @@ void sub_8129088(u8 *dest, u16 tile) mode = tile >> 10; if (tile != 0) - { tile &= 0x03FF; - } + CpuFastCopy(&((u8 *)gTilesetPointer_SecretBase->tiles)[tile << 5], buffer, 32); switch (mode) { - case 0: - CpuFastCopy(buffer, dest, 32); - break; - case 1: - for (i = 0; i < 8; i ++) - { - dest[4 * i] = (buffer[4 * (i + 1) - 1] >> 4) + ((buffer[4 * (i + 1) - 1] & 0x0F) << 4); - dest[4 * i + 1] = (buffer[4 * (i + 1) - 2] >> 4) + ((buffer[4 * (i + 1) - 2] & 0x0F) << 4); - dest[4 * i + 2] = (buffer[4 * (i + 1) - 3] >> 4) + ((buffer[4 * (i + 1) - 3] & 0x0F) << 4); - dest[4 * i + 3] = (buffer[4 * (i + 1) - 4] >> 4) + ((buffer[4 * (i + 1) - 4] & 0x0F) << 4); - } - break; - case 2: - for (i = 0; i < 8; i ++) - { - dest[4 * i] = buffer[4 * (7 - i)]; - dest[4 * i + 1] = buffer[4 * (7 - i) + 1]; - dest[4 * i + 2] = buffer[4 * (7 - i) + 2]; - dest[4 * i + 3] = buffer[4 * (7 - i) + 3]; - } - break; - case 3: - for (i = 0; i < 32; i ++) - { - dest[i] = (buffer[31 - i] >> 4) + ((buffer[31 - i] & 0x0F) << 4); - } - break; + case 0: + CpuFastCopy(buffer, dest, 32); + break; + case 1: + for (i = 0; i < 8; i++) + { + dest[4 * i] = (buffer[4 * (i + 1) - 1] >> 4) + ((buffer[4 * (i + 1) - 1] & 0x0F) << 4); + dest[4 * i + 1] = (buffer[4 * (i + 1) - 2] >> 4) + ((buffer[4 * (i + 1) - 2] & 0x0F) << 4); + dest[4 * i + 2] = (buffer[4 * (i + 1) - 3] >> 4) + ((buffer[4 * (i + 1) - 3] & 0x0F) << 4); + dest[4 * i + 3] = (buffer[4 * (i + 1) - 4] >> 4) + ((buffer[4 * (i + 1) - 4] & 0x0F) << 4); + } + break; + case 2: + for (i = 0; i < 8; i++) + { + dest[4 * i] = buffer[4 * (7 - i)]; + dest[4 * i + 1] = buffer[4 * (7 - i) + 1]; + dest[4 * i + 2] = buffer[4 * (7 - i) + 2]; + dest[4 * i + 3] = buffer[4 * (7 - i) + 3]; + } + break; + case 3: + for (i = 0; i < 32; i++) + { + dest[i] = (buffer[31 - i] >> 4) + ((buffer[31 - i] & 0x0F) << 4); + } + break; } } void sub_81291A4(struct PlaceDecorationGraphicsDataBuffer *data) { u16 i; - for (i = 0; i < 64; i ++) - { + for (i = 0; i < 64; i++) sub_8129088(&data->image[i * 32], data->tiles[i]); - } } u16 sub_81291CC(u16 tile) @@ -1975,7 +1941,7 @@ void sub_81291E8(struct PlaceDecorationGraphicsDataBuffer *data) u8 shape; shape = data->decoration->shape; - for (i = 0; i < gUnknown_085A71B0[shape].size; i ++) + for (i = 0; i < gUnknown_085A71B0[shape].size; i++) { data->tiles[gUnknown_085A71B0[shape].tiles[i]] = sub_81291CC(data->decoration->tiles[gUnknown_085A71B0[shape].y[i]] * 8 + gUnknown_085A71B0[shape].x[i]); } @@ -1988,10 +1954,10 @@ void SetDecorSelectionBoxOamAttributes(u8 decorShape) sDecorSelectorOam.objMode = ST_OAM_OBJ_NORMAL; sDecorSelectorOam.mosaic = 0; sDecorSelectorOam.bpp = ST_OAM_4BPP; - sDecorSelectorOam.shape = gUnknown_085A7250[decorShape].shape; + sDecorSelectorOam.shape = sDecorationMovementInfo[decorShape].shape; sDecorSelectorOam.x = 0; sDecorSelectorOam.matrixNum = 0; - sDecorSelectorOam.size = gUnknown_085A7250[decorShape].size; + sDecorSelectorOam.size = sDecorationMovementInfo[decorShape].size; sDecorSelectorOam.tileNum = 0; sDecorSelectorOam.priority = 0; sDecorSelectorOam.paletteNum = 0; @@ -2013,14 +1979,11 @@ void sub_81292E8(struct Sprite *sprite) if (sprite->data[7] == 0) { if (sprite->data[6] < 15) - { - sprite->invisible = FALSE; - } + sprite->invisible = 0; else - { - sprite->invisible = TRUE; - } - sprite->data[6] ++; + sprite->invisible = 1; + + sprite->data[6]++; sprite->data[6] &= 0x1F; } else @@ -2034,16 +1997,15 @@ u8 gpu_pal_decompress_alloc_tag_and_upload(struct PlaceDecorationGraphicsDataBuf sub_8129048(data); data->decoration = &gDecorations[decor]; if (data->decoration->permission == DECORPERM_SPRITE) - { return AddPseudoEventObject(data->decoration->tiles[0], SpriteCallbackDummy, 0, 0, 1); - } - FreeSpritePaletteByTag(OVERWORLD_PLACE_DECOR_SELECTOR_PAL_TAG); + + FreeSpritePaletteByTag(PLACE_DECORATION_SELECTOR_TAG); sub_81291E8(data); SetDecorSelectionBoxOamAttributes(data->decoration->shape); sub_81291A4(data); sub_8129068(data->palette, ((u16 *)gTilesetPointer_SecretBaseRedCave->metatiles)[(data->decoration->tiles[0] * 8) + 7] >> 12); LoadSpritePalette(&gUnknown_085A72BC); - return CreateSprite(&sDecorSelectorSpriteTemplate, 0, 0, 0); + return CreateSprite(&sDecorationSelectorSpriteTemplate, 0, 0, 0); } u8 AddDecorationIconObjectFromIconTable(u16 tilesTag, u16 paletteTag, u8 decor) @@ -2054,9 +2016,8 @@ u8 AddDecorationIconObjectFromIconTable(u16 tilesTag, u16 paletteTag, u8 decor) u8 spriteId; if (!AllocItemIconTemporaryBuffers()) - { return MAX_SPRITES; - } + LZDecompressWram(GetDecorationIconPicOrPalette(decor, 0), gItemIconDecompressionBuffer); CopyItemIconPicTo4x4Buffer(gItemIconDecompressionBuffer, gItemIcon4x4Buffer); sheet.data = gItemIcon4x4Buffer; @@ -2078,10 +2039,9 @@ u8 AddDecorationIconObjectFromIconTable(u16 tilesTag, u16 paletteTag, u8 decor) const u32 *GetDecorationIconPicOrPalette(u16 decor, u8 mode) { - if (decor > 120) - { + if (decor > NUM_DECORATIONS) decor = DECOR_NONE; - } + return gUnknown_085A6BE8[decor][mode]; } @@ -2125,13 +2085,12 @@ u8 AddDecorationIconObject(u8 decor, s16 x, s16 y, u8 priority, u16 tilesTag, u1 { u8 spriteId; - if (decor > 120) + if (decor > NUM_DECORATIONS) { spriteId = AddDecorationIconObjectFromIconTable(tilesTag, paletteTag, DECOR_NONE); if (spriteId == MAX_SPRITES) - { return MAX_SPRITES; - } + gSprites[spriteId].pos2.x = x + 4; gSprites[spriteId].pos2.y = y + 4; } @@ -2139,37 +2098,32 @@ u8 AddDecorationIconObject(u8 decor, s16 x, s16 y, u8 priority, u16 tilesTag, u1 { spriteId = AddDecorationIconObjectFromEventObject(tilesTag, paletteTag, decor); if (spriteId == MAX_SPRITES) - { return MAX_SPRITES; - } + gSprites[spriteId].pos2.x = x; if (decor == DECOR_SILVER_SHIELD || decor == DECOR_GOLD_SHIELD) - { gSprites[spriteId].pos2.y = y - 4; - } else - { gSprites[spriteId].pos2.y = y; - } } else { spriteId = AddDecorationIconObjectFromIconTable(tilesTag, paletteTag, decor); if (spriteId == MAX_SPRITES) - { return MAX_SPRITES; - } + gSprites[spriteId].pos2.x = x + 4; gSprites[spriteId].pos2.y = y + 4; } + gSprites[spriteId].oam.priority = priority; return spriteId; } void sub_81296EC(u8 idx) { - gUnknown_0203A17C.items[idx] = 0; - gUnknown_0203A17C.pos[idx] = 0; + gDecorationContext.items[idx] = 0; + gDecorationContext.pos[idx] = 0; } void sub_8129708(void) @@ -2182,11 +2136,11 @@ void sub_8129708(void) { gSpecialVar_Result = 1; } - else if (gDecorations[gUnknown_0203A17C.items[sDecorRearrangementDataBuffer[gSpecialVar_0x8004].idx]].permission == DECORPERM_SPRITE) + else if (gDecorations[gDecorationContext.items[sDecorRearrangementDataBuffer[gSpecialVar_0x8004].idx]].permission == DECORPERM_SPRITE) { gSpecialVar_0x8005 = sDecorRearrangementDataBuffer[gSpecialVar_0x8004].flagId; sub_81296EC(sDecorRearrangementDataBuffer[gSpecialVar_0x8004].idx); - for (i = 0; i < gMapHeader.events->eventObjectCount; i ++) + for (i = 0; i < gMapHeader.events->eventObjectCount; i++) { if (gMapHeader.events->eventObjects[i].flagId == gSpecialVar_0x8005) { @@ -2201,7 +2155,7 @@ void sub_81297AC(void) { u8 i; - for (i = 0; i < gMapHeader.events->eventObjectCount; i ++) + for (i = 0; i < gMapHeader.events->eventObjectCount; i++) { if (gMapHeader.events->eventObjects[i].flagId == gSpecialVar_0x8004) { @@ -2220,20 +2174,21 @@ void sub_81297F8(void) int posY; u8 perm; - for (i = 0; i < sCurDecorSelectedInRearrangement; i ++) + for (i = 0; i < sCurDecorSelectedInRearrangement; i++) { - perm = gDecorations[gUnknown_0203A17C.items[sDecorRearrangementDataBuffer[i].idx]].permission; - posX = gUnknown_0203A17C.pos[sDecorRearrangementDataBuffer[i].idx] >> 4; - posY = gUnknown_0203A17C.pos[sDecorRearrangementDataBuffer[i].idx] & 0x0F; + perm = gDecorations[gDecorationContext.items[sDecorRearrangementDataBuffer[i].idx]].permission; + posX = gDecorationContext.pos[sDecorRearrangementDataBuffer[i].idx] >> 4; + posY = gDecorationContext.pos[sDecorRearrangementDataBuffer[i].idx] & 0x0F; if (perm != DECORPERM_SPRITE) { - for (y = 0; y < sDecorRearrangementDataBuffer[i].height; y ++) + for (y = 0; y < sDecorRearrangementDataBuffer[i].height; y++) { - for (x = 0; x < sDecorRearrangementDataBuffer[i].width; x ++) + for (x = 0; x < sDecorRearrangementDataBuffer[i].width; x++) { MapGridSetMetatileEntryAt(posX + 7 + x, posY + 7 - y, gMapHeader.mapLayout->map[posX + x + gMapHeader.mapLayout->width * (posY - y)] | 0x3000); } } + sub_81296EC(sDecorRearrangementDataBuffer[i].idx); } } @@ -2243,35 +2198,33 @@ void sub_81298EC(u8 taskId) { switch (gTasks[taskId].data[2]) { - case 0: - sub_81297F8(); - gTasks[taskId].data[2] = 1; - break; - case 1: - if (!gPaletteFade.active) { - DrawWholeMapView(); - ScriptContext1_SetupScript(EventScript_275D2E); - ClearDialogWindowAndFrame(0, 1); - gTasks[taskId].data[2] = 2; - } - break; - case 2: - ScriptContext2_Enable(); - IdentifyOwnedDecorationsCurrentlyInUseInternal(taskId); - pal_fill_black(); - gTasks[taskId].data[2] = 3; - break; - case 3: - if (IsWeatherNotFadingIn() == TRUE) - { - StringExpandPlaceholders(gStringVar4, gText_DecorationReturnedToPC); - DisplayItemMessageOnField(taskId, gStringVar4, sub_8129D64); - if (gMapHeader.regionMapSectionId == MAPSEC_SECRET_BASE) - { - TV_PutSecretBaseVisitOnTheAir(); - } - } - break; + case 0: + sub_81297F8(); + gTasks[taskId].data[2] = 1; + break; + case 1: + if (!gPaletteFade.active) { + DrawWholeMapView(); + ScriptContext1_SetupScript(EventScript_275D2E); + ClearDialogWindowAndFrame(0, 1); + gTasks[taskId].data[2] = 2; + } + break; + case 2: + ScriptContext2_Enable(); + IdentifyOwnedDecorationsCurrentlyInUseInternal(taskId); + pal_fill_black(); + gTasks[taskId].data[2] = 3; + break; + case 3: + if (IsWeatherNotFadingIn() == TRUE) + { + StringExpandPlaceholders(gStringVar4, gText_DecorationReturnedToPC); + DisplayItemMessageOnField(taskId, gStringVar4, sub_8129D64); + if (gMapHeader.regionMapSectionId == MAPSEC_SECRET_BASE) + TV_PutSecretBaseVisitOnTheAir(); + } + break; } } @@ -2279,14 +2232,12 @@ void sub_81298EC(u8 taskId) bool8 sub_81299AC(u8 taskId) { u16 i; - - for (i = 0; i < gUnknown_0203A17C.size; i ++) + for (i = 0; i < gDecorationContext.size; i++) { - if (gUnknown_0203A17C.items[i] != DECOR_NONE) - { + if (gDecorationContext.items[i] != DECOR_NONE) return TRUE; - } } + return FALSE; } @@ -2295,15 +2246,12 @@ void SetUpPuttingAwayDecorationPlayerAvatar(void) GetPlayerFacingDirection(); sDecor_CameraSpriteObjectIdx1 = gSprites[gFieldCamera.spriteId].data[0]; sub_812A39C(); - gFieldCamera.spriteId = CreateSprite(&gUnknown_085A7404, 0x78, 0x50, 0); + gFieldCamera.spriteId = CreateSprite(&gUnknown_085A7404, 120, 80, 0); if (gSaveBlock2Ptr->playerGender == MALE) - { - sDecor_CameraSpriteObjectIdx2 = AddPseudoEventObject(0xC1, SpriteCallbackDummy, 0x88, 0x48, 0); - } + sDecor_CameraSpriteObjectIdx2 = AddPseudoEventObject(EVENT_OBJ_GFX_BRENDAN_DECORATING, SpriteCallbackDummy, 136, 72, 0); else - { - sDecor_CameraSpriteObjectIdx2 = AddPseudoEventObject(0xC2, SpriteCallbackDummy, 0x88, 0x48, 0); - } + sDecor_CameraSpriteObjectIdx2 = AddPseudoEventObject(EVENT_OBJ_GFX_MAY_DECORATING, SpriteCallbackDummy, 136, 72, 0); + gSprites[sDecor_CameraSpriteObjectIdx2].oam.priority = 1; DestroySprite(&gSprites[sDecor_CameraSpriteObjectIdx1]); sDecor_CameraSpriteObjectIdx1 = gFieldCamera.spriteId; @@ -2317,27 +2265,27 @@ void sub_8129ABC(u8 taskId) data = gTasks[taskId].data; switch (data[2]) { - case 0: - if (!gPaletteFade.active) - { - sub_8127ACC(taskId); - data[2] = 1; - data[6] = 1; - data[5] = 1; - } - break; - case 1: - SetUpPuttingAwayDecorationPlayerAvatar(); - pal_fill_black(); - data[2] = 2; - break; - case 2: - if (IsWeatherNotFadingIn() == TRUE) - { - data[12] = 1; - sub_8129B34(taskId); - } - break; + case 0: + if (!gPaletteFade.active) + { + sub_8127ACC(taskId); + data[2] = 1; + data[6] = 1; + data[5] = 1; + } + break; + case 1: + SetUpPuttingAwayDecorationPlayerAvatar(); + pal_fill_black(); + data[2] = 2; + break; + case 2: + if (IsWeatherNotFadingIn() == TRUE) + { + data[12] = 1; + sub_8129B34(taskId); + } + break; } } @@ -2347,8 +2295,8 @@ void sub_8129B34(u8 taskId) gSprites[sDecor_CameraSpriteObjectIdx1].data[7] = 0; gSprites[sDecor_CameraSpriteObjectIdx1].invisible = FALSE; gSprites[sDecor_CameraSpriteObjectIdx1].callback = sub_812A36C; - gSprites[sDecor_CameraSpriteObjectIdx2].pos1.x = 0x88; - gSprites[sDecor_CameraSpriteObjectIdx2].pos1.y = 0x48; + gSprites[sDecor_CameraSpriteObjectIdx2].pos1.x = 136; + gSprites[sDecor_CameraSpriteObjectIdx2].pos1.y = 72; gTasks[taskId].data[10] = 0; gTasks[taskId].func = sub_8128E18; } @@ -2403,9 +2351,7 @@ void sub_8129C74(u8 taskId) void sub_8129D64(u8 taskId) { if (gMain.newKeys & A_BUTTON || gMain.newKeys & B_BUTTON) - { sub_8129B34(taskId); - } } void sub_8129D8C(u8 decor, struct DecorRearrangementDataBuffer *data) @@ -2414,39 +2360,48 @@ void sub_8129D8C(u8 decor, struct DecorRearrangementDataBuffer *data) { data->width = 1; data->height = 1; - } else if (gDecorations[decor].shape == DECORSHAPE_2x1) + } + else if (gDecorations[decor].shape == DECORSHAPE_2x1) { data->width = 2; data->height = 1; - } else if (gDecorations[decor].shape == DECORSHAPE_3x1) + } + else if (gDecorations[decor].shape == DECORSHAPE_3x1) { data->width = 3; data->height = 1; - } else if (gDecorations[decor].shape == DECORSHAPE_4x2) + } + else if (gDecorations[decor].shape == DECORSHAPE_4x2) { data->width = 4; data->height = 2; - } else if (gDecorations[decor].shape == DECORSHAPE_2x2) + } + else if (gDecorations[decor].shape == DECORSHAPE_2x2) { data->width = 2; data->height = 2; - } else if (gDecorations[decor].shape == DECORSHAPE_1x2) + } + else if (gDecorations[decor].shape == DECORSHAPE_1x2) { data->width = 1; data->height = 2; - } else if (gDecorations[decor].shape == DECORSHAPE_1x3) + } + else if (gDecorations[decor].shape == DECORSHAPE_1x3) { data->width = 1; data->height = 3; - } else if (gDecorations[decor].shape == DECORSHAPE_2x4) + } + else if (gDecorations[decor].shape == DECORSHAPE_2x4) { data->width = 2; data->height = 4; - } else if (gDecorations[decor].shape == DECORSHAPE_3x3) + } + else if (gDecorations[decor].shape == DECORSHAPE_3x3) { data->width = 3; data->height = 3; - } else if (gDecorations[decor].shape == DECORSHAPE_3x2) + } + else if (gDecorations[decor].shape == DECORSHAPE_3x2) { data->width = 3; data->height = 2; @@ -2457,8 +2412,8 @@ void sub_8129E0C(u8 x, u8 y) { gSprites[sDecor_CameraSpriteObjectIdx1].invisible = TRUE; gSprites[sDecor_CameraSpriteObjectIdx1].callback = SpriteCallbackDummy; - gSprites[sDecor_CameraSpriteObjectIdx2].pos1.x = (x << 4) + 0x88; - gSprites[sDecor_CameraSpriteObjectIdx2].pos1.y = (y << 4) + 0x48; + gSprites[sDecor_CameraSpriteObjectIdx2].pos1.x = (x << 4) + 136; + gSprites[sDecor_CameraSpriteObjectIdx2].pos1.y = (y << 4) + 72; } bool8 sub_8129E74(u8 taskId, u8 idx, struct DecorRearrangementDataBuffer *data) @@ -2471,18 +2426,18 @@ bool8 sub_8129E74(u8 taskId, u8 idx, struct DecorRearrangementDataBuffer *data) x = gTasks[taskId].data[0] - 7; y = gTasks[taskId].data[1] - 7; - xOff = gUnknown_0203A17C.pos[idx] >> 4; - yOff = gUnknown_0203A17C.pos[idx] & 0x0F; + xOff = gDecorationContext.pos[idx] >> 4; + yOff = gDecorationContext.pos[idx] & 0x0F; ht = data->height; - if (gUnknown_0203A17C.items[idx] == DECOR_SAND_ORNAMENT && MapGridGetMetatileIdAt(xOff + 7, yOff + 7) == 0x28C) - { - ht --; - } + if (gDecorationContext.items[idx] == DECOR_SAND_ORNAMENT && MapGridGetMetatileIdAt(xOff + 7, yOff + 7) == 0x28C) + ht--; + if (x >= xOff && x < xOff + data->width && y > yOff - ht && y <= yOff) { sub_8129E0C(data->width - (x - xOff + 1), yOff - y); return TRUE; } + return FALSE; } @@ -2492,9 +2447,9 @@ void sub_8129F20(void) u8 yOff; u16 i; - xOff = gUnknown_0203A17C.pos[sDecorRearrangementDataBuffer[sCurDecorSelectedInRearrangement].idx] >> 4; - yOff = gUnknown_0203A17C.pos[sDecorRearrangementDataBuffer[sCurDecorSelectedInRearrangement].idx] & 0x0F; - for (i = 0; i < 0x40; i ++) + xOff = gDecorationContext.pos[sDecorRearrangementDataBuffer[sCurDecorSelectedInRearrangement].idx] >> 4; + yOff = gDecorationContext.pos[sDecorRearrangementDataBuffer[sCurDecorSelectedInRearrangement].idx] & 0x0F; + for (i = 0; i < 0x40; i++) { if (gSaveBlock1Ptr->eventObjectTemplates[i].x == xOff && gSaveBlock1Ptr->eventObjectTemplates[i].y == yOff && !FlagGet(gSaveBlock1Ptr->eventObjectTemplates[i].flagId)) { @@ -2508,13 +2463,13 @@ bool8 sub_8129FC8(u8 taskId) { u16 i; - for (i = 0; i < gUnknown_0203A17C.size; i ++) + for (i = 0; i < gDecorationContext.size; i++) { - if (gUnknown_0203A17C.items[i] != 0) + if (gDecorationContext.items[i] != 0) { - if (gDecorations[gUnknown_0203A17C.items[i]].permission == DECORPERM_SPRITE) + if (gDecorations[gDecorationContext.items[i]].permission == DECORPERM_SPRITE) { - sub_8129D8C(gUnknown_0203A17C.items[i], sDecorRearrangementDataBuffer); + sub_8129D8C(gDecorationContext.items[i], sDecorRearrangementDataBuffer); if (sub_8129E74(taskId, i, sDecorRearrangementDataBuffer) == TRUE) { sDecorRearrangementDataBuffer->idx = i; @@ -2535,11 +2490,11 @@ void sub_812A040(u8 left, u8 top, u8 right, u8 bottom) u8 yOff; u8 decorIdx; - for (i = 0; i < gUnknown_0203A17C.size; i ++) + for (i = 0; i < gDecorationContext.size; i++) { - decorIdx = gUnknown_0203A17C.items[i]; - xOff = gUnknown_0203A17C.pos[i] >> 4; - yOff = gUnknown_0203A17C.pos[i] & 0x0F; + decorIdx = gDecorationContext.items[i]; + xOff = gDecorationContext.pos[i] >> 4; + yOff = gDecorationContext.pos[i] & 0x0F; if (decorIdx != 0 && gDecorations[decorIdx].permission == DECORPERM_SPRITE && left <= xOff && top <= yOff && right >= xOff && bottom >= yOff) { sDecorRearrangementDataBuffer[sCurDecorSelectedInRearrangement].idx = i; @@ -2560,9 +2515,9 @@ void sub_812A0E8(u8 taskId) sCurDecorSelectedInRearrangement = 0; if (sub_8129FC8(taskId) != TRUE) { - for (i = 0; i < gUnknown_0203A17C.size; i++) + for (i = 0; i < gDecorationContext.size; i++) { - var1 = gUnknown_0203A17C.items[i]; + var1 = gDecorationContext.items[i]; if (var1 != DECOR_NONE) { sub_8129D8C(var1, &sDecorRearrangementDataBuffer[0]); @@ -2576,8 +2531,8 @@ void sub_812A0E8(u8 taskId) } if (sCurDecorSelectedInRearrangement != 0) { - xOff = gUnknown_0203A17C.pos[sDecorRearrangementDataBuffer[0].idx] >> 4; - yOff = gUnknown_0203A17C.pos[sDecorRearrangementDataBuffer[0].idx] & 0x0F; + xOff = gDecorationContext.pos[sDecorRearrangementDataBuffer[0].idx] >> 4; + yOff = gDecorationContext.pos[sDecorRearrangementDataBuffer[0].idx] & 0x0F; var1 = yOff - sDecorRearrangementDataBuffer[0].height + 1; var2 = sDecorRearrangementDataBuffer[0].width + xOff - 1; @@ -2622,47 +2577,43 @@ void sub_812A25C(u8 taskId) { switch (gTasks[taskId].data[2]) { - case 0: - if (!gPaletteFade.active) - { - sub_8127B04(taskId); - gTasks[taskId].data[2] = 1; - } - break; - case 1: - sub_812A3C8(); - gFieldCallback = sub_812A334; - SetMainCallback2(CB2_ReturnToField); - DestroyTask(taskId); - break; + case 0: + if (!gPaletteFade.active) + { + sub_8127B04(taskId); + gTasks[taskId].data[2] = 1; + } + break; + case 1: + sub_812A3C8(); + gFieldCallback = sub_812A334; + SetMainCallback2(CB2_ReturnToField); + DestroyTask(taskId); + break; } } void sub_812A2C4(u8 taskId) { - s16 *data; - - data = gTasks[taskId].data; + s16 *data = gTasks[taskId].data; switch (data[2]) { - case 0: - HideSecretBaseDecorationSprites(); - data[2] ++; - break; - case 1: - ScriptContext1_SetupScript(EventScript_275D0C); - data[2] ++; - break; - case 2: - ScriptContext2_Enable(); - data[2] ++; - break; - case 3: - if (IsWeatherNotFadingIn() == TRUE) - { - gTasks[taskId].func = sub_8126B80; - } - break; + case 0: + HideSecretBaseDecorationSprites(); + data[2]++; + break; + case 1: + ScriptContext1_SetupScript(EventScript_275D0C); + data[2]++; + break; + case 2: + ScriptContext2_Enable(); + data[2]++; + break; + case 3: + if (IsWeatherNotFadingIn() == TRUE) + gTasks[taskId].func = HandleDecorationActionsMenuInput; + break; } } @@ -2672,47 +2623,39 @@ void sub_812A334(void) pal_fill_black(); DrawDialogueFrame(0, 1); - sub_8126ABC(); + InitDecorationActionsWindow(); taskId = CreateTask(sub_812A2C4, 8); gTasks[taskId].data[2] = 0; } void sub_812A36C(struct Sprite *sprite) { - sprite->data[0] ++; + sprite->data[0]++; sprite->data[0] &= 0x1F; if (sprite->data[0] > 15) - { sprite->invisible = TRUE; - } else - { sprite->invisible = FALSE; - } } void sub_812A39C(void) { if (gSaveBlock2Ptr->playerGender == MALE) - { LoadSpritePalette(&gUnknown_085A73D8); - } else - { LoadSpritePalette(&gUnknown_085A73E0); - } } void sub_812A3C8(void) { - FreeSpritePaletteByTag(OVERWORLD_PLACE_DECOR_PLAYER_PAL_TAG); + FreeSpritePaletteByTag(PLACE_DECORATION_PLAYER_TAG); } void sub_812A3D4(u8 taskId) { if (IsSelectedDecorInThePC() == TRUE) { - StringCopy(gStringVar1, gDecorations[gCurDecorInventoryItems[gCurDecorationIndex]].name); + StringCopy(gStringVar1, gDecorations[gCurDecorationItems[gCurDecorationIndex]].name); StringExpandPlaceholders(gStringVar4, gText_DecorationWillBeDiscarded); DisplayItemMessageOnField(taskId, gStringVar4, sub_812A458); } @@ -2731,9 +2674,9 @@ void sub_812A458(u8 taskId) void sub_812A478(u8 taskId) { - gCurDecorInventoryItems[gCurDecorationIndex] = DECOR_NONE; - sCurDecorCatCount = CountDecorationCategoryN(sCurDecorationCategory); - CondenseDecorationCategoryN(sCurDecorationCategory); + gCurDecorationItems[gCurDecorationIndex] = DECOR_NONE; + sNumOwnedDecorationsInCurCategory = GetNumOwnedDecorationsInCategory(sCurDecorationCategory); + CondenseDecorationsInCategory(sCurDecorationCategory); IdentifyOwnedDecorationsCurrentlyInUseInternal(taskId); StringExpandPlaceholders(gStringVar4, gText_DecorationThrownAway); DisplayItemMessageOnField(taskId, gStringVar4, sub_8127A5C); diff --git a/src/decoration_inventory.c b/src/decoration_inventory.c index 308320206..80646c69c 100644 --- a/src/decoration_inventory.c +++ b/src/decoration_inventory.c @@ -32,7 +32,7 @@ void SetDecorationInventoriesPointers(void) SET_DECOR_INV(5, gSaveBlock1Ptr->decorPoster); SET_DECOR_INV(6, gSaveBlock1Ptr->decorDoll); SET_DECOR_INV(7, gSaveBlock1Ptr->decorCushion); - sub_8126968(); + InitDecorationContextItems(); } static void ClearDecorationInventory(u8 idx) @@ -120,7 +120,7 @@ bool8 DecorationCheckSpace(u8 decor) s8 DecorationRemove(u8 decor) { u8 i; - u8 idx; + u8 category; i = 0; if (decor == DECOR_NONE) @@ -129,38 +129,38 @@ s8 DecorationRemove(u8 decor) } for (i = 0; i < gDecorationInventories[gDecorations[decor].category].size; i ++) { - idx = gDecorations[decor].category; - if (gDecorationInventories[idx].items[i] == decor) + category = gDecorations[decor].category; + if (gDecorationInventories[category].items[i] == decor) { - gDecorationInventories[idx].items[i] = DECOR_NONE; - CondenseDecorationCategoryN(idx); + gDecorationInventories[category].items[i] = DECOR_NONE; + CondenseDecorationsInCategory(category); return 1; } } return 0; } -void CondenseDecorationCategoryN(u8 idx) +void CondenseDecorationsInCategory(u8 category) { u8 i; u8 j; u8 tmp; - for (i = 0; i < gDecorationInventories[idx].size; i ++) + for (i = 0; i < gDecorationInventories[category].size; i ++) { - for (j = i + 1; j < gDecorationInventories[idx].size; j ++) + for (j = i + 1; j < gDecorationInventories[category].size; j ++) { - if (gDecorationInventories[idx].items[j] != DECOR_NONE && (gDecorationInventories[idx].items[i] == DECOR_NONE || gDecorationInventories[idx].items[i] > gDecorationInventories[idx].items[j])) + if (gDecorationInventories[category].items[j] != DECOR_NONE && (gDecorationInventories[category].items[i] == DECOR_NONE || gDecorationInventories[category].items[i] > gDecorationInventories[category].items[j])) { - tmp = gDecorationInventories[idx].items[i]; - gDecorationInventories[idx].items[i] = gDecorationInventories[idx].items[j]; - gDecorationInventories[idx].items[j] = tmp; + tmp = gDecorationInventories[category].items[i]; + gDecorationInventories[category].items[i] = gDecorationInventories[category].items[j]; + gDecorationInventories[category].items[j] = tmp; } } } } -u8 CountDecorationCategoryN(u8 idx) +u8 GetNumOwnedDecorationsInCategory(u8 idx) { u8 i; u8 ct; @@ -176,15 +176,14 @@ u8 CountDecorationCategoryN(u8 idx) return ct; } -u8 CountDecorations(void) +u8 GetNumOwnedDecorations(void) { - u8 idx; - u8 ct; + u8 category; + u8 count; - ct = 0; - for (idx = 0; idx < 8; idx ++) - { - ct += CountDecorationCategoryN(idx); - } - return ct; + count = 0; + for (category = 0; category < DECORCAT_COUNT; category++) + count += GetNumOwnedDecorationsInCategory(category); + + return count; } diff --git a/src/menu_helpers.c b/src/menu_helpers.c index b5745d812..801e2546b 100644 --- a/src/menu_helpers.c +++ b/src/menu_helpers.c @@ -344,17 +344,17 @@ void sub_812220C(struct ItemSlot *slots, u8 count, u8 *arg2, u8 *usedSlotsCount, *arg2 = (*usedSlotsCount); } -void sub_812225C(u16 *arg0, u16 *arg1, u8 arg2, u8 arg3) +void sub_812225C(u16 *scrollOffset, u16 *cursorPos, u8 maxShownItems, u8 numItems) { - if ((*arg0) != 0 && (*arg0) + arg2 > arg3) - (*arg0) = arg3 - arg2; + if (*scrollOffset != 0 && *scrollOffset + maxShownItems > numItems) + *scrollOffset = numItems - maxShownItems; - if ((*arg0) + (*arg1) >= arg3) + if (*scrollOffset + *cursorPos >= numItems) { - if (arg3 == 0) - (*arg1) = 0; + if (numItems == 0) + *cursorPos = 0; else - (*arg1) = arg3 - 1; + *cursorPos = numItems - 1; } } diff --git a/src/player_pc.c b/src/player_pc.c index 49b9cc5f5..08f24d379 100644 --- a/src/player_pc.c +++ b/src/player_pc.c @@ -412,9 +412,9 @@ static void PlayerPC_Mailbox(u8 taskId) } } -static void PlayerPC_Decoration(u8 var) +static void PlayerPC_Decoration(u8 taskId) { - sub_8126B2C(var); //DoPlayerPCDecoration(var); + DoPlayerRoomDecorationMenu(taskId); } static void PlayerPC_TurnOff(u8 taskId) diff --git a/src/secret_base.c b/src/secret_base.c index a311db37d..ac35a090a 100644 --- a/src/secret_base.c +++ b/src/secret_base.c @@ -854,7 +854,7 @@ void GetCurSecretBaseRegistrationValidity(void) { if (IsSecretBaseRegistered(VarGet(VAR_CURRENT_SECRET_BASE)) == TRUE) gSpecialVar_Result = 1; - else if (GetNumRegisteredSecretBases() > 9) + else if (GetNumRegisteredSecretBases() >= 10) gSpecialVar_Result = 2; else gSpecialVar_Result = 0; @@ -868,7 +868,7 @@ void ToggleCurSecretBaseRegistry(void) void ShowSecretBaseDecorationMenu(void) { - CreateTask(sub_8126AD8, 0); + CreateTask(DoSecretBaseDecorationMenu, 0); } void ShowSecretBaseRegistryMenu(void) diff --git a/src/trader.c b/src/trader.c index 97bc4626f..dcf1fa076 100644 --- a/src/trader.c +++ b/src/trader.c @@ -142,7 +142,7 @@ void ScrSpecial_DoesPlayerHaveNoDecorations(void) for (i = 0; i < 8; i++) { - if (CountDecorationCategoryN(i)) + if (GetNumOwnedDecorationsInCategory(i)) { gSpecialVar_Result = FALSE; return; @@ -157,21 +157,21 @@ void ScrSpecial_IsDecorationFull(void) if (gDecorations[gSpecialVar_0x8004].category != gDecorations[gSpecialVar_0x8006].category && GetFirstEmptyDecorSlot(gDecorations[gSpecialVar_0x8004].category) == -1) { - sub_8127250(gStringVar2, gDecorations[gSpecialVar_0x8004].category); + CopyDecorationCategoryName(gStringVar2, gDecorations[gSpecialVar_0x8004].category); gSpecialVar_Result = TRUE; } } void ScrSpecial_TraderMenuGiveDecoration(void) { - CreateTask(sub_8127208, 0); + CreateTask(ShowDecorationCategoriesWindow, 0); } void sub_8133DA0(u8 taskId) { if (IsSelectedDecorInThePC() == TRUE) { - gSpecialVar_0x8006 = gCurDecorInventoryItems[gCurDecorationIndex]; + gSpecialVar_0x8006 = gCurDecorationItems[gCurDecorationIndex]; StringCopy(gStringVar3, gDecorations[gSpecialVar_0x8004].name); StringCopy(gStringVar2, gDecorations[gSpecialVar_0x8006].name); } @@ -183,7 +183,7 @@ void sub_8133DA0(u8 taskId) EnableBothScriptContexts(); } -void sub_8133E1C(u8 taskId) +void ExitTraderMenu(u8 taskId) { gSpecialVar_0x8006 = 0; DestroyTask(taskId);