You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: include/Horrible.hpp
+1Lines changed: 1 addition & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -44,6 +44,7 @@ namespace horrible {
44
44
private:
45
45
std::vector<Option> m_options; // Array of registered options
46
46
std::vector<std::string> m_categories; // Array of auto-registered categories
47
+
47
48
std::unordered_map<std::string_view, std::vector<geode::Function<void(bool)>>> m_delegates; // Map of option ID to array of delegates to call when that option is toggled
|`class`|`OptionManager`| Manager for Horrible Ideas options |
68
-
|`enum class`|`SillyTier`| Defines how silly an option is |
69
-
|`struct`|`Option`| Represents a toggleable option |
70
-
|`class`|`HorribleOptionEvent`| Fired when an option is toggled |
71
-
|`class`|`HorribleOptionEventFilter`| Filters through option toggle events |
72
-
73
-
### Options
74
-
You can register and check any and as many options as you desire through this API.
75
-
76
-
> [!IMPORTANT]
77
-
> To work with options, you will first be required to access the pointer to the **`OptionManager`** class by using `OptionManager::get()` to define a variable to use in your code.
78
-
>
79
-
> ```cpp
80
-
> auto optMgr = OptionManager::get();
81
-
> ```
82
-
>
83
-
> This way, you can now safely use its methods to work directly with Horrible Ideas's API to handle your own custom options.
84
-
85
-
#### Registering
86
-
This mod makes it easy for players to access the options they want to use. You can register your own options by using the **`OptionManager::registerOption`** method inside an `$on_mod(Loaded)` block. You will need to pass one parameter, which is a constructed **`Option`** object for the option you want to register.
87
-
88
-
*Required fields of the **`Option`** struct are, in order: `id`, `name`, `description`, `category`, and `silly`. Optional fields are `restart` and `platforms`.*
89
-
90
-
> [!TIP]
91
-
> Be sure to prefix your option's unique ID with your Geode mod ID by appending **`_spr`** after the end of the string to prevent conflicts with this mod or other mods that may also register options with possibly identical IDs.
92
-
93
-
```cpp
94
-
$on_mod(Loaded){
95
-
auto optMgr = OptionManager::get();
96
-
97
-
optMgr->registerOption({
98
-
"something-interesting"_spr,
99
-
"Something Interesting",
100
-
"This is something that is very interesting.",
101
-
"Stuff!",
102
-
SillyTier::Medium,
103
-
});
104
-
};
105
-
```
106
-
107
-
You can include optional fields **`restart`** and **`platforms`** as well! Set `restart` to `true` or `false` depending on whether your option is only meant to load once per session. The array for `platforms` uses Geode's dynamic **`PlatformID`** class to identify the exact platform the player is running Geometry Dash on. By default, Horrible Ideas sets every option to be compatible for `PlatformID::Desktop` and `PlatformID::Mobile`, essentially covering all platforms. However, you can also get very specific about the exact platform you can run your own options on if absolutely necessary, though such a case may not present itself often.
108
-
109
-
> [!IMPORTANT]
110
-
> Even if `restart` is **enabled** for your option, the global event for it *will still fire* whenever the player changes it mid-game. What this setting does is actually just notify the player that your option will only load after they restart the game.
111
-
112
-
```cpp
113
-
$on_mod(Loaded){
114
-
auto optMgr = OptionManager::get();
115
-
116
-
optMgr->registerOption({
117
-
"cool-things"_spr,
118
-
"Cool Things",
119
-
"Some really really cool things.",
120
-
"Stuff!",
121
-
SillyTier::Low,
122
-
true, // Notify player to restart
123
-
{
124
-
PlatformID::Android32,
125
-
PlatformID::X64 // Support specific platforms
126
-
},
127
-
});
128
-
};
129
-
```
130
-
131
-
This will automatically include your option in Horrible Ideas's pre-existing list of options, and will appear in the menu for the player whenever they open it.
132
-
133
-
#### Handling
134
-
Once you've registered an option on `$on_mod(Loaded)`, you can use other methods to work with the option.
135
-
136
-
##### Static Conditioning
137
-
You can begin by using **`OptionManager::isEnabled`** and provide your option's unique ID to check if an option is enabled or disabled.
138
-
```cpp
139
-
usingnamespacegeode::prelude;
140
-
using namespace horrible;
141
-
142
-
class $modify(CoolThingsPlayLayer, PlayLayer) {
143
-
struct Fields {
144
-
bool enabled = OptionManager::get()->isEnabled("cool-things"_spr); // If this option is set to true or false
if (!PlayLayer::init(level, useReplay, dontCreateObjects)) return false;
149
-
150
-
if (m_fields->enabled) {
151
-
// do stuff!
152
-
};
153
-
154
-
return true;
155
-
};
156
-
};
157
-
```
158
-
159
-
##### Events
160
-
If you would like or need to re-implement or remove an option's functionality live as the player clicks on the toggle for that option, you can listen to the **`HorribleOptionEvent`** global event, which fires any time any option is toggled.
161
-
162
-
> [!IMPORTANT]
163
-
> Be sure to return `ListenerResult::Propagate` after you're finished handling each event to ensure other remaining event instances function properly.
164
-
165
-
```cpp
166
-
using namespace geode::prelude;
167
-
using namespace horrible;
168
-
169
-
class $modify(SomethingInterestingMenuLayer, MenuLayer) {
Let's start off by adding this mod as an optional dependency in your `mod.json`!
200
-
```jsonc
201
-
"dependencies": {
202
-
"arcticwoof.horrible_ideas": {
203
-
"importance":"suggested",
204
-
"version":">=1.0.0"
205
-
}
206
-
}
207
-
```
208
-
209
-
You can directly access the Horrible Ideas mod menu optional API by including the [`OptionalAPI.hpp`](OptionalAPI.hpp) file in your code. Make sure to include the **`horrible`** namespace to directly access all needed classes and methods.
|`class`|`OptionManagerV2`| Manager for Horrible Ideas options |
235
-
|`class`|`HorribleOptionEventV2`| Fired when an option is toggled |
236
-
|`class`|`HorribleOptionEventFilterV2`| Filters through option toggle events |
237
-
238
-
### Option
239
-
You can register and check any and as many options as you desire through this API. Most of the examples given and implied context here will be derived from earlier examples.
240
-
241
-
#### Registering
242
-
Here's how you can register your own options through the optional API.
243
-
244
-
```cpp
245
-
$on_mod(Loaded){
246
-
auto res = OptionManagerV2::registerOption({
247
-
"optional-something"_spr,
248
-
"Optional Something",
249
-
"An option registered through the optional API.",
250
-
"Optional",
251
-
SillyTier::Low,
252
-
});
253
-
254
-
if (res.isErr()) log::error("Failed to register option: {}", res.unwrapErr());
0 commit comments