Browse Source

- Models, Animations, Materials, and JavaScript file components are now also being referenced to in the Project Frame when clicked on in the Inspector.
- Implemented the ScrollTo function for the UIScrollContainer

Concerns:
- EditField Components trigger events onFocusChanged --> We would prefer it onClick.
- The ScrollTo implementation in the ProjectFrame.ts might be unnecessarily complicated.
- Animation components in array widget are not referencing.

JohnnyWahib 9 years ago
parent
commit
f1880b2a87

+ 30 - 12
Script/AtomicEditor/ui/frames/ProjectFrame.ts

@@ -20,6 +20,9 @@ class ProjectFrame extends ScriptWidget {
     assetGUIDToItemID = {};
     resourcesID: number = -1;
     assetReferencePath: string = null;
+    currentReferencedButton: Atomic.UIButton = null;
+    containerScrollToHeight: number;
+    containerScrollToHeightCounter: number;
 
     constructor(parent: Atomic.UIWidget) {
 
@@ -221,6 +224,11 @@ class ProjectFrame extends ScriptWidget {
 
             }
 
+            if (this.currentReferencedButton) {
+                this.currentReferencedButton.setState(4, false);
+                this.currentReferencedButton = null;
+            }
+
         }
 
         return false;
@@ -385,15 +393,14 @@ 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.folderList.selectItemByID(asset.parent.guid, true);
         this.refreshContent(asset.parent);
-        this.folderList.scrollToSelectedItem();  
+        this.folderList.scrollToSelectedItem();
     }
 
     private refreshContent(folder: ToolCore.Asset) {
@@ -413,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);
 
     }
 
@@ -456,19 +468,25 @@ class ProjectFrame extends ScriptWidget {
 
         var button = new Atomic.UIButton();
 
-        //Get the path of the button and compare it to the asset's path to highlight 
-        var texturePath = this.resourceFolder.getPath() + "/" + this.assetReferencePath;
 
-        //Highlight Button UI
-        if (texturePath == asset.path) {
-            button.setState(4, true);
-        }
 
         // 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, "UIWidgetFocusChanged", (ev: Atomic.UIWidgetFocusChangedEvent) => {
+
+                    if (ev.widget == this.editField && this.editField.focus) {
+
+                        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 {
+
+                            console.debug("Unknown resource reference type.");
+
+                        }
+                    }
+
+                });
             }
 
 

+ 14 - 1
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;
 
@@ -141,7 +143,7 @@ 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";
@@ -199,6 +201,16 @@ class SubmeshAttributeEdit extends AttributeInfoEdit {
 
         });
 
+        o.editField.subscribeToEvent(o.editField, "UIWidgetFocusChanged", (ev: Atomic.UIWidgetFocusChangedEvent) => {
+
+            if (ev.widget == o.editField && o.editField.focus) {
+
+                var pathName = materialEdit.pathReference;
+                this.sendEvent(EditorEvents.InspectorProjectReference, { "path": pathName });
+
+             }
+
+        });
     }
 
     createEditWidget() {
@@ -332,6 +344,7 @@ class SubmeshAttributeEdit extends AttributeInfoEdit {
 
                     var pathinfo = Atomic.splitPath(text);
                     matEdit.editField.text = pathinfo.fileName;
+                    matEdit.pathReference = text;
                 }
 
 

+ 1 - 1
Script/AtomicEditor/ui/frames/inspector/MaterialInspector.ts

@@ -266,7 +266,7 @@ class MaterialInspector extends ScriptWidget {
             var texture = this.material.getTexture(textureUnit);
 
             if (texture != null) {
-                this.sendEvent(EditorEvents.InspectorProjectReference, { "path": texture.getName() });            
+                this.sendEvent(EditorEvents.InspectorProjectReference, { "path": texture.getName() });
             } else {
                 this.openTextureSelectionBox(textureUnit, textureWidget);
             }

+ 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();
 

+ 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: