Ejemplo n.º 1
0
        void OnSearchInGraph()
        {
            Vector3 pos   = m_GraphView.viewTransform.position;
            Vector3 scale = m_GraphView.viewTransform.scale;

            SearcherService.FindInGraph(this, (VSGraphModel)m_Store.GetState().CurrentGraphModel,
                                        // when highlighting an entry
                                        item => m_GraphView.UIController.UpdateViewTransform(item),
                                        // when pressing enter/double clicking on an entry
                                        i =>
            {
                if (i == null)     // cancelled by pressing escape, no selection, reset view
                {
                    m_GraphView.UpdateViewTransform(pos, scale);
                }
            });
        }
Ejemplo n.º 2
0
        internal static void DisplayFunctionVariableSearcher(Button addButton, Vector2 pos)
        {
            var functionNode = addButton.GetFirstOfType <FunctionNode>();

            if (functionNode == null)
            {
                return;
            }

            Stencil stencil = functionNode.Store.GetState().CurrentGraphModel.Stencil;

            SearcherService.ShowTypes(stencil, pos,
                                      (t, i) =>
            {
                functionNode.CreateFunctionField(t, FunctionNode.SupportedFields.Variable);
            });
        }
Ejemplo n.º 3
0
        public void DisplayAppropriateSearcher(Vector2 mousePosition, Blackboard blackboard)
        {
            VisualElement picked = blackboard.panel.Pick(mousePosition);

            while (picked != null && !(picked is IVisualScriptingField || picked is ICustomSearcherHandler))
            {
                picked = picked.parent;
            }

            // optimization: stop at the first IVsBlackboardField, but still exclude BlackboardThisFields
            if (picked != null)
            {
                if (picked is BlackboardVariableField field)
                {
                    SearcherService.ShowTypes(
                        m_Stencil,
                        Event.current.mousePosition,
                        (t, i) =>
                    {
                        var variableDeclarationModel = (VariableDeclarationModel)field.VariableDeclarationModel;
                        blackboard.Store.Dispatch(new UpdateTypeAction(variableDeclarationModel, t));
                        blackboard.Rebuild(Blackboard.RebuildMode.BlackboardAndGraphView);
                    });
                }
                else if (picked is ComponentQuery query)
                {
                    var componentsSubSection = picked.GetFirstAncestorOfType <ComponentsSubSection>();
                    if (componentsSubSection != null)
                    {
                        componentsSubSection.AddComponentToQuery(query.ComponentQueryDeclarationModel);
                    }
                    else
                    {
                        var criteriaSubSection = picked.GetFirstAncestorOfType <CriteriaSubSection>();
                        criteriaSubSection?.AddCriteriaModel(query.ComponentQueryDeclarationModel);
                    }
                }
                else if (picked is ICustomSearcherHandler customSearcherHandler)
                {
                    customSearcherHandler.HandleCustomSearcher(mousePosition);
                }
            }

            // Else do nothing for now, we don't have a default action for the ECS blackboard
        }
Ejemplo n.º 4
0
        public static VisualElement BuildEnumEditor(this IConstantEditorBuilder builder, EnumConstantNodeModel enumConstant)
        {
            var enumEditor = new Button {
                text = enumConstant.EnumValue.ToString()
            };                                                                        // TODO use a bindable element

            enumEditor.clickable.clickedWithEventInfo += e =>
            {
                SearcherService.ShowEnumValues("Pick a value", enumConstant.EnumType.Resolve(enumConstant.GraphModel.Stencil), e.originalMousePosition, (v, i) =>
                {
                    enumConstant.value.Value = Convert.ToInt32(v);
                    enumEditor.text          = v.ToString();
                    builder.OnValueChanged?.Invoke(null);
                });
            };
            enumEditor.SetEnabled(!enumConstant.IsLocked);
            return(enumEditor);
        }
 public static GraphElement CreateUnaryOperator(this INodeBuilder builder, Store store, UnaryOperatorNodeModel model)
 {
     return(new Node(model, store, builder.GraphView)
     {
         CustomSearcherHandler = (node, nStore, pos, _) =>
         {
             SearcherService.ShowEnumValues("Pick a new operator type", typeof(UnaryOperatorKind), pos, (pickedEnum, __) =>
             {
                 if (pickedEnum != null)
                 {
                     ((UnaryOperatorNodeModel)node.model).Kind = (UnaryOperatorKind)pickedEnum;
                     nStore.Dispatch(new RefreshUIAction(UpdateFlags.GraphTopology));
                 }
             });
             return true;
         }
     });
 }
 public void AddComponentToQuery(ComponentQueryDeclarationModel componentQueryDeclarationModel)
 {
     SearcherService.ShowTypes(
         m_Stencil,
         Event.current.mousePosition, (t, i) =>
     {
         var resolvedType = t.Resolve(m_Stencil);
         ComponentDefinitionFlags creationFlags =
             (typeof(ISharedComponentData).IsAssignableFrom(resolvedType))
                 ? ComponentDefinitionFlags.Shared
                 : 0;
         Store.Dispatch(new AddComponentToQueryAction(componentQueryDeclarationModel,
                                                      t,
                                                      creationFlags));
     },
         GetComponentsSearcherFilter(m_Stencil)
         );
 }
Ejemplo n.º 7
0
        protected override void ShowSearcher(Vector2 mousePosition, INodeModel nodeModel,
                                             Action <MathGenericNode.MathGeneratedNodeSerializable> notifyChanged)
        {
            var currentMethodName = Target.Function.GetMethodsSignature().OpType;
            var opSignatures      = MathOperationsMetaData.MethodsByName[currentMethodName];

            void OnValuePicked(string s, int i)
            {
                if (MathOperationsMetaData.EnumForSignature.TryGetValue(opSignatures[i], out var value))
                {
                    notifyChanged(new MathGenericNode.MathGeneratedNodeSerializable {
                        Function = value
                    });
                }
            }

            SearcherService.ShowValues("Types", opSignatures.Select(OpTitle), mousePosition, OnValuePicked);
        }
Ejemplo n.º 8
0
        public BlackboardVariablePropertyView WithTypeSelector()
        {
            var typeButton = new Button(() =>
                                        SearcherService.ShowTypes(
                                            m_Stencil,
                                            Event.current.mousePosition,
                                            (t, i) => OnTypeChanged(t)
                                            )
                                        )
            {
                text = TypeText
            };

            typeButton.AddToClassList("rowButton");
            AddRow("Type", typeButton);

            return(this);
        }
Ejemplo n.º 9
0
        public async Task Setup()
        {
            SearcherService = new SearcherService();
            SearchModels    = new List <SearchModel>
            {
                new()
                {
                    Type = SearchType.Fulltext,
                    Key  = "Text",
                    Term = "parent mission"
                }
            };

            if (!Directory.Exists(_path))
            {
                Data.SetData(IndexModel);
                await Data.SetDataAndDirectoriesForTestGetOperation();
            }
        }
Ejemplo n.º 10
0
        public static IGraphElement CreateUnaryOperator(this ElementBuilder elementBuilder, IStore store, UnaryOperatorNodeModel model)
        {
            var ui = new Node();

            ui.Setup(model, store, elementBuilder.GraphView);
            ui.CustomSearcherHandler = (node, nStore, pos, _) =>
            {
                SearcherService.ShowEnumValues("Pick a new operator type", typeof(UnaryOperatorKind), pos, (pickedEnum, __) =>
                {
                    if (pickedEnum != null)
                    {
                        ((UnaryOperatorNodeModel)node.NodeModel).Kind = (UnaryOperatorKind)pickedEnum;
                        nStore.Dispatch(new RefreshUIAction(UpdateFlags.GraphTopology));
                    }
                });
                return(true);
            };
            return(ui);
        }
Ejemplo n.º 11
0
        public static VisualElement BuildStringWrapperEditor(this IConstantEditorBuilder builder, IStringWrapperConstantModel icm)
        {
            var enumEditor = new Button {
                text = icm.ObjectValue.ToString()
            };                                                                 // TODO use a bindable element

            enumEditor.clickable.clickedWithEventInfo += e =>
            {
                List <string> allInputNames = icm.GetAllInputNames();
                SearcherService.ShowValues("Pick a value", allInputNames, e.originalMousePosition, (v, pickedIndex) =>
                {
                    icm.SetValueFromString(v);
                    enumEditor.text = v;
                    builder.OnValueChanged?.Invoke(null);
                });
            };
            enumEditor.SetEnabled(!icm.IsLocked);
            return(enumEditor);
        }
Ejemplo n.º 12
0
        public virtual void CreateNodesFromPort(Store store, IPortModel portModel, Vector2 localPosition, Vector2 worldPosition,
                                                IEnumerable <IGTFEdgeModel> edgesToDelete, IStackModel stackModel, int index)
        {
            switch (portModel.PortType)
            {
            case PortType.Data:
            case PortType.Instance:
                switch (portModel.Direction)
                {
                case Direction.Output when stackModel != null:
                    if (portModel.DataTypeHandle != TypeHandle.Unknown)
                    {
                        SearcherService.ShowOutputToStackNodes(
                            store.GetState(), stackModel, portModel, worldPosition, item =>
                        {
                            store.Dispatch(new CreateStackedNodeFromOutputPortAction(
                                               portModel, stackModel, index, item, edgesToDelete));
                        });
                    }
                    break;

                case Direction.Output:
                    SearcherService.ShowOutputToGraphNodes(store.GetState(), portModel, worldPosition, item =>
                                                           store.Dispatch(new CreateNodeFromOutputPortAction(portModel, localPosition, item, edgesToDelete)));
                    break;

                case Direction.Input:
                    SearcherService.ShowInputToGraphNodes(store.GetState(), portModel, worldPosition, item =>
                                                          store.Dispatch(new CreateNodeFromInputPortAction(portModel, localPosition, item, edgesToDelete)));
                    break;

                default:
                    throw new ArgumentOutOfRangeException();
                }
                break;

            case PortType.Execution:
                store.Dispatch(new CreateNodeFromExecutionPortAction(portModel, localPosition, edgesToDelete));
                break;
            }
        }
Ejemplo n.º 13
0
        public static void TypeEditor(this Stencil stencil, TypeHandle typeHandle, Action <TypeHandle, int> onSelection,
                                      SearcherFilter filter = null, TypeOptions options = TypeOptions.None)
        {
            var wasArray             = typeHandle.IsVsArrayType(stencil);
            var missingTypeReference = TypeHandle.MissingType;

            EditorGUILayout.BeginHorizontal();
            EditorGUILayout.PrefixLabel("Type");

            var selected = EditorGUILayout.DropdownButton(new GUIContent(typeHandle != missingTypeReference ? typeHandle.GetMetadata(stencil).FriendlyName : "<unknown type>"), FocusType.Passive, GUI.skin.button);

            if (Event.current.type == EventType.Repaint)
            {
                s_ButtonRect = GUILayoutUtility.GetLastRect();
            }

            if (selected)
            {
                SearcherService.ShowTypes(
                    stencil,
                    EditorWindow.focusedWindow.rootVisualElement.LocalToWorld(s_ButtonRect.center),
                    (t, i) => onSelection(wasArray ? t.MakeVsArrayType(stencil) : t, i),
                    filter
                    );
            }
            EditorGUILayout.EndHorizontal();

            if (!options.HasFlag(TypeOptions.AllowArray))
            {
                return;
            }

            var newIsArray = EditorGUILayout.Toggle("Is Array", wasArray);

            if (newIsArray != wasArray)
            {
                onSelection(newIsArray ? typeHandle.MakeVsArrayType(stencil) : typeHandle.GetVsArrayElementType(stencil), 0);
            }
        }
Ejemplo n.º 14
0
        internal void DisplayTokenDeclarationSearcher(VariableDeclarationModel declaration, Vector2 pos)
        {
            if (m_Store.GetState().CurrentGraphModel == null || !declaration.Capabilities.HasFlag(CapabilityFlags.Modifiable))
            {
                return;
            }

            SearcherService.ShowTypes(
                m_Store.GetState().CurrentGraphModel.Stencil,
                pos,
                (t, i) =>
            {
                var graphModel       = (VSGraphModel)m_Store.GetState().CurrentGraphModel;
                declaration.DataType = t;

                foreach (var usage in graphModel.FindUsages(declaration))
                {
                    usage.UpdateTypeFromDeclaration();
                }

                RefreshUI(UpdateFlags.All);
            });
        }
Ejemplo n.º 15
0
            public VisitStatus Visit <TProperty, TContainer>(IPropertyVisitor visitor, TProperty property, ref TContainer container, ref TypeHandle value, ref ChangeTracker changeTracker) where TProperty : IProperty <TContainer, TypeHandle>
            {
                if (!property.Attributes.HasAttribute <TypeSearcherAttribute>())
                {
                    return(VisitStatus.Unhandled);
                }

                if (m_EditedModel == m_HighLevelNodeImguiVisitor.model && m_Picked != default)
                {
                    value         = m_Picked;
                    m_Picked      = default;
                    m_EditedModel = null;
                    changeTracker.MarkChanged();
                }

                var attribute = property.Attributes.GetAttribute <TypeSearcherAttribute>();
                var model     = m_HighLevelNodeImguiVisitor.model;
                var stencil   = model.GraphModel.Stencil;

                var friendlyName = value.GetMetadata(stencil).FriendlyName;

                EditorGUILayout.BeginHorizontal();
                EditorGUILayout.PrefixLabel(property.GetName());

                if (GUILayout.Button(friendlyName))
                {
                    m_EditedModel = model;
                    var mousePosition = GUILayoutUtility.GetLastRect().center; // /*mainContainer.LocalToWorld*/(Event.current.mousePosition);
                    void Callback(TypeHandle type, int index) => m_Picked = type;

                    SearcherService.ShowTypes(stencil, mousePosition, Callback, attribute.Filter?.GetFilter(model));
                }

                EditorGUILayout.EndHorizontal();

                return(VisitStatus.Handled);
            }
Ejemplo n.º 16
0
        internal void DisplayPropertySearcher(PropertyGroupBaseNodeModel model, Vector2 displayAtPosition)
        {
            var items = PropertyGroupSearcherAdapter.GetPropertySearcherItems(model, 4)?.ToList();

            if (items == null)
            {
                return;
            }

            var adapter = new PropertyGroupSearcherAdapter(m_Store, model);

            SearcherService.ShowTransientData(this, items, adapter,
                                              item =>
            {
                if (item == null)
                {
                    return;
                }

                PropertyElement propertyElement = ((PropertySearcherItem)item).Element;
                adapter.EditModel(!propertyElement.Toggle.value, propertyElement.Item);
            },
                                              displayAtPosition);
        }
Ejemplo n.º 17
0
        internal void DisplayAddVariableSearcher(Vector2 pos)
        {
            if (m_Store.GetState().CurrentGraphModel == null)
            {
                return;
            }

            SearcherService.ShowTypes(
                m_Store.GetState().CurrentGraphModel.Stencil,
                pos,
                (t, i) =>
            {
                Focus();

                VSGraphModel graphModel = (VSGraphModel)m_Store.GetState().CurrentGraphModel;
                VariableDeclarationModel declaration = graphModel.CreateGraphVariableDeclaration(
                    "newVariable",
                    t,
                    true
                    );
                DataModel.ElementModelToRename = declaration;
                RefreshUI(UpdateFlags.All);
            });
        }
Ejemplo n.º 18
0
        public EventPropagation DisplayAppropriateSearcher()
        {
            if (m_GraphView.panel == null)
            {
                return(EventPropagation.Continue);
            }

            var selectedToken = m_GraphView.selection?.OfType <Token>().ToList();

            if (selectedToken?.Any() == true)
            {
                var latestSelectedToken = selectedToken.LastOrDefault();
                if (!(latestSelectedToken?.output.userData is IPortModel portModel))
                {
                    return(EventPropagation.Continue);
                }

                Vector2 pos = Event.current.mousePosition;
                SearcherService.ShowOutputToGraphNodes(m_Store.GetState(), portModel, pos, item =>
                {
                    m_Store.Dispatch(new CreateNodeFromOutputPortAction(portModel, pos, item));
                });
            }
            else if (m_GraphView.lastHoveredVisualElement != null)
            {
                var addButton = m_GraphView.lastHoveredVisualElement.GetFirstOfType <Button>();
                if (addButton != null && addButton.name == FunctionNode.AddButtonName)
                {
                    DisplayFunctionVariableSearcher(addButton, Event.current.mousePosition);
                    return(EventPropagation.Continue);
                }

                var customSearcherHandler = m_GraphView.lastHoveredVisualElement?.GetFirstOfType <ICustomSearcherHandler>();
                if (customSearcherHandler != null && customSearcherHandler.HandleCustomSearcher(Event.current.mousePosition))
                {
                    return(EventPropagation.Continue);
                }

                // TODO this is bad: need GV refactor to introduce an interface for the types we want to whitelist
                if (!(m_GraphView.lastHoveredVisualElement is Node node))
                {
                    // In case of lastHoveredVisualElement is Label or Port
                    node = m_GraphView.lastHoveredVisualElement.GetFirstOfType <Node>();
                }

                if (node != null)
                {
                    // TODO: that's terrible
                    if (node.GraphElementModel is PropertyGroupBaseNodeModel model)
                    {
                        DisplayPropertySearcher(model, Event.current.mousePosition);
                    }
                    else
                    {
                        DisplaySmartSearch();
                    }

                    return(EventPropagation.Continue);
                }

                var tokenDeclaration = m_GraphView.lastHoveredVisualElement.GetFirstOfType <TokenDeclaration>();
                if (tokenDeclaration != null)
                {
                    DisplayTokenDeclarationSearcher((VariableDeclarationModel)tokenDeclaration.Declaration, Event.current.mousePosition);
                }
                else
                {
                    DisplaySmartSearch();
                }
            }

            return(EventPropagation.Continue);
        }
Ejemplo n.º 19
0
 public SearchController(SearcherService searcher,
                         ILogger <SearchController> logger)
 {
     _searcher = searcher;
     _logger   = logger;
 }
 protected override void ShowSearcher(Stencil stencil, Vector2 position, IProperty property, TypeHandle currentValue)
 {
     SearcherService.ShowTypes(stencil, position, (type, unknown) => m_Picked = type, MakeSearcherAdapterForProperty(property, VisitorModel));
 }