Skip to content

Commit 4b5c658

Browse files
committed
feat(input): Fix crash when dragging input
1 parent 1707fcf commit 4b5c658

File tree

3 files changed

+35
-24
lines changed

3 files changed

+35
-24
lines changed

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,13 @@ All notable changes to this project will be documented in this file.
55
The format is based on [Keep a Changelog](http://keepachangelog.com/)
66
and this project adheres to [Semantic Versioning](http://semver.org/).
77

8+
## [v3.1.0-beta] - 2024-06-08
9+
10+
### Fixed
11+
12+
- Dragging input in the index crashing the game
13+
- Some mouse issues
14+
815
## [v3.0.0-beta] - 2024-06-06
916

1017
### Added

mod.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"gd": {
44
"win": "2.206"
55
},
6-
"version": "v3.0.1-beta",
6+
"version": "v3.1.0-beta",
77
"id": "spaghettdev.betterinputs",
88
"name": "BetterInputs",
99
"developer": "SpaghettDev",

src/main.cpp

Lines changed: 27 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -836,8 +836,8 @@ struct AlertLayerFix : Modify<AlertLayerFix, CCScene>
836836
{
837837
struct Fields
838838
{
839-
// its not like the input will change parents...
840-
CCLayer* m_outermostInputParent = nullptr;
839+
std::size_t m_previous_scene_children_count = 0;
840+
CCLayer* m_outermost_input_parent;
841841
};
842842

843843
static CCScene* create()
@@ -852,27 +852,28 @@ struct AlertLayerFix : Modify<AlertLayerFix, CCScene>
852852

853853
void onUpdateTick(float)
854854
{
855+
const std::size_t currentChildrenCount = this->getChildrenCount();
856+
855857
if (
856858
!g_selectedInput ||
857-
!BI::geode::get<bool>("auto-deselect") ||
858-
typeinfo_cast<geode::Notification*>(this->getChildren()->lastObject()) ||
859-
typeinfo_cast<LoadingCircle*>(this->getChildren()->lastObject())
860-
) {
861-
m_fields->m_outermostInputParent = nullptr;
859+
currentChildrenCount == 1 ||
860+
currentChildrenCount == m_fields->m_previous_scene_children_count
861+
)
862862
return;
863-
}
864863

865-
if (!m_fields->m_outermostInputParent)
864+
if (!m_fields->m_outermost_input_parent)
866865
{
867866
CCLayer* outermostInputParent = static_cast<CCLayer*>(g_selectedInput->getParent());
868867
while (outermostInputParent->getParent() != this)
869868
outermostInputParent = static_cast<CCLayer*>(outermostInputParent->getParent());
870869

871-
m_fields->m_outermostInputParent = outermostInputParent;
870+
m_fields->m_outermost_input_parent = outermostInputParent;
872871
}
873872

874-
if (static_cast<CCLayer*>(this->getChildren()->lastObject())->getZOrder() > m_fields->m_outermostInputParent->getZOrder())
873+
if (static_cast<CCLayer*>(this->getChildren()->lastObject())->getZOrder() > m_fields->m_outermost_input_parent->getZOrder())
875874
g_selectedInput->deselectInput();
875+
876+
m_fields->m_previous_scene_children_count = currentChildrenCount;
876877
}
877878
};
878879

@@ -997,21 +998,24 @@ struct BetterCCEGLView : Modify<BetterCCEGLView, CCEGLView>
997998
{
998999
CCEGLView::onGLFWMouseCallBack(window, button, action, mods);
9991000

1000-
if (!g_selectedInput || button != GLFW_MOUSE_BUTTON_1 || action == 1) return;
1001+
if (!g_selectedInput || button != GLFW_MOUSE_BUTTON_1 || action == 2) return;
10011002

1002-
CCSize winSize = CCDirector::sharedDirector()->getWinSize();
1003-
CCPoint mousePos = BI::cocos::getMousePosition();
1004-
1005-
// OpenGL's mouse origin is the bottom left
1006-
// CCTouch's mouse origin is top left (because of course it is)
1007-
CCTouch touch{};
1008-
touch.setTouchInfo(0, mousePos.x, winSize.height - mousePos.y);
1003+
if (action == 1)
1004+
{
1005+
CCSize winSize = CCDirector::sharedDirector()->getWinSize();
1006+
CCPoint mousePos = BI::cocos::getMousePosition();
10091007

1010-
g_selectedInput->useUpdateBlinkPos(true);
1008+
// OpenGL's mouse origin is the bottom left
1009+
// CCTouch's mouse origin is top left (because of course it is)
1010+
CCTouch touch{};
1011+
touch.setTouchInfo(0, mousePos.x, winSize.height - mousePos.y);
10111012

1012-
// 🥰
1013-
g_selectedInput->ccTouchBegan(&touch, nullptr);
1013+
g_selectedInput->useUpdateBlinkPos(true);
10141014

1015-
g_selectedInput->useUpdateBlinkPos(false);
1015+
// 🥰
1016+
g_selectedInput->ccTouchBegan(&touch, nullptr);
1017+
}
1018+
else
1019+
g_selectedInput->useUpdateBlinkPos(false);
10161020
}
10171021
};

0 commit comments

Comments
 (0)