SelectionPrefabWidget.ts 3.5 KB

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