Skip to content

Commit

Permalink
tr2/input: add ui for editing controller layouts
Browse files Browse the repository at this point in the history
  • Loading branch information
rr- committed Oct 30, 2024
1 parent 3ee39c9 commit 9f137ac
Show file tree
Hide file tree
Showing 28 changed files with 729 additions and 260 deletions.
10 changes: 5 additions & 5 deletions data/tr1/ship/cfg/TR1X_gameflow.json5
Original file line number Diff line number Diff line change
Expand Up @@ -595,13 +595,13 @@
],

"strings": {
"CONTROL_CONTROLLER": "Controller",
"CONTROL_BACKEND_CONTROLLER": "Controller",
"CONTROL_BACKEND_KEYBOARD": "Keyboard",
"CONTROL_CUSTOMIZE": "Customize Controls",
"CONTROL_CUSTOM_1": "Custom Scheme 1",
"CONTROL_CUSTOM_2": "Custom Scheme 2",
"CONTROL_CUSTOM_3": "Custom Scheme 3",
"CONTROL_CUSTOM_1": "User Keys 1",
"CONTROL_CUSTOM_2": "User Keys 2",
"CONTROL_CUSTOM_3": "User Keys 3",
"CONTROL_DEFAULT_KEYS": "Default Keys",
"CONTROL_KEYBOARD": "Keyboard",
"CONTROL_RESET_DEFAULTS": "Reset All: Hold %s",
"CONTROL_UNBIND": "Unbind: Hold %s",
"DETAIL_BILINEAR": "Bilinear",
Expand Down
10 changes: 5 additions & 5 deletions data/tr1/ship/cfg/TR1X_gameflow_demo_pc.json5
Original file line number Diff line number Diff line change
Expand Up @@ -83,13 +83,13 @@
],

"strings": {
"CONTROL_CONTROLLER": "Controller",
"CONTROL_BACKEND_CONTROLLER": "Controller",
"CONTROL_BACKEND_KEYBOARD": "Keyboard",
"CONTROL_CUSTOMIZE": "Customize Controls",
"CONTROL_CUSTOM_1": "Custom Scheme 1",
"CONTROL_CUSTOM_2": "Custom Scheme 2",
"CONTROL_CUSTOM_3": "Custom Scheme 3",
"CONTROL_CUSTOM_1": "User Keys 1",
"CONTROL_CUSTOM_2": "User Keys 2",
"CONTROL_CUSTOM_3": "User Keys 3",
"CONTROL_DEFAULT_KEYS": "Default Keys",
"CONTROL_KEYBOARD": "Keyboard",
"CONTROL_RESET_DEFAULTS": "Reset All: Hold %s",
"CONTROL_UNBIND": "Unbind: Hold %s",
"DETAIL_BILINEAR": "Bilinear",
Expand Down
10 changes: 5 additions & 5 deletions data/tr1/ship/cfg/TR1X_gameflow_ub.json5
Original file line number Diff line number Diff line change
Expand Up @@ -155,13 +155,13 @@
],

"strings": {
"CONTROL_CONTROLLER": "Controller",
"CONTROL_BACKEND_CONTROLLER": "Controller",
"CONTROL_BACKEND_KEYBOARD": "Keyboard",
"CONTROL_CUSTOMIZE": "Customize Controls",
"CONTROL_CUSTOM_1": "Custom Scheme 1",
"CONTROL_CUSTOM_2": "Custom Scheme 2",
"CONTROL_CUSTOM_3": "Custom Scheme 3",
"CONTROL_CUSTOM_1": "User Keys 1",
"CONTROL_CUSTOM_2": "User Keys 2",
"CONTROL_CUSTOM_3": "User Keys 3",
"CONTROL_DEFAULT_KEYS": "Default Keys",
"CONTROL_KEYBOARD": "Keyboard",
"CONTROL_RESET_DEFAULTS": "Reset All: Hold %s",
"CONTROL_UNBIND": "Unbind: Hold %s",
"DETAIL_BILINEAR": "Bilinear",
Expand Down
9 changes: 6 additions & 3 deletions data/tr2/ship/cfg/TR2X_gameflow.json5
Original file line number Diff line number Diff line change
Expand Up @@ -351,9 +351,12 @@
},

