Browse Source

Material editor improvements

Josh Engebretson 10 years ago
parent
commit
3abb154ebe

+ 5 - 0
Resources/EditorData/AtomicEditor/resources/default_skin/skin.tb.txt

@@ -73,6 +73,11 @@ elements
 		clone TBButton
 		text-color #D4FB79
 
+	TBButton.flatoutline
+		clone TBButton.flat
+		bitmap button_flat_outline.png
+		cut 15
+		expand 6	
 
 	# == TBButtonInGroup is not a widget. It's only used as override for TBButton under a "button_group" ====
 	TBButtonInGroup

+ 35 - 18
Script/AtomicEditor/ui/inspector/MaterialInspector.ts

@@ -1,6 +1,7 @@
 
 import ScriptWidget = require("../ScriptWidget");
 import UIEvents = require("../UIEvents");
+import EditorUI = require("../EditorUI");
 
 import TextureSelector = require("./TextureSelector");
 
@@ -219,6 +220,29 @@ class MaterialInspector extends ScriptWidget {
 
     }
 
+    createTextureButtonCallback(textureUnit:number, textureWidget:Atomic.UITextureWidget) {
+
+      return  () => {
+
+        var inspector = this;
+
+        EditorUI.getModelOps().showResourceSelection("Select Texture", "TextureImporter", function(asset: ToolCore.Asset, args: any) {
+
+            var texture = <Atomic.Texture2D> Atomic.cache.getResource("Texture2D", asset.path);
+
+            if (texture) {
+                inspector.material.setTexture(textureUnit, texture);
+                textureWidget.texture = inspector.getTextureThumbnail(texture);
+            }
+
+        });
+
+        return true;
+
+      }
+
+    }
+
 
     createTextureSection(): Atomic.UISection {
 
@@ -257,34 +281,28 @@ class MaterialInspector extends ScriptWidget {
             attrLayout.addChild(name);
 
             var textureWidget = new Atomic.UITextureWidget();
-            textureWidget.texture = this.getTextureThumbnail(this.material.getTexture(tunit));
 
             var tlp = new Atomic.UILayoutParams();
             tlp.width = 64;
             tlp.height = 64;
             textureWidget.layoutParams = tlp;
-            textureWidget["tunit"] = tunit;
-
-            attrLayout.addChild(textureWidget);
-
-            attrsVerticalLayout.addChild(attrLayout);
+            textureWidget.texture = this.getTextureThumbnail(this.material.getTexture(tunit));
 
-            var editInfo: { textureUnit: Atomic.TextureUnit } = { textureUnit: tunit };
+            var textureButton = new Atomic.UIButton();
+            textureButton.skinBg = "TBButton.flatoutline";
+            textureButton["tunit"] = tunit;
+            textureButton["textureWidget"] = textureWidget;
 
-            var callback = function(ev: Atomic.UIWidgetEvent) {
+            textureButton.onClick = this.createTextureButtonCallback(tunit, textureWidget);
 
-                if (ev.type == Atomic.UI_EVENT_TYPE_CLICK) {
-                    var tselect = new TextureSelector(ev.target.view);
-                }
+            textureButton.contentRoot.addChild(textureWidget);
 
-            }.bind(editInfo);
+            attrLayout.addChild(textureButton);
 
-            textureWidget.subscribeToEvent(textureWidget, "WidgetEvent", callback);
+            attrsVerticalLayout.addChild(attrLayout);
 
             // handle dropping of texture on widget
-            textureWidget.subscribeToEvent(textureWidget, "DragEnded", (ev: Atomic.DragEndedEvent) => {
-
-                var tunit2 = tunit;
+            textureButton.subscribeToEvent(textureButton, "DragEnded", (ev: Atomic.DragEndedEvent) => {
 
                 var importer = this.acceptAssetDrag("TextureImporter", ev);
 
@@ -298,13 +316,12 @@ class MaterialInspector extends ScriptWidget {
                     if (texture) {
 
                         this.material.setTexture(ev.target["tunit"], texture);
-                        (<Atomic.UITextureWidget>ev.target).texture = this.getTextureThumbnail(texture);
+                        (<Atomic.UITextureWidget>ev.target["textureWidget"]).texture = this.getTextureThumbnail(texture);
 
                     }
                 }
             });
 
-
         }
 
         return section;

+ 2 - 2
Script/AtomicEditor/ui/modal/ModalOps.ts

@@ -71,11 +71,11 @@ class ModalOps extends Atomic.ScriptObject {
 
     }
 
-    showResourceSelection(windowText:string, importerType:string, callback: (asset: ToolCore.Asset) => any) {
+    showResourceSelection(windowText:string, importerType:string, callback: (asset: ToolCore.Asset, args:any) => void, args:any = undefined) {
 
       if (this.show()) {
 
-          this.opWindow = new ResourceSelection(windowText, importerType, callback);
+          this.opWindow = new ResourceSelection(windowText, importerType, callback, args);
 
       }
 

+ 5 - 3
Script/AtomicEditor/ui/modal/ResourceSelection.ts

@@ -6,7 +6,8 @@ import ModalWindow = require("./ModalWindow");
 class ResourceSelection extends ModalWindow {
 
     folderList: Atomic.UIListView;
-    callback: (asset: ToolCore.Asset) => any;
+    callback: (asset: ToolCore.Asset, args:any) => void;
+    args:any;
 
     populate(importerType: string) {
 
@@ -28,11 +29,12 @@ class ResourceSelection extends ModalWindow {
 
     }
 
-    constructor(windowText: string, importerType: string, callback: (asset: ToolCore.Asset) => any) {
+    constructor(windowText: string, importerType: string, callback: (asset: ToolCore.Asset, args:any) => void, args:any) {
 
         super();
 
         this.callback = callback;
+        this.args = args;
 
         this.load("AtomicEditor/editor/ui/resourceselection.tb.txt");
 
@@ -64,7 +66,7 @@ class ResourceSelection extends ModalWindow {
 
                 if (id.length) {
 
-                  this.callback(ToolCore.assetDatabase.getAssetByGUID(id));
+                  this.callback(ToolCore.assetDatabase.getAssetByGUID(id), this.args);
 
                 }