From 4bce7af2bd196de403e213f7e9efd3709d015c94 Mon Sep 17 00:00:00 2001 From: PikalaxALT Date: Sat, 3 Aug 2024 21:00:46 -0400 Subject: [PATCH] documentation, 2 --- asm/include/launch_application.inc | 8 +- asm/include/overlay_73.inc | 2 +- asm/include/unk_0202C730.inc | 2 +- asm/macros/script.inc | 6 +- asm/overlay_73.s | 4 +- asm/unk_0202C730.s | 6 +- .../script/scr_seq/scr_seq_0819_T10R0101.s | 74 +- include/constants/game_stats.h | 17 +- include/constants/ranking.h | 35 + include/constants/save_arrays.h | 2 +- include/constants/scrcmd.h | 1 + include/launch_application.h | 2 +- include/overlay_121.h | 6 +- include/scrcmd.h | 2 +- include/unk_0202C730.h | 2 +- include/unk_0202E4B0.h | 26 +- include/unk_02097D3C.h | 13 +- src/data/fieldmap/script_cmd_table.h | 4 +- src/game_clear.c | 2 +- src/game_stats.c | 2 +- src/launch_application.c | 6 +- src/overlay_121.c | 885 +++++++++--------- src/save_arrays.c | 6 +- src/scrcmd_c.c | 8 +- src/unk_0202E4B0.c | 272 +++--- src/unk_02097D3C.c | 16 +- tools/py_scripts/scrcmd.json | 2 +- 27 files changed, 734 insertions(+), 677 deletions(-) create mode 100644 include/constants/ranking.h diff --git a/asm/include/launch_application.inc b/asm/include/launch_application.inc index d3ebe6d41..b85e79c6c 100644 --- a/asm/include/launch_application.inc +++ b/asm/include/launch_application.inc @@ -135,7 +135,7 @@ .public sub_0203FC68 .public sub_0203FC90 .public LegendaryCinematic_LaunchApp -.public sub_0203FD08 +.public LaunchApp_ViewFriendRecords .public Save_VarsFlags_Get .public Save_VarsFlags_CheckFlagInArray .public TaskManager_Call @@ -352,9 +352,9 @@ .public UnownReport_Init .public UnownReport_Main .public UnownReport_Exit -.public ov121_021E5900 -.public ov121_021E590C -.public ov121_021E59BC +.public ViewFriendRecordsApp_Init +.public ViewFriendRecordsApp_Main +.public ViewFriendRecordsApp_Exit .public VoltorbFlip_Init .public VoltorbFlip_Exit .public VoltorbFlip_Main diff --git a/asm/include/overlay_73.inc b/asm/include/overlay_73.inc index b598e9ac3..1b5e02c7e 100644 --- a/asm/include/overlay_73.inc +++ b/asm/include/overlay_73.inc @@ -163,7 +163,7 @@ .public sub_0202E474 .public sub_0202E530 .public sub_0202E58C -.public sub_0202E66C +.public Save_GetPlayerRankingEntry .public sub_0202E97C .public sub_0203189C .public sub_02033250 diff --git a/asm/include/unk_0202C730.inc b/asm/include/unk_0202C730.inc index 0f98a9b43..608a7dbd9 100644 --- a/asm/include/unk_0202C730.inc +++ b/asm/include/unk_0202C730.inc @@ -8,7 +8,7 @@ .public sub_0202C738 .public Save_FriendGroup_Init .public sub_0202C78C -.public sub_0202C7B4 +.public Save_FriendGroup_GetGroupId .public sub_0202C7C0 .public sub_0202C7DC .public sub_0202C7E0 diff --git a/asm/macros/script.inc b/asm/macros/script.inc index 108f34ec1..0bf74c5f1 100644 --- a/asm/macros/script.inc +++ b/asm/macros/script.inc @@ -2134,10 +2134,10 @@ .short \arg0 .endm - .macro scrcmd_378 arg0, arg1 + .macro view_rankings scope, page, record .short 378 - .short \arg0 - .short \arg1 + .short \scope * 3 + \page + .short \record .endm .macro scrcmd_379 arg0 diff --git a/asm/overlay_73.s b/asm/overlay_73.s index c5f764e55..3959b1e92 100644 --- a/asm/overlay_73.s +++ b/asm/overlay_73.s @@ -9476,10 +9476,10 @@ ov73_021EA2FC: ; 0x021EA2FC thumb_func_start ov73_021EA31C ov73_021EA31C: ; 0x021EA31C - ldr r3, _021EA320 ; =sub_0202E66C + ldr r3, _021EA320 ; =Save_GetPlayerRankingEntry bx r3 .balign 4, 0 -_021EA320: .word sub_0202E66C +_021EA320: .word Save_GetPlayerRankingEntry thumb_func_end ov73_021EA31C thumb_func_start ov73_021EA324 diff --git a/asm/unk_0202C730.s b/asm/unk_0202C730.s index abae9ffc2..438658572 100644 --- a/asm/unk_0202C730.s +++ b/asm/unk_0202C730.s @@ -93,15 +93,15 @@ _0202C7A8: .balign 4, 0 thumb_func_end sub_0202C78C - thumb_func_start sub_0202C7B4 -sub_0202C7B4: ; 0x0202C7B4 + thumb_func_start Save_FriendGroup_GetGroupId +Save_FriendGroup_GetGroupId: ; 0x0202C7B4 mov r2, #0x2c mul r2, r1 add r0, r0, r2 ldr r0, [r0, #0x24] bx lr .balign 4, 0 - thumb_func_end sub_0202C7B4 + thumb_func_end Save_FriendGroup_GetGroupId thumb_func_start sub_0202C7C0 sub_0202C7C0: ; 0x0202C7C0 diff --git a/files/fielddata/script/scr_seq/scr_seq_0819_T10R0101.s b/files/fielddata/script/scr_seq/scr_seq_0819_T10R0101.s index 9a1babb59..a5d9c917a 100644 --- a/files/fielddata/script/scr_seq/scr_seq_0819_T10R0101.s +++ b/files/fielddata/script/scr_seq/scr_seq_0819_T10R0101.s @@ -232,9 +232,9 @@ scr_seq_T10R0101_007: touchscreen_menu_hide _02CD: menu_init 1, 1, 0, 1, VAR_SPECIAL_RESULT - menu_item_add 8, 255, 0 - menu_item_add 9, 255, 1 - menu_item_add 10, 255, 2 + menu_item_add msg_0522_T10R0101_00008, 255, 0 + menu_item_add msg_0522_T10R0101_00009, 255, 1 + menu_item_add msg_0522_T10R0101_00010, 255, 2 menu_exec switch VAR_SPECIAL_RESULT case 0, _0317 @@ -247,9 +247,9 @@ _0317: goto_if_eq _037A npc_msg msg_0522_T10R0101_00011 menu_init 1, 1, 0, 1, VAR_SPECIAL_RESULT - menu_item_add 12, 255, 0 - menu_item_add 13, 255, 1 - menu_item_add 14, 255, 2 + menu_item_add msg_0522_T10R0101_00012, 255, 0 + menu_item_add msg_0522_T10R0101_00013, 255, 1 + menu_item_add msg_0522_T10R0101_00014, 255, 2 menu_exec switch VAR_SPECIAL_RESULT case 0, _037A @@ -264,16 +264,16 @@ _0371: _037A: npc_msg msg_0522_T10R0101_00015 menu_init 1, 1, 0, 1, VAR_SPECIAL_RESULT - menu_item_add 16, 255, 0 - menu_item_add 17, 255, 1 - menu_item_add 18, 255, 2 - menu_item_add 19, 255, 3 - menu_item_add 26, 255, 4 + menu_item_add msg_0522_T10R0101_00016, 255, 0 + menu_item_add msg_0522_T10R0101_00017, 255, 1 + menu_item_add msg_0522_T10R0101_00018, 255, 2 + menu_item_add msg_0522_T10R0101_00019, 255, 3 + menu_item_add msg_0522_T10R0101_00026, 255, 4 menu_exec compare VAR_SPECIAL_RESULT, 4 goto_if_eq _03CF closemsg - scrcmd_378 4, VAR_SPECIAL_RESULT + view_rankings RANKINGS_SCOPE_GROUP, RANKINGS_PAGE_POKEMON, VAR_SPECIAL_RESULT npc_msg msg_0522_T10R0101_00007 touchscreen_menu_hide goto _02CD @@ -293,18 +293,18 @@ _03EB: _03F1: npc_msg msg_0522_T10R0101_00015 menu_init 1, 1, 0, 1, VAR_SPECIAL_RESULT - menu_item_add 20, 255, 0 - menu_item_add 21, 255, 1 - menu_item_add 22, 255, 2 - menu_item_add 23, 255, 3 - menu_item_add 24, 255, 4 - menu_item_add 25, 255, 5 - menu_item_add 26, 255, 6 + menu_item_add msg_0522_T10R0101_00020, 255, 0 + menu_item_add msg_0522_T10R0101_00021, 255, 1 + menu_item_add msg_0522_T10R0101_00022, 255, 2 + menu_item_add msg_0522_T10R0101_00023, 255, 3 + menu_item_add msg_0522_T10R0101_00024, 255, 4 + menu_item_add msg_0522_T10R0101_00025, 255, 5 + menu_item_add msg_0522_T10R0101_00026, 255, 6 menu_exec compare VAR_SPECIAL_RESULT, 6 goto_if_eq _03CF closemsg - scrcmd_378 3, VAR_SPECIAL_RESULT + view_rankings RANKINGS_SCOPE_GROUP, RANKINGS_PAGE_BATTLE_TOWER, VAR_SPECIAL_RESULT npc_msg msg_0522_T10R0101_00007 touchscreen_menu_hide goto _02CD @@ -314,9 +314,9 @@ _0456: goto_if_eq _04B0 npc_msg msg_0522_T10R0101_00011 menu_init 1, 1, 0, 1, VAR_SPECIAL_RESULT - menu_item_add 12, 255, 0 - menu_item_add 13, 255, 1 - menu_item_add 14, 255, 2 + menu_item_add msg_0522_T10R0101_00012, 255, 0 + menu_item_add msg_0522_T10R0101_00013, 255, 1 + menu_item_add msg_0522_T10R0101_00014, 255, 2 menu_exec switch VAR_SPECIAL_RESULT case 0, _04B0 @@ -327,16 +327,16 @@ _0456: _04B0: npc_msg msg_0522_T10R0101_00015 menu_init 1, 1, 0, 1, VAR_SPECIAL_RESULT - menu_item_add 16, 255, 0 - menu_item_add 17, 255, 1 - menu_item_add 18, 255, 2 - menu_item_add 19, 255, 3 - menu_item_add 26, 255, 4 + menu_item_add msg_0522_T10R0101_00016, 255, 0 + menu_item_add msg_0522_T10R0101_00017, 255, 1 + menu_item_add msg_0522_T10R0101_00018, 255, 2 + menu_item_add msg_0522_T10R0101_00019, 255, 3 + menu_item_add msg_0522_T10R0101_00026, 255, 4 menu_exec compare VAR_SPECIAL_RESULT, 4 goto_if_eq _0505 closemsg - scrcmd_378 1, VAR_SPECIAL_RESULT + view_rankings RANKINGS_SCOPE_GLOBAL, RANKINGS_PAGE_POKEMON, VAR_SPECIAL_RESULT npc_msg msg_0522_T10R0101_00007 touchscreen_menu_hide goto _02CD @@ -356,18 +356,18 @@ _0521: _0527: npc_msg msg_0522_T10R0101_00015 menu_init 1, 1, 0, 1, VAR_SPECIAL_RESULT - menu_item_add 20, 255, 0 - menu_item_add 21, 255, 1 - menu_item_add 22, 255, 2 - menu_item_add 23, 255, 3 - menu_item_add 24, 255, 4 - menu_item_add 25, 255, 5 - menu_item_add 26, 255, 6 + menu_item_add msg_0522_T10R0101_00020, 255, 0 + menu_item_add msg_0522_T10R0101_00021, 255, 1 + menu_item_add msg_0522_T10R0101_00022, 255, 2 + menu_item_add msg_0522_T10R0101_00023, 255, 3 + menu_item_add msg_0522_T10R0101_00024, 255, 4 + menu_item_add msg_0522_T10R0101_00025, 255, 5 + menu_item_add msg_0522_T10R0101_00026, 255, 6 menu_exec compare VAR_SPECIAL_RESULT, 6 goto_if_eq _0505 closemsg - scrcmd_378 0, VAR_SPECIAL_RESULT + view_rankings RANKINGS_SCOPE_GLOBAL, RANKINGS_PAGE_BATTLE_TOWER, VAR_SPECIAL_RESULT npc_msg msg_0522_T10R0101_00007 touchscreen_menu_hide goto _02CD diff --git a/include/constants/game_stats.h b/include/constants/game_stats.h index 7c80d0edb..28f2e8dd9 100644 --- a/include/constants/game_stats.h +++ b/include/constants/game_stats.h @@ -8,9 +8,9 @@ #define GAME_STAT_UNK6 6 #define GAME_STAT_UNK8 8 //wild battles? #define GAME_STAT_UNK9 9 //trainer battles? -#define GAME_STAT_UNK10 10 -#define GAME_STAT_UNK11 11 -#define GAME_STAT_UNK12 12 +#define GAME_STAT_CAUGHT_MON 10 +#define GAME_STAT_FISHING_LANDED_MON 11 +#define GAME_STAT_HATCHED_EGG 12 #define GAME_STAT_UNK14 14 #define GAME_STAT_UNK16 16 #define GAME_STAT_UNK17 17 @@ -23,14 +23,15 @@ #define GAME_STAT_UNK46 46 #define GAME_STAT_BATTLE_POINTS 69 #define GAME_STAT_UNK70 70 +#define GAME_STAT_UNK74 74 #define GAME_STAT_UNK77 77 #define GAME_STAT_UNK79 79 #define GAME_STAT_UNK80 80 -#define GAME_STAT_UNK91 91 -#define GAME_STAT_UNK92 92 -#define GAME_STAT_UNK93 93 -#define GAME_STAT_UNK94 94 -#define GAME_STAT_UNK95 95 +#define GAME_STAT_LOCAL_CONTEST_ENTRIES 91 +#define GAME_STAT_COMM_CONTEST_ENTRIES 92 +#define GAME_STAT_LOCAL_CONTEST_WINS 93 +#define GAME_STAT_COMM_CONTEST_WINS 94 +#define GAME_STAT_RIBBONS_EARNED 95 #define GAME_STAT_UNK96 96 #define GAME_STAT_PLAYER_MON_FAINTED 97 #define GAME_STAT_UNK98 98 diff --git a/include/constants/ranking.h b/include/constants/ranking.h new file mode 100644 index 000000000..e58a99228 --- /dev/null +++ b/include/constants/ranking.h @@ -0,0 +1,35 @@ +#ifndef POKEHEARTGOLD_CONSTANTS_RANKING_H +#define POKEHEARTGOLD_CONSTANTS_RANKING_H + +#define RANKINGS_SCOPE_GLOBAL 0 +#define RANKINGS_SCOPE_GROUP 1 + +#define RANKINGS_PAGE_BATTLE_TOWER 0 +#define RANKINGS_PAGE_POKEMON 1 +#define RANKINGS_PAGE_CONTEST 2 + +#define RANKINGS_RECORD_BATTLE_TOWER_BEGIN 0 +#define RANKINGS_RECORD_BATTLE_TOWER_SINGLE_WINS 0 +#define RANKINGS_RECORD_BATTLE_TOWER_DOUBLE_WINS 1 +#define RANKINGS_RECORD_BATTLE_TOWER_MULTI_NPC_WINS 2 +#define RANKINGS_RECORD_BATTLE_TOWER_MULTI_COMM_WINS 3 +#define RANKINGS_RECORD_BATTLE_TOWER_WIFI_WINS 4 +#define RANKINGS_RECORD_BATTLE_TOWER_AVG_WIN_STREAK 5 +#define RANKINGS_RECORD_BATTLE_TOWER_COUNT 6 + +#define RANKINGS_RECORD_POKEMON_BEGIN 6 +#define RANKINGS_RECORD_POKEMON_MONS_DEFEATED 6 +#define RANKINGS_RECORD_POKEMON_MONS_CAUGHT 7 +#define RANKINGS_RECORD_POKEMON_MONS_HATCHED 8 +#define RANKINGS_RECORD_POKEMON_MONS_FISHED 9 +#define RANKINGS_RECORD_POKEMON_COUNT 4 + +#define RANKINGS_RECORD_CONTEST_BEGIN 10 +#define RANKINGS_RECORD_CONTEST_WIN 10 +#define RANKINGS_RECORD_CONTEST_ENTRY 11 +#define RANKINGS_RECORD_CONTEST_RIBBONS 12 +#define RANKINGS_RECORD_CONTEST_COUNT 3 + +#define RANKINGS_COUNT 13 + +#endif //POKEHEARTGOLD_CONSTANTS_RANKING_H diff --git a/include/constants/save_arrays.h b/include/constants/save_arrays.h index 23d724f67..27c2b3335 100644 --- a/include/constants/save_arrays.h +++ b/include/constants/save_arrays.h @@ -27,7 +27,7 @@ #define SAVE_ROAMER 21 #define SAVE_UNK_22 22 #define SAVE_UNK_23 23 -#define SAVE_UNK_24 24 +#define SAVE_RANKINGS 24 #define SAVE_UNK_25 25 #define SAVE_UNK_26 26 #define SAVE_MYSTERY_GIFT 27 diff --git a/include/constants/scrcmd.h b/include/constants/scrcmd.h index 2f5cda94c..a8a12b81d 100644 --- a/include/constants/scrcmd.h +++ b/include/constants/scrcmd.h @@ -21,6 +21,7 @@ #include "constants/badge.h" #include "constants/global.fieldmap.h" #include "constants/game_stats.h" +#include "constants/ranking.h" #define lt 0 #define eq 1 diff --git a/include/launch_application.h b/include/launch_application.h index b7e9982ee..500c4c445 100644 --- a/include/launch_application.h +++ b/include/launch_application.h @@ -146,7 +146,7 @@ void PokeathlonCourse_LaunchApp(FieldSystem *fieldSystem, PokeathlonCourseArgs * void sub_0203FC68(FieldSystem *fieldSystem, void *args); void sub_0203FC90(FieldSystem *fieldSystem, void *args); LegendaryCinematicArgs *LegendaryCinematic_LaunchApp(FieldSystem *fieldSystem, UnkStruct_0203FCC4 *a1, u16 a2, u16 a3, HeapID heapId); -void sub_0203FD08(FieldSystem *fieldSystem, UnkStruct_02097D56 *args); +void LaunchApp_ViewFriendRecords(FieldSystem *fieldSystem, ViewFriendRecordsArgs *args); PartyMenuArgs *PartyMenu_LaunchApp_Unk1(FieldSystem *fieldSystem, FieldMoveCheckData *fieldMoveCheckData, u8 partySlot); void CallTask_NamingScreen(TaskManager *taskManager, NameScreenType type, int species, int maxLen, int initPos, const u16 *defaultStr, u16 *retVar); void sub_0203E960(TaskManager *a0, int a1, UnkStruct_0203E8C8 *a2, u16 *a3, u16 *a4); diff --git a/include/overlay_121.h b/include/overlay_121.h index 6fe0d835a..579c147af 100644 --- a/include/overlay_121.h +++ b/include/overlay_121.h @@ -3,8 +3,8 @@ #include "overlay_manager.h" -BOOL ov121_021E5900(OVY_MANAGER *man, int *state); -BOOL ov121_021E590C(OVY_MANAGER *man, int *state); -BOOL ov121_021E59BC(OVY_MANAGER *man, int *state); +BOOL ViewFriendRecordsApp_Init(OVY_MANAGER *man, int *state); +BOOL ViewFriendRecordsApp_Main(OVY_MANAGER *man, int *state); +BOOL ViewFriendRecordsApp_Exit(OVY_MANAGER *man, int *state); #endif //POKEHEARTGOLD_OVY_121_H diff --git a/include/scrcmd.h b/include/scrcmd.h index b8aaf46bd..1e65bcc0c 100644 --- a/include/scrcmd.h +++ b/include/scrcmd.h @@ -412,7 +412,7 @@ BOOL ScrCmd_374(ScriptContext* ctx); BOOL ScrCmd_MakeObjectVisible(ScriptContext* ctx); BOOL ScrCmd_376(ScriptContext* ctx); BOOL ScrCmd_377(ScriptContext* ctx); -BOOL ScrCmd_378(ScriptContext* ctx); +BOOL ScrCmd_ViewFriendRecords(ScriptContext* ctx); BOOL ScrCmd_379(ScriptContext* ctx); BOOL ScrCmd_Random(ScriptContext* ctx); BOOL ScrCmd_381(ScriptContext* ctx); diff --git a/include/unk_0202C730.h b/include/unk_0202C730.h index 92c37a358..d15ce2626 100644 --- a/include/unk_0202C730.h +++ b/include/unk_0202C730.h @@ -10,7 +10,7 @@ BOOL sub_0202C878(SAV_FRIEND_GRP *group, u16 a1); void sub_0202C738(SAV_FRIEND_GRP *group, u16 a1, int a2); // return group->groups[a1].unk_24; -u8 sub_0202C7B4(SAV_FRIEND_GRP *group, int a1); +u8 Save_FriendGroup_GetGroupId(SAV_FRIEND_GRP *group, int a1); void sub_0202C7F8(SAV_FRIEND_GRP *group, int a1, int a2, String *str); void sub_0202C824(SAV_FRIEND_GRP *group, int a1, u32 gender); void sub_0202C848(SAV_FRIEND_GRP *group, int a1, int a2); diff --git a/include/unk_0202E4B0.h b/include/unk_0202E4B0.h index 25807530a..77b75a633 100644 --- a/include/unk_0202E4B0.h +++ b/include/unk_0202E4B0.h @@ -4,12 +4,12 @@ #include "pm_string.h" #include "save.h" -typedef struct UnkStruct_0202E4B0_sub UnkStruct_0202E4B0_sub; -typedef struct UnkStruct_0202E4B0 UnkStruct_0202E4B0; +typedef struct SaveRankingsEntry SaveRankingsEntry; +typedef struct SaveRankings SaveRankings; typedef struct UnkStruct_0202E9FC_sub { - int unk_0; - u32 unk_4; + int groupId; + u32 stat; String *playerName; } UnkStruct_0202E9FC_sub; @@ -18,17 +18,17 @@ typedef struct UnkStruct_0202E9FC { UnkStruct_0202E9FC_sub unk_04[6]; } UnkStruct_0202E9FC; -u8 sub_0202E4B0(int a0); -u8 sub_0202E4BC(int a0); -u32 sub_0202E4F4(void); // ???_sizeof -void sub_0202E4FC(UnkStruct_0202E4B0 *a0); // ???_Init -UnkStruct_0202E4B0 *sub_0202E530(SaveData *saveData); // ???_Get -void sub_0202E544(UnkStruct_0202E4B0 *a0, int a1, u8 a2); +u8 RankingsViewSys_GetNumRecordsPerPage(int a0); +u8 RankingsViewSys_GetFirstRecordIndexOnPage(int a0); +u32 Save_Rankings_sizeof(void); // ???_sizeof +void Save_Rankings_Init(SaveRankings *a0); // ???_Init +SaveRankings *sub_0202E530(SaveData *saveData); // ???_Get +void sub_0202E544(SaveRankings *a0, int a1, u8 a2); u32 sub_0202E58C(void); -UnkStruct_0202E4B0_sub *sub_0202E66C(SaveData *saveData, HeapID heapId); -void sub_0202E97C(SaveData *saveData, u8 a1, u8 a2, UnkStruct_0202E4B0_sub **a3, HeapID heapId); +SaveRankingsEntry *Save_GetPlayerRankingEntry(SaveData *saveData, HeapID heapId); +void sub_0202E97C(SaveData *saveData, u8 a1, u8 a2, SaveRankingsEntry **a3, HeapID heapId); UnkStruct_0202E9FC *sub_0202E9FC(SaveData *saveData, int a1, HeapID heapId); -UnkStruct_0202E9FC *sub_0202EA80(UnkStruct_0202E4B0 *a0, int a1, HeapID heapId); +UnkStruct_0202E9FC *sub_0202EA80(SaveRankings *a0, int a1, HeapID heapId); void sub_0202EAFC(UnkStruct_0202E9FC *a0); #endif //GUARD_POKEHEARTGOLD_UNK_0202E4B0_H diff --git a/include/unk_02097D3C.h b/include/unk_02097D3C.h index 3a76b26ae..2c8acdf7b 100644 --- a/include/unk_02097D3C.h +++ b/include/unk_02097D3C.h @@ -4,17 +4,18 @@ #include "field_types_def.h" #include "save.h" -typedef struct UnkStruct_02097D56 { - u16 unk_0; - u16 unk_2; +typedef struct ViewFriendRecordsArgs { + u16 page_scroll; + u16 cursorPos; SaveData *saveData; -} UnkStruct_02097D56; +} ViewFriendRecordsArgs; typedef struct UnkStruct_02097D48 { u32 state; - UnkStruct_02097D56 *args; + ViewFriendRecordsArgs *args; } UnkStruct_02097D48; -void sub_02097D3C(FieldSystem *fieldSystem, u8 a1, u8 a2); +// pageScrollParam = 3 * scroll + page +void FieldSystem_LaunchTask_ViewFriendRecordsApp(FieldSystem *fieldSystem, u8 pageScrollParam, u8 cursorPos); #endif //POKEHEARTGOLD_UNK_02097D3C_H diff --git a/src/data/fieldmap/script_cmd_table.h b/src/data/fieldmap/script_cmd_table.h index 0e5909f3e..3eafe2ef7 100644 --- a/src/data/fieldmap/script_cmd_table.h +++ b/src/data/fieldmap/script_cmd_table.h @@ -377,7 +377,7 @@ BOOL ScrCmd_374(ScriptContext *ctx); BOOL ScrCmd_MakeObjectVisible(ScriptContext *ctx); BOOL ScrCmd_376(ScriptContext *ctx); BOOL ScrCmd_377(ScriptContext *ctx); -BOOL ScrCmd_378(ScriptContext *ctx); +BOOL ScrCmd_ViewFriendRecords(ScriptContext *ctx); BOOL ScrCmd_379(ScriptContext *ctx); BOOL ScrCmd_Random(ScriptContext *ctx); BOOL ScrCmd_381(ScriptContext *ctx); @@ -1232,7 +1232,7 @@ const ScrCmdFunc gScriptCmdTable[] = { ScrCmd_MakeObjectVisible, ScrCmd_376, ScrCmd_377, - ScrCmd_378, + ScrCmd_ViewFriendRecords, ScrCmd_379, ScrCmd_Random, ScrCmd_381, diff --git a/src/game_clear.c b/src/game_clear.c index af418f8b5..624218119 100644 --- a/src/game_clear.c +++ b/src/game_clear.c @@ -290,7 +290,7 @@ void CallTask_GameClear(TaskManager *taskman, u16 vsTrainerRed) { PlayerProfile_SetGameClearFlag(profile); if (!env->vsTrainerRed) { - GameStats_Inc(Save_GameStats_Get(fieldSystem->saveData), 74); + GameStats_Inc(Save_GameStats_Get(fieldSystem->saveData), GAME_STAT_UNK74); } TaskManager_Call(taskman, Task_GameClear, env); } diff --git a/src/game_stats.c b/src/game_stats.c index 607ca6318..6b91fd30e 100644 --- a/src/game_stats.c +++ b/src/game_stats.c @@ -219,7 +219,7 @@ u32 GameStats_sizeof(void) { void GameStats_Init(GAME_STATS *gameStats) { MI_CpuClear32(gameStats, sizeof(GAME_STATS)); gameStats->unk_1BE = OS_GetVBlankCount() | (OS_GetVBlankCount() << 8); - GameStats_Release(gameStats, 2); + GameStats_Release(gameStats, GAME_STAT_SCORE); } GAME_STATS *Save_GameStats_Get(SaveData *saveData) { diff --git a/src/launch_application.c b/src/launch_application.c index 98294a062..bafabf1e7 100644 --- a/src/launch_application.c +++ b/src/launch_application.c @@ -1397,7 +1397,7 @@ LegendaryCinematicArgs *LegendaryCinematic_LaunchApp(FieldSystem *fieldSystem, U return args; } -void sub_0203FD08(FieldSystem *fieldSystem, UnkStruct_02097D56 *args) { - static const OVY_MGR_TEMPLATE _020FA494 = { ov121_021E5900, ov121_021E590C, ov121_021E59BC, FS_OVERLAY_ID(OVY_121) }; - FieldSystem_LaunchApplication(fieldSystem, &_020FA494, args); +void LaunchApp_ViewFriendRecords(FieldSystem *fieldSystem, ViewFriendRecordsArgs *args) { + static const OVY_MGR_TEMPLATE sViewFriendRecordsAppTemplate = { ViewFriendRecordsApp_Init, ViewFriendRecordsApp_Main, ViewFriendRecordsApp_Exit, FS_OVERLAY_ID(OVY_121) }; + FieldSystem_LaunchApplication(fieldSystem, &sViewFriendRecordsAppTemplate, args); } diff --git a/src/overlay_121.c b/src/overlay_121.c index b7bad3e8e..c6c905ae0 100644 --- a/src/overlay_121.c +++ b/src/overlay_121.c @@ -24,35 +24,44 @@ #include "yes_no_prompt.h" #include "player_data.h" #include "msgdata/msg/msg_0421.h" +#include "constants/ranking.h" #define min(a, b) ((a) <= (b) ? (a) : (b)) -typedef enum Overlay121WindowId { - OV121_WINDOW_0, - OV121_WINDOW_1, - OV121_WINDOW_2, - OV121_WINDOW_3, - OV121_WINDOW_4, - OV121_WINDOW_5, -} Overlay121WindowId; +typedef enum ViewFriendRecordsWindowId { + OV121_WINDOW_RANKING, + OV121_WINDOW_RECORDS, + OV121_WINDOW_HEADER, + OV121_WINDOW_RETURN, + OV121_WINDOW_DELETE_RECORD, + OV121_WINDOW_SELECT_RECORD_TO_DELETE, +} ViewFriendRecordsWindowId; -typedef enum Overlay121SpriteId { - OV121_SPRITE_0, - OV121_SPRITE_1, - OV121_SPRITE_2, - OV121_SPRITE_3, - OV121_SPRITE_4, -} Overlay121SpriteId; +typedef enum ViewFriendRecordsSpriteId { + OV121_SPRITE_CURSOR, + OV121_SPRITE_RIGHT_ARROW, + OV121_SPRITE_LEFT_ARROW, + OV121_SPRITE_RETURN, + OV121_SPRITE_DELETE_RECORD, +} ViewFriendRecordsSpriteId; -typedef enum Overlay121State { - OV121_STATE_INIT, - OV121_STATE_1, +typedef enum ViewFriendRecordsMainState { + OV121_MAIN_STATE_FADE_IN, + OV121_MAIN_STATE_WAIT_FADE_IN, + OV121_MAIN_STATE_MAIN, + OV121_MAIN_STATE_FADE_OUT, + OV121_MAIN_STATE_WAIT_FADE_OUT, +} ViewFriendRecordsMainState; + +typedef enum ViewFriendRecordsState { + OV121_STATE_REDRAW, + OV121_STATE_HANDLE_INPUT, OV121_STATE_YESNO, - OV121_STATE_3, - OV121_STATE_4, -} Overlay121State; + OV121_STATE_DELETE_FAILED_CANT_DELETE_OWN, + OV121_STATE_DO_DELETE_RECORD, +} ViewFriendRecordsState; -typedef enum Overlay121Input { +typedef enum ViewFriendRecordsInput { OV121_INPUT_NONE, OV121_INPUT_CURSOR_UP, OV121_INPUT_CURSOR_DOWN, @@ -62,34 +71,34 @@ typedef enum Overlay121Input { OV121_INPUT_CURSOR_LEFT, OV121_INPUT_CURSOR_RIGHT, OV121_INPUT_A_BUTTON, -} Overlay121Input; +} ViewFriendRecordsInput; -typedef struct UnkStruct_ov121_021E7014 { - u32 unk_0; - u16 unk_4; - u16 unk_6; -} UnkStruct_ov121_021E7014; +typedef struct RecordPageParam { + u32 max; + u16 numDigits; + u16 msgId; +} RecordPageParam; -typedef struct Overlay121Sub258 { +typedef struct ViewFriendRecordsSub258 { UnkStruct_0202E9FC_sub *unk_00; - u16 unk_04; - u8 unk_06; -} Overlay121Sub258; + u16 active; + u8 friendIdx; +} ViewFriendRecordsSub258; -typedef struct Overlay121Sub254 { - int unk_00; - Overlay121Sub258 unk_04[7]; -} Overlay121Sub254; +typedef struct ViewFriendRecordsSub254 { + int count; + ViewFriendRecordsSub258 entries[7]; +} ViewFriendRecordsSub254; -typedef struct Overlay121Appdata { +typedef struct ViewFriendRecordsAppdata { BgConfig *bgConfig; Window windows[6]; MsgData *msgData; MessageFormat *msgFormat; - String *unk_06C; - String *unk_070; - String *unk_074; - String *unk_078[7]; + String *formatedStrBuf; + String *playerNameString; + String *rankingString; + String *miscStrings[7]; YesNoPrompt *yesNoPrompt; SpriteList *spriteList; GF_G2dRenderer g2dRenderer; @@ -98,31 +107,31 @@ typedef struct Overlay121Appdata { SpriteResourcesHeader spriteResourcesHeader; Sprite *sprites[5]; TouchscreenHitbox *touchscreenHitboxes; - u8 unk_230; - u8 unk_231; - s8 unk_232; + u8 mainState; + u8 isDeleteMode; + s8 cursorPos; u8 state; - UnkStruct_0202E4B0 *unk_234; + SaveRankings *unk_234; UnkStruct_0202E9FC *unk_238[7]; - Overlay121Sub254 *unk_254; - Overlay121Sub258 *unk_258; + ViewFriendRecordsSub254 *records; + ViewFriendRecordsSub258 *recordToDelete; u8 page; u8 unk_25D; - u8 unk_25E; - u8 unk_25F; - u8 unk_260; - u8 unk_261; - u8 unk_262[6]; + u8 pageLength; + u8 pageOffset; + u8 recordIdx; + u8 numRecords; + u8 recordEntryIdxs[6]; u8 unk_268; -} Overlay121AppData; +} ViewFriendRecordsAppData; -typedef struct UnkStruct_Overlay121_021E7140 { +typedef struct ViewFriendRecordsCursorPositionParam { int x; int y; int anim; -} UnkStruct_Overlay121_021E7140; +} ViewFriendRecordsCursorPositionParam; -static const UnkStruct_Overlay121_021E7140 ov121_021E7140[] = { +static const ViewFriendRecordsCursorPositionParam sCursorPositionParams[] = { { .x = 128, .y = 64, @@ -160,139 +169,143 @@ static const UnkStruct_Overlay121_021E7140 ov121_021E7140[] = { }, }; -static const UnkStruct_ov121_021E7014 ov121_021E7110[] = { +static const RecordPageParam sRecordPageParam_BattleTower[] = { { - .unk_0 = 9999, - .unk_4 = 4, - .unk_6 = 44, + .max = 9999, + .numDigits = 4, + .msgId = msg_0421_00044, }, { - .unk_0 = 9999, - .unk_4 = 4, - .unk_6 = 44, + .max = 9999, + .numDigits = 4, + .msgId = msg_0421_00044, }, { - .unk_0 = 9999, - .unk_4 = 4, - .unk_6 = 44, + .max = 9999, + .numDigits = 4, + .msgId = msg_0421_00044, }, { - .unk_0 = 9999, - .unk_4 = 4, - .unk_6 = 44, + .max = 9999, + .numDigits = 4, + .msgId = msg_0421_00044, }, { - .unk_0 = 9999, - .unk_4 = 4, - .unk_6 = 44, + .max = 9999, + .numDigits = 4, + .msgId = msg_0421_00044, }, { - .unk_0 = 7, - .unk_4 = 0x0001, - .unk_6 = 0x002D, + .max = 7, + .numDigits = 1, + .msgId = msg_0421_00045, }, }; -static const UnkStruct_ov121_021E7014 ov121_021E70C8[] = { +static const RecordPageParam sRecordPageParam_Pokemon[] = { + // mons fainted { - .unk_0 = 999999, - .unk_4 = 6, - .unk_6 = 47, + .max = 999999, + .numDigits = 6, + .msgId = msg_0421_00047, }, + // mons caught { - .unk_0 = 999999, - .unk_4 = 6, - .unk_6 = 47, + .max = 999999, + .numDigits = 6, + .msgId = msg_0421_00047, }, + // eggs hatched { - .unk_0 = 999999, - .unk_4 = 6, - .unk_6 = 0x002E, + .max = 999999, + .numDigits = 6, + .msgId = msg_0421_00046, }, + // fishing landed { - .unk_0 = 999999, - .unk_4 = 6, - .unk_6 = 47, + .max = 999999, + .numDigits = 6, + .msgId = msg_0421_00047, }, }; -static const UnkStruct_ov121_021E7014 *const ov121_021E7014[] = { - ov121_021E7110, - ov121_021E70C8, +static const RecordPageParam *const sRecordPageParams[] = { + sRecordPageParam_BattleTower, + sRecordPageParam_Pokemon, }; -static void ov121_021E5AEC(OVY_MANAGER *man, int *pState); -static BOOL ov121_021E5C50(Overlay121AppData *appData); -static void ov121_021E5CB4(Overlay121AppData *appData); -static BOOL ov121_021E5CC4(Overlay121AppData *appData); -static void Overlay121_HandleYesNoInput(Overlay121AppData *appData); -static BOOL ov121_021E5D5C(Overlay121AppData *appData); -static void Overlay121_SetGfxBanks(void); -static void Overlay121_InitBgLayers(BgConfig *bgConfig); -static void Overlay121_InitObjCharTransfer(void); -static void Overlay121_CreateOamManager(void); -static void VBlankCB_Overlay121(void *cbData); -static void Overlay121_LoadBgGraphics(BgConfig *bgConfig, HeapID heapId); -static void Overlay121_LoadSpriteGraphics(Overlay121AppData *appData, HeapID heapId); -static void Overlay121_CreateSpriteResourcesHeader(Overlay121AppData *appData); -static void Overlay121_DestroySprites(Overlay121AppData *appData); -static void setSpriteTemplate(SpriteTemplate *spriteTemplate, Overlay121AppData *appData); -static void Overlay121_CreateSprites(Overlay121AppData *appData); -static void Overlay121_CreateTouchscreenHitboxes(Overlay121AppData *appData, HeapID heapId); -static Overlay121Input Overlay121_PollInput(Overlay121AppData *appData, int *pSelection); -static BOOL ov121_021E6404(Overlay121AppData *appData, Overlay121Input input, int selection); -static void ov121_021E6478(Overlay121AppData *appData, Overlay121Input input, int selection); -static void ov121_021E6544(Overlay121AppData *appData, int direction); -static void ov121_021E65A8(Overlay121AppData *appData, int selection); -static void ov121_021E65D8(Overlay121AppData *appData); -static void ov121_021E662C(Overlay121AppData *appData, int direction); -static void ov121_021E6690(Overlay121AppData *appData, BOOL selection); -static void Overlay121_CreateWindows(Overlay121AppData *appData); -static void ov121_021E67E4(Overlay121AppData *appData); -static void ov121_021E67FC(Overlay121AppData *appData, SaveData *saveData); -static void ov121_021E69F0(Overlay121AppData *appData); -static void ov121_021E6A4C(Overlay121AppData *appData); -static void ov121_021E6A84(Overlay121AppData *appData); -static void Overlay121_PrintDeleteRecordText(Overlay121AppData *appData); -static void Overlay121_PrintReturnText(Overlay121AppData *appData); -static void Overlay121_PrintDeleteXsRecordAreYouSure(Overlay121AppData *appData); -static void Overlay121_PrintYourOwnRecordCantBeDeleted(Overlay121AppData *appData); -static void Overlay121_PrintRecordStatHeaderText(Overlay121AppData *appData); -static void Overlay121_PrintSelectRecordToDeleteText(Overlay121AppData *appData); -static void ov121_021E6EC0(Overlay121AppData *appData); +static void ViewFriendRecordsApp_Init_Internal(OVY_MANAGER *man, int *pState); +static BOOL ViewFriendRecordsApp_Main_Internal(ViewFriendRecordsAppData *appData); +static void ov121_021E5CB4(ViewFriendRecordsAppData *appData); +static BOOL ViewFriendRecords_PollAndHandleInput(ViewFriendRecordsAppData *appData); +static void ViewFriendRecords_HandleYesNoInput(ViewFriendRecordsAppData *appData); +static BOOL ViewFriendRecords_WaitButtonOrTouch(ViewFriendRecordsAppData *appData); +static void ViewFriendRecords_SetGfxBanks(void); +static void ViewFriendRecords_InitBgLayers(BgConfig *bgConfig); +static void ViewFriendRecords_InitObjCharTransfer(void); +static void ViewFriendRecords_CreateOamManager(void); +static void VBlankCB_ViewFriendRecords(void *cbData); +static void ViewFriendRecords_LoadBgGraphics(BgConfig *bgConfig, HeapID heapId); +static void ViewFriendRecords_LoadSpriteGraphics(ViewFriendRecordsAppData *appData, HeapID heapId); +static void ViewFriendRecords_CreateSpriteResourcesHeader(ViewFriendRecordsAppData *appData); +static void ViewFriendRecords_DestroySprites(ViewFriendRecordsAppData *appData); +static void setSpriteTemplate(SpriteTemplate *spriteTemplate, ViewFriendRecordsAppData *appData); +static void ViewFriendRecords_CreateSprites(ViewFriendRecordsAppData *appData); +static void ViewFriendRecords_CreateTouchscreenHitboxes(ViewFriendRecordsAppData *appData, HeapID heapId); +static ViewFriendRecordsInput ViewFriendRecords_PollInput(ViewFriendRecordsAppData *appData, int *pSelection); +static BOOL ViewFriendRecords_HandleInput_BrowsePages(ViewFriendRecordsAppData *appData, ViewFriendRecordsInput input, int selection); +static void ViewFriendRecords_HandleInput_SelectRecordToDelete(ViewFriendRecordsAppData *appData, ViewFriendRecordsInput input, int selection); +static void ViewFriendRecords_MoveCursorInDirection(ViewFriendRecordsAppData *appData, int direction); +static void ViewFriendRecords_TrySetCursorPosition(ViewFriendRecordsAppData *appData, int selection); +static void ViewFriendRecords_DrawCursor(ViewFriendRecordsAppData *appData); +static void ViewFriendRecords_SwitchPage(ViewFriendRecordsAppData *appData, int direction); +static void ViewFriendRecords_ToggleDeleteMode(ViewFriendRecordsAppData *appData, BOOL selection); +static void ViewFriendRecords_CreateWindows(ViewFriendRecordsAppData *appData); +static void ViewFriendRecords_HideSelectRecordToDeleteText(ViewFriendRecordsAppData *appData); +static void ov121_021E67FC(ViewFriendRecordsAppData *appData, SaveData *saveData); +static void ViewFriendRecords_CreateStrings(ViewFriendRecordsAppData *appData); +static void ViewFriendRecords_DeleteStrings(ViewFriendRecordsAppData *appData); +static void ViewFriendRecords_PrintRecords(ViewFriendRecordsAppData *appData); +static void ViewFriendRecords_PrintDeleteRecordText(ViewFriendRecordsAppData *appData); +static void ViewFriendRecords_PrintReturnText(ViewFriendRecordsAppData *appData); +static void ViewFriendRecords_PrintDeleteXsRecordAreYouSure(ViewFriendRecordsAppData *appData); +static void ViewFriendRecords_PrintYourOwnRecordCantBeDeleted(ViewFriendRecordsAppData *appData); +static void ViewFriendRecords_PrintRecordStatHeaderText(ViewFriendRecordsAppData *appData); +static void ViewFriendRecords_PrintSelectRecordToDeleteText(ViewFriendRecordsAppData *appData); +static void ViewFriendRecords_AskConfirmDeleteRecord(ViewFriendRecordsAppData *appData); static void dimAllMainBgsExceptLyr0(void); static void resetMainBgsBrightness(void); -static void ov121_021E6F78(Overlay121AppData *appData); +static void ViewFriendRecordsApp_CommitChanges(ViewFriendRecordsAppData *appData); -BOOL ov121_021E5900(OVY_MANAGER *man, int *pState) { - ov121_021E5AEC(man, pState); +BOOL ViewFriendRecordsApp_Init(OVY_MANAGER *man, int *pState) { + ViewFriendRecordsApp_Init_Internal(man, pState); return TRUE; } -BOOL ov121_021E590C(OVY_MANAGER *man, int *pState) { - Overlay121AppData *appData = OverlayManager_GetData(man); - switch (appData->unk_230) { - case 0: +BOOL ViewFriendRecordsApp_Main(OVY_MANAGER *man, int *pState) { + ViewFriendRecordsAppData *appData = OverlayManager_GetData(man); + switch (appData->mainState) { + case OV121_MAIN_STATE_FADE_IN: BeginNormalPaletteFade(0, 1, 1, RGB_BLACK, 6, 1, HEAP_ID_9E); - appData->unk_230 = 1; + appData->mainState = OV121_MAIN_STATE_WAIT_FADE_IN; break; - case 1: + case OV121_MAIN_STATE_WAIT_FADE_IN: if (IsPaletteFadeFinished()) { - appData->unk_230 = 2; + appData->mainState = OV121_MAIN_STATE_MAIN; } break; - case 2: - if (ov121_021E5C50(appData)) { - appData->unk_230 = 3; + case OV121_MAIN_STATE_MAIN: + if (ViewFriendRecordsApp_Main_Internal(appData)) { + appData->mainState = OV121_MAIN_STATE_FADE_OUT; } break; - case 3: + case OV121_MAIN_STATE_FADE_OUT: BeginNormalPaletteFade(0, 0, 0, RGB_BLACK, 6, 1, HEAP_ID_9E); - appData->unk_230 = 4; + appData->mainState = OV121_MAIN_STATE_WAIT_FADE_OUT; break; - case 4: + case OV121_MAIN_STATE_WAIT_FADE_OUT: if (IsPaletteFadeFinished()) { - ov121_021E6F78(appData); + ViewFriendRecordsApp_CommitChanges(appData); return TRUE; } break; @@ -302,26 +315,26 @@ BOOL ov121_021E590C(OVY_MANAGER *man, int *pState) { return FALSE; } -BOOL ov121_021E59BC(OVY_MANAGER *man, int *pState) { - Overlay121AppData *appData = OverlayManager_GetData(man); +BOOL ViewFriendRecordsApp_Exit(OVY_MANAGER *man, int *pState) { + ViewFriendRecordsAppData *appData = OverlayManager_GetData(man); gSystem.screensFlipped = FALSE; GfGfx_SwapDisplay(); Main_SetVBlankIntrCB(NULL, NULL); G2_BlendNone(); - ov121_021E6A4C(appData); - RemoveWindow(&appData->windows[OV121_WINDOW_0]); - RemoveWindow(&appData->windows[OV121_WINDOW_1]); - RemoveWindow(&appData->windows[OV121_WINDOW_2]); - RemoveWindow(&appData->windows[OV121_WINDOW_3]); - RemoveWindow(&appData->windows[OV121_WINDOW_4]); - RemoveWindow(&appData->windows[OV121_WINDOW_5]); + ViewFriendRecords_DeleteStrings(appData); + RemoveWindow(&appData->windows[OV121_WINDOW_RANKING]); + RemoveWindow(&appData->windows[OV121_WINDOW_RECORDS]); + RemoveWindow(&appData->windows[OV121_WINDOW_HEADER]); + RemoveWindow(&appData->windows[OV121_WINDOW_RETURN]); + RemoveWindow(&appData->windows[OV121_WINDOW_DELETE_RECORD]); + RemoveWindow(&appData->windows[OV121_WINDOW_SELECT_RECORD_TO_DELETE]); FreeBgTilemapBuffer(appData->bgConfig, GF_BG_LYR_MAIN_0); FreeBgTilemapBuffer(appData->bgConfig, GF_BG_LYR_MAIN_1); FreeBgTilemapBuffer(appData->bgConfig, GF_BG_LYR_MAIN_2); FreeBgTilemapBuffer(appData->bgConfig, GF_BG_LYR_MAIN_3); FreeBgTilemapBuffer(appData->bgConfig, GF_BG_LYR_SUB_0); - Overlay121_DestroySprites(appData); + ViewFriendRecords_DestroySprites(appData); sub_0200AEB0(appData->gf2dGfxResObjects[GF_GFX_RES_TYPE_CHAR]); sub_0200B0A8(appData->gf2dGfxResObjects[GF_GFX_RES_TYPE_PLTT]); for (int i = 0; i < 6; ++i) { @@ -335,134 +348,134 @@ BOOL ov121_021E59BC(OVY_MANAGER *man, int *pState) { YesNoPrompt_Destroy(appData->yesNoPrompt); FreeToHeap(appData->touchscreenHitboxes); FreeToHeap(appData->bgConfig); - for (int i = 0; i < appData->unk_25E + 1; ++i) { + for (int i = 0; i < appData->pageLength + 1; ++i) { sub_0202EAFC(appData->unk_238[i]); } - FreeToHeap(appData->unk_254); + FreeToHeap(appData->records); FreeToHeap(appData); DestroyHeap(HEAP_ID_9E); return TRUE; } -static void ov121_021E5AEC(OVY_MANAGER *man, int *pState) { - UnkStruct_02097D56 *args = OverlayManager_GetArgs(man); +static void ViewFriendRecordsApp_Init_Internal(OVY_MANAGER *man, int *pState) { + ViewFriendRecordsArgs *args = OverlayManager_GetArgs(man); CreateHeap(HEAP_ID_3, HEAP_ID_9E, 0x10000); - Overlay121AppData *data = OverlayManager_CreateAndGetData(man, sizeof(Overlay121AppData), HEAP_ID_9E); - memset(data, 0, sizeof(Overlay121AppData)); + ViewFriendRecordsAppData *data = OverlayManager_CreateAndGetData(man, sizeof(ViewFriendRecordsAppData), HEAP_ID_9E); + memset(data, 0, sizeof(ViewFriendRecordsAppData)); data->bgConfig = BgConfig_Alloc(HEAP_ID_9E); - Overlay121_SetGfxBanks(); - Overlay121_InitBgLayers(data->bgConfig); - Overlay121_InitObjCharTransfer(); - Overlay121_CreateOamManager(); - Overlay121_LoadSpriteGraphics(data, HEAP_ID_9E); - Overlay121_CreateSpriteResourcesHeader(data); + ViewFriendRecords_SetGfxBanks(); + ViewFriendRecords_InitBgLayers(data->bgConfig); + ViewFriendRecords_InitObjCharTransfer(); + ViewFriendRecords_CreateOamManager(); + ViewFriendRecords_LoadSpriteGraphics(data, HEAP_ID_9E); + ViewFriendRecords_CreateSpriteResourcesHeader(data); data->yesNoPrompt = YesNoPrompt_Create(HEAP_ID_9E); data->unk_268 = Options_GetFrame(Save_PlayerData_GetOptionsAddr(args->saveData)); - Main_SetVBlankIntrCB(VBlankCB_Overlay121, data->bgConfig); - data->unk_230 = 0; + Main_SetVBlankIntrCB(VBlankCB_ViewFriendRecords, data->bgConfig); + data->mainState = 0; ResetAllTextPrinters(); FontID_Alloc(4, HEAP_ID_9E); - Overlay121_LoadBgGraphics(data->bgConfig, HEAP_ID_9E); + ViewFriendRecords_LoadBgGraphics(data->bgConfig, HEAP_ID_9E); LoadFontPal0(GF_PAL_LOCATION_MAIN_BG, (enum GFPalSlotOffset)0x1E0, HEAP_ID_9E); - Overlay121_CreateWindows(data); - Overlay121_CreateSprites(data); + ViewFriendRecords_CreateWindows(data); + ViewFriendRecords_CreateSprites(data); GfGfx_EngineATogglePlanes(GX_PLANEMASK_OBJ, GF_PLANE_TOGGLE_ON); - Overlay121_CreateTouchscreenHitboxes(data, HEAP_ID_9E); + ViewFriendRecords_CreateTouchscreenHitboxes(data, HEAP_ID_9E); data->state = 1; data->unk_234 = sub_0202E530(args->saveData); - data->page = args->unk_0 % 3; - data->unk_25D = args->unk_0 / 3; - data->unk_25E = sub_0202E4B0(data->page); - data->unk_25F = sub_0202E4BC(data->page); + data->page = args->page_scroll % 3; + data->unk_25D = args->page_scroll / 3; + data->pageLength = RankingsViewSys_GetNumRecordsPerPage(data->page); + data->pageOffset = RankingsViewSys_GetFirstRecordIndexOnPage(data->page); ov121_021E67FC(data, args->saveData); - data->unk_260 = args->unk_2; - if (data->unk_260 >= data->unk_25E) { + data->recordIdx = args->cursorPos; + if (data->recordIdx >= data->pageLength) { GF_ASSERT(FALSE); - data->unk_260 = 0; + data->recordIdx = 0; } - ov121_021E69F0(data); - ov121_021E6690(data, 0); - ov121_021E6A84(data); - Overlay121_PrintDeleteRecordText(data); - Overlay121_PrintReturnText(data); - Overlay121_PrintRecordStatHeaderText(data); + ViewFriendRecords_CreateStrings(data); + ViewFriendRecords_ToggleDeleteMode(data, 0); + ViewFriendRecords_PrintRecords(data); + ViewFriendRecords_PrintDeleteRecordText(data); + ViewFriendRecords_PrintReturnText(data); + ViewFriendRecords_PrintRecordStatHeaderText(data); } -static BOOL ov121_021E5C50(Overlay121AppData *appData) { +static BOOL ViewFriendRecordsApp_Main_Internal(ViewFriendRecordsAppData *appData) { switch (appData->state) { - case OV121_STATE_INIT: - ov121_021E6A84(appData); - appData->state = OV121_STATE_1; + case OV121_STATE_REDRAW: + ViewFriendRecords_PrintRecords(appData); + appData->state = OV121_STATE_HANDLE_INPUT; break; - case OV121_STATE_1: - if (ov121_021E5CC4(appData)) { + case OV121_STATE_HANDLE_INPUT: + if (ViewFriendRecords_PollAndHandleInput(appData)) { return TRUE; } break; case OV121_STATE_YESNO: - Overlay121_HandleYesNoInput(appData); + ViewFriendRecords_HandleYesNoInput(appData); break; - case OV121_STATE_3: - if (ov121_021E5D5C(appData)) { - appData->state = OV121_STATE_1; + case OV121_STATE_DELETE_FAILED_CANT_DELETE_OWN: + if (ViewFriendRecords_WaitButtonOrTouch(appData)) { + appData->state = OV121_STATE_HANDLE_INPUT; } break; - case OV121_STATE_4: - appData->unk_258->unk_04 = 0; - appData->state = OV121_STATE_INIT; + case OV121_STATE_DO_DELETE_RECORD: + appData->recordToDelete->active = FALSE; + appData->state = OV121_STATE_REDRAW; break; } return FALSE; } -static void ov121_021E5CB4(Overlay121AppData *appData) { +static void ov121_021E5CB4(ViewFriendRecordsAppData *appData) { if (appData->spriteList != NULL) { sub_0202457C(appData->spriteList); } } -static BOOL ov121_021E5CC4(Overlay121AppData *appData) { +static BOOL ViewFriendRecords_PollAndHandleInput(ViewFriendRecordsAppData *appData) { int selection; - Overlay121Input input = Overlay121_PollInput(appData, &selection); + ViewFriendRecordsInput input = ViewFriendRecords_PollInput(appData, &selection); if (input == 0) { return FALSE; } - if (appData->unk_231 == 0) { - if (ov121_021E6404(appData, input, selection)) { + if (appData->isDeleteMode == 0) { + if (ViewFriendRecords_HandleInput_BrowsePages(appData, input, selection)) { return TRUE; } } else { - ov121_021E6478(appData, input, selection); + ViewFriendRecords_HandleInput_SelectRecordToDelete(appData, input, selection); } return FALSE; } -static void Overlay121_HandleYesNoInput(Overlay121AppData *appData) { +static void ViewFriendRecords_HandleYesNoInput(ViewFriendRecordsAppData *appData) { switch (YesNoPrompt_HandleInput(appData->yesNoPrompt)) { case YESNORESPONSE_YES: YesNoPrompt_Reset(appData->yesNoPrompt); resetMainBgsBrightness(); - appData->state = OV121_STATE_4; - Overlay121_PrintSelectRecordToDeleteText(appData); + appData->state = OV121_STATE_DO_DELETE_RECORD; + ViewFriendRecords_PrintSelectRecordToDeleteText(appData); break; case YESNORESPONSE_NO: YesNoPrompt_Reset(appData->yesNoPrompt); resetMainBgsBrightness(); - appData->state = OV121_STATE_1; - Overlay121_PrintSelectRecordToDeleteText(appData); + appData->state = OV121_STATE_HANDLE_INPUT; + ViewFriendRecords_PrintSelectRecordToDeleteText(appData); break; } } -static BOOL ov121_021E5D5C(Overlay121AppData *appData) { +static BOOL ViewFriendRecords_WaitButtonOrTouch(ViewFriendRecordsAppData *appData) { if (gSystem.newKeys != 0 || System_GetTouchNew()) { - Overlay121_PrintSelectRecordToDeleteText(appData); + ViewFriendRecords_PrintSelectRecordToDeleteText(appData); return TRUE; } return FALSE; } -static void Overlay121_SetGfxBanks(void) { +static void ViewFriendRecords_SetGfxBanks(void) { GraphicsBanks graphicsBanks = { .bg = GX_VRAM_BG_128_A, .bgextpltt = GX_VRAM_BGEXTPLTT_NONE, @@ -478,7 +491,7 @@ static void Overlay121_SetGfxBanks(void) { GfGfx_SetBanks(&graphicsBanks); } -static void Overlay121_InitBgLayers(BgConfig *bgConfig) { +static void ViewFriendRecords_InitBgLayers(BgConfig *bgConfig) { gSystem.screensFlipped = TRUE; GfGfx_SwapDisplay(); @@ -587,7 +600,7 @@ static void Overlay121_InitBgLayers(BgConfig *bgConfig) { BG_FillCharDataRange(bgConfig, GF_BG_LYR_MAIN_2, 0, 1, 0); } -static void Overlay121_InitObjCharTransfer(void) { +static void ViewFriendRecords_InitObjCharTransfer(void) { ObjCharTransferTemplate template = { .maxTasks = 10, .sizeMain = 0x10000, @@ -600,12 +613,12 @@ static void Overlay121_InitObjCharTransfer(void) { sub_02022638(); } -static void Overlay121_CreateOamManager(void) { +static void ViewFriendRecords_CreateOamManager(void) { NNS_G2dInitOamManagerModule(); OamManager_Create(0, 126, 0, 32, 0, 126, 0, 32, HEAP_ID_9E); } -static void VBlankCB_Overlay121(void *cbData) { +static void VBlankCB_ViewFriendRecords(void *cbData) { BgConfig *bgConfig = (BgConfig *)cbData; OamManager_ApplyAndResetBuffers(); @@ -614,7 +627,7 @@ static void VBlankCB_Overlay121(void *cbData) { OS_SetIrqCheckFlag(OS_IE_V_BLANK); } -static void Overlay121_LoadBgGraphics(BgConfig *bgConfig, HeapID heapId) { +static void ViewFriendRecords_LoadBgGraphics(BgConfig *bgConfig, HeapID heapId) { GfGfxLoader_GXLoadPal(NARC_a_2_6_0, 1, GF_PAL_LOCATION_MAIN_BG, (enum GFPalSlotOffset)0, 0x40, heapId); GfGfxLoader_LoadCharData(NARC_a_2_6_0, 3, bgConfig, GF_BG_LYR_MAIN_3, 0, 0x1000, TRUE, heapId); GfGfxLoader_LoadScrnData(NARC_a_2_6_0, 5, bgConfig, GF_BG_LYR_MAIN_3, 0, 0x600, TRUE, heapId); @@ -626,7 +639,7 @@ static void Overlay121_LoadBgGraphics(BgConfig *bgConfig, HeapID heapId) { BgCommitTilemapBufferToVram(bgConfig, GF_BG_LYR_SUB_0); } -static void Overlay121_LoadSpriteGraphics(Overlay121AppData *appData, HeapID heapId) { +static void ViewFriendRecords_LoadSpriteGraphics(ViewFriendRecordsAppData *appData, HeapID heapId) { appData->spriteList = G2dRenderer_Init(5, &appData->g2dRenderer, heapId); for (int i = 0; i < 6; ++i) { appData->gf2dGfxResManagers[i] = Create2DGfxResObjMan(1, (GfGfxResType)i, heapId); @@ -639,29 +652,29 @@ static void Overlay121_LoadSpriteGraphics(Overlay121AppData *appData, HeapID hea sub_0200AF94(appData->gf2dGfxResObjects[GF_GFX_RES_TYPE_PLTT]); } -static void Overlay121_CreateSpriteResourcesHeader(Overlay121AppData *appData) { +static void ViewFriendRecords_CreateSpriteResourcesHeader(ViewFriendRecordsAppData *appData) { CreateSpriteResourcesHeader(&appData->spriteResourcesHeader, 0, 0, 0, 0, -1, -1, 0, 3, appData->gf2dGfxResManagers[GF_GFX_RES_TYPE_CHAR], appData->gf2dGfxResManagers[GF_GFX_RES_TYPE_PLTT], appData->gf2dGfxResManagers[GF_GFX_RES_TYPE_CELL], appData->gf2dGfxResManagers[GF_GFX_RES_TYPE_ANIM], NULL, NULL); } -static void Overlay121_DestroySprites(Overlay121AppData *appData) { - if (appData->sprites[OV121_SPRITE_0] != NULL) { - Sprite_Delete(appData->sprites[OV121_SPRITE_0]); +static void ViewFriendRecords_DestroySprites(ViewFriendRecordsAppData *appData) { + if (appData->sprites[OV121_SPRITE_CURSOR] != NULL) { + Sprite_Delete(appData->sprites[OV121_SPRITE_CURSOR]); } - if (appData->sprites[OV121_SPRITE_1] != NULL) { - Sprite_Delete(appData->sprites[OV121_SPRITE_1]); + if (appData->sprites[OV121_SPRITE_RIGHT_ARROW] != NULL) { + Sprite_Delete(appData->sprites[OV121_SPRITE_RIGHT_ARROW]); } - if (appData->sprites[OV121_SPRITE_2] != NULL) { - Sprite_Delete(appData->sprites[OV121_SPRITE_2]); + if (appData->sprites[OV121_SPRITE_LEFT_ARROW] != NULL) { + Sprite_Delete(appData->sprites[OV121_SPRITE_LEFT_ARROW]); } - if (appData->sprites[OV121_SPRITE_3] != NULL) { - Sprite_Delete(appData->sprites[OV121_SPRITE_3]); + if (appData->sprites[OV121_SPRITE_RETURN] != NULL) { + Sprite_Delete(appData->sprites[OV121_SPRITE_RETURN]); } - if (appData->sprites[OV121_SPRITE_4] != NULL) { - Sprite_Delete(appData->sprites[OV121_SPRITE_4]); + if (appData->sprites[OV121_SPRITE_DELETE_RECORD] != NULL) { + Sprite_Delete(appData->sprites[OV121_SPRITE_DELETE_RECORD]); } } -static void setSpriteTemplate(SpriteTemplate *spriteTemplate, Overlay121AppData *appData) { +static void setSpriteTemplate(SpriteTemplate *spriteTemplate, ViewFriendRecordsAppData *appData) { spriteTemplate->spriteList = appData->spriteList; spriteTemplate->header = &appData->spriteResourcesHeader; spriteTemplate->position.z = 0; @@ -672,7 +685,7 @@ static void setSpriteTemplate(SpriteTemplate *spriteTemplate, Overlay121AppData spriteTemplate->heapId = HEAP_ID_9E; } -static void Overlay121_CreateSprites(Overlay121AppData *appData) { +static void ViewFriendRecords_CreateSprites(ViewFriendRecordsAppData *appData) { Sprite *sprite; SpriteTemplate spriteTemplate; setSpriteTemplate(&spriteTemplate, appData); @@ -684,7 +697,7 @@ static void Overlay121_CreateSprites(Overlay121AppData *appData) { Set2dSpriteAnimSeqNo(sprite, 2); Sprite_SetPriority(sprite, 1); Set2dSpriteVisibleFlag(sprite, TRUE); - appData->sprites[OV121_SPRITE_0] = sprite; + appData->sprites[OV121_SPRITE_CURSOR] = sprite; spriteTemplate.position.x = FX32_CONST(16); spriteTemplate.position.y = FX32_CONST(96); @@ -692,7 +705,7 @@ static void Overlay121_CreateSprites(Overlay121AppData *appData) { Set2dSpriteAnimActiveFlag(sprite, TRUE); Set2dSpriteAnimSeqNo(sprite, 3); Set2dSpriteVisibleFlag(sprite, TRUE); - appData->sprites[OV121_SPRITE_2] = sprite; + appData->sprites[OV121_SPRITE_LEFT_ARROW] = sprite; spriteTemplate.position.x = FX32_CONST(240); spriteTemplate.position.y = FX32_CONST(96); @@ -700,7 +713,7 @@ static void Overlay121_CreateSprites(Overlay121AppData *appData) { Set2dSpriteAnimActiveFlag(sprite, TRUE); Set2dSpriteAnimSeqNo(sprite, 5); Set2dSpriteVisibleFlag(sprite, TRUE); - appData->sprites[OV121_SPRITE_1] = sprite; + appData->sprites[OV121_SPRITE_RIGHT_ARROW] = sprite; spriteTemplate.position.x = FX32_CONST(224); spriteTemplate.position.y = FX32_CONST(176); @@ -708,7 +721,7 @@ static void Overlay121_CreateSprites(Overlay121AppData *appData) { Set2dSpriteAnimActiveFlag(sprite, TRUE); Set2dSpriteAnimSeqNo(sprite, 0); Set2dSpriteVisibleFlag(sprite, TRUE); - appData->sprites[OV121_SPRITE_3] = sprite; + appData->sprites[OV121_SPRITE_RETURN] = sprite; spriteTemplate.position.x = FX32_CONST(64); spriteTemplate.position.y = FX32_CONST(176); @@ -716,10 +729,10 @@ static void Overlay121_CreateSprites(Overlay121AppData *appData) { Set2dSpriteAnimActiveFlag(sprite, TRUE); Set2dSpriteAnimSeqNo(sprite, 8); Set2dSpriteVisibleFlag(sprite, TRUE); - appData->sprites[OV121_SPRITE_4] = sprite; + appData->sprites[OV121_SPRITE_DELETE_RECORD] = sprite; } -static void Overlay121_CreateTouchscreenHitboxes(Overlay121AppData *appData, HeapID heapId) { +static void ViewFriendRecords_CreateTouchscreenHitboxes(ViewFriendRecordsAppData *appData, HeapID heapId) { appData->touchscreenHitboxes = AllocFromHeap(heapId, 10 * sizeof(TouchscreenHitbox)); for (int i = 0; i < 6; ++i) { TouchscreenHitbox_SetRect(&appData->touchscreenHitboxes[i], 56 + 16 * i, 40, 16, 176); @@ -730,7 +743,7 @@ static void Overlay121_CreateTouchscreenHitboxes(Overlay121AppData *appData, Hea TouchscreenHitbox_SetCircle(&appData->touchscreenHitboxes[9], 240, 96, 16); } -static Overlay121Input Overlay121_PollInput(Overlay121AppData *appData, int *a1) { +static ViewFriendRecordsInput ViewFriendRecords_PollInput(ViewFriendRecordsAppData *appData, int *a1) { int input = 0; if (!System_GetTouchHeld()) { input = gSystem.newKeys; @@ -781,7 +794,7 @@ static Overlay121Input Overlay121_PollInput(Overlay121AppData *appData, int *a1) return OV121_INPUT_NONE; } -static BOOL ov121_021E6404(Overlay121AppData *appData, Overlay121Input input, int selection) { +static BOOL ViewFriendRecords_HandleInput_BrowsePages(ViewFriendRecordsAppData *appData, ViewFriendRecordsInput input, int selection) { switch (input) { case OV121_INPUT_NONE: case OV121_INPUT_CURSOR_UP: @@ -789,359 +802,359 @@ static BOOL ov121_021E6404(Overlay121AppData *appData, Overlay121Input input, in case OV121_INPUT_TAP_RECORD: break; case OV121_INPUT_CURSOR_LEFT: - ov121_021E662C(appData, -1); + ViewFriendRecords_SwitchPage(appData, -1); break; case OV121_INPUT_CURSOR_RIGHT: - ov121_021E662C(appData, 1); + ViewFriendRecords_SwitchPage(appData, 1); break; case OV121_INPUT_X_BUTTON: PlaySE(SEQ_SE_DP_DECIDE); - Set2dSpriteAnimSeqNo(appData->sprites[OV121_SPRITE_4], 9); - ov121_021E6690(appData, 1); + Set2dSpriteAnimSeqNo(appData->sprites[OV121_SPRITE_DELETE_RECORD], 9); + ViewFriendRecords_ToggleDeleteMode(appData, 1); break; case OV121_INPUT_B_BUTTON: case OV121_INPUT_A_BUTTON: PlaySE(SEQ_SE_DP_DECIDE); - Set2dSpriteAnimSeqNo(appData->sprites[OV121_SPRITE_3], 1); + Set2dSpriteAnimSeqNo(appData->sprites[OV121_SPRITE_RETURN], 1); return TRUE; } return FALSE; } -static void ov121_021E6478(Overlay121AppData *appData, Overlay121Input input, int selection) { +static void ViewFriendRecords_HandleInput_SelectRecordToDelete(ViewFriendRecordsAppData *appData, ViewFriendRecordsInput input, int selection) { switch (input) { case OV121_INPUT_NONE: case OV121_INPUT_CURSOR_LEFT: case OV121_INPUT_CURSOR_RIGHT: break; case OV121_INPUT_CURSOR_UP: - ov121_021E6544(appData, -1); + ViewFriendRecords_MoveCursorInDirection(appData, -1); break; case OV121_INPUT_CURSOR_DOWN: - ov121_021E6544(appData, 1); + ViewFriendRecords_MoveCursorInDirection(appData, 1); break; case OV121_INPUT_TAP_RECORD: - ov121_021E65A8(appData, selection); + ViewFriendRecords_TrySetCursorPosition(appData, selection); break; case OV121_INPUT_X_BUTTON: - if (appData->unk_232 < appData->unk_261) { + if (appData->cursorPos < appData->numRecords) { PlaySE(SEQ_SE_DP_DECIDE); - ov121_021E6EC0(appData); + ViewFriendRecords_AskConfirmDeleteRecord(appData); } else { PlaySE(SEQ_SE_DP_DECIDE); - Set2dSpriteAnimSeqNo(appData->sprites[OV121_SPRITE_3], 1); - ov121_021E6690(appData, 0); + Set2dSpriteAnimSeqNo(appData->sprites[OV121_SPRITE_RETURN], 1); + ViewFriendRecords_ToggleDeleteMode(appData, 0); } break; case OV121_INPUT_B_BUTTON: PlaySE(SEQ_SE_DP_DECIDE); - Set2dSpriteAnimSeqNo(appData->sprites[OV121_SPRITE_3], 1); - ov121_021E6690(appData, 0); + Set2dSpriteAnimSeqNo(appData->sprites[OV121_SPRITE_RETURN], 1); + ViewFriendRecords_ToggleDeleteMode(appData, 0); break; case OV121_INPUT_A_BUTTON: - if (appData->unk_232 < appData->unk_261) { + if (appData->cursorPos < appData->numRecords) { PlaySE(SEQ_SE_DP_DECIDE); - ov121_021E6EC0(appData); + ViewFriendRecords_AskConfirmDeleteRecord(appData); } else { PlaySE(SEQ_SE_DP_DECIDE); - Set2dSpriteAnimSeqNo(appData->sprites[OV121_SPRITE_3], 1); - ov121_021E6690(appData, 0); + Set2dSpriteAnimSeqNo(appData->sprites[OV121_SPRITE_RETURN], 1); + ViewFriendRecords_ToggleDeleteMode(appData, 0); } break; } } -static void ov121_021E6544(Overlay121AppData *appData, int direction) { +static void ViewFriendRecords_MoveCursorInDirection(ViewFriendRecordsAppData *appData, int direction) { if (direction > 0) { - if (appData->unk_232 == 6) { - appData->unk_232 = 0; - } else if (appData->unk_232 + direction >= appData->unk_261) { - appData->unk_232 = 6; + if (appData->cursorPos == 6) { + appData->cursorPos = 0; + } else if (appData->cursorPos + direction >= appData->numRecords) { + appData->cursorPos = 6; } else { - appData->unk_232 += direction; + appData->cursorPos += direction; } } else if (direction < 0) { - if (appData->unk_232 == 6) { - appData->unk_232 = appData->unk_261 - 1; - } else if (appData->unk_232 + direction < 0) { - appData->unk_232 = 6; + if (appData->cursorPos == 6) { + appData->cursorPos = appData->numRecords - 1; + } else if (appData->cursorPos + direction < 0) { + appData->cursorPos = 6; } else { - appData->unk_232 += direction; + appData->cursorPos += direction; } } PlaySE(SEQ_SE_DP_SELECT); - ov121_021E65D8(appData); + ViewFriendRecords_DrawCursor(appData); } -static void ov121_021E65A8(Overlay121AppData *appData, int selection) { - if (selection == 6 || selection < appData->unk_261) { +static void ViewFriendRecords_TrySetCursorPosition(ViewFriendRecordsAppData *appData, int selection) { + if (selection == 6 || selection < appData->numRecords) { PlaySE(SEQ_SE_DP_SELECT); - appData->unk_232 = selection; - ov121_021E65D8(appData); + appData->cursorPos = selection; + ViewFriendRecords_DrawCursor(appData); } } -static void ov121_021E65D8(Overlay121AppData *appData) { +static void ViewFriendRecords_DrawCursor(ViewFriendRecordsAppData *appData) { VecFx32 pos = {}; - u8 idx = appData->unk_232; - pos.x = ov121_021E7140[idx].x * FX32_ONE; - pos.y = ov121_021E7140[idx].y * FX32_ONE; - Sprite_SetMatrix(appData->sprites[OV121_SPRITE_0], &pos); - Set2dSpriteAnimSeqNo(appData->sprites[OV121_SPRITE_0], ov121_021E7140[idx].anim); + u8 idx = appData->cursorPos; + pos.x = sCursorPositionParams[idx].x * FX32_ONE; + pos.y = sCursorPositionParams[idx].y * FX32_ONE; + Sprite_SetMatrix(appData->sprites[OV121_SPRITE_CURSOR], &pos); + Set2dSpriteAnimSeqNo(appData->sprites[OV121_SPRITE_CURSOR], sCursorPositionParams[idx].anim); } -static void ov121_021E662C(Overlay121AppData *appData, int direction) { - int new = appData->unk_260 + direction; +static void ViewFriendRecords_SwitchPage(ViewFriendRecordsAppData *appData, int direction) { + int new = appData->recordIdx + direction; if (new < 0) { - new = appData->unk_25E - 1; - } else if (new >= appData->unk_25E) { + new = appData->pageLength - 1; + } else if (new >= appData->pageLength) { new = 0; } - appData->unk_260 = new; + appData->recordIdx = new; PlaySE(SEQ_SE_DP_SELECT78); if (direction > 0) { - Set2dSpriteAnimSeqNo(appData->sprites[OV121_SPRITE_1], 6); + Set2dSpriteAnimSeqNo(appData->sprites[OV121_SPRITE_RIGHT_ARROW], 6); } else if (direction < 0) { - Set2dSpriteAnimSeqNo(appData->sprites[OV121_SPRITE_2], 4); + Set2dSpriteAnimSeqNo(appData->sprites[OV121_SPRITE_LEFT_ARROW], 4); } - Overlay121_PrintRecordStatHeaderText(appData); - appData->state = OV121_STATE_INIT; + ViewFriendRecords_PrintRecordStatHeaderText(appData); + appData->state = OV121_STATE_REDRAW; } -static void ov121_021E6690(Overlay121AppData *appData, BOOL selection) { - appData->unk_231 = selection; - if (selection == 0) { - appData->unk_232 = 6; - Set2dSpriteVisibleFlag(appData->sprites[OV121_SPRITE_1], TRUE); - Set2dSpriteVisibleFlag(appData->sprites[OV121_SPRITE_2], TRUE); - ov121_021E67E4(appData); +static void ViewFriendRecords_ToggleDeleteMode(ViewFriendRecordsAppData *appData, BOOL selection) { + appData->isDeleteMode = selection; + if (selection == FALSE) { + appData->cursorPos = 6; + Set2dSpriteVisibleFlag(appData->sprites[OV121_SPRITE_RIGHT_ARROW], TRUE); + Set2dSpriteVisibleFlag(appData->sprites[OV121_SPRITE_LEFT_ARROW], TRUE); + ViewFriendRecords_HideSelectRecordToDeleteText(appData); } else { - appData->unk_232 = 0; - Set2dSpriteVisibleFlag(appData->sprites[OV121_SPRITE_1], FALSE); - Set2dSpriteVisibleFlag(appData->sprites[OV121_SPRITE_2], FALSE); - Overlay121_PrintSelectRecordToDeleteText(appData); + appData->cursorPos = 0; + Set2dSpriteVisibleFlag(appData->sprites[OV121_SPRITE_RIGHT_ARROW], FALSE); + Set2dSpriteVisibleFlag(appData->sprites[OV121_SPRITE_LEFT_ARROW], FALSE); + ViewFriendRecords_PrintSelectRecordToDeleteText(appData); } - ov121_021E65D8(appData); + ViewFriendRecords_DrawCursor(appData); } -static void Overlay121_CreateWindows(Overlay121AppData *appData) { +static void ViewFriendRecords_CreateWindows(ViewFriendRecordsAppData *appData) { LoadFontPal0(GF_PAL_LOCATION_MAIN_BG, (enum GFPalSlotOffset)0x1E0, HEAP_ID_9E); - AddWindowParameterized(appData->bgConfig, &appData->windows[OV121_WINDOW_0], GF_BG_LYR_MAIN_1, 5, 7, 2, 12, 15, 0x1); - AddWindowParameterized(appData->bgConfig, &appData->windows[OV121_WINDOW_1], GF_BG_LYR_MAIN_1, 7, 7, 20, 12, 15, 0x19); - AddWindowParameterized(appData->bgConfig, &appData->windows[OV121_WINDOW_2], GF_BG_LYR_MAIN_2, 2, 1, 28, 4, 15, 0x109); - AddWindowParameterized(appData->bgConfig, &appData->windows[OV121_WINDOW_3], GF_BG_LYR_MAIN_2, 25, 21, 6, 2, 1, 0x179); - AddWindowParameterized(appData->bgConfig, &appData->windows[OV121_WINDOW_4], GF_BG_LYR_MAIN_2, 4, 21, 12, 2, 1, 0x185); - AddWindowParameterized(appData->bgConfig, &appData->windows[OV121_WINDOW_5], GF_BG_LYR_MAIN_0, 2, 1, 28, 4, 15, 0x1F); + AddWindowParameterized(appData->bgConfig, &appData->windows[OV121_WINDOW_RANKING], GF_BG_LYR_MAIN_1, 5, 7, 2, 12, 15, 0x1); + AddWindowParameterized(appData->bgConfig, &appData->windows[OV121_WINDOW_RECORDS], GF_BG_LYR_MAIN_1, 7, 7, 20, 12, 15, 0x19); + AddWindowParameterized(appData->bgConfig, &appData->windows[OV121_WINDOW_HEADER], GF_BG_LYR_MAIN_2, 2, 1, 28, 4, 15, 0x109); + AddWindowParameterized(appData->bgConfig, &appData->windows[OV121_WINDOW_RETURN], GF_BG_LYR_MAIN_2, 25, 21, 6, 2, 1, 0x179); + AddWindowParameterized(appData->bgConfig, &appData->windows[OV121_WINDOW_DELETE_RECORD], GF_BG_LYR_MAIN_2, 4, 21, 12, 2, 1, 0x185); + AddWindowParameterized(appData->bgConfig, &appData->windows[OV121_WINDOW_SELECT_RECORD_TO_DELETE], GF_BG_LYR_MAIN_0, 2, 1, 28, 4, 15, 0x1F); LoadUserFrameGfx2(appData->bgConfig, GF_BG_LYR_MAIN_0, 0x1, 12, appData->unk_268, HEAP_ID_9E); } -static void ov121_021E67E4(Overlay121AppData *appData) { - ClearFrameAndWindow2(&appData->windows[OV121_WINDOW_5], TRUE); - ClearWindowTilemapAndCopyToVram(&appData->windows[OV121_WINDOW_5]); +static void ViewFriendRecords_HideSelectRecordToDeleteText(ViewFriendRecordsAppData *appData) { + ClearFrameAndWindow2(&appData->windows[OV121_WINDOW_SELECT_RECORD_TO_DELETE], TRUE); + ClearWindowTilemapAndCopyToVram(&appData->windows[OV121_WINDOW_SELECT_RECORD_TO_DELETE]); } -static void ov121_021E67FC(Overlay121AppData *appData, SaveData *saveData) { +static void ov121_021E67FC(ViewFriendRecordsAppData *appData, SaveData *saveData) { int j; int i; BOOL inserted; UnkStruct_0202E9FC *ptr; int cnt; - appData->unk_254 = AllocFromHeap(HEAP_ID_9E, appData->unk_25E * sizeof(Overlay121Sub254)); - MI_CpuClear8(appData->unk_254, appData->unk_25E * sizeof(Overlay121Sub254)); + appData->records = AllocFromHeap(HEAP_ID_9E, appData->pageLength * sizeof(ViewFriendRecordsSub254)); + MI_CpuClear8(appData->records, appData->pageLength * sizeof(ViewFriendRecordsSub254)); appData->unk_238[0] = sub_0202E9FC(saveData, appData->page, HEAP_ID_9E); - for (i = 0; i < appData->unk_25E; ++i) { - appData->unk_238[1 + i] = sub_0202EA80(appData->unk_234, appData->unk_25F + appData->unk_25D * 13 + i, HEAP_ID_9E); + for (i = 0; i < appData->pageLength; ++i) { + appData->unk_238[1 + i] = sub_0202EA80(appData->unk_234, appData->pageOffset + appData->unk_25D * RANKINGS_COUNT + i, HEAP_ID_9E); cnt = 0; inserted = FALSE; ptr = appData->unk_238[1 + i]; if (ptr->count == 0) { - appData->unk_254[i].unk_04[0].unk_00 = &appData->unk_238[0]->unk_04[i]; - appData->unk_254[i].unk_04[0].unk_04 = 1; - appData->unk_254[i].unk_04[0].unk_06 = 0xFF; - appData->unk_254[i].unk_00 = 1; + appData->records[i].entries[0].unk_00 = &appData->unk_238[0]->unk_04[i]; + appData->records[i].entries[0].active = TRUE; + appData->records[i].entries[0].friendIdx = 0xFF; + appData->records[i].count = 1; } else { for (j = 0; j < ptr->count; ++j) { - if (!inserted && appData->unk_238[0]->unk_04[i].unk_4 >= ptr->unk_04[j].unk_4) { - appData->unk_254[i].unk_04[cnt].unk_00 = &appData->unk_238[0]->unk_04[i]; - appData->unk_254[i].unk_04[cnt].unk_04 = 1; - appData->unk_254[i].unk_04[cnt].unk_06 = 0xFF; + if (!inserted && appData->unk_238[0]->unk_04[i].stat >= ptr->unk_04[j].stat) { + appData->records[i].entries[cnt].unk_00 = &appData->unk_238[0]->unk_04[i]; + appData->records[i].entries[cnt].active = TRUE; + appData->records[i].entries[cnt].friendIdx = 0xFF; ++cnt; - appData->unk_254[i].unk_04[cnt].unk_00 = &ptr->unk_04[j]; - appData->unk_254[i].unk_04[cnt].unk_04 = 1; - appData->unk_254[i].unk_04[cnt].unk_06 = j; + appData->records[i].entries[cnt].unk_00 = &ptr->unk_04[j]; + appData->records[i].entries[cnt].active = TRUE; + appData->records[i].entries[cnt].friendIdx = j; inserted = TRUE; } else { - appData->unk_254[i].unk_04[cnt].unk_00 = &ptr->unk_04[j]; - appData->unk_254[i].unk_04[cnt].unk_04 = 1; - appData->unk_254[i].unk_04[cnt].unk_06 = j; + appData->records[i].entries[cnt].unk_00 = &ptr->unk_04[j]; + appData->records[i].entries[cnt].active = TRUE; + appData->records[i].entries[cnt].friendIdx = j; } ++cnt; } if (!inserted) { - appData->unk_254[i].unk_04[cnt].unk_00 = &appData->unk_238[0]->unk_04[i]; - appData->unk_254[i].unk_04[cnt].unk_04 = 1; - appData->unk_254[i].unk_04[cnt].unk_06 = 0xFF; + appData->records[i].entries[cnt].unk_00 = &appData->unk_238[0]->unk_04[i]; + appData->records[i].entries[cnt].active = TRUE; + appData->records[i].entries[cnt].friendIdx = 0xFF; } - appData->unk_254[i].unk_00 = ptr->count + 1; + appData->records[i].count = ptr->count + 1; } } } -static void ov121_021E69F0(Overlay121AppData *appData) { +static void ViewFriendRecords_CreateStrings(ViewFriendRecordsAppData *appData) { appData->msgData = NewMsgDataFromNarc(MSGDATA_LOAD_DIRECT, NARC_msgdata_msg, NARC_msg_msg_0421_bin, HEAP_ID_9E); appData->msgFormat = MessageFormat_New_Custom(2, 76, HEAP_ID_9E); - appData->unk_06C = String_New(76, HEAP_ID_9E); - appData->unk_070 = NewString_ReadMsgData(appData->msgData, msg_0421_00043); - appData->unk_074 = NewString_ReadMsgData(appData->msgData, msg_0421_00042); + appData->formatedStrBuf = String_New(76, HEAP_ID_9E); + appData->playerNameString = NewString_ReadMsgData(appData->msgData, msg_0421_00043); + appData->rankingString = NewString_ReadMsgData(appData->msgData, msg_0421_00042); for (int i = 0; i < 7; ++i) { - appData->unk_078[i] = NewString_ReadMsgData(appData->msgData, msg_0421_00044 + i); + appData->miscStrings[i] = NewString_ReadMsgData(appData->msgData, msg_0421_00044 + i); } } -static void ov121_021E6A4C(Overlay121AppData *appData) { +static void ViewFriendRecords_DeleteStrings(ViewFriendRecordsAppData *appData) { for (int i = 0; i < 7; ++i) { - String_Delete(appData->unk_078[i]); + String_Delete(appData->miscStrings[i]); } - String_Delete(appData->unk_070); - String_Delete(appData->unk_074); - String_Delete(appData->unk_06C); + String_Delete(appData->playerNameString); + String_Delete(appData->rankingString); + String_Delete(appData->formatedStrBuf); MessageFormat_Delete(appData->msgFormat); DestroyMsgData(appData->msgData); } -static void ov121_021E6A84(Overlay121AppData *appData) { +static void ViewFriendRecords_PrintRecords(ViewFriendRecordsAppData *appData) { int i; - int sp18; - int sp14; - const UnkStruct_ov121_021E7014 *sp10; - Overlay121Sub254 *sp24_plus_sp20; - int r0; - int r5; + int ranking; + int y; + const RecordPageParam *sp10; + ViewFriendRecordsSub254 *pRecord; + int prev; + int cur; - sp24_plus_sp20= &appData->unk_254[appData->unk_260]; - sp10 = &ov121_021E7014[appData->page][appData->unk_260]; + pRecord= &appData->records[appData->recordIdx]; + sp10 = &sRecordPageParams[appData->page][appData->recordIdx]; - FillWindowPixelBuffer(&appData->windows[OV121_WINDOW_1], 0); - FillWindowPixelBuffer(&appData->windows[OV121_WINDOW_0], 0); - sp18 = 1; - sp14 = 0; - r0 = 0; + FillWindowPixelBuffer(&appData->windows[OV121_WINDOW_RECORDS], 0); + FillWindowPixelBuffer(&appData->windows[OV121_WINDOW_RANKING], 0); + ranking = 1; + y = 0; + prev = 0; i = 0; - appData->unk_261 = 0; - for (; i < sp24_plus_sp20->unk_00; ++i) { - if (sp24_plus_sp20->unk_04[i].unk_04 != 0) { - r5 = min(sp24_plus_sp20->unk_04[i].unk_00->unk_4, sp10->unk_0); - if (r5 < r0) { - ++sp18; + appData->numRecords = 0; + for (; i < pRecord->count; ++i) { + if (pRecord->entries[i].active != 0) { + cur = min(pRecord->entries[i].unk_00->stat, sp10->max); + if (cur < prev) { + ++ranking; } - BufferIntegerAsString(appData->msgFormat, 0, sp18, 1, PRINTING_MODE_RIGHT_ALIGN, TRUE); - StringExpandPlaceholders(appData->msgFormat, appData->unk_06C, appData->unk_074); - AddTextPrinterParameterizedWithColor(&appData->windows[OV121_WINDOW_0], 0, appData->unk_06C, 0, 16 * sp14, TEXT_SPEED_NOTRANSFER, MAKE_TEXT_COLOR(1, 2, 0), NULL); + BufferIntegerAsString(appData->msgFormat, 0, ranking, 1, PRINTING_MODE_RIGHT_ALIGN, TRUE); + StringExpandPlaceholders(appData->msgFormat, appData->formatedStrBuf, appData->rankingString); + AddTextPrinterParameterizedWithColor(&appData->windows[OV121_WINDOW_RANKING], 0, appData->formatedStrBuf, 0, 16 * y, TEXT_SPEED_NOTRANSFER, MAKE_TEXT_COLOR(1, 2, 0), NULL); - BufferString(appData->msgFormat, 1, sp24_plus_sp20->unk_04[i].unk_00->playerName, 2, 1, 2); - StringExpandPlaceholders(appData->msgFormat, appData->unk_06C, appData->unk_070); - AddTextPrinterParameterizedWithColor(&appData->windows[OV121_WINDOW_1], 0, appData->unk_06C, 0, 16 * sp14, TEXT_SPEED_NOTRANSFER, MAKE_TEXT_COLOR(1, 2, 0), NULL); + BufferString(appData->msgFormat, 1, pRecord->entries[i].unk_00->playerName, 2, 1, 2); + StringExpandPlaceholders(appData->msgFormat, appData->formatedStrBuf, appData->playerNameString); + AddTextPrinterParameterizedWithColor(&appData->windows[OV121_WINDOW_RECORDS], 0, appData->formatedStrBuf, 0, 16 * y, TEXT_SPEED_NOTRANSFER, MAKE_TEXT_COLOR(1, 2, 0), NULL); - BufferIntegerAsString(appData->msgFormat, 0, r5, sp10->unk_4, PRINTING_MODE_RIGHT_ALIGN, TRUE); - StringExpandPlaceholders(appData->msgFormat, appData->unk_06C, appData->unk_078[sp10->unk_6 - 44]); - AddTextPrinterParameterizedWithColor(&appData->windows[OV121_WINDOW_1], 0, appData->unk_06C, 160 - FontID_String_GetWidth(0, appData->unk_06C, 0), 16 * sp14, TEXT_SPEED_NOTRANSFER, MAKE_TEXT_COLOR(1, 2, 0), NULL); + BufferIntegerAsString(appData->msgFormat, 0, cur, sp10->numDigits, PRINTING_MODE_RIGHT_ALIGN, TRUE); + StringExpandPlaceholders(appData->msgFormat, appData->formatedStrBuf, appData->miscStrings[sp10->msgId - msg_0421_00044]); + AddTextPrinterParameterizedWithColor(&appData->windows[OV121_WINDOW_RECORDS], 0, appData->formatedStrBuf, 160 - FontID_String_GetWidth(0, appData->formatedStrBuf, 0), 16 * y, TEXT_SPEED_NOTRANSFER, MAKE_TEXT_COLOR(1, 2, 0), NULL); - appData->unk_262[sp14] = i; - r0 = r5; - if (++sp14 >= 6) { + appData->recordEntryIdxs[y] = i; + prev = cur; + if (++y >= 6) { break; } } } - CopyWindowToVram(&appData->windows[OV121_WINDOW_1]); - CopyWindowToVram(&appData->windows[OV121_WINDOW_0]); - appData->unk_261 = sp14; - if (appData->unk_231 == 1 && appData->unk_232 >= appData->unk_261) { - GF_ASSERT(appData->unk_232 != 7); - appData->unk_232 = appData->unk_261 - 1; - ov121_021E65D8(appData); + CopyWindowToVram(&appData->windows[OV121_WINDOW_RECORDS]); + CopyWindowToVram(&appData->windows[OV121_WINDOW_RANKING]); + appData->numRecords = y; + if (appData->isDeleteMode == 1 && appData->cursorPos >= appData->numRecords) { + GF_ASSERT(appData->cursorPos != 7); + appData->cursorPos = appData->numRecords - 1; + ViewFriendRecords_DrawCursor(appData); } } -static void Overlay121_PrintDeleteRecordText(Overlay121AppData *appData) { - FillWindowPixelBuffer(&appData->windows[OV121_WINDOW_4], 0); +static void ViewFriendRecords_PrintDeleteRecordText(ViewFriendRecordsAppData *appData) { + FillWindowPixelBuffer(&appData->windows[OV121_WINDOW_DELETE_RECORD], 0); String *string = NewString_ReadMsgData(appData->msgData, msg_0421_00040); - AddTextPrinterParameterizedWithColor(&appData->windows[OV121_WINDOW_4], 4, string, 0, 0, TEXT_SPEED_NOTRANSFER, MAKE_TEXT_COLOR(3, 1, 0), NULL); + AddTextPrinterParameterizedWithColor(&appData->windows[OV121_WINDOW_DELETE_RECORD], 4, string, 0, 0, TEXT_SPEED_NOTRANSFER, MAKE_TEXT_COLOR(3, 1, 0), NULL); String_Delete(string); - CopyWindowToVram(&appData->windows[OV121_WINDOW_4]); + CopyWindowToVram(&appData->windows[OV121_WINDOW_DELETE_RECORD]); } -static void Overlay121_PrintReturnText(Overlay121AppData *appData) { - FillWindowPixelBuffer(&appData->windows[OV121_WINDOW_3], 0); +static void ViewFriendRecords_PrintReturnText(ViewFriendRecordsAppData *appData) { + FillWindowPixelBuffer(&appData->windows[OV121_WINDOW_RETURN], 0); String *string = NewString_ReadMsgData(appData->msgData, msg_0421_00041); - AddTextPrinterParameterizedWithColor(&appData->windows[OV121_WINDOW_3], 4, string, 0, 0, TEXT_SPEED_NOTRANSFER, MAKE_TEXT_COLOR(3, 1, 0), NULL); + AddTextPrinterParameterizedWithColor(&appData->windows[OV121_WINDOW_RETURN], 4, string, 0, 0, TEXT_SPEED_NOTRANSFER, MAKE_TEXT_COLOR(3, 1, 0), NULL); String_Delete(string); - CopyWindowToVram(&appData->windows[OV121_WINDOW_3]); + CopyWindowToVram(&appData->windows[OV121_WINDOW_RETURN]); } -static void Overlay121_PrintDeleteXsRecordAreYouSure(Overlay121AppData *appData) { - Overlay121Sub254 *r6; +static void ViewFriendRecords_PrintDeleteXsRecordAreYouSure(ViewFriendRecordsAppData *appData) { + ViewFriendRecordsSub254 *r6; u8 r4; String *string; - r4 = appData->unk_262[appData->unk_232]; - r6 = &appData->unk_254[appData->unk_260]; - DrawFrameAndWindow2(&appData->windows[OV121_WINDOW_5], TRUE, 0x1, 12); - FillWindowPixelBuffer(&appData->windows[OV121_WINDOW_5], 0xFF); - BufferString(appData->msgFormat, 0, r6->unk_04[r4].unk_00->playerName, 2, 1, 2); + r4 = appData->recordEntryIdxs[appData->cursorPos]; + r6 = &appData->records[appData->recordIdx]; + DrawFrameAndWindow2(&appData->windows[OV121_WINDOW_SELECT_RECORD_TO_DELETE], TRUE, 0x1, 12); + FillWindowPixelBuffer(&appData->windows[OV121_WINDOW_SELECT_RECORD_TO_DELETE], 0xFF); + BufferString(appData->msgFormat, 0, r6->entries[r4].unk_00->playerName, 2, 1, 2); string = ReadMsgData_ExpandPlaceholders(appData->msgFormat, appData->msgData, msg_0421_00049, HEAP_ID_9E); - AddTextPrinterParameterizedWithColor(&appData->windows[OV121_WINDOW_5], 0, string, 0, 0, TEXT_SPEED_NOTRANSFER, MAKE_TEXT_COLOR(1, 2, 0), NULL); + AddTextPrinterParameterizedWithColor(&appData->windows[OV121_WINDOW_SELECT_RECORD_TO_DELETE], 0, string, 0, 0, TEXT_SPEED_NOTRANSFER, MAKE_TEXT_COLOR(1, 2, 0), NULL); String_Delete(string); - CopyWindowToVram(&appData->windows[OV121_WINDOW_5]); + CopyWindowToVram(&appData->windows[OV121_WINDOW_SELECT_RECORD_TO_DELETE]); } -static void Overlay121_PrintYourOwnRecordCantBeDeleted(Overlay121AppData *appData) { +static void ViewFriendRecords_PrintYourOwnRecordCantBeDeleted(ViewFriendRecordsAppData *appData) { String *string; - DrawFrameAndWindow2(&appData->windows[OV121_WINDOW_5], TRUE, 0x1, 12); - FillWindowPixelBuffer(&appData->windows[OV121_WINDOW_5], 0xFF); + DrawFrameAndWindow2(&appData->windows[OV121_WINDOW_SELECT_RECORD_TO_DELETE], TRUE, 0x1, 12); + FillWindowPixelBuffer(&appData->windows[OV121_WINDOW_SELECT_RECORD_TO_DELETE], 0xFF); string = NewString_ReadMsgData(appData->msgData, msg_0421_00052); - AddTextPrinterParameterizedWithColor(&appData->windows[OV121_WINDOW_5], 0, string, 0, 0, TEXT_SPEED_NOTRANSFER, MAKE_TEXT_COLOR(1, 2, 0), NULL); + AddTextPrinterParameterizedWithColor(&appData->windows[OV121_WINDOW_SELECT_RECORD_TO_DELETE], 0, string, 0, 0, TEXT_SPEED_NOTRANSFER, MAKE_TEXT_COLOR(1, 2, 0), NULL); String_Delete(string); - CopyWindowToVram(&appData->windows[OV121_WINDOW_5]); + CopyWindowToVram(&appData->windows[OV121_WINDOW_SELECT_RECORD_TO_DELETE]); } -static void Overlay121_PrintRecordStatHeaderText(Overlay121AppData *appData) { +static void ViewFriendRecords_PrintRecordStatHeaderText(ViewFriendRecordsAppData *appData) { String *string; String *string2; int msgNo; - FillWindowPixelBuffer(&appData->windows[OV121_WINDOW_2], 0); - msgNo = (appData->page == 0 ? msg_0421_00053 : msg_0421_00065) + appData->unk_260 * 2; + FillWindowPixelBuffer(&appData->windows[OV121_WINDOW_HEADER], 0); + msgNo = (appData->page == 0 ? msg_0421_00053 : msg_0421_00065) + appData->recordIdx * 2; string = NewString_ReadMsgData(appData->msgData, msgNo); string2 = NewString_ReadMsgData(appData->msgData, msgNo + 1); - AddTextPrinterParameterizedWithColor(&appData->windows[OV121_WINDOW_2], 0, string, 0, 0, TEXT_SPEED_NOTRANSFER, MAKE_TEXT_COLOR(1, 2, 0), NULL); - AddTextPrinterParameterizedWithColor(&appData->windows[OV121_WINDOW_2], 0, string2, 0, 16, TEXT_SPEED_NOTRANSFER, MAKE_TEXT_COLOR(1, 2, 0), NULL); + AddTextPrinterParameterizedWithColor(&appData->windows[OV121_WINDOW_HEADER], 0, string, 0, 0, TEXT_SPEED_NOTRANSFER, MAKE_TEXT_COLOR(1, 2, 0), NULL); + AddTextPrinterParameterizedWithColor(&appData->windows[OV121_WINDOW_HEADER], 0, string2, 0, 16, TEXT_SPEED_NOTRANSFER, MAKE_TEXT_COLOR(1, 2, 0), NULL); String_Delete(string); String_Delete(string2); - CopyWindowToVram(&appData->windows[OV121_WINDOW_2]); + CopyWindowToVram(&appData->windows[OV121_WINDOW_HEADER]); } -static void Overlay121_PrintSelectRecordToDeleteText(Overlay121AppData *appData) { +static void ViewFriendRecords_PrintSelectRecordToDeleteText(ViewFriendRecordsAppData *appData) { String *string; - DrawFrameAndWindow2(&appData->windows[OV121_WINDOW_5], TRUE, 0x1, 12); - FillWindowPixelBuffer(&appData->windows[OV121_WINDOW_5], 0xFF); + DrawFrameAndWindow2(&appData->windows[OV121_WINDOW_SELECT_RECORD_TO_DELETE], TRUE, 0x1, 12); + FillWindowPixelBuffer(&appData->windows[OV121_WINDOW_SELECT_RECORD_TO_DELETE], 0xFF); string = NewString_ReadMsgData(appData->msgData, msg_0421_00048); - AddTextPrinterParameterizedWithColor(&appData->windows[OV121_WINDOW_5], 0, string, 0, 0, TEXT_SPEED_NOTRANSFER, MAKE_TEXT_COLOR(1, 2, 0), NULL); + AddTextPrinterParameterizedWithColor(&appData->windows[OV121_WINDOW_SELECT_RECORD_TO_DELETE], 0, string, 0, 0, TEXT_SPEED_NOTRANSFER, MAKE_TEXT_COLOR(1, 2, 0), NULL); String_Delete(string); - CopyWindowToVram(&appData->windows[OV121_WINDOW_5]); + CopyWindowToVram(&appData->windows[OV121_WINDOW_SELECT_RECORD_TO_DELETE]); } -static void ov121_021E6EC0(Overlay121AppData *appData) { +static void ViewFriendRecords_AskConfirmDeleteRecord(ViewFriendRecordsAppData *appData) { YesNoPromptTemplate template; - appData->unk_258 = &appData->unk_254[appData->unk_260].unk_04[appData->unk_262[appData->unk_232]]; - if (appData->unk_258->unk_06 == 0xFF) { - appData->state = OV121_STATE_3; - Overlay121_PrintYourOwnRecordCantBeDeleted(appData); + appData->recordToDelete = &appData->records[appData->recordIdx].entries[appData->recordEntryIdxs[appData->cursorPos]]; + if (appData->recordToDelete->friendIdx == 0xFF) { + appData->state = OV121_STATE_DELETE_FAILED_CANT_DELETE_OWN; + ViewFriendRecords_PrintYourOwnRecordCantBeDeleted(appData); PlaySE(SEQ_SE_DP_CUSTOM06); } else { MI_CpuClear8(&template, sizeof(YesNoPromptTemplate)); @@ -1152,7 +1165,7 @@ static void ov121_021E6EC0(Overlay121AppData *appData) { template.x = 25; template.y = 6; YesNoPrompt_InitFromTemplate(appData->yesNoPrompt, &template); - Overlay121_PrintDeleteXsRecordAreYouSure(appData); + ViewFriendRecords_PrintDeleteXsRecordAreYouSure(appData); dimAllMainBgsExceptLyr0(); appData->state = OV121_STATE_YESNO; } @@ -1169,18 +1182,18 @@ static void resetMainBgsBrightness(void) { G2_BlendNone(); } -static void ov121_021E6F78(Overlay121AppData *appData) { +static void ViewFriendRecordsApp_CommitChanges(ViewFriendRecordsAppData *appData) { int i; int j; - int r6; - Overlay121Sub258 *r1; - for (i = 0; i < appData->unk_25E; ++i) { - r6 = 0; - for (j = 0; j < appData->unk_254[i].unk_00; ++j) { - r1 = &appData->unk_254[i].unk_04[j]; - if (r1->unk_06 != 0xFF && r1->unk_04 == 0) { - sub_0202E544(appData->unk_234, appData->unk_25F + appData->unk_25D * 13 + i, r1->unk_06 - r6); - ++r6; + int count; + ViewFriendRecordsSub258 *r1; + for (i = 0; i < appData->pageLength; ++i) { + count = 0; + for (j = 0; j < appData->records[i].count; ++j) { + r1 = &appData->records[i].entries[j]; + if (r1->friendIdx != 0xFF && r1->active == FALSE) { + sub_0202E544(appData->unk_234, appData->pageOffset + appData->unk_25D * RANKINGS_COUNT + i, r1->friendIdx - count); + ++count; } } } diff --git a/src/save_arrays.c b/src/save_arrays.c index b89ea9c8a..7f6256d04 100644 --- a/src/save_arrays.c +++ b/src/save_arrays.c @@ -169,10 +169,10 @@ const struct SaveChunkHeader gSaveChunkHeaders[] = { (SAVESIZEFN)sub_0202E41C, (SAVEINITFN)sub_0202E424 }, { - SAVE_UNK_24, + SAVE_RANKINGS, 0, - (SAVESIZEFN)sub_0202E4F4, - (SAVEINITFN)sub_0202E4FC + (SAVESIZEFN)Save_Rankings_sizeof, + (SAVEINITFN)Save_Rankings_Init }, { SAVE_UNK_25, 0, diff --git a/src/scrcmd_c.c b/src/scrcmd_c.c index 3410fcdd0..593033df5 100644 --- a/src/scrcmd_c.c +++ b/src/scrcmd_c.c @@ -3239,10 +3239,10 @@ BOOL ScrCmd_377(ScriptContext *ctx) { return FALSE; } -BOOL ScrCmd_378(ScriptContext *ctx) { - u16 r4 = ScriptGetVar(ctx); - u16 r2 = ScriptGetVar(ctx); - sub_02097D3C(ctx->fieldSystem, r4, r2); +BOOL ScrCmd_ViewFriendRecords(ScriptContext *ctx) { + u16 pageScrollParam = ScriptGetVar(ctx); + u16 cursorPos = ScriptGetVar(ctx); + FieldSystem_LaunchTask_ViewFriendRecordsApp(ctx->fieldSystem, pageScrollParam, cursorPos); return TRUE; } diff --git a/src/unk_0202E4B0.c b/src/unk_0202E4B0.c index 6b8459b4f..a5dc9b053 100644 --- a/src/unk_0202E4B0.c +++ b/src/unk_0202E4B0.c @@ -9,15 +9,16 @@ #include "unk_02030A98.h" #include "unk_0202E4B0.h" #include "constants/game_stats.h" +#include "constants/ranking.h" -struct UnkStruct_0202E4B0_sub { - int unk_00; - u32 unk_04; +struct SaveRankingsEntry { + int groupId; + u32 stat; u16 playerName[PLAYER_NAME_LENGTH + 1]; }; -struct UnkStruct_0202E4B0 { - UnkStruct_0202E4B0_sub unk_000[26][6]; +struct SaveRankings { + SaveRankingsEntry array[26][6]; }; typedef struct UnkStruct_0202E920_sub { @@ -25,101 +26,106 @@ typedef struct UnkStruct_0202E920_sub { } UnkStruct_0202E920_sub; typedef struct UnkStruct_0202E920 { - int unk_00; - int unk_04; - int unk_08; - UnkStruct_0202E4B0_sub *unk_0C[11]; - UnkStruct_0202E4B0_sub *unk_38[6]; - UnkStruct_0202E4B0_sub unk_50[6]; + int count_sub2; + int count_sub1; + int count_total; + SaveRankingsEntry *rankings[11]; + SaveRankingsEntry *unk_38[6]; + SaveRankingsEntry unk_50[6]; } UnkStruct_0202E920; -static void sub_0202E4C8(UnkStruct_0202E4B0_sub *a0); -static BOOL sub_0202E4E0(UnkStruct_0202E4B0_sub *a0); -static u32 *sub_0202E594(SaveData *saveData, HeapID heapId); -static void sub_0202E6F0(UnkStruct_0202E4B0_sub *a0); -static BOOL sub_0202E708(const UnkStruct_0202E4B0_sub *a0, const UnkStruct_0202E4B0_sub *a1); -static BOOL sub_0202E72C(const UnkStruct_0202E920 *a0, const UnkStruct_0202E4B0_sub *a1); -static void sub_0202E75C(UnkStruct_0202E4B0 *a0, UnkStruct_0202E920 *a1, int a2, u8 a3, u8 a4, UnkStruct_0202E4B0_sub **a5, u8 a6, HeapID heapId); -static void sub_0202E920(UnkStruct_0202E4B0 *a0, int a1, u8 a2, UnkStruct_0202E4B0_sub **a3, u8 a4, HeapID heapId); +static void RankingEntry_Init(SaveRankingsEntry *a0); +static BOOL sub_0202E4E0(SaveRankingsEntry *a0); +static u32 *Save_RankingSys_GetPlayerStats(SaveData *saveData, HeapID heapId); +static void SaveRankingsEntry_InitArrayOf6(SaveRankingsEntry *a0); +static BOOL SaveRankingsEntry_TestEqual(const SaveRankingsEntry *a0, const SaveRankingsEntry *a1); +static BOOL sub_0202E72C(const UnkStruct_0202E920 *a0, const SaveRankingsEntry *a1); +static void sub_0202E75C(SaveRankings *a0, UnkStruct_0202E920 *a1, int a2, u8 a3, u8 a4, SaveRankingsEntry **a5, u8 a6, HeapID heapId); +static void sub_0202E920(SaveRankings *a0, int a1, u8 a2, SaveRankingsEntry **a3, u8 a4, HeapID heapId); static const u8 sPageOffsets[][2] = { - { 6, 0 }, - { 4, 6 }, - { 3, 10 }, + { RANKINGS_RECORD_BATTLE_TOWER_COUNT, RANKINGS_RECORD_BATTLE_TOWER_BEGIN }, + { RANKINGS_RECORD_POKEMON_COUNT, RANKINGS_RECORD_POKEMON_BEGIN }, + { RANKINGS_RECORD_CONTEST_COUNT, RANKINGS_RECORD_CONTEST_BEGIN }, }; static const int sStatIDs[] = { - 0, - 2, - 4, - 6, - 8, + // Battle Tower + 0, // Battle Tower singles + 2, // Battle Tower doubles + 4, // Battle Tower multi with NPC partner + 6, // Battle Tower multi with friend + 8, // Battle Tower WiFi GAME_STAT_BATTLE_TOWER_WIN_COUNT, + + // Adventure GAME_STAT_OPPONENT_MON_FAINTED, - GAME_STAT_UNK10, - GAME_STAT_UNK12, - GAME_STAT_UNK11, - GAME_STAT_UNK93, - GAME_STAT_UNK91, - GAME_STAT_UNK95, + GAME_STAT_CAUGHT_MON, + GAME_STAT_HATCHED_EGG, + GAME_STAT_FISHING_LANDED_MON, + + // Contest (unused in HGSS) + GAME_STAT_LOCAL_CONTEST_WINS, + GAME_STAT_LOCAL_CONTEST_ENTRIES, + GAME_STAT_RIBBONS_EARNED, }; -u8 sub_0202E4B0(int page) { +u8 RankingsViewSys_GetNumRecordsPerPage(int page) { return sPageOffsets[page][0]; } -u8 sub_0202E4BC(int page) { +u8 RankingsViewSys_GetFirstRecordIndexOnPage(int page) { return sPageOffsets[page][1]; } -static void sub_0202E4C8(UnkStruct_0202E4B0_sub *a0) { - a0->unk_00 = 0; - a0->unk_04 = 0; +static void RankingEntry_Init(SaveRankingsEntry *a0) { + a0->groupId = 0; + a0->stat = 0; StringFillEOS(a0->playerName, PLAYER_NAME_LENGTH + 1); - SaveSubstruct_UpdateCRC(SAVE_UNK_24); + SaveSubstruct_UpdateCRC(SAVE_RANKINGS); } -static BOOL sub_0202E4E0(UnkStruct_0202E4B0_sub *a0) { +static BOOL sub_0202E4E0(SaveRankingsEntry *a0) { return StringLength(a0->playerName) != 0; } -u32 sub_0202E4F4(void) { - return sizeof(UnkStruct_0202E4B0); +u32 Save_Rankings_sizeof(void) { + return sizeof(SaveRankings); } -void sub_0202E4FC(UnkStruct_0202E4B0 *a0) { - MI_CpuClear8(a0, sizeof(UnkStruct_0202E4B0)); +void Save_Rankings_Init(SaveRankings *a0) { + MI_CpuClear8(a0, sizeof(SaveRankings)); for (int i = 0; i < 26; ++i) { for (int j = 0; j < 6; ++j) { - sub_0202E4C8(&a0->unk_000[i][j]); + RankingEntry_Init(&a0->array[i][j]); } } - SaveSubstruct_UpdateCRC(SAVE_UNK_24); + SaveSubstruct_UpdateCRC(SAVE_RANKINGS); } -UnkStruct_0202E4B0 *sub_0202E530(SaveData *saveData) { - SaveSubstruct_AssertCRC(SAVE_UNK_24); - return SaveArray_Get(saveData, SAVE_UNK_24); +SaveRankings *sub_0202E530(SaveData *saveData) { + SaveSubstruct_AssertCRC(SAVE_RANKINGS); + return SaveArray_Get(saveData, SAVE_RANKINGS); } -void sub_0202E544(UnkStruct_0202E4B0 *a0, int a1, u8 a2) { +void sub_0202E544(SaveRankings *a0, int a1, u8 a2) { if (a2 >= 6) { GF_ASSERT(a2 < 6); return; } - UnkStruct_0202E4B0_sub *r6 = a0->unk_000[a1]; + SaveRankingsEntry *r6 = a0->array[a1]; for (int i = a2; i < 5; ++i) { r6[i] = r6[i + 1]; } - sub_0202E4C8(&r6[5]); - SaveSubstruct_UpdateCRC(SAVE_UNK_24); + RankingEntry_Init(&r6[5]); + SaveSubstruct_UpdateCRC(SAVE_RANKINGS); } u32 sub_0202E58C(void) { return 0x138; // TODO: what is this? } -static u32 *sub_0202E594(SaveData *saveData, HeapID heapId) { +static u32 *Save_RankingSys_GetPlayerStats(SaveData *saveData, HeapID heapId) { int i; u32 val; GAME_STATS *gameStats; @@ -130,9 +136,9 @@ static u32 *sub_0202E594(SaveData *saveData, HeapID heapId) { frontierSave = Save_Frontier_GetStatic(saveData); ret = AllocFromHeapAtEnd(heapId, 13 * sizeof(u32)); - for (i = 0; i < 13; ++i) { + for (i = 0; i < RANKINGS_COUNT; ++i) { switch (i) { - case 5: { + case RANKINGS_RECORD_BATTLE_TOWER_AVG_WIN_STREAK: { val = GameStats_GetCapped(gameStats, GAME_STAT_UNK16); if (val != 0) { val = GameStats_GetCapped(gameStats, GAME_STAT_BATTLE_TOWER_WIN_COUNT) / val; @@ -140,15 +146,15 @@ static u32 *sub_0202E594(SaveData *saveData, HeapID heapId) { ret[i] = val; break; } - case 10: { - val = GameStats_GetCapped(gameStats, GAME_STAT_UNK93); - val += GameStats_GetCapped(gameStats, GAME_STAT_UNK94); + case RANKINGS_RECORD_CONTEST_WIN: { + val = GameStats_GetCapped(gameStats, GAME_STAT_LOCAL_CONTEST_WINS); + val += GameStats_GetCapped(gameStats, GAME_STAT_COMM_CONTEST_WINS); ret[i] = val; break; } - case 11: { - val = GameStats_GetCapped(gameStats, GAME_STAT_UNK91); - val += GameStats_GetCapped(gameStats, GAME_STAT_UNK92); + case RANKINGS_RECORD_CONTEST_ENTRY: { + val = GameStats_GetCapped(gameStats, GAME_STAT_LOCAL_CONTEST_ENTRIES); + val += GameStats_GetCapped(gameStats, GAME_STAT_COMM_CONTEST_ENTRIES); if (val != 0) { val = ret[10] * 100 / val; } @@ -164,53 +170,53 @@ static u32 *sub_0202E594(SaveData *saveData, HeapID heapId) { break; } } - SaveSubstruct_UpdateCRC(SAVE_UNK_24); + SaveSubstruct_UpdateCRC(SAVE_RANKINGS); return ret; } -UnkStruct_0202E4B0_sub *sub_0202E66C(SaveData *saveData, HeapID heapId) { +SaveRankingsEntry *Save_GetPlayerRankingEntry(SaveData *saveData, HeapID heapId) { int i; - int sp8; - UnkStruct_0202E4B0_sub *ret; + int groupId; + SaveRankingsEntry *ret; u32 *tmp; String *name; PlayerProfile *profile; profile = Save_PlayerData_GetProfileAddr(saveData); - ret = AllocFromHeapAtEnd(heapId, 13 * sizeof(UnkStruct_0202E4B0_sub)); - MI_CpuClear8(ret, 13 * sizeof(UnkStruct_0202E4B0_sub)); - sp8 = sub_0202C7B4(Save_FriendGroup_Get(saveData), 1); + ret = AllocFromHeapAtEnd(heapId, 13 * sizeof(SaveRankingsEntry)); + MI_CpuClear8(ret, 13 * sizeof(SaveRankingsEntry)); + groupId = Save_FriendGroup_GetGroupId(Save_FriendGroup_Get(saveData), 1); name = PlayerProfile_GetPlayerName_NewString(profile, heapId); - tmp = sub_0202E594(saveData, heapId); + tmp = Save_RankingSys_GetPlayerStats(saveData, heapId); - for (i = 0; i < 13; ++i) { - ret[i].unk_00 = sp8; + for (i = 0; i < RANKINGS_COUNT; ++i) { + ret[i].groupId = groupId; CopyStringToU16Array(name, ret[i].playerName, PLAYER_NAME_LENGTH + 1); - ret[i].unk_04 = tmp[i]; + ret[i].stat = tmp[i]; } FreeToHeap(tmp); String_Delete(name); - SaveSubstruct_UpdateCRC(SAVE_UNK_24); + SaveSubstruct_UpdateCRC(SAVE_RANKINGS); return ret; } -static void sub_0202E6F0(UnkStruct_0202E4B0_sub *a0) { +static void SaveRankingsEntry_InitArrayOf6(SaveRankingsEntry *entries) { for (int i = 0; i < 6; ++i) { - sub_0202E4C8(&a0[i]); + RankingEntry_Init(&entries[i]); } } -static BOOL sub_0202E708(const UnkStruct_0202E4B0_sub *a0, const UnkStruct_0202E4B0_sub *a1) { - if (a0->unk_00 != a1->unk_00) { +static BOOL SaveRankingsEntry_TestEqual(const SaveRankingsEntry *lhs, const SaveRankingsEntry *rhs) { + if (lhs->groupId != rhs->groupId) { return FALSE; } - return !StringNotEqual(a0->playerName, a1->playerName); + return !StringNotEqual(lhs->playerName, rhs->playerName); } -static BOOL sub_0202E72C(const UnkStruct_0202E920 *a0, const UnkStruct_0202E4B0_sub *a1) { - for (int i = 0; i < a0->unk_04; ++i) { - if (sub_0202E708(a0->unk_0C[i], a1)) { +static BOOL sub_0202E72C(const UnkStruct_0202E920 *a0, const SaveRankingsEntry *a1) { + for (int i = 0; i < a0->count_sub1; ++i) { + if (SaveRankingsEntry_TestEqual(a0->rankings[i], a1)) { return TRUE; } } @@ -218,74 +224,74 @@ static BOOL sub_0202E72C(const UnkStruct_0202E920 *a0, const UnkStruct_0202E4B0_ return FALSE; } -static void sub_0202E75C(UnkStruct_0202E4B0 *a0, UnkStruct_0202E920 *a1, int a2, u8 a3, u8 a4, UnkStruct_0202E4B0_sub **a5, u8 a6, HeapID unused) { - UnkStruct_0202E4B0_sub *sp8; +static void sub_0202E75C(SaveRankings *saveRankings, UnkStruct_0202E920 *a1, int a2, u8 statIdx, u8 scope, SaveRankingsEntry **a5, u8 a6, HeapID unused) { + SaveRankingsEntry *saveRecordsPtr; int i; int j; MI_CpuClear8(a1, sizeof(UnkStruct_0202E920)); - if (a4 == 0) { - sp8 = a0->unk_000[a3]; - MI_CpuCopy8(sp8, a1->unk_50, 6 * sizeof(UnkStruct_0202E4B0_sub)); + if (scope == RANKINGS_SCOPE_GLOBAL) { + saveRecordsPtr = saveRankings->array[statIdx]; + MI_CpuCopy8(saveRecordsPtr, a1->unk_50, 6 * sizeof(SaveRankingsEntry)); for (i = 0; i < a6; ++i) { - a1->unk_0C[a1->unk_04++] = &a5[i][a3]; + a1->rankings[a1->count_sub1++] = &a5[i][statIdx]; } for (i = 0; i < 6; ++i) { if (sub_0202E4E0(&a1->unk_50[i]) && !sub_0202E72C(a1, &a1->unk_50[i])) { - a1->unk_38[a1->unk_00++] = &a1->unk_50[i]; + a1->unk_38[a1->count_sub2++] = &a1->unk_50[i]; } } } else { - sp8 = a0->unk_000[a3 + 13]; - MI_CpuCopy8(sp8, a1->unk_50, 6 * sizeof(UnkStruct_0202E4B0_sub)); + saveRecordsPtr = saveRankings->array[statIdx + RANKINGS_COUNT]; + MI_CpuCopy8(saveRecordsPtr, a1->unk_50, 6 * sizeof(SaveRankingsEntry)); for (i = 0; i < a6; ++i) { - if (a5[i][a3].unk_00 != 0 && a2 == a5[i][a3].unk_00) { - a1->unk_0C[a1->unk_04++] = &a5[i][a3]; + if (a5[i][statIdx].groupId != 0 && a2 == a5[i][statIdx].groupId) { + a1->rankings[a1->count_sub1++] = &a5[i][statIdx]; } } for (i = 0; i < 6; ++i) { - if (sub_0202E4E0(&a1->unk_50[i]) && a1->unk_50[i].unk_00 == a2 && !sub_0202E72C(a1, &a1->unk_50[i])) { - a1->unk_38[a1->unk_00++] = &a1->unk_50[i]; + if (sub_0202E4E0(&a1->unk_50[i]) && a1->unk_50[i].groupId == a2 && !sub_0202E72C(a1, &a1->unk_50[i])) { + a1->unk_38[a1->count_sub2++] = &a1->unk_50[i]; } } } - a1->unk_08 = a1->unk_04 + a1->unk_00; - for (i = 0; i < a1->unk_00; ++i) { - a1->unk_0C[i + a1->unk_04] = a1->unk_38[i]; + a1->count_total = a1->count_sub1 + a1->count_sub2; + for (i = 0; i < a1->count_sub2; ++i) { + a1->rankings[i + a1->count_sub1] = a1->unk_38[i]; } - for (i = 0; i < a1->unk_08 - 1; ++i) { - for (j = a1->unk_08 - 1; j > i; --j) { - if (a1->unk_0C[i]->unk_04 < a1->unk_0C[j]->unk_04) { - UnkStruct_0202E4B0_sub *tmp = a1->unk_0C[i]; - a1->unk_0C[i] = a1->unk_0C[j]; - a1->unk_0C[j] = tmp; + for (i = 0; i < a1->count_total - 1; ++i) { + for (j = a1->count_total - 1; j > i; --j) { + if (a1->rankings[i]->stat < a1->rankings[j]->stat) { + SaveRankingsEntry *tmp = a1->rankings[i]; + a1->rankings[i] = a1->rankings[j]; + a1->rankings[j] = tmp; } } } - sub_0202E6F0(sp8); - for (i = 0; i < 6 && i < a1->unk_08; ++i) { - sp8[i] = *a1->unk_0C[i]; + SaveRankingsEntry_InitArrayOf6(saveRecordsPtr); + for (i = 0; i < 6 && i < a1->count_total; ++i) { + saveRecordsPtr[i] = *a1->rankings[i]; } } -static void sub_0202E920(UnkStruct_0202E4B0 *a0, int a1, u8 a2, UnkStruct_0202E4B0_sub **a3, u8 a4, HeapID heapId) { - UnkStruct_0202E920 *r6 = AllocFromHeapAtEnd(heapId, sizeof(UnkStruct_0202E920)); - sub_0202E75C(a0, r6, a1, a2, 0, a3, a4, heapId); +static void sub_0202E920(SaveRankings *a0, int a1, u8 a2, SaveRankingsEntry **a3, u8 a4, HeapID heapId) { + UnkStruct_0202E920 *temp = AllocFromHeapAtEnd(heapId, sizeof(UnkStruct_0202E920)); + sub_0202E75C(a0, temp, a1, a2, 0, a3, a4, heapId); if (a1 != 0) { - sub_0202E75C(a0, r6, a1, a2, 1, a3, a4, heapId); + sub_0202E75C(a0, temp, a1, a2, 1, a3, a4, heapId); } - FreeToHeap(r6); + FreeToHeap(temp); } -void sub_0202E97C(SaveData *saveData, u8 a1, u8 a2, UnkStruct_0202E4B0_sub **a3, HeapID heapId) { +void sub_0202E97C(SaveData *saveData, u8 a1, u8 a2, SaveRankingsEntry **a3, HeapID heapId) { u8 i; u8 cnt; - UnkStruct_0202E4B0_sub *sp10[5]; - int spC; - UnkStruct_0202E4B0 *sp8; + SaveRankingsEntry *sp10[5]; + int groupId; + SaveRankings *sp8; sp8 = sub_0202E530(saveData); - spC = sub_0202C7B4(Save_FriendGroup_Get(saveData), 1); + groupId = Save_FriendGroup_GetGroupId(Save_FriendGroup_Get(saveData), 1); cnt = 0; for (i = 0; i < a2; ++i) { if (i != a1 && a3[i] != NULL) { @@ -294,48 +300,48 @@ void sub_0202E97C(SaveData *saveData, u8 a1, u8 a2, UnkStruct_0202E4B0_sub **a3, } if (cnt != 0) { for (i = 0; i < 13; ++i) { - sub_0202E920(sp8, spC, i, sp10, cnt, heapId); + sub_0202E920(sp8, groupId, i, sp10, cnt, heapId); } - SaveSubstruct_UpdateCRC(SAVE_UNK_24); + SaveSubstruct_UpdateCRC(SAVE_RANKINGS); } } UnkStruct_0202E9FC *sub_0202E9FC(SaveData *saveData, int page, HeapID heapId) { int i; - int r0; + int pageOffset; UnkStruct_0202E9FC *ret; - int spC; + int groupId; u32 *tmp; PlayerProfile *profile; profile = Save_PlayerData_GetProfileAddr(saveData); ret = AllocFromHeap(heapId, sizeof(UnkStruct_0202E9FC)); MI_CpuClear8(ret, sizeof(UnkStruct_0202E9FC)); - spC = sub_0202C7B4(Save_FriendGroup_Get(saveData), 1); - tmp = sub_0202E594(saveData, heapId); - ret->count = sub_0202E4B0(page); - r0 = sub_0202E4BC(page); + groupId = Save_FriendGroup_GetGroupId(Save_FriendGroup_Get(saveData), 1); + tmp = Save_RankingSys_GetPlayerStats(saveData, heapId); + ret->count = RankingsViewSys_GetNumRecordsPerPage(page); + pageOffset = RankingsViewSys_GetFirstRecordIndexOnPage(page); for (i = 0; i < ret->count; ++i) { - ret->unk_04[i].unk_0 = spC; - ret->unk_04[i].unk_4 = tmp[i + r0]; + ret->unk_04[i].groupId = groupId; + ret->unk_04[i].stat = tmp[i + pageOffset]; ret->unk_04[i].playerName = PlayerProfile_GetPlayerName_NewString(profile, heapId); } FreeToHeap(tmp); return ret; } -UnkStruct_0202E9FC *sub_0202EA80(UnkStruct_0202E4B0 *a0, int a1, HeapID heapId) { +UnkStruct_0202E9FC *sub_0202EA80(SaveRankings *saveRankings, int a1, HeapID heapId) { int i; UnkStruct_0202E9FC *ret; ret = AllocFromHeap(heapId, sizeof(UnkStruct_0202E9FC)); MI_CpuClear8(ret, sizeof(UnkStruct_0202E9FC)); for (i = 0; i < 6; ++i) { - if (sub_0202E4E0(&a0->unk_000[a1][i])) { - ret->unk_04[ret->count].unk_0 = a0->unk_000[a1][i].unk_00; - ret->unk_04[ret->count].unk_4 = a0->unk_000[a1][i].unk_04; + if (sub_0202E4E0(&saveRankings->array[a1][i])) { + ret->unk_04[ret->count].groupId = saveRankings->array[a1][i].groupId; + ret->unk_04[ret->count].stat = saveRankings->array[a1][i].stat; ret->unk_04[ret->count].playerName = String_New(PLAYER_NAME_LENGTH + 1, heapId); - CopyU16ArrayToString(ret->unk_04[ret->count].playerName, a0->unk_000[a1][i].playerName); + CopyU16ArrayToString(ret->unk_04[ret->count].playerName, saveRankings->array[a1][i].playerName); ++ret->count; } } @@ -352,5 +358,5 @@ void sub_0202EAFC(UnkStruct_0202E9FC *a0) { } MI_CpuClear8(a0, sizeof(UnkStruct_0202E9FC)); FreeToHeap(a0); - SaveSubstruct_UpdateCRC(SAVE_UNK_24); + SaveSubstruct_UpdateCRC(SAVE_RANKINGS); } diff --git a/src/unk_02097D3C.c b/src/unk_02097D3C.c index afacafbec..d9ad80b4e 100644 --- a/src/unk_02097D3C.c +++ b/src/unk_02097D3C.c @@ -5,19 +5,19 @@ #include "unk_0200FA24.h" #include "unk_02097D3C.h" -static BOOL sub_02097D80(TaskManager *taskManager); +static BOOL Task_ViewFriendRecordsApp(TaskManager *taskManager); -void sub_02097D3C(FieldSystem *fieldSystem, u8 a1, u8 a2) { +void FieldSystem_LaunchTask_ViewFriendRecordsApp(FieldSystem *fieldSystem, u8 pageScrollParam, u8 cursorPos) { UnkStruct_02097D48 *taskData = AllocFromHeapAtEnd(HEAP_ID_FIELD, sizeof(UnkStruct_02097D48)); taskData->state = 0; - taskData->args = AllocFromHeapAtEnd(HEAP_ID_FIELD, sizeof(UnkStruct_02097D56)); + taskData->args = AllocFromHeapAtEnd(HEAP_ID_FIELD, sizeof(ViewFriendRecordsArgs)); taskData->args->saveData = FieldSystem_GetSaveData(fieldSystem); - taskData->args->unk_0 = a1; - taskData->args->unk_2 = a2; - TaskManager_Call(fieldSystem->taskman, sub_02097D80, taskData); + taskData->args->page_scroll = pageScrollParam; + taskData->args->cursorPos = cursorPos; + TaskManager_Call(fieldSystem->taskman, Task_ViewFriendRecordsApp, taskData); } -static BOOL sub_02097D80(TaskManager *taskManager) { +static BOOL Task_ViewFriendRecordsApp(TaskManager *taskManager) { FieldSystem *fieldSystem = TaskManager_GetFieldSystem(taskManager); UnkStruct_02097D48 *taskData = TaskManager_GetEnvironment(taskManager); @@ -32,7 +32,7 @@ static BOOL sub_02097D80(TaskManager *taskManager) { break; } - sub_0203FD08(fieldSystem, taskData->args); + LaunchApp_ViewFriendRecords(fieldSystem, taskData->args); sub_0203E30C(); taskData->state++; break; diff --git a/tools/py_scripts/scrcmd.json b/tools/py_scripts/scrcmd.json index daa6ac050..b69e786c7 100644 --- a/tools/py_scripts/scrcmd.json +++ b/tools/py_scripts/scrcmd.json @@ -2296,7 +2296,7 @@ ] }, { - "name": "scrcmd_378", + "name": "view_rankings", "args": [ 2, "var"