HierarchyFrameMenu.ts 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  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 EditorEvents = require("editor/EditorEvents");
  24. import EditorUI = require("ui/EditorUI");
  25. import MenuItemSources = require("./MenuItemSources");
  26. class HierarchyFrameMenus extends Atomic.ScriptObject {
  27. constructor() {
  28. super();
  29. MenuItemSources.createMenuItemSource("hierarchy create items", createItems);
  30. MenuItemSources.createMenuItemSource("node context general", nodeGeneralContextItems);
  31. this.subscribeToEvent(EditorEvents.ContentFolderChanged, (ev: EditorEvents.ContentFolderChangedEvent) => {
  32. this.contentFolder = ev.path;
  33. });
  34. }
  35. handlePopupMenu(target: Atomic.UIWidget, refid: string, node: Atomic.Node): boolean {
  36. if (!target || !refid) return false;
  37. if (target.id == "create popup") {
  38. var child: Atomic.Node;
  39. if (refid == "create_node") {
  40. if (node) {
  41. child = node.createChild("Node");
  42. }
  43. }
  44. else if (refid == "create_light") {
  45. if (node) {
  46. child = node.createChild("Light");
  47. child.createComponent("Light");
  48. }
  49. }
  50. if (child) {
  51. child.scene.sendEvent("SceneEditNodeCreated", { node: child });
  52. }
  53. return true;
  54. }
  55. return false;
  56. }
  57. handleNodeContextMenu(target: Atomic.UIWidget, refid: string): boolean {
  58. if (target.id == "node context menu") {
  59. var node = <Atomic.Node>target["node"];
  60. if (!node) {
  61. return false;
  62. }
  63. if (refid == "delete_node") {
  64. if (node instanceof Atomic.Scene)
  65. return;
  66. var scene = node.scene;
  67. scene.sendEvent("SceneEditAddRemoveNodes", { end: false });
  68. scene.sendEvent("SceneEditNodeRemoved", { node: node, parent: node.parent, scene: scene });
  69. node.remove();
  70. scene.sendEvent("SceneEditAddRemoveNodes", { end: true });
  71. } else if (refid == "duplicate_node") {
  72. if (node instanceof Atomic.Scene)
  73. return;
  74. var newnode = node.clone();
  75. node.scene.sendEvent("SceneEditNodeCreated", { node: newnode });
  76. }
  77. return true;
  78. }
  79. return false;
  80. }
  81. createNodeContextMenu(parent: Atomic.UIWidget, node: Atomic.Node, x: number, y: number) {
  82. var menu = new Atomic.UIMenuWindow(parent, "node context menu");
  83. menu["node"] = node;
  84. var srcName: string = "node context general";
  85. var src = MenuItemSources.getMenuItemSource(srcName);
  86. menu.show(src, x, y);
  87. }
  88. contentFolder: string;
  89. }
  90. export = HierarchyFrameMenus;
  91. // initialization
  92. var StringID = strings.StringID;
  93. var createItems = {
  94. Node: ["create_node", undefined, "Folder.icon"],
  95. "-1": null,
  96. "3D": {
  97. Light: ["create_light", undefined, "JavascriptBitmap"]
  98. }
  99. };
  100. var nodeGeneralContextItems = {
  101. "Duplicate": ["duplicate_node", undefined, ""],
  102. "-1": null,
  103. "Delete": ["delete_node", undefined, ""]
  104. };