Skip to content

Commit

Permalink
add option to place scale controls in fixed location in ui
Browse files Browse the repository at this point in the history
  • Loading branch information
HJfod committed Oct 7, 2023
1 parent e9468eb commit 1258a02
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 3 deletions.
6 changes: 6 additions & 0 deletions mod.json
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
8 changes: 6 additions & 2 deletions src/features/CenterScaleUI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,15 @@ using namespace geode::prelude;
class $modify(CenterScaleEditorUI, EditorUI) {
void activateScaleControl(CCObject* sender) {
EditorUI::activateScaleControl(sender);
if (Mod::get()->getSettingValue<bool>("center-scale-on-screen")) {
if (
Mod::get()->getSettingValue<bool>("center-scale-on-screen") &&
// incompatible with scale controls in UI
!Mod::get()->getSettingValue<bool>("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);
}
}
};
};
52 changes: 52 additions & 0 deletions src/features/FixedScaleLocation.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@

#include <Geode/modify/EditorUI.hpp>
#include <Geode/binding/GameObject.hpp>
#include <Geode/binding/LevelEditorLayer.hpp>
#include <Geode/binding/GJScaleControl.hpp>
#include <Geode/binding/GJSpriteColor.hpp>

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<bool>("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);
}
}
};
2 changes: 1 addition & 1 deletion src/main.cpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
#include <Geode/Geode.hpp>

// the edit is now better :D
// the edit is now better :D

0 comments on commit 1258a02

Please sign in to comment.