#pragma once #include #include #include #include "imgui.h" #include "fonts.h" #include "theme.h" #include "widgets.h" #include "../input.h" #include "../modules/module_manager.h" inline std::string key_name(int vk) { 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 case VK_INSERT: case VK_DELETE: case VK_HOME: case VK_END: case VK_PRIOR: case VK_NEXT: case VK_LEFT: case VK_RIGHT: case VK_UP: case VK_DOWN: case VK_RCONTROL: case VK_RMENU: lparam |= (1 << 24); break; default: break; } char buf[64] = {}; if (GetKeyNameTextA(lparam, buf, sizeof(buf)) > 0) return buf; return "Key " + std::to_string(vk); } class clickgui { public: // after ImGui::CreateContext(), before the backends are initialized void init() { ImGuiIO& io = ImGui::GetIO(); io.IniFilename = nullptr; // never write imgui.ini into the game's folder io.LogFilename = nullptr; fonts::load(); theme::apply(); } // once per frame, after ImGui::NewFrame() void update() { const bool menu_down = is_key_down(k_menu_key); if (menu_down && !menu_key_was_down_) set_open(!g_menu_open); menu_key_was_down_ = menu_down; const bool esc_down = is_key_down(VK_ESCAPE); if (esc_down && !esc_was_down_ && g_menu_open && !any_binding()) set_open(false); esc_was_down_ = esc_down; open_t_ = theme::approach(open_t_, g_menu_open ? 1.f : 0.f, ImGui::GetIO().DeltaTime * 14.f); } // 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(), k_backdrop_alpha * a))); // 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"); // 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 void draw() { if (open_t_ <= 0.01f) return; ImGui::PushStyleVar(ImGuiStyleVar_Alpha, open_t_); float x = 40.f; for (category cat : k_categories) { if (!has_modules(cat)) continue; draw_panel(cat, x); x += k_panel_w + 20.f; } draw_hud_editor(); ImGui::PopStyleVar(); } private: static constexpr int k_menu_key = VK_RSHIFT; 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 }; float open_t_ = 0.f; bool menu_key_was_down_ = false; bool esc_was_down_ = false; static const char* category_title(category c) { switch (c) { case category::hud: return "hud"; case category::visual: return "visual"; case category::utility: return "utility"; } return ""; } void set_open(bool open) { if (open == g_menu_open) return; g_menu_open = open; ImGui::GetIO().MouseDrawCursor = open; // ImGui draws its own cursor while open if (open) { input::release_cursor(); } else { input::restore_cursor(); for (auto& m : modules().all()) m->ui.binding = false; } } bool any_binding() const { for (auto& m : modules().all()) if (m->ui.binding) return true; return false; } bool has_modules(category cat) const { for (auto& m : modules().all()) if (m->cat() == cat) return true; return false; } // ---------------- panels ---------------- void draw_panel(category cat, float default_x) { 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_NoTitleBar | ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoCollapse | ImGuiWindowFlags_NoScrollbar | ImGuiWindowFlags_NoScrollWithMouse | ImGuiWindowFlags_NoSavedSettings; if (!g_menu_open) flags |= ImGuiWindowFlags_NoInputs; // fading out: no more clicks 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 = 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(); const bool active = ImGui::IsItemActive(); if (ImGui::IsItemClicked(ImGuiMouseButton_Left)) m.toggle(); if (ImGui::IsItemClicked(ImGuiMouseButton_Right)) { m.ui.expanded = !m.ui.expanded; m.ui.binding = false; } 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); // 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; } 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); 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); draw_settings(m, w); ImGui::PopStyleVar(); ImGui::Dummy(ImVec2(0.f, 2.f)); } ImGui::PopID(); } // 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; 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 if (is_key_down(vk)) { m.set_toggle_key(vk == VK_ESCAPE ? 0 : vk); // Esc clears the bind m.ui.binding = false; break; } } } } void draw_setting(setting& s, float w) { ImGui::PushID(&s); switch (s.type) { case setting_type::toggle: widgets::checkbox(s.name.c_str(), &s.bool_value, w); break; 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: 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: if (!s.modes.empty()) { if (s.int_value < 0 || s.int_value >= (int)s.modes.size()) s.int_value = 0; 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: ImGui::ColorEdit4("##c", s.color, ImGuiColorEditFlags_NoInputs | ImGuiColorEditFlags_NoLabel | ImGuiColorEditFlags_AlphaBar); ImGui::SameLine(0.f, 10.f); ImGui::AlignTextToFramePadding(); ImGui::TextUnformatted(s.name.c_str()); break; } ImGui::PopID(); } // ---------------- HUD drag editor ---------------- void draw_hud_editor() { ImGuiIO& io = ImGui::GetIO(); for (auto& up : modules().all()) { module& m = *up; if (!m.enabled() || !m.is_hud()) continue; const ImVec2 size = m.hud_size(); if (size.x <= 0.f || size.y <= 0.f) continue; // keep it on screen m.hud_pos.x = theme::clampf(m.hud_pos.x, 0.f, io.DisplaySize.x - size.x); m.hud_pos.y = theme::clampf(m.hud_pos.y, 0.f, io.DisplaySize.y - size.y); ImGui::SetNextWindowPos(m.hud_pos, ImGuiCond_Always); ImGui::SetNextWindowSize(size, ImGuiCond_Always); ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, ImVec2(0.f, 0.f)); ImGui::PushStyleVar(ImGuiStyleVar_WindowBorderSize, 0.f); const std::string id = "##hud_" + m.name(); ImGuiWindowFlags flags = ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoScrollbar | ImGuiWindowFlags_NoScrollWithMouse | ImGuiWindowFlags_NoSavedSettings | ImGuiWindowFlags_NoBackground | ImGuiWindowFlags_NoNav | ImGuiWindowFlags_NoBringToFrontOnFocus; if (!g_menu_open) flags |= ImGuiWindowFlags_NoInputs; if (ImGui::Begin(id.c_str(), nullptr, flags)) { ImGui::InvisibleButton("##drag", size); const bool hovered = ImGui::IsItemHovered(); const bool active = ImGui::IsItemActive(); if (active && ImGui::IsMouseDragging(ImGuiMouseButton_Left, 0.f)) { m.hud_pos.x += io.MouseDelta.x; m.hud_pos.y += io.MouseDelta.y; } 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), 10.f, 0, 1.5f); } ImGui::End(); ImGui::PopStyleVar(2); } } }; inline clickgui& gui() { static clickgui instance; return instance; }