SelectionPrefabWidget.ts 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. //
  2. // Copyright (c) 2014-2015, THUNDERBEAST GAMES LLC All rights reserved
  3. // LICENSE: Atomic Game Engine Editor and Tools EULA
  4. // Please see LICENSE_ATOMIC_EDITOR_AND_TOOLS.md in repository root for
  5. // license information: https://github.com/AtomicGameEngine/AtomicGameEngine
  6. //
  7. class SelectionPrefabWidget extends Atomic.UILayout {
  8. widgetLayout: Atomic.UILayout;
  9. noticeLayout: Atomic.UILayout;
  10. node: Atomic.Node;
  11. constructor() {
  12. super();
  13. var fd = new Atomic.UIFontDescription();
  14. fd.id = "Vera";
  15. fd.size = 11;
  16. var widgetLayout = this.widgetLayout = new Atomic.UILayout();
  17. var noticeLayout = this.noticeLayout = new Atomic.UILayout();
  18. this.axis = Atomic.UI_AXIS_Y;
  19. widgetLayout.layoutDistribution = Atomic.UI_LAYOUT_DISTRIBUTION_GRAVITY;
  20. noticeLayout.layoutDistribution = Atomic.UI_LAYOUT_DISTRIBUTION_GRAVITY;
  21. var name = new Atomic.UITextField();
  22. name.textAlign = Atomic.UI_TEXT_ALIGN_LEFT;
  23. name.skinBg = "InspectorTextAttrName";
  24. name.text = "Prefab"
  25. name.fontDescription = fd;
  26. var saveButton = new Atomic.UIButton();
  27. saveButton.text = "Save";
  28. saveButton.fontDescription = fd;
  29. saveButton.onClick = () => {
  30. this.node.scene.sendEvent("SceneEditPrefabSave", {node : this.node});
  31. return true;
  32. }
  33. var undoButton = new Atomic.UIButton();
  34. undoButton.text = "Revert";
  35. undoButton.fontDescription = fd;
  36. undoButton.onClick = () => {
  37. this.node.scene.sendEvent("SceneEditPrefabRevert", {node : this.node});
  38. return true;
  39. }
  40. var breakButton = new Atomic.UIButton();
  41. breakButton.text = "Break";
  42. breakButton.fontDescription = fd;
  43. breakButton.onClick = () => {
  44. this.node.scene.sendEvent("SceneEditPrefabBreak", {node : this.node});
  45. return true;
  46. }
  47. var noticeName = new Atomic.UITextField();
  48. noticeName.textAlign = Atomic.UI_TEXT_ALIGN_LEFT;
  49. noticeName.skinBg = "InspectorTextAttrName";
  50. noticeName.text = "Prefab"
  51. noticeName.fontDescription = fd;
  52. var noticeText = new Atomic.UITextField();
  53. noticeText.textAlign = Atomic.UI_TEXT_ALIGN_LEFT;
  54. noticeText.skinBg = "InspectorTextAttrName";
  55. noticeText.text = "Multiple Selection"
  56. noticeText.fontDescription = fd;
  57. noticeLayout.addChild(noticeName);
  58. noticeLayout.addChild(noticeText);
  59. widgetLayout.addChild(name);
  60. widgetLayout.addChild(saveButton);
  61. widgetLayout.addChild(undoButton);
  62. widgetLayout.addChild(breakButton);
  63. this.addChild(this.widgetLayout);
  64. this.addChild(this.noticeLayout);
  65. this.visibility = Atomic.UI_WIDGET_VISIBILITY_GONE;
  66. }
  67. detectPrefab(node: Atomic.Node): boolean {
  68. if (node.getComponent("PrefabComponent"))
  69. return true;
  70. if (node.parent)
  71. return this.detectPrefab(node.parent);
  72. return false;
  73. }
  74. updateSelection(nodes: Atomic.Node[]) {
  75. var hasPrefab = false;
  76. this.node = null;
  77. for (var i in nodes) {
  78. var node = nodes[i];
  79. if (this.detectPrefab(node)) {
  80. hasPrefab = true;
  81. break;
  82. }
  83. }
  84. if (!hasPrefab) {
  85. this.visibility = Atomic.UI_WIDGET_VISIBILITY_GONE;
  86. return;
  87. }
  88. this.visibility = Atomic.UI_WIDGET_VISIBILITY_VISIBLE;
  89. if (nodes.length > 1) {
  90. this.noticeLayout.visibility = Atomic.UI_WIDGET_VISIBILITY_VISIBLE;
  91. this.widgetLayout.visibility = Atomic.UI_WIDGET_VISIBILITY_GONE;
  92. return;
  93. }
  94. this.noticeLayout.visibility = Atomic.UI_WIDGET_VISIBILITY_GONE;
  95. this.widgetLayout.visibility = Atomic.UI_WIDGET_VISIBILITY_VISIBLE;
  96. this.node = nodes[0];
  97. }
  98. }
  99. export = SelectionPrefabWidget;