Browse Source

Issue #660

Added an option called "None" to the Resource Selection Dialog Box:
     This dereferences and removes the component.
     Works for Materials and Textures.
JohnnyWahib 9 years ago
parent
commit
1f61d62995

+ 5 - 0
Script/AtomicEditor/editor/EditorEvents.ts

@@ -99,3 +99,8 @@ export interface InspectorProjectReferenceEvent {
 
 }
 
+export const RemoveCurrentAssetAssigned = "RemoveCurrentAssetAssigned";
+export interface RemoveCurrentAssetAssignedEvent {
+
+}
+

+ 41 - 19
Script/AtomicEditor/ui/frames/inspector/ComponentAttributeUI.ts

@@ -123,12 +123,46 @@ class SubmeshAttributeEdit extends AttributeInfoEdit {
     enabledCheckBox: Atomic.UICheckBox;
     nameField: Atomic.UITextField;
     name: string;
+    matIndex: number;
 
     constructor(name: string) {
 
         super();
         this.name = name;
         this.hideName = true;
+
+        this.subscribeToEvent(EditorEvents.RemoveCurrentAssetAssigned, (ev: EditorEvents.RemoveCurrentAssetAssignedEvent) => {
+
+            this.editType.onAttributeInfoEdited(this.attrInfo, null, this.matIndex);
+            this.refresh();
+        });
+
+
+    }
+
+    openResourceSelectionBox(materialIndex: number, resourceTypeName: string, importerName: string) {
+
+        this.matIndex = materialIndex;
+
+        EditorUI.getModelOps().showResourceSelection("Select " + resourceTypeName + " Resource", importerName, resourceTypeName, function (retObject: any) {
+
+            var resource: Atomic.Resource = null;
+
+            if (retObject instanceof ToolCore.Asset) {
+
+                resource = (<ToolCore.Asset>retObject).getResource(resourceTypeName);
+
+            } else if (retObject instanceof Atomic.Resource) {
+
+                resource = <Atomic.Resource>retObject;
+
+            }
+
+            this.editType.onAttributeInfoEdited(this.attrInfo, resource, materialIndex);
+            this.refresh();
+
+        }.bind(this));
+
     }
 
     createMaterialEdit(materialIndex: number) {
@@ -149,26 +183,11 @@ class SubmeshAttributeEdit extends AttributeInfoEdit {
         var resourceTypeName = "Material";
         var importerName = ToolCore.assetDatabase.getResourceImporterName(resourceTypeName);
 
-        selectButton.onClick = () => {
-
-            EditorUI.getModelOps().showResourceSelection("Select " + resourceTypeName + " Resource", importerName, resourceTypeName, function(retObject: any) {
-
-                var resource: Atomic.Resource = null;
-
-                if (retObject instanceof ToolCore.Asset) {
 
-                    resource = (<ToolCore.Asset>retObject).getResource(resourceTypeName);
-
-                } else if (retObject instanceof Atomic.Resource) {
-
-                    resource = <Atomic.Resource>retObject;
-
-                }
+        selectButton.onClick = () => {
 
-                this.editType.onAttributeInfoEdited(this.attrInfo, resource, materialIndex);
-                this.refresh();
+            this.openResourceSelectionBox(materialIndex, resourceTypeName, importerName);
 
-            }.bind(this));
         };
 
         // handle dropping of component on field
@@ -203,12 +222,15 @@ class SubmeshAttributeEdit extends AttributeInfoEdit {
 
         o.editField.subscribeToEvent(o.editField, "UIWidgetFocusChanged", (ev: Atomic.UIWidgetFocusChangedEvent) => {
 
-            if (ev.widget == o.editField && o.editField.focus) {
+            if (ev.widget == o.editField && o.editField.focus && o.editField.text != "") {
 
                 var pathName = materialEdit.pathReference;
                 this.sendEvent(EditorEvents.InspectorProjectReference, { "path": pathName });
 
-             }
+            } else if (o.editField.text == "") {
+
+                this.openResourceSelectionBox(materialIndex, resourceTypeName, importerName);
+            }
 
         });
     }

+ 19 - 2
Script/AtomicEditor/ui/frames/inspector/MaterialInspector.ts

@@ -74,6 +74,10 @@ for (var key in techniqueLookup) {
 
 class MaterialInspector extends ScriptWidget {
 
+    currentTexture: Atomic.UITextureWidget = null;
+    tunit: number;
+    textureWidget: Atomic.UITextureWidget 
+
     constructor() {
 
         super();
@@ -81,7 +85,7 @@ class MaterialInspector extends ScriptWidget {
         this.fd.id = "Vera";
         this.fd.size = 11;
 
-
+        this.subscribeToEvent(EditorEvents.RemoveCurrentAssetAssigned, (ev: EditorEvents.RemoveCurrentAssetAssignedEvent) => this.createTextureRemoveButtonCallback(this.tunit, this.textureWidget));
     }
 
     createShaderParametersSection(): Atomic.UISection {
@@ -265,7 +269,7 @@ class MaterialInspector extends ScriptWidget {
 
             var texture = this.material.getTexture(textureUnit);
 
-            if (texture != null) {
+            if (textureWidget.getTexture() != null) {
                 this.sendEvent(EditorEvents.InspectorProjectReference, { "path": texture.getName() });
             } else {
                 this.openTextureSelectionBox(textureUnit, textureWidget);
@@ -281,11 +285,24 @@ class MaterialInspector extends ScriptWidget {
     createTextureReferenceButtonCallback(textureUnit: number, textureWidget: Atomic.UITextureWidget) {
 
         return () => {
+            this.tunit = textureUnit;
+            this.textureWidget = textureWidget;
             this.openTextureSelectionBox(textureUnit, textureWidget);
             return true;
         };
     }
 
+    //Remove Texture Button
+    createTextureRemoveButtonCallback(textureUnit: number, textureWidget: Atomic.UITextureWidget) {
+
+            var texture = this.material.getTexture(textureUnit);
+
+            if (texture != null && textureWidget != null) {
+                textureWidget.setTexture(null);
+            }
+
+    }
+
     createTextureSection(): Atomic.UISection {
 
         var section = new Atomic.UISection();

+ 8 - 0
Script/AtomicEditor/ui/modal/ResourceSelection.ts

@@ -21,6 +21,8 @@ class ResourceSelection extends ModalWindow {
         var db = ToolCore.assetDatabase;
         var assets = db.getAssetsByImporterType(importerType, resourceType);
 
+        this.folderList.addRootItem("None", "", "");
+
         for (var i in assets) {
 
             var asset = assets[i];
@@ -116,6 +118,12 @@ class ResourceSelection extends ModalWindow {
 
         var id = this.folderList.selectedItemID;
 
+        if (id == "") {
+            this.sendEvent(EditorEvents.RemoveCurrentAssetAssigned);
+            this.hide();
+            return true;
+        }
+
         if (this.resourceType == "Animation") {
 
           if (id.length) {