Skip to content

Commit e988a2e

Browse files
committed
1 player mode vertical disable
1 parent 1051f32 commit e988a2e

File tree

4 files changed

+35
-16
lines changed

4 files changed

+35
-16
lines changed

mod.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,12 @@
2222
"name": "Enabled",
2323
"description": "Enable or disable the joystick.",
2424
"default": true
25+
},
26+
"disable-updown": {
27+
"type": "bool",
28+
"name": "Vertical in 1 Player Mode",
29+
"description": "Disables the vertical input while in 1 player mode, as they're registered as left and right.",
30+
"default": true
2531
}
2632
}
2733
}

src/JoystickNode.cpp

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#include "JoystickNode.hpp"
2+
#include "utils.hpp"
23

34
bool JoystickNode::init() {
45
if (!CCMenu::init()) return false;
@@ -37,27 +38,31 @@ bool JoystickNode::ccTouchBegan(CCTouch *touch, CCEvent *event) {
3738
return ccpDistance(getPosition(), touch->getLocation()) <= getScaledContentSize().width / 2;
3839
}
3940

40-
void handleInput(GJBaseGameLayer *layer, CCPoint input, CCPoint old) {
41+
void JoystickNode::handleInput(GJBaseGameLayer *layer, CCPoint input, CCPoint old) {
4142
if (old.x == 1) {
4243
layer->queueButton(3, false, false);
4344
} else if (old.x == -1) {
4445
layer->queueButton(2, false, false);
4546
}
46-
if (old.y == 1) {
47-
layer->queueButton(3, false, true);
48-
} else if (old.y == -1) {
49-
layer->queueButton(2, false, true);
47+
if (!fastGetSetting<"disable-updown", bool>() || m_twoPlayer) {
48+
if (old.y == 1) {
49+
layer->queueButton(3, false, true);
50+
} else if (old.y == -1) {
51+
layer->queueButton(2, false, true);
52+
}
5053
}
5154

5255
if (input.x == 1) {
5356
layer->queueButton(3, true, false);
5457
} else if (input.x == -1) {
5558
layer->queueButton(2, true, false);
5659
}
57-
if (input.y == 1) {
58-
layer->queueButton(3, true, true);
59-
} else if (input.y == -1) {
60-
layer->queueButton(2, true, true);
60+
if (!fastGetSetting<"disable-updown", bool>() || m_twoPlayer) {
61+
if (input.y == 1) {
62+
layer->queueButton(3, true, true);
63+
} else if (input.y == -1) {
64+
layer->queueButton(2, true, true);
65+
}
6166
}
6267
}
6368

src/JoystickNode.hpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,13 @@ class JoystickNode : public CCMenu {
1212
void ccTouchCancelled(CCTouch *touch, CCEvent *event) override;
1313
void registerWithTouchDispatcher() override;
1414

15+
void handleInput(GJBaseGameLayer *layer, CCPoint input, CCPoint old);
16+
1517
CCPoint m_currentInput = {0, 0};
1618

1719
CCSprite *m_bg = nullptr;
1820
CCSprite *m_center = nullptr;
1921
public:
2022
static JoystickNode *create();
23+
bool m_twoPlayer = false;
2124
};

src/main.cpp

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,20 +14,25 @@ class $modify(JSUILayer, UILayer) {
1414

1515
bool init(GJBaseGameLayer *gjbgl) {
1616
if (!UILayer::init(gjbgl)) return false;
17+
queueInMainThread([this, gjbgl](){
18+
m_fields->m_joystickNode = JoystickNode::create();
19+
log::info("{}", gjbgl);
20+
log::info("{}", gjbgl->m_level);
21+
log::info("{}", gjbgl->m_level->m_twoPlayerMode);
22+
m_fields->m_joystickNode->m_twoPlayer = gjbgl->m_level->m_twoPlayerMode;
23+
addChildAtPosition(m_fields->m_joystickNode, Anchor::BottomLeft, {75, 75}, false);
1724

18-
m_fields->m_joystickNode = JoystickNode::create();
19-
addChildAtPosition(m_fields->m_joystickNode, Anchor::BottomLeft, {75, 75}, false);
20-
21-
fixVisibility();
25+
fixVisibility();
2226

27+
});
2328
return true;
2429
}
2530

2631
void fixVisibility() {
32+
if (!m_fields->m_joystickNode) {
33+
return;
34+
}
2735
if (!fastGetSetting<"enabled", bool>() || !m_inPlatformer) {
28-
if (!m_fields->m_joystickNode) {
29-
return;
30-
}
3136
m_fields->m_joystickNode->setVisible(false);
3237
m_fields->m_joystickNode->setTouchEnabled(false);
3338
return;

0 commit comments

Comments
 (0)