264 lines
13 KiB
C++
264 lines
13 KiB
C++
#include "render/ui.hpp"
|
|
|
|
#include <algorithm>
|
|
#include <cstdio>
|
|
#include <cstring>
|
|
|
|
#include "raylib.h"
|
|
#include "raygui.h"
|
|
#include "render/ui_font.hpp"
|
|
#include "render/clay_ui.hpp"
|
|
|
|
namespace {
|
|
|
|
void draw_bar(float x, float y, float w, float h, float frac, Color fill, const char* label) {
|
|
frac = std::max(0.0f, std::min(1.0f, frac));
|
|
DrawRectangle(x, y, w, h, Color{20, 20, 22, 210});
|
|
DrawRectangle(x, y, w * frac, h, fill);
|
|
DrawRectangleLines(x, y, w, h, Color{210, 210, 215, 60});
|
|
if (label != nullptr) ui_font::draw_text(label, x + 8, y + h / 2 - 8, 16, Color{235, 232, 224, 235});
|
|
}
|
|
|
|
void draw_hud(const Game& game) {
|
|
// Top left: agent vitals.
|
|
char hp_label[64];
|
|
std::snprintf(hp_label, sizeof(hp_label), "SECURITY AGENT HP %d / %d",
|
|
static_cast<int>(game.player.hp), static_cast<int>(game.player.stats.max_hp));
|
|
draw_bar(20, 20, 300, 22, game.player.hp / game.player.stats.max_hp,
|
|
Color{193, 18, 31, 235}, hp_label);
|
|
|
|
// Top right: shift timer + RoR2-style CONTAINMENT STATUS gauge.
|
|
const int total = static_cast<int>(game.run_time);
|
|
char timer[16];
|
|
std::snprintf(timer, sizeof(timer), "SHIFT %02d:%02d", total / 60, total % 60);
|
|
ui_font::draw_text(timer, GetScreenWidth() - 20 - ui_font::measure_text(timer, 28), 20, 28, Color{235, 232, 224, 245});
|
|
|
|
const int tier = game.corruption.tier();
|
|
char status[96];
|
|
std::snprintf(status, sizeof(status), "CONTAINMENT STATUS: %s", game.corruption.tier_name());
|
|
const int status_w = ui_font::measure_text(status, 18);
|
|
ui_font::draw_text(status, GetScreenWidth() - 20 - status_w, 58, 18, Color{245, 197, 24, 245});
|
|
|
|
const float gauge_w = 260.0f;
|
|
const float gauge_x = GetScreenWidth() - 20 - gauge_w;
|
|
const Color gauge_fill = Color{
|
|
static_cast<unsigned char>(std::min(255, 120 + tier * 24)),
|
|
static_cast<unsigned char>(std::max(0, 180 - tier * 32)),
|
|
static_cast<unsigned char>(std::max(0, 60 - tier * 12)), 235};
|
|
draw_bar(gauge_x, 84, gauge_w, 12, game.corruption.tier_progress(), gauge_fill, nullptr);
|
|
|
|
// Floor 01 flow: current room + the key/door objective.
|
|
{
|
|
const int panel_w = 470;
|
|
const int px = GetScreenWidth() / 2 - panel_w / 2;
|
|
DrawRectangle(px, 16, panel_w, 62, Color{17, 17, 19, 205});
|
|
DrawRectangleLines(px, 16, panel_w, 62, Color{245, 197, 24, 120});
|
|
char room_line[96];
|
|
std::snprintf(room_line, sizeof(room_line), "FLOOR %02d // %s",
|
|
game.floor_number, game.floor.room_name(game.player.pos));
|
|
const int rw = ui_font::measure_text(room_line, 17);
|
|
ui_font::draw_text(room_line, px + panel_w / 2 - rw / 2, 22, 17,
|
|
Color{245, 197, 24, 245});
|
|
const char* objective = game.has_key
|
|
? "OBJECTIVE: REACH THE THRESHOLD STAIRWELL"
|
|
: "OBJECTIVE: RECOVER THE THRESHOLD KEY (SILOS)";
|
|
const int ow = ui_font::measure_text(objective, 16);
|
|
ui_font::draw_text(objective, px + panel_w / 2 - ow / 2, 46, 16,
|
|
Color{232, 228, 220, 235});
|
|
if (game.floor_banner > 0.0f) {
|
|
const char* banner = game.has_key
|
|
? "THRESHOLD KEY ACQUIRED" : "FLOOR CLEARED — THE HOUSE NOTICED";
|
|
const int bw = ui_font::measure_text(banner, 18);
|
|
ui_font::draw_text(banner, GetScreenWidth() / 2 - bw / 2, 108, 18,
|
|
Color{245, 197, 24, 250});
|
|
}
|
|
}
|
|
|
|
// Kills + clearance level.
|
|
char misc[64];
|
|
std::snprintf(misc, sizeof(misc), "KILLS %d CLEARANCE LV %d", game.kills, game.level);
|
|
ui_font::draw_text(misc, 20, 52, 18, Color{200, 198, 192, 235});
|
|
|
|
// Ritual in progress — mini-game indicator (the player understands the
|
|
// ritual starts when it appears). MVP: the TV ritual; complex: the
|
|
// lightswitch — catch the bait around the switch (§2.3).
|
|
if (game.ritual_system.active()) {
|
|
char rit[160];
|
|
if (game.ritual_system.type() == RitualType::Lightswitch) {
|
|
std::snprintf(rit, sizeof(rit),
|
|
"RITUAL IN PROGRESS — LIGHT SWITCH — CATCHING (%d/%d)",
|
|
game.ritual_system.lightswitch_caught(),
|
|
game.ritual_system.lightswitch_required());
|
|
} else {
|
|
std::snprintf(rit, sizeof(rit),
|
|
"RITUAL IN PROGRESS — The TV must flash (%.0f s)",
|
|
std::max(0.0f, game.ritual_system.remaining()));
|
|
}
|
|
ui_font::draw_text(rit, 20, 70.0f, 16, Color{245, 197, 24, 255});
|
|
}
|
|
if (game.ritual_system.complete()) {
|
|
ui_font::draw_text(game.ritual_system.type() == RitualType::Lightswitch
|
|
? "RITUAL COMPLETE — Fluorescents revived"
|
|
: "RITUAL COMPLETE — The TV is live",
|
|
20, 70.0f, 16, Color{245, 197, 24, 255});
|
|
}
|
|
|
|
// Owned OoP loadout (left column).
|
|
float oy = 84.0f;
|
|
ui_font::draw_text("OoP LOADOUT", 20, oy, 16, Color{245, 197, 24, 235});
|
|
oy += 22.0f;
|
|
for (const WeaponInstance& w : game.weapon_system.weapons) {
|
|
const WeaponDef& def = weapon_def(w.type);
|
|
char line[96];
|
|
if (w.evolved) {
|
|
std::snprintf(line, sizeof(line), "%s [ALTERED]", def.evolution_name);
|
|
ui_font::draw_text(line, 20, oy, 17, Color{245, 197, 24, 245});
|
|
} else {
|
|
std::snprintf(line, sizeof(line), "%s lv %d", def.name, w.level);
|
|
ui_font::draw_text(line, 20, oy, 17, Color{200, 198, 192, 235});
|
|
}
|
|
oy += 21.0f;
|
|
}
|
|
|
|
// Pending offers (real-time progression).
|
|
if (!game.pending_offers.empty()) {
|
|
float oy2 = oy + 6.0f;
|
|
char offer_line[128];
|
|
std::snprintf(offer_line, sizeof(offer_line), "OFFERS PENDING: %d", static_cast<int>(game.pending_offers.size()));
|
|
ui_font::draw_text(offer_line, 20, oy2, 16, Color{245, 197, 24, 245});
|
|
oy2 += 18.0f;
|
|
for (const Offer& o : game.pending_offers) {
|
|
std::snprintf(offer_line, sizeof(offer_line), "- %s", o.name);
|
|
ui_font::draw_text(offer_line, 20, oy2, 15, Color{200, 198, 192, 220});
|
|
oy2 += 16.0f;
|
|
}
|
|
}
|
|
|
|
// Bottom: XP bar.
|
|
const float xp_w = 640.0f;
|
|
draw_bar(GetScreenWidth() / 2.0f - xp_w / 2.0f, GetScreenHeight() - 44, xp_w, 18,
|
|
game.xp / game.xp_to_next, Color{245, 197, 24, 235}, "RESONANCE SHARDS");
|
|
|
|
// Dev readout (pre-alpha): frame rate + entity counts + director bank.
|
|
char debug[160];
|
|
std::snprintf(debug, sizeof(debug),
|
|
"FPS %d | ENEMIES %d | PROJECTILES %d | SHARDS %d | DIRECTOR %.0f "
|
|
"| WORLD OBJECTS %d | BUFFS %d",
|
|
GetFPS(), game.enemy_system.alive_count(),
|
|
static_cast<int>(game.weapon_system.projectiles.size()),
|
|
static_cast<int>(game.pickup_system.shards.size()),
|
|
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});
|
|
}
|
|
|
|
void draw_gameover(const Game& game) {
|
|
DrawRectangle(0, 0, GetScreenWidth(), GetScreenHeight(), Color{40, 6, 8, 200});
|
|
const char* title = "CONTAINMENT FAILURE";
|
|
ui_font::draw_text(title, GetScreenWidth() / 2 - ui_font::measure_text(title, 42) / 2, GetScreenHeight() / 2 - 140,
|
|
42, Color{193, 18, 31, 255});
|
|
|
|
const int total = static_cast<int>(game.run_time);
|
|
char stats[256];
|
|
std::snprintf(stats, sizeof(stats),
|
|
"SHIFT TIME SURVIVED %02d:%02d\nKILLS CONFIRMED %d\nCLEARANCE LEVEL %d\nFINAL CORRUPTION %s",
|
|
total / 60, total % 60, game.kills, game.level, game.corruption.tier_name());
|
|
ui_font::draw_text(stats, GetScreenWidth() / 2 - 190, GetScreenHeight() / 2 - 60, 22, Color{232, 228, 216, 255});
|
|
|
|
const char* hint = "PRESS [R] TO RE-ENTER THE HOUSE";
|
|
ui_font::draw_text(hint, GetScreenWidth() / 2 - ui_font::measure_text(hint, 24) / 2, GetScreenHeight() / 2 + 110,
|
|
24, Color{245, 197, 24, 255});
|
|
}
|
|
|
|
} // namespace
|
|
|
|
void ui::draw_all(const Game& game) {
|
|
if (game.state == GameState::Title) return;
|
|
draw_hud(game);
|
|
if (game.state == GameState::GameOver) draw_gameover(game);
|
|
}
|
|
|
|
void ui::draw_camera_dev(CameraTuning& tuning) {
|
|
if (IsKeyPressed(KEY_F9)) tuning.panel = !tuning.panel;
|
|
if (!tuning.panel) {
|
|
ui_font::draw_text("F9 CAM DEV", GetScreenWidth() - 130, GetScreenHeight() - 26,
|
|
14, Color{160, 158, 152, 220});
|
|
return;
|
|
}
|
|
|
|
const float w = 300.0f, h = 150.0f;
|
|
const float x = static_cast<float>(GetScreenWidth()) - w - 20.0f;
|
|
const float y = static_cast<float>(GetScreenHeight()) - h - 20.0f;
|
|
DrawRectangle(x, y, w, h, Color{14, 16, 18, 225});
|
|
DrawRectangleLines(x, y, w, h, Color{120, 118, 112, 160});
|
|
ui_font::draw_text("CAMERA DEV [F9 HIDE]", x + 10, y + 8, 14,
|
|
Color{245, 197, 24, 245});
|
|
|
|
const Rectangle r_fov = {x + 90.0f, y + 34.0f, 150.0f, 18.0f};
|
|
const Rectangle r_height = {x + 90.0f, y + 62.0f, 150.0f, 18.0f};
|
|
const Rectangle r_forward = {x + 90.0f, y + 90.0f, 150.0f, 18.0f};
|
|
|
|
ui_font::draw_text("FOV", x + 10, y + 36, 14, Color{220, 218, 210, 230});
|
|
GuiSlider(r_fov, nullptr, TextFormat("%3.0f", tuning.fov), &tuning.fov, 30.0f, 80.0f);
|
|
|
|
ui_font::draw_text("HEIGHT", x + 10, y + 64, 14, Color{220, 218, 210, 230});
|
|
GuiSlider(r_height, nullptr, TextFormat("%4.1f", tuning.height), &tuning.height, 5.0f, 45.0f);
|
|
|
|
ui_font::draw_text("FORWARD", x + 10, y + 92, 14, Color{220, 218, 210, 230});
|
|
GuiSlider(r_forward, nullptr, TextFormat("%4.1f", tuning.forward), &tuning.forward, 2.0f, 40.0f);
|
|
|
|
ui_font::draw_text("[ ] FOV - = HEIGHT , . FORWARD", x + 10, y + 124, 12,
|
|
Color{160, 158, 152, 220});
|
|
|
|
if (IsKeyPressed(KEY_LEFT_BRACKET)) tuning.fov = std::max(30.0f, tuning.fov - 2.0f);
|
|
if (IsKeyPressed(KEY_RIGHT_BRACKET)) tuning.fov = std::min(80.0f, tuning.fov + 2.0f);
|
|
if (IsKeyPressed(KEY_MINUS)) tuning.height = std::max(5.0f, tuning.height - 1.0f);
|
|
if (IsKeyPressed(KEY_EQUAL)) tuning.height = std::min(45.0f, tuning.height + 1.0f);
|
|
if (IsKeyPressed(KEY_COMMA)) tuning.forward = std::max(2.0f, tuning.forward - 1.0f);
|
|
if (IsKeyPressed(KEY_PERIOD)) tuning.forward = std::min(40.0f, tuning.forward + 1.0f);
|
|
}
|
|
|
|
void ui::draw_menu(Game& game) {
|
|
bool start = false;
|
|
CLAY(CLAY_ID("MenuRoot"), {
|
|
.layout = { .sizing = { CLAY_SIZING_GROW(0), CLAY_SIZING_GROW(0) },
|
|
.padding = CLAY_PADDING_ALL(64),
|
|
.childAlignment = { CLAY_ALIGN_X_CENTER, CLAY_ALIGN_Y_CENTER },
|
|
.layoutDirection = CLAY_TOP_TO_BOTTOM },
|
|
.backgroundColor = clay_ui::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 },
|
|
.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);
|
|
}
|
|
}
|
|
};
|
|
if (IsKeyPressed(KEY_ENTER)) start = true;
|
|
for (int i = 0; i < 4; ++i) {
|
|
if (IsGamepadAvailable(i) && (IsGamepadButtonPressed(i, GAMEPAD_BUTTON_RIGHT_FACE_DOWN)
|
|
|| IsGamepadButtonPressed(i, GAMEPAD_BUTTON_MIDDLE_RIGHT))) { start = true; break; }
|
|
}
|
|
if (start) game.reset();
|
|
}
|