-
Notifications
You must be signed in to change notification settings - Fork 103
Expand file tree
/
Copy pathmain.cpp
More file actions
100 lines (91 loc) · 3.07 KB
/
main.cpp
File metadata and controls
100 lines (91 loc) · 3.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
/**
* Include the Geode headers.
*/
#include <Geode/Geode.hpp>
/**
* Brings cocos2d and all Geode namespaces to the current scope.
*/
using namespace geode::prelude;
/**
* `$modify` lets you extend and modify GD's classes.
* To hook a function in Geode, simply $modify the class
* and write a new function definition with the signature of
* the function you want to hook.
*
* Here we use the overloaded `$modify` macro to set our own class name,
* so that we can use it for button callbacks.
*
* Notice the header being included, you *must* include the header for
* the class you are modifying, or you will get a compile error.
*
* Another way you could do this is like this:
*
* struct MyMenuLayer : Modify<MyMenuLayer, MenuLayer> {};
*/
#include <Geode/modify/MenuLayer.hpp>
class $modify(MyMenuLayer, MenuLayer) {
/**
* Typically classes in GD are initialized using the `init` function, (though not always!),
* so here we use it to add our own button to the bottom menu.
*
* Note that for all hooks, your signature has to *match exactly*,
* `void init()` would not place a hook!
*/
bool init() {
/**
* We call the original init function so that the
* original class is properly initialized.
*/
if (!MenuLayer::init()) {
return false;
}
/**
* You can use methods from the `geode::log` namespace to log messages to the console,
* being useful for debugging and such. See this page for more info about logging:
* https://docs.geode-sdk.org/tutorials/logging
*/
log::debug("Hello from my MenuLayer::init hook! This layer has {} children.", this->getChildrenCount());
/**
* See this page for more info about buttons
* https://docs.geode-sdk.org/tutorials/buttons
*/
auto myButton = CCMenuItemSpriteExtra::create(
CCSprite::createWithSpriteFrameName("GJ_likeBtn_001.png"),
this,
/**
* Here we use the name we set earlier for our modify class.
*/
menu_selector(MyMenuLayer::onMyButton)
);
/**
* Here we access the `bottom-menu` node by its ID, and add our button to it.
* Node IDs are a Geode feature, see this page for more info about it:
* https://docs.geode-sdk.org/tutorials/nodetree
*/
auto menu = this->getChildByID("bottom-menu");
menu->addChild(myButton);
/**
* The `_spr` string literal operator just prefixes the string with
* your mod id followed by a slash. This is good practice for setting your own node ids.
*/
myButton->setID("my-button"_spr);
/**
* We update the layout of the menu to ensure that our button is properly placed.
* This is yet another Geode feature, see this page for more info about it:
* https://docs.geode-sdk.org/tutorials/layouts
*/
menu->updateLayout();
/**
* We return `true` to indicate that the class was properly initialized.
*/
return true;
}
/**
* This is the callback function for the button we created earlier.
* The signature for button callbacks must always be the same,
* return type `void` and taking a `CCObject*`.
*/
void onMyButton(CCObject*) {
FLAlertLayer::create("Geode", "Hello from my custom mod!", "OK")->show();
}
};