Skip to content

Commit 2672708

Browse files
Keybind setting type documentation (#94)
* Keybind setting type documentation * use this --------- Co-authored-by: mat <26722564+matcool@users.noreply.github.com>
1 parent 8ceb659 commit 2672708

2 files changed

Lines changed: 59 additions & 0 deletions

File tree

assets/settings/keybind.png

12.7 KB
Loading

mods/settings.md

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -352,6 +352,64 @@ auto rgba = Mod::get()->getSettingValue<cocos2d::ccColor4B>("rgba-setting-exampl
352352

353353
---
354354

355+
### Keybind (`keybind`)
356+
357+
![An image showcasing a basic keybind setting](/assets/settings/keybind.png)
358+
359+
Keybind settings allow the user to pick a key or combination of keys for a specified action, such as the keybind to open a mod's menu. The default keybind can be specified as either a single keybind or an array of keybinds.
360+
361+
```json
362+
"keybind-example": {
363+
"type": "keybind",
364+
"name": "Groovy Menu Keybind",
365+
"default": "Ctrl+Shift+G"
366+
}
367+
"multiple-keybind-example": {
368+
"type": "keybind",
369+
"name": "Groovy Action Keybinds",
370+
"default": ["G", "Ctrl+W"]
371+
}
372+
```
373+
374+
```cpp
375+
auto keybinds = Mod::get()->getSettingValue<std::vector<geode::Keybind>>("keybind-example");
376+
```
377+
378+
You can listen for keybinds globally via the `listenForKeybindSettingPresses` function, or locally via an event listener for `KeybindSettingPressedEventV3`.
379+
380+
```cpp
381+
#include <Geode/loader/GameEvent.hpp>
382+
#include <Geode/loader/SettingV3.hpp>
383+
384+
using namespace geode::prelude;
385+
386+
$on_game(Loaded) {
387+
listenForKeybindSettingPresses("keybind-example", [](Keybind const& keybind, bool down, bool repeat) {
388+
if (down && !repeat) {
389+
// do something
390+
}
391+
});
392+
}
393+
394+
class GroovyLayer : public CCLayer {
395+
protected:
396+
bool init() {
397+
if (!CCLayer::init())
398+
return false;
399+
400+
this->addEventListener(KeybindSettingPressedEventV3(Mod::get(), "keybind-example"), [this](Keybind const& keybind, bool down, bool repeat) {
401+
if (down && !repeat) {
402+
// do something
403+
}
404+
});
405+
406+
return true;
407+
}
408+
};
409+
```
410+
411+
---
412+
355413
## Custom Settings
356414

357415
Mods can also specify custom setting types. Unlike the old system, where custom settings where defined per-setting, under the new system you can reuse the same custom setting type for multiple settings.
@@ -841,3 +899,4 @@ Unless your custom settings are particularly complex, **it is recommended to jus
841899
It is heavily recommended to follow the practices laid out in the [Custom Settings part of this tutorial](#custom-settings) for setting nodes, as this results in conventional, easy-to-use and easy-to-maintain UIs. However, if you do have a reason to make a setting that has unconventional UI, you can of course always hide the name label and do what you want.
842900

843901

902+

0 commit comments

Comments
 (0)