public void Execute(SelectTypeCommand command) { var menu = new SelectionMenu(); if (command.AllowNoneType) { menu.AddItem(new SelectionMenuItem("", "None", () => { command.Item.RelatedType = null; })); } // var types = GetRelatedTypes(command).ToArray(); foreach (var item in GetRelatedTypes(command)) { var type1 = item; if (command.Filter == null || command.Filter(item)) { menu.AddItem(new SelectionMenuItem(item.Group, TypedItemViewModel.TypeAlias(item.TypeName), () => { var record = type1 as IDataRecord; if (record != null) { command.Item.RelatedType = record.Identifier; } else { // TODO: Change RelatedType from FullName to TypeName, not sure if there is any bug command.Item.RelatedType = type1.TypeName;//type1.FullName; } if (command.OnSelectionFinished != null) { command.OnSelectionFinished(); } })); } } if (!command.AllowNoneType) { menu.OnCancel = () => { if (String.IsNullOrEmpty(command.Item.RelatedType)) { command.Item.Node.Repository.Remove(command.Item); } }; } Signal <IShowSelectionMenu>(_ => _.ShowSelectionMenu(menu)); }
public void QueryPossibleConnections(SelectionMenu menu, DiagramViewModel diagramViewModel, ConnectorViewModel startConnector, Vector2 mousePosition) { if (startConnector.ConnectorForType == typeof(ElementNode)) { menu.Items.Clear(); var vm = InvertGraphEditor.CurrentDiagramViewModel; var category = new SelectionMenuCategory() { Title = "Connect" }; menu.AddItem(category); menu.AddItem(new SelectionMenuItem("Connect", "Create View Node and Connect to : Element", () => { ViewNode viewNode = new ViewNode(); viewNode.Name = String.Format("{0}View", vm.Title); vm.AddNode(viewNode, vm.LastMouseEvent.LastMousePosition); diagramViewModel.GraphData.AddConnection(startConnector.ConnectorFor.DataObject as IConnectable, viewNode.ElementInputSlot); }), category); ElementNode elementNode = (ElementNode)startConnector.ConnectorFor.InputConnector.DataObject; if (elementNode.BaseNode != null) { ViewNode firstBaseViewNode = diagramViewModel.GraphData.Repository.All <ViewNode>() .FirstOrDefault(graphViewNode => { return(graphViewNode.Element == elementNode.BaseNode); }); if (firstBaseViewNode != null) { menu.AddItem(new SelectionMenuItem("Connect", "Create Inherited View Node and Connect to : Element", () => { ViewNode viewNode = new ViewNode(); viewNode.Name = String.Format("{0}View", vm.Title); vm.AddNode(viewNode, vm.LastMouseEvent.LastMousePosition); diagramViewModel.GraphData.AddConnection(startConnector.ConnectorFor.DataObject as IConnectable, viewNode.ElementInputSlot); diagramViewModel.GraphData.AddConnection(firstBaseViewNode, viewNode); IFilterItem viewNodeFilterItem = diagramViewModel.GraphData.CurrentFilter.FilterItems.First(item => item.Node == viewNode); diagramViewModel.GraphData.CurrentFilter.ShowInFilter(firstBaseViewNode, viewNodeFilterItem.Position - new Vector2(250, 0)); }), category); } } } }
public void SelectItem() { var menu = new SelectionMenu(); menu.AddItem(new SelectionMenuItem(string.Empty, "[None]", () => { ReferenceItem.SetInput(null); })); menu.ConvertAndAdd(ReferenceItem.GetAllowed().OfType <IItem>(), _ => { var item = _ as IValueItem; if (item == null) { return; } if (IsInput) { ReferenceItem.SetInput(item); } else { ReferenceItem.SetOutput(item); } }); InvertApplication.SignalEvent <IShowSelectionMenu>(_ => _.ShowSelectionMenu(menu)); //InvertGraphEditor.WindowManager.InitItemWindow(ReferenceItem.GetAllowed().ToArray(), _ => //{ // InvertApplication.Execute(new LambdaCommand("Set Item", () => // { // })); //}); }
public void Execute(SelectTypeCommand command) { var menu = new SelectionMenu(); if (command.AllowNone) { menu.AddItem(new SelectionMenuItem("", "None", () => { command.Item.RelatedType = null; })); } // var types = GetRelatedTypes(command).ToArray(); foreach (var item in GetRelatedTypes(command)) { var type1 = item; if (command.Filter == null || command.Filter(item)) { menu.AddItem(new SelectionMenuItem(item, () => { var record = type1 as IDataRecord; if (record != null) { command.Item.RelatedType = record.Identifier; } else { // TODO: Change RelatedType from FullName to TypeName, not sure if there is any bug command.Item.RelatedType = type1.TypeName;//type1.FullName; } if (command.OnSelectionFinished != null) { command.OnSelectionFinished(); } })); } } Signal <IShowSelectionMenu>(_ => _.ShowSelectionMenu(menu)); }
public void QueryPossibleConnections(SelectionMenu menu, DiagramViewModel diagramViewModel, ConnectorViewModel startConnector, Vector2 mousePosition) { if (startConnector.ConnectorForType.FullName == typeof(ElementNode).FullName) { menu.Items.Clear(); var vm = InvertGraphEditor.CurrentDiagramViewModel; var category = new SelectionMenuCategory() { Title = "Connect" }; menu.AddItem(category); menu.AddItem(new SelectionMenuItem("Connect", "Create View Node and Connect to : Element", () => { ViewNode viewNode = new ViewNode(); vm.AddNode(viewNode, vm.LastMouseEvent.LastMousePosition); diagramViewModel.GraphData.AddConnection(startConnector.ConnectorFor.DataObject as IConnectable, viewNode.ElementInputSlot); }), category); } }
public void Execute(ChangeHandlerEventCommand command) { var selectionMenu = new SelectionMenu(); foreach (var item in uFrameECS.Events) { var item1 = item; selectionMenu.AddItem(new SelectionMenuItem(item.Value, () => { command.Node.MetaType = item1.Value.FullName; })); } Signal <IShowSelectionMenu>(_ => _.ShowSelectionMenu(selectionMenu)); }
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; }
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; }
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; }
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; }
public void QueryPossibleConnections(SelectionMenu menu, DiagramViewModel diagramViewModel, ConnectorViewModel startConnector, Vector2 mousePosition) { var currentGraph = InvertApplication.Container.Resolve <WorkspaceService>().CurrentWorkspace.CurrentGraph; var allowedFilterNodes = FilterExtensions.AllowedFilterNodes[currentGraph.CurrentFilter.GetType()]; foreach (var item in allowedFilterNodes) { if (item.IsInterface) { continue; } if (item.IsAbstract) { continue; } //if(item.FullName == "uFrame.MVVM.ViewNode") continue; var node = Activator.CreateInstance(item) as IDiagramNode; node.Repository = diagramViewModel.CurrentRepository; node.GraphId = currentGraph.Identifier; var vm = InvertGraphEditor.Container.GetNodeViewModel(node, diagramViewModel) as DiagramNodeViewModel; if (vm == null) { continue; } vm.IsCollapsed = false; var connectors = new List <ConnectorViewModel>(); vm.GetConnectors(connectors); var config = InvertGraphEditor.Container.Resolve <NodeConfigBase>(item.Name); var name = config == null ? item.Name : config.Name; foreach (var connector in connectors) { foreach (var strategy in InvertGraphEditor.ConnectionStrategies) { var connection = strategy.Connect(diagramViewModel, startConnector, connector); if (connection == null) { continue; } var node1 = node; var message = string.Format("Create {0}", name); //if (!string.IsNullOrEmpty(connector.Name)) //{ // message += string.Format(" and connect to {0}", connector.Name); //} var value = new KeyValuePair <IDiagramNode, ConnectionViewModel>(node1, connection); var qaItem = new SelectionMenuItem("Connect", message, () => { diagramViewModel.AddNode(value.Key, mousePosition); connection.Apply(value.Value as ConnectionViewModel); value.Key.IsSelected = true; value.Key.IsEditing = true; value.Key.Name = ""; }); menu.AddItem(qaItem); } } } }