From ba7ee9113a7f2d52969ec1e6b9a5fb4f23a953a2 Mon Sep 17 00:00:00 2001 From: SpaghettDev <37266659+SpaghettDev@users.noreply.github.com> Date: Sat, 13 Jan 2024 15:25:07 -0600 Subject: [PATCH] Rainbow Menu --- src/GUI/GUI.cpp | 38 +++++++++++++++++++++++++++++++++++- src/GUI/GUI.h | 1 + src/GUI/Widgets.cpp | 16 ++++----------- src/Macrobot/record.cpp | 5 +++-- src/dllmain.cpp | 43 ++++++++++++++++++++++++++--------------- 5 files changed, 72 insertions(+), 31 deletions(-) diff --git a/src/GUI/GUI.cpp b/src/GUI/GUI.cpp index 29646b4..45848e6 100644 --- a/src/GUI/GUI.cpp +++ b/src/GUI/GUI.cpp @@ -274,7 +274,43 @@ void GUI::loadStyle(std::string name) styleFile.close(); } +void GUI::setStyle() +{ + ImGuiStyle& style = ImGui::GetStyle(); + + float r = Settings::get("menu/window/color/r", 1.f); + float g = Settings::get("menu/window/color/g", 0.f); + float b = Settings::get("menu/window/color/b", 0.f); + + if (Settings::get("menu/window/rainbow/enabled")) + { + ImGui::ColorConvertHSVtoRGB( + ImGui::GetTime() * Settings::get("menu/window/rainbow/speed", .4f), + Settings::get("menu/window/rainbow/brightness", .8f), + Settings::get("menu/window/rainbow/brightness"), + r, g, b + ); + + style.Colors[ImGuiCol_Border] = { r, g, b, 1 }; + style.Colors[ImGuiCol_TitleBg] = { r, g, b, 1 }; + style.Colors[ImGuiCol_TitleBgCollapsed] = { r, g, b, 1 }; + style.Colors[ImGuiCol_TitleBgActive] = { r, g, b, 1 }; + + style.Colors[ImGuiCol_Tab] = { r * .85f, g * .85f, b * .85f, 1 }; + style.Colors[ImGuiCol_TabActive] = { r * .85f, g * .85f, b * .85f, 1 }; + style.Colors[ImGuiCol_TabHovered] = { r * .70f, g * .70f, b * .70f, 1 }; + style.Colors[ImGuiCol_TabUnfocused] = { r * .60f, g * .60f, b * .60f, 1 }; + style.Colors[ImGuiCol_TabUnfocusedActive] = { r * .60f, g * .60f, b * .60f, 1 }; + } + else + { + style.Colors[ImGuiCol_TitleBg] = { r, g, b, 1.f }; + style.Colors[ImGuiCol_TitleBgActive] = { r, g, b, 1.f }; + style.Colors[ImGuiCol_TitleBgCollapsed] = { r, g, b, 1.f }; + } +} + bool GUI::shouldRender() { return isVisible && !shortcutLoop; -} \ No newline at end of file +} diff --git a/src/GUI/GUI.h b/src/GUI/GUI.h index d41fe0a..050a984 100644 --- a/src/GUI/GUI.h +++ b/src/GUI/GUI.h @@ -53,6 +53,7 @@ namespace GUI void saveStyle(std::string name); void loadStyle(std::string name); + void setStyle(); bool shouldRender(); }; \ No newline at end of file diff --git a/src/GUI/Widgets.cpp b/src/GUI/Widgets.cpp index 72de403..7a97cda 100644 --- a/src/GUI/Widgets.cpp +++ b/src/GUI/Widgets.cpp @@ -9,11 +9,11 @@ inline ImVec2 operator+(const ImVec2& a, const ImVec2& b) { - return {a.x + b.x, a.y + b.y}; + return { a.x + b.x, a.y + b.y }; } inline ImVec2 operator-(const ImVec2& a, const ImVec2& b) { - return {a.x - b.x, a.y - b.y}; + return { a.x - b.x, a.y - b.y }; } bool GUI::button(std::string name) @@ -83,9 +83,8 @@ bool GUI::hotkey(std::string name, int* keyPointer, const ImVec2& size_arg) if (focus_requested || user_clicked) { if (g.ActiveId != id) - { *keyPointer = 0; - } + ImGui::SetActiveID(id, window); ImGui::FocusWindow(window); } @@ -119,9 +118,7 @@ bool GUI::hotkey(std::string name, int* keyPointer, const ImVec2& size_arg) ImGui::ClearActiveID(); } else - { *keyPointer = key; - } } char buf_display[64] = "None"; @@ -130,13 +127,9 @@ bool GUI::hotkey(std::string name, int* keyPointer, const ImVec2& size_arg) style.FrameRounding); if (*keyPointer != 0 && g.ActiveId != id) - { strcpy_s(buf_display, KeyNames[*keyPointer]); - } else if (g.ActiveId == id) - { strcpy_s(buf_display, ""); - } const ImRect clip_rect(frame_bb.Min.x, frame_bb.Min.y, frame_bb.Min.x + size.x, frame_bb.Min.y + size.y); ImVec2 render_pos = frame_bb.Min + style.FramePadding; @@ -158,9 +151,8 @@ bool GUI::modalPopup(std::string name, const std::function& popupFunctio if (GUI::shouldRender()) { if (ImGui::Button("Cancel")) - { ImGui::CloseCurrentPopup(); - } + ImGui::EndPopup(); } } diff --git a/src/Macrobot/record.cpp b/src/Macrobot/record.cpp index c2be5ca..b26dcdd 100644 --- a/src/Macrobot/record.cpp +++ b/src/Macrobot/record.cpp @@ -2,6 +2,7 @@ #include "../Common.h" #include "../GUI/GUI.h" #include "../Settings.h" +#include "../types/GJGameLevel.hpp" #include "AudioRecord.h" #include "Clickpacks.h" #include "Macrobot.h" @@ -336,9 +337,9 @@ void Recorder::stop_audio() { AudioRecord::stop(); - void* level = MBO(void*, Common::getBGL(), 1504); // found in playlayer_init + gd::GJGameLevel* level = MBO(void*, Common::getBGL(), 1504); // found in playlayer_init - std::string level_id = std::to_string(MBO(int, level, 268) - MBO(int, level, 272)); + std::string level_id = std::to_string(level->m_levelID); std::string video_path = "GDMO/renders/" + level_id + "/final.mp4"; diff --git a/src/dllmain.cpp b/src/dllmain.cpp index d18168a..f595389 100644 --- a/src/dllmain.cpp +++ b/src/dllmain.cpp @@ -163,16 +163,14 @@ void init() GUI::checkbox("Startpos Switcher", Settings::get("level/startpos_switcher")); GUI::arrowButton("Startpos Switcher Settings"); - GUI::modalPopup( - "Startpos Switcher Settings", - [] { - if (GUI::button("Switch Left")) - StartposSwitcher::change(false); + GUI::modalPopup("Startpos Switcher Settings",[] { + if (GUI::button("Switch Left")) + StartposSwitcher::change(false); - if (GUI::button("Switch Right")) - StartposSwitcher::change(true); - }, - ImGuiWindowFlags_AlwaysAutoResize); + if (GUI::button("Switch Right")) + StartposSwitcher::change(true); + }, + ImGuiWindowFlags_AlwaysAutoResize); GUI::checkbox("Replay Last Checkpoint", Settings::get("level/replay_checkpoint")); @@ -198,19 +196,31 @@ void init() if (GUI::inputFloat("Window Opacity", &windowOpacity, 0.f, 1.f)) Settings::set("menu/window/opacity", windowOpacity); - float windowColor[3]{}; - windowColor[0] = Settings::get("menu/window/color/r", 1.f); - windowColor[1] = Settings::get("menu/window/color/g", 0.f); - windowColor[2] = Settings::get("menu/window/color/b", 0.f); + GUI::checkbox("Rainbow Menu", Settings::get("menu/window/rainbow/enabled")); + + GUI::arrowButton("Rainbow Menu Settings"); + GUI::modalPopup("Rainbow Menu Settings", [] { + float speed = Settings::get("menu/window/rainbow/speed", .4f); + if (GUI::inputFloat("Rainbow Speed", &speed, .1f, 2.f)) + Settings::set("menu/window/rainbow/speed", speed); + + float brightness = Settings::get("menu/window/rainbow/brightness", .8f); + if (GUI::inputFloat("Rainbow Brightness", &brightness, .1f, 2.f)) + Settings::set("menu/window/rainbow/brightness", brightness); + }, + ImGuiWindowFlags_AlwaysAutoResize); + + float windowColor[3]{ + Settings::get("menu/window/color/r", 1.f), + Settings::get("menu/window/color/g", .0f), + Settings::get("menu/window/color/b", .0f) + }; if (GUI::colorEdit("Window Color", windowColor)) { Settings::set("menu/window/color/r", windowColor[0]); Settings::set("menu/window/color/g", windowColor[1]); Settings::set("menu/window/color/b", windowColor[2]); - ImGui::GetStyle().Colors[ImGuiCol_TitleBg] = {windowColor[0], windowColor[1], windowColor[2], 1.f}; - ImGui::GetStyle().Colors[ImGuiCol_TitleBgActive] = {windowColor[0], windowColor[1], windowColor[2], 1.f}; - ImGui::GetStyle().Colors[ImGuiCol_TitleBgCollapsed] = {windowColor[0], windowColor[1], windowColor[2], 1.f}; } }); GUI::addWindow(menuSettings); @@ -256,6 +266,7 @@ void render() } GUI::draw(); + GUI::setStyle(); if (DiscordRPCManager::core) DiscordRPCManager::core->RunCallbacks();