Alchemy
Loading...
Searching...
No Matches

icons.c

Go to the documentation of this file.
1/// @file
2/// The stat arrows and the other icons the menus load into VRAM blocks.
3/// Part of menu.c, the menu object, compiled only through it.
4
5#include "../menu_internal.h"
6
7/// Loads each menu icon resource whose cache slot was acquired.
9 s32 firstSlot;
10 s32 secondSlot;
11 struct InventoryMenuState *activeState;
12
13 activeState = gMenuWork;
14 firstSlot = Resource_FindFreeEntry();
15 activeState->resourceSlots[0] = firstSlot;
16 if (firstSlot != -1) {
17 VramCache_Load(firstSlot, 0x80, gMenu_PairSpriteATiles);
18 }
19 secondSlot = Resource_FindFreeEntry();
20 activeState->resourceSlots[1] = secondSlot;
21 if (secondSlot != -1) {
22 VramCache_Load(secondSlot, 0x80, gMenu_PairSpriteBTiles);
23 }
24}
25
26/// Releases both cached icon resources used by the menu.
28 struct InventoryMenuState *state;
29
30 state = gMenuWork;
33}
34
35/// Decodes one icon into a temporary buffer and reloads its VRAM slot.
37 s32 decodedResource;
38 s32 selectedSlot;
39 s32 firstTile;
40 s32 allocationBits;
41
42 allocationBits = (s32)Runtime_AllocateBlock(0x11, 0x608);
43 selectedSlot = slot;
44 Ability_LoadGlyphFar(resourceId, 0, &selectedSlot, &decodedResource, 1);
45 firstTile = VramCache_Reload(slot, allocationBits + 0x400);
47 return firstTile;
48}
49
50/// Loads an icon into a free cache slot and creates its sprite when possible.
52 s32 resourceId) {
53 s32 slot;
54
56 if (slot != 0x60) {
57 UiIcon_LoadResourceIntoSlot(resourceId, slot);
58 RenderOutput_CreateFar(slot, ICON_SPRITE_16X16, window, x, y);
59 }
60#ifdef UBFIX
61 return 0;
62#endif
63}
64
65/// Creates a stat-change arrow from one of the two loaded resources.
67 s32 variant) {
68 struct RenderOutput *object;
69 u32 resource;
70 s32 selectedVariant = variant;
71 struct UiWindow *targetWindow = window;
72 s32 targetX = x;
73 struct InventoryMenuState *menu = gMenuWork;
74
75 if (selectedVariant == 0)
76 resource = (u16)menu->resourceSlots[0];
77 else
78 resource = (u16)menu->resourceSlots[1];
79 object = RenderOutput_CreateFar(resource, ICON_SPRITE_16X16, targetWindow,
80 targetX, y);
81 if (object == 0) {
82 /* FAKEMATCH(dead): a test whose two arms both return -1, which emits
83 * nothing but keeps variant and x live across the call; as a plain
84 * return -1, 10 of 37 instructions differ in tbs-en. */
85 if (variant || targetX)
86 return -1;
87 else
88 return -1;
89 }
90 object->kind = 0;
91 object->animStep = 0;
92 object->active = ICON_SHOWN;
93 return 1;
94}
95
96/// Creates an arrow with the vertical adjustment for its resource variant.
98 s32 variant) {
99 struct RenderOutput *object;
100 u32 resource;
101 s32 selectedVariant = variant;
102 struct UiWindow *targetWindow = window;
103 s32 targetX = x;
104 struct InventoryMenuState *menu = gMenuWork;
105
106 if (selectedVariant == 0) {
107 resource = (u16)menu->resourceSlots[0];
108 y -= 3;
109 } else {
110 resource = (u16)menu->resourceSlots[1];
111 y -= 4;
112 }
113 object = RenderOutput_CreateFar(resource, ICON_SPRITE_16X16, targetWindow,
114 targetX, y);
115 if (object == 0) {
116 /* FAKEMATCH(dead): a test whose two arms both return -1, which emits
117 * nothing but keeps variant and x live across the call; as a plain
118 * return -1, 13 of 41 instructions differ in tbs-en. */
119 if (selectedVariant || x)
120 return -1;
121 else
122 return -1;
123 }
124 object->kind = 0;
125 object->animStep = 0;
126 object->active = ICON_SHOWN;
127 return 1;
128}
void Ability_LoadGlyphFar(s32 action, s32 with_base, s32 *slot, s32 *tile, s32 reuse)
struct RenderOutput * RenderOutput_CreateFar(s32 slot, s32 flags, struct UiWindow *input, s32 offsetX, s32 offsetY)
void * gMenuWork
void * Runtime_AllocateBlock(s32 kind, s32 size)
As Runtime_AllocateHeapBlock, but tries EWRAM first, for blocks that need room more than speed: the b...
Definition heap.c:80
void Runtime_ReleaseHeapBlock(s32 slot)
s32 UiIcon_LoadResourceIntoSlot(s32 resourceId, s32 slot)
Decodes one icon into a temporary buffer and reloads its VRAM slot.
Definition icons.c:36
s32 UiIcon_DrawVariantWithTileOffset(struct UiWindow *window, s32 x, s32 y, s32 variant)
Creates an arrow with the vertical adjustment for its resource variant.
Definition icons.c:97
void Resource_LoadPairedBlocksIfAvailable(void)
Loads each menu icon resource whose cache slot was acquired.
Definition icons.c:8
void Menu_ResetTwoResourceEntries(void)
Releases both cached icon resources used by the menu.
Definition icons.c:27
s32 UiIcon_CreateWithLoadedResource(struct UiWindow *window, s32 x, s32 y, s32 resourceId)
Loads an icon into a free cache slot and creates its sprite when possible.
Definition icons.c:51
s32 UiIcon_CreateStatChangeArrow(struct UiWindow *window, s32 x, s32 y, s32 variant)
Creates a stat-change arrow from one of the two loaded resources.
Definition icons.c:66
u8 gMenu_PairSpriteATiles[]
u8 gMenu_PairSpriteBTiles[]
What every part of the menu object shares: its includes, and the macros and types more than one part ...
#define ICON_SHOWN
RenderOutput.active as the menu sets it: shown, or hidden but kept.
#define ICON_SPRITE_16X16
RenderOutput_CreateFar's sprite attributes for the menu's 16x16 icons.
The item menu's work, in the HEAP_SLOT_MENU work slot: its windows, the party figures,...
s16 resourceSlots[2]
VRAM cache slots of two arrow pictures.
A render output: a sprite in a window's output list (a character, an icon or a portrait),...
A window: a framed rectangle of the tilemap with its sprite outputs, its opening or closing animation...
Definition uiwindow.h:11
u16 x
tiles
Definition uiwindow.h:15
signed int s32
Definition types.h:14
unsigned int u32
Definition types.h:15
unsigned short u16
Definition types.h:13
s32 VramCache_Reload(s32 no, s32 src)
Copies src again into entry no's VRAM, keeping its size.
Definition vram_cache.c:238
s32 Resource_ResetEntry(u32 no)
Frees cache entry no: its blocks go back and the entry is marked free (offset 0xffff).
Definition vram_cache.c:106
s32 Resource_FindFreeEntry(void)
Returns the number of the first free cache entry, or VRAM_CACHE_ENTRY_COUNT when all are taken.
Definition vram_cache.c:211
s32 VramCache_Load(u32 no, u32 size, const void *src)
Gives cache entry no size bytes of sprite VRAM and copies src there.
Definition vram_cache.c:143