From 91c8ae446e37d1721e8e1a0b4ebdf83cfd784697 Mon Sep 17 00:00:00 2001 From: matcool <26722564+matcool@users.noreply.github.com> Date: Fri, 16 Feb 2024 22:46:16 -0300 Subject: [PATCH 1/6] why did we even override keyDown --- loader/src/ui/internal/list/ModListLayer.cpp | 8 -------- loader/src/ui/internal/list/ModListLayer.hpp | 1 - 2 files changed, 9 deletions(-) diff --git a/loader/src/ui/internal/list/ModListLayer.cpp b/loader/src/ui/internal/list/ModListLayer.cpp index 65cb2dfe..ed0ca924 100644 --- a/loader/src/ui/internal/list/ModListLayer.cpp +++ b/loader/src/ui/internal/list/ModListLayer.cpp @@ -377,8 +377,6 @@ bool ModListLayer::init() { bg->setVisible(false); } - // enable keyboard - this->setKeyboardEnabled(true); this->setKeypadEnabled(true); return true; @@ -709,12 +707,6 @@ void ModListLayer::onTab(CCObject* pSender) { toggleTab(m_featuredTabBtn); } -void ModListLayer::keyDown(enumKeyCodes key) { - if (key == KEY_Escape) { - this->onExit(nullptr); - } -} - void ModListLayer::textChanged(CCTextInputNode* input) { this->reloadList(false); } diff --git a/loader/src/ui/internal/list/ModListLayer.hpp b/loader/src/ui/internal/list/ModListLayer.hpp index 1d2b7a98..4f6f1234 100644 --- a/loader/src/ui/internal/list/ModListLayer.hpp +++ b/loader/src/ui/internal/list/ModListLayer.hpp @@ -77,7 +77,6 @@ protected: void onExpand(CCObject*); void onTab(CCObject*); void onFilters(CCObject*); - void keyDown(enumKeyCodes) override; void textChanged(CCTextInputNode*) override; void createSearchControl(); void onIndexUpdate(IndexUpdateEvent* event); From 29f99c2eaa489c8ea018643ee08d52c0057077a8 Mon Sep 17 00:00:00 2001 From: HJfod <60038575+HJfod@users.noreply.github.com> Date: Sat, 17 Feb 2024 18:24:23 +0200 Subject: [PATCH 2/6] fix TextInputs and InputNodes using tags for fixed touch behaviour --- loader/include/Geode/ui/InputNode.hpp | 7 +++- loader/include/Geode/ui/TextInput.hpp | 4 +++ loader/src/ui/nodes/InputNode.cpp | 43 ++---------------------- loader/src/ui/nodes/TextInput.cpp | 48 ++++++++++++++++++++++++--- 4 files changed, 55 insertions(+), 47 deletions(-) diff --git a/loader/include/Geode/ui/InputNode.hpp b/loader/include/Geode/ui/InputNode.hpp index a1d0e72e..9d18056f 100644 --- a/loader/include/Geode/ui/InputNode.hpp +++ b/loader/include/Geode/ui/InputNode.hpp @@ -5,7 +5,7 @@ #include namespace geode { - class GEODE_DLL [[deprecated("Use geode::TextInput from the ui/TextInput.hpp header instead")]] InputNode : public cocos2d::CCMenuItem { + class GEODE_DLL InputNode : public cocos2d::CCMenuItem { protected: cocos2d::extension::CCScale9Sprite* m_bgSprite; CCTextInputNode* m_input; @@ -14,15 +14,20 @@ namespace geode { bool init(float, char const*, char const*, std::string const&, int); public: + [[deprecated("Use geode::TextInput from the ui/TextInput.hpp header instead")]] static InputNode* create( float width, char const* placeholder, char const* fontFile, std::string const& filter, int limit ); + [[deprecated("Use geode::TextInput from the ui/TextInput.hpp header instead")]] static InputNode* create( float width, char const* placeholder, std::string const& filter, int limit ); + [[deprecated("Use geode::TextInput from the ui/TextInput.hpp header instead")]] static InputNode* create(float width, char const* placeholder, std::string const& filter); + [[deprecated("Use geode::TextInput from the ui/TextInput.hpp header instead")]] static InputNode* create(float width, char const* placeholder, char const* fontFile); + [[deprecated("Use geode::TextInput from the ui/TextInput.hpp header instead")]] static InputNode* create(float width, char const* placeholder); void activate() override; diff --git a/loader/include/Geode/ui/TextInput.hpp b/loader/include/Geode/ui/TextInput.hpp index 86b59c18..aae8dc1d 100644 --- a/loader/include/Geode/ui/TextInput.hpp +++ b/loader/include/Geode/ui/TextInput.hpp @@ -99,6 +99,10 @@ namespace geode { * the text input */ void setCallback(std::function onInput); + /** + * Enable/disable the input + */ + void setEnabled(bool enabled); /** * Hides the background of this input. Shorthand for diff --git a/loader/src/ui/nodes/InputNode.cpp b/loader/src/ui/nodes/InputNode.cpp index cc800623..08d49ca7 100644 --- a/loader/src/ui/nodes/InputNode.cpp +++ b/loader/src/ui/nodes/InputNode.cpp @@ -1,49 +1,10 @@ #include #include #include +#include using namespace geode::prelude; -// rob only uses `CCTextInputNode`s in mostly-flat hierarchies, which still -// happen to work with the weird vanilla code. this fix makes it work even in -// deep hierarchies, because the vanilla code uses `getParent` and manually -// calculates the child location in the world space based on that rather than -// using `convertToNodeSpace`. -static constexpr int INPUT_TAG = 0x80082; - -#include - -struct TextInputNodeFix : Modify { - GEODE_FORWARD_COMPAT_DISABLE_HOOKS("TextInputNode fix") - - bool ccTouchBegan(cocos2d::CCTouch* touch, cocos2d::CCEvent* event) { - if (this->getTag() != INPUT_TAG) return CCTextInputNode::ccTouchBegan(touch, event); - - if (!this->isVisible()) { - this->onClickTrackNode(false); - return false; - } - - auto const touchPos = touch->getLocation(); - auto const size = this->getContentSize(); - auto const pos = this->convertToNodeSpace(touchPos) + m_textField->getAnchorPoint() * size; - - if (pos.x < 0 || pos.x > size.width || pos.y < 0 || pos.y > size.height) { - this->onClickTrackNode(false); - return false; - } - if (m_delegate && !m_delegate->allowTextInput(this)) { - this->onClickTrackNode(false); - return false; - } - - this->onClickTrackNode(true); - this->updateCursorPosition(touchPos, {{0, 0}, size}); - - return true; - } -}; - std::string InputNode::getString() { return m_input->getString(); } @@ -94,7 +55,7 @@ bool InputNode::init( m_input->setMaxLabelScale(.85f); m_input->setMaxLabelLength(maxCharCount); m_input->setPosition(width / 2, height / 2); - m_input->setTag(INPUT_TAG); + m_input->setAttribute("fix-text-input", true); if (filter.length()) { m_input->setAllowedChars(filter); } diff --git a/loader/src/ui/nodes/TextInput.cpp b/loader/src/ui/nodes/TextInput.cpp index 582e5278..7672a047 100644 --- a/loader/src/ui/nodes/TextInput.cpp +++ b/loader/src/ui/nodes/TextInput.cpp @@ -1,9 +1,43 @@ #include #include +#include #include using namespace geode::prelude; +struct TextInputNodeFix : Modify { + GEODE_FORWARD_COMPAT_DISABLE_HOOKS("TextInputNode fix") + + bool ccTouchBegan(cocos2d::CCTouch* touch, cocos2d::CCEvent* event) { + if (!this->template getAttribute("fix-text-input").value_or(false)) { + return CCTextInputNode::ccTouchBegan(touch, event); + } + + if (!this->isVisible()) { + this->onClickTrackNode(false); + return false; + } + + auto const touchPos = touch->getLocation(); + auto const size = this->getContentSize(); + auto const pos = this->convertToNodeSpace(touchPos) + m_textField->getAnchorPoint() * size; + + if (pos.x < 0 || pos.x > size.width || pos.y < 0 || pos.y > size.height) { + this->onClickTrackNode(false); + return false; + } + if (m_delegate && !m_delegate->allowTextInput(this)) { + this->onClickTrackNode(false); + return false; + } + + this->onClickTrackNode(true); + this->updateCursorPosition(touchPos, {{0, 0}, size}); + + return true; + } +}; + const char* geode::getCommonFilterAllowedChars(CommonFilter filter) { switch (filter) { default: @@ -35,14 +69,13 @@ bool TextInput::init(float width, std::string const& placeholder, std::string co m_bgSprite->setContentSize({ width * 2, HEIGHT * 2 }); this->addChildAtPosition(m_bgSprite, cocos2d::Anchor::Center); - m_input = CCTextInputNode::create(width - 10.f, HEIGHT, placeholder.c_str(), "Thonburi", 24, font.c_str()); + m_input = CCTextInputNode::create(width, HEIGHT, placeholder.c_str(), 24, font.c_str()); m_input->setLabelPlaceholderColor({ 150, 150, 150 }); m_input->setLabelPlaceholderScale(.6f); m_input->setMaxLabelScale(.6f); + m_input->setAttribute("fix-text-input", true); this->addChildAtPosition(m_input, cocos2d::Anchor::Center); - handleTouchPriority(this); - return true; } @@ -80,12 +113,12 @@ void TextInput::setPasswordMode(bool enable) { m_input->refreshLabel(); } void TextInput::setWidth(float width) { - m_input->m_maxLabelWidth = width - 10; + m_input->m_maxLabelWidth = width; m_input->setContentWidth(width * 2); m_bgSprite->setContentWidth(width * 2); } void TextInput::setDelegate(TextInputDelegate* delegate, std::optional tag) { - m_input->setDelegate(delegate); + m_input->m_delegate = delegate; m_onInput = nullptr; if (tag.has_value()) { m_input->setTag(tag.value()); @@ -95,6 +128,11 @@ void TextInput::setCallback(std::function onInput) { this->setDelegate(this); m_onInput = onInput; } +void TextInput::setEnabled(bool enabled) { + m_input->setMouseEnabled(enabled); + m_input->setTouchEnabled(enabled); + m_input->m_placeholderLabel->setOpacity(enabled ? 255 : 150); +} void TextInput::hideBG() { m_bgSprite->setVisible(false); From db710c504da9d141014ffa81232c11112cff5966 Mon Sep 17 00:00:00 2001 From: HJfod <60038575+HJfod@users.noreply.github.com> Date: Sat, 17 Feb 2024 18:32:15 +0200 Subject: [PATCH 3/6] update changeloge --- CHANGELOG.md | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1e33c806..e04d9317 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,19 @@ # Geode Changelog +## v2.0.0-beta.20 + * Enable PCH on Mac for better compile times (dd62eac) + * Add `numFromString` utility for safely parsing numbers (c4e9c17) + * Add `CCNode::setContentWidth` along with respective height setter and getters (e06b907) + * Add `getChildBySpriteFrameName` (85f8a20) + * Add `isSpriteFrameName` (eea3556) + * Add new more refined `TextInput` class, deprecating `InputNode` (28f393b) + * Fix `InputNode` and `TextInput` using tags on their internal input node for controlling behaviour (29f99c2) + * Remove `strfmt` and `cstrfmt` utilties for being outdated and unsafe (b69ac71) + * Make `clamp` utility use template magic for better type inference (4ba0b7d) + * Improve user errors (4b667cc) + * Deprecate invalidally formatted mod IDs (e80d228) + * Fix `pickFile` on Android (9051779) + ## v2.0.0-beta.19 * Fix Windows forward compatibility mode (eef949c5, 824efbf3, 456075a2) * This was caused by Clang not setting `/DELAYLOAD` properly, but also a mutex introduced in beta.7 causing Geode not to load at all From 453fac9653dd0ecf9915fe34d5c484a871bcd043 Mon Sep 17 00:00:00 2001 From: HJfod <60038575+HJfod@users.noreply.github.com> Date: Sat, 17 Feb 2024 18:50:01 +0200 Subject: [PATCH 4/6] Update CHANGELOG.md --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index e04d9317..4f495238 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,7 @@ * Make `clamp` utility use template magic for better type inference (4ba0b7d) * Improve user errors (4b667cc) * Deprecate invalidally formatted mod IDs (e80d228) + * Add new `superseded` importance level to incompatabilities (e80d228) * Fix `pickFile` on Android (9051779) ## v2.0.0-beta.19 From 8cccb4ce5ca1d1c1294b8269fd5807690464d315 Mon Sep 17 00:00:00 2001 From: HJfod Date: Sun, 18 Feb 2024 00:13:34 +0200 Subject: [PATCH 5/6] fix numFromString on floats --- loader/include/Geode/utils/general.hpp | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/loader/include/Geode/utils/general.hpp b/loader/include/Geode/utils/general.hpp index 1260197e..abc66007 100644 --- a/loader/include/Geode/utils/general.hpp +++ b/loader/include/Geode/utils/general.hpp @@ -105,7 +105,13 @@ namespace geode { template Result numFromString(std::string_view const str, int base = 10) { Num result; - auto [_, ec] = std::from_chars(str.data(), str.data() + str.size(), result, base); + std::errc ec; + if constexpr (std::is_floating_point_v) { + ec = std::from_chars(str.data(), str.data() + str.size(), result).ec; + } + else { + ec = std::from_chars(str.data(), str.data() + str.size(), result, base).ec; + } switch (ec) { case std::errc(): return Ok(result); case std::errc::invalid_argument: return Err("String is not a number"); From f61e577c0e5e43988b9c569023667ebafe6637ba Mon Sep 17 00:00:00 2001 From: Cvolton Date: Sun, 18 Feb 2024 11:19:38 +0100 Subject: [PATCH 6/6] fix missing include --- loader/src/ui/nodes/InputNode.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/loader/src/ui/nodes/InputNode.cpp b/loader/src/ui/nodes/InputNode.cpp index 08d49ca7..eb809ec6 100644 --- a/loader/src/ui/nodes/InputNode.cpp +++ b/loader/src/ui/nodes/InputNode.cpp @@ -2,6 +2,7 @@ #include #include #include +#include using namespace geode::prelude;