Skip to content
This repository has been archived by the owner on Oct 4, 2024. It is now read-only.

ui: move console ui to libtrx #267

Merged
merged 7 commits into from
Sep 26, 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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
## [Unreleased](https://github.com/LostArtefacts/TR2X/compare/stable...develop) - ××××-××-××
- added `/sfx` command
- fixed crash in the `/set` console command (regression from 0.3)
- fixed using console in cutscenes immediately exiting the game (regression from 0.3)

## [0.3](https://github.com/LostArtefacts/TR2X/compare/0.2-460-g4721b93...0.3) - 2024-09-20
- added new console commands:
Expand Down
3 changes: 0 additions & 3 deletions meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -163,15 +163,12 @@ dll_sources = [
'src/game/text.c',
'src/game/ui/common.c',
'src/game/ui/controllers/controls.c',
'src/game/ui/events.c',
'src/game/ui/widgets/console.c',
'src/game/ui/widgets/controls_column.c',
'src/game/ui/widgets/controls_dialog.c',
'src/game/ui/widgets/controls_input_selector.c',
'src/game/ui/widgets/controls_layout_selector.c',
'src/game/ui/widgets/label.c',
'src/game/ui/widgets/prompt.c',
'src/game/ui/widgets/stack.c',
'src/game/ui/widgets/window.c',
'src/global/enum_str.c',
'src/global/vars.c',
Expand Down
28 changes: 8 additions & 20 deletions src/config.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,37 +2,25 @@

#include "config_map.h"

#include <libtrx/config/config_file.h>
#include <libtrx/filesystem.h>
#include <libtrx/config/file.h>

CONFIG g_Config = { 0 };

#define DIR_CONFIG "cfg"
static const char *m_ConfigPath = "cfg/TR2X.json5";

static const char *m_ConfigPath = DIR_CONFIG "/TR2X.json5";

static void M_Load(JSON_OBJECT *root_obj);
static void M_Dump(JSON_OBJECT *root_obj);

static void M_Load(JSON_OBJECT *root_obj)
const char *Config_GetPath(void)
{
ConfigFile_LoadOptions(root_obj, g_ConfigOptionMap);
return m_ConfigPath;
}

static void M_Dump(JSON_OBJECT *root_obj)
void Config_LoadFromJSON(JSON_OBJECT *root_obj)
{
ConfigFile_DumpOptions(root_obj, g_ConfigOptionMap);
}

bool Config_Read(void)
{
return ConfigFile_Read(m_ConfigPath, &M_Load);
ConfigFile_LoadOptions(root_obj, g_ConfigOptionMap);
}

bool Config_Write(void)
void Config_DumpToJSON(JSON_OBJECT *root_obj)
{
File_CreateDirectory(DIR_CONFIG);
return ConfigFile_Write(m_ConfigPath, &M_Dump);
ConfigFile_DumpOptions(root_obj, g_ConfigOptionMap);
}

void Config_Sanitize(void)
Expand Down
8 changes: 1 addition & 7 deletions src/config.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#pragma once

#include <libtrx/config/config_option.h>
#include <libtrx/config.h>

#include <stdbool.h>

Expand All @@ -13,9 +13,3 @@ typedef struct {
} CONFIG;

extern CONFIG g_Config;

bool Config_Read(void);
bool Config_Write(void);
void Config_Sanitize(void);
void Config_ApplyChanges(void);
const CONFIG_OPTION *Config_GetOptionMap(void);
2 changes: 1 addition & 1 deletion src/config_map.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#include "config.h"

// import order guard
#include <libtrx/config/config_map.h>
#include <libtrx/config/map.h>
// import order guard

#include "global/enum_str.h"
Expand Down
2 changes: 1 addition & 1 deletion src/config_map.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#pragma once

#include <libtrx/config/config_option.h>
#include <libtrx/config/option.h>

extern const CONFIG_OPTION g_ConfigOptionMap[];
8 changes: 6 additions & 2 deletions src/decomp/decomp.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include "decomp/decomp.h"

#include "config.h"
#include "game/background.h"
#include "game/camera.h"
#include "game/console/common.h"
Expand All @@ -22,14 +23,14 @@
#include "game/shell.h"
#include "game/sound.h"
#include "game/text.h"
#include "game/ui/common.h"
#include "global/const.h"
#include "global/funcs.h"
#include "global/vars.h"
#include "lib/ddraw.h"
#include "lib/dinput.h"
#include "specific/s_flagged_string.h"

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

#include <assert.h>
Expand Down Expand Up @@ -250,6 +251,7 @@ int32_t __stdcall WinMain(
g_StopInventory = 0;
g_IsGameToExit = 0;
Shell_Main();
Config_Write();
Shell_Shutdown();
SE_WriteAppSettings(&g_SavedAppSettings);
}
Expand Down Expand Up @@ -563,6 +565,7 @@ void __cdecl Shell_Shutdown(void)
MessageBoxA(NULL, g_ErrorMessage, NULL, MB_ICONWARNING);
}
UI_Shutdown();
Config_Shutdown();
}

int16_t __cdecl TitleSequence(void)
Expand Down Expand Up @@ -757,7 +760,8 @@ bool __cdecl WinVidSpinMessageLoop(bool need_wait)
UI_HandleKeyUp(msg.wParam);
return 0;
} else if (msg.message == WM_CHAR) {
UI_HandleChar(msg.wParam);
char insert_string[2] = { msg.wParam, '\0' };
UI_HandleTextEdit(insert_string);
return 0;
}
}
Expand Down
68 changes: 2 additions & 66 deletions src/game/console/common.c
Original file line number Diff line number Diff line change
@@ -1,83 +1,19 @@
#include "game/console/common.h"

#include "game/console/setup.h"
#include "game/input.h"
#include "game/text.h"
#include "game/ui/widgets/console.h"

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

static bool m_IsOpened = false;
static UI_WIDGET *m_Console;

void Console_Init(void)
{
m_Console = UI_Console_Create();
}

void Console_Shutdown(void)
{
if (m_Console != NULL) {
m_Console->free(m_Console);
m_Console = NULL;
}

m_IsOpened = false;
}

void Console_Open(void)
{
if (m_IsOpened) {
UI_Console_HandleClose(m_Console);
}
m_IsOpened = true;
UI_Console_HandleOpen(m_Console);
}

void Console_Close(void)
{
UI_Console_HandleClose(m_Console);
m_IsOpened = false;
}

bool Console_IsOpened(void)
{
return m_IsOpened;
}

int32_t Console_GetMaxLineLength(void)
{
return TEXT_MAX_STRING_SIZE - 1;
}

void Console_LogImpl(const char *const text)
{
UI_Console_HandleLog(m_Console, text);
}

CONSOLE_COMMAND **Console_GetCommands(void)
{
return g_ConsoleCommands;
}

void Console_Draw(void)
void Console_DrawBackdrop(void)
{
UI_Console_ScrollLogs(m_Console);

#if 0
// TODO: draw screen quad
int32_t sx = 0;
int32_t sw = Viewport_GetWidth();
int32_t sh = Screen_GetRenderScale(
// not entirely accurate, but good enough
TEXT_HEIGHT * m_PromptScale
+ MAX_LOG_LINES * TEXT_HEIGHT * m_LogScale,
RSR_TEXT);
int32_t sy = Viewport_GetHeight() - sh;

RGBA_8888 top = { 0, 0, 0, 0 };
RGBA_8888 bottom = { 0, 0, 0, 196 };

Output_DrawScreenGradientQuad(sx, sy, sw, sh, top, top, bottom, bottom);
#endif
// TODO: implement me
}
12 changes: 1 addition & 11 deletions src/game/console/common.h
Original file line number Diff line number Diff line change
@@ -1,15 +1,5 @@
#pragma once

#include <stdbool.h>
#include <stdint.h>
#include <libtrx/game/console/common.h>

