mirror of
https://github.com/LostArtefacts/TRX.git
synced 2025-04-28 12:47:58 +03:00
ui: rename ui2 to just ui
Some checks failed
Run code linters / Run code linters (push) Has been cancelled
Some checks failed
Run code linters / Run code linters (push) Has been cancelled
This commit is contained in:
parent
177dc6de60
commit
e3a5ee4ca1
116 changed files with 2126 additions and 2139 deletions
|
@ -4,7 +4,7 @@
|
|||
#include "debug.h"
|
||||
#include "game/console/registry.h"
|
||||
#include "game/game_string.h"
|
||||
#include "game/ui2.h"
|
||||
#include "game/ui.h"
|
||||
#include "log.h"
|
||||
#include "memory.h"
|
||||
#include "strings.h"
|
||||
|
@ -14,18 +14,18 @@
|
|||
#include <string.h>
|
||||
|
||||
static bool m_IsOpened = false;
|
||||
static UI2_CONSOLE_STATE m_UIState = {};
|
||||
static UI_CONSOLE_STATE m_UIState = {};
|
||||
|
||||
void Console_Init(void)
|
||||
{
|
||||
UI2_Console_Init(&m_UIState);
|
||||
UI_Console_Init(&m_UIState);
|
||||
|
||||
Console_History_Init();
|
||||
}
|
||||
|
||||
void Console_Shutdown(void)
|
||||
{
|
||||
UI2_Console_Free(&m_UIState);
|
||||
UI_Console_Free(&m_UIState);
|
||||
|
||||
Console_History_Shutdown();
|
||||
Console_Registry_Shutdown();
|
||||
|
@ -39,7 +39,7 @@ void Console_Open(void)
|
|||
return;
|
||||
}
|
||||
m_IsOpened = true;
|
||||
UI2_FireEvent(
|
||||
UI_FireEvent(
|
||||
(EVENT) { .name = "console_open", .sender = nullptr, .data = nullptr });
|
||||
}
|
||||
|
||||
|
@ -49,7 +49,7 @@ void Console_Close(void)
|
|||
return;
|
||||
}
|
||||
m_IsOpened = false;
|
||||
UI2_FireEvent((EVENT) {
|
||||
UI_FireEvent((EVENT) {
|
||||
.name = "console_close", .sender = nullptr, .data = nullptr });
|
||||
}
|
||||
|
||||
|
@ -75,7 +75,7 @@ void Console_Log(const char *fmt, ...)
|
|||
|
||||
LOG_INFO("%s", text);
|
||||
|
||||
UI2_FireEvent((EVENT) {
|
||||
UI_FireEvent((EVENT) {
|
||||
.name = "console_log",
|
||||
.sender = nullptr,
|
||||
.data = text,
|
||||
|
@ -130,10 +130,10 @@ COMMAND_RESULT Console_Eval(const char *const cmdline)
|
|||
|
||||
void Console_Control(void)
|
||||
{
|
||||
UI2_Console_Control(&m_UIState);
|
||||
UI_Console_Control(&m_UIState);
|
||||
}
|
||||
|
||||
void Console_Draw(void)
|
||||
{
|
||||
UI2_Console(&m_UIState);
|
||||
UI_Console(&m_UIState);
|
||||
}
|
||||
|
|
|
@ -12,7 +12,7 @@
|
|||
#include "game/savegame.h"
|
||||
#include "game/shell.h"
|
||||
#include "game/text.h"
|
||||
#include "game/ui2.h"
|
||||
#include "game/ui.h"
|
||||
#include "gfx/gl/track.h"
|
||||
|
||||
#define DEBUG_OPTIM 0
|
||||
|
@ -67,7 +67,7 @@ static PHASE_CONTROL M_Control(PHASE *const phase, const int32_t nframes)
|
|||
static void M_Draw(PHASE *const phase)
|
||||
{
|
||||
Output_BeginScene();
|
||||
UI2_BeginScene();
|
||||
UI_BeginScene();
|
||||
#if DEBUG_OPTIM
|
||||
BENCHMARK benchmark = Benchmark_Start();
|
||||
#endif
|
||||
|
@ -77,7 +77,7 @@ static void M_Draw(PHASE *const phase)
|
|||
|
||||
Console_Draw();
|
||||
Text_Draw();
|
||||
UI2_EndScene();
|
||||
UI_EndScene();
|
||||
Output_DrawPolyList();
|
||||
Fader_Draw(&m_ExitFader);
|
||||
|
||||
|
|
|
@ -11,7 +11,7 @@
|
|||
#include "game/shell.h"
|
||||
#include "game/sound.h"
|
||||
#include "game/text.h"
|
||||
#include "game/ui2.h"
|
||||
#include "game/ui.h"
|
||||
#include "memory.h"
|
||||
|
||||
#include <stdint.h>
|
||||
|
@ -29,7 +29,7 @@ typedef struct {
|
|||
STATE state;
|
||||
struct {
|
||||
bool is_ready;
|
||||
UI2_PAUSE_STATE state;
|
||||
UI_PAUSE_STATE state;
|
||||
} ui;
|
||||
TEXTSTRING *mode_text;
|
||||
GF_ACTION action;
|
||||
|
@ -108,7 +108,7 @@ static PHASE_CONTROL M_Start(PHASE *const phase)
|
|||
M_PRIV *const p = phase->priv;
|
||||
|
||||
p->ui.is_ready = false;
|
||||
UI2_Pause_Init(&p->ui.state);
|
||||
UI_Pause_Init(&p->ui.state);
|
||||
M_PauseGame(p);
|
||||
return (PHASE_CONTROL) { .action = PHASE_ACTION_CONTINUE };
|
||||
}
|
||||
|
@ -117,7 +117,7 @@ static void M_End(PHASE *const phase)
|
|||
{
|
||||
M_PRIV *const p = phase->priv;
|
||||
M_RemoveText(p);
|
||||
UI2_Pause_Free(&p->ui.state);
|
||||
UI_Pause_Free(&p->ui.state);
|
||||
}
|
||||
|
||||
static PHASE_CONTROL M_Control(PHASE *const phase, int32_t const num_frames)
|
||||
|
@ -128,7 +128,7 @@ static PHASE_CONTROL M_Control(PHASE *const phase, int32_t const num_frames)
|
|||
Shell_ProcessInput();
|
||||
|
||||
if (p->ui.is_ready) {
|
||||
UI2_Pause_Control(&p->ui.state);
|
||||
UI_Pause_Control(&p->ui.state);
|
||||
}
|
||||
|
||||
switch (p->state) {
|
||||
|
@ -153,15 +153,15 @@ static PHASE_CONTROL M_Control(PHASE *const phase, int32_t const num_frames)
|
|||
break;
|
||||
|
||||
case STATE_ASK: {
|
||||
const UI2_PAUSE_EXIT_CHOICE choice = UI2_Pause_Control(&p->ui.state);
|
||||
const UI_PAUSE_EXIT_CHOICE choice = UI_Pause_Control(&p->ui.state);
|
||||
switch (choice) {
|
||||
case UI2_PAUSE_RESUME_PAUSE:
|
||||
case UI_PAUSE_RESUME_PAUSE:
|
||||
p->state = STATE_WAIT;
|
||||
return (PHASE_CONTROL) { .action = PHASE_ACTION_NO_WAIT };
|
||||
case UI2_PAUSE_EXIT_TO_GAME:
|
||||
case UI_PAUSE_EXIT_TO_GAME:
|
||||
M_ReturnToGame(p);
|
||||
return (PHASE_CONTROL) { .action = PHASE_ACTION_NO_WAIT };
|
||||
case UI2_PAUSE_EXIT_TO_TITLE:
|
||||
case UI_PAUSE_EXIT_TO_TITLE:
|
||||
M_ExitToTitle(p);
|
||||
return (PHASE_CONTROL) { .action = PHASE_ACTION_NO_WAIT };
|
||||
default:
|
||||
|
@ -193,7 +193,7 @@ static void M_Draw(PHASE *const phase)
|
|||
Fader_Draw(&p->back_fader);
|
||||
|
||||
if (p->state == STATE_ASK) {
|
||||
UI2_Pause(&p->ui.state);
|
||||
UI_Pause(&p->ui.state);
|
||||
}
|
||||
Output_DrawPolyList();
|
||||
}
|
||||
|
|
|
@ -12,7 +12,7 @@
|
|||
#include "game/overlay.h"
|
||||
#include "game/shell.h"
|
||||
#include "game/sound.h"
|
||||
#include "game/ui2.h"
|
||||
#include "game/ui.h"
|
||||
#include "memory.h"
|
||||
|
||||
typedef struct {
|
||||
|
@ -69,7 +69,7 @@ static PHASE_CONTROL M_Control(PHASE *const phase, int32_t num_frames)
|
|||
Shell_ProcessInput();
|
||||
|
||||
if (g_InputDB.toggle_ui) {
|
||||
UI2_ToggleState(&g_Config.ui.enable_photo_mode_ui);
|
||||
UI_ToggleState(&g_Config.ui.enable_photo_mode_ui);
|
||||
}
|
||||
|
||||
if (g_InputDB.toggle_photo_mode || g_InputDB.menu_back) {
|
||||
|
@ -99,7 +99,7 @@ static void M_Draw(PHASE *const phase)
|
|||
Output_DrawPolyList();
|
||||
|
||||
if (!p->taking_screenshot) {
|
||||
UI2_PhotoMode();
|
||||
UI_PhotoMode();
|
||||
}
|
||||
Output_DrawPolyList();
|
||||
}
|
||||
|
|
|
@ -9,7 +9,7 @@
|
|||
#include "game/interpolation.h"
|
||||
#include "game/shell.h"
|
||||
#include "game/text.h"
|
||||
#include "game/ui2.h"
|
||||
#include "game/ui.h"
|
||||
#include "memory.h"
|
||||
|
||||
typedef enum {
|
||||
|
@ -25,7 +25,7 @@ typedef struct {
|
|||
FADER back_fader;
|
||||
FADER top_fader;
|
||||
bool ui_active;
|
||||
UI2_STATS_DIALOG_STATE ui_state;
|
||||
UI_STATS_DIALOG_STATE ui_state;
|
||||
} M_PRIV;
|
||||
|
||||
static bool M_IsFading(M_PRIV *p);
|
||||
|
@ -88,14 +88,14 @@ static PHASE_CONTROL M_Start(PHASE *const phase)
|
|||
}
|
||||
|
||||
p->ui_active = true;
|
||||
UI2_StatsDialog_Init(
|
||||
UI_StatsDialog_Init(
|
||||
&p->ui_state,
|
||||
(UI2_STATS_DIALOG_ARGS) {
|
||||
.mode = p->args.show_final_stats ? UI2_STATS_DIALOG_MODE_FINAL
|
||||
: UI2_STATS_DIALOG_MODE_LEVEL,
|
||||
(UI_STATS_DIALOG_ARGS) {
|
||||
.mode = p->args.show_final_stats ? UI_STATS_DIALOG_MODE_FINAL
|
||||
: UI_STATS_DIALOG_MODE_LEVEL,
|
||||
.style = p->args.use_bare_style
|
||||
? UI2_STATS_DIALOG_STYLE_BARE
|
||||
: UI2_STATS_DIALOG_STYLE_BORDERED,
|
||||
? UI_STATS_DIALOG_STYLE_BARE
|
||||
: UI_STATS_DIALOG_STYLE_BORDERED,
|
||||
.level_num = p->args.level_num != -1
|
||||
? p->args.level_num
|
||||
: Game_GetCurrentLevel()->num,
|
||||
|
@ -110,7 +110,7 @@ static void M_End(PHASE *const phase)
|
|||
M_PRIV *const p = phase->priv;
|
||||
if (p->ui_active) {
|
||||
p->ui_active = false;
|
||||
UI2_StatsDialog_Free(&p->ui_state);
|
||||
UI_StatsDialog_Free(&p->ui_state);
|
||||
}
|
||||
Output_UnloadBackground();
|
||||
}
|
||||
|
@ -166,11 +166,11 @@ static void M_Draw(PHASE *const phase)
|
|||
}
|
||||
Fader_Draw(&p->back_fader);
|
||||
|
||||
UI2_BeginFade(&p->top_fader, true);
|
||||
UI_BeginFade(&p->top_fader, true);
|
||||
if (p->ui_active) {
|
||||
UI2_StatsDialog(&p->ui_state);
|
||||
UI_StatsDialog(&p->ui_state);
|
||||
}
|
||||
UI2_EndFade();
|
||||
UI_EndFade();
|
||||
}
|
||||
|
||||
PHASE *Phase_Stats_Create(const PHASE_STATS_ARGS args)
|
||||
|
|
|
@ -1,11 +1,11 @@
|
|||
#include "game/ui2/common.h"
|
||||
#include "game/ui/common.h"
|
||||
|
||||
#include "config.h"
|
||||
#include "debug.h"
|
||||
#include "game/console/common.h"
|
||||
#include "game/game_string.h"
|
||||
#include "game/ui2/elements/anchor.h"
|
||||
#include "game/ui2/events.h"
|
||||
#include "game/ui/elements/anchor.h"
|
||||
#include "game/ui/events.h"
|
||||
#include "memory.h"
|
||||
|
||||
#include <SDL2/SDL.h>
|
||||
|
@ -16,41 +16,41 @@ static struct {
|
|||
|
||||
int32_t node_count;
|
||||
int32_t node_capacity;
|
||||
UI2_NODE *nodes;
|
||||
UI_NODE *nodes;
|
||||
|
||||
UI2_NODE *root; // The top-level container
|
||||
UI2_NODE *current; // The current container into which we attach nodes
|
||||
UI_NODE *root; // The top-level container
|
||||
UI_NODE *current; // The current container into which we attach nodes
|
||||
} m_Priv = {
|
||||
.alloc = {
|
||||
.default_chunk_size = 1024 * 4,
|
||||
},
|
||||
};
|
||||
|
||||
static UI2_INPUT M_TranslateInput(uint32_t system_keycode);
|
||||
static void M_MeasureNode(UI2_NODE *node);
|
||||
static void M_LayoutNode(UI2_NODE *node, float x, float y, float w, float h);
|
||||
static void M_DrawNode(const UI2_NODE *node);
|
||||
static UI_INPUT M_TranslateInput(uint32_t system_keycode);
|
||||
static void M_MeasureNode(UI_NODE *node);
|
||||
static void M_LayoutNode(UI_NODE *node, float x, float y, float w, float h);
|
||||
static void M_DrawNode(const UI_NODE *node);
|
||||
|
||||
static UI2_INPUT M_TranslateInput(const uint32_t system_keycode)
|
||||
static UI_INPUT M_TranslateInput(const uint32_t system_keycode)
|
||||
{
|
||||
// clang-format off
|
||||
switch (system_keycode) {
|
||||
case SDLK_UP: return UI2_KEY_UP;
|
||||
case SDLK_DOWN: return UI2_KEY_DOWN;
|
||||
case SDLK_LEFT: return UI2_KEY_LEFT;
|
||||
case SDLK_RIGHT: return UI2_KEY_RIGHT;
|
||||
case SDLK_HOME: return UI2_KEY_HOME;
|
||||
case SDLK_END: return UI2_KEY_END;
|
||||
case SDLK_BACKSPACE: return UI2_KEY_BACK;
|
||||
case SDLK_RETURN: return UI2_KEY_RETURN;
|
||||
case SDLK_ESCAPE: return UI2_KEY_ESCAPE;
|
||||
case SDLK_UP: return UI_KEY_UP;
|
||||
case SDLK_DOWN: return UI_KEY_DOWN;
|
||||
case SDLK_LEFT: return UI_KEY_LEFT;
|
||||
case SDLK_RIGHT: return UI_KEY_RIGHT;
|
||||
case SDLK_HOME: return UI_KEY_HOME;
|
||||
case SDLK_END: return UI_KEY_END;
|
||||
case SDLK_BACKSPACE: return UI_KEY_BACK;
|
||||
case SDLK_RETURN: return UI_KEY_RETURN;
|
||||
case SDLK_ESCAPE: return UI_KEY_ESCAPE;
|
||||
}
|
||||
// clang-format on
|
||||
return -1;
|
||||
}
|
||||
|
||||
// Depth-first measure pass
|
||||
static void M_MeasureNode(UI2_NODE *const node)
|
||||
static void M_MeasureNode(UI_NODE *const node)
|
||||
{
|
||||
if (node == nullptr || node->ops == nullptr
|
||||
|| node->ops->measure == nullptr) {
|
||||
|
@ -58,7 +58,7 @@ static void M_MeasureNode(UI2_NODE *const node)
|
|||
}
|
||||
|
||||
// Recurse to children
|
||||
UI2_NODE *child = node->first_child;
|
||||
UI_NODE *child = node->first_child;
|
||||
while (child != nullptr) {
|
||||
M_MeasureNode(child);
|
||||
child = child->next_sibling;
|
||||
|
@ -69,7 +69,7 @@ static void M_MeasureNode(UI2_NODE *const node)
|
|||
|
||||
// Depth-first layout pass
|
||||
static void M_LayoutNode(
|
||||
UI2_NODE *const node, const float x, const float y, const float w,
|
||||
UI_NODE *const node, const float x, const float y, const float w,
|
||||
const float h)
|
||||
{
|
||||
if (node == nullptr || node->ops == nullptr
|
||||
|
@ -82,7 +82,7 @@ static void M_LayoutNode(
|
|||
}
|
||||
|
||||
// Depth-first draw pass
|
||||
static void M_DrawNode(const UI2_NODE *const node)
|
||||
static void M_DrawNode(const UI_NODE *const node)
|
||||
{
|
||||
if (node == nullptr || node->ops == nullptr || node->ops->draw == nullptr) {
|
||||
return;
|
||||
|
@ -93,20 +93,20 @@ static void M_DrawNode(const UI2_NODE *const node)
|
|||
}
|
||||
|
||||
// Allocate a new node
|
||||
UI2_NODE *UI2_AllocNode(
|
||||
const UI2_WIDGET_OPS *const ops, const size_t additional_size)
|
||||
UI_NODE *UI_AllocNode(
|
||||
const UI_WIDGET_OPS *const ops, const size_t additional_size)
|
||||
{
|
||||
const size_t size = sizeof(UI2_NODE) + additional_size;
|
||||
UI2_NODE *const node = Memory_ArenaAlloc(&m_Priv.alloc, size);
|
||||
const size_t size = sizeof(UI_NODE) + additional_size;
|
||||
UI_NODE *const node = Memory_ArenaAlloc(&m_Priv.alloc, size);
|
||||
memset(node, 0, size);
|
||||
node->ops = ops;
|
||||
node->data = (char *)node + sizeof(UI2_NODE);
|
||||
node->data = (char *)node + sizeof(UI_NODE);
|
||||
m_Priv.node_count++;
|
||||
return node;
|
||||
}
|
||||
|
||||
// Attach child to parent's child list
|
||||
void UI2_AddChild(UI2_NODE *const child)
|
||||
void UI_AddChild(UI_NODE *const child)
|
||||
{
|
||||
// Special case - the root widget
|
||||
if (m_Priv.root == nullptr) {
|
||||
|
@ -114,7 +114,7 @@ void UI2_AddChild(UI2_NODE *const child)
|
|||
return;
|
||||
}
|
||||
|
||||
UI2_NODE *const parent = m_Priv.current;
|
||||
UI_NODE *const parent = m_Priv.current;
|
||||
if (parent == nullptr || child == nullptr) {
|
||||
return;
|
||||
}
|
||||
|
@ -127,12 +127,12 @@ void UI2_AddChild(UI2_NODE *const child)
|
|||
parent->last_child = child;
|
||||
}
|
||||
|
||||
void UI2_PushCurrent(UI2_NODE *const child)
|
||||
void UI_PushCurrent(UI_NODE *const child)
|
||||
{
|
||||
m_Priv.current = child;
|
||||
}
|
||||
|
||||
void UI2_PopCurrent(void)
|
||||
void UI_PopCurrent(void)
|
||||
{
|
||||
ASSERT(m_Priv.current != nullptr);
|
||||
m_Priv.current = m_Priv.current->parent;
|
||||
|
@ -142,63 +142,62 @@ void UI2_PopCurrent(void)
|
|||
}
|
||||
|
||||
// Scene management
|
||||
void UI2_BeginScene(void)
|
||||
void UI_BeginScene(void)
|
||||
{
|
||||
Memory_ArenaReset(&m_Priv.alloc);
|
||||
m_Priv.node_count = 0;
|
||||
|
||||
// Make a root node.
|
||||
UI2_BeginAnchor(0.5f, 0.5f);
|
||||
UI_BeginAnchor(0.5f, 0.5f);
|
||||
}
|
||||
|
||||
void UI2_EndScene(void)
|
||||
void UI_EndScene(void)
|
||||
{
|
||||
M_MeasureNode(m_Priv.root);
|
||||
M_LayoutNode(
|
||||
m_Priv.root, 0, 0, UI2_GetCanvasWidth(), UI2_GetCanvasHeight());
|
||||
M_LayoutNode(m_Priv.root, 0, 0, UI_GetCanvasWidth(), UI_GetCanvasHeight());
|
||||
M_DrawNode(m_Priv.root);
|
||||
UI2_EndAnchor();
|
||||
UI_EndAnchor();
|
||||
ASSERT(m_Priv.root == nullptr);
|
||||
}
|
||||
|
||||
void UI2_Init(void)
|
||||
void UI_Init(void)
|
||||
{
|
||||
UI2_InitEvents();
|
||||
UI_InitEvents();
|
||||
}
|
||||
|
||||
void UI2_Shutdown(void)
|
||||
void UI_Shutdown(void)
|
||||
{
|
||||
Memory_ArenaFree(&m_Priv.alloc);
|
||||
UI2_ShutdownEvents();
|
||||
UI_ShutdownEvents();
|
||||
}
|
||||
|
||||
void UI2_ToggleState(bool *const config_setting)
|
||||
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 UI2_HandleKeyDown(const uint32_t key)
|
||||
void UI_HandleKeyDown(const uint32_t key)
|
||||
{
|
||||
UI2_FireEvent((EVENT) {
|
||||
UI_FireEvent((EVENT) {
|
||||
.name = "key_down",
|
||||
.sender = nullptr,
|
||||
.data = (void *)M_TranslateInput(key),
|
||||
});
|
||||
}
|
||||
|
||||
void UI2_HandleKeyUp(const uint32_t key)
|
||||
void UI_HandleKeyUp(const uint32_t key)
|
||||
{
|
||||
UI2_FireEvent((EVENT) {
|
||||
UI_FireEvent((EVENT) {
|
||||
.name = "key_up",
|
||||
.sender = nullptr,
|
||||
.data = (void *)M_TranslateInput(key),
|
||||
});
|
||||
}
|
||||
|
||||
void UI2_HandleTextEdit(const char *const text)
|
||||
void UI_HandleTextEdit(const char *const text)
|
||||
{
|
||||
UI2_FireEvent((EVENT) {
|
||||
UI_FireEvent((EVENT) {
|
||||
.name = "text_edit", .sender = nullptr, .data = (void *)text });
|
||||
}
|
|
@ -1,55 +1,55 @@
|
|||
#include "game/ui2/dialogs/controls.h"
|
||||
#include "game/ui/dialogs/controls.h"
|
||||
|
||||
#include "config.h"
|
||||
#include "game/game_string.h"
|
||||
#include "game/input.h"
|
||||
#include "game/ui2/dialogs/controls_backend.h"
|
||||
#include "game/ui2/dialogs/controls_editor.h"
|
||||
#include "game/ui2/elements/requester.h"
|
||||
#include "game/ui/dialogs/controls_backend.h"
|
||||
#include "game/ui/dialogs/controls_editor.h"
|
||||
#include "game/ui/elements/requester.h"
|
||||
|
||||
typedef enum {
|
||||
M_PHASE_BACKEND,
|
||||
M_PHASE_EDITOR,
|
||||
} M_PHASE;
|
||||
|
||||
void UI2_Controls_Init(UI2_CONTROLS_STATE *const s)
|
||||
void UI_Controls_Init(UI_CONTROLS_STATE *const s)
|
||||
{
|
||||
s->events = EventManager_Create();
|
||||
s->phase = M_PHASE_BACKEND;
|
||||
s->backend = INPUT_BACKEND_KEYBOARD;
|
||||
s->active_layout = g_Config.input.keyboard_layout;
|
||||
UI2_ControlsBackend_Init(&s->backend_state);
|
||||
UI2_ControlsEditor_Init(&s->editor_state, s->events);
|
||||
UI_ControlsBackend_Init(&s->backend_state);
|
||||
UI_ControlsEditor_Init(&s->editor_state, s->events);
|
||||
}
|
||||
|
||||
void UI2_Controls_Free(UI2_CONTROLS_STATE *const s)
|
||||
void UI_Controls_Free(UI_CONTROLS_STATE *const s)
|
||||
{
|
||||
UI2_ControlsEditor_Free(&s->editor_state);
|
||||
UI2_ControlsBackend_Free(&s->backend_state);
|
||||
UI_ControlsEditor_Free(&s->editor_state);
|
||||
UI_ControlsBackend_Free(&s->backend_state);
|
||||
EventManager_Free(s->events);
|
||||
s->events = nullptr;
|
||||
}
|
||||
|
||||
bool UI2_Controls_Control(UI2_CONTROLS_STATE *const s)
|
||||
bool UI_Controls_Control(UI_CONTROLS_STATE *const s)
|
||||
{
|
||||
switch (s->phase) {
|
||||
case M_PHASE_BACKEND: {
|
||||
const int32_t choice = UI2_ControlsBackend_Control(&s->backend_state);
|
||||
const int32_t choice = UI_ControlsBackend_Control(&s->backend_state);
|
||||
switch (choice) {
|
||||
case UI2_REQUESTER_NO_CHOICE:
|
||||
case UI_REQUESTER_NO_CHOICE:
|
||||
return false;
|
||||
case UI2_REQUESTER_CANCEL:
|
||||
case UI_REQUESTER_CANCEL:
|
||||
return true;
|
||||
case INPUT_BACKEND_KEYBOARD:
|
||||
s->backend = choice;
|
||||
s->phase = M_PHASE_EDITOR;
|
||||
UI2_ControlsEditor_Reinit(
|
||||
UI_ControlsEditor_Reinit(
|
||||
&s->editor_state, choice, g_Config.input.keyboard_layout);
|
||||
break;
|
||||
case INPUT_BACKEND_CONTROLLER:
|
||||
s->backend = choice;
|
||||
s->phase = M_PHASE_EDITOR;
|
||||
UI2_ControlsEditor_Reinit(
|
||||
UI_ControlsEditor_Reinit(
|
||||
&s->editor_state, choice, g_Config.input.controller_layout);
|
||||
break;
|
||||
}
|
||||
|
@ -57,15 +57,15 @@ bool UI2_Controls_Control(UI2_CONTROLS_STATE *const s)
|
|||
}
|
||||
|
||||
case M_PHASE_EDITOR: {
|
||||
const UI2_CONTROLS_CHOICE choice =
|
||||
UI2_ControlsEditor_Control(&s->editor_state);
|
||||
const UI_CONTROLS_CHOICE choice =
|
||||
UI_ControlsEditor_Control(&s->editor_state);
|
||||
switch (choice) {
|
||||
case UI2_CONTROLS_CHOICE_NOOP:
|
||||
case UI_CONTROLS_CHOICE_NOOP:
|
||||
break;
|
||||
case UI2_CONTROLS_CHOICE_GO_BACK:
|
||||
case UI_CONTROLS_CHOICE_GO_BACK:
|
||||
s->phase = M_PHASE_BACKEND;
|
||||
break;
|
||||
case UI2_CONTROLS_CHOICE_EXIT:
|
||||
case UI_CONTROLS_CHOICE_EXIT:
|
||||
return true;
|
||||
}
|
||||
break;
|
||||
|
@ -75,14 +75,14 @@ bool UI2_Controls_Control(UI2_CONTROLS_STATE *const s)
|
|||
return false;
|
||||
}
|
||||
|
||||
void UI2_Controls(UI2_CONTROLS_STATE *const s)
|
||||
void UI_Controls(UI_CONTROLS_STATE *const s)
|
||||
{
|
||||
switch (s->phase) {
|
||||
case M_PHASE_BACKEND:
|
||||
UI2_ControlsBackend(&s->backend_state);
|
||||
UI_ControlsBackend(&s->backend_state);
|
||||
break;
|
||||
case M_PHASE_EDITOR:
|
||||
UI2_ControlsEditor(&s->editor_state);
|
||||
UI_ControlsEditor(&s->editor_state);
|
||||
break;
|
||||
}
|
||||
}
|
57
src/libtrx/game/ui/dialogs/controls_backend.c
Normal file
57
src/libtrx/game/ui/dialogs/controls_backend.c
Normal file
|
@ -0,0 +1,57 @@
|
|||
#include "game/ui/dialogs/controls_backend.h"
|
||||
|
||||
#include "game/game_string.h"
|
||||
#include "game/input.h"
|
||||
#include "game/ui/elements/anchor.h"
|
||||
#include "game/ui/elements/label.h"
|
||||
#include "game/ui/elements/modal.h"
|
||||
#include "game/ui/elements/requester.h"
|
||||
|
||||
static const GAME_STRING_ID m_Options[] = {
|
||||
GS_ID(CONTROLS_BACKEND_KEYBOARD),
|
||||
GS_ID(CONTROLS_BACKEND_CONTROLLER),
|
||||
nullptr,
|
||||
};
|
||||
|
||||
void UI_ControlsBackend_Init(UI_CONTROLS_BACKEND_STATE *const s)
|
||||
{
|
||||
int32_t count = 0;
|
||||
for (count = 0; m_Options[count] != nullptr; count++) { }
|
||||
UI_Requester_Init(&s->req, count, count, true);
|
||||
}
|
||||
|
||||
void UI_ControlsBackend_Free(UI_CONTROLS_BACKEND_STATE *const s)
|
||||
{
|
||||
UI_Requester_Free(&s->req);
|
||||
}
|
||||
|
||||
int32_t UI_ControlsBackend_Control(UI_CONTROLS_BACKEND_STATE *const s)
|
||||
{
|
||||
const int32_t choice = UI_Requester_Control(&s->req);
|
||||
switch (choice) {
|
||||
case 0:
|
||||
return INPUT_BACKEND_KEYBOARD;
|
||||
case 1:
|
||||
return INPUT_BACKEND_CONTROLLER;
|
||||
default:
|
||||
return choice;
|
||||
}
|
||||
}
|
||||
|
||||
void UI_ControlsBackend(UI_CONTROLS_BACKEND_STATE *const s)
|
||||
{
|
||||
UI_BeginModal(0.5f, 2.0f / 3.0f);
|
||||
UI_BeginRequester(&s->req, GS(CONTROLS_CUSTOMIZE));
|
||||
|
||||
for (int32_t i = UI_Requester_GetFirstRow(&s->req);
|
||||
i < UI_Requester_GetLastRow(&s->req); i++) {
|
||||
UI_BeginRequesterRow(&s->req, i);
|
||||
UI_BeginAnchor(0.5f, 0.5f);
|
||||
UI_Label(GameString_Get(m_Options[i]));
|
||||
UI_EndAnchor();
|
||||
UI_EndRequesterRow(&s->req, i);
|
||||
}
|
||||
|
||||
UI_EndRequester(&s->req);
|
||||
UI_EndModal();
|
||||
}
|
|
@ -1,19 +1,19 @@
|
|||
#include "game/ui2/dialogs/controls_editor.h"
|
||||
#include "game/ui/dialogs/controls_editor.h"
|
||||
|
||||
#include "config.h"
|
||||
#include "game/const.h"
|
||||
#include "game/game_string.h"
|
||||
#include "game/input.h"
|
||||
#include "game/shell.h"
|
||||
#include "game/ui2/elements/anchor.h"
|
||||
#include "game/ui2/elements/frame.h"
|
||||
#include "game/ui2/elements/label.h"
|
||||
#include "game/ui2/elements/modal.h"
|
||||
#include "game/ui2/elements/pad.h"
|
||||
#include "game/ui2/elements/requester.h"
|
||||
#include "game/ui2/elements/spacer.h"
|
||||
#include "game/ui2/elements/stack.h"
|
||||
#include "game/ui2/elements/window.h"
|
||||
#include "game/ui/elements/anchor.h"
|
||||
#include "game/ui/elements/frame.h"
|
||||
#include "game/ui/elements/label.h"
|
||||
#include "game/ui/elements/modal.h"
|
||||
#include "game/ui/elements/pad.h"
|
||||
#include "game/ui/elements/requester.h"
|
||||
#include "game/ui/elements/spacer.h"
|
||||
#include "game/ui/elements/stack.h"
|
||||
#include "game/ui/elements/window.h"
|
||||
#include "utils.h"
|
||||
|
||||
typedef enum {
|
||||
|
@ -87,18 +87,17 @@ static const INPUT_ROLE *m_RightRoles = nullptr;
|
|||
|
||||
static INPUT_ROLE M_GetInputRole(int32_t col, int32_t row);
|
||||
static int32_t M_GetInputRoleCount(int32_t col);
|
||||
static void M_CycleLayout(UI2_CONTROLS_EDITOR_STATE *s, int32_t dir);
|
||||
static UI2_CONTROLS_CHOICE M_NavigateLayout(UI2_CONTROLS_EDITOR_STATE *s);
|
||||
static UI2_CONTROLS_CHOICE M_NavigateInputs(UI2_CONTROLS_EDITOR_STATE *s);
|
||||
static UI2_CONTROLS_CHOICE M_NavigateInputsDebounce(
|
||||
UI2_CONTROLS_EDITOR_STATE *s);
|
||||
static UI2_CONTROLS_CHOICE M_Listen(UI2_CONTROLS_EDITOR_STATE *s);
|
||||
static UI2_CONTROLS_CHOICE M_ListenDebounce(UI2_CONTROLS_EDITOR_STATE *s);
|
||||
static void M_CycleLayout(UI_CONTROLS_EDITOR_STATE *s, int32_t dir);
|
||||
static UI_CONTROLS_CHOICE M_NavigateLayout(UI_CONTROLS_EDITOR_STATE *s);
|
||||
static UI_CONTROLS_CHOICE M_NavigateInputs(UI_CONTROLS_EDITOR_STATE *s);
|
||||
static UI_CONTROLS_CHOICE M_NavigateInputsDebounce(UI_CONTROLS_EDITOR_STATE *s);
|
||||
static UI_CONTROLS_CHOICE M_Listen(UI_CONTROLS_EDITOR_STATE *s);
|
||||
static UI_CONTROLS_CHOICE M_ListenDebounce(UI_CONTROLS_EDITOR_STATE *s);
|
||||
|
||||
static void M_Title(const UI2_CONTROLS_EDITOR_STATE *s);
|
||||
static void M_InputChoice(UI2_CONTROLS_EDITOR_STATE *s, INPUT_ROLE role);
|
||||
static void M_InputLabel(const UI2_CONTROLS_EDITOR_STATE *s, INPUT_ROLE role);
|
||||
static void M_Column(UI2_CONTROLS_EDITOR_STATE *s, const INPUT_ROLE *roles);
|
||||
static void M_Title(const UI_CONTROLS_EDITOR_STATE *s);
|
||||
static void M_InputChoice(UI_CONTROLS_EDITOR_STATE *s, INPUT_ROLE role);
|
||||
static void M_InputLabel(const UI_CONTROLS_EDITOR_STATE *s, INPUT_ROLE role);
|
||||
static void M_Column(UI_CONTROLS_EDITOR_STATE *s, const INPUT_ROLE *roles);
|
||||
|
||||
static INPUT_ROLE M_GetInputRole(const int32_t col, const int32_t row)
|
||||
{
|
||||
|
@ -118,7 +117,7 @@ static int32_t M_GetInputRoleCount(const int32_t col)
|
|||
return row;
|
||||
}
|
||||
|
||||
static void M_CycleLayout(UI2_CONTROLS_EDITOR_STATE *const s, const int32_t dir)
|
||||
static void M_CycleLayout(UI_CONTROLS_EDITOR_STATE *const s, const int32_t dir)
|
||||
{
|
||||
s->active_layout += dir;
|
||||
s->active_layout += INPUT_LAYOUT_NUMBER_OF;
|
||||
|
@ -132,12 +131,12 @@ static void M_CycleLayout(UI2_CONTROLS_EDITOR_STATE *const s, const int32_t dir)
|
|||
EventManager_Fire(s->events, &event);
|
||||
}
|
||||
|
||||
static UI2_CONTROLS_CHOICE M_NavigateLayout(UI2_CONTROLS_EDITOR_STATE *const s)
|
||||
static UI_CONTROLS_CHOICE M_NavigateLayout(UI_CONTROLS_EDITOR_STATE *const s)
|
||||
{
|
||||
if (g_InputDB.menu_confirm) {
|
||||
return UI2_CONTROLS_CHOICE_EXIT;
|
||||
return UI_CONTROLS_CHOICE_EXIT;
|
||||
} else if (g_InputDB.menu_back) {
|
||||
return UI2_CONTROLS_CHOICE_GO_BACK;
|
||||
return UI_CONTROLS_CHOICE_GO_BACK;
|
||||
} else if (g_InputDB.menu_left) {
|
||||
M_CycleLayout(s, -1);
|
||||
} else if (g_InputDB.menu_right) {
|
||||
|
@ -151,18 +150,18 @@ static UI2_CONTROLS_CHOICE M_NavigateLayout(UI2_CONTROLS_EDITOR_STATE *const s)
|
|||
s->active_col = 1;
|
||||
s->active_row = M_GetInputRoleCount(1) - 1;
|
||||
} else {
|
||||
return UI2_CONTROLS_CHOICE_NOOP;
|
||||
return UI_CONTROLS_CHOICE_NOOP;
|
||||
}
|
||||
s->active_role = M_GetInputRole(s->active_col, s->active_row);
|
||||
return UI2_CONTROLS_CHOICE_NOOP;
|
||||
return UI_CONTROLS_CHOICE_NOOP;
|
||||
}
|
||||
|
||||
static UI2_CONTROLS_CHOICE M_NavigateInputs(UI2_CONTROLS_EDITOR_STATE *const s)
|
||||
static UI_CONTROLS_CHOICE M_NavigateInputs(UI_CONTROLS_EDITOR_STATE *const s)
|
||||
{
|
||||
if (g_InputDB.menu_confirm) {
|
||||
s->phase = M_PHASE_NAVIGATE_INPUTS_DEBOUNCE;
|
||||
} else if (g_InputDB.menu_back) {
|
||||
return UI2_CONTROLS_CHOICE_GO_BACK;
|
||||
return UI_CONTROLS_CHOICE_GO_BACK;
|
||||
} else if (g_InputDB.menu_left || g_InputDB.menu_right) {
|
||||
s->active_col ^= 1;
|
||||
CLAMP(s->active_row, 0, M_GetInputRoleCount(s->active_col) - 1);
|
||||
|
@ -187,30 +186,30 @@ static UI2_CONTROLS_CHOICE M_NavigateInputs(UI2_CONTROLS_EDITOR_STATE *const s)
|
|||
}
|
||||
}
|
||||
} else {
|
||||
return UI2_CONTROLS_CHOICE_NOOP;
|
||||
return UI_CONTROLS_CHOICE_NOOP;
|
||||
}
|
||||
s->active_role = M_GetInputRole(s->active_col, s->active_row);
|
||||
return UI2_CONTROLS_CHOICE_NOOP;
|
||||
return UI_CONTROLS_CHOICE_NOOP;
|
||||
}
|
||||
|
||||
static UI2_CONTROLS_CHOICE M_NavigateInputsDebounce(
|
||||
UI2_CONTROLS_EDITOR_STATE *const s)
|
||||
static UI_CONTROLS_CHOICE M_NavigateInputsDebounce(
|
||||
UI_CONTROLS_EDITOR_STATE *const s)
|
||||
{
|
||||
Shell_ProcessEvents();
|
||||
Input_Update();
|
||||
if (g_Input.any) {
|
||||
return UI2_CONTROLS_CHOICE_NOOP;
|
||||
return UI_CONTROLS_CHOICE_NOOP;
|
||||
}
|
||||
Input_EnterListenMode();
|
||||
s->phase = M_PHASE_LISTEN;
|
||||
return UI2_CONTROLS_CHOICE_NOOP;
|
||||
return UI_CONTROLS_CHOICE_NOOP;
|
||||
}
|
||||
|
||||
static UI2_CONTROLS_CHOICE M_Listen(UI2_CONTROLS_EDITOR_STATE *const s)
|
||||
static UI_CONTROLS_CHOICE M_Listen(UI_CONTROLS_EDITOR_STATE *const s)
|
||||
{
|
||||
if (!Input_ReadAndAssignRole(
|
||||
s->backend, s->active_layout, s->active_role)) {
|
||||
return UI2_CONTROLS_CHOICE_NOOP;
|
||||
return UI_CONTROLS_CHOICE_NOOP;
|
||||
}
|
||||
|
||||
Input_ExitListenMode();
|
||||
|
@ -223,49 +222,49 @@ static UI2_CONTROLS_CHOICE M_Listen(UI2_CONTROLS_EDITOR_STATE *const s)
|
|||
EventManager_Fire(s->events, &event);
|
||||
|
||||
s->phase = M_PHASE_LISTEN_DEBOUNCE;
|
||||
return UI2_CONTROLS_CHOICE_NOOP;
|
||||
return UI_CONTROLS_CHOICE_NOOP;
|
||||
}
|
||||
|
||||
static UI2_CONTROLS_CHOICE M_ListenDebounce(UI2_CONTROLS_EDITOR_STATE *const s)
|
||||
static UI_CONTROLS_CHOICE M_ListenDebounce(UI_CONTROLS_EDITOR_STATE *const s)
|
||||
{
|
||||
if (!g_Input.any) {
|
||||
s->phase = M_PHASE_NAVIGATE_INPUTS;
|
||||
}
|
||||
return UI2_CONTROLS_CHOICE_NOOP;
|
||||
return UI_CONTROLS_CHOICE_NOOP;
|
||||
}
|
||||
|
||||
static void M_Title(const UI2_CONTROLS_EDITOR_STATE *const s)
|
||||
static void M_Title(const UI_CONTROLS_EDITOR_STATE *const s)
|
||||
{
|
||||
UI2_BeginAnchor(0.5f, 0.5f);
|
||||
UI_BeginAnchor(0.5f, 0.5f);
|
||||
if (s->phase == M_PHASE_NAVIGATE_LAYOUT) {
|
||||
UI2_BeginFrame(UI2_FRAME_SELECTED_OPTION);
|
||||
UI_BeginFrame(UI_FRAME_SELECTED_OPTION);
|
||||
}
|
||||
UI2_BeginPad(2.0f, 1.0f);
|
||||
UI2_Label(Input_GetLayoutName(s->active_layout));
|
||||
UI2_EndPad();
|
||||
UI_BeginPad(2.0f, 1.0f);
|
||||
UI_Label(Input_GetLayoutName(s->active_layout));
|
||||
UI_EndPad();
|
||||
if (s->phase == M_PHASE_NAVIGATE_LAYOUT) {
|
||||
UI2_EndFrame();
|
||||
UI_EndFrame();
|
||||
}
|
||||
UI2_EndAnchor();
|
||||
UI_EndAnchor();
|
||||
}
|
||||
|
||||
static void M_InputLabel(
|
||||
const UI2_CONTROLS_EDITOR_STATE *const s, const INPUT_ROLE role)
|
||||
const UI_CONTROLS_EDITOR_STATE *const s, const INPUT_ROLE role)
|
||||
{
|
||||
const bool is_selected = s->active_role == role
|
||||
&& (s->phase == M_PHASE_NAVIGATE_INPUTS
|
||||
|| s->phase == M_PHASE_NAVIGATE_INPUTS_DEBOUNCE);
|
||||
if (is_selected) {
|
||||
UI2_BeginFrame(UI2_FRAME_SELECTED_OPTION);
|
||||
UI_BeginFrame(UI_FRAME_SELECTED_OPTION);
|
||||
}
|
||||
UI2_Label(Input_GetRoleName(role));
|
||||
UI_Label(Input_GetRoleName(role));
|
||||
if (is_selected) {
|
||||
UI2_EndFrame();
|
||||
UI_EndFrame();
|
||||
}
|
||||
}
|
||||
|
||||
static void M_InputChoice(
|
||||
UI2_CONTROLS_EDITOR_STATE *const s, const INPUT_ROLE role)
|
||||
UI_CONTROLS_EDITOR_STATE *const s, const INPUT_ROLE role)
|
||||
{
|
||||
const bool is_flashing =
|
||||
Input_IsKeyConflicted(s->backend, s->active_layout, role);
|
||||
|
@ -273,54 +272,54 @@ static void M_InputChoice(
|
|||
s->active_role == role && s->phase == M_PHASE_LISTEN;
|
||||
|
||||
if (is_flashing) {
|
||||
UI2_BeginFlash(&s->flash);
|
||||
UI_BeginFlash(&s->flash);
|
||||
}
|
||||
if (is_selected) {
|
||||
UI2_BeginFrame(UI2_FRAME_SELECTED_OPTION);
|
||||
UI_BeginFrame(UI_FRAME_SELECTED_OPTION);
|
||||
}
|
||||
UI2_Label(Input_GetKeyName(s->backend, s->active_layout, role));
|
||||
UI_Label(Input_GetKeyName(s->backend, s->active_layout, role));
|
||||
if (is_selected) {
|
||||
UI2_EndFrame();
|
||||
UI_EndFrame();
|
||||
}
|
||||
if (is_flashing) {
|
||||
UI2_EndFlash();
|
||||
UI_EndFlash();
|
||||
}
|
||||
}
|
||||
|
||||
static void M_Column(
|
||||
UI2_CONTROLS_EDITOR_STATE *const s, const INPUT_ROLE *const roles)
|
||||
UI_CONTROLS_EDITOR_STATE *const s, const INPUT_ROLE *const roles)
|
||||
{
|
||||
UI2_BeginStack(UI2_STACK_HORIZONTAL);
|
||||
UI2_BeginStack(UI2_STACK_VERTICAL);
|
||||
UI_BeginStack(UI_STACK_HORIZONTAL);
|
||||
UI_BeginStack(UI_STACK_VERTICAL);
|
||||
for (const INPUT_ROLE *role = roles; *role != (INPUT_ROLE)-1; role++) {
|
||||
M_InputChoice(s, *role);
|
||||
}
|
||||
UI2_EndStack();
|
||||
UI2_Spacer(10.0f, 0.0f);
|
||||
UI2_BeginStack(UI2_STACK_VERTICAL);
|
||||
UI_EndStack();
|
||||
UI_Spacer(10.0f, 0.0f);
|
||||
UI_BeginStack(UI_STACK_VERTICAL);
|
||||
for (const INPUT_ROLE *role = roles; *role != (INPUT_ROLE)-1; role++) {
|
||||
M_InputLabel(s, *role);
|
||||
}
|
||||
UI2_EndStack();
|
||||
UI2_EndStack();
|
||||
UI_EndStack();
|
||||
UI_EndStack();
|
||||
}
|
||||
|
||||
void UI2_ControlsEditor_Init(
|
||||
UI2_CONTROLS_EDITOR_STATE *const s, EVENT_MANAGER *events)
|
||||
void UI_ControlsEditor_Init(
|
||||
UI_CONTROLS_EDITOR_STATE *const s, EVENT_MANAGER *events)
|
||||
{
|
||||
m_RightRoles = g_Config.gameplay.enable_cheats ? m_RightRoles_CheatsOn
|
||||
: m_RightRoles_CheatsOff;
|
||||
s->events = events;
|
||||
UI2_Flash_Init(&s->flash, LOGIC_FPS * 2 / 3);
|
||||
UI_Flash_Init(&s->flash, LOGIC_FPS * 2 / 3);
|
||||
}
|
||||
|
||||
void UI2_ControlsEditor_Free(UI2_CONTROLS_EDITOR_STATE *const s)
|
||||
void UI_ControlsEditor_Free(UI_CONTROLS_EDITOR_STATE *const s)
|
||||
{
|
||||
UI2_Flash_Free(&s->flash);
|
||||
UI_Flash_Free(&s->flash);
|
||||
}
|
||||
|
||||
void UI2_ControlsEditor_Reinit(
|
||||
UI2_CONTROLS_EDITOR_STATE *s, INPUT_BACKEND backend, int32_t layout)
|
||||
void UI_ControlsEditor_Reinit(
|
||||
UI_CONTROLS_EDITOR_STATE *s, INPUT_BACKEND backend, int32_t layout)
|
||||
{
|
||||
s->backend = backend;
|
||||
s->active_layout = layout;
|
||||
|
@ -330,10 +329,9 @@ void UI2_ControlsEditor_Reinit(
|
|||
s->phase = M_PHASE_NAVIGATE_LAYOUT;
|
||||
}
|
||||
|
||||
UI2_CONTROLS_CHOICE UI2_ControlsEditor_Control(
|
||||
UI2_CONTROLS_EDITOR_STATE *const s)
|
||||
UI_CONTROLS_CHOICE UI_ControlsEditor_Control(UI_CONTROLS_EDITOR_STATE *const s)
|
||||
{
|
||||
UI2_Flash_Control(&s->flash);
|
||||
UI_Flash_Control(&s->flash);
|
||||
switch (s->phase) {
|
||||
case M_PHASE_NAVIGATE_LAYOUT:
|
||||
return M_NavigateLayout(s);
|
||||
|
@ -346,32 +344,32 @@ UI2_CONTROLS_CHOICE UI2_ControlsEditor_Control(
|
|||
case M_PHASE_LISTEN_DEBOUNCE:
|
||||
return M_ListenDebounce(s);
|
||||
default:
|
||||
return UI2_CONTROLS_CHOICE_NOOP;
|
||||
return UI_CONTROLS_CHOICE_NOOP;
|
||||
}
|
||||
}
|
||||
|
||||
void UI2_ControlsEditor(UI2_CONTROLS_EDITOR_STATE *const s)
|
||||
void UI_ControlsEditor(UI_CONTROLS_EDITOR_STATE *const s)
|
||||
{
|
||||
UI2_BeginModal(0.5f, 0.5f);
|
||||
UI2_BeginWindow();
|
||||
UI2_WindowTitle(GS(CONTROLS_CUSTOMIZE));
|
||||
UI2_BeginWindowBody();
|
||||
UI_BeginModal(0.5f, 0.5f);
|
||||
UI_BeginWindow();
|
||||
UI_WindowTitle(GS(CONTROLS_CUSTOMIZE));
|
||||
UI_BeginWindowBody();
|
||||
|
||||
UI2_BeginStackEx((UI2_STACK_SETTINGS) {
|
||||
.orientation = UI2_STACK_VERTICAL,
|
||||
.align = { .h = UI2_STACK_H_ALIGN_SPAN },
|
||||
UI_BeginStackEx((UI_STACK_SETTINGS) {
|
||||
.orientation = UI_STACK_VERTICAL,
|
||||
.align = { .h = UI_STACK_H_ALIGN_SPAN },
|
||||
});
|
||||
M_Title(s);
|
||||
UI2_Spacer(0.0f, 5.0f);
|
||||
UI_Spacer(0.0f, 5.0f);
|
||||
|
||||
UI2_BeginStack(UI2_STACK_HORIZONTAL);
|
||||
UI_BeginStack(UI_STACK_HORIZONTAL);
|
||||
M_Column(s, m_LeftRoles);
|
||||
UI2_Spacer(10.0f, 0.0f);
|
||||
UI_Spacer(10.0f, 0.0f);
|
||||
M_Column(s, m_RightRoles);
|
||||
UI2_EndStack();
|
||||
UI_EndStack();
|
||||
|
||||
UI2_EndStack();
|
||||
UI2_EndWindowBody();
|
||||
UI2_EndWindow();
|
||||
UI2_EndModal();
|
||||
UI_EndStack();
|
||||
UI_EndWindowBody();
|
||||
UI_EndWindow();
|
||||
UI_EndModal();
|
||||
}
|
|
@ -1,17 +1,17 @@
|
|||
#include "game/ui2/dialogs/examine_item.h"
|
||||
#include "game/ui/dialogs/examine_item.h"
|
||||
|
||||
#include "game/game_string.h"
|
||||
#include "game/input.h"
|
||||
#include "game/sound.h"
|
||||
#include "game/text.h"
|
||||
#include "game/ui2/elements/anchor.h"
|
||||
#include "game/ui2/elements/frame.h"
|
||||
#include "game/ui2/elements/label.h"
|
||||
#include "game/ui2/elements/modal.h"
|
||||
#include "game/ui2/elements/pad.h"
|
||||
#include "game/ui2/elements/resize.h"
|
||||
#include "game/ui2/elements/spacer.h"
|
||||
#include "game/ui2/elements/stack.h"
|
||||
#include "game/ui/elements/anchor.h"
|
||||
#include "game/ui/elements/frame.h"
|
||||
#include "game/ui/elements/label.h"
|
||||
#include "game/ui/elements/modal.h"
|
||||
#include "game/ui/elements/pad.h"
|
||||
#include "game/ui/elements/resize.h"
|
||||
#include "game/ui/elements/spacer.h"
|
||||
#include "game/ui/elements/stack.h"
|
||||
#include "memory.h"
|
||||
#include "strings.h"
|
||||
|
||||
|
@ -22,10 +22,10 @@
|
|||
#define DIALOG_PADDING 8.0f
|
||||
#define PADDING_SCALED (3.5f * (DIALOG_PADDING + WINDOW_MARGIN))
|
||||
|
||||
static bool M_SelectPage(UI2_EXAMINE_ITEM_STATE *state, int32_t new_page);
|
||||
static bool M_SelectPage(UI_EXAMINE_ITEM_STATE *state, int32_t new_page);
|
||||
|
||||
static bool M_SelectPage(
|
||||
UI2_EXAMINE_ITEM_STATE *const state, const int32_t new_page)
|
||||
UI_EXAMINE_ITEM_STATE *const state, const int32_t new_page)
|
||||
{
|
||||
if (new_page == state->current_page || new_page < 0
|
||||
|| new_page >= state->page_content->count) {
|
||||
|
@ -35,8 +35,8 @@ static bool M_SelectPage(
|
|||
return true;
|
||||
}
|
||||
|
||||
void UI2_ExamineItem_Init(
|
||||
UI2_EXAMINE_ITEM_STATE *const state, const char *const title,
|
||||
void UI_ExamineItem_Init(
|
||||
UI_EXAMINE_ITEM_STATE *const state, const char *const title,
|
||||
const char *const text, size_t max_lines)
|
||||
{
|
||||
state->max_lines = max_lines;
|
||||
|
@ -50,7 +50,7 @@ void UI2_ExamineItem_Init(
|
|||
Memory_FreePointer(&wrapped);
|
||||
}
|
||||
|
||||
void UI2_ExamineItem_Control(UI2_EXAMINE_ITEM_STATE *const state)
|
||||
void UI_ExamineItem_Control(UI_EXAMINE_ITEM_STATE *const state)
|
||||
{
|
||||
const int32_t page_shift =
|
||||
g_InputDB.menu_left ? -1 : (g_InputDB.menu_right ? 1 : 0);
|
||||
|
@ -59,7 +59,7 @@ void UI2_ExamineItem_Control(UI2_EXAMINE_ITEM_STATE *const state)
|
|||
}
|
||||
}
|
||||
|
||||
void UI2_ExamineItem_Free(UI2_EXAMINE_ITEM_STATE *const state)
|
||||
void UI_ExamineItem_Free(UI_EXAMINE_ITEM_STATE *const state)
|
||||
{
|
||||
Memory_FreePointer(&state->title);
|
||||
for (int32_t i = state->page_content->count - 1; i >= 0; i--) {
|
||||
|
@ -69,63 +69,63 @@ void UI2_ExamineItem_Free(UI2_EXAMINE_ITEM_STATE *const state)
|
|||
Vector_Free(state->page_content);
|
||||
}
|
||||
|
||||
void UI2_ExamineItem(UI2_EXAMINE_ITEM_STATE *const state)
|
||||
void UI_ExamineItem(UI_EXAMINE_ITEM_STATE *const state)
|
||||
{
|
||||
if (state->is_empty) {
|
||||
return;
|
||||
}
|
||||
|
||||
UI2_BeginModal(0.5f, 0.5f);
|
||||
UI2_BeginFrame(UI2_FRAME_DIALOG_BACKGROUND);
|
||||
UI2_BeginPad(DIALOG_PADDING, DIALOG_PADDING);
|
||||
UI2_BeginStackEx((UI2_STACK_SETTINGS) {
|
||||
.orientation = UI2_STACK_VERTICAL,
|
||||
.align = { .h = UI2_STACK_H_ALIGN_SPAN },
|
||||
UI_BeginModal(0.5f, 0.5f);
|
||||
UI_BeginFrame(UI_FRAME_DIALOG_BACKGROUND);
|
||||
UI_BeginPad(DIALOG_PADDING, DIALOG_PADDING);
|
||||
UI_BeginStackEx((UI_STACK_SETTINGS) {
|
||||
.orientation = UI_STACK_VERTICAL,
|
||||
.align = { .h = UI_STACK_H_ALIGN_SPAN },
|
||||
});
|
||||
|
||||
UI2_BeginAnchor(0.5f, 0.5f);
|
||||
UI2_Label(state->title);
|
||||
UI2_EndAnchor();
|
||||
UI2_Spacer(TITLE_MARGIN, TITLE_MARGIN);
|
||||
UI_BeginAnchor(0.5f, 0.5f);
|
||||
UI_Label(state->title);
|
||||
UI_EndAnchor();
|
||||
UI_Spacer(TITLE_MARGIN, TITLE_MARGIN);
|
||||
|
||||
for (int32_t i = 0; i < state->page_content->count; i++) {
|
||||
if (i != state->current_page) {
|
||||
UI2_BeginResize(-1.0f, 0.0f);
|
||||
UI_BeginResize(-1.0f, 0.0f);
|
||||
} else if (state->page_content->count == 1) {
|
||||
UI2_BeginResize(-1.0f, -1.0f);
|
||||
UI_BeginResize(-1.0f, -1.0f);
|
||||
} else {
|
||||
UI2_BeginResize(-1.0f, TEXT_HEIGHT_FIXED * state->max_lines);
|
||||
UI_BeginResize(-1.0f, TEXT_HEIGHT_FIXED * state->max_lines);
|
||||
}
|
||||
UI2_Label(*(char **)Vector_Get(state->page_content, i));
|
||||
UI2_EndResize();
|
||||
UI_Label(*(char **)Vector_Get(state->page_content, i));
|
||||
UI_EndResize();
|
||||
}
|
||||
|
||||
if (state->page_content->count > 1) {
|
||||
UI2_Spacer(TITLE_MARGIN, TITLE_MARGIN * 3);
|
||||
UI_Spacer(TITLE_MARGIN, TITLE_MARGIN * 3);
|
||||
|
||||
UI2_BeginAnchor(1.0f, 0.5f);
|
||||
UI2_BeginStack(UI2_STACK_HORIZONTAL);
|
||||
UI_BeginAnchor(1.0f, 0.5f);
|
||||
UI_BeginStack(UI_STACK_HORIZONTAL);
|
||||
|
||||
if (state->current_page > 0) {
|
||||
UI2_Label("\\{button left} ");
|
||||
UI_Label("\\{button left} ");
|
||||
}
|
||||
|
||||
char page_indicator[100];
|
||||
sprintf(
|
||||
page_indicator, GS(PAGINATION_NAV), state->current_page + 1,
|
||||
state->page_content->count);
|
||||
UI2_Label(page_indicator);
|
||||
UI_Label(page_indicator);
|
||||
|
||||
if (state->current_page < state->page_content->count - 1) {
|
||||
UI2_Label(" \\{button right}");
|
||||
UI_Label(" \\{button right}");
|
||||
}
|
||||
|
||||
UI2_EndStack();
|
||||
UI2_EndAnchor();
|
||||
UI_EndStack();
|
||||
UI_EndAnchor();
|
||||
}
|
||||
|
||||
UI2_EndStack();
|
||||
UI2_EndPad();
|
||||
UI2_EndFrame();
|
||||
UI2_EndModal();
|
||||
UI_EndStack();
|
||||
UI_EndPad();
|
||||
UI_EndFrame();
|
||||
UI_EndModal();
|
||||
}
|
55
src/libtrx/game/ui/dialogs/new_game.c
Normal file
55
src/libtrx/game/ui/dialogs/new_game.c
Normal file
|
@ -0,0 +1,55 @@
|
|||
#include "game/ui/dialogs/new_game.h"
|
||||
|
||||
#include "game/game_string.h"
|
||||
#include "game/ui/elements/anchor.h"
|
||||
#include "game/ui/elements/frame.h"
|
||||
#include "game/ui/elements/label.h"
|
||||
#include "game/ui/elements/modal.h"
|
||||
#include "game/ui/elements/pad.h"
|
||||
#include "game/ui/elements/requester.h"
|
||||
|
||||
static const GAME_STRING_ID m_Options[] = {
|
||||
GS_ID(PASSPORT_MODE_NEW_GAME),
|
||||
GS_ID(PASSPORT_MODE_NEW_GAME_PLUS),
|
||||
GS_ID(PASSPORT_MODE_NEW_GAME_JP),
|
||||
GS_ID(PASSPORT_MODE_NEW_GAME_JP_PLUS),
|
||||
nullptr,
|
||||
};
|
||||
|
||||
void UI_NewGame_Init(UI_NEW_GAME_STATE *const s)
|
||||
{
|
||||
int32_t option_count = 0;
|
||||
for (int32_t i = 0; m_Options[i] != nullptr; i++) {
|
||||
option_count++;
|
||||
}
|
||||
|
||||
UI_Requester_Init(&s->req, option_count, option_count, true);
|
||||
}
|
||||
|
||||
void UI_NewGame_Free(UI_NEW_GAME_STATE *const s)
|
||||
{
|
||||
UI_Requester_Free(&s->req);
|
||||
}
|
||||
|
||||
int32_t UI_NewGame_Control(UI_NEW_GAME_STATE *const s)
|
||||
{
|
||||
return UI_Requester_Control(&s->req);
|
||||
}
|
||||
|
||||
void UI_NewGame(UI_NEW_GAME_STATE *const s)
|
||||
{
|
||||
UI_BeginModal(0.5f, 2.0f / 3.0f);
|
||||
UI_BeginRequester(&s->req, GS(PASSPORT_SELECT_MODE));
|
||||
|
||||
for (int32_t i = UI_Requester_GetFirstRow(&s->req);
|
||||
i < UI_Requester_GetLastRow(&s->req); i++) {
|
||||
UI_BeginRequesterRow(&s->req, i);
|
||||
UI_BeginAnchor(0.5f, 0.5f);
|
||||
UI_Label(GameString_Get(m_Options[i]));
|
||||
UI_EndAnchor();
|
||||
UI_EndRequesterRow(&s->req, i);
|
||||
}
|
||||
|
||||
UI_EndRequester(&s->req);
|
||||
UI_EndModal();
|
||||
}
|
72
src/libtrx/game/ui/dialogs/pause.c
Normal file
72
src/libtrx/game/ui/dialogs/pause.c
Normal file
|
@ -0,0 +1,72 @@
|
|||
#include "game/ui/dialogs/pause.h"
|
||||
|
||||
#include "game/game_string.h"
|
||||
#include "game/ui/elements/anchor.h"
|
||||
#include "game/ui/elements/frame.h"
|
||||
#include "game/ui/elements/label.h"
|
||||
#include "game/ui/elements/modal.h"
|
||||
#include "game/ui/elements/pad.h"
|
||||
#include "game/ui/elements/requester.h"
|
||||
|
||||
static const GAME_STRING_ID m_Options[2][2] = {
|
||||
{ GS_ID(PAUSE_CONTINUE), GS_ID(PAUSE_QUIT) },
|
||||
{ GS_ID(PAUSE_YES), GS_ID(PAUSE_NO) },
|
||||
};
|
||||
|
||||
void UI_Pause_Init(UI_PAUSE_STATE *const s)
|
||||
{
|
||||
s->phase = 0;
|
||||
UI_Requester_Init(&s->req, 2, 2, true);
|
||||
}
|
||||
|
||||
void UI_Pause_Free(UI_PAUSE_STATE *const s)
|
||||
{
|
||||
UI_Requester_Free(&s->req);
|
||||
}
|
||||
|
||||
UI_PAUSE_EXIT_CHOICE UI_Pause_Control(UI_PAUSE_STATE *const s)
|
||||
{
|
||||
const int32_t choice = UI_Requester_Control(&s->req);
|
||||
if (s->phase == 0) {
|
||||
if (choice == UI_REQUESTER_CANCEL) {
|
||||
return UI_PAUSE_RESUME_PAUSE;
|
||||
} else if (choice == 0) {
|
||||
return UI_PAUSE_EXIT_TO_GAME;
|
||||
} else if (choice == 1) {
|
||||
s->phase = 1;
|
||||
UI_Requester_Free(&s->req);
|
||||
UI_Requester_Init(&s->req, 2, 2, true);
|
||||
}
|
||||
} else {
|
||||
if (choice == UI_REQUESTER_CANCEL) {
|
||||
s->phase = 0;
|
||||
} else if (choice == 0) {
|
||||
return UI_PAUSE_EXIT_TO_TITLE;
|
||||
} else if (choice == 1) {
|
||||
return UI_PAUSE_EXIT_TO_GAME;
|
||||
}
|
||||
}
|
||||
return UI_PAUSE_NOOP;
|
||||
}
|
||||
|
||||
void UI_Pause(UI_PAUSE_STATE *const s)
|
||||
{
|
||||
UI_BeginModal(0.5f, 1.0f);
|
||||
UI_BeginPad(50.0f, 50.0f);
|
||||
UI_BeginRequester(
|
||||
&s->req,
|
||||
s->phase == 0 ? GS(PAUSE_EXIT_TO_TITLE) : GS(PAUSE_ARE_YOU_SURE));
|
||||
|
||||
for (int32_t i = UI_Requester_GetFirstRow(&s->req);
|
||||
i < UI_Requester_GetLastRow(&s->req); i++) {
|
||||
UI_BeginRequesterRow(&s->req, i);
|
||||
UI_BeginAnchor(0.5f, 0.5f);
|
||||
UI_Label(GameString_Get(m_Options[s->phase][i]));
|
||||
UI_EndAnchor();
|
||||
UI_EndRequesterRow(&s->req, i);
|
||||
}
|
||||
|
||||
UI_EndRequester(&s->req);
|
||||
UI_EndPad();
|
||||
UI_EndModal();
|
||||
}
|
|
@ -1,18 +1,18 @@
|
|||
#include "game/ui2/dialogs/photo_mode.h"
|
||||
#include "game/ui/dialogs/photo_mode.h"
|
||||
|
||||
#include "config.h"
|
||||
#include "game/game_string.h"
|
||||
#include "game/input.h"
|
||||
#include "game/ui2/elements/frame.h"
|
||||
#include "game/ui2/elements/label.h"
|
||||
#include "game/ui2/elements/modal.h"
|
||||
#include "game/ui2/elements/pad.h"
|
||||
#include "game/ui2/elements/spacer.h"
|
||||
#include "game/ui2/elements/stack.h"
|
||||
#include "game/ui/elements/frame.h"
|
||||
#include "game/ui/elements/label.h"
|
||||
#include "game/ui/elements/modal.h"
|
||||
#include "game/ui/elements/pad.h"
|
||||
#include "game/ui/elements/spacer.h"
|
||||
#include "game/ui/elements/stack.h"
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
void UI2_PhotoMode(void)
|
||||
void UI_PhotoMode(void)
|
||||
{
|
||||
if (!g_Config.ui.enable_photo_mode_ui) {
|
||||
return;
|
||||
|
@ -20,21 +20,21 @@ void UI2_PhotoMode(void)
|
|||
|
||||
char tmp[50];
|
||||
|
||||
UI2_BeginModal(0.0f, 0.0f);
|
||||
UI2_BeginPad(8.0f, 10.0f);
|
||||
UI2_BeginFrame(UI2_FRAME_DIALOG_BACKGROUND);
|
||||
UI2_BeginPad(8.0, 6.0);
|
||||
UI_BeginModal(0.0f, 0.0f);
|
||||
UI_BeginPad(8.0f, 10.0f);
|
||||
UI_BeginFrame(UI_FRAME_DIALOG_BACKGROUND);
|
||||
UI_BeginPad(8.0, 6.0);
|
||||
|
||||
UI2_BeginStackEx((UI2_STACK_SETTINGS) {
|
||||
.orientation = UI2_STACK_VERTICAL,
|
||||
UI_BeginStackEx((UI_STACK_SETTINGS) {
|
||||
.orientation = UI_STACK_VERTICAL,
|
||||
.spacing = { .v = 8.0f },
|
||||
});
|
||||
UI2_Label(GS(PHOTO_MODE_TITLE));
|
||||
UI_Label(GS(PHOTO_MODE_TITLE));
|
||||
|
||||
UI2_BeginStack(UI2_STACK_HORIZONTAL);
|
||||
UI_BeginStack(UI_STACK_HORIZONTAL);
|
||||
|
||||
// Inputs column
|
||||
UI2_BeginStack(UI2_STACK_VERTICAL);
|
||||
UI_BeginStack(UI_STACK_VERTICAL);
|
||||
sprintf(
|
||||
tmp, "%s%s%s%s%s%s: ",
|
||||
Input_GetKeyName(
|
||||
|
@ -55,26 +55,26 @@ void UI2_PhotoMode(void)
|
|||
Input_GetKeyName(
|
||||
INPUT_BACKEND_KEYBOARD, g_Config.input.keyboard_layout,
|
||||
INPUT_ROLE_CAMERA_RIGHT));
|
||||
UI2_Label(tmp);
|
||||
UI2_Label(
|
||||
UI_Label(tmp);
|
||||
UI_Label(
|
||||
"\\{button left} \\{button up} "
|
||||
"\\{button down} \\{button right} : ");
|
||||
sprintf(tmp, "%s: ", GS(PHOTO_MODE_ROLL_ROLE));
|
||||
UI2_Label(tmp);
|
||||
UI_Label(tmp);
|
||||
sprintf(tmp, "%s: ", GS(KEYMAP_ROLL));
|
||||
UI2_Label(tmp);
|
||||
UI_Label(tmp);
|
||||
sprintf(tmp, "%s: ", GS(PHOTO_MODE_FOV_ROLE));
|
||||
UI2_Label(tmp);
|
||||
UI_Label(tmp);
|
||||
sprintf(tmp, "%s: ", GS(KEYMAP_LOOK));
|
||||
UI2_Label(tmp);
|
||||
UI_Label(tmp);
|
||||
sprintf(
|
||||
tmp, "%s: ",
|
||||
Input_GetKeyName(
|
||||
INPUT_BACKEND_KEYBOARD, g_Config.input.keyboard_layout,
|
||||
INPUT_ROLE_TOGGLE_UI));
|
||||
UI2_Label(tmp);
|
||||
UI_Label(tmp);
|
||||
sprintf(tmp, "%s: ", GS(KEYMAP_ACTION));
|
||||
UI2_Label(tmp);
|
||||
UI_Label(tmp);
|
||||
sprintf(
|
||||
tmp, "%s/%s: ",
|
||||
Input_GetKeyName(
|
||||
|
@ -83,29 +83,29 @@ void UI2_PhotoMode(void)
|
|||
Input_GetKeyName(
|
||||
INPUT_BACKEND_KEYBOARD, g_Config.input.keyboard_layout,
|
||||
INPUT_ROLE_OPTION));
|
||||
UI2_Label(tmp);
|
||||
UI2_EndStack();
|
||||
UI_Label(tmp);
|
||||
UI_EndStack();
|
||||
|
||||
UI2_Spacer(4.0f, 0.0f);
|
||||
UI_Spacer(4.0f, 0.0f);
|
||||
|
||||
// Behaviors column
|
||||
UI2_BeginStack(UI2_STACK_VERTICAL);
|
||||
UI2_Label(GS(PHOTO_MODE_MOVE_PROMPT));
|
||||
UI2_Label(GS(PHOTO_MODE_ROTATE_PROMPT));
|
||||
UI2_Label(GS(PHOTO_MODE_ROLL_PROMPT));
|
||||
UI2_Label(GS(PHOTO_MODE_ROTATE90_PROMPT));
|
||||
UI2_Label(GS(PHOTO_MODE_FOV_PROMPT));
|
||||
UI2_Label(GS(PHOTO_MODE_RESET_PROMPT));
|
||||
UI2_Label(GS(MISC_TOGGLE_HELP));
|
||||
UI2_Label(GS(PHOTO_MODE_SNAP_PROMPT));
|
||||
UI2_Label(GS(MISC_EXIT));
|
||||
UI2_EndStack();
|
||||
UI_BeginStack(UI_STACK_VERTICAL);
|
||||
UI_Label(GS(PHOTO_MODE_MOVE_PROMPT));
|
||||
UI_Label(GS(PHOTO_MODE_ROTATE_PROMPT));
|
||||
UI_Label(GS(PHOTO_MODE_ROLL_PROMPT));
|
||||
UI_Label(GS(PHOTO_MODE_ROTATE90_PROMPT));
|
||||
UI_Label(GS(PHOTO_MODE_FOV_PROMPT));
|
||||
UI_Label(GS(PHOTO_MODE_RESET_PROMPT));
|
||||
UI_Label(GS(MISC_TOGGLE_HELP));
|
||||
UI_Label(GS(PHOTO_MODE_SNAP_PROMPT));
|
||||
UI_Label(GS(MISC_EXIT));
|
||||
UI_EndStack();
|
||||
|
||||
UI2_EndStack();
|
||||
UI_EndStack();
|
||||
|
||||
UI2_EndStack();
|
||||
UI2_EndPad();
|
||||
UI2_EndFrame();
|
||||
UI2_EndPad();
|
||||
UI2_EndModal();
|
||||
UI_EndStack();
|
||||
UI_EndPad();
|
||||
UI_EndFrame();
|
||||
UI_EndPad();
|
||||
UI_EndModal();
|
||||
}
|
18
src/libtrx/game/ui/dialogs/stats.c
Normal file
18
src/libtrx/game/ui/dialogs/stats.c
Normal file
|
@ -0,0 +1,18 @@
|
|||
#include "game/ui/dialogs/stats.h"
|
||||
|
||||
void UI_StatsDialog_Init(
|
||||
UI_STATS_DIALOG_STATE *const s, const UI_STATS_DIALOG_ARGS args)
|
||||
{
|
||||
UI_Requester_Init(&s->assault_req, 7, 10, false);
|
||||
s->args = args;
|
||||
}
|
||||
|
||||
void UI_StatsDialog_Free(UI_STATS_DIALOG_STATE *const s)
|
||||
{
|
||||
UI_Requester_Free(&s->assault_req);
|
||||
}
|
||||
|
||||
int32_t UI_StatsDialog_Control(UI_STATS_DIALOG_STATE *const s)
|
||||
{
|
||||
return UI_Requester_Control(&s->assault_req);
|
||||
}
|
56
src/libtrx/game/ui/elements/anchor.c
Normal file
56
src/libtrx/game/ui/elements/anchor.c
Normal file
|
@ -0,0 +1,56 @@
|
|||
#include "game/ui/elements/anchor.h"
|
||||
|
||||
#include "game/text.h"
|
||||
#include "game/ui/helpers.h"
|
||||
|
||||
typedef struct {
|
||||
float x;
|
||||
float y;
|
||||
} M_DATA;
|
||||
|
||||
static void M_Measure(UI_NODE *node);
|
||||
static void M_Layout(UI_NODE *node, float x, float y, float w, float h);
|
||||
|
||||
static const UI_WIDGET_OPS m_Ops = {
|
||||
.measure = UI_MeasureWrapper,
|
||||
.layout = M_Layout,
|
||||
.draw = UI_DrawWrapper,
|
||||
};
|
||||
|
||||
static void M_Measure(UI_NODE *const node)
|
||||
{
|
||||
node->measure_w = UI_GetCanvasWidth();
|
||||
node->measure_h = UI_GetCanvasHeight() - TEXT_HEIGHT_FIXED;
|
||||
}
|
||||
|
||||
static void M_Layout(
|
||||
UI_NODE *const node, const float x, const float y, const float w,
|
||||
const float h)
|
||||
{
|
||||
UI_LayoutBasic(node, x, y, w, h);
|
||||
const M_DATA *const data = node->data;
|
||||
UI_NODE *child = node->first_child;
|
||||
while (child != nullptr) {
|
||||
const float cw = child->measure_w;
|
||||
const float ch = child->measure_h;
|
||||
const float cx = x + (w - cw) * data->x;
|
||||
const float cy = y + (h - ch) * data->y;
|
||||
child->ops->layout(child, cx, cy, cw, ch);
|
||||
child = child->next_sibling;
|
||||
}
|
||||
}
|
||||
|
||||
void UI_BeginAnchor(const float x, const float y)
|
||||
{
|
||||
UI_NODE *const node = UI_AllocNode(&m_Ops, sizeof(M_DATA));
|
||||
M_DATA *const data = node->data;
|
||||
data->x = x;
|
||||
data->y = y;
|
||||
UI_AddChild(node);
|
||||
UI_PushCurrent(node);
|
||||
}
|
||||
|
||||
void UI_EndAnchor(void)
|
||||
{
|
||||
UI_PopCurrent();
|
||||
}
|
45
src/libtrx/game/ui/elements/fade.c
Normal file
45
src/libtrx/game/ui/elements/fade.c
Normal file
|
@ -0,0 +1,45 @@
|
|||
#include "game/ui/elements/fade.h"
|
||||
|
||||
#include "game/output.h"
|
||||
#include "game/ui/helpers.h"
|
||||
|
||||
typedef struct {
|
||||
FADER *fader;
|
||||
bool is_on_top;
|
||||
} M_DATA;
|
||||
|
||||
static void M_Draw(const UI_NODE *node);
|
||||
|
||||
static const UI_WIDGET_OPS m_Ops = {
|
||||
.measure = UI_MeasureWrapper,
|
||||
.layout = UI_LayoutWrapper,
|
||||
.draw = M_Draw,
|
||||
};
|
||||
|
||||
static void M_Draw(const UI_NODE *const node)
|
||||
{
|
||||
const M_DATA *const data = node->data;
|
||||
if (data->is_on_top) {
|
||||
UI_DrawWrapper(node);
|
||||
Output_DrawPolyList(); // flush geometry
|
||||
Fader_Draw(data->fader);
|
||||
} else {
|
||||
Fader_Draw(data->fader);
|
||||
UI_DrawWrapper(node);
|
||||
}
|
||||
}
|
||||
|
||||
void UI_BeginFade(FADER *const fader, bool is_on_top)
|
||||
{
|
||||
UI_NODE *const node = UI_AllocNode(&m_Ops, sizeof(M_DATA *));
|
||||
M_DATA *const data = node->data;
|
||||
data->fader = fader;
|
||||
data->is_on_top = is_on_top;
|
||||
UI_AddChild(node);
|
||||
UI_PushCurrent(node);
|
||||
}
|
||||
|
||||
void UI_EndFade(void)
|
||||
{
|
||||
UI_PopCurrent();
|
||||
}
|
51
src/libtrx/game/ui/elements/flash.c
Normal file
51
src/libtrx/game/ui/elements/flash.c
Normal file
|
@ -0,0 +1,51 @@
|
|||
#include "game/ui/elements/flash.h"
|
||||
|
||||
#include "game/ui/elements/hide.h"
|
||||
#include "game/ui/helpers.h"
|
||||
|
||||
static void M_Draw(const UI_NODE *node);
|
||||
|
||||
static const UI_WIDGET_OPS m_Ops = {
|
||||
.measure = UI_MeasureWrapper,
|
||||
.layout = UI_LayoutWrapper,
|
||||
.draw = M_Draw,
|
||||
};
|
||||
|
||||
static void M_Draw(const UI_NODE *const node)
|
||||
{
|
||||
UI_FLASH_STATE *const s = *(UI_FLASH_STATE **)node->data;
|
||||
UI_BeginHide(s->count >= 0);
|
||||
UI_DrawWrapper(node);
|
||||
UI_EndHide();
|
||||
}
|
||||
|
||||
void UI_Flash_Init(UI_FLASH_STATE *const s, const int32_t rate)
|
||||
{
|
||||
s->count = 0;
|
||||
s->rate = rate;
|
||||
}
|
||||
|
||||
void UI_Flash_Free(UI_FLASH_STATE *const s)
|
||||
{
|
||||
}
|
||||
|
||||
void UI_Flash_Control(UI_FLASH_STATE *const s)
|
||||
{
|
||||
s->count -= 2;
|
||||
if (s->count < -s->rate) {
|
||||
s->count = s->rate;
|
||||
}
|
||||
}
|
||||
|
||||
void UI_BeginFlash(UI_FLASH_STATE *const s)
|
||||
{
|
||||
UI_NODE *const node = UI_AllocNode(&m_Ops, sizeof(UI_FLASH_STATE *));
|
||||
*(UI_FLASH_STATE **)node->data = s;
|
||||
UI_AddChild(node);
|
||||
UI_PushCurrent(node);
|
||||
}
|
||||
|
||||
void UI_EndFlash(void)
|
||||
{
|
||||
UI_PopCurrent();
|
||||
}
|
|
@ -1,9 +1,9 @@
|
|||
#include "game/ui2/elements/frame.h"
|
||||
#include "game/ui/elements/frame.h"
|
||||
|
||||
#include "config.h"
|
||||
#include "game/output.h"
|
||||
#include "game/text.h"
|
||||
#include "game/ui2/helpers.h"
|
||||
#include "game/ui/helpers.h"
|
||||
|
||||
typedef struct {
|
||||
UI_STYLE ui_style;
|
||||
|
@ -12,35 +12,35 @@ typedef struct {
|
|||
int32_t background_z;
|
||||
} M_DATA;
|
||||
|
||||
static void M_Draw(const UI2_NODE *node);
|
||||
static void M_Draw(const UI_NODE *node);
|
||||
|
||||
static const UI2_WIDGET_OPS m_Ops = {
|
||||
.measure = UI2_MeasureWrapper,
|
||||
.layout = UI2_LayoutWrapper,
|
||||
static const UI_WIDGET_OPS m_Ops = {
|
||||
.measure = UI_MeasureWrapper,
|
||||
.layout = UI_LayoutWrapper,
|
||||
.draw = M_Draw,
|
||||
};
|
||||
|
||||
static void M_Draw(const UI2_NODE *node)
|
||||
static void M_Draw(const UI_NODE *node)
|
||||
{
|
||||
const M_DATA *const data = node->data;
|
||||
if (data->background_z >= 0) {
|
||||
Output_DrawTextBackground(
|
||||
data->ui_style, UI2_ScaleX(node->x), UI2_ScaleY(node->y),
|
||||
UI2_ScaleX(node->w), UI2_ScaleY(node->h), data->background_z,
|
||||
data->ui_style, UI_ScaleX(node->x), UI_ScaleY(node->y),
|
||||
UI_ScaleX(node->w), UI_ScaleY(node->h), data->background_z,
|
||||
data->text_style);
|
||||
}
|
||||
if (data->outline_z >= 0) {
|
||||
Output_DrawTextOutline(
|
||||
data->ui_style, UI2_ScaleX(node->x), UI2_ScaleY(node->y),
|
||||
UI2_ScaleX(node->w), UI2_ScaleY(node->h), data->outline_z,
|
||||
data->ui_style, UI_ScaleX(node->x), UI_ScaleY(node->y),
|
||||
UI_ScaleX(node->w), UI_ScaleY(node->h), data->outline_z,
|
||||
data->text_style);
|
||||
}
|
||||
UI2_DrawWrapper(node);
|
||||
UI_DrawWrapper(node);
|
||||
}
|
||||
|
||||
void UI2_BeginFrame(UI2_FRAME_STYLE style)
|
||||
void UI_BeginFrame(UI_FRAME_STYLE style)
|
||||
{
|
||||
UI2_NODE *const node = UI2_AllocNode(&m_Ops, sizeof(M_DATA));
|
||||
UI_NODE *const node = UI_AllocNode(&m_Ops, sizeof(M_DATA));
|
||||
M_DATA *const data = node->data;
|
||||
|
||||
data->ui_style = UI_STYLE_PC;
|
||||
|
@ -49,33 +49,33 @@ void UI2_BeginFrame(UI2_FRAME_STYLE style)
|
|||
#endif
|
||||
|
||||
switch (style) {
|
||||
case UI2_FRAME_DIALOG_BACKGROUND:
|
||||
case UI_FRAME_DIALOG_BACKGROUND:
|
||||
data->outline_z = 160;
|
||||
data->background_z = 160;
|
||||
data->text_style = TS_BACKGROUND;
|
||||
break;
|
||||
case UI2_FRAME_DIALOG_HEADING:
|
||||
case UI_FRAME_DIALOG_HEADING:
|
||||
data->outline_z = 80;
|
||||
data->background_z = 80;
|
||||
data->text_style = TS_HEADING;
|
||||
break;
|
||||
case UI2_FRAME_SELECTED_OPTION:
|
||||
case UI_FRAME_SELECTED_OPTION:
|
||||
data->outline_z = 80;
|
||||
data->background_z = 80;
|
||||
data->text_style = TS_REQUESTED;
|
||||
break;
|
||||
case UI2_FRAME_OUTLINE_ONLY:
|
||||
case UI_FRAME_OUTLINE_ONLY:
|
||||
data->outline_z = 80;
|
||||
data->background_z = -1;
|
||||
data->text_style = TS_REQUESTED;
|
||||
break;
|
||||
}
|
||||
|
||||
UI2_AddChild(node);
|
||||
UI2_PushCurrent(node);
|
||||
UI_AddChild(node);
|
||||
UI_PushCurrent(node);
|
||||
}
|
||||
|
||||
void UI2_EndFrame(void)
|
||||
void UI_EndFrame(void)
|
||||
{
|
||||
UI2_PopCurrent();
|
||||
UI_PopCurrent();
|
||||
}
|
32
src/libtrx/game/ui/elements/hide.c
Normal file
32
src/libtrx/game/ui/elements/hide.c
Normal file
|
@ -0,0 +1,32 @@
|
|||
#include "game/ui/elements/hide.h"
|
||||
|
||||
#include "game/ui/helpers.h"
|
||||
|
||||
static void M_Draw(const UI_NODE *node);
|
||||
|
||||
static const UI_WIDGET_OPS m_Ops = {
|
||||
.measure = UI_MeasureWrapper,
|
||||
.layout = UI_LayoutWrapper,
|
||||
.draw = M_Draw,
|
||||
};
|
||||
|
||||
static void M_Draw(const UI_NODE *const node)
|
||||
{
|
||||
const bool draw_children = *(bool *)node->data;
|
||||
if (draw_children) {
|
||||
UI_DrawWrapper(node);
|
||||
}
|
||||
}
|
||||
|
||||
void UI_BeginHide(const bool hide_children)
|
||||
{
|
||||
UI_NODE *const node = UI_AllocNode(&m_Ops, sizeof(bool));
|
||||
*(bool *)node->data = !hide_children;
|
||||
UI_AddChild(node);
|
||||
UI_PushCurrent(node);
|
||||
}
|
||||
|
||||
void UI_EndHide(void)
|
||||
{
|
||||
UI_PopCurrent();
|
||||
}
|
|
@ -1,33 +1,33 @@
|
|||
#include "game/ui2/elements/label.h"
|
||||
#include "game/ui/elements/label.h"
|
||||
|
||||
#include "config.h"
|
||||
#include "game/text.h"
|
||||
#include "game/ui2/helpers.h"
|
||||
#include "game/ui/helpers.h"
|
||||
|
||||
#include <string.h>
|
||||
|
||||
typedef struct {
|
||||
UI2_LABEL_SETTINGS settings;
|
||||
UI_LABEL_SETTINGS settings;
|
||||
char *text;
|
||||
} M_DATA;
|
||||
|
||||
static void M_Measure(UI2_NODE *node);
|
||||
static void M_Draw(const UI2_NODE *node);
|
||||
static void M_Measure(UI_NODE *node);
|
||||
static void M_Draw(const UI_NODE *node);
|
||||
|
||||
static UI2_LABEL_SETTINGS m_DefaultSettings = { .scale = 1.0f };
|
||||
static const UI2_WIDGET_OPS m_Ops = {
|
||||
static UI_LABEL_SETTINGS m_DefaultSettings = { .scale = 1.0f };
|
||||
static const UI_WIDGET_OPS m_Ops = {
|
||||
.measure = M_Measure,
|
||||
.layout = UI2_LayoutBasic,
|
||||
.layout = UI_LayoutBasic,
|
||||
.draw = M_Draw,
|
||||
};
|
||||
|
||||
static TEXTSTRING *M_CreateText(
|
||||
const float x, const float y, const char *text,
|
||||
const UI2_LABEL_SETTINGS settings);
|
||||
const UI_LABEL_SETTINGS settings);
|
||||
|
||||
static TEXTSTRING *M_CreateText(
|
||||
const float x, const float y, const char *text,
|
||||
const UI2_LABEL_SETTINGS settings)
|
||||
const UI_LABEL_SETTINGS settings)
|
||||
{
|
||||
TEXTSTRING *const textstring = Text_Create(x, y, text);
|
||||
Text_SetPos(
|
||||
|
@ -40,14 +40,14 @@ static TEXTSTRING *M_CreateText(
|
|||
return textstring;
|
||||
}
|
||||
|
||||
static void M_Measure(UI2_NODE *const node)
|
||||
static void M_Measure(UI_NODE *const node)
|
||||
{
|
||||
M_DATA *const data = node->data;
|
||||
UI2_Label_MeasureEx(
|
||||
UI_Label_MeasureEx(
|
||||
data->text, &node->measure_w, &node->measure_h, data->settings);
|
||||
}
|
||||
|
||||
static void M_Draw(const UI2_NODE *const node)
|
||||
static void M_Draw(const UI_NODE *const node)
|
||||
{
|
||||
M_DATA *const data = node->data;
|
||||
TEXTSTRING *const textstring =
|
||||
|
@ -57,34 +57,34 @@ static void M_Draw(const UI2_NODE *const node)
|
|||
}
|
||||
Text_DrawText(textstring);
|
||||
Text_Remove(textstring);
|
||||
UI2_DrawWrapper(node);
|
||||
UI_DrawWrapper(node);
|
||||
}
|
||||
|
||||
void UI2_Label(const char *const text)
|
||||
void UI_Label(const char *const text)
|
||||
{
|
||||
UI2_LabelEx(text, m_DefaultSettings);
|
||||
UI_LabelEx(text, m_DefaultSettings);
|
||||
}
|
||||
|
||||
void UI2_LabelEx(const char *const text, const UI2_LABEL_SETTINGS settings)
|
||||
void UI_LabelEx(const char *const text, const UI_LABEL_SETTINGS settings)
|
||||
{
|
||||
UI2_NODE *const node =
|
||||
UI2_AllocNode(&m_Ops, sizeof(M_DATA) + strlen(text) + 1);
|
||||
UI_NODE *const node =
|
||||
UI_AllocNode(&m_Ops, sizeof(M_DATA) + strlen(text) + 1);
|
||||
M_DATA *const data = node->data;
|
||||
data->settings = settings;
|
||||
data->text = (char *)node->data + sizeof(M_DATA);
|
||||
strcpy(data->text, text);
|
||||
UI2_AddChild(node);
|
||||
UI_AddChild(node);
|
||||
}
|
||||
|
||||
void UI2_Label_Measure(
|
||||
void UI_Label_Measure(
|
||||
const char *const text, float *const out_w, float *const out_h)
|
||||
{
|
||||
UI2_Label_MeasureEx(text, out_w, out_h, m_DefaultSettings);
|
||||
UI_Label_MeasureEx(text, out_w, out_h, m_DefaultSettings);
|
||||
}
|
||||
|
||||
void UI2_Label_MeasureEx(
|
||||
void UI_Label_MeasureEx(
|
||||
const char *const text, float *const out_w, float *const out_h,
|
||||
const UI2_LABEL_SETTINGS settings)
|
||||
const UI_LABEL_SETTINGS settings)
|
||||
{
|
||||
TEXTSTRING *const textstring = M_CreateText(0, 0, text, settings);
|
||||
if (out_w != nullptr) {
|
33
src/libtrx/game/ui/elements/modal.c
Normal file
33
src/libtrx/game/ui/elements/modal.c
Normal file
|
@ -0,0 +1,33 @@
|
|||
#include "game/ui/elements/modal.h"
|
||||
|
||||
#include "game/text.h"
|
||||
#include "game/ui/elements/anchor.h"
|
||||
#include "game/ui/helpers.h"
|
||||
|
||||
static void M_Measure(UI_NODE *node);
|
||||
|
||||
static const UI_WIDGET_OPS m_Ops = {
|
||||
.measure = M_Measure,
|
||||
.layout = UI_LayoutWrapper,
|
||||
.draw = UI_DrawWrapper,
|
||||
};
|
||||
|
||||
static void M_Measure(UI_NODE *const node)
|
||||
{
|
||||
node->measure_w = UI_GetCanvasWidth();
|
||||
node->measure_h = UI_GetCanvasHeight() - TEXT_HEIGHT_FIXED;
|
||||
}
|
||||
|
||||
void UI_BeginModal(const float x, const float y)
|
||||
{
|
||||
UI_NODE *const node = UI_AllocNode(&m_Ops, 0);
|
||||
UI_AddChild(node);
|
||||
UI_PushCurrent(node);
|
||||
UI_BeginAnchor(x, y);
|
||||
}
|
||||
|
||||
void UI_EndModal(void)
|
||||
{
|
||||
UI_EndAnchor();
|
||||
UI_PopCurrent();
|
||||
}
|
|
@ -1,7 +1,7 @@
|
|||
#include "game/ui2/elements/pad.h"
|
||||
#include "game/ui/elements/pad.h"
|
||||
|
||||
#include "config.h"
|
||||
#include "game/ui2/helpers.h"
|
||||
#include "game/ui/helpers.h"
|
||||
|
||||
typedef struct {
|
||||
float t;
|
||||
|
@ -10,56 +10,56 @@ typedef struct {
|
|||
float l;
|
||||
} M_DATA;
|
||||
|
||||
static void M_Measure(UI2_NODE *node);
|
||||
static void M_Layout(UI2_NODE *node, float x, float y, float w, float h);
|
||||
static void M_Measure(UI_NODE *node);
|
||||
static void M_Layout(UI_NODE *node, float x, float y, float w, float h);
|
||||
|
||||
static const UI2_WIDGET_OPS m_Ops = {
|
||||
static const UI_WIDGET_OPS m_Ops = {
|
||||
.measure = M_Measure,
|
||||
.layout = M_Layout,
|
||||
.draw = UI2_DrawWrapper,
|
||||
.draw = UI_DrawWrapper,
|
||||
};
|
||||
|
||||
static void M_Measure(UI2_NODE *const node)
|
||||
static void M_Measure(UI_NODE *const node)
|
||||
{
|
||||
UI2_MeasureWrapper(node);
|
||||
UI_MeasureWrapper(node);
|
||||
const M_DATA *const data = node->data;
|
||||
node->measure_w += data->l + data->r;
|
||||
node->measure_h += data->t + data->d;
|
||||
}
|
||||
|
||||
static void M_Layout(
|
||||
UI2_NODE *const node, const float x, const float y, const float w,
|
||||
UI_NODE *const node, const float x, const float y, const float w,
|
||||
const float h)
|
||||
{
|
||||
UI2_LayoutBasic(node, x, y, w, h);
|
||||
UI_LayoutBasic(node, x, y, w, h);
|
||||
const M_DATA *const data = node->data;
|
||||
const float px = data->l;
|
||||
const float py = data->t;
|
||||
UI2_NODE *child = node->first_child;
|
||||
UI_NODE *child = node->first_child;
|
||||
while (child != nullptr) {
|
||||
child->ops->layout(child, x + px, y + py, w - px * 2.0f, h - py * 2.0f);
|
||||
child = child->next_sibling;
|
||||
}
|
||||
}
|
||||
|
||||
void UI2_BeginPad(const float x, const float y)
|
||||
void UI_BeginPad(const float x, const float y)
|
||||
{
|
||||
UI2_BeginPadEx(x, x, y, y);
|
||||
UI_BeginPadEx(x, x, y, y);
|
||||
}
|
||||
|
||||
void UI2_BeginPadEx(const float l, const float r, const float t, const float d)
|
||||
void UI_BeginPadEx(const float l, const float r, const float t, const float d)
|
||||
{
|
||||
UI2_NODE *const node = UI2_AllocNode(&m_Ops, sizeof(M_DATA));
|
||||
UI_NODE *const node = UI_AllocNode(&m_Ops, sizeof(M_DATA));
|
||||
M_DATA *const data = node->data;
|
||||
data->t = t * g_Config.ui.text_scale;
|
||||
data->r = r * g_Config.ui.text_scale;
|
||||
data->d = d * g_Config.ui.text_scale;
|
||||
data->l = l * g_Config.ui.text_scale;
|
||||
UI2_AddChild(node);
|
||||
UI2_PushCurrent(node);
|
||||
UI_AddChild(node);
|
||||
UI_PushCurrent(node);
|
||||
}
|
||||
|
||||
void UI2_EndPad(void)
|
||||
void UI_EndPad(void)
|
||||
{
|
||||
UI2_PopCurrent();
|
||||
UI_PopCurrent();
|
||||
}
|
|
@ -1,12 +1,12 @@
|
|||
#include "game/ui2/elements/prompt.h"
|
||||
#include "game/ui/elements/prompt.h"
|
||||
|
||||
#include "game/const.h"
|
||||
#include "game/input.h"
|
||||
#include "game/ui2/common.h"
|
||||
#include "game/ui2/elements/flash.h"
|
||||
#include "game/ui2/elements/label.h"
|
||||
#include "game/ui2/events.h"
|
||||
#include "game/ui2/helpers.h"
|
||||
#include "game/ui/common.h"
|
||||
#include "game/ui/elements/flash.h"
|
||||
#include "game/ui/elements/label.h"
|
||||
#include "game/ui/events.h"
|
||||
#include "game/ui/helpers.h"
|
||||
#include "log.h"
|
||||
#include "memory.h"
|
||||
#include "strings.h"
|
||||
|
@ -15,77 +15,77 @@
|
|||
#include <string.h>
|
||||
|
||||
typedef struct {
|
||||
UI2_PROMPT_STATE *state;
|
||||
UI_PROMPT_STATE *state;
|
||||
} M_DATA;
|
||||
|
||||
static const char m_ValidPromptChars[] =
|
||||
"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789.-: ";
|
||||
|
||||
static void M_Layout(UI2_NODE *node, float x, float y, float w, float h);
|
||||
static void M_Layout(UI_NODE *node, float x, float y, float w, float h);
|
||||
|
||||
static const UI2_WIDGET_OPS m_Ops = {
|
||||
.measure = UI2_MeasureWrapper,
|
||||
static const UI_WIDGET_OPS m_Ops = {
|
||||
.measure = UI_MeasureWrapper,
|
||||
.layout = M_Layout,
|
||||
.draw = UI2_DrawWrapper,
|
||||
.draw = UI_DrawWrapper,
|
||||
};
|
||||
|
||||
static void M_MoveCaretLeft(UI2_PROMPT_STATE *s);
|
||||
static void M_MoveCaretRight(UI2_PROMPT_STATE *s);
|
||||
static void M_MoveCaretStart(UI2_PROMPT_STATE *s);
|
||||
static void M_MoveCaretEnd(UI2_PROMPT_STATE *s);
|
||||
static void M_DeleteCharBack(UI2_PROMPT_STATE *s);
|
||||
static void M_Confirm(UI2_PROMPT_STATE *s);
|
||||
static void M_Cancel(UI2_PROMPT_STATE *s);
|
||||
static void M_Clear(UI2_PROMPT_STATE *s);
|
||||
static void M_MoveCaretLeft(UI_PROMPT_STATE *s);
|
||||
static void M_MoveCaretRight(UI_PROMPT_STATE *s);
|
||||
static void M_MoveCaretStart(UI_PROMPT_STATE *s);
|
||||
static void M_MoveCaretEnd(UI_PROMPT_STATE *s);
|
||||
static void M_DeleteCharBack(UI_PROMPT_STATE *s);
|
||||
static void M_Confirm(UI_PROMPT_STATE *s);
|
||||
static void M_Cancel(UI_PROMPT_STATE *s);
|
||||
static void M_Clear(UI_PROMPT_STATE *s);
|
||||
|
||||
static void M_HandleKeyDown(const EVENT *event, void *user_data);
|
||||
static void M_HandleTextEdit(const EVENT *event, void *user_data);
|
||||
|
||||
static void M_Layout(
|
||||
UI2_NODE *const node, const float x, const float y, const float w,
|
||||
UI_NODE *const node, const float x, const float y, const float w,
|
||||
const float h)
|
||||
{
|
||||
UI2_LayoutBasic(node, x, y, w, h);
|
||||
UI_LayoutBasic(node, x, y, w, h);
|
||||
const M_DATA *const data = node->data;
|
||||
const UI2_PROMPT_STATE *const s = data->state;
|
||||
UI2_NODE *const prompt = node->first_child;
|
||||
UI2_NODE *const caret = prompt->next_sibling;
|
||||
const UI_PROMPT_STATE *const s = data->state;
|
||||
UI_NODE *const prompt = node->first_child;
|
||||
UI_NODE *const caret = prompt->next_sibling;
|
||||
prompt->ops->layout(prompt, x, y, w, h);
|
||||
|
||||
const char old = s->current_text[s->caret_pos];
|
||||
s->current_text[s->caret_pos] = '\0';
|
||||
float caret_pos;
|
||||
UI2_Label_Measure(s->current_text, &caret_pos, nullptr);
|
||||
UI_Label_Measure(s->current_text, &caret_pos, nullptr);
|
||||
s->current_text[s->caret_pos] = old;
|
||||
|
||||
caret->ops->layout(caret, x + caret_pos, y, w, h);
|
||||
}
|
||||
|
||||
static void M_MoveCaretLeft(UI2_PROMPT_STATE *const s)
|
||||
static void M_MoveCaretLeft(UI_PROMPT_STATE *const s)
|
||||
{
|
||||
if (s->caret_pos > 0) {
|
||||
s->caret_pos--;
|
||||
}
|
||||
}
|
||||
|
||||
static void M_MoveCaretRight(UI2_PROMPT_STATE *const s)
|
||||
static void M_MoveCaretRight(UI_PROMPT_STATE *const s)
|
||||
{
|
||||
if (s->caret_pos < (int32_t)strlen(s->current_text)) {
|
||||
s->caret_pos++;
|
||||
}
|
||||
}
|
||||
|
||||
static void M_MoveCaretStart(UI2_PROMPT_STATE *const s)
|
||||
static void M_MoveCaretStart(UI_PROMPT_STATE *const s)
|
||||
{
|
||||
s->caret_pos = 0;
|
||||
}
|
||||
|
||||
static void M_MoveCaretEnd(UI2_PROMPT_STATE *const s)
|
||||
static void M_MoveCaretEnd(UI_PROMPT_STATE *const s)
|
||||
{
|
||||
s->caret_pos = strlen(s->current_text);
|
||||
}
|
||||
|
||||
static void M_DeleteCharBack(UI2_PROMPT_STATE *const s)
|
||||
static void M_DeleteCharBack(UI_PROMPT_STATE *const s)
|
||||
{
|
||||
if (s->caret_pos <= 0) {
|
||||
return;
|
||||
|
@ -97,13 +97,13 @@ static void M_DeleteCharBack(UI2_PROMPT_STATE *const s)
|
|||
s->caret_pos--;
|
||||
}
|
||||
|
||||
static void M_Confirm(UI2_PROMPT_STATE *const s)
|
||||
static void M_Confirm(UI_PROMPT_STATE *const s)
|
||||
{
|
||||
if (String_IsEmpty(s->current_text)) {
|
||||
M_Cancel(s);
|
||||
return;
|
||||
}
|
||||
UI2_FireEvent((EVENT) {
|
||||
UI_FireEvent((EVENT) {
|
||||
.name = "confirm",
|
||||
.sender = s,
|
||||
.data = s->current_text,
|
||||
|
@ -111,9 +111,9 @@ static void M_Confirm(UI2_PROMPT_STATE *const s)
|
|||
M_Clear(s);
|
||||
}
|
||||
|
||||
static void M_Cancel(UI2_PROMPT_STATE *const s)
|
||||
static void M_Cancel(UI_PROMPT_STATE *const s)
|
||||
{
|
||||
UI2_FireEvent((EVENT) {
|
||||
UI_FireEvent((EVENT) {
|
||||
.name = "cancel",
|
||||
.sender = s,
|
||||
.data = s->current_text,
|
||||
|
@ -121,7 +121,7 @@ static void M_Cancel(UI2_PROMPT_STATE *const s)
|
|||
M_Clear(s);
|
||||
}
|
||||
|
||||
static void M_Clear(UI2_PROMPT_STATE *const s)
|
||||
static void M_Clear(UI_PROMPT_STATE *const s)
|
||||
{
|
||||
strcpy(s->current_text, "");
|
||||
s->caret_pos = 0;
|
||||
|
@ -129,8 +129,8 @@ static void M_Clear(UI2_PROMPT_STATE *const s)
|
|||
|
||||
static void M_HandleKeyDown(const EVENT *const event, void *const user_data)
|
||||
{
|
||||
const UI2_INPUT key = (UI2_INPUT)(uintptr_t)event->data;
|
||||
UI2_PROMPT_STATE *const s = user_data;
|
||||
const UI_INPUT key = (UI_INPUT)(uintptr_t)event->data;
|
||||
UI_PROMPT_STATE *const s = user_data;
|
||||
|
||||
if (!s->is_focused) {
|
||||
return;
|
||||
|
@ -138,13 +138,13 @@ static void M_HandleKeyDown(const EVENT *const event, void *const user_data)
|
|||
|
||||
// clang-format off
|
||||
switch (key) {
|
||||
case UI2_KEY_LEFT: M_MoveCaretLeft(s); break;
|
||||
case UI2_KEY_RIGHT: M_MoveCaretRight(s); break;
|
||||
case UI2_KEY_HOME: M_MoveCaretStart(s); break;
|
||||
case UI2_KEY_END: M_MoveCaretEnd(s); break;
|
||||
case UI2_KEY_BACK: M_DeleteCharBack(s); break;
|
||||
case UI2_KEY_RETURN: M_Confirm(s); break;
|
||||
case UI2_KEY_ESCAPE: M_Cancel(s); break;
|
||||
case UI_KEY_LEFT: M_MoveCaretLeft(s); break;
|
||||
case UI_KEY_RIGHT: M_MoveCaretRight(s); break;
|
||||
case UI_KEY_HOME: M_MoveCaretStart(s); break;
|
||||
case UI_KEY_END: M_MoveCaretEnd(s); break;
|
||||
case UI_KEY_BACK: M_DeleteCharBack(s); break;
|
||||
case UI_KEY_RETURN: M_Confirm(s); break;
|
||||
case UI_KEY_ESCAPE: M_Cancel(s); break;
|
||||
default: break;
|
||||
}
|
||||
// clang-format on
|
||||
|
@ -154,7 +154,7 @@ static void M_HandleTextEdit(const EVENT *const event, void *const user_data)
|
|||
{
|
||||
const char *insert_string = event->data;
|
||||
const size_t insert_length = strlen(insert_string);
|
||||
UI2_PROMPT_STATE *const s = user_data;
|
||||
UI_PROMPT_STATE *const s = user_data;
|
||||
|
||||
if (!s->is_focused) {
|
||||
return;
|
||||
|
@ -182,51 +182,51 @@ static void M_HandleTextEdit(const EVENT *const event, void *const user_data)
|
|||
s->caret_pos += insert_length;
|
||||
}
|
||||
|
||||
void UI2_Prompt_Init(UI2_PROMPT_STATE *const s)
|
||||
void UI_Prompt_Init(UI_PROMPT_STATE *const s)
|
||||
{
|
||||
s->is_focused = false;
|
||||
s->current_text_capacity = 30;
|
||||
s->current_text = Memory_Alloc(s->current_text_capacity);
|
||||
s->listener1 = UI2_Subscribe("key_down", nullptr, M_HandleKeyDown, s);
|
||||
s->listener2 = UI2_Subscribe("text_edit", nullptr, M_HandleTextEdit, s);
|
||||
UI2_Flash_Init(&s->flash, LOGIC_FPS * 2 / 3);
|
||||
s->listener1 = UI_Subscribe("key_down", nullptr, M_HandleKeyDown, s);
|
||||
s->listener2 = UI_Subscribe("text_edit", nullptr, M_HandleTextEdit, s);
|
||||
UI_Flash_Init(&s->flash, LOGIC_FPS * 2 / 3);
|
||||
}
|
||||
|
||||
void UI2_Prompt_Free(UI2_PROMPT_STATE *const s)
|
||||
void UI_Prompt_Free(UI_PROMPT_STATE *const s)
|
||||
{
|
||||
UI2_Unsubscribe(s->listener1);
|
||||
UI2_Unsubscribe(s->listener2);
|
||||
UI2_Flash_Free(&s->flash);
|
||||
UI_Unsubscribe(s->listener1);
|
||||
UI_Unsubscribe(s->listener2);
|
||||
UI_Flash_Free(&s->flash);
|
||||
Memory_FreePointer(&s->current_text);
|
||||
}
|
||||
|
||||
void UI2_Prompt_Control(UI2_PROMPT_STATE *const s)
|
||||
void UI_Prompt_Control(UI_PROMPT_STATE *const s)
|
||||
{
|
||||
UI2_Flash_Control(&s->flash);
|
||||
UI_Flash_Control(&s->flash);
|
||||
}
|
||||
|
||||
void UI2_Prompt(UI2_PROMPT_STATE *const s)
|
||||
void UI_Prompt(UI_PROMPT_STATE *const s)
|
||||
{
|
||||
UI2_NODE *const node = UI2_AllocNode(&m_Ops, sizeof(M_DATA));
|
||||
UI_NODE *const node = UI_AllocNode(&m_Ops, sizeof(M_DATA));
|
||||
M_DATA *const data = node->data;
|
||||
data->state = s;
|
||||
UI2_AddChild(node);
|
||||
UI2_PushCurrent(node);
|
||||
UI2_LabelEx(
|
||||
UI_AddChild(node);
|
||||
UI_PushCurrent(node);
|
||||
UI_LabelEx(
|
||||
s->current_text != nullptr ? s->current_text : "",
|
||||
(UI2_LABEL_SETTINGS) { .scale = 1.0f, .z = 16 });
|
||||
(UI_LABEL_SETTINGS) { .scale = 1.0f, .z = 16 });
|
||||
if (s->is_focused) {
|
||||
UI2_BeginFlash(&s->flash);
|
||||
UI_BeginFlash(&s->flash);
|
||||
}
|
||||
UI2_LabelEx(
|
||||
"\\{button left}", (UI2_LABEL_SETTINGS) { .scale = 1.0f, .z = 8 });
|
||||
UI_LabelEx(
|
||||
"\\{button left}", (UI_LABEL_SETTINGS) { .scale = 1.0f, .z = 8 });
|
||||
if (s->is_focused) {
|
||||
UI2_EndFlash();
|
||||
UI_EndFlash();
|
||||
}
|
||||
UI2_PopCurrent();
|
||||
UI_PopCurrent();
|
||||
}
|
||||
|
||||
void UI2_Prompt_SetFocus(UI2_PROMPT_STATE *const s, const bool is_focused)
|
||||
void UI_Prompt_SetFocus(UI_PROMPT_STATE *const s, const bool is_focused)
|
||||
{
|
||||
if (s->is_focused == is_focused) {
|
||||
return;
|
||||
|
@ -240,13 +240,12 @@ void UI2_Prompt_SetFocus(UI2_PROMPT_STATE *const s, const bool is_focused)
|
|||
}
|
||||
}
|
||||
|
||||
void UI2_Prompt_Clear(UI2_PROMPT_STATE *const s)
|
||||
void UI_Prompt_Clear(UI_PROMPT_STATE *const s)
|
||||
{
|
||||
M_Clear(s);
|
||||
}
|
||||
|
||||
void UI2_Prompt_ChangeText(
|
||||
UI2_PROMPT_STATE *const s, const char *const new_text)
|
||||
void UI_Prompt_ChangeText(UI_PROMPT_STATE *const s, const char *const new_text)
|
||||
{
|
||||
Memory_FreePointer(&s->current_text);
|
||||
s->current_text = Memory_DupStr(new_text);
|
125
src/libtrx/game/ui/elements/requester.c
Normal file
125
src/libtrx/game/ui/elements/requester.c
Normal file
|
@ -0,0 +1,125 @@
|
|||
#include "game/ui/elements/requester.h"
|
||||
|
||||
#include "game/input.h"
|
||||
#include "game/ui/elements/frame.h"
|
||||
#include "game/ui/elements/pad.h"
|
||||
#include "game/ui/elements/stack.h"
|
||||
#include "game/ui/elements/window.h"
|
||||
#include "utils.h"
|
||||
|
||||
void UI_Requester_Init(
|
||||
UI_REQUESTER_STATE *const s, const int32_t vis_rows, const int32_t max_rows,
|
||||
const bool is_selectable)
|
||||
{
|
||||
s->vis_row = 0;
|
||||
s->sel_row = 0;
|
||||
s->vis_rows = vis_rows;
|
||||
s->max_rows = max_rows;
|
||||
s->is_selectable = is_selectable;
|
||||
s->row_pad = 20.0f;
|
||||
s->row_spacing = 3.0f;
|
||||
}
|
||||
|
||||
void UI_Requester_Free(UI_REQUESTER_STATE *const s)
|
||||
{
|
||||
}
|
||||
|
||||
int32_t UI_Requester_Control(UI_REQUESTER_STATE *const s)
|
||||
{
|
||||
if (g_InputDB.menu_down) {
|
||||
if (s->vis_row + s->vis_rows < s->max_rows) {
|
||||
s->vis_row++;
|
||||
}
|
||||
} else if (g_InputDB.menu_up) {
|
||||
if (s->vis_row > 0) {
|
||||
s->vis_row--;
|
||||
}
|
||||
}
|
||||
|
||||
if (s->is_selectable) {
|
||||
if (g_InputDB.menu_down && s->sel_row + 1 < s->max_rows) {
|
||||
s->sel_row++;
|
||||
} else if (g_InputDB.menu_up && s->sel_row > 0) {
|
||||
s->sel_row--;
|
||||
}
|
||||
if (g_InputDB.menu_back) {
|
||||
return UI_REQUESTER_CANCEL;
|
||||
}
|
||||
if (g_InputDB.menu_confirm) {
|
||||
return s->sel_row;
|
||||
}
|
||||
}
|
||||
return UI_REQUESTER_NO_CHOICE;
|
||||
}
|
||||
|
||||
void UI_Requester_SetMaxRows(
|
||||
UI_REQUESTER_STATE *const s, const int32_t max_rows)
|
||||
{
|
||||
s->max_rows = max_rows;
|
||||
}
|
||||
|
||||
int32_t UI_Requester_GetFirstRow(const UI_REQUESTER_STATE *const s)
|
||||
{
|
||||
return s->vis_row;
|
||||
}
|
||||
|
||||
int32_t UI_Requester_GetLastRow(const UI_REQUESTER_STATE *const s)
|
||||
{
|
||||
return MIN(s->vis_row + s->vis_rows, s->max_rows);
|
||||
}
|
||||
|
||||
int32_t UI_Requester_GetCurrentRow(const UI_REQUESTER_STATE *s)
|
||||
{
|
||||
return s->sel_row;
|
||||
}
|
||||
|
||||
bool UI_Requester_IsRowVisible(
|
||||
const UI_REQUESTER_STATE *const s, const int32_t i)
|
||||
{
|
||||
return i >= UI_Requester_GetFirstRow(s) && i <= UI_Requester_GetLastRow(s);
|
||||
}
|
||||
|
||||
bool UI_Requester_IsRowSelected(
|
||||
const UI_REQUESTER_STATE *const s, const int32_t i)
|
||||
{
|
||||
return i == s->sel_row;
|
||||
}
|
||||
|
||||
void UI_BeginRequester(
|
||||
const UI_REQUESTER_STATE *const s, const char *const title)
|
||||
{
|
||||
UI_BeginWindow();
|
||||
UI_WindowTitle(title);
|
||||
UI_BeginWindowBody();
|
||||
|
||||
UI_BeginStackEx((UI_STACK_SETTINGS) {
|
||||
.orientation = UI_STACK_VERTICAL,
|
||||
.align = { .h = UI_STACK_H_ALIGN_SPAN },
|
||||
.spacing = { .v = s->row_spacing },
|
||||
});
|
||||
}
|
||||
|
||||
void UI_EndRequester(const UI_REQUESTER_STATE *const s)
|
||||
{
|
||||
UI_EndStack();
|
||||
UI_EndWindowBody();
|
||||
UI_EndWindow();
|
||||
}
|
||||
|
||||
void UI_BeginRequesterRow(const UI_REQUESTER_STATE *const s, const int32_t i)
|
||||
{
|
||||
UI_BeginPad(0.0f, TR_VERSION == 1 ? -1.0f : 0.0f);
|
||||
if (UI_Requester_IsRowSelected(s, i)) {
|
||||
UI_BeginFrame(UI_FRAME_SELECTED_OPTION);
|
||||
}
|
||||
UI_BeginPad(s->row_pad, TR_VERSION == 1 ? 1.0f : 0.0f);
|
||||
}
|
||||
|
||||
void UI_EndRequesterRow(const UI_REQUESTER_STATE *const s, const int32_t i)
|
||||
{
|
||||
UI_EndPad();
|
||||
if (UI_Requester_IsRowSelected(s, i)) {
|
||||
UI_EndFrame();
|
||||
}
|
||||
UI_EndPad();
|
||||
}
|
44
src/libtrx/game/ui/elements/resize.c
Normal file
44
src/libtrx/game/ui/elements/resize.c
Normal file
|
@ -0,0 +1,44 @@
|
|||
#include "game/ui/elements/resize.h"
|
||||
|
||||
#include "config.h"
|
||||
#include "game/ui/helpers.h"
|
||||
|
||||
typedef struct {
|
||||
float x;
|
||||
float y;
|
||||
} M_DATA;
|
||||
|
||||
static void M_Measure(UI_NODE *node);
|
||||
|
||||
static const UI_WIDGET_OPS m_Ops = {
|
||||
.measure = M_Measure,
|
||||
.layout = UI_LayoutWrapper,
|
||||
.draw = UI_DrawWrapper,
|
||||
};
|
||||
|
||||
static void M_Measure(UI_NODE *const node)
|
||||
{
|
||||
UI_MeasureWrapper(node);
|
||||
const M_DATA *const data = node->data;
|
||||
if (data->x >= 0.0f) {
|
||||
node->measure_w = data->x;
|
||||
}
|
||||
if (data->y >= 0.0f) {
|
||||
node->measure_h = data->y;
|
||||
}
|
||||
}
|
||||
|
||||
void UI_BeginResize(const float x, const float y)
|
||||
{
|
||||
UI_NODE *const node = UI_AllocNode(&m_Ops, sizeof(M_DATA));
|
||||
M_DATA *const data = node->data;
|
||||
data->x = x * g_Config.ui.text_scale;
|
||||
data->y = y * g_Config.ui.text_scale;
|
||||
UI_AddChild(node);
|
||||
UI_PushCurrent(node);
|
||||
}
|
||||
|
||||
void UI_EndResize(void)
|
||||
{
|
||||
UI_PopCurrent();
|
||||
}
|
25
src/libtrx/game/ui/elements/spacer.c
Normal file
25
src/libtrx/game/ui/elements/spacer.c
Normal file
|
@ -0,0 +1,25 @@
|
|||
#include "game/ui/elements/spacer.h"
|
||||
|
||||
#include "config.h"
|
||||
#include "game/ui/helpers.h"
|
||||
|
||||
static void M_Measure(UI_NODE *node);
|
||||
|
||||
static const UI_WIDGET_OPS m_Ops = {
|
||||
.measure = M_Measure,
|
||||
.layout = UI_LayoutBasic,
|
||||
.draw = UI_DrawWrapper,
|
||||
};
|
||||
|
||||
static void M_Measure(UI_NODE *const node)
|
||||
{
|
||||
// already done in the constructor
|
||||
}
|
||||
|
||||
void UI_Spacer(const float w, const float h)
|
||||
{
|
||||
UI_NODE *const node = UI_AllocNode(&m_Ops, 0);
|
||||
node->measure_w = w * g_Config.ui.text_scale;
|
||||
node->measure_h = h * g_Config.ui.text_scale;
|
||||
UI_AddChild(node);
|
||||
}
|
|
@ -1,94 +1,90 @@
|
|||
#include "game/ui2/elements/stack.h"
|
||||
#include "game/ui/elements/stack.h"
|
||||
|
||||
#include "config.h"
|
||||
#include "debug.h"
|
||||
#include "game/ui2/helpers.h"
|
||||
#include "game/ui/helpers.h"
|
||||
#include "utils.h"
|
||||
|
||||
#include <math.h>
|
||||
#include <stdint.h>
|
||||
|
||||
typedef struct {
|
||||
UI2_STACK_SETTINGS settings;
|
||||
UI_STACK_SETTINGS settings;
|
||||
} M_DATA;
|
||||
|
||||
static float M_CalcChildW(const UI2_NODE *node, const UI2_NODE *child);
|
||||
static float M_CalcChildH(const UI2_NODE *node, const UI2_NODE *child);
|
||||
static float M_CalcStartX(const UI2_NODE *node, const UI2_NODE *child);
|
||||
static float M_CalcStartY(const UI2_NODE *node, const UI2_NODE *child);
|
||||
static void M_Measure(UI2_NODE *node);
|
||||
static void M_Layout(UI2_NODE *node, float x, float y, float w, float h);
|
||||
static float M_CalcChildW(const UI_NODE *node, const UI_NODE *child);
|
||||
static float M_CalcChildH(const UI_NODE *node, const UI_NODE *child);
|
||||
static float M_CalcStartX(const UI_NODE *node, const UI_NODE *child);
|
||||
static float M_CalcStartY(const UI_NODE *node, const UI_NODE *child);
|
||||
static void M_Measure(UI_NODE *node);
|
||||
static void M_Layout(UI_NODE *node, float x, float y, float w, float h);
|
||||
|
||||
static const UI2_WIDGET_OPS m_Ops = {
|
||||
static const UI_WIDGET_OPS m_Ops = {
|
||||
.measure = M_Measure,
|
||||
.layout = M_Layout,
|
||||
.draw = UI2_DrawWrapper,
|
||||
.draw = UI_DrawWrapper,
|
||||
};
|
||||
|
||||
static float M_CalcChildW(
|
||||
const UI2_NODE *const node, const UI2_NODE *const child)
|
||||
static float M_CalcChildW(const UI_NODE *const node, const UI_NODE *const child)
|
||||
{
|
||||
M_DATA *const data = node->data;
|
||||
if (data->settings.align.h == UI2_STACK_H_ALIGN_SPAN) {
|
||||
if (data->settings.align.h == UI_STACK_H_ALIGN_SPAN) {
|
||||
return MAX(child->measure_w, node->w);
|
||||
}
|
||||
return child->measure_w;
|
||||
}
|
||||
|
||||
static float M_CalcChildH(
|
||||
const UI2_NODE *const node, const UI2_NODE *const child)
|
||||
static float M_CalcChildH(const UI_NODE *const node, const UI_NODE *const child)
|
||||
{
|
||||
M_DATA *const data = node->data;
|
||||
if (data->settings.align.v == UI2_STACK_V_ALIGN_SPAN) {
|
||||
if (data->settings.align.v == UI_STACK_V_ALIGN_SPAN) {
|
||||
return MAX(child->measure_h, node->h);
|
||||
}
|
||||
return child->measure_h;
|
||||
}
|
||||
|
||||
static float M_CalcStartX(
|
||||
const UI2_NODE *const node, const UI2_NODE *const child)
|
||||
static float M_CalcStartX(const UI_NODE *const node, const UI_NODE *const child)
|
||||
{
|
||||
M_DATA *const data = node->data;
|
||||
switch (data->settings.align.h) {
|
||||
case UI2_STACK_H_ALIGN_SPAN:
|
||||
case UI2_STACK_H_ALIGN_LEFT:
|
||||
case UI_STACK_H_ALIGN_SPAN:
|
||||
case UI_STACK_H_ALIGN_LEFT:
|
||||
return node->x;
|
||||
case UI2_STACK_H_ALIGN_CENTER:
|
||||
case UI_STACK_H_ALIGN_CENTER:
|
||||
return node->x + (node->w - child->measure_w) * 0.5f;
|
||||
case UI2_STACK_H_ALIGN_RIGHT:
|
||||
case UI_STACK_H_ALIGN_RIGHT:
|
||||
return node->x + node->w - child->measure_w;
|
||||
case UI2_STACK_H_ALIGN_DISTRIBUTE:
|
||||
case UI_STACK_H_ALIGN_DISTRIBUTE:
|
||||
ASSERT_FAIL();
|
||||
}
|
||||
return 0.0f;
|
||||
}
|
||||
|
||||
static float M_CalcStartY(
|
||||
const UI2_NODE *const node, const UI2_NODE *const child)
|
||||
static float M_CalcStartY(const UI_NODE *const node, const UI_NODE *const child)
|
||||
{
|
||||
M_DATA *const data = node->data;
|
||||
switch (data->settings.align.v) {
|
||||
case UI2_STACK_V_ALIGN_SPAN:
|
||||
case UI2_STACK_V_ALIGN_TOP:
|
||||
case UI_STACK_V_ALIGN_SPAN:
|
||||
case UI_STACK_V_ALIGN_TOP:
|
||||
return node->y;
|
||||
case UI2_STACK_V_ALIGN_CENTER:
|
||||
case UI_STACK_V_ALIGN_CENTER:
|
||||
return node->y + (node->h - child->measure_h) * 0.5f;
|
||||
case UI2_STACK_V_ALIGN_BOTTOM:
|
||||
case UI_STACK_V_ALIGN_BOTTOM:
|
||||
return node->y + node->h - child->measure_h;
|
||||
case UI2_STACK_V_ALIGN_DISTRIBUTE:
|
||||
case UI_STACK_V_ALIGN_DISTRIBUTE:
|
||||
ASSERT_FAIL();
|
||||
}
|
||||
return 0.0f;
|
||||
}
|
||||
|
||||
static void M_Measure(UI2_NODE *const node)
|
||||
static void M_Measure(UI_NODE *const node)
|
||||
{
|
||||
node->measure_w = 0.0f;
|
||||
node->measure_h = 0.0f;
|
||||
UI2_NODE *child = node->first_child;
|
||||
UI_NODE *child = node->first_child;
|
||||
M_DATA *const data = node->data;
|
||||
while (child != nullptr) {
|
||||
if (data->settings.orientation == UI2_STACK_VERTICAL) {
|
||||
if (data->settings.orientation == UI_STACK_VERTICAL) {
|
||||
node->measure_w = MAX(node->measure_w, child->measure_w);
|
||||
node->measure_h += child->measure_h;
|
||||
if (child->next_sibling != nullptr) {
|
||||
|
@ -106,23 +102,23 @@ static void M_Measure(UI2_NODE *const node)
|
|||
}
|
||||
|
||||
static void M_Layout(
|
||||
UI2_NODE *const node, const float x, const float y, const float w,
|
||||
UI_NODE *const node, const float x, const float y, const float w,
|
||||
const float h)
|
||||
{
|
||||
UI2_LayoutBasic(node, x, y, w, h);
|
||||
UI_LayoutBasic(node, x, y, w, h);
|
||||
M_DATA *const data = node->data;
|
||||
|
||||
// Count children and compute the total size they occupy on the main axis
|
||||
// including the base spacing from the settings.
|
||||
int32_t child_count = 0;
|
||||
float total_child_main_size = 0.0f;
|
||||
UI2_NODE *child = node->first_child;
|
||||
UI_NODE *child = node->first_child;
|
||||
while (child != NULL) {
|
||||
switch (data->settings.orientation) {
|
||||
case UI2_STACK_HORIZONTAL:
|
||||
case UI_STACK_HORIZONTAL:
|
||||
total_child_main_size += child->measure_w;
|
||||
break;
|
||||
case UI2_STACK_VERTICAL:
|
||||
case UI_STACK_VERTICAL:
|
||||
total_child_main_size += child->measure_h;
|
||||
break;
|
||||
}
|
||||
|
@ -136,10 +132,10 @@ static void M_Layout(
|
|||
const int32_t gaps = (child_count > 1) ? (child_count - 1) : 0;
|
||||
float base_spacing = 0.0f;
|
||||
switch (data->settings.orientation) {
|
||||
case UI2_STACK_HORIZONTAL:
|
||||
case UI_STACK_HORIZONTAL:
|
||||
base_spacing = data->settings.spacing.h * gaps;
|
||||
break;
|
||||
case UI2_STACK_VERTICAL:
|
||||
case UI_STACK_VERTICAL:
|
||||
base_spacing = data->settings.spacing.v * gaps;
|
||||
break;
|
||||
}
|
||||
|
@ -152,10 +148,10 @@ static void M_Layout(
|
|||
float leftover = 0.0f;
|
||||
float extra_per_gap = 0.0f;
|
||||
switch (data->settings.orientation) {
|
||||
case UI2_STACK_HORIZONTAL:
|
||||
case UI_STACK_HORIZONTAL:
|
||||
leftover = w - needed_size;
|
||||
break;
|
||||
case UI2_STACK_VERTICAL:
|
||||
case UI_STACK_VERTICAL:
|
||||
leftover = h - needed_size;
|
||||
break;
|
||||
}
|
||||
|
@ -173,7 +169,7 @@ static void M_Layout(
|
|||
const float ch = M_CalcChildH(node, child);
|
||||
|
||||
switch (data->settings.orientation) {
|
||||
case UI2_STACK_HORIZONTAL:
|
||||
case UI_STACK_HORIZONTAL:
|
||||
// For horizontal: vertical alignment is determined by M_CalcStartY
|
||||
cy = M_CalcStartY(node, child);
|
||||
|
||||
|
@ -188,7 +184,7 @@ static void M_Layout(
|
|||
}
|
||||
break;
|
||||
|
||||
case UI2_STACK_VERTICAL:
|
||||
case UI_STACK_VERTICAL:
|
||||
cx = M_CalcStartX(node, child);
|
||||
|
||||
child->ops->layout(child, cx, cy, cw, ch);
|
||||
|
@ -204,9 +200,9 @@ static void M_Layout(
|
|||
}
|
||||
}
|
||||
|
||||
UI2_NODE *UI2_CreateStack(const UI2_STACK_SETTINGS settings)
|
||||
UI_NODE *UI_CreateStack(const UI_STACK_SETTINGS settings)
|
||||
{
|
||||
UI2_NODE *const node = UI2_AllocNode(&m_Ops, sizeof(M_DATA));
|
||||
UI_NODE *const node = UI_AllocNode(&m_Ops, sizeof(M_DATA));
|
||||
if (node == nullptr) {
|
||||
return nullptr;
|
||||
}
|
||||
|
@ -215,13 +211,13 @@ UI2_NODE *UI2_CreateStack(const UI2_STACK_SETTINGS settings)
|
|||
return node;
|
||||
}
|
||||
|
||||
void UI2_BeginStack(const UI2_STACK_ORIENTATION orientation)
|
||||
void UI_BeginStack(const UI_STACK_ORIENTATION orientation)
|
||||
{
|
||||
UI2_BeginStackEx((UI2_STACK_SETTINGS) {
|
||||
UI_BeginStackEx((UI_STACK_SETTINGS) {
|
||||
.orientation = orientation,
|
||||
.align = {
|
||||
.h = UI2_STACK_H_ALIGN_LEFT,
|
||||
.v = UI2_STACK_V_ALIGN_TOP,
|
||||
.h = UI_STACK_H_ALIGN_LEFT,
|
||||
.v = UI_STACK_V_ALIGN_TOP,
|
||||
},
|
||||
.spacing = {
|
||||
.h = 0.0f,
|
||||
|
@ -230,14 +226,14 @@ void UI2_BeginStack(const UI2_STACK_ORIENTATION orientation)
|
|||
});
|
||||
}
|
||||
|
||||
void UI2_BeginStackEx(const UI2_STACK_SETTINGS settings)
|
||||
void UI_BeginStackEx(const UI_STACK_SETTINGS settings)
|
||||
{
|
||||
UI2_NODE *const child = UI2_CreateStack(settings);
|
||||
UI2_AddChild(child);
|
||||
UI2_PushCurrent(child);
|
||||
UI_NODE *const child = UI_CreateStack(settings);
|
||||
UI_AddChild(child);
|
||||
UI_PushCurrent(child);
|
||||
}
|
||||
|
||||
void UI2_EndStack(void)
|
||||
void UI_EndStack(void)
|
||||
{
|
||||
UI2_PopCurrent();
|
||||
UI_PopCurrent();
|
||||
}
|
50
src/libtrx/game/ui/elements/window.c
Normal file
50
src/libtrx/game/ui/elements/window.c
Normal file
|
@ -0,0 +1,50 @@
|
|||
#include "game/ui/elements/window.h"
|
||||
|
||||
#include "game/ui/elements/anchor.h"
|
||||
#include "game/ui/elements/frame.h"
|
||||
#include "game/ui/elements/label.h"
|
||||
#include "game/ui/elements/modal.h"
|
||||
#include "game/ui/elements/pad.h"
|
||||
#include "game/ui/elements/stack.h"
|
||||
|
||||
void UI_BeginWindow(void)
|
||||
{
|
||||
const float outer_pad = 2.0f;
|
||||
const float title_spacing = 3.0f;
|
||||
UI_BeginFrame(UI_FRAME_DIALOG_BACKGROUND);
|
||||
UI_BeginPad(outer_pad, outer_pad);
|
||||
UI_BeginStackEx((UI_STACK_SETTINGS) {
|
||||
.orientation = UI_STACK_VERTICAL,
|
||||
.align = { .h = UI_STACK_H_ALIGN_SPAN },
|
||||
.spacing = { .v = title_spacing },
|
||||
});
|
||||
}
|
||||
|
||||
void UI_EndWindow(void)
|
||||
{
|
||||
UI_EndStack();
|
||||
UI_EndPad();
|
||||
UI_EndFrame();
|
||||
}
|
||||
|
||||
void UI_BeginWindowBody(void)
|
||||
{
|
||||
const float body_pad = 8.0f;
|
||||
UI_BeginPad(body_pad, body_pad);
|
||||
}
|
||||
|
||||
void UI_EndWindowBody(void)
|
||||
{
|
||||
UI_EndPad();
|
||||
}
|
||||
|
||||
void UI_WindowTitle(const char *const title)
|
||||
{
|
||||
UI_BeginFrame(UI_FRAME_DIALOG_HEADING);
|
||||
UI_BeginPad(10.0f, 2.0f);
|
||||
UI_BeginAnchor(0.5f, 0.5f);
|
||||
UI_Label(title);
|
||||
UI_EndAnchor();
|
||||
UI_EndPad();
|
||||
UI_EndFrame();
|
||||
}
|
|
@ -1,23 +1,23 @@
|
|||
#include "game/ui2/events.h"
|
||||
#include "game/ui/events.h"
|
||||
|
||||
#include "config/common.h"
|
||||
#include "debug.h"
|
||||
#include "game/ui2/common.h"
|
||||
#include "game/ui/common.h"
|
||||
|
||||
static EVENT_MANAGER *m_EventManager = nullptr;
|
||||
|
||||
void UI2_InitEvents(void)
|
||||
void UI_InitEvents(void)
|
||||
{
|
||||
m_EventManager = EventManager_Create();
|
||||
}
|
||||
|
||||
void UI2_ShutdownEvents(void)
|
||||
void UI_ShutdownEvents(void)
|
||||
{
|
||||
EventManager_Free(m_EventManager);
|
||||
m_EventManager = nullptr;
|
||||
}
|
||||
|
||||
int32_t UI2_Subscribe(
|
||||
int32_t UI_Subscribe(
|
||||
const char *const event_name, const void *const sender,
|
||||
const EVENT_LISTENER listener, void *const user_data)
|
||||
{
|
||||
|
@ -26,14 +26,14 @@ int32_t UI2_Subscribe(
|
|||
m_EventManager, event_name, sender, listener, user_data);
|
||||
}
|
||||
|
||||
void UI2_Unsubscribe(const int32_t listener_id)
|
||||
void UI_Unsubscribe(const int32_t listener_id)
|
||||
{
|
||||
if (m_EventManager != nullptr) {
|
||||
EventManager_Unsubscribe(m_EventManager, listener_id);
|
||||
}
|
||||
}
|
||||
|
||||
void UI2_FireEvent(const EVENT event)
|
||||
void UI_FireEvent(const EVENT event)
|
||||
{
|
||||
if (m_EventManager != nullptr) {
|
||||
EventManager_Fire(m_EventManager, &event);
|
|
@ -1,12 +1,12 @@
|
|||
#include "game/ui2/helpers.h"
|
||||
#include "game/ui/helpers.h"
|
||||
|
||||
#include "utils.h"
|
||||
|
||||
void UI2_MeasureWrapper(UI2_NODE *const node)
|
||||
void UI_MeasureWrapper(UI_NODE *const node)
|
||||
{
|
||||
node->measure_w = 0.0f;
|
||||
node->measure_h = 0.0f;
|
||||
const UI2_NODE *child = node->first_child;
|
||||
const UI_NODE *child = node->first_child;
|
||||
while (child != nullptr) {
|
||||
node->measure_w = MAX(node->measure_w, child->measure_w);
|
||||
node->measure_h = MAX(node->measure_h, child->measure_h);
|
||||
|
@ -14,8 +14,8 @@ void UI2_MeasureWrapper(UI2_NODE *const node)
|
|||
}
|
||||
}
|
||||
|
||||
void UI2_LayoutBasic(
|
||||
UI2_NODE *const node, const float x, const float y, const float w,
|
||||
void UI_LayoutBasic(
|
||||
UI_NODE *const node, const float x, const float y, const float w,
|
||||
const float h)
|
||||
{
|
||||
node->x = x;
|
||||
|
@ -24,12 +24,12 @@ void UI2_LayoutBasic(
|
|||
node->h = h;
|
||||
}
|
||||
|
||||
void UI2_LayoutWrapper(
|
||||
UI2_NODE *const node, const float x, const float y, const float w,
|
||||
void UI_LayoutWrapper(
|
||||
UI_NODE *const node, const float x, const float y, const float w,
|
||||
const float h)
|
||||
{
|
||||
UI2_LayoutBasic(node, x, y, w, h);
|
||||
UI2_NODE *child = node->first_child;
|
||||
UI_LayoutBasic(node, x, y, w, h);
|
||||
UI_NODE *child = node->first_child;
|
||||
while (child != nullptr) {
|
||||
if (child->ops->layout != nullptr) {
|
||||
child->ops->layout(child, x, y, w, h);
|
||||
|
@ -38,12 +38,12 @@ void UI2_LayoutWrapper(
|
|||
}
|
||||
}
|
||||
|
||||
void UI2_DrawWrapper(const UI2_NODE *const node)
|
||||
void UI_DrawWrapper(const UI_NODE *const node)
|
||||
{
|
||||
if (node->measure_w <= 0.0f || node->measure_h <= 0.0f) {
|
||||
return;
|
||||
}
|
||||
UI2_NODE *child = node->first_child;
|
||||
UI_NODE *child = node->first_child;
|
||||
while (child != nullptr) {
|
||||
if (child->ops->draw != nullptr) {
|
||||
child->ops->draw(child);
|
9
src/libtrx/game/ui/helpers.h
Normal file
9
src/libtrx/game/ui/helpers.h
Normal file
|
@ -0,0 +1,9 @@
|
|||
#pragma once
|
||||
|
||||
#include "game/ui/common.h"
|
||||
|
||||
// Repetitive widget ops strategies
|
||||
void UI_MeasureWrapper(UI_NODE *node);
|
||||
void UI_LayoutBasic(UI_NODE *node, float x, float y, float w, float h);
|
||||
void UI_LayoutWrapper(UI_NODE *node, float x, float y, float w, float h);
|
||||
void UI_DrawWrapper(const UI_NODE *node);
|
168
src/libtrx/game/ui/hud/console.c
Normal file
168
src/libtrx/game/ui/hud/console.c
Normal file
|
@ -0,0 +1,168 @@
|
|||
#include "game/ui/hud/console.h"
|
||||
|
||||
#include "game/console.h"
|
||||
#include "game/text.h"
|
||||
#include "game/ui/elements/modal.h"
|
||||
#include "game/ui/elements/pad.h"
|
||||
#include "game/ui/elements/prompt.h"
|
||||
#include "game/ui/elements/spacer.h"
|
||||
#include "game/ui/elements/stack.h"
|
||||
#include "game/ui/events.h"
|
||||
#include "game/ui/helpers.h"
|
||||
#include "game/ui/hud/console_logs.h"
|
||||
#include "utils.h"
|
||||
|
||||
static void M_Draw(const UI_NODE *node);
|
||||
|
||||
static const UI_WIDGET_OPS m_Ops = {
|
||||
.measure = UI_MeasureWrapper,
|
||||
.layout = UI_LayoutWrapper,
|
||||
.draw = M_Draw,
|
||||
};
|
||||
|
||||
static void M_MoveHistoryUp(UI_CONSOLE_STATE *s);
|
||||
static void M_MoveHistoryDown(UI_CONSOLE_STATE *s);
|
||||
static void M_HandleOpen(const EVENT *event, void *user_data);
|
||||
static void M_HandleClose(const EVENT *event, void *user_data);
|
||||
static void M_HandleCancel(const EVENT *event, void *user_data);
|
||||
static void M_HandleConfirm(const EVENT *event, void *user_data);
|
||||
|
||||
static void M_MoveHistoryUp(UI_CONSOLE_STATE *const s)
|
||||
{
|
||||
s->history_idx--;
|
||||
CLAMP(s->history_idx, 0, Console_History_GetLength());
|
||||
const char *const new_prompt = Console_History_Get(s->history_idx);
|
||||
UI_Prompt_ChangeText(&s->prompt, new_prompt == nullptr ? "" : new_prompt);
|
||||
}
|
||||
|
||||
static void M_MoveHistoryDown(UI_CONSOLE_STATE *const s)
|
||||
{
|
||||
s->history_idx++;
|
||||
CLAMP(s->history_idx, 0, Console_History_GetLength());
|
||||
const char *const new_prompt = Console_History_Get(s->history_idx);
|
||||
UI_Prompt_ChangeText(&s->prompt, new_prompt == nullptr ? "" : new_prompt);
|
||||
}
|
||||
|
||||
static void M_HandleKeyDown(const EVENT *const event, void *const user_data)
|
||||
{
|
||||
if (!Console_IsOpened()) {
|
||||
return;
|
||||
}
|
||||
|
||||
UI_CONSOLE_STATE *const s = user_data;
|
||||
const UI_INPUT key = (UI_INPUT)(uintptr_t)event->data;
|
||||
|
||||
// clang-format off
|
||||
switch (key) {
|
||||
case UI_KEY_UP: M_MoveHistoryUp(s); break;
|
||||
case UI_KEY_DOWN: M_MoveHistoryDown(s); break;
|
||||
default: break;
|
||||
}
|
||||
// clang-format on
|
||||
}
|
||||
|
||||
static void M_HandleOpen(const EVENT *event, void *user_data)
|
||||
{
|
||||
UI_CONSOLE_STATE *const s = user_data;
|
||||
UI_Prompt_SetFocus(&s->prompt, true);
|
||||
s->history_idx = Console_History_GetLength();
|
||||
}
|
||||
|
||||
static void M_HandleClose(const EVENT *event, void *user_data)
|
||||
{
|
||||
UI_CONSOLE_STATE *const s = user_data;
|
||||
UI_Prompt_SetFocus(&s->prompt, false);
|
||||
UI_Prompt_Clear(&s->prompt);
|
||||
}
|
||||
|
||||
static void M_HandleCancel(const EVENT *const event, void *const data)
|
||||
{
|
||||
Console_Close();
|
||||
}
|
||||
|
||||
static void M_HandleConfirm(const EVENT *event, void *user_data)
|
||||
{
|
||||
UI_CONSOLE_STATE *const s = user_data;
|
||||
const char *text = event->data;
|
||||
Console_History_Append(text);
|
||||
Console_Eval(text);
|
||||
Console_Close();
|
||||
s->history_idx = Console_History_GetLength();
|
||||
}
|
||||
|
||||
static void M_Draw(const UI_NODE *node)
|
||||
{
|
||||
UI_CONSOLE_STATE *const s = *(UI_CONSOLE_STATE **)node->data;
|
||||
UI_DrawWrapper(node);
|
||||
if (Console_IsOpened() || s->logs.vis_lines > 0) {
|
||||
Console_DrawBackdrop();
|
||||
}
|
||||
}
|
||||
|
||||
void UI_Console_Init(UI_CONSOLE_STATE *const s)
|
||||
{
|
||||
UI_Prompt_Init(&s->prompt);
|
||||
UI_ConsoleLogs_Init(&s->logs);
|
||||
|
||||
struct {
|
||||
const char *event_name;
|
||||
const void *sender;
|
||||
EVENT_LISTENER handler;
|
||||
} listeners[] = {
|
||||
{ "console_open", nullptr, M_HandleOpen },
|
||||
{ "console_close", nullptr, M_HandleClose },
|
||||
{ "cancel", &s->prompt, M_HandleCancel },
|
||||
{ "confirm", &s->prompt, M_HandleConfirm },
|
||||
{ "key_down", nullptr, M_HandleKeyDown },
|
||||
{ 0 },
|
||||
};
|
||||
for (int32_t i = 0; listeners[i].event_name != nullptr; i++) {
|
||||
s->listeners[i] = UI_Subscribe(
|
||||
listeners[i].event_name, listeners[i].sender, listeners[i].handler,
|
||||
s);
|
||||
}
|
||||
|
||||
s->history_idx = -1;
|
||||
}
|
||||
|
||||
void UI_Console_Free(UI_CONSOLE_STATE *const s)
|
||||
{
|
||||
UI_ConsoleLogs_Free(&s->logs);
|
||||
UI_Prompt_Free(&s->prompt);
|
||||
for (int32_t i = 0; i < 5; i++) {
|
||||
UI_Unsubscribe(s->listeners[i]);
|
||||
}
|
||||
}
|
||||
|
||||
void UI_Console_Control(UI_CONSOLE_STATE *const s)
|
||||
{
|
||||
UI_Prompt_Control(&s->prompt);
|
||||
}
|
||||
|
||||
void UI_Console(UI_CONSOLE_STATE *const s)
|
||||
{
|
||||
UI_Prompt_SetFocus(&s->prompt, Console_IsOpened());
|
||||
|
||||
UI_NODE *const node = UI_AllocNode(&m_Ops, sizeof(UI_CONSOLE_STATE *));
|
||||
*(UI_CONSOLE_STATE **)node->data = s;
|
||||
UI_AddChild(node);
|
||||
UI_PushCurrent(node);
|
||||
|
||||
UI_BeginModal(0.0f, 1.0f);
|
||||
UI_BeginPad(5.0f, 5.0f);
|
||||
UI_BeginStack(UI_STACK_VERTICAL);
|
||||
|
||||
UI_ConsoleLogs(&s->logs);
|
||||
UI_Spacer(0.0f, 8.0f);
|
||||
if (Console_IsOpened()) {
|
||||
UI_Prompt(&s->prompt);
|
||||
} else {
|
||||
UI_Spacer(0.0f, TEXT_HEIGHT_FIXED);
|
||||
}
|
||||
|
||||
UI_EndStack();
|
||||
UI_EndModal();
|
||||
UI_EndPad();
|
||||
|
||||
UI_PopCurrent();
|
||||
}
|
|
@ -1,11 +1,11 @@
|
|||
#include "game/ui2/hud/console_logs.h"
|
||||
#include "game/ui/hud/console_logs.h"
|
||||
|
||||
#include "debug.h"
|
||||
#include "game/clock.h"
|
||||
#include "game/text.h"
|
||||
#include "game/ui2/elements/label.h"
|
||||
#include "game/ui2/elements/stack.h"
|
||||
#include "game/ui2/events.h"
|
||||
#include "game/ui/elements/label.h"
|
||||
#include "game/ui/elements/stack.h"
|
||||
#include "game/ui/events.h"
|
||||
#include "memory.h"
|
||||
#include "strings.h"
|
||||
|
||||
|
@ -15,11 +15,11 @@
|
|||
#define M_MAX_LOG_LINES 20
|
||||
#define M_DELAY_PER_CHAR 0.2
|
||||
|
||||
static void M_ScrollLogs(UI2_CONSOLE_LOGS *s);
|
||||
static void M_UpdateLogCount(UI2_CONSOLE_LOGS *s);
|
||||
static void M_ScrollLogs(UI_CONSOLE_LOGS *s);
|
||||
static void M_UpdateLogCount(UI_CONSOLE_LOGS *s);
|
||||
static void M_HandleLog(const EVENT *event, void *user_data);
|
||||
|
||||
static void M_ScrollLogs(UI2_CONSOLE_LOGS *const s)
|
||||
static void M_ScrollLogs(UI_CONSOLE_LOGS *const s)
|
||||
{
|
||||
int32_t i = s->max_lines - 1;
|
||||
while (i >= 0 && !s->logs[i].expire_at) {
|
||||
|
@ -39,7 +39,7 @@ static void M_ScrollLogs(UI2_CONSOLE_LOGS *const s)
|
|||
M_UpdateLogCount(s);
|
||||
}
|
||||
}
|
||||
static void M_UpdateLogCount(UI2_CONSOLE_LOGS *const s)
|
||||
static void M_UpdateLogCount(UI_CONSOLE_LOGS *const s)
|
||||
{
|
||||
s->vis_lines = 0;
|
||||
for (int32_t i = s->max_lines - 1; i >= 0; i--) {
|
||||
|
@ -53,7 +53,7 @@ static void M_UpdateLogCount(UI2_CONSOLE_LOGS *const s)
|
|||
static void M_HandleLog(const EVENT *const event, void *const user_data)
|
||||
{
|
||||
const char *text = event->data;
|
||||
UI2_CONSOLE_LOGS *const s = user_data;
|
||||
UI_CONSOLE_LOGS *const s = user_data;
|
||||
Memory_FreePointer(&s->logs[s->max_lines - 1].text);
|
||||
for (int32_t i = s->max_lines - 1; i > 0; i--) {
|
||||
s->logs[i] = s->logs[i - 1];
|
||||
|
@ -65,36 +65,36 @@ static void M_HandleLog(const EVENT *const event, void *const user_data)
|
|||
M_UpdateLogCount(s);
|
||||
}
|
||||
|
||||
void UI2_ConsoleLogs_Init(UI2_CONSOLE_LOGS *const s)
|
||||
void UI_ConsoleLogs_Init(UI_CONSOLE_LOGS *const s)
|
||||
{
|
||||
if (s->max_lines <= 0) {
|
||||
s->max_lines = M_MAX_LOG_LINES;
|
||||
}
|
||||
s->logs = Memory_Alloc(s->max_lines * sizeof(UI2_CONSOLE_LOG_LINE));
|
||||
s->logs = Memory_Alloc(s->max_lines * sizeof(UI_CONSOLE_LOG_LINE));
|
||||
s->vis_lines = 0;
|
||||
s->listener_id = UI2_Subscribe("console_log", nullptr, M_HandleLog, s);
|
||||
s->listener_id = UI_Subscribe("console_log", nullptr, M_HandleLog, s);
|
||||
}
|
||||
|
||||
void UI2_ConsoleLogs_Free(UI2_CONSOLE_LOGS *const s)
|
||||
void UI_ConsoleLogs_Free(UI_CONSOLE_LOGS *const s)
|
||||
{
|
||||
Memory_FreePointer(&s->logs);
|
||||
UI2_Unsubscribe(s->listener_id);
|
||||
UI_Unsubscribe(s->listener_id);
|
||||
}
|
||||
|
||||
void UI2_ConsoleLogs(UI2_CONSOLE_LOGS *const s)
|
||||
void UI_ConsoleLogs(UI_CONSOLE_LOGS *const s)
|
||||
{
|
||||
ASSERT(s != nullptr);
|
||||
M_ScrollLogs(s);
|
||||
UI2_BeginStackEx((UI2_STACK_SETTINGS) {
|
||||
.orientation = UI2_STACK_VERTICAL,
|
||||
UI_BeginStackEx((UI_STACK_SETTINGS) {
|
||||
.orientation = UI_STACK_VERTICAL,
|
||||
.align = {
|
||||
.h = UI2_STACK_H_ALIGN_LEFT,
|
||||
.v = UI2_STACK_V_ALIGN_CENTER,
|
||||
.h = UI_STACK_H_ALIGN_LEFT,
|
||||
.v = UI_STACK_V_ALIGN_CENTER,
|
||||
},
|
||||
});
|
||||
for (int32_t i = s->vis_lines - 1; i >= 0; i--) {
|
||||
UI2_LabelEx(
|
||||
s->logs[i].text, (UI2_LABEL_SETTINGS) { .scale = M_LOG_SCALE });
|
||||
UI_LabelEx(
|
||||
s->logs[i].text, (UI_LABEL_SETTINGS) { .scale = M_LOG_SCALE });
|
||||
}
|
||||
UI2_EndStack();
|
||||
UI_EndStack();
|
||||
}
|
|
@ -1,57 +0,0 @@
|
|||
#include "game/ui2/dialogs/controls_backend.h"
|
||||
|
||||
#include "game/game_string.h"
|
||||
#include "game/input.h"
|
||||
#include "game/ui2/elements/anchor.h"
|
||||
#include "game/ui2/elements/label.h"
|
||||
#include "game/ui2/elements/modal.h"
|
||||
#include "game/ui2/elements/requester.h"
|
||||
|
||||
static const GAME_STRING_ID m_Options[] = {
|
||||
GS_ID(CONTROLS_BACKEND_KEYBOARD),
|
||||
GS_ID(CONTROLS_BACKEND_CONTROLLER),
|
||||
nullptr,
|
||||
};
|
||||
|
||||
void UI2_ControlsBackend_Init(UI2_CONTROLS_BACKEND_STATE *const s)
|
||||
{
|
||||
int32_t count = 0;
|
||||
for (count = 0; m_Options[count] != nullptr; count++) { }
|
||||
UI2_Requester_Init(&s->req, count, count, true);
|
||||
}
|
||||
|
||||
void UI2_ControlsBackend_Free(UI2_CONTROLS_BACKEND_STATE *const s)
|
||||
{
|
||||
UI2_Requester_Free(&s->req);
|
||||
}
|
||||
|
||||
int32_t UI2_ControlsBackend_Control(UI2_CONTROLS_BACKEND_STATE *const s)
|
||||
{
|
||||
const int32_t choice = UI2_Requester_Control(&s->req);
|
||||
switch (choice) {
|
||||
case 0:
|
||||
return INPUT_BACKEND_KEYBOARD;
|
||||
case 1:
|
||||
return INPUT_BACKEND_CONTROLLER;
|
||||
default:
|
||||
return choice;
|
||||
}
|
||||
}
|
||||
|
||||
void UI2_ControlsBackend(UI2_CONTROLS_BACKEND_STATE *const s)
|
||||
{
|
||||
UI2_BeginModal(0.5f, 2.0f / 3.0f);
|
||||
UI2_BeginRequester(&s->req, GS(CONTROLS_CUSTOMIZE));
|
||||
|
||||
for (int32_t i = UI2_Requester_GetFirstRow(&s->req);
|
||||
i < UI2_Requester_GetLastRow(&s->req); i++) {
|
||||
UI2_BeginRequesterRow(&s->req, i);
|
||||
UI2_BeginAnchor(0.5f, 0.5f);
|
||||
UI2_Label(GameString_Get(m_Options[i]));
|
||||
UI2_EndAnchor();
|
||||
UI2_EndRequesterRow(&s->req, i);
|
||||
}
|
||||
|
||||
UI2_EndRequester(&s->req);
|
||||
UI2_EndModal();
|
||||
}
|
|
@ -1,55 +0,0 @@
|
|||
#include "game/ui2/dialogs/new_game.h"
|
||||
|
||||
#include "game/game_string.h"
|
||||
#include "game/ui2/elements/anchor.h"
|
||||
#include "game/ui2/elements/frame.h"
|
||||
#include "game/ui2/elements/label.h"
|
||||
#include "game/ui2/elements/modal.h"
|
||||
#include "game/ui2/elements/pad.h"
|
||||
#include "game/ui2/elements/requester.h"
|
||||
|
||||
static const GAME_STRING_ID m_Options[] = {
|
||||
GS_ID(PASSPORT_MODE_NEW_GAME),
|
||||
GS_ID(PASSPORT_MODE_NEW_GAME_PLUS),
|
||||
GS_ID(PASSPORT_MODE_NEW_GAME_JP),
|
||||
GS_ID(PASSPORT_MODE_NEW_GAME_JP_PLUS),
|
||||
nullptr,
|
||||
};
|
||||
|
||||
void UI2_NewGame_Init(UI2_NEW_GAME_STATE *const s)
|
||||
{
|
||||
int32_t option_count = 0;
|
||||
for (int32_t i = 0; m_Options[i] != nullptr; i++) {
|
||||
option_count++;
|
||||
}
|
||||
|
||||
UI2_Requester_Init(&s->req, option_count, option_count, true);
|
||||
}
|
||||
|
||||
void UI2_NewGame_Free(UI2_NEW_GAME_STATE *const s)
|
||||
{
|
||||
UI2_Requester_Free(&s->req);
|
||||
}
|
||||
|
||||
int32_t UI2_NewGame_Control(UI2_NEW_GAME_STATE *const s)
|
||||
{
|
||||
return UI2_Requester_Control(&s->req);
|
||||
}
|
||||
|
||||
void UI2_NewGame(UI2_NEW_GAME_STATE *const s)
|
||||
{
|
||||
UI2_BeginModal(0.5f, 2.0f / 3.0f);
|
||||
UI2_BeginRequester(&s->req, GS(PASSPORT_SELECT_MODE));
|
||||
|
||||
for (int32_t i = UI2_Requester_GetFirstRow(&s->req);
|
||||
i < UI2_Requester_GetLastRow(&s->req); i++) {
|
||||
UI2_BeginRequesterRow(&s->req, i);
|
||||
UI2_BeginAnchor(0.5f, 0.5f);
|
||||
UI2_Label(GameString_Get(m_Options[i]));
|
||||
UI2_EndAnchor();
|
||||
UI2_EndRequesterRow(&s->req, i);
|
||||
}
|
||||
|
||||
UI2_EndRequester(&s->req);
|
||||
UI2_EndModal();
|
||||
}
|
|
@ -1,72 +0,0 @@
|
|||
#include "game/ui2/dialogs/pause.h"
|
||||
|
||||
#include "game/game_string.h"
|
||||
#include "game/ui2/elements/anchor.h"
|
||||
#include "game/ui2/elements/frame.h"
|
||||
#include "game/ui2/elements/label.h"
|
||||
#include "game/ui2/elements/modal.h"
|
||||
#include "game/ui2/elements/pad.h"
|
||||
#include "game/ui2/elements/requester.h"
|
||||
|
||||
static const GAME_STRING_ID m_Options[2][2] = {
|
||||
{ GS_ID(PAUSE_CONTINUE), GS_ID(PAUSE_QUIT) },
|
||||
{ GS_ID(PAUSE_YES), GS_ID(PAUSE_NO) },
|
||||
};
|
||||
|
||||
void UI2_Pause_Init(UI2_PAUSE_STATE *const s)
|
||||
{
|
||||
s->phase = 0;
|
||||
UI2_Requester_Init(&s->req, 2, 2, true);
|
||||
}
|
||||
|
||||
void UI2_Pause_Free(UI2_PAUSE_STATE *const s)
|
||||
{
|
||||
UI2_Requester_Free(&s->req);
|
||||
}
|
||||
|
||||
UI2_PAUSE_EXIT_CHOICE UI2_Pause_Control(UI2_PAUSE_STATE *const s)
|
||||
{
|
||||
const int32_t choice = UI2_Requester_Control(&s->req);
|
||||
if (s->phase == 0) {
|
||||
if (choice == UI2_REQUESTER_CANCEL) {
|
||||
return UI2_PAUSE_RESUME_PAUSE;
|
||||
} else if (choice == 0) {
|
||||
return UI2_PAUSE_EXIT_TO_GAME;
|
||||
} else if (choice == 1) {
|
||||
s->phase = 1;
|
||||
UI2_Requester_Free(&s->req);
|
||||
UI2_Requester_Init(&s->req, 2, 2, true);
|
||||
}
|
||||
} else {
|
||||
if (choice == UI2_REQUESTER_CANCEL) {
|
||||
s->phase = 0;
|
||||
} else if (choice == 0) {
|
||||
return UI2_PAUSE_EXIT_TO_TITLE;
|
||||
} else if (choice == 1) {
|
||||
return UI2_PAUSE_EXIT_TO_GAME;
|
||||
}
|
||||
}
|
||||
return UI2_PAUSE_NOOP;
|
||||
}
|
||||
|
||||
void UI2_Pause(UI2_PAUSE_STATE *const s)
|
||||
{
|
||||
UI2_BeginModal(0.5f, 1.0f);
|
||||
UI2_BeginPad(50.0f, 50.0f);
|
||||
UI2_BeginRequester(
|
||||
&s->req,
|
||||
s->phase == 0 ? GS(PAUSE_EXIT_TO_TITLE) : GS(PAUSE_ARE_YOU_SURE));
|
||||
|
||||
for (int32_t i = UI2_Requester_GetFirstRow(&s->req);
|
||||
i < UI2_Requester_GetLastRow(&s->req); i++) {
|
||||
UI2_BeginRequesterRow(&s->req, i);
|
||||
UI2_BeginAnchor(0.5f, 0.5f);
|
||||
UI2_Label(GameString_Get(m_Options[s->phase][i]));
|
||||
UI2_EndAnchor();
|
||||
UI2_EndRequesterRow(&s->req, i);
|
||||
}
|
||||
|
||||
UI2_EndRequester(&s->req);
|
||||
UI2_EndPad();
|
||||
UI2_EndModal();
|
||||
}
|
|
@ -1,18 +0,0 @@
|
|||
#include "game/ui2/dialogs/stats.h"
|
||||
|
||||
void UI2_StatsDialog_Init(
|
||||
UI2_STATS_DIALOG_STATE *const s, const UI2_STATS_DIALOG_ARGS args)
|
||||
{
|
||||
UI2_Requester_Init(&s->assault_req, 7, 10, false);
|
||||
s->args = args;
|
||||
}
|
||||
|
||||
void UI2_StatsDialog_Free(UI2_STATS_DIALOG_STATE *const s)
|
||||
{
|
||||
UI2_Requester_Free(&s->assault_req);
|
||||
}
|
||||
|
||||
int32_t UI2_StatsDialog_Control(UI2_STATS_DIALOG_STATE *const s)
|
||||
{
|
||||
return UI2_Requester_Control(&s->assault_req);
|
||||
}
|
|
@ -1,56 +0,0 @@
|
|||
#include "game/ui2/elements/anchor.h"
|
||||
|
||||
#include "game/text.h"
|
||||
#include "game/ui2/helpers.h"
|
||||
|
||||
typedef struct {
|
||||
float x;
|
||||
float y;
|
||||
} M_DATA;
|
||||
|
||||
static void M_Measure(UI2_NODE *node);
|
||||
static void M_Layout(UI2_NODE *node, float x, float y, float w, float h);
|
||||
|
||||
static const UI2_WIDGET_OPS m_Ops = {
|
||||
.measure = UI2_MeasureWrapper,
|
||||
.layout = M_Layout,
|
||||
.draw = UI2_DrawWrapper,
|
||||
};
|
||||
|
||||
static void M_Measure(UI2_NODE *const node)
|
||||
{
|
||||
node->measure_w = UI2_GetCanvasWidth();
|
||||
node->measure_h = UI2_GetCanvasHeight() - TEXT_HEIGHT_FIXED;
|
||||
}
|
||||
|
||||
static void M_Layout(
|
||||
UI2_NODE *const node, const float x, const float y, const float w,
|
||||
const float h)
|
||||
{
|
||||
UI2_LayoutBasic(node, x, y, w, h);
|
||||
const M_DATA *const data = node->data;
|
||||
UI2_NODE *child = node->first_child;
|
||||
while (child != nullptr) {
|
||||
const float cw = child->measure_w;
|
||||
const float ch = child->measure_h;
|
||||
const float cx = x + (w - cw) * data->x;
|
||||
const float cy = y + (h - ch) * data->y;
|
||||
child->ops->layout(child, cx, cy, cw, ch);
|
||||
child = child->next_sibling;
|
||||
}
|
||||
}
|
||||
|
||||
void UI2_BeginAnchor(const float x, const float y)
|
||||
{
|
||||
UI2_NODE *const node = UI2_AllocNode(&m_Ops, sizeof(M_DATA));
|
||||
M_DATA *const data = node->data;
|
||||
data->x = x;
|
||||
data->y = y;
|
||||
UI2_AddChild(node);
|
||||
UI2_PushCurrent(node);
|
||||
}
|
||||
|
||||
void UI2_EndAnchor(void)
|
||||
{
|
||||
UI2_PopCurrent();
|
||||
}
|
|
@ -1,45 +0,0 @@
|
|||
#include "game/ui2/elements/fade.h"
|
||||
|
||||
#include "game/output.h"
|
||||
#include "game/ui2/helpers.h"
|
||||
|
||||
typedef struct {
|
||||
FADER *fader;
|
||||
bool is_on_top;
|
||||
} M_DATA;
|
||||
|
||||
static void M_Draw(const UI2_NODE *node);
|
||||
|
||||
static const UI2_WIDGET_OPS m_Ops = {
|
||||
.measure = UI2_MeasureWrapper,
|
||||
.layout = UI2_LayoutWrapper,
|
||||
.draw = M_Draw,
|
||||
};
|
||||
|
||||
static void M_Draw(const UI2_NODE *const node)
|
||||
{
|
||||
const M_DATA *const data = node->data;
|
||||
if (data->is_on_top) {
|
||||
UI2_DrawWrapper(node);
|
||||
Output_DrawPolyList(); // flush geometry
|
||||
Fader_Draw(data->fader);
|
||||
} else {
|
||||
Fader_Draw(data->fader);
|
||||
UI2_DrawWrapper(node);
|
||||
}
|
||||
}
|
||||
|
||||
void UI2_BeginFade(FADER *const fader, bool is_on_top)
|
||||
{
|
||||
UI2_NODE *const node = UI2_AllocNode(&m_Ops, sizeof(M_DATA *));
|
||||
M_DATA *const data = node->data;
|
||||
data->fader = fader;
|
||||
data->is_on_top = is_on_top;
|
||||
UI2_AddChild(node);
|
||||
UI2_PushCurrent(node);
|
||||
}
|
||||
|
||||
void UI2_EndFade(void)
|
||||
{
|
||||
UI2_PopCurrent();
|
||||
}
|
|
@ -1,51 +0,0 @@
|
|||
#include "game/ui2/elements/flash.h"
|
||||
|
||||
#include "game/ui2/elements/hide.h"
|
||||
#include "game/ui2/helpers.h"
|
||||
|
||||
static void M_Draw(const UI2_NODE *node);
|
||||
|
||||
static const UI2_WIDGET_OPS m_Ops = {
|
||||
.measure = UI2_MeasureWrapper,
|
||||
.layout = UI2_LayoutWrapper,
|
||||
.draw = M_Draw,
|
||||
};
|
||||
|
||||
static void M_Draw(const UI2_NODE *const node)
|
||||
{
|
||||
UI2_FLASH_STATE *const s = *(UI2_FLASH_STATE **)node->data;
|
||||
UI2_BeginHide(s->count >= 0);
|
||||
UI2_DrawWrapper(node);
|
||||
UI2_EndHide();
|
||||
}
|
||||
|
||||
void UI2_Flash_Init(UI2_FLASH_STATE *const s, const int32_t rate)
|
||||
{
|
||||
s->count = 0;
|
||||
s->rate = rate;
|
||||
}
|
||||
|
||||
void UI2_Flash_Free(UI2_FLASH_STATE *const s)
|
||||
{
|
||||
}
|
||||
|
||||
void UI2_Flash_Control(UI2_FLASH_STATE *const s)
|
||||
{
|
||||
s->count -= 2;
|
||||
if (s->count < -s->rate) {
|
||||
s->count = s->rate;
|
||||
}
|
||||
}
|
||||
|
||||
void UI2_BeginFlash(UI2_FLASH_STATE *const s)
|
||||
{
|
||||
UI2_NODE *const node = UI2_AllocNode(&m_Ops, sizeof(UI2_FLASH_STATE *));
|
||||
*(UI2_FLASH_STATE **)node->data = s;
|
||||
UI2_AddChild(node);
|
||||
UI2_PushCurrent(node);
|
||||
}
|
||||
|
||||
void UI2_EndFlash(void)
|
||||
{
|
||||
UI2_PopCurrent();
|
||||
}
|
|
@ -1,32 +0,0 @@
|
|||
#include "game/ui2/elements/hide.h"
|
||||
|
||||
#include "game/ui2/helpers.h"
|
||||
|
||||
static void M_Draw(const UI2_NODE *node);
|
||||
|
||||
static const UI2_WIDGET_OPS m_Ops = {
|
||||
.measure = UI2_MeasureWrapper,
|
||||
.layout = UI2_LayoutWrapper,
|
||||
.draw = M_Draw,
|
||||
};
|
||||
|
||||
static void M_Draw(const UI2_NODE *const node)
|
||||
{
|
||||
const bool draw_children = *(bool *)node->data;
|
||||
if (draw_children) {
|
||||
UI2_DrawWrapper(node);
|
||||
}
|
||||
}
|
||||
|
||||
void UI2_BeginHide(const bool hide_children)
|
||||
{
|
||||
UI2_NODE *const node = UI2_AllocNode(&m_Ops, sizeof(bool));
|
||||
*(bool *)node->data = !hide_children;
|
||||
UI2_AddChild(node);
|
||||
UI2_PushCurrent(node);
|
||||
}
|
||||
|
||||
void UI2_EndHide(void)
|
||||
{
|
||||
UI2_PopCurrent();
|
||||
}
|
|
@ -1,33 +0,0 @@
|
|||
#include "game/ui2/elements/modal.h"
|
||||
|
||||
#include "game/text.h"
|
||||
#include "game/ui2/elements/anchor.h"
|
||||
#include "game/ui2/helpers.h"
|
||||
|
||||
static void M_Measure(UI2_NODE *node);
|
||||
|
||||
static const UI2_WIDGET_OPS m_Ops = {
|
||||
.measure = M_Measure,
|
||||
.layout = UI2_LayoutWrapper,
|
||||
.draw = UI2_DrawWrapper,
|
||||
};
|
||||
|
||||
static void M_Measure(UI2_NODE *const node)
|
||||
{
|
||||
node->measure_w = UI2_GetCanvasWidth();
|
||||
node->measure_h = UI2_GetCanvasHeight() - TEXT_HEIGHT_FIXED;
|
||||
}
|
||||
|
||||
void UI2_BeginModal(const float x, const float y)
|
||||
{
|
||||
UI2_NODE *const node = UI2_AllocNode(&m_Ops, 0);
|
||||
UI2_AddChild(node);
|
||||
UI2_PushCurrent(node);
|
||||
UI2_BeginAnchor(x, y);
|
||||
}
|
||||
|
||||
void UI2_EndModal(void)
|
||||
{
|
||||
UI2_EndAnchor();
|
||||
UI2_PopCurrent();
|
||||
}
|
|
@ -1,126 +0,0 @@
|
|||
#include "game/ui2/elements/requester.h"
|
||||
|
||||
#include "game/input.h"
|
||||
#include "game/ui2/elements/frame.h"
|
||||
#include "game/ui2/elements/pad.h"
|
||||
#include "game/ui2/elements/stack.h"
|
||||
#include "game/ui2/elements/window.h"
|
||||
#include "utils.h"
|
||||
|
||||
void UI2_Requester_Init(
|
||||
UI2_REQUESTER_STATE *const s, const int32_t vis_rows,
|
||||
const int32_t max_rows, const bool is_selectable)
|
||||
{
|
||||
s->vis_row = 0;
|
||||
s->sel_row = 0;
|
||||
s->vis_rows = vis_rows;
|
||||
s->max_rows = max_rows;
|
||||
s->is_selectable = is_selectable;
|
||||
s->row_pad = 20.0f;
|
||||
s->row_spacing = 3.0f;
|
||||
}
|
||||
|
||||
void UI2_Requester_Free(UI2_REQUESTER_STATE *const s)
|
||||
{
|
||||
}
|
||||
|
||||
int32_t UI2_Requester_Control(UI2_REQUESTER_STATE *const s)
|
||||
{
|
||||
if (g_InputDB.menu_down) {
|
||||
if (s->vis_row + s->vis_rows < s->max_rows) {
|
||||
s->vis_row++;
|
||||
}
|
||||
} else if (g_InputDB.menu_up) {
|
||||
if (s->vis_row > 0) {
|
||||
s->vis_row--;
|
||||
}
|
||||
}
|
||||
|
||||
if (s->is_selectable) {
|
||||
if (g_InputDB.menu_down && s->sel_row + 1 < s->max_rows) {
|
||||
s->sel_row++;
|
||||
} else if (g_InputDB.menu_up && s->sel_row > 0) {
|
||||
s->sel_row--;
|
||||
}
|
||||
if (g_InputDB.menu_back) {
|
||||
return UI2_REQUESTER_CANCEL;
|
||||
}
|
||||
if (g_InputDB.menu_confirm) {
|
||||
return s->sel_row;
|
||||
}
|
||||
}
|
||||
return UI2_REQUESTER_NO_CHOICE;
|
||||
}
|
||||
|
||||
void UI2_Requester_SetMaxRows(
|
||||
UI2_REQUESTER_STATE *const s, const int32_t max_rows)
|
||||
{
|
||||
s->max_rows = max_rows;
|
||||
}
|
||||
|
||||
int32_t UI2_Requester_GetFirstRow(const UI2_REQUESTER_STATE *const s)
|
||||
{
|
||||
return s->vis_row;
|
||||
}
|
||||
|
||||
int32_t UI2_Requester_GetLastRow(const UI2_REQUESTER_STATE *const s)
|
||||
{
|
||||
return MIN(s->vis_row + s->vis_rows, s->max_rows);
|
||||
}
|
||||
|
||||
int32_t UI2_Requester_GetCurrentRow(const UI2_REQUESTER_STATE *s)
|
||||
{
|
||||
return s->sel_row;
|
||||
}
|
||||
|
||||
bool UI2_Requester_IsRowVisible(
|
||||
const UI2_REQUESTER_STATE *const s, const int32_t i)
|
||||
{
|
||||
return i >= UI2_Requester_GetFirstRow(s)
|
||||
&& i <= UI2_Requester_GetLastRow(s);
|
||||
}
|
||||
|
||||
bool UI2_Requester_IsRowSelected(
|
||||
const UI2_REQUESTER_STATE *const s, const int32_t i)
|
||||
{
|
||||
return i == s->sel_row;
|
||||
}
|
||||
|
||||
void UI2_BeginRequester(
|
||||
const UI2_REQUESTER_STATE *const s, const char *const title)
|
||||
{
|
||||
UI2_BeginWindow();
|
||||
UI2_WindowTitle(title);
|
||||
UI2_BeginWindowBody();
|
||||
|
||||
UI2_BeginStackEx((UI2_STACK_SETTINGS) {
|
||||
.orientation = UI2_STACK_VERTICAL,
|
||||
.align = { .h = UI2_STACK_H_ALIGN_SPAN },
|
||||
.spacing = { .v = s->row_spacing },
|
||||
});
|
||||
}
|
||||
|
||||
void UI2_EndRequester(const UI2_REQUESTER_STATE *const s)
|
||||
{
|
||||
UI2_EndStack();
|
||||
UI2_EndWindowBody();
|
||||
UI2_EndWindow();
|
||||
}
|
||||
|
||||
void UI2_BeginRequesterRow(const UI2_REQUESTER_STATE *const s, const int32_t i)
|
||||
{
|
||||
UI2_BeginPad(0.0f, TR_VERSION == 1 ? -1.0f : 0.0f);
|
||||
if (UI2_Requester_IsRowSelected(s, i)) {
|
||||
UI2_BeginFrame(UI2_FRAME_SELECTED_OPTION);
|
||||
}
|
||||
UI2_BeginPad(s->row_pad, TR_VERSION == 1 ? 1.0f : 0.0f);
|
||||
}
|
||||
|
||||
void UI2_EndRequesterRow(const UI2_REQUESTER_STATE *const s, const int32_t i)
|
||||
{
|
||||
UI2_EndPad();
|
||||
if (UI2_Requester_IsRowSelected(s, i)) {
|
||||
UI2_EndFrame();
|
||||
}
|
||||
UI2_EndPad();
|
||||
}
|
|
@ -1,44 +0,0 @@
|
|||
#include "game/ui2/elements/resize.h"
|
||||
|
||||
#include "config.h"
|
||||
#include "game/ui2/helpers.h"
|
||||
|
||||
typedef struct {
|
||||
float x;
|
||||
float y;
|
||||
} M_DATA;
|
||||
|
||||
static void M_Measure(UI2_NODE *node);
|
||||
|
||||
static const UI2_WIDGET_OPS m_Ops = {
|
||||
.measure = M_Measure,
|
||||
.layout = UI2_LayoutWrapper,
|
||||
.draw = UI2_DrawWrapper,
|
||||
};
|
||||
|
||||
static void M_Measure(UI2_NODE *const node)
|
||||
{
|
||||
UI2_MeasureWrapper(node);
|
||||
const M_DATA *const data = node->data;
|
||||
if (data->x >= 0.0f) {
|
||||
node->measure_w = data->x;
|
||||
}
|
||||
if (data->y >= 0.0f) {
|
||||
node->measure_h = data->y;
|
||||
}
|
||||
}
|
||||
|
||||
void UI2_BeginResize(const float x, const float y)
|
||||
{
|
||||
UI2_NODE *const node = UI2_AllocNode(&m_Ops, sizeof(M_DATA));
|
||||
M_DATA *const data = node->data;
|
||||
data->x = x * g_Config.ui.text_scale;
|
||||
data->y = y * g_Config.ui.text_scale;
|
||||
UI2_AddChild(node);
|
||||
UI2_PushCurrent(node);
|
||||
}
|
||||
|
||||
void UI2_EndResize(void)
|
||||
{
|
||||
UI2_PopCurrent();
|
||||
}
|
|
@ -1,25 +0,0 @@
|
|||
#include "game/ui2/elements/spacer.h"
|
||||
|
||||
#include "config.h"
|
||||
#include "game/ui2/helpers.h"
|
||||
|
||||
static void M_Measure(UI2_NODE *node);
|
||||
|
||||
static const UI2_WIDGET_OPS m_Ops = {
|
||||
.measure = M_Measure,
|
||||
.layout = UI2_LayoutBasic,
|
||||
.draw = UI2_DrawWrapper,
|
||||
};
|
||||
|
||||
static void M_Measure(UI2_NODE *const node)
|
||||
{
|
||||
// already done in the constructor
|
||||
}
|
||||
|
||||
void UI2_Spacer(const float w, const float h)
|
||||
{
|
||||
UI2_NODE *const node = UI2_AllocNode(&m_Ops, 0);
|
||||
node->measure_w = w * g_Config.ui.text_scale;
|
||||
node->measure_h = h * g_Config.ui.text_scale;
|
||||
UI2_AddChild(node);
|
||||
}
|
|
@ -1,50 +0,0 @@
|
|||
#include "game/ui2/elements/window.h"
|
||||
|
||||
#include "game/ui2/elements/anchor.h"
|
||||
#include "game/ui2/elements/frame.h"
|
||||
#include "game/ui2/elements/label.h"
|
||||
#include "game/ui2/elements/modal.h"
|
||||
#include "game/ui2/elements/pad.h"
|
||||
#include "game/ui2/elements/stack.h"
|
||||
|
||||
void UI2_BeginWindow(void)
|
||||
{
|
||||
const float outer_pad = 2.0f;
|
||||
const float title_spacing = 3.0f;
|
||||
UI2_BeginFrame(UI2_FRAME_DIALOG_BACKGROUND);
|
||||
UI2_BeginPad(outer_pad, outer_pad);
|
||||
UI2_BeginStackEx((UI2_STACK_SETTINGS) {
|
||||
.orientation = UI2_STACK_VERTICAL,
|
||||
.align = { .h = UI2_STACK_H_ALIGN_SPAN },
|
||||
.spacing = { .v = title_spacing },
|
||||
});
|
||||
}
|
||||
|
||||
void UI2_EndWindow(void)
|
||||
{
|
||||
UI2_EndStack();
|
||||
UI2_EndPad();
|
||||
UI2_EndFrame();
|
||||
}
|
||||
|
||||
void UI2_BeginWindowBody(void)
|
||||
{
|
||||
const float body_pad = 8.0f;
|
||||
UI2_BeginPad(body_pad, body_pad);
|
||||
}
|
||||
|
||||
void UI2_EndWindowBody(void)
|
||||
{
|
||||
UI2_EndPad();
|
||||
}
|
||||
|
||||
void UI2_WindowTitle(const char *const title)
|
||||
{
|
||||
UI2_BeginFrame(UI2_FRAME_DIALOG_HEADING);
|
||||
UI2_BeginPad(10.0f, 2.0f);
|
||||
UI2_BeginAnchor(0.5f, 0.5f);
|
||||
UI2_Label(title);
|
||||
UI2_EndAnchor();
|
||||
UI2_EndPad();
|
||||
UI2_EndFrame();
|
||||
}
|
|
@ -1,9 +0,0 @@
|
|||
#pragma once
|
||||
|
||||
#include "game/ui2/common.h"
|
||||
|
||||
// Repetitive widget ops strategies
|
||||
void UI2_MeasureWrapper(UI2_NODE *node);
|
||||
void UI2_LayoutBasic(UI2_NODE *node, float x, float y, float w, float h);
|
||||
void UI2_LayoutWrapper(UI2_NODE *node, float x, float y, float w, float h);
|
||||
void UI2_DrawWrapper(const UI2_NODE *node);
|
|
@ -1,168 +0,0 @@
|
|||
#include "game/ui2/hud/console.h"
|
||||
|
||||
#include "game/console.h"
|
||||
#include "game/text.h"
|
||||
#include "game/ui2/elements/modal.h"
|
||||
#include "game/ui2/elements/pad.h"
|
||||
#include "game/ui2/elements/prompt.h"
|
||||
#include "game/ui2/elements/spacer.h"
|
||||
#include "game/ui2/elements/stack.h"
|
||||
#include "game/ui2/events.h"
|
||||
#include "game/ui2/helpers.h"
|
||||
#include "game/ui2/hud/console_logs.h"
|
||||
#include "utils.h"
|
||||
|
||||
static void M_Draw(const UI2_NODE *node);
|
||||
|
||||
static const UI2_WIDGET_OPS m_Ops = {
|
||||
.measure = UI2_MeasureWrapper,
|
||||
.layout = UI2_LayoutWrapper,
|
||||
.draw = M_Draw,
|
||||
};
|
||||
|
||||
static void M_MoveHistoryUp(UI2_CONSOLE_STATE *s);
|
||||
static void M_MoveHistoryDown(UI2_CONSOLE_STATE *s);
|
||||
static void M_HandleOpen(const EVENT *event, void *user_data);
|
||||
static void M_HandleClose(const EVENT *event, void *user_data);
|
||||
static void M_HandleCancel(const EVENT *event, void *user_data);
|
||||
static void M_HandleConfirm(const EVENT *event, void *user_data);
|
||||
|
||||
static void M_MoveHistoryUp(UI2_CONSOLE_STATE *const s)
|
||||
{
|
||||
s->history_idx--;
|
||||
CLAMP(s->history_idx, 0, Console_History_GetLength());
|
||||
const char *const new_prompt = Console_History_Get(s->history_idx);
|
||||
UI2_Prompt_ChangeText(&s->prompt, new_prompt == nullptr ? "" : new_prompt);
|
||||
}
|
||||
|
||||
static void M_MoveHistoryDown(UI2_CONSOLE_STATE *const s)
|
||||
{
|
||||
s->history_idx++;
|
||||
CLAMP(s->history_idx, 0, Console_History_GetLength());
|
||||
const char *const new_prompt = Console_History_Get(s->history_idx);
|
||||
UI2_Prompt_ChangeText(&s->prompt, new_prompt == nullptr ? "" : new_prompt);
|
||||
}
|
||||
|
||||
static void M_HandleKeyDown(const EVENT *const event, void *const user_data)
|
||||
{
|
||||
if (!Console_IsOpened()) {
|
||||
return;
|
||||
}
|
||||
|
||||
UI2_CONSOLE_STATE *const s = user_data;
|
||||
const UI2_INPUT key = (UI2_INPUT)(uintptr_t)event->data;
|
||||
|
||||
// clang-format off
|
||||
switch (key) {
|
||||
case UI2_KEY_UP: M_MoveHistoryUp(s); break;
|
||||
case UI2_KEY_DOWN: M_MoveHistoryDown(s); break;
|
||||
default: break;
|
||||
}
|
||||
// clang-format on
|
||||
}
|
||||
|
||||
static void M_HandleOpen(const EVENT *event, void *user_data)
|
||||
{
|
||||
UI2_CONSOLE_STATE *const s = user_data;
|
||||
UI2_Prompt_SetFocus(&s->prompt, true);
|
||||
s->history_idx = Console_History_GetLength();
|
||||
}
|
||||
|
||||
static void M_HandleClose(const EVENT *event, void *user_data)
|
||||
{
|
||||
UI2_CONSOLE_STATE *const s = user_data;
|
||||
UI2_Prompt_SetFocus(&s->prompt, false);
|
||||
UI2_Prompt_Clear(&s->prompt);
|
||||
}
|
||||
|
||||
static void M_HandleCancel(const EVENT *const event, void *const data)
|
||||
{
|
||||
Console_Close();
|
||||
}
|
||||
|
||||
static void M_HandleConfirm(const EVENT *event, void *user_data)
|
||||
{
|
||||
UI2_CONSOLE_STATE *const s = user_data;
|
||||
const char *text = event->data;
|
||||
Console_History_Append(text);
|
||||
Console_Eval(text);
|
||||
Console_Close();
|
||||
s->history_idx = Console_History_GetLength();
|
||||
}
|
||||
|
||||
static void M_Draw(const UI2_NODE *node)
|
||||
{
|
||||
UI2_CONSOLE_STATE *const s = *(UI2_CONSOLE_STATE **)node->data;
|
||||
UI2_DrawWrapper(node);
|
||||
if (Console_IsOpened() || s->logs.vis_lines > 0) {
|
||||
Console_DrawBackdrop();
|
||||
}
|
||||
}
|
||||
|
||||
void UI2_Console_Init(UI2_CONSOLE_STATE *const s)
|
||||
{
|
||||
UI2_Prompt_Init(&s->prompt);
|
||||
UI2_ConsoleLogs_Init(&s->logs);
|
||||
|
||||
struct {
|
||||
const char *event_name;
|
||||
const void *sender;
|
||||
EVENT_LISTENER handler;
|
||||
} listeners[] = {
|
||||
{ "console_open", nullptr, M_HandleOpen },
|
||||
{ "console_close", nullptr, M_HandleClose },
|
||||
{ "cancel", &s->prompt, M_HandleCancel },
|
||||
{ "confirm", &s->prompt, M_HandleConfirm },
|
||||
{ "key_down", nullptr, M_HandleKeyDown },
|
||||
{ 0 },
|
||||
};
|
||||
for (int32_t i = 0; listeners[i].event_name != nullptr; i++) {
|
||||
s->listeners[i] = UI2_Subscribe(
|
||||
listeners[i].event_name, listeners[i].sender, listeners[i].handler,
|
||||
s);
|
||||
}
|
||||
|
||||
s->history_idx = -1;
|
||||
}
|
||||
|
||||
void UI2_Console_Free(UI2_CONSOLE_STATE *const s)
|
||||
{
|
||||
UI2_ConsoleLogs_Free(&s->logs);
|
||||
UI2_Prompt_Free(&s->prompt);
|
||||
for (int32_t i = 0; i < 5; i++) {
|
||||
UI2_Unsubscribe(s->listeners[i]);
|
||||
}
|
||||
}
|
||||
|
||||
void UI2_Console_Control(UI2_CONSOLE_STATE *const s)
|
||||
{
|
||||
UI2_Prompt_Control(&s->prompt);
|
||||
}
|
||||
|
||||
void UI2_Console(UI2_CONSOLE_STATE *const s)
|
||||
{
|
||||
UI2_Prompt_SetFocus(&s->prompt, Console_IsOpened());
|
||||
|
||||
UI2_NODE *const node = UI2_AllocNode(&m_Ops, sizeof(UI2_CONSOLE_STATE *));
|
||||
*(UI2_CONSOLE_STATE **)node->data = s;
|
||||
UI2_AddChild(node);
|
||||
UI2_PushCurrent(node);
|
||||
|
||||
UI2_BeginModal(0.0f, 1.0f);
|
||||
UI2_BeginPad(5.0f, 5.0f);
|
||||
UI2_BeginStack(UI2_STACK_VERTICAL);
|
||||
|
||||
UI2_ConsoleLogs(&s->logs);
|
||||
UI2_Spacer(0.0f, 8.0f);
|
||||
if (Console_IsOpened()) {
|
||||
UI2_Prompt(&s->prompt);
|
||||
} else {
|
||||
UI2_Spacer(0.0f, TEXT_HEIGHT_FIXED);
|
||||
}
|
||||
|
||||
UI2_EndStack();
|
||||
UI2_EndModal();
|
||||
UI2_EndPad();
|
||||
|
||||
UI2_PopCurrent();
|
||||
}
|
24
src/libtrx/include/libtrx/game/ui.h
Normal file
24
src/libtrx/include/libtrx/game/ui.h
Normal file
|
@ -0,0 +1,24 @@
|
|||
#pragma once
|
||||
|
||||
#include "./ui/common.h"
|
||||
#include "./ui/dialogs/controls.h"
|
||||
#include "./ui/dialogs/controls_backend.h"
|
||||
#include "./ui/dialogs/examine_item.h"
|
||||
#include "./ui/dialogs/new_game.h"
|
||||
#include "./ui/dialogs/pause.h"
|
||||
#include "./ui/dialogs/photo_mode.h"
|
||||
#include "./ui/dialogs/stats.h"
|
||||
#include "./ui/elements/anchor.h"
|
||||
#include "./ui/elements/fade.h"
|
||||
#include "./ui/elements/flash.h"
|
||||
#include "./ui/elements/frame.h"
|
||||
#include "./ui/elements/label.h"
|
||||
#include "./ui/elements/modal.h"
|
||||
#include "./ui/elements/pad.h"
|
||||
#include "./ui/elements/requester.h"
|
||||
#include "./ui/elements/resize.h"
|
||||
#include "./ui/elements/spacer.h"
|
||||
#include "./ui/elements/stack.h"
|
||||
#include "./ui/events.h"
|
||||
#include "./ui/hud/console.h"
|
||||
#include "./ui/hud/console_logs.h"
|
74
src/libtrx/include/libtrx/game/ui/common.h
Normal file
74
src/libtrx/include/libtrx/game/ui/common.h
Normal file
|
@ -0,0 +1,74 @@
|
|||
#pragma once
|
||||
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
|
||||
typedef enum {
|
||||
UI_KEY_UP,
|
||||
UI_KEY_DOWN,
|
||||
UI_KEY_LEFT,
|
||||
UI_KEY_RIGHT,
|
||||
UI_KEY_HOME,
|
||||
UI_KEY_END,
|
||||
UI_KEY_BACK,
|
||||
UI_KEY_RETURN,
|
||||
UI_KEY_ESCAPE,
|
||||
} UI_INPUT;
|
||||
|
||||
// Forward declaration of the node and its vtable.
|
||||
struct UI_NODE;
|
||||
typedef struct {
|
||||
void (*measure)(struct UI_NODE *node);
|
||||
void (*layout)(struct UI_NODE *node, float x, float y, float w, float h);
|
||||
void (*draw)(const struct UI_NODE *node);
|
||||
} UI_WIDGET_OPS;
|
||||
|
||||
// Node structure that forms the UI tree
|
||||
typedef struct UI_NODE {
|
||||
// Common operations on a widget
|
||||
const UI_WIDGET_OPS *ops;
|
||||
|
||||
// Final layout rectangle
|
||||
float x;
|
||||
float y;
|
||||
float w;
|
||||
float h;
|
||||
|
||||
// Needed size from measure pass
|
||||
float measure_w;
|
||||
float measure_h;
|
||||
|
||||
// Link to parent and siblings to form a tree
|
||||
struct UI_NODE *parent;
|
||||
struct UI_NODE *first_child;
|
||||
struct UI_NODE *last_child;
|
||||
struct UI_NODE *next_sibling;
|
||||
|
||||
// Widget-specific data
|
||||
void *data;
|
||||
} UI_NODE;
|
||||
|
||||
// Dimensions in virtual pixels of the screen area
|
||||
// (640x480 for any 4:3 resolution on 1.00 text scaling)
|
||||
extern int32_t UI_GetCanvasWidth(void);
|
||||
extern int32_t UI_GetCanvasHeight(void);
|
||||
extern float UI_ScaleX(float x);
|
||||
extern float UI_ScaleY(float y);
|
||||
|
||||
// Public API for scene management
|
||||
void UI_BeginScene(void);
|
||||
void UI_EndScene(void);
|
||||
|
||||
// Helpers to add children, etc.
|
||||
UI_NODE *UI_AllocNode(const UI_WIDGET_OPS *ops, size_t additional_size);
|
||||
void UI_AddChild(UI_NODE *child);
|
||||
void UI_PushCurrent(UI_NODE *child);
|
||||
void UI_PopCurrent(void);
|
||||
|
||||
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);
|
||||
void UI_HandleTextEdit(const char *text);
|
|
@ -14,14 +14,14 @@ typedef struct {
|
|||
int32_t active_layout;
|
||||
|
||||
EVENT_MANAGER *events;
|
||||
UI2_CONTROLS_BACKEND_STATE backend_state;
|
||||
UI2_CONTROLS_EDITOR_STATE editor_state;
|
||||
} UI2_CONTROLS_STATE;
|
||||
UI_CONTROLS_BACKEND_STATE backend_state;
|
||||
UI_CONTROLS_EDITOR_STATE editor_state;
|
||||
} UI_CONTROLS_STATE;
|
||||
|
||||
// state functions
|
||||
void UI2_Controls_Init(UI2_CONTROLS_STATE *s);
|
||||
void UI2_Controls_Free(UI2_CONTROLS_STATE *s);
|
||||
bool UI2_Controls_Control(UI2_CONTROLS_STATE *s);
|
||||
void UI_Controls_Init(UI_CONTROLS_STATE *s);
|
||||
void UI_Controls_Free(UI_CONTROLS_STATE *s);
|
||||
bool UI_Controls_Control(UI_CONTROLS_STATE *s);
|
||||
|
||||
// draw functions
|
||||
void UI2_Controls(UI2_CONTROLS_STATE *s);
|
||||
void UI_Controls(UI_CONTROLS_STATE *s);
|
18
src/libtrx/include/libtrx/game/ui/dialogs/controls_backend.h
Normal file
18
src/libtrx/include/libtrx/game/ui/dialogs/controls_backend.h
Normal file
|
@ -0,0 +1,18 @@
|
|||
#pragma once
|
||||
|
||||
// A control backend (keyboard/controller) choice dialog.
|
||||
|
||||
#include "../common.h"
|
||||
#include "../elements/requester.h"
|
||||
|
||||
typedef struct {
|
||||
UI_REQUESTER_STATE req;
|
||||
} UI_CONTROLS_BACKEND_STATE;
|
||||
|
||||
// state functions
|
||||
void UI_ControlsBackend_Init(UI_CONTROLS_BACKEND_STATE *s);
|
||||
void UI_ControlsBackend_Free(UI_CONTROLS_BACKEND_STATE *s);
|
||||
int32_t UI_ControlsBackend_Control(UI_CONTROLS_BACKEND_STATE *s);
|
||||
|
||||
// draw functions
|
||||
void UI_ControlsBackend(UI_CONTROLS_BACKEND_STATE *s);
|
36
src/libtrx/include/libtrx/game/ui/dialogs/controls_editor.h
Normal file
36
src/libtrx/include/libtrx/game/ui/dialogs/controls_editor.h
Normal file
|
@ -0,0 +1,36 @@
|
|||
#pragma once
|
||||
|
||||
// A controls remapper dialog.
|
||||
|
||||
#include "../../../event_manager.h"
|
||||
#include "../../input.h"
|
||||
#include "../common.h"
|
||||
#include "../elements/flash.h"
|
||||
#include "../elements/requester.h"
|
||||
|
||||
typedef struct {
|
||||
int32_t phase;
|
||||
INPUT_BACKEND backend;
|
||||
int32_t active_layout;
|
||||
INPUT_ROLE active_role;
|
||||
int32_t active_col;
|
||||
int32_t active_row;
|
||||
UI_FLASH_STATE flash;
|
||||
EVENT_MANAGER *events;
|
||||
} UI_CONTROLS_EDITOR_STATE;
|
||||
|
||||
typedef enum {
|
||||
UI_CONTROLS_CHOICE_EXIT,
|
||||
UI_CONTROLS_CHOICE_GO_BACK,
|
||||
UI_CONTROLS_CHOICE_NOOP,
|
||||
} UI_CONTROLS_CHOICE;
|
||||
|
||||
// state functions
|
||||
void UI_ControlsEditor_Init(UI_CONTROLS_EDITOR_STATE *s, EVENT_MANAGER *events);
|
||||
void UI_ControlsEditor_Free(UI_CONTROLS_EDITOR_STATE *s);
|
||||
void UI_ControlsEditor_Reinit(
|
||||
UI_CONTROLS_EDITOR_STATE *s, INPUT_BACKEND backend, int32_t layout);
|
||||
UI_CONTROLS_CHOICE UI_ControlsEditor_Control(UI_CONTROLS_EDITOR_STATE *s);
|
||||
|
||||
// draw functions
|
||||
void UI_ControlsEditor(UI_CONTROLS_EDITOR_STATE *s);
|
22
src/libtrx/include/libtrx/game/ui/dialogs/examine_item.h
Normal file
22
src/libtrx/include/libtrx/game/ui/dialogs/examine_item.h
Normal file
|
@ -0,0 +1,22 @@
|
|||
#pragma once
|
||||
|
||||
#include "../../../vector.h"
|
||||
#include "../common.h"
|
||||
|
||||
// A widget to cycle through several pages of a text content.
|
||||
|
||||
typedef struct {
|
||||
char *title;
|
||||
size_t max_lines;
|
||||
int32_t current_page;
|
||||
VECTOR *page_content;
|
||||
bool is_empty;
|
||||
} UI_EXAMINE_ITEM_STATE;
|
||||
|
||||
void UI_ExamineItem_Init(
|
||||
UI_EXAMINE_ITEM_STATE *state, const char *title, const char *text,
|
||||
size_t max_lines);
|
||||
void UI_ExamineItem_Control(UI_EXAMINE_ITEM_STATE *state);
|
||||
void UI_ExamineItem_Free(UI_EXAMINE_ITEM_STATE *state);
|
||||
|
||||
void UI_ExamineItem(UI_EXAMINE_ITEM_STATE *state);
|
18
src/libtrx/include/libtrx/game/ui/dialogs/new_game.h
Normal file
18
src/libtrx/include/libtrx/game/ui/dialogs/new_game.h
Normal file
|
@ -0,0 +1,18 @@
|
|||
#pragma once
|
||||
|
||||
// A new game mode selector dialog.
|
||||
|
||||
#include "../common.h"
|
||||
#include "../elements/requester.h"
|
||||
|
||||
typedef struct {
|
||||
UI_REQUESTER_STATE req;
|
||||
} UI_NEW_GAME_STATE;
|
||||
|
||||
// state functions
|
||||
void UI_NewGame_Init(UI_NEW_GAME_STATE *s);
|
||||
int32_t UI_NewGame_Control(UI_NEW_GAME_STATE *s);
|
||||
void UI_NewGame_Free(UI_NEW_GAME_STATE *s);
|
||||
|
||||
// draw functions
|
||||
void UI_NewGame(UI_NEW_GAME_STATE *s);
|
26
src/libtrx/include/libtrx/game/ui/dialogs/pause.h
Normal file
26
src/libtrx/include/libtrx/game/ui/dialogs/pause.h
Normal file
|
@ -0,0 +1,26 @@
|
|||
#pragma once
|
||||
|
||||
// A pause exit confirmation dialog.
|
||||
|
||||
#include "../common.h"
|
||||
#include "../elements/requester.h"
|
||||
|
||||
typedef struct {
|
||||
int32_t phase;
|
||||
UI_REQUESTER_STATE req;
|
||||
} UI_PAUSE_STATE;
|
||||
|
||||
typedef enum {
|
||||
UI_PAUSE_NOOP,
|
||||
UI_PAUSE_RESUME_PAUSE,
|
||||
UI_PAUSE_EXIT_TO_GAME,
|
||||
UI_PAUSE_EXIT_TO_TITLE,
|
||||
} UI_PAUSE_EXIT_CHOICE;
|
||||
|
||||
// state functions
|
||||
void UI_Pause_Init(UI_PAUSE_STATE *s);
|
||||
UI_PAUSE_EXIT_CHOICE UI_Pause_Control(UI_PAUSE_STATE *s);
|
||||
void UI_Pause_Free(UI_PAUSE_STATE *s);
|
||||
|
||||
// draw functions
|
||||
void UI_Pause(UI_PAUSE_STATE *s);
|
|
@ -4,4 +4,4 @@
|
|||
|
||||
// A photo mode tutorial dialog.
|
||||
|
||||
void UI2_PhotoMode(void);
|
||||
void UI_PhotoMode(void);
|
34
src/libtrx/include/libtrx/game/ui/dialogs/stats.h
Normal file
34
src/libtrx/include/libtrx/game/ui/dialogs/stats.h
Normal file
|
@ -0,0 +1,34 @@
|
|||
#pragma once
|
||||
|
||||
#include "../common.h"
|
||||
#include "../elements/requester.h"
|
||||
|
||||
typedef enum {
|
||||
UI_STATS_DIALOG_MODE_LEVEL,
|
||||
UI_STATS_DIALOG_MODE_FINAL,
|
||||
#if TR_VERSION == 2
|
||||
UI_STATS_DIALOG_MODE_ASSAULT_COURSE,
|
||||
#endif
|
||||
} UI_STATS_DIALOG_MODE;
|
||||
|
||||
typedef enum {
|
||||
UI_STATS_DIALOG_STYLE_BARE,
|
||||
UI_STATS_DIALOG_STYLE_BORDERED,
|
||||
} UI_STATS_DIALOG_STYLE;
|
||||
|
||||
typedef struct {
|
||||
UI_STATS_DIALOG_MODE mode;
|
||||
UI_STATS_DIALOG_STYLE style;
|
||||
int32_t level_num;
|
||||
} UI_STATS_DIALOG_ARGS;
|
||||
|
||||
typedef struct {
|
||||
UI_STATS_DIALOG_ARGS args;
|
||||
UI_REQUESTER_STATE assault_req;
|
||||
} UI_STATS_DIALOG_STATE;
|
||||
|
||||
void UI_StatsDialog_Init(UI_STATS_DIALOG_STATE *s, UI_STATS_DIALOG_ARGS args);
|
||||
void UI_StatsDialog_Free(UI_STATS_DIALOG_STATE *s);
|
||||
int32_t UI_StatsDialog_Control(UI_STATS_DIALOG_STATE *s);
|
||||
|
||||
extern void UI_StatsDialog(UI_STATS_DIALOG_STATE *s);
|
|
@ -5,5 +5,5 @@
|
|||
// Used to align a top-level widget to the screen center or to the screen edges.
|
||||
// Uses ratio inputs.
|
||||
|
||||
void UI2_BeginAnchor(const float x, const float y);
|
||||
void UI2_EndAnchor(void);
|
||||
void UI_BeginAnchor(const float x, const float y);
|
||||
void UI_EndAnchor(void);
|
|
@ -7,5 +7,5 @@
|
|||
|
||||
// Draw a fade on top or behind children.
|
||||
|
||||
void UI2_BeginFade(FADER *fader, bool is_on_top);
|
||||
void UI2_EndFade(void);
|
||||
void UI_BeginFade(FADER *fader, bool is_on_top);
|
||||
void UI_EndFade(void);
|
21
src/libtrx/include/libtrx/game/ui/elements/flash.h
Normal file
21
src/libtrx/include/libtrx/game/ui/elements/flash.h
Normal file
|
@ -0,0 +1,21 @@
|
|||
#pragma once
|
||||
|
||||
#include "../common.h"
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
// Make the child widget invisible in the specified interval.
|
||||
|
||||
typedef struct {
|
||||
int32_t rate;
|
||||
int32_t count;
|
||||
} UI_FLASH_STATE;
|
||||
|
||||
// state functions
|
||||
void UI_Flash_Init(UI_FLASH_STATE *s, int32_t rate);
|
||||
void UI_Flash_Free(UI_FLASH_STATE *s);
|
||||
void UI_Flash_Control(UI_FLASH_STATE *s);
|
||||
|
||||
// draw functions
|
||||
void UI_BeginFlash(UI_FLASH_STATE *s);
|
||||
void UI_EndFlash(void);
|
15
src/libtrx/include/libtrx/game/ui/elements/frame.h
Normal file
15
src/libtrx/include/libtrx/game/ui/elements/frame.h
Normal file
|
@ -0,0 +1,15 @@
|
|||
#pragma once
|
||||
|
||||
#include "../common.h"
|
||||
|
||||
// A frame around the child widget.
|
||||
|
||||
typedef enum {
|
||||
UI_FRAME_DIALOG_BACKGROUND,
|
||||
UI_FRAME_DIALOG_HEADING,
|
||||
UI_FRAME_SELECTED_OPTION,
|
||||
UI_FRAME_OUTLINE_ONLY,
|
||||
} UI_FRAME_STYLE;
|
||||
|
||||
void UI_BeginFrame(UI_FRAME_STYLE style);
|
||||
void UI_EndFrame(void);
|
|
@ -5,5 +5,5 @@
|
|||
// Make the child widget invisible if the given flag is true.
|
||||
// The children still take up their size.
|
||||
|
||||
void UI2_BeginHide(bool hide_children);
|
||||
void UI2_EndHide(void);
|
||||
void UI_BeginHide(bool hide_children);
|
||||
void UI_EndHide(void);
|
19
src/libtrx/include/libtrx/game/ui/elements/label.h
Normal file
19
src/libtrx/include/libtrx/game/ui/elements/label.h
Normal file
|
@ -0,0 +1,19 @@
|
|||
#pragma once
|
||||
|
||||
#include "../common.h"
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
// Basic text widget.
|
||||
|
||||
typedef struct {
|
||||
float scale;
|
||||
int32_t z;
|
||||
} UI_LABEL_SETTINGS;
|
||||
|
||||
void UI_Label(const char *text);
|
||||
void UI_LabelEx(const char *text, UI_LABEL_SETTINGS settings);
|
||||
|
||||
void UI_Label_Measure(const char *text, float *out_w, float *out_h);
|
||||
void UI_Label_MeasureEx(
|
||||
const char *text, float *out_w, float *out_h, UI_LABEL_SETTINGS settings);
|
|
@ -5,5 +5,5 @@
|
|||
// A widget that resizes the children to the canvas size
|
||||
// and places it at a specific proportional spot.
|
||||
|
||||
void UI2_BeginModal(float x, float y);
|
||||
void UI2_EndModal(void);
|
||||
void UI_BeginModal(float x, float y);
|
||||
void UI_EndModal(void);
|
9
src/libtrx/include/libtrx/game/ui/elements/pad.h
Normal file
9
src/libtrx/include/libtrx/game/ui/elements/pad.h
Normal file
|
@ -0,0 +1,9 @@
|
|||
#pragma once
|
||||
|
||||
#include "../common.h"
|
||||
|
||||
// An invisible border in pixel units around the child widget.
|
||||
|
||||
void UI_BeginPad(float x, float y);
|
||||
void UI_BeginPadEx(float l, float r, float t, float d);
|
||||
void UI_EndPad(void);
|
|
@ -17,16 +17,16 @@ typedef struct {
|
|||
int32_t listener1;
|
||||
int32_t listener2;
|
||||
|
||||
UI2_FLASH_STATE flash;
|
||||
} UI2_PROMPT_STATE;
|
||||
UI_FLASH_STATE flash;
|
||||
} UI_PROMPT_STATE;
|
||||
|
||||
// state functions
|
||||
void UI2_Prompt_Init(UI2_PROMPT_STATE *s);
|
||||
void UI2_Prompt_Free(UI2_PROMPT_STATE *s);
|
||||
void UI2_Prompt_Control(UI2_PROMPT_STATE *s);
|
||||
void UI2_Prompt_Clear(UI2_PROMPT_STATE *s);
|
||||
void UI2_Prompt_SetFocus(UI2_PROMPT_STATE *s, bool is_focused);
|
||||
void UI2_Prompt_ChangeText(UI2_PROMPT_STATE *s, const char *new_text);
|
||||
void UI_Prompt_Init(UI_PROMPT_STATE *s);
|
||||
void UI_Prompt_Free(UI_PROMPT_STATE *s);
|
||||
void UI_Prompt_Control(UI_PROMPT_STATE *s);
|
||||
void UI_Prompt_Clear(UI_PROMPT_STATE *s);
|
||||
void UI_Prompt_SetFocus(UI_PROMPT_STATE *s, bool is_focused);
|
||||
void UI_Prompt_ChangeText(UI_PROMPT_STATE *s, const char *new_text);
|
||||
|
||||
// draw functions
|
||||
void UI2_Prompt(UI2_PROMPT_STATE *s);
|
||||
void UI_Prompt(UI_PROMPT_STATE *s);
|
40
src/libtrx/include/libtrx/game/ui/elements/requester.h
Normal file
40
src/libtrx/include/libtrx/game/ui/elements/requester.h
Normal file
|
@ -0,0 +1,40 @@
|
|||
#pragma once
|
||||
|
||||
// A window to select a single option from a list of predefined choices.
|
||||
|
||||
#include "../common.h"
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#define UI_REQUESTER_CANCEL -2
|
||||
#define UI_REQUESTER_NO_CHOICE -1
|
||||
|
||||
typedef struct {
|
||||
bool is_selectable;
|
||||
int32_t vis_rows;
|
||||
int32_t max_rows;
|
||||
int32_t vis_row;
|
||||
int32_t sel_row;
|
||||
float row_pad;
|
||||
float row_spacing;
|
||||
} UI_REQUESTER_STATE;
|
||||
|
||||
// state functions
|
||||
void UI_Requester_Init(
|
||||
UI_REQUESTER_STATE *s, int32_t vis_rows, int32_t max_rows,
|
||||
bool is_selectable);
|
||||
void UI_Requester_Free(UI_REQUESTER_STATE *s);
|
||||
int32_t UI_Requester_Control(UI_REQUESTER_STATE *s);
|
||||
void UI_Requester_SetMaxRows(UI_REQUESTER_STATE *s, int32_t max_rows);
|
||||
int32_t UI_Requester_GetFirstRow(const UI_REQUESTER_STATE *s);
|
||||
int32_t UI_Requester_GetLastRow(const UI_REQUESTER_STATE *s);
|
||||
int32_t UI_Requester_GetCurrentRow(const UI_REQUESTER_STATE *s);
|
||||
bool UI_Requester_IsRowVisible(const UI_REQUESTER_STATE *s, int32_t i);
|
||||
bool UI_Requester_IsRowSelected(const UI_REQUESTER_STATE *s, int32_t i);
|
||||
|
||||
// draw functions
|
||||
void UI_BeginRequester(const UI_REQUESTER_STATE *s, const char *title);
|
||||
void UI_EndRequester(const UI_REQUESTER_STATE *s);
|
||||
|
||||
void UI_BeginRequesterRow(const UI_REQUESTER_STATE *s, int32_t i);
|
||||
void UI_EndRequesterRow(const UI_REQUESTER_STATE *s, int32_t i);
|
|
@ -6,5 +6,5 @@
|
|||
// A negative size means to use the child's size.
|
||||
// A zero value means to hide the child, but participate in the layout pass.
|
||||
|
||||
void UI2_BeginResize(float x, float y);
|
||||
void UI2_EndResize(void);
|
||||
void UI_BeginResize(float x, float y);
|
||||
void UI_EndResize(void);
|
|
@ -4,4 +4,4 @@
|
|||
|
||||
// An invisible widget that occupies certain space in pixels.
|
||||
|
||||
void UI2_Spacer(float w, float h);
|
||||
void UI_Spacer(float w, float h);
|
44
src/libtrx/include/libtrx/game/ui/elements/stack.h
Normal file
44
src/libtrx/include/libtrx/game/ui/elements/stack.h
Normal file
|
@ -0,0 +1,44 @@
|
|||
#pragma once
|
||||
|
||||
#include "../common.h"
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
// Stack several widgets vertically or horizontally.
|
||||
|
||||
typedef enum {
|
||||
UI_STACK_VERTICAL,
|
||||
UI_STACK_HORIZONTAL,
|
||||
} UI_STACK_ORIENTATION;
|
||||
|
||||
typedef enum {
|
||||
UI_STACK_H_ALIGN_LEFT,
|
||||
UI_STACK_H_ALIGN_CENTER,
|
||||
UI_STACK_H_ALIGN_RIGHT,
|
||||
UI_STACK_H_ALIGN_SPAN,
|
||||
UI_STACK_H_ALIGN_DISTRIBUTE,
|
||||
} UI_STACK_H_ALIGN;
|
||||
|
||||
typedef enum {
|
||||
UI_STACK_V_ALIGN_TOP,
|
||||
UI_STACK_V_ALIGN_CENTER,
|
||||
UI_STACK_V_ALIGN_BOTTOM,
|
||||
UI_STACK_V_ALIGN_SPAN,
|
||||
UI_STACK_V_ALIGN_DISTRIBUTE,
|
||||
} UI_STACK_V_ALIGN;
|
||||
|
||||
typedef struct {
|
||||
UI_STACK_ORIENTATION orientation;
|
||||
struct {
|
||||
UI_STACK_H_ALIGN h;
|
||||
UI_STACK_V_ALIGN v;
|
||||
} align;
|
||||
struct {
|
||||
float h;
|
||||
float v;
|
||||
} spacing;
|
||||
} UI_STACK_SETTINGS;
|
||||
|
||||
void UI_BeginStack(UI_STACK_ORIENTATION orientation);
|
||||
void UI_BeginStackEx(UI_STACK_SETTINGS settings);
|
||||
void UI_EndStack(void);
|
7
src/libtrx/include/libtrx/game/ui/elements/window.h
Normal file
7
src/libtrx/include/libtrx/game/ui/elements/window.h
Normal file
|
@ -0,0 +1,7 @@
|
|||
#pragma once
|
||||
|
||||
void UI_BeginWindow(void);
|
||||
void UI_EndWindow(void);
|
||||
void UI_BeginWindowBody(void);
|
||||
void UI_EndWindowBody(void);
|
||||
void UI_WindowTitle(const char *title);
|
|
@ -4,13 +4,13 @@
|
|||
|
||||
typedef void (*EVENT_LISTENER)(const EVENT *, void *user_data);
|
||||
|
||||
void UI2_InitEvents(void);
|
||||
void UI2_ShutdownEvents(void);
|
||||
void UI_InitEvents(void);
|
||||
void UI_ShutdownEvents(void);
|
||||
|
||||
int32_t UI2_Subscribe(
|
||||
int32_t UI_Subscribe(
|
||||
const char *event_name, const void *sender, EVENT_LISTENER listener,
|
||||
void *user_data);
|
||||
|
||||
void UI2_Unsubscribe(int32_t listener_id);
|
||||
void UI_Unsubscribe(int32_t listener_id);
|
||||
|
||||
void UI2_FireEvent(EVENT event);
|
||||
void UI_FireEvent(EVENT event);
|
22
src/libtrx/include/libtrx/game/ui/hud/console.h
Normal file
22
src/libtrx/include/libtrx/game/ui/hud/console.h
Normal file
|
@ -0,0 +1,22 @@
|
|||
#pragma once
|
||||
|
||||
#include "../elements/prompt.h"
|
||||
#include "./console_logs.h"
|
||||
|
||||
// Dev console display widget.
|
||||
|
||||
typedef struct {
|
||||
UI_CONSOLE_LOGS logs;
|
||||
UI_PROMPT_STATE prompt;
|
||||
|
||||
int32_t listeners[5];
|
||||
int32_t history_idx;
|
||||
} UI_CONSOLE_STATE;
|
||||
|
||||
// state functions
|
||||
void UI_Console_Init(UI_CONSOLE_STATE *s);
|
||||
void UI_Console_Free(UI_CONSOLE_STATE *s);
|
||||
void UI_Console_Control(UI_CONSOLE_STATE *s);
|
||||
|
||||
// draw functions
|
||||
void UI_Console(UI_CONSOLE_STATE *s);
|
|
@ -8,16 +8,16 @@
|
|||
typedef struct {
|
||||
char *text;
|
||||
double expire_at;
|
||||
} UI2_CONSOLE_LOG_LINE;
|
||||
} UI_CONSOLE_LOG_LINE;
|
||||
|
||||
typedef struct {
|
||||
size_t max_lines;
|
||||
size_t vis_lines;
|
||||
UI2_CONSOLE_LOG_LINE *logs;
|
||||
UI_CONSOLE_LOG_LINE *logs;
|
||||
int32_t listener_id;
|
||||
} UI2_CONSOLE_LOGS;
|
||||
} UI_CONSOLE_LOGS;
|
||||
|
||||
// state functions
|
||||
void UI2_ConsoleLogs_Init(UI2_CONSOLE_LOGS *s);
|
||||
void UI2_ConsoleLogs_Free(UI2_CONSOLE_LOGS *s);
|
||||
void UI2_ConsoleLogs(UI2_CONSOLE_LOGS *s);
|
||||
void UI_ConsoleLogs_Init(UI_CONSOLE_LOGS *s);
|
||||
void UI_ConsoleLogs_Free(UI_CONSOLE_LOGS *s);
|
||||
void UI_ConsoleLogs(UI_CONSOLE_LOGS *s);
|
|
@ -1,24 +0,0 @@
|
|||
#pragma once
|
||||
|
||||
#include "./ui2/common.h"
|
||||
#include "./ui2/dialogs/controls.h"
|
||||
#include "./ui2/dialogs/controls_backend.h"
|
||||
#include "./ui2/dialogs/examine_item.h"
|
||||
#include "./ui2/dialogs/new_game.h"
|
||||
#include "./ui2/dialogs/pause.h"
|
||||
#include "./ui2/dialogs/photo_mode.h"
|
||||
#include "./ui2/dialogs/stats.h"
|
||||
#include "./ui2/elements/anchor.h"
|
||||
#include "./ui2/elements/fade.h"
|
||||
#include "./ui2/elements/flash.h"
|
||||
#include "./ui2/elements/frame.h"
|
||||
#include "./ui2/elements/label.h"
|
||||
#include "./ui2/elements/modal.h"
|
||||
#include "./ui2/elements/pad.h"
|
||||
#include "./ui2/elements/requester.h"
|
||||
#include "./ui2/elements/resize.h"
|
||||
#include "./ui2/elements/spacer.h"
|
||||
#include "./ui2/elements/stack.h"
|
||||
#include "./ui2/events.h"
|
||||
#include "./ui2/hud/console.h"
|
||||
#include "./ui2/hud/console_logs.h"
|
|
@ -1,74 +0,0 @@
|
|||
#pragma once
|
||||
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
|
||||
typedef enum {
|
||||
UI2_KEY_UP,
|
||||
UI2_KEY_DOWN,
|
||||
UI2_KEY_LEFT,
|
||||
UI2_KEY_RIGHT,
|
||||
UI2_KEY_HOME,
|
||||
UI2_KEY_END,
|
||||
UI2_KEY_BACK,
|
||||
UI2_KEY_RETURN,
|
||||
UI2_KEY_ESCAPE,
|
||||
} UI2_INPUT;
|
||||
|
||||
// Forward declaration of the node and its vtable.
|
||||
struct UI2_NODE;
|
||||
typedef struct {
|
||||
void (*measure)(struct UI2_NODE *node);
|
||||
void (*layout)(struct UI2_NODE *node, float x, float y, float w, float h);
|
||||
void (*draw)(const struct UI2_NODE *node);
|
||||
} UI2_WIDGET_OPS;
|
||||
|
||||
// Node structure that forms the UI tree
|
||||
typedef struct UI2_NODE {
|
||||
// Common operations on a widget
|
||||
const UI2_WIDGET_OPS *ops;
|
||||
|
||||
// Final layout rectangle
|
||||
float x;
|
||||
float y;
|
||||
float w;
|
||||
float h;
|
||||
|
||||
// Needed size from measure pass
|
||||
float measure_w;
|
||||
float measure_h;
|
||||
|
||||
// Link to parent and siblings to form a tree
|
||||
struct UI2_NODE *parent;
|
||||
struct UI2_NODE *first_child;
|
||||
struct UI2_NODE *last_child;
|
||||
struct UI2_NODE *next_sibling;
|
||||
|
||||
// Widget-specific data
|
||||
void *data;
|
||||
} UI2_NODE;
|
||||
|
||||
// Dimensions in virtual pixels of the screen area
|
||||
// (640x480 for any 4:3 resolution on 1.00 text scaling)
|
||||
extern int32_t UI2_GetCanvasWidth(void);
|
||||
extern int32_t UI2_GetCanvasHeight(void);
|
||||
extern float UI2_ScaleX(float x);
|
||||
extern float UI2_ScaleY(float y);
|
||||
|
||||
// Public API for scene management
|
||||
void UI2_BeginScene(void);
|
||||
void UI2_EndScene(void);
|
||||
|
||||
// Helpers to add children, etc.
|
||||
UI2_NODE *UI2_AllocNode(const UI2_WIDGET_OPS *ops, size_t additional_size);
|
||||
void UI2_AddChild(UI2_NODE *child);
|
||||
void UI2_PushCurrent(UI2_NODE *child);
|
||||
void UI2_PopCurrent(void);
|
||||
|
||||
void UI2_Init(void);
|
||||
void UI2_Shutdown(void);
|
||||
void UI2_ToggleState(bool *config_setting);
|
||||
|
||||
void UI2_HandleKeyDown(uint32_t key);
|
||||
void UI2_HandleKeyUp(uint32_t key);
|
||||
void UI2_HandleTextEdit(const char *text);
|
|
@ -1,18 +0,0 @@
|
|||
#pragma once
|
||||
|
||||
// A control backend (keyboard/controller) choice dialog.
|
||||
|
||||
#include "../common.h"
|
||||
#include "../elements/requester.h"
|
||||
|
||||
typedef struct {
|
||||
UI2_REQUESTER_STATE req;
|
||||
} UI2_CONTROLS_BACKEND_STATE;
|
||||
|
||||
// state functions
|
||||
void UI2_ControlsBackend_Init(UI2_CONTROLS_BACKEND_STATE *s);
|
||||
void UI2_ControlsBackend_Free(UI2_CONTROLS_BACKEND_STATE *s);
|
||||
int32_t UI2_ControlsBackend_Control(UI2_CONTROLS_BACKEND_STATE *s);
|
||||
|
||||
// draw functions
|
||||
void UI2_ControlsBackend(UI2_CONTROLS_BACKEND_STATE *s);
|
|
@ -1,37 +0,0 @@
|
|||
#pragma once
|
||||
|
||||
// A controls remapper dialog.
|
||||
|
||||
#include "../../../event_manager.h"
|
||||
#include "../../input.h"
|
||||
#include "../common.h"
|
||||
#include "../elements/flash.h"
|
||||
#include "../elements/requester.h"
|
||||
|
||||
typedef struct {
|
||||
int32_t phase;
|
||||
INPUT_BACKEND backend;
|
||||
int32_t active_layout;
|
||||
INPUT_ROLE active_role;
|
||||
int32_t active_col;
|
||||
int32_t active_row;
|
||||
UI2_FLASH_STATE flash;
|
||||
EVENT_MANAGER *events;
|
||||
} UI2_CONTROLS_EDITOR_STATE;
|
||||
|
||||
typedef enum {
|
||||
UI2_CONTROLS_CHOICE_EXIT,
|
||||
UI2_CONTROLS_CHOICE_GO_BACK,
|
||||
UI2_CONTROLS_CHOICE_NOOP,
|
||||
} UI2_CONTROLS_CHOICE;
|
||||
|
||||
// state functions
|
||||
void UI2_ControlsEditor_Init(
|
||||
UI2_CONTROLS_EDITOR_STATE *s, EVENT_MANAGER *events);
|
||||
void UI2_ControlsEditor_Free(UI2_CONTROLS_EDITOR_STATE *s);
|
||||
void UI2_ControlsEditor_Reinit(
|
||||
UI2_CONTROLS_EDITOR_STATE *s, INPUT_BACKEND backend, int32_t layout);
|
||||
UI2_CONTROLS_CHOICE UI2_ControlsEditor_Control(UI2_CONTROLS_EDITOR_STATE *s);
|
||||
|
||||
// draw functions
|
||||
void UI2_ControlsEditor(UI2_CONTROLS_EDITOR_STATE *s);
|
|
@ -1,22 +0,0 @@
|
|||
#pragma once
|
||||
|
||||
#include "../../../vector.h"
|
||||
#include "../common.h"
|
||||
|
||||
// A widget to cycle through several pages of a text content.
|
||||
|
||||
typedef struct {
|
||||
char *title;
|
||||
size_t max_lines;
|
||||
int32_t current_page;
|
||||
VECTOR *page_content;
|
||||
bool is_empty;
|
||||
} UI2_EXAMINE_ITEM_STATE;
|
||||
|
||||
void UI2_ExamineItem_Init(
|
||||
UI2_EXAMINE_ITEM_STATE *state, const char *title, const char *text,
|
||||
size_t max_lines);
|
||||
void UI2_ExamineItem_Control(UI2_EXAMINE_ITEM_STATE *state);
|
||||
void UI2_ExamineItem_Free(UI2_EXAMINE_ITEM_STATE *state);
|
||||
|
||||
void UI2_ExamineItem(UI2_EXAMINE_ITEM_STATE *state);
|
|
@ -1,18 +0,0 @@
|
|||
#pragma once
|
||||
|
||||
// A new game mode selector dialog.
|
||||
|
||||
#include "../common.h"
|
||||
#include "../elements/requester.h"
|
||||
|
||||
typedef struct {
|
||||
UI2_REQUESTER_STATE req;
|
||||
} UI2_NEW_GAME_STATE;
|
||||
|
||||
// state functions
|
||||
void UI2_NewGame_Init(UI2_NEW_GAME_STATE *s);
|
||||
int32_t UI2_NewGame_Control(UI2_NEW_GAME_STATE *s);
|
||||
void UI2_NewGame_Free(UI2_NEW_GAME_STATE *s);
|
||||
|
||||
// draw functions
|
||||
void UI2_NewGame(UI2_NEW_GAME_STATE *s);
|
|
@ -1,26 +0,0 @@
|
|||
#pragma once
|
||||
|
||||
// A pause exit confirmation dialog.
|
||||
|
||||
#include "../common.h"
|
||||
#include "../elements/requester.h"
|
||||
|
||||
typedef struct {
|
||||
int32_t phase;
|
||||
UI2_REQUESTER_STATE req;
|
||||
} UI2_PAUSE_STATE;
|
||||
|
||||
typedef enum {
|
||||
UI2_PAUSE_NOOP,
|
||||
UI2_PAUSE_RESUME_PAUSE,
|
||||
UI2_PAUSE_EXIT_TO_GAME,
|
||||
UI2_PAUSE_EXIT_TO_TITLE,
|
||||
} UI2_PAUSE_EXIT_CHOICE;
|
||||
|
||||
// state functions
|
||||
void UI2_Pause_Init(UI2_PAUSE_STATE *s);
|
||||
UI2_PAUSE_EXIT_CHOICE UI2_Pause_Control(UI2_PAUSE_STATE *s);
|
||||
void UI2_Pause_Free(UI2_PAUSE_STATE *s);
|
||||
|
||||
// draw functions
|
||||
void UI2_Pause(UI2_PAUSE_STATE *s);
|
|
@ -1,35 +0,0 @@
|
|||
#pragma once
|
||||
|
||||
#include "../common.h"
|
||||
#include "../elements/requester.h"
|
||||
|
||||
typedef enum {
|
||||
UI2_STATS_DIALOG_MODE_LEVEL,
|
||||
UI2_STATS_DIALOG_MODE_FINAL,
|
||||
#if TR_VERSION == 2
|
||||
UI2_STATS_DIALOG_MODE_ASSAULT_COURSE,
|
||||
#endif
|
||||
} UI2_STATS_DIALOG_MODE;
|
||||
|
||||
typedef enum {
|
||||
UI2_STATS_DIALOG_STYLE_BARE,
|
||||
UI2_STATS_DIALOG_STYLE_BORDERED,
|
||||
} UI2_STATS_DIALOG_STYLE;
|
||||
|
||||
typedef struct {
|
||||
UI2_STATS_DIALOG_MODE mode;
|
||||
UI2_STATS_DIALOG_STYLE style;
|
||||
int32_t level_num;
|
||||
} UI2_STATS_DIALOG_ARGS;
|
||||
|
||||
typedef struct {
|
||||
UI2_STATS_DIALOG_ARGS args;
|
||||
UI2_REQUESTER_STATE assault_req;
|
||||
} UI2_STATS_DIALOG_STATE;
|
||||
|
||||
void UI2_StatsDialog_Init(
|
||||
UI2_STATS_DIALOG_STATE *s, UI2_STATS_DIALOG_ARGS args);
|
||||
void UI2_StatsDialog_Free(UI2_STATS_DIALOG_STATE *s);
|
||||
int32_t UI2_StatsDialog_Control(UI2_STATS_DIALOG_STATE *s);
|
||||
|
||||
extern void UI2_StatsDialog(UI2_STATS_DIALOG_STATE *s);
|
|
@ -1,21 +0,0 @@
|
|||
#pragma once
|
||||
|
||||
#include "../common.h"
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
// Make the child widget invisible in the specified interval.
|
||||
|
||||
typedef struct {
|
||||
int32_t rate;
|
||||
int32_t count;
|
||||
} UI2_FLASH_STATE;
|
||||
|
||||
// state functions
|
||||
void UI2_Flash_Init(UI2_FLASH_STATE *s, int32_t rate);
|
||||
void UI2_Flash_Free(UI2_FLASH_STATE *s);
|
||||
void UI2_Flash_Control(UI2_FLASH_STATE *s);
|
||||
|
||||
// draw functions
|
||||
void UI2_BeginFlash(UI2_FLASH_STATE *s);
|
||||
void UI2_EndFlash(void);
|
|
@ -1,15 +0,0 @@
|
|||
#pragma once
|
||||
|
||||
#include "../common.h"
|
||||
|
||||
// A frame around the child widget.
|
||||
|
||||
typedef enum {
|
||||
UI2_FRAME_DIALOG_BACKGROUND,
|
||||
UI2_FRAME_DIALOG_HEADING,
|
||||
UI2_FRAME_SELECTED_OPTION,
|
||||
UI2_FRAME_OUTLINE_ONLY,
|
||||
} UI2_FRAME_STYLE;
|
||||
|
||||
void UI2_BeginFrame(UI2_FRAME_STYLE style);
|
||||
void UI2_EndFrame(void);
|
|
@ -1,19 +0,0 @@
|
|||
#pragma once
|
||||
|
||||
#include "../common.h"
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
// Basic text widget.
|
||||
|
||||
typedef struct {
|
||||
float scale;
|
||||
int32_t z;
|
||||
} UI2_LABEL_SETTINGS;
|
||||
|
||||
void UI2_Label(const char *text);
|
||||
void UI2_LabelEx(const char *text, UI2_LABEL_SETTINGS settings);
|
||||
|
||||
void UI2_Label_Measure(const char *text, float *out_w, float *out_h);
|
||||
void UI2_Label_MeasureEx(
|
||||
const char *text, float *out_w, float *out_h, UI2_LABEL_SETTINGS settings);
|
|
@ -1,9 +0,0 @@
|
|||
#pragma once
|
||||
|
||||
#include "../common.h"
|
||||
|
||||
// An invisible border in pixel units around the child widget.
|
||||
|
||||
void UI2_BeginPad(float x, float y);
|
||||
void UI2_BeginPadEx(float l, float r, float t, float d);
|
||||
void UI2_EndPad(void);
|
|
@ -1,40 +0,0 @@
|
|||
#pragma once
|
||||
|
||||
// A window to select a single option from a list of predefined choices.
|
||||
|
||||
#include "../common.h"
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#define UI2_REQUESTER_CANCEL -2
|
||||
#define UI2_REQUESTER_NO_CHOICE -1
|
||||
|
||||
typedef struct {
|
||||
bool is_selectable;
|
||||
int32_t vis_rows;
|
||||
int32_t max_rows;
|
||||
int32_t vis_row;
|
||||
int32_t sel_row;
|
||||
float row_pad;
|
||||
float row_spacing;
|
||||
} UI2_REQUESTER_STATE;
|
||||
|
||||
// state functions
|
||||
void UI2_Requester_Init(
|
||||
UI2_REQUESTER_STATE *s, int32_t vis_rows, int32_t max_rows,
|
||||
bool is_selectable);
|
||||
void UI2_Requester_Free(UI2_REQUESTER_STATE *s);
|
||||
int32_t UI2_Requester_Control(UI2_REQUESTER_STATE *s);
|
||||
void UI2_Requester_SetMaxRows(UI2_REQUESTER_STATE *s, int32_t max_rows);
|
||||
int32_t UI2_Requester_GetFirstRow(const UI2_REQUESTER_STATE *s);
|
||||
int32_t UI2_Requester_GetLastRow(const UI2_REQUESTER_STATE *s);
|
||||
int32_t UI2_Requester_GetCurrentRow(const UI2_REQUESTER_STATE *s);
|
||||
bool UI2_Requester_IsRowVisible(const UI2_REQUESTER_STATE *s, int32_t i);
|
||||
bool UI2_Requester_IsRowSelected(const UI2_REQUESTER_STATE *s, int32_t i);
|
||||
|
||||
// draw functions
|
||||
void UI2_BeginRequester(const UI2_REQUESTER_STATE *s, const char *title);
|
||||
void UI2_EndRequester(const UI2_REQUESTER_STATE *s);
|
||||
|
||||
void UI2_BeginRequesterRow(const UI2_REQUESTER_STATE *s, int32_t i);
|
||||
void UI2_EndRequesterRow(const UI2_REQUESTER_STATE *s, int32_t i);
|
|
@ -1,44 +0,0 @@
|
|||
#pragma once
|
||||
|
||||
#include "../common.h"
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
// Stack several widgets vertically or horizontally.
|
||||
|
||||
typedef enum {
|
||||
UI2_STACK_VERTICAL,
|
||||
UI2_STACK_HORIZONTAL,
|
||||
} UI2_STACK_ORIENTATION;
|
||||
|
||||
typedef enum {
|
||||
UI2_STACK_H_ALIGN_LEFT,
|
||||
UI2_STACK_H_ALIGN_CENTER,
|
||||
UI2_STACK_H_ALIGN_RIGHT,
|
||||
UI2_STACK_H_ALIGN_SPAN,
|
||||
UI2_STACK_H_ALIGN_DISTRIBUTE,
|
||||
} UI2_STACK_H_ALIGN;
|
||||
|
||||
typedef enum {
|
||||
UI2_STACK_V_ALIGN_TOP,
|
||||
UI2_STACK_V_ALIGN_CENTER,
|
||||
UI2_STACK_V_ALIGN_BOTTOM,
|
||||
UI2_STACK_V_ALIGN_SPAN,
|
||||
UI2_STACK_V_ALIGN_DISTRIBUTE,
|
||||
} UI2_STACK_V_ALIGN;
|
||||
|
||||
typedef struct {
|
||||
UI2_STACK_ORIENTATION orientation;
|
||||
struct {
|
||||
UI2_STACK_H_ALIGN h;
|
||||
UI2_STACK_V_ALIGN v;
|
||||
} align;
|
||||
struct {
|
||||
float h;
|
||||
float v;
|
||||
} spacing;
|
||||
} UI2_STACK_SETTINGS;
|
||||
|
||||
void UI2_BeginStack(UI2_STACK_ORIENTATION orientation);
|
||||
void UI2_BeginStackEx(UI2_STACK_SETTINGS settings);
|
||||
void UI2_EndStack(void);
|
|
@ -1,7 +0,0 @@
|
|||
#pragma once
|
||||
|
||||
void UI2_BeginWindow(void);
|
||||
void UI2_EndWindow(void);
|
||||
void UI2_BeginWindowBody(void);
|
||||
void UI2_EndWindowBody(void);
|
||||
void UI2_WindowTitle(const char *title);
|
|
@ -1,22 +0,0 @@
|
|||
#pragma once
|
||||
|
||||
#include "../elements/prompt.h"
|
||||
#include "./console_logs.h"
|
||||
|
||||
// Dev console display widget.
|
||||
|
||||
typedef struct {
|
||||
UI2_CONSOLE_LOGS logs;
|
||||
UI2_PROMPT_STATE prompt;
|
||||
|
||||
int32_t listeners[5];
|
||||
int32_t history_idx;
|
||||
} UI2_CONSOLE_STATE;
|
||||
|
||||
// state functions
|
||||
void UI2_Console_Init(UI2_CONSOLE_STATE *s);
|
||||
void UI2_Console_Free(UI2_CONSOLE_STATE *s);
|
||||
void UI2_Console_Control(UI2_CONSOLE_STATE *s);
|
||||
|
||||
// draw functions
|
||||
void UI2_Console(UI2_CONSOLE_STATE *s);
|
|
@ -201,33 +201,33 @@ sources = [
|
|||
'game/shell/main.c',
|
||||
'game/sound.c',
|
||||
'game/text.c',
|
||||
'game/ui2/common.c',
|
||||
'game/ui2/dialogs/controls.c',
|
||||
'game/ui2/dialogs/controls_backend.c',
|
||||
'game/ui2/dialogs/controls_editor.c',
|
||||
'game/ui2/dialogs/examine_item.c',
|
||||
'game/ui2/dialogs/new_game.c',
|
||||
'game/ui2/dialogs/pause.c',
|
||||
'game/ui2/dialogs/photo_mode.c',
|
||||
'game/ui2/dialogs/stats.c',
|
||||
'game/ui2/elements/anchor.c',
|
||||
'game/ui2/elements/fade.c',
|
||||
'game/ui2/elements/flash.c',
|
||||
'game/ui2/elements/frame.c',
|
||||
'game/ui2/elements/hide.c',
|
||||
'game/ui2/elements/label.c',
|
||||
'game/ui2/elements/modal.c',
|
||||
'game/ui2/elements/pad.c',
|
||||
'game/ui2/elements/prompt.c',
|
||||
'game/ui2/elements/requester.c',
|
||||
'game/ui2/elements/resize.c',
|
||||
'game/ui2/elements/spacer.c',
|
||||
'game/ui2/elements/stack.c',
|
||||
'game/ui2/elements/window.c',
|
||||
'game/ui2/events.c',
|
||||
'game/ui2/helpers.c',
|
||||
'game/ui2/hud/console.c',
|
||||
'game/ui2/hud/console_logs.c',
|
||||
'game/ui/common.c',
|
||||
'game/ui/dialogs/controls.c',
|
||||
'game/ui/dialogs/controls_backend.c',
|
||||
'game/ui/dialogs/controls_editor.c',
|
||||
'game/ui/dialogs/examine_item.c',
|
||||
'game/ui/dialogs/new_game.c',
|
||||
'game/ui/dialogs/pause.c',
|
||||
'game/ui/dialogs/photo_mode.c',
|
||||
'game/ui/dialogs/stats.c',
|
||||
'game/ui/elements/anchor.c',
|
||||
'game/ui/elements/fade.c',
|
||||
'game/ui/elements/flash.c',
|
||||
'game/ui/elements/frame.c',
|
||||
'game/ui/elements/hide.c',
|
||||
'game/ui/elements/label.c',
|
||||
'game/ui/elements/modal.c',
|
||||
'game/ui/elements/pad.c',
|
||||
'game/ui/elements/prompt.c',
|
||||
'game/ui/elements/requester.c',
|
||||
'game/ui/elements/resize.c',
|
||||
'game/ui/elements/spacer.c',
|
||||
'game/ui/elements/stack.c',
|
||||
'game/ui/elements/window.c',
|
||||
'game/ui/events.c',
|
||||
'game/ui/helpers.c',
|
||||
'game/ui/hud/console.c',
|
||||
'game/ui/hud/console_logs.c',
|
||||
'gfx/2d/2d_renderer.c',
|
||||
'gfx/2d/2d_surface.c',
|
||||
'gfx/3d/3d_renderer.c',
|
||||
|
|
|
@ -23,7 +23,7 @@
|
|||
#include <libtrx/config.h>
|
||||
#include <libtrx/debug.h>
|
||||
#include <libtrx/game/interpolation.h>
|
||||
#include <libtrx/game/ui2.h>
|
||||
#include <libtrx/game/ui.h>
|
||||
|
||||
#define FRAME_BUFFER(key) \
|
||||
do { \
|
||||
|
@ -66,7 +66,7 @@ void Game_ProcessInput(void)
|
|||
}
|
||||
|
||||
if (g_InputDB.toggle_ui) {
|
||||
UI2_ToggleState(&g_Config.ui.enable_game_ui);
|
||||
UI_ToggleState(&g_Config.ui.enable_game_ui);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -8,7 +8,7 @@
|
|||
#include "global/vars.h"
|
||||
|
||||
#include <libtrx/config.h>
|
||||
#include <libtrx/game/ui2.h>
|
||||
#include <libtrx/game/ui.h>
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
|
@ -16,7 +16,7 @@
|
|||
typedef struct {
|
||||
struct {
|
||||
bool is_ready;
|
||||
UI2_STATS_DIALOG_STATE state;
|
||||
UI_STATS_DIALOG_STATE state;
|
||||
} ui;
|
||||
} M_PRIV;
|
||||
|
||||
|
@ -31,11 +31,11 @@ static void M_Shutdown(M_PRIV *p);
|
|||
static void M_Init(M_PRIV *const p)
|
||||
{
|
||||
p->ui.is_ready = true;
|
||||
UI2_StatsDialog_Init(
|
||||
UI_StatsDialog_Init(
|
||||
&p->ui.state,
|
||||
(UI2_STATS_DIALOG_ARGS) {
|
||||
.mode = UI2_STATS_DIALOG_MODE_LEVEL,
|
||||
.style = UI2_STATS_DIALOG_STYLE_BORDERED,
|
||||
(UI_STATS_DIALOG_ARGS) {
|
||||
.mode = UI_STATS_DIALOG_MODE_LEVEL,
|
||||
.style = UI_STATS_DIALOG_STYLE_BORDERED,
|
||||
.level_num = Game_GetCurrentLevel()->num,
|
||||
});
|
||||
}
|
||||
|
@ -44,7 +44,7 @@ static void M_Shutdown(M_PRIV *const p)
|
|||
{
|
||||
if (p->ui.is_ready) {
|
||||
p->ui.is_ready = false;
|
||||
UI2_StatsDialog_Free(&p->ui.state);
|
||||
UI_StatsDialog_Free(&p->ui.state);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -58,7 +58,7 @@ void Option_Compass_Control(INVENTORY_ITEM *const inv_item, const bool is_busy)
|
|||
if (!p->ui.is_ready && g_Config.gameplay.enable_compass_stats) {
|
||||
M_Init(p);
|
||||
}
|
||||
UI2_StatsDialog_Control(&p->ui.state);
|
||||
UI_StatsDialog_Control(&p->ui.state);
|
||||
|
||||
if (g_InputDB.menu_confirm || g_InputDB.menu_back) {
|
||||
M_Shutdown(p);
|
||||
|
@ -71,7 +71,7 @@ void Option_Compass_Draw(void)
|
|||
{
|
||||
M_PRIV *const p = &m_Priv;
|
||||
if (p->ui.is_ready) {
|
||||
UI2_StatsDialog(&p->ui.state);
|
||||
UI_StatsDialog(&p->ui.state);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -3,14 +3,14 @@
|
|||
#include "game/input.h"
|
||||
|
||||
#include <libtrx/game/objects/names.h>
|
||||
#include <libtrx/game/ui2.h>
|
||||
#include <libtrx/game/ui.h>
|
||||
|
||||
#define MAX_LINES 10
|
||||
|
||||
typedef struct {
|
||||
struct {
|
||||
bool is_ready;
|
||||
UI2_EXAMINE_ITEM_STATE state;
|
||||
UI_EXAMINE_ITEM_STATE state;
|
||||
} ui;
|
||||
} M_PRIV;
|
||||
|
||||
|
@ -22,7 +22,7 @@ static void M_Shutdown(M_PRIV *p);
|
|||
static void M_Init(M_PRIV *const p, const GAME_OBJECT_ID obj_id)
|
||||
{
|
||||
p->ui.is_ready = true;
|
||||
UI2_ExamineItem_Init(
|
||||
UI_ExamineItem_Init(
|
||||
&p->ui.state, Object_GetName(obj_id), Object_GetDescription(obj_id),
|
||||
MAX_LINES);
|
||||
}
|
||||
|
@ -30,7 +30,7 @@ static void M_Init(M_PRIV *const p, const GAME_OBJECT_ID obj_id)
|
|||
static void M_Shutdown(M_PRIV *const p)
|
||||
{
|
||||
if (p->ui.is_ready) {
|
||||
UI2_ExamineItem_Free(&p->ui.state);
|
||||
UI_ExamineItem_Free(&p->ui.state);
|
||||
p->ui.is_ready = false;
|
||||
}
|
||||
}
|
||||
|
@ -56,7 +56,7 @@ void Option_Examine_Control(const GAME_OBJECT_ID obj_id, const bool is_busy)
|
|||
if (!p->ui.is_ready) {
|
||||
M_Init(p, obj_id);
|
||||
}
|
||||
UI2_ExamineItem_Control(&p->ui.state);
|
||||
UI_ExamineItem_Control(&p->ui.state);
|
||||
|
||||
if (g_InputDB.menu_back || g_InputDB.menu_confirm) {
|
||||
M_Shutdown(p);
|
||||
|
@ -67,7 +67,7 @@ void Option_Examine_Draw(void)
|
|||
{
|
||||
M_PRIV *const p = &m_Priv;
|
||||
if (p->ui.is_ready) {
|
||||
UI2_ExamineItem(&p->ui.state);
|
||||
UI_ExamineItem(&p->ui.state);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -14,7 +14,7 @@
|
|||
#include "global/vars.h"
|
||||
|
||||
#include <libtrx/config.h>
|
||||
#include <libtrx/game/ui2.h>
|
||||
#include <libtrx/game/ui.h>
|
||||
#include <libtrx/memory.h>
|
||||
|
||||
#include <stdint.h>
|
||||
|
@ -52,7 +52,7 @@ static struct {
|
|||
M_PAGE_NUMBER active_page;
|
||||
struct {
|
||||
bool is_ready;
|
||||
UI2_NEW_GAME_STATE state;
|
||||
UI_NEW_GAME_STATE state;
|
||||
} new_game;
|
||||
} m_State = {
|
||||
.current_page = PAGE_1,
|
||||
|
@ -130,12 +130,12 @@ static void M_InitRequesters(void)
|
|||
Requester_Init(&g_SavegameRequester, Savegame_GetSlotCount());
|
||||
Requester_Init(
|
||||
&m_SelectLevelRequester, g_GameFlow.level_tables[GFLT_MAIN].count + 1);
|
||||
UI2_NewGame_Init(&m_State.new_game.state);
|
||||
UI_NewGame_Init(&m_State.new_game.state);
|
||||
}
|
||||
|
||||
static void M_FreeRequesters(void)
|
||||
{
|
||||
UI2_NewGame_Free(&m_State.new_game.state);
|
||||
UI_NewGame_Free(&m_State.new_game.state);
|
||||
m_State.new_game.is_ready = false;
|
||||
}
|
||||
|
||||
|
@ -541,11 +541,11 @@ static void M_NewGame(void)
|
|||
g_GameInfo.passport_selection = PASSPORT_MODE_NEW_GAME;
|
||||
}
|
||||
} else if (m_State.mode == PASSPORT_MODE_NEW_GAME) {
|
||||
const int32_t choice = UI2_NewGame_Control(&m_State.new_game.state);
|
||||
if (choice == UI2_REQUESTER_NO_CHOICE) {
|
||||
const int32_t choice = UI_NewGame_Control(&m_State.new_game.state);
|
||||
if (choice == UI_REQUESTER_NO_CHOICE) {
|
||||
g_Input = (INPUT_STATE) {};
|
||||
g_InputDB = (INPUT_STATE) {};
|
||||
} else if (choice == UI2_REQUESTER_CANCEL) {
|
||||
} else if (choice == UI_REQUESTER_CANCEL) {
|
||||
m_State.new_game.is_ready = false;
|
||||
m_State.mode = PASSPORT_MODE_BROWSE;
|
||||
g_Input = (INPUT_STATE) {};
|
||||
|
@ -719,7 +719,7 @@ void Option_Passport_Draw(INVENTORY_ITEM *const item)
|
|||
switch (m_State.pages[m_State.active_page].role) {
|
||||
case PASSPORT_MODE_NEW_GAME:
|
||||
if (m_State.new_game.is_ready) {
|
||||
UI2_NewGame(&m_State.new_game.state);
|
||||
UI_NewGame(&m_State.new_game.state);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
|
|
|
@ -26,7 +26,7 @@
|
|||
#include <libtrx/filesystem.h>
|
||||
#include <libtrx/game/game_buf.h>
|
||||
#include <libtrx/game/game_string_table.h>
|
||||
#include <libtrx/game/ui2.h>
|
||||
#include <libtrx/game/ui.h>
|
||||
#include <libtrx/memory.h>
|
||||
#include <libtrx/strings.h>
|
||||
|
||||
|
@ -159,7 +159,7 @@ void Shell_Shutdown(void)
|
|||
Input_Shutdown();
|
||||
Music_Shutdown();
|
||||
Sound_Shutdown();
|
||||
UI2_Shutdown();
|
||||
UI_Shutdown();
|
||||
Text_Shutdown();
|
||||
Config_Shutdown();
|
||||
Log_Shutdown();
|
||||
|
@ -184,7 +184,7 @@ void Shell_Main(void)
|
|||
Config_Init();
|
||||
|
||||
Text_Init();
|
||||
UI2_Init();
|
||||
UI_Init();
|
||||
|
||||
Input_Init();
|
||||
Sound_Init();
|
||||
|
|
|
@ -1,24 +1,24 @@
|
|||
#include "game/screen.h"
|
||||
|
||||
#include <libtrx/config.h>
|
||||
#include <libtrx/game/ui2/common.h>
|
||||
#include <libtrx/game/ui/common.h>
|
||||
|
||||
int32_t UI2_GetCanvasWidth(void)
|
||||
int32_t UI_GetCanvasWidth(void)
|
||||
{
|
||||
return Screen_GetResHeightDownscaled(RSR_GENERIC) * 16 / 9;
|
||||
}
|
||||
|
||||
int32_t UI2_GetCanvasHeight(void)
|
||||
int32_t UI_GetCanvasHeight(void)
|
||||
{
|
||||
return Screen_GetResHeightDownscaled(RSR_GENERIC);
|
||||
}
|
||||
|
||||
float UI2_ScaleX(const float x)
|
||||
float UI_ScaleX(const float x)
|
||||
{
|
||||
return Screen_GetRenderScale(x * 0x10000, RSR_GENERIC) / (float)0x10000;
|
||||
}
|
||||
|
||||
float UI2_ScaleY(const float y)
|
||||
float UI_ScaleY(const float y)
|
||||
{
|
||||
return Screen_GetRenderScale(y * 0x10000, RSR_GENERIC) / (float)0x10000;
|
||||
}
|
|
@ -1,4 +1,4 @@
|
|||
#include "game/ui2/dialogs/stats.h"
|
||||
#include "game/ui/dialogs/stats.h"
|
||||
|
||||
#include "game/game_flow.h"
|
||||
#include "game/game_string.h"
|
||||
|
@ -6,13 +6,13 @@
|
|||
#include "game/stats.h"
|
||||
|
||||
#include <libtrx/config.h>
|
||||
#include <libtrx/game/ui2/common.h>
|
||||
#include <libtrx/game/ui2/elements/anchor.h>
|
||||
#include <libtrx/game/ui2/elements/frame.h>
|
||||
#include <libtrx/game/ui2/elements/label.h>
|
||||
#include <libtrx/game/ui2/elements/modal.h>
|
||||
#include <libtrx/game/ui2/elements/stack.h>
|
||||
#include <libtrx/game/ui2/elements/window.h>
|
||||
#include <libtrx/game/ui/common.h>
|
||||
#include <libtrx/game/ui/elements/anchor.h>
|
||||
#include <libtrx/game/ui/elements/frame.h>
|
||||
#include <libtrx/game/ui/elements/label.h>
|
||||
#include <libtrx/game/ui/elements/modal.h>
|
||||
#include <libtrx/game/ui/elements/stack.h>
|
||||
#include <libtrx/game/ui/elements/window.h>
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
@ -31,17 +31,16 @@ typedef enum {
|
|||
static void M_FormatTime(char *out, int32_t total_frames);
|
||||
static void M_FormatDistance(char *const out, int32_t distance);
|
||||
static void M_Row(
|
||||
const UI2_STATS_DIALOG_STATE *s, const char *key, const char *value);
|
||||
const UI_STATS_DIALOG_STATE *s, const char *key, const char *value);
|
||||
static void M_RowFromRole(
|
||||
const UI2_STATS_DIALOG_STATE *s, M_ROW_ROLE role,
|
||||
const STATS_COMMON *stats);
|
||||
const UI_STATS_DIALOG_STATE *s, M_ROW_ROLE role, const STATS_COMMON *stats);
|
||||
static void M_CommonRows(
|
||||
const UI2_STATS_DIALOG_STATE *s, const STATS_COMMON *stats);
|
||||
static void M_LevelStatsRows(const UI2_STATS_DIALOG_STATE *s);
|
||||
static void M_FinalStatsRows(const UI2_STATS_DIALOG_STATE *s);
|
||||
static const char *M_GetDialogTitle(const UI2_STATS_DIALOG_STATE *s);
|
||||
static void M_BeginDialog(const UI2_STATS_DIALOG_STATE *s);
|
||||
static void M_EndDialog(const UI2_STATS_DIALOG_STATE *s);
|
||||
const UI_STATS_DIALOG_STATE *s, const STATS_COMMON *stats);
|
||||
static void M_LevelStatsRows(const UI_STATS_DIALOG_STATE *s);
|
||||
static void M_FinalStatsRows(const UI_STATS_DIALOG_STATE *s);
|
||||
static const char *M_GetDialogTitle(const UI_STATS_DIALOG_STATE *s);
|
||||
static void M_BeginDialog(const UI_STATS_DIALOG_STATE *s);
|
||||
static void M_EndDialog(const UI_STATS_DIALOG_STATE *s);
|
||||
|
||||
static void M_FormatTime(char *const out, const int32_t total_frames)
|
||||
{
|
||||
|
@ -67,29 +66,29 @@ static void M_FormatDistance(char *const out, int32_t distance)
|
|||
}
|
||||
|
||||
static void M_Row(
|
||||
const UI2_STATS_DIALOG_STATE *const s, const char *const key,
|
||||
const UI_STATS_DIALOG_STATE *const s, const char *const key,
|
||||
const char *const value)
|
||||
{
|
||||
if (s->args.style == UI2_STATS_DIALOG_STYLE_BARE) {
|
||||
UI2_BeginStack(UI2_STACK_HORIZONTAL);
|
||||
UI2_Label(key);
|
||||
UI2_Label(" ");
|
||||
UI2_Label(value);
|
||||
UI2_EndStack();
|
||||
if (s->args.style == UI_STATS_DIALOG_STYLE_BARE) {
|
||||
UI_BeginStack(UI_STACK_HORIZONTAL);
|
||||
UI_Label(key);
|
||||
UI_Label(" ");
|
||||
UI_Label(value);
|
||||
UI_EndStack();
|
||||
} else {
|
||||
UI2_BeginStackEx((UI2_STACK_SETTINGS) {
|
||||
.orientation = UI2_STACK_HORIZONTAL,
|
||||
UI_BeginStackEx((UI_STACK_SETTINGS) {
|
||||
.orientation = UI_STACK_HORIZONTAL,
|
||||
.spacing = { .h = 30.0f },
|
||||
.align = { .h = UI2_STACK_H_ALIGN_DISTRIBUTE },
|
||||
.align = { .h = UI_STACK_H_ALIGN_DISTRIBUTE },
|
||||
});
|
||||
UI2_Label(key);
|
||||
UI2_Label(value);
|
||||
UI2_EndStack();
|
||||
UI_Label(key);
|
||||
UI_Label(value);
|
||||
UI_EndStack();
|
||||
}
|
||||
}
|
||||
|
||||
static void M_RowFromRole(
|
||||
const UI2_STATS_DIALOG_STATE *const s, const M_ROW_ROLE role,
|
||||
const UI_STATS_DIALOG_STATE *const s, const M_ROW_ROLE role,
|
||||
const STATS_COMMON *const stats)
|
||||
{
|
||||
char buf[50];
|
||||
|
@ -147,7 +146,7 @@ static void M_RowFromRole(
|
|||
}
|
||||
|
||||
static void M_CommonRows(
|
||||
const UI2_STATS_DIALOG_STATE *const s, const STATS_COMMON *const stats)
|
||||
const UI_STATS_DIALOG_STATE *const s, const STATS_COMMON *const stats)
|
||||
{
|
||||
if (g_Config.gameplay.stat_detail_mode == SDM_MINIMAL) {
|
||||
M_RowFromRole(s, M_ROW_KILLS, stats);
|
||||
|
@ -175,7 +174,7 @@ static void M_CommonRows(
|
|||
}
|
||||
}
|
||||
|
||||
static void M_LevelStatsRows(const UI2_STATS_DIALOG_STATE *const s)
|
||||
static void M_LevelStatsRows(const UI_STATS_DIALOG_STATE *const s)
|
||||
{
|
||||
const GF_LEVEL *const current_level =
|
||||
GF_GetLevel(GFLT_MAIN, s->args.level_num);
|
||||
|
@ -185,7 +184,7 @@ static void M_LevelStatsRows(const UI2_STATS_DIALOG_STATE *const s)
|
|||
M_CommonRows(s, stats);
|
||||
}
|
||||
|
||||
static void M_FinalStatsRows(const UI2_STATS_DIALOG_STATE *const s)
|
||||
static void M_FinalStatsRows(const UI_STATS_DIALOG_STATE *const s)
|
||||
{
|
||||
FINAL_STATS final_stats;
|
||||
const GF_LEVEL_TYPE level_type =
|
||||
|
@ -194,13 +193,13 @@ static void M_FinalStatsRows(const UI2_STATS_DIALOG_STATE *const s)
|
|||
M_CommonRows(s, (STATS_COMMON *)&final_stats);
|
||||
}
|
||||
|
||||
static const char *M_GetDialogTitle(const UI2_STATS_DIALOG_STATE *const s)
|
||||
static const char *M_GetDialogTitle(const UI_STATS_DIALOG_STATE *const s)
|
||||
{
|
||||
switch (s->args.mode) {
|
||||
case UI2_STATS_DIALOG_MODE_LEVEL:
|
||||
case UI_STATS_DIALOG_MODE_LEVEL:
|
||||
return GF_GetLevel(GFLT_MAIN, s->args.level_num)->title;
|
||||
|
||||
case UI2_STATS_DIALOG_MODE_FINAL: {
|
||||
case UI_STATS_DIALOG_MODE_FINAL: {
|
||||
const GF_LEVEL_TYPE level_type =
|
||||
GF_GetLevel(GFLT_MAIN, s->args.level_num)->type;
|
||||
if (level_type == GFL_BONUS) {
|
||||
|
@ -213,54 +212,54 @@ static const char *M_GetDialogTitle(const UI2_STATS_DIALOG_STATE *const s)
|
|||
return nullptr;
|
||||
}
|
||||
|
||||
static void M_BeginDialog(const UI2_STATS_DIALOG_STATE *const s)
|
||||
static void M_BeginDialog(const UI_STATS_DIALOG_STATE *const s)
|
||||
{
|
||||
const char *const title = M_GetDialogTitle(s);
|
||||
UI2_BeginModal(0.5f, 0.5f);
|
||||
if (s->args.style == UI2_STATS_DIALOG_STYLE_BARE) {
|
||||
UI2_BeginStackEx((UI2_STACK_SETTINGS) {
|
||||
.orientation = UI2_STACK_VERTICAL,
|
||||
UI_BeginModal(0.5f, 0.5f);
|
||||
if (s->args.style == UI_STATS_DIALOG_STYLE_BARE) {
|
||||
UI_BeginStackEx((UI_STACK_SETTINGS) {
|
||||
.orientation = UI_STACK_VERTICAL,
|
||||
.spacing = { .v = 11.0f },
|
||||
.align = { .h = UI2_STACK_H_ALIGN_CENTER },
|
||||
.align = { .h = UI_STACK_H_ALIGN_CENTER },
|
||||
});
|
||||
if (title != nullptr) {
|
||||
UI2_Label(title);
|
||||
UI_Label(title);
|
||||
}
|
||||
} else {
|
||||
UI2_BeginWindow();
|
||||
UI_BeginWindow();
|
||||
if (title != nullptr) {
|
||||
UI2_WindowTitle(title);
|
||||
UI_WindowTitle(title);
|
||||
}
|
||||
UI2_BeginWindowBody();
|
||||
UI2_BeginStackEx((UI2_STACK_SETTINGS) {
|
||||
.orientation = UI2_STACK_VERTICAL,
|
||||
UI_BeginWindowBody();
|
||||
UI_BeginStackEx((UI_STACK_SETTINGS) {
|
||||
.orientation = UI_STACK_VERTICAL,
|
||||
.spacing = { .v = 4.0f },
|
||||
.align = { .h = UI2_STACK_H_ALIGN_SPAN },
|
||||
.align = { .h = UI_STACK_H_ALIGN_SPAN },
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
static void M_EndDialog(const UI2_STATS_DIALOG_STATE *const s)
|
||||
static void M_EndDialog(const UI_STATS_DIALOG_STATE *const s)
|
||||
{
|
||||
if (s->args.style == UI2_STATS_DIALOG_STYLE_BARE) {
|
||||
UI2_EndStack();
|
||||
if (s->args.style == UI_STATS_DIALOG_STYLE_BARE) {
|
||||
UI_EndStack();
|
||||
} else {
|
||||
UI2_EndStack();
|
||||
UI2_EndWindowBody();
|
||||
UI2_EndWindow();
|
||||
UI_EndStack();
|
||||
UI_EndWindowBody();
|
||||
UI_EndWindow();
|
||||
}
|
||||
UI2_EndModal();
|
||||
UI_EndModal();
|
||||
}
|
||||
|
||||
void UI2_StatsDialog(UI2_STATS_DIALOG_STATE *const s)
|
||||
void UI_StatsDialog(UI_STATS_DIALOG_STATE *const s)
|
||||
{
|
||||
M_BeginDialog(s);
|
||||
|
||||
switch (s->args.mode) {
|
||||
case UI2_STATS_DIALOG_MODE_LEVEL:
|
||||
case UI_STATS_DIALOG_MODE_LEVEL:
|
||||
M_LevelStatsRows(s);
|
||||
break;
|
||||
case UI2_STATS_DIALOG_MODE_FINAL:
|
||||
case UI_STATS_DIALOG_MODE_FINAL:
|
||||
M_FinalStatsRows(s);
|
||||
break;
|
||||
}
|
3
src/tr1/game/ui/dialogs/stats.h
Normal file
3
src/tr1/game/ui/dialogs/stats.h
Normal file
|
@ -0,0 +1,3 @@
|
|||
#pragma once
|
||||
|
||||
#include <libtrx/game/ui/dialogs/stats.h>
|
Some files were not shown because too many files have changed in this diff Show more
Loading…
Add table
Add a link
Reference in a new issue