예제 #1
0
        public TokenDeclaration(Store store, IVariableDeclarationModel model, GraphView graphView)
        {
            m_Pill = new Pill();
            Add(m_Pill);

            if (model is IObjectReference modelReference)
            {
                if (modelReference is IExposeTitleProperty titleProperty)
                {
#if UNITY_2019_3_OR_NEWER
                    m_TitleLabel = m_Pill.Q <Label>("title-label");
#else
                    m_TitleLabel = m_Pill.Q <Label>("title-label").ReplaceWithBoundLabel();
#endif
                    m_TitleLabel.bindingPath = titleProperty.TitlePropertyName;
                }
            }

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

            styleSheets.Add(AssetDatabase.LoadAssetAtPath <StyleSheet>(UICreationHelper.templatePath + "Token.uss"));

            Declaration = model;
            m_Store     = store;
            m_GraphView = graphView;

            m_Pill.icon = Declaration.IsExposed
                ? VisualScriptingIconUtility.LoadIconRequired("GraphView/Nodes/BlackboardFieldExposed.png")
                : null;

            m_Pill.text = Declaration.Title;

            if (model != null)
            {
                capabilities = VseUtility.ConvertCapabilities(model);
            }

            var     variableModel = model as VariableDeclarationModel;
            Stencil stencil       = store.GetState().CurrentGraphModel?.Stencil;
            if (variableModel != null && stencil && variableModel.DataType.IsValid)
            {
                string friendlyTypeName = variableModel.DataType.GetMetadata(stencil).FriendlyName;
                Assert.IsTrue(!string.IsNullOrEmpty(friendlyTypeName));
                tooltip = $"{variableModel.VariableString} declaration of type {friendlyTypeName}";
                if (!string.IsNullOrEmpty(variableModel.Tooltip))
                {
                    tooltip += "\n" + variableModel.Tooltip;
                }
            }

            SetClasses();

            this.EnableRename();

            if (model != null)
            {
                viewDataKey = model.GetId();
            }
        }
        public override void UpdateFromModel()
        {
            base.UpdateFromModel();

            if (TitleLabel != null)
            {
                TitleLabel.Text = "Set";
            }

            var label = m_Pill.Q <Label>("title-label");

            label.text = SetVariableNodeModel.DeclarationModel?.Name ?? "<Pick a variable>";
        }
        public TokenDeclaration(Store store, IVariableDeclarationModel model, GraphView graphView)
        {
            m_Pill = new Pill();
            Add(m_Pill);

            if (model is IObjectReference modelReference)
            {
                if (modelReference is IExposeTitleProperty titleProperty)
                {
                    var titleLabel = m_Pill.Q <Label>("title-label");
                    titleLabel.bindingPath = titleProperty.TitlePropertyName;
                }
            }

            styleSheets.Add(AssetDatabase.LoadAssetAtPath <StyleSheet>(UICreationHelper.templatePath + "Token.uss"));

            Setup(model as IGTFGraphElementModel, store, graphView);

            m_Pill.icon = Declaration.IsExposed
                ? GraphViewStaticBridge.LoadIconRequired("GraphView/Nodes/BlackboardFieldExposed.png")
                : null;

            m_Pill.text = Declaration.Title;

            var     variableModel = model as VariableDeclarationModel;
            Stencil stencil       = store.GetState().CurrentGraphModel?.Stencil;

            if (variableModel != null && stencil != null && variableModel.DataType.IsValid)
            {
                string friendlyTypeName = variableModel.DataType.GetMetadata(stencil).FriendlyName;
                Assert.IsTrue(!string.IsNullOrEmpty(friendlyTypeName));
                tooltip = $"{variableModel.VariableString} declaration of type {friendlyTypeName}";
                if (!string.IsNullOrEmpty(variableModel.Tooltip))
                {
                    tooltip += "\n" + variableModel.Tooltip;
                }
            }

            SetClasses();

            this.EnableRename();

            if (model != null)
            {
                viewDataKey = model.GetId();
            }
        }
예제 #4
0
        public SetVariableNode(SetVariableNodeModel model, Store store, GraphView builderGraphView)
            : base(model, store, builderGraphView)
        {
            // make it clear the ux is not final
            this.Q("title").style.backgroundColor = new StyleColor(new Color32(147, 15, 109, 255));
            this.Q <Label>("title-label").text    = "Set ";

            var pill  = new Pill();
            var label = pill.Q <Label>("title-label");

            label.text = model.DeclarationModel?.Name ?? "<Pick a variable>";

            var pillContainer = new VisualElement();

            pillContainer.AddToClassList("token");
            pillContainer.style.justifyContent = Justify.Center;
            pillContainer.style.flexGrow       = 1;
            pillContainer.Add(pill);

            titleContainer.Insert(1, pillContainer);
            titleContainer.styleSheets.Add(AssetDatabase.LoadAssetAtPath <StyleSheet>(UICreationHelper.templatePath + "Token.uss"));

            pill.RegisterCallback <MouseDownEvent>(_ =>
            {
                SearcherWindow.Show(EditorWindow.focusedWindow, ((VSGraphModel)model.GraphModel).GraphVariableModels.Where(g => GraphBuilder.GetVariableType(g) == GraphBuilder.VariableType.Variable)
                                    .Select(v => (SearcherItem) new VariableSearcherItem(v)).ToList(), "Pick a variable to set", item =>
                {
                    var variableSearcherItem = (item as VariableSearcherItem);
                    if (variableSearcherItem == null)
                    {
                        return(true);
                    }
                    model.DeclarationModel = variableSearcherItem.declarationModel;
                    model.DefineNode();
                    store.Dispatch(new RefreshUIAction(UpdateFlags.GraphTopology));
                    return(true);
                }, Event.current.mousePosition);
            });
        }