TextureInspector.ts 7.6 KB

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