TextureInspector.ts 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226
  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. import InspectorWidget = require("./InspectorWidget");
  25. import InspectorUtils = require("./InspectorUtils");
  26. import TextureSelector = require("./TextureSelector");
  27. class TextureInspector extends InspectorWidget {
  28. constructor() {
  29. super();
  30. this.fd.id = "Vera";
  31. this.fd.size = 11;
  32. }
  33. handleWidgetEvent(ev: Atomic.UIWidgetEvent): boolean {
  34. return false;
  35. }
  36. getTextureThumbnail(texture: Atomic.Texture2D): Atomic.Texture {
  37. if (!texture) return null;
  38. var db = ToolCore.getAssetDatabase();
  39. var asset = db.getAssetByPath(texture.name);
  40. if (!asset)
  41. return texture;
  42. var thumbnail = asset.cachePath + "_thumbnail.png";
  43. var cache = Atomic.getResourceCache();
  44. var thumb = <Atomic.Texture2D>cache.getTempResource("Texture2D", thumbnail);
  45. if (thumb)
  46. return thumb;
  47. return texture;
  48. }
  49. createTextureSection(): Atomic.UISection {
  50. var section = new Atomic.UISection();
  51. section.text = "Texture Image";
  52. section.value = 1;
  53. section.fontDescription = this.fd;
  54. var attrsVerticalLayout = new Atomic.UILayout(Atomic.UI_AXIS.UI_AXIS_Y);
  55. attrsVerticalLayout.spacing = 3;
  56. attrsVerticalLayout.layoutPosition = Atomic.UI_LAYOUT_POSITION.UI_LAYOUT_POSITION_CENTER;
  57. attrsVerticalLayout.layoutSize = Atomic.UI_LAYOUT_SIZE.UI_LAYOUT_SIZE_AVAILABLE;
  58. section.contentRoot.addChild(attrsVerticalLayout);
  59. var attrLayout = new Atomic.UILayout();
  60. attrLayout.layoutDistribution = Atomic.UI_LAYOUT_DISTRIBUTION.UI_LAYOUT_DISTRIBUTION_PREFERRED;
  61. var textureWidget = new Atomic.UITextureWidget();
  62. var tlp = new Atomic.UILayoutParams();
  63. tlp.width = 200;
  64. tlp.height = 200;
  65. textureWidget.layoutParams = tlp;
  66. textureWidget.texture = this.getTextureThumbnail(this.texture);
  67. var textureButton = new Atomic.UIButton();
  68. textureButton.skinBg = "TBButton.flatoutline";
  69. textureButton["textureWidget"] = textureWidget;
  70. textureButton.contentRoot.addChild(textureWidget);
  71. attrLayout.addChild(textureButton);
  72. attrsVerticalLayout.addChild(attrLayout);
  73. return section;
  74. }
  75. inspect(texture: Atomic.Texture2D, asset: ToolCore.Asset) {
  76. this.texture = texture;
  77. this.asset = asset;
  78. this.importer = <ToolCore.TextureImporter>asset.importer;
  79. var mlp = new Atomic.UILayoutParams();
  80. mlp.width = 310;
  81. var textureLayout = new Atomic.UILayout();
  82. textureLayout.spacing = 4;
  83. textureLayout.layoutDistribution = Atomic.UI_LAYOUT_DISTRIBUTION.UI_LAYOUT_DISTRIBUTION_GRAVITY;
  84. textureLayout.layoutPosition = Atomic.UI_LAYOUT_POSITION.UI_LAYOUT_POSITION_LEFT_TOP;
  85. textureLayout.layoutParams = mlp;
  86. textureLayout.axis = Atomic.UI_AXIS.UI_AXIS_Y;
  87. var textureSection = new Atomic.UISection();
  88. textureSection.text = "Texture";
  89. textureSection.value = 1;
  90. textureSection.fontDescription = this.fd;
  91. textureLayout.addChild(textureSection);
  92. var attrsVerticalLayout = new Atomic.UILayout(Atomic.UI_AXIS.UI_AXIS_Y);
  93. attrsVerticalLayout.spacing = 3;
  94. attrsVerticalLayout.layoutPosition = Atomic.UI_LAYOUT_POSITION.UI_LAYOUT_POSITION_LEFT_TOP;
  95. attrsVerticalLayout.layoutSize = Atomic.UI_LAYOUT_SIZE.UI_LAYOUT_SIZE_PREFERRED;
  96. // NAME
  97. var nameLayout = new Atomic.UILayout();
  98. nameLayout.layoutDistribution = Atomic.UI_LAYOUT_DISTRIBUTION.UI_LAYOUT_DISTRIBUTION_GRAVITY;
  99. var name = new Atomic.UITextField();
  100. name.textAlign = Atomic.UI_TEXT_ALIGN.UI_TEXT_ALIGN_LEFT;
  101. name.skinBg = "InspectorTextAttrName";
  102. name.text = "Name";
  103. name.fontDescription = this.fd;
  104. nameLayout.addChild(name);
  105. var field = new Atomic.UIEditField();
  106. field.textAlign = Atomic.UI_TEXT_ALIGN.UI_TEXT_ALIGN_LEFT;
  107. field.skinBg = "TBAttrEditorField";
  108. field.fontDescription = this.fd;
  109. var lp = new Atomic.UILayoutParams();
  110. lp.width = 160;
  111. field.layoutParams = lp;
  112. field.text = Atomic.splitPath(asset.name).fileName;
  113. nameLayout.addChild(field);
  114. attrsVerticalLayout.addChild(nameLayout);
  115. var maxSizeLayout = new Atomic.UILayout();
  116. maxSizeLayout.layoutDistribution = Atomic.UI_LAYOUT_DISTRIBUTION.UI_LAYOUT_DISTRIBUTION_GRAVITY;
  117. //COMPRESSION SIZE
  118. var maxSize = InspectorUtils.createAttrName("Max Size");
  119. this.populateCompressionSizeList();
  120. maxSizeLayout.addChild(maxSize);
  121. maxSizeLayout.addChild(this.compressionSize);
  122. attrsVerticalLayout.addChild(maxSizeLayout);
  123. attrsVerticalLayout.addChild(this.createApplyButton());
  124. textureSection.contentRoot.addChild(attrsVerticalLayout);
  125. textureLayout.addChild(this.createTextureSection());
  126. this.addChild(textureLayout);
  127. }
  128. onApply() {
  129. this.importer.setCompressedImageSize(Number(this.compressionSize.text));
  130. this.asset.import();
  131. this.asset.save();
  132. }
  133. populateCompressionSizeList() {
  134. this.compressionSize = new Atomic.UISelectDropdown();
  135. this.compressionSizeSource = new Atomic.UISelectItemSource();
  136. for (var i = 0; i < this.compressionSizes.length; i ++) {
  137. var size = new Atomic.UISelectItem();
  138. size.setString(this.compressionSizes[i].toString());
  139. this.compressionSizeSource.addItem(size);
  140. }
  141. this.compressionSize.setSource(this.compressionSizeSource);
  142. if (this.importer.getCompressedImageSize() != 0) {
  143. this.compressionSize.setText(this.importer.getCompressedImageSize().toString());
  144. }
  145. else {
  146. this.compressionSize.setText("NONE");
  147. }
  148. }
  149. texture: Atomic.Texture2D;
  150. techniqueButton: Atomic.UIButton;
  151. material: Atomic.Material;
  152. asset: ToolCore.Asset;
  153. nameTextField: Atomic.UITextField;
  154. compressionSize: Atomic.UISelectDropdown;
  155. compressionSizeSource: Atomic.UISelectItemSource;
  156. fd: Atomic.UIFontDescription = new Atomic.UIFontDescription();
  157. importer: ToolCore.TextureImporter;
  158. compressionSizes: number[] = [32, 64, 128, 256, 512, 1024, 2048, 4096, 8192];
  159. }
  160. export = TextureInspector;