From 3db14e830acdbf01325df17834b9524e6f542458 Mon Sep 17 00:00:00 2001 From: HJfod <60038575+HJfod@users.noreply.github.com> Date: Wed, 10 Jul 2024 23:57:20 +0300 Subject: [PATCH] bake pro features into BE on compilation --- CMakeLists.txt | 25 +++++++++++++++++----- src/features/Keybinds.cpp | 20 ++++++++++++++++++ src/features/MoveMenu.cpp | 6 +++++- src/features/scaling/EditorUIScaling.cpp | 4 ++++ src/utils/Pro.cpp | 10 --------- src/utils/Pro.hpp | 27 +++++++++++++++++++++++- src/utils/Warn.hpp | 9 +++++--- 7 files changed, 81 insertions(+), 20 deletions(-) delete mode 100644 src/utils/Pro.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt index 15b1100..f8df685 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -6,6 +6,13 @@ set(CMAKE_CXX_VISIBILITY_PRESET hidden) project(BetterEdit VERSION 1.0.0) +if (EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/pro/) + message(STATUS "Including Pro features") + set(BE_PRO_FOUND TRUE) +else() + message(STATUS "Including only free features, no Pro") +endif() + file(GLOB SOURCES src/features/*.cpp src/features/scaling/*.cpp @@ -18,9 +25,21 @@ file(GLOB SOURCES src/*.cpp ) -add_library(${PROJECT_NAME} SHARED ${SOURCES}) +if (${BE_PRO_FOUND}) + file(GLOB PRO_SOURCES + pro/*.cpp + pro/features/*.cpp + pro/ui/*.cpp + ) +endif() + +add_library(${PROJECT_NAME} SHARED ${SOURCES} ${PRO_SOURCES}) target_include_directories(${PROJECT_NAME} PUBLIC "src") +if (${BE_PRO_FOUND}) + target_include_directories(${PROJECT_NAME} PUBLIC "") + target_compile_definitions(${PROJECT_NAME} PUBLIC BETTEREDIT_PRO) +endif() if (NOT DEFINED ENV{GEODE_SDK}) message(FATAL_ERROR "Unable to find Geode SDK! Please define GEODE_SDK environment variable to point to Geode") @@ -32,10 +51,6 @@ add_subdirectory($ENV{GEODE_SDK} ${CMAKE_CURRENT_BINARY_DIR}/geode) setup_geode_mod(${PROJECT_NAME}) -if (EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/pro/) - add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/pro) -endif() - # Bad code will NOT be deployed! if(MSVC) target_compile_options(${PROJECT_NAME} PRIVATE /W4) diff --git a/src/features/Keybinds.cpp b/src/features/Keybinds.cpp index d1e5d2b..e6cda15 100644 --- a/src/features/Keybinds.cpp +++ b/src/features/Keybinds.cpp @@ -9,6 +9,10 @@ #include #include +#ifdef BETTEREDIT_PRO +#include +#endif + using namespace geode::prelude; using namespace keybinds; @@ -137,6 +141,12 @@ struct $modify(EditorUI) { this->defineKeybind("move-obj-big-down"_spr, [this] { this->moveObjectCall(EditCommand::BigDown); }); + + #ifdef BETTEREDIT_PRO + this->defineKeybind("group-summary"_spr, [this] { + GroupSummaryPopup::create()->show(); + }); + #endif return true; } @@ -412,6 +422,16 @@ struct $modify(EditorUI) { {}, Category::EDITOR_MOVE, true }); + +#ifdef BETTEREDIT_PRO + BindManager::get()->registerBindable({ + "group-summary"_spr, + "Open Group Summary", + "", + {}, + Category::EDITOR, false + }); +#endif } #endif diff --git a/src/features/MoveMenu.cpp b/src/features/MoveMenu.cpp index 1ae257e..b2053dd 100644 --- a/src/features/MoveMenu.cpp +++ b/src/features/MoveMenu.cpp @@ -179,7 +179,11 @@ class CustomEditMenu : public CCNode { return menu; } - if (!Mod::get()->template getSettingValue("new-edit-menu") || isProUIEnabled()) { + if (!Mod::get()->template getSettingValue("new-edit-menu")) { + return nullptr; + } + + if (isProUIEnabled()) { return nullptr; } diff --git a/src/features/scaling/EditorUIScaling.cpp b/src/features/scaling/EditorUIScaling.cpp index 85f18fe..84b0cbd 100644 --- a/src/features/scaling/EditorUIScaling.cpp +++ b/src/features/scaling/EditorUIScaling.cpp @@ -158,6 +158,10 @@ class $modify(ScaledUI, EditorUI) { } void centerBuildTabs() { + if (isProUIEnabled()) { + return; + } + // This centers the build tab auto winSize = CCDirector::get()->getWinSize(); for (auto c : CCArrayExt(this->getChildren())) { diff --git a/src/utils/Pro.cpp b/src/utils/Pro.cpp deleted file mode 100644 index d8ca5d1..0000000 --- a/src/utils/Pro.cpp +++ /dev/null @@ -1,10 +0,0 @@ -#include "Pro.hpp" -#include - -using namespace geode::prelude; - -bool isProUIEnabled() { - auto pro = Loader::get()->getLoadedMod("hjfod.betteredit-pro"); - // geode-ignore-unknown-setting - return pro && pro->template getSettingValue("pro-ui"); -} diff --git a/src/utils/Pro.hpp b/src/utils/Pro.hpp index 0c87d3f..d5896fd 100644 --- a/src/utils/Pro.hpp +++ b/src/utils/Pro.hpp @@ -1,3 +1,28 @@ #pragma once -bool isProUIEnabled(); +#include "Warn.hpp" + +#ifdef BETTEREDIT_PRO +#include +#include +#endif + +BE_ALLOW_START +BE_ALLOW_UNUSED_FUNCTION + +static bool isProUIEnabled() { +#ifdef BETTEREDIT_PRO + return pro::isNewUIEnabled(); +#else + return false; +#endif +} +static bool isProEnabled() { +#ifdef BETTEREDIT_PRO + return pro::isProEnabled(); +#else + return false; +#endif +} + +BE_ALLOW_END diff --git a/src/utils/Warn.hpp b/src/utils/Warn.hpp index 418d22c..8cebc64 100644 --- a/src/utils/Warn.hpp +++ b/src/utils/Warn.hpp @@ -7,9 +7,10 @@ #define BE_ALLOW_END __pragma(warning( pop )) #define BE_ALLOW_MSVC(warningNumber) __pragma(warning( disable : warningNumber )) - #define BE_ALLOW_SHADOWING BE_ALLOW_MSVC(4458) - #define BE_ALLOW_FAKE_ENUMS BE_ALLOW_MSVC(4063) - #define BE_ALLOW_UNUSED_PARAMS BE_ALLOW_MSVC(4100) + #define BE_ALLOW_SHADOWING BE_ALLOW_MSVC(4458) + #define BE_ALLOW_FAKE_ENUMS BE_ALLOW_MSVC(4063) + #define BE_ALLOW_UNUSED_PARAMS BE_ALLOW_MSVC(4100) + #define BE_ALLOW_UNUSED_FUNCTION BE_ALLOW_MSVC(4505) #elif defined(__GNUC__) || defined(__clang__) #define DO_PRAGMA(X) _Pragma(#X) #define BE_ALLOW_START DO_PRAGMA(GCC diagnostic push) @@ -19,12 +20,14 @@ #define BE_ALLOW_SHADOWING BE_ALLOW_CLANG(-Wshadow) #define BE_ALLOW_FAKE_ENUMS #define BE_ALLOW_UNUSED_PARAMS BE_ALLOW_CLANG(-Wunused-parameter) + #define BE_ALLOW_UNUSED_FUNCTION #else #define BE_ALLOW_START #define BE_ALLOW_END #define BE_ALLOW_SHADOWING #define BE_ALLOW_FAKE_ENUMS #define BE_ALLOW_UNUSED_PARAMS + #define BE_ALLOW_UNUSED_FUNCTION #endif #define $be_ensure_hookable(...) static_assert(requires { __VA_ARGS__; })