Naming Screen file split

This commit is contained in:
DizzyEggg 2025-06-03 10:23:47 +02:00
parent 7ef8b081fe
commit 12df1f050e
17 changed files with 193 additions and 182 deletions

View File

@ -6,7 +6,7 @@
u32 sub_8012A64(MenuInputStructSub *r0, s32 r1);
s32 GetKeyPress(MenuInputStruct *r0);
s32 sub_8012AE8(void);
s32 GetMenuInput(void);
void sub_8012BC4(u32 x, u32 y, s32 n, s32 len, u32 color, u32 windowId);
void DrawCharOnWindowWidth12(u32 x, u32 y, u32 param_3, u32 color, u32 param_5);
void sub_8012CAC(WindowTemplate *param_1, const MenuItem *param_2);

10
include/naming_screen.h Normal file
View File

@ -0,0 +1,10 @@
#ifndef GUARD_NAMING_SCREEN_H
#define GUARD_NAMING_SCREEN_H
u32 NamingScreen_Init(u32 type, u8 *defaultText);
u32 NamingScreen_HandleInput(void);
void NamingScreen_Free(void);
s32 GetStrWidth(u8 *buffer, s32 size);
s32 GetMaxPokeNameWidth(void);
#endif

View File

@ -101,6 +101,7 @@ SECTIONS {
src/code_8012A18.o(.text);
src/menu_input.o(.text);
src/string_format.o(.text);
src/code_8015080.o(.text);
src/naming_screen.o(.text);
src/code_801602C.o(.text);
src/felicity_bank.o(.text);
@ -453,6 +454,7 @@ SECTIONS {
src/string_format.o(.rodata);
data/data_80D47B8.o(.rodata);
src/common_strings.o(.rodata);
src/code_8015080.o(.rodata);
src/naming_screen.o(.rodata);
src/code_801602C.o(.rodata);
src/felicity_bank.o(.rodata);

102
src/code_8015080.c Normal file
View File

@ -0,0 +1,102 @@
#include "global.h"
#include "globaldata.h"
#include "code_800D090.h"
#include "code_80118A4.h"
#include "code_803D0D8.h"
#include "input.h"
#include "memory.h"
#include "menu_input.h"
#include "sprite.h"
#include "string_format.h"
#include "text_1.h"
#include "text_2.h"
#include "text_3.h"
#include "text_util.h"
#include "constants/input.h"
struct unkStruct_203B1F8
{
// size: 0x4B4
u32 menuAction;
MenuStruct unk4;
WindowTemplates windows;
u8 buffer[0x400];
};
EWRAM_INIT struct unkStruct_203B1F8 *gUnknown_203B1F8 = {NULL};
const WindowTemplate gUnknown_80DAF70 = {
0x00,
0x03,
0x00, 0x00,
0x00, 0x00,
0x00, 0x00,
NULL
};
const WindowTemplate gUnknown_80DAF88 = {
0x00,
0x03,
0x02, 0x02,
0x1A, 0x0c,
0x0c, 0x00,
NULL
};
const WindowTemplate gUnknown_80DAFA0 = {
0x00,
0x03,
0x16, 0x0F,
0x06, 0x03,
0x03, 0x00,
NULL
};
bool8 sub_8015080(u8 *buffer, const MenuItem *menuItems)
{
s32 index;
gUnknown_203B1F8 = MemoryAlloc(sizeof(struct unkStruct_203B1F8), 8);
gUnknown_203B1F8->menuAction = 0;
for(index = 0; index < 4; index++)
{
gUnknown_203B1F8->windows.id[index] = gUnknown_80DAF70;
}
gUnknown_203B1F8->windows.id[0] = gUnknown_80DAF88;
gUnknown_203B1F8->windows.id[2] = gUnknown_80DAFA0;
sub_8012CAC(&gUnknown_203B1F8->windows.id[2], menuItems);
ResetUnusedInputStruct();
ShowWindows(&gUnknown_203B1F8->windows, 1, 1);
sub_80073B8(0);
FormatString(buffer, gUnknown_203B1F8->buffer, gUnknown_203B1F8->buffer + 0x400, 0);
PrintStringOnWindow(4, 4, gUnknown_203B1F8->buffer, 0, 0);
sub_80073E0(0);
sub_8012D60(&gUnknown_203B1F8->unk4, menuItems, 0, 0, -1, 2);
return TRUE;
}
u32 sub_801516C(void)
{
if(!sub_8012FD8(&gUnknown_203B1F8->unk4)) {
sub_8013114(&gUnknown_203B1F8->unk4, &gUnknown_203B1F8->menuAction);
return 3;
}
else {
return 0;
}
}
u32 sub_8015198(void)
{
return gUnknown_203B1F8->menuAction;
}
void sub_80151A4(void)
{
if(gUnknown_203B1F8) {
MemoryFree(gUnknown_203B1F8);
gUnknown_203B1F8 = NULL;
}
}

View File

@ -8,10 +8,7 @@
#include "string_format.h"
#include "text_util.h"
#include "text_1.h"
u32 NamingScreen_Init(u32 type, u8 *defaultText);
u32 NamingScreen_HandleInput(void);
void NamingScreen_Free(void);
#include "naming_screen.h"
EWRAM_INIT static struct unkStruct_203B200 *sUnknown_203B200 = {NULL};

View File

@ -31,10 +31,7 @@
#include "wigglytuff_shop1.h"
#include "wigglytuff_shop3.h"
#include "wonder_mail.h"
u32 NamingScreen_Init(u32 type, u8 *defaultText);
u32 NamingScreen_HandleInput(void);
void NamingScreen_Free(void);
#include "naming_screen.h"
IWRAM_INIT struct unkStruct_3001B64 *gUnknown_3001B64 = { NULL };

View File

@ -27,10 +27,7 @@
#include "text_util.h"
#include "wonder_mail_4.h"
#include "wonder_mail_5.h"
u32 NamingScreen_Init(u32 type, u8 *defaultText);
u32 NamingScreen_HandleInput(void);
void NamingScreen_Free(void);
#include "naming_screen.h"
extern void SetFriendRescueMenuState(u32);

View File

@ -71,7 +71,7 @@ static bool8 sub_8013DD0(unkStructFor8013AA0 *);
u32 sub_8012A64(MenuInputStructSub *r0, s32 r1)
{
if (r0 == NULL)
return sub_8012AE8();
return GetMenuInput();
if (r1 != -1)
nullsub_34(r0, r1);
@ -82,7 +82,7 @@ u32 sub_8012A64(MenuInputStructSub *r0, s32 r1)
}
if (r0->b_button == 0)
return sub_8012AE8();
return GetMenuInput();
r0->b_button = 0;
return INPUT_B_BUTTON;
@ -104,10 +104,10 @@ s32 GetKeyPress(MenuInputStruct *r0)
return INPUT_DPAD_RIGHT;
}
return sub_8012AE8();
return GetMenuInput();
}
s32 sub_8012AE8(void)
s32 GetMenuInput(void)
{
if (gRealInputs.held & R_BUTTON) {
if (gRealInputs.pressed & A_BUTTON)
@ -1051,7 +1051,7 @@ u32 sub_8013BBC(unkStructFor8013AA0 *a0)
if (sub_8013DD0(a0))
return 1;
switch (sub_8012AE8()) {
switch (GetMenuInput()) {
case INPUT_B_BUTTON:
PlayMenuSoundEffect(1);
return 2;
@ -1095,7 +1095,7 @@ void sub_8013D10(unkStructFor8013AA0 *a0)
window = &gWindows[a0->unk14];
uVar4 = a0->unk24;
switch (sub_8012AE8()) {
switch (GetMenuInput()) {
case INPUT_DPAD_LEFT:
uVar4 = a0->unk24 < a0->unk25 - 1 ? a0->unk24 + 1 : 0;
break;
@ -1121,7 +1121,7 @@ static bool8 sub_8013DD0(unkStructFor8013AA0 *a0)
{
s32 iVar2;
switch (sub_8012AE8()) {
switch (GetMenuInput()) {
case INPUT_DPAD_UP:
if (a0->unk0 == a0->unkC) {
PlayMenuSoundEffect(2);

View File

@ -1,5 +1,6 @@
#include "global.h"
#include "globaldata.h"
#include "naming_screen.h"
#include "code_800D090.h"
#include "code_80118A4.h"
#include "code_803D0D8.h"
@ -14,43 +15,64 @@
#include "text_util.h"
#include "constants/input.h"
struct unkStruct_203B1F8
#define MAX_TEXT_SIZE 54
enum
{
// size: 0x4B4
u32 menuAction;
MenuStruct unk4;
MODE_OVR,
MODE_INS,
};
struct NamingScreen
{
// size: 0x198
u32 type;
bool8 isPassword;
// Note: These had to be declared like these, because SpriteOAM is aligned by 4 and these aren't. Makes you think if SpriteOAM is actually a struct, and not just an array of 4 u16s.
u16 spriteLetterCursor[4];
u16 spriteInputCursor[4];
u8 letterCursorFrames;
u8 inputCursorFrames;
u8 insOvr;
u8 inputCursorArrId; // Always 0
u8 inputCursorPosition;
u8 maxLetters;
u8 letterCursorPos;
u16 letterTotalWidths[MAX_TEXT_SIZE];
s16 letterWidths[MAX_TEXT_SIZE];
u8 *textPtr; // Points to the field below. A bit over complicated in my opinion...
u8 text[MAX_TEXT_SIZE];
u8 *defaultText;
WindowTemplates windows;
u8 buffer[0x400];
};
EWRAM_INIT struct unkStruct_203B1F8 *gUnknown_203B1F8 = {NULL};
static EWRAM_INIT struct NamingScreen *sNamingScreen = NULL;
const WindowTemplate gUnknown_80DAF70 = {
0x00,
0x03,
0x00, 0x00,
0x00, 0x00,
0x00, 0x00,
NULL
static s32 GetEnteredNameLength(void);
static void UpdateInputWindow(bool8);
static void UpdateNameWindow(void);
static void UpdateLetterWidths(void);
static void SetLetterCursorSpritePosition(void);
static void HandleInputCursor(void);
static void UpdatePassword1Window(u8 *text, s32 windowId, s32 _yAdd);
static void UpdatePassword2Window(u8 *text, s32 windowId, s32 _yAdd);
s32 GetMaxPokeNameWidth(void);
s32 GetStrWidth(u8 *buffer, s32 size);
static u32 HandleAPress(void);
static bool8 HandleBPress(void);
enum
{
NAMING_SELF,
NAMING_TEAM,
NAMING_POKEMON,
NAMING_PARTNER,
NAMING_PASSWORD1,
NAMING_PASSWORD2,
};
const WindowTemplate gUnknown_80DAF88 = {
0x00,
0x03,
0x02, 0x02,
0x1A, 0x0c,
0x0c, 0x00,
NULL
};
const WindowTemplate gUnknown_80DAFA0 = {
0x00,
0x03,
0x16, 0x0F,
0x06, 0x03,
0x03, 0x00,
NULL
};
#define NAMING_WINDOW_INPUT 0
#define NAMING_WINDOW_NAME 1
struct LayoutInfo
{
@ -64,7 +86,6 @@ struct LayoutInfo
s32 letter;
};
UNUSED static const char sPksDir[] = "pksdir0";
static const DungeonPos gUnknown_80DAFC0[] =
{
{3, 0xD},
@ -295,114 +316,6 @@ static const WindowTemplate sPasswordNameWindowTemplate = {
.header = NULL,
};
bool8 sub_8015080(u8 *buffer, const MenuItem *menuItems)
{
s32 index;
gUnknown_203B1F8 = MemoryAlloc(sizeof(struct unkStruct_203B1F8), 8);
gUnknown_203B1F8->menuAction = 0;
for(index = 0; index < 4; index++)
{
gUnknown_203B1F8->windows.id[index] = gUnknown_80DAF70;
}
gUnknown_203B1F8->windows.id[0] = gUnknown_80DAF88;
gUnknown_203B1F8->windows.id[2] = gUnknown_80DAFA0;
sub_8012CAC(&gUnknown_203B1F8->windows.id[2], menuItems);
ResetUnusedInputStruct();
ShowWindows(&gUnknown_203B1F8->windows, 1, 1);
sub_80073B8(0);
FormatString(buffer, gUnknown_203B1F8->buffer, gUnknown_203B1F8->buffer + 0x400, 0);
PrintStringOnWindow(4, 4, gUnknown_203B1F8->buffer, 0, 0);
sub_80073E0(0);
sub_8012D60(&gUnknown_203B1F8->unk4, menuItems, 0, 0, -1, 2);
return TRUE;
}
u32 sub_801516C(void)
{
if(!sub_8012FD8(&gUnknown_203B1F8->unk4)) {
sub_8013114(&gUnknown_203B1F8->unk4, &gUnknown_203B1F8->menuAction);
return 3;
}
else {
return 0;
}
}
u32 sub_8015198(void)
{
return gUnknown_203B1F8->menuAction;
}
void sub_80151A4(void)
{
if(gUnknown_203B1F8) {
MemoryFree(gUnknown_203B1F8);
gUnknown_203B1F8 = NULL;
}
}
#define MAX_TEXT_SIZE 54
enum
{
MODE_OVR,
MODE_INS,
};
struct NamingScreen
{
// size: 0x198
u32 type;
bool8 isPassword;
// Note: These had to be declared like these, because SpriteOAM is aligned by 4 and these aren't. Makes you think if SpriteOAM is actually a struct, and not just an array of 4 u16s.
u16 spriteLetterCursor[4];
u16 spriteInputCursor[4];
u8 letterCursorFrames;
u8 inputCursorFrames;
u8 insOvr;
u8 inputCursorArrId; // Always 0
u8 inputCursorPosition;
u8 maxLetters;
u8 letterCursorPos;
u16 letterTotalWidths[MAX_TEXT_SIZE];
s16 letterWidths[MAX_TEXT_SIZE];
u8 *textPtr; // Points to the field below. A bit over complicated in my opinion...
u8 text[MAX_TEXT_SIZE];
u8 *defaultText;
WindowTemplates windows;
};
static EWRAM_INIT struct NamingScreen *sNamingScreen = NULL;
static s32 GetEnteredNameLength(void);
static void UpdateInputWindow(bool8);
static void UpdateNameWindow(void);
static void UpdateLetterWidths(void);
static void SetLetterCursorSpritePosition(void);
static void HandleInputCursor(void);
static void UpdatePassword1Window(u8 *text, s32 windowId, s32 _yAdd);
static void UpdatePassword2Window(u8 *text, s32 windowId, s32 _yAdd);
s32 GetMaxPokeNameWidth(void);
s32 GetStrWidth(u8 *buffer, s32 size);
static u32 HandleAPress(void);
static bool8 HandleBPress(void);
enum
{
NAMING_SELF,
NAMING_TEAM,
NAMING_POKEMON,
NAMING_PARTNER,
NAMING_PASSWORD1,
NAMING_PASSWORD2,
};
#define NAMING_WINDOW_INPUT 0
#define NAMING_WINDOW_NAME 1
u32 NamingScreen_Init(u32 type, u8 *defaultText)
{
SpriteOAM *sprite;
@ -426,9 +339,13 @@ u32 NamingScreen_Init(u32 type, u8 *defaultText)
sNamingScreen->isPassword = TRUE;
sNamingScreen->maxLetters = 0x18;
break;
case NAMING_SELF:
case NAMING_TEAM:
sNamingScreen->inputCursorPosition = 6;
sNamingScreen->maxLetters = TEAM_NAME_LENGTH;
break;
case NAMING_SELF:
case NAMING_PARTNER:
case NAMING_POKEMON:
default:
sNamingScreen->inputCursorPosition = 6;
sNamingScreen->maxLetters = POKEMON_NAME_LENGTH;
@ -535,7 +452,7 @@ u32 NamingScreen_HandleInput(void)
AddSprite((SpriteOAM *) &sNamingScreen->spriteInputCursor, 0x100, NULL, NULL);
}
switch (sub_8012AE8()) {
switch (GetMenuInput()) {
case INPUT_L_BUTTON:
if (sNamingScreen->letterCursorPos == 0) {
PlayMenuSoundEffect(2);
@ -706,7 +623,7 @@ static void HandleInputCursor(void)
Window *window = &gWindows[0];
u32 newPosition;
switch (sub_8012AE8()) {
switch (GetMenuInput()) {
case INPUT_DPAD_UP:
newPosition = sLayoutInfo[sNamingScreen->inputCursorArrId][sNamingScreen->inputCursorPosition].upPos;
break;

View File

@ -42,7 +42,7 @@ u32 sub_801E218(void)
flag = FALSE;
switch (sub_8012AE8()) {
switch (GetMenuInput()) {
case INPUT_B_BUTTON:
PlayMenuSoundEffect(1);
return 2;

View File

@ -9,6 +9,7 @@
#include "other_menus2.h"
#include "pokemon.h"
#include "save.h"
#include "menu_input.h"
#include "structs/str_dungeon.h"
typedef struct unkStruct_800D670
@ -41,7 +42,6 @@ extern u8 sub_800D600(void);
extern void sub_800D670(s32 idx, void *dst, s32 size);
extern void sub_800D68C(u32);
void sub_800D414(void);
s32 sub_8012AE8(void);
// Inline needed for 8-bit return cast
static inline bool8 IsNotChunsoft(unkStruct_800D670 *unk)
@ -118,7 +118,7 @@ s32 sub_8037B28(s32 mode)
while (TRUE) {
for (i = 0; i < 1; i++) {
sub_80373C4();
switch (sub_8012AE8()) {
switch (GetMenuInput()) {
case 2:
case 3:
sub_800D520();

View File

@ -15,10 +15,7 @@
#include "sprite.h"
#include "string_format.h"
#include "text_1.h"
u32 NamingScreen_Init(u32 type, u8 *defaultText);
u32 NamingScreen_HandleInput(void);
void NamingScreen_Free(void);
#include "naming_screen.h"
#define RESCUE_PASSWORD_SIZE 0x36

View File

@ -46,7 +46,7 @@ void sub_8014114(void) {
void nullsub_201(void) {}
u32 sub_8014128(void) {
if(sub_8012AE8() == INPUT_B_BUTTON) return 0;
if(GetMenuInput() == INPUT_B_BUTTON) return 0;
else return 1;
}

View File

@ -24,10 +24,7 @@
#include "thank_you_wonder_mail.h"
#include "wonder_mail_4.h"
#include "wonder_mail_5.h"
u32 NamingScreen_Init(u32 type, u8 *defaultText);
u32 NamingScreen_HandleInput(void);
void NamingScreen_Free(void);
#include "naming_screen.h"
static EWRAM_INIT WonderMailStruct_203B2C4 *sUnknown_203B2C4 = {NULL};

View File

@ -22,10 +22,7 @@
#include "wonder_mail.h"
#include "wonder_mail_4.h"
#include "wonder_mail_5.h"
u32 NamingScreen_Init(u32 type, u8 *defaultText);
u32 NamingScreen_HandleInput(void);
void NamingScreen_Free(void);
#include "naming_screen.h"
static EWRAM_INIT WonderMailStruct_203B2C0 *sUnknown_203B2C0 = {NULL};

View File

@ -20,10 +20,7 @@
#include "wonder_mail_5.h"
#include "wonder_mail_802D098.h"
#include "wonder_mail_main_menu.h"
u32 NamingScreen_Init(u32 type, u8 *defaultText);
u32 NamingScreen_HandleInput(void);
void NamingScreen_Free(void);
#include "naming_screen.h"
#define SELECT_WONDER_MAIL_MODE_MAIN_SCREEN 0
#define SEND_WONDER_MAIL_MAIN_SCREEN 1

View File

@ -24,6 +24,7 @@
.include "src/quick_save_read.o"
.include "src/quick_save_write.o"
.include "src/string_format.o"
.include "src/code_8015080.o"
.include "src/naming_screen.o"
.include "src/code_801602C.o"
.include "src/felicity_bank.o"