Skip to content

Commit 3a6513d

Browse files
committed
stuff
1 parent b5c0f91 commit 3a6513d

14 files changed

Lines changed: 432 additions & 10 deletions

File tree

311 Bytes
Loading

src/GUI/AndroidUI.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#include "FloatingButton/FloatingUIManager.hpp"
1414
#include "EasyBG.hpp"
1515
#include <BlurAPI.hpp>
16+
#include <Gestures/GestureManager.hpp>
1617

1718
using namespace qolmod;
1819

@@ -249,7 +250,8 @@ void AndroidUI::keyDown(cocos2d::enumKeyCodes key, double timestamp)
249250
void AndroidUI::visit()
250251
{
251252
FloatingUIManager::get()->visit();
252-
AndroidBall::get()->visit();
253+
AndroidBall::get()->visit();
254+
GestureManager::get()->visit();
253255

254256
PopupBase::visit();
255257
}

src/GUI/FloatingButton/FloatingUIButton.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66

77
using namespace geode::prelude;
88

9-
#define BUTTON_RADIUS 40
10-
#define ICON_SIZE 22.5f
9+
#define BUTTON_RADIUS 40.0f
10+
#define ICON_SIZE 22.0f
1111

1212
FloatingUIButton* FloatingUIButton::create(std::function<void()> onClick)
1313
{
Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
#include "GestureManager.hpp"
2+
3+
using namespace geode::prelude;
4+
using namespace qolmod;
5+
6+
GestureManager* GestureManager::get()
7+
{
8+
static GestureManager* instance = []{
9+
auto pRet = new GestureManager();
10+
pRet->onEnter();
11+
return pRet;
12+
}();
13+
14+
return instance;
15+
}
16+
17+
void GestureManager::draw()
18+
{
19+
return;
20+
auto rect = geode::utils::getSafeAreaRect();
21+
22+
glLineWidth(3);
23+
ccDrawColor4B(0, 0, 255, 255);
24+
ccDrawRect(rect.origin, rect.origin + rect.size);
25+
}
26+
27+
bool GestureManager::touchBegan(qolmod::Touch* touch)
28+
{
29+
return false;
30+
if (trackedTouches.contains(touch->id))
31+
trackedTouches.erase(touch->id);
32+
33+
for (auto node : getNodes())
34+
{
35+
if (node->touchBegan(touch))
36+
{
37+
trackedTouches[touch->id] = node;
38+
return true;
39+
}
40+
}
41+
42+
return false;
43+
}
44+
45+
bool GestureManager::touchMoved(qolmod::Touch* touch)
46+
{
47+
if (trackedTouches.contains(touch->id))
48+
{
49+
trackedTouches[touch->id]->touchMoved(touch);
50+
return true;
51+
}
52+
53+
return false;
54+
}
55+
56+
bool GestureManager::touchEnded(qolmod::Touch* touch)
57+
{
58+
if (trackedTouches.contains(touch->id))
59+
{
60+
trackedTouches[touch->id]->touchEnded(touch);
61+
trackedTouches.erase(touch->id);
62+
return true;
63+
}
64+
65+
return false;
66+
}
67+
68+
bool GestureManager::touchCancelled(qolmod::Touch* touch)
69+
{
70+
if (trackedTouches.contains(touch->id))
71+
{
72+
trackedTouches[touch->id]->touchCancelled(touch);
73+
trackedTouches.erase(touch->id);
74+
return true;
75+
}
76+
77+
return false;
78+
}
79+
80+
std::vector<GestureNode*> GestureManager::getNodes()
81+
{
82+
auto vec = CCArrayExt<GestureNode*, false>(getChildren());
83+
84+
return std::vector<GestureNode*>(vec.begin(), vec.end());
85+
}
86+
87+
88+
/*$on_game(Loaded)
89+
{
90+
GestureManager::get()->addChild([]{
91+
auto test = new GestureNode();
92+
test->init();
93+
test->autorelease();
94+
return test;
95+
}());
96+
}*/
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
#pragma once
2+
3+
#include <Geode/Geode.hpp>
4+
#include <Touch.hpp>
5+
#include "GestureNode.hpp"
6+
7+
namespace qolmod
8+
{
9+
class GestureManager : public cocos2d::CCNode
10+
{
11+
protected:
12+
std::unordered_map<int, geode::Ref<GestureNode>> trackedTouches = {};
13+
14+
virtual void draw();
15+
16+
std::vector<GestureNode*> getNodes();
17+
18+
public:
19+
static GestureManager* get();
20+
21+
bool touchBegan(qolmod::Touch* touch);
22+
bool touchMoved(qolmod::Touch* touch);
23+
bool touchEnded(qolmod::Touch* touch);
24+
bool touchCancelled(qolmod::Touch* touch);
25+
};
26+
};

src/GUI/Gestures/GestureNode.cpp

Lines changed: 171 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,171 @@
1+
#include "GestureNode.hpp"
2+
#include <Speedhack.hpp>
3+
#include <Utils.hpp>
4+
5+
using namespace geode::prelude;
6+
using namespace qolmod;
7+
8+
bool GestureNode::init()
9+
{
10+
if (!CCNodeRGBA::init())
11+
return false;
12+
13+
setAnchorPoint(ccp(0, 0.5f));
14+
15+
cornerTop = UserSprite::create(fmt::format("<sprite>{}gesture-corner.png", ""_spr));
16+
cornerBottom = UserSprite::create(fmt::format("<sprite>{}gesture-corner.png", ""_spr));
17+
18+
cornerTop->setAnchorPoint(ccp(0, 0));
19+
cornerBottom->setAnchorPoint(ccp(0, 0));
20+
cornerBottom->setRotation(90);
21+
22+
sideFill = CCLayerColor::create(ccc4(255, 255, 255, 255));
23+
sideFill->ignoreAnchorPointForPosition(false);
24+
sideFill->setAnchorPoint(ccp(0, 0.5f));
25+
sideFill->setPosition(CCPointZero);
26+
27+
gapFill = CCLayerColor::create(ccc4(255, 255, 255, 255));
28+
gapFill->ignoreAnchorPointForPosition(false);
29+
gapFill->setAnchorPoint(ccp(0, 0.5f));
30+
gapFill->setPosition(CCPointZero);
31+
32+
anchor = GestureAnchor::Left;
33+
realPosition = ccp(0, CCDirector::get()->getWinSize().height * 0.75f);
34+
35+
scheduleUpdate();
36+
setContentSize(ccp(4, 50));
37+
setOpacity(100);
38+
39+
this->addChild(cornerTop);
40+
this->addChild(cornerBottom);
41+
this->addChild(sideFill);
42+
this->addChild(gapFill);
43+
return true;
44+
}
45+
46+
void GestureNode::update(float dt)
47+
{
48+
dt = Speedhack::get()->getRealDeltaTime();
49+
auto winSize = CCDirector::get()->getWinSize();
50+
51+
switch (anchor)
52+
{
53+
case GestureAnchor::Left:
54+
setRotation(0);
55+
setPosition(ccp(0, displayedPosition.y));
56+
break;
57+
58+
case GestureAnchor::Top:
59+
setRotation(90);
60+
setPosition(ccp(displayedPosition.x, winSize.height));
61+
break;
62+
63+
case GestureAnchor::Right:
64+
setRotation(180);
65+
setPosition(ccp(winSize.width, displayedPosition.y));
66+
break;
67+
68+
case GestureAnchor::Bottom:
69+
setRotation(270);
70+
setPosition(ccp(displayedPosition.x, 0));
71+
break;
72+
}
73+
74+
float t = 10 * Speedhack::get()->getRealDeltaTime();
75+
76+
displayedPosition = ccp(
77+
std::lerp<double>(displayedPosition.x, realPosition.x, t),
78+
std::lerp<double>(displayedPosition.y, realPosition.y, t)
79+
);
80+
}
81+
82+
bool GestureNode::touchBegan(qolmod::Touch* touch)
83+
{
84+
auto local = convertToNodeSpace(touch->location);
85+
log::info("local: {}", local);
86+
87+
if (CCRectMake(0, 0, getContentWidth(), getContentHeight()).containsPoint(local))
88+
{
89+
return true;
90+
}
91+
92+
return false;
93+
}
94+
95+
void GestureNode::touchMoved(qolmod::Touch* touch)
96+
{
97+
realPosition = touch->location;
98+
}
99+
100+
void GestureNode::touchEnded(qolmod::Touch* touch)
101+
{
102+
103+
}
104+
105+
void GestureNode::touchCancelled(qolmod::Touch* touch)
106+
{
107+
touchEnded(touch);
108+
}
109+
110+
void GestureNode::setContentSize(const CCSize& contentSize)
111+
{
112+
CCNode::setContentSize(contentSize);
113+
114+
gapFill->setContentSize(ccp(contentSize.width - cornerTop->getContentWidth(), contentSize.height));
115+
gapFill->setPositionY(contentSize.height / 2);
116+
117+
sideFill->setContentSize(ccp(cornerTop->getContentWidth(), contentSize.height - cornerTop->getContentHeight() * 2));
118+
sideFill->setPosition(ccp(contentSize.width - cornerTop->getContentWidth(), contentSize.height / 2));
119+
120+
cornerTop->setPosition(contentSize.width - cornerTop->getContentWidth(), contentSize.height - cornerTop->getContentHeight());
121+
cornerBottom->setPosition(contentSize.width - cornerTop->getContentWidth(), cornerBottom->getContentHeight());
122+
}
123+
124+
void GestureNode::setOpacity(GLubyte opacity)
125+
{
126+
CCNodeRGBA::setOpacity(opacity);
127+
128+
cornerTop->setOpacity(opacity);
129+
cornerBottom->setOpacity(opacity);
130+
sideFill->setOpacity(opacity);
131+
gapFill->setOpacity(opacity);
132+
}
133+
134+
void GestureNode::setColor(const ccColor3B& color)
135+
{
136+
CCNodeRGBA::setColor(color);
137+
138+
cornerTop->setColor(color);
139+
cornerBottom->setColor(color);
140+
sideFill->setColor(color);
141+
gapFill->setColor(color);
142+
}
143+
144+
void GestureNode::setAnchor(qolmod::GestureAnchor anchor)
145+
{
146+
if (this->anchor == anchor)
147+
return;
148+
149+
auto winSize = CCDirector::get()->getWinSize();
150+
auto prev = this->anchor;
151+
this->anchor = anchor;
152+
153+
switch (prev)
154+
{
155+
case GestureAnchor::Top:
156+
displayedPosition.y = winSize.height;
157+
break;
158+
159+
case GestureAnchor::Bottom:
160+
displayedPosition.y = 0;
161+
break;
162+
163+
case GestureAnchor::Left:
164+
displayedPosition.y = 0;
165+
break;
166+
167+
case GestureAnchor::Right:
168+
displayedPosition.y = winSize.width;
169+
break;
170+
}
171+
}

src/GUI/Gestures/GestureNode.hpp

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
#pragma once
2+
3+
#include <Geode/Geode.hpp>
4+
#include <Touch.hpp>
5+
#include <UserSprite.hpp>
6+
7+
namespace qolmod
8+
{
9+
enum class GestureAnchor
10+
{
11+
Left,
12+
Top,
13+
Right,
14+
Bottom,
15+
};
16+
17+
class GestureNode : public cocos2d::CCNodeRGBA
18+
{
19+
private:
20+
qolmod::GestureAnchor anchor = qolmod::GestureAnchor::Left;
21+
cocos2d::CCPoint displayedPosition = cocos2d::CCPointZero;
22+
cocos2d::CCPoint realPosition = cocos2d::CCPointZero;
23+
qolmod::UserSprite* cornerTop = nullptr;
24+
qolmod::UserSprite* cornerBottom = nullptr;
25+
cocos2d::CCLayerColor* sideFill = nullptr;
26+
cocos2d::CCLayerColor* gapFill = nullptr;
27+
28+
public:
29+
void setAnchor(qolmod::GestureAnchor anchor);
30+
31+
virtual bool touchBegan(qolmod::Touch* touch);
32+
virtual void touchMoved(qolmod::Touch* touch);
33+
virtual void touchEnded(qolmod::Touch* touch);
34+
virtual void touchCancelled(qolmod::Touch* touch);
35+
36+
virtual bool init();
37+
virtual void update(float dt);
38+
virtual void setContentSize(const cocos2d::CCSize& contentSize);
39+
40+
virtual void setOpacity(GLubyte opacity);
41+
virtual void setColor(const cocos2d::ccColor3B& color);
42+
};
43+
};

0 commit comments

Comments
 (0)