SelectionSection.ts 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  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. import SerializableEditType = require("./SerializableEditType");
  8. import AttributeInfoEdit = require("./AttributeInfoEdit");
  9. import SelectionSectionUI = require("./SelectionSectionUI");
  10. import "./ComponentAttributeUI";
  11. abstract class SelectionSection extends Atomic.UISection {
  12. hasDynamicAttr: boolean = false;
  13. editType: SerializableEditType;
  14. attrLayout: Atomic.UILayout;
  15. suppressed: boolean = false;
  16. customUI: SelectionSectionUI;
  17. attrEdits: { [name: string]: AttributeInfoEdit } = {};
  18. constructor(editType: SerializableEditType) {
  19. super();
  20. this.editType = editType;
  21. this.text = editType.typeName;
  22. this.createUI();
  23. }
  24. refresh() {
  25. for (var name in this.attrEdits) {
  26. this.attrEdits[name].refresh();
  27. }
  28. if (this.customUI)
  29. this.customUI.refresh();
  30. }
  31. suppress(value: boolean) {
  32. if (this.suppressed == value) {
  33. return;
  34. }
  35. this.suppressed = value;
  36. if (value) {
  37. this.visibility = Atomic.UI_WIDGET_VISIBILITY_GONE;
  38. } else {
  39. this.visibility = Atomic.UI_WIDGET_VISIBILITY_VISIBLE;
  40. }
  41. }
  42. updateDynamicAttrInfos(attrInfos: Atomic.AttributeInfo[]) {
  43. Atomic.ui.blockChangedEvents = true;
  44. this.editType.attrInfos = attrInfos;
  45. var attrEdit: AttributeInfoEdit;
  46. var remove: AttributeInfoEdit[] = [];
  47. var addWidget: Atomic.UIWidget;
  48. for (var name in this.attrEdits) {
  49. attrEdit = this.attrEdits[name];
  50. if (attrEdit.attrInfo.dynamic) {
  51. remove.push(attrEdit);
  52. } else {
  53. addWidget = attrEdit;
  54. }
  55. }
  56. for (var i in remove) {
  57. var attrEdit = remove[i];
  58. attrEdit.remove();
  59. delete this.attrEdits[attrEdit.attrInfo.name];
  60. }
  61. for (var i in attrInfos) {
  62. var attr = attrInfos[i];
  63. if (!attr.dynamic) {
  64. continue;
  65. }
  66. if (attr.mode & Atomic.AM_NOEDIT)
  67. continue;
  68. var attrEdit = AttributeInfoEdit.createAttrEdit(this.editType, attr);
  69. if (!attrEdit)
  70. continue;
  71. this.attrEdits[attr.name] = attrEdit;
  72. if (!addWidget) {
  73. this.attrLayout.addChild(attrEdit);
  74. addWidget = attrEdit;
  75. } else {
  76. this.attrLayout.addChildAfter(attrEdit, addWidget);
  77. addWidget = attrEdit;
  78. }
  79. }
  80. this.refresh();
  81. Atomic.ui.blockChangedEvents = false;
  82. }
  83. createUI() {
  84. var attrLayout = this.attrLayout = new Atomic.UILayout(Atomic.UI_AXIS_Y);
  85. attrLayout.spacing = 3;
  86. attrLayout.layoutPosition = Atomic.UI_LAYOUT_POSITION_LEFT_TOP;
  87. attrLayout.layoutSize = Atomic.UI_LAYOUT_SIZE_AVAILABLE;
  88. this.contentRoot.addChild(attrLayout);
  89. for (var i in this.editType.attrInfos) {
  90. var attr = this.editType.attrInfos[i];
  91. if (attr.mode & Atomic.AM_NOEDIT)
  92. continue;
  93. var attrEdit = AttributeInfoEdit.createAttrEdit(this.editType, attr);
  94. if (!attrEdit)
  95. continue;
  96. this.attrEdits[attr.name] = attrEdit;
  97. attrLayout.addChild(attrEdit);
  98. }
  99. if (SelectionSection.customSectionUI[this.editType.typeName]) {
  100. this.customUI = new SelectionSection.customSectionUI[this.editType.typeName]();
  101. this.customUI.createUI(this.editType);
  102. attrLayout.addChild(this.customUI);
  103. }
  104. }
  105. static fontDesc: Atomic.UIFontDescription;
  106. static customSectionUI: { [typeName: string]: typeof SelectionSectionUI } = {};
  107. static registerCustomSectionUI(typeName: string, ui: typeof SelectionSectionUI) {
  108. SelectionSection.customSectionUI[typeName] = ui;
  109. }
  110. private static Ctor = (() => {
  111. var fd = SelectionSection.fontDesc = new Atomic.UIFontDescription();
  112. fd.id = "Vera";
  113. fd.size = 11;
  114. })();
  115. }
  116. export = SelectionSection;