Skip to content

Commit 6270e1c

Browse files
committed
add Popup::CloseEvent
1 parent 879ca57 commit 6270e1c

File tree

1 file changed

+60
-1
lines changed

1 file changed

+60
-1
lines changed

loader/include/Geode/ui/Popup.hpp

Lines changed: 60 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,59 @@
66
#include <Geode/utils/cocos.hpp>
77

88
namespace geode {
9-
template <typename... InitArgs>
9+
template <class... InitArgs>
1010
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+
1162
protected:
1263
cocos2d::CCSize m_size;
1364
cocos2d::extension::CCScale9Sprite* m_bgSprite;
@@ -115,6 +166,7 @@ namespace geode {
115166
}
116167

117168
virtual void onClose(cocos2d::CCObject*) {
169+
CloseEvent(this).post();
118170
this->setKeypadEnabled(false);
119171
this->setTouchEnabled(false);
120172
this->removeFromParentAndCleanup(true);
@@ -158,6 +210,13 @@ namespace geode {
158210
spr->setAnchorPoint(orig->getAnchorPoint());
159211
m_closeBtn->setContentSize(origSize);
160212
}
213+
214+
/**
215+
* Returns an event filter that listens for when this popup is closed
216+
*/
217+
CloseEventFilter listenForClose() {
218+
return CloseEventFilter(this);
219+
}
161220
};
162221

163222
GEODE_DLL FLAlertLayer* createQuickPopup(

0 commit comments

Comments
 (0)