HierarchyFrame.ts 3.2 KB

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