99 lines
2.8 KiB
ActionScript
99 lines
2.8 KiB
ActionScript
class TreePannel : DockPanel {
|
|
void onRender() {
|
|
Entity root = getRoot();
|
|
contextMenuPopup("Window popup", any(root), ReciverFunc(this.entityContextMenu));
|
|
|
|
bool opened = treeNode(root.name, false, any(root), ReciverFunc(this.renderNode));
|
|
if (!opened) {
|
|
contextItemPopup("POP_ENTITY_" + root.id, any(root), ReciverFunc(this.entityContextMenu));
|
|
}
|
|
|
|
modalPopup("Rename entity", renameEntity);
|
|
}
|
|
|
|
void entityInteraction(Entity entity) {
|
|
any data = any(entity);
|
|
|
|
dragDropSource("ENTITY", data, entity.name);
|
|
dragDropTarget("ENTITY", data, TransferFunc(this.entityDrop));
|
|
contextItemPopup("POP_ENTITY_" + entity.id, data, ReciverFunc(this.entityContextMenu));
|
|
|
|
// We can't select the entity
|
|
if (isItemClicked(0)) {
|
|
activeEntity = entity;
|
|
}
|
|
}
|
|
|
|
void renderNode(any@ data) {
|
|
Entity entity;
|
|
data.retrieve(entity);
|
|
|
|
entityInteraction(entity);
|
|
|
|
// Maybe we deleted the entity in the context menu
|
|
if (!entity.exists)
|
|
return;
|
|
|
|
for (int i = 0; i < entity.childs.count; i++) {
|
|
Entity child = entity.childs[i];
|
|
bool isActive = child == activeEntity;
|
|
|
|
string displayName = child.name;
|
|
if (displayName == "") {
|
|
displayName = "-";
|
|
}
|
|
|
|
displayName += "##" + child.id;
|
|
if (child.childs.count == 0) {
|
|
// END OF THE TREE
|
|
treeNodeLeaf(displayName, isActive);
|
|
entityInteraction(child);
|
|
} else {
|
|
// ADD ANOTHER NODE
|
|
bool opened = treeNode(displayName, isActive, any(child), ReciverFunc(this.renderNode));
|
|
if (!opened) {
|
|
entityInteraction(child);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
void entityContextMenu(any@ data) {
|
|
Entity entity;
|
|
data.retrieve(entity);
|
|
|
|
if (entity.isRoot) {
|
|
if (menuItem("New Entity")) {
|
|
entity.createChild("node");
|
|
}
|
|
} else {
|
|
if (menuItem("Add child")) {
|
|
entity.createChild("node");
|
|
}
|
|
|
|
if (menuItem("Rename")) {
|
|
openPopup("Rename entity", data);
|
|
}
|
|
|
|
if (menuItem("Destroy")) {
|
|
entity.destroy();
|
|
}
|
|
}
|
|
}
|
|
|
|
void entityDrop(any@ reciver, any@ emiter) {
|
|
Entity reciver_entity;
|
|
reciver.retrieve(reciver_entity);
|
|
|
|
Entity emiter_entity;
|
|
emiter.retrieve(emiter_entity);
|
|
|
|
// You cant be the father of your father
|
|
if (emiter_entity.isRoot || reciver_entity.isDescendantOf(emiter_entity)) {
|
|
return;
|
|
}
|
|
|
|
emiter_entity.parent = reciver_entity;
|
|
}
|
|
}
|