2022-08-01 11:18:03 -04:00
|
|
|
#pragma once
|
|
|
|
|
2022-08-02 06:17:26 -04:00
|
|
|
#include <Geode/Bindings.hpp>
|
2022-08-01 11:18:03 -04:00
|
|
|
|
|
|
|
namespace geode {
|
2022-09-01 02:35:18 -04:00
|
|
|
template<typename... InitArgs>
|
2022-08-01 11:18:03 -04:00
|
|
|
class GEODE_DLL Popup : public FLAlertLayer {
|
|
|
|
protected:
|
|
|
|
cocos2d::CCSize m_size;
|
|
|
|
cocos2d::extension::CCScale9Sprite* m_bgSprite;
|
2022-09-01 02:35:18 -04:00
|
|
|
cocos2d::CCLabelBMFont* m_title = nullptr;
|
2022-10-05 08:41:05 -04:00
|
|
|
CCMenuItemSpriteExtra* m_closeBtn;
|
2022-08-01 11:18:03 -04:00
|
|
|
|
|
|
|
bool init(
|
|
|
|
float width,
|
|
|
|
float height,
|
|
|
|
InitArgs... args,
|
2022-09-27 18:15:20 -04:00
|
|
|
const char* bg = "GJ_square01.png",
|
|
|
|
cocos2d::CCRect bgRect = { 0, 0, 80, 80 }
|
2022-08-01 11:18:03 -04:00
|
|
|
) {
|
|
|
|
auto winSize = cocos2d::CCDirector::sharedDirector()->getWinSize();
|
2022-09-01 02:35:18 -04:00
|
|
|
m_size = cocos2d::CCSize { width, height };
|
2022-08-01 11:18:03 -04:00
|
|
|
|
2022-09-01 02:35:18 -04:00
|
|
|
if (!this->initWithColor({ 0, 0, 0, 105 })) return false;
|
2022-08-01 11:18:03 -04:00
|
|
|
m_mainLayer = cocos2d::CCLayer::create();
|
|
|
|
this->addChild(m_mainLayer);
|
|
|
|
|
2022-09-27 18:15:20 -04:00
|
|
|
m_bgSprite = cocos2d::extension::CCScale9Sprite::create(bg, bgRect);
|
2022-08-01 11:18:03 -04:00
|
|
|
m_bgSprite->setContentSize(m_size);
|
|
|
|
m_bgSprite->setPosition(winSize.width / 2, winSize.height / 2);
|
|
|
|
m_mainLayer->addChild(m_bgSprite);
|
|
|
|
|
|
|
|
m_buttonMenu = cocos2d::CCMenu::create();
|
2022-09-01 05:46:37 -04:00
|
|
|
m_buttonMenu->setZOrder(100);
|
2022-08-01 11:18:03 -04:00
|
|
|
m_mainLayer->addChild(m_buttonMenu);
|
|
|
|
|
|
|
|
cocos2d::CCDirector::sharedDirector()->getTouchDispatcher()->incrementForcePrio(2);
|
|
|
|
this->registerWithTouchDispatcher();
|
|
|
|
|
|
|
|
auto closeSpr = cocos2d::CCSprite::createWithSpriteFrameName("GJ_closeBtn_001.png");
|
|
|
|
closeSpr->setScale(.8f);
|
|
|
|
|
2022-10-05 08:41:05 -04:00
|
|
|
m_closeBtn = CCMenuItemSpriteExtra::create(
|
2022-09-01 02:35:18 -04:00
|
|
|
closeSpr, this, (cocos2d::SEL_MenuHandler)(&Popup::onClose)
|
|
|
|
);
|
2022-10-05 08:41:05 -04:00
|
|
|
m_closeBtn->setPosition(
|
2022-09-01 02:35:18 -04:00
|
|
|
-m_size.width / 2 + 3.f,
|
|
|
|
m_size.height / 2 - 3.f
|
|
|
|
);
|
2022-10-05 08:41:05 -04:00
|
|
|
m_buttonMenu->addChild(m_closeBtn);
|
|
|
|
|
|
|
|
if (!setup(std::forward<InitArgs>(args)...)) {
|
|
|
|
return false;
|
|
|
|
}
|
2022-08-01 11:18:03 -04:00
|
|
|
|
|
|
|
this->setKeypadEnabled(true);
|
|
|
|
this->setTouchEnabled(true);
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2022-09-01 02:35:18 -04:00
|
|
|
virtual bool setup(InitArgs... args) = 0;
|
2022-08-01 11:18:03 -04:00
|
|
|
|
|
|
|
void keyDown(cocos2d::enumKeyCodes key) {
|
|
|
|
if (key == cocos2d::enumKeyCodes::KEY_Escape) return this->onClose(nullptr);
|
|
|
|
if (key == cocos2d::enumKeyCodes::KEY_Space) return;
|
|
|
|
return FLAlertLayer::keyDown(key);
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual void onClose(cocos2d::CCObject*) {
|
|
|
|
this->setKeyboardEnabled(false);
|
|
|
|
this->removeFromParentAndCleanup(true);
|
|
|
|
}
|
2022-09-01 02:35:18 -04:00
|
|
|
|
2022-09-27 18:15:20 -04:00
|
|
|
void setTitle(
|
|
|
|
const char* title,
|
|
|
|
const char* font = "goldFont.fnt",
|
|
|
|
float scale = .7f,
|
|
|
|
float offset = 20.f
|
|
|
|
) {
|
2022-09-01 02:35:18 -04:00
|
|
|
if (m_title) {
|
|
|
|
m_title->setString(title);
|
|
|
|
} else {
|
|
|
|
auto winSize = cocos2d::CCDirector::sharedDirector()->getWinSize();
|
|
|
|
m_title = cocos2d::CCLabelBMFont::create(title, font);
|
|
|
|
m_title->setPosition(
|
|
|
|
winSize.width / 2,
|
2022-09-27 18:15:20 -04:00
|
|
|
winSize.height / 2 + m_size.height / 2 - offset
|
2022-09-01 02:35:18 -04:00
|
|
|
);
|
|
|
|
m_mainLayer->addChild(m_title, 2);
|
|
|
|
}
|
2022-09-27 18:15:20 -04:00
|
|
|
m_title->limitLabelWidth(m_size.width - 20.f, scale, .1f);
|
2022-09-01 02:35:18 -04:00
|
|
|
}
|
2022-08-01 11:18:03 -04:00
|
|
|
};
|
|
|
|
|
2022-09-28 12:56:34 -04:00
|
|
|
GEODE_DLL FLAlertLayer* createQuickPopup(
|
2022-08-01 11:18:03 -04:00
|
|
|
const char* title,
|
|
|
|
std::string const& content,
|
|
|
|
const char* btn1,
|
|
|
|
const char* btn2,
|
2022-09-28 12:56:34 -04:00
|
|
|
std::function<void(FLAlertLayer*, bool)> selected,
|
|
|
|
bool doShow = true
|
2022-08-01 11:18:03 -04:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
|