2022-10-13 06:07:37 -04:00
|
|
|
#include <Geode/Loader.hpp>
|
2022-10-13 07:00:41 -04:00
|
|
|
#include <Geode/modify/MenuLayer.hpp>
|
2024-02-25 02:21:27 -05:00
|
|
|
#include <Geode/loader/Dispatch.hpp>
|
|
|
|
#include <Geode/Bindings.hpp>
|
2023-04-03 03:04:56 -04:00
|
|
|
#include "main.hpp"
|
|
|
|
|
|
|
|
using namespace geode::prelude;
|
|
|
|
|
|
|
|
std::string TestEvent::getData() const {
|
|
|
|
return data;
|
|
|
|
}
|
|
|
|
|
|
|
|
TestEvent::TestEvent(std::string const& data) : data(data) {}
|
|
|
|
|
2024-11-04 12:42:09 -05:00
|
|
|
ListenerResult TestEventFilter::handle(std::function<Callback> fn, TestEvent* event) {
|
2023-04-03 03:04:56 -04:00
|
|
|
fn(event);
|
|
|
|
return ListenerResult::Propagate;
|
|
|
|
}
|
|
|
|
|
|
|
|
TestEventFilter::TestEventFilter() {}
|
2022-12-13 15:39:45 -05:00
|
|
|
|
|
|
|
enum class Icon {
|
|
|
|
Steve,
|
|
|
|
Mike,
|
|
|
|
LazarithTheDestroyerOfForsakenSouls,
|
|
|
|
Geoff,
|
|
|
|
};
|
|
|
|
constexpr Icon DEFAULT_ICON = Icon::Steve;
|
|
|
|
|
|
|
|
class MySettingValue;
|
|
|
|
|
2024-11-04 12:14:23 -05:00
|
|
|
// TODO: v4 (port to new settings)
|
|
|
|
// class MySettingValue : public SettingValue {
|
|
|
|
// protected:
|
|
|
|
// Icon m_icon;
|
|
|
|
|
|
|
|
// public:
|
|
|
|
// MySettingValue(std::string const& key, std::string const& modID, Icon icon)
|
|
|
|
// : SettingValue(key, modID), m_icon(icon) {}
|
|
|
|
|
|
|
|
// bool load(matjson::Value const& json) override {
|
|
|
|
// if (!json.is<int>()) return false;
|
|
|
|
// m_icon = static_cast<Icon>(json.as<int>());
|
|
|
|
// return true;
|
|
|
|
// }
|
|
|
|
// bool save(matjson::Value& json) const override {
|
|
|
|
// json = static_cast<int>(m_icon);
|
|
|
|
// return true;
|
|
|
|
// }
|
|
|
|
// SettingNode* createNode(float width) override;
|
|
|
|
|
|
|
|
// void setIcon(Icon icon) {
|
|
|
|
// m_icon = icon;
|
|
|
|
// }
|
|
|
|
// Icon getIcon() const {
|
|
|
|
// return m_icon;
|
|
|
|
// }
|
|
|
|
// };
|
|
|
|
|
|
|
|
// class MySettingNode : public SettingNode {
|
|
|
|
// protected:
|
|
|
|
// Icon m_currentIcon;
|
|
|
|
// std::vector<CCSprite*> m_sprites;
|
|
|
|
|
|
|
|
// bool init(MySettingValue* value, float width) {
|
|
|
|
// if (!SettingNode::init(value))
|
|
|
|
// return false;
|
2022-12-13 15:39:45 -05:00
|
|
|
|
2024-11-04 12:14:23 -05:00
|
|
|
// m_currentIcon = value->getIcon();
|
|
|
|
// this->setContentSize({ width, 40.f });
|
|
|
|
|
|
|
|
// auto menu = CCMenu::create();
|
|
|
|
// menu->setPosition(width / 2, 20.f);
|
|
|
|
|
|
|
|
// float x = -75.f;
|
|
|
|
|
|
|
|
// for (auto& [spr, icon] : {
|
|
|
|
// std::pair { "GJ_square01.png", Icon::Steve, },
|
|
|
|
// std::pair { "GJ_square02.png", Icon::Mike, },
|
|
|
|
// std::pair { "GJ_square03.png", Icon::LazarithTheDestroyerOfForsakenSouls, },
|
|
|
|
// std::pair { "GJ_square04.png", Icon::Geoff, },
|
|
|
|
// }) {
|
|
|
|
// auto btnSpr = CCSprite::create(spr);
|
|
|
|
// btnSpr->setScale(.7f);
|
|
|
|
// m_sprites.push_back(btnSpr);
|
|
|
|
// if (icon == m_currentIcon) {
|
|
|
|
// btnSpr->setColor({ 0, 255, 0 });
|
|
|
|
// } else {
|
|
|
|
// btnSpr->setColor({ 200, 200, 200 });
|
|
|
|
// }
|
|
|
|
// auto btn = CCMenuItemSpriteExtra::create(
|
|
|
|
// btnSpr, this, menu_selector(MySettingNode::onSelect)
|
|
|
|
// );
|
|
|
|
// btn->setTag(static_cast<int>(icon));
|
|
|
|
// btn->setPosition(x, 0);
|
|
|
|
// menu->addChild(btn);
|
|
|
|
|
|
|
|
// x += 50.f;
|
|
|
|
// }
|
|
|
|
|
|
|
|
// this->addChild(menu);
|
|
|
|
|
|
|
|
// return true;
|
|
|
|
// }
|
|
|
|
|
|
|
|
// void onSelect(CCObject* sender) {
|
|
|
|
// for (auto& spr : m_sprites) {
|
|
|
|
// spr->setColor({ 200, 200, 200 });
|
|
|
|
// }
|
|
|
|
// m_currentIcon = static_cast<Icon>(sender->getTag());
|
|
|
|
// static_cast<CCSprite*>(
|
|
|
|
// static_cast<CCMenuItemSpriteExtra*>(sender)->getNormalImage()
|
|
|
|
// )->setColor({ 0, 255, 0 });
|
|
|
|
// this->dispatchChanged();
|
|
|
|
// }
|
|
|
|
|
|
|
|
// public:
|
|
|
|
// void commit() override {
|
|
|
|
// static_cast<MySettingValue*>(m_value)->setIcon(m_currentIcon);
|
|
|
|
// this->dispatchCommitted();
|
|
|
|
// }
|
|
|
|
// bool hasUncommittedChanges() override {
|
|
|
|
// return m_currentIcon != static_cast<MySettingValue*>(m_value)->getIcon();
|
|
|
|
// }
|
|
|
|
// bool hasNonDefaultValue() override {
|
|
|
|
// return m_currentIcon != DEFAULT_ICON;
|
|
|
|
// }
|
|
|
|
// void resetToDefault() override {
|
|
|
|
// m_currentIcon = DEFAULT_ICON;
|
|
|
|
// }
|
|
|
|
|
|
|
|
// static MySettingNode* create(MySettingValue* value, float width) {
|
|
|
|
// auto ret = new MySettingNode;
|
|
|
|
// if (ret->init(value, width)) {
|
|
|
|
// ret->autorelease();
|
|
|
|
// return ret;
|
|
|
|
// }
|
|
|
|
// delete ret;
|
|
|
|
// return nullptr;
|
|
|
|
// }
|
|
|
|
// };
|
|
|
|
|
|
|
|
// SettingNode* MySettingValue::createNode(float width) {
|
|
|
|
// return MySettingNode::create(this, width);
|
|
|
|
// }
|
2022-11-09 13:03:53 -05:00
|
|
|
|
|
|
|
struct MyMenuLayer : Modify<MyMenuLayer, MenuLayer> {
|
|
|
|
void onMoreGames(CCObject*) {
|
2023-04-03 03:04:56 -04:00
|
|
|
TestEvent("Event system works!").post();
|
2022-11-09 13:03:53 -05:00
|
|
|
if (Mod::get()->getSettingValue<bool>("its-raining-after-all")) {
|
2023-12-21 11:42:01 -05:00
|
|
|
FLAlertLayer::create("Damn", ":(", "OK")->show();
|
2022-11-09 13:03:53 -05:00
|
|
|
}
|
|
|
|
else {
|
2023-12-21 11:42:01 -05:00
|
|
|
FLAlertLayer::create(
|
|
|
|
"Yay",
|
|
|
|
"The weather report said it wouldn't rain today :)",
|
|
|
|
"OK"
|
|
|
|
)->show();
|
2022-11-09 13:03:53 -05:00
|
|
|
}
|
|
|
|
}
|
2022-09-14 12:21:35 -04:00
|
|
|
};
|
|
|
|
|
2022-12-13 15:39:45 -05:00
|
|
|
$on_mod(Loaded) {
|
2024-11-04 12:14:23 -05:00
|
|
|
// Mod::get()->addCustomSetting<MySettingValue>("overcast-skies", DEFAULT_ICON);
|
2022-12-13 15:39:45 -05:00
|
|
|
|
2024-02-25 02:21:27 -05:00
|
|
|
(void)new EventListener(+[](GJGarageLayer* gl) {
|
|
|
|
auto label = CCLabelBMFont::create("Dispatcher works!", "bigFont.fnt");
|
|
|
|
label->setPosition(100, 80);
|
|
|
|
label->setScale(.4f);
|
|
|
|
label->setZOrder(99999);
|
|
|
|
gl->addChild(label);
|
|
|
|
return ListenerResult::Propagate;
|
2024-02-25 02:38:46 -05:00
|
|
|
}, MyDispatchFilter("geode.test/test-garage-open"));
|
2024-02-25 02:21:27 -05:00
|
|
|
}
|