SelectionSection.ts 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. import SerializableEditType = require("./SerializableEditType");
  2. import AttributeInfoEdit = require("./AttributeInfoEdit");
  3. import SelectionSectionUI = require("./SelectionSectionUI");
  4. import "./ComponentAttributeUI";
  5. abstract class SelectionSection extends Atomic.UISection {
  6. editType: SerializableEditType;
  7. attrLayout: Atomic.UILayout;
  8. suppressed: boolean = false;
  9. customUI:SelectionSectionUI;
  10. attrEdits: { [name: string]: AttributeInfoEdit } = {};
  11. constructor(editType: SerializableEditType) {
  12. super();
  13. this.editType = editType;
  14. this.text = editType.typeName;
  15. this.createUI();
  16. }
  17. refresh() {
  18. for (var name in this.attrEdits) {
  19. this.attrEdits[name].refresh();
  20. }
  21. if (this.customUI)
  22. this.customUI.refresh();
  23. }
  24. suppress(value: boolean) {
  25. if (this.suppressed == value) {
  26. return;
  27. }
  28. this.suppressed = value;
  29. if (value) {
  30. this.visibility = Atomic.UI_WIDGET_VISIBILITY_GONE;
  31. } else {
  32. this.visibility = Atomic.UI_WIDGET_VISIBILITY_VISIBLE;
  33. }
  34. }
  35. createUI() {
  36. var attrLayout = this.attrLayout = new Atomic.UILayout(Atomic.UI_AXIS_Y);
  37. attrLayout.spacing = 3;
  38. attrLayout.layoutPosition = Atomic.UI_LAYOUT_POSITION_LEFT_TOP;
  39. attrLayout.layoutSize = Atomic.UI_LAYOUT_SIZE_AVAILABLE;
  40. this.contentRoot.addChild(attrLayout);
  41. for (var i in this.editType.attrInfos) {
  42. var attr = this.editType.attrInfos[i];
  43. if (attr.mode & Atomic.AM_NOEDIT)
  44. continue;
  45. var attrEdit = AttributeInfoEdit.createAttrEdit(this.editType, attr);
  46. if (!attrEdit)
  47. continue;
  48. this.attrEdits[attr.name] = attrEdit;
  49. attrLayout.addChild(attrEdit);
  50. }
  51. if (SelectionSection.customSectionUI[this.editType.typeName]) {
  52. this.customUI = new SelectionSection.customSectionUI[this.editType.typeName]();
  53. this.customUI.createUI(this.editType);
  54. attrLayout.addChild(this.customUI);
  55. }
  56. }
  57. static fontDesc: Atomic.UIFontDescription;
  58. static customSectionUI: { [typeName: string]: typeof SelectionSectionUI } = {};
  59. static registerCustomSectionUI(typeName: string, ui: typeof SelectionSectionUI) {
  60. SelectionSection.customSectionUI[typeName] = ui;
  61. }
  62. private static Ctor = (() => {
  63. var fd = SelectionSection.fontDesc = new Atomic.UIFontDescription();
  64. fd.id = "Vera";
  65. fd.size = 11;
  66. })();
  67. }
  68. export = SelectionSection;