SelectionPrefabWidget.ts 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  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. constructor() {
  11. super();
  12. var fd = new Atomic.UIFontDescription();
  13. fd.id = "Vera";
  14. fd.size = 11;
  15. var widgetLayout = this.widgetLayout = new Atomic.UILayout();
  16. var noticeLayout = this.noticeLayout = new Atomic.UILayout();
  17. this.axis = Atomic.UI_AXIS_Y;
  18. widgetLayout.layoutDistribution = Atomic.UI_LAYOUT_DISTRIBUTION_GRAVITY;
  19. noticeLayout.layoutDistribution = Atomic.UI_LAYOUT_DISTRIBUTION_GRAVITY;
  20. var name = new Atomic.UITextField();
  21. name.textAlign = Atomic.UI_TEXT_ALIGN_LEFT;
  22. name.skinBg = "InspectorTextAttrName";
  23. name.text = "Prefab"
  24. name.fontDescription = fd;
  25. var saveButton = new Atomic.UIButton();
  26. saveButton.text = "Save";
  27. saveButton.fontDescription = fd;
  28. saveButton.onClick = () => {
  29. this.sendEvent("SelectionPrefabSave");
  30. return true;
  31. }
  32. var undoButton = new Atomic.UIButton();
  33. undoButton.text = "Undo";
  34. undoButton.fontDescription = fd;
  35. undoButton.onClick = () => {
  36. this.sendEvent("SelectionPrefabUndo");
  37. return true;
  38. }
  39. var breakButton = new Atomic.UIButton();
  40. breakButton.text = "Break";
  41. breakButton.fontDescription = fd;
  42. breakButton.onClick = () => {
  43. this.sendEvent("SelectionPrefabBreak");
  44. return true;
  45. }
  46. var noticeName = new Atomic.UITextField();
  47. noticeName.textAlign = Atomic.UI_TEXT_ALIGN_LEFT;
  48. noticeName.skinBg = "InspectorTextAttrName";
  49. noticeName.text = "Prefab"
  50. noticeName.fontDescription = fd;
  51. var noticeText = new Atomic.UITextField();
  52. noticeText.textAlign = Atomic.UI_TEXT_ALIGN_LEFT;
  53. noticeText.skinBg = "InspectorTextAttrName";
  54. noticeText.text = "Multiple Selection"
  55. noticeText.fontDescription = fd;
  56. noticeLayout.addChild(noticeName);
  57. noticeLayout.addChild(noticeText);
  58. widgetLayout.addChild(name);
  59. widgetLayout.addChild(saveButton);
  60. widgetLayout.addChild(undoButton);
  61. widgetLayout.addChild(breakButton);
  62. this.addChild(this.widgetLayout);
  63. this.addChild(this.noticeLayout);
  64. this.visibility = Atomic.UI_WIDGET_VISIBILITY_GONE;
  65. }
  66. detectPrefab(node: Atomic.Node): boolean {
  67. if (node.getComponent("PrefabComponent"))
  68. return true;
  69. if (node.parent)
  70. return this.detectPrefab(node.parent);
  71. return false;
  72. }
  73. updateSelection(nodes: Atomic.Node[]) {
  74. var hasPrefab = false;
  75. for (var i in nodes) {
  76. var node = nodes[i];
  77. if (this.detectPrefab(node)) {
  78. hasPrefab = true;
  79. break;
  80. }
  81. }
  82. if (!hasPrefab) {
  83. this.visibility = Atomic.UI_WIDGET_VISIBILITY_GONE;
  84. return;
  85. }
  86. this.visibility = Atomic.UI_WIDGET_VISIBILITY_VISIBLE;
  87. if (nodes.length > 1) {
  88. this.noticeLayout.visibility = Atomic.UI_WIDGET_VISIBILITY_VISIBLE;
  89. this.widgetLayout.visibility = Atomic.UI_WIDGET_VISIBILITY_GONE;
  90. return;
  91. }
  92. this.noticeLayout.visibility = Atomic.UI_WIDGET_VISIBILITY_GONE;
  93. this.widgetLayout.visibility = Atomic.UI_WIDGET_VISIBILITY_VISIBLE;
  94. }
  95. }
  96. export = SelectionPrefabWidget;