HierarchyFrame.ts 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. class HierarchyFrame extends Atomic.UIWidget {
  2. hierList: Atomic.UIListView;
  3. constructor(parent: Atomic.UIWidget) {
  4. super();
  5. this.load("AtomicEditor/editor/ui/hierarchyframe.tb.txt");
  6. this.gravity = Atomic.UI_GRAVITY_TOP_BOTTOM;
  7. var hierarchycontainer = parent.getWidget("hierarchycontainer");
  8. hierarchycontainer.addChild(this);
  9. hierarchycontainer = this.getWidget("hierarchycontainer");
  10. var hierList = this.hierList = new Atomic.UIListView();
  11. hierList.rootList.id = "hierList_";
  12. hierarchycontainer.addChild(hierList);
  13. //this.subscribeToEvent("NodeAdded", (data) => this.handleNodeAdded(data));
  14. this.subscribeToEvent("EditorUpdateHierarchy", (data) => this.handleUpdateHierarchy(data));
  15. this.subscribeToEvent(this, "WidgetEvent", (data) => this.handleWidgetEvent(data));
  16. this.subscribeToEvent("EditorActiveSceneChanged", (data) => this.handleActiveSceneChanged(data));
  17. }
  18. recursiveAddNode(parentID: number, node: Atomic.Node) {
  19. var name = node.name;
  20. if (!name.length)
  21. name = "(Anonymous)"
  22. var childItemID = this.hierList.addChildItem(parentID, name, "Folder.icon", node.id.toString());
  23. for (var i = 0; i < node.getNumChildren(false); i++) {
  24. this.recursiveAddNode(childItemID, node.getChildAtIndex(i));
  25. }
  26. }
  27. refresh() {
  28. this.hierList.deleteAllItems();
  29. if (!this.scene)
  30. return;
  31. var parentID = this.hierList.addRootItem("Scene", "Folder.icon", this.scene.id.toString());
  32. for (var i = 0; i < this.scene.getNumChildren(false); i++) {
  33. this.recursiveAddNode(parentID, this.scene.getChildAtIndex(i));
  34. }
  35. this.hierList.rootList.value = 0;
  36. this.hierList.setExpanded(parentID, true);
  37. }
  38. handleUpdateHierarchy(data) {
  39. this.refresh();
  40. }
  41. handleActiveSceneChanged(data) {
  42. this.scene = <Atomic.Scene> data.scene;
  43. this.refresh();
  44. }
  45. handleWidgetEvent(data: Atomic.UIWidgetEvent): boolean {
  46. if (data.type == Atomic.UI_EVENT_TYPE_CLICK && data.target) {
  47. var id = data.target.id;
  48. if (id == "hierList_") {
  49. var list = <Atomic.UISelectList> data.target;
  50. var selectedId = Number(list.selectedItemID);
  51. var node = this.scene.getNode(selectedId);
  52. this.hierList.rootList.dragObject = new Atomic.UIDragObject(node, node.name.length ? node.name : "(Anonymous)");
  53. this.sendEvent("EditorActiveNodeChange", { node: node });
  54. return false;
  55. }
  56. }
  57. return false;
  58. }
  59. scene: Atomic.Scene = null;
  60. }
  61. export = HierarchyFrame;