diff --git a/Source/Editor/Surface/SurfaceUtils.cs b/Source/Editor/Surface/SurfaceUtils.cs index 563d00df0..f5ca394fb 100644 --- a/Source/Editor/Surface/SurfaceUtils.cs +++ b/Source/Editor/Surface/SurfaceUtils.cs @@ -14,6 +14,7 @@ using FlaxEngine.Utilities; using FlaxEngine; using FlaxEditor.GUI; using FlaxEditor.Options; +using FlaxEngine.GUI; namespace FlaxEditor.Surface { @@ -535,9 +536,10 @@ namespace FlaxEditor.Surface return value; } + // This might not be the greatest place to put this but I couldn't find anything better yet. public static void VisjectCommonToolstripSetup(Editor editor, ToolStrip toolStrip, FlaxEditor.Undo undo, - Action save, Action showWholeGraph, InputActionsContainer actionsContainer, - out ToolStripButton saveButton, out ToolStripButton undoButton, out ToolStripButton redoButton) + Action save, Action showWholeGraph, Action toggleGridSnap, InputActionsContainer actionsContainer, + out ToolStripButton saveButton, out ToolStripButton undoButton, out ToolStripButton redoButton, out ToolStripButton gridSnapButton) { // Toolstrip saveButton = (ToolStripButton)toolStrip.AddButton(editor.Icons.Save64, save).LinkTooltip("Save"); @@ -547,11 +549,26 @@ namespace FlaxEditor.Surface toolStrip.AddSeparator(); toolStrip.AddButton(editor.Icons.Search64, editor.ContentFinding.ShowSearch).LinkTooltip("Open content search tool (Ctrl+F)"); toolStrip.AddButton(editor.Icons.CenterView64, showWholeGraph).LinkTooltip("Show whole graph"); + gridSnapButton = (ToolStripButton)toolStrip.AddButton(editor.Icons.Stop64, toggleGridSnap).LinkTooltip("Toggle grid snapping for nodes."); + gridSnapButton.BackgroundColor = Style.Current.Background; // Default color for grid snap button. // Setup input actions actionsContainer.Add(options => options.Undo, undo.PerformUndo); actionsContainer.Add(options => options.Redo, undo.PerformRedo); actionsContainer.Add(options => options.Search, editor.ContentFinding.ShowSearch); } + + public static void ToggleSurfaceGridSnap(VisjectSurface surface, ToolStripButton gridSnapButton) + { + surface.GridSnappingEnabled = !surface.GridSnappingEnabled; + if (surface.GridSnappingEnabled) + { + gridSnapButton.BackgroundColor = Style.Current.BackgroundSelected; + } + else + { + gridSnapButton.BackgroundColor = Style.Current.Background; + } + } } } diff --git a/Source/Editor/Surface/VisjectSurfaceWindow.cs b/Source/Editor/Surface/VisjectSurfaceWindow.cs index 8362cbd44..eff8ec8a3 100644 --- a/Source/Editor/Surface/VisjectSurfaceWindow.cs +++ b/Source/Editor/Surface/VisjectSurfaceWindow.cs @@ -669,6 +669,7 @@ namespace FlaxEditor.Surface private readonly ToolStripButton _saveButton; private readonly ToolStripButton _undoButton; private readonly ToolStripButton _redoButton; + private readonly ToolStripButton _gridSnapButton; private bool _showWholeGraphOnLoad = true; /// @@ -772,8 +773,9 @@ namespace FlaxEditor.Surface } _propertiesEditor.Modified += OnPropertyEdited; - SurfaceUtils.VisjectCommonToolstripSetup(editor, _toolstrip, _undo, Save, ShowWholeGraph, InputActions, - out _saveButton, out _undoButton, out _redoButton); + SurfaceUtils.VisjectCommonToolstripSetup(editor, _toolstrip, _undo, + Save, ShowWholeGraph, ToggleGridSnap, InputActions, + out _saveButton, out _undoButton, out _redoButton, out _gridSnapButton); } private void OnUndoRedo(IUndoAction action) @@ -812,6 +814,11 @@ namespace FlaxEditor.Surface _surface.ShowWholeGraph(); } + private void ToggleGridSnap() + { + SurfaceUtils.ToggleSurfaceGridSnap(_surface, _gridSnapButton); + } + /// /// Refreshes temporary asset to see changes live when editing the surface. /// diff --git a/Source/Editor/Windows/Assets/VisjectFunctionSurfaceWindow.cs b/Source/Editor/Windows/Assets/VisjectFunctionSurfaceWindow.cs index 69a1ae6ad..9750fa3e6 100644 --- a/Source/Editor/Windows/Assets/VisjectFunctionSurfaceWindow.cs +++ b/Source/Editor/Windows/Assets/VisjectFunctionSurfaceWindow.cs @@ -30,6 +30,7 @@ namespace FlaxEditor.Windows.Assets private readonly ToolStripButton _saveButton; private readonly ToolStripButton _undoButton; private readonly ToolStripButton _redoButton; + private readonly ToolStripButton _gridSnapButton; private bool _showWholeGraphOnLoad = true; /// @@ -68,8 +69,9 @@ namespace FlaxEditor.Windows.Assets _undo.ActionDone += OnUndoRedo; // Toolstrip - SurfaceUtils.VisjectCommonToolstripSetup(editor, _toolstrip, _undo, Save, ShowWholeGraph, InputActions, - out _saveButton, out _undoButton, out _redoButton); + SurfaceUtils.VisjectCommonToolstripSetup(editor, _toolstrip, _undo, + Save, ShowWholeGraph, ToggleGridSnap, InputActions, + out _saveButton, out _undoButton, out _redoButton, out _gridSnapButton); // Panel _panel = new Panel(ScrollBars.None) @@ -94,6 +96,11 @@ namespace FlaxEditor.Windows.Assets _surface.ShowWholeGraph(); } + private void ToggleGridSnap() + { + SurfaceUtils.ToggleSurfaceGridSnap(_surface, _gridSnapButton); + } + /// /// Refreshes temporary asset to see changes live when editing the surface. /// diff --git a/Source/Editor/Windows/Assets/VisualScriptWindow.cs b/Source/Editor/Windows/Assets/VisualScriptWindow.cs index cd5455a5b..3b6480063 100644 --- a/Source/Editor/Windows/Assets/VisualScriptWindow.cs +++ b/Source/Editor/Windows/Assets/VisualScriptWindow.cs @@ -533,6 +533,7 @@ namespace FlaxEditor.Windows.Assets private readonly ToolStripButton _saveButton; private readonly ToolStripButton _undoButton; private readonly ToolStripButton _redoButton; + private readonly ToolStripButton _gridSnapButton; private Control[] _debugToolstripControls; private bool _showWholeGraphOnLoad = true; private bool _tmpAssetIsDirty; @@ -596,8 +597,11 @@ namespace FlaxEditor.Windows.Assets _propertiesEditor.Select(_properties); // Toolstrip - SurfaceUtils.VisjectCommonToolstripSetup(editor, _toolstrip, _undo, Save, ShowWholeGraph, InputActions, - out _saveButton, out _undoButton, out _redoButton); + SurfaceUtils.VisjectCommonToolstripSetup(editor, _toolstrip, _undo, + Save, ShowWholeGraph, ToggleGridSnap, InputActions, + out _saveButton, out _undoButton, out _redoButton, out _gridSnapButton); + + // The rest of the toolstrip _toolstrip.AddSeparator(); _toolstrip.AddButton(editor.Icons.Docs64, () => Platform.OpenUrl(Utilities.Constants.DocsUrl + "manual/scripting/visual/index.html")).LinkTooltip("See documentation to learn more"); _debugToolstripControls = new[] @@ -678,6 +682,11 @@ namespace FlaxEditor.Windows.Assets _surface.ShowWholeGraph(); } + private void ToggleGridSnap() + { + SurfaceUtils.ToggleSurfaceGridSnap(_surface, _gridSnapButton); + } + /// /// Refreshes temporary asset to see changes live when editing the surface. ///