Exemplo n.º 1
0
        public uFrameMiniInspector(object target)
        {
            DiagramViewModel = InvertApplication.Container.Resolve <DesignerWindow>().DiagramViewModel;

            foreach (var item in target.GetPropertiesWithAttribute <InspectorProperty>())
            {
                var property       = item.Key;
                var attribute      = item.Value;
                var fieldViewModel = new PropertyFieldViewModel()
                {
                    Name = property.Name,
                };
                fieldViewModel.Getter           = () => property.GetValue(target, null);
                fieldViewModel.Setter           = (d, v) => property.SetValue(d, v, null);
                fieldViewModel.InspectorType    = attribute.InspectorType;
                fieldViewModel.Type             = property.PropertyType;
                fieldViewModel.DiagramViewModel = DiagramViewModel;
                fieldViewModel.DataObject       = target;
                fieldViewModel.CustomDrawerType = attribute.CustomDrawerType;
                fieldViewModel.CachedValue      = fieldViewModel.Getter();
                if (!string.IsNullOrEmpty(attribute.InspectorTip))
                {
                    fieldViewModel.InspectorTip = attribute.InspectorTip;
                }
                Properties.Add(fieldViewModel);

                Height += fieldViewModel.InspectorType == InspectorType.GraphItems ? 30 : 17;
            }
        }
Exemplo n.º 2
0
    public virtual List<PropertyFieldViewModel> GetInspectorOptions(object obj)
    {
        List<PropertyFieldViewModel> list = new List<PropertyFieldViewModel>();
        if (obj == null) return list;
        var items = obj.GetType().GetPropertiesWithAttributeByType<InspectorProperty>().ToArray();
        for (int index = 0; index < items.Length; index++)
        {
            var item = items[index];

            var property = item.Key;
            var attribute = item.Value;
            var item1 = item;
            var fieldViewModel = new PropertyFieldViewModel()
            {
                Name = property.Name,
            };

            fieldViewModel.Getter = () => property.GetValue(obj, null);

            fieldViewModel.Setter = delegate(object d, object v)
            {
                fieldViewModel.PropertyInfo.SetValue(d, v, null);
            };

            fieldViewModel.PropertyInfo = item.Key;
            fieldViewModel.InspectorType = attribute.InspectorType;
            fieldViewModel.InspectorTip = attribute.InspectorTip;
            fieldViewModel.Type = property.PropertyType;
            fieldViewModel.DataObject = obj;
            fieldViewModel.CustomDrawerType = attribute.CustomDrawerType;
            fieldViewModel.CachedValue = fieldViewModel.Getter();
            list.Add(fieldViewModel);
        }
        return list;
    }
Exemplo n.º 3
0
 public BoneSubPanelViewModel(Editor editor) : base(editor)
 {
     BoneLength = new PropertyFieldViewModel(PropertyType.BoneLength, "Length")
     {
         IsKeyingEnabled = false
     };
     RegisterField(BoneLength);
 }
Exemplo n.º 4
0
 public TranslateSubPanelViewModel(Editor editor)
     : base(editor)
 {
     X = new PropertyFieldViewModel(PropertyType.TranslationX, "Translation X");
     Y = new PropertyFieldViewModel(PropertyType.TranslationY, "Y");
     RegisterField(X);
     RegisterField(Y);
 }
Exemplo n.º 5
0
 public void DrawPropertyField(Rect r, PropertyFieldViewModel fieldViewModel, float scale)
 {
     DrawInspector(r, fieldViewModel, new GUIStyle(EditorStyles.boldLabel)
     {
         normal = new GUIStyleState()
         {
             textColor = new Color(0.77f, 0.77f, 0.77f)
         }
     });
 }
Exemplo n.º 6
0
 public RotateSubPanelViewModel(Editor editor)
     : base(editor)
 {
     Angle = new PropertyFieldViewModel(PropertyType.RotationAngle, "Rotation")
     {
         DragFactor         = -0.5f, // reverse how mousedrag changes the angle, so it is like steering
         DisplayValueFactor = RadiansToDegrees
     };
     RegisterField(Angle);
 }
Exemplo n.º 7
0
 //TODO DRAWER Introduce tooltip parameter
 public void DrawPropertyField(PropertyFieldViewModel fieldViewModel, float scale)
 {
     //base.Draw(scale);
     GUILayout.BeginArea(fieldViewModel.Bounds.Scale(scale), ElementDesignerStyles.SelectedItemStyle);
     EditorGUIUtility.labelWidth = fieldViewModel.Bounds.width * 0.55f;
     DrawInspector(fieldViewModel, new GUIStyle(EditorStyles.boldLabel)
     {
         normal = new GUIStyleState()
         {
             textColor = new Color(0.77f, 0.77f, 0.77f)
         }
     });
     GUILayout.EndArea();
 }
Exemplo n.º 8
0
 private void LinkPropertyFieldEvents(PropertyFieldViewModel vm, float displayFactor = 1f)
 {
     vm.PropertyKeyed += propertyType =>
     {
         Editor.AddOrUpdateKeyAtCurrentFrame(NodeId, propertyType);
     };
     vm.PropertyUnkeyed += propertyType =>
     {
         Editor.RemoveKeyAtCurrentFrame(NodeId, propertyType);
     };
     vm.PropertyValueChanged += (sender, e) =>
     {
         if (e.IsTransient)
         {
             Editor.SetNodePropertyVisual(NodeId, e.PropertyType, e.NewValue / displayFactor);
         }
         else
         {
             Editor.SetNodeProperty(NodeId, e.PropertyType, e.NewValue / displayFactor);
         }
     };
 }
Exemplo n.º 9
0
        public virtual void DrawInspector(Rect rect, PropertyFieldViewModel d, GUIStyle labelStyle)
        {
            var colorCache = GUI.color;
            GUI.color = Color.white;
            var labelArea = rect.LeftHalf();
            var fieldArea = rect.RightHalf();
            var labelWidtho = GUILayout.Width(140);

            if (d.InspectorType == InspectorType.GraphItems)
            {
                var item = d.CachedValue as IGraphItem;
                var text = "--Select--";
                if (item != null)
                {
                    text = item.Label;
                }
                //GUILayout.BeginHorizontal();

                if (GUI.Button(rect, d.Label + ": " + text, ElementDesignerStyles.ButtonStyle))
                {
                    var type = d.Type;

                    var items = InvertGraphEditor.CurrentDiagramViewModel.CurrentRepository.AllOf<IGraphItem>().Where(p => type.IsAssignableFrom(p.GetType()));

                    var menu = new SelectionMenu();
                    menu.AddItem(new SelectionMenuItem(string.Empty,"[None]", () =>
                    {
                        InvertApplication.Execute(() =>
                        {
                            d.Setter(d.DataObject, null);
                        });
                    }));
                    foreach (var graphItem in items)
                    {
                        var graphItem1 = graphItem;
                        menu.AddItem(new SelectionMenuItem(graphItem1, () =>
                        {
                            InvertApplication.Execute(() =>
                            {
                                d.Setter(d.DataObject, graphItem1);
                            });
                        }));
                    }

                    InvertApplication.SignalEvent<IShowSelectionMenu>(_ => _.ShowSelectionMenu(menu));



                    //
                    //                    InvertGraphEditor.WindowManager.InitItemWindow(items, 
                    //                        
                    //                    },true);

                }
                SetTooltipForRect(rect, d.InspectorTip);

                GUI.color = colorCache;
                //GUILayout.EndHorizontal();
                return;
            }


            if (d.Type == typeof(string))
            {
                if (d.InspectorType == InspectorType.TextArea)
                {
                    labelArea = rect.WithHeight(17).InnerAlignWithUpperRight(rect);
                    fieldArea = rect.Below(labelArea).Clip(rect).PadSides(2);
                    EditorGUI.LabelField(labelArea, d.Name, labelStyle);
                    SetTooltipForRect(rect, d.InspectorTip);
                    EditorGUI.BeginChangeCheck();
                    d.CachedValue = EditorGUI.TextArea(fieldArea, (string)d.CachedValue, TextWrappingTextArea);
                    if (EditorGUI.EndChangeCheck())
                    {
                        d.Setter(d.DataObject, d.CachedValue);
                    }
                    if (Event.current.isKey && Event.current.keyCode == KeyCode.Return)
                    {
                        InvertApplication.Execute(() =>
                        {

                        });
                    }
                }
                else if (d.InspectorType == InspectorType.TypeSelection)
                {

                    if (GUI.Button(rect, (string)d.CachedValue))
                    {
                        d.NodeViewModel.Select();
                        // TODO 2.0 Open Selection?
                    }
                    SetTooltipForRect(rect, d.InspectorTip);


                }

                else
                {
                    EditorGUI.BeginChangeCheck();
                    EditorGUI.LabelField(labelArea, d.Name, labelStyle);
                    d.CachedValue = EditorGUI.TextField(fieldArea, (string)d.CachedValue);
                    SetTooltipForRect(rect, d.InspectorTip);

                    if (EditorGUI.EndChangeCheck())
                    {
                        d.Setter(d.DataObject, d.CachedValue);
                    }
                }

            }
            else
            {
                if (d.Type == typeof(int))
                {
                    EditorGUI.BeginChangeCheck();
                    GUI.Label(labelArea, d.Name, labelStyle);
                    d.CachedValue = EditorGUI.IntField(fieldArea, (int)d.CachedValue);
                    SetTooltipForRect(rect, d.InspectorTip);

                    if (EditorGUI.EndChangeCheck())
                    {
                        d.Setter(d.DataObject, d.CachedValue);
                    }
                }
                else if (d.Type == typeof(float))
                {
                    EditorGUI.BeginChangeCheck();
                    GUI.Label(labelArea, d.Name, labelStyle);
                    d.CachedValue = EditorGUI.FloatField(fieldArea, (float)d.CachedValue);
                    SetTooltipForRect(rect, d.InspectorTip);

                    if (EditorGUI.EndChangeCheck())
                    {
                        d.Setter(d.DataObject, d.CachedValue);
                    }
                }
                else if (d.Type == typeof(Vector2))
                {
                    EditorGUI.BeginChangeCheck();
                    GUI.Label(labelArea, d.Name, labelStyle);
                    d.CachedValue = EditorGUI.Vector2Field(fieldArea, string.Empty, (Vector2)d.CachedValue);
                    SetTooltipForRect(rect, d.InspectorTip);

                    if (EditorGUI.EndChangeCheck())
                    {
                        d.Setter(d.DataObject, d.CachedValue);
                    }
                }

                else if (d.Type == typeof(Vector3))
                {
                    EditorGUI.BeginChangeCheck();
                    GUI.Label(labelArea, d.Name, labelStyle);
                    d.CachedValue = EditorGUI.Vector3Field(fieldArea, string.Empty, (Vector3)d.CachedValue);
                    SetTooltipForRect(rect, d.InspectorTip);

                    if (EditorGUI.EndChangeCheck())
                    {
                        d.Setter(d.DataObject, d.CachedValue);
                    }

                }
                else if (d.Type == typeof(Color))
                {
                    EditorGUI.BeginChangeCheck();
                    GUI.Label(labelArea, d.Name, labelStyle);
                    d.CachedValue = EditorGUI.ColorField(fieldArea, (Color)d.CachedValue);
                    SetTooltipForRect(rect, d.InspectorTip);

                    if (EditorGUI.EndChangeCheck())
                    {
                        d.Setter(d.DataObject, d.CachedValue);
                    }

                }
                else if (d.Type == typeof(Vector4))
                {
                    EditorGUI.BeginChangeCheck();
                    GUI.Label(labelArea, d.Name, labelStyle);
                    d.CachedValue = EditorGUI.Vector4Field(fieldArea, string.Empty, (Vector4)d.CachedValue);
                    SetTooltipForRect(rect, d.InspectorTip);

                    if (EditorGUI.EndChangeCheck())
                    {
                        d.Setter(d.DataObject, d.CachedValue);
                    }
                }
                else if (d.Type == typeof(bool))
                {
                    EditorGUI.BeginChangeCheck();
                    GUI.Label(labelArea, d.Name, labelStyle);
                    d.CachedValue = EditorGUI.Toggle(fieldArea, (bool)d.CachedValue);
                    SetTooltipForRect(rect, d.InspectorTip);

                    if (EditorGUI.EndChangeCheck())
                    {

                        d.Setter(d.DataObject, d.CachedValue);
                    }
                }
                else if (typeof(Enum).IsAssignableFrom(d.Type))
                {
                    EditorGUI.BeginChangeCheck();
                    GUI.Label(labelArea, d.Name, labelStyle);
                    d.CachedValue = EditorGUI.EnumPopup(fieldArea, (Enum)d.CachedValue);
                    SetTooltipForRect(rect, d.InspectorTip);

                    if (EditorGUI.EndChangeCheck())
                    {
                        InvertApplication.Execute(() =>
                        {
                            d.Setter(d.DataObject, d.CachedValue);
                        });

                    }
                }
                else if (d.Type == typeof(Type))
                {
                    //InvertGraphEditor.WindowManager.InitTypeListWindow();
                }
            }

            GUI.color = colorCache;

        }
Exemplo n.º 10
0
        public virtual void DrawInspector(PropertyFieldViewModel d, GUIStyle labelStyle)
        {
            var labelWidth = 140;
            var labelWidtho = GUILayout.ExpandWidth(true);

            var colorCache = GUI.color;
            GUI.color = Color.white;
            if (d.InspectorType == InspectorType.GraphItems)
            {
                var item = d.CachedValue as IGraphItem;
                var text = "--Select--";
                if (item != null)
                {
                    text = item.Label;
                }
                //GUILayout.BeginHorizontal();

                if (GUILayout.Button(d.Label + ": " + text, ElementDesignerStyles.ButtonStyle))
                {
                    var type = d.Type;

                    var items = InvertGraphEditor.CurrentDiagramViewModel.CurrentRepository.AllOf<IGraphItem>().Where(p => type.IsAssignableFrom(p.GetType()));

                    var menu = new SelectionMenu();

                    foreach (var graphItem in items)
                    {
                        var graphItem1 = graphItem;
                        menu.AddItem(new SelectionMenuItem(graphItem, () =>
                        {
                            InvertApplication.Execute(() =>
                            {
                                d.Setter(d.DataObject, graphItem1);
                            });
                        }));
                    }

                    InvertApplication.SignalEvent<IShowSelectionMenu>(_ => _.ShowSelectionMenu(menu));



                    //
                    //                    InvertGraphEditor.WindowManager.InitItemWindow(items, 
                    //                        
                    //                    },true);

                }
                SetTooltipForRect(GUILayoutUtility.GetLastRect(), d.InspectorTip);

                GUI.color = colorCache;
                //GUILayout.EndHorizontal();
                return;
            }


            if (d.Type == typeof(string))
            {
                if (d.InspectorType == InspectorType.TextArea)
                {
                    EditorGUILayout.LabelField(d.Name, labelWidtho);
                    SetTooltipForRect(GUILayoutUtility.GetLastRect(), d.InspectorTip);
                    EditorGUI.BeginChangeCheck();
                    d.CachedValue = EditorGUILayout.TextArea((string)d.CachedValue, GUILayout.Height(50));
                    if (EditorGUI.EndChangeCheck())
                    {
                        d.Setter(d.DataObject, d.CachedValue);

                    }
                    if (Event.current.isKey && Event.current.keyCode == KeyCode.Return)
                    {
                        InvertApplication.Execute(() =>
                        {

                        });
                    }
                }
                else if (d.InspectorType == InspectorType.TypeSelection)
                {
                    GUILayout.BeginHorizontal();
                    //GUILayout.Label(d.ViewModel.Name);

                    if (GUILayout.Button((string)d.CachedValue))
                    {
                        d.NodeViewModel.Select();
                        // TODO 2.0 Open Selection?
                    }
                    SetTooltipForRect(GUILayoutUtility.GetLastRect(), d.InspectorTip);


                    GUILayout.EndHorizontal();
                }

                else
                {
                    EditorGUI.BeginChangeCheck();
                    GUILayout.BeginHorizontal();
                    GUILayout.Label(d.Name, labelStyle);
                    d.CachedValue = EditorGUILayout.TextField((string)d.CachedValue);
                    GUILayout.EndHorizontal();
                    SetTooltipForRect(GUILayoutUtility.GetLastRect(), d.InspectorTip);

                    if (EditorGUI.EndChangeCheck())
                    {
                        d.Setter(d.DataObject, d.CachedValue);
                    }
                }

            }
            else
            {
                if (d.Type == typeof(int))
                {
                    EditorGUI.BeginChangeCheck();
                    GUILayout.BeginHorizontal();
                    GUILayout.Label(d.Name, labelStyle, labelWidtho);
                    d.CachedValue = EditorGUILayout.IntField((int)d.CachedValue);
                    GUILayout.EndHorizontal();
                    SetTooltipForRect(GUILayoutUtility.GetLastRect(), d.InspectorTip);

                    if (EditorGUI.EndChangeCheck())
                    {
                        d.Setter(d.DataObject, d.CachedValue);
                    }
                }
                else if (d.Type == typeof(float))
                {
                    EditorGUI.BeginChangeCheck();
                    GUILayout.BeginHorizontal();
                    GUILayout.Label(d.Name, labelStyle, labelWidtho);
                    d.CachedValue = EditorGUILayout.FloatField((float)d.CachedValue);
                    GUILayout.EndHorizontal();
                    SetTooltipForRect(GUILayoutUtility.GetLastRect(), d.InspectorTip);

                    if (EditorGUI.EndChangeCheck())
                    {
                        d.Setter(d.DataObject, d.CachedValue);
                    }
                }
                else if (d.Type == typeof(Vector2))
                {
                    EditorGUI.BeginChangeCheck();
                    GUILayout.BeginHorizontal();
                    GUILayout.Label(d.Name, labelStyle, labelWidtho);
                    d.CachedValue = EditorGUILayout.Vector2Field(string.Empty, (Vector3)d.CachedValue);
                    GUILayout.EndHorizontal();
                    SetTooltipForRect(GUILayoutUtility.GetLastRect(), d.InspectorTip);

                    if (EditorGUI.EndChangeCheck())
                    {
                        d.Setter(d.DataObject, d.CachedValue);
                    }
                }

                else if (d.Type == typeof(Vector3))
                {
                    EditorGUI.BeginChangeCheck();
                    GUILayout.BeginHorizontal();
                    GUILayout.Label(d.Name, labelStyle, labelWidtho);
                    d.CachedValue = EditorGUILayout.Vector3Field(string.Empty, (Vector3)d.CachedValue);
                    GUILayout.EndHorizontal();
                    SetTooltipForRect(GUILayoutUtility.GetLastRect(), d.InspectorTip);

                    if (EditorGUI.EndChangeCheck())
                    {
                        d.Setter(d.DataObject, d.CachedValue);
                    }

                }
                else if (d.Type == typeof(Color))
                {
                    EditorGUI.BeginChangeCheck();
                    GUILayout.BeginHorizontal();
                    GUILayout.Label(d.Name, labelStyle, labelWidtho);
                    d.CachedValue = EditorGUILayout.ColorField((Color)d.CachedValue);
                    GUILayout.EndHorizontal();
                    SetTooltipForRect(GUILayoutUtility.GetLastRect(), d.InspectorTip);

                    if (EditorGUI.EndChangeCheck())
                    {
                        d.Setter(d.DataObject, d.CachedValue);
                    }

                }
                else if (d.Type == typeof(Vector4))
                {
                    EditorGUI.BeginChangeCheck();
                    GUILayout.BeginHorizontal();
                    GUILayout.Label(d.Name, labelStyle, labelWidtho);
                    d.CachedValue = EditorGUILayout.Vector4Field(string.Empty, (Vector4)d.CachedValue);
                    GUILayout.EndHorizontal();
                    SetTooltipForRect(GUILayoutUtility.GetLastRect(), d.InspectorTip);

                    if (EditorGUI.EndChangeCheck())
                    {
                        d.Setter(d.DataObject, d.CachedValue);
                    }
                }
                else if (d.Type == typeof(bool))
                {
                    EditorGUI.BeginChangeCheck();
                    GUILayout.BeginHorizontal();
                    GUILayout.Label(d.Name, labelStyle, labelWidtho);
                    d.CachedValue = EditorGUILayout.Toggle((bool)d.CachedValue);
                    GUILayout.EndHorizontal();
                    SetTooltipForRect(GUILayoutUtility.GetLastRect(), d.InspectorTip);

                    if (EditorGUI.EndChangeCheck())
                    {
                        d.Setter(d.DataObject, d.CachedValue);
                    }
                }
                else if (typeof(Enum).IsAssignableFrom(d.Type))
                {
                    EditorGUI.BeginChangeCheck();
                    GUILayout.BeginHorizontal();
                    GUILayout.Label(d.Name, labelStyle, labelWidtho);
                    d.CachedValue = EditorGUILayout.EnumPopup((Enum)d.CachedValue);
                    GUILayout.EndHorizontal();
                    SetTooltipForRect(GUILayoutUtility.GetLastRect(), d.InspectorTip);

                    if (EditorGUI.EndChangeCheck())
                    {
                        InvertApplication.Execute(() =>
                        {
                            d.Setter(d.DataObject, d.CachedValue);
                        });

                    }
                }
                else if (d.Type == typeof(Type))
                {
                    //InvertGraphEditor.WindowManager.InitTypeListWindow();
                }
            }

            GUI.color = colorCache;

        }
Exemplo n.º 11
0
 public void DrawPropertyField(Rect r, PropertyFieldViewModel fieldViewModel, float scale)
 {
     //base.Draw(scale);
     //GUILayout.BeginArea(fieldViewModel.Bounds.Scale(scale), ElementDesignerStyles.SelectedItemStyle);
     //EditorGUIUtility.labelWidth = fieldViewModel.Bounds.width * 0.55f;
     DrawInspector(r, fieldViewModel, new GUIStyle(EditorStyles.boldLabel) { normal = new GUIStyleState() { textColor = new Color(0.77f, 0.77f, 0.77f) } });
     //GUILayout.EndArea();
 }
Exemplo n.º 12
0
        public virtual void DrawInspector(Rect rect, PropertyFieldViewModel d, GUIStyle labelStyle)
        {
            var colorCache = GUI.color;

            GUI.color = Color.white;
            var labelArea   = rect.LeftHalf();
            var fieldArea   = rect.RightHalf();
            var labelWidtho = GUILayout.Width(140);

            if (d.InspectorType == InspectorType.GraphItems)
            {
                var item = d.CachedValue as IGraphItem;
                var text = "--Select--";
                if (item != null)
                {
                    text = item.Label;
                }

                if (GUI.Button(rect, d.Label + ": " + text, ElementDesignerStyles.ButtonStyle))
                {
                    var type = d.Type;

                    var items = InvertGraphEditor.CurrentDiagramViewModel.CurrentRepository.AllOf <IGraphItem>().Where(p => type.IsAssignableFrom(p.GetType()));

                    var menu = new SelectionMenu();
                    menu.AddItem(new SelectionMenuItem(string.Empty, "[None]", () =>
                    {
                        InvertApplication.Execute(() =>
                        {
                            d.Setter(d.DataObject, null);
                        });
                    }));
                    foreach (var graphItem in items)
                    {
                        var graphItem1 = graphItem;
                        menu.AddItem(new SelectionMenuItem(graphItem1, () =>
                        {
                            InvertApplication.Execute(() =>
                            {
                                d.Setter(d.DataObject, graphItem1);
                            });
                        }));
                    }

                    InvertApplication.SignalEvent <IShowSelectionMenu>(_ => _.ShowSelectionMenu(menu));
                }
                SetTooltipForRect(rect, d.InspectorTip);

                GUI.color = colorCache;
                return;
            }


            if (d.Type == typeof(string))
            {
                if (d.InspectorType == InspectorType.TextArea)
                {
                    labelArea = rect.WithHeight(17).InnerAlignWithUpperRight(rect);
                    fieldArea = rect.Below(labelArea).Clip(rect).PadSides(2);
                    EditorGUI.LabelField(labelArea, d.Name, labelStyle);
                    SetTooltipForRect(rect, d.InspectorTip);
                    EditorGUI.BeginChangeCheck();
                    d.CachedValue = EditorGUI.TextArea(fieldArea, (string)d.CachedValue, TextWrappingTextArea);
                    if (EditorGUI.EndChangeCheck())
                    {
                        d.Setter(d.DataObject, d.CachedValue);
                    }
                    if (Event.current.isKey && Event.current.keyCode == KeyCode.Return)
                    {
                        InvertApplication.Execute(() =>
                        {
                        });
                    }
                }
                else if (d.InspectorType == InspectorType.TypeSelection)
                {
                    if (GUI.Button(rect, (string)d.CachedValue))
                    {
                        d.NodeViewModel.Select();
                        // TODO 2.0 Open Selection?
                    }
                    SetTooltipForRect(rect, d.InspectorTip);
                }

                else
                {
                    EditorGUI.BeginChangeCheck();
                    EditorGUI.LabelField(labelArea, d.Name, labelStyle);
                    d.CachedValue = EditorGUI.TextField(fieldArea, (string)d.CachedValue);
                    SetTooltipForRect(rect, d.InspectorTip);

                    if (EditorGUI.EndChangeCheck())
                    {
                        d.Setter(d.DataObject, d.CachedValue);
                    }
                }
            }
            else
            {
                if (d.Type == typeof(int))
                {
                    EditorGUI.BeginChangeCheck();
                    GUI.Label(labelArea, d.Name, labelStyle);
                    d.CachedValue = EditorGUI.IntField(fieldArea, (int)d.CachedValue);
                    SetTooltipForRect(rect, d.InspectorTip);

                    if (EditorGUI.EndChangeCheck())
                    {
                        d.Setter(d.DataObject, d.CachedValue);
                    }
                }
                else if (d.Type == typeof(float))
                {
                    EditorGUI.BeginChangeCheck();
                    GUI.Label(labelArea, d.Name, labelStyle);
                    d.CachedValue = EditorGUI.FloatField(fieldArea, (float)d.CachedValue);
                    SetTooltipForRect(rect, d.InspectorTip);

                    if (EditorGUI.EndChangeCheck())
                    {
                        d.Setter(d.DataObject, d.CachedValue);
                    }
                }
                else if (d.Type == typeof(Vector2))
                {
                    EditorGUI.BeginChangeCheck();
                    GUI.Label(labelArea, d.Name, labelStyle);
                    d.CachedValue = EditorGUI.Vector2Field(fieldArea, string.Empty, (Vector2)d.CachedValue);
                    SetTooltipForRect(rect, d.InspectorTip);

                    if (EditorGUI.EndChangeCheck())
                    {
                        d.Setter(d.DataObject, d.CachedValue);
                    }
                }

                else if (d.Type == typeof(Vector3))
                {
                    EditorGUI.BeginChangeCheck();
                    GUI.Label(labelArea, d.Name, labelStyle);
                    d.CachedValue = EditorGUI.Vector3Field(fieldArea, string.Empty, (Vector3)d.CachedValue);
                    SetTooltipForRect(rect, d.InspectorTip);

                    if (EditorGUI.EndChangeCheck())
                    {
                        d.Setter(d.DataObject, d.CachedValue);
                    }
                }
                else if (d.Type == typeof(Color))
                {
                    EditorGUI.BeginChangeCheck();
                    GUI.Label(labelArea, d.Name, labelStyle);
                    d.CachedValue = EditorGUI.ColorField(fieldArea, (Color)d.CachedValue);
                    SetTooltipForRect(rect, d.InspectorTip);

                    if (EditorGUI.EndChangeCheck())
                    {
                        d.Setter(d.DataObject, d.CachedValue);
                    }
                }
                else if (d.Type == typeof(Vector4))
                {
                    EditorGUI.BeginChangeCheck();
                    GUI.Label(labelArea, d.Name, labelStyle);
                    d.CachedValue = EditorGUI.Vector4Field(fieldArea, string.Empty, (Vector4)d.CachedValue);
                    SetTooltipForRect(rect, d.InspectorTip);

                    if (EditorGUI.EndChangeCheck())
                    {
                        d.Setter(d.DataObject, d.CachedValue);
                    }
                }
                else if (d.Type == typeof(bool))
                {
                    EditorGUI.BeginChangeCheck();
                    GUI.Label(labelArea, d.Name, labelStyle);
                    d.CachedValue = EditorGUI.Toggle(fieldArea, (bool)d.CachedValue);
                    SetTooltipForRect(rect, d.InspectorTip);

                    if (EditorGUI.EndChangeCheck())
                    {
                        d.Setter(d.DataObject, d.CachedValue);
                    }
                }
                else if (typeof(Enum).IsAssignableFrom(d.Type))
                {
                    EditorGUI.BeginChangeCheck();
                    GUI.Label(labelArea, d.Name, labelStyle);
                    d.CachedValue = EditorGUI.EnumPopup(fieldArea, (Enum)d.CachedValue);
                    SetTooltipForRect(rect, d.InspectorTip);

                    if (EditorGUI.EndChangeCheck())
                    {
                        InvertApplication.Execute(() =>
                        {
                            d.Setter(d.DataObject, d.CachedValue);
                        });
                    }
                }
                else if (d.Type == typeof(Type))
                {
                    //InvertGraphEditor.WindowManager.InitTypeListWindow();
                }
            }

            GUI.color = colorCache;
        }
Exemplo n.º 13
0
        public virtual void DrawInspector(PropertyFieldViewModel d, GUIStyle labelStyle)
        {
            var labelWidth  = 140;
            var labelWidtho = GUILayout.ExpandWidth(true);

            var colorCache = GUI.color;

            GUI.color = Color.white;
            if (d.InspectorType == InspectorType.GraphItems)
            {
                var item = d.CachedValue as IGraphItem;
                var text = "--Select--";
                if (item != null)
                {
                    text = item.Label;
                }
                //GUILayout.BeginHorizontal();

                if (GUILayout.Button(d.Label + ": " + text, ElementDesignerStyles.ButtonStyle))
                {
                    var type = d.Type;

                    var items = InvertGraphEditor.CurrentDiagramViewModel.CurrentRepository.AllOf <IGraphItem>().Where(p => type.IsAssignableFrom(p.GetType()));

                    var menu = new SelectionMenu();

                    foreach (var graphItem in items)
                    {
                        var graphItem1 = graphItem;
                        menu.AddItem(new SelectionMenuItem(graphItem, () =>
                        {
                            InvertApplication.Execute(() =>
                            {
                                d.Setter(d.DataObject, graphItem1);
                            });
                        }));
                    }

                    InvertApplication.SignalEvent <IShowSelectionMenu>(_ => _.ShowSelectionMenu(menu));



                    //
                    //                    InvertGraphEditor.WindowManager.InitItemWindow(items,
                    //
                    //                    },true);
                }
                SetTooltipForRect(GUILayoutUtility.GetLastRect(), d.InspectorTip);

                GUI.color = colorCache;
                //GUILayout.EndHorizontal();
                return;
            }


            if (d.Type == typeof(string))
            {
                if (d.InspectorType == InspectorType.TextArea)
                {
                    EditorGUILayout.LabelField(d.Name, labelWidtho);
                    SetTooltipForRect(GUILayoutUtility.GetLastRect(), d.InspectorTip);
                    EditorGUI.BeginChangeCheck();
                    d.CachedValue = EditorGUILayout.TextArea((string)d.CachedValue, GUILayout.Height(50));
                    if (EditorGUI.EndChangeCheck())
                    {
                        d.Setter(d.DataObject, d.CachedValue);
                    }
                    if (Event.current.isKey && Event.current.keyCode == KeyCode.Return)
                    {
                        InvertApplication.Execute(() =>
                        {
                        });
                    }
                }
                else if (d.InspectorType == InspectorType.TypeSelection)
                {
                    GUILayout.BeginHorizontal();
                    //GUILayout.Label(d.ViewModel.Name);

                    if (GUILayout.Button((string)d.CachedValue))
                    {
                        d.NodeViewModel.Select();
                        // TODO 2.0 Open Selection?
                    }
                    SetTooltipForRect(GUILayoutUtility.GetLastRect(), d.InspectorTip);


                    GUILayout.EndHorizontal();
                }

                else
                {
                    EditorGUI.BeginChangeCheck();
                    GUILayout.BeginHorizontal();
                    GUILayout.Label(d.Name, labelStyle);
                    d.CachedValue = EditorGUILayout.TextField((string)d.CachedValue);
                    GUILayout.EndHorizontal();
                    SetTooltipForRect(GUILayoutUtility.GetLastRect(), d.InspectorTip);

                    if (EditorGUI.EndChangeCheck())
                    {
                        d.Setter(d.DataObject, d.CachedValue);
                    }
                }
            }
            else
            {
                if (d.Type == typeof(int))
                {
                    EditorGUI.BeginChangeCheck();
                    GUILayout.BeginHorizontal();
                    GUILayout.Label(d.Name, labelStyle, labelWidtho);
                    d.CachedValue = EditorGUILayout.IntField((int)d.CachedValue);
                    GUILayout.EndHorizontal();
                    SetTooltipForRect(GUILayoutUtility.GetLastRect(), d.InspectorTip);

                    if (EditorGUI.EndChangeCheck())
                    {
                        d.Setter(d.DataObject, d.CachedValue);
                    }
                }
                else if (d.Type == typeof(float))
                {
                    EditorGUI.BeginChangeCheck();
                    GUILayout.BeginHorizontal();
                    GUILayout.Label(d.Name, labelStyle, labelWidtho);
                    d.CachedValue = EditorGUILayout.FloatField((float)d.CachedValue);
                    GUILayout.EndHorizontal();
                    SetTooltipForRect(GUILayoutUtility.GetLastRect(), d.InspectorTip);

                    if (EditorGUI.EndChangeCheck())
                    {
                        d.Setter(d.DataObject, d.CachedValue);
                    }
                }
                else if (d.Type == typeof(Vector2))
                {
                    EditorGUI.BeginChangeCheck();
                    GUILayout.BeginHorizontal();
                    GUILayout.Label(d.Name, labelStyle, labelWidtho);
                    d.CachedValue = EditorGUILayout.Vector2Field(string.Empty, (Vector3)d.CachedValue);
                    GUILayout.EndHorizontal();
                    SetTooltipForRect(GUILayoutUtility.GetLastRect(), d.InspectorTip);

                    if (EditorGUI.EndChangeCheck())
                    {
                        d.Setter(d.DataObject, d.CachedValue);
                    }
                }

                else if (d.Type == typeof(Vector3))
                {
                    EditorGUI.BeginChangeCheck();
                    GUILayout.BeginHorizontal();
                    GUILayout.Label(d.Name, labelStyle, labelWidtho);
                    d.CachedValue = EditorGUILayout.Vector3Field(string.Empty, (Vector3)d.CachedValue);
                    GUILayout.EndHorizontal();
                    SetTooltipForRect(GUILayoutUtility.GetLastRect(), d.InspectorTip);

                    if (EditorGUI.EndChangeCheck())
                    {
                        d.Setter(d.DataObject, d.CachedValue);
                    }
                }
                else if (d.Type == typeof(Color))
                {
                    EditorGUI.BeginChangeCheck();
                    GUILayout.BeginHorizontal();
                    GUILayout.Label(d.Name, labelStyle, labelWidtho);
                    d.CachedValue = EditorGUILayout.ColorField((Color)d.CachedValue);
                    GUILayout.EndHorizontal();
                    SetTooltipForRect(GUILayoutUtility.GetLastRect(), d.InspectorTip);

                    if (EditorGUI.EndChangeCheck())
                    {
                        d.Setter(d.DataObject, d.CachedValue);
                    }
                }
                else if (d.Type == typeof(Vector4))
                {
                    EditorGUI.BeginChangeCheck();
                    GUILayout.BeginHorizontal();
                    GUILayout.Label(d.Name, labelStyle, labelWidtho);
                    d.CachedValue = EditorGUILayout.Vector4Field(string.Empty, (Vector4)d.CachedValue);
                    GUILayout.EndHorizontal();
                    SetTooltipForRect(GUILayoutUtility.GetLastRect(), d.InspectorTip);

                    if (EditorGUI.EndChangeCheck())
                    {
                        d.Setter(d.DataObject, d.CachedValue);
                    }
                }
                else if (d.Type == typeof(bool))
                {
                    EditorGUI.BeginChangeCheck();
                    GUILayout.BeginHorizontal();
                    GUILayout.Label(d.Name, labelStyle, labelWidtho);
                    d.CachedValue = EditorGUILayout.Toggle((bool)d.CachedValue);
                    GUILayout.EndHorizontal();
                    SetTooltipForRect(GUILayoutUtility.GetLastRect(), d.InspectorTip);

                    if (EditorGUI.EndChangeCheck())
                    {
                        d.Setter(d.DataObject, d.CachedValue);
                    }
                }
                else if (typeof(Enum).IsAssignableFrom(d.Type))
                {
                    EditorGUI.BeginChangeCheck();
                    GUILayout.BeginHorizontal();
                    GUILayout.Label(d.Name, labelStyle, labelWidtho);
                    d.CachedValue = EditorGUILayout.EnumPopup((Enum)d.CachedValue);
                    GUILayout.EndHorizontal();
                    SetTooltipForRect(GUILayoutUtility.GetLastRect(), d.InspectorTip);

                    if (EditorGUI.EndChangeCheck())
                    {
                        InvertApplication.Execute(() =>
                        {
                            d.Setter(d.DataObject, d.CachedValue);
                        });
                    }
                }
                else if (d.Type == typeof(Type))
                {
                    //InvertGraphEditor.WindowManager.InitTypeListWindow();
                }
            }

            GUI.color = colorCache;
        }
Exemplo n.º 14
0
 /// <param name="displayValueFactor">The internal value is multiplied by this factor when being displayed</param>
 protected void RegisterField(PropertyFieldViewModel field)
 {
     _fields.Add(field);
     LinkPropertyFieldEvents(field);
 }