lots of stuff

- add TableView virtuals on windows
 - rework events to match new events system
 - rename NodeStringIDManager to NodeIDs and add a syntactically sugary NodeIDs::provideFor function
 - change test mod to use event callbacks instead of exported ones
This commit is contained in:
HJfod 2022-11-12 14:55:25 +02:00
parent 61c0f1b274
commit d701563534
17 changed files with 103 additions and 106 deletions

View file

@ -5215,18 +5215,22 @@ class TableView : CCScrollLayerExt, CCScrollLayerExtDelegate {
static TableView* create(TableViewDelegate*, TableViewDataSource*, cocos2d::CCRect) = mac 0x37eb30, win 0x30ed0;
void reloadData() = mac 0x37f970, win 0x317e0;
virtual void onEnter() = mac 0x37ff30, ios 0x21dcac;
virtual void onExit() = mac 0x37ff40, ios 0x21dcb0;
virtual void onEnter() {
CCLayer::onEnter();
}
virtual void onExit() {
CCLayer::onExit();
}
virtual bool ccTouchBegan(cocos2d::CCTouch*, cocos2d::CCEvent*) = mac 0x380120, ios 0x21de24, win 0x31de0;
virtual void ccTouchMoved(cocos2d::CCTouch*, cocos2d::CCEvent*) = mac 0x380be0, ios 0x21e5e8;
virtual void ccTouchEnded(cocos2d::CCTouch*, cocos2d::CCEvent*) = mac 0x3809a0, ios 0x21e46c;
virtual void ccTouchCancelled(cocos2d::CCTouch*, cocos2d::CCEvent*) = mac 0x380b20, ios 0x21e580;
virtual void registerWithTouchDispatcher() = mac 0x37ff50, ios 0x21dcb4;
virtual void scrollWheel(float, float) = mac 0x380cd0, ios 0x21e6b4;
virtual void scrllViewWillBeginDecelerating(CCScrollLayerExt*) = mac 0x3818a0, ios 0x21efd4;
virtual void scrollViewDidEndDecelerating(CCScrollLayerExt*) = mac 0x3818c0, ios 0x21efdc;
virtual void scrollViewTouchMoving(CCScrollLayerExt*) = mac 0x3818e0, ios 0x21efe4;
virtual void scrollViewDidEndMoving(CCScrollLayerExt*) = mac 0x381900, ios 0x21efec;
virtual void ccTouchMoved(cocos2d::CCTouch*, cocos2d::CCEvent*) = mac 0x380be0, ios 0x21e5e8, win 0x31f30;
virtual void ccTouchEnded(cocos2d::CCTouch*, cocos2d::CCEvent*) = mac 0x3809a0, ios 0x21e46c, win 0x31e80;
virtual void ccTouchCancelled(cocos2d::CCTouch*, cocos2d::CCEvent*) = mac 0x380b20, ios 0x21e580, win 0x31ed0;
virtual void registerWithTouchDispatcher() = mac 0x37ff50, ios 0x21dcb4, win 0x12aa0;
virtual void scrollWheel(float, float) = mac 0x380cd0, ios 0x21e6b4, win 0x320a0;
virtual void scrllViewWillBeginDecelerating(CCScrollLayerExt*) {}
virtual void scrollViewDidEndDecelerating(CCScrollLayerExt*) {}
virtual void scrollViewTouchMoving(CCScrollLayerExt*) {}
virtual void scrollViewDidEndMoving(CCScrollLayerExt*) {}
bool m_touchOutOfBoundary;
cocos2d::CCTouch* m_touchStart;

View file

@ -19,6 +19,7 @@ namespace geode {
virtual void enable();
virtual void disable();
virtual ListenerResult passThrough(Event*) = 0;
virtual ~EventListenerProtocol();
};
template <typename C, typename T>

View file

@ -6,12 +6,12 @@
namespace geode {
enum class ModEventType {
Load,
Unload,
Enable,
Disable,
LoadData,
SaveData,
Loaded,
Unloaded,
Enabled,
Disabled,
DataLoaded,
DataSaved,
};
class GEODE_DLL ModStateEvent : public Event {
@ -25,35 +25,33 @@ namespace geode {
Mod* getMod() const;
};
class GEODE_DLL ModStateEventHandler : public EventHandler<ModStateEvent> {
class GEODE_DLL ModStateFilter : public EventFilter<ModStateEvent> {
public:
using Consumer = void(*)();
using Callback = void(ModStateEvent*);
protected:
ModEventType m_type;
Mod* m_mod;
Consumer m_consumer;
public:
PassThrough handle(ModStateEvent* event) override;
ModStateEventHandler(Mod* mod, ModEventType type, Consumer handler);
ListenerResult handle(std::function<Callback> fn, ModStateEvent* event);
ModStateFilter(Mod* mod, ModEventType type);
};
}
#define $on(type) \
#define $on_mod(type) \
template<class> \
void GEODE_CONCAT(geodeExecFunction, __LINE__)(); \
void GEODE_CONCAT(geodeExecFunction, __LINE__)(ModStateEvent*); \
namespace { \
struct GEODE_CONCAT(ExecFuncUnique, __LINE__) {}; \
} \
static inline auto GEODE_CONCAT(Exec, __LINE__) = (Loader::get()->scheduleOnModLoad(\
nullptr, []() { \
static ModStateEventHandler _(\
Mod::get(),\
ModEventType::type,\
&GEODE_CONCAT(geodeExecFunction, __LINE__)<GEODE_CONCAT(ExecFuncUnique, __LINE__)>\
);\
static inline auto GEODE_CONCAT(Exec, __LINE__) = (geode::Loader::get()->scheduleOnModLoad(\
geode::Mod::get(), []() { \
static auto _ = geode::EventListener( \
&GEODE_CONCAT(geodeExecFunction, __LINE__)<GEODE_CONCAT(ExecFuncUnique, __LINE__)>,\
geode::ModStateFilter(geode::Mod::get(), geode::ModEventType::type)\
); \
} \
), 0); \
template<class> \
void GEODE_CONCAT(geodeExecFunction, __LINE__)()
void GEODE_CONCAT(geodeExecFunction, __LINE__)(ModStateEvent*)

View file

@ -57,14 +57,18 @@ namespace geode {
std::string const& settingID, void (*callback)(std::shared_ptr<T>)
) {
Loader::get()->scheduleOnModLoad(getMod(), [=]() {
static auto _ = EventListener(callback, SettingChangedFilter<T>(getMod()->getID(), settingID));
static auto _ = EventListener(
callback, SettingChangedFilter<T>(getMod()->getID(), settingID)
);
});
return std::monostate();
}
static std::monostate listenForAllSettingChanges(void (*callback)(std::shared_ptr<Setting>)) {
Loader::get()->scheduleOnModLoad(getMod(), [=]() {
static auto _ = EventListener(callback, SettingChangedFilter(getMod()->getID()));
static auto _ = EventListener(
callback, SettingChangedFilter(getMod()->getID())
);
});
return std::monostate();
}

View file

@ -13,7 +13,7 @@ namespace geode {
{ T::CLASS_NAME } -> std::convertible_to<const char*>;
};
class GEODE_DLL NodeStringIDManager {
class GEODE_DLL NodeIDs {
public:
template<class T>
using Provider = void(GEODE_CALL*)(T*);
@ -22,7 +22,7 @@ namespace geode {
std::unordered_map<std::string, Provider<cocos2d::CCNode>> m_providers;
public:
static NodeStringIDManager* get();
static NodeIDs* get();
template<IDProvidable T>
void registerProvider(void(GEODE_CALL* fun)(T*)) {
@ -40,6 +40,12 @@ namespace geode {
}
return false;
}
// @note Because NodeIDs::provideFor(this) looks really neat
template<IDProvidable T>
static bool provideFor(T* layer) {
return NodeIDs::get()->provide(layer);
}
};
template<IDProvidable For>
@ -57,7 +63,7 @@ namespace geode {
void provide();\
};\
$execute {\
NodeStringIDManager::get()->registerProvider(\
NodeIDs::get()->registerProvider(\
&geodeInternalProvideIDsFor<GEODE_CONCAT(ProvideIDsFor, Layer_)>\
);\
};\

View file

@ -26,20 +26,18 @@ namespace geode {
cocos2d::CCNode* getLayer() const;
};
class GEODE_DLL AEnterLayerEventHandler : public EventHandler<AEnterLayerEvent> {
class GEODE_DLL AEnterLayerFilter : public EventFilter<AEnterLayerEvent> {
public:
using Consumer = std::function<void(AEnterLayerEvent*)>;
using Callback = std::function<void(AEnterLayerEvent*)>;
protected:
Consumer m_consumer;
std::optional<std::string> m_targetID;
public:
PassThrough handle(AEnterLayerEvent* event) override;
ListenerResult handle(Callback fn, AEnterLayerEvent* event);
AEnterLayerEventHandler(
std::optional<std::string> const& id,
Consumer handler
AEnterLayerFilter(
std::optional<std::string> const& id
);
};
@ -60,26 +58,23 @@ namespace geode {
concept InheritsEnterLayer = std::is_base_of_v<EnterLayerEvent<N>, T>;
template<class N, InheritsEnterLayer<N> T>
class EnterLayerEventHandler : public EventHandler<EnterLayerEvent<N>> {
class EnterLayerFilter : public EventFilter<EnterLayerEvent<N>> {
public:
using Consumer = std::function<void(T*)>;
using Callback = void(T*);
protected:
Consumer m_consumer;
std::optional<std::string> m_targetID;
public:
PassThrough handle(EnterLayerEvent<N>* event) override {
ListenerResult handle(std::function<Callback> fn, EnterLayerEvent<N>* event) {
if (m_targetID == event->getID()) {
m_consumer(static_cast<T*>(event));
fn(static_cast<T*>(event));
}
return PassThrough::Propagate;
return ListenerResult::Propagate;
}
EnterLayerEventHandler(
std::optional<std::string> const& id,
Consumer handler
) : m_targetID(id),
m_consumer(handler) {}
EnterLayerFilter(
std::optional<std::string> const& id
) : m_targetID(id) {}
};
}

View file

@ -4,16 +4,15 @@
#include <Geode/utils/Ref.hpp>
#include "../ui/internal/info/ModInfoLayer.hpp"
#include "../ui/internal/list/ModListLayer.hpp"
#include <Geode/ui/BasedButtonSprite.hpp>
#include <Geode/ui/MDPopup.hpp>
#include <Geode/ui/Notification.hpp>
#include <Geode/utils/cocos.hpp>
#include <Index.hpp>
#include <InternalLoader.hpp>
#include <Geode/Modify.hpp>
#include "../ids/AddIDs.hpp"
#include <InternalMod.hpp>
#include <Geode/modify/Modify.hpp>
USE_GEODE_NAMESPACE();
@ -64,7 +63,7 @@ static void updateIndexProgress(UpdateStatus status, std::string const& info, ui
}
#include <Geode/modify/MenuLayer.hpp>
class CustomMenuLayer : Modify<CustomMenuLayer, MenuLayer> {
struct CustomMenuLayer : Modify<CustomMenuLayer, MenuLayer> {
void destructor() {
g_geodeButton = nullptr;
MenuLayer::~MenuLayer();
@ -76,7 +75,7 @@ class CustomMenuLayer : Modify<CustomMenuLayer, MenuLayer> {
// make sure to add the string IDs for nodes (Geode has no manual
// hook order support yet so gotta do this to ensure)
NodeStringIDManager::get()->provide(this);
NodeIDs::provideFor(this);
auto winSize = CCDirector::sharedDirector()->getWinSize();

View file

@ -49,7 +49,7 @@ class $modify(CreatorLayer) {
if (!CreatorLayer::init())
return false;
NodeStringIDManager::get()->provide(this);
NodeIDs::get()->provide(this);
return true;
}

View file

@ -2,7 +2,7 @@
using namespace geode;
NodeStringIDManager* NodeStringIDManager::get() {
static auto inst = new NodeStringIDManager;
NodeIDs* NodeIDs::get() {
static auto inst = new NodeIDs;
return inst;
}

View file

@ -34,7 +34,7 @@ class $modify(LevelBrowserLayer) {
if (!LevelBrowserLayer::init(obj))
return false;
NodeStringIDManager::get()->provide(this);
NodeIDs::get()->provide(this);
return true;
}

View file

@ -84,7 +84,7 @@ class $modify(LevelInfoLayer) {
if (!LevelInfoLayer::init(level))
return false;
NodeStringIDManager::get()->provide(this);
NodeIDs::get()->provide(this);
return true;
}

View file

@ -70,7 +70,7 @@ class $modify(LevelSearchLayer) {
if (!LevelSearchLayer::init())
return false;
NodeStringIDManager::get()->provide(this);
NodeIDs::get()->provide(this);
return true;
}

View file

@ -13,8 +13,8 @@ void EventListenerProtocol::disable() {
Event::s_listeners.erase(this);
}
BasicEventHandler::~BasicEventHandler() {
this->unlisten();
EventListenerProtocol::~EventListenerProtocol() {
this->disable();
}
Event::~Event() {}

View file

@ -158,7 +158,7 @@ Result<> Mod::loadData() {
log::log(Severity::Error, this, "Mod load data function returned false");
}
}
ModStateEvent(this, ModEventType::LoadData).post();
ModStateEvent(this, ModEventType::DataLoaded).post();
return this->loadSettings();
}
@ -169,7 +169,7 @@ Result<> Mod::saveData() {
log::log(Severity::Error, this, "Mod save data function returned false");
}
}
ModStateEvent(this, ModEventType::SaveData).post();
ModStateEvent(this, ModEventType::DataSaved).post();
return this->saveSettings();
}
@ -276,7 +276,7 @@ Result<> Mod::load() {
log::log(Severity::Error, this, "Mod load data function returned false");
}
}
ModStateEvent(this, ModEventType::Load).post();
ModStateEvent(this, ModEventType::Loaded).post();
auto loadRes = this->loadData();
if (!loadRes) {
log::warn("Unable to load data for \"{}\": {}", m_info.m_id, loadRes.error());
@ -303,7 +303,7 @@ Result<> Mod::unload() {
if (m_unloadFunc) {
m_unloadFunc();
}
ModStateEvent(this, ModEventType::Unload).post();
ModStateEvent(this, ModEventType::Unloaded).post();
for (auto const& hook : m_hooks) {
auto d = this->disableHook(hook);
@ -340,7 +340,7 @@ Result<> Mod::enable() {
}
}
ModStateEvent(this, ModEventType::Enable).post();
ModStateEvent(this, ModEventType::Enabled).post();
for (auto const& hook : m_hooks) {
auto d = this->enableHook(hook);
@ -369,7 +369,7 @@ Result<> Mod::disable() {
}
}
ModStateEvent(this, ModEventType::Disable).post();
ModStateEvent(this, ModEventType::Disabled).post();
for (auto const& hook : m_hooks) {
auto d = this->disableHook(hook);

View file

@ -12,15 +12,14 @@ Mod* ModStateEvent::getMod() const {
return m_mod;
}
PassThrough ModStateEventHandler::handle(ModStateEvent* event) {
ListenerResult ModStateFilter::handle(std::function<Callback> fn, ModStateEvent* event) {
if (event->getMod() == m_mod && event->getType() == m_type) {
m_consumer();
fn(event);
}
return PassThrough::Propagate;
return ListenerResult::Propagate;
}
ModStateEventHandler::ModStateEventHandler(
ModStateFilter::ModStateFilter(
Mod* mod,
ModEventType type,
Consumer consumer
) : m_mod(mod), m_type(type), m_consumer(consumer) {}
ModEventType type
) : m_mod(mod), m_type(type) {}

View file

@ -16,15 +16,13 @@ cocos2d::CCNode* AEnterLayerEvent::getLayer() const {
return m_layer;
}
PassThrough AEnterLayerEventHandler::handle(AEnterLayerEvent* event) {
ListenerResult AEnterLayerFilter::handle(Callback fn, AEnterLayerEvent* event) {
if (m_targetID == event->getID()) {
m_consumer(event);
fn(event);
}
return PassThrough::Propagate;
return ListenerResult::Propagate;
}
AEnterLayerEventHandler::AEnterLayerEventHandler(
std::optional<std::string> const& id,
Consumer handler
) : m_targetID(id),
m_consumer(handler) {}
AEnterLayerFilter::AEnterLayerFilter(
std::optional<std::string> const& id
) : m_targetID(id) {}

View file

@ -8,24 +8,17 @@ auto test = []() {
};
// Exported functions
GEODE_API bool GEODE_CALL geode_enable() {
$on_mod(Enabled) {
log::info("Enabled");
return true;
}
GEODE_API bool GEODE_CALL geode_disable() {
$on_mod(Disabled) {
log::info("Disabled");
return true;
}
GEODE_API bool GEODE_CALL geode_load(Mod*) {
$on_mod(Loaded) {
log::info("Loaded");
return true;
}
GEODE_API bool GEODE_CALL geode_unload() {
$on_mod(Unloaded) {
log::info("Unloaded");
return true;
}
// Modify