Example #1
0
// ---------------------------------------------------------------------------
    #region Toolbar GUI
// ---------------------------------------------------------------------------
    private void DisplayToolbarGUI()
    {
        // Calculate toolbar icon size
        toolBarIconSize = (position.height / 15.3f) * MAST_Settings.gui.toolbar.scale;

        GUILayout.Space(toolBarIconSize / 10);

        GUILayout.BeginVertical();

        GUILayout.Space(toolBarIconSize / 7.5f);

        // ----------------------------------------------
        // Grid Section
        // ----------------------------------------------
        GUILayout.BeginVertical("MAST Toolbar BG Inset");

        // ------------------------------------
        // Grid Up Button
        // ------------------------------------
        if (GUILayout.Button(new GUIContent(iconGridUp, "Move Grid Up"),
                             "MAST Half Button", GUILayout.Width(toolBarIconSize), GUILayout.Height(toolBarIconSize / 2)))
        {
            MAST_Grid_Manager.MoveGridUp();
        }

        // ------------------------------------
        // Toggle Grid Button
        // ------------------------------------
        EditorGUI.BeginChangeCheck();

        // OnScene Enable/Disable Randomizer Icon Button
        MAST_Grid_Manager.gridExists = GUILayout.Toggle(
            MAST_Grid_Manager.gridExists,
            new GUIContent(iconGridToggle, "Toggle Scene Grid"),
            "MAST Toggle", GUILayout.Width(toolBarIconSize), GUILayout.Height(toolBarIconSize));

        // If randomizer enabled value changed, process the change
        if (EditorGUI.EndChangeCheck())
        {
            MAST_Grid_Manager.ChangeGridVisibility();
        }

        // ------------------------------------
        // Grid Down Button
        // ------------------------------------
        if (GUILayout.Button(new GUIContent(iconGridDown, "Move Grid Down"),
                             "MAST Half Button", GUILayout.Width(toolBarIconSize), GUILayout.Height(toolBarIconSize / 2)))
        {
            MAST_Grid_Manager.MoveGridDown();
        }

        GUILayout.EndVertical();

        GUILayout.Space(toolBarIconSize / 5);

        // ----------------------------------------------
        // Draw Tool Section
        // ----------------------------------------------
        GUILayout.BeginVertical("MAST Toolbar BG Inset");

        // ------------------------------------
        // Add Draw Tool Toggle Group
        // ------------------------------------
        EditorGUI.BeginChangeCheck();

        // Create drawtools SelectionGrid
        int newSelectedDrawToolIndex = GUILayout.SelectionGrid(
            MAST_Settings.gui.toolbar.selectedDrawToolIndex,
            guiContentDrawTool, 1, "MAST Toggle",
            GUILayout.Width(toolBarIconSize),
            GUILayout.Height(toolBarIconSize * 5));

        // If the draw tool was changed
        if (EditorGUI.EndChangeCheck())
        {
            // If the draw tool was clicked again, deselect it
            if (newSelectedDrawToolIndex == MAST_Settings.gui.toolbar.selectedDrawToolIndex)
            {
                MAST_Settings.gui.toolbar.selectedDrawToolIndex = -1;

                MAST_Placement_Interface.ChangePlacementMode(MAST_Placement_Interface.PlacementMode.None);

                drawing  = false;
                painting = false;
                erasing  = false;
            }

            // If a different draw tool was clicked, change to it
            else
            {
                MAST_Settings.gui.toolbar.selectedDrawToolIndex = newSelectedDrawToolIndex;

                if (MAST_Settings.gui.toolbar.selectedDrawToolIndex != 1)
                {
                    drawing = false;
                }
                if (MAST_Settings.gui.toolbar.selectedDrawToolIndex != 2)
                {
                    painting = false;
                }
                if (MAST_Settings.gui.toolbar.selectedDrawToolIndex != 4)
                {
                    erasing = false;
                }

                switch (MAST_Settings.gui.toolbar.selectedDrawToolIndex)
                {
                // Draw Single Tool selected
                case 0:
                    MAST_Placement_Interface.ChangePlacementMode(MAST_Placement_Interface.PlacementMode.DrawSingle);
                    break;

                // Draw Continuous Tool selected
                case 1:
                    MAST_Placement_Interface.ChangePlacementMode(MAST_Placement_Interface.PlacementMode.DrawContinuous);
                    break;

                // Flood Fill Tool selected
                case 2:
                    MAST_Placement_Interface.ChangePlacementMode(MAST_Placement_Interface.PlacementMode.PaintArea);
                    break;

                // Randomizer Tool selected
                case 3:
                    MAST_Placement_Interface.ChangePlacementMode(MAST_Placement_Interface.PlacementMode.Randomize);
                    SceneView.RepaintAll();
                    break;

                // Eraser Tool selected
                case 4:
                    MAST_Placement_Interface.ChangePlacementMode(MAST_Placement_Interface.PlacementMode.Erase);
                    SceneView.RepaintAll();
                    break;
                }
            }
        }

        GUILayout.EndVertical();

        GUILayout.Space(toolBarIconSize / 5);

        // ----------------------------------------------
        // Manipulate Section
        // ----------------------------------------------
        GUILayout.BeginVertical("MAST Toolbar BG Inset");

        // ------------------------------------
        // Rotate Button
        // ------------------------------------
        if (GUILayout.Button(new GUIContent(iconRotate, "Rotate Prefab/Selection"),
                             "MAST Button", GUILayout.Width(toolBarIconSize), GUILayout.Height(toolBarIconSize)))
        {
            MAST_Placement_Manipulate.RotateObject();
        }

        // OnScene Change Rotate Axis Icon Button
        switch (MAST_Placement_Manipulate.GetCurrentRotateAxis())
        {
        case MAST_Placement_Manipulate.Axis.X:
            if (GUILayout.Button(new GUIContent(iconAxisX, "Change Rotate Axis"),
                                 "MAST Half Button", GUILayout.Width(toolBarIconSize), GUILayout.Height(toolBarIconSize / 2)))
            {
                MAST_Placement_Manipulate.ToggleRotateAxis();
            }
            break;

        case MAST_Placement_Manipulate.Axis.Y:
            if (GUILayout.Button(new GUIContent(iconAxisY, "Change Rotate Axis"),
                                 "MAST Half Button", GUILayout.Width(toolBarIconSize), GUILayout.Height(toolBarIconSize / 2)))
            {
                MAST_Placement_Manipulate.ToggleRotateAxis();
            }
            break;

        case MAST_Placement_Manipulate.Axis.Z:
            if (GUILayout.Button(new GUIContent(iconAxisZ, "Change Rotate Axis"),
                                 "MAST Half Button", GUILayout.Width(toolBarIconSize), GUILayout.Height(toolBarIconSize / 2)))
            {
                MAST_Placement_Manipulate.ToggleRotateAxis();
            }
            break;
        }

        GUILayout.Space(toolBarIconSize / 10);

        // ------------------------------------
        // Flip Button
        // ------------------------------------
        if (GUILayout.Button(new GUIContent(iconFlip, "Flip Prefab/Selection"),
                             "MAST Button", GUILayout.Width(toolBarIconSize), GUILayout.Height(toolBarIconSize)))
        {
            MAST_Placement_Manipulate.FlipObject();
        }

        // OnScene Change Flip Axis Icon Button
        switch (MAST_Placement_Manipulate.GetCurrentFlipAxis())
        {
        case MAST_Placement_Manipulate.Axis.X:
            if (GUILayout.Button(new GUIContent(iconAxisX, "Change Flip Axis"),
                                 "MAST Half Button", GUILayout.Width(toolBarIconSize), GUILayout.Height(toolBarIconSize / 2)))
            {
                MAST_Placement_Manipulate.ToggleFlipAxis();
            }
            break;

        case MAST_Placement_Manipulate.Axis.Y:
            if (GUILayout.Button(new GUIContent(iconAxisY, "Change Flip Axis"),
                                 "MAST Half Button", GUILayout.Width(toolBarIconSize), GUILayout.Height(toolBarIconSize / 2)))
            {
                MAST_Placement_Manipulate.ToggleFlipAxis();
            }
            break;

        case MAST_Placement_Manipulate.Axis.Z:
            if (GUILayout.Button(new GUIContent(iconAxisZ, "Change Flip Axis"),
                                 "MAST Half Button", GUILayout.Width(toolBarIconSize), GUILayout.Height(toolBarIconSize / 2)))
            {
                MAST_Placement_Manipulate.ToggleFlipAxis();
            }
            break;
        }

        GUILayout.EndVertical();

        GUILayout.Space(toolBarIconSize / 5);

        // ----------------------------------------------
        // Misc Section
        // ----------------------------------------------
        GUILayout.BeginVertical("MAST Toolbar BG Inset");

        // ------------------------------------
        // Load Palette Button
        // ------------------------------------
        if (GUILayout.Button(new GUIContent(iconLoadFromFolder, "Load prefabs from a project folder"),
                             "MAST Button", GUILayout.Width(toolBarIconSize), GUILayout.Height(toolBarIconSize)))
        {
            // Process prefabs for palette and save chosen path for future use
            string chosenPath =
                MAST_Palette.LoadPrefabs(MAST_Interface_Data_Manager.state.lastPrefabPath);

            // If a folder was chosen "Cancel was not clicked"
            if (chosenPath != "")
            {
                // Save the path the user chose and all palette items
                MAST_Interface_Data_Manager.state.lastPrefabPath = chosenPath;
                MAST_Interface_Data_Manager.Save_Palette_Items(true);
                MAST_Interface_Data_Manager.Save_Changes_To_Disk();
            }
        }

        // ------------------------------------
        // Open Tools Window Button
        // ------------------------------------
        if (GUILayout.Button(new GUIContent(iconTools, "Tools"),
                             "MAST Button", GUILayout.Width(toolBarIconSize), GUILayout.Height(toolBarIconSize)))
        {
            // If Tools window is closed, show and initialize it
            if (Tools == null)
            {
                Tools = (MAST_Tools_Window)EditorWindow.GetWindow(
                    typeof(MAST_Tools_Window),
                    true, "MAST Tools");

                Tools.minSize = Tools.maxSize = new Vector2(330, 300);
            }

            // If Tools window is open, close it
            else
            {
                EditorWindow.GetWindow(typeof(MAST_Tools_Window)).Close();
            }
        }

        // ------------------------------------
        // Open Settings Window Button
        // ------------------------------------
        if (GUILayout.Button(new GUIContent(iconSettings, "Settings"),
                             "MAST Button", GUILayout.Width(toolBarIconSize), GUILayout.Height(toolBarIconSize)))
        {
            // If Settings window is closed, show and initialize it
            if (Settings == null)
            {
                Settings = (MAST_Settings_Window)EditorWindow.GetWindow(
                    typeof(MAST_Settings_Window),
                    true, "MAST Settings");

                Settings.minSize = Settings.maxSize = new Vector2(330, 300);
                Settings.Initialize();
            }

            // If Settings window is open, close it
            else
            {
                EditorWindow.GetWindow(typeof(MAST_Settings_Window)).Close();
            }
        }

        GUILayout.EndVertical();

        GUILayout.EndVertical();
    }
