1+ #pragma once
2+
3+ #include " Keybinds.hpp"
4+ #include < Geode/loader/Dispatch.hpp>
5+
6+ #ifdef MY_MOD_ID
7+ #undef MY_MOD_ID
8+ #endif
9+ #define MY_MOD_ID " geode.custom-keybinds"
10+
11+ namespace keybinds {
12+ enum class Modifier2 : unsigned int {
13+ None = 0b0000 ,
14+ Control = 0b0001 ,
15+ Shift = 0b0010 ,
16+ Alt = 0b0100 ,
17+ Command = 0b1000 ,
18+ };
19+
20+ inline Modifier2 operator |(Modifier2 const & a, Modifier2 const & b) {
21+ return static_cast <Modifier2>(static_cast <unsigned int >(a) | static_cast <unsigned int >(b));
22+ }
23+
24+ inline Modifier2& operator |=(Modifier2& a, Modifier2 const & b) {
25+ a = a | b;
26+ return a;
27+ }
28+
29+ inline bool operator &(Modifier2 const & a, Modifier2 const & b) {
30+ return (static_cast <unsigned int >(a) & static_cast <unsigned int >(b)) != 0 ;
31+ }
32+
33+ // TODO: move actual classes into these in v2
34+ class KeybindV2 final {
35+ class Impl ;
36+ std::unique_ptr<Impl> m_impl;
37+ public:
38+ static geode::Result<Keybind*> create (cocos2d::enumKeyCodes key, Modifier modifiers = Modifier::None) GEODE_EVENT_EXPORT(&KeybindV2::create, (key, modifiers));
39+ };
40+
41+ class MouseBindV2 final {
42+ class Impl ;
43+ std::unique_ptr<Impl> m_impl;
44+ public:
45+ static geode::Result<MouseBind*> create (MouseButton button, Modifier modifiers = Modifier::None) GEODE_EVENT_EXPORT(&MouseBindV2::create, (button, modifiers));
46+ };
47+
48+ class ControllerBindV2 final {
49+ class Impl ;
50+ std::unique_ptr<Impl> m_impl;
51+ public:
52+ static geode::Result<ControllerBind*> create (cocos2d::enumKeyCodes button) GEODE_EVENT_EXPORT(&ControllerBindV2::create, (button));
53+ };
54+
55+
56+ class CategoryV2 final {
57+ class Impl ;
58+ std::unique_ptr<Impl> m_impl;
59+ public:
60+ static geode::Result<std::shared_ptr<Category>> create (std::string_view path) GEODE_EVENT_EXPORT(&CategoryV2::create, (path));
61+
62+ static inline auto const PLAY = CategoryV2::create(" Play" );
63+ static inline auto const PLAY_PAUSE = CategoryV2::create(" Play/Pause" );
64+ static inline auto const EDITOR = CategoryV2::create(" Editor" );
65+ static inline auto const GLOBAL = CategoryV2::create(" Global" );
66+ static inline auto const EDITOR_UI = CategoryV2::create(" Editor/UI" );
67+ static inline auto const EDITOR_MODIFY = CategoryV2::create(" Editor/Modify" );
68+ static inline auto const EDITOR_MOVE = CategoryV2::create(" Editor/Move" );
69+ };
70+
71+ class BindableActionV2 final {
72+ class Impl ;
73+ std::unique_ptr<Impl> m_impl;
74+ public:
75+ static geode::Result<std::shared_ptr<BindableAction>> create (
76+ ActionID const & id,
77+ std::string const & name,
78+ std::string const & description = " " ,
79+ std::vector<geode::Ref<Bind>> const & defaults = {},
80+ std::shared_ptr<Category> category = {},
81+ bool repeatable = true ,
82+ geode::Mod* owner = geode::Mod::get()
83+ ) GEODE_EVENT_EXPORT(&BindableActionV2::create, (id, name, description, defaults, category, repeatable, owner));
84+ };
85+
86+ class InvokeBindEventV2 final : public geode::Event {
87+ private:
88+ ActionID m_id;
89+ bool m_down;
90+
91+ friend class BindManager ;
92+ friend class InvokeBindFilterV2 ;
93+
94+ public:
95+ InvokeBindEventV2 (ActionID const & id, bool down) : m_id(id), m_down(down) {}
96+ ActionID getID () const {
97+ return m_id;
98+ }
99+ bool isDown () const {
100+ return m_down;
101+ }
102+ };
103+
104+ class InvokeBindFilterV2 final : public geode::EventFilter<InvokeBindEventV2> {
105+ private:
106+ cocos2d::CCNode* m_target;
107+ ActionID m_id;
108+
109+ public:
110+ using Callback = geode::ListenerResult(InvokeBindEventV2*);
111+
112+ geode::ListenerResult handle (std::function<Callback> fn, InvokeBindEventV2* event) {
113+ if (event->getID () == m_id) {
114+ return fn (event);
115+ }
116+ return geode::ListenerResult::Propagate;
117+ }
118+ InvokeBindFilterV2 (cocos2d::CCNode* target, ActionID const & id) : m_target(target), m_id(id) {}
119+ };
120+
121+ class BindManagerV2 {
122+ class Impl ;
123+ std::unique_ptr<Impl> m_impl;
124+ public:
125+ static geode::Result<bool > registerBindable (
126+ std::shared_ptr<BindableAction> action,
127+ ActionID const & after = " "
128+ ) GEODE_EVENT_EXPORT(&BindManagerV2::registerBindable, (action, after));
129+ static geode::Result<> removeBindable (ActionID const & action) GEODE_EVENT_EXPORT(&BindManagerV2::removeBindable, (action));
130+ static geode::Result<std::shared_ptr<BindableAction>> getBindable (ActionID const & action) GEODE_EVENT_EXPORT(&BindManagerV2::getBindable, (action));
131+ static geode::Result<std::vector<std::shared_ptr<BindableAction>>> getAllBindables () GEODE_EVENT_EXPORT(&BindManagerV2::getAllBindables, ());
132+ static geode::Result<std::vector<std::shared_ptr<BindableAction>>> getBindablesIn (std::shared_ptr<Category> category, bool sub = false ) GEODE_EVENT_EXPORT(&BindManagerV2::getBindablesIn, (category, sub));
133+ static geode::Result<std::vector<std::shared_ptr<BindableAction>>> getBindablesFor (Bind* bind) GEODE_EVENT_EXPORT(&BindManagerV2::getBindablesFor, (bind));
134+
135+ static geode::Result<std::vector<std::shared_ptr<Category>>> getAllCategories () GEODE_EVENT_EXPORT(&BindManagerV2::getAllCategories, ());
136+ static geode::Result<> addCategory (std::shared_ptr<Category> category) GEODE_EVENT_EXPORT(&BindManagerV2::addCategory, (category));
137+ static geode::Result<> removeCategory (std::shared_ptr<Category> category) GEODE_EVENT_EXPORT(&BindManagerV2::removeCategory, (category));
138+
139+ static geode::Result<std::vector<geode::Ref<Bind>>> getBindsFor (ActionID const & action) GEODE_EVENT_EXPORT(&BindManagerV2::getBindsFor, (action));
140+ };
141+ }
0 commit comments