|
6 | 6 | #include <Geode/utils/cocos.hpp>
|
7 | 7 |
|
8 | 8 | namespace geode {
|
9 |
| - template <typename... InitArgs> |
| 9 | + template <class... InitArgs> |
10 | 10 | class Popup : public FLAlertLayer {
|
| 11 | + public: |
| 12 | + /** |
| 13 | + * Event posted when this popup is being closed |
| 14 | + */ |
| 15 | + class CloseEvent final : public ::geode::Event { |
| 16 | + private: |
| 17 | + class Impl final { |
| 18 | + private: |
| 19 | + Popup* popup; |
| 20 | + friend class CloseEvent; |
| 21 | + }; |
| 22 | + std::shared_ptr<Impl> m_impl; |
| 23 | + |
| 24 | + friend class Popup; |
| 25 | + |
| 26 | + CloseEvent(Popup* popup) : m_impl(std::make_shared<Impl>()) { |
| 27 | + m_impl->popup = popup; |
| 28 | + } |
| 29 | + |
| 30 | + public: |
| 31 | + Popup* getPopup() const { |
| 32 | + return m_impl->popup; |
| 33 | + } |
| 34 | + }; |
| 35 | + class CloseEventFilter final : public ::geode::EventFilter<CloseEvent> { |
| 36 | + public: |
| 37 | + using Callback = void(CloseEvent*); |
| 38 | + |
| 39 | + private: |
| 40 | + class Impl final { |
| 41 | + private: |
| 42 | + Popup* popup; |
| 43 | + friend class CloseEventFilter; |
| 44 | + }; |
| 45 | + std::shared_ptr<Impl> m_impl; |
| 46 | + |
| 47 | + friend class Popup; |
| 48 | + |
| 49 | + CloseEventFilter(Popup* popup) : m_impl(std::make_shared<Impl>()) { |
| 50 | + m_impl->popup = popup; |
| 51 | + } |
| 52 | + |
| 53 | + public: |
| 54 | + ListenerResult handle(utils::MiniFunction<Callback> fn, CloseEvent* event) { |
| 55 | + if (event->getPopup() == m_impl->popup) { |
| 56 | + fn(event); |
| 57 | + } |
| 58 | + return ListenerResult::Propagate; |
| 59 | + } |
| 60 | + }; |
| 61 | + |
11 | 62 | protected:
|
12 | 63 | cocos2d::CCSize m_size;
|
13 | 64 | cocos2d::extension::CCScale9Sprite* m_bgSprite;
|
@@ -115,6 +166,7 @@ namespace geode {
|
115 | 166 | }
|
116 | 167 |
|
117 | 168 | virtual void onClose(cocos2d::CCObject*) {
|
| 169 | + CloseEvent(this).post(); |
118 | 170 | this->setKeypadEnabled(false);
|
119 | 171 | this->setTouchEnabled(false);
|
120 | 172 | this->removeFromParentAndCleanup(true);
|
@@ -158,6 +210,13 @@ namespace geode {
|
158 | 210 | spr->setAnchorPoint(orig->getAnchorPoint());
|
159 | 211 | m_closeBtn->setContentSize(origSize);
|
160 | 212 | }
|
| 213 | + |
| 214 | + /** |
| 215 | + * Returns an event filter that listens for when this popup is closed |
| 216 | + */ |
| 217 | + CloseEventFilter listenForClose() { |
| 218 | + return CloseEventFilter(this); |
| 219 | + } |
161 | 220 | };
|
162 | 221 |
|
163 | 222 | GEODE_DLL FLAlertLayer* createQuickPopup(
|
|
0 commit comments