From c072ec239cc139562353cad01b8317b3be547e5a Mon Sep 17 00:00:00 2001 From: lahm86 <33758420+lahm86@users.noreply.github.com> Date: Fri, 4 Oct 2024 13:12:56 +0100 Subject: [PATCH] overlay: add option to toggle game UI This adds an option to allow toggling the in-game UI. Resolves #1656. --- data/tr1/ship/cfg/TR1X_gameflow.json5 | 3 +++ data/tr1/ship/cfg/TR1X_gameflow_demo_pc.json5 | 3 +++ data/tr1/ship/cfg/TR1X_gameflow_ub.json5 | 3 +++ docs/tr1/CHANGELOG.md | 1 + docs/tr1/README.md | 1 + src/tr1/config.h | 1 + src/tr1/config_map.def | 1 + src/tr1/game/game_string.def | 3 +++ src/tr1/game/option/option_control.c | 2 ++ src/tr1/game/overlay.c | 11 ++++++++++- src/tr1/game/phase/phase_inventory.c | 4 +++- src/tr1/game/shell.c | 7 +++++++ src/tr1/global/types.h | 4 +++- src/tr1/specific/s_input.c | 10 ++++++++++ 14 files changed, 51 insertions(+), 3 deletions(-) diff --git a/data/tr1/ship/cfg/TR1X_gameflow.json5 b/data/tr1/ship/cfg/TR1X_gameflow.json5 index b9556f847..2ebc6bcf5 100644 --- a/data/tr1/ship/cfg/TR1X_gameflow.json5 +++ b/data/tr1/ship/cfg/TR1X_gameflow.json5 @@ -687,6 +687,7 @@ "KEYMAP_SAVE": "Quick Save", "KEYMAP_STEP_LEFT": "Step Left", "KEYMAP_STEP_RIGHT": "Step Right", + "KEYMAP_TOGGLE_UI": "Toggle UI", "KEYMAP_TURBO_CHEAT": "Turbo Speed", "KEYMAP_USE_BIG_MEDI": "Large Medi", "KEYMAP_USE_SMALL_MEDI": "Small Medi", @@ -757,6 +758,8 @@ "OSD_TEXTURE_FILTER_BILINEAR": "bilinear", "OSD_TEXTURE_FILTER_NN": "nearest-neighbor", "OSD_TEXTURE_FILTER_SET": "Texture filter set to %s", + "OSD_UI_OFF": "UI disabled", + "OSD_UI_ON": "UI enabled", "OSD_UNKNOWN_COMMAND": "Unknown command: %s", "PASSPORT_EXIT_GAME": "Exit Game", "PASSPORT_EXIT_TO_TITLE": "Exit to Title", diff --git a/data/tr1/ship/cfg/TR1X_gameflow_demo_pc.json5 b/data/tr1/ship/cfg/TR1X_gameflow_demo_pc.json5 index 29c22f82f..8db33fca5 100644 --- a/data/tr1/ship/cfg/TR1X_gameflow_demo_pc.json5 +++ b/data/tr1/ship/cfg/TR1X_gameflow_demo_pc.json5 @@ -180,6 +180,7 @@ "KEYMAP_SAVE": "Quick Save", "KEYMAP_STEP_LEFT": "Step Left", "KEYMAP_STEP_RIGHT": "Step Right", + "KEYMAP_TOGGLE_UI": "Toggle UI", "KEYMAP_TURBO_CHEAT": "Turbo Speed", "KEYMAP_USE_BIG_MEDI": "Large Medi", "KEYMAP_USE_SMALL_MEDI": "Small Medi", @@ -250,6 +251,8 @@ "OSD_TEXTURE_FILTER_BILINEAR": "bilinear", "OSD_TEXTURE_FILTER_NN": "nearest-neighbor", "OSD_TEXTURE_FILTER_SET": "Texture filter set to %s", + "OSD_UI_OFF": "UI disabled", + "OSD_UI_ON": "UI enabled", "OSD_UNKNOWN_COMMAND": "Unknown command: %s", "PASSPORT_EXIT_GAME": "Exit Game", "PASSPORT_EXIT_TO_TITLE": "Exit to Title", diff --git a/data/tr1/ship/cfg/TR1X_gameflow_ub.json5 b/data/tr1/ship/cfg/TR1X_gameflow_ub.json5 index 65427cfb9..b83e01067 100644 --- a/data/tr1/ship/cfg/TR1X_gameflow_ub.json5 +++ b/data/tr1/ship/cfg/TR1X_gameflow_ub.json5 @@ -252,6 +252,7 @@ "KEYMAP_SAVE": "Quick Save", "KEYMAP_STEP_LEFT": "Step Left", "KEYMAP_STEP_RIGHT": "Step Right", + "KEYMAP_TOGGLE_UI": "Toggle UI", "KEYMAP_TURBO_CHEAT": "Turbo Speed", "KEYMAP_USE_BIG_MEDI": "Large Medi", "KEYMAP_USE_SMALL_MEDI": "Small Medi", @@ -322,6 +323,8 @@ "OSD_TEXTURE_FILTER_BILINEAR": "bilinear", "OSD_TEXTURE_FILTER_NN": "nearest-neighbor", "OSD_TEXTURE_FILTER_SET": "Texture filter set to %s", + "OSD_UI_OFF": "UI disabled", + "OSD_UI_ON": "UI enabled", "OSD_UNKNOWN_COMMAND": "Unknown command: %s", "PASSPORT_EXIT_GAME": "Exit Game", "PASSPORT_EXIT_TO_TITLE": "Exit to Title", diff --git a/docs/tr1/CHANGELOG.md b/docs/tr1/CHANGELOG.md index 6f329a496..55196756e 100644 --- a/docs/tr1/CHANGELOG.md +++ b/docs/tr1/CHANGELOG.md @@ -2,6 +2,7 @@ - added `/sfx` command - added `/nextlevel` alias to `/endlevel` console command - added `/quit` alias to `/exit` console command +- added an option to toggle the in-game UI, such as healthbars and ammo text (#1656) - changed the easter egg console command to pack more punch - changed `/set` console command to do fuzzy matching (LostArtefacts/libtrx#38) - fixed console caret position off by a couple of pixels (regression from 3.0) diff --git a/docs/tr1/README.md b/docs/tr1/README.md index 576dcc176..8e1815693 100644 --- a/docs/tr1/README.md +++ b/docs/tr1/README.md @@ -372,6 +372,7 @@ Not all options are turned on by default. Refer to `TR1X_ConfigTool.exe` for det - added fade effects to displayed images - added an option to use PS1 loading screens - added a wireframe mode +- added an option to toggle in-game UI, such as healthbars and ammo text - improved support for windowed mode #### Gameplay diff --git a/src/tr1/config.h b/src/tr1/config.h index f113404a4..2194e005c 100644 --- a/src/tr1/config.h +++ b/src/tr1/config.h @@ -121,6 +121,7 @@ typedef struct { int32_t turbo_speed; bool pretty_pixels; bool enable_reflections; + bool enable_ui; } rendering; struct { diff --git a/src/tr1/config_map.def b/src/tr1/config_map.def index 891ce1f53..d07c52fb9 100644 --- a/src/tr1/config_map.def +++ b/src/tr1/config_map.def @@ -109,3 +109,4 @@ CFG_BOOL(g_Config, profile.new_game_plus_unlock, false) CFG_BOOL(g_Config, fix_animated_sprites, true) CFG_BOOL(g_Config, enable_skybox, true) CFG_BOOL(g_Config, enable_ps1_crystals, true) +CFG_BOOL(g_Config, rendering.enable_ui, true) diff --git a/src/tr1/game/game_string.def b/src/tr1/game/game_string.def index da2ac9eaa..99496eb11 100644 --- a/src/tr1/game/game_string.def +++ b/src/tr1/game/game_string.def @@ -72,6 +72,7 @@ GS_DEFINE(KEYMAP_LEVEL_SKIP_CHEAT, "Level Skip") GS_DEFINE(KEYMAP_TURBO_CHEAT, "Turbo Speed") GS_DEFINE(KEYMAP_ENTER_CONSOLE, "Enter Console") GS_DEFINE(KEYMAP_CHANGE_TARGET, "Change Target") +GS_DEFINE(KEYMAP_TOGGLE_UI, "Toggle UI") GS_DEFINE(KEYMAP_CAMERA_UP, "Camera Up") GS_DEFINE(KEYMAP_CAMERA_DOWN, "Camera Down") GS_DEFINE(KEYMAP_CAMERA_LEFT, "Camera Left") @@ -151,6 +152,8 @@ GS_DEFINE(OSD_PERSPECTIVE_FILTER_ON, "Perspective filter enabled") GS_DEFINE(OSD_PERSPECTIVE_FILTER_OFF, "Perspective filter disabled") GS_DEFINE(OSD_FPS_COUNTER_ON, "FPS counter enabled") GS_DEFINE(OSD_FPS_COUNTER_OFF, "FPS counter disabled") +GS_DEFINE(OSD_UI_ON, "UI enabled") +GS_DEFINE(OSD_UI_OFF, "UI disabled") GS_DEFINE(OSD_DOOR_OPEN, "Open Sesame!") GS_DEFINE(OSD_DOOR_CLOSE, "Close Sesame!") GS_DEFINE(OSD_DOOR_OPEN_FAIL, "No doors in Lara's proximity") diff --git a/src/tr1/game/option/option_control.c b/src/tr1/game/option/option_control.c index 8285c3d14..5a1600990 100644 --- a/src/tr1/game/option/option_control.c +++ b/src/tr1/game/option/option_control.c @@ -144,6 +144,7 @@ static const TEXT_COLUMN_PLACEMENT CtrlTextPlacementNormal[] = { { INPUT_ROLE_FPS, GS_ID(KEYMAP_FPS), true }, { INPUT_ROLE_BILINEAR, GS_ID(KEYMAP_BILINEAR), true }, { INPUT_ROLE_ENTER_CONSOLE, GS_ID(KEYMAP_ENTER_CONSOLE), true }, + { INPUT_ROLE_TOGGLE_UI, GS_ID(KEYMAP_TOGGLE_UI), true }, // end { COL_END, NULL, false }, }; @@ -184,6 +185,7 @@ static const TEXT_COLUMN_PLACEMENT CtrlTextPlacementCheats[] = { { INPUT_ROLE_LEVEL_SKIP_CHEAT, GS_ID(KEYMAP_LEVEL_SKIP_CHEAT), true }, { INPUT_ROLE_TURBO_CHEAT, GS_ID(KEYMAP_TURBO_CHEAT), true }, { INPUT_ROLE_ENTER_CONSOLE, GS_ID(KEYMAP_ENTER_CONSOLE), true }, + { INPUT_ROLE_TOGGLE_UI, GS_ID(KEYMAP_TOGGLE_UI), true }, // end { COL_END, NULL, false }, }; diff --git a/src/tr1/game/overlay.c b/src/tr1/game/overlay.c index a682ad1bf..ea4186f7a 100644 --- a/src/tr1/game/overlay.c +++ b/src/tr1/game/overlay.c @@ -715,6 +715,11 @@ void Overlay_HideGameInfo(void) void Overlay_DrawGameInfo(void) { M_ResetBarLocations(); + if (!g_Config.rendering.enable_ui) { + M_RemoveAmmoText(); + return; + } + Overlay_BarDrawHealth(); M_BarDrawAir(); M_BarDrawEnemy(); @@ -724,7 +729,7 @@ void Overlay_DrawGameInfo(void) void Overlay_DrawFPSInfo(void) { - if (g_Config.rendering.enable_fps_counter) { + if (g_Config.rendering.enable_fps_counter && g_Config.rendering.enable_ui) { const int32_t text_offset_x = 3; const int32_t text_height = 17; const int32_t text_inv_offset_y = 3; @@ -781,6 +786,10 @@ void Overlay_DrawFPSInfo(void) void Overlay_AddPickup(const GAME_OBJECT_ID object_id) { + if (!g_Config.rendering.enable_ui) { + return; + } + int32_t grid_x = -1; int32_t grid_y = -1; for (int i = 0; i < MAX_PICKUPS; i++) { diff --git a/src/tr1/game/phase/phase_inventory.c b/src/tr1/game/phase/phase_inventory.c index 1cb3d4d9a..268b879e3 100644 --- a/src/tr1/game/phase/phase_inventory.c +++ b/src/tr1/game/phase/phase_inventory.c @@ -135,7 +135,9 @@ static void Inv_Draw(RING_INFO *ring, IMOTION_INFO *motion) switch (inv_item->object_id) { case O_MEDI_OPTION: case O_BIGMEDI_OPTION: - Overlay_BarDrawHealth(); + if (g_Config.rendering.enable_ui) { + Overlay_BarDrawHealth(); + } break; default: diff --git a/src/tr1/game/shell.c b/src/tr1/game/shell.c index 34dc4152f..fddedc1cf 100644 --- a/src/tr1/game/shell.c +++ b/src/tr1/game/shell.c @@ -337,6 +337,13 @@ void Shell_ProcessInput(void) Config_Write(); } + if (g_InputDB.toggle_ui) { + g_Config.rendering.enable_ui ^= true; + Console_Log( + g_Config.rendering.enable_ui ? GS(OSD_UI_ON) : GS(OSD_UI_OFF)); + Config_Write(); + } + if (g_InputDB.turbo_cheat) { Clock_CycleTurboSpeed(!g_Input.slow); } diff --git a/src/tr1/global/types.h b/src/tr1/global/types.h index d026c9f00..a46143833 100644 --- a/src/tr1/global/types.h +++ b/src/tr1/global/types.h @@ -966,6 +966,7 @@ typedef union INPUT_STATE { uint64_t menu_back : 1; uint64_t enter_console : 1; uint64_t change_target : 1; + uint64_t toggle_ui : 1; }; } INPUT_STATE; @@ -1005,7 +1006,8 @@ typedef enum { INPUT_ROLE_BILINEAR = 32, INPUT_ROLE_ENTER_CONSOLE = 33, INPUT_ROLE_CHANGE_TARGET = 34, - INPUT_ROLE_NUMBER_OF = 35, + INPUT_ROLE_TOGGLE_UI = 35, + INPUT_ROLE_NUMBER_OF = 36, } INPUT_ROLE; typedef enum { diff --git a/src/tr1/specific/s_input.c b/src/tr1/specific/s_input.c index d63ded7d0..ae4774f94 100644 --- a/src/tr1/specific/s_input.c +++ b/src/tr1/specific/s_input.c @@ -64,6 +64,7 @@ static INPUT_SCANCODE m_Layout[INPUT_LAYOUT_NUMBER_OF][INPUT_ROLE_NUMBER_OF] = { SDL_SCANCODE_F3, // INPUT_ROLE_BILINEAR SDL_SCANCODE_SLASH, // INPUT_ROLE_ENTER_CONSOLE SDL_SCANCODE_Z, // INPUT_ROLE_CHANGE_TARGET + SDL_SCANCODE_H, // INPUT_ROLE_TOGGLE_UI }, // custom user controls @@ -103,6 +104,7 @@ static INPUT_SCANCODE m_Layout[INPUT_LAYOUT_NUMBER_OF][INPUT_ROLE_NUMBER_OF] = { SDL_SCANCODE_F3, // INPUT_ROLE_BILINEAR SDL_SCANCODE_SLASH, // INPUT_ROLE_ENTER_CONSOLE SDL_SCANCODE_Z, // INPUT_ROLE_CHANGE_TARGET + SDL_SCANCODE_H, // INPUT_ROLE_TOGGLE_UI }, { @@ -141,6 +143,7 @@ static INPUT_SCANCODE m_Layout[INPUT_LAYOUT_NUMBER_OF][INPUT_ROLE_NUMBER_OF] = { SDL_SCANCODE_F3, // INPUT_ROLE_BILINEAR SDL_SCANCODE_SLASH, // INPUT_ROLE_ENTER_CONSOLE SDL_SCANCODE_Z, // INPUT_ROLE_CHANGE_TARGET + SDL_SCANCODE_H, // INPUT_ROLE_TOGGLE_UI }, { @@ -179,6 +182,7 @@ static INPUT_SCANCODE m_Layout[INPUT_LAYOUT_NUMBER_OF][INPUT_ROLE_NUMBER_OF] = { SDL_SCANCODE_F3, // INPUT_ROLE_BILINEAR SDL_SCANCODE_SLASH, // INPUT_ROLE_ENTER_CONSOLE SDL_SCANCODE_Z, // INPUT_ROLE_CHANGE_TARGET + SDL_SCANCODE_H, // INPUT_ROLE_TOGGLE_UI } // clang-format on }; @@ -222,6 +226,7 @@ static CONTROLLER_MAP { BT_BUTTON, {SDL_CONTROLLER_BUTTON_INVALID}, 0 }, // INPUT_ROLE_BILINEAR { BT_BUTTON, {SDL_CONTROLLER_BUTTON_INVALID}, 0 }, // INPUT_ROLE_ENTER_CONSOLE { BT_BUTTON, {SDL_CONTROLLER_BUTTON_LEFTSTICK}, 0 }, // INPUT_ROLE_CHANGE_TARGET + { BT_BUTTON, {SDL_CONTROLLER_BUTTON_INVALID}, 0 }, // INPUT_ROLE_TOGGLE_UI }, { @@ -260,6 +265,7 @@ static CONTROLLER_MAP { BT_BUTTON, {SDL_CONTROLLER_BUTTON_INVALID}, 0 }, // INPUT_ROLE_BILINEAR { BT_BUTTON, {SDL_CONTROLLER_BUTTON_INVALID}, 0 }, // INPUT_ROLE_ENTER_CONSOLE { BT_BUTTON, {SDL_CONTROLLER_BUTTON_LEFTSTICK}, 0 }, // INPUT_ROLE_CHANGE_TARGET + { BT_BUTTON, {SDL_CONTROLLER_BUTTON_INVALID}, 0 }, // INPUT_ROLE_TOGGLE_UI }, { @@ -298,6 +304,7 @@ static CONTROLLER_MAP { BT_BUTTON, {SDL_CONTROLLER_BUTTON_INVALID}, 0 }, // INPUT_ROLE_BILINEAR { BT_BUTTON, {SDL_CONTROLLER_BUTTON_INVALID}, 0 }, // INPUT_ROLE_ENTER_CONSOLE { BT_BUTTON, {SDL_CONTROLLER_BUTTON_LEFTSTICK}, 0 }, // INPUT_ROLE_CHANGE_TARGET + { BT_BUTTON, {SDL_CONTROLLER_BUTTON_INVALID}, 0 }, // INPUT_ROLE_TOGGLE_UI }, { @@ -336,6 +343,7 @@ static CONTROLLER_MAP { BT_BUTTON, {SDL_CONTROLLER_BUTTON_INVALID}, 0 }, // INPUT_ROLE_BILINEAR { BT_BUTTON, {SDL_CONTROLLER_BUTTON_INVALID}, 0 }, // INPUT_ROLE_ENTER_CONSOLE { BT_BUTTON, {SDL_CONTROLLER_BUTTON_LEFTSTICK}, 0 }, // INPUT_ROLE_CHANGE_TARGET + { BT_BUTTON, {SDL_CONTROLLER_BUTTON_INVALID}, 0 }, // INPUT_ROLE_TOGGLE_UI } // clang-format on }; @@ -868,6 +876,7 @@ static INPUT_STATE M_GetControllerState( state.load |= M_GetBindState(INPUT_ROLE_LOAD, cntlr_layout_num); state.toggle_fps_counter |= M_GetBindState(INPUT_ROLE_FPS, cntlr_layout_num); state.toggle_bilinear_filter |= M_GetBindState(INPUT_ROLE_BILINEAR, cntlr_layout_num); + state.toggle_ui |= M_GetBindState(INPUT_ROLE_TOGGLE_UI, cntlr_layout_num); state.change_target |= M_GetBindState(INPUT_ROLE_CHANGE_TARGET, cntlr_layout_num); state.menu_confirm |= M_JoyBtn(SDL_CONTROLLER_BUTTON_A); state.menu_back |= M_JoyBtn(SDL_CONTROLLER_BUTTON_B); @@ -982,6 +991,7 @@ INPUT_STATE S_Input_GetCurrentState( linput.toggle_fps_counter = M_Key(INPUT_ROLE_FPS, layout_num); linput.toggle_bilinear_filter = M_Key(INPUT_ROLE_BILINEAR, layout_num); linput.toggle_perspective_filter = KEY_DOWN(SDL_SCANCODE_F4); + linput.toggle_ui = M_Key(INPUT_ROLE_TOGGLE_UI, layout_num); // clang-format on if (m_Controller) {