mirror of
https://github.com/geode-sdk/geode.git
synced 2024-11-22 23:48:08 -05:00
Merge branch 'main' of https://github.com/geode-sdk/geode
This commit is contained in:
commit
e7997d6c84
7 changed files with 71 additions and 56 deletions
15
CHANGELOG.md
15
CHANGELOG.md
|
@ -1,5 +1,20 @@
|
|||
# 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)
|
||||
* Add new `superseded` importance level to incompatabilities (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
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
#include <cocos2d.h>
|
||||
|
||||
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;
|
||||
|
|
|
@ -99,6 +99,10 @@ namespace geode {
|
|||
* the text input
|
||||
*/
|
||||
void setCallback(std::function<void(std::string const&)> onInput);
|
||||
/**
|
||||
* Enable/disable the input
|
||||
*/
|
||||
void setEnabled(bool enabled);
|
||||
|
||||
/**
|
||||
* Hides the background of this input. Shorthand for
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -1,49 +1,11 @@
|
|||
#include <Geode/binding/CCTextInputNode.hpp>
|
||||
#include <Geode/binding/TextInputDelegate.hpp>
|
||||
#include <Geode/ui/InputNode.hpp>
|
||||
#include <Geode/ui/TextInput.hpp>
|
||||
#include <Geode/utils/cocos.hpp>
|
||||
|
||||
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 <Geode/modify/CCTextInputNode.hpp>
|
||||
|
||||
struct TextInputNodeFix : Modify<TextInputNodeFix, CCTextInputNode> {
|
||||
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 +56,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);
|
||||
}
|
||||
|
|
|
@ -1,9 +1,43 @@
|
|||
#include <Geode/binding/CCTextInputNode.hpp>
|
||||
#include <Geode/binding/TextInputDelegate.hpp>
|
||||
#include <Geode/modify/CCTextInputNode.hpp>
|
||||
#include <Geode/ui/TextInput.hpp>
|
||||
|
||||
using namespace geode::prelude;
|
||||
|
||||
struct TextInputNodeFix : Modify<TextInputNodeFix, CCTextInputNode> {
|
||||
GEODE_FORWARD_COMPAT_DISABLE_HOOKS("TextInputNode fix")
|
||||
|
||||
bool ccTouchBegan(cocos2d::CCTouch* touch, cocos2d::CCEvent* event) {
|
||||
if (!this->template getAttribute<bool>("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<int> 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<void(std::string const&)> 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);
|
||||
|
|
Loading…
Reference in a new issue