Example #2
0
    public bool ProcessHotkeys()
    {
        // Set change made to false
        bool changeMade = false;

        // Get current event
        Event currentEvent = Event.current;

        // Get the control's ID
        int controlID = GUIUtility.GetControlID(FocusType.Passive);

        // If a key is pressed
        if (Event.current.GetTypeForControl(controlID) == EventType.KeyDown)
        {
            // Toggle grid visibility
            if (KeysPressed(currentEvent,
                            MAST_Settings.hotkey.toggleGridKey,
                            MAST_Settings.hotkey.toggleGridMod))
            {
                MAST_Grid_Manager.gridExists = !MAST_Grid_Manager.gridExists;
                MAST_Grid_Manager.ChangeGridVisibility();
                changeMade = true;
            }
            // Move grid up
            if (KeysPressed(currentEvent,
                            MAST_Settings.hotkey.moveGridUpKey,
                            MAST_Settings.hotkey.moveGridUpMod))
            {
                MAST_Grid_Manager.MoveGridUp();
                changeMade = true;
            }
            // Move grid down
            if (KeysPressed(currentEvent,
                            MAST_Settings.hotkey.moveGridDownKey,
                            MAST_Settings.hotkey.moveGridDownMod))
            {
                MAST_Grid_Manager.MoveGridDown();
                changeMade = true;
            }
            // Deselect prefab in palette or draw tool
            if (KeysPressed(currentEvent,
                            MAST_Settings.hotkey.deselectPrefabKey,
                            MAST_Settings.hotkey.deselectPrefabMod))
            {
                // Deselect palette item and draw tool
                MAST_Palette.selectedItemIndex = -1;
                MAST_Settings.gui.toolbar.selectedDrawToolIndex = -1;
                MAST_Placement_Interface.ChangePlacementMode(MAST_Placement_Interface.PlacementMode.None);
                changeMade = true;
            }
            // Draw single
            if (KeysPressed(currentEvent,
                            MAST_Settings.hotkey.drawSingleKey,
                            MAST_Settings.hotkey.drawSingleMod))
            {
                // If Draw Single isn't selected, select it
                if (MAST_Settings.gui.toolbar.selectedDrawToolIndex != 0)
                {
                    MAST_Settings.gui.toolbar.selectedDrawToolIndex = 0;
                    MAST_Placement_Interface.ChangePlacementMode(MAST_Placement_Interface.PlacementMode.DrawSingle);
                }
                else
                {
                    // If Draw Single was selected, deselect it
                    if (MAST_Settings.gui.toolbar.selectedDrawToolIndex == 0)
                    {
                        MAST_Settings.gui.toolbar.selectedDrawToolIndex = -1;
                        MAST_Placement_Interface.ChangePlacementMode(MAST_Placement_Interface.PlacementMode.None);
                    }
                }
                changeMade = true;
            }
            // Draw Continuous
            if (KeysPressed(currentEvent,
                            MAST_Settings.hotkey.drawContinuousKey,
                            MAST_Settings.hotkey.drawContinuousMod))
            {
                // If Draw Continuous isn't selected, select it
                if (MAST_Settings.gui.toolbar.selectedDrawToolIndex != 1)
                {
                    MAST_Settings.gui.toolbar.selectedDrawToolIndex = 1;
                    MAST_Placement_Interface.ChangePlacementMode(MAST_Placement_Interface.PlacementMode.DrawContinuous);
                }
                else
                {
                    // If Draw continuous was selected, deselect it
                    if (MAST_Settings.gui.toolbar.selectedDrawToolIndex == 1)
                    {
                        MAST_Settings.gui.toolbar.selectedDrawToolIndex = -1;
                        MAST_Placement_Interface.ChangePlacementMode(MAST_Placement_Interface.PlacementMode.None);
                    }
                }
                changeMade = true;
            }
            // Paint square
            if (KeysPressed(currentEvent,
                            MAST_Settings.hotkey.paintSquareKey,
                            MAST_Settings.hotkey.paintSquareMod))
            {
                // If Paint Square isn't selected, select it
                if (MAST_Settings.gui.toolbar.selectedDrawToolIndex != 2)
                {
                    MAST_Settings.gui.toolbar.selectedDrawToolIndex = 2;
                    MAST_Placement_Interface.ChangePlacementMode(MAST_Placement_Interface.PlacementMode.PaintArea);
                }
                else
                {
                    // If Paint Square was selected, deselect it
                    if (MAST_Settings.gui.toolbar.selectedDrawToolIndex == 2)
                    {
                        MAST_Settings.gui.toolbar.selectedDrawToolIndex = -1;
                        MAST_Placement_Interface.ChangePlacementMode(MAST_Placement_Interface.PlacementMode.None);
                    }
                }
                changeMade = true;
            }
            // Toggle randomizer
            if (KeysPressed(currentEvent,
                            MAST_Settings.hotkey.randomizerKey,
                            MAST_Settings.hotkey.randomizerMod))
            {
                // If Randomizer isn't selected, select it
                if (MAST_Settings.gui.toolbar.selectedDrawToolIndex != 3)
                {
                    MAST_Settings.gui.toolbar.selectedDrawToolIndex = 3;
                    MAST_Placement_Interface.ChangePlacementMode(MAST_Placement_Interface.PlacementMode.Randomize);
                }
                else
                {
                    // If Randomizer was selected, deselect it
                    if (MAST_Settings.gui.toolbar.selectedDrawToolIndex == 3)
                    {
                        MAST_Settings.gui.toolbar.selectedDrawToolIndex = -1;
                        MAST_Placement_Interface.ChangePlacementMode(MAST_Placement_Interface.PlacementMode.None);
                    }
                }
                changeMade = true;
            }
            // Toggle erase
            if (KeysPressed(currentEvent,
                            MAST_Settings.hotkey.eraseKey,
                            MAST_Settings.hotkey.eraseMod))
            {
                // If Erase isn't selected, select it
                if (MAST_Settings.gui.toolbar.selectedDrawToolIndex != 4)
                {
                    MAST_Settings.gui.toolbar.selectedDrawToolIndex = 4;
                    MAST_Placement_Interface.ChangePlacementMode(MAST_Placement_Interface.PlacementMode.Erase);
                }
                else
                {
                    // If Erase was selected, deselect it
                    if (MAST_Settings.gui.toolbar.selectedDrawToolIndex == 4)
                    {
                        MAST_Settings.gui.toolbar.selectedDrawToolIndex = -1;
                        MAST_Placement_Interface.ChangePlacementMode(MAST_Placement_Interface.PlacementMode.None);
                    }
                }
                changeMade = true;
            }
            // New random seed
            if (KeysPressed(currentEvent,
                            MAST_Settings.hotkey.newRandomSeedKey,
                            MAST_Settings.hotkey.newRandomSeedMod))
            {
                MAST_Placement_Randomizer.GenerateNewRandomSeed();
                changeMade = true;
            }
            // Rotate prefab
            if (KeysPressed(currentEvent,
                            MAST_Settings.hotkey.rotatePrefabKey,
                            MAST_Settings.hotkey.rotatePrefabMod))
            {
                MAST_Placement_Manipulate.RotateObject();
                changeMade = true;
            }
            // Flip prefab
            if (KeysPressed(currentEvent,
                            MAST_Settings.hotkey.flipPrefabKey,
                            MAST_Settings.hotkey.flipPrefabMod))
            {
                MAST_Placement_Manipulate.FlipObject();
                changeMade = true;
            }
        }

        return(changeMade);
    }