TextureInspector.ts 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  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 TextureSelector = require("./TextureSelector");
  27. class TextureInspector extends ScriptWidget {
  28. constructor() {
  29. super();
  30. this.fd.id = "Vera";
  31. this.fd.size = 11;
  32. }
  33. getTextureThumbnail(texture: Atomic.Texture2D): Atomic.Texture {
  34. if (!texture) return null;
  35. var db = ToolCore.getAssetDatabase();
  36. var asset = db.getAssetByPath(texture.name);
  37. if (!asset)
  38. return texture;
  39. var thumbnail = asset.cachePath + "_thumbnail.png";
  40. var cache = Atomic.getResourceCache();
  41. var thumb = <Atomic.Texture2D>cache.getTempResource("Texture2D", thumbnail);
  42. if (thumb)
  43. return thumb;
  44. return texture;
  45. }
  46. createTextureSection(): Atomic.UISection {
  47. var section = new Atomic.UISection();
  48. section.text = "Texture Image";
  49. section.value = 1;
  50. section.fontDescription = this.fd;
  51. var attrsVerticalLayout = new Atomic.UILayout(Atomic.UI_AXIS_Y);
  52. attrsVerticalLayout.spacing = 3;
  53. attrsVerticalLayout.layoutPosition = Atomic.UI_LAYOUT_POSITION_CENTER;
  54. attrsVerticalLayout.layoutSize = Atomic.UI_LAYOUT_SIZE_AVAILABLE;
  55. section.contentRoot.addChild(attrsVerticalLayout);
  56. var attrLayout = new Atomic.UILayout();
  57. attrLayout.layoutDistribution = Atomic.UI_LAYOUT_POSITION_CENTER;
  58. var textureWidget = new Atomic.UITextureWidget();
  59. var tlp = new Atomic.UILayoutParams();
  60. tlp.width = 200;
  61. tlp.height = 200;
  62. textureWidget.layoutParams = tlp;
  63. textureWidget.texture = this.getTextureThumbnail(this.texture);
  64. var textureButton = new Atomic.UIButton();
  65. textureButton.skinBg = "TBButton.flatoutline";
  66. textureButton["textureWidget"] = textureWidget;
  67. textureButton.contentRoot.addChild(textureWidget);
  68. attrLayout.addChild(textureButton);
  69. attrsVerticalLayout.addChild(attrLayout);
  70. return section;
  71. }
  72. inspect(texture: Atomic.Texture2D, asset: ToolCore.Asset) {
  73. this.texture = texture;
  74. this.asset = asset;
  75. var mlp = new Atomic.UILayoutParams();
  76. mlp.width = 310;
  77. var textureLayout = new Atomic.UILayout();
  78. textureLayout.spacing = 4;
  79. textureLayout.layoutDistribution = Atomic.UI_LAYOUT_DISTRIBUTION_GRAVITY;
  80. textureLayout.layoutPosition = Atomic.UI_LAYOUT_POSITION_LEFT_TOP;
  81. textureLayout.layoutParams = mlp;
  82. textureLayout.axis = Atomic.UI_AXIS_Y;
  83. var textureSection = new Atomic.UISection();
  84. textureSection.text = "Texture";
  85. textureSection.value = 1;
  86. textureSection.fontDescription = this.fd;
  87. textureLayout.addChild(textureSection);
  88. var attrsVerticalLayout = new Atomic.UILayout(Atomic.UI_AXIS_Y);
  89. attrsVerticalLayout.spacing = 3;
  90. attrsVerticalLayout.layoutPosition = Atomic.UI_LAYOUT_POSITION_LEFT_TOP;
  91. attrsVerticalLayout.layoutSize = Atomic.UI_LAYOUT_SIZE_PREFERRED;
  92. // NAME
  93. var nameLayout = new Atomic.UILayout();
  94. nameLayout.layoutDistribution = Atomic.UI_LAYOUT_DISTRIBUTION_GRAVITY;
  95. var name = new Atomic.UITextField();
  96. name.textAlign = Atomic.UI_TEXT_ALIGN_LEFT;
  97. name.skinBg = "InspectorTextAttrName";
  98. name.text = "Name";
  99. name.fontDescription = this.fd;
  100. nameLayout.addChild(name);
  101. var field = new Atomic.UIEditField();
  102. field.textAlign = Atomic.UI_TEXT_ALIGN_LEFT;
  103. field.skinBg = "TBAttrEditorField";
  104. field.fontDescription = this.fd;
  105. var lp = new Atomic.UILayoutParams();
  106. lp.width = 160;
  107. field.layoutParams = lp;
  108. field.text = Atomic.splitPath(asset.name).fileName;
  109. nameLayout.addChild(field);
  110. attrsVerticalLayout.addChild(nameLayout);
  111. textureSection.contentRoot.addChild(attrsVerticalLayout);
  112. textureLayout.addChild(this.createTextureSection());
  113. this.addChild(textureLayout);
  114. }
  115. texture: Atomic.Texture2D;
  116. techniqueButton: Atomic.UIButton;
  117. material: Atomic.Material;
  118. asset: ToolCore.Asset;
  119. nameTextField: Atomic.UITextField;
  120. fd: Atomic.UIFontDescription = new Atomic.UIFontDescription();
  121. }
  122. export = TextureInspector;