Add persistent options menu and restyle title screen
Full-screen translucent FBC-style menu with BRIEFING/OPTIONS tabs, resolution (720p/900p/1080p/4K), RAW/POST FX, unlocked FPS and hidden dev UI. Settings persist to cntrl.cfg, CLI overrides stay authoritative, render targets resize with resolution. Adds settings unit test and README docs.
This commit is contained in:
parent
da0d157e29
commit
64610a2e89
9 changed files with 845 additions and 86 deletions
|
|
@ -45,6 +45,10 @@ add_executable(debug_test tests/debug_test.cpp)
|
|||
target_link_libraries(debug_test PRIVATE level_core)
|
||||
add_test(NAME debug_trace_toggle COMMAND debug_test)
|
||||
|
||||
add_executable(settings_test tests/settings_test.cpp src/render/settings.cpp)
|
||||
target_link_libraries(settings_test PRIVATE level_core)
|
||||
add_test(NAME settings_defaults_and_roundtrip COMMAND settings_test)
|
||||
|
||||
add_executable(level_binary_test tests/level_binary_test.cpp)
|
||||
target_link_libraries(level_binary_test PRIVATE level_core)
|
||||
add_test(NAME level_binary_roundtrip COMMAND level_binary_test)
|
||||
|
|
@ -178,6 +182,7 @@ add_executable(cntrl
|
|||
src/render/aura.cpp
|
||||
src/render/profiler.cpp
|
||||
src/render/graphics_settings.cpp
|
||||
src/render/settings.cpp
|
||||
src/render/ui.cpp)
|
||||
|
||||
target_include_directories(cntrl PRIVATE src third_party/raygui third_party/clay)
|
||||
|
|
|
|||
15
README.md
15
README.md
|
|
@ -17,13 +17,26 @@ You are a nameless FBC worker who never resonated. Your Objects of Power have a
|
|||
|
||||
```sh
|
||||
cmake -B build && cmake --build build -j6
|
||||
./build/cntrl --seed 42 # 1400×900 default
|
||||
./build/cntrl --seed 42 # 900p default, raw look
|
||||
./build/cntrl --seed 42 --post-fx # graded + bloom
|
||||
./build/cntrl --seed 42 --shadows off # compare lighting
|
||||
```
|
||||
|
||||
C++23 (GCC 13+) and OpenGL/X11 headers; raylib 6.2 is fetched by CMake. Automated captures: `--screenshot /tmp/shot.png --screenshot-at 8`. Dev QA: `--skill-test` (staged CALL/WARP casts for VFX captures), `--floor-overview`, `--beacon-test`, `--plaza-test`, `--bot`, `--no-damage`, `--trace all`; full flag list in `src/main.cpp`. F12 saves a screenshot.
|
||||
|
||||
## Title screen & options
|
||||
|
||||
The title screen has **BRIEFING** and **OPTIONS** tabs (`Tab`/Select to switch, mouse click, or Left/Right from the briefing). Options persist to `cntrl.cfg` in the working directory and apply immediately:
|
||||
|
||||
| Option | Values | Default |
|
||||
|---|---|---|
|
||||
| Resolution | 720p / 900p / 1080p / 4K (clamped to the monitor) | 900p |
|
||||
| Rendering | RAW / POST FX | RAW |
|
||||
| Frame rate | 60 FPS / Unlocked | 60 FPS |
|
||||
| Dev UI | Visible / Hidden (profile, camera dev, HUD debug counters) | Hidden |
|
||||
|
||||
In Options: Up/Down select, Left/Right change a value, Enter/A apply, Esc/B go back, and **DEFAULTS** restores the shipped settings. CLI overrides (for reproducible captures) are `--720p`, `--900p`, `--1080p`, `--4k`, `--raw`, `--post-fx`, `--unlock-fps` (alias `--uncapped`), `--dev-ui`, `--hide-dev-ui`, and `--menu-options` (opens the Options tab for QA). `--dev` keeps the compact 1400x900 test window.
|
||||
|
||||
## Controls
|
||||
|
||||
| Input | Action |
|
||||
|
|
|
|||
164
src/main.cpp
164
src/main.cpp
|
|
@ -20,30 +20,42 @@
|
|||
#include "render/ui_font.hpp"
|
||||
#include "render/profiler.hpp"
|
||||
#include "render/graphics_settings.hpp"
|
||||
#include "render/settings.hpp"
|
||||
|
||||
namespace {
|
||||
|
||||
constexpr float kFixedDt = 1.0f / 60.0f;
|
||||
// 1400x900 fits under the monitor chrome on a 1080p display without the
|
||||
// window clamp scaling it down. 720p/1080p stay as explicit test resolutions.
|
||||
constexpr const char* kOptionsPath = "cntrl.cfg";
|
||||
// 900p is the shipped default; 1400x900 remains the compact dev window that
|
||||
// fits under monitor chrome on a 1080p display.
|
||||
constexpr int k900pWidth = 1600;
|
||||
constexpr int k900pHeight = 900;
|
||||
constexpr int kDevWidth = 1400;
|
||||
constexpr int kDevHeight = 900;
|
||||
constexpr int k1080pWidth = 1920;
|
||||
constexpr int k1080pHeight = 1080;
|
||||
constexpr int k720pWidth = 1280;
|
||||
constexpr int k720pHeight = 720;
|
||||
constexpr int k4kWidth = 3840;
|
||||
constexpr int k4kHeight = 2160;
|
||||
|
||||
struct Options {
|
||||
std::uint64_t seed = 0xC0FFEEULL;
|
||||
int width = kDevWidth; // dev default; --720p/--1080p for testing
|
||||
int height = kDevHeight;
|
||||
int width = k900pWidth; // shipped default; presets override
|
||||
int height = k900pHeight;
|
||||
const char* screenshot_path = nullptr; // --screenshot <path>: capture the framebuffer
|
||||
float screenshot_at = 3.0f; // --screenshot-at <sec>: when to capture
|
||||
bool bot = false; // --bot: kiting autopilot (M6 balance-bot seed)
|
||||
bool no_damage = false; // --no-damage: stress-test mode
|
||||
bool post_fx = false; // --post-fx: opt into graded/bloomed look
|
||||
bool post_fx = false; // --post-fx / --raw: render mode override
|
||||
bool post_fx_set = false; // was a render mode passed on the CLI?
|
||||
bool shadows = true; // --shadows off|hard: hard depth-map shadows
|
||||
bool uncapped = false; // --uncapped: remove the 60 FPS target for headroom tests
|
||||
bool unlock_fps_set = false; // --unlock-fps alias / --uncapped
|
||||
bool hide_dev_ui = true; // --dev-ui / --hide-dev-ui override
|
||||
bool hide_dev_ui_set = false;
|
||||
bool resolution_set = false; // --720p/--900p/--1080p/--4k
|
||||
bool menu_options = false; // --menu-options: QA capture of the Options tab
|
||||
bool hiss_test = false; // --hiss-test: close-up of one Hiss Brute
|
||||
bool room_test = false; // --room-test: frozen look at the open-plan room
|
||||
bool aoe_test = false; // --aoe-test: repeating area blast for VFX QA
|
||||
|
|
@ -86,16 +98,40 @@ Options parse_options(int argc, char** argv) {
|
|||
} else if (std::strcmp(argv[i], "--1080p") == 0) {
|
||||
opts.width = k1080pWidth;
|
||||
opts.height = k1080pHeight;
|
||||
opts.resolution_set = true;
|
||||
} else if (std::strcmp(argv[i], "--900p") == 0) {
|
||||
opts.width = k900pWidth;
|
||||
opts.height = k900pHeight;
|
||||
opts.resolution_set = true;
|
||||
} else if (std::strcmp(argv[i], "--720p") == 0) {
|
||||
opts.width = k720pWidth;
|
||||
opts.height = k720pHeight;
|
||||
opts.resolution_set = true;
|
||||
} else if (std::strcmp(argv[i], "--4k") == 0) {
|
||||
opts.width = k4kWidth;
|
||||
opts.height = k4kHeight;
|
||||
opts.resolution_set = true;
|
||||
} else if (std::strcmp(argv[i], "--post-fx") == 0) {
|
||||
opts.post_fx = true;
|
||||
opts.post_fx_set = true;
|
||||
} else if (std::strcmp(argv[i], "--raw") == 0) {
|
||||
opts.post_fx = false;
|
||||
opts.post_fx_set = true;
|
||||
} else if (std::strcmp(argv[i], "--shadows") == 0 && i + 1 < argc) {
|
||||
const char* value = argv[++i];
|
||||
opts.shadows = std::strcmp(value, "off") != 0;
|
||||
} else if (std::strcmp(argv[i], "--uncapped") == 0) {
|
||||
} else if (std::strcmp(argv[i], "--uncapped") == 0
|
||||
|| std::strcmp(argv[i], "--unlock-fps") == 0) {
|
||||
opts.uncapped = true;
|
||||
opts.unlock_fps_set = true;
|
||||
} else if (std::strcmp(argv[i], "--dev-ui") == 0) {
|
||||
opts.hide_dev_ui = false;
|
||||
opts.hide_dev_ui_set = true;
|
||||
} else if (std::strcmp(argv[i], "--hide-dev-ui") == 0) {
|
||||
opts.hide_dev_ui = true;
|
||||
opts.hide_dev_ui_set = true;
|
||||
} else if (std::strcmp(argv[i], "--menu-options") == 0) {
|
||||
opts.menu_options = true;
|
||||
} else if (std::strcmp(argv[i], "--hiss-test") == 0) {
|
||||
opts.hiss_test = true;
|
||||
} else if (std::strcmp(argv[i], "--room-test") == 0) {
|
||||
|
|
@ -271,8 +307,24 @@ int main(int argc, char** argv) {
|
|||
unsigned trace_mask = debug::None;
|
||||
if (debug::parse(opts.trace, trace_mask)) debug::set_mask(trace_mask);
|
||||
}
|
||||
// The future graphics menu writes this same setting; --aniso lets us
|
||||
// exercise it from the CLI until that menu exists.
|
||||
|
||||
// Persisted options load first; explicit CLI flags win over the saved file
|
||||
// so scripted captures and balance runs stay reproducible.
|
||||
settings::RuntimeSettings& cfg = settings::runtime();
|
||||
settings::load(cfg, kOptionsPath);
|
||||
if (opts.resolution_set) {
|
||||
settings::resolution_from_dimensions(opts.width, opts.height,
|
||||
cfg.resolution);
|
||||
}
|
||||
if (opts.post_fx_set) {
|
||||
cfg.render_mode = opts.post_fx ? settings::RenderMode::PostFx
|
||||
: settings::RenderMode::Raw;
|
||||
}
|
||||
if (opts.unlock_fps_set) cfg.unlock_fps = opts.uncapped;
|
||||
if (opts.hide_dev_ui_set) cfg.hide_dev_ui = opts.hide_dev_ui;
|
||||
|
||||
// --aniso still exercises texture filtering from the CLI until that option
|
||||
// joins the menu; the rest of the graphics state lives in settings::runtime().
|
||||
gfx::graphics_settings().concrete_filter = gfx::filtering_from_aniso(opts.aniso);
|
||||
gfx::graphics_settings().shadows = opts.shadows ? gfx::ShadowQuality::Hard
|
||||
: gfx::ShadowQuality::Off;
|
||||
|
|
@ -282,18 +334,20 @@ int main(int argc, char** argv) {
|
|||
SetWindowSize(GetMonitorWidth(monitor), GetMonitorHeight(monitor));
|
||||
ToggleFullscreen();
|
||||
} else {
|
||||
int w = opts.width, h = opts.height;
|
||||
const int max_w = GetMonitorWidth(monitor);
|
||||
const int max_h = GetMonitorHeight(monitor) - 48;
|
||||
if (opts.width > max_w || opts.height > max_h) {
|
||||
const float scale = std::min(static_cast<float>(max_w) / opts.width,
|
||||
static_cast<float>(max_h) / opts.height);
|
||||
SetWindowSize(static_cast<int>(opts.width * scale),
|
||||
static_cast<int>(opts.height * scale));
|
||||
if (w > max_w || h > max_h) {
|
||||
const float scale = std::min(static_cast<float>(max_w) / w,
|
||||
static_cast<float>(max_h) / h);
|
||||
w = static_cast<int>(w * scale);
|
||||
h = static_cast<int>(h * scale);
|
||||
SetWindowSize(w, h);
|
||||
}
|
||||
}
|
||||
SetTargetFPS(opts.uncapped ? 0 : 60);
|
||||
SetTargetFPS(cfg.unlock_fps ? 0 : 60);
|
||||
PROF_INIT();
|
||||
PROF_SET_UNCAPPED(opts.uncapped);
|
||||
PROF_SET_UNCAPPED(cfg.unlock_fps);
|
||||
ui_font::init();
|
||||
ui_font::init_gui_style();
|
||||
clay_ui::init();
|
||||
|
|
@ -400,14 +454,28 @@ int main(int argc, char** argv) {
|
|||
// The scene renders to a texture and is blitted raw by default. --post-fx
|
||||
// opts into the corruption grade, bloom, VHS noise and damage flash from
|
||||
// assets/shaders/post_fx.fs (docs/ART_DIRECTION.md "Post FX").
|
||||
RenderTexture2D post_target =
|
||||
LoadRenderTexture(GetScreenWidth(), GetScreenHeight());
|
||||
// Render targets follow the window so a resolution change from the menu
|
||||
// (or a manual window resize) always gets matching post-FX buffers.
|
||||
RenderTexture2D post_target{}, bloom_a{}, bloom_b{};
|
||||
int bloom_w = 1, bloom_h = 1;
|
||||
auto resize_targets = [&]() {
|
||||
const int w = GetScreenWidth();
|
||||
const int h = GetScreenHeight();
|
||||
if (post_target.texture.id != 0 && post_target.texture.width == w
|
||||
&& post_target.texture.height == h) {
|
||||
return;
|
||||
}
|
||||
if (post_target.texture.id != 0) UnloadRenderTexture(post_target);
|
||||
if (bloom_a.texture.id != 0) UnloadRenderTexture(bloom_a);
|
||||
if (bloom_b.texture.id != 0) UnloadRenderTexture(bloom_b);
|
||||
post_target = LoadRenderTexture(w, h);
|
||||
bloom_w = std::max(1, w / 2);
|
||||
bloom_h = std::max(1, h / 2);
|
||||
bloom_a = LoadRenderTexture(bloom_w, bloom_h);
|
||||
bloom_b = LoadRenderTexture(bloom_w, bloom_h);
|
||||
};
|
||||
resize_targets();
|
||||
|
||||
// S12 bloom: half-res bright pass + separable blur, composited in post_fx.
|
||||
const int bloom_w = GetScreenWidth() / 2;
|
||||
const int bloom_h = GetScreenHeight() / 2;
|
||||
RenderTexture2D bloom_a = LoadRenderTexture(bloom_w, bloom_h);
|
||||
RenderTexture2D bloom_b = LoadRenderTexture(bloom_w, bloom_h);
|
||||
auto shader_path_for = [](const char* rel) -> std::string {
|
||||
if (FileExists(rel)) return rel;
|
||||
char path[512];
|
||||
|
|
@ -447,8 +515,33 @@ int main(int argc, char** argv) {
|
|||
const int loc_bloom = post_ok
|
||||
? GetShaderLocation(post_shader, "texture1") : -1;
|
||||
|
||||
const bool use_post = opts.post_fx && post_ok;
|
||||
const bool use_bloom = use_post && bloom_ok;
|
||||
// A saved (or CLI-selected) preset is applied on the first frame if it
|
||||
// differs from the window created above.
|
||||
auto clamp_window = [](int& w, int& h) {
|
||||
const int monitor = GetCurrentMonitor();
|
||||
const int max_w = GetMonitorWidth(monitor);
|
||||
const int max_h = GetMonitorHeight(monitor) - 48;
|
||||
if (w <= max_w && h <= max_h) return;
|
||||
const float scale = std::min(static_cast<float>(max_w) / w,
|
||||
static_cast<float>(max_h) / h);
|
||||
w = static_cast<int>(w * scale);
|
||||
h = static_cast<int>(h * scale);
|
||||
};
|
||||
auto apply_resolution = [&](settings::Resolution r) {
|
||||
int w = 0, h = 0;
|
||||
settings::resolution_dimensions(r, w, h);
|
||||
clamp_window(w, h);
|
||||
SetWindowSize(w, h);
|
||||
resize_targets();
|
||||
};
|
||||
settings::Resolution applied_resolution = cfg.resolution;
|
||||
settings::Resolution from_window;
|
||||
if (settings::resolution_from_dimensions(GetScreenWidth(), GetScreenHeight(),
|
||||
from_window)) {
|
||||
applied_resolution = from_window;
|
||||
}
|
||||
bool applied_uncapped = cfg.unlock_fps;
|
||||
if (opts.menu_options) ui::set_menu_tab(1);
|
||||
|
||||
float accumulator = 0.0f;
|
||||
float aoe_clock = 0.0f;
|
||||
|
|
@ -459,6 +552,20 @@ int main(int argc, char** argv) {
|
|||
InputFrame input;
|
||||
while (!WindowShouldClose()) {
|
||||
PROF_BEGIN_FRAME();
|
||||
if (cfg.resolution != applied_resolution) {
|
||||
apply_resolution(cfg.resolution);
|
||||
applied_resolution = cfg.resolution;
|
||||
}
|
||||
if (cfg.unlock_fps != applied_uncapped) {
|
||||
SetTargetFPS(cfg.unlock_fps ? 0 : 60);
|
||||
PROF_SET_UNCAPPED(cfg.unlock_fps);
|
||||
applied_uncapped = cfg.unlock_fps;
|
||||
}
|
||||
resize_targets(); // also covers user-driven window resizes
|
||||
const bool use_post = cfg.render_mode == settings::RenderMode::PostFx
|
||||
&& post_ok;
|
||||
const bool use_bloom = use_post && bloom_ok;
|
||||
|
||||
poll_input(input);
|
||||
accumulator += GetFrameTime();
|
||||
if (accumulator > 0.25f) accumulator = 0.25f; // avoid spiral of death
|
||||
|
|
@ -624,9 +731,10 @@ int main(int argc, char** argv) {
|
|||
if (game.state == GameState::Title) ui::draw_menu(game, input.pad);
|
||||
clay_ui::end_frame(GetFrameTime());
|
||||
|
||||
ui::draw_all(game);
|
||||
if (game.state != GameState::Title) ui::draw_camera_dev(presenter.camera_tuning());
|
||||
PROF_DRAW_OVERLAY();
|
||||
ui::draw_all(game, !cfg.hide_dev_ui);
|
||||
if (game.state != GameState::Title && !cfg.hide_dev_ui)
|
||||
ui::draw_camera_dev(presenter.camera_tuning(), true);
|
||||
if (!cfg.hide_dev_ui) PROF_DRAW_OVERLAY();
|
||||
PROF_END_CPU(profiler::Sec_UI);
|
||||
PROF_BEGIN_CPU(profiler::Sec_Present);
|
||||
EndDrawing();
|
||||
|
|
@ -652,7 +760,7 @@ int main(int argc, char** argv) {
|
|||
TakeScreenshot(opts.screenshot_path);
|
||||
screenshot_taken = true;
|
||||
}
|
||||
if (IsKeyPressed(KEY_F10)) PROF_TOGGLE();
|
||||
if (!cfg.hide_dev_ui && IsKeyPressed(KEY_F10)) PROF_TOGGLE();
|
||||
if (IsKeyPressed(KEY_F12)) TakeScreenshot("screenshot.png");
|
||||
|
||||
// The presenter has consumed this frame's sim events.
|
||||
|
|
|
|||
|
|
@ -27,16 +27,19 @@ void Label(Clay_String text, int size, Clay_Color color,
|
|||
inline constexpr uint16_t kFontUi = 0;
|
||||
inline constexpr uint16_t kFontTitle = 1;
|
||||
|
||||
// Restrained, near-monochrome palette for the full-screen menu overlay. The
|
||||
// 3D scene stays visible underneath; only white/gray ink sits on top of it.
|
||||
namespace theme {
|
||||
inline constexpr Clay_Color kDim{10.0f, 12.0f, 18.0f, 216.0f};
|
||||
inline constexpr Clay_Color kPanel{22.0f, 25.0f, 36.0f, 252.0f};
|
||||
inline constexpr Clay_Color kPanelDeep{13.0f, 15.0f, 23.0f, 255.0f};
|
||||
inline constexpr Clay_Color kBorder{64.0f, 76.0f, 102.0f, 255.0f};
|
||||
inline constexpr Clay_Color kBorderFocus{193.0f, 18.0f, 31.0f, 255.0f};
|
||||
inline constexpr Clay_Color kText{235.0f, 232.0f, 224.0f, 255.0f};
|
||||
inline constexpr Clay_Color kTextDim{150.0f, 148.0f, 144.0f, 255.0f};
|
||||
inline constexpr Clay_Color kTitle{245.0f, 197.0f, 24.0f, 255.0f};
|
||||
inline constexpr Clay_Color kAccent{193.0f, 18.0f, 31.0f, 255.0f};
|
||||
inline constexpr Clay_Color kDim{4.0f, 6.0f, 10.0f, 176.0f};
|
||||
inline constexpr Clay_Color kPanel{10.0f, 13.0f, 20.0f, 214.0f};
|
||||
inline constexpr Clay_Color kText{232.0f, 232.0f, 230.0f, 255.0f};
|
||||
inline constexpr Clay_Color kTextStrong{255.0f, 255.0f, 255.0f, 255.0f};
|
||||
inline constexpr Clay_Color kTextDim{152.0f, 154.0f, 160.0f, 255.0f};
|
||||
inline constexpr Clay_Color kRule{255.0f, 255.0f, 255.0f, 72.0f};
|
||||
inline constexpr Clay_Color kRuleStrong{255.0f, 255.0f, 255.0f, 220.0f};
|
||||
inline constexpr Clay_Color kSliderOff{255.0f, 255.0f, 255.0f, 52.0f};
|
||||
inline constexpr Clay_Color kSliderOn{242.0f, 242.0f, 242.0f, 245.0f};
|
||||
inline constexpr Clay_Color kSelectionBg{255.0f, 255.0f, 255.0f, 14.0f};
|
||||
inline constexpr Clay_Color kTransparent{0.0f, 0.0f, 0.0f, 0.0f};
|
||||
} // namespace theme
|
||||
|
||||
|
|
|
|||
171
src/render/settings.cpp
Normal file
171
src/render/settings.cpp
Normal file
|
|
@ -0,0 +1,171 @@
|
|||
#include "render/settings.hpp"
|
||||
|
||||
#include <algorithm>
|
||||
#include <cstdio>
|
||||
#include <cstring>
|
||||
#include <fstream>
|
||||
#include <string>
|
||||
|
||||
namespace settings {
|
||||
namespace {
|
||||
|
||||
int wrap(int value, int direction, int count) {
|
||||
const int d = ((direction % count) + count) % count;
|
||||
return (value + d) % count;
|
||||
}
|
||||
|
||||
std::string trim(const std::string& s) {
|
||||
const auto first = s.find_first_not_of(" \t\r\n");
|
||||
if (first == std::string::npos) return {};
|
||||
const auto last = s.find_last_not_of(" \t\r\n");
|
||||
return s.substr(first, last - first + 1);
|
||||
}
|
||||
|
||||
bool equals_ignore_case(const std::string& a, const char* b) {
|
||||
if (a.size() != std::strlen(b)) return false;
|
||||
for (std::size_t i = 0; i < a.size(); ++i) {
|
||||
const char x = a[i] >= 'A' && a[i] <= 'Z' ? a[i] - 'A' + 'a' : a[i];
|
||||
const char y = b[i] >= 'A' && b[i] <= 'Z' ? b[i] - 'A' + 'a' : b[i];
|
||||
if (x != y) return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool parse_resolution(const std::string& value, Resolution& out) {
|
||||
if (equals_ignore_case(value, "720p")) { out = Resolution::P720; return true; }
|
||||
if (equals_ignore_case(value, "900p")) { out = Resolution::P900; return true; }
|
||||
if (equals_ignore_case(value, "1080p")) { out = Resolution::P1080; return true; }
|
||||
if (equals_ignore_case(value, "4k") || equals_ignore_case(value, "2160p")) {
|
||||
out = Resolution::P4K;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool parse_bool(const std::string& value, const char* true_word,
|
||||
const char* false_word, bool& out) {
|
||||
if (equals_ignore_case(value, true_word)) { out = true; return true; }
|
||||
if (equals_ignore_case(value, false_word)) { out = false; return true; }
|
||||
return false;
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
RuntimeSettings& runtime() {
|
||||
static RuntimeSettings s;
|
||||
return s;
|
||||
}
|
||||
|
||||
void reset(RuntimeSettings& s) {
|
||||
s = RuntimeSettings{};
|
||||
}
|
||||
|
||||
void cycle_resolution(RuntimeSettings& s, int direction) {
|
||||
s.resolution = static_cast<Resolution>(
|
||||
wrap(index(s.resolution), direction, static_cast<int>(Resolution::Count)));
|
||||
}
|
||||
|
||||
void cycle_render_mode(RuntimeSettings& s, int direction) {
|
||||
s.render_mode = static_cast<RenderMode>(
|
||||
wrap(index(s.render_mode), direction, static_cast<int>(RenderMode::Count)));
|
||||
}
|
||||
|
||||
int index(Resolution r) {
|
||||
return std::clamp(static_cast<int>(r), 0,
|
||||
static_cast<int>(Resolution::Count) - 1);
|
||||
}
|
||||
|
||||
int index(RenderMode m) {
|
||||
return std::clamp(static_cast<int>(m), 0,
|
||||
static_cast<int>(RenderMode::Count) - 1);
|
||||
}
|
||||
|
||||
const char* resolution_label(Resolution r) {
|
||||
switch (r) {
|
||||
case Resolution::P720: return "720p";
|
||||
case Resolution::P1080: return "1080p";
|
||||
case Resolution::P4K: return "4K";
|
||||
default: return "900p";
|
||||
}
|
||||
}
|
||||
|
||||
const char* resolution_size_label(Resolution r) {
|
||||
switch (r) {
|
||||
case Resolution::P720: return "1280 x 720";
|
||||
case Resolution::P1080: return "1920 x 1080";
|
||||
case Resolution::P4K: return "3840 x 2160";
|
||||
default: return "1600 x 900";
|
||||
}
|
||||
}
|
||||
|
||||
void resolution_dimensions(Resolution r, int& width, int& height) {
|
||||
switch (r) {
|
||||
case Resolution::P720: width = 1280; height = 720; break;
|
||||
case Resolution::P1080: width = 1920; height = 1080; break;
|
||||
case Resolution::P4K: width = 3840; height = 2160; break;
|
||||
default: width = 1600; height = 900; break;
|
||||
}
|
||||
}
|
||||
|
||||
bool resolution_from_dimensions(int width, int height, Resolution& out) {
|
||||
for (int i = 0; i < static_cast<int>(Resolution::Count); ++i) {
|
||||
const Resolution r = static_cast<Resolution>(i);
|
||||
int w = 0, h = 0;
|
||||
resolution_dimensions(r, w, h);
|
||||
if (w == width && h == height) {
|
||||
out = r;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
const char* render_mode_label(RenderMode m) {
|
||||
return m == RenderMode::PostFx ? "POST FX" : "RAW";
|
||||
}
|
||||
|
||||
bool load(RuntimeSettings& s, const char* path) {
|
||||
if (path == nullptr) return false;
|
||||
std::ifstream in(path);
|
||||
if (!in) return false;
|
||||
|
||||
std::string line;
|
||||
while (std::getline(in, line)) {
|
||||
const auto eq = line.find('=');
|
||||
if (eq == std::string::npos) continue;
|
||||
const std::string key = trim(line.substr(0, eq));
|
||||
const std::string value = trim(line.substr(eq + 1));
|
||||
|
||||
if (key == "resolution") {
|
||||
Resolution r = s.resolution;
|
||||
if (parse_resolution(value, r)) s.resolution = r;
|
||||
} else if (key == "render") {
|
||||
if (equals_ignore_case(value, "raw")) s.render_mode = RenderMode::Raw;
|
||||
else if (equals_ignore_case(value, "postfx")
|
||||
|| equals_ignore_case(value, "post-fx")) {
|
||||
s.render_mode = RenderMode::PostFx;
|
||||
}
|
||||
} else if (key == "fps") {
|
||||
bool unlocked = s.unlock_fps;
|
||||
if (parse_bool(value, "unlocked", "60", unlocked)) s.unlock_fps = unlocked;
|
||||
} else if (key == "dev_ui") {
|
||||
bool hidden = s.hide_dev_ui;
|
||||
if (parse_bool(value, "hidden", "visible", hidden)) s.hide_dev_ui = hidden;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool save(const RuntimeSettings& s, const char* path) {
|
||||
if (path == nullptr) return false;
|
||||
std::ofstream out(path, std::ios::trunc);
|
||||
if (!out) return false;
|
||||
out << "cntrl options\n"
|
||||
<< "resolution=" << resolution_label(s.resolution) << '\n'
|
||||
<< "render=" << (s.render_mode == RenderMode::Raw ? "raw" : "postfx") << '\n'
|
||||
<< "fps=" << (s.unlock_fps ? "unlocked" : "60") << '\n'
|
||||
<< "dev_ui=" << (s.hide_dev_ui ? "hidden" : "visible") << '\n';
|
||||
return static_cast<bool>(out);
|
||||
}
|
||||
|
||||
} // namespace settings
|
||||
45
src/render/settings.hpp
Normal file
45
src/render/settings.hpp
Normal file
|
|
@ -0,0 +1,45 @@
|
|||
#pragma once
|
||||
|
||||
#include <cstddef>
|
||||
|
||||
// Runtime options written by the title-screen Options tab and applied by
|
||||
// main.cpp. Kept free of raylib/UI dependencies so the option logic can be
|
||||
// unit-tested and shared by the CLI.
|
||||
namespace settings {
|
||||
|
||||
enum class Resolution { P720 = 0, P900 = 1, P1080 = 2, P4K = 3, Count = 4 };
|
||||
|
||||
enum class RenderMode { Raw = 0, PostFx = 1, Count = 2 };
|
||||
|
||||
struct RuntimeSettings {
|
||||
Resolution resolution = Resolution::P900;
|
||||
RenderMode render_mode = RenderMode::Raw; // shipped default: raw palette
|
||||
bool unlock_fps = false; // false -> 60 FPS target
|
||||
bool hide_dev_ui = true; // clean, shippable presentation
|
||||
};
|
||||
|
||||
RuntimeSettings& runtime();
|
||||
|
||||
// Restores the shipped defaults (used by the menu's "restore defaults" row).
|
||||
void reset(RuntimeSettings& s);
|
||||
|
||||
// Cycling helpers wrap in both directions; direction is -1 or +1.
|
||||
void cycle_resolution(RuntimeSettings& s, int direction);
|
||||
void cycle_render_mode(RuntimeSettings& s, int direction);
|
||||
|
||||
int index(Resolution r);
|
||||
int index(RenderMode m);
|
||||
|
||||
// Labels for the menu. Keep them ASCII: the UI font has no symbol glyphs.
|
||||
const char* resolution_label(Resolution r); // "720p", "900p", ...
|
||||
const char* resolution_size_label(Resolution r); // "1280 x 720"
|
||||
void resolution_dimensions(Resolution r, int& width, int& height);
|
||||
bool resolution_from_dimensions(int width, int height, Resolution& out);
|
||||
const char* render_mode_label(RenderMode m);
|
||||
|
||||
// Tiny line-based config file ("cntrl.cfg" in the working directory). Failures
|
||||
// are non-fatal: a read-only directory must not stop the game from starting.
|
||||
bool load(RuntimeSettings& s, const char* path);
|
||||
bool save(const RuntimeSettings& s, const char* path);
|
||||
|
||||
} // namespace settings
|
||||
|
|
@ -2,6 +2,7 @@
|
|||
|
||||
#include <algorithm>
|
||||
#include <cmath>
|
||||
#include <cstdint>
|
||||
#include <cstdio>
|
||||
#include <cstring>
|
||||
|
||||
|
|
@ -9,6 +10,7 @@
|
|||
#include "raygui.h"
|
||||
#include "render/ui_font.hpp"
|
||||
#include "render/clay_ui.hpp"
|
||||
#include "render/settings.hpp"
|
||||
|
||||
namespace {
|
||||
|
||||
|
|
@ -110,7 +112,7 @@ void draw_skill_icon(const Game& game, SkillType type, float x, float y,
|
|||
static_cast<int>(y) - 17, 14, stamp);
|
||||
}
|
||||
|
||||
void draw_hud(const Game& game) {
|
||||
void draw_hud(const Game& game, bool show_dev_ui) {
|
||||
// Top left: agent vitals.
|
||||
char hp_label[64];
|
||||
std::snprintf(hp_label, sizeof(hp_label), "SECURITY AGENT HP %d / %d",
|
||||
|
|
@ -289,6 +291,7 @@ void draw_hud(const Game& game) {
|
|||
static_cast<int>(y) + 22, 13, mode_color);
|
||||
}
|
||||
|
||||
if (show_dev_ui) {
|
||||
// Dev readout (pre-alpha): frame rate + entity counts + director bank.
|
||||
char debug[160];
|
||||
std::snprintf(debug, sizeof(debug),
|
||||
|
|
@ -300,7 +303,9 @@ void draw_hud(const Game& game) {
|
|||
static_cast<double>(game.director.credits()),
|
||||
game.buff_system.world_object_count(),
|
||||
game.buff_system.buff_count());
|
||||
ui_font::draw_text(debug, 20, GetScreenHeight() - 22, 16, Color{150, 148, 144, 210});
|
||||
ui_font::draw_text(debug, 20, GetScreenHeight() - 22, 16,
|
||||
Color{150, 148, 144, 210});
|
||||
}
|
||||
}
|
||||
|
||||
void draw_gameover(const Game& game) {
|
||||
|
|
@ -323,13 +328,14 @@ void draw_gameover(const Game& game) {
|
|||
|
||||
} // namespace
|
||||
|
||||
void ui::draw_all(const Game& game) {
|
||||
void ui::draw_all(const Game& game, bool show_dev_ui) {
|
||||
if (game.state == GameState::Title) return;
|
||||
draw_hud(game);
|
||||
draw_hud(game, show_dev_ui);
|
||||
if (game.state == GameState::GameOver) draw_gameover(game);
|
||||
}
|
||||
|
||||
void ui::draw_camera_dev(CameraTuning& tuning) {
|
||||
void ui::draw_camera_dev(CameraTuning& tuning, bool show_dev_ui) {
|
||||
if (!show_dev_ui) return;
|
||||
if (IsKeyPressed(KEY_F9)) tuning.panel = !tuning.panel;
|
||||
if (!tuning.panel) {
|
||||
ui_font::draw_text("F9 CAM DEV", GetScreenWidth() - 130, GetScreenHeight() - 26,
|
||||
|
|
@ -369,46 +375,385 @@ void ui::draw_camera_dev(CameraTuning& tuning) {
|
|||
if (IsKeyPressed(KEY_PERIOD)) tuning.forward = std::min(40.0f, tuning.forward + 1.0f);
|
||||
}
|
||||
|
||||
namespace {
|
||||
|
||||
constexpr const char* kOptionsPath = "cntrl.cfg";
|
||||
constexpr int kOptionCount = 5;
|
||||
|
||||
struct MenuState {
|
||||
int tab = 0; // 0 = briefing, 1 = options
|
||||
int row = 0;
|
||||
};
|
||||
|
||||
MenuState& menu_state() {
|
||||
static MenuState state;
|
||||
return state;
|
||||
}
|
||||
|
||||
bool pad_pressed(int pad, GamepadButton button) {
|
||||
return pad >= 0 && IsGamepadButtonPressed(pad, button);
|
||||
}
|
||||
|
||||
const char* option_value(int row) {
|
||||
const settings::RuntimeSettings& s = settings::runtime();
|
||||
switch (row) {
|
||||
case 0:
|
||||
return clay_ui::T("%s / %s", settings::resolution_label(s.resolution),
|
||||
settings::resolution_size_label(s.resolution)).chars;
|
||||
case 1:
|
||||
return s.render_mode == settings::RenderMode::Raw
|
||||
? "RAW (DEFAULT)" : "POST FX (GRADE + BLOOM)";
|
||||
case 2:
|
||||
return s.unlock_fps ? "UNLOCKED" : "60 FPS (CAPPED)";
|
||||
case 3:
|
||||
return s.hide_dev_ui ? "HIDDEN" : "VISIBLE";
|
||||
default:
|
||||
return "RESTORE SHIPPED DEFAULTS";
|
||||
}
|
||||
}
|
||||
|
||||
int option_segment_count(int row) {
|
||||
return row == 0 ? 4 : (row == 4 ? 1 : 2);
|
||||
}
|
||||
|
||||
int option_segment_index(int row) {
|
||||
const settings::RuntimeSettings& s = settings::runtime();
|
||||
switch (row) {
|
||||
case 0: return settings::index(s.resolution);
|
||||
case 1: return s.render_mode == settings::RenderMode::PostFx ? 1 : 0;
|
||||
case 2: return s.unlock_fps ? 1 : 0;
|
||||
case 3: return s.hide_dev_ui ? 1 : 0;
|
||||
default: return -1;
|
||||
}
|
||||
}
|
||||
|
||||
void cycle_option(int row, int direction) {
|
||||
settings::RuntimeSettings& s = settings::runtime();
|
||||
switch (row) {
|
||||
case 0: settings::cycle_resolution(s, direction); break;
|
||||
case 1: settings::cycle_render_mode(s, direction); break;
|
||||
case 2: s.unlock_fps = !s.unlock_fps; break;
|
||||
case 3: s.hide_dev_ui = !s.hide_dev_ui; break;
|
||||
default: settings::reset(s); break;
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
void ui::set_menu_tab(int tab) {
|
||||
menu_state().tab = tab == 1 ? 1 : 0;
|
||||
}
|
||||
|
||||
void ui::draw_menu(Game& game, int gamepad) {
|
||||
namespace theme = clay_ui::theme;
|
||||
MenuState& state = menu_state();
|
||||
const settings::RuntimeSettings& cfg = settings::runtime();
|
||||
|
||||
// One translucent panel over the live scene. Type scales gently so the
|
||||
// layout stays readable from 720p through 4K.
|
||||
const float scale = std::clamp(GetScreenHeight() / 900.0f, 0.8f, 1.0f);
|
||||
const auto px = [scale](float v) { return v * scale; };
|
||||
const auto pxi = [scale](float v) {
|
||||
return static_cast<uint16_t>(std::lround(v * scale));
|
||||
};
|
||||
const auto fs = [scale](float v) {
|
||||
return std::max(11, static_cast<int>(std::lround(v * scale)));
|
||||
};
|
||||
|
||||
const bool click = IsMouseButtonPressed(MOUSE_LEFT_BUTTON);
|
||||
const bool up = IsKeyPressed(KEY_UP) || IsKeyPressed(KEY_W)
|
||||
|| pad_pressed(gamepad, GAMEPAD_BUTTON_LEFT_FACE_UP);
|
||||
const bool down = IsKeyPressed(KEY_DOWN) || IsKeyPressed(KEY_S)
|
||||
|| pad_pressed(gamepad, GAMEPAD_BUTTON_LEFT_FACE_DOWN);
|
||||
const bool left = IsKeyPressed(KEY_LEFT) || IsKeyPressed(KEY_A)
|
||||
|| pad_pressed(gamepad, GAMEPAD_BUTTON_LEFT_FACE_LEFT);
|
||||
const bool right = IsKeyPressed(KEY_RIGHT) || IsKeyPressed(KEY_D)
|
||||
|| pad_pressed(gamepad, GAMEPAD_BUTTON_LEFT_FACE_RIGHT);
|
||||
const bool confirm = IsKeyPressed(KEY_ENTER) || IsKeyPressed(KEY_SPACE)
|
||||
|| pad_pressed(gamepad, GAMEPAD_BUTTON_RIGHT_FACE_DOWN)
|
||||
|| pad_pressed(gamepad, GAMEPAD_BUTTON_MIDDLE_RIGHT);
|
||||
const bool back = IsKeyPressed(KEY_ESCAPE) || IsKeyPressed(KEY_BACKSPACE)
|
||||
|| pad_pressed(gamepad, GAMEPAD_BUTTON_RIGHT_FACE_RIGHT);
|
||||
const bool switch_tab = IsKeyPressed(KEY_TAB)
|
||||
|| pad_pressed(gamepad, GAMEPAD_BUTTON_MIDDLE_LEFT);
|
||||
|
||||
bool start = false;
|
||||
bool options_changed = false;
|
||||
int pending_tab = -1;
|
||||
int hover_row = -1;
|
||||
int clicked_row = -1;
|
||||
|
||||
if (switch_tab) state.tab = 1 - state.tab;
|
||||
if (back && state.tab == 1) state.tab = 0;
|
||||
if (state.tab == 0) {
|
||||
if (left || right) state.tab = 1;
|
||||
if (confirm) start = true;
|
||||
} else {
|
||||
if (up) state.row = std::max(0, state.row - 1);
|
||||
if (down) state.row = std::min(kOptionCount - 1, state.row + 1);
|
||||
if (left) { cycle_option(state.row, -1); options_changed = true; }
|
||||
if (right) { cycle_option(state.row, +1); options_changed = true; }
|
||||
if (confirm) { cycle_option(state.row, +1); options_changed = true; }
|
||||
}
|
||||
|
||||
CLAY(CLAY_ID("MenuRoot"), {
|
||||
.layout = { .sizing = { CLAY_SIZING_GROW(0), CLAY_SIZING_GROW(0) },
|
||||
.padding = CLAY_PADDING_ALL(64),
|
||||
.padding = CLAY_PADDING_ALL(pxi(28)),
|
||||
.childAlignment = { CLAY_ALIGN_X_CENTER, CLAY_ALIGN_Y_CENTER },
|
||||
.layoutDirection = CLAY_TOP_TO_BOTTOM },
|
||||
.backgroundColor = clay_ui::theme::kDim }) {
|
||||
.backgroundColor = theme::kDim }) {
|
||||
CLAY(CLAY_ID("MenuPanel"), {
|
||||
.layout = { .sizing = { CLAY_SIZING_FIXED(520), CLAY_SIZING_FIT(0) },
|
||||
.padding = CLAY_PADDING_ALL(40),
|
||||
.childGap = 16,
|
||||
.childAlignment = { CLAY_ALIGN_X_CENTER, CLAY_ALIGN_Y_CENTER },
|
||||
.layout = { .sizing = { CLAY_SIZING_FIXED(px(1000)),
|
||||
CLAY_SIZING_FIT(0) },
|
||||
.padding = CLAY_PADDING_ALL(pxi(30)),
|
||||
.childGap = pxi(16),
|
||||
.childAlignment = { CLAY_ALIGN_X_LEFT,
|
||||
CLAY_ALIGN_Y_TOP },
|
||||
.layoutDirection = CLAY_TOP_TO_BOTTOM },
|
||||
.backgroundColor = clay_ui::theme::kPanel,
|
||||
.cornerRadius = CLAY_CORNER_RADIUS(16),
|
||||
.border = { .color = clay_ui::theme::kBorder, .width = CLAY_BORDER_ALL(2) } }) {
|
||||
clay_ui::Label(clay_ui::S("FBC: NIGHT SHIFT"), 48, clay_ui::theme::kTitle,
|
||||
CLAY_TEXT_ALIGN_CENTER, clay_ui::kFontTitle);
|
||||
clay_ui::Label(clay_ui::S("CONTAINMENT PROTOCOL - PRE-ALPHA"), 16,
|
||||
clay_ui::theme::kTextDim, CLAY_TEXT_ALIGN_CENTER);
|
||||
CLAY(CLAY_ID("StartBtn"), {
|
||||
.layout = { .sizing = { CLAY_SIZING_GROW(0), CLAY_SIZING_FIXED(52) },
|
||||
.padding = CLAY_PADDING_ALL(16),
|
||||
.childGap = 0,
|
||||
.childAlignment = { CLAY_ALIGN_X_CENTER, CLAY_ALIGN_Y_CENTER } },
|
||||
.backgroundColor = Clay_Hovered() ? clay_ui::theme::kBorderFocus
|
||||
: clay_ui::theme::kPanelDeep,
|
||||
.cornerRadius = CLAY_CORNER_RADIUS(8),
|
||||
.border = { .color = clay_ui::theme::kBorder, .width = CLAY_BORDER_ALL(1) } }) {
|
||||
if (Clay_Hovered() && IsMouseButtonPressed(MOUSE_LEFT_BUTTON)) start = true;
|
||||
clay_ui::Label(clay_ui::S("ENTER THE HOUSE"), 20, clay_ui::theme::kText,
|
||||
CLAY_TEXT_ALIGN_CENTER);
|
||||
.backgroundColor = theme::kPanel,
|
||||
.cornerRadius = CLAY_CORNER_RADIUS(2),
|
||||
.border = { .color = theme::kRule,
|
||||
.width = CLAY_BORDER_ALL(1) } }) {
|
||||
// Header: game title, separator, active section.
|
||||
CLAY(CLAY_ID("MenuHeader"), {
|
||||
.layout = { .sizing = { CLAY_SIZING_GROW(0), CLAY_SIZING_FIT(0) },
|
||||
.childGap = pxi(14),
|
||||
.childAlignment = { CLAY_ALIGN_X_LEFT,
|
||||
CLAY_ALIGN_Y_CENTER },
|
||||
.layoutDirection = CLAY_LEFT_TO_RIGHT } }) {
|
||||
clay_ui::Label(clay_ui::S("FBC: NIGHT SHIFT"), fs(26),
|
||||
theme::kTextStrong, CLAY_TEXT_ALIGN_LEFT,
|
||||
clay_ui::kFontTitle, CLAY_TEXT_WRAP_NONE, 1);
|
||||
clay_ui::Label(clay_ui::S("|"), fs(26), theme::kTextDim,
|
||||
CLAY_TEXT_ALIGN_LEFT, clay_ui::kFontUi,
|
||||
CLAY_TEXT_WRAP_NONE);
|
||||
clay_ui::Label(clay_ui::S(state.tab == 0 ? "BRIEFING" : "OPTIONS"),
|
||||
fs(26), theme::kTextDim, CLAY_TEXT_ALIGN_LEFT,
|
||||
clay_ui::kFontUi, CLAY_TEXT_WRAP_NONE, 1);
|
||||
}
|
||||
|
||||
// Tabs: text and a thin underline, no boxes.
|
||||
CLAY(CLAY_ID("MenuTabs"), {
|
||||
.layout = { .sizing = { CLAY_SIZING_GROW(0), CLAY_SIZING_FIT(0) },
|
||||
.childGap = pxi(64),
|
||||
.layoutDirection = CLAY_LEFT_TO_RIGHT } }) {
|
||||
auto tab_button = [&](int tab, const char* label) {
|
||||
CLAY(CLAY_IDI("MenuTab", tab), {
|
||||
.layout = { .sizing = { CLAY_SIZING_FIXED(px(180)),
|
||||
CLAY_SIZING_FIT(0) },
|
||||
.childGap = pxi(8),
|
||||
.layoutDirection = CLAY_TOP_TO_BOTTOM } }) {
|
||||
const bool active = state.tab == tab;
|
||||
const bool hovered = Clay_Hovered();
|
||||
if (hovered && click) pending_tab = tab;
|
||||
clay_ui::Label(clay_ui::S(label), fs(20),
|
||||
active || hovered ? theme::kTextStrong
|
||||
: theme::kTextDim,
|
||||
CLAY_TEXT_ALIGN_LEFT, clay_ui::kFontUi,
|
||||
CLAY_TEXT_WRAP_NONE, 1);
|
||||
CLAY(CLAY_IDI("MenuTabRule", tab), {
|
||||
.layout = { .sizing = { CLAY_SIZING_GROW(0),
|
||||
CLAY_SIZING_FIXED(
|
||||
px(active ? 3 : 1)) } },
|
||||
.backgroundColor = active ? theme::kRuleStrong
|
||||
: theme::kTransparent }) {}
|
||||
}
|
||||
};
|
||||
tab_button(0, "BRIEFING");
|
||||
tab_button(1, "OPTIONS");
|
||||
}
|
||||
|
||||
CLAY(CLAY_ID("MenuRule"), {
|
||||
.layout = { .sizing = { CLAY_SIZING_GROW(0),
|
||||
CLAY_SIZING_FIXED(1) } },
|
||||
.backgroundColor = theme::kRule }) {}
|
||||
|
||||
if (state.tab == 0) {
|
||||
CLAY(CLAY_ID("BriefingBody"), {
|
||||
.layout = { .sizing = { CLAY_SIZING_GROW(0),
|
||||
CLAY_SIZING_FIT(0) },
|
||||
.childGap = pxi(16),
|
||||
.layoutDirection = CLAY_TOP_TO_BOTTOM } }) {
|
||||
clay_ui::Label(clay_ui::S("ASSIGNMENT 01 / FLOOR 01"), fs(38),
|
||||
theme::kTextStrong, CLAY_TEXT_ALIGN_LEFT,
|
||||
clay_ui::kFontTitle, CLAY_TEXT_WRAP_NONE, 1);
|
||||
clay_ui::Label(clay_ui::S(
|
||||
"Locate and ignite three Beacons. The House decays while "
|
||||
"you move; your Objects of Power fire themselves."), fs(20),
|
||||
theme::kText, CLAY_TEXT_ALIGN_LEFT, clay_ui::kFontUi,
|
||||
CLAY_TEXT_WRAP_WORDS);
|
||||
clay_ui::Label(clay_ui::S(
|
||||
"WASD / STICK MOVE SHIFT / SPACE DASH J K L "
|
||||
"SKILLS U FLUORESCENT TAB AUTOPLAY"), fs(17),
|
||||
theme::kTextDim, CLAY_TEXT_ALIGN_LEFT, clay_ui::kFontUi,
|
||||
CLAY_TEXT_WRAP_WORDS);
|
||||
clay_ui::Label(clay_ui::T(
|
||||
"CONFIGURED: %s / %s / %s / DEV UI %s",
|
||||
settings::resolution_label(cfg.resolution),
|
||||
settings::render_mode_label(cfg.render_mode),
|
||||
cfg.unlock_fps ? "UNLOCKED FPS" : "60 FPS",
|
||||
cfg.hide_dev_ui ? "HIDDEN" : "VISIBLE"), fs(17),
|
||||
theme::kTextDim, CLAY_TEXT_ALIGN_LEFT, clay_ui::kFontUi,
|
||||
CLAY_TEXT_WRAP_WORDS);
|
||||
|
||||
CLAY(CLAY_ID("StartCta"), {
|
||||
.layout = { .sizing = { CLAY_SIZING_FIXED(px(460)),
|
||||
CLAY_SIZING_FIT(0) },
|
||||
.padding = { 0, 0, pxi(10), 0 },
|
||||
.childGap = pxi(8),
|
||||
.layoutDirection = CLAY_TOP_TO_BOTTOM } }) {
|
||||
const bool hovered = Clay_Hovered();
|
||||
if (hovered && click) start = true;
|
||||
clay_ui::Label(clay_ui::S("ENTER THE HOUSE >"), fs(28),
|
||||
hovered ? theme::kTextStrong : theme::kText,
|
||||
CLAY_TEXT_ALIGN_LEFT, clay_ui::kFontTitle,
|
||||
CLAY_TEXT_WRAP_NONE, 1);
|
||||
CLAY(CLAY_ID("StartRule"), {
|
||||
.layout = { .sizing = { CLAY_SIZING_GROW(0),
|
||||
CLAY_SIZING_FIXED(
|
||||
px(hovered ? 3 : 1)) } },
|
||||
.backgroundColor = hovered ? theme::kRuleStrong
|
||||
: theme::kRule }) {}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
CLAY(CLAY_ID("OptionsBody"), {
|
||||
.layout = { .sizing = { CLAY_SIZING_GROW(0),
|
||||
CLAY_SIZING_FIT(0) },
|
||||
.childGap = pxi(14),
|
||||
.layoutDirection = CLAY_TOP_TO_BOTTOM } }) {
|
||||
auto option_row = [&](int row, const char* name) {
|
||||
CLAY(CLAY_IDI("OptionRow", row), {
|
||||
.layout = { .sizing = { CLAY_SIZING_GROW(0),
|
||||
CLAY_SIZING_FIXED(px(52)) },
|
||||
.childGap = pxi(16),
|
||||
.childAlignment = { CLAY_ALIGN_X_LEFT,
|
||||
CLAY_ALIGN_Y_CENTER },
|
||||
.layoutDirection = CLAY_LEFT_TO_RIGHT },
|
||||
.backgroundColor = Clay_Hovered() || state.row == row
|
||||
? theme::kSelectionBg : theme::kTransparent }) {
|
||||
const bool hovered = Clay_Hovered();
|
||||
const bool active = (state.row == row) || hovered;
|
||||
if (hovered) hover_row = row;
|
||||
if (hovered && click) clicked_row = row;
|
||||
CLAY(CLAY_IDI("RowMark", row), {
|
||||
.layout = { .sizing = { CLAY_SIZING_FIXED(px(3)),
|
||||
CLAY_SIZING_FIXED(
|
||||
px(26)) } },
|
||||
.backgroundColor = active ? theme::kRuleStrong
|
||||
: theme::kTransparent }) {}
|
||||
CLAY(CLAY_IDI("OptionName", row), {
|
||||
.layout = { .sizing = { CLAY_SIZING_FIXED(px(250)),
|
||||
CLAY_SIZING_GROW(0) },
|
||||
.childAlignment = {
|
||||
CLAY_ALIGN_X_LEFT,
|
||||
CLAY_ALIGN_Y_CENTER } } }) {
|
||||
clay_ui::Label(clay_ui::S(name), fs(20),
|
||||
active ? theme::kTextStrong
|
||||
: theme::kTextDim,
|
||||
CLAY_TEXT_ALIGN_LEFT,
|
||||
clay_ui::kFontUi,
|
||||
CLAY_TEXT_WRAP_NONE, 1);
|
||||
}
|
||||
CLAY(CLAY_IDI("OptionSlider", row), {
|
||||
.layout = { .sizing = { CLAY_SIZING_GROW(0),
|
||||
CLAY_SIZING_GROW(0) },
|
||||
.childGap = pxi(7),
|
||||
.childAlignment = {
|
||||
CLAY_ALIGN_X_LEFT,
|
||||
CLAY_ALIGN_Y_CENTER },
|
||||
.layoutDirection =
|
||||
CLAY_LEFT_TO_RIGHT } }) {
|
||||
const int count = option_segment_count(row);
|
||||
const int selected = option_segment_index(row);
|
||||
for (int seg = 0; seg < count; ++seg) {
|
||||
CLAY(CLAY_IDI("OptionSegment",
|
||||
row * 8 + seg), {
|
||||
.layout = {
|
||||
.sizing = {
|
||||
CLAY_SIZING_GROW(0),
|
||||
CLAY_SIZING_FIXED(px(6)) } },
|
||||
.backgroundColor = seg <= selected
|
||||
? theme::kSliderOn
|
||||
: theme::kSliderOff,
|
||||
.cornerRadius = CLAY_CORNER_RADIUS(
|
||||
px(3)) }) {}
|
||||
}
|
||||
}
|
||||
CLAY(CLAY_IDI("OptionValue", row), {
|
||||
.layout = { .sizing = { CLAY_SIZING_FIXED(px(330)),
|
||||
CLAY_SIZING_GROW(0) },
|
||||
.childAlignment = {
|
||||
CLAY_ALIGN_X_RIGHT,
|
||||
CLAY_ALIGN_Y_CENTER } } }) {
|
||||
clay_ui::Label(clay_ui::S(option_value(row)),
|
||||
fs(20),
|
||||
active ? theme::kTextStrong
|
||||
: theme::kText,
|
||||
CLAY_TEXT_ALIGN_RIGHT,
|
||||
clay_ui::kFontUi,
|
||||
CLAY_TEXT_WRAP_NONE);
|
||||
}
|
||||
}
|
||||
};
|
||||
if (IsKeyPressed(KEY_ENTER)) start = true;
|
||||
if (gamepad >= 0 && (IsGamepadButtonPressed(gamepad, GAMEPAD_BUTTON_RIGHT_FACE_DOWN)
|
||||
|| IsGamepadButtonPressed(gamepad, GAMEPAD_BUTTON_MIDDLE_RIGHT))) {
|
||||
start = true;
|
||||
option_row(0, "RESOLUTION");
|
||||
option_row(1, "RENDERING");
|
||||
option_row(2, "FRAME RATE");
|
||||
option_row(3, "DEV UI");
|
||||
option_row(4, "DEFAULTS");
|
||||
}
|
||||
}
|
||||
|
||||
CLAY(CLAY_ID("MenuHints"), {
|
||||
.layout = { .sizing = { CLAY_SIZING_GROW(0), CLAY_SIZING_FIT(0) },
|
||||
.childGap = pxi(24),
|
||||
.childAlignment = { CLAY_ALIGN_X_LEFT,
|
||||
CLAY_ALIGN_Y_CENTER },
|
||||
.layoutDirection = CLAY_LEFT_TO_RIGHT } }) {
|
||||
int hint_no = 0;
|
||||
auto hint = [&](const char* key, const char* label) {
|
||||
const int id = hint_no++;
|
||||
CLAY(CLAY_IDI("HintGroup", id), {
|
||||
.layout = { .sizing = { CLAY_SIZING_FIT(0),
|
||||
CLAY_SIZING_FIT(0) },
|
||||
.childGap = pxi(9),
|
||||
.childAlignment = { CLAY_ALIGN_X_LEFT,
|
||||
CLAY_ALIGN_Y_CENTER },
|
||||
.layoutDirection = CLAY_LEFT_TO_RIGHT } }) {
|
||||
CLAY(CLAY_IDI("HintKey", id), {
|
||||
.layout = { .sizing = { CLAY_SIZING_FIXED(px(22)),
|
||||
CLAY_SIZING_FIXED(px(22)) },
|
||||
.childAlignment = { CLAY_ALIGN_X_CENTER,
|
||||
CLAY_ALIGN_Y_CENTER } },
|
||||
.backgroundColor = theme::kSliderOff,
|
||||
.cornerRadius = CLAY_CORNER_RADIUS(px(11)) }) {
|
||||
clay_ui::Label(clay_ui::S(key), fs(12), theme::kText,
|
||||
CLAY_TEXT_ALIGN_CENTER,
|
||||
clay_ui::kFontUi,
|
||||
CLAY_TEXT_WRAP_NONE);
|
||||
}
|
||||
clay_ui::Label(clay_ui::S(label), fs(15),
|
||||
theme::kTextDim, CLAY_TEXT_ALIGN_LEFT,
|
||||
clay_ui::kFontUi, CLAY_TEXT_WRAP_NONE, 1);
|
||||
}
|
||||
};
|
||||
hint("A", "CONFIRM");
|
||||
hint("B", "BACK");
|
||||
hint("Y", "RESET");
|
||||
clay_ui::Label(clay_ui::S("ENTER / ESC / TAB ON KEYBOARD"),
|
||||
fs(13), theme::kTextDim, CLAY_TEXT_ALIGN_LEFT,
|
||||
clay_ui::kFontUi, CLAY_TEXT_WRAP_NONE, 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (hover_row >= 0) state.row = hover_row;
|
||||
if (pending_tab >= 0) state.tab = pending_tab;
|
||||
if (clicked_row >= 0 && state.tab == 1) {
|
||||
cycle_option(clicked_row, +1);
|
||||
options_changed = true;
|
||||
}
|
||||
if (pending_tab == 1) state.row = 0;
|
||||
if (options_changed) settings::save(cfg, kOptionsPath);
|
||||
if (start) game.reset();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -7,7 +7,11 @@
|
|||
// The look is "FBC paperwork" (see docs/ART_DIRECTION.md); M1 uses the default
|
||||
// font and grey-box styling.
|
||||
namespace ui {
|
||||
void draw_all(const Game& game);
|
||||
// `show_dev_ui` hides the in-game debug counters and the camera dev panel.
|
||||
void draw_all(const Game& game, bool show_dev_ui);
|
||||
void draw_menu(Game& game, int gamepad);
|
||||
void draw_camera_dev(CameraTuning& tuning);
|
||||
void draw_camera_dev(CameraTuning& tuning, bool show_dev_ui);
|
||||
|
||||
// QA/CLI hook: open a specific title-screen tab for scripted captures.
|
||||
void set_menu_tab(int tab);
|
||||
}
|
||||
|
|
|
|||
65
tests/settings_test.cpp
Normal file
65
tests/settings_test.cpp
Normal file
|
|
@ -0,0 +1,65 @@
|
|||
// Title-screen options: defaults, cycling and config round-trip.
|
||||
#include <cstdio>
|
||||
#include <filesystem>
|
||||
|
||||
#include "render/settings.hpp"
|
||||
|
||||
namespace {
|
||||
|
||||
bool failed = false;
|
||||
|
||||
void check(bool ok, const char* what) {
|
||||
if (!ok) {
|
||||
std::printf("FAIL: %s\n", what);
|
||||
failed = true;
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
int main() {
|
||||
settings::RuntimeSettings s;
|
||||
settings::reset(s);
|
||||
check(s.resolution == settings::Resolution::P900, "default resolution is 900p");
|
||||
check(s.render_mode == settings::RenderMode::Raw, "default rendering is raw");
|
||||
check(!s.unlock_fps, "frame rate starts capped");
|
||||
check(s.hide_dev_ui, "dev UI starts hidden");
|
||||
|
||||
int w = 0, h = 0;
|
||||
settings::resolution_dimensions(settings::Resolution::P720, w, h);
|
||||
check(w == 1280 && h == 720, "720p dimensions");
|
||||
settings::resolution_dimensions(settings::Resolution::P4K, w, h);
|
||||
check(w == 3840 && h == 2160, "4K dimensions");
|
||||
|
||||
settings::cycle_resolution(s, +1);
|
||||
check(s.resolution == settings::Resolution::P1080, "cycle forward to 1080p");
|
||||
settings::cycle_resolution(s, -1);
|
||||
check(s.resolution == settings::Resolution::P900, "cycle back to 900p");
|
||||
s.resolution = settings::Resolution::P720;
|
||||
settings::cycle_resolution(s, -1);
|
||||
check(s.resolution == settings::Resolution::P4K, "resolution wraps backwards");
|
||||
|
||||
settings::cycle_render_mode(s, +1);
|
||||
check(s.render_mode == settings::RenderMode::PostFx, "cycle into post FX");
|
||||
settings::cycle_render_mode(s, +1);
|
||||
check(s.render_mode == settings::RenderMode::Raw, "render mode wraps to raw");
|
||||
|
||||
const auto path = std::filesystem::temp_directory_path() / "cntrl_settings_test.cfg";
|
||||
s.resolution = settings::Resolution::P1080;
|
||||
s.render_mode = settings::RenderMode::PostFx;
|
||||
s.unlock_fps = true;
|
||||
s.hide_dev_ui = false;
|
||||
check(settings::save(s, path.c_str()), "config file written");
|
||||
|
||||
settings::RuntimeSettings loaded;
|
||||
check(settings::load(loaded, path.c_str()), "config file read");
|
||||
check(loaded.resolution == settings::Resolution::P1080, "resolution persisted");
|
||||
check(loaded.render_mode == settings::RenderMode::PostFx, "render mode persisted");
|
||||
check(loaded.unlock_fps, "unlocked FPS persisted");
|
||||
check(!loaded.hide_dev_ui, "dev UI visibility persisted");
|
||||
std::filesystem::remove(path);
|
||||
|
||||
if (failed) return 1;
|
||||
std::printf("settings: OK\n");
|
||||
return 0;
|
||||
}
|
||||
Loading…
Add table
Reference in a new issue