Esempio n. 1
0
        int AddCriteriaModelRows(IIteratorStackModel iteratorStackModel, ExpandedContainer expandedContainer)
        {
            foreach (var criteriaModel in iteratorStackModel.CriteriaModels)
            {
                AddCriteriaModelRow(criteriaModel, iteratorStackModel, expandedContainer);
            }

            return(iteratorStackModel.CriteriaModels.Count);
        }
        int AddRows(ComponentQueryDeclarationModel componentQueryDeclarationModel, ExpandedContainer expandedContainer)
        {
            QueryContainer query = componentQueryDeclarationModel.Query;

            if (query?.RootGroup == null)
            {
                return(0);
            }

            return(AddGroupComponentRows(query, query.RootGroup, expandedContainer, componentQueryDeclarationModel));
        }
Esempio n. 3
0
        void AddCriteriaModelRow(CriteriaModel criteriaModel,
                                 IGraphElementModel graphElementModel,
                                 ExpandedContainer expandedContainer)
        {
            Assert.IsNotNull(expandedContainer);

            expandedContainer.Add(new CriteriaModelRow(graphElementModel,
                                                       criteriaModel,
                                                       m_Stencil,
                                                       Store,
                                                       m_Blackboard,
                                                       expandedContainer,
                                                       OnDeleteCriteriaModel));
        }
        int AddComponentRow(ComponentDefinition component,
                            ComponentQueryDeclarationModel componentQueryDeclarationModel,
                            ExpandedContainer expandedContainer)
        {
            Assert.IsNotNull(expandedContainer);

            expandedContainer.Add(new ComponentRow(componentQueryDeclarationModel,
                                                   component,
                                                   m_Stencil,
                                                   Store,
                                                   expandedContainer,
                                                   OnDeleteComponent,
                                                   OnUsageChanged));

            return(1);
        }
        int AddGroupComponentRows(QueryContainer query, QueryGroup queryRootGroup, ExpandedContainer expandedContainer, ComponentQueryDeclarationModel componentQueryDeclarationModel)
        {
            int nbRows = 0;

            foreach (QueryGroup subGroup in query.GetSubGroups(queryRootGroup))
            {
                nbRows += AddGroupComponentRows(query, subGroup, expandedContainer, componentQueryDeclarationModel);
            }

            foreach (QueryComponent component in query.GetComponentsInQuery(queryRootGroup))
            {
                nbRows += AddComponentRow(component.Component, componentQueryDeclarationModel, expandedContainer);
            }

            return(nbRows);
        }
Esempio n. 6
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);
        }
        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. 8
0
        public ComponentRow(ComponentQueryDeclarationModel componentQueryDeclarationModel,
                            ComponentDefinition component,
                            Stencil stencil,
                            Store store,
                            ExpandedContainer parentElement,
                            Action <EventBase> onDeleteComponent,
                            EventCallback <ChangeEvent <bool> > onUsageChanged)
            : base(string.Empty, componentQueryDeclarationModel, store, parentElement, null, null)
        {
            Component = component;
            m_Stencil = stencil;

            ClearClassList();
            AddToClassList("componentRow");

            var fieldViewContainerTooltip = new StringBuilder();
            var fields   = Component.TypeHandle.Resolve(stencil).GetFields();
            int nbFields = fields.Length;

            if (nbFields > 0)
            {
                int i = 0;
                foreach (var field in fields)
                {
                    var fieldView = new VisualElement {
                        name = "fieldView"
                    };
                    var fieldName     = field.Name + ": ";
                    var fieldTypeName = field.FieldType.Name;
                    fieldView.Add(new Label(fieldName));
                    fieldView.Add(new Label(fieldTypeName));
                    fieldViewContainerTooltip.Append(fieldName + fieldTypeName);
                    i++;
                    if (i < nbFields)
                    {
                        fieldViewContainerTooltip.Append('\n');
                    }
                    ExpandedContainer.Add(fieldView);
                }
            }
            else
            {
                ExpandedButton.style.display = DisplayStyle.None;
            }

            var deleteComponentButton = new Button {
                name = "deleteComponentIcon"
            };

            deleteComponentButton.clickable.clickedWithEventInfo += onDeleteComponent;
            ExpandableRowTitleContainer.Insert(0, deleteComponentButton);

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

            string componentNamespace = component.TypeHandle.GetMetadata(stencil).Namespace;
            string componentName      = component.TypeHandle.ToTypeSyntax(stencil).ToString().Replace(componentNamespace + ".", "");

            userData = $"{GraphElementModel}/{componentName}";

            var rowPillContainer = new VisualElement {
                name = "rowPillContainer"
            };

            var componentPill = new ComponentPill(component, componentName, fieldViewContainerTooltip.ToString());

            rowPillContainer.Add(componentPill);

            componentContainer.Add(rowPillContainer);

            var usageField = new Toggle("Subtract")
            {
                value = component.Subtract
            };

            usageField.AddToClassList("usage");
            usageField.RegisterValueChangedCallback(onUsageChanged);
            componentContainer.Add(usageField);

            ExpandableRowTitleContainer.Add(componentContainer);

            capabilities |= Capabilities.Selectable | Capabilities.Deletable;

            var expandedRowName = $"{ComponentQueriesRow.BlackboardEcsProviderTypeName}/{typeof(ComponentsSubSection).Name}/{componentQueryDeclarationModel}/{componentName}";

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

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

            this.AddManipulator(new ContextualMenuManipulator(OnContextualMenuEvent));
        }
