InspectorWidget.ts 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  1. //
  2. // Copyright (c) 2014-2016 THUNDERBEAST GAMES LLC
  3. //
  4. // Permission is hereby granted, free of charge, to any person obtaining a copy
  5. // of this software and associated documentation files (the "Software"), to deal
  6. // in the Software without restriction, including without limitation the rights
  7. // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  8. // copies of the Software, and to permit persons to whom the Software is
  9. // furnished to do so, subject to the following conditions:
  10. //
  11. // The above copyright notice and this permission notice shall be included in
  12. // all copies or substantial portions of the Software.
  13. //
  14. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  17. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  19. // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  20. // THE SOFTWARE.
  21. //
  22. import ScriptWidget = require("ui/ScriptWidget");
  23. import EditorUI = require("ui/EditorUI");
  24. class InspectorWidget extends ScriptWidget {
  25. constructor() {
  26. super();
  27. var fd = this.attrFontDesc = new Atomic.UIFontDescription();
  28. fd.id = "Vera";
  29. fd.size = 11;
  30. var nlp = new Atomic.UILayoutParams();
  31. nlp.width = 310;
  32. var layout = this.rootLayout = new Atomic.UILayout();
  33. layout.spacing = 4;
  34. layout.layoutDistribution = Atomic.UI_LAYOUT_DISTRIBUTION.UI_LAYOUT_DISTRIBUTION_GRAVITY;
  35. layout.layoutPosition = Atomic.UI_LAYOUT_POSITION.UI_LAYOUT_POSITION_LEFT_TOP;
  36. layout.layoutParams = nlp;
  37. layout.axis = Atomic.UI_AXIS.UI_AXIS_Y;
  38. this.gravity = Atomic.UI_GRAVITY.UI_GRAVITY_ALL;
  39. this.addChild(layout);
  40. this.subscribeToEvent(Atomic.UIWidgetEvent((data) => this.handleWidgetEvent(data)));
  41. }
  42. onApply() {
  43. console.log("Apply Pressed!");
  44. }
  45. createAttrName(name:string):Atomic.UITextField {
  46. var nameField = new Atomic.UITextField();
  47. nameField.textAlign = Atomic.UI_TEXT_ALIGN.UI_TEXT_ALIGN_LEFT;
  48. nameField.skinBg = "InspectorTextAttrName";
  49. nameField.text = name;
  50. nameField.fontDescription = this.attrFontDesc;
  51. return nameField;
  52. }
  53. createSection(parent:Atomic.UIWidget, text:string, expanded:number):Atomic.UILayout {
  54. var section = new Atomic.UISection();
  55. section.text = text;
  56. section.value = expanded;
  57. section.fontDescription = this.attrFontDesc;
  58. var layout = this.createVerticalAttrLayout();
  59. parent.addChild(section);
  60. section.contentRoot.addChild(layout);
  61. return layout;
  62. }
  63. createVerticalAttrLayout():Atomic.UILayout {
  64. var layout = new Atomic.UILayout(Atomic.UI_AXIS.UI_AXIS_Y);
  65. layout.spacing = 3;
  66. layout.layoutPosition = Atomic.UI_LAYOUT_POSITION.UI_LAYOUT_POSITION_LEFT_TOP;
  67. layout.layoutSize = Atomic.UI_LAYOUT_SIZE.UI_LAYOUT_SIZE_AVAILABLE;
  68. return layout;
  69. }
  70. createApplyButton():Atomic.UIButton {
  71. var button = new Atomic.UIButton();
  72. button.fontDescription = this.attrFontDesc;
  73. button.gravity = Atomic.UI_GRAVITY.UI_GRAVITY_RIGHT;
  74. button.text = "Apply";
  75. button.onClick = function() {
  76. this.onApply();
  77. }.bind(this);
  78. return button;
  79. }
  80. createAttrCheckBox(name:string, parent:Atomic.UIWidget):Atomic.UICheckBox {
  81. var attrLayout = new Atomic.UILayout();
  82. attrLayout.layoutDistribution = Atomic.UI_LAYOUT_DISTRIBUTION.UI_LAYOUT_DISTRIBUTION_GRAVITY;
  83. var _name = this.createAttrName(name);
  84. attrLayout.addChild(_name);
  85. var box = new Atomic.UICheckBox();
  86. box.skinBg = "TBCheckBox";
  87. attrLayout.addChild(box);
  88. parent.addChild(attrLayout);
  89. return box;
  90. }
  91. createAttrEditField(name:string, parent:Atomic.UIWidget):Atomic.UIEditField {
  92. var attrLayout = new Atomic.UILayout();
  93. attrLayout.layoutDistribution = Atomic.UI_LAYOUT_DISTRIBUTION.UI_LAYOUT_DISTRIBUTION_GRAVITY;
  94. var _name = this.createAttrName(name);
  95. attrLayout.addChild(_name);
  96. var edit = new Atomic.UIEditField();
  97. edit.textAlign = Atomic.UI_TEXT_ALIGN.UI_TEXT_ALIGN_LEFT;
  98. edit.skinBg = "TBAttrEditorField";
  99. edit.fontDescription = this.attrFontDesc;
  100. var lp = new Atomic.UILayoutParams();
  101. lp.width = 140;
  102. edit.layoutParams = lp;
  103. attrLayout.addChild(edit);
  104. parent.addChild(attrLayout);
  105. return edit;
  106. }
  107. handleWidgetEvent(ev: Atomic.UIWidgetEvent):boolean {
  108. return false;
  109. }
  110. createPreviewAnimationButton(asset: ToolCore.Asset): Atomic.UIButton {
  111. var button = new Atomic.UIButton();
  112. button.fontDescription = this.attrFontDesc;
  113. button.gravity = Atomic.UI_GRAVITY.UI_GRAVITY_RIGHT;
  114. button.text = "Preview Animation";
  115. button.onClick = function () {
  116. this.onPreviewAnimation(asset);
  117. // button is deleted in callback, so make sure we return
  118. // that we're handled
  119. return true;
  120. }.bind(this);
  121. return button;
  122. }
  123. onPreviewAnimation(asset: ToolCore.Asset) {
  124. var mainFrame = EditorUI.getMainFrame();
  125. mainFrame.showAnimationToolbar(asset);
  126. }
  127. rootLayout:Atomic.UILayout;
  128. attrFontDesc:Atomic.UIFontDescription;
  129. }
  130. export = InspectorWidget;