added fullbright

This commit is contained in:
st committed 2026-10-13 02:04:50 -05:00
1 parent fafeee709f
commit b1634d195c
21 files changed
+1263 -204

No files matched your search

+144 -93
View File
@@ -1,20 +1,16 @@
#pragma once
#include <cfloat>
#include <cmath>
#include <string>
#include "imgui.h"
#include "fonts.h"
#include "theme.h"
#include "widgets.h"
#include "../input.h"
#include "../modules/module_manager.h"
#if __has_include("../font_data.h")
#include "../font_data.h"
#define AMNESIA_HAS_FONT 1
#else
#define AMNESIA_HAS_FONT 0
#endif
inline std::string key_name(int vk) {
if (vk == 0) return "None";
if (vk == 0) return "none";
LONG lparam = (LONG)(MapVirtualKeyA((UINT)vk, MAPVK_VK_TO_VSC) << 16);
switch (vk) { // extended keys need bit 24 set to get the right name
@@ -39,7 +35,7 @@ public:
ImGuiIO& io = ImGui::GetIO();
io.IniFilename = nullptr; // never write imgui.ini into the game's folder
io.LogFilename = nullptr;
load_fonts();
fonts::load();
theme::apply();
}
@@ -56,28 +52,36 @@ public:
open_t_ = theme::approach(open_t_, g_menu_open ? 1.f : 0.f, ImGui::GetIO().DeltaTime * 14.f);
}
// dim + title; call BEFORE modules().render() so the HUD stays above the dimming
// dim + wordmark; call BEFORE modules().render() so the HUD stays above the dimming
void draw_backdrop() {
if (open_t_ <= 0.01f) return;
ImGuiIO& io = ImGui::GetIO();
ImDrawList* dl = ImGui::GetBackgroundDrawList();
const float a = open_t_;
dl->AddRectFilled(ImVec2(0.f, 0.f), io.DisplaySize,
theme::u32(theme::with_alpha(theme::bg_dark(), 0.6f * open_t_)));
theme::u32(theme::with_alpha(theme::bg(), k_backdrop_alpha * a)));
const char* title = "AMNESIA";
const float tw = ImGui::CalcTextSize(title).x * k_title_size / ImGui::GetFontSize();
const ImVec2 tp(io.DisplaySize.x * 0.5f - tw * 0.5f, 18.f);
dl->AddText(font_title_, k_title_size, ImVec2(tp.x + 3.f, tp.y + 3.f),
theme::u32(theme::with_alpha(theme::bg_dark(), open_t_)), title);
dl->AddText(font_title_, k_title_size, tp,
theme::u32(theme::with_alpha(theme::accent_bright(), open_t_)), title);
// title bar, like the launcher: cube + lowercase wordmark
const ImVec2 logo_pos(26.f, 18.f);
const float logo_h = 30.f;
const float logo_w = theme::draw_logo(dl, logo_pos, logo_h, a);
const ImVec2 ts = fonts::text_size(fonts::heading, fonts::k_heading_size, "amnesia");
dl->AddText(fonts::heading, fonts::k_heading_size,
ImVec2(floorf(logo_pos.x + logo_w + 12.f), floorf(logo_pos.y + (logo_h - ts.y) * 0.5f)),
theme::u32(theme::with_alpha(theme::fg(), a)), "amnesia");
const char* hint = "Right-click a module for settings | drag HUD elements to move them";
const float hw = ImGui::CalcTextSize(hint).x;
dl->AddText(ImVec2(io.DisplaySize.x * 0.5f - hw * 0.5f, tp.y + k_title_size + 8.f),
theme::u32(theme::with_alpha(theme::fg_muted(), open_t_)), hint);
// footer, like the launcher's status strip
dl->AddText(fonts::label, fonts::k_label_size,
ImVec2(28.f, io.DisplaySize.y - 30.f),
theme::u32(theme::with_alpha(theme::dim(), a)), "amnesia / v0.0.1");
const char* hint = "right click a module for settings | drag hud elements to move them | right shift or esc to close";
const ImVec2 hs = fonts::text_size(fonts::body, fonts::k_body_size, hint);
dl->AddText(fonts::body, fonts::k_body_size,
ImVec2(floorf(io.DisplaySize.x - hs.x - 28.f), io.DisplaySize.y - 32.f),
theme::u32(theme::with_alpha(theme::muted(), a)), hint);
}
// the panels and the HUD drag editor
@@ -99,30 +103,21 @@ public:
private:
static constexpr int k_menu_key = VK_RSHIFT;
static constexpr float k_panel_w = 230.f;
static constexpr float k_main_size = 18.f;
static constexpr float k_title_size = 32.f;
static constexpr float k_panel_w = 270.f;
static constexpr float k_backdrop_alpha = 0.6f; // the launcher's overlay is 0.85; lower so you can see the game
static constexpr category k_categories[] = { category::hud, category::visual, category::utility };
ImFont* font_main_ = nullptr;
ImFont* font_title_ = nullptr;
float open_t_ = 0.f;
bool menu_key_was_down_ = false;
bool esc_was_down_ = false;
void load_fonts() {
ImGuiIO& io = ImGui::GetIO();
#if AMNESIA_HAS_FONT
ImFontConfig cfg;
cfg.FontDataOwnedByAtlas = false; // the data lives in our DLL, ImGui must not free it
font_main_ = io.Fonts->AddFontFromMemoryTTF((void*)k_font_data, (int)k_font_size, k_main_size, &cfg);
font_title_ = io.Fonts->AddFontFromMemoryTTF((void*)k_font_data, (int)k_font_size, k_title_size, &cfg);
#endif
if (!font_main_) { // no font_data.h (or it failed): fall back to ImGui's built-in
font_main_ = io.Fonts->AddFontDefault();
font_title_ = font_main_;
static const char* category_title(category c) {
switch (c) {
case category::hud: return "hud";
case category::visual: return "visual";
case category::utility: return "utility";
}
io.FontDefault = font_main_;
return "";
}
void set_open(bool open) {
@@ -154,28 +149,49 @@ private:
// ---------------- panels ----------------
void draw_panel(category cat, float default_x) {
ImGui::SetNextWindowPos(ImVec2(default_x, 110.f), ImGuiCond_FirstUseEver);
ImGui::SetNextWindowPos(ImVec2(default_x, 100.f), ImGuiCond_FirstUseEver);
ImGui::SetNextWindowSize(ImVec2(k_panel_w, 0.f), ImGuiCond_Always); // fixed width, auto height
ImGuiWindowFlags flags = ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoCollapse |
ImGuiWindowFlags_NoScrollbar | ImGuiWindowFlags_NoScrollWithMouse |
ImGuiWindowFlags_NoSavedSettings;
ImGuiWindowFlags flags = ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoResize |
ImGuiWindowFlags_NoCollapse | ImGuiWindowFlags_NoScrollbar |
ImGuiWindowFlags_NoScrollWithMouse | ImGuiWindowFlags_NoSavedSettings;
if (!g_menu_open) flags |= ImGuiWindowFlags_NoInputs; // fading out: no more clicks
if (ImGui::Begin(category_name(cat), nullptr, flags)) {
const std::string id = std::string("##panel_") + category_name(cat);
if (ImGui::Begin(id.c_str(), nullptr, flags)) {
// header: small uppercase muted label + SemiBold heading (drag the panel by this area)
/*fonts::push_font(fonts::label, fonts::k_label_size);
ImGui::TextColored(theme::muted(), "%s", category_name(cat));
ImGui::PopFont();*/
fonts::push_font(fonts::heading, fonts::k_heading_size);
ImGui::TextUnformatted(category_title(cat));
ImGui::PopFont();
ImGui::Dummy(ImVec2(0.f, 4.f));
for (auto& m : modules().all())
if (m->cat() == cat) draw_module(*m);
}
ImGui::End();
}
void draw_tooltip(const module& m) {
ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, ImVec2(14.f, 12.f));
ImGui::BeginTooltip();
ImGui::TextUnformatted(m.description().c_str());
ImGui::TextColored(theme::muted(), "click to toggle | right click for settings");
ImGui::EndTooltip();
ImGui::PopStyleVar();
}
void draw_module(module& m) {
ImGui::PushID(&m);
ImDrawList* dl = ImGui::GetWindowDrawList();
const float w = ImGui::GetContentRegionAvail().x;
const float h = ImGui::GetFontSize() + 14.f;
const float h = 38.f;
const ImVec2 p = ImGui::GetCursorScreenPos();
const ImVec2 q(p.x + w, p.y + h);
ImGui::InvisibleButton("##row", ImVec2(w, h));
const bool hovered = ImGui::IsItemHovered();
@@ -185,35 +201,44 @@ private:
m.ui.expanded = !m.ui.expanded;
m.ui.binding = false;
}
if (hovered)
ImGui::SetTooltip("%s\n\nLMB: toggle | RMB: settings", m.description().c_str());
if (hovered) draw_tooltip(m);
const float dt = ImGui::GetIO().DeltaTime;
m.ui.hover_t = theme::approach(m.ui.hover_t, hovered ? 1.f : 0.f, dt * 16.f);
m.ui.enable_t = theme::approach(m.ui.enable_t, m.enabled() ? 1.f : 0.f, dt * 12.f);
m.ui.expand_t = theme::approach(m.ui.expand_t, m.ui.expanded ? 1.f : 0.f, dt * 12.f);
ImVec4 base = theme::mix(theme::bg_raised(), theme::accent(), m.ui.enable_t);
base = theme::shade(base, 1.f + 0.15f * m.ui.hover_t);
theme::bevel_box(dl, p, ImVec2(p.x + w, p.y + h), base, active);
// off = secondary button, on = Primary (Accent fill, dark text)
const ImVec4 fill_off = theme::mix(theme::raised(), theme::hover(), m.ui.hover_t);
const ImVec4 fill_on = theme::shade(theme::accent(), 1.f + 0.10f * m.ui.hover_t);
ImVec4 fill = theme::mix(fill_off, fill_on, m.ui.enable_t);
ImVec4 border = theme::mix(theme::line(), theme::accent(), m.ui.hover_t);
ImVec4 text_col = theme::mix(theme::fg(), theme::bg(), m.ui.enable_t);
if (active) { fill.w *= 0.7f; border.w *= 0.7f; text_col.w *= 0.7f; }
const ImVec4 text_col = theme::mix(theme::fg(), theme::bg_dark(), m.ui.enable_t);
const float text_y = p.y + (h - ImGui::GetFontSize()) * 0.5f;
theme::shadow_text(dl, ImVec2(p.x + 8.f, text_y), text_col, m.name().c_str());
dl->AddRectFilled(p, q, theme::u32(fill), theme::k_radius_button);
dl->AddRect(p, q, theme::u32(border), theme::k_radius_button, 0, 1.f);
if (m.toggle_key()) {
const std::string k = "[" + key_name(m.toggle_key()) + "]";
const float kw = ImGui::CalcTextSize(k.c_str()).x;
const ImVec4 kcol = theme::mix(theme::fg_muted(), theme::bg_dark(), m.ui.enable_t * 0.6f);
dl->AddText(ImVec2(p.x + w - kw - 8.f, text_y), theme::u32(kcol), k.c_str());
const ImVec2 ts = fonts::text_size(fonts::semibold, fonts::k_body_size, m.name().c_str());
dl->AddText(fonts::semibold, fonts::k_body_size,
ImVec2(floorf(p.x + 16.f), floorf(p.y + (h - ts.y) * 0.5f)),
theme::u32(text_col), m.name().c_str());
if (m.toggle_key()) { // keycap chip on the right
const std::string k = key_name(m.toggle_key());
const ImVec2 ks = fonts::text_size(fonts::label, fonts::k_label_size, k.c_str());
const float cw = ks.x + 14.f, ch = 20.f;
const ImVec2 c0(q.x - 12.f - cw, p.y + (h - ch) * 0.5f);
const ImVec2 c1(c0.x + cw, c0.y + ch);
dl->AddRectFilled(c0, c1, theme::u32(theme::with_alpha(theme::bg(), 0.55f)), 6.f);
dl->AddText(fonts::label, fonts::k_label_size,
ImVec2(floorf(c0.x + 7.f), floorf(c0.y + (ch - ks.y) * 0.5f)),
theme::u32(theme::muted()), k.c_str());
}
if (m.ui.expand_t > 0.01f) {
ImGui::PushStyleVar(ImGuiStyleVar_Alpha, ImGui::GetStyle().Alpha * m.ui.expand_t);
ImGui::Indent(6.f);
draw_bind_button(m);
for (auto& s : m.settings()) draw_setting(s);
ImGui::Unindent(6.f);
draw_settings(m, w);
ImGui::PopStyleVar();
ImGui::Dummy(ImVec2(0.f, 2.f));
}
@@ -221,12 +246,41 @@ private:
ImGui::PopID();
}
void draw_bind_button(module& m) {
std::string label;
if (m.ui.binding) label = "Bind: press a key...";
else label = "Bind: [" + key_name(m.toggle_key()) + "]";
// settings live in an inset card (Bg fill, Line border), drawn behind the widgets
void draw_settings(module& m, float w) {
ImDrawList* dl = ImGui::GetWindowDrawList();
const ImVec2 start = ImGui::GetCursorScreenPos();
const float pad = 12.f;
const float inner_w = w - pad * 2.f;
if (ImGui::Button(label.c_str(), ImVec2(-FLT_MIN, 0.f))) m.ui.binding = !m.ui.binding;
dl->ChannelsSplit(2);
dl->ChannelsSetCurrent(1);
ImGui::BeginGroup();
ImGui::Dummy(ImVec2(w, 2.f));
ImGui::Indent(pad);
draw_bind(m, inner_w);
for (auto& s : m.settings()) draw_setting(s, inner_w);
ImGui::Unindent(pad);
ImGui::Dummy(ImVec2(0.f, 2.f));
ImGui::EndGroup();
const ImVec2 gmin = ImGui::GetItemRectMin();
const ImVec2 gmax = ImGui::GetItemRectMax();
dl->ChannelsSetCurrent(0);
const ImVec2 a(start.x, gmin.y), b(start.x + w, gmax.y);
dl->AddRectFilled(a, b, theme::u32(theme::bg()), theme::k_radius_button);
dl->AddRect(a, b, theme::u32(theme::line()), theme::k_radius_button, 0, 1.f);
dl->ChannelsMerge();
}
void draw_bind(module& m, float w) {
ImGui::TextUnformatted("bind");
const std::string text = m.ui.binding ? std::string("press a key...") : key_name(m.toggle_key());
if (widgets::button("##bind", text.c_str(), false, w)) m.ui.binding = !m.ui.binding;
if (m.ui.binding) {
for (int vk = 0x08; vk < 0xFF; ++vk) { // starts above the mouse buttons
@@ -239,47 +293,44 @@ private:
}
}
void draw_setting(setting& s) {
void draw_setting(setting& s, float w) {
ImGui::PushID(&s);
switch (s.type) {
case setting_type::toggle: {
const std::string label = s.name + ": " + (s.bool_value ? "ON" : "OFF");
ImGui::PushStyleColor(ImGuiCol_Text, s.bool_value ? theme::accent_bright() : theme::fg_muted());
if (ImGui::Button(label.c_str(), ImVec2(-FLT_MIN, 0.f))) s.bool_value = !s.bool_value;
ImGui::PopStyleColor();
case setting_type::toggle:
widgets::checkbox(s.name.c_str(), &s.bool_value, w);
break;
}
case setting_type::slider_float: {
const std::string fmt = s.name + ": %.2f";
ImGui::SetNextItemWidth(-FLT_MIN);
ImGui::SliderFloat("##v", &s.float_value, s.float_min, s.float_max, fmt.c_str());
case setting_type::slider_float:
ImGui::TextUnformatted(s.name.c_str());
ImGui::SetNextItemWidth(w);
ImGui::SliderFloat("##v", &s.float_value, s.float_min, s.float_max, "%.2f");
break;
}
case setting_type::slider_int: {
const std::string fmt = s.name + ": %d";
ImGui::SetNextItemWidth(-FLT_MIN);
ImGui::SliderInt("##v", &s.int_value, s.int_min, s.int_max, fmt.c_str());
case setting_type::slider_int:
ImGui::TextUnformatted(s.name.c_str());
ImGui::SetNextItemWidth(w);
ImGui::SliderInt("##v", &s.int_value, s.int_min, s.int_max, "%d");
break;
}
case setting_type::mode: {
case setting_type::mode:
if (!s.modes.empty()) {
if (s.int_value < 0 || s.int_value >= (int)s.modes.size()) s.int_value = 0;
const std::string label = s.name + ": " + s.modes[s.int_value];
if (ImGui::Button(label.c_str(), ImVec2(-FLT_MIN, 0.f)))
ImGui::TextUnformatted(s.name.c_str());
if (widgets::button("##mode", s.modes[s.int_value].c_str(), false, w))
s.int_value = (s.int_value + 1) % (int)s.modes.size();
}
break;
}
case setting_type::color: {
case setting_type::color:
ImGui::ColorEdit4("##c", s.color,
ImGuiColorEditFlags_NoInputs | ImGuiColorEditFlags_NoLabel |
ImGuiColorEditFlags_AlphaBar);
ImGui::SameLine();
ImGui::SameLine(0.f, 10.f);
ImGui::AlignTextToFramePadding();
ImGui::TextUnformatted(s.name.c_str());
break;
}
}
ImGui::PopID();
}
@@ -323,10 +374,10 @@ private:
m.hud_pos.y += io.MouseDelta.y;
}
const ImVec4 col = (hovered || active) ? theme::accent_bright() : theme::accent_dark();
const ImVec4 col = (hovered || active) ? theme::focus() : theme::hover();
ImGui::GetForegroundDrawList()->AddRect(
m.hud_pos, ImVec2(m.hud_pos.x + size.x, m.hud_pos.y + size.y),
theme::u32(col), 0.f, 0, 2.f);
theme::u32(col), 10.f, 0, 1.5f);
}
ImGui::End();
ImGui::PopStyleVar(2);