public ComponentsSubSection(Stencil stencil,
                                    ComponentQueryDeclarationModel componentQueryDeclarationModel,
                                    Blackboard blackboard)
            : base(SectionTitleText,
                   graphElementModel: null,
                   store: blackboard.Store,
                   parentElement: null,
                   rebuildCallback: null,
                   canAcceptDrop: null)
        {
            m_Stencil = stencil;

            name     = "componentsSection";
            userData = name;

            AddToClassList("subSection");

            int nbRows = 0;

            ExpandedButton.style.display = DisplayStyle.None;
            ExpandableRowTitleContainer.Add(new Button(() => { AddComponentToQuery(componentQueryDeclarationModel); })
            {
                name = "addComponentButton", text = "+"
            });

            componentQueryDeclarationModel.ExpandOnCreateUI = false;

            nbRows += AddRows(componentQueryDeclarationModel, ExpandedContainer);

            viewDataKey = "blackboardComponentsSection";

            Expanded = true;

            SectionTitle.text += " (" + nbRows + ")";
        }
Esempio n. 2
0
        public ComponentQueriesRow(IReadOnlyCollection <ComponentQueryDeclarationModel> componentQueryDeclarationModels,
                                   Blackboard blackboard,
                                   Stencil stencil,
                                   Blackboard.RebuildCallback rebuildCallback)
        {
            AddToClassList("componentQueriesRow");

            styleSheets.Add(AssetDatabase.LoadAssetAtPath <StyleSheet>(UICreationHelper.TemplatePath + "BlackboardECS.uss"));
            // @TODO: This might need to be reviewed in favor of a better / more scalable approach (non preprocessor based)
            // that would ideally bring the same level of backward/forward compatibility and/or removed when a 2013 beta version lands.
#if UNITY_2019_3_OR_NEWER
            styleSheets.Add(AssetDatabase.LoadAssetAtPath <StyleSheet>(UICreationHelper.TemplatePath + "BlackboardECS.2019.3.uss"));
#endif

            IReadOnlyCollection <ComponentQueryDeclarationModel> activeQueryDeclarationModels = componentQueryDeclarationModels;

            State state = blackboard.Store.GetState();

            var componentsSubSection = new ComponentsSubSection(stencil, activeQueryDeclarationModels, blackboard);
            Add(componentsSubSection);
            if (state.EditorDataModel.ShouldExpandBlackboardRowUponCreation($"{BlackboardEcsProviderTypeName}/{componentsSubSection.GetType().Name}"))
            {
                componentsSubSection.Expanded = true;
            }

            var criteriaSubSection = new CriteriaSubSection(stencil, activeQueryDeclarationModels, blackboard);
            Add(criteriaSubSection);
            if (state.EditorDataModel.ShouldExpandBlackboardRowUponCreation($"{BlackboardEcsProviderTypeName}/{criteriaSubSection.GetType().Name}"))
            {
                criteriaSubSection.Expanded = true;
            }

            userData = "ComponentQueriesRow";
        }
Esempio n. 3
0
        public CriteriaSubSection(Stencil stencil,
                                  IReadOnlyCollection <ComponentQueryDeclarationModel> componentQueryDeclarationModels,
                                  Blackboard blackboard)
            : base("Criteria",
                   graphElementModel: null,
                   store: blackboard.Store,
                   parentElement: null,
                   rebuildCallback: null,
                   canAcceptDrop: null)
        {
            m_Stencil    = stencil;
            m_Blackboard = blackboard;

            name     = "criteriaSection";
            userData = name;

            AddToClassList("subSection");

            int nbRows = 0;

            foreach (var componentQueryDeclarationModel in componentQueryDeclarationModels)
            {
                BuildCriteriaForComponentQuery(componentQueryDeclarationModel, ref nbRows, blackboard);
            }

            viewDataKey = "BlackboardCriteriaSection";

            OnExpanded = e => Store.GetState().EditorDataModel?.ExpandBlackboardRowsUponCreation(
                new[] { $"{ComponentQueriesRow.BlackboardEcsProviderTypeName}/{GetType().Name}" }, e);

            SectionTitle.text += " (" + nbRows + ")";
        }
