Example #1
0
    private void DrawGameboardTools()
    {
        EditorGUILayout.Separator();
        EditorGUILayout.LabelField("Viewing Options", EditorStyles.boldLabel);

        EditorGUILayout.BeginHorizontal();
        if (GUILayout.Button("Toggle Locks", GUILayout.MaxWidth(150f)))
        {
            GameboardTools.ToggleLocks();
            EditorSceneManager.MarkSceneDirty(EditorSceneManager.GetActiveScene());
        }
        EditorGUILayout.EndHorizontal();

        EditorGUILayout.Separator();
        EditorGUILayout.LabelField("Board Manipulation", EditorStyles.boldLabel);

        if (GUILayout.Button("Clear All Boards", GUILayout.MaxWidth(150f)))
        {
            GameboardTools.ClearGameboard(true, true);
            GameboardTools.ClearSolutionboard(true, true);
            EditorSceneManager.MarkSceneDirty(EditorSceneManager.GetActiveScene());
        }

        if (GUILayout.Button("Reset All Slot References", GUILayout.MaxWidth(150f)))
        {
            if (gameManager == null)
            {
                gameManager = GameObject.FindObjectOfType <GameManager>();
            }

            GameboardTools.SetAllGameSlotReferences(gameManager.gameBoardParent);
            GameboardTools.SetAllGameSlotReferences(gameManager.solutionBoardParent);
        }

        #region Gameboard Manipulation
        viewingGameboardSection = EditorGUILayout.Foldout(viewingGameboardSection, "GameBoard Tools");

        if (viewingGameboardSection)
        {
            EditorGUILayout.BeginHorizontal();
            if (GUILayout.Button("Resize GameShapes", GUILayout.MaxWidth(150f)))
            {
                GameboardTools.ResizeGameShapes(sizing != 0 ? sizing : boardManager.shapeSize);
                EditorSceneManager.MarkSceneDirty(EditorSceneManager.GetActiveScene());
            }

            sizing = EditorGUILayout.FloatField(sizing, GUILayout.MaxWidth(50f));
            EditorGUILayout.EndHorizontal();

            EditorGUILayout.Separator();
            if (GUILayout.Button("Reset Slot References", GUILayout.MaxWidth(150f)))
            {
                if (gameManager == null)
                {
                    gameManager = GameObject.FindObjectOfType <GameManager>();
                }

                GameboardTools.SetAllGameSlotReferences(gameManager.gameBoardParent);
            }

            EditorGUILayout.Separator();
            if (GUILayout.Button("Clear GameBoard", GUILayout.MaxWidth(150f)))
            {
                GameboardTools.ClearGameboard(true, true);
                EditorSceneManager.MarkSceneDirty(EditorSceneManager.GetActiveScene());
            }

            EditorGUILayout.BeginHorizontal();
            if (GUILayout.Button("Clear Shapes", GUILayout.MaxWidth(150f)))
            {
                GameboardTools.ClearGameboard(true, false);
                EditorSceneManager.MarkSceneDirty(EditorSceneManager.GetActiveScene());
            }

            if (GUILayout.Button("Clear Locks", GUILayout.MaxWidth(150f)))
            {
                GameboardTools.ClearGameboard(false, true);
                EditorSceneManager.MarkSceneDirty(EditorSceneManager.GetActiveScene());
            }
            EditorGUILayout.EndHorizontal();
        }
        #endregion

        #region Solutionboard Manipulation
        viewingSolutionboardSection = EditorGUILayout.Foldout(viewingSolutionboardSection, "SolutionBoard Tools");

        if (viewingSolutionboardSection)
        {
            EditorGUILayout.BeginHorizontal();
            if (GUILayout.Button("Resize GameShapes", GUILayout.MaxWidth(150f)))
            {
                GameboardTools.ResizeGameShapes(sizing != 0 ? sizing : boardManager.shapeSize);
                EditorSceneManager.MarkSceneDirty(EditorSceneManager.GetActiveScene());
            }

            sizing = EditorGUILayout.FloatField(sizing, GUILayout.MaxWidth(50f));
            EditorGUILayout.EndHorizontal();

            EditorGUILayout.Separator();
            if (GUILayout.Button("Reset Slot References", GUILayout.MaxWidth(150f)))
            {
                if (gameManager == null)
                {
                    gameManager = GameObject.FindObjectOfType <GameManager>();
                }

                GameboardTools.SetAllGameSlotReferences(gameManager.solutionBoardParent);
            }

            EditorGUILayout.Separator();
            if (GUILayout.Button("Clear SolutionBoard", GUILayout.MaxWidth(150f)))
            {
                GameboardTools.ClearSolutionboard(true, true);
                EditorSceneManager.MarkSceneDirty(EditorSceneManager.GetActiveScene());
            }

            EditorGUILayout.BeginHorizontal();
            if (GUILayout.Button("Clear Shapes", GUILayout.MaxWidth(150f)))
            {
                GameboardTools.ClearGameboard(true, false);
                EditorSceneManager.MarkSceneDirty(EditorSceneManager.GetActiveScene());
            }

            if (GUILayout.Button("Clear Locks", GUILayout.MaxWidth(150f)))
            {
                GameboardTools.ClearGameboard(false, true);
                EditorSceneManager.MarkSceneDirty(EditorSceneManager.GetActiveScene());
            }
            EditorGUILayout.EndHorizontal();
        }
        #endregion
    }
