Преглед изворни кода

Animation field display now properly displays fields of imported curves
When no curve is selected, display them all

BearishSun пре 9 година
родитељ
комит
7ef077de40

+ 3 - 3
Source/MBansheeEditor/Windows/Animation/EditorAnimInfo.cs

@@ -61,6 +61,7 @@ namespace BansheeEditor
     internal class EditorAnimClipInfo
     {
         public AnimationClip clip;
+        public bool isImported;
         public Dictionary<string, FieldAnimCurves> curves = new Dictionary<string, FieldAnimCurves>();
         public AnimationEvent[] events = new AnimationEvent[0];
 
@@ -74,6 +75,7 @@ namespace BansheeEditor
         {
             EditorAnimClipInfo clipInfo = new EditorAnimClipInfo();
             clipInfo.clip = clip;
+            clipInfo.isImported = IsClipImported(clip);
 
             AnimationCurves clipCurves = clip.Curves;
             EditorAnimClipTangents editorCurveData = null;
@@ -269,9 +271,7 @@ namespace BansheeEditor
         /// </summary>
         public void SaveToClip()
         {
-            bool clipIsImported = IsClipImported(clip);
-
-            if (!clipIsImported)
+            if (!isImported)
             {
                 List<NamedVector3Curve> positionCurves = new List<NamedVector3Curve>();
                 List<NamedVector3Curve> rotationCurves = new List<NamedVector3Curve>();

+ 48 - 24
Source/MBansheeEditor/Windows/Animation/GUIAnimFieldDisplay.cs

@@ -18,7 +18,7 @@ namespace BansheeEditor
         private int height;
 
         private GUIScrollArea scrollArea;
-        private List<string> paths = new List<string>();
+        private List<AnimFieldInfo> fieldInfos = new List<AnimFieldInfo>();
 
         private GUIAnimFieldEntry[] fields;
         private GUIAnimFieldLayouts layouts;
@@ -46,19 +46,24 @@ namespace BansheeEditor
             Rebuild();
         }
 
-        public void SetFields(string[] paths)
+        public void SetFields(AnimFieldInfo[] fields)
         {
-            this.paths.Clear();
-            this.paths.AddRange(paths);
+            this.fieldInfos.Clear();
+            this.fieldInfos.AddRange(fields);
 
             Rebuild();
         }
 
-        public void AddField(string path)
+        public void AddField(AnimFieldInfo field)
         {
-            if (!paths.Contains(path))
+            bool exists = fieldInfos.Exists(x =>
             {
-                paths.Add(path);
+                return x.path == field.path;
+            });
+
+            if (!exists)
+            {
+                fieldInfos.Add(field);
                 Rebuild();
             }
         }
@@ -115,7 +120,7 @@ namespace BansheeEditor
             scrollArea.Layout.Clear();
             fields = null;
 
-            if (paths == null || root == null)
+            if (fieldInfos == null || root == null)
                 return;
 
             layouts = new GUIAnimFieldLayouts();
@@ -141,41 +146,48 @@ namespace BansheeEditor
             layouts.overlay.AddSpace(5);
             layouts.background.AddSpace(5);
 
-            fields = new GUIAnimFieldEntry[paths.Count];
-            for (int i = 0; i < paths.Count; i++)
+            fields = new GUIAnimFieldEntry[fieldInfos.Count];
+            for (int i = 0; i < fieldInfos.Count; i++)
             {
-                if (string.IsNullOrEmpty(paths[i]))
+                if (string.IsNullOrEmpty(fieldInfos[i].path))
                     continue;
 
-                string pathSuffix;
-                SerializableProperty property = Animation.FindProperty(root, paths[i], out pathSuffix);
+                bool entryIsMissing;
+                if (fieldInfos[i].isUserCurve)
+                {
+                    string pathSuffix;
+                    SerializableProperty property = Animation.FindProperty(root, fieldInfos[i].path, out pathSuffix);
+                    entryIsMissing = property == null;
+                }
+                else
+                    entryIsMissing = false;
 
-                if (property != null)
+                if (!entryIsMissing)
                 {
-                    switch (property.Type)
+                    switch (fieldInfos[i].type)
                     {
                         case SerializableProperty.FieldType.Vector2:
-                            fields[i] = new GUIAnimVec2Entry(layouts, paths[i]);
+                            fields[i] = new GUIAnimVec2Entry(layouts, fieldInfos[i].path);
                             break;
                         case SerializableProperty.FieldType.Vector3:
-                            fields[i] = new GUIAnimVec3Entry(layouts, paths[i]);
+                            fields[i] = new GUIAnimVec3Entry(layouts, fieldInfos[i].path);
                             break;
                         case SerializableProperty.FieldType.Vector4:
-                            fields[i] = new GUIAnimVec4Entry(layouts, paths[i]);
+                            fields[i] = new GUIAnimVec4Entry(layouts, fieldInfos[i].path);
                             break;
                         case SerializableProperty.FieldType.Color:
-                            fields[i] = new GUIAnimColorEntry(layouts, paths[i]);
+                            fields[i] = new GUIAnimColorEntry(layouts, fieldInfos[i].path);
                             break;
                         case SerializableProperty.FieldType.Bool:
                         case SerializableProperty.FieldType.Int:
                         case SerializableProperty.FieldType.Float:
-                            fields[i] = new GUIAnimSimpleEntry(layouts, paths[i]);
+                            fields[i] = new GUIAnimSimpleEntry(layouts, fieldInfos[i].path);
                             break;
                     }
                 }
                 else
                 {
-                    fields[i] = new GUIAnimMissingEntry(layouts, paths[i]);
+                    fields[i] = new GUIAnimMissingEntry(layouts, fieldInfos[i].path);
                 }
 
                 if (fields[i] != null)
@@ -210,7 +222,7 @@ namespace BansheeEditor
 
     internal abstract class GUIAnimFieldEntry
     {
-        private const int MAX_PATH_LENGTH = 20;
+        private const int MAX_PATH_LENGTH = 30;
         protected const int INDENT_AMOUNT = 10;
 
         protected string path;
@@ -561,8 +573,6 @@ namespace BansheeEditor
 
             overlaySpacing = new GUILabel("", GUIOption.FixedHeight(GetEntryHeight()));
             layouts.overlay.AddElement(overlaySpacing);
-
-            // TODO - Alternating backgrounds
         }
 
         public override void Toggle(bool on)
@@ -574,5 +584,19 @@ namespace BansheeEditor
         }
     }
 
+    internal struct AnimFieldInfo
+    {
+        public AnimFieldInfo(string path, SerializableProperty.FieldType type, bool isUserCurve)
+        {
+            this.path = path;
+            this.type = type;
+            this.isUserCurve = isUserCurve;
+        }
+
+        public string path;
+        public SerializableProperty.FieldType type;
+        public bool isUserCurve;
+    }
+
     /** @} */
 }

+ 43 - 33
Source/MBansheeEditor/Windows/AnimationWindow.cs

@@ -17,7 +17,7 @@ namespace BansheeEditor
     [DefaultSize(900, 500)]
     internal class AnimationWindow : EditorWindow
     {
-        private const int FIELD_DISPLAY_WIDTH = 200;
+        private const int FIELD_DISPLAY_WIDTH = 300;
         private const int DRAG_START_DISTANCE = 3;
         private const float DRAG_SCALE = 1.0f;
         private const float ZOOM_SCALE = 0.1f/120.0f; // One scroll step is usually 120 units, we want 1/10 of that
@@ -258,7 +258,7 @@ namespace BansheeEditor
                 }
                 else
                 {
-                    if (IsClipImported(clipInfo.clip))
+                    if (clipInfo.isImported)
                     {
                         LocEdString title = new LocEdString("Warning");
                         LocEdString message =
@@ -277,7 +277,7 @@ namespace BansheeEditor
                 if (clipInfo.clip == null)
                     return;
 
-                if (IsClipImported(clipInfo.clip))
+                if (clipInfo.isImported)
                 {
                     LocEdString title = new LocEdString("Warning");
                     LocEdString message =
@@ -539,13 +539,12 @@ namespace BansheeEditor
         {
             EditorPersistentData persistentData = EditorApplication.PersistentData;
 
-            bool clipIsImported = IsClipImported(clip);
             if (persistentData.dirtyAnimClips.TryGetValue(clip.UUID, out clipInfo))
             {
                 // If an animation clip is imported, we don't care about it's cached curve values as they could have changed
                 // since last modification, so we re-load the clip. But we persist the events as those can only be set
                 // within the editor.
-                if (clipIsImported)
+                if (clipInfo.isImported)
                 {
                     EditorAnimClipInfo newClipInfo = EditorAnimClipInfo.Create(clip);
                     newClipInfo.events = clipInfo.events;
@@ -557,20 +556,14 @@ namespace BansheeEditor
             persistentData.dirtyAnimClips[clip.UUID] = clipInfo;
 
             foreach (var curve in clipInfo.curves)
-                guiFieldDisplay.AddField(curve.Key);
+                guiFieldDisplay.AddField(new AnimFieldInfo(curve.Key, curve.Value.type, !clipInfo.isImported));
 
             guiCurveEditor.Events = clipInfo.events;
-            guiCurveEditor.DisableCurveEdit = clipIsImported;
+            guiCurveEditor.DisableCurveEdit = clipInfo.isImported;
 
             SetCurrentFrame(0);
         }
 
-        private static bool IsClipImported(AnimationClip clip)
-        {
-            string resourcePath = ProjectLibrary.GetPath(clip);
-            return ProjectLibrary.IsSubresource(resourcePath);
-        }
-
         private void UpdateSelectedSO(bool force)
         {
             SceneObject so = Selection.SceneObject;
@@ -613,6 +606,8 @@ namespace BansheeEditor
 
                 if(clipInfo == null)
                     clipInfo = new EditorAnimClipInfo();
+
+                UpdateDisplayedCurves(true);
             }
         }
 
@@ -704,19 +699,41 @@ namespace BansheeEditor
             guiFieldDisplay.SetDisplayValues(values.ToArray());
         }
 
-        private Vector2 GetOptimalRange()
+        private EdAnimationCurve[] GetDisplayedCurves()
         {
-            List<EdAnimationCurve> displayedCurves = new List<EdAnimationCurve>();
-            for (int i = 0; i < selectedFields.Count; i++)
+            List<EdAnimationCurve> curvesToDisplay = new List<EdAnimationCurve>();
+
+            if (selectedFields.Count == 0) // Display all if nothing is selected
+            {
+                if (clipInfo == null)
+                    return curvesToDisplay.ToArray();
+
+                foreach (var curve in clipInfo.curves)
+                {
+                    for (int i = 0; i < curve.Value.curves.Length; i++)
+                        curvesToDisplay.Add(curve.Value.curves[i]);
+                }
+            }
+            else
             {
-                EdAnimationCurve curve;
-                if (TryGetCurve(selectedFields[i], out curve))
-                    displayedCurves.Add(curve);
+                for (int i = 0; i < selectedFields.Count; i++)
+                {
+                    EdAnimationCurve curve;
+                    if (TryGetCurve(selectedFields[i], out curve))
+                        curvesToDisplay.Add(curve);
+                }
             }
 
+            return curvesToDisplay.ToArray();
+        }
+
+        private Vector2 GetOptimalRange()
+        {
+            EdAnimationCurve[] curvesToDisplay = GetDisplayedCurves();
+
             float xRange;
             float yRange;
-            CalculateRange(displayedCurves, out xRange, out yRange);
+            CalculateRange(curvesToDisplay, out xRange, out yRange);
 
             // Add padding to y range
             yRange *= 1.05f;
@@ -733,15 +750,8 @@ namespace BansheeEditor
 
         private void UpdateDisplayedCurves(bool allowReduce = false)
         {
-            List<EdAnimationCurve> curvesToDisplay = new List<EdAnimationCurve>();
-            for (int i = 0; i < selectedFields.Count; i++)
-            {
-                EdAnimationCurve curve;
-                if (TryGetCurve(selectedFields[i], out curve))
-                    curvesToDisplay.Add(curve);
-            }
-
-            guiCurveEditor.SetCurves(curvesToDisplay.ToArray());
+            EdAnimationCurve[] curvesToDisplay = GetDisplayedCurves();
+            guiCurveEditor.SetCurves(curvesToDisplay);
 
             Vector2 newRange = GetOptimalRange();
             if (!allowReduce)
@@ -762,7 +772,7 @@ namespace BansheeEditor
         private void AddNewField(string path, SerializableProperty.FieldType type)
         {
             bool noSelection = selectedFields.Count == 0;
-            guiFieldDisplay.AddField(path);
+            guiFieldDisplay.AddField(new AnimFieldInfo(path, type, !clipInfo.isImported));
 
             switch (type)
             {
@@ -877,9 +887,9 @@ namespace BansheeEditor
                 clipInfo.curves.Remove(GetSubPathParent(selectedFields[i]));
             }
 
-            List<string> existingFields = new List<string>();
+            List<AnimFieldInfo> existingFields = new List<AnimFieldInfo>();
             foreach (var KVP in clipInfo.curves)
-                existingFields.Add(KVP.Key);
+                existingFields.Add(new AnimFieldInfo(KVP.Key, KVP.Value.type, !clipInfo.isImported));
 
             guiFieldDisplay.SetFields(existingFields.ToArray());
 
@@ -899,7 +909,7 @@ namespace BansheeEditor
             return output;
         }
 
-        private static void CalculateRange(List<EdAnimationCurve> curves, out float xRange, out float yRange)
+        private static void CalculateRange(EdAnimationCurve[] curves, out float xRange, out float yRange)
         {
             xRange = 0.0f;
             yRange = 0.0f;