Skip to content

Commit

Permalink
i hate myselff os fucking much i am going to do ti very soon
Browse files Browse the repository at this point in the history
  • Loading branch information
TheSillyDoggo committed Nov 29, 2024
1 parent 782366c commit 77c30b9
Show file tree
Hide file tree
Showing 8 changed files with 75 additions and 28 deletions.
15 changes: 14 additions & 1 deletion resources/midgahack.ini
Original file line number Diff line number Diff line change
@@ -1 +1,14 @@
[Size:Titlebar]
[Colors]
TitleBg = $accent_colour
TitleBgActive = $accent_colour
TitleBgCollapsed = $accent_colour
ModuleDisabled = #2A2A2AFF
ModuleDisabledHovered = #1B1B1BFF
ModuleDisabledActive = #0F0F0FFF

[WidgetSize]
Width = 186
Height = 24

[Offsets]
WindowDistance = 3
58 changes: 39 additions & 19 deletions src/Client/Client.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#include "Client.h"
#include "../Utils/LaunchArgs.hpp"

#include <Geode/modify/CCEGLView.hpp>

Client* Client::get()
{
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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<float, float> yMap;
bool stacking = false;

Expand All @@ -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)
{
Expand Down Expand Up @@ -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<Window*> 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;
Expand All @@ -270,17 +284,19 @@ void Client::toggleWindowVisibility(WindowTransitionType type, bool instant)
if (window->getActionByTag(69))
window->stopActionByTag(69);

bool up = ((as<int>(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;
}
}
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -403,4 +423,4 @@ void Client::loadImGuiTheme(std::string theme)
THEME_COLOUR(NavWindowingHighlight);
THEME_COLOUR(NavWindowingDimBg);
THEME_COLOUR(ModalWindowDimBg);
}
}
1 change: 1 addition & 0 deletions src/Client/Client.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ class Client
Ref<BlurLayer> blurLayer;
bool over = false;
SimpleINI* ini = nullptr;
ImVec2 widgetSize = ImVec2(215, 25);

Client()
{
Expand Down
10 changes: 6 additions & 4 deletions src/Client/Module.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand All @@ -25,7 +27,7 @@ void Module::drawImGui()
Client::get()->hoveredModule = this;

if (f)
ImGui::PopStyleColor(2);
ImGui::PopStyleColor(3);
}

void Module::onOptionsAndroid(CCObject* sender)
Expand Down
7 changes: 4 additions & 3 deletions src/Client/Window.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include "Client.h"
#include "Types/SetValueModule.hpp"
#include <imgui_internal.h>

Window::Window()
{
Expand All @@ -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))
{
Expand All @@ -30,7 +32,7 @@ void Window::drawImGui()

for (auto module : modules)
{
ImGui::PushItemWidth(215);
ImGui::PushItemWidth(Client::get()->widgetSize.x);
module->drawImGui();
}

Expand All @@ -41,10 +43,9 @@ void Window::drawImGui()

ImVec2 Window::getDesiredWindowSize()
{
auto vec = ImVec2(215, 25 * ((std::min<int>(modules.size(), 40) * closedTimer) + 1));
auto vec = ImVec2(Client::get()->widgetSize.x, Client::get()->widgetSize.y * ((std::min<int>(modules.size(), 69) * closedTimer) + 1));

vec.y = clamp<float>(vec.y, 0, ImGui::GetIO().DisplaySize.y - (15 + 15));

return vec;
}

Expand Down
2 changes: 1 addition & 1 deletion src/Client/Windows/Config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down
8 changes: 8 additions & 0 deletions src/Utils/SimpleINI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 2 additions & 0 deletions src/Utils/SimpleINI.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 77c30b9

Please sign in to comment.