mirror of
https://github.com/geode-sdk/geode.git
synced 2024-11-14 19:15:05 -05:00
Merge pull request #1096 from geode-sdk/smjs
Some checks are pending
Build Binaries / Build Windows (push) Waiting to run
Build Binaries / Build macOS (push) Waiting to run
Build Binaries / Build Android (64-bit) (push) Waiting to run
Build Binaries / Build Android (32-bit) (push) Waiting to run
Build Binaries / Publish (push) Blocked by required conditions
Some checks are pending
Build Binaries / Build Windows (push) Waiting to run
Build Binaries / Build macOS (push) Waiting to run
Build Binaries / Build Android (64-bit) (push) Waiting to run
Build Binaries / Build Android (32-bit) (push) Waiting to run
Build Binaries / Publish (push) Blocked by required conditions
add `Popup::CloseEvent`
This commit is contained in:
commit
c68c31c2d8
5 changed files with 80 additions and 5 deletions
|
@ -141,6 +141,16 @@ namespace geode {
|
|||
* Open the settings popup for a mod (if it has any settings)
|
||||
*/
|
||||
GEODE_DLL void openSettingsPopup(Mod* mod);
|
||||
/**
|
||||
* Open the settings popup for a mod (if it has any settings)
|
||||
* @param mod Mod the open the popup for
|
||||
* @param disableGeodeTheme If false, the popup follows the user's chosen
|
||||
* theme options. If true, the popup is always in the GD theme (not Geode's
|
||||
* dark purple colors)
|
||||
* @returns A pointer to the created Popup, or null if the mod has no
|
||||
* settings
|
||||
*/
|
||||
GEODE_DLL Popup<Mod*>* openSettingsPopup(Mod* mod, bool disableGeodeTheme);
|
||||
/**
|
||||
* Create a default logo sprite
|
||||
*/
|
||||
|
|
|
@ -6,8 +6,59 @@
|
|||
#include <Geode/utils/cocos.hpp>
|
||||
|
||||
namespace geode {
|
||||
template <typename... InitArgs>
|
||||
template <class... InitArgs>
|
||||
class Popup : public FLAlertLayer {
|
||||
public:
|
||||
/**
|
||||
* Event posted when this popup is being closed
|
||||
*/
|
||||
class CloseEvent final : public ::geode::Event {
|
||||
private:
|
||||
class Impl final {
|
||||
private:
|
||||
Popup* popup;
|
||||
friend class CloseEvent;
|
||||
};
|
||||
std::shared_ptr<Impl> m_impl;
|
||||
|
||||
friend class Popup;
|
||||
|
||||
CloseEvent(Popup* popup) : m_impl(std::make_shared<Impl>()) {
|
||||
m_impl->popup = popup;
|
||||
}
|
||||
|
||||
public:
|
||||
Popup* getPopup() const {
|
||||
return m_impl->popup;
|
||||
}
|
||||
};
|
||||
class CloseEventFilter final : public ::geode::EventFilter<CloseEvent> {
|
||||
public:
|
||||
using Callback = void(CloseEvent*);
|
||||
|
||||
private:
|
||||
class Impl final {
|
||||
private:
|
||||
Popup* popup;
|
||||
friend class CloseEventFilter;
|
||||
};
|
||||
std::shared_ptr<Impl> m_impl;
|
||||
|
||||
friend class Popup;
|
||||
|
||||
CloseEventFilter(Popup* popup) : m_impl(std::make_shared<Impl>()) {
|
||||
m_impl->popup = popup;
|
||||
}
|
||||
|
||||
public:
|
||||
ListenerResult handle(utils::MiniFunction<Callback> fn, CloseEvent* event) {
|
||||
if (event->getPopup() == m_impl->popup) {
|
||||
fn(event);
|
||||
}
|
||||
return ListenerResult::Propagate;
|
||||
}
|
||||
};
|
||||
|
||||
protected:
|
||||
cocos2d::CCSize m_size;
|
||||
cocos2d::extension::CCScale9Sprite* m_bgSprite;
|
||||
|
@ -115,6 +166,7 @@ namespace geode {
|
|||
}
|
||||
|
||||
virtual void onClose(cocos2d::CCObject*) {
|
||||
CloseEvent(this).post();
|
||||
this->setKeypadEnabled(false);
|
||||
this->setTouchEnabled(false);
|
||||
this->removeFromParentAndCleanup(true);
|
||||
|
@ -158,6 +210,13 @@ namespace geode {
|
|||
spr->setAnchorPoint(orig->getAnchorPoint());
|
||||
m_closeBtn->setContentSize(origSize);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an event filter that listens for when this popup is closed
|
||||
*/
|
||||
CloseEventFilter listenForClose() {
|
||||
return CloseEventFilter(this);
|
||||
}
|
||||
};
|
||||
|
||||
GEODE_DLL FLAlertLayer* createQuickPopup(
|
||||
|
|
|
@ -159,9 +159,15 @@ void geode::openChangelogPopup(Mod* mod) {
|
|||
}
|
||||
|
||||
void geode::openSettingsPopup(Mod* mod) {
|
||||
if (mod->hasSettings()) {
|
||||
ModSettingsPopup::create(mod)->show();
|
||||
openSettingsPopup(mod, true);
|
||||
}
|
||||
Popup<Mod*>* geode::openSettingsPopup(Mod* mod, bool disableGeodeTheme) {
|
||||
if (mod->hasSettings()) {
|
||||
auto popup = ModSettingsPopup::create(mod, disableGeodeTheme);
|
||||
popup->show();
|
||||
return popup;
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
class ModLogoSprite : public CCNode {
|
||||
|
|
|
@ -345,9 +345,9 @@ void ModSettingsPopup::onClose(CCObject* sender) {
|
|||
GeodePopup::onClose(sender);
|
||||
}
|
||||
|
||||
ModSettingsPopup* ModSettingsPopup::create(Mod* mod) {
|
||||
ModSettingsPopup* ModSettingsPopup::create(Mod* mod, bool forceDisableTheme) {
|
||||
auto ret = new ModSettingsPopup();
|
||||
if (ret->init(440, 280, mod)) {
|
||||
if (ret->init(440, 280, mod, GeodePopupStyle::Default, forceDisableTheme)) {
|
||||
ret->autorelease();
|
||||
return ret;
|
||||
}
|
||||
|
|
|
@ -33,5 +33,5 @@ protected:
|
|||
void onClearSearch(CCObject*);
|
||||
|
||||
public:
|
||||
static ModSettingsPopup* create(Mod* mod);
|
||||
static ModSettingsPopup* create(Mod* mod, bool forceDisableTheme = false);
|
||||
};
|
||||
|
|
Loading…
Reference in a new issue