Skip to content

Commit 45000aa

Browse files
committed
update Popup guides
1 parent 1f10e07 commit 45000aa

File tree

2 files changed

+10
-8
lines changed

2 files changed

+10
-8
lines changed

tutorials/popup.md

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,14 @@ This makes working with simple confirmation popups much simpler, as you don't ha
3333

3434
## Complex popups
3535

36-
However, what if you want to make a popup that's more complex? For example, something with a different background and lots of buttons and other controls, like the move trigger popup? For this, the **unrecommended** GD way is to inherit from `FLAlertLayer` and override `init` with your own code. However, this is not ideal, as most complex popups share a lot of similar base functionality like a close button and a standard `GJ_squareXX` background. For this reason, Geode provides a convenience class `Popup<...>` for creating your own complex popups.
36+
However, what if you want to make a popup that's more complex? For example, something with a different background and lots of buttons and other controls, like the move trigger popup? For this, the **unrecommended** GD way is to inherit from `FLAlertLayer` and override `init` with your own code. However, this is not ideal, as most complex popups share a lot of similar base functionality like a close button and a standard `GJ_squareXX` background. For this reason, Geode provides a convenience class `Popup` for creating your own complex popups.
3737
```cpp
38-
// specify parameters for the setup function in the Popup<...> template
39-
class MyPopup : public geode::Popup<std::string const&> {
38+
class MyPopup : public geode::Popup {
4039
protected:
41-
bool setup(std::string const& value) override {
40+
bool init(std::string const& value) {
41+
if (!Popup::init(240.f, 160.f))
42+
return false;
43+
4244
// convenience function provided by Popup
4345
// for adding/setting a title to the popup
4446
this->setTitle("Hi mom!");
@@ -52,7 +54,7 @@ protected:
5254
public:
5355
static MyPopup* create(std::string const& text) {
5456
auto ret = new MyPopup();
55-
if (ret->initAnchored(240.f, 160.f, text)) {
57+
if (ret->init(text)) {
5658
ret->autorelease();
5759
return ret;
5860
}
@@ -63,7 +65,7 @@ public:
6365
};
6466
```
6567
66-
`Popup` contains one pure virtual member function: `setup`, whose parameters are the class template arguments. This function is called at the end of `Popup::init`, which initializes all the relevant `FLAlertLayer` members and adds a background and a close button. This abstracts away a lot of boilerplate and makes creating complex popups simple.
68+
`Popup::init` abstracts away a lot of boilerplate and makes creating complex popups simple, by initializing all the relevant `FLAlertLayer` members and adding a background with a close button.
6769
6870
**This is the recommended way to create complex popups in Geode**, although as with question popups, this is not an interoperability concern and as such **you can do what fits your case**. If you are porting an existing mod that uses some other setup and it works just fine, no need to change it unless you want to make the codebase more easily refactorable.
6971

tutorials/touchpriority.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@ Robtop has 3 main functions for dealing with force priority: `CCTouchDispatcher:
3030

3131
If you're not dealing with any popups, chances are you don't need to deal with any of these either. But if you are, you should follow these guidelines.
3232

33-
If your popup subclasses `geode::Popup<>`, the registering and unregistering is handled automatically.
33+
If your popup subclasses `geode::Popup`, the registering and unregistering is handled automatically.
3434

35-
If you're not using `geode::Popup<>` class and directly subclassing `FLAlertLayer` instead, you should call `FLAlertLayer::init(int opacity)` inside your init. This will handle the registering of the force priority, along with creating the `m_mainLayer`. You should also override `registerWithTouchDispatcher` and call `CCTouchDispatcher::addTargetedDelegate` in it, since that will allow you to register the popup not as a prio targeted delegate. If you leave it the default, `FLAlertLayer` will have one less priority than your layers (-503 vs -502), meaning none of the touches will go to your layers since they will be consumed. And lastly, `~FLAlertLayer` handles unregistering of the force priority.
35+
If you're not using `geode::Popup` class and directly subclassing `FLAlertLayer` instead, you should call `FLAlertLayer::init(int opacity)` inside your init. This will handle the registering of the force priority, along with creating the `m_mainLayer`. You should also override `registerWithTouchDispatcher` and call `CCTouchDispatcher::addTargetedDelegate` in it, since that will allow you to register the popup not as a prio targeted delegate. If you leave it the default, `FLAlertLayer` will have one less priority than your layers (-503 vs -502), meaning none of the touches will go to your layers since they will be consumed. And lastly, `~FLAlertLayer` handles unregistering of the force priority.
3636

3737
If you want to set the priorities manually (such as for an overlay), you can call `CCLayer::setTouchPriority`/`CCMenu::setHandlerPriority` on your layer with the `CCTouchDispatcher::getTargetPrio` value.

0 commit comments

Comments
 (0)