Skip to content

Commit 81248da

Browse files
committed
add code for hover select thing, fix compile errors
1 parent f7b8f81 commit 81248da

File tree

7 files changed

+357
-36
lines changed

7 files changed

+357
-36
lines changed

mod.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"geode": "4.0.0-beta.1",
2+
"geode": "4.3.1",
33
"version": "v1.8.0",
44
"gd": {
55
"win": "*",
@@ -25,4 +25,4 @@
2525
"default": true
2626
}
2727
}
28-
}
28+
}

src/DevTools.cpp

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -259,4 +259,12 @@ void DevTools::sceneChanged() {
259259

260260
bool DevTools::shouldUseGDWindow() const {
261261
return Mod::get()->getSettingValue<bool>("should-use-gd-window");
262-
}
262+
}
263+
264+
bool DevTools::isHoverSelectEnabled() const {
265+
return m_nodeHoverSelectEnabled;
266+
}
267+
268+
void DevTools::consumeNodeHoverTouch() {
269+
m_nodeHoverSelectConsumeTouch = true;
270+
}

src/DevTools.hpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ class DevTools {
3838
bool m_shouldRelayout = false;
3939
bool m_showModGraph = false;
4040
bool m_pauseGame = false;
41+
bool m_nodeHoverSelectEnabled = false;
42+
bool m_nodeHoverSelectConsumeTouch = false;
4143
Settings m_settings;
4244
ImGuiID m_dockspaceID;
4345
ImFont* m_defaultFont = nullptr;
@@ -51,7 +53,9 @@ class DevTools {
5153
void setupPlatform();
5254

5355
void drawTree();
54-
void drawTreeBranch(CCNode* node, size_t index);
56+
void drawTreeBranch(CCNode* node, size_t index, const std::vector<CCNode*>& selectedAncestors);
57+
void drawTreeHoverSelectButton();
58+
void drawHoveredNodeHighlight();
5559
void drawSettings();
5660
void drawAdvancedSettings();
5761
void drawNodeAttributes(CCNode* node);
@@ -88,6 +92,8 @@ class DevTools {
8892
bool pausedGame() const;
8993
bool isSetup() const;
9094
bool shouldOrderChildren() const;
95+
bool isHoverSelectEnabled() const;
96+
void consumeNodeHoverTouch();
9197

9298
CCNode* getSelectedNode() const;
9399
void selectNode(CCNode* node);

src/backend.cpp

Lines changed: 24 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ namespace {
9999
ccGLEnableVertexAttribs(kCCVertexAttribFlag_PosColorTex);
100100

101101
static_assert(sizeof(CCPoint) == sizeof(ccVertex2F), "so the cocos devs were right then");
102-
102+
103103
glVertexAttribPointer(kCCVertexAttrib_Position, 2, GL_FLOAT, GL_FALSE, 0, poli.data());
104104
glVertexAttribPointer(kCCVertexAttrib_Color, 4, GL_FLOAT, GL_FALSE, 0, colors.data());
105105
glVertexAttribPointer(kCCVertexAttrib_TexCoords, 2, GL_FLOAT, GL_FALSE, 0, uvs.data());
@@ -262,24 +262,29 @@ class $modify(CCTouchDispatcher) {
262262
if (io.WantCaptureMouse) {
263263
bool didGDSwallow = false;
264264

265-
if (DevTools::get()->shouldUseGDWindow() && shouldPassEventsToGDButTransformed()) {
266-
auto win = ImGui::GetMainViewport()->Size;
267-
const auto gdRect = getGDWindowRect();
268-
if (gdRect.Contains(pos) && !DevTools::get()->pausedGame()) {
269-
auto relativePos = ImVec2(
270-
pos.x - gdRect.Min.x,
271-
pos.y - gdRect.Min.y
272-
);
273-
auto x = (relativePos.x / gdRect.GetWidth()) * win.x;
274-
auto y = (1.f - relativePos.y / gdRect.GetHeight()) * win.y;
275-
276-
auto pos = toCocos(ImVec2(x, y));
277-
touch->setTouchInfo(touch->getID(), pos.x, pos.y);
278-
CCTouchDispatcher::touches(touches, event, type);
279-
280-
ImGui::SetWindowFocus("Geometry Dash");
281-
didGDSwallow = true;
282-
io.AddMouseButtonEvent(0, false);
265+
auto dt = DevTools::get();
266+
if (dt->shouldUseGDWindow() && shouldPassEventsToGDButTransformed()) {
267+
if (dt->isHoverSelectEnabled()) {
268+
dt->consumeNodeHoverTouch();
269+
} else {
270+
auto win = ImGui::GetMainViewport()->Size;
271+
const auto gdRect = getGDWindowRect();
272+
if (gdRect.Contains(pos) && !dt->pausedGame()) {
273+
auto relativePos = ImVec2(
274+
pos.x - gdRect.Min.x,
275+
pos.y - gdRect.Min.y
276+
);
277+
auto x = (relativePos.x / gdRect.GetWidth()) * win.x;
278+
auto y = (1.f - relativePos.y / gdRect.GetHeight()) * win.y;
279+
280+
auto pos = toCocos(ImVec2(x, y));
281+
touch->setTouchInfo(touch->getID(), pos.x, pos.y);
282+
CCTouchDispatcher::touches(touches, event, type);
283+
284+
ImGui::SetWindowFocus("Geometry Dash");
285+
didGDSwallow = true;
286+
io.AddMouseButtonEvent(0, false);
287+
}
283288
}
284289
}
285290

src/pages/Attributes.cpp

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -119,29 +119,28 @@ void DevTools::drawNodeAttributes(CCNode* node) {
119119
if (node->getZOrder() != zOrder) {
120120
node->setZOrder(zOrder);
121121
}
122-
122+
123123
checkbox("Visible", node, &CCNode::isVisible, &CCNode::setVisible);
124124
checkbox(
125125
"Ignore Anchor Point for Position",
126126
node,
127127
&CCNode::isIgnoreAnchorPointForPosition,
128128
&CCNode::ignoreAnchorPointForPosition
129129
);
130-
130+
131131
if (auto rgbaNode = typeinfo_cast<CCRGBAProtocol*>(node)) {
132132
auto color = rgbaNode->getColor();
133133
float _color[4] = { color.r / 255.f, color.g / 255.f, color.b / 255.f, rgbaNode->getOpacity() / 255.f };
134134
if (ImGui::ColorEdit4("Color", _color)) {
135-
rgbaNode->setColor({
135+
rgbaNode->setColor(ccColor4B{
136136
static_cast<GLubyte>(_color[0] * 255),
137137
static_cast<GLubyte>(_color[1] * 255),
138-
static_cast<GLubyte>(_color[2] * 255)
138+
static_cast<GLubyte>(_color[2] * 255),
139+
static_cast<GLubyte>(_color[3] * 255)
139140
});
140-
141-
rgbaNode->setOpacity(static_cast<GLubyte>(_color[3] * 255));
142141
}
143142
}
144-
143+
145144
if (auto labelNode = typeinfo_cast<CCLabelProtocol*>(node)) {
146145
std::string str = labelNode->getString();
147146
if (ImGui::InputText("Text", &str, 256)) {
@@ -180,7 +179,7 @@ void DevTools::drawNodeAttributes(CCNode* node) {
180179
ImGui::NewLine();
181180
ImGui::Separator();
182181
ImGui::NewLine();
183-
182+
184183
if (auto rawOpts = node->getLayoutOptions()) {
185184
ImGui::Text("Layout options: %s", typeid(*rawOpts).name());
186185

@@ -287,15 +286,15 @@ void DevTools::drawNodeAttributes(CCNode* node) {
287286
}
288287
}
289288
}
290-
289+
291290

292291
ImGui::NewLine();
293292
ImGui::Separator();
294293
ImGui::NewLine();
295294

296295
if (auto rawLayout = node->getLayout()) {
297296
ImGui::Text("Layout: %s", typeid(*rawLayout).name());
298-
297+
299298
if (ImGui::Button(U8STR(FEATHER_REFRESH_CW " Update Layout"))) {
300299
node->updateLayout();
301300
}

0 commit comments

Comments
 (0)