mirror of
https://github.com/geode-sdk/geode.git
synced 2024-11-26 17:36:05 -05:00
string id helpers and editorui fully done
This commit is contained in:
parent
44bcf1844a
commit
5921c96bcb
6 changed files with 278 additions and 20 deletions
|
@ -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 <typename ...Args>
|
||||
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<CCNode*>(parent->getChildren()->objectAtIndex(idx)), menu);
|
||||
}
|
||||
|
||||
template <typename ...Args>
|
||||
static void switchChildrenToMenu(CCNode* parent, CCMenu* menu, Args... args) {
|
||||
for (auto i : { args... }) {
|
||||
switchChildToMenu(parent, i, menu);
|
||||
}
|
||||
}
|
||||
|
||||
template <typename T, typename ...Args>
|
||||
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;
|
||||
}
|
||||
}
|
|
@ -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
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
219
loader/src/ids/EditorUI.cpp
Normal file
219
loader/src/ids/EditorUI.cpp
Normal file
|
@ -0,0 +1,219 @@
|
|||
#include <Geode/Modify.hpp>
|
||||
#include <Geode/Bindings.hpp>
|
||||
#include <Geode/utils/cocos.hpp>
|
||||
#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<CCMenu>(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<CCMenu>(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<CCMenu>(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<CCMenu>(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;
|
||||
}
|
||||
};
|
|
@ -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
|
||||
);
|
||||
}
|
||||
|
||||
|
|
|
@ -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
|
||||
);
|
||||
}
|
||||
|
||||
|
|
|
@ -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
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue