Browse Source

Merge pull request #811 from LumaDigital/TextureInspector

Created a texture inspector for Atomic.
JoshEngebretson 9 years ago
parent
commit
e448c63985

+ 17 - 0
Script/AtomicEditor/ui/frames/inspector/InspectorFrame.ts

@@ -29,6 +29,7 @@ import MaterialInspector = require("./MaterialInspector");
 import ModelInspector = require("./ModelInspector");
 import AssemblyInspector = require("./AssemblyInspector");
 import PrefabInspector = require("./PrefabInspector");
+import TextureInspector = require("./TextureInspector");
 
 import SelectionInspector = require("./SelectionInspector");
 // make sure these are hooked in
@@ -213,6 +214,22 @@ class InspectorFrame extends ScriptWidget {
             prefabInspector.inspect(asset);
         }
 
+        if (asset.importerTypeName == "TextureImporter") {
+
+            var thumbnail = asset.cachePath + "_thumbnail.png";
+            var cache = Atomic.getResourceCache();
+            var texture = <Atomic.Texture2D>cache.getResource("Texture2D", thumbnail);
+
+            if (!texture) {
+                return;
+            }
+
+            var textureInspector = new TextureInspector();
+            container.addChild(textureInspector);
+
+            textureInspector.inspect(texture, asset);
+        }
+
     }
 
 }

+ 174 - 0
Script/AtomicEditor/ui/frames/inspector/TextureInspector.ts

