mirror of
https://github.com/geode-sdk/geode.git
synced 2025-03-25 04:11:42 -04:00
Merge branch 'main' of https://github.com/geode-sdk/geode
This commit is contained in:
commit
87b8138433
7 changed files with 98 additions and 8 deletions
|
@ -108,7 +108,7 @@ elseif(EXISTS ${GEODE_PLATFORM_BIN_PATH})
|
|||
target_precompile_headers(${PROJECT_NAME} INTERFACE
|
||||
"${GEODE_LOADER_PATH}/include/Geode/DefaultInclude.hpp"
|
||||
"${GEODE_LOADER_PATH}/include/Geode/Loader.hpp"
|
||||
"${GEODE_LOADER_PATH}/include/Geode/Modify.hpp"
|
||||
# please stop adding modify here its not here because it makes windows compilation take longer than geode 1.0 release date
|
||||
"${GEODE_LOADER_PATH}/include/Geode/UI.hpp"
|
||||
"${GEODE_LOADER_PATH}/include/Geode/cocos/include/cocos2d.h"
|
||||
"${GEODE_LOADER_PATH}/include/Geode/cocos/extensions/cocos-ext.h"
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
|
||||
#include <Geode/binding/CCMenuItemSpriteExtra.hpp>
|
||||
#include <Geode/binding/FLAlertLayer.hpp>
|
||||
#include <Geode/utils/MiniFunction.hpp>
|
||||
|
||||
namespace geode {
|
||||
template <typename... InitArgs>
|
||||
|
@ -89,11 +90,11 @@ namespace geode {
|
|||
|
||||
GEODE_DLL FLAlertLayer* createQuickPopup(
|
||||
char const* title, std::string const& content, char const* btn1, char const* btn2,
|
||||
std::function<void(FLAlertLayer*, bool)> selected, bool doShow = true
|
||||
utils::MiniFunction<void(FLAlertLayer*, bool)> selected, bool doShow = true
|
||||
);
|
||||
|
||||
GEODE_DLL FLAlertLayer* createQuickPopup(
|
||||
char const* title, std::string const& content, char const* btn1, char const* btn2,
|
||||
float width, std::function<void(FLAlertLayer*, bool)> selected, bool doShow = true
|
||||
float width, utils::MiniFunction<void(FLAlertLayer*, bool)> selected, bool doShow = true
|
||||
);
|
||||
}
|
||||
|
|
86
loader/include/Geode/utils/MiniFunction.hpp
Normal file
86
loader/include/Geode/utils/MiniFunction.hpp
Normal file
|
@ -0,0 +1,86 @@
|
|||
#pragma once
|
||||
|
||||
#include <Geode/DefaultInclude.hpp>
|
||||
#include <memory>
|
||||
|
||||
namespace geode::utils {
|
||||
|
||||
template <class FunctionType>
|
||||
class MiniFunction;
|
||||
|
||||
template <class Ret, class... Args>
|
||||
class MiniFunctionStateBase {
|
||||
public:
|
||||
virtual ~MiniFunctionStateBase() = default;
|
||||
virtual Ret call(Args... args) const = 0;
|
||||
virtual MiniFunctionStateBase* clone() const = 0;
|
||||
};
|
||||
|
||||
template <class Type, class Ret, class... Args>
|
||||
class MiniFunctionState final : public MiniFunctionStateBase<Ret, Args...> {
|
||||
public:
|
||||
Type m_func;
|
||||
|
||||
explicit MiniFunctionState(Type func) : m_func(std::move(func)) {}
|
||||
|
||||
Ret call(Args... args) const override {
|
||||
return const_cast<Type&>(m_func)(args...);
|
||||
}
|
||||
|
||||
MiniFunctionStateBase<Ret, Args...>* clone() const override {
|
||||
return new MiniFunctionState(*this);
|
||||
}
|
||||
};
|
||||
|
||||
template <class Ret, class... Args>
|
||||
class MiniFunction<Ret(Args...)> {
|
||||
public:
|
||||
using FunctionType = Ret(Args...);
|
||||
using StateType = MiniFunctionStateBase<Ret, Args...>;
|
||||
|
||||
private:
|
||||
StateType* m_state;
|
||||
|
||||
public:
|
||||
MiniFunction() : m_state(nullptr) {}
|
||||
|
||||
MiniFunction(MiniFunction const& other) :
|
||||
m_state(other.m_state ? other.m_state->clone() : nullptr) {}
|
||||
|
||||
MiniFunction(MiniFunction&& other) : m_state(other.m_state) {
|
||||
other.m_state = nullptr;
|
||||
}
|
||||
|
||||
~MiniFunction() {
|
||||
delete m_state;
|
||||
}
|
||||
|
||||
template <class Callable>
|
||||
requires requires(Callable&& func, Args... args) {
|
||||
{ func(args...) } -> std::same_as<Ret>;
|
||||
}
|
||||
MiniFunction(Callable&& func) :
|
||||
m_state(new MiniFunctionState<std::decay_t<Callable>, Ret, Args...>(std::forward<Callable>(func))) {}
|
||||
|
||||
MiniFunction& operator=(MiniFunction const& other) {
|
||||
delete m_state;
|
||||
m_state = other.m_state ? other.m_state->clone() : nullptr;
|
||||
return *this;
|
||||
}
|
||||
|
||||
MiniFunction& operator=(MiniFunction&& other) {
|
||||
delete m_state;
|
||||
m_state = other.m_state;
|
||||
other.m_state = nullptr;
|
||||
return *this;
|
||||
}
|
||||
|
||||
Ret operator()(Args... args) const {
|
||||
return m_state->call(args...);
|
||||
}
|
||||
|
||||
explicit operator bool() const {
|
||||
return m_state;
|
||||
}
|
||||
};
|
||||
}
|
|
@ -2,6 +2,7 @@ cmake_minimum_required(VERSION 3.3.0)
|
|||
|
||||
|
||||
add_library(Bootstrapper SHARED Bootstrapper.cpp)
|
||||
target_compile_features(Bootstrapper PUBLIC cxx_std_17)
|
||||
set_target_properties(Bootstrapper PROPERTIES
|
||||
PREFIX ""
|
||||
OUTPUT_NAME "GeodeBootstrapper"
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
cmake_minimum_required(VERSION 3.3.0)
|
||||
|
||||
add_library(ProxyLoader SHARED proxyLoader.c)
|
||||
target_compile_features(ProxyLoader PUBLIC cxx_std_17)
|
||||
set_target_properties(ProxyLoader PROPERTIES
|
||||
PREFIX ""
|
||||
OUTPUT_NAME "XInput9_1_0"
|
||||
|
@ -21,6 +22,7 @@ set_target_properties(ProxyLoader PROPERTIES
|
|||
)
|
||||
|
||||
add_library(Bootstrapper SHARED Bootstrapper.cpp)
|
||||
target_compile_features(Bootstrapper PUBLIC cxx_std_17)
|
||||
set_target_properties(Bootstrapper PROPERTIES
|
||||
PREFIX ""
|
||||
OUTPUT_NAME "GeodeBootstrapper"
|
||||
|
|
|
@ -136,7 +136,7 @@ namespace {
|
|||
"Are you sure you want to <cr>reset</c> <cl>" + setting->getDisplayName() +
|
||||
"</c> to <cy>default</c>?",
|
||||
"Cancel", "Reset",
|
||||
[this](auto, bool btn2) {
|
||||
[this](FLAlertLayer*, bool btn2) {
|
||||
if (btn2) this->resetToDefault();
|
||||
}
|
||||
);
|
||||
|
|
|
@ -4,7 +4,7 @@ USE_GEODE_NAMESPACE();
|
|||
|
||||
class QuickPopup : public FLAlertLayer, public FLAlertLayerProtocol {
|
||||
protected:
|
||||
std::function<void(FLAlertLayer*, bool)> m_selected;
|
||||
MiniFunction<void(FLAlertLayer*, bool)> m_selected;
|
||||
|
||||
void FLAlert_Clicked(FLAlertLayer* layer, bool btn2) override {
|
||||
if (m_selected) {
|
||||
|
@ -15,7 +15,7 @@ protected:
|
|||
public:
|
||||
static QuickPopup* create(
|
||||
char const* title, std::string const& content, char const* btn1, char const* btn2,
|
||||
float width, std::function<void(FLAlertLayer*, bool)> selected
|
||||
float width, MiniFunction<void(FLAlertLayer*, bool)> selected
|
||||
) {
|
||||
auto inst = new QuickPopup;
|
||||
inst->m_selected = selected;
|
||||
|
@ -30,7 +30,7 @@ public:
|
|||
|
||||
FLAlertLayer* geode::createQuickPopup(
|
||||
char const* title, std::string const& content, char const* btn1, char const* btn2, float width,
|
||||
std::function<void(FLAlertLayer*, bool)> selected, bool doShow
|
||||
MiniFunction<void(FLAlertLayer*, bool)> selected, bool doShow
|
||||
) {
|
||||
auto ret = QuickPopup::create(title, content, btn1, btn2, width, selected);
|
||||
if (doShow) {
|
||||
|
@ -41,7 +41,7 @@ FLAlertLayer* geode::createQuickPopup(
|
|||
|
||||
FLAlertLayer* geode::createQuickPopup(
|
||||
char const* title, std::string const& content, char const* btn1, char const* btn2,
|
||||
std::function<void(FLAlertLayer*, bool)> selected, bool doShow
|
||||
MiniFunction<void(FLAlertLayer*, bool)> selected, bool doShow
|
||||
) {
|
||||
return createQuickPopup(title, content, btn1, btn2, 350.f, selected, doShow);
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue