diff --git a/mod.json b/mod.json index 5712fc02..edd04bec 100644 --- a/mod.json +++ b/mod.json @@ -51,6 +51,12 @@ "name": "Center Scaling UI", "description": "When enabled, displays the scaling UI in the center of the screen, instead of displaying it above the selected object" }, + "scale-controls-in-ui": { + "type": "bool", + "default": false, + "name": "Fixed Scale Control Position", + "description": "The scale controls are always placed in the same location on screen rather than above the selected object(s)" + }, "editor-pulse": { "type": "bool", "default": true, diff --git a/src/features/CenterScaleUI.cpp b/src/features/CenterScaleUI.cpp index 0ad57949..bd332e3b 100644 --- a/src/features/CenterScaleUI.cpp +++ b/src/features/CenterScaleUI.cpp @@ -6,11 +6,15 @@ using namespace geode::prelude; class $modify(CenterScaleEditorUI, EditorUI) { void activateScaleControl(CCObject* sender) { EditorUI::activateScaleControl(sender); - if (Mod::get()->getSettingValue("center-scale-on-screen")) { + if ( + Mod::get()->getSettingValue("center-scale-on-screen") && + // incompatible with scale controls in UI + !Mod::get()->getSettingValue("scale-controls-in-ui") + ) { auto position = CCDirector::sharedDirector()->getWinSize() / 2; position.height += 50.0f; position = m_editorLayer->m_objectLayer->convertToNodeSpace(position); m_scaleControl->setPosition(position); } } -}; \ No newline at end of file +}; diff --git a/src/features/FixedScaleLocation.cpp b/src/features/FixedScaleLocation.cpp new file mode 100644 index 00000000..b35b5b44 --- /dev/null +++ b/src/features/FixedScaleLocation.cpp @@ -0,0 +1,52 @@ + +#include +#include +#include +#include +#include + +using namespace geode::prelude; + +static void switchToParent(CCNode* node, CCNode* parent) { + if (node->getParent() != parent) { + node->retain(); + node->removeFromParent(); + parent->addChild(node); + node->release(); + } +} + +class $modify(EditorUI) { + void activateScaleControl(CCObject* sender) { + EditorUI::activateScaleControl(sender); + if (!Mod::get()->getSettingValue("scale-controls-in-ui")) { + switchToParent(m_scaleControl, m_editorLayer->m_objectLayer); + } + else { + auto bg = this->getChildByID("scale-ui-bg"_spr); + if (!bg) { + auto winSize = CCDirector::get()->getWinSize(); + auto b = CCScale9Sprite::create("square02b_001.png", { 0, 0, 80, 80 }); + b->setPosition(winSize.width / 2, 135.f); + b->setContentSize({ 200, 60 }); + b->setScale(.75f); + b->setColor({ 0, 0, 0 }); + b->setOpacity(155); + b->setID("scale-ui-bg"_spr); + this->addChild(b); + bg = b; + } + bg->setVisible(m_scaleControl->isVisible()); + switchToParent(m_scaleControl, bg); + m_scaleControl->setScale(.8f); + m_scaleControl->setPosition(bg->getContentSize() / 2 - ccp(0, 10)); + } + } + + void deactivateScaleControl() { + EditorUI::deactivateScaleControl(); + if (auto bg = this->getChildByID("scale-ui-bg"_spr)) { + bg->setVisible(false); + } + } +}; diff --git a/src/main.cpp b/src/main.cpp index 78be7a43..870bf6a0 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1,3 +1,3 @@ #include -// the edit is now better :D \ No newline at end of file +// the edit is now better :D