Skip to content
This repository has been archived by the owner on Jun 18, 2024. It is now read-only.

Commit

Permalink
drop shadow, title gradient, bugfixing
Browse files Browse the repository at this point in the history
  • Loading branch information
maxnut committed Mar 12, 2024
1 parent 9e43d72 commit a2abe39
Show file tree
Hide file tree
Showing 14 changed files with 182 additions and 71 deletions.
Binary file modified img/screen.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion mod.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"gd": {
"win": "2.204"
},
"version": "v2.8.0",
"version": "v2.8.1",
"id": "maxnu.gd_mega_overlay",
"name": "GD Mega Overlay",
"developers": ["maxnu", "SpaghettDev"],
Expand Down
22 changes: 11 additions & 11 deletions res/default_windows.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@
"Bypass": {
"h": 540.0,
"w": 200.0,
"x": 0.5027415156364441,
"x": 0.5,
"y": 0.03703703731298447
},
"Creator": {
"h": 120.0,
"w": 200.0,
"x": 0.6179533004760742,
"x": 0.6145833134651184,
"y": 0.03703703731298447
},
"Credits": {
Expand All @@ -20,19 +20,19 @@
"General": {
"h": 270.0,
"w": 200.0,
"x": 0.0417807474732399,
"x": 0.0416666679084301,
"y": 0.03703703731298447
},
"Global": {
"h": 290.0,
"w": 200.0,
"x": 0.15710672736167908,
"x": 0.15625,
"y": 0.03703703731298447
},
"Labels": {
"h": 370.0,
"w": 200.0,
"x": 0.8483765125274658,
"x": 0.84375,
"y": 0.03703703731298447
},
"Level": {
Expand All @@ -44,31 +44,31 @@
"Macrobot": {
"h": 360.0,
"w": 200.0,
"x": 0.04169922694563866,
"x": 0.04169108346104622,
"y": 0.31481480598449707
},
"Menu Settings": {
"h": 440.0,
"h": 500.0,
"w": 200.0,
"x": 0.6179533004760742,
"x": 0.6145833134651184,
"y": 0.1666666716337204
},
"Player": {
"h": 380.0,
"w": 200.0,
"x": 0.38752999901771545,
"x": 0.3854166567325592,
"y": 0.03703703731298447
},
"Recorder": {
"h": 430.0,
"w": 200.0,
"x": 0.1563721001148224,
"x": 0.15670838952064514,
"y": 0.31481480598449707
},
"Shortcuts": {
"h": 530.0,
"w": 200.0,
"x": 0.7311630249023438,
"x": 0.7291666865348816,
"y": 0.03703703731298447
},
"res": {
Expand Down
11 changes: 10 additions & 1 deletion src/Common.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,7 @@ void Common::uncompleteLevel()
{
if (!PlayLayer::get())
{
FLAlertLayer::create("Error", "Enter a level first!", "Ok")->show();
Common::showWithPriority(FLAlertLayer::create("Error", "Enter a level first!", "Ok"));
return;
}
GJGameLevel* level = PlayLayer::get()->m_level;
Expand All @@ -318,4 +318,13 @@ void Common::uncompleteLevel()
level->m_bestTime = 0;

GameLevelManager::sharedState()->saveLevel(level);
}

void Common::showWithPriority(FLAlertLayer* alert)
{
alert->show();
if (auto delegate = typeinfo_cast<CCTouchDelegate*>(alert)) {
if (auto handler = CCTouchDispatcher::get()->findHandler(delegate))
CCTouchDispatcher::get()->setPriority(-600, handler->getDelegate());
}
}
3 changes: 3 additions & 0 deletions src/Common.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include "util.hpp"

class GameObject;
class FLAlertLayer;

namespace cocos2d
{
Expand All @@ -32,4 +33,6 @@ namespace Common
float getTPS();

void updateCheating();

void showWithPriority(FLAlertLayer* alert);
};
1 change: 1 addition & 0 deletions src/GUI/Blur.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,7 @@ void Blur::blurWindowBackground()
ImDrawList* draw_list = ImGui::GetWindowDrawList();

draw_list->PushClipRectFullScreen();

draw_list->AddCallback(blurCallback, nullptr);

//add rect filled doesnt have tex coords so i add them manually
Expand Down
1 change: 1 addition & 0 deletions src/GUI/GUI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ void GUI::init()
windowPositions = json::object();
GUI::loadStyle(Mod::get()->getResourcesDir() / "Style.style");
shortcuts.clear();
shadowTexture = cocos2d::CCTextureCache::get()->addImage("C:\\Users\\MaxNu\\Downloads\\shadow.png", true);
load();
}

Expand Down
3 changes: 3 additions & 0 deletions src/GUI/GUI.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include <nlohmann/json.hpp>
#include <vector>

#include <cocos2d.h>

using json = nlohmann::json;

Expand All @@ -31,6 +32,8 @@ namespace GUI

inline float hideTimer = 0.0f;

inline cocos2d::CCTexture2D* shadowTexture = nullptr;

inline std::function<void()> lateInit;

ImVec2 getJsonPosition(const std::string&);
Expand Down
78 changes: 77 additions & 1 deletion src/GUI/Window.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@
#include "Settings.hpp"
#include "Blur.h"
#include <Geode/Geode.hpp>

#define IMGUI_DEFINE_MATH_OPERATORS
#include "imgui_internal.h"

using namespace geode::prelude;

using namespace GUI;
Expand Down Expand Up @@ -53,7 +57,13 @@ void Window::draw()

ImGui::Begin(name.c_str(), (bool*)0, flags);

if (blurEnabled && !blurGD)
if(Settings::get<bool>("menu/drop_shadow/enabled", true))
dropShadow(Settings::get<float>("menu/drop_shadow/size", 24.f), 255);

if(Settings::get<bool>("menu/title_gradient/enabled", true))
customTitlebar();

if(blurEnabled && !blurGD)
Blur::blurWindowBackground();

if (ImGui::IsMouseDragging(0, 0.1f) && ImGui::IsWindowFocused())
Expand Down Expand Up @@ -83,4 +93,70 @@ void Window::draw()

if (GUI::isVisible && visibleInScreen())
ImGui::End();
}

//https://github.com/ocornut/imgui/issues/4722
void Window::customTitlebar()
{
ImDrawList* draw_list = ImGui::GetWindowDrawList();

draw_list->PushClipRectFullScreen();

ImVec2 min = ImGui::GetCurrentWindow()->TitleBarRect().Min;
ImVec2 max = ImGui::GetCurrentWindow()->TitleBarRect().Max;
auto size_arg = ImVec2(-FLT_MIN, 0.0f);

auto col_bg = ImGui::GetStyleColorVec4(ImGuiCol_TitleBg);

ImVec4 bg_color_1 = {col_bg.x * 0.5f, col_bg.y * 1.5f, col_bg.z * 0.75f, col_bg.w};
ImVec4 bg_color_2 = {col_bg.x * 1.5f, col_bg.y * 0.5f, col_bg.z * 1.25f, col_bg.w};

ImGuiContext& g = *GImGui;
const ImGuiStyle& style = g.Style;

const ImVec2 label_size = ImGui::CalcTextSize(ImGui::GetCurrentWindow()->Name, NULL, true);

ImVec2 pos = {ImGui::GetCurrentWindow()->DC.CursorPos.x, ImGui::GetWindowPos().y};
ImVec2 size = ImGui::CalcItemSize(size_arg, label_size.x + style.FramePadding.x * 2.0f, label_size.y + style.FramePadding.y * 2.0f);

const ImRect bb(pos, pos + size);

int vert_start_idx = draw_list->VtxBuffer.Size;
draw_list->AddRectFilled(min, max, ImGui::GetColorU32(bg_color_1), g.Style.FrameRounding);
int vert_end_idx = draw_list->VtxBuffer.Size;
ImGui::ShadeVertsLinearColorGradientKeepAlpha(draw_list, vert_start_idx, vert_end_idx, min, max, ImGui::GetColorU32(bg_color_1), ImGui::GetColorU32(bg_color_2));
if (g.Style.FrameBorderSize > 0.0f)
draw_list->AddRect(min, max, ImGui::GetColorU32(ImGuiCol_Border), g.Style.FrameRounding, 0, g.Style.FrameBorderSize);

ImGui::RenderTextClipped(bb.Min + style.FramePadding, bb.Max - style.FramePadding, ImGui::GetCurrentWindow()->Name, NULL, &label_size, style.ButtonTextAlign, &bb);

draw_list->PopClipRect();
}

//https://gist.github.com/kpcftsz/b044b43213564f2fb32e8685a50daf6a
void Window::dropShadow(float size, ImU8 opacity)
{
if(!GUI::shadowTexture)
return;

auto tex_id = (ImTextureID)GUI::shadowTexture->getName();
ImVec2 p = ImGui::GetWindowPos();
ImVec2 s = ImGui::GetWindowSize();
ImVec2 m = {p.x + s.x, p.y + s.y};
float uv0 = 0.0f; // left/top region
float uv1 = 0.333333f; // leftward/upper region
float uv2 = 0.666666f; // rightward/lower region
float uv3 = 1.0f; // right/bottom region
ImU32 col = (opacity << 24) | 0xFFFFFF;
ImDrawList* dl = ImGui::GetWindowDrawList();
dl->PushClipRectFullScreen();
dl->AddImage(tex_id, {p.x - size, p.y - size}, {p.x, p.y }, {uv0, uv0}, {uv1, uv1}, col);
dl->AddImage(tex_id, {p.x, p.y - size}, {m.x, p.y }, {uv1, uv0}, {uv2, uv1}, col);
dl->AddImage(tex_id, {m.x, p.y - size}, {m.x + size, p.y }, {uv2, uv0}, {uv3, uv1}, col);
dl->AddImage(tex_id, {p.x - size, p.y }, {p.x, m.y }, {uv0, uv1}, {uv1, uv2}, col);
dl->AddImage(tex_id, {m.x, p.y }, {m.x + size, m.y }, {uv2, uv1}, {uv3, uv2}, col);
dl->AddImage(tex_id, {p.x - size, m.y }, {p.x, m.y + size}, {uv0, uv2}, {uv1, uv3}, col);
dl->AddImage(tex_id, {p.x, m.y }, {m.x, m.y + size}, {uv1, uv2}, {uv2, uv3}, col);
dl->AddImage(tex_id, {m.x, m.y }, {m.x + size, m.y + size}, {uv2, uv2}, {uv3, uv3}, col);
dl->PopClipRect();
}
4 changes: 4 additions & 0 deletions src/GUI/Window.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,9 @@ namespace GUI
void draw();

bool visibleInScreen();

void customTitlebar();

void dropShadow(float size, ImU8 opacity);
};
};
2 changes: 1 addition & 1 deletion src/Macrobot/Clickpacks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ void Clickpacks::drawGUI()
Mod::get()->setSavedValue<std::string>("clickpacks/path", result);
}
else
FLAlertLayer::create("Error", "The folder is not a valid clickpack!", "Ok")->show();
Common::showWithPriority(FLAlertLayer::create("Error", "The folder is not a valid clickpack!", "Ok"));
}
}

Expand Down
Loading

0 comments on commit a2abe39

Please sign in to comment.