Esempio n. 4
0
        public CriteriaSubSection(Stencil stencil,
                                  ComponentQueryDeclarationModel componentQueryDeclarationModel,
                                  Blackboard blackboard)
            : base(SectionTitleText,
                   graphElementModel: null,
                   store: blackboard.Store,
                   parentElement: null,
                   rebuildCallback: null,
                   canAcceptDrop: null)
        {
            m_Stencil    = stencil;
            m_Blackboard = blackboard;

            name     = "criteriaSection";
            userData = name;

            AddToClassList("subSection");

            ExpandedButton.style.display = DisplayStyle.None;
            int nbRows = 0;

            BuildCriteriaForComponentQuery(componentQueryDeclarationModel, ref nbRows, blackboard);

            viewDataKey = "BlackboardCriteriaSection";

            Expanded = true;

            SectionTitle.text += " (" + nbRows + ")";
        }
Esempio n. 5
0
        public void RebuildSections(Blackboard blackboard)
        {
            m_Blackboard = blackboard;
            m_Store      = blackboard.Store;
            var currentGraphModel = (VSGraphModel)blackboard.Store.GetState().CurrentGraphModel;

            blackboard.ClearContents();

            if (blackboard.Sections != null && blackboard.Sections.Count > 1)
            {
                blackboard.Sections[k_GraphDeclarationsSection].title     = k_GraphDeclarationsSectionTitle;
                blackboard.Sections[k_InputPortDeclarationsSection].title = k_InputPortDeclarationsSectionTitle;
            }

            foreach (VariableDeclarationModel declaration in currentGraphModel.VariableDeclarations)
            {
                var blackboardField = new BlackboardVariableField(blackboard.Store, declaration, blackboard.GraphView);
                var blackboardVariablePropertyView = new DotsVariablePropertyView(blackboard.Store, declaration, blackboard.Rebuild, m_Stencil);
                if (declaration.DataType != TypeHandle.ExecutionFlow)
                {
                    blackboardVariablePropertyView = (DotsVariablePropertyView)blackboardVariablePropertyView.WithLocalInputOutputToggle().WithTypeSelector();
                    if (declaration.IsGraphVariable())
                    {
                        blackboardVariablePropertyView = (DotsVariablePropertyView)blackboardVariablePropertyView.WithInitializationField();
                    }
                }
                blackboardVariablePropertyView = (DotsVariablePropertyView)blackboardVariablePropertyView.WithTooltipField();
                var blackboardRow = new BlackboardRow(
                    blackboardField,
                    blackboardVariablePropertyView)
                {
                    userData = declaration,
                    expanded = true, // TODO not pretty
                };
                if (blackboard.Sections != null)
                {
                    if (declaration.IsInputOrOutputTrigger())
                    {
                        blackboard.Sections[k_InputPortDeclarationsSection].Add(blackboardRow);
                    }
                    else
                    {
                        blackboard.Sections[k_GraphDeclarationsSection].Add(blackboardRow);
                    }
                }
                blackboard.GraphVariables.Add(blackboardField);
            }
        }
Esempio n. 6
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
        }
Esempio n. 7
0
        public IEnumerator Test_BlackboardLocalScopeShowsAllVariablesFromSelection()
        {
            Stencil stencil = GraphModel.Stencil;

            var functionModel     = GraphModel.CreateFunction("function", new Vector2(200, 50));
            var functionVariable  = functionModel.CreateFunctionVariableDeclaration("l", typeof(int).GenerateTypeHandle(stencil));
            var functionParameter = functionModel.CreateAndRegisterFunctionParameterDeclaration("a", typeof(int).GenerateTypeHandle(stencil));

            var stackModel1  = GraphModel.CreateStack("stack1", new Vector2(200, 200));
            var stack1Input  = stackModel1.InputPorts[0];
            var stack1Output = stackModel1.OutputPorts[0];

            var stackModel2 = GraphModel.CreateStack("stack2", new Vector2(200, 400));
            var stack2Input = stackModel2.InputPorts[0];

            Store.Dispatch(new RefreshUIAction(UpdateFlags.All));
            yield return(null);

            Store.Dispatch(new CreateEdgeAction(stack1Input, functionModel.OutputPort));
            yield return(null);

            Store.Dispatch(new CreateEdgeAction(stack2Input, stack1Output));
            yield return(null);

            GraphView.selection.Add(GetGraphElement(5));
            Store.Dispatch(new RefreshUIAction(UpdateFlags.All));
            yield return(null);

            Blackboard blackboard   = GraphView.UIController.Blackboard;
            var        allVariables = GraphView.UIController.GetAllVariableDeclarationsFromSelection(GraphView.selection).ToList();

            Assert.That(allVariables.Find(x => (VariableDeclarationModel)x.Item1 == functionVariable) != null);
            Assert.That(allVariables.Find(x => (VariableDeclarationModel)x.Item1 == functionParameter) != null);

            // Test assumes that section displays
            var blackboardVariableFields = blackboard.Query <BlackboardVariableField>().ToList();

            Assert.That(blackboardVariableFields.Find(x => (VariableDeclarationModel)x.VariableDeclarationModel == functionVariable) != null);
            Assert.That(blackboardVariableFields.Find(x => (VariableDeclarationModel)x.VariableDeclarationModel == functionParameter) != null);
        }
        public QuerySubSection(Stencil stencil,
                               ComponentQueryDeclarationModel componentQueryDeclarationModel,
                               Blackboard blackboard)
            : base("",
                   graphElementModel: null,
                   store: blackboard.Store,
                   parentElement: null,
                   rebuildCallback: null,
                   canAcceptDrop: null)
        {
            name     = "queriesSection";
            userData = name;

            AddToClassList("subSection");
            State state = blackboard.Store.GetState();

            var componentQuery = new ComponentQuery(componentQueryDeclarationModel, Store, blackboard.Rebuild);

            Sortable = true;
            ExpandableRowTitleContainer.AddManipulator(new Clickable(() => {}));
            ExpandableRowTitleContainer.Add(componentQuery);
            ExpandableRowTitleContainer.Add(new Label($"({(componentQueryDeclarationModel.Query?.Components?.Count ?? 0)})")
            {
                name = "count"
            });
            var rowName = $"{ComponentQueriesRow.BlackboardEcsProviderTypeName}/{GetType().Name}/{componentQueryDeclarationModel}";

            OnExpanded += e =>
                          Store.GetState().EditorDataModel?.ExpandBlackboardRowsUponCreation(new[] { rowName }, e);
            if (state.EditorDataModel.ShouldExpandBlackboardRowUponCreation(rowName))
            {
                Expanded = true;
            }

            ExpandedContainer.Add(new ComponentsSubSection(stencil, componentQueryDeclarationModel, blackboard));
            ExpandedContainer.Add(new CriteriaSubSection(stencil, componentQueryDeclarationModel, blackboard));
            blackboard.GraphVariables.Add(componentQuery);
        }
Esempio n. 9
0
        public ComponentQueriesRow(IReadOnlyCollection <ComponentQueryDeclarationModel> componentQueryDeclarationModels,
                                   Blackboard blackboard,
                                   Stencil stencil,
                                   Blackboard.RebuildCallback rebuildCallback)
        {
            AddToClassList("componentQueriesRow");

            styleSheets.Add(AssetDatabase.LoadAssetAtPath <StyleSheet>(UICreationHelper.TemplatePath + "BlackboardECS.uss"));
            // @TODO: This might need to be reviewed in favor of a better / more scalable approach (non preprocessor based)
            // that would ideally bring the same level of backward/forward compatibility and/or removed when a 2013 beta version lands.
#if UNITY_2019_3_OR_NEWER
            styleSheets.Add(AssetDatabase.LoadAssetAtPath <StyleSheet>(UICreationHelper.TemplatePath + "BlackboardECS.2019.3.uss"));
#endif

            IReadOnlyCollection <ComponentQueryDeclarationModel> activeQueryDeclarationModels = componentQueryDeclarationModels;

            foreach (var queryDeclarationModel in activeQueryDeclarationModels)
            {
                var componentQuery = new QuerySubSection(stencil, queryDeclarationModel, blackboard);
                Add(componentQuery);
            }

            userData = "ComponentQueriesRow";
        }
Esempio n. 10
0
 public void DisplayAppropriateSearcher(Vector2 mousePosition, Blackboard blackboard)
 {
     throw new NotImplementedException();
 }
Esempio n. 11
0
        public void RebuildSections(Blackboard blackboard)
        {
            m_Blackboard = blackboard;

            blackboard.styleSheets.Add(k_BlackboardStyleSheet);
            // @TODO: This might need to be reviewed in favor of a better / more scalable approach (non preprocessor based)
            // that would ideally bring the same level of backward/forward compatibility and/or removed when a 2013 beta version lands.
#if UNITY_2019_3_OR_NEWER
            blackboard.styleSheets.Add(AssetDatabase.LoadAssetAtPath <StyleSheet>(UICreationHelper.TemplatePath + "BlackboardECS.2019.3.uss"));
#endif

            // Fetch expanded states as well as active component query toggles (note that this doesn't not apply to
            // elements that do not survive a domain reload)
            var expandedRows = new Dictionary <object, bool>();

            foreach (BlackboardSection blackBoardSection in blackboard.Sections)
            {
                blackBoardSection.Query <ExpandableRow>().ForEach(row =>
                {
                    switch (row.userData)
                    {
                    case IVariableDeclarationModel model:
                        {
                            var queryDeclarationModel = model as ComponentQueryDeclarationModel;
                            bool expanded             = row.Expanded;
                            if (!expanded && queryDeclarationModel != null)
                            {
                                expanded = queryDeclarationModel.ExpandOnCreateUI;
                            }
                            expandedRows[model] = expanded;
                            break;
                        }

                    case string str:
                        expandedRows[str] = row.Expanded;
                        break;
                    }
                });

                blackBoardSection.Query <BlackboardRow>().ForEach(row =>
                {
                    switch (row.userData)
                    {
                    case IVariableDeclarationModel model:
                        expandedRows[model] = row.expanded;
                        break;

                    case Tuple <IVariableDeclarationModel, bool> modelTuple:
                        expandedRows[modelTuple.Item1] = row.expanded;
                        break;
                    }
                });
            }

            List <ISelectable> selectionCopy = blackboard.selection.ToList();

            // TODO: This is too hardcore.  We need to let all unrolling happen smoothly.
            blackboard.ClearContents();

            var state          = blackboard.Store.GetState();
            var graphVariables = ((IVSGraphModel)state.CurrentGraphModel).GraphVariableModels.ToList();

            // Fill component queries section
            var componentQueryDeclarationModels = graphVariables.OfType <ComponentQueryDeclarationModel>().ToList();
            var nbModels = componentQueryDeclarationModels.Count;
            if (nbModels > 0)
            {
                blackboard.Sections[k_ComponentQueriesSection]
                .Add(new ComponentQueriesRow(componentQueryDeclarationModels,
                                             blackboard,
                                             m_Stencil,
                                             blackboard.Rebuild));
                blackboard.Sections[k_ComponentQueriesSection].title = $"{k_ComponentQueriesSectionTitle} ({nbModels})";
            }

            // Fill variables section
            var variables = graphVariables.Where(v => !(v is ComponentQueryDeclarationModel)).ToList();
            blackboard.Sections[k_VariablesSection].title = $"{k_VariableSectionTitle} ({variables.Count})";

            foreach (var variable in variables)
            {
                var blackboardField = new BlackboardVariableField(blackboard.Store, variable, blackboard.GraphView);
                var blackboardRow   = new BlackboardRow(
                    blackboardField,
                    CreateExtendedFieldView(blackboard.Store, variable, m_Stencil, blackboard.Rebuild))
                {
                    userData = variable,
                    expanded = expandedRows.TryGetValue(variable, out var isExpended) && isExpended
                };

                blackboard.Sections[k_VariablesSection].Add(blackboardRow);
                blackboard.GraphVariables.Add(blackboardField);
                blackboard.RestoreSelectionForElement(blackboardField);
            }

            // Fill local scope section
            foreach (Tuple <IVariableDeclarationModel, bool> variableDeclarationModelTuple in blackboard.GraphView.UIController
                     .GetAllVariableDeclarationsFromSelection(selectionCopy))
            {
                var blackboardField = new BlackboardVariableField(blackboard.Store, variableDeclarationModelTuple.Item1, blackboard.GraphView);

                if (variableDeclarationModelTuple.Item1.VariableType == VariableType.FunctionParameter)
                {
                    blackboardField.AddToClassList("parameter");
                }

                if (variableDeclarationModelTuple.Item2)
                {
                    var blackboardRow = new BlackboardRow(blackboardField,
                                                          CreateExtendedFieldView(blackboard.Store,
                                                                                  variableDeclarationModelTuple.Item1,
                                                                                  m_Stencil,
                                                                                  blackboard.Rebuild))
                    {
                        userData = variableDeclarationModelTuple
                    };
                    blackboard.Sections[k_CurrentScopeSection].Add(blackboardRow);
                }
                else
                {
                    blackboardField.AddToClassList("readonly");
                    blackboard.Sections[k_CurrentScopeSection].Add(blackboardField);
                }

                blackboard.GraphVariables.Add(blackboardField);
                blackboard.RestoreSelectionForElement(blackboardField);
            }

            // Apply expanded states for (weak) elements that could not survive a domain reload
            bool expandedValue;
            foreach (BlackboardSection blackBoardSection in blackboard.Sections)
            {
                blackBoardSection.Query <ExpandableRow>().ForEach(row =>
                {
                    var model = row.userData is IVariableDeclarationModel data ? data : null;
                    if (model != null && expandedRows.TryGetValue(model, out expandedValue))
                    {
                        row.Expanded = expandedValue;
                    }
                    else if (row.userData is string str && expandedRows.TryGetValue(str, out expandedValue))
                    {
                        row.Expanded = expandedValue;
                    }
                });

                blackBoardSection.Query <BlackboardRow>().ForEach(row =>
                {
                    if (row.userData is IVariableDeclarationModel model && expandedRows.TryGetValue(model, out expandedValue))
                    {
                        row.expanded = expandedValue;
                    }
Esempio n. 12
0
        public ComponentsSubSection(Stencil stencil,
                                    IReadOnlyCollection <ComponentQueryDeclarationModel> componentQueryDeclarationModels,
                                    Blackboard blackboard)
            : base("Components",
                   graphElementModel: null,
                   store: blackboard.Store,
                   parentElement: null,
                   rebuildCallback: null,
                   canAcceptDrop: null)
        {
            m_Stencil = stencil;

            name     = "componentsSection";
            userData = name;

            AddToClassList("subSection");

            int nbRows = 0;

            State state = blackboard.Store.GetState();

            foreach (var componentQueryDeclarationModel in componentQueryDeclarationModels)
            {
                var componentQuery = new ComponentQuery(componentQueryDeclarationModel, Store, blackboard.Rebuild);

                var componentQueryDeclarationExpandableRow = new ExpandableRow("")
                {
                    name        = "componentsSectionComponentQuery",
                    viewDataKey = "ComponentsSubSection/" + componentQueryDeclarationModel.GetId(),
                    userData    = $"ComponentsSubSection/{componentQueryDeclarationModel.name}",
                };
                componentQueryDeclarationExpandableRow.Sortable = true;
                componentQueryDeclarationExpandableRow.ExpandableRowTitleContainer.AddManipulator(new Clickable(() => {}));
                componentQueryDeclarationExpandableRow.ExpandableRowTitleContainer.Add(componentQuery);
                componentQueryDeclarationExpandableRow.ExpandableRowTitleContainer.Add(new Label($"({(componentQueryDeclarationModel.Query?.Components?.Count ?? 0)})")
                {
                    name = "count"
                });
                componentQueryDeclarationExpandableRow.ExpandableRowTitleContainer.Add(new Button(() => { AddComponentToQuery(componentQueryDeclarationModel); })
                {
                    name = "addComponentButton", text = "+"
                });
                var rowName = $"{ComponentQueriesRow.BlackboardEcsProviderTypeName}/{GetType().Name}/{componentQueryDeclarationModel}";
                componentQueryDeclarationExpandableRow.OnExpanded += e =>
                                                                     Store.GetState().EditorDataModel?.ExpandBlackboardRowsUponCreation(new[] { rowName }, e);
                if (state.EditorDataModel.ShouldExpandBlackboardRowUponCreation(rowName))
                {
                    componentQueryDeclarationExpandableRow.Expanded = true;
                }

                ExpandedContainer.Add(componentQueryDeclarationExpandableRow);
                blackboard.GraphVariables.Add(componentQuery);

                componentQueryDeclarationModel.ExpandOnCreateUI = false;

                nbRows += AddRows(componentQueryDeclarationModel, componentQueryDeclarationExpandableRow.ExpandedContainer);
            }

            viewDataKey = "blackboardComponentsSection";

            OnExpanded = e => Store.GetState().EditorDataModel?.ExpandBlackboardRowsUponCreation(
                new[] { $"{ComponentQueriesRow.BlackboardEcsProviderTypeName}/{GetType().Name}" }, e);

            SectionTitle.text += " (" + nbRows + ")";
        }
Esempio n. 13
0
 void BuildCriteriaForComponentQuery(ComponentQueryDeclarationModel componentQueryDeclarationModel, ref int nbRows, Blackboard blackboard)
 {
     Sortable = true;
     ExpandableRowTitleContainer.AddManipulator(new Clickable(() => {}));
     ExpandableRowTitleContainer.Add(new Button(() => { AddCriteriaModel(componentQueryDeclarationModel); })
     {
         name = "addCriteriaButton", text = "+"
     });
     componentQueryDeclarationModel.ExpandOnCreateUI = false;
     nbRows += AddCriteriaModelRows(componentQueryDeclarationModel, ExpandedContainer);
 }
Esempio n. 14
0
        void BuildCriteriaForComponentQuery(ComponentQueryDeclarationModel componentQueryDeclarationModel, ref int nbRows, Blackboard blackboard)
        {
            var componentQuery = blackboard != null ? new ComponentQuery(componentQueryDeclarationModel,
                                                                         Store,
                                                                         blackboard.Rebuild) :
                                 new ComponentQuery(componentQueryDeclarationModel,
                                                    Store,
                                                    _ => { });

            var componentQueryDeclarationExpandableRow = new ExpandableRow("")
            {
                name        = "componentsSectionComponentQuery",
                viewDataKey = "CriteriaSubSection/" + componentQueryDeclarationModel.GetId(),
                userData    = $"CriteriaSubSection/{componentQueryDeclarationModel.name}",
            };

            componentQueryDeclarationExpandableRow.Sortable = true;
            componentQueryDeclarationExpandableRow.ExpandableRowTitleContainer.AddManipulator(new Clickable(() => { }));
            componentQueryDeclarationExpandableRow.ExpandableRowTitleContainer.Add(componentQuery);
            componentQueryDeclarationExpandableRow.ExpandableRowTitleContainer.Add(new Label("(" + componentQueryDeclarationModel.CriteriaModels.Count + ")")
            {
                name = "count"
            });
            componentQueryDeclarationExpandableRow.ExpandableRowTitleContainer.Add(new Button(() => { AddCriteriaModel(componentQueryDeclarationModel); })
            {
                name = "addCriteriaButton", text = "+"
            });
            var rowName = $"{ComponentQueriesRow.BlackboardEcsProviderTypeName}/{GetType().Name}/{componentQueryDeclarationModel}";

            componentQueryDeclarationExpandableRow.OnExpanded += e => Store.GetState().EditorDataModel?.ExpandBlackboardRowsUponCreation(new[] { rowName }, e);
            State state = blackboard?.Store.GetState();

            if (state != null && state.EditorDataModel.ShouldExpandBlackboardRowUponCreation(rowName))
            {
                componentQueryDeclarationExpandableRow.Expanded = true;
            }

            ExpandedContainer.Add(componentQueryDeclarationExpandableRow);

            blackboard?.GraphVariables.Add(componentQuery);

            componentQueryDeclarationModel.ExpandOnCreateUI = false;

            nbRows += AddCriteriaModelRows(componentQueryDeclarationModel, componentQueryDeclarationExpandableRow.ExpandedContainer);
        }
Esempio n. 15
0
        public CriteriaModelRow(IGraphElementModel graphElementModel,
                                CriteriaModel criteriaModel,
                                Stencil stencil,
                                Store store,
                                Blackboard blackboard,
                                ExpandedContainer parentElement,
                                Action <EventBase> onDeleteCriteriaModel)
            : base(string.Empty,
                   graphElementModel as ComponentQueryDeclarationModel,
                   store,
                   parentElement,
                   rebuildCallback: null,
                   canAcceptDrop: null)
        {
            Sortable = true;

            if (criteriaModel == null)
            {
                throw new ArgumentNullException(nameof(criteriaModel), "criteriaModel should not be null");
            }

            CriteriaModel               = criteriaModel;
            GraphElementModel           = graphElementModel;
            ExpandableGraphElementModel = criteriaModel;

            m_Store = store;

            if (graphElementModel is IIteratorStackModel)
            {
                OnExpanded = e => m_Store.GetState().EditorDataModel?.ExpandElementsUponCreation(new[] { this }, e);
            }
            else if (graphElementModel is ComponentQueryDeclarationModel componentQueryDeclarationModel)
            {
                var expandedRowName =
                    $"{ComponentQueriesRow.BlackboardEcsProviderTypeName}/{typeof(CriteriaSubSection).Name}/{componentQueryDeclarationModel}/{criteriaModel.Name}";

                if (store.GetState().EditorDataModel.ShouldExpandBlackboardRowUponCreation(expandedRowName))
                {
                    Expanded = true;
                }

                OnExpanded = e => Store.GetState().EditorDataModel?.ExpandBlackboardRowsUponCreation(new[] { expandedRowName }, e);
            }

            ClearClassList();
            AddToClassList("criteriaModelRow");

            int nbCriteria = CriteriaModel.Criteria?.Count ?? 0;

            if (nbCriteria > 0)
            {
                if (CriteriaModel.Criteria != null)
                {
                    foreach (var criterion in CriteriaModel.Criteria)
                    {
                        var criterionRow = new CriterionRow(graphElementModel, criteriaModel, criterion, stencil, store, ExpandedContainer, OnDeleteCriterion);
                        ExpandedContainer.Add(criterionRow);
                    }
                }
            }
            else
            {
                ExpandedButton.style.display = DisplayStyle.None;
            }

            var deleteCriteriaModelButton = new Button {
                name = "deleteCriteriaModelIcon"
            };

            deleteCriteriaModelButton.clickable.clickedWithEventInfo += onDeleteCriteriaModel;
            ExpandableRowTitleContainer.Insert(0, deleteCriteriaModelButton);

            var componentContainer = new VisualElement {
                name = "rowFieldContainer"
            };

            userData = $"CriteriaModelRow/{graphElementModel}/{criteriaModel.GetHashCode()}";

            var rowCriteriaModelContainer = new VisualElement {
                name = "rowPillContainer"
            };
            var criteriaModelLabel = new RenamableLabel(criteriaModel,
                                                        criteriaModel.Name,
                                                        store,
                                                        (n) =>
            {
                store.Dispatch(new RenameCriteriaModelAction((ICriteriaModelContainer)GraphElementModel, CriteriaModel, n));
            });

            criteriaModelLabel.MandatoryQ <Label>("label").AddToClassList("criteriaModel");
            rowCriteriaModelContainer.Add(criteriaModelLabel);

            componentContainer.Add(rowCriteriaModelContainer);
            componentContainer.Add(new Button(() => { AddCriterionToCriteriaModel(graphElementModel, criteriaModel); })
            {
                name = "addCriterionButton", text = "+"
            });

            ExpandableRowTitleContainer.Add(componentContainer);

            capabilities |= Capabilities.Selectable | Capabilities.Deletable | Capabilities.Droppable;

            this.AddManipulator(new ContextualMenuManipulator(OnContextualMenuEvent));
        }
Esempio n. 16
0
        public void RebuildSections(Blackboard blackboard)
        {
            VSGraphModel currentGraphModel = (VSGraphModel)blackboard.Store.GetState().CurrentGraphModel;

            Dictionary <IVariableDeclarationModel, bool> expandedRows = new Dictionary <IVariableDeclarationModel, bool>();

            foreach (BlackboardSection blackBoardSection in blackboard.Sections)
            {
                foreach (VisualElement visualElement in blackBoardSection.Children())
                {
                    if (visualElement is BlackboardRow row)
                    {
                        if (row.userData is IVariableDeclarationModel model)
                        {
                            expandedRows[model] = row.expanded;
                        }
                        else if (row.userData is Tuple <IVariableDeclarationModel, bool> modelTuple)
                        {
                            expandedRows[modelTuple.Item1] = row.expanded;
                        }
                    }
                }
            }

            blackboard.ClearContents();

            if (CanDisplayThisToken)
            {
                var thisNodeModel = currentGraphModel.NodeModels.OfType <ThisNodeModel>().FirstOrDefault();
                var thisField     = new BlackboardThisField(blackboard.GraphView, thisNodeModel, currentGraphModel);
                blackboard.Sections[k_MainSection].Add(thisField);
                blackboard.GraphVariables.Add(thisField);
                blackboard.RestoreSelectionForElement(thisField);
            }

            // Fetch all fields from the GraphModel in the main section
            foreach (IVariableDeclarationModel variableDeclarationModel in ((IVSGraphModel)currentGraphModel).GraphVariableModels)
            {
                var blackboardField = new BlackboardVariableField(blackboard.Store, variableDeclarationModel, blackboard.GraphView);
                var blackboardRow   = new BlackboardRow(
                    blackboardField,
                    CreateExtendedFieldView(blackboard.Store, variableDeclarationModel, blackboard.Rebuild))
                {
                    userData = variableDeclarationModel,
                    expanded = expandedRows.TryGetValue(variableDeclarationModel, out var expandedValue) && expandedValue
                };
                blackboard.Sections[k_MainSection].Add(blackboardRow);
                blackboard.GraphVariables.Add(blackboardField);
                blackboard.RestoreSelectionForElement(blackboardField);
            }

            if (blackboard.selection != null)
            {
                // Fill local scope section
                foreach (Tuple <IVariableDeclarationModel, bool> variableDeclarationModelTuple in blackboard.GraphView.UIController
                         .GetAllVariableDeclarationsFromSelection(blackboard.selection))
                {
                    var blackboardField = new BlackboardVariableField(blackboard.Store, variableDeclarationModelTuple.Item1, blackboard.GraphView);

                    if (variableDeclarationModelTuple.Item1.VariableType == VariableType.FunctionParameter)
                    {
                        blackboardField.AddToClassList("parameter");
                    }

                    if (variableDeclarationModelTuple.Item2)
                    {
                        var blackboardRow = new BlackboardRow(
                            blackboardField,
                            CreateExtendedFieldView(blackboard.Store, variableDeclarationModelTuple.Item1, blackboard.Rebuild))
                        {
                            userData = variableDeclarationModelTuple,
                            expanded = expandedRows.TryGetValue(variableDeclarationModelTuple.Item1, out var expandedValue) && expandedValue
                        };
                        blackboard.Sections[k_CurrentScopeVariableDeclarationsSection].Add(blackboardRow);
                    }
                    else
                    {
                        blackboardField.AddToClassList("readonly");
                        blackboard.Sections[k_CurrentScopeVariableDeclarationsSection].Add(blackboardField);
                    }

                    blackboard.GraphVariables.Add(blackboardField);

                    blackboard.RestoreSelectionForElement(blackboardField);
                }
            }
        }