summaryrefslogtreecommitdiff
path: root/arm9/src/list_menu_items.c
diff options
context:
space:
mode:
authorPikalaxALT <pikalaxalt@gmail.com>2021-05-22 18:11:00 -0400
committerPikalaxALT <pikalaxalt@gmail.com>2021-05-22 18:11:00 -0400
commite14ce23516daf20a5fcd9ca6ca53f30d33c4ef24 (patch)
tree20788d979ea7a2a4135cb29bef0606182fc91f4c /arm9/src/list_menu_items.c
parentd5bd2337cf8970b1ce7f8a3d0e64aa092e705462 (diff)
Decompile list_menu_items
Diffstat (limited to 'arm9/src/list_menu_items.c')
-rw-r--r--arm9/src/list_menu_items.c93
1 files changed, 93 insertions, 0 deletions
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;
+ }
+}