mirror of
https://github.com/geode-sdk/geode.git
synced 2024-11-14 19:15:05 -05:00
redesign id registering again, now it's really good
This commit is contained in:
parent
40300afb25
commit
e995beb2f9
3 changed files with 24 additions and 40 deletions
|
@ -8,7 +8,7 @@ namespace cocos2d {
|
|||
|
||||
namespace geode {
|
||||
template<class T>
|
||||
concept IDProvidable = requires {
|
||||
concept IDProvidable = std::is_base_of_v<cocos2d::CCNode, T> && requires {
|
||||
{ T::CLASS_NAME } -> std::convertible_to<const char*>;
|
||||
};
|
||||
|
||||
|
@ -40,16 +40,15 @@ namespace geode {
|
|||
return false;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
namespace geode {
|
||||
template<class For>
|
||||
template<IDProvidable For>
|
||||
void GEODE_CALL geodeInternalProvideIDsFor(For* cls) {
|
||||
cls->setID(For::CLASS_NAME);
|
||||
cls->provide();
|
||||
}
|
||||
}
|
||||
|
||||
#define $register_ids(Layer_, ...) \
|
||||
#define $register_ids(Layer_) \
|
||||
struct GEODE_CONCAT(ProvideIDsFor, Layer_);\
|
||||
$execute {\
|
||||
NodeStringIDManager::get()->registerProvider(\
|
||||
|
@ -57,5 +56,6 @@ namespace geode {
|
|||
);\
|
||||
};\
|
||||
struct GEODE_CONCAT(ProvideIDsFor, Layer_) : public Layer_ {\
|
||||
void provide() __VA_ARGS__\
|
||||
void provide();\
|
||||
};\
|
||||
void GEODE_CONCAT(ProvideIDsFor, Layer_)::provide()
|
||||
|
|
|
@ -6,41 +6,26 @@
|
|||
|
||||
USE_GEODE_NAMESPACE();
|
||||
|
||||
class $modify(LevelBrowserLayer) {
|
||||
bool init(GJSearchObject* search) {
|
||||
std::cout << __FUNCTION__ << "\n";
|
||||
$register_ids(LevelBrowserLayer) {
|
||||
if (auto menu = getChildOfType<CCMenu>(this, 0)) {
|
||||
menu->setID("go-back-menu");
|
||||
setIDSafe(menu, 0, "back-button");
|
||||
}
|
||||
|
||||
if (!LevelBrowserLayer::init(search))
|
||||
return false;
|
||||
if (m_searchObject->m_searchType == SearchType::MyLevels) {
|
||||
if (auto menu = getChildOfType<CCMenu>(this, 1)) {
|
||||
menu->setID("new-level-menu");
|
||||
setIDSafe(menu, 0, "new-level-button");
|
||||
|
||||
std::cout << "setting ids\n";
|
||||
|
||||
this->setID("LevelBrowserLayer");
|
||||
|
||||
if (auto menu = getChildOfType<CCMenu>(this, 0)) {
|
||||
menu->setID("go-back-menu");
|
||||
setIDSafe(menu, 0, "back-button");
|
||||
}
|
||||
|
||||
if (m_searchObject->m_searchType == SearchType::MyLevels) {
|
||||
if (auto menu = getChildOfType<CCMenu>(this, 1)) {
|
||||
menu->setID("new-level-menu");
|
||||
setIDSafe(menu, 0, "new-level-button");
|
||||
|
||||
if (auto myLevelsBtn = setIDSafe(menu, 1, "my-levels-button")) {
|
||||
detachIntoOwnMenu(this, myLevelsBtn, "my-levels-menu",
|
||||
ColumnLayout::create(5.f, 0.f)->setAlignment(Alignment::End)
|
||||
);
|
||||
}
|
||||
|
||||
menu->setLayout(
|
||||
if (auto myLevelsBtn = setIDSafe(menu, 1, "my-levels-button")) {
|
||||
detachIntoOwnMenu(this, myLevelsBtn, "my-levels-menu",
|
||||
ColumnLayout::create(5.f, 0.f)->setAlignment(Alignment::End)
|
||||
);
|
||||
}
|
||||
|
||||
menu->setLayout(
|
||||
ColumnLayout::create(5.f, 0.f)->setAlignment(Alignment::End)
|
||||
);
|
||||
}
|
||||
|
||||
EnterLayerEvent("LevelBrowserLayer", this).post();
|
||||
|
||||
return true;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
|
|
@ -5,9 +5,8 @@
|
|||
|
||||
USE_GEODE_NAMESPACE();
|
||||
|
||||
$register_ids(MenuLayer, {
|
||||
$register_ids(MenuLayer) {
|
||||
// set IDs to everything
|
||||
this->setID("MenuLayer");
|
||||
setIDSafe(this, 0, "main-menu-bg");
|
||||
setIDSafe<CCSprite>(this, 0, "main-title");
|
||||
|
||||
|
@ -85,4 +84,4 @@ $register_ids(MenuLayer, {
|
|||
);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue