Browse Source

Merge pull request #664 from JohnnyWahib/AtomicFileReference

Atomic file reference
LaraEngebretson 9 years ago
parent
commit
e5a0b49d69

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

@@ -90,3 +90,17 @@ export interface SceneEditStateChangeEvent {
   serializable: Atomic.Serializable;
 
 }
+
+export const InspectorProjectReference = "InspectorProjectReference";
+export interface InspectorProjectReferenceEvent {
+
+    // The full path to the resource to edit
+    path: string;
+
+}
+
+export const RemoveCurrentAssetAssigned = "RemoveCurrentAssetAssigned";
+export interface RemoveCurrentAssetAssignedEvent {
+
+}
+

+ 43 - 3
Script/AtomicEditor/ui/frames/ProjectFrame.ts

@@ -19,6 +19,10 @@ class ProjectFrame extends ScriptWidget {
     resourceFolder: ToolCore.Asset;
     assetGUIDToItemID = {};
     resourcesID: number = -1;
+    assetReferencePath: string = null;
+    currentReferencedButton: Atomic.UIButton = null;
+    containerScrollToHeight: number;
+    containerScrollToHeightCounter: number;
 
     constructor(parent: Atomic.UIWidget) {
 
@@ -50,6 +54,7 @@ class ProjectFrame extends ScriptWidget {
         this.subscribeToEvent("ResourceAdded", (ev: ToolCore.ResourceAddedEvent) => this.handleResourceAdded(ev));
         this.subscribeToEvent("ResourceRemoved", (ev: ToolCore.ResourceRemovedEvent) => this.handleResourceRemoved(ev));
         this.subscribeToEvent("AssetRenamed", (ev: ToolCore.AssetRenamedEvent) => this.handleAssetRenamed(ev));
+        this.subscribeToEvent(EditorEvents.InspectorProjectReference, (ev: EditorEvents.InspectorProjectReferenceEvent) => { this.handleInspectorProjectReferenceHighlight(ev.path) });
 
         folderList.subscribeToEvent("UIListViewSelectionChanged", (event: Atomic.UIListViewSelectionChangedEvent) => this.handleFolderListSelectionChangedEvent(event));
 
@@ -213,13 +218,17 @@ class ProjectFrame extends ScriptWidget {
                     } else {
 
                         this.sendEvent(EditorEvents.EditResource, { "path": asset.path });
-
                     }
 
                 }
 
             }
 
+            if (this.currentReferencedButton) {
+                this.currentReferencedButton.setState(4, false);
+                this.currentReferencedButton = null;
+            }
+
         }
 
         return false;
@@ -382,6 +391,18 @@ class ProjectFrame extends ScriptWidget {
 
     }
 
+    // Shows referenced file in projectframe
+    handleInspectorProjectReferenceHighlight(path: string): void {
+        this.assetReferencePath = path;
+        var db = ToolCore.getAssetDatabase();
+        var asset = db.getAssetByPath(this.resourceFolder.getPath() + "/" + path);
+
+        this.folderList.selectAllItems(false);
+        this.folderList.selectItemByID(asset.parent.guid, true);
+        this.refreshContent(asset.parent);
+        this.folderList.scrollToSelectedItem();
+    }
+
     private refreshContent(folder: ToolCore.Asset) {
 
         if (this.currentFolder != folder) {
@@ -399,12 +420,17 @@ class ProjectFrame extends ScriptWidget {
 
         var assets = db.getFolderAssets(folder.path);
 
+        this.containerScrollToHeightCounter = 0;
+
         for (var i in assets) {
 
             var asset = assets[i];
-
             container.addChild(this.createButtonLayout(asset));
+            this.containerScrollToHeightCounter++;
         }
+       
+        var containerScroll: Atomic.UIScrollContainer = <Atomic.UIScrollContainer>this.getWidget("contentcontainerscroll");
+        containerScroll.scrollTo(0, this.containerScrollToHeight);
 
     }
 
@@ -442,11 +468,25 @@ class ProjectFrame extends ScriptWidget {
 
         var button = new Atomic.UIButton();
 
+
+
         // setup the drag object
         button.dragObject = new Atomic.UIDragObject(asset, asset.name);
 
         var lp = new Atomic.UILayoutParams;
-        lp.height = 20;
+        var buttonHeight = lp.height = 20;
+        
+        //Get the path of the button and compare it to the asset's path to highlight 
+        var resourcePath = this.resourceFolder.getPath() + "/" + this.assetReferencePath;
+
+        //Highlight Button UI
+        if (resourcePath == asset.path) {
+
+            button.setState(4, true);
+            this.currentReferencedButton = button;
+            this.containerScrollToHeight = this.containerScrollToHeightCounter * buttonHeight;
+
+        }
 
         var fd = new Atomic.UIFontDescription();
         fd.id = "Vera";

+ 32 - 0
Script/AtomicEditor/ui/frames/inspector/AttributeInfoEdit.ts

@@ -8,6 +8,7 @@
 import EditorUI = require("ui/EditorUI");
 import InspectorUtils = require("./InspectorUtils");
 import SerializableEditType = require("./SerializableEditType");
+import EditorEvents = require("editor/EditorEvents");
 
 class AttributeInfoEdit extends Atomic.UILayout {
 
@@ -700,6 +701,37 @@ class ResourceRefAttributeEdit extends AttributeInfoEdit {
                     }
                 }
                 this.editField.text = text;
+
+                this.editField.subscribeToEvent(this.editField, "WidgetEvent", (ev: Atomic.UIWidgetEvent) => {
+
+                    if (ev.type == Atomic.UI_EVENT_TYPE_POINTER_DOWN) {
+
+                        resource = <Atomic.Resource>object.getAttribute(this.attrInfo.name);
+
+                        if (resource instanceof Atomic.JSComponentFile) {
+
+                            var pathName = resource.name;
+                            this.sendEvent(EditorEvents.InspectorProjectReference, { "path": pathName });
+
+                        } else if (resource instanceof Atomic.Model) {
+
+                            var asset = ToolCore.assetDatabase.getAssetByCachePath(resource.name);
+                            this.sendEvent(EditorEvents.InspectorProjectReference, { "path": asset.getRelativePath() });
+
+                        } else if (resource instanceof Atomic.Animation) {
+
+                             var animCacheReferenceName = resource.name.replace("_"+(<Atomic.Animation>resource).animationName, "");
+                             var asset = ToolCore.assetDatabase.getAssetByCachePath(animCacheReferenceName);
+                             this.sendEvent(EditorEvents.InspectorProjectReference, { "path": asset.getRelativePath() });
+
+                        } else {
+
+                            //Unknown Resource
+
+                        }
+                    }
+
+                });
             }
 
 

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

@@ -9,6 +9,7 @@ import EditorUI = require("ui/EditorUI");
 import InspectorUtils = require("./InspectorUtils");
 import AttributeInfoEdit = require("./AttributeInfoEdit");
 import SerializableEditType = require("./SerializableEditType");
+import EditorEvents = require("editor/EditorEvents");
 
 class LightCascadeAttributeEdit extends AttributeInfoEdit {
 
@@ -106,6 +107,7 @@ class LightCascadeAttributeEdit extends AttributeInfoEdit {
 interface MaterialEdit {
 
     index: number;
+    pathReference: string;
     editField: Atomic.UIEditField;
     selectButton: Atomic.UIButton;
 
@@ -121,12 +123,47 @@ 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.sendEvent(EditorEvents.InspectorProjectReference, { "path": resource.name });
+            this.editType.onAttributeInfoEdited(this.attrInfo, resource, materialIndex);
+            this.refresh();
+
+        }.bind(this));
+
     }
 
     createMaterialEdit(materialIndex: number) {
@@ -141,32 +178,18 @@ class SubmeshAttributeEdit extends AttributeInfoEdit {
 
         var selectButton = o.selectButton;
 
-        var materialEdit: MaterialEdit = { index: materialIndex, editField: o.editField, selectButton: selectButton };
+        var materialEdit: MaterialEdit = { index: materialIndex, pathReference: "" , editField: o.editField, selectButton: selectButton };
         this.materialEdits[materialIndex] = materialEdit;
 
         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);
+           // this.sendEvent(EditorEvents.InspectorProjectReference, { "path": pathName });
 
-            }.bind(this));
         };
 
         // handle dropping of component on field
@@ -191,7 +214,7 @@ class SubmeshAttributeEdit extends AttributeInfoEdit {
                 if (importer) {
 
                     var resource = asset.getResource(resourceTypeName);
-
+                    this.sendEvent(EditorEvents.InspectorProjectReference, { "path": resource.name });
                     this.editType.onAttributeInfoEdited(this.attrInfo, resource, materialIndex);
                     this.refresh();
                 }
@@ -199,6 +222,19 @@ class SubmeshAttributeEdit extends AttributeInfoEdit {
 
         });
 
+        o.editField.subscribeToEvent(o.editField, "WidgetEvent", (ev: Atomic.UIWidgetEvent) => {
+
+            if (ev.type == Atomic.UI_EVENT_TYPE_POINTER_DOWN && o.editField.text != "") {
+
+                var pathName = materialEdit.pathReference;
+                this.sendEvent(EditorEvents.InspectorProjectReference, { "path": pathName });
+
+            } else if (o.editField.text == "") {
+
+                this.openResourceSelectionBox(materialIndex, resourceTypeName, importerName);
+            }
+
+        });
     }
 
     createEditWidget() {
@@ -332,6 +368,7 @@ class SubmeshAttributeEdit extends AttributeInfoEdit {
 
                     var pathinfo = Atomic.splitPath(text);
                     matEdit.editField.text = pathinfo.fileName;
+                    matEdit.pathReference = text;
                 }
 
 

+ 57 - 6
Script/AtomicEditor/ui/frames/inspector/MaterialInspector.ts

@@ -8,6 +8,7 @@
 import ScriptWidget = require("ui/ScriptWidget");
 import UIEvents = require("ui/UIEvents");
 import EditorUI = require("ui/EditorUI");
+import EditorEvents = require("editor/EditorEvents");
 
 import TextureSelector = require("./TextureSelector");
 
@@ -73,6 +74,10 @@ for (var key in techniqueLookup) {
 
 class MaterialInspector extends ScriptWidget {
 
+    currentTexture: Atomic.UITextureWidget = null;
+    tunit: number;
+    textureWidget: Atomic.UITextureWidget 
+
     constructor() {
 
         super();
@@ -80,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 {
@@ -237,22 +242,38 @@ class MaterialInspector extends ScriptWidget {
 
     }
 
-    createTextureButtonCallback(textureUnit:number, textureWidget:Atomic.UITextureWidget) {
 
-      return  () => {
+    openTextureSelectionBox(textureUnit: number, textureWidget: Atomic.UITextureWidget) {
 
         var inspector = this;
+        
+        EditorUI.getModelOps().showResourceSelection("Select Texture", "TextureImporter", "Texture2D", function (asset: ToolCore.Asset, args: any) {
 
-        EditorUI.getModelOps().showResourceSelection("Select Texture", "TextureImporter", "Texture2D", function(asset: ToolCore.Asset, args: any) {
-
-            var texture = <Atomic.Texture2D> Atomic.cache.getResource("Texture2D", asset.path);
+            var texture = <Atomic.Texture2D>Atomic.cache.getResource("Texture2D", asset.path);
 
             if (texture) {
                 inspector.material.setTexture(textureUnit, texture);
                 textureWidget.texture = inspector.getTextureThumbnail(texture);
+
+                this.sendEvent(EditorEvents.InspectorProjectReference, { "path": texture.getName() });
             }
 
         });
+        
+    }
+    
+     // Big Texture Button(referenced texture file path in project frame)
+    createTextureButtonCallback(textureUnit:number, textureWidget:Atomic.UITextureWidget) {
+        
+        return () => {
+
+            var texture = this.material.getTexture(textureUnit);
+
+            if (textureWidget.getTexture() != null) {
+                this.sendEvent(EditorEvents.InspectorProjectReference, { "path": texture.getName() });
+            } else {
+                this.openTextureSelectionBox(textureUnit, textureWidget);
+            }
 
         return true;
 
@@ -260,6 +281,27 @@ class MaterialInspector extends ScriptWidget {
 
     }
 
+   // Small Texture Button (Opens texture selection window)
+    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 {
 
@@ -309,11 +351,19 @@ class MaterialInspector extends ScriptWidget {
             textureButton["tunit"] = tunit;
             textureButton["textureWidget"] = textureWidget;
 
+            //Create drop-down buttons to open Texture Selection Dialog Box
+            var textureRefButton = new Atomic.UIButton();
+            textureRefButton.skinBg = "arrow.down";
+            textureRefButton["tunit"] = tunit;
+            textureRefButton["textureWidget"] = textureWidget;
+
             textureButton.onClick = this.createTextureButtonCallback(tunit, textureWidget);
+            textureRefButton.onClick = this.createTextureReferenceButtonCallback(tunit, textureWidget);
 
             textureButton.contentRoot.addChild(textureWidget);
 
             attrLayout.addChild(textureButton);
+            attrLayout.addChild(textureRefButton);
 
             attrsVerticalLayout.addChild(attrLayout);
 
@@ -334,6 +384,7 @@ class MaterialInspector extends ScriptWidget {
                         this.material.setTexture(ev.target["tunit"], texture);
                         (<Atomic.UITextureWidget>ev.target["textureWidget"]).texture = this.getTextureThumbnail(texture);
 
+                        this.sendEvent("InspectorProjectReference", { "path": texture.getName(), "ButtonID": texture.getName() });
                     }
                 }
             });

+ 10 - 0
Script/AtomicEditor/ui/frames/inspector/ModelInspector.ts

@@ -8,6 +8,7 @@
 import InspectorWidget = require("./InspectorWidget");
 import ArrayEditWidget = require("./ArrayEditWidget");
 import InspectorUtils = require("./InspectorUtils");
+import EditorEvents = require("editor/EditorEvents");
 
 class ModelInspector extends InspectorWidget {
 
@@ -75,6 +76,15 @@ class ModelInspector extends InspectorWidget {
         editField.readOnly = true;
         editField.text = asset.name;
 
+        //This should preferably be onClick
+        editField.subscribeToEvent(editField, "UIWidgetFocusChanged", (ev: Atomic.UIWidgetFocusChangedEvent) => {
+
+            if (ev.widget == editField && editField.focus) {
+                this.sendEvent(EditorEvents.InspectorProjectReference, { "path": asset.getRelativePath() });
+            }
+
+        });
+
         this.scaleEdit = InspectorUtils.createAttrEditField("Scale", modelLayout);
         this.scaleEdit.text = this.importer.scale.toString();
 

+ 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) {

+ 44 - 11
Source/Atomic/UI/UIListView.cpp

@@ -852,6 +852,13 @@ void UIListView::SendItemSelectedChanged(ListViewItem* item)
 
 }
 
+void UIListView::SelectItem(ListViewItem* item, bool select)
+{
+    item->SetSelected(select);
+    UpdateItemVisibility();
+    SendItemSelectedChanged(item);
+}
+
 bool UIListView::OnEvent(const tb::TBWidgetEvent &ev)
 {
     if (ev.type == EVENT_TYPE_KEY_UP )
@@ -883,25 +890,51 @@ bool UIListView::OnEvent(const tb::TBWidgetEvent &ev)
             if (item->id == ev.target->GetID())
             {
                 bool multi = false;
-                if (multiSelect_ && (ev.modifierkeys & TB_SHIFT || ev.modifierkeys & TB_CTRL || ev.modifierkeys & TB_SUPER))
+                if (multiSelect_ && (ev.modifierkeys & TB_CTRL || ev.modifierkeys & TB_SUPER))
                     multi = true;
 
-                if (multi)
+                bool shiftMulti = false;
+                if (multiSelect_ && (ev.modifierkeys & TB_SHIFT))
+                    shiftMulti = true;
+
+                if (shiftMulti)
+                {
+                    int first = rootList_->GetValue();
+
+                    if (i > first)
+                    {
+                        for (int j = first + 1; j < i; j++)
+                        {
+                            ListViewItem* itemSelect = source_->GetItem(j);
+                            SelectItem(itemSelect, true);
+                            SetValueFirstSelected();
+                        }
+
+                        SelectItem(item, true);
+                        SetValueFirstSelected();
+                    }
+                    else if (i < first)
+                    {
+                        for (int j = first - 1; j > i; j--)
+                        {
+                            ListViewItem* itemSelect = source_->GetItem(j);
+                            SelectItem(itemSelect, true);
+                            SetValueFirstSelected();
+                        }
+
+                        SelectItem(item, true);
+                        SetValueFirstSelected();
+                    }
+                }
+                else if (multi)
                 {
                     if (item->GetSelected())
                     {
-                        item->SetSelected(false);
-                        UpdateItemVisibility();
-
-                        SendItemSelectedChanged(item);
+                        SelectItem(item, false);
                     }
                     else
                     {
-
-                        item->SetSelected(true);
-                        UpdateItemVisibility();
-
-                        SendItemSelectedChanged(item);
+                        SelectItem(item, true);
                     }
 
                     SetValueFirstSelected();

+ 2 - 0
Source/Atomic/UI/UIListView.h

@@ -96,6 +96,8 @@ private:
 
     unsigned itemLookupId_;
 
+    void SelectItem(ListViewItem* item, bool select);
+
 };
 
 }

+ 7 - 0
Source/Atomic/UI/UIScrollContainer.cpp

@@ -104,6 +104,13 @@ UI_SCROLL_MODE UIScrollContainer::GetScrollMode()
 
 }
 
+void UIScrollContainer::ScrollTo(int x, int y)
+{
+    if (!widget_)
+        return;
+
+    return ((TBScrollContainer *)widget_)->ScrollTo(x, y);
+}
 
 bool UIScrollContainer::OnEvent(const tb::TBWidgetEvent &ev)
 {

+ 2 - 0
Source/Atomic/UI/UIScrollContainer.h

@@ -63,6 +63,8 @@ public:
     void SetAdaptContentSize(bool adapt);
     bool GetAdaptContentSize();
 
+    void ScrollTo(int x, int y);
+
 
 protected: