HierarchyFrameMenu.ts 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  1. //
  2. // Copyright (c) 2014-2016 THUNDERBEAST GAMES LLC
  3. //
  4. // Permission is hereby granted, free of charge, to any person obtaining a copy
  5. // of this software and associated documentation files (the "Software"), to deal
  6. // in the Software without restriction, including without limitation the rights
  7. // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  8. // copies of the Software, and to permit persons to whom the Software is
  9. // furnished to do so, subject to the following conditions:
  10. //
  11. // The above copyright notice and this permission notice shall be included in
  12. // all copies or substantial portions of the Software.
  13. //
  14. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  17. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  19. // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  20. // THE SOFTWARE.
  21. //
  22. import strings = require("ui/EditorStrings");
  23. import EditorUI = require("ui/EditorUI");
  24. import MenuItemSources = require("./MenuItemSources");
  25. import ServiceLocator from "../../../hostExtensions/ServiceLocator";
  26. class HierarchyFrameMenus extends Atomic.ScriptObject {
  27. contentFolder: string;
  28. private contextMenuItemSource: Atomic.UIMenuItemSource = null;
  29. constructor() {
  30. super();
  31. MenuItemSources.createMenuItemSource("hierarchy create items", createItems);
  32. this.contextMenuItemSource = MenuItemSources.createMenuItemSource("node context general", nodeGeneralContextItems);
  33. this.subscribeToEvent(Editor.ContentFolderChangedEvent((ev: Editor.ContentFolderChangedEvent) => {
  34. this.contentFolder = ev.path;
  35. }));
  36. }
  37. handlePopupMenu(target: Atomic.UIWidget, refid: string, node: Atomic.Node): boolean {
  38. if (!target || !refid) return false;
  39. if (target.id == "create popup") {
  40. var child: Atomic.Node;
  41. if (refid == "create_node") {
  42. if (node) {
  43. child = node.createChild("Node");
  44. }
  45. }
  46. else if (refid == "create_light") {
  47. if (node) {
  48. child = node.createChild("Light");
  49. child.createComponent("Light");
  50. }
  51. }
  52. if (child) {
  53. child.scene.sendEvent(Editor.SceneEditNodeCreatedEventType, { node: child });
  54. }
  55. return true;
  56. }
  57. return false;
  58. }
  59. handleNodeContextMenu(target: Atomic.UIWidget, refid: string, editor: Editor.SceneEditor3D): boolean {
  60. if (target.id == "node context menu") {
  61. var node = <Atomic.Node>target["node"];
  62. if (!node) {
  63. return false;
  64. }
  65. if (refid == "delete_node") {
  66. if (node instanceof Atomic.Scene)
  67. return;
  68. var scene = node.scene;
  69. scene.sendEvent(Editor.SceneEditAddRemoveNodesEventType, { end: false });
  70. scene.sendEvent(Editor.SceneEditNodeRemovedEventType, { node: node, parent: node.parent, scene: scene });
  71. node.remove();
  72. scene.sendEvent(Editor.SceneEditAddRemoveNodesEventType, { end: true });
  73. editor.selection.delete();
  74. return true;
  75. } else if (refid == "duplicate_node") {
  76. if (node instanceof Atomic.Scene)
  77. return;
  78. var newnode = node.clone();
  79. node.scene.sendEvent(Editor.SceneEditNodeCreatedEventType, { node: newnode });
  80. return true;
  81. }
  82. // Let plugins handle context
  83. return ServiceLocator.uiServices.hierarchyContextItemClicked(node, refid);
  84. }
  85. return false;
  86. }
  87. createNodeContextMenu(parent: Atomic.UIWidget, node: Atomic.Node, x: number, y: number) {
  88. var menu = new Atomic.UIMenuWindow(parent, "node context menu");
  89. menu["node"] = node;
  90. var srcName: string = "node context general";
  91. var src = MenuItemSources.getMenuItemSource(srcName);
  92. menu.show(src, x, y);
  93. }
  94. createPluginItemSource(id: string, items: any): Atomic.UIMenuItemSource {
  95. return MenuItemSources.createSubMenuItemSource(this.contextMenuItemSource , id, items);
  96. }
  97. removePluginItemSource(id: string) {
  98. this.contextMenuItemSource.removeItemWithStr(id);
  99. }
  100. }
  101. export = HierarchyFrameMenus;
  102. // initialization
  103. var StringID = strings.StringID;
  104. var createItems = {
  105. Node: ["create_node", undefined, "Folder.icon"],
  106. "-1": null,
  107. "3D": {
  108. Light: ["create_light", undefined, "JavascriptBitmap"]
  109. }
  110. };
  111. var nodeGeneralContextItems = {
  112. "Duplicate": ["duplicate_node", undefined, ""],
  113. "-1": null,
  114. "Delete": ["delete_node", undefined, ""]
  115. };