added a SHIT ton of modules

This commit is contained in:
st committed 2026-10-14 00:10:39 -05:00
1 parent b1634d195c
commit 361892bf0b
64 files changed
+5346 -482

No files matched your search

+127 -14
View File
@@ -1,5 +1,6 @@
#pragma once
#include <cfloat>
#include <algorithm>
#include <cmath>
#include <string>
#include "imgui.h"
@@ -8,6 +9,7 @@
#include "widgets.h"
#include "../input.h"
#include "../modules/module_manager.h"
#include "../config/profiles.h"
inline std::string key_name(int vk) {
if (vk == 0) return "none";
@@ -34,6 +36,9 @@ public:
void init() {
ImGuiIO& io = ImGui::GetIO();
io.IniFilename = nullptr; // never write imgui.ini into the game's folder
// Minecraft owns the OS cursor. ImGui's WM_SETCURSOR handler must not
// hide it on the window thread while our software cursor is visible.
io.ConfigFlags |= ImGuiConfigFlags_NoMouseCursorChange;
io.LogFilename = nullptr;
fonts::load();
theme::apply();
@@ -49,6 +54,7 @@ public:
if (esc_down && !esc_was_down_ && g_menu_open && !any_binding()) set_open(false);
esc_was_down_ = esc_down;
update_menu_cursor();
open_t_ = theme::approach(open_t_, g_menu_open ? 1.f : 0.f, ImGui::GetIO().DeltaTime * 14.f);
}
@@ -63,6 +69,12 @@ public:
dl->AddRectFilled(ImVec2(0.f, 0.f), io.DisplaySize,
theme::u32(theme::with_alpha(theme::bg(), k_backdrop_alpha * a)));
if(g_menu_open && hud_editor::options.snap && hud_editor::options.show_grid) {
const float spacing=float(std::clamp(hud_editor::options.grid_size,4,64));
const auto color=theme::u32(theme::with_alpha(theme::line(),.22f*a));
for(float x=0;x<io.DisplaySize.x;x+=spacing)dl->AddLine({x,0},{x,io.DisplaySize.y},color);
for(float y=0;y<io.DisplaySize.y;y+=spacing)dl->AddLine({0,y},{io.DisplaySize.x,y},color);
}
// title bar, like the launcher: cube + lowercase wordmark
const ImVec2 logo_pos(26.f, 18.f);
const float logo_h = 30.f;
@@ -90,6 +102,7 @@ public:
ImGui::PushStyleVar(ImGuiStyleVar_Alpha, open_t_);
draw_profiles();
float x = 40.f;
for (category cat : k_categories) {
if (!has_modules(cat)) continue;
@@ -110,6 +123,67 @@ private:
float open_t_ = 0.f;
bool menu_key_was_down_ = false;
bool esc_was_down_ = false;
char profile_name_[49]{};
hud_editor::drag hud_drag_;
void draw_profiles() {
ImGui::SetNextWindowPos(ImVec2(40.f, 56.f), ImGuiCond_Always);
ImGui::SetNextWindowSize(ImVec2(850.f, 0.f), ImGuiCond_Always);
ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, ImVec2(8.f, 4.f));
auto flags = ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoMove |
ImGuiWindowFlags_NoSavedSettings | ImGuiWindowFlags_AlwaysAutoResize;
if (!g_menu_open) flags |= ImGuiWindowFlags_NoInputs;
if (ImGui::Begin("##profiles", nullptr, flags)) {
ImGui::AlignTextToFramePadding(); ImGui::TextUnformatted("profile"); ImGui::SameLine();
ImGui::SetNextItemWidth(200.f);
if (ImGui::BeginCombo("##active", profiles().active().c_str())) {
const auto choices = profiles().names();
for (const auto& name : choices) {
const bool selected = name == profiles().active();
if (ImGui::Selectable(name.c_str(), selected)) profiles().switch_to(name);
if (selected) ImGui::SetItemDefaultFocus();
}
ImGui::EndCombo();
}
ImGui::SameLine(); if (ImGui::Button("save now")) profiles().save();
ImGui::SameLine(); if (ImGui::Button("manage profiles")) { profiles().refresh(); ImGui::OpenPopup("manage profiles"); }
ImGui::SameLine();
ImGui::TextColored(profiles().blocked() ? theme::accent() : theme::muted(), "%s",
profiles().blocked() ? "autosave paused: file error" : profiles().dirty() ? "autosaving..." : "autosave on / saved");
ImGui::SameLine();if(ImGui::Button("hud editor"))ImGui::OpenPopup("hud editor");
if(ImGui::BeginPopup("hud editor")) {
widgets::checkbox("snap to grid",&hud_editor::options.snap,220);
widgets::checkbox("show grid",&hud_editor::options.show_grid,220);
ImGui::TextUnformatted("grid size (px)");ImGui::SetNextItemWidth(220);
ImGui::SliderInt("##grid size",&hud_editor::options.grid_size,4,64);
ImGui::TextColored(theme::muted(),"hold Shift while dragging for free movement");
ImGui::EndPopup();
}
if (ImGui::BeginPopup("manage profiles")) {
ImGui::TextUnformatted("New profiles copy your current settings.");
ImGui::TextUnformatted("Names: letters, numbers, spaces, _ or -");
ImGui::SetNextItemWidth(310.f); ImGui::InputText("name", profile_name_, sizeof(profile_name_));
if (ImGui::Button("create & use")) { if (profiles().create(profile_name_)) profile_name_[0] = 0; }
ImGui::SameLine();
if (ImGui::Button("rename current")) { if (profiles().rename(profile_name_)) profile_name_[0] = 0; }
ImGui::Separator();
if (ImGui::Button("delete current profile")) ImGui::OpenPopup("Delete profile?");
if (ImGui::BeginPopupModal("Delete profile?", nullptr, ImGuiWindowFlags_AlwaysAutoResize)) {
ImGui::Text("Delete '%s'?", profiles().active().c_str());
ImGui::TextUnformatted("Default is protected. Another profile will be loaded.");
if (ImGui::Button("delete")) { if (profiles().remove_active()) ImGui::CloseCurrentPopup(); }
ImGui::SameLine(); if (ImGui::Button("cancel")) ImGui::CloseCurrentPopup();
ImGui::EndPopup();
}
if (!profiles().last_error().empty()) {
ImGui::PushTextWrapPos(ImGui::GetCursorPosX() + 400.f);
ImGui::TextColored(theme::accent(), "%s", profiles().last_error().c_str()); ImGui::PopTextWrapPos();
}
ImGui::EndPopup();
}
}
ImGui::End(); ImGui::PopStyleVar();
}
static const char* category_title(category c) {
switch (c) {
@@ -123,20 +197,33 @@ private:
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
update_menu_cursor();
if (open) {
input::release_cursor();
}
else {
input::restore_cursor();
for (auto& m : modules().all()) m->ui.binding = false;
for (auto& m : modules().all()) {
m->ui.binding = false;
for (auto& s : m->settings()) s.binding = false;
}
}
}
static void update_menu_cursor() {
CURSORINFO cursor{sizeof(cursor)};
const bool native_visible=GetCursorInfo(&cursor) && (cursor.flags&CURSOR_SHOWING);
// Show a software pointer in gameplay, while retaining the native pointer
// in inventory screens. Never change the game's cursor visibility/count.
ImGui::GetIO().MouseDrawCursor=g_menu_open && !native_visible;
}
bool any_binding() const {
for (auto& m : modules().all())
for (auto& m : modules().all()) {
if (m->ui.binding) return true;
for (auto& s : m->settings()) if (s.binding) return true;
}
return false;
}
@@ -151,10 +238,11 @@ private:
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
ImGui::SetNextWindowSizeConstraints(ImVec2(k_panel_w, 0.f),
ImVec2(k_panel_w, (std::max)(100.f, ImGui::GetIO().DisplaySize.y - 145.f)));
ImGuiWindowFlags flags = ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoResize |
ImGuiWindowFlags_NoCollapse | ImGuiWindowFlags_NoScrollbar |
ImGuiWindowFlags_NoScrollWithMouse | ImGuiWindowFlags_NoSavedSettings;
ImGuiWindowFlags_NoCollapse | ImGuiWindowFlags_NoSavedSettings;
if (!g_menu_open) flags |= ImGuiWindowFlags_NoInputs; // fading out: no more clicks
const std::string id = std::string("##panel_") + category_name(cat);
@@ -297,6 +385,32 @@ private:
ImGui::PushID(&s);
switch (s.type) {
case setting_type::text: {
char value[257]{}; strncpy_s(value, s.text_value.c_str(), _TRUNCATE);
ImGui::TextUnformatted(s.name.c_str()); ImGui::SetNextItemWidth(w);
if (ImGui::InputText("##text", value, (std::min)(sizeof(value), size_t(s.int_max + 1)))) s.text_value = value;
break;
}
case setting_type::action:
if (widgets::button("##action", s.name.c_str(), false, w) && s.action) s.action();
break;
case setting_type::keybind: {
ImGui::TextUnformatted(s.name.c_str());
const std::string text = s.binding ? "press a key..." : key_name(s.int_value);
if (widgets::button("##key", text.c_str(), false, w)) s.binding = !s.binding;
if (s.binding) {
for (int vk = 0x08; vk < 0xFF; ++vk) {
if (is_key_down(vk)) {
// Keep modifiers specific so synthetic input and real input can be separated.
if (vk == VK_SHIFT || vk == VK_CONTROL || vk == VK_MENU) continue;
s.int_value = vk == VK_ESCAPE ? 0 : vk;
s.binding = false;
break;
}
}
}
break;
}
case setting_type::toggle:
widgets::checkbox(s.name.c_str(), &s.bool_value, w);
break;
@@ -348,11 +462,10 @@ private:
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);
m.hud_pos = hud_editor::constrain(m.hud_pos,size,io.DisplaySize,false,10);
ImGui::SetNextWindowPos(m.hud_pos, ImGuiCond_Always);
ImGui::SetNextWindowSize(size, ImGuiCond_Always);
ImGui::SetNextWindowSize(m.hud_drag_size(), ImGuiCond_Always);
ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, ImVec2(0.f, 0.f));
ImGui::PushStyleVar(ImGuiStyleVar_WindowBorderSize, 0.f);
@@ -365,14 +478,14 @@ private:
if (!g_menu_open) flags |= ImGuiWindowFlags_NoInputs;
if (ImGui::Begin(id.c_str(), nullptr, flags)) {
ImGui::InvisibleButton("##drag", size);
ImGui::InvisibleButton("##drag", m.hud_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;
}
if(ImGui::IsItemActivated())hud_drag_.begin(m.hud_pos,io.MousePos);
if(g_menu_open && active && ImGui::IsMouseDragging(ImGuiMouseButton_Left,0.f))
m.hud_pos=hud_drag_.move(io.MousePos,size,io.DisplaySize,
hud_editor::options.snap && !io.KeyShift,hud_editor::options.grid_size);
const ImVec4 col = (hovered || active) ? theme::focus() : theme::hover();
ImGui::GetForegroundDrawList()->AddRect(
@@ -388,4 +501,4 @@ private:
inline clickgui& gui() {
static clickgui instance;
return instance;
}
}
+4 -3
View File
@@ -5,7 +5,8 @@
// optional fallback if the Segoe UI files can't be found
#if __has_include("../font_data.h")
#include "../font_data.h"
const unsigned char* amnesia_fallback_font();
int amnesia_fallback_font_size();
#define AMNESIA_HAS_FONT 1
#else
#define AMNESIA_HAS_FONT 0
@@ -55,7 +56,7 @@ namespace fonts {
#if AMNESIA_HAS_FONT
ImFontConfig cfg;
cfg.FontDataOwnedByAtlas = false;
return io.Fonts->AddFontFromMemoryTTF((void*)k_font_data, (int)k_font_size, size, &cfg);
return io.Fonts->AddFontFromMemoryTTF((void*)amnesia_fallback_font(), amnesia_fallback_font_size(), size, &cfg);
#else
return io.Fonts->AddFontDefault();
#endif
@@ -71,4 +72,4 @@ namespace fonts {
io.FontDefault = body;
}
} // namespace fonts
} // namespace fonts
+34
View File
@@ -0,0 +1,34 @@
#pragma once
#include <algorithm>
#include "fonts.h"
#include "theme.h"
namespace hud_card {
inline constexpr float pad_x = 12.f, pad_y = 7.f, gap = 6.f;
inline ImVec2 size(const char* label, const char* value, float scale, const char* reserve = "") {
const auto a = fonts::text_size(fonts::body, fonts::k_body_size, label);
const auto b = fonts::text_size(fonts::semibold, fonts::k_body_size, value);
const auto c = fonts::text_size(fonts::semibold, fonts::k_body_size, reserve);
return ImVec2((pad_x * 2 + a.x + (a.x > 0 ? gap : 0) + (std::max)(b.x, c.x)) * scale,
(pad_y * 2 + (std::max)(a.y, b.y)) * scale);
}
inline void background(ImDrawList* draw, ImVec2 pos, ImVec2 size, float scale, bool enabled, float alpha = 1.f) {
if (!enabled) return;
const ImVec2 end(pos.x + size.x, pos.y + size.y);
draw->AddRectFilled(pos, end, theme::u32(theme::with_alpha(theme::surface(), .85f * alpha)), 10.f * scale);
draw->AddRect(pos, end, theme::u32(theme::with_alpha(theme::line(), alpha)), 10.f * scale, 0, scale);
}
inline void text(ImDrawList* draw, ImFont* font, float scale, ImVec2 pos, ImU32 color, const char* value, bool card) {
if (!card) draw->AddText(font, fonts::k_body_size * scale, ImVec2(pos.x + scale, pos.y + scale),
theme::u32(theme::with_alpha(theme::bg(), .7f)), value);
draw->AddText(font, fonts::k_body_size * scale, pos, color, value);
}
inline void draw(ImVec2 pos, const char* label, const char* value, float scale, bool card, ImU32 color, const char* reserve = "") {
auto* draw = ImGui::GetBackgroundDrawList(); const auto bounds = size(label, value, scale, reserve);
background(draw, pos, bounds, scale, card);
const auto a = fonts::text_size(fonts::body, fonts::k_body_size, label);
const float y = pos.y + pad_y * scale;
text(draw, fonts::body, scale, ImVec2(pos.x + pad_x * scale, y), theme::u32(theme::muted()), label, card);
text(draw, fonts::semibold, scale, ImVec2(pos.x + (pad_x + a.x + (a.x > 0 ? gap : 0)) * scale, y), color, value, card);
}
}
+23
View File
@@ -0,0 +1,23 @@
#pragma once
#include <algorithm>
#include <cmath>
#include "imgui.h"
namespace hud_editor {
struct preferences {bool snap=true,show_grid=true;int grid_size=10;};
inline preferences options;
inline ImVec2 constrain(ImVec2 position,ImVec2 size,ImVec2 screen,bool snap,int spacing) {
const float step=float(std::clamp(spacing,4,64));
if(snap){position.x=std::round(position.x/step)*step;position.y=std::round(position.y/step)*step;}
return {std::clamp(position.x,0.f,(std::max)(0.f,screen.x-size.x)),
std::clamp(position.y,0.f,(std::max)(0.f,screen.y-size.y))};
}
struct drag {
ImVec2 start{},mouse{};
void begin(ImVec2 position,ImVec2 cursor){start=position;mouse=cursor;}
ImVec2 move(ImVec2 cursor,ImVec2 size,ImVec2 screen,bool snap,int spacing) const {
// Keep the unsnapped mouse displacement so small movements accumulate.
return constrain({start.x+cursor.x-mouse.x,start.y+cursor.y-mouse.y},size,screen,snap,spacing);
}
};
}
+71
View File
@@ -0,0 +1,71 @@
#pragma once
#include <algorithm>
#include <chrono>
#include <cmath>
#include <deque>
#include <string>
#include <mutex>
#include "fonts.h"
#include "theme.h"
namespace notifications {
enum class kind { info,success,warning,error };
inline double now() { return std::chrono::duration<double>(std::chrono::steady_clock::now().time_since_epoch()).count(); }
struct toast {
std::string key,title,body;
kind type=kind::info;
double born=0,duration=3;
float progress=-1,y=-1;
};
inline std::deque<toast> items;
inline std::mutex mutex;
inline void dismiss(const std::string& key) {
std::lock_guard lock(mutex);
for(auto& item:items) if(item.key==key) item.duration=(std::max)(0.001,now()-item.born);
}
inline void push(std::string title,std::string body,kind type=kind::info,double duration=3,
std::string key={},float progress=-1) {
std::lock_guard lock(mutex);
if(!key.empty()) for(auto& item:items) if(item.key==key) {
const bool changed=item.title!=title || item.type!=type || item.duration!=duration;
item.title=std::move(title);item.body=std::move(body);item.type=type;
item.duration=duration;item.progress=progress;if(changed) item.born=now();return;
}
if(items.size()>=6) {
auto removable=std::find_if(items.begin(),items.end(),[](const toast& t){return t.duration>0;});
if(removable!=items.end()) items.erase(removable);else items.pop_front();
}
items.push_back({std::move(key),std::move(title),std::move(body),type,now(),duration,progress,-1});
}
inline float entrance(float t) {t=std::clamp(t,0.f,1.f);return 1-(1-t)*(1-t);}
inline void draw() {
std::lock_guard lock(mutex);const double time=now();
for(auto it=items.begin();it!=items.end();) {
if(it->duration>0 && time-it->born>it->duration+.2)it=items.erase(it);else ++it;
}
const auto& io=ImGui::GetIO();auto* draw=ImGui::GetForegroundDrawList();
const float width=std::clamp(io.DisplaySize.x-24.f,140.f,300.f);float y=16;int shown=0;
for(auto it=items.rbegin();it!=items.rend() && shown<3;++it,++shown) {
auto& item=*it;const float age=float(time-item.born),in=std::clamp(age/.18f,0.f,1.f);
const float out=item.duration>0 ? std::clamp((age-float(item.duration))/.2f,0.f,1.f) : 0;
const float alpha=entrance(in)*(1-out);
if(item.y<0)item.y=y;item.y+=(y-item.y)*(1-std::exp(-16.f*io.DeltaTime));
const float x=io.DisplaySize.x-width-16+(1-entrance(in)+out)*8;
fonts::push_font(fonts::body,fonts::k_body_size);
const auto body=ImGui::CalcTextSize(item.body.c_str(),nullptr,false,width-24);ImGui::PopFont();
const float height=28+(item.body.empty() ? 0 : body.y+5)+(item.progress>=0 ? 8 : 0);
auto color=[&](ImVec4 c){c.w*=alpha;return ImGui::ColorConvertFloat4ToU32(c);};
draw->AddRectFilled({x,item.y},{x+width,item.y+height},color(theme::with_alpha(theme::surface(),.85f)),10);
draw->AddRect({x,item.y},{x+width,item.y+height},color(theme::line()),10);
draw->PushClipRect({x+12,item.y},{x+width-12,item.y+height},true);
draw->AddText(fonts::semibold,fonts::k_body_size,{x+12,item.y+7},color(item.type==kind::error ? theme::danger() : theme::fg()),item.title.c_str());
if(!item.body.empty())draw->AddText(fonts::body,fonts::k_body_size,{x+12,item.y+26},color(theme::muted()),item.body.c_str(),nullptr,width-24);
if(item.progress>=0) {
const float p=std::isfinite(item.progress) ? std::clamp(item.progress,0.f,1.f) : 0;
draw->AddRectFilled({x+12,item.y+height-7},{x+width-12,item.y+height-4},color(theme::line()),2);
draw->AddRectFilled({x+12,item.y+height-7},{x+12+(width-24)*p,item.y+height-4},color(theme::accent()),2);
}
draw->PopClipRect();y+=height+8;
}
}
}