"game_strings": {
"CONTROL_CUSTOM_1": "Custom Scheme 1",
"CONTROL_CUSTOM_2": "Custom Scheme 2",
"CONTROL_CUSTOM_3": "Custom Scheme 3",
"CONTROL_BACKEND_CONTROLLER": "Controller",
"CONTROL_BACKEND_KEYBOARD": "Keyboard",
"CONTROL_CUSTOMIZE": "Customize Controls",
"CONTROL_CUSTOM_1": "User Keys 1",
"CONTROL_CUSTOM_2": "User Keys 2",
"CONTROL_CUSTOM_3": "User Keys 3",
"CONTROL_DEFAULT_KEYS": "Default Keys",
"MISC_OFF": "Off",
"MISC_ON": "On",
Expand Down
25 changes: 13 additions & 12 deletions docs/tr2/progress.txt
Original file line number Diff line number Diff line change
Expand Up @@ -261,18 +261,19 @@ typedef struct __unaligned {
union {
uint32_t all;
struct {
uint32_t active: 1;
uint32_t flash: 1;
uint32_t rotate_h: 1;
uint32_t rotate_v: 1;
uint32_t centre_h: 1;
uint32_t centre_v: 1;
uint32_t hide: 1;
uint32_t right: 1;
uint32_t bottom: 1;
uint32_t background: 1;
uint32_t outline: 1;
uint32_t multiline: 1;
uint32_t active: 1;
uint32_t flash: 1;
uint32_t rotate_h: 1;
uint32_t rotate_v: 1;
uint32_t centre_h: 1;
uint32_t centre_v: 1;
uint32_t hide: 1;
uint32_t right: 1;
uint32_t bottom: 1;
uint32_t background: 1;
uint32_t outline: 1;
uint32_t multiline: 1;
uint32_t manual_draw: 1; // not present in the OG
};
} flags;
uint16_t text_flags;
Expand Down
298 changes: 163 additions & 135 deletions src/libtrx/game/input/backends/controller.c

Large diffs are not rendered by default.

6 changes: 6 additions & 0 deletions src/libtrx/game/ui/widgets/stack.c
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,12 @@ static void M_Free(UI_STACK *const self)
Memory_Free(self);
}

void UI_Stack_ClearChildren(UI_WIDGET *const widget)
{
UI_STACK *const self = (UI_STACK *)widget;
Vector_Clear(self->children);
}

void UI_Stack_AddChild(UI_WIDGET *const widget, UI_WIDGET *const child)
{
UI_STACK *const self = (UI_STACK *)widget;
Expand Down
9 changes: 6 additions & 3 deletions src/libtrx/include/libtrx/game/game_string.def
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@ GS_DEFINE(OSD_AMBIGUOUS_INPUT_3, "Ambiguous input: %s, %s, ...")
GS_DEFINE(OSD_UI_ON, "UI enabled")
GS_DEFINE(OSD_UI_OFF, "UI disabled")
GS_DEFINE(CONTROL_DEFAULT_KEYS, "Default Keys")
GS_DEFINE(CONTROL_CUSTOM_1, "Custom Scheme 1")
GS_DEFINE(CONTROL_CUSTOM_2, "Custom Scheme 2")
GS_DEFINE(CONTROL_CUSTOM_3, "Custom Scheme 3")
GS_DEFINE(CONTROL_CUSTOM_1, "User Keys 1")
GS_DEFINE(CONTROL_CUSTOM_2, "User Keys 2")
GS_DEFINE(CONTROL_CUSTOM_3, "User Keys 3")
GS_DEFINE(CONTROL_BACKEND_KEYBOARD, "Keyboard")
GS_DEFINE(CONTROL_BACKEND_CONTROLLER, "Controller")
GS_DEFINE(CONTROL_CUSTOMIZE, "Customize Controls")
1 change: 1 addition & 0 deletions src/libtrx/include/libtrx/game/ui/widgets/stack.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ UI_WIDGET *UI_Stack_Create(
UI_STACK_LAYOUT layout, int32_t width, int32_t height);
void UI_Stack_SetHAlign(UI_WIDGET *self, UI_STACK_H_ALIGN align);
void UI_Stack_SetVAlign(UI_WIDGET *self, UI_STACK_V_ALIGN align);
void UI_Stack_ClearChildren(UI_WIDGET *self);
void UI_Stack_AddChild(UI_WIDGET *self, UI_WIDGET *child);
void UI_Stack_SetSize(UI_WIDGET *widget, int32_t width, int32_t height);
void UI_Stack_DoLayout(UI_WIDGET *self);
3 changes: 3 additions & 0 deletions src/libtrx/include/libtrx/game/ui/widgets/window.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,6 @@
extern UI_WIDGET *UI_Window_Create(
UI_WIDGET *root, int32_t border_top, int32_t border_right,
int32_t border_bottom, int32_t border_left);

extern void UI_Window_SetTitle(UI_WIDGET *widget, const char *text);
extern void UI_Window_SetRootWidget(UI_WIDGET *widget, UI_WIDGET *root);
3 changes: 0 additions & 3 deletions src/tr1/game/game_string.def
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,6 @@ GS_DEFINE(DETAIL_STRING_FMT, "%s")
GS_DEFINE(DETAIL_FLOAT_FMT, "%.1f")
GS_DEFINE(DETAIL_RESOLUTION_FMT, "%dx%d")
GS_DEFINE(SOUND_SET_VOLUMES, "Set Volumes")
GS_DEFINE(CONTROL_CUSTOMIZE, "Customize Controls")
GS_DEFINE(CONTROL_KEYBOARD, "Keyboard")
GS_DEFINE(CONTROL_CONTROLLER, "Controller")
GS_DEFINE(CONTROL_RESET_DEFAULTS, "Reset All: Hold %s")
GS_DEFINE(CONTROL_UNBIND, "Unbind: Hold %s")
GS_DEFINE(KEYMAP_RUN, "Run")
Expand Down
5 changes: 3 additions & 2 deletions src/tr1/game/option/option_control_pick.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,9 @@ static void M_InitText(void)
Text_AddBackground(m_Text[TEXT_TITLE], 176, 0, 0, 0, TS_HEADING);
Text_AddOutline(m_Text[TEXT_TITLE], true, TS_HEADING);

m_Text[TEXT_KEYBOARD] = Text_Create(0, 0, GS(CONTROL_KEYBOARD));
m_Text[TEXT_CONTROLLER] = Text_Create(0, 25, GS(CONTROL_CONTROLLER));
m_Text[TEXT_KEYBOARD] = Text_Create(0, 0, GS(CONTROL_BACKEND_KEYBOARD));
m_Text[TEXT_CONTROLLER] =
Text_Create(0, 25, GS(CONTROL_BACKEND_CONTROLLER));

Text_AddBackground(m_Text[g_OptionSelected], 128, 0, 0, 0, TS_REQUESTED);
Text_AddOutline(m_Text[g_OptionSelected], true, TS_REQUESTED);
Expand Down
86 changes: 72 additions & 14 deletions src/tr1/game/ui/widgets/window.c
Original file line number Diff line number Diff line change
@@ -1,20 +1,25 @@
#include "game/text.h"

#include <libtrx/game/ui/widgets/label.h>
#include <libtrx/game/ui/widgets/window.h>
#include <libtrx/memory.h>
#include <libtrx/utils.h>

typedef struct {
UI_WIDGET_VTABLE vtable;
TEXTSTRING *text;
TEXTSTRING *frame;
UI_WIDGET *root;
UI_WIDGET *title_label;
struct {
int32_t left;
int32_t right;
int32_t top;
int32_t bottom;
} border;
int32_t title_margin;
} UI_WINDOW;

static void M_SyncChildren(UI_WINDOW *self);
static int32_t M_GetWidth(const UI_WINDOW *self);
static int32_t M_GetHeight(const UI_WINDOW *self);
static void M_SetPosition(UI_WINDOW *self, int32_t x, int32_t y);
Expand All @@ -24,28 +29,52 @@ static void M_Free(UI_WINDOW *self);

static int32_t M_GetWidth(const UI_WINDOW *const self)
{
return self->root->get_width(self->root) + self->border.left
+ self->border.right;
const int32_t title_width = self->title_label != NULL
? self->title_label->get_width(self->title_label)
+ 2 * self->title_margin
: 0;
const int32_t root_width = self->root->get_width(self->root)
+ self->border.left + self->border.right;
return MAX(title_width, root_width);
}

static int32_t M_GetHeight(const UI_WINDOW *const self)
{
return self->root->get_height(self->root) + self->border.top
+ self->border.bottom;
const int32_t title_height = self->title_label != NULL
? self->title_label->get_height(self->title_label)
+ 2 * self->title_margin
: 0;
const int32_t root_height = self->root->get_height(self->root)
+ self->border.top + self->border.bottom;
return title_height + root_height;
}

static void M_SetPosition(
UI_WINDOW *const self, const int32_t x, const int32_t y)
{
self->root->set_position(
self->root, x + self->border.left, y + self->border.top);
if (self->title_label != NULL) {
self->title_label->set_position(
self->title_label, x + self->title_margin, y + self->title_margin);
self->root->set_position(
self->root,
x + self->border.left
+ (self->title_label->get_width(self->title_label)
- self->root->get_width(self->root))
/ 2,
y + self->title_margin
+ self->title_label->get_height(self->title_label)
+ self->title_margin + self->border.top);
} else {
self->root->set_position(
self->root, x + self->border.left, y + self->border.top);
}

Text_SetPos(self->text, x, y + TEXT_HEIGHT);
Text_SetPos(self->frame, x, y + TEXT_HEIGHT);

const int32_t w = M_GetWidth(self);
const int32_t h = M_GetHeight(self);
Text_AddBackground(self->text, w, h, w / 2, 0, TS_BACKGROUND);
Text_AddOutline(self->text, true, TS_BACKGROUND);
Text_AddBackground(self->frame, w, h, w / 2, 0, TS_BACKGROUND);
Text_AddOutline(self->frame, true, TS_BACKGROUND);
}

static void M_Control(UI_WINDOW *const self)
Expand All @@ -60,12 +89,18 @@ static void M_Draw(UI_WINDOW *const self)
if (self->root->draw != NULL) {
self->root->draw(self->root);
}
Text_DrawText(self->text);
if (self->title_label != NULL) {
self->title_label->draw(self->title_label);
}
Text_DrawText(self->frame);
}

static void M_Free(UI_WINDOW *const self)
{
Text_Remove(self->text);
if (self->title_label != NULL) {
self->title_label->free(self->title_label);
}
Text_Remove(self->frame);
Memory_Free(self);
}

Expand All @@ -84,11 +119,34 @@ UI_WIDGET *UI_Window_Create(
};

self->root = root;
self->text = Text_Create(0, 0, "");
self->text->flags.manual_draw = 1;
self->border.top = border_top;
self->border.right = border_right;
self->border.bottom = border_bottom;
self->border.left = border_left;
self->title_margin = 2;

self->frame = Text_Create(0, 0, "");
self->frame->flags.manual_draw = 1;

return (UI_WIDGET *)self;
}

