Skip to content

Commit 73fc99f

Browse files
committed
Options API + slight change
1 parent 6ee6bcf commit 73fc99f

File tree

3 files changed

+34
-10
lines changed

3 files changed

+34
-10
lines changed

mod.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,11 @@
1010
"developer": "km7dev",
1111
"description": "Adds a joystick to platformer mode.",
1212
"dependencies": {
13-
"geode.node-ids": "1.20.0"
13+
"geode.node-ids": "1.20.0",
14+
"ninxout.options_api": {
15+
"importance": "required",
16+
"version": "1.0.0"
17+
}
1418
},
1519
"settings": {
1620
"enabled": {

src/JoystickNode.cpp

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -33,13 +33,7 @@ JoystickNode *JoystickNode::create() {
3333
}
3434

3535
bool JoystickNode::ccTouchBegan(CCTouch *touch, CCEvent *event) {
36-
if (getScaledContentSize().width / 2 < ccpDistance(getPosition(), touch->getLocation())) {
37-
return false;
38-
}
39-
40-
// m_offset = m_center->getPosition() - convertToNodeSpace(touch->getLocation());
41-
42-
return true;
36+
return ccpDistance(getPosition(), touch->getLocation()) <= getScaledContentSize().width / 2;
4337
}
4438

4539
void handleInput(GJBaseGameLayer *layer, CCPoint input, CCPoint old) {

src/main.cpp

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ class $modify(JSUILayer, UILayer) {
1515
if (!UILayer::init(gjbgl)) return false;
1616

1717
m_fields->m_joystickNode = JoystickNode::create();
18-
addChildAtPosition(m_fields->m_joystickNode, Anchor::BottomLeft, {50, 50}, false);
18+
addChildAtPosition(m_fields->m_joystickNode, Anchor::BottomLeft, {75, 75}, false);
1919

2020
fixVisibility();
2121

@@ -43,4 +43,30 @@ class $modify(JSUILayer, UILayer) {
4343
p2move->setPosition({10000, 10000});
4444
}
4545
}
46-
};
46+
47+
void refreshDpad() {
48+
UILayer::refreshDpad();
49+
fixVisibility();
50+
}
51+
};
52+
53+
#include <ninxout.options_api/include/API.hpp>
54+
55+
$on_mod(Loaded) {
56+
OptionsAPI::addPreLevelSetting<bool>(
57+
"Platformer Joystick",
58+
"enable"_spr,
59+
[](GJGameLevel*) {
60+
Mod::get()->setSettingValue<bool>("enabled", !fastGetSetting<"enabled", bool>());
61+
},
62+
[](GJGameLevel*) { return fastGetSetting<"enabled", bool>(); },
63+
"Enables the joystick in platformer levels."
64+
);
65+
OptionsAPI::addMidLevelSetting<bool>(
66+
"Platformer Joystick",
67+
"enable"_spr,
68+
[](GJBaseGameLayer*) { Mod::get()->setSettingValue<bool>("enabled", !fastGetSetting<"enabled", bool>()); },
69+
[](GJBaseGameLayer*) { return fastGetSetting<"enabled", bool>(); },
70+
"Enables the joystick in platformer levels."
71+
);
72+
}

0 commit comments

Comments
 (0)