internal static void DeleteBrush(Brush brush, bool selectParentTileset)
        {
            var brushRecord = BrushDatabase.Instance.FindRecord(brush);

            if (brushRecord == null)
            {
                return;
            }

            RotorzEditorGUI.ClearControlFocus();

            if (EditorUtility.DisplayDialog(
                    TileLang.ParticularText("Action", "Delete Brush"),
                    string.Format(
                        /* 0: name of brush */
                        TileLang.Text("Deleting a brush that has been previously used in a tile system may cause damage to that tile system.\n\n'{0}'\n\nDo you really want to delete this brush?"),
                        brushRecord.DisplayName
                        ),
                    TileLang.ParticularText("Action", "Yes"),
                    TileLang.ParticularText("Action", "No")
                    ))
            {
                // Determine whether tileset should be selected in designer.
                var designerWindow = RotorzWindow.GetInstance <DesignerWindow>();
                if (designerWindow != null && ReferenceEquals(brushRecord.Brush, designerWindow.SelectedObject))
                {
                    designerWindow.SelectedObject = selectParentTileset && brushRecord.Brush is TilesetBrush
                        ? (brushRecord.Brush as TilesetBrush).Tileset
                        : null;
                }

                BrushUtility.DeleteBrush(brushRecord.Brush);
            }
        }
        private void _brushList_BrushClicked(Brush brush)
        {
            // Only proceed if either the left mouse button or right mouse button was used.
            if (Event.current.button != 0 && Event.current.button != 1)
            {
                return;
            }

            Brush previousSelectedBrush = null;

            // Left click to select brush, or holding control to select secondary brush.
            if (Event.current.button == 0)
            {
                previousSelectedBrush = ToolUtility.SelectedBrush;
                if (brush != previousSelectedBrush)
                {
                    ToolUtility.SelectedBrush = brush;
                    this.brushList.ScrollToBrush(brush);
                }
                else
                {
                    // Brush is already selected, open in designer?
                    var designerWindow = RotorzWindow.GetInstance <DesignerWindow>();
                    if (designerWindow != null && !designerWindow.IsLocked)
                    {
                        designerWindow.SelectedObject = brush;
                    }
                }

                Event.current.Use();
            }
            else if (Event.current.control)
            {
                previousSelectedBrush = ToolUtility.SelectedBrushSecondary;
                ToolUtility.SelectedBrushSecondary = brush;

                Event.current.Use();
            }

            // If control was held, toggle paint tool.
            if (Event.current.control)
            {
                if (ToolManager.Instance.CurrentTool == null)
                {
                    ToolManager.Instance.CurrentTool = ToolManager.DefaultPaintTool;
                }
                else if (Event.current.button == 0 && previousSelectedBrush == brush)
                {
                    // Deselect paint tool if control was held whilst clicking selected brush.
                    ToolManager.Instance.CurrentTool = null;
                }
            }

            // If painting tool is active then repaint active scene view so that gizmos,
            // handles and other annotations are properly updated.
            if (ToolManager.Instance.CurrentTool != null && SceneView.lastActiveSceneView != null)
            {
                SceneView.lastActiveSceneView.Repaint();
            }
        }
 /// <summary>
 /// Show scene palette window.
 /// </summary>
 /// <param name="focus">Indicates if window should be focused.</param>
 public static void ShowScenePalette(bool focus = true)
 {
     if (focus || RotorzWindow.GetInstance <ScenePaletteWindow>() == null)
     {
         RotorzWindow.GetWindow <ScenePaletteWindow>();
     }
 }
        private static void PrepareSettings_Misc(ISettingStore store)
        {
            ControlContent.TrailingTipsVisibleChanged += () => {
                RotorzWindow.RepaintIfShown <DesignerWindow>();
            };

            DisableCustomCursors = store.Fetch <bool>(
                "DisableCustomCursors", false
                );

            AlwaysCenterUtilityWindows = store.Fetch <bool>(
                "AlwaysCenterUtilityWindows", false
                );
        }
        /// <summary>
        /// Reveal brush in brushes palette where possible.
        /// </summary>
        /// <param name="brush">The brush.</param>
        /// <param name="showWindow">Indicates if brush palette window should be shown
        /// if not already shown.</param>
        public static void RevealBrush(Brush brush, bool showWindow = true)
        {
            var brushPalette = RotorzWindow.GetInstance <BrushPaletteWindow>();

            if (showWindow && brushPalette == null)
            {
                brushPalette = RotorzWindow.GetWindow <BrushPaletteWindow>();
            }

            if (brushPalette != null)
            {
                brushPalette.RevealBrush(brush);
            }
        }
        /// <summary>
        /// Reveal tile system in scene palette.
        /// </summary>
        /// <param name="system">The tile system.</param>
        /// <param name="showWindow">Indicates if scene palette window should be shown if not already.</param>
        public static void RevealTileSystem(TileSystem system, bool showWindow = true)
        {
            var palette = RotorzWindow.GetInstance <ScenePaletteWindow>();

            if (showWindow && palette == null)
            {
                palette = RotorzWindow.GetWindow <ScenePaletteWindow>();
            }

            if (palette != null)
            {
                palette.ScrollToTileSystem(system);
                palette.Repaint();
            }
        }
        private void _brushList_BrushContextMenu(Brush brush)
        {
            // Do not attempt to display context menu for "(Erase)" item.
            if (brush == null)
            {
                return;
            }

            var brushRecord = BrushDatabase.Instance.FindRecord(brush);

            var brushContextMenu = new EditorMenu();

            brushContextMenu.AddCommand(TileLang.OpensWindow(TileLang.ParticularText("Action", "Show in Designer")))
            .Enabled(!brushRecord.IsMaster)     // Cannot edit a master brush :)
            .Action(() => {
                ToolUtility.ShowBrushInDesigner(brush);
            });

            var selectedTilesetBrush = brush as TilesetBrush;

            if (selectedTilesetBrush != null)
            {
                brushContextMenu.AddCommand(TileLang.ParticularText("Action", "Goto Tileset"))
                .Action(() => {
                    this.brushList.Model.View            = BrushListView.Tileset;
                    this.brushList.Model.SelectedTileset = selectedTilesetBrush.Tileset;

                    var designerWindow = RotorzWindow.GetInstance <DesignerWindow>();
                    if (designerWindow != null && !designerWindow.IsLocked)
                    {
                        designerWindow.SelectedObject = selectedTilesetBrush.Tileset;
                    }

                    this.Repaint();
                });
            }

            brushContextMenu.AddCommand(TileLang.ParticularText("Action", "Reveal Asset"))
            .Action(() => {
                EditorGUIUtility.PingObject(brush);
            });

            brushContextMenu.AddSeparator();

            brushContextMenu.AddCommand(TileLang.ParticularText("Action", "Refresh Preview"))
            .Action(() => {
                BrushUtility.RefreshPreviewIncludingDependencies(brush);
            });

            brushContextMenu.AddSeparator();

            brushContextMenu.AddCommand(TileLang.OpensWindow(TileLang.ParticularText("Action", "Create Duplicate")))
            .Action(() => {
                var window = CreateBrushWindow.ShowWindow <DuplicateBrushCreator>();
                window.SharedProperties["targetBrush"] = brush;
            });

            var brushDescriptor = BrushUtility.GetDescriptor(brush.GetType());

            brushContextMenu.AddCommand(TileLang.OpensWindow(TileLang.ParticularText("Action", "Create Alias")))
            .Enabled(brushDescriptor.SupportsAliases)
            .Action(() => {
                var window = CreateBrushWindow.ShowWindow <AliasBrushCreator>();
                window.SharedProperties["targetBrush"] = brush;
            });

            brushContextMenu.AddCommand(TileLang.OpensWindow(TileLang.ParticularText("Action", "Delete Brush")))
            .Action(() => {
                TileSystemCommands.DeleteBrush(brush, ToolUtility.SharedBrushListModel.View == BrushListView.Tileset);
            });

            brushContextMenu.ShowAsContext();
        }
 /// <summary>
 /// Repaint scene palette window if shown.
 /// </summary>
 public static void RepaintScenePalette()
 {
     RotorzWindow.RepaintIfShown <ScenePaletteWindow>();
 }
 /// <summary>
 /// Repaint brush palette window if shown.
 /// </summary>
 public static void RepaintBrushPalette()
 {
     RotorzWindow.RepaintIfShown <BrushPaletteWindow>();
 }
 /// <summary>
 /// Repaint tool palette window if shown.
 /// </summary>
 public static void RepaintToolPalette()
 {
     RotorzWindow.RepaintIfShown <ToolPaletteWindow>();
 }
 private static void ShowToolPalette()
 {
     RotorzWindow.GetWindow <ToolPaletteWindow>();
 }