ui: move select level dialog to libtrx

This commit is contained in:
Marcin Kurczewski 2025-04-20 00:33:40 +02:00
parent 7f574c9448
commit f23a777f64
12 changed files with 59 additions and 33 deletions

View file

@ -625,6 +625,8 @@
"PASSPORT_EXIT_DEMO": "Exit Demo",
"PASSPORT_EXIT_GAME": "Exit Game",
"PASSPORT_EXIT_TO_TITLE": "Exit to Title",
"PASSPORT_LEGACY_SELECT_LEVEL_1": "Legacy saves do not",
"PASSPORT_LEGACY_SELECT_LEVEL_2": "support this feature.",
"PASSPORT_LOAD_GAME": "Load Game",
"PASSPORT_MODE_NEW_GAME": "New Game",
"PASSPORT_MODE_NEW_GAME_JP": "Japanese NG",
@ -634,6 +636,7 @@
"PASSPORT_SAVE_GAME": "Save Game",
"PASSPORT_SELECT_LEVEL": "Select Level",
"PASSPORT_SELECT_MODE": "Select Mode",
"PASSPORT_STORY_SO_FAR": "Story so far...",
"PAUSE_ARE_YOU_SURE": "Are you sure?",
"PAUSE_CONTINUE": "Continue",
"PAUSE_EXIT_TO_TITLE": "Exit to title?",

View file

@ -1,24 +1,30 @@
#include "game/ui/dialogs/select_level.h"
#include "debug.h"
#include "game/game_flow.h"
#include "game/game_string.h"
#include "game/savegame.h"
#include "game/screen.h"
#include "global/vars.h"
#include "game/scaler.h"
#include "game/ui/common.h"
#include "game/ui/elements/anchor.h"
#include "game/ui/elements/hide.h"
#include "game/ui/elements/label.h"
#include "game/ui/elements/modal.h"
#include "game/ui/elements/offset.h"
#include "game/ui/elements/requester.h"
#include "game/ui/elements/resize.h"
#include "game/ui/elements/spacer.h"
#include "game/ui/elements/stack.h"
#include "game/viewport.h"
#include "memory.h"
#include "vector.h"
#include <libtrx/debug.h>
#include <libtrx/game/ui/common.h>
#include <libtrx/game/ui/elements/anchor.h>
#include <libtrx/game/ui/elements/hide.h>
#include <libtrx/game/ui/elements/label.h>
#include <libtrx/game/ui/elements/modal.h>
#include <libtrx/game/ui/elements/offset.h>
#include <libtrx/game/ui/elements/requester.h>
#include <libtrx/game/ui/elements/resize.h>
#include <libtrx/game/ui/elements/spacer.h>
#include <libtrx/game/ui/elements/stack.h>
#include <libtrx/memory.h>
#include <libtrx/vector.h>
// TODO: consolidate this variable
#if TR_VERSION == 1
extern int32_t g_InvMode;
#else
extern int32_t g_Inv_Mode;
#endif
typedef enum {
M_ROW_ROLE_PLAY_LEVEL,
@ -41,15 +47,20 @@ static int32_t M_GetVisibleRows(void);
static int32_t M_GetVisibleRows(void)
{
const int32_t res_h = Screen_GetResHeightDownscaled(RSR_TEXT);
if (res_h <= 240) {
return 5;
} else if (res_h <= 384) {
return 7;
} else if (res_h <= 480) {
if (TR_VERSION == 2) {
return 10;
} else {
return 12;
const int32_t res_h =
Scaler_CalcInverse(Viewport_GetHeight(), SCALER_TARGET_TEXT);
if (res_h <= 240) {
return 5;
} else if (res_h <= 384) {
return 7;
} else if (res_h <= 480) {
return 10;
} else {
return 12;
}
}
}
@ -80,7 +91,12 @@ UI_SELECT_LEVEL_DIALOG_STATE *UI_SelectLevelDialog_Init(const int32_t save_slot)
}
}
if (g_InvMode == INV_TITLE_MODE && GF_HasAvailableStory(save_slot)) {
#if TR_VERSION == 1
const INVENTORY_MODE inv_mode = g_InvMode;
#else
const INVENTORY_MODE inv_mode = g_Inv_Mode;
#endif
if (inv_mode == INV_TITLE_MODE && GF_HasAvailableStory(save_slot)) {
Vector_Add(
s->rows,
&(M_ROW) {
@ -120,7 +136,12 @@ int32_t UI_SelectLevelDialog_Control(UI_SELECT_LEVEL_DIALOG_STATE *const s)
void UI_SelectLevelDialog(UI_SELECT_LEVEL_DIALOG_STATE *const s)
{
UI_BeginModal(0.5f, g_InvMode == INV_TITLE_MODE ? 0.72f : 0.55f);
#if TR_VERSION == 1
const float modal_y = g_InvMode == INV_TITLE_MODE ? 0.72f : 0.55f;
#else
const float modal_y = g_Inv_Mode == INV_TITLE_MODE ? 0.8f : 0.65f;
#endif
UI_BeginModal(0.5f, modal_y);
UI_BeginResize(300.0f, -1.0f);
UI_BeginRequester(&s->req, GS(PASSPORT_SELECT_LEVEL));

View file

@ -129,6 +129,9 @@ GS_DEFINE(PASSPORT_MODE_NEW_GAME, "New Game")
GS_DEFINE(PASSPORT_MODE_NEW_GAME_PLUS, "New Game+")
GS_DEFINE(PASSPORT_MODE_NEW_GAME_JP, "Japanese NG")
GS_DEFINE(PASSPORT_MODE_NEW_GAME_JP_PLUS, "Japanese NG+")
GS_DEFINE(PASSPORT_STORY_SO_FAR, "Story so far...")
GS_DEFINE(PASSPORT_LEGACY_SELECT_LEVEL_1, "Legacy saves do not")
GS_DEFINE(PASSPORT_LEGACY_SELECT_LEVEL_2, "support this feature.")
GS_DEFINE(SOUND_SET_VOLUMES, "Set Volumes")
GS_DEFINE(OSD_TRAPEZOID_FILTER_ON, "Trapezoid filter enabled")
GS_DEFINE(OSD_TRAPEZOID_FILTER_OFF, "Trapezoid filter disabled")

View file

@ -54,12 +54,10 @@ typedef struct {
int32_t level_num;
char *level_title;
int16_t initial_version;
#if TR_VERSION == 1
struct {
bool restart;
bool select_level;
} features;
#endif
} SAVEGAME_INFO;
typedef struct {

View file

@ -8,6 +8,7 @@
#include "./ui/dialogs/pause.h"
#include "./ui/dialogs/photo_mode.h"
#include "./ui/dialogs/save_slot.h"
#include "./ui/dialogs/select_level.h"
#include "./ui/dialogs/stats.h"
#include "./ui/elements/anchor.h"
#include "./ui/elements/fade.h"

View file

@ -2,7 +2,7 @@
#pragma once
#include <libtrx/game/ui/common.h>
#include "../common.h"
#include <stdint.h>

View file

@ -211,6 +211,7 @@ sources = [
'game/ui/dialogs/pause.c',
'game/ui/dialogs/photo_mode.c',
'game/ui/dialogs/save_slot.c',
'game/ui/dialogs/select_level.c',
'game/ui/dialogs/stats.c',
'game/ui/elements/anchor.c',
'game/ui/elements/fade.c',
@ -241,8 +242,8 @@ sources = [
'gfx/gl/buffer.c',
'gfx/gl/program.c',
'gfx/gl/sampler.c',
'gfx/gl/track.c',
'gfx/gl/texture.c',
'gfx/gl/track.c',
'gfx/gl/utils.c',
'gfx/gl/vertex_array.c',
'gfx/renderers/fbo_renderer.c',

View file

@ -1,7 +1,4 @@
GS_DEFINE(PASSPORT_RESTART_LEVEL, "Restart Level")
GS_DEFINE(PASSPORT_STORY_SO_FAR, "Story so far...")
GS_DEFINE(PASSPORT_LEGACY_SELECT_LEVEL_1, "Legacy saves do not")
GS_DEFINE(PASSPORT_LEGACY_SELECT_LEVEL_2, "support this feature.")
GS_DEFINE(DETAIL_REFLECTIONS, "Reflections")
GS_DEFINE(DETAIL_FBO_FILTER, "FBO filter")
GS_DEFINE(DETAIL_VSYNC, "VSync")

View file

@ -9,7 +9,6 @@
#include "game/screen.h"
#include "game/sound.h"
#include "game/text.h"
#include "game/ui/dialogs/select_level.h"
#include "global/const.h"
#include "global/vars.h"

View file

@ -262,7 +262,6 @@ sources = [
'game/stats/common.c',
'game/text.c',
'game/ui/common.c',
'game/ui/dialogs/select_level.c',
'game/ui/dialogs/stats.c',
'game/viewport.c',
'global/enum_map.c',

View file

@ -102,6 +102,8 @@ static bool M_FillInfo(MYFILE *const fp, SAVEGAME_INFO *const info)
File_Seek(fp, 0, FILE_SEEK_SET);
File_ReadData(fp, &header, sizeof(SAVEGAME_BSON_HEADER));
info->initial_version = header.initial_version;
info->features.restart = false;
info->features.select_level = false;
File_Skip(fp, header.compressed_size);
SAVEGAME_BSON_EXTENDED_HEADER extra_header;

View file

@ -717,6 +717,8 @@ static bool M_FillInfo(MYFILE *const fp, SAVEGAME_INFO *const savegame_info)
savegame_info->level_num = File_ReadS16(fp);
savegame_info->initial_version = VERSION_LEGACY;
savegame_info->features.restart = false;
savegame_info->features.select_level = false;
return true;
}