SelectionPrefabWidget.ts 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  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. class SelectionPrefabWidget extends Atomic.UILayout {
  23. widgetLayout: Atomic.UILayout;
  24. noticeLayout: Atomic.UILayout;
  25. node: Atomic.Node;
  26. constructor() {
  27. super();
  28. var fd = new Atomic.UIFontDescription();
  29. fd.id = "Vera";
  30. fd.size = 11;
  31. var widgetLayout = this.widgetLayout = new Atomic.UILayout();
  32. var noticeLayout = this.noticeLayout = new Atomic.UILayout();
  33. this.axis = Atomic.UI_AXIS_Y;
  34. widgetLayout.layoutDistribution = Atomic.UI_LAYOUT_DISTRIBUTION_GRAVITY;
  35. noticeLayout.layoutDistribution = Atomic.UI_LAYOUT_DISTRIBUTION_GRAVITY;
  36. var name = new Atomic.UITextField();
  37. name.textAlign = Atomic.UI_TEXT_ALIGN_LEFT;
  38. name.skinBg = "InspectorTextAttrName";
  39. name.text = "Prefab";
  40. name.fontDescription = fd;
  41. var saveButton = new Atomic.UIButton();
  42. saveButton.text = "Save";
  43. saveButton.fontDescription = fd;
  44. saveButton.onClick = () => {
  45. this.node.scene.sendEvent("SceneEditPrefabSave", {node : this.node});
  46. return true;
  47. };
  48. var undoButton = new Atomic.UIButton();
  49. undoButton.text = "Revert";
  50. undoButton.fontDescription = fd;
  51. undoButton.onClick = () => {
  52. this.node.scene.sendEvent("SceneEditPrefabRevert", {node : this.node});
  53. return true;
  54. };
  55. var breakButton = new Atomic.UIButton();
  56. breakButton.text = "Break";
  57. breakButton.fontDescription = fd;
  58. breakButton.onClick = () => {
  59. this.node.scene.sendEvent("SceneEditPrefabBreak", {node : this.node});
  60. return true;
  61. };
  62. var copyButton = new Atomic.UIButton();
  63. copyButton.text = "Copy";
  64. copyButton.fontDescription = fd;
  65. copyButton.onClick = () => {
  66. this.node.scene.sendEvent("SceneEditPrefabCopy", {node : this.node });
  67. return true;
  68. };
  69. var pasteButton = new Atomic.UIButton();
  70. pasteButton.text = "Paste";
  71. pasteButton.fontDescription = fd;
  72. pasteButton.onClick = () => {
  73. this.node.scene.sendEvent("SceneEditPrefabPaste", {node : this.node });
  74. return true;
  75. };
  76. var noticeName = new Atomic.UITextField();
  77. noticeName.textAlign = Atomic.UI_TEXT_ALIGN_LEFT;
  78. noticeName.skinBg = "InspectorTextAttrName";
  79. noticeName.text = "Prefab";
  80. noticeName.fontDescription = fd;
  81. var noticeText = new Atomic.UITextField();
  82. noticeText.textAlign = Atomic.UI_TEXT_ALIGN_LEFT;
  83. noticeText.skinBg = "InspectorTextAttrName";
  84. noticeText.text = "Multiple Selection";
  85. noticeText.fontDescription = fd;
  86. noticeLayout.addChild(noticeName);
  87. noticeLayout.addChild(noticeText);
  88. widgetLayout.addChild(name);
  89. widgetLayout.addChild(saveButton);
  90. widgetLayout.addChild(undoButton);
  91. widgetLayout.addChild(breakButton);
  92. widgetLayout.addChild(copyButton);
  93. widgetLayout.addChild(pasteButton);
  94. this.addChild(this.widgetLayout);
  95. this.addChild(this.noticeLayout);
  96. this.visibility = Atomic.UI_WIDGET_VISIBILITY_GONE;
  97. }
  98. detectPrefab(node: Atomic.Node): boolean {
  99. if (node.getComponent("PrefabComponent"))
  100. return true;
  101. if (node.parent)
  102. return this.detectPrefab(node.parent);
  103. return false;
  104. }
  105. updateSelection(nodes: Atomic.Node[]) {
  106. var hasPrefab = false;
  107. this.node = null;
  108. for (var i in nodes) {
  109. var node = nodes[i];
  110. if (this.detectPrefab(node)) {
  111. hasPrefab = true;
  112. break;
  113. }
  114. }
  115. if (!hasPrefab) {
  116. this.visibility = Atomic.UI_WIDGET_VISIBILITY_GONE;
  117. return;
  118. }
  119. this.visibility = Atomic.UI_WIDGET_VISIBILITY_VISIBLE;
  120. if (nodes.length > 1) {
  121. this.noticeLayout.visibility = Atomic.UI_WIDGET_VISIBILITY_VISIBLE;
  122. this.widgetLayout.visibility = Atomic.UI_WIDGET_VISIBILITY_GONE;
  123. return;
  124. }
  125. this.noticeLayout.visibility = Atomic.UI_WIDGET_VISIBILITY_GONE;
  126. this.widgetLayout.visibility = Atomic.UI_WIDGET_VISIBILITY_VISIBLE;
  127. this.node = nodes[0];
  128. }
  129. }
  130. export = SelectionPrefabWidget;