diff --git a/loader/include/Geode/ui/ColorPickPopup.hpp b/loader/include/Geode/ui/ColorPickPopup.hpp index 4c0b5d4b..8a0dc68d 100644 --- a/loader/include/Geode/ui/ColorPickPopup.hpp +++ b/loader/include/Geode/ui/ColorPickPopup.hpp @@ -2,16 +2,23 @@ #include "Popup.hpp" #include "TextInput.hpp" -#include "Popup.hpp" - +#include "../loader/Event.hpp" #include namespace geode { + class ColorPickPopup; + class GEODE_DLL ColorPickPopupDelegate { public: virtual void updateColor(cocos2d::ccColor4B const& color) {} }; + // todo in v4: make this pimpl and maybe use events over the delegate? + // thing with events is that if you just filter via ColorPickPopup* it + // won't work unless you automatically detach the filter when closing the + // popup (otherwise opening another popup really quickly will just be + // allocated into the same memory and now the old filter is catching the + // new popup too) class GEODE_DLL ColorPickPopup : public Popup, public cocos2d::extension::ColorPickerDelegate, diff --git a/loader/src/ui/nodes/ColorPickPopup.cpp b/loader/src/ui/nodes/ColorPickPopup.cpp index 01083a6f..7a6b46c3 100644 --- a/loader/src/ui/nodes/ColorPickPopup.cpp +++ b/loader/src/ui/nodes/ColorPickPopup.cpp @@ -10,6 +10,55 @@ using namespace geode::prelude; +// class ColorPickPopupEvent::Impl final { +// public: +// ColorPickPopup* popup; +// ccColor4B color; +// bool closed = false; +// }; + +// ColorPickPopupEvent::ColorPickPopupEvent(ColorPickPopup* popup, ccColor4B const& color) +// : m_impl(std::make_shared()) +// { +// m_impl->popup = popup; +// m_impl->color = color; +// } +// ColorPickPopupEvent::~ColorPickPopupEvent() = default; + +// ColorPickPopup* ColorPickPopupEvent::getPopup() const { +// return m_impl->popup; +// } +// ccColor4B ColorPickPopupEvent::getColor() const { +// return m_impl->color; +// } +// bool ColorPickPopupEvent::isPopupClosed() const { +// return m_impl->closed; +// } + +// class ColorPickPopupEventFilter::Impl final { +// public: +// ColorPickPopup* popup; +// }; + +// ListenerResult ColorPickPopupEventFilter::handle(utils::MiniFunction fn, ColorPickPopupEvent* event) { +// if (event->getPopup() == m_impl->popup) { +// if (event->isPopupClosed()) { +// m_impl->popup = nullptr; +// } +// else { +// fn(event); +// } +// } +// return ListenerResult::Propagate; +// } +// ColorPickPopupEventFilter::ColorPickPopupEventFilter() : ColorPickPopupEventFilter(nullptr) {} +// ColorPickPopupEventFilter::ColorPickPopupEventFilter(ColorPickPopup* popup) +// : m_impl(std::make_shared()) +// { +// m_impl->popup = popup; +// } +// ColorPickPopupEventFilter::~ColorPickPopupEventFilter() = default; + bool ColorPickPopup::setup(ccColor4B const& color, bool isRGBA) { m_noElasticity = true; m_color = color; @@ -334,7 +383,9 @@ void ColorPickPopup::updateState(CCNode* except) { } m_resetBtn->setVisible(m_originalColor != m_color); m_newColorSpr->setColor(to3B(m_color)); - if (m_delegate) m_delegate->updateColor(m_color); + if (m_delegate) { + m_delegate->updateColor(m_color); + } } void ColorPickPopup::onOpacitySlider(CCObject* sender) {