diff --git a/loader/src/ids/AddIDs.hpp b/loader/src/ids/AddIDs.hpp index 42b7948c..2d876a1b 100644 --- a/loader/src/ids/AddIDs.hpp +++ b/loader/src/ids/AddIDs.hpp @@ -22,21 +22,54 @@ T* setIDSafe(CCNode* node, int index, const char* id) { return nullptr; } -static CCMenu* detachIntoOwnMenu(CCNode* parent, CCNode* node, const char* menuID, Layout* layout) { - auto oldMenu = node->getParent(); +template +void setIDs(CCNode* node, int startIndex, Args... args) { + for (auto i : { args... }) { + setIDSafe(node, startIndex, i); + ++startIndex; + } +} + +static void switchToMenu(CCNode* node, CCMenu* menu) { + auto worldPos = node->getParent()->convertToWorldSpace(node->getPosition()); node->retain(); node->removeFromParent(); + menu->addChild(node); + node->setPosition(menu->convertToNodeSpace(worldPos)); +} + +static void switchChildToMenu(CCNode* parent, int idx, CCMenu* menu) { + switchToMenu(static_cast(parent->getChildren()->objectAtIndex(idx)), menu); +} + +template +static void switchChildrenToMenu(CCNode* parent, CCMenu* menu, Args... args) { + for (auto i : { args... }) { + switchChildToMenu(parent, i, menu); + } +} + +template +static CCMenu* detachAndCreateMenu(CCNode* parent, const char* menuID, Layout* layout, T first, Args... args) { + auto oldMenu = first->getParent(); + + first->retain(); + first->removeFromParent(); + auto newMenu = CCMenu::create(); - newMenu->setPosition(oldMenu->convertToWorldSpace(node->getPosition())); + newMenu->setPosition(parent->convertToNodeSpace(oldMenu->convertToWorldSpace(first->getPosition()))); newMenu->setID(menuID); - node->setPosition(0, 0); - newMenu->addChild(node); + newMenu->setZOrder(oldMenu->getZOrder()); newMenu->setLayout(layout); parent->addChild(newMenu); - node->release(); + first->setPosition(0, 0); + newMenu->addChild(first); + first->release(); + + (switchToMenu(args, newMenu), ...); return newMenu; -} +} \ No newline at end of file diff --git a/loader/src/ids/CreatorLayer.cpp b/loader/src/ids/CreatorLayer.cpp index 05bd0424..62e066a8 100644 --- a/loader/src/ids/CreatorLayer.cpp +++ b/loader/src/ids/CreatorLayer.cpp @@ -25,15 +25,17 @@ $register_ids(CreatorLayer) { // move vault button to its own menu if (auto lockBtn = setIDSafe(menu, -2, "vault-button")) { - detachIntoOwnMenu(this, lockBtn, "top-right-menu", - ColumnLayout::create(5.f, 0.f)->setAlignment(Alignment::Begin) + detachAndCreateMenu(this, "top-right-menu", + ColumnLayout::create(5.f, 0.f)->setAlignment(Alignment::Begin), + lockBtn ); } // move treasure room button to its own menu if (auto roomBtn = setIDSafe(menu, -1, "treasure-room-button")) { - detachIntoOwnMenu(this, roomBtn, "bottom-right-menu", - ColumnLayout::create(5.f, 0.f)->setAlignment(Alignment::End) + detachAndCreateMenu(this, "bottom-right-menu", + ColumnLayout::create(5.f, 0.f)->setAlignment(Alignment::End), + roomBtn ); } } diff --git a/loader/src/ids/EditorUI.cpp b/loader/src/ids/EditorUI.cpp new file mode 100644 index 00000000..47be54e2 --- /dev/null +++ b/loader/src/ids/EditorUI.cpp @@ -0,0 +1,219 @@ +#include +#include +#include +#include "AddIDs.hpp" + +USE_GEODE_NAMESPACE(); + +$register_ids(EditorUI) { + + setIDSafe(this, 0, "position-slider"); + setIDSafe(this, this->getChildrenCount() - 2, "layer-index-label"); + setIDSafe(this, this->getChildrenCount() - 1, "object-info-label"); + + if (auto menu = getChildOfType(this, 0)) { + menu->setID("toolbar-categories-menu"); + + setIDs(menu, 0, + "build-button", + "edit-button", + "delete-button", + + "swipe-button", + "free-move-button", + "snap-button", + "rotate-button", + + "undo-button", + "redo-button", + "delete-button", + + "music-playback-button", + + "playtest-button", + "stop-playtest-button", + + "zoom-in-button", + "zoom-out-button", + + "link-button", + "unlink-button" + ); + + detachAndCreateMenu( + this, + "toolbar-toggles-menu", + GridLayout::create(2, GridAlignment::Begin, GridDirection::Column), + menu->getChildByID("swipe-button"), + menu->getChildByID("free-move-button"), + menu->getChildByID("snap-button"), + menu->getChildByID("rotate-button") + ); + + detachAndCreateMenu( + this, + "top-left-menu", + RowLayout::create(), + menu->getChildByID("undo-button"), + menu->getChildByID("redo-button"), + menu->getChildByID("delete-button") + ); + + detachAndCreateMenu( + this, + "playback-menu", + RowLayout::create(), + menu->getChildByID("music-playback-button") + ); + + detachAndCreateMenu( + this, + "playtest-menu", + RowLayout::create(), + menu->getChildByID("playtest-button"), + menu->getChildByID("stop-playtest-button") + ); + + detachAndCreateMenu( + this, + "zoom-menu", + ColumnLayout::create(), + menu->getChildByID("zoom-in-button"), + menu->getChildByID("zoom-out-button") + ); + + detachAndCreateMenu( + this, + "link-menu", + ColumnLayout::create(), + menu->getChildByID("link-button"), + menu->getChildByID("unlink-button") + ); + } + + if (auto menu = getChildOfType(this, 1)) { + menu->setID("delete-category-menu"); + + setIDs(menu, 0, + "delete-button", + "delete-startpos-button", + "delete-all-of-button", + + "delete-filter-none", + "delete-filter-static", + "delete-filter-detail", + "delete-filter-custom", + + "delete-help-icon" + ); + + detachAndCreateMenu( + menu, + "delete-button-menu", + GridLayout::create(2, GridAlignment::Begin, GridDirection::Column), + menu->getChildByID("delete-button"), + menu->getChildByID("delete-all-of-button"), + menu->getChildByID("delete-startpos-button") + ); + + detachAndCreateMenu( + menu, + "delete-filter-menu", + GridLayout::create(2, GridAlignment::Begin, GridDirection::Column), + menu->getChildByID("delete-filter-none"), + menu->getChildByID("delete-filter-static"), + menu->getChildByID("delete-filter-detail"), + menu->getChildByID("delete-filter-custom") + ); + } + + if (auto menu = getChildOfType(this, 2)) { + menu->setID("build-tabs-menu"); + + setIDs(menu, 0, + "static-tab-1", + "static-tab-2", + "static-tab-3", + "slope-tab", + "hazard-tab", + "3d-tab", + "portal-tab", + "deco-tab-1", + "deco-tab-2", + "pulse-deco-tab", + "sawblade-tab", + "trigger-tab", + "custom-tab" + ); + } + + if (auto menu = getChildOfType(this, 3)) { + setIDs(menu, 0, + "pause-button", + "settings-button", + "copy-paste-button", + "copy-button", + "paste-button", + "hsv-button", + "edit-special-button", + "edit-object-button", + "deselect-button", + "edit-group-button", + "portal-check", + "copy-values-button", + "paste-state-button", + "paste-color-button", + "go-to-layer-button", + "next-layer-button", + "prev-layer-button", + "all-layers-button" + ); + + detachAndCreateMenu( + this, + "top-right-menu", + RowLayout::create()->setAlignment(Alignment::End), + menu->getChildByID("pause-button"), + menu->getChildByID("settings-button") + ); + + detachAndCreateMenu( + this, + "editor-buttons-menu", + GridLayout::create(4, GridAlignment::End, GridDirection::Column), + menu->getChildByID("copy-paste-button"), + menu->getChildByID("edit-object-button"), + menu->getChildByID("paste-color-button"), + menu->getChildByID("deselect-button"), + menu->getChildByID("paste-button"), + menu->getChildByID("edit-group-button"), + menu->getChildByID("paste-state-button"), + menu->getChildByID("go-to-layer-button"), + menu->getChildByID("copy-button"), + menu->getChildByID("edit-special-button"), + menu->getChildByID("copy-values-button"), + menu->getChildByID("hsv-button") + ); + + detachAndCreateMenu( + this, + "layer-menu", + RowLayout::create(), + menu->getChildByID("all-layers-button"), + menu->getChildByID("prev-layer-button"), + this->getChildByID("layer-index-label"), + menu->getChildByID("next-layer-button") + ); + } +} + +class $modify(EditorUI) { + bool init(LevelEditorLayer* lel) { + if (!EditorUI::init(lel)) + return false; + + NodeIDs::get()->provide(this); + + return true; + } +}; diff --git a/loader/src/ids/LevelBrowserLayer.cpp b/loader/src/ids/LevelBrowserLayer.cpp index 16859613..3df0c150 100644 --- a/loader/src/ids/LevelBrowserLayer.cpp +++ b/loader/src/ids/LevelBrowserLayer.cpp @@ -17,8 +17,9 @@ $register_ids(LevelBrowserLayer) { setIDSafe(menu, 0, "new-level-button"); if (auto myLevelsBtn = setIDSafe(menu, 1, "my-levels-button")) { - detachIntoOwnMenu(this, myLevelsBtn, "my-levels-menu", - ColumnLayout::create(5.f, 0.f)->setAlignment(Alignment::End) + detachAndCreateMenu(this, "my-levels-menu", + ColumnLayout::create(5.f, 0.f)->setAlignment(Alignment::End), + myLevelsBtn ); } diff --git a/loader/src/ids/LevelInfoLayer.cpp b/loader/src/ids/LevelInfoLayer.cpp index 28e216b0..3bd0b7a3 100644 --- a/loader/src/ids/LevelInfoLayer.cpp +++ b/loader/src/ids/LevelInfoLayer.cpp @@ -42,9 +42,10 @@ $register_ids(LevelInfoLayer) { menu->setID("right-side-menu"); if (auto name = setIDSafe(menu, 0, "creator-name")) { - detachIntoOwnMenu( - this, name, "creator-info-menu", - ColumnLayout::create()->setAlignment(Alignment::Begin) + detachAndCreateMenu( + this, "creator-info-menu", + ColumnLayout::create()->setAlignment(Alignment::Begin), + name ); } diff --git a/loader/src/ids/MenuLayer.cpp b/loader/src/ids/MenuLayer.cpp index a62f3939..5cf66c06 100644 --- a/loader/src/ids/MenuLayer.cpp +++ b/loader/src/ids/MenuLayer.cpp @@ -55,8 +55,9 @@ $register_ids(MenuLayer) { // move daily chest to its own menu if (auto dailyChest = setIDSafe(menu, -1, "daily-chest-button")) { - detachIntoOwnMenu(this, dailyChest, "right-side-menu", - ColumnLayout::create(0.f, 0.f) + detachAndCreateMenu(this, "right-side-menu", + ColumnLayout::create(0.f, 0.f), + dailyChest ); } @@ -78,8 +79,9 @@ $register_ids(MenuLayer) { // move close button to its own menu if (auto closeBtn = setIDSafe(menu, 1, "close-button")) { - detachIntoOwnMenu(this, closeBtn, "close-menu", - RowLayout::create(5.f, 0.f)->setAlignment(Alignment::Begin) + detachAndCreateMenu(this, "close-menu", + RowLayout::create(5.f, 0.f)->setAlignment(Alignment::Begin), + closeBtn ); } }