Create custom-layers.md, update utils.md, and Create chap4_2#63
Create custom-layers.md, update utils.md, and Create chap4_2#63Chs000-00 wants to merge 8 commits intogeode-sdk:mainfrom
Conversation
Fix no return statement
dankmeme01
left a comment
There was a problem hiding this comment.
definitely needs more polishing, also not entirely sure what to do with the searching through the docs page, not saying to remove it but I personally don't see the idea as very useful
| static MyVeryOriginalLayer* scene() { | ||
| auto layer = MyVeryOriginalLayer::create(); | ||
| switchToScene(layer); | ||
| return layer; | ||
| } |
There was a problem hiding this comment.
making a function that returns the layer yet switches to it is misleading, this would be better if it just created a scene with the layer and returned it
additionally, switchToScene uses CCDirector::replaceScene so I would suggest to just manually call pushScene
There was a problem hiding this comment.
heck i would recommend just the geode utils geode::cocos::switchToScene i think? needs a double check
we are in 2025 imo
There was a problem hiding this comment.
without this function i mean, just call switchToScene where you need it, never liked ::scene funcs anyway
| #include <Geode/ui/General.hpp> | ||
|
|
||
| bool init() override { | ||
| log::info("Hi from my very original layer"); |
There was a problem hiding this comment.
should still call original here
| } | ||
|
|
||
| void onBack(CCObject* sender) { | ||
| CCDirector::get()->replaceScene(CCTransitionFade::create(0.5, MenuLayer::scene())); |
| class MyVeryOriginalLayer : public CCLayer { | ||
| protected: | ||
| bool init() override { | ||
| log::info("Hi from my very original layer"); | ||
|
|
||
| // Create a new menu. UI elemnts should be added to here! | ||
| menu = CCMenu::create(); | ||
|
|
||
| // Add side art to the layer | ||
| addSideArt(this, SideArt::All, SideArtStyle::Layer); | ||
|
|
||
| // And a background to the layer | ||
| auto background = createLayerBG(); | ||
| background->setID("background"); | ||
| this->addChild(background); | ||
| return true; | ||
| } | ||
|
|
||
| // This function is called when the escape key is pressed! | ||
| void keyBackClicked() override { | ||
| this->onBack(nullptr); | ||
| } | ||
|
|
||
| public: | ||
| static MyVeryOriginalLayer* create() { | ||
| auto ret = new MyVeryOriginalLayer; | ||
| if (ret->init()) { | ||
| ret->autorelease(); | ||
| return ret; | ||
| } | ||
| CC_SAFE_DELETE(ret); | ||
| return nullptr; | ||
| } | ||
|
|
||
| static MyVeryOriginalLayer* MyVeryOriginalLayer::scene() { | ||
| auto layer = MyVeryOriginalLayer::create(); | ||
| switchToScene(layer); | ||
| return layer; | ||
| } | ||
|
|
||
|
|
||
| void onBack(CCObject* sender) { | ||
| CCDirector::get()->replaceScene(CCTransitionFade::create(0.5, MenuLayer::scene())); | ||
| } | ||
|
|
||
| } | ||
|
|
||
| class $modify(MenuLayer) { | ||
| void onMoreGames(CCObject* target) { | ||
| MyVeryOriginalLayer::scene(); | ||
| } | ||
| }; |
There was a problem hiding this comment.
All the same things as before, should use geode:: when calling global geode functions, call original CCLayer::init, cc safe delete, scene and onBack fixes
| return nullptr; | ||
| } | ||
|
|
||
| static MyVeryOriginalLayer* MyVeryOriginalLayer::scene() { |
There was a problem hiding this comment.
suspicious extra qualification before the function name
| ```cpp | ||
| // This is where geode is located! | ||
| auto geodeDir = dirs::getGeodeDir(); | ||
|
|
||
| // This is where geodes resources are stored! | ||
| auto geodeResourcesDir = dirs::getGeodeResourcesDir(); | ||
|
|
||
| // This is where geodes saves its files! | ||
| auto geodeSaveDir = dirs::getGeodeSaveDir(); | ||
|
|
||
| // This is where mod's save files are! | ||
| auto modSaveDir = dirs::getModsSaveDir(); | ||
|
|
||
| // This is where GD saves its files! | ||
| auto saveDir = dirs::getSaveDir(); | ||
|
|
||
| // Other directories also exist | ||
| ``` |
There was a problem hiding this comment.
These comments are not really useful because you can already make these conclusions from the function names. it would be much more useful if there were examples of paths, "This is where geode is located" can be interpreted as either the geode/ subfolder or as the folder where Geode.dll is located.
| } | ||
| ``` | ||
|
|
||
| This code will create a new layer called MyVeryOriginalLayer. When we start up the game, we will not see the layer as we do transition to it. Calling `MyVeryOriginalLayer::create()` will not transition to the layer, as it only creates it, not replaces the current layer. To be able to transition to the layer, we can use `switchToScene(layer)`. We can create a static function to easily create and switch to the scene: |
| static MyVeryOriginalLayer* scene() { | ||
| auto layer = MyVeryOriginalLayer::create(); | ||
| switchToScene(layer); | ||
| return layer; | ||
| } |
There was a problem hiding this comment.
heck i would recommend just the geode utils geode::cocos::switchToScene i think? needs a double check
we are in 2025 imo
| static MyVeryOriginalLayer* scene() { | ||
| auto layer = MyVeryOriginalLayer::create(); | ||
| switchToScene(layer); | ||
| return layer; | ||
| } |
There was a problem hiding this comment.
without this function i mean, just call switchToScene where you need it, never liked ::scene funcs anyway
| auto backBtn = CCMenuItemSpriteExtra::create( | ||
| CCSprite::createWithSpriteFrameName("GJ_arrow_01_001.png"), | ||
| this, | ||
| menu_selector(MyVeryOriginalLayer::onBack) |
There was a problem hiding this comment.
might alao recommend just using CCMenuItemExt::createSpriteExtra, its important to kill off old habits slowly
No description provided.