void Console_Init(void);
void Console_Shutdown(void);
void Console_Draw(void);

void Console_Open(void);
void Console_Close(void);
bool Console_IsOpened(void);

void Console_Log(const char *fmt, ...);
void Console_ScrollLogs(void);
2 changes: 1 addition & 1 deletion src/game/input.c
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ bool Input_Update(void)
if (m_ListenMode) {
g_Input = 0;
g_InputDB = 0;
return true;
return result;
}

if (g_InputDB & IN_CONSOLE) {
Expand Down
6 changes: 0 additions & 6 deletions src/game/option/option_controls.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
#include "game/ui/widgets/controls_dialog.h"
#include "global/vars.h"

#include <libtrx/utils.h>

static UI_WIDGET *m_ControlsDialog;
static UI_CONTROLS_CONTROLLER m_ControlsDialogController;

Expand All @@ -21,10 +19,6 @@ void __cdecl Option_Controls(INVENTORY_ITEM *const item)
if (m_ControlsDialog == NULL) {
m_ControlsDialog =
UI_ControlsDialog_Create(&m_ControlsDialogController);
m_ControlsDialog->set_position(
m_ControlsDialog,
(640 - m_ControlsDialog->get_width(m_ControlsDialog)) / 2,
(480 - m_ControlsDialog->get_height(m_ControlsDialog)) * 2 / 3);
}

m_ControlsDialog->control(m_ControlsDialog);
Expand Down
8 changes: 2 additions & 6 deletions src/game/shell.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@
#include "game/input.h"
#include "game/music.h"
#include "game/sound.h"
#include "game/ui/common.h"
#include "global/funcs.h"
#include "global/vars.h"

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

#include <stdarg.h>
Expand All @@ -28,6 +28,7 @@ BOOL __cdecl Shell_Main(void)
g_GameSizerCopy = 1.0;

GameString_Init();
Config_Init();
UI_Init();

Config_Read();
Expand Down Expand Up @@ -81,7 +82,6 @@ BOOL __cdecl Shell_Main(void)

if (is_frontend_fail) {
strcpy(g_ErrorMessage, "GameMain: failed in GF_DoFrontendSequence()");
Config_Write();
return false;
}

Expand All @@ -105,7 +105,6 @@ BOOL __cdecl Shell_Main(void)
g_ErrorMessage,
"GameMain: STARTGAME with invalid level number (%d)",
gf_param);
Config_Write();
return false;
}
gf_option = GF_DoLevelSequence(gf_param, GFL_NORMAL);
Expand All @@ -119,7 +118,6 @@ BOOL __cdecl Shell_Main(void)
g_ErrorMessage,
"GameMain: STARTSAVEDGAME with invalid level number (%d)",
g_SaveGame.current_level);
Config_Write();
return false;
}
gf_option = GF_DoLevelSequence(g_SaveGame.current_level, GFL_SAVED);
Expand All @@ -146,7 +144,6 @@ BOOL __cdecl Shell_Main(void)
strcpy(
g_ErrorMessage,
"GameMain Failed: Title disabled & no replacement");
Config_Write();
return false;
}
gf_option = g_GameFlow.title_replace;
Expand All @@ -164,7 +161,6 @@ BOOL __cdecl Shell_Main(void)

S_SaveSettings();
GameBuf_Shutdown();
Config_Write();
GameString_Shutdown();
return true;
}
Expand Down
1 change: 0 additions & 1 deletion src/game/text.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
#include <string.h>

#define MAX_TEXTSTRINGS 128
#define TEXT_HEIGHT 15
#define TEXT_Y_SPACING 3
#define CHAR_SECRET_1 0x7Fu
#define CHAR_SECRET_2 0x80u
Expand Down
1 change: 1 addition & 0 deletions src/game/text.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

#include "global/types.h"

#define TEXT_HEIGHT 15
#define TEXT_MAX_STRING_SIZE 64

void __cdecl Text_Init(void);
Expand Down
Loading
Loading