Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

misc: reconfigure UI toggling mechanism #1683

Merged
merged 3 commits into from
Oct 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions data/tr2/ship/cfg/TR2X_gameflow.json5
Original file line number Diff line number Diff line change
Expand Up @@ -405,6 +405,8 @@
"OSD_SAVE_GAME_FAIL_INVALID_SLOT": "Invalid save slot %d",
"OSD_SOUND_AVAILABLE_SAMPLES": "Available sounds: %s",
"OSD_SOUND_PLAYING_SAMPLE": "Playing sound %d",
"OSD_UI_OFF": "UI disabled",
"OSD_UI_ON": "UI enabled",
"OSD_UNKNOWN_COMMAND": "Unknown command: %s",
},
}
11 changes: 10 additions & 1 deletion src/libtrx/game/ui/common.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#include "game/ui/common.h"

#include "vector.h"
#include "config.h"
#include "game/console/common.h"
#include "game/game_string.h"

void UI_Init(void)
{
Expand All @@ -12,6 +14,13 @@ void UI_Shutdown(void)
UI_Events_Shutdown();
}

void UI_ToggleState(bool *const config_setting)
{
*config_setting ^= true;
Config_Write();
Console_Log(*config_setting ? GS(OSD_UI_ON) : GS(OSD_UI_OFF));
}

void UI_HandleKeyDown(const uint32_t key)
{
const EVENT event = {
Expand Down
2 changes: 2 additions & 0 deletions src/libtrx/include/libtrx/game/game_string.def
Original file line number Diff line number Diff line change
Expand Up @@ -43,3 +43,5 @@ GS_DEFINE(OSD_FLIPMAP_FAIL_ALREADY_ON, "Flipmap is already ON")
GS_DEFINE(OSD_FLIPMAP_FAIL_ALREADY_OFF, "Flipmap is already OFF")
GS_DEFINE(OSD_AMBIGUOUS_INPUT_2, "Ambiguous input: %s and %s")
GS_DEFINE(OSD_AMBIGUOUS_INPUT_3, "Ambiguous input: %s, %s, ...")
GS_DEFINE(OSD_UI_ON, "UI enabled")
GS_DEFINE(OSD_UI_OFF, "UI disabled")
1 change: 1 addition & 0 deletions src/libtrx/include/libtrx/game/ui/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ typedef enum {

void UI_Init(void);
void UI_Shutdown(void);
void UI_ToggleState(bool *config_setting);

void UI_HandleKeyDown(uint32_t key);
void UI_HandleKeyUp(uint32_t key);
Expand Down
3 changes: 2 additions & 1 deletion src/tr1/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,8 @@ typedef struct {
} rendering;

struct {
bool enable_ui;
bool enable_game_ui;
bool enable_photo_mode_ui;
double text_scale;
double bar_scale;
UI_STYLE menu_style;
Expand Down
3 changes: 2 additions & 1 deletion src/tr1/config_map.def
Original file line number Diff line number Diff line change
Expand Up @@ -109,4 +109,5 @@ 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, ui.enable_ui, true)
CFG_BOOL(g_Config, ui.enable_game_ui, true)
CFG_BOOL(g_Config, ui.enable_photo_mode_ui, true)
5 changes: 5 additions & 0 deletions src/tr1/game/game/game.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#include "game/stats.h"
#include "global/vars.h"

#include <libtrx/game/ui/common.h>
#include <libtrx/log.h>

#define FRAME_BUFFER(key) \
Expand Down Expand Up @@ -58,6 +59,10 @@ void Game_ProcessInput(void)
FRAME_BUFFER(toggle_fps_counter);
}
}

if (g_InputDB.toggle_ui) {
UI_ToggleState(&g_Config.ui.enable_game_ui);
}
}

bool Game_Start(int32_t level_num, GAMEFLOW_LEVEL_TYPE level_type)
Expand Down
2 changes: 0 additions & 2 deletions src/tr1/game/game_string.def
Original file line number Diff line number Diff line change
Expand Up @@ -156,8 +156,6 @@ GS_DEFINE(OSD_PERSPECTIVE_FILTER_OFF, "Perspective filter disabled")
GS_DEFINE(OSD_PHOTO_MODE_LAUNCHED, "Entering photo mode, press %s for help")
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")
Expand Down
10 changes: 5 additions & 5 deletions src/tr1/game/overlay.c
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ static void M_BarGetLocation(

void Overlay_BarDraw(BAR_INFO *bar_info, RENDER_SCALE_REF scale_ref)
{
if (!g_Config.ui.enable_ui) {
if (!g_Config.ui.enable_game_ui) {
return;
}

Expand Down Expand Up @@ -324,7 +324,7 @@ static float M_Ease(int32_t cur_frame, int32_t max_frames)

static void M_DrawPickup3D(DISPLAY_PICKUP *pu)
{
if (!g_Config.ui.enable_ui) {
if (!g_Config.ui.enable_game_ui) {
return;
}

Expand Down Expand Up @@ -490,7 +490,7 @@ static void M_DrawPickupsSprites(void)
continue;
}

if (!g_Config.ui.enable_ui) {
if (!g_Config.ui.enable_game_ui) {
return;
}

Expand Down Expand Up @@ -600,7 +600,7 @@ static void M_RemoveAmmoText(void)

static void M_DrawAmmoInfo(void)
{
if (!g_Config.ui.enable_ui) {
if (!g_Config.ui.enable_game_ui) {
M_RemoveAmmoText();
return;
}
Expand Down Expand Up @@ -742,7 +742,7 @@ void Overlay_DrawGameInfo(void)

void Overlay_DrawFPSInfo(void)
{
if (g_Config.rendering.enable_fps_counter && g_Config.ui.enable_ui
if (g_Config.rendering.enable_fps_counter && g_Config.ui.enable_game_ui
&& Phase_Get() != PHASE_PHOTO_MODE) {
const int32_t text_offset_x = 3;
const int32_t text_height = 17;
Expand Down
2 changes: 1 addition & 1 deletion src/tr1/game/phase/phase_inventory.c
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ static void Inv_Draw(RING_INFO *ring, IMOTION_INFO *motion)
switch (inv_item->object_id) {
case O_MEDI_OPTION:
case O_BIGMEDI_OPTION:
if (g_Config.ui.enable_ui) {
if (g_Config.ui.enable_game_ui) {
Overlay_BarDrawHealth();
}
break;
Expand Down
14 changes: 6 additions & 8 deletions src/tr1/game/phase/phase_photo_mode.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

#include <libtrx/game/console/common.h>
#include <libtrx/game/game_string.h>
#include <libtrx/game/ui/common.h>

#include <assert.h>
#include <stdio.h>
Expand All @@ -23,7 +24,6 @@ typedef enum {
PS_COOLDOWN,
} PHOTO_STATUS;

static bool m_OldUIState;
static PHASE_PHOTO_MODE_ARGS m_Args;

static PHOTO_STATUS m_Status = PS_NONE;
Expand All @@ -41,15 +41,14 @@ static void M_Start(const PHASE_PHOTO_MODE_ARGS *const args)

m_Status = PS_NONE;
g_OldInputDB = g_Input;
m_OldUIState = g_Config.ui.enable_ui;
Camera_EnterPhotoMode();

Overlay_HideGameInfo();
Music_Pause();
Sound_PauseAll();

m_PhotoMode = UI_PhotoMode_Create();
if (!g_Config.ui.enable_ui) {
if (!g_Config.ui.enable_photo_mode_ui) {
Console_Log(
GS(OSD_PHOTO_MODE_LAUNCHED),
Input_GetKeyName(
Expand All @@ -63,11 +62,6 @@ static void M_End(void)

g_Input = g_OldInputDB;

if (m_OldUIState != g_Config.ui.enable_ui) {
g_Config.ui.enable_ui ^= true;
Config_Write();
}

m_PhotoMode->free(m_PhotoMode);
m_PhotoMode = NULL;

Expand All @@ -88,6 +82,10 @@ static PHASE_CONTROL M_Control(int32_t nframes)
Input_Update();
Shell_ProcessInput();

if (g_InputDB.toggle_ui) {
UI_ToggleState(&g_Config.ui.enable_photo_mode_ui);
}

if (g_InputDB.toggle_photo_mode || g_InputDB.option) {
Phase_Set(m_Args.phase_to_return_to, m_Args.phase_arg);
return (PHASE_CONTROL) { .end = false };
Expand Down
6 changes: 0 additions & 6 deletions src/tr1/game/shell.c
Original file line number Diff line number Diff line change
Expand Up @@ -338,12 +338,6 @@ void Shell_ProcessInput(void)
Config_Write();
}

if (g_InputDB.toggle_ui) {
g_Config.ui.enable_ui ^= true;
Console_Log(g_Config.ui.enable_ui ? GS(OSD_UI_ON) : GS(OSD_UI_OFF));
Config_Write();
}

if (g_InputDB.turbo_cheat) {
Clock_CycleTurboSpeed(!g_Input.slow);
}
Expand Down
2 changes: 1 addition & 1 deletion src/tr1/game/ui/widgets/photo_mode.c
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ static void M_Control(UI_PHOTO_MODE *const self)
self->window->control(self->window);
}

self->shown = g_Config.ui.enable_ui;
self->shown = g_Config.ui.enable_photo_mode_ui;
}

static void M_Draw(UI_PHOTO_MODE *const self)
Expand Down