From 733217a07acde1df434232b249b6428907d7bd31 Mon Sep 17 00:00:00 2001 From: MysterD Date: Thu, 1 Jul 2021 21:27:57 -0700 Subject: [PATCH] Removed old custom menu system --- build-windows-visual-studio/sm64ex.vcxproj | 4 - .../sm64ex.vcxproj.filters | 12 - src/menu/custom_menu.c | 266 ------------ src/menu/custom_menu.h | 13 - src/menu/custom_menu_system.c | 409 ------------------ src/menu/custom_menu_system.h | 51 --- src/menu/file_select.c | 39 +- src/menu/file_select.h | 1 - src/pc/network/discord/activity.c | 3 +- src/pc/network/discord/discord.c | 3 +- src/pc/network/network.c | 14 +- src/pc/network/network.h | 4 +- src/pc/network/packets/packet_join.c | 7 +- src/pc/network/packets/packet_kick.c | 5 +- src/pc/network/packets/packet_leaving.c | 1 - src/pc/network/socket/socket.c | 3 +- src/pc/pc_main.c | 3 +- 17 files changed, 26 insertions(+), 812 deletions(-) delete mode 100644 src/menu/custom_menu.c delete mode 100644 src/menu/custom_menu.h delete mode 100644 src/menu/custom_menu_system.c delete mode 100644 src/menu/custom_menu_system.h diff --git a/build-windows-visual-studio/sm64ex.vcxproj b/build-windows-visual-studio/sm64ex.vcxproj index 4060bd018..f14a61b4d 100644 --- a/build-windows-visual-studio/sm64ex.vcxproj +++ b/build-windows-visual-studio/sm64ex.vcxproj @@ -3921,9 +3921,7 @@ - - @@ -4378,8 +4376,6 @@ - - diff --git a/build-windows-visual-studio/sm64ex.vcxproj.filters b/build-windows-visual-studio/sm64ex.vcxproj.filters index 4de3e3507..2fde8f968 100644 --- a/build-windows-visual-studio/sm64ex.vcxproj.filters +++ b/build-windows-visual-studio/sm64ex.vcxproj.filters @@ -15042,12 +15042,6 @@ Source Files\src\pc\network\discord - - Source Files\src\menu - - - Source Files\src\menu - Source Files\src\pc\network\packets @@ -16192,12 +16186,6 @@ Header Files\src\pc\network\discord - - Header Files\src\menu - - - Header Files\src\menu - Header Files\src\pc\network diff --git a/src/menu/custom_menu.c b/src/menu/custom_menu.c deleted file mode 100644 index 830fa8d61..000000000 --- a/src/menu/custom_menu.c +++ /dev/null @@ -1,266 +0,0 @@ -#include -#include -#include -#include "custom_menu.h" -#include "custom_menu_system.h" -#include "pc/network/network.h" - -#include "pc/configfile.h" -#include "pc/controller/controller_keyboard.h" -#include "game/object_list_processor.h" -#include "game/object_helpers.h" -#include "game/ingame_menu.h" -#include "game/game_init.h" -#include "game/segment2.h" -#include "object_fields.h" -#include "model_ids.h" -#include "behavior_data.h" -#include "audio_defines.h" -#include "audio/external.h" -#include "config.h" -#include "pc/network/version.h" - -#ifdef DISCORD_SDK - #include "pc/network/discord/discord.h" -#endif - -#define MAIN_MENU_HEADER_TEXT "SM64 COOP" - -char sConnectionJoinError[128] = { 0 }; -char gConnectionText[128] = { 0 }; -struct CustomMenu* sConnectMenu = NULL; - -u8 gOpenConnectMenu = FALSE; -s8 sGotoGame = 0; - -static void menu_main_draw_strings(void) { - char* subtitle = "Still in development."; - s16 subtitleX = (SCREEN_WIDTH - get_generic_ascii_string_width(subtitle)) / 2; - print_generic_ascii_string(subtitleX, 150, subtitle); - - char* versionString = get_version(); - gDPSetEnvColor(gDisplayListHead++, 255, 255, 255, 120); - print_generic_ascii_string(25, 25, versionString); - -} - -static void host_menu_draw_strings(void) { - #ifdef DISCORD_SDK - #define HOST_MENU_MAX_ITEMS 6 - #else - #define HOST_MENU_MAX_ITEMS 5 - #endif - - // set up server setting strings - char* buttonText[HOST_MENU_MAX_ITEMS]; - - switch (configPlayerInteraction) { - case 0: buttonText[0] = "Non-solid players."; break; - case 1: buttonText[0] = "Solid players."; break; - case 2: buttonText[0] = "Friendly fire."; break; - default: buttonText[0] = "UNKNOWN"; break; - } - if (configPlayerKnockbackStrength <= 20) { - buttonText[1] = "Weak knockback."; - } else if (configPlayerKnockbackStrength <= 40) { - buttonText[1] = "Normal knockback."; - } else { - buttonText[1] = "Too much knockback."; - } - - buttonText[2] = configStayInLevelAfterStar ? "Stay in level after star." : "Leave level after star."; - - buttonText[3] = configSkipIntro ? "Skip intro cutscene." : "Play intro cutscene."; - - buttonText[4] = configShareLives ? "Share lives." : "Lives are not shared."; - - #ifdef DISCORD_SDK - buttonText[5] = (configNetworkSystem == 0) ? "Host through Discord." : "Host direct connection."; - #endif - - // display server setting strings - for (int i = 0; i < HOST_MENU_MAX_ITEMS; i++) { - print_generic_ascii_string(95, 173 + -29 * i, buttonText[i]); - } - - // display direct connection warning - if (configNetworkSystem != 0) { - f32 red = (f32)fabs(sin(gGlobalTimer / 20.0f)); - gDPSetEnvColor(gDisplayListHead++, 222, 222 * red, 222 * red, gMenuStringAlpha); - char warning[128]; - snprintf(warning, 127, "Port forward '%d' in network router settings or use Hamachi.", configHostPort); - print_generic_ascii_string(0, 5, warning); - } -#ifdef DISCORD_SDK - else if ((configNetworkSystem == 0) && gDiscordFailed) { - f32 red = (f32)fabs(sin(gGlobalTimer / 20.0f)); - gDPSetEnvColor(gDisplayListHead++, 222, 222 * red, 222 * red, gMenuStringAlpha); - char warning[128]; - snprintf(warning, 127, "Discord failed to initialize."); - print_generic_ascii_string(0, 15, warning); - } -#endif -} - -static void host_menu_do_host(void) { -#ifndef DISCORD_SDK - configNetworkSystem = 1; -#endif - if (configNetworkSystem == 0) { - network_set_system(NS_DISCORD); - } else { - network_set_system(NS_SOCKET); - } - custom_menu_close_system(); -} - -static void host_menu_setting_network_system(void) { -#ifdef DISCORD_SDK - configNetworkSystem = (configNetworkSystem == 0) ? 1 : 0; -#else - configNetworkSystem = 1; -#endif -} - -static void host_menu_setting_interaction(void) { - switch (configPlayerInteraction) { - case 0: configPlayerInteraction = 1; break; - case 1: configPlayerInteraction = 2; break; - default: configPlayerInteraction = 0; break; - } -} - -static void host_menu_setting_knockback(void) { - if (configPlayerKnockbackStrength <= 20) { - configPlayerKnockbackStrength = 25; - } else if (configPlayerKnockbackStrength <= 40) { - configPlayerKnockbackStrength = 75; - } else { - configPlayerKnockbackStrength = 10; - } -} - -static void host_menu_setting_stay_in_level(void) { - configStayInLevelAfterStar = (configStayInLevelAfterStar == 0) ? 1 : 0; -} - -static void host_menu_setting_skip_intro(void) { - configSkipIntro = (configSkipIntro == 1) ? 0 : 1; -} - -static void host_menu_setting_share_lives(void) { - configShareLives = (configShareLives == 0) ? 1 : 0; -} - -#ifdef DISCORD_SDK -static void join_menu_draw_strings(void) { - print_generic_ascii_string(30, 155, "Accept a Discord game invite in order to join."); - print_generic_ascii_string(30, 130, "For direct connections, click connect to type in an IP."); -} -#endif - -static void connect_menu_draw_strings(void) { - if (gNetworkType == NT_CLIENT) { - f32 alpha = (f32)fabs(sin(gGlobalTimer / 20.0f)); - gDPSetEnvColor(gDisplayListHead++, 222, 222, 222, gMenuStringAlpha * alpha); - print_generic_ascii_string(130, 130, "Connecting..."); - return; - } - - if (*sConnectionJoinError) { - f32 red = (f32)fabs(sin(gGlobalTimer / 20.0f)); - gDPSetEnvColor(gDisplayListHead++, 222, 222 * red, 222 * red, gMenuStringAlpha); - f32 messageX = (SCREEN_WIDTH - get_generic_ascii_string_width(sConnectionJoinError)) / 2.0; - f32 messageY = (SCREEN_HEIGHT + get_generic_ascii_string_height(sConnectionJoinError)) / 2.0; - print_generic_ascii_string(messageX, messageY, sConnectionJoinError); - return; - } - - print_generic_ascii_string(30, 175, "Type in or paste the host's IP."); - print_generic_ascii_string(30, 160, "Note - the host must forward a port on their router."); -} - -static void connect_menu_on_connection_attempt(void) { -} - -static void connect_menu_on_click(void) { -} - -static void connect_menu_on_close(void) { - network_shutdown(); -} - -void custom_menu_init(struct CustomMenu* head) { - - // set the header text - head->me->label = calloc(strlen(MAIN_MENU_HEADER_TEXT) + 1, sizeof(char)); - strcpy(head->me->label, MAIN_MENU_HEADER_TEXT); - - // set main menu settings - head->headerY = 55; - head->draw_strings = menu_main_draw_strings; - - // create sub menus and buttons - struct CustomMenu* hostMenu = custom_menu_create(head, "HOST", -266, 0, gButtonScale.large); - hostMenu->headerY = 30; - hostMenu->draw_strings = host_menu_draw_strings; - custom_menu_create_button(hostMenu, "CANCEL", 700, -196 + (210 * 3), gButtonScale.large, SOUND_MENU_CAMERA_ZOOM_OUT, custom_menu_close); - custom_menu_create_button(hostMenu, "HOST", 700, -220, gButtonScale.large, SOUND_MENU_CAMERA_ZOOM_IN, host_menu_do_host); - custom_menu_create_button(hostMenu, "", -700, -180 + (210 * 3), gButtonScale.medium, SOUND_ACTION_BONK, host_menu_setting_interaction); - custom_menu_create_button(hostMenu, "", -700, -180 + (210 * 2), gButtonScale.medium, SOUND_ACTION_BONK, host_menu_setting_knockback); - custom_menu_create_button(hostMenu, "", -700, -180 + (210 * 1), gButtonScale.medium, SOUND_ACTION_BONK, host_menu_setting_stay_in_level); - custom_menu_create_button(hostMenu, "", -700, -180 + (210 * 0), gButtonScale.medium, SOUND_ACTION_BONK, host_menu_setting_skip_intro); - custom_menu_create_button(hostMenu, "", -700, -180 + (210 * -1), gButtonScale.medium, SOUND_ACTION_BONK, host_menu_setting_share_lives); - #ifdef DISCORD_SDK - custom_menu_create_button(hostMenu, "", -700, -180 + (210 * -2), gButtonScale.medium, SOUND_ACTION_BONK, host_menu_setting_network_system); - #endif - - #ifdef DISCORD_SDK - struct CustomMenu* joinMenu = custom_menu_create(head, "JOIN", 266, 0, gButtonScale.large); - custom_menu_create_button(joinMenu, "CANCEL", -266, -320, gButtonScale.large, SOUND_MENU_CAMERA_ZOOM_OUT, custom_menu_close); - joinMenu->draw_strings = join_menu_draw_strings; - struct CustomMenu* connectMenu = custom_menu_create(joinMenu, "CONNECT", 266, -320, gButtonScale.large); - #else - struct CustomMenu* connectMenu = custom_menu_create(head, "CONNECT", 266, 0, gButtonScale.large); - #endif - connectMenu->me->on_click = connect_menu_on_click; - connectMenu->on_close = connect_menu_on_close; - connectMenu->draw_strings = connect_menu_draw_strings; - custom_menu_create_button(connectMenu, "CANCEL", 0, -400, gButtonScale.large, SOUND_MENU_CAMERA_ZOOM_OUT, custom_menu_close); - sConnectMenu = connectMenu; -} - -void custom_menu_loop(void) { - // we've received an event that makes us exit the menus - if (sGotoGame) { - sSelectedFileNum = sGotoGame; - custom_menu_close_system(); - } - - // force-start the load when command-line server hosting - if (gNetworkType == NT_SERVER && sSelectedFileNum == 0) { - sSelectedFileNum = 1; - } - - if (gOpenConnectMenu && sConnectMenu != NULL) { - gOpenConnectMenu = FALSE; - custom_menu_open(sConnectMenu); - } -} - -void custom_menu_on_load_save_file(s8 saveFileNum) { - if (gNetworkType != NT_CLIENT && saveFileNum != 0) { - configHostSaveSlot = saveFileNum; - network_init(NT_SERVER); - } -} - -void custom_menu_goto_game(s16 saveFileNum) { - sGotoGame = saveFileNum; -} - -void custom_menu_connection_error(char* message) { - play_sound(SOUND_MARIO_MAMA_MIA, gDefaultSoundArgs); - strcpy(sConnectionJoinError, message); - network_shutdown(); -} diff --git a/src/menu/custom_menu.h b/src/menu/custom_menu.h deleted file mode 100644 index b3cb7cebc..000000000 --- a/src/menu/custom_menu.h +++ /dev/null @@ -1,13 +0,0 @@ -#ifndef CUSTOM_MENU_H -#define CUSTOM_MENU_H -#include "custom_menu_system.h" - -extern u8 gOpenConnectMenu; - -void custom_menu_init(struct CustomMenu* head); -void custom_menu_loop(void); -void custom_menu_on_load_save_file(s8 saveFileNum); -void custom_menu_goto_game(s16 saveFileNum); -void custom_menu_connection_error(char* message); - -#endif // CUSTOM_MENU_H diff --git a/src/menu/custom_menu_system.c b/src/menu/custom_menu_system.c deleted file mode 100644 index 796f8e40f..000000000 --- a/src/menu/custom_menu_system.c +++ /dev/null @@ -1,409 +0,0 @@ -#include -#include -#include -#include "custom_menu_system.h" -#include "custom_menu.h" - -#include "game/object_list_processor.h" -#include "game/object_helpers.h" -#include "game/ingame_menu.h" -#include "game/game_init.h" -#include "game/segment2.h" -#include "object_fields.h" -#include "model_ids.h" -#include "behavior_data.h" -#include "audio_defines.h" -#include "audio/external.h" -#include "gfx_dimensions.h" -#include "config.h" - -static struct CustomMenu* sHead = NULL; -static struct CustomMenu* sCurrentMenu = NULL; -static struct CustomMenu* sLastMenu = NULL; -struct CustomMenuButtonScale gButtonScale = { - .small = 0.08111111f, - .medium = 0.09511111f, - .large = 0.11111111f, -}; - -u8 gMenuStringAlpha = 255; - -struct ErrorDialog { - u8* dialog; - struct ErrorDialog* next; -}; -static struct ErrorDialog* sErrorDialog = NULL; - -struct CustomMenuButton* custom_menu_create_button(struct CustomMenu* parent, char* label, u16 x, u16 y, f32 scale, s32 clickSound, void (*on_click)(void)) { - struct CustomMenuButton* button = calloc(1, sizeof(struct CustomMenuButton)); - if (parent->buttons == NULL) { - parent->buttons = button; - } else { - struct CustomMenuButton* parentButton = parent->buttons; - while (parentButton->next != NULL) { parentButton = parentButton->next; } - parentButton->next = button; - } - button->label = calloc(strlen(label), sizeof(char) + 1); - strcpy(button->label, label); - - button->on_click = on_click; - button->clickSound = clickSound; - - struct Object* obj = spawn_object_rel_with_rot(parent->me->object, MODEL_MAIN_MENU_MARIO_NEW_BUTTON, bhvMenuButton, x * -1, y, -1, 0, 0x8000, 0); - - obj->oMenuButtonScale = scale; - obj->oFaceAngleRoll = 0; - obj->oMenuButtonTimer = 0; - obj->oMenuButtonOrigPosX = obj->oParentRelativePosX; - obj->oMenuButtonOrigPosY = obj->oParentRelativePosY; - obj->oMenuButtonOrigPosZ = obj->oParentRelativePosZ; - obj->oMenuButtonIsCustom = 1; - obj->oMenuButtonState = MENU_BUTTON_STATE_DEFAULT; - button->object = obj; - return button; -} - -struct CustomMenu* custom_menu_create(struct CustomMenu* parent, char* label, u16 x, u16 y, f32 scale) { - struct CustomMenuButton* button = custom_menu_create_button(parent, label, x, y, scale, SOUND_MENU_CAMERA_ZOOM_IN, NULL); - struct CustomMenu* menu = calloc(1, sizeof(struct CustomMenu)); - menu->parent = parent; - menu->depth = parent->depth + 1; - menu->headerY = 25; - menu->me = button; - button->menu = menu; - return menu; -} - -void custom_menu_system_init(void) { - // allocate the main menu and set it to current - sHead = calloc(1, sizeof(struct CustomMenu)); - sHead->me = calloc(1, sizeof(struct CustomMenuButton)); - sCurrentMenu = sHead; - - // spawn the main menu game object - struct Object* obj = spawn_object_rel_with_rot(gCurrentObject, MODEL_MAIN_MENU_GREEN_SCORE_BUTTON, bhvMenuButton, 0, 0, 0, 0, 0, 0); - obj->oParentRelativePosZ += 1000; - obj->oMenuButtonState = MENU_BUTTON_STATE_FULLSCREEN; - obj->oFaceAngleYaw = 0x8000; - obj->oFaceAngleRoll = 0; - obj->oMenuButtonScale = 9.0f; - obj->oMenuButtonOrigPosZ = obj->oPosZ; - obj->oMenuButtonOrigPosX = 99999; - obj->oMenuButtonIsCustom = 1; - sHead->me->object = obj; - - custom_menu_init(sHead); -} - -void custom_menu_destroy(void) { - // TODO: clean up all of the calloc()'d memory -} - -void custom_menu_system_loop(void) { - custom_menu_loop(); -} - -static void button_force_instant_close(struct Object* obj) { - obj->oFaceAngleYaw = 0x8000; - obj->oFaceAnglePitch = 0; - obj->oParentRelativePosX = obj->oMenuButtonOrigPosX; - obj->oParentRelativePosY = obj->oMenuButtonOrigPosY; - obj->oParentRelativePosZ = obj->oMenuButtonOrigPosZ; - obj->oMenuButtonScale = 0.11111111f; - obj->oMenuButtonState = MENU_BUTTON_STATE_DEFAULT; - obj->oMenuButtonTimer = 0; -} - -static void button_force_instant_open(struct Object* obj) { - obj->oFaceAngleYaw = 0; - obj->oFaceAnglePitch = 0; - obj->oParentRelativePosX = 0.0f; - obj->oParentRelativePosY = 0.0f; - obj->oParentRelativePosZ = -801; - obj->oMenuButtonScale = 0.623111; - obj->oMenuButtonState = MENU_BUTTON_STATE_FULLSCREEN; - obj->oMenuButtonTimer = 0; -} - -void custom_menu_open(struct CustomMenu* menu) { - if (sCurrentMenu == menu) { return; } - if (menu == NULL) { return; } - // force instant-close all parents if not a direct route - { - // check all buttons of current menu to see if the desired menu is directly beneath it - struct CustomMenuButton* onButton = sCurrentMenu->buttons; - u8 foundMenu = FALSE; - while (onButton != NULL) { - if (onButton == menu->me) { foundMenu = TRUE; break; } - onButton = onButton->next; - } - - // if not direct route, force close all the way to the main menu - if (!foundMenu) { - struct CustomMenu* onMenu = sCurrentMenu; - while (onMenu != NULL && onMenu != sHead) { - struct Object* obj = onMenu->me->object; - if (obj->oMenuButtonState != MENU_BUTTON_STATE_FULLSCREEN) { break; } - button_force_instant_close(obj); - if (onMenu->on_close != NULL) { onMenu->on_close(); } - onMenu = onMenu->parent; - } - } - } - - // force instant-open all parents - { - struct CustomMenu* onMenu = menu->parent; - while (onMenu != NULL) { - struct Object* obj = onMenu->me->object; - if (obj->oMenuButtonState == MENU_BUTTON_STATE_FULLSCREEN) { break; } - button_force_instant_open(obj); - onMenu = onMenu->parent; - } - } - struct Object* obj = menu->me->object; - obj->oMenuButtonState = MENU_BUTTON_STATE_GROWING; - obj->oMenuButtonTimer = 0; - gMenuStringAlpha = 0; - sLastMenu = sCurrentMenu; - sCurrentMenu = menu; -} - -void custom_menu_close(void) { - struct Object* obj = sCurrentMenu->me->object; - obj->oMenuButtonState = MENU_BUTTON_STATE_SHRINKING; - obj->oMenuButtonTimer = 0; - gMenuStringAlpha = 0; - if (sCurrentMenu->on_close != NULL) { sCurrentMenu->on_close(); } - sLastMenu = sCurrentMenu; - if (sCurrentMenu->parent != NULL) { - sCurrentMenu = sCurrentMenu->parent; - } -} - -void custom_menu_close_system(void) { - sHead->me->object->oMenuButtonState = MENU_BUTTON_STATE_SHRINKING; - gInCustomMenu = FALSE; -} - -static s32 cursor_inside_button(struct CustomMenuButton* button, f32 cursorX, f32 cursorY) { - f32 x = button->object->oParentRelativePosX; - f32 y = button->object->oParentRelativePosY; - f32 scale = button->object->oMenuButtonScale; - - x *= -0.137f; - y *= 0.137f; - - s16 maxX = x + scale * 185.0f; - s16 minX = x - scale * 185.0f; - s16 maxY = y + scale * 185.0f; - s16 minY = y - scale * 101.0f; - - return (cursorX < maxX && minX < cursorX && cursorY < maxY && minY < cursorY); -} - -void custom_menu_cursor_click(f32 cursorX, f32 cursorY) { - -#ifdef VERSION_EU - u16 cursorClickButtons = (A_BUTTON | B_BUTTON | START_BUTTON | Z_TRIG); -#else - u16 cursorClickButtons = (A_BUTTON | B_BUTTON | START_BUTTON); -#endif - if (!(gPlayer3Controller->buttonPressed & cursorClickButtons)) { return; } - if (sCurrentMenu->me->object->oMenuButtonState != MENU_BUTTON_STATE_FULLSCREEN) { return; } - - if (sErrorDialog != NULL) { - struct ErrorDialog* current = sErrorDialog; - sErrorDialog = sErrorDialog->next; - free(current->dialog); - free(current); - play_sound(SOUND_ACTION_BONK, gDefaultSoundArgs); - if (sErrorDialog != NULL) { - play_sound(SOUND_MARIO_OOOF2, gDefaultSoundArgs); - } - return; - } - - struct CustomMenuButton* button = sCurrentMenu->buttons; - while (button != NULL) { - if (cursor_inside_button(button, cursorX, cursorY)) { - u8 didSomething = FALSE; - - if (button->menu != NULL) { - custom_menu_open(button->menu); - didSomething = TRUE; - } - - if (button->on_click != NULL) { - button->on_click(); - didSomething = TRUE; - } - - if (button->clickSound != 0) { - play_sound(button->clickSound, gDefaultSoundArgs); - } - - if (didSomething) { break; } - } - button = button->next; - } -} - -static void button_label_pos(struct CustomMenuButton* button, s16* outX, s16* outY) { - f32 x = button->object->oParentRelativePosX; - f32 y = button->object->oParentRelativePosY; - x -= strlen(button->label) * -27.0f; - y += -163.0f; - *outX = 165.0f + x * -0.137f; - *outY = 110.0f + y * 0.137f; -} - -void custom_menu_print_strings(void) { - // figure out alpha - struct Object* curObj = sCurrentMenu->me->object; - struct Object* lastObj = (sLastMenu != NULL) ? sLastMenu->me->object : NULL; - - if (curObj != NULL && lastObj != NULL) { - if (curObj->oMenuButtonState == MENU_BUTTON_STATE_FULLSCREEN && lastObj->oMenuButtonState != MENU_BUTTON_STATE_SHRINKING) { - if (gMenuStringAlpha < 250) { - gMenuStringAlpha += 10; - } else { - gMenuStringAlpha = 255; - } - } - } - - // print header - gSPDisplayList(gDisplayListHead++, dl_rgba16_text_begin); - gDPSetEnvColor(gDisplayListHead++, 255, 255, 255, gMenuStringAlpha); - char* headerLabel = sCurrentMenu->me->label; - u16 headerLabelLen = strlen(headerLabel); - u16 headerX = (u16)(159.66f - (headerLabelLen * 5.66f)); - - unsigned char header[64]; - str_ascii_to_dialog(headerLabel, header, headerLabelLen); - - print_hud_lut_string(HUD_LUT_DIFF, headerX, sCurrentMenu->headerY, header); - gSPDisplayList(gDisplayListHead++, dl_rgba16_text_end); - - // print text - gSPDisplayList(gDisplayListHead++, dl_ia_text_begin); - struct CustomMenuButton* button = sCurrentMenu->buttons; - while (button != NULL) { - gDPSetEnvColor(gDisplayListHead++, 222, 222, 222, gMenuStringAlpha); - s16 x, y; - button_label_pos(button, &x, &y); - print_generic_ascii_string(x, y, button->label); - button = button->next; - } - if (sCurrentMenu->draw_strings != NULL) { sCurrentMenu->draw_strings(); } - gSPDisplayList(gDisplayListHead++, dl_ia_text_end); -} - -void custom_menu_render_top(void) { - // print error message - if (sErrorDialog != NULL) { - // black screen - create_dl_translation_matrix(MENU_MTX_PUSH, GFX_DIMENSIONS_FROM_LEFT_EDGE(0), 240.0f, 0); - create_dl_scale_matrix(MENU_MTX_NOPUSH, GFX_DIMENSIONS_ASPECT_RATIO * SCREEN_HEIGHT / 130.0f, 3.0f, 1.0f); - gDPSetEnvColor(gDisplayListHead++, 0, 0, 0, 240); - gSPDisplayList(gDisplayListHead++, dl_draw_text_bg_box); - gSPPopMatrix(gDisplayListHead++, G_MTX_MODELVIEW); - - // print text - gSPDisplayList(gDisplayListHead++, dl_ia_text_begin); - f32 textWidth = get_generic_dialog_width(sErrorDialog->dialog); - f32 textHeight = get_generic_dialog_height(sErrorDialog->dialog); - - f32 xPos = (SCREEN_WIDTH - textWidth) / 2.0f; - f32 yPos = (SCREEN_HEIGHT + textHeight) / 2.0f; - - gDPSetEnvColor(gDisplayListHead++, 30, 30, 30, 255); - print_generic_string(xPos, yPos, sErrorDialog->dialog); - - gDPSetEnvColor(gDisplayListHead++, 255, 255, 255, 255); - print_generic_string((xPos - 1), (yPos + 1), sErrorDialog->dialog); - - gSPDisplayList(gDisplayListHead++, dl_ia_text_end); - } -} - -/** - * Grow from submenu, used by selecting a file in the score menu. - */ -void bhv_menu_button_growing_from_custom(struct Object* button) { - if (button->oMenuButtonTimer < 16) { - button->oFaceAngleYaw += 0x800; - } - if (button->oMenuButtonTimer < 8) { - button->oFaceAnglePitch += 0x800; - } - if (button->oMenuButtonTimer >= 8 && button->oMenuButtonTimer < 16) { - button->oFaceAnglePitch -= 0x800; - } - - button->oParentRelativePosX -= button->oMenuButtonOrigPosX / 16.0; - button->oParentRelativePosY -= button->oMenuButtonOrigPosY / 16.0; - button->oParentRelativePosZ -= 50; - - button->oMenuButtonScale += 0.032f; - - button->oMenuButtonTimer++; - if (button->oMenuButtonTimer == 16) { - button->oParentRelativePosX = 0.0f; - button->oParentRelativePosY = 0.0f; - button->oMenuButtonState = MENU_BUTTON_STATE_FULLSCREEN; - button->oMenuButtonTimer = 0; - } -} - -/** - * Shrink back to submenu, used to return back while inside a score save menu. - */ -void bhv_menu_button_shrinking_to_custom(struct Object* button) { - if (button->oMenuButtonTimer < 16) { - button->oFaceAngleYaw -= 0x800; - } - if (button->oMenuButtonTimer < 8) { - button->oFaceAnglePitch -= 0x800; - } - if (button->oMenuButtonTimer >= 8 && button->oMenuButtonTimer < 16) { - button->oFaceAnglePitch += 0x800; - } - - button->oParentRelativePosX += button->oMenuButtonOrigPosX / 16.0; - button->oParentRelativePosY += button->oMenuButtonOrigPosY / 16.0; - button->oParentRelativePosZ += 50; - - button->oMenuButtonScale -= 0.032f; - - button->oMenuButtonTimer++; - if (button->oMenuButtonTimer == 16) { - button->oParentRelativePosX = button->oMenuButtonOrigPosX; - button->oParentRelativePosY = button->oMenuButtonOrigPosY; - button->oMenuButtonScale = 0.11111111f; - button->oMenuButtonState = MENU_BUTTON_STATE_DEFAULT; - button->oMenuButtonTimer = 0; - } -} - -void custom_menu_error(char* message) { - struct ErrorDialog* errorDialog = malloc(sizeof(struct ErrorDialog)); - memset(errorDialog, 0, sizeof(struct ErrorDialog)); - errorDialog->dialog = malloc(sizeof(u8) * (strlen(message) + 1)); - str_ascii_to_dialog(message, errorDialog->dialog, strlen(message)); - - if (sErrorDialog == NULL) { - sErrorDialog = errorDialog; - play_sound(SOUND_MARIO_OOOF2, gDefaultSoundArgs); - } else { - struct ErrorDialog* item = sErrorDialog; - while (item != NULL) { - if (item->next == NULL) { - item->next = errorDialog; - break; - } - item = item->next; - } - } -} diff --git a/src/menu/custom_menu_system.h b/src/menu/custom_menu_system.h deleted file mode 100644 index f2e998d41..000000000 --- a/src/menu/custom_menu_system.h +++ /dev/null @@ -1,51 +0,0 @@ -#ifndef CUSTOM_MENU_SYSTEM_H -#define CUSTOM_MENU_SYSTEM_H -#include "file_select.h" - -struct CustomMenuButton { - struct Object* object; - char* label; - void (*on_click)(void); - u32 clickSound; - struct CustomMenu* menu; - struct CustomMenuButton* next; -}; - -struct CustomMenu { - struct CustomMenu* parent; - struct CustomMenuButton* me; - struct CustomMenuButton* buttons; - u16 headerY; - u16 depth; - void (*draw_strings)(void); - void (*on_close)(void); -}; - -struct CustomMenuButtonScale { - f32 small; - f32 medium; - f32 large; -}; -extern struct CustomMenuButtonScale gButtonScale; - -extern u8 gMenuStringAlpha; - -void custom_menu_system_init(void); -struct CustomMenu* custom_menu_create(struct CustomMenu* parent, char* label, u16 x, u16 y, f32 scale); -struct CustomMenuButton* custom_menu_create_button(struct CustomMenu* parent, char* label, u16 x, u16 y, f32 scale, s32 clickSound, void (*on_click)(void)); - -void custom_menu_system_loop(void); -void custom_menu_print_strings(void); -void custom_menu_render_top(void); -void custom_menu_cursor_click(f32 x, f32 y); - -void custom_menu_open(struct CustomMenu* menu); -void custom_menu_close(void); -void custom_menu_close_system(void); - -void bhv_menu_button_growing_from_custom(struct Object* button); -void bhv_menu_button_shrinking_to_custom(struct Object* button); - -void custom_menu_error(char* message); - -#endif // CUSTOM_MENU_SYSTEM_H diff --git a/src/menu/file_select.c b/src/menu/file_select.c index 86ccf5908..d0a36a06f 100644 --- a/src/menu/file_select.c +++ b/src/menu/file_select.c @@ -23,9 +23,6 @@ #include "eu_translation.h" -#include "custom_menu_system.h" -#include "custom_menu.h" - #ifdef VERSION_EU #undef LANGUAGE_FUNCTION #define LANGUAGE_FUNCTION sLanguageMode @@ -38,9 +35,6 @@ * special menu messages and phases, button states and button clicked checks. */ -u8 gInCustomMenu = 1; -u8 sIgnoreMenuTimer = 5; - #ifdef VERSION_US // The current sound mode is automatically centered on US due to // the large length difference between options. @@ -530,9 +524,7 @@ void bhv_menu_button_loop(void) { gCurrentObject->oMenuButtonOrigPosZ = gCurrentObject->oPosZ; break; case MENU_BUTTON_STATE_GROWING: // Switching from button to menu state - if (gInCustomMenu) { - bhv_menu_button_growing_from_custom(gCurrentObject); - } else if (sCurrentMenuLevel == MENU_LAYER_MAIN) { + if (sCurrentMenuLevel == MENU_LAYER_MAIN) { bhv_menu_button_growing_from_main_menu(gCurrentObject); } else if (sCurrentMenuLevel == MENU_LAYER_SUBMENU) { bhv_menu_button_growing_from_submenu(gCurrentObject); // Only used for score files @@ -543,9 +535,7 @@ void bhv_menu_button_loop(void) { case MENU_BUTTON_STATE_FULLSCREEN: // Menu state break; case MENU_BUTTON_STATE_SHRINKING: // Switching from menu to button state - if (gInCustomMenu) { - bhv_menu_button_shrinking_to_custom(gCurrentObject); - } else if (sCurrentMenuLevel == MENU_LAYER_MAIN) { + if (sCurrentMenuLevel == MENU_LAYER_MAIN) { bhv_menu_button_shrinking_to_main_menu(gCurrentObject); } else if (sCurrentMenuLevel == MENU_LAYER_SUBMENU) { bhv_menu_button_shrinking_to_submenu(gCurrentObject); // Only used for score files @@ -1127,7 +1117,6 @@ void check_sound_mode_menu_clicked_buttons(struct Object *soundModeButton) { void load_main_menu_save_file(struct Object *fileButton, s32 fileNum) { if (fileButton->oMenuButtonState == MENU_BUTTON_STATE_FULLSCREEN) { sSelectedFileNum = fileNum; - custom_menu_on_load_save_file(sSelectedFileNum); } } @@ -1362,9 +1351,6 @@ void bhv_menu_button_manager_init(void) { sMainMenuButtons[MENU_BUTTON_SOUND_MODE]->oMenuButtonScale = 1.0f; sTextBaseAlpha = 0; - - // custom menus - custom_menu_system_init(); } #if defined(VERSION_JP) || defined(VERSION_SH) @@ -1378,10 +1364,6 @@ void bhv_menu_button_manager_init(void) { * Also play a sound and/or render buttons depending of the button ID selected. */ void check_main_menu_clicked_buttons(void) { - if (sIgnoreMenuTimer > 0) { - sIgnoreMenuTimer--; - return; - } #ifdef VERSION_EU if (sMainMenuTimer >= 5) { #endif @@ -1461,10 +1443,6 @@ void check_main_menu_clicked_buttons(void) { * is loaded, and that checks what buttonID is clicked in the main menu. */ void bhv_menu_button_manager_loop(void) { - if (gInCustomMenu) { - custom_menu_system_loop(); - return; - } switch (sSelectedButtonID) { case MENU_BUTTON_NONE: check_main_menu_clicked_buttons(); @@ -1651,13 +1629,6 @@ void handle_controller_cursor_input(void) { if (sCursorPos[1] < -90.0f) { sCursorPos[1] = -90.0f; } - - if (sCursorClickingTimer == 0) { - handle_cursor_button_input(); - if (gInCustomMenu) { - custom_menu_cursor_click(sCursorPos[0], sCursorPos[1]); - } - } } /** @@ -2741,11 +2712,6 @@ static void print_file_select_strings(void) { create_dl_ortho_matrix(); - if (gInCustomMenu) { - custom_menu_print_strings(); - return; - } - switch (sSelectedButtonID) { case MENU_BUTTON_NONE: #ifdef VERSION_EU @@ -2804,7 +2770,6 @@ Gfx *geo_file_select_strings_and_menu_cursor(s32 callContext, UNUSED struct Grap if (callContext == GEO_CONTEXT_RENDER) { print_file_select_strings(); print_menu_cursor(); - custom_menu_render_top(); } return NULL; } diff --git a/src/menu/file_select.h b/src/menu/file_select.h index f05eeeccc..62235995f 100644 --- a/src/menu/file_select.h +++ b/src/menu/file_select.h @@ -129,7 +129,6 @@ enum SoundModeMenuActionPhase { extern f32 sCursorPos[2]; extern s8 sSelectedFileNum; -extern u8 gInCustomMenu; void beh_yellow_background_menu_init(void); void beh_yellow_background_menu_loop(void); diff --git a/src/pc/network/discord/activity.c b/src/pc/network/discord/activity.c index e0021bbc5..e4aa213c8 100644 --- a/src/pc/network/discord/activity.c +++ b/src/pc/network/discord/activity.c @@ -2,7 +2,6 @@ #include "lobby.h" #include "discord_network.h" #include "pc/debuglog.h" -#include "menu/custom_menu.h" #include "pc/network/version.h" #define HASH_LENGTH 8 @@ -39,7 +38,7 @@ static void on_activity_join_callback(UNUSED void* data, enum EDiscordResult res static void on_activity_join(UNUSED void* data, const char* secret) { LOG_INFO("> on_activity_join, secret: %s", secret); - gOpenConnectMenu = TRUE; + djui_connect_menu_open(); app.lobbies->connect_lobby_with_activity_secret(app.lobbies, (char*)secret, NULL, on_activity_join_callback); } diff --git a/src/pc/network/discord/discord.c b/src/pc/network/discord/discord.c index f890e7cf1..430ad38ae 100644 --- a/src/pc/network/discord/discord.c +++ b/src/pc/network/discord/discord.c @@ -4,7 +4,6 @@ #include "lobby.h" #include "discord_network.h" #include "pc/debuglog.h" -#include "menu/custom_menu_system.h" #include "pc/network/version.h" #if defined(_WIN32) || defined(_WIN64) @@ -149,7 +148,7 @@ static bool ns_discord_initialize(enum NetworkType networkType) { DISCORD_REQUIRE(rc); } else if (rc) { LOG_ERROR("DiscordCreate failed: %d", rc); - custom_menu_error("Could not detect Discord.\n\nTry closing the game,\nrestarting Discord,\nand opening the game again."); + djui_show_popup("Could not detect Discord.\n\nTry closing the game,\nrestarting Discord,\nand opening the game again."); gDiscordFailed = true; return false; } diff --git a/src/pc/network/network.c b/src/pc/network/network.c index f7f2f73e3..8c97e69dd 100644 --- a/src/pc/network/network.c +++ b/src/pc/network/network.c @@ -274,7 +274,17 @@ void network_shutdown(void) { gNetworkType = NT_NONE; } -// TODO: REPLACE WITH A REAL CHAT +// TODO: replace void chat_add_message(char* message) { LOG_INFO("chat: %s", message); -} \ No newline at end of file +} + +// TODO: replace +void djui_show_popup(char* message) { + LOG_INFO("popup: %s", message); +} + +// TODO: replace +void djui_connect_menu_open(void) { + LOG_INFO("djui: connecting"); +} diff --git a/src/pc/network/network.h b/src/pc/network/network.h index a24dd6854..60b4e7ded 100644 --- a/src/pc/network/network.h +++ b/src/pc/network/network.h @@ -101,6 +101,8 @@ void network_update(void); void network_register_mod(char* modName); void network_shutdown(void); -// TODO: replace with a real chat +// TODO: replace void chat_add_message(char* message); +void djui_show_popup(char* message); +void djui_connect_menu_open(void); #endif diff --git a/src/pc/network/packets/packet_join.c b/src/pc/network/packets/packet_join.c index ed87e20c3..704ba04fc 100644 --- a/src/pc/network/packets/packet_join.c +++ b/src/pc/network/packets/packet_join.c @@ -7,7 +7,6 @@ #include "src/game/interaction.h" #include "src/engine/math_util.h" #include "src/game/save_file.h" -#include "src/menu/custom_menu.h" #include "src/pc/fs/fs.h" #include "PR/os_eeprom.h" #include "pc/network/version.h" @@ -119,7 +118,7 @@ void network_receive_join(struct Packet* p) { char mismatchMessage[128] = { 0 }; snprintf(mismatchMessage, 128, "Version mismatch.\n\nYour version - %s\nTheir version - %s\n\nSomeone is out of date!\n", version, remoteVersion); - custom_menu_connection_error(mismatchMessage); + djui_show_popup(mismatchMessage); return; } @@ -144,7 +143,7 @@ void network_receive_join(struct Packet* p) { if (string_linked_list_mismatch(&gRegisteredMods, &head)) { string_linked_list_free(&head); - custom_menu_connection_error("Your mods don't match!"); + djui_show_popup("Your mods don't match!"); return; } string_linked_list_free(&head); @@ -153,5 +152,5 @@ void network_receive_join(struct Packet* p) { network_player_connected(NPT_LOCAL, myGlobalIndex); save_file_load_all(TRUE); - custom_menu_goto_game(gCurrSaveFileNum); + //custom_menu_goto_game(gCurrSaveFileNum); } diff --git a/src/pc/network/packets/packet_kick.c b/src/pc/network/packets/packet_kick.c index 21a0ef8b8..57d9da47a 100644 --- a/src/pc/network/packets/packet_kick.c +++ b/src/pc/network/packets/packet_kick.c @@ -1,6 +1,5 @@ #include #include "../network.h" -#include "menu/custom_menu_system.h" #include "pc/debuglog.h" void network_send_kick(enum KickReasonType kickReason) { @@ -27,8 +26,8 @@ void network_receive_kick(struct Packet* p) { enum KickReasonType kickReason = kickReasonType; switch (kickReason) { - case EKT_FULL_PARTY: custom_menu_error("The party is full."); break; - default: custom_menu_error("Host has closed the connection."); break; + case EKT_FULL_PARTY: djui_show_popup("The party is full."); break; + default: djui_show_popup("Host has closed the connection."); break; } network_shutdown(); } diff --git a/src/pc/network/packets/packet_leaving.c b/src/pc/network/packets/packet_leaving.c index 5d067b431..4e71af48a 100644 --- a/src/pc/network/packets/packet_leaving.c +++ b/src/pc/network/packets/packet_leaving.c @@ -1,6 +1,5 @@ #include #include "../network.h" -#include "menu/custom_menu_system.h" #include "pc/debuglog.h" void network_send_leaving(u8 globalIndex) { diff --git a/src/pc/network/socket/socket.c b/src/pc/network/socket/socket.c index 4387c34e8..f3dce82fa 100644 --- a/src/pc/network/socket/socket.c +++ b/src/pc/network/socket/socket.c @@ -2,7 +2,6 @@ #include "socket.h" #include "pc/configfile.h" #include "pc/debuglog.h" -#include "menu/custom_menu.h" static SOCKET curSocket = INVALID_SOCKET; static struct sockaddr_in addr[MAX_PLAYERS] = { 0 }; @@ -84,7 +83,7 @@ static bool ns_socket_initialize(enum NetworkType networkType) { if (networkType == NT_CLIENT) { char joinText[128] = { 0 }; snprintf(joinText, 63, "%s %d", configJoinIp, configJoinPort); - gOpenConnectMenu = TRUE; + djui_connect_menu_open(); gNetworkType = NT_CLIENT; network_send_join_request(); diff --git a/src/pc/pc_main.c b/src/pc/pc_main.c index 198bda378..18eff5ce1 100644 --- a/src/pc/pc_main.c +++ b/src/pc/pc_main.c @@ -42,7 +42,6 @@ #include "pc/discord/discordrpc.h" #endif #include "pc/network/version.h" -#include "menu/custom_menu_system.h" OSMesg D_80339BEC; OSMesgQueue gSIEventMesgQueue; @@ -281,7 +280,7 @@ void main_func(void) { } #ifdef UNSTABLE_BRANCH - custom_menu_error("This is an unstable branch build.\n\nExpect many strange bugs.\n\nFor a more stable experience use the normal coop branch."); + djui_show_popup("This is an unstable branch build.\n\nExpect many strange bugs.\n\nFor a more stable experience use the normal coop branch."); #endif audio_init();