13#define STATUS_PANEL_TEXT_X 32
14#define STATUS_PANEL_CANNOT_EQUIP_X 0
16#define STATUS_PANEL_TEXT_X 40
17#define STATUS_PANEL_CANNOT_EQUIP_X 16
22#if LANGUAGE == LANGUAGE_SPANISH
23#define STATUS_PANEL_LEARN_NAME_Y 56
24#define STATUS_PANEL_LEARN_STATUS_Y 48
26#define STATUS_PANEL_LEARN_NAME_Y 48
27#define STATUS_PANEL_LEARN_STATUS_Y 56
32#define WINDOW_KEEP_EXISTING 0x100
33#define WINDOW_STYLE_MASK 0xff
99 if (*handle !=
NULL) {
137 window =
state->statusWindow;
169 if (ailmentRows < 2) {
224 s32 psynergy =
def->actionId;
228 for (i = 0; i < 32; i++) {
253 s32 labels = MsgPanelStatLabel;
272#if LANGUAGE != LANGUAGE_JAPANESE
275#define NUMBER_PIXELS_PER_DIGIT 8
287 for (count = 1; count < 16; count++) {
338#if LANGUAGE != LANGUAGE_JAPANESE
347 if (value < unit->
maxHp >> 2) {
371 if (value < unit->
maxHp >> 2) {
399 if (after->
atk != before->
atk) {
401 if (after->
atk > before->
atk) {
409 if (after->
def != before->
def) {
411 if (after->
def > before->
def) {
419 if (after->
agi != before->
agi) {
421 if (after->
agi > before->
agi) {
430#define ICON_TILE_BYTES 0x80
466 if (
object !=
NULL) {
468 object->oam.x =
object->x;
469 object->oam.y =
object->y;
470 object->oam.matrix = 0;
471 object->oam.affineMode = 0;
512 s32 spacing,
s32 unused) {
521 for (i = 0; i < ownerCount; i++) {
533 tileX = originX + windowX;
588 for (i = 0; i < count; i++) {
597 position.
x = menu->
tabX[i] << 16;
607#define CURSOR_BOB_STEP() ((gFrameCount >> 1) & 7)
644 s32 biasedX = cursor->
oam.
x + 64;
645 s32 biasedY = cursor->
oam.
y + 64;
652 if (cursor->
x - 8 > 0)
659 startX = cursor->
x << 4;
660 stepX = ((
x << 4) - startX + 1) / steps;
662 stepY = ((
y << 4) - startY + 1) / steps;
668 cursor->
oam.
x = cursor->
x =
671 cursor->
oam.
y = cursor->
y =
676 }
while (steps != 0);
698 if (*scan++ !=
NULL) {
703 }
while (index < 32);
716 icon->
y = (
index / columns) * 16 + originY;
717 icon->
x = (
index % columns) * 16 + originX;
724 s32 originY,
s32 columns) {
730 icon->
y = slotIndex / columns * 16 + originY;
731 icon->
x = slotIndex % columns * 24 + originX;
760 }
while (index < 15);
841 for (i = 0; i < 15; i++)
842 items[i] = inventory[i];
845 for (i = 0; i < 15; i++) {
850 for (i = count; i < 15; i++)
859 for (i = 0; i < count; i++) {
876 sorted[sortedCount] = items[bestSlot];
883 for (i = 0; i < count; i++)
884 inventory[i] = sorted[i];
921#define PAGE_LABEL_FIRST 49
944 pages = count / pageSize;
945 if (count % pageSize != 0)
963 if (*cursor + *page * pageSize > count - 1) {
964 *cursor = count - *page * pageSize - 1;
965 if (*cursor > pageSize - 1)
966 *cursor = pageSize - 1;
974 if (++*page > pages - 1)
976 if (*cursor + *page * pageSize > count - 1) {
977 *cursor = count - *page * pageSize - 1;
978 if (*cursor > pageSize - 1)
979 *cursor = pageSize - 1;
988 *cursor = pageSize - 1;
989 *cursor = count - *page * pageSize - 1;
990 if (*cursor > pageSize - 1)
991 *cursor = pageSize - 1;
1001 if (++*cursor == count - *page * pageSize)
1003 if (*cursor > pageSize - 1)
1022 blue = palette[4] >> 10;
1023 green = (palette[4] >> 5) & 31;
1024 red = palette[4] & 31;
1034 palette[4] = (blue << 10) | (green << 5) | red;
1041 s32 pageSize,
s32 selectedPage,
s32 rightEdge) {
1049 pageCount = itemCount / pageSize;
1050 if (itemCount % pageSize != 0)
1054 if (pageCount > 1) {
1057 for (page = 0; page < pageCount; page++) {
1058 if (page == selectedPage)
1087 if (x + width > 29) {
1094 if (y + height > 29) {
1097 if (width > 0 && height > 0) {
1103 s32 remaining = width;
1104 while (remaining != 0) {
1106 value &= 0xFFFFEFFF;
1114 }
while (height != 0);
1137 for (i = 0; i < 32; i++) {
1147 icon->
y =
y + (i - first) * 16;
1165 if (window !=
NULL) {
1166 window->
width = width;
1218#undef STATUS_PANEL_TEXT_X
1219#undef STATUS_PANEL_CANNOT_EQUIP_X
1220#undef STATUS_PANEL_LEARN_NAME_Y
1221#undef STATUS_PANEL_LEARN_STATUS_Y
1222#undef WINDOW_KEEP_EXISTING
1223#undef WINDOW_STYLE_MASK
1224#undef NUMBER_PIXELS_PER_DIGIT
1225#undef ICON_TILE_BYTES
1226#undef CURSOR_BOB_STEP
1227#undef PAGE_LABEL_FIRST
void UiMenu_SlideCursor(s32 x, s32 y)
Slides the hand cursor from where it is to (x, y) inside the menu's top-left window over two frames,...
void PsynergyMenu_PositionOwnerEntry(struct RenderOutput **slot, s32 index, s32 originX, s32 originY, s32 columns)
Places the icon in *slot at grid cell index (0 above 31) of a grid of 16x16 cells,...
#define WINDOW_STYLE_MASK
void Menu_ReleaseEntryObjects(void)
Releases the party figures PsynergyMenu_InitializeEntryObjects created and stops their placement call...
struct UiWindow * UiMenu_CreateCursor(void *source)
Opens the menu's top-left window (13 by 5 tiles) and puts the hand cursor in it, hidden for now.
s32 InventoryMenu_SortByListOrder(u16 *inventory, s32 mode)
Sorts a party member's 15 inventory slots by the list order of mode (see Menu_CopyListOrder): items a...
#define PAGE_LABEL_FIRST
The page indicator: the window font's digit tiles for pages 1, 2, ..., between the two page arrows.
void UiText_DrawStatComparison(const struct BattleUnit *after, const struct BattleUnit *before, struct UiWindow *window)
Writes Attack, Defense and Agility into a status window as they are now (before), and beside each one...
#define WINDOW_KEEP_EXISTING
UiWindow_UpdateOrCreate: keep an existing window as it is, without redrawing its saved rectangle.
UNUSED void PsynergyMenu_ReservedNoOp(void)
Nothing calls it.
void UiIcon_PrepareObject(struct RenderOutput *object)
Shows a menu icon at its stored position, without rotation or scaling.
void UiText_DrawWorkValueWithLabel(struct UiWindow *window)
Writes the party's coins and the "Coins" label into window.
#define NUMBER_PIXELS_PER_DIGIT
The pixels the field allows each digit.
void Palette_LightenBankHighlight(s32 bank)
Copies the last background palette (15) into background palette bank and lightens its colour 4 by 9 s...
#define STATUS_PANEL_LEARN_NAME_Y
void PsynergyMenu_CallIconRoutineWithValue(const void *unused, s32 unit)
Loads the graphics of character unit into menu entry slot 0.
#define ICON_TILE_BYTES
Size of one 16x16 4bpp sprite tile block.
void UiPalette_SetColor2(void)
void Menu_UpdateEntryObjectTransforms(void)
Scheduler callback: each frame, places every party member sprite created by PsynergyMenu_InitializeEn...
void Render_SetTilemapFlagRect(const struct UiWindow *window, s32 x, s32 y, s32 width, s32 height, u32 palette)
Switches a rectangle of a window's text between palette 15 (normal) and 14 (the highlight made by Pal...
void PsynergyMenu_RefreshOwnerEntries(s32 originX, s32 originY, s32 columns)
Lays the menu's entry icons (up to 32) out in a grid of 16x16 cells, columns wide,...
s32 UiIcon_CreateWithResourceVariant(struct UiWindow *window, s32 x, s32 y)
Creates the menu's hand cursor sprite in window at (x, y), loading the hand's tiles into a free VRAM ...
#define STATUS_PANEL_TEXT_X
void ItemMenu_PlaceIcon(struct RenderOutput **slot, s32 slotIndex, s32 originX, s32 originY, s32 columns)
Places the icon at slotIndex (0 above 15) in a columns-wide grid of 24x16 cells starting at (originX,...
void Palette_CopyObjectBankToBackground14(void)
Copies the first sprite palette into background palette 14, then colour 4 of background palette 15 ov...
void UiWork_SetMenuBusy(void)
StatArrow
The stat arrows: the up and down arrow sprites the menu loads into its two resource slots (Resource_L...
void Menu_DrawPageIndicator(struct UiWindow *window, s32 itemCount, s32 pageSize, s32 selectedPage, s32 rightEdge)
Draws a paged list's page numbers on the top border of window, ending at tile rightEdge: one digit pe...
static s32 CountDigitsAtLeastTwo(s32 number)
Returns how many decimal digits number has, but at least 2: 0-99 give 2, 100-999 give 3,...
void UiMenu_PositionCursor(s32 xOffset, s32 yOffset)
Places the hand cursor at (xOffset, yOffset) inside the menu's top-left window, bobbing.
#define STATUS_PANEL_LEARN_STATUS_Y
void ItemMenu_RefreshEntry(s32 layout)
Lays the inventory's 15 item icons out five to a row from (116, y): y is 56 for layout 1 and 40 other...
static void Owner_Copy(struct BattleUnit *destination, struct BattleUnit *source)
Copies one BattleUnit with the resident IWRAM word copy.
UNUSED s32 UiIcon_CreateWithResource(struct UiWindow *window, s32 unused, s32 x, s32 y)
Creates a hand cursor sprite in window at (x, y), loading the hand's tiles into a free VRAM block.
#define STATUS_PANEL_CANNOT_EQUIP_X
void Menu_CancelSoundReset(void)
Starts watching for Start: clears FLAG_MENU_START_PRESSED and adds Menu_CancelSoundTick.
void UiWindow_SetBounds(struct UiWindow *window, s32 x, s32 y, s32 width, s32 height)
Moves and resizes a window, in tiles.
s32 Menu_SuspendFieldTasks(void)
Suspends the overlay tasks and tile animations while a menu is open, and sets flags 0x152 and 0x166.
void UiWindow_CloseIfOpen(struct UiWindow **handle, s32 style)
Closes the window kept in *handle, if any, and clears the handle.
void UiWindow_InitializeWork(s32 unused)
Clears the whole menu work and sets its defaults: no pane selected, one entry in each pane,...
void UiPalette_SetColor4(void)
#define CURSOR_BOB_STEP()
The cursor bobs through an 8-step table, one step every two frames.
void Menu_CopyListOrder(s32 mode, u8 *order)
Copies the list order of mode 0 to 2 (any other mode: the default order) into order,...
void UiWork_ClearMenuBusy(void)
Lets the window renderer resume drawing after a menu update.
void UiPalette_SetColor15(void)
Sets the window text colour: normal (15), no HP (2) and low HP (4).
void PsynergyMenu_InitializeEntryObjects(void *source, s32 originX, s32 originY, s32 spacing, s32 unused)
Creates a walking figure for each active party member, side by side under the window source: origin (...
void Menu_EnsureCancelSound(void)
Stops watching for Start, if Start has not removed the watch already.
s32 Menu_ResumeFieldTasks(void)
Resumes the overlay tasks and tile animations when a menu closes, and clears game flags 0x166 and 0x1...
void Menu_DrawOwnerStatusPanel(struct UiWindow *unused, s32 owner, s32 slot, s32 mode)
Draws the item menu's status panel for the party member owner (window at tile 0,5,...
void Ui_DrawValuePairRows(struct BattleUnit *unit, struct UiWindow *window)
Draws a character's HP and PP into window as two rows, "HP current/maximum" at pixel row 40 and "PP c...
void InventoryMenu_ShowModalMessage(s32 message, s32 x, s32 y)
Shows message in the item menu, with the hand cursor hidden meanwhile.
void Menu_CancelSoundTick(void)
Scheduler callback while a menu runs: on Start, plays the cancel sound, sets FLAG_MENU_START_PRESSED ...
s32 Menu_HandlePageInput(s32 horizontal, s32 count, s32 pageSize, s32 *cursor, s32 *page)
Moves a paged list's cursor and page with the d-pad's repeating keys.
UNUSED void PsynergyMenu_RefreshOwnerEntriesDefault(void)
Lays the entry icons out eight to a row from (108, 40). Nothing calls it.
void UiText_DrawNumberRightAligned(s32 number, struct UiWindow *window, s32 x, s32 y)
Draws number right-aligned in a field that ends at pixel column x and allows 8 pixels for each digit,...
s32 Audio_PlayCueReturnOne(s32 cue)
void Menu_SetPageIcons(s32 pageSize, s32 first, struct UiWindow *window, s32 x, s32 y)
Shows the item icons of one page of the item list: entries first to first + pageSize - 1,...
s32 UiWindow_UpdateOrCreate(struct UiWindow **handle, s32 x, s32 y, s32 w, s32 h, s32 flags)
Opens the window kept in *handle, or redraws it if it is already open.
static __inline__ void Dma_Set(const volatile void *source, volatile void *destination, u32 control, volatile u32 *channel)
Starts a DMA transfer: stores the source, destination and control words into channel's registers with...
#define Dma_Fill32(value, destination, size)
Fills size bytes at destination with the word value by DMA3.
void MapAnimation_SuspendFar(void)
s32 AnimationObjects_SelectAnimationFar(struct AnimationObject *state, s32 flags)
struct AnimationObject * ResourceObject_CreateFar(s32 id)
void MapAnimation_ResumeFar(void)
void Object_ApplyProjectedPlacementFar(struct AnimationObject *sprite, const struct SpritePlacement *position, const struct SpriteScale *scale, s32 facing)
Far call to Render_ApplyProjectedPlacement.
void ResourceObject_ReleaseFar(struct AnimationObject *sprite)
struct BattleUnit * UnitGetFar(u32 owner)
struct ItemDefinition * Item_GetDirectFar(s32 item)
s32 Party_ListActiveOwnersFar(s16 *owners)
s32 GameFlag_TestFar(s32 flag)
s32 GameFlag_SetBitFar(s32 flag)
s32 Inventory_EquipFar(s32 owner, s32 slot)
s32 Item_CanOwnerEquip(s32 unit, s32 item)
Far call to Item_CanOwnerEquipDirect.
s32 Party_CountActiveOwnersFar(void)
void GameFlag_ClearBitFar(s32 flag)
void UnitCalcFar(s32 owner)
s32 Party_RemapCharacterIdByFlagsFar(s32 arg0)
void AudioCommand_PlayFar(s32 id)
void Ui_LoadCharacterEntryForSlotFar(u32 slot, s32 character, s32 value)
struct UiWindow * UiWindow_CreateFar(s32 x, s32 y, s32 width, s32 height, s32 attrs)
void RenderOutput_ClearListFar(void *work)
void UiText_DrawNumberInWindowFar(s32 arg0, s32 arg1, struct UiWindow *arg2, s32 arg3, s32 arg4)
void UiWork_SetParamNibbleFar(s32 param)
s32 UiText_GetResourceDimensionsFar(s32 no, s32 *x, s32 *y, u32 *width, u32 *height)
void Link_DrawShiftedTilePairFar(s32 offset)
struct RenderOutput * SideObject_CreateFar(s32 object_kind, s32 position, s32 side, struct UiWindow *arg3, s32 arg4, s32 arg5)
Far call to CreateSideObject.
void UiText_DrawNumberAtOffsetFar(s32 arg0, s32 arg1, const struct UiWindow *arg2, s32 arg3, s32 arg4)
void UiWindow_ClearInteriorTilesFar(const struct UiWindow *window, u32 left, u32 top, u32 right, u32 bottom)
void UiWindow_DrawDividerLineFar(struct UiWindow *win, u32 x1, u32 y1, u32 x2, u32 y2)
void UiText_DrawCharacterAtOffsetFar(s32 character, const struct UiWindow *position, u32 offsetX, u32 offsetY)
struct RenderOutput * RenderOutput_CreateFar(s32 slot, s32 flags, struct UiWindow *input, s32 offsetX, s32 offsetY)
void UiText_DrawResourceFar(s32 arg0, struct UiWindow *arg1, s32 arg2, s32 arg3)
void UiWork_FinalizeFar(struct UiWindow *work, s32 release)
void UiText_DrawStringAtOffsetFar(const u8 *text, const struct UiWindow *work, s32 offsetX, s32 offsetY)
void UiWindow_SetTilemapEntryFar(struct UiWindow *window, s32 value, s32 x, s32 y, u32 mode)
void RenderOutput_RedrawSavedRectFar(struct UiWindow *window)
void UiText_DrawStringInWindowFar(const u8 *text, struct UiWindow *arg1, u32 x, u32 y)
void Input_ResetKeyRepeat(void)
Restarts the key repeat delay, so held keys wait the full delay again.
void WaitFrames(s32 frames)
The game's frame loop: runs frames frames and returns.
struct GameState gGameState
const u8 gUi_SlashString[]
const u8 gUi_PpRowString[]
u8 gUiIcon_ResourceTiles[]
const u8 gUi_HpRowString[]
void * MemAlloc(s32 size)
Allocates size bytes (rounded up to words) with no slot, from IWRAM when they fit and EWRAM otherwise...
#define BG_PLTT_COLOR(palette, color)
volatile u32 gKeysPressed
Keys that went down this frame.
volatile u32 gKeysRepeat
Pressed keys, repeating while held: after 19 frames, then every 6.
void MemFree(void *buffer)
s32 Scheduler_AddOrUpdateCallback(SchedulerCallback callback, s32 order)
Schedules callback with order, or gives a task already running it the new order, and re-sorts the tab...
s32 Scheduler_ResumeOverlayTasks(void)
Resumes every task whose routine is in an overlay, flagged or not.
s32 Scheduler_SuspendOverlayTasks(void)
Suspends every task whose routine is in an overlay (EWRAM, 0x02xxxxxx) unless its flag bit 0 asks to ...
s32 Scheduler_RemoveCallback(SchedulerCallback callback)
Unschedules the task running callback: clears its routine and gives it order 0x7fff,...
s32 _call_via_r3(s32, s32, s32, s32)
#define SE_MENU_CURSOR_MOVE
An animated sprite: its image and shadow, scale, rotation, size and up to four animation layers.
struct AnimationSpritePart image
u8 flags
bits: 1 outlined in ObjectSystemWork's edge and fill colours | 0 shadow drawn (set when created)
u8 count
layers in use, up to the last one present
s32 scale
16.16 fixed point, 0x10000 full size
u16 priority
2 when created
A unit in battle: a party member's or an enemy's stats, Psynergy, items, Djinn and ailments.
u8 luck
0 to 99 (UnitCalc)
s16 maxPp
0 to 1999 for a character, 9999 for an enemy (UnitCalc)
u8 name[0x0f]
The name, one byte a character, ending in 0.
s16 hp
current HP, 0 when downed
struct OwnerActionSlot actionSlots[32]
The action list: Psynergy taught for good, then the class's and the equipment's (Unit_RefreshPsynergy...
s16 maxHp
0 to 1999 for a character, 9999 for an enemy (UnitCalc)
u32 experience
a character's experience points
u8 classIndex
The character's class, worked out from its Djinn (Unit_UpdateClass); 0 marks an enemy,...
u16 atk
Attack, 0 to 999 (UnitCalc).
u8 level
1 to 99 for a character
u16 agi
Agility, 0 to 999: the order of the round's actions.
u16 def
Defense, 0 to 999 (UnitCalc).
u16 inventory[15]
Items held, one entry each: bits 15..11 quantity | 10 broken | 9 equipped | 8..0 item id (INVENTORY_*...
An item's definition: its price, type, who can equip it, its bonuses and unleash, its effects and the...
u8 type
enum ItemType; 0 for an item that is not equipment
u16 encodedAction
bits: 15 from the class | 14 from an equipped item | 13..0 action id.
A render output: a sprite in a window's output list (a character, an icon or a portrait),...
u8 sentinel
depth slot it is drawn at (254 for glyphs)
s8 active
its UI_SPRITE_ motion; 0 while free
s8 index
VRAM cache slot, or a glyph's tile after glyphTiles.
A sprite's screen position and its two vertical offsets, in 16.16 pixels.
s32 x
screen x of the sprite's centre
s32 y
screen y at the ground; sets the depth slot
s32 groundHeight
how far the shadow is raised above y
s32 height
how far the image is raised above y
Horizontal and vertical sprite scale; 0x10000 is the original size.
The window system's work: the windows' tilemap, the windows, the three text channels,...
u16 tilemap[640]
the windows' BG tilemap, 32 by 20 tiles
u8 dirty
The tilemap's 4-row bands to upload: bit 0 for all, bit n + 1 for band n.
u8 menuBusy
while set, the tilemap is not uploaded
A window: a framed rectangle of the tilemap with its sprite outputs, its opening or closing animation...
u16 flags
UI_WINDOW_ flags; 0 once closing or free.
u16 state
0 while a message channel is typing into the window; 1 once its text has ended or closed the window,...
#define UI_PAGE_ARROW_RIGHT
#define UI_PAGE_ARROW_LEFT
#define UI_PAGE_ARROW_VRAM
s32 Resource_FindFreeEntry(void)
Returns the number of the first free cache entry, or VRAM_CACHE_ENTRY_COUNT when all are taken.
s32 VramCache_Load(u32 no, u32 size, const void *src)
Gives cache entry no size bytes of sprite VRAM and copies src there.