-
Notifications
You must be signed in to change notification settings - Fork 42
Create custom-layers.md, update utils.md, and Create chap4_2 #63
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
Fix no return statement
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should still call original here
} | ||
|
||
void onBack(CCObject* sender) { | ||
CCDirector::get()->replaceScene(CCTransitionFade::create(0.5, MenuLayer::scene())); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should be a popScene
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
does not replace
static MyVeryOriginalLayer* scene() { | ||
auto layer = MyVeryOriginalLayer::create(); | ||
switchToScene(layer); | ||
return layer; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
might alao recommend just using CCMenuItemExt::createSpriteExtra
, its important to kill off old habits slowly
No description provided.