-
-
Notifications
You must be signed in to change notification settings - Fork 42
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add type in Z layer input, functionality coming later when i have RE'd
- Loading branch information
Showing
4 changed files
with
136 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
|
||
#include <Geode/modify/EditorUI.hpp> | ||
#include <utils/EditableBMLabelProxy.hpp> | ||
|
||
using namespace geode::prelude; | ||
|
||
class $modify(EditorUI) { | ||
bool init(LevelEditorLayer* lel) { | ||
if (!EditorUI::init(lel)) | ||
return false; | ||
|
||
m_currentLayerLabel = EditableBMLabelProxy::replace( | ||
m_currentLayerLabel, 40.f, "Z", | ||
[this](auto str) { | ||
// try { | ||
// m_editorLayer->m_currentLayer = std::stoi(str); | ||
// } | ||
// catch(...) { | ||
// m_editorLayer->m_currentLayer = -1; | ||
// } | ||
} | ||
); | ||
|
||
return true; | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
#include "EditableBMLabelProxy.hpp" | ||
|
||
EditableBMLabelProxy* EditableBMLabelProxy::create() { | ||
auto ret = new EditableBMLabelProxy(); | ||
if (ret && ret->init()) { | ||
ret->autorelease(); | ||
return ret; | ||
} | ||
CC_SAFE_DELETE(ret); | ||
return nullptr; | ||
} | ||
|
||
EditableBMLabelProxy* EditableBMLabelProxy::replace( | ||
CCLabelBMFont* existing, | ||
float width, std::string const& placeholder, | ||
std::function<void(std::string const&)> setValue | ||
) { | ||
auto proxy = EditableBMLabelProxy::create(); | ||
|
||
proxy->m_setValue = setValue; | ||
proxy->m_input = InputNode::create(width, placeholder.c_str()); | ||
proxy->m_input->ignoreAnchorPointForPosition(false); | ||
proxy->m_input->getInput()->setDelegate(proxy); | ||
// 2021 Fod was sadistic for not doing this | ||
proxy->m_input->setContentSize(proxy->m_input->getBG()->getScaledContentSize()); | ||
existing->getParent()->addChild(proxy->m_input); | ||
|
||
proxy->setString(existing->getString()); | ||
proxy->setScale(existing->getScale()); | ||
proxy->setZOrder(existing->getZOrder()); | ||
proxy->setPosition(existing->getPosition()); | ||
proxy->setAnchorPoint(existing->getAnchorPoint()); | ||
proxy->setID(existing->getID()); | ||
proxy->setTag(existing->getTag()); | ||
|
||
existing->getParent()->addChild(proxy); | ||
existing->removeFromParent(); | ||
|
||
return proxy; | ||
} | ||
|
||
void EditableBMLabelProxy::updateLabel() {} | ||
|
||
void EditableBMLabelProxy::setString(const char* str) { | ||
this->setString(str, true); | ||
} | ||
|
||
void EditableBMLabelProxy::setString(const char* str, bool needUpdateLabel) { | ||
CCLabelBMFont::setString(str, needUpdateLabel); | ||
if (m_input && !m_ignoreLabelUpdate) { | ||
m_input->setString(str); | ||
} | ||
} | ||
|
||
void EditableBMLabelProxy::textChanged(CCTextInputNode*) { | ||
if (m_setValue && !m_ignoreLabelUpdate) { | ||
m_ignoreLabelUpdate = true; | ||
m_setValue(m_input->getString()); | ||
m_ignoreLabelUpdate = false; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
#pragma once | ||
|
||
#include <Geode/DefaultInclude.hpp> | ||
#include <Geode/utils/cocos.hpp> | ||
|
||
using namespace geode::prelude; | ||
|
||
class EditableBMLabelProxy : public CCLabelBMFont, TextInputDelegate { | ||
protected: | ||
Ref<InputNode> m_input = nullptr; | ||
std::function<void(std::string const&)> m_setValue = nullptr; | ||
bool m_ignoreLabelUpdate = false; | ||
|
||
static EditableBMLabelProxy* create(); | ||
|
||
public: | ||
static EditableBMLabelProxy* replace( | ||
CCLabelBMFont* existing, | ||
float width, std::string const& placeholder, | ||
std::function<void(std::string const&)> setValue | ||
); | ||
|
||
#define PROXY_FWD_1(fun, param_ty) \ | ||
void fun(param_ty x) override { \ | ||
CCLabelBMFont::fun(x); \ | ||
if (m_input) m_input->fun(x); \ | ||
} | ||
|
||
// PROXY_FWD_1(setContentSize, CCSize const&); | ||
PROXY_FWD_1(setAnchorPoint, CCPoint const&); | ||
PROXY_FWD_1(setPosition, CCPoint const&); | ||
PROXY_FWD_1(setRotation, float); | ||
PROXY_FWD_1(setRotationX, float); | ||
PROXY_FWD_1(setRotationY, float); | ||
PROXY_FWD_1(setScale, float); | ||
PROXY_FWD_1(setScaleX, float); | ||
PROXY_FWD_1(setScaleY, float); | ||
PROXY_FWD_1(setVisible, bool); | ||
PROXY_FWD_1(setSkewX, float); | ||
PROXY_FWD_1(setSkewY, float); | ||
PROXY_FWD_1(setZOrder, int); | ||
|
||
void updateLabel() override; | ||
void setString(const char* str) override; | ||
void setString(const char* str, bool needUpdateLabel) override; | ||
|
||
void textChanged(CCTextInputNode*) override; | ||
}; |