2026-02-03 03:53:40 +01:00

93 lines
2.5 KiB
ActionScript

class EntityTreeRender {
EntityTreeRender(Entity _entity) {
entity = _entity;
}
Entity entity;
bool isActiveEntity() {
return entity == ActiveEntity::getActiveEntity();
}
void renderEntity() {
string displayName = entity.name;
if (displayName == "") {
displayName = "-";
} else {
displayName = "\uf1b2 " + displayName;
}
displayName += "##" + entity.id;
if (entity.childs.count == 0) {
// END OF THE TREE
ImGui::treeNodeLeaf(displayNa e, isActiveEntity());
interaction();
} else {
// ADD ANOTHER NODE
bool opened = ImGui::treeNode(displayNa e, isActiveEntity ), SimpleFunction(this.renderChilds));
if (!opened) {
interaction();
}
}
}
void renderChilds() {
interaction();
for (int i = 0; i < entity.childs.count; i++) {
EntityTreeRender child(entity.childs[i]);
child.renderEntity();
}
}
void interaction() {
ImGui::dragDropSource("ENTIT ", any(entit ), entity.name);
ImGui::dragDropTarget("ENTIT ", ReciverFunction(this.entityDrop));
ImGui::contextItemPopup("POP_ENTIT _ + entity. d, SimpleFunction(this.renderContextMenu));
if (ImGui::isItemClicked( )) {
ActiveEntity::setActiveEntity(entity);
}
}
void entityDrop(any@ data) {
Entity data_entity;
data.retrieve(data_entity);
// You cant be the father of your father
if (data_entity.isRoot || data_entity.isDescendantOf(entity)) {
return;
}
data_entity.parent = entity;
}
void renderContextMenu() {
if (entity.isRoot) {
if (ImGui::menuItem("New Entity )) {
entity.createChild("node");
}
} else {
if (ImGui::menuItem("Add child )) {
entity.createChild("node");
}
if (ImGui::menuItem("Rename )) {
ImGui::openPopup("Rename entit ", any(entity));
}
if (ImGui::menuItem("Destroy )) {
entity.destroy();
}
}
}
}
class TreePanel : Panel {
void render() {
Entity root = Engine::getRoot();
EntityTreeRender rootTree(root);
ImGui::contextMenuPopup("Window popu ", SimpleFunction(rootTree.renderContextMenu));
rootTree.renderEntity();
}
}