From 2679e0eae0843e3a32c7474d7014dd7bbb514b4f Mon Sep 17 00:00:00 2001 From: AJ Martinez Date: Sat, 18 May 2024 21:09:00 -0700 Subject: [PATCH] Add Online Manual and I_OpenURL stuff --- src/dummy/i_system.c | 10 ++++++++++ src/i_system.h | 4 ++++ src/k_menu.h | 1 + src/menus/extras-1.c | 30 ++++++++++++++++++++++++++++++ src/sdl/i_system.cpp | 14 ++++++++++++++ 5 files changed, 59 insertions(+) diff --git a/src/dummy/i_system.c b/src/dummy/i_system.c index 519fac44a..e44d5efb6 100644 --- a/src/dummy/i_system.c +++ b/src/dummy/i_system.c @@ -195,5 +195,15 @@ void I_GetCursorPosition(INT32 *x, INT32 *y) (void)y; } +boolean I_HasOpenURL() +{ + return 0; +} + +void I_OpenURL(const char *data) +{ + return; +} + #include "../sdl/dosstr.c" diff --git a/src/i_system.h b/src/i_system.h index c78e09fd8..a55640017 100644 --- a/src/i_system.h +++ b/src/i_system.h @@ -309,6 +309,10 @@ void I_RegisterSysCommands(void); void I_CursedWindowMovement(int xd, int yd); +boolean I_HasOpenURL(void); + +void I_OpenURL(const char *data); + #ifdef __cplusplus } // extern "C" #endif diff --git a/src/k_menu.h b/src/k_menu.h index 643170b62..41192a9fb 100644 --- a/src/k_menu.h +++ b/src/k_menu.h @@ -1213,6 +1213,7 @@ extern struct extrasmenu_s { typedef enum { extras_addons = 0, + extras_manual, extras_tutorial, extras_challenges, extras_statistics, diff --git a/src/menus/extras-1.c b/src/menus/extras-1.c index 71c911537..81af3d716 100644 --- a/src/menus/extras-1.c +++ b/src/menus/extras-1.c @@ -17,6 +17,7 @@ #include "../f_finale.h" #include "../k_credits.h" #include "../m_pw.h" +#include "../i_system.h" static void M_Credits(INT32 choice) { @@ -26,6 +27,32 @@ static void M_Credits(INT32 choice) F_StartCredits(); } +const char *manual_url = "https://kartkrew.org/rr-manual"; + +static void M_ManualSelect(INT32 choice) +{ + if (choice != MA_YES) + return; + + I_OpenURL(manual_url); +} + +static void M_Manual(INT32 choice) +{ + (void)choice; + restoreMenu = currentMenu; + + if (I_HasOpenURL()) + { + M_StartMessage("Online Manual", "This will open a webpage in your default browser.", M_ManualSelect, MM_YESNO, "Let's go!", "Not now..."); + } + else + { + I_ClipboardCopy(manual_url, strlen(manual_url)); + M_StartMessage("Online Manual", "A URL has been copied to your clipboard!", NULL, MM_NOTHING, NULL, NULL); + } +} + menuitem_t EXTRAS_Main[] = { // The following has NULL strings for text and tooltip. @@ -35,6 +62,9 @@ menuitem_t EXTRAS_Main[] = {IT_STRING | IT_CALL, NULL, NULL, NULL, {.routine = M_Addons}, 0, 0}, + {IT_STRING | IT_CALL, "Online Manual", "Learn everything there is to know about handling, items, and strategy.", + NULL, {.routine = M_Manual}, 0, 0}, + {IT_STRING | IT_CALL, "Tutorial", "Help Dr. Robotnik and Tails test out their new Ring Racers.", NULL, {.routine = M_LevelSelectInit}, 0, GT_TUTORIAL}, diff --git a/src/sdl/i_system.cpp b/src/sdl/i_system.cpp index 7a4c36939..2f1027139 100644 --- a/src/sdl/i_system.cpp +++ b/src/sdl/i_system.cpp @@ -1013,6 +1013,20 @@ I_CursedWindowMovement (int xd, int yd) SDL_SetWindowPosition(window, window_x + xd, window_y + yd); } +boolean I_HasOpenURL() +{ + #if (SDL_VERSION_ATLEAST(2, 0, 14)) + return true; + #else + return false; + #endif +} + +void I_OpenURL(const char *data) +{ + SDL_OpenURL(data); +} + // // I_JoyScale //