public virtual void UpdateUI()
        {
            VSPreferences prefs     = m_Store.GetState().Preferences;
            bool          isEnabled = m_Store.GetState().CurrentGraphModel != null;

            UpdateCommonMenu(prefs, isEnabled);
            UpdateBreadcrumbMenu(isEnabled);
        }
Exemple #2
0
        protected virtual void UpdateCommonMenu(VSPreferences prefs, bool enabled)
        {
            m_NewGraphButton.SetEnabled(enabled);
            m_SaveAllButton.SetEnabled(enabled);
            m_BuildAllButton.SetEnabled(enabled);

            var stencil         = m_Store.GetState()?.CurrentGraphModel?.Stencil;
            var toolbarProvider = stencil?.GetToolbarProvider();

            if (!(toolbarProvider?.ShowButton(NewGraphButton) ?? true))
            {
                m_NewGraphButton.style.display = DisplayStyle.None;
            }
            else
            {
                m_NewGraphButton.style.display = StyleKeyword.Null;
            }

            if (!(toolbarProvider?.ShowButton(SaveAllButton) ?? true))
            {
                m_SaveAllButton.style.display = DisplayStyle.None;
            }
            else
            {
                m_SaveAllButton.style.display = StyleKeyword.Null;
            }

            if (!(toolbarProvider?.ShowButton(BuildAllButton) ?? true))
            {
                m_BuildAllButton.style.display = DisplayStyle.None;
            }
            else
            {
                m_BuildAllButton.style.display = StyleKeyword.Null;
            }

            if (!(toolbarProvider?.ShowButton(ShowBlackboardButton) ?? true))
            {
                m_ShowBlackboardButton.style.display = DisplayStyle.None;
            }
            else
            {
                m_ShowBlackboardButton.style.display = StyleKeyword.Null;
            }

            if (!(stencil?.GeneratesCode ?? false) || !(toolbarProvider?.ShowButton(ViewInCodeViewerButton) ?? true))
            {
                m_ViewInCodeViewerButton.style.display = DisplayStyle.None;
            }
            else
            {
                m_ViewInCodeViewerButton.style.display = StyleKeyword.Null;
            }
        }
Exemple #3
0
        public override void Dispatch <TAction>(TAction action)
        {
            VSPreferences vsPreferences = GetState().Preferences;

            if (vsPreferences != null && vsPreferences.GetBool(VSPreferences.BoolPref.LogAllDispatchedActions))
            {
                Debug.Log(action);
            }
            int currentFrame = GetState()?.EditorDataModel == null ? -1 : GetState().EditorDataModel.UpdateCounter;

            if (vsPreferences != null && currentFrame == m_LastActionFrame &&
                vsPreferences.GetBool(VSPreferences.BoolPref.ErrorOnMultipleDispatchesPerFrame))
            {
                // TODO: Specific case for a non-model specific action, possibly triggered by a callback that is unaware of the store's current state;
                //       About RefreshUIAction: maybe this is not a good idea to update the UI via an action, as it has nothing
                //       to do with the model.  Problem is, currently, the Store reacts on state changes and is responsible
                //       of updating the UI accordingly.  This UI update loop could be moved elsewhere and detach itself
                //       from the editor model.  Same goes for PanToNode action.
                if (!(action is RefreshUIAction || action is PanToNodeAction))
                {
                    Debug.LogError($"Multiple actions dispatched during the same frame (previous one was {m_LastActionThisFrame.GetType().Name}), current: {action.GetType().Name}");
                }
            }

            m_LastActionFrame     = currentFrame;
            m_LastActionThisFrame = action;

            if (vsPreferences != null && m_CurrentAction != null &&
                vsPreferences.GetBool(VSPreferences.BoolPref.ErrorOnRecursiveDispatch))
            {
                // TODO: Same check here, see comments above
                if (!(action is RefreshUIAction))
                {
                    Debug.LogError($"Recursive dispatch detected: action {action.GetType().Name} dispatched during {m_CurrentAction.GetType().Name}'s dispatch");
                }
            }

            m_CurrentAction = action;
            try
            {
                base.Dispatch(action);
            }
            finally
            {
                m_CurrentAction = null;
            }
        }