void UI_Window_SetTitle(UI_WIDGET *const widget, const char *const text)
{
UI_WINDOW *const self = (UI_WINDOW *)widget;
if (self->title_label != NULL) {
self->title_label->free(self->title_label);
self->title_label = NULL;
}
if (text != NULL) {
self->title_label =
UI_Label_Create(text, UI_LABEL_AUTO_SIZE, UI_LABEL_AUTO_SIZE);
UI_Label_AddFrame(self->title_label);
}
}

void UI_Window_SetRootWidget(UI_WIDGET *const widget, UI_WIDGET *const root)
{
UI_WINDOW *const self = (UI_WINDOW *)widget;
self->root = root;
}
18 changes: 9 additions & 9 deletions src/tr2/game/inventory/common.c
Original file line number Diff line number Diff line change
Expand Up @@ -402,17 +402,8 @@ int32_t __cdecl Inv_Display(int32_t inventory_mode)
Matrix_Pop();
Overlay_DrawModeInfo();
Text_Draw();
S_OutputPolyList();
Sound_EndScene();

const int32_t frames = S_DumpScreen();
Shell_ProcessEvents();
g_Inv_NFrames = frames;
g_Camera.num_frames = frames;
if (g_CurrentLevel) {
g_SaveGame.statistics.timer += frames / 2;
}

if (!ring.rotating) {
switch (imo.status) {
case RNG_OPEN:
Expand Down Expand Up @@ -747,6 +738,15 @@ int32_t __cdecl Inv_Display(int32_t inventory_mode)
break;
}
}

S_OutputPolyList();
const int32_t frames = S_DumpScreen();
Shell_ProcessEvents();
g_Inv_NFrames = frames;
g_Camera.num_frames = frames;
if (g_CurrentLevel) {
g_SaveGame.statistics.timer += frames / 2;
}
} while (imo.status != RNG_DONE);

M_RemoveAllText();
Expand Down
1 change: 1 addition & 0 deletions src/tr2/game/option/option_controls.c
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ void __cdecl Option_Controls(INVENTORY_ITEM *const item)
}

m_Dialog->control(m_Dialog);
m_Dialog->draw(m_Dialog);
if (m_Controller.state == UI_CONTROLS_STATE_EXIT) {
Option_Controls_Shutdown();
} else {
Expand Down
Loading

0 comments on commit 9f137ac

Please sign in to comment.