@@ -0,0 +1,174 @@
+//
+// Copyright (c) 2014-2016 THUNDERBEAST GAMES LLC
+//
+// Permission is hereby granted, free of charge, to any person obtaining a copy
+// of this software and associated documentation files (the "Software"), to deal
+// in the Software without restriction, including without limitation the rights
+// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+// copies of the Software, and to permit persons to whom the Software is
+// furnished to do so, subject to the following conditions:
+//
+// The above copyright notice and this permission notice shall be included in
+// all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+// THE SOFTWARE.
+//
+
+import ScriptWidget = require("ui/ScriptWidget");
+import UIEvents = require("ui/UIEvents");
+import EditorUI = require("ui/EditorUI");
+import EditorEvents = require("editor/EditorEvents");
+
+import TextureSelector = require("./TextureSelector");
+
+class TextureInspector extends ScriptWidget {
+
+    constructor() {
+
+        super();
+
+        this.fd.id = "Vera";
+        this.fd.size = 11;
+
+    }
+
+    getTextureThumbnail(texture: Atomic.Texture2D): Atomic.Texture {
+
+        if (!texture) return null;
+
+        var db = ToolCore.getAssetDatabase();
+        var asset = db.getAssetByPath(texture.name);
+
+        if (!asset)
+            return texture;
+
+        var thumbnail = asset.cachePath + "_thumbnail.png";
+        var cache = Atomic.getResourceCache();
+
+        var thumb = <Atomic.Texture2D>cache.getTempResource("Texture2D", thumbnail);
+
+        if (thumb)
+            return thumb;
+
+        return texture;
+
+    }
+
+    createTextureSection(): Atomic.UISection {
+
+        var section = new Atomic.UISection();
+        section.text = "Texture Image";
+        section.value = 1;
+        section.fontDescription = this.fd;
+
+        var attrsVerticalLayout = new Atomic.UILayout(Atomic.UI_AXIS_Y);
+        attrsVerticalLayout.spacing = 3;
+        attrsVerticalLayout.layoutPosition = Atomic.UI_LAYOUT_POSITION_CENTER;
+        attrsVerticalLayout.layoutSize = Atomic.UI_LAYOUT_SIZE_AVAILABLE;
+
+        section.contentRoot.addChild(attrsVerticalLayout);
+
+        var attrLayout = new Atomic.UILayout();
+        attrLayout.layoutDistribution = Atomic.UI_LAYOUT_POSITION_CENTER;
+
+        var textureWidget = new Atomic.UITextureWidget();
+
+        var tlp = new Atomic.UILayoutParams();
+        tlp.width = 200;
+        tlp.height = 200;
+        textureWidget.layoutParams = tlp;
+        textureWidget.texture = this.getTextureThumbnail(this.texture);
+
+        var textureButton = new Atomic.UIButton();
+        textureButton.skinBg = "TBButton.flatoutline";
+        textureButton["textureWidget"] = textureWidget;
+
+        textureButton.contentRoot.addChild(textureWidget);
+
+        attrLayout.addChild(textureButton);
+
+        attrsVerticalLayout.addChild(attrLayout);
+
+        return section;
+
+    }
+
+    inspect(texture: Atomic.Texture2D, asset: ToolCore.Asset) {
+
+        this.texture = texture;
+        this.asset = asset;
+
+        var mlp = new Atomic.UILayoutParams();
+        mlp.width = 310;
+
+        var textureLayout = new Atomic.UILayout();
+        textureLayout.spacing = 4;
+
+        textureLayout.layoutDistribution = Atomic.UI_LAYOUT_DISTRIBUTION_GRAVITY;
+        textureLayout.layoutPosition = Atomic.UI_LAYOUT_POSITION_LEFT_TOP;
+        textureLayout.layoutParams = mlp;
+        textureLayout.axis = Atomic.UI_AXIS_Y;
+
+        var textureSection = new Atomic.UISection();
+        textureSection.text = "Texture";
+        textureSection.value = 1;
+        textureSection.fontDescription = this.fd;
+        textureLayout.addChild(textureSection);
+
+        var attrsVerticalLayout = new Atomic.UILayout(Atomic.UI_AXIS_Y);
+        attrsVerticalLayout.spacing = 3;
+        attrsVerticalLayout.layoutPosition = Atomic.UI_LAYOUT_POSITION_LEFT_TOP;
+        attrsVerticalLayout.layoutSize = Atomic.UI_LAYOUT_SIZE_PREFERRED;
+
+        // NAME
+        var nameLayout = new Atomic.UILayout();
+        nameLayout.layoutDistribution = Atomic.UI_LAYOUT_DISTRIBUTION_GRAVITY;
+
+        var name = new Atomic.UITextField();
+        name.textAlign = Atomic.UI_TEXT_ALIGN_LEFT;
+        name.skinBg = "InspectorTextAttrName";
+
+        name.text = "Name";
+        name.fontDescription = this.fd;
+
+        nameLayout.addChild(name);
+
+        var field = new Atomic.UIEditField();
+        field.textAlign = Atomic.UI_TEXT_ALIGN_LEFT;
+        field.skinBg = "TBAttrEditorField";
+        field.fontDescription = this.fd;
+        var lp = new Atomic.UILayoutParams();
+        lp.width = 160;
+        field.layoutParams = lp;
+
+        field.text = Atomic.splitPath(asset.name).fileName;
+
+        nameLayout.addChild(field);
+
+        attrsVerticalLayout.addChild(nameLayout);
+
+        textureSection.contentRoot.addChild(attrsVerticalLayout);
+
+        textureLayout.addChild(this.createTextureSection());
+
+        this.addChild(textureLayout);
+
+    }
+
+    texture: Atomic.Texture2D;
+
+    techniqueButton: Atomic.UIButton;
+    material: Atomic.Material;
+    asset: ToolCore.Asset;
+    nameTextField: Atomic.UITextField;
+    fd: Atomic.UIFontDescription = new Atomic.UIFontDescription();
+
+}
+
+export = TextureInspector;

+ 1 - 0
Script/tsconfig.json

@@ -47,6 +47,7 @@
         "./AtomicEditor/ui/frames/inspector/InspectorUtils.ts",
         "./AtomicEditor/ui/frames/inspector/InspectorWidget.ts",
         "./AtomicEditor/ui/frames/inspector/MaterialInspector.ts",
+        "./AtomicEditor/ui/frames/inspector/TextureInspector.ts",
         "./AtomicEditor/ui/frames/inspector/ModelInspector.ts",
         "./AtomicEditor/ui/frames/inspector/PrefabInspector.ts",
         "./AtomicEditor/ui/frames/inspector/SelectionEditTypes.ts",