Exemple #4
0
 protected virtual void UpdateCommonMenu(VSPreferences prefs, bool enabled)
 {
     m_SaveAllButton.SetEnabled(enabled);
     m_BuildAllButton.SetEnabled(enabled);
     m_ViewInCodeViewerButton.SetEnabled(enabled);
 }
Exemple #5
0
        public void Test_CreateEdgeAction_Itemize(TestingMode testingMode, ItemizeOptions options, ItemizeTestType itemizeTest, Func <VSGraphModel, IHasMainOutputPort> makeNode)
        {
            // save initial itemize options
            VSPreferences  pref           = ((TestState)m_Store.GetState()).Preferences;
            ItemizeOptions initialOptions = pref.CurrentItemizeOptions;

            try
            {
                // create int node
                IHasMainOutputPort node0 = makeNode(GraphModel);

                // create Addition node
                BinaryOperatorNodeModel opNode = GraphModel.CreateBinaryOperatorNode(BinaryOperatorKind.Add, Vector2.zero);

                // enable Itemize depending on the test case
                var itemizeOptions = ItemizeOptions.Nothing;
                pref.CurrentItemizeOptions = (itemizeTest == ItemizeTestType.Enabled) ? options : itemizeOptions;

                // connect int to first input
                m_Store.Dispatch(new CreateEdgeAction(opNode.InputPortA, node0.OutputPort));
                m_Store.Update();

                // test how the node reacts to getting connected a second time
                TestPrereqActionPostreq(testingMode,
                                        () =>
                {
                    RefreshReference(ref node0);
                    RefreshReference(ref opNode);
                    var binOp            = GraphModel.GetAllNodes().OfType <BinaryOperatorNodeModel>().First();
                    IPortModel input0    = binOp.InputPortA;
                    IPortModel input1    = binOp.InputPortB;
                    IPortModel binOutput = binOp.OutputPort;
                    Assert.That(GetNodeCount(), Is.EqualTo(2));
                    Assert.That(GetEdgeCount(), Is.EqualTo(1));
                    Assert.That(input0, Is.ConnectedTo(node0.OutputPort));
                    Assert.That(input1, Is.Not.ConnectedTo(node0.OutputPort));
                    Assert.That(binOutput.Connected, Is.False);
                    return(new CreateEdgeAction(input1, node0.OutputPort));
                },
                                        () =>
                {
                    RefreshReference(ref node0);
                    RefreshReference(ref opNode);
                    var binOp            = GraphModel.GetAllNodes().OfType <BinaryOperatorNodeModel>().First();
                    IPortModel input0    = binOp.InputPortA;
                    IPortModel input1    = binOp.InputPortB;
                    IPortModel binOutput = binOp.OutputPort;
                    Assert.That(GetEdgeCount(), Is.EqualTo(2));
                    Assert.That(input0, Is.ConnectedTo(node0.OutputPort));
                    Assert.That(binOutput.Connected, Is.False);

                    if (itemizeTest == ItemizeTestType.Enabled)
                    {
                        Assert.That(GetNodeCount(), Is.EqualTo(3));
                        IHasMainOutputPort newNode = GetNode(2) as IHasMainOutputPort;
                        Assert.NotNull(newNode);
                        Assert.That(newNode, Is.TypeOf(node0.GetType()));
                        IPortModel output1 = newNode.OutputPort;
                        Assert.That(input1, Is.ConnectedTo(output1));
                    }
                    else
                    {
                        Assert.That(GetNodeCount(), Is.EqualTo(2));
                    }
                });
            }
            finally
            {
                // restore itemize options
                pref.CurrentItemizeOptions = initialOptions;
            }
        }
        void OnOptionsButton()
        {
            GenericMenu   menu         = new GenericMenu();
            VSGraphModel  vsGraphModel = (VSGraphModel)m_Store.GetState().CurrentGraphModel;
            VSPreferences pref         = m_Store.GetState().Preferences;

            void MenuItem(string title, bool value, GenericMenu.MenuFunction onToggle)
            => menu.AddItem(VseUtility.CreatTextContent(title), value, onToggle);

            void MenuToggle(string title, BoolPref k, Action callback = null)
            => MenuItem(title, pref.GetBool(k), () =>
            {
                pref.ToggleBool(k);
                callback?.Invoke();
            });

            void MenuMapToggle(string title, Func <bool> match, GenericMenu.MenuFunction onToggle)
            => MenuItem(title, match(), onToggle);

            void MenuItemDisable(string title, bool value, GenericMenu.MenuFunction onToggle, Func <bool> shouldDisable)
            {
                if (shouldDisable())
                {
                    menu.AddDisabledItem(VseUtility.CreatTextContent(title));
                }
                else
                {
                    menu.AddItem(VseUtility.CreatTextContent(title), value, onToggle);
                }
            }

            MenuItem("Build All", false, AssetDatabase.SaveAssets);
            MenuItemDisable("Compile", false, () =>
            {
                m_Store.GetState().EditorDataModel.RequestCompilation(RequestCompilationOptions.SaveGraph);
            }, () => (vsGraphModel == null || !vsGraphModel.Stencil.CreateTranslator().SupportsCompilation()));
            MenuItem("Auto-itemize/Variables", pref.CurrentItemizeOptions.HasFlag(ItemizeOptions.Variables), () =>
                     pref.ToggleItemizeOption(ItemizeOptions.Variables));
            MenuItem("Auto-itemize/System Constants", pref.CurrentItemizeOptions.HasFlag(ItemizeOptions.SystemConstants), () =>
                     pref.ToggleItemizeOption(ItemizeOptions.SystemConstants));
            MenuItem("Auto-itemize/Constants", pref.CurrentItemizeOptions.HasFlag(ItemizeOptions.Constants), () =>
                     pref.ToggleItemizeOption(ItemizeOptions.Constants));
            MenuToggle("Show unused nodes", BoolPref.ShowUnusedNodes, () => m_Store.Dispatch(new RefreshUIAction(UpdateFlags.All)));
            if (Unsupported.IsDeveloperMode())
            {
                MenuItem("Log compile time stats", LogCompileTimeStats, () => LogCompileTimeStats = !LogCompileTimeStats);

                MenuItem("Rebuild UI", false, () =>
                {
                    m_Store.Dispatch(new RefreshUIAction(UpdateFlags.All));
                });
                MenuItem("Rebuild Blackboard", false, () =>
                {
                    m_GraphView.UIController.Blackboard?.Rebuild(Blackboard.RebuildMode.BlackboardOnly);
                });
                menu.AddSeparator("");
                MenuItem("Reload and Rebuild UI", false, () =>
                {
                    if (m_Store.GetState()?.CurrentGraphModel != null)
                    {
                        var path = m_Store.GetState().CurrentGraphModel.GetAssetPath();
                        Selection.activeObject = null;
                        Resources.UnloadAsset((Object)m_Store.GetState().CurrentGraphModel.AssetModel);
                        Resources.UnloadAsset((Object)m_Store.GetState().CurrentGraphModel);
                        m_Store.Dispatch(new LoadGraphAssetAction(path));
                    }
                });

                MenuItem("Layout", false, () =>
                {
                    m_GraphView.FrameAll();
                    m_Store.Dispatch(new RefreshUIAction(UpdateFlags.All));
                });

                menu.AddSeparator("");
                MenuItem("Clear Searcher Databases", false, () =>
                {
                    var provider = m_Store.GetState().CurrentGraphModel.Stencil.GetSearcherDatabaseProvider();
                    provider.ClearTypesItemsSearcherDatabases();
                    provider.ClearTypeMembersSearcherDatabases();
                    provider.ClearGraphElementsSearcherDatabases();
                    provider.ClearGraphVariablesSearcherDatabases();
                    provider.ClearReferenceItemsSearcherDatabases();
                });
                MenuItem("Integrity Check", false, () => vsGraphModel.CheckIntegrity(GraphModel.Verbosity.Verbose));
                MenuItem("Graph cleanup", false, () =>
                {
                    vsGraphModel.QuickCleanup();
                    vsGraphModel.CheckIntegrity(GraphModel.Verbosity.Verbose);
                });
                MenuItem("Fix and reimport all textures", false, OnFixAndReimportTextures);

                MenuToggle("Auto compilation when idle", BoolPref.AutoRecompile);
                MenuToggle("Auto align new dragged edges", BoolPref.AutoAlignDraggedEdges);
                if (Unsupported.IsDeveloperMode())
                {
                    MenuToggle("Bound object logging", BoolPref.BoundObjectLogging);
                    MenuToggle("Dependencies logging", BoolPref.DependenciesLogging);
                    MenuToggle("UI Performance/Always fully rebuild UI on change", BoolPref.FullUIRebuildOnChange);
                    MenuToggle("UI Performance/Warn when UI gets fully rebuilt", BoolPref.WarnOnUIFullRebuild);
                    MenuToggle("UI Performance/Log UI build time", BoolPref.LogUIBuildTime);
                    if (DebugDisplayElement.Allowed)
                    {
                        MenuItem("Show Debug", m_GraphView.ShowDebug, () => m_GraphView.ShowDebug = !m_GraphView.ShowDebug);
                    }
                    MenuToggle("Diagnostics/Log Recursive Action Dispatch", BoolPref.ErrorOnRecursiveDispatch);
                    MenuToggle("Diagnostics/Log Multiple Actions Dispatch", BoolPref.ErrorOnMultipleDispatchesPerFrame);
                    MenuToggle("Diagnostics/Log All Dispatched Actions", BoolPref.LogAllDispatchedActions);
                    MenuItem("Spawn all node types in graph", false, () =>
                    {
                        VSGraphModel graph   = (VSGraphModel)m_Store.GetState().CurrentGraphModel;
                        Stencil stencil      = graph.Stencil;
                        Vector2 nextPosition = Vector2.zero;
                        Vector2 spaceBetween = new Vector2(300, 0);
                        foreach (var node in stencil.SpawnAllNodes(graph))
                        {
                            node.Position += nextPosition;
                            nextPosition  += spaceBetween;
                        }
                    });
                }

                var compilationResult = m_Store.GetState()?.CompilationResultModel?.GetLastResult();
                if (compilationResult != null)
                {
                    foreach (var pluginType in compilationResult.pluginSourceCode.Keys)
                    {
                        MenuMapToggle(title: "CodeViewer/Plugin/" + pluginType.Name, match: () => pref.PluginTypePref == pluginType, onToggle: () =>
                        {
                            VseUtility.UpdateCodeViewer(show: true, pluginIndex: pluginType,
                                                        compilationResult: compilationResult,
                                                        selectionDelegate: lineMetadata =>
                            {
                                if (lineMetadata == null)
                                {
                                    return;
                                }

                                GUID nodeGuid = (GUID)lineMetadata;
                                m_Store.Dispatch(new PanToNodeAction(nodeGuid));
                            });
                            pref.PluginTypePref = pluginType;
                        });
                    }
                }
            }

            menu.ShowAsContext();
        }
 public PositionDependenciesManager(VseGraphView vseGraphView, VSPreferences vsPreferences)
 {
     m_VseGraphView = vseGraphView;
     m_Preferences  = vsPreferences;
 }