Skip to content

Commit

Permalink
complete
Browse files Browse the repository at this point in the history
  • Loading branch information
z64a committed Oct 24, 2024
1 parent 3caeba7 commit 2738cbd
Show file tree
Hide file tree
Showing 13 changed files with 249 additions and 210 deletions.
12 changes: 9 additions & 3 deletions include/enums.h
Original file line number Diff line number Diff line change
Expand Up @@ -5369,14 +5369,14 @@ enum FileMenuMessages {
/* 31 */ FILE_MESSAGE_HAS_BEEN_CREATED, // has been created.[End]
#if VERSION_PAL
// TODO: determine where these new entries should be placed
UNK1,
UNK2,
FILE_MESSAGE_PAL_UNK1,
FILE_MESSAGE_PAL_UNK2,
#endif
/* 32 */ FILE_MESSAGE_ENTER_A_FILE_NAME, // Enter a file name![End]
/* 33 */ FILE_MESSAGE_QUESTION, // ?[End]
/* 34 */ FILE_MESSAGE_PERIOD_34, // .[End]
#if VERSION_PAL
FILE_MESSAGE_BASE_UNK,
FILE_MESSAGE_PAL_UNK3,
#endif
};

Expand Down Expand Up @@ -6033,6 +6033,12 @@ enum MsgChars {

MSG_CHAR_UNK_C3 = 0xC3,

MSG_CHAR_MENU_SPACE = 0xC6,
MSG_CHAR_MENU_USE_CHARSET_B = 0xC7,
MSG_CHAR_MENU_USE_CHARSET_A = 0xC8,
MSG_CHAR_MENU_BACK = 0xC9,
MSG_CHAR_MENU_END = 0xCA,

// special character codes used when reading from the source buffer
MSG_CHAR_READ_ENDL = 0xF0,
MSG_CHAR_READ_WAIT = 0xF1,
Expand Down
14 changes: 11 additions & 3 deletions include/filemenu.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,30 +19,38 @@ enum {
FILE_MENU_CONFIRM = 1, // confirmation prompt is open
FILE_MENU_MESSAGE = 2, // message is displayed, e.g. "File X has been deleted."
FILE_MENU_INPUT_NAME = 3, // "Enter a file name!" screen
FILE_MENU_SELECT_LANG = 4, // PAL only
};

enum {
// states for main menu
FM_MAIN_SELECT_FILE = 0, // choose which file to load
FM_MAIN_SELECT_DELETE, // choose which file to delete
#if !VERSION_PAL
FM_MAIN_DUMMY_LANG_SELECT,
FM_MAIN_DUMMY_LANG_SELECT, // non-PAL versions have an unimplemented dummy language select
#endif
FM_MAIN_SELECT_COPY_FROM,
FM_MAIN_SELECT_COPY_TO,
FM_MAIN_PAL_LANG_SELECT,

// states for confirm submenu
FM_CONFIRM_DELETE = 0,
FM_CONFIRM_CREATE,
#if !VERSION_PAL
FM_CONFIRM_DUMMY, // order??
FM_CONFIRM_DUMMY,
#endif
FM_CONFIRM_CREATE,
FM_CONFIRM_COPY, // unused
FM_CONFIRM_START,

// states for message submenu
FM_MESSAGE_DELETED = 0,
#if !VERSION_PAL
FM_MESSAGE_DUMMY,
#endif
FM_MESSAGE_COPIED,
FM_MESSAGE_CREATED,

// states for input submenu
FM_INPUT_CHARSET_A = 0,
FM_INPUT_CHARSET_B,
};
Expand Down
2 changes: 1 addition & 1 deletion include/functions.h
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ void pause_cleanup(void);
void filemenu_init(s32 mode);
void filemenu_cleanup(void);
void filemenu_update(void);
s32 func_80244BC4(void);
s32 filemenu_get_exit_mode(void);
void filemenu_set_selected(MenuPanel* menu, s32 col, s32 row);
void filemenu_set_cursor_alpha(s32 arg0);
void filemenu_set_cursor_goal_pos(s32 windowIndex, s32 posX, s32 posY);
Expand Down
23 changes: 15 additions & 8 deletions src/filemenu/filemenu_common.c
Original file line number Diff line number Diff line change
Expand Up @@ -1047,10 +1047,10 @@ void filemenu_init(s32 mode) {
if (mode != 2) {
filemenu_currentMenu = FILE_MENU_MAIN;
menu = filemenu_menus[FILE_MENU_MAIN];
menu->state = filemenu_currentMenu;
menu->state = FM_MAIN_SELECT_FILE;
func_PAL_8002B574();

if (menu->state == 0) {
if (menu->state == FM_MAIN_SELECT_FILE) {
fio_load_globals();
if (gSaveGlobals.lastFileSelected >= 4) {
gSaveGlobals.lastFileSelected = 0;
Expand Down Expand Up @@ -1146,15 +1146,22 @@ void filemenu_cleanup(void) {

set_window_update(WIN_PAUSE_TUTORIAL, WINDOW_UPDATE_HIDE);
set_window_update(WIN_PAUSE_DECRIPTION, WINDOW_UPDATE_HIDE);
func_80244BC4();
filemenu_get_exit_mode(); // part of a conditional that optimized out?
}

s32 func_80244BC4() {
if (filemenu_menus[0]->state == 0 && filemenu_currentMenu == 1 && filemenu_menus[1]->selected == 0) {
s32 filemenu_get_exit_mode() {
if (filemenu_menus[FILE_MENU_MAIN]->state == FM_MAIN_SELECT_FILE
&& filemenu_currentMenu == FILE_MENU_CONFIRM
&& filemenu_menus[FILE_MENU_CONFIRM]->selected == 0
) {
return 2;
} else if (filemenu_menus[0]->state == 0 && filemenu_menus[0]->selected < 4) {
}

if (filemenu_menus[FILE_MENU_MAIN]->state == FM_MAIN_SELECT_FILE
&& filemenu_menus[FILE_MENU_MAIN]->selected <= FM_MAIN_OPT_FILE_4
) {
return 1;
} else {
return 0;
}

return 0;
}
90 changes: 47 additions & 43 deletions src/filemenu/filemenu_createfile.c
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ void filemenu_draw_contents_file_create_header(
}
}

if (filemenu_currentMenu == 3) {
if (filemenu_currentMenu == FILE_MENU_INPUT_NAME) {
if (filemenu_filename_pos == 8) {
xOffset = temp_s2 + 86;
} else {
Expand Down Expand Up @@ -148,7 +148,7 @@ void filemenu_draw_contents_file_create_header(
}

tempAmt = 8;
if (filemenu_currentMenu == 3) {
if (filemenu_currentMenu == FILE_MENU_INPUT_NAME) {
s32 phi_v0 = 122;

if (filemenu_filename_pos != tempAmt) {
Expand Down Expand Up @@ -221,7 +221,7 @@ void filemenu_draw_contents_choose_name(

for (col = 0; col < menu->numCols; col++) {
c = menu->gridData[page * menu->numCols * menu->numRows + menu->numCols * row + col];
if (c != 0xF7) {
if (c != MSG_CHAR_READ_SPACE) {
if (col == menu->col && row == menu->row) {
flags = 8;
color = 0;
Expand All @@ -236,23 +236,23 @@ void filemenu_draw_contents_choose_name(
#endif
specialChar = c;
if (c >= 0xA2 && c < 0xF0) {
if (c >= 0xC6) {
if (c >= MSG_CHAR_MENU_SPACE) {
hud_element_set_render_pos(filemenu_createfile_HIDs[2], baseX + xOffset + 22, baseY + yOffset + 8);
hud_element_draw_without_clipping(filemenu_createfile_HIDs[2]);
flags = 0;
}
}
if (specialChar == 0xC6) {
if (specialChar == MSG_CHAR_MENU_SPACE) {
xOffset--;
}
if (specialChar == 0xC9) {
if (specialChar == MSG_CHAR_MENU_BACK) {
#if VERSION_PAL
xOffset += 16;
#else
xOffset += 5;
#endif
}
if (specialChar == 0xCA) {
if (specialChar == MSG_CHAR_MENU_END) {
#if VERSION_PAL
if (gCurrentLanguage == LANGUAGE_DE) {
xOffset += 4;
Expand All @@ -263,7 +263,7 @@ void filemenu_draw_contents_choose_name(
xOffset += 8;
#endif
}
if (specialChar == 0xC6 || specialChar == 0xCA || specialChar == 0xC9) {
if (specialChar == MSG_CHAR_MENU_SPACE || specialChar == MSG_CHAR_MENU_END || specialChar == MSG_CHAR_MENU_BACK) {
yOffset--;
xNudge = 9;
}
Expand All @@ -281,7 +281,7 @@ void filemenu_draw_contents_choose_name(
for (col = 0; col < menu->numCols; col++) {
for (row = 0; row < menu->numRows; row++) {
c = menu->gridData[menu->state * menu->numCols * menu->numRows + menu->numCols * row + col];
if (c != 0xF7) {
if (c != MSG_CHAR_READ_SPACE) {
if (col == menu->col && row == menu->row) {
flags = 8;
color = 0;
Expand All @@ -296,19 +296,19 @@ void filemenu_draw_contents_choose_name(
#endif
specialChar = c;
if (c >= 0xA2 && c < 0xF0) {
if (c >= 0xC6) {
if (c >= MSG_CHAR_MENU_SPACE) {
hud_element_set_render_pos(filemenu_createfile_HIDs[2], baseX + xOffset + 22, baseY + yOffset + 8);
hud_element_draw_without_clipping(filemenu_createfile_HIDs[2]);
flags = 0;
}
}
if (specialChar == 0xC6) {
if (specialChar == MSG_CHAR_MENU_SPACE) {
xOffset--;
}
if (specialChar == 0xC9) {
if (specialChar == MSG_CHAR_MENU_BACK) {
xOffset += FILEMENU_C9_OFFSET;
}
if (specialChar == 0xCA) {
if (specialChar == MSG_CHAR_MENU_END) {
#if VERSION_PAL
if (gCurrentLanguage == LANGUAGE_DE) {
xOffset += 4;
Expand All @@ -319,7 +319,7 @@ void filemenu_draw_contents_choose_name(
xOffset += 8;
#endif
}
if (specialChar == 0xC6 || specialChar == 0xCA || specialChar == 0xC9) {
if (specialChar == MSG_CHAR_MENU_SPACE || specialChar == MSG_CHAR_MENU_END || specialChar == MSG_CHAR_MENU_BACK) {
yOffset--;
xNudge = 9;
}
Expand All @@ -333,7 +333,7 @@ void filemenu_draw_contents_choose_name(
}
}

if (filemenu_currentMenu == 3) {
if (filemenu_currentMenu == FILE_MENU_INPUT_NAME) {
if (filemenu_heldButtons & (BUTTON_STICK_RIGHT | BUTTON_STICK_LEFT | BUTTON_STICK_DOWN | BUTTON_STICK_UP)) {
D_8024A18C = -4;
}
Expand Down Expand Up @@ -367,8 +367,6 @@ void filemenu_choose_name_init(MenuPanel* menu) {

void filemenu_choose_name_handle_input(MenuPanel* menu) {
s32 oldSelected = menu->selected;
MenuPanel* newMenu;
MenuPanel* newMenu2;
s32 i;

#if VERSION_PAL
Expand Down Expand Up @@ -431,39 +429,42 @@ void filemenu_choose_name_handle_input(MenuPanel* menu) {
}

if (filemenu_pressedButtons & BUTTON_A) {
MenuPanel* confirmMenu;

switch (menu->selected) {
case 0xC6:
case MSG_CHAR_MENU_SPACE:
sfx_play_sound(SOUND_CREATE_FILE_SET_CHARACTER);
if (filemenu_filename_pos == ARRAY_COUNT(filemenu_filename)) {
filemenu_filename_pos = ARRAY_COUNT(filemenu_filename) - 1;
}
filemenu_filename[filemenu_filename_pos] = 0xF7;
filemenu_filename[filemenu_filename_pos] = MSG_CHAR_READ_SPACE;
filemenu_filename_pos++;
if (filemenu_filename_pos > ARRAY_COUNT(filemenu_filename)) {
filemenu_filename_pos = ARRAY_COUNT(filemenu_filename);
}
break;
case 0xC9:
case MSG_CHAR_MENU_BACK:
// handled later to combine with B-input detection
break;
case 0xC7:
if (menu->state != 1) {
case MSG_CHAR_MENU_USE_CHARSET_B:
if (menu->state != FM_INPUT_CHARSET_B) {
sfx_play_sound(SOUND_CREATE_FILE_CHANGE_CHARSET);
menu->state = 1;
menu->state = FM_INPUT_CHARSET_B;
filemenu_set_selected(menu, menu->col, menu->row);
set_window_update(WIN_FILES_INPUT_KEYBOARD, (s32)filemenu_update_change_layout);
}
break;
case 0xC8:
if (menu->state != 0) {
case MSG_CHAR_MENU_USE_CHARSET_A:
if (menu->state != FM_INPUT_CHARSET_A) {
sfx_play_sound(SOUND_CREATE_FILE_CHANGE_CHARSET);
menu->state = 0;
menu->state = FM_INPUT_CHARSET_A;
filemenu_set_selected(menu, menu->col, menu->row);
set_window_update(WIN_FILES_INPUT_KEYBOARD, (s32)filemenu_update_change_layout);
}
break;
case 0xCA:
case MSG_CHAR_MENU_END:
for (i = 0; i < ARRAY_COUNT(filemenu_filename); i++) {
if (filemenu_filename[i] != 0xF7) {
if (filemenu_filename[i] != MSG_CHAR_READ_SPACE) {
break;
}
}
Expand All @@ -490,10 +491,10 @@ void filemenu_choose_name_handle_input(MenuPanel* menu) {
gWindows[WIN_FILES_CONFIRM_PROMPT].pos.x = CENTER_WINDOW_X(WIN_FILES_CONFIRM_PROMPT);
#endif

filemenu_currentMenu = 1;
newMenu = filemenu_menus[filemenu_currentMenu];
newMenu->state = INPUT_FINAL_PAGE;
filemenu_set_selected(newMenu, 0, 0);
filemenu_currentMenu = FILE_MENU_CONFIRM;
confirmMenu = filemenu_menus[filemenu_currentMenu];
confirmMenu->state = FM_CONFIRM_CREATE;
filemenu_set_selected(confirmMenu, 0, 0);
return;
default:
sfx_play_sound(SOUND_CREATE_FILE_SET_CHARACTER);
Expand All @@ -509,13 +510,16 @@ void filemenu_choose_name_handle_input(MenuPanel* menu) {
break;
}

if (menu->selected != 0xC7 && menu->selected != 0xC8 && menu->selected != 0xC9 &&
filemenu_filename_pos == ARRAY_COUNT(filemenu_filename)) {
if (menu->selected != MSG_CHAR_MENU_USE_CHARSET_A
&& menu->selected != MSG_CHAR_MENU_USE_CHARSET_B
&& menu->selected != MSG_CHAR_MENU_BACK
&& filemenu_filename_pos == ARRAY_COUNT(filemenu_filename)
) {
filemenu_set_selected(menu, menu->numCols - 3, menu->numRows - 1);
}
}

if ((filemenu_pressedButtons & BUTTON_B) || ((filemenu_pressedButtons & BUTTON_A) && menu->selected == 0xC9)) {
if ((filemenu_pressedButtons & BUTTON_B) || ((filemenu_pressedButtons & BUTTON_A) && menu->selected == MSG_CHAR_MENU_BACK)) {
sfx_play_sound(SOUND_CREATE_FILE_BACKSPACE);
filemenu_filename_pos--;
if (filemenu_filename_pos < 0) {
Expand All @@ -538,13 +542,15 @@ void filemenu_choose_name_handle_input(MenuPanel* menu) {
}

for (i = filemenu_filename_pos; i < ARRAY_COUNT(filemenu_filename); i++) {
filemenu_filename[i] = 0xF7;
filemenu_filename[i] = MSG_CHAR_READ_SPACE;
}
}

if (filemenu_pressedButtons & BUTTON_START) {
MenuPanel* confirmMenu;

for (i = 0; i < ARRAY_COUNT(filemenu_filename); i++) {
if (filemenu_filename[i] != 0xF7) {
if (filemenu_filename[i] != MSG_CHAR_READ_SPACE) {
break;
}
}
Expand Down Expand Up @@ -573,15 +579,13 @@ void filemenu_choose_name_handle_input(MenuPanel* menu) {
gWindows[WIN_FILES_CONFIRM_PROMPT].pos.x = CENTER_WINDOW_X(WIN_FILES_CONFIRM_PROMPT);
#endif

filemenu_currentMenu = 1;
newMenu2 = filemenu_menus[filemenu_currentMenu];
newMenu2->state = INPUT_FINAL_PAGE;
filemenu_set_selected(newMenu2, 0, 0);
filemenu_currentMenu = FILE_MENU_CONFIRM;
confirmMenu = filemenu_menus[filemenu_currentMenu];
confirmMenu->state = FM_CONFIRM_CREATE;
filemenu_set_selected(confirmMenu, 0, 0);
}
}

static const f32 padding[2] = { 0.0f, 0.0f }; // not sure why this is needed

void filemenu_choose_name_update(MenuPanel* menu) {
}

Expand Down
Loading

0 comments on commit 2738cbd

Please sign in to comment.