From 77c30b97599c938f29670fb5a422f4001e672f81 Mon Sep 17 00:00:00 2001 From: Explodingbill Date: Fri, 29 Nov 2024 19:34:56 +1100 Subject: [PATCH] i hate myselff os fucking much i am going to do ti very soon --- resources/midgahack.ini | 15 ++++++++- src/Client/Client.cpp | 58 +++++++++++++++++++++++------------ src/Client/Client.h | 1 + src/Client/Module.cpp | 10 +++--- src/Client/Window.cpp | 7 +++-- src/Client/Windows/Config.cpp | 2 +- src/Utils/SimpleINI.cpp | 8 +++++ src/Utils/SimpleINI.hpp | 2 ++ 8 files changed, 75 insertions(+), 28 deletions(-) diff --git a/resources/midgahack.ini b/resources/midgahack.ini index 0c3d6c6..2e9480d 100644 --- a/resources/midgahack.ini +++ b/resources/midgahack.ini @@ -1 +1,14 @@ -[Size:Titlebar] \ No newline at end of file +[Colors] +TitleBg = $accent_colour +TitleBgActive = $accent_colour +TitleBgCollapsed = $accent_colour +ModuleDisabled = #2A2A2AFF +ModuleDisabledHovered = #1B1B1BFF +ModuleDisabledActive = #0F0F0FFF + +[WidgetSize] +Width = 186 +Height = 24 + +[Offsets] +WindowDistance = 3 \ No newline at end of file diff --git a/src/Client/Client.cpp b/src/Client/Client.cpp index 68b2a7d..2206889 100644 --- a/src/Client/Client.cpp +++ b/src/Client/Client.cpp @@ -1,6 +1,6 @@ #include "Client.h" #include "../Utils/LaunchArgs.hpp" - +#include Client* Client::get() { @@ -76,7 +76,7 @@ void Client::initImGui() io->ConfigWindowsMoveFromTitleBarOnly = true; - style->FramePadding = ImVec2(3, 6); + style->FramePadding = ImVec2(3, 4); style->ItemSpacing = ImVec2(0, 0); style->WindowPadding = ImVec2(0, 0); style->Colors[ImGuiCol_TitleBg] = ImVec4(20.0f / 255, 20.0f / 255, 20.0f / 255, 1); @@ -122,21 +122,25 @@ void Client::drawImGui() if (hoveredModule && !hoveredModule->description.empty()) { - // ImGui::SetNextWindowPos(hoveredModule->lastRenderedPosition); + // // ImGui::SetNextWindowPos(hoveredModule->lastRenderedPosition); + + // ImGui::SetNextWindowPos(ImVec2(ImGui::GetMousePos().x + 12.5f, ImGui::GetMousePos().y)); - ImGui::SetNextWindowPos(ImVec2(ImGui::GetMousePos().x + 12.5f, ImGui::GetMousePos().y)); + // ImGui::Begin("Description Window", nullptr, ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoFocusOnAppearing | ImGuiWindowFlags_NoNavFocus | ImGuiWindowFlags_NoInputs | ImGuiWindowFlags_AlwaysAutoResize | ImGuiWindowFlags_Tooltip | ImGuiWindowFlags_NoBackground); - ImGui::Begin("Description Window", nullptr, ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoFocusOnAppearing | ImGuiWindowFlags_NoNavFocus | ImGuiWindowFlags_NoInputs | ImGuiWindowFlags_AlwaysAutoResize | ImGuiWindowFlags_Tooltip | ImGuiWindowFlags_NoBackground); + // ImGui::SetCursorPos(ImVec2(ImGui::GetMousePos().x + 12.5f, ImGui::GetMousePos().y)); ImGuiExt::colouredText(hoveredModule->description); - ImGui::End(); + // ImGui::End(); } } void Client::sortWindows(bool instant) { - float x = 15; + float offset = ini->getKeyValueFloat("Offsets::WindowDistance", "15"); + + float x = offset; std::map yMap; bool stacking = false; @@ -148,30 +152,30 @@ void Client::sortWindows(bool instant) for (auto window : windows) { if (!yMap.contains(x)) - yMap[x] = 15; + yMap[x] = offset; if (x + window->getDesiredWindowSize().x > ImGui::GetIO().DisplaySize.x) { - x = 15; + x = offset; stacking = true; } - ImVec2 wndPos = ImVec2(x, yMap[x + window->getDesiredWindowSize().x + 15]); + ImVec2 wndPos = ImVec2(x, yMap[x + window->getDesiredWindowSize().x + offset]); for (size_t i = 0; i < 8; i++) { if (wndPos.y + window->getDesiredWindowSize().y > ImGui::GetIO().DisplaySize.y) { - x += window->getDesiredWindowSize().x + 15; + x += window->getDesiredWindowSize().x + offset; - wndPos = ImVec2(x, yMap[x + window->getDesiredWindowSize().x + 15]); + wndPos = ImVec2(x, yMap[x + window->getDesiredWindowSize().x + offset]); } } - x += window->getDesiredWindowSize().x + 15; - yMap[x] += window->getDesiredWindowSize().y + 15; + x += window->getDesiredWindowSize().x + offset; + yMap[x] += window->getDesiredWindowSize().y + offset; - wndPos.y += 15; + wndPos.y += offset; if (instant) { @@ -256,6 +260,16 @@ void Client::toggleWindowVisibility(WindowTransitionType type, bool instant) if (blurLayer) blurLayer->runAction(CCFadeTo::create(!isWindowOpen ? 0.15f : 0.5f, isWindowOpen ? 255 : 0)); + std::vector windows = this->windows; + + std::sort(windows.begin(), windows.end(), [](Window* a, Window* b) + { + return a->getPosition().x < b->getPosition().x; + }); + + bool verticalUp; + float lastX = 0; + for (auto window : windows) { CCAction* fade; @@ -270,17 +284,19 @@ void Client::toggleWindowVisibility(WindowTransitionType type, bool instant) if (window->getActionByTag(69)) window->stopActionByTag(69); - bool up = ((as(window->getPosition().x) - 15) % 235 * 2) == 0 ? true : false; + bool verticalUp = window->getPosition().y > ImGui::GetIO().DisplaySize.y / 2; if (window->windowPos.x == window->actualWindowPos.x && window->windowPos.y == window->actualWindowPos.y) { - window->setPosition(ccp(window->actualWindowPos.x, window->actualWindowPos.y + (!isWindowOpen ? 0 : (ImGui::GetIO().DisplaySize.y + window->getDesiredWindowSize().y) * (up ? 1 : -1)))); + window->setPosition(ccp(window->actualWindowPos.x, window->actualWindowPos.y + (!isWindowOpen ? 0 : (ImGui::GetIO().DisplaySize.y + window->getDesiredWindowSize().y) * (verticalUp ? 1 : -1)))); } - verticalMove = CCEaseInOut::create(CCMoveTo::create(instant ? 0 : 0.5f, ccp(window->actualWindowPos.x, window->actualWindowPos.y + (isWindowOpen ? 0 : (ImGui::GetIO().DisplaySize.y + window->getDesiredWindowSize().y) * (up ? 1 : -1)))), 2); + verticalMove = CCEaseInOut::create(CCMoveTo::create(instant ? 0 : 0.5f, ccp(window->actualWindowPos.x, window->actualWindowPos.y + (isWindowOpen ? 0 : (ImGui::GetIO().DisplaySize.y + window->getDesiredWindowSize().y) * (verticalUp ? 1 : -1)))), 2); verticalMove->setTag(69); window->runAction(verticalMove); + + lastX = window->getPosition().x; break; } } @@ -348,6 +364,10 @@ void Client::loadImGuiTheme(std::string theme) ini = SimpleINI::createWithFile((Mod::get()->getResourcesDir() / theme).string()); + ini->addVariable("accent_colour", fmt::format("#{}", cc4bToHexString(ccc4(207, 67, 115, 255)))); + + widgetSize = ImVec2(ini->getKeyValueFloat("WidgetSize::Width", "215"), ini->getKeyValueFloat("WidgetSize::Height", "25")); + auto style = &ImGui::GetStyle(); THEME_COLOUR(Text); @@ -403,4 +423,4 @@ void Client::loadImGuiTheme(std::string theme) THEME_COLOUR(NavWindowingHighlight); THEME_COLOUR(NavWindowingDimBg); THEME_COLOUR(ModalWindowDimBg); -} \ No newline at end of file +} diff --git a/src/Client/Client.h b/src/Client/Client.h index 805cf81..dbaabfe 100644 --- a/src/Client/Client.h +++ b/src/Client/Client.h @@ -44,6 +44,7 @@ class Client Ref blurLayer; bool over = false; SimpleINI* ini = nullptr; + ImVec2 widgetSize = ImVec2(215, 25); Client() { diff --git a/src/Client/Module.cpp b/src/Client/Module.cpp index c6ffc72..438256e 100644 --- a/src/Client/Module.cpp +++ b/src/Client/Module.cpp @@ -2,19 +2,21 @@ #include "../Layers/ModuleOptionsLayer.h" #include "Dropdown.h" +#include "Client.h" void Module::drawImGui() { bool f = false; if (!enabled) { - ImGui::PushStyleColor(ImGuiCol_Button, ImVec4(40 / 255.0f, 40 / 255.0f, 40 / 255.0f, 1)); - ImGui::PushStyleColor(ImGuiCol_ButtonHovered, ImVec4(50 / 255.0f, 50 / 255.0f, 50 / 255.0f, 1)); + ImGui::PushStyleColor(ImGuiCol_Button, ccc4ToVec(Client::get()->getThemeColour("ModuleDisabled", ccc4(40, 40, 40, 255)))); + ImGui::PushStyleColor(ImGuiCol_ButtonHovered, ccc4ToVec(Client::get()->getThemeColour("ModuleDisabledHovered", ccc4(50, 50, 50, 255)))); + ImGui::PushStyleColor(ImGuiCol_ButtonActive, ccc4ToVec(Client::get()->getThemeColour("ModuleDisabledActive", ccc4(50, 50, 50, 255)))); f = true; } - if (ImGui::Button(this->name.c_str(), ImVec2(215, 25))) + if (ImGui::Button(this->name.c_str(), Client::get()->widgetSize)) { onToggleAndroid(nullptr); } @@ -25,7 +27,7 @@ void Module::drawImGui() Client::get()->hoveredModule = this; if (f) - ImGui::PopStyleColor(2); + ImGui::PopStyleColor(3); } void Module::onOptionsAndroid(CCObject* sender) diff --git a/src/Client/Window.cpp b/src/Client/Window.cpp index bffa37c..ebc0063 100644 --- a/src/Client/Window.cpp +++ b/src/Client/Window.cpp @@ -1,5 +1,6 @@ #include "Client.h" #include "Types/SetValueModule.hpp" +#include Window::Window() { @@ -16,6 +17,7 @@ void Window::drawImGui() ImGui::SetNextWindowSize(getDesiredWindowSize()); ImGui::Begin(this->name.c_str(), nullptr, ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoCollapse); + ImGui::GetCurrentWindow()->TitleBarHeight = Client::get()->widgetSize.y; if (ImGui::IsWindowHovered() && ImGui::IsMouseDown(ImGuiMouseButton_Left)) { @@ -30,7 +32,7 @@ void Window::drawImGui() for (auto module : modules) { - ImGui::PushItemWidth(215); + ImGui::PushItemWidth(Client::get()->widgetSize.x); module->drawImGui(); } @@ -41,10 +43,9 @@ void Window::drawImGui() ImVec2 Window::getDesiredWindowSize() { - auto vec = ImVec2(215, 25 * ((std::min(modules.size(), 40) * closedTimer) + 1)); + auto vec = ImVec2(Client::get()->widgetSize.x, Client::get()->widgetSize.y * ((std::min(modules.size(), 69) * closedTimer) + 1)); vec.y = clamp(vec.y, 0, ImGui::GetIO().DisplaySize.y - (15 + 15)); - return vec; } diff --git a/src/Client/Windows/Config.cpp b/src/Client/Windows/Config.cpp index 44119de..62d7117 100644 --- a/src/Client/Windows/Config.cpp +++ b/src/Client/Windows/Config.cpp @@ -672,7 +672,7 @@ void Config::drawImGui() Client::get()->sortWindows(false); if (ImGui::Button("Reload Theme")) - Client::get()->loadImGuiTheme("catppuccin-frappe.ini"); + Client::get()->loadImGuiTheme("midgahack.ini"); for (auto module : modules) { diff --git a/src/Utils/SimpleINI.cpp b/src/Utils/SimpleINI.cpp index 7e854ca..c43e2e6 100644 --- a/src/Utils/SimpleINI.cpp +++ b/src/Utils/SimpleINI.cpp @@ -69,6 +69,14 @@ bool SimpleINI::init(std::string data) return true; } +void SimpleINI::addVariable(std::string varName, std::string varVal) +{ + for (auto hKey : headerKeys) + { + headerKeys.at(hKey.first) = utils::string::replace(hKey.second, fmt::format("${}", varName), varVal); + } +} + bool SimpleINI::hasKey(std::string key) { return headerKeys.contains(key); diff --git a/src/Utils/SimpleINI.hpp b/src/Utils/SimpleINI.hpp index 78bd879..b993306 100644 --- a/src/Utils/SimpleINI.hpp +++ b/src/Utils/SimpleINI.hpp @@ -16,6 +16,8 @@ class SimpleINI bool init(std::string data); + void addVariable(std::string varName, std::string varVal); + bool hasKey(std::string key); std::string getKeyValue(std::string key, std::string def); float getKeyValueFloat(std::string key, std::string def);