|
|
@@ -1,10 +1,20 @@
|
|
|
|
|
|
+import HierarchyFrameMenu = require("./HierarchyFrameMenu");
|
|
|
+import MenuItemSources = require("./menus/MenuItemSources");
|
|
|
+
|
|
|
class HierarchyFrame extends Atomic.UIWidget {
|
|
|
|
|
|
+ scene: Atomic.Scene = null;
|
|
|
+ hierList: Atomic.UIListView;
|
|
|
+ menu: HierarchyFrameMenu;
|
|
|
+ nodeIDToItemID = {};
|
|
|
+
|
|
|
constructor(parent: Atomic.UIWidget) {
|
|
|
|
|
|
super();
|
|
|
|
|
|
+ this.menu = new HierarchyFrameMenu();
|
|
|
+
|
|
|
this.load("AtomicEditor/editor/ui/hierarchyframe.tb.txt");
|
|
|
|
|
|
this.gravity = Atomic.UI_GRAVITY_TOP_BOTTOM;
|
|
|
@@ -20,8 +30,6 @@ class HierarchyFrame extends Atomic.UIWidget {
|
|
|
|
|
|
hierarchycontainer.addChild(hierList);
|
|
|
|
|
|
- this.subscribeToEvent("EditorUpdateHierarchy", (data) => this.handleUpdateHierarchy(data));
|
|
|
-
|
|
|
this.subscribeToEvent(this, "WidgetEvent", (data) => this.handleWidgetEvent(data));
|
|
|
|
|
|
this.subscribeToEvent("EditorActiveSceneChanged", (data) => this.handleActiveSceneChanged(data));
|
|
|
@@ -29,91 +37,98 @@ class HierarchyFrame extends Atomic.UIWidget {
|
|
|
this.subscribeToEvent("EditorActiveNodeChange", (data) => {
|
|
|
|
|
|
if (data.node)
|
|
|
- this.hierList.selectItemByID(data.node.id.toString());
|
|
|
+ this.hierList.selectItemByID(data.node.id.toString());
|
|
|
|
|
|
});
|
|
|
|
|
|
}
|
|
|
|
|
|
- recursiveAddNode(parentID: number, node: Atomic.Node) {
|
|
|
+ handleNodeAdded(ev: Atomic.NodeAddedEvent) {
|
|
|
|
|
|
- //if (node.isTemporary())
|
|
|
- // return;
|
|
|
+ var node = ev.node;
|
|
|
|
|
|
- var name = node.name;
|
|
|
+ if (!node.parent || node.scene != this.scene)
|
|
|
+ return;
|
|
|
|
|
|
- if (!name.length)
|
|
|
- name = "(Anonymous)"
|
|
|
+ var parentID = this.nodeIDToItemID[node.parent.id];
|
|
|
|
|
|
- var childItemID = this.hierList.addChildItem(parentID, name, "Folder.icon", node.id.toString());
|
|
|
+ var childItemID = this.hierList.addChildItem(parentID, node.name, "Folder.icon", node.id.toString());
|
|
|
|
|
|
- for (var i = 0; i < node.getNumChildren(false); i++) {
|
|
|
+ this.nodeIDToItemID[node.id] = childItemID;
|
|
|
|
|
|
- this.recursiveAddNode(childItemID, node.getChildAtIndex(i));
|
|
|
+ }
|
|
|
|
|
|
- }
|
|
|
+ handleNodeRemoved(ev: Atomic.NodeRemovedEvent) {
|
|
|
|
|
|
- }
|
|
|
+ console.log("handle Node Removed");
|
|
|
|
|
|
- refresh() {
|
|
|
+ var node = ev.node;
|
|
|
|
|
|
- this.hierList.deleteAllItems();
|
|
|
+ delete this.nodeIDToItemID[node.id];
|
|
|
|
|
|
- if (!this.scene)
|
|
|
+ if (!node.parent || node.scene != this.scene)
|
|
|
return;
|
|
|
|
|
|
- var parentID = this.hierList.addRootItem("Scene", "Folder.icon", this.scene.id.toString());
|
|
|
+ this.hierList.deleteItemByID(node.id.toString());
|
|
|
|
|
|
- for (var i = 0; i < this.scene.getNumChildren(false); i++) {
|
|
|
+ this.sendEvent("EditorActiveNodeChange", { node: ev.parent ? ev.parent : this.scene});
|
|
|
|
|
|
- this.recursiveAddNode(parentID, this.scene.getChildAtIndex(i));
|
|
|
+ }
|
|
|
|
|
|
- }
|
|
|
+ handleActiveSceneChanged(data) {
|
|
|
|
|
|
- this.hierList.rootList.value = 0;
|
|
|
- this.hierList.setExpanded(parentID, true);
|
|
|
+ if (this.scene)
|
|
|
+ this.unsubscribeFromEvents(this.scene);
|
|
|
|
|
|
- }
|
|
|
+ this.scene = <Atomic.Scene> data.scene;
|
|
|
|
|
|
- handleUpdateHierarchy(data) {
|
|
|
+ this.populate();
|
|
|
|
|
|
- this.refresh();
|
|
|
+ if (this.scene) {
|
|
|
|
|
|
- }
|
|
|
+ this.subscribeToEvent(this.scene, "NodeAdded", (ev: Atomic.NodeAddedEvent) => this.handleNodeAdded(ev));
|
|
|
+ this.subscribeToEvent(this.scene, "NodeRemoved", (ev: Atomic.NodeRemovedEvent) => this.handleNodeRemoved(ev));
|
|
|
+ this.subscribeToEvent(this.scene, "NodeNameChanged", (ev: Atomic.NodeNameChangedEvent) => {
|
|
|
|
|
|
- handleActiveSceneChanged(data) {
|
|
|
+ this.hierList.setItemText(ev.node.id.toString(), ev.node.name);
|
|
|
|
|
|
- if (this.scene)
|
|
|
- this.unsubscribeFromEvents(this.scene);
|
|
|
+ });
|
|
|
|
|
|
- this.scene = <Atomic.Scene> data.scene;
|
|
|
+ }
|
|
|
|
|
|
- if (this.scene) {
|
|
|
+ }
|
|
|
|
|
|
- this.subscribeToEvent("NodeRemoved", (data) => {
|
|
|
+ handleWidgetEvent(data: Atomic.UIWidgetEvent): boolean {
|
|
|
|
|
|
- this.hierList.deleteItemByID(data.node.id.toString());
|
|
|
+ if (data.type == Atomic.UI_EVENT_TYPE_CLICK) {
|
|
|
|
|
|
- });
|
|
|
+ var id = data.target.id;
|
|
|
|
|
|
- this.subscribeToEvent("NodeAdded", (data) => {
|
|
|
+ if (this.menu.handlePopupMenu(data.target, data.refid))
|
|
|
+ return true;
|
|
|
|
|
|
- this.refresh();
|
|
|
+ if (id == "create popup") {
|
|
|
|
|
|
- });
|
|
|
+ if (data.refid == "create_node") {
|
|
|
|
|
|
+ var selectedId = Number(this.hierList.rootList.selectedItemID);
|
|
|
+ var node = this.scene.getNode(selectedId);
|
|
|
+ node.createChild("Node");
|
|
|
|
|
|
- }
|
|
|
+ }
|
|
|
|
|
|
- this.refresh();
|
|
|
+ }
|
|
|
|
|
|
- }
|
|
|
+ // create
|
|
|
+ if (id == "menu create") {
|
|
|
|
|
|
- handleWidgetEvent(data: Atomic.UIWidgetEvent): boolean {
|
|
|
+ var src = MenuItemSources.getMenuItemSource("hierarchy create items");
|
|
|
+ var menu = new Atomic.UIMenuWindow(data.target, "create popup");
|
|
|
+ menu.show(src);
|
|
|
+ return true;
|
|
|
|
|
|
- if (data.type == Atomic.UI_EVENT_TYPE_CLICK && data.target) {
|
|
|
+ }
|
|
|
|
|
|
- var id = data.target.id;
|
|
|
|
|
|
if (id == "hierList_") {
|
|
|
|
|
|
@@ -131,8 +146,50 @@ class HierarchyFrame extends Atomic.UIWidget {
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
- scene: Atomic.Scene = null;
|
|
|
- hierList: Atomic.UIListView;
|
|
|
+ recursiveAddNode(parentID: number, node: Atomic.Node) {
|
|
|
+
|
|
|
+ //if (node.isTemporary())
|
|
|
+ // return;
|
|
|
+
|
|
|
+ var name = node.name;
|
|
|
+
|
|
|
+ if (!name.length)
|
|
|
+ name = "(Anonymous)"
|
|
|
+
|
|
|
+ var childItemID = this.hierList.addChildItem(parentID, name, "Folder.icon", node.id.toString());
|
|
|
+
|
|
|
+ this.nodeIDToItemID[node.id] = childItemID;
|
|
|
+
|
|
|
+ for (var i = 0; i < node.getNumChildren(false); i++) {
|
|
|
+
|
|
|
+ this.recursiveAddNode(childItemID, node.getChildAtIndex(i));
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ populate() {
|
|
|
+
|
|
|
+ this.nodeIDToItemID = {};
|
|
|
+ this.hierList.deleteAllItems();
|
|
|
+
|
|
|
+ if (!this.scene)
|
|
|
+ return;
|
|
|
+
|
|
|
+ var parentID = this.hierList.addRootItem("Scene", "Folder.icon", this.scene.id.toString());
|
|
|
+
|
|
|
+ this.nodeIDToItemID[this.scene.id] = parentID;
|
|
|
+
|
|
|
+ for (var i = 0; i < this.scene.getNumChildren(false); i++) {
|
|
|
+
|
|
|
+ this.recursiveAddNode(parentID, this.scene.getChildAtIndex(i));
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ this.hierList.rootList.value = 0;
|
|
|
+ this.hierList.setExpanded(parentID, true);
|
|
|
+
|
|
|
+ }
|
|
|
|
|
|
}
|
|
|
|