diff options
author | PikalaxALT <pikalaxalt@gmail.com> | 2021-05-22 18:11:00 -0400 |
---|---|---|
committer | PikalaxALT <pikalaxalt@gmail.com> | 2021-05-22 18:11:00 -0400 |
commit | e14ce23516daf20a5fcd9ca6ca53f30d33c4ef24 (patch) | |
tree | 20788d979ea7a2a4135cb29bef0606182fc91f4c /arm9/src | |
parent | d5bd2337cf8970b1ce7f8a3d0e64aa092e705462 (diff) |
Decompile list_menu_items
Diffstat (limited to 'arm9/src')
-rw-r--r-- | arm9/src/error_message_reset.c | 2 | ||||
-rw-r--r-- | arm9/src/list_menu.c | 22 | ||||
-rw-r--r-- | arm9/src/list_menu_items.c | 93 | ||||
-rw-r--r-- | arm9/src/scrcmd.c | 6 | ||||
-rw-r--r-- | arm9/src/text.c | 16 | ||||
-rw-r--r-- | arm9/src/text_02054590.c | 4 |
6 files changed, 118 insertions, 25 deletions
diff --git a/arm9/src/error_message_reset.c b/arm9/src/error_message_reset.c index 426ba876..80c7ada8 100644 --- a/arm9/src/error_message_reset.c +++ b/arm9/src/error_message_reset.c @@ -102,7 +102,7 @@ THUMB_FUNC void PrintErrorMessageAndReset() ReadMsgDataIntoString(msg_data, 3, str); - AddTextPrinterParameterized(&buf, 0, (const u16 *)str, 0, 0, 0, NULL); // wtf + AddTextPrinterParameterized(&buf, 0, str, 0, 0, 0, NULL); String_dtor(str); GX_BothDispOn(); diff --git a/arm9/src/list_menu.c b/arm9/src/list_menu.c index 5ae5a5b4..c54677a9 100644 --- a/arm9/src/list_menu.c +++ b/arm9/src/list_menu.c @@ -60,7 +60,7 @@ THUMB_FUNC s32 ListMenu_ProcessInput(struct ListMenu * list) list->unk_33 = 0; if (gMain.newKeys & REG_PAD_KEYINPUT_A_MASK) { - return list->template.items[list->cursorPos + list->itemsAbove].index; + return list->template.items[list->cursorPos + list->itemsAbove].value; } else if (gMain.newKeys & REG_PAD_KEYINPUT_B_MASK) { return LIST_CANCEL; @@ -192,7 +192,7 @@ THUMB_FUNC u8 ListMenuGetUnk33(struct ListMenu * list) THUMB_FUNC s32 ListMenuGetValueByArrayId(struct ListMenu * list, s32 index) { - return list->template.items[index].index; + return list->template.items[index].value; } THUMB_FUNC s32 ListMenuGetTemplateField(struct ListMenu * list, u32 attr) @@ -314,7 +314,7 @@ THUMB_FUNC void ListMenuGetItemStr(struct ListMenu * list, struct ListMenuItem * list->template.items = items; } -THUMB_FUNC void ListMenuPrint(struct ListMenu * list, const u16 * str, u8 x, u8 y) +THUMB_FUNC void ListMenuPrint(struct ListMenu * list, struct String * str, u8 x, u8 y) { if (str != NULL) { @@ -337,13 +337,13 @@ THUMB_FUNC void ListMenuPrintEntries(struct ListMenu * list, u16 startIndex, u16 for (i = 0; i < count; i++) { - if (list->template.items[startIndex].index != LIST_HEADER) + if (list->template.items[startIndex].value != LIST_HEADER) x = list->template.item_X; else x = list->template.header_X; y = (yOffset + i) * yMultiplier + list->template.upText_Y; if (list->template.itemPrintFunc != NULL) - list->template.itemPrintFunc(list, list->template.items[startIndex].index, y); + list->template.itemPrintFunc(list, list->template.items[startIndex].value, y); ListMenuPrint(list, list->template.items[startIndex].text, x, y); startIndex++; } @@ -409,7 +409,7 @@ THUMB_FUNC u8 ListMenuUpdateSelectedRowIndexAndScrollOffset(struct ListMenu *lis while (itemsAbove != 0) { itemsAbove--; - if (list->template.items[cursorPos + itemsAbove].index != LIST_HEADER) + if (list->template.items[cursorPos + itemsAbove].value != LIST_HEADER) { list->itemsAbove = itemsAbove; return 1; @@ -422,7 +422,7 @@ THUMB_FUNC u8 ListMenuUpdateSelectedRowIndexAndScrollOffset(struct ListMenu *lis while (itemsAbove > newRow) { itemsAbove--; - if (list->template.items[cursorPos + itemsAbove].index != LIST_HEADER) + if (list->template.items[cursorPos + itemsAbove].value != LIST_HEADER) { list->itemsAbove = itemsAbove; return 1; @@ -444,7 +444,7 @@ THUMB_FUNC u8 ListMenuUpdateSelectedRowIndexAndScrollOffset(struct ListMenu *lis while (itemsAbove < list->template.maxShowed - 1) { itemsAbove++; - if (list->template.items[cursorPos + itemsAbove].index != LIST_HEADER) + if (list->template.items[cursorPos + itemsAbove].value != LIST_HEADER) { list->itemsAbove = itemsAbove; return 1; @@ -457,7 +457,7 @@ THUMB_FUNC u8 ListMenuUpdateSelectedRowIndexAndScrollOffset(struct ListMenu *lis while (itemsAbove < newRow) { itemsAbove++; - if (list->template.items[cursorPos + itemsAbove].index != LIST_HEADER) + if (list->template.items[cursorPos + itemsAbove].value != LIST_HEADER) { list->itemsAbove = itemsAbove; return 1; @@ -529,7 +529,7 @@ THUMB_FUNC BOOL ListMenuChangeSelection(struct ListMenu * list, u8 updateCursorA break; cursorCount++; } - while (list->template.items[list->cursorPos + list->itemsAbove].index == LIST_HEADER); + while (list->template.items[list->cursorPos + list->itemsAbove].value == LIST_HEADER); } if (updateCursorAndCallCallback) @@ -562,7 +562,7 @@ THUMB_FUNC void ListMenuCallSelectionChangedCallback(struct ListMenu * list, u8 { if (list->template.moveCursorFunc != NULL) { - list->template.moveCursorFunc(list, list->template.items[list->cursorPos + list->itemsAbove].index, onInit); + list->template.moveCursorFunc(list, list->template.items[list->cursorPos + list->itemsAbove].value, onInit); } } diff --git a/arm9/src/list_menu_items.c b/arm9/src/list_menu_items.c new file mode 100644 index 00000000..7e7b36d2 --- /dev/null +++ b/arm9/src/list_menu_items.c @@ -0,0 +1,93 @@ +#include "global.h" +#include "list_menu_items.h" +#include "msgdata.h" +#include "heap.h" + +void ListMenuItems_DestroyMenuStrings(struct ListMenuItem * items); +struct ListMenuItem * ListMenuItems_SeekEnd(struct ListMenuItem * items, s32 * idx_p); + +THUMB_FUNC struct ListMenuItem * ListMenuItems_ctor(u32 count, u32 heap_id) +{ + s32 i; + struct ListMenuItem * ret = AllocFromHeap(heap_id, (count + 1) * sizeof(struct ListMenuItem)); + if (ret != NULL) + { + for (i = 0; i < count; i++) + { + ret[i].text = NULL; + ret[i].value = 0; + } + ret[i].text = (struct String *)-1u; + ret[i].value = heap_id; + } + return ret; +} + +THUMB_FUNC void ListMenuItems_dtor(struct ListMenuItem * items) +{ + ListMenuItems_DestroyMenuStrings(items); + FreeToHeap(items); +} + +THUMB_FUNC void ListMenuItems_AppendFromMsgData(struct ListMenuItem * items, struct MsgData * msgData, u32 msgNo, s32 value) +{ + s32 heap_id; + struct ListMenuItem * newItem = ListMenuItems_SeekEnd(items, &heap_id); + if (newItem != NULL) + { + newItem->text = NewString_ReadMsgData(msgData, msgNo); + newItem->value = value; + } +} + +THUMB_FUNC void ListMenuItems_AddItem(struct ListMenuItem * items, struct String * str, s32 value) +{ + s32 heap_id; + struct ListMenuItem * newItem = ListMenuItems_SeekEnd(items, &heap_id); + if (newItem != NULL) + { + newItem->text = StringDup(str, heap_id); + newItem->value = value; + } +} + +THUMB_FUNC void ListMenuItems_CopyItem(struct ListMenuItem * items, struct ListMenuItem * src) +{ + s32 heap_id; + struct ListMenuItem * newItem = ListMenuItems_SeekEnd(items, &heap_id); + if (newItem != NULL) + { + newItem->text = src->text; + newItem->value = src->value; + } +} + +THUMB_FUNC struct ListMenuItem * ListMenuItems_SeekEnd(struct ListMenuItem * items, s32 * heap_id_p) +{ + struct ListMenuItem * ret; + for (; items->text != NULL; items++) + { + if (items->text == (struct String *)-1u) + { + GF_ASSERT(0); + return NULL; + } + } + ret = items; + for (; items->text != (struct String *)-1u; items++) + ; + *heap_id_p = items->value; + return ret; +} + +THUMB_FUNC void ListMenuItems_DestroyMenuStrings(struct ListMenuItem * items) +{ + s32 i; + for (i = 0; items[i].text != (struct String *)-1u; i++) + { + if (items[i].text == NULL) + break; + String_dtor(items[i].text); + items[i].text = NULL; + } +} diff --git a/arm9/src/scrcmd.c b/arm9/src/scrcmd.c index 00ccd34d..5503f5f3 100644 --- a/arm9/src/scrcmd.c +++ b/arm9/src/scrcmd.c @@ -34,9 +34,9 @@ extern u32 FUN_02058510(u32 param0, u32 param1); extern void MOD05_021E8128(u32 param0, u8 type, u16 map); extern void MOD05_021E8130(u32 param0, u32 param1); extern void MOD05_021E8158(struct UnkSavStruct80 *unk80); -extern u32 MOD05_021E8140(u32 param0); +extern struct Window * MOD05_021E8140(u32 param0); extern BOOL MOD05_021E8148(u32 param0); -extern u8 FUN_02054658(u32 param0, struct String *str, struct Options *opt, u32 param3); +extern u8 FUN_02054658(struct Window * param0, struct String *str, struct Options *opt, u32 param3); extern void MOD05_021E8144(u32 param0); extern void FUN_0200CB00(u32 param0, u32 param1, u32 param2, u32 param3, u32 param4, u32 param5); extern u32 Std_CreateYesNoMenu(u32 param0, u8 **param1, u32 param2, u32 param3, u32 param4); @@ -893,7 +893,7 @@ THUMB_FUNC BOOL ScrCmd_CreateMessageBox(struct ScriptContext* ctx) MOD05_021E8158(unk80); ReadMsgDataIntoString(ctx->msgData, msg, *unk1); StringExpandPlaceholders(*unk3, *unk2, *unk1); - AddTextPrinterParameterized(MOD05_021E8140(unk80->unk60), 1, (u16 *)*unk2, 0, 0, 0, NULL); + AddTextPrinterParameterized(MOD05_021E8140(unk80->unk60), 1, *unk2, 0, 0, 0, NULL); return TRUE; } diff --git a/arm9/src/text.c b/arm9/src/text.c index b21acf88..83d2612b 100644 --- a/arm9/src/text.c +++ b/arm9/src/text.c @@ -95,12 +95,12 @@ THUMB_FUNC void FUN_0201BD7C(u32 param0) FUN_0201BCFC(param0); } -THUMB_FUNC u16 AddTextPrinterParameterized(struct Window * window, u8 fontId, const u16 *str, u32 x, u32 y, u32 speed, u8 (*callback)(struct TextPrinterTemplate *, u16)) +THUMB_FUNC u16 AddTextPrinterParameterized(struct Window * window, u8 fontId, struct String *str, u32 x, u32 y, u32 speed, u8 (*callback)(struct TextPrinterTemplate *, u16)) { struct TextPrinterTemplate printerTemplate; printerTemplate.window = window; - printerTemplate.currentChar = str; + printerTemplate.currentChar.wrapped = str; printerTemplate.fontId = fontId; printerTemplate.x = (u8)x; printerTemplate.y = (u8)y; @@ -118,12 +118,12 @@ THUMB_FUNC u16 AddTextPrinterParameterized(struct Window * window, u8 fontId, co return AddTextPrinter(&printerTemplate, speed, callback); } -THUMB_FUNC u16 AddTextPrinterParameterized2(struct Window * window, u8 fontId, const u16 *str, u32 x, u32 y, u32 speed, u32 colors, u8 (*callback)(struct TextPrinterTemplate *, u16)) +THUMB_FUNC u16 AddTextPrinterParameterized2(struct Window * window, u8 fontId, struct String *str, u32 x, u32 y, u32 speed, u32 colors, u8 (*callback)(struct TextPrinterTemplate *, u16)) { struct TextPrinterTemplate printerTemplate; printerTemplate.window = window; - printerTemplate.currentChar = str; + printerTemplate.currentChar.wrapped = str; printerTemplate.fontId = fontId; printerTemplate.x = (u8)x; printerTemplate.y = (u8)y; @@ -141,12 +141,12 @@ THUMB_FUNC u16 AddTextPrinterParameterized2(struct Window * window, u8 fontId, c return AddTextPrinter(&printerTemplate, speed, callback); } -THUMB_FUNC u16 AddTextPrinterParameterized3(struct Window * window, u32 fontId, const u16 *str, u32 x, u32 y, u32 speed, u32 colors, u32 letterSpacing, u32 lineSpacing, u8 (*callback)(struct TextPrinterTemplate *, u16)) +THUMB_FUNC u16 AddTextPrinterParameterized3(struct Window * window, u32 fontId, struct String *str, u32 x, u32 y, u32 speed, u32 colors, u32 letterSpacing, u32 lineSpacing, u8 (*callback)(struct TextPrinterTemplate *, u16)) { struct TextPrinterTemplate printerTemplate; printerTemplate.window = window; - printerTemplate.currentChar = str; + printerTemplate.currentChar.wrapped = str; printerTemplate.fontId = (u8)fontId; printerTemplate.x = (u8)x; printerTemplate.y = (u8)y; @@ -184,13 +184,13 @@ THUMB_FUNC u16 AddTextPrinter(struct TextPrinterTemplate *printerTemplate, u32 s } printer->printerTemplate = *printerTemplate; - printer->printerTemplate.currentChar = String_c_str((struct String *)printer->printerTemplate.currentChar); //TODO clean up + printer->printerTemplate.currentChar.raw = String_c_str(printer->printerTemplate.currentChar.wrapped); printer->callback = callback; UNK_021C570C = 0; FUN_0201C1A8(printer); if (speed != 0xff && speed != 0) { - printer->textSpeedBottom += 0xff; + printer->textSpeedBottom--; printer->textSpeedTop = 1; printer->minLetterSpacing = FUN_0201BCC8(RunTextPrinter, printer, 1); return printer->minLetterSpacing; diff --git a/arm9/src/text_02054590.c b/arm9/src/text_02054590.c index e2765c6f..b7c4f91c 100644 --- a/arm9/src/text_02054590.c +++ b/arm9/src/text_02054590.c @@ -53,7 +53,7 @@ THUMB_FUNC void FUN_0205464C(struct Window *param0) FillWindowPixelBuffer(param0, 15); } -THUMB_FUNC u16 FUN_02054658(struct Window * window, const u16 *str, struct Options *options, u8 param3) +THUMB_FUNC u16 FUN_02054658(struct Window * window, struct String *str, struct Options *options, u8 param3) { FUN_02002B60(param3); FUN_02002B7C(0); @@ -61,7 +61,7 @@ THUMB_FUNC u16 FUN_02054658(struct Window * window, const u16 *str, struct Optio return AddTextPrinterParameterized(window, 1, str, 0, 0, (u32)Options_GetTextFrameDelay(options), NULL); } -THUMB_FUNC u16 DrawFieldMessage(struct Window * window, const u16 *str, u8 fontId, u32 speed, u8 a4, u32 a5) +THUMB_FUNC u16 DrawFieldMessage(struct Window * window, struct String *str, u8 fontId, u32 speed, u8 a4, u32 a5) { FUN_02002B60(a4); FUN_02002B7C(a5); |