Example #2
0
    private void DrawLevelGenerator()
    {
        #region General Board Settings
        EditorGUILayout.LabelField("Board Settings", EditorStyles.boldLabel);
        EditorGUILayout.Separator();

        genShapePrefs.targetShapeScale = EditorGUILayout.FloatField("Shape Scale", genShapePrefs.targetShapeScale, GUILayout.MaxWidth(200f));
        #endregion
        EditorGUILayout.Separator();

        #region Shape Settings
        EditorGUILayout.LabelField("Shape Settings", EditorStyles.boldLabel, GUILayout.MaxWidth(150f));
        EditorGUILayout.Separator();

        string[]            shapeTags = Enum.GetNames(typeof(GameShape.ShapeType));
        GameShape.ShapeType currentShapeType;
        for (int i = 0; i < shapeTags.Length; i++)
        {
            currentShapeType = (GameShape.ShapeType)i;

            EditorGUILayout.BeginHorizontal();
            if (GUILayout.Button("+", GUILayout.Width(20f), GUILayout.Height(20f)))
            {
                if (genShapePrefs.shapes.TryGetValue(currentShapeType, out int sCount))
                {
                    genShapePrefs.shapes[currentShapeType] = Mathf.Clamp(sCount + 1, 0, sCount + genShapePrefs.GetRemainingShapes(GetBoardSize()));
                }
                else
                {
                    genShapePrefs.shapes.Add(currentShapeType, Mathf.Clamp(1, 0, sCount + genShapePrefs.GetRemainingShapes(GetBoardSize())));
                }
            }

            if (GUILayout.Button("-", GUILayout.Width(20f), GUILayout.Height(20f)))
            {
                if (genShapePrefs.shapes.TryGetValue(currentShapeType, out int sCount))
                {
                    genShapePrefs.shapes[currentShapeType] = Mathf.Clamp(sCount - 1, 0, sCount + genShapePrefs.GetRemainingShapes(GetBoardSize()));
                }
                else
                {
                    genShapePrefs.shapes.Add(currentShapeType, 0);
                }
            }

            int squareCount = genShapePrefs.shapes.TryGetValue(currentShapeType, out int squares) ? squares : 0;
            EditorGUILayout.LabelField($"{shapeTags[i]}: {squareCount}", GUILayout.Width(75f), GUILayout.Height(20f));
            EditorGUILayout.EndHorizontal();
        }
        #endregion
        EditorGUILayout.Separator();

        #region Color Settings
        EditorGUILayout.LabelField("Color Settings", EditorStyles.boldLabel, GUILayout.MaxWidth(150f));
        EditorGUILayout.Separator();

        string[]            colorTags = Enum.GetNames(typeof(GameShape.ColorType));
        GameShape.ColorType currentColorType;
        for (int i = 0; i < shapeTags.Length; i++)
        {
            currentColorType = (GameShape.ColorType)i;

            EditorGUILayout.BeginHorizontal();
            if (GUILayout.Button("+", GUILayout.Width(20f), GUILayout.Height(20f)))
            {
                if (genShapePrefs.colors.TryGetValue(currentColorType, out int sCount))
                {
                    genShapePrefs.colors[currentColorType] = Mathf.Clamp(sCount + 1, 0, sCount + genShapePrefs.GetRemainingColors(GetBoardSize()));
                }
                else
                {
                    genShapePrefs.colors.Add(currentColorType, Mathf.Clamp(1, 0, sCount + genShapePrefs.GetRemainingColors(GetBoardSize())));
                }
            }

            if (GUILayout.Button("-", GUILayout.Width(20f), GUILayout.Height(20f)))
            {
                if (genShapePrefs.colors.TryGetValue(currentColorType, out int sCount))
                {
                    genShapePrefs.colors[currentColorType] = Mathf.Clamp(sCount - 1, 0, sCount + genShapePrefs.GetRemainingColors(GetBoardSize()));
                }
                else
                {
                    genShapePrefs.colors.Add(currentColorType, 0);
                }
            }

            int squareCount = genShapePrefs.colors.TryGetValue(currentColorType, out int squares) ? squares : 0;
            EditorGUILayout.LabelField($"{colorTags[i]}: {squareCount}", GUILayout.Width(75f), GUILayout.Height(20f));
            EditorGUILayout.EndHorizontal();
        }
        #endregion
        EditorGUILayout.Separator();

        if (genPrefsMismatchError)
        {
            EditorGUILayout.LabelField("Ensure the selected shape count and color count match before generating a level", EditorStyles.helpBox);
        }

        if (zeroShapeScaleError)
        {
            EditorGUILayout.LabelField("Ensure the shape size is more that 0 before generating a level", EditorStyles.helpBox);
        }

        EditorGUILayout.BeginHorizontal();
        if (GUILayout.Button("Generate Board", GUILayout.MaxWidth(200f)))
        {
            genPrefsMismatchError = (genShapePrefs.GetCurrentColorCount() != genShapePrefs.GetCurrentShapeCount());
            zeroShapeScaleError   = (genShapePrefs.targetShapeScale <= 0f);

            if (!genPrefsMismatchError && !zeroShapeScaleError)
            {
                GameboardTools.ClearGameboard(true, true);
                LevelGenerator.GenerateGameboardShapes(genShapePrefs);
            }
        }

        if (GUILayout.Button("Clear Board", GUILayout.MaxWidth(150f)))
        {
            GameboardTools.ClearGameboard(true, true);
        }
        EditorGUILayout.EndHorizontal();

        EditorGUILayout.Separator();
        EditorGUILayout.BeginHorizontal();
        if (GUILayout.Button("Recreate Gameboard"))
        {
            GameManager manager = GameObject.Find("LevelManager").GetComponent <GameManager>();
            LevelGenerator.RecreateBoard(manager.gameBoardParent);
        }

        if (GUILayout.Button("Recreate Solutionboard"))
        {
            GameManager manager = GameObject.Find("LevelManager").GetComponent <GameManager>();
            LevelGenerator.RecreateBoard(manager.solutionBoardParent);
        }
        EditorGUILayout.EndHorizontal();
    }