Esempio n. 9
0
        public CriterionRow(IGraphElementModel graphElementModel,
                            CriteriaModel criteriaModel,
                            Criterion criterion,
                            Stencil stencil,
                            Store store,
                            ExpandedContainer parentElement,
                            Action <EventBase> onDeleteCriterion)
            : base(string.Empty, graphElementModel as ComponentQueryDeclarationModel, store, parentElement, null, null)
        {
            GraphElementModel = graphElementModel;
            CriteriaModel     = criteriaModel;
            Criterion         = criterion ?? throw new ArgumentNullException(nameof(criterion), "criterion should not be null");
            ClearClassList();
            AddToClassList("criterionRow");

            capabilities |= Capabilities.Selectable | Capabilities.Deletable;

            styleSheets.Add(AssetDatabase.LoadAssetAtPath <StyleSheet>(UnityEditor.VisualScripting.Editor.UICreationHelper.templatePath + "PropertyField.uss"));

            var deleteCriterionButton = new Button {
                name = "deleteCriterionIcon"
            };

            deleteCriterionButton.clickable.clickedWithEventInfo += onDeleteCriterion;
            ExpandableRowTitleContainer.Insert(0, deleteCriterionButton);

            userData = criterion.GetHashCode();

            var criterionContainer = new VisualElement {
                name = "rowCriterionContainer"
            };

            string criterionNamespace = criterion.ObjectType.GetMetadata(stencil).Namespace;
            string criterionName      = criterion.ObjectType.ToTypeSyntax(stencil).ToString().Replace(criterionNamespace + ".", "");

            var criterionStr = new StringBuilder(criterionName);

            if (criterion.Member.Path.Any())
            {
                criterionStr.Append(" > ");
                criterionStr.Append(string.Join(" > ", criterion.Member.Path));
            }

            var criterionPillContainer = new VisualElement {
                name = "rowPillContainer"
            };
            var criterionPill = new Pill {
                text = criterionStr.ToString()
            };

            criterionPillContainer.Add(criterionPill);

            criterionPillContainer.Add(new Label()
            {
                name = "criterionOperatorKind", text = criterion.Operator.NicifyBinaryOperationKindName(OperatorExtensions.NicifyBinaryOperationKindType.String)
            });

            // TODO SERIALIZATION
//            if (criterion.Value.NodeAssetReference != null)
//                m_WatchedObject = new SerializedObject(criterion.Value.NodeAssetReference);
            m_EditorElement = SetupConstantEditor(criterion.Value);
            var label = m_EditorElement.Q <Label>();

            if (label != null && !EditorNeedsLabel)
            {
                label.style.width = 0;
            }

            criterionPillContainer.Add(m_EditorElement);

            criterionContainer.Add(criterionPillContainer);

            ExpandableRowTitleContainer.Add(criterionContainer);

            // CriterionRow's are NOT expandable (for now, until we find a reason to) but since we need everything
            // else that is provided by SortableExpandableRow, we'll just disable expansion altogether
            ExpandedButton.style.display = DisplayStyle.None;

            RegisterCallback <AttachToPanelEvent>(OnAttachToPanel);
            RegisterCallback <DetachFromPanelEvent>(OnDetachFromPanel);

            this.AddManipulator(new ContextualMenuManipulator(OnContextualMenuEvent));
        }
Esempio n. 10
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. 11
0
        int AddCriteriaModelRows(ComponentQueryDeclarationModel componentQueryDeclarationModel, ExpandedContainer expandedContainer)
        {
            foreach (var criteriaModel in componentQueryDeclarationModel.CriteriaModels)
            {
                AddCriteriaModelRow(criteriaModel, componentQueryDeclarationModel, expandedContainer);
            }

            return(componentQueryDeclarationModel.CriteriaModels.Count);
        }
Esempio n. 12
0
 void BuildCriteriaForIteratorStackModel(ref int nbRows, IIteratorStackModel iteratorStackModel, ExpandedContainer expandedContainer)
 {
     nbRows += AddCriteriaModelRows(iteratorStackModel, expandedContainer);
 }
Esempio n. 13
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));
        }