예제 #1
0
    void drawLayoutTable()
    {
        if (GUILayout.Button("Launch Window", GUILayout.Width(250)))
        {
            EditorWindow.GetWindow(typeof(BoardLayoutWindow), false, "Board Setup");
        }

        if (GUILayout.Button("Show/Hide Panel 1", GUILayout.Width(250)))
        {
            hidePanel1.boolValue = !hidePanel1.boolValue;
        }
        if (!hidePanel1.boolValue)
        {
            drawPanel1();
        }

        if (GUILayout.Button("Show/Hide Panel 2", GUILayout.Width(250)))
        {
            hidePanel2.boolValue = !hidePanel2.boolValue;
        }

        if (!hidePanel2.boolValue)
        {
            drawPanel2();
        }

        if (GUILayout.Button("Show/Hide NOTES", GUILayout.Width(250)))
        {
            hidePanel3.boolValue = !hidePanel3.boolValue;
        }

        if (!hidePanel3.boolValue)
        {
            drawPanel3();
        }

        // custom inspector auto naming for ease of use.
        for (int x = 0; x < panelEditVisuals.arraySize; x++)
        {
            bl.panelEditVisuals[x].name = scripts[x].GetType().Name + "'s";
            panelEditVisuals.GetArrayElementAtIndex(x).isExpanded = true;
        }
        for (int x = 0; x < pieceEditVisuals.arraySize; x++)
        {
            bl.pieceEditVisuals[x].name = pieces[x].GetType().Name + "'s";
            pieceEditVisuals.GetArrayElementAtIndex(x).isExpanded = true;
        }
        for (int x = 0; x < randomPanelLimit.arraySize; x++)
        {
            bl.randomPanelLimit[x].name = scripts[x].GetType().Name + "'s";
            randomPanelLimit.GetArrayElementAtIndex(x).isExpanded = true;
        }


        EditorGUILayout.LabelField("\n*If enabled, will generate a random board" +
                                   "\nwhenever a new game starts disregarding the below layout.", GUILayout.Height(45));

        EditorGUILayout.BeginHorizontal();
        EditorGUILayout.PropertyField(randomOnStart, new GUILayoutOption[] { GUILayout.MinHeight(0), GUILayout.Width(200) });
        EditorGUILayout.PropertyField(showHexGrid, new GUIContent("Hex Layout in Hex Mode"), GUILayout.MinWidth(0));
        EditorGUILayout.EndHorizontal();

        EditorGUILayout.BeginHorizontal();
        EditorGUILayout.PropertyField(useSelector, new GUILayoutOption[] { GUILayout.Height(30), GUILayout.Width(200) });
        EditorGUILayout.LabelField("<-- hold 'ctrl-btn' to alternate between the modes during clicks", GUILayout.MinWidth(0));
        EditorGUILayout.EndHorizontal();


        if (panelArray != null && !Application.isPlaying)
        {
            // selector switching for easy selector usage via ctrl-btn to alternate between itself
            if (Event.current.control == true)
            {
                selectorSwitch = !bl.useSelector;
            }
            else
            {
                selectorSwitch = bl.useSelector;
            }

            GUILayoutOption[] scrollParams = { GUILayout.MinHeight(200), GUILayout.MaxHeight(888) };
            scrollPos.vector2Value = EditorGUILayout.BeginScrollView(scrollPos.vector2Value, scrollParams);

            int count = 0;
            GUILayoutOption[] layoutParams = { GUILayout.Width(35), GUILayout.Height(35) };

            EditorGUILayout.BeginHorizontal();
            for (int x = 0; x < Mathf.Min(bl.gm.boardWidth, 20); x++)
            {
                EditorGUILayout.BeginVertical();
                // hexagon displacement
                //if(x%2 == 1 && bl.showHexGrid && bl.gm.boardType == BoardType.Hexagon){
                if (x % 2 == 1 && bl.showHexGrid)
                {
                    EditorGUILayout.LabelField("", new GUILayoutOption[] { GUILayout.Height(25), GUILayout.Width(0) });
                }
                for (int y = 0; y < Mathf.Min(bl.gm.boardHeight, 20); y++)
                {
                    count = x + (bl.gm.boardWidth * y);
                    EditorGUILayout.BeginHorizontal();

                    // the strength field
                    pStrength.GetArrayElementAtIndex(count).intValue =
                        EditorGUILayout.IntField(pStrength.GetArrayElementAtIndex(count).intValue,
                                                 new GUILayoutOption[] { GUILayout.Width(30), GUILayout.Height(18) });
                    // color selection
                    GUI.backgroundColor = bColor[bl.colorArray[count]]; // render the color to the gui button
                    if (GUILayout.Button("", new GUILayoutOption[] { GUILayout.ExpandWidth(false) }))
                    {
                        if (Event.current.button == 0)
                        {
                            bl.toggleColor(count, 1);
                        }
                        else
                        {
                            bl.toggleColor(count, -1);
                        }
                    }
                    GUI.backgroundColor = Color.white; // back to normal color for other GUIs
                    // weights selection
                    if (bl.colorArray[count] == 0)
                    { // show weights option if no color grouping...
                        if (bl.colorWeight[count].useWeights)
                        {
                            GUI.backgroundColor = Color.green;
                        }
                        if (GUILayout.Button("w", new GUILayoutOption[] { GUILayout.Width(22), GUILayout.Height(18) }))
                        {
                            EditorWindow.GetWindow(typeof(BoardLayoutWeightsWindow), false, "Set Weights");
                            BoardLayoutWeightsWindow.setDisplayType(count);
                        }
                    }
                    GUI.backgroundColor = Color.white; // back to normal color for other GUIs
                    EditorGUILayout.EndHorizontal();
                    EditorGUILayout.BeginHorizontal();
                    // panels selection
                    int num = panelArray.GetArrayElementAtIndex(count).intValue;
                    if (num > bl.panelEditVisuals.Length - 1)
                    { // script out of bounds, auto-fix!
                        bl.togglePanel(count, -1);
                        num = bl.panelArray[count];
                    }
                    if (bl.panelEditVisuals[num] != null && bl.panelEditVisuals[num].texture != null)
                    { // assigned texture version
                        if (GUILayout.Button(bl.panelEditVisuals[num].texture, GUI.skin.box, layoutParams))
                        {
                            if (selectorSwitch)
                            {
                                EditorWindow.GetWindow(typeof(BoardLayoutChooserWindow), false, "Choose Type");
                                BoardLayoutChooserWindow.setDisplayType(count, false);
                            }
                            else
                            {
                                if (Event.current.button == 0)
                                {
                                    bl.togglePanel(count, 1);
                                }
                                else
                                {
                                    bl.togglePanel(count, -1);
                                }
                            }
                        }
                    }
                    else
                    { // script name version
                        if (GUILayout.Button(bl.panelScripts[num].GetType().Name.Substring(0,
                                                                                           Mathf.Min(5, bl.panelScripts[num].name.Length)).ToString().Replace("Panel", ""),
                                             new GUILayoutOption[] { GUILayout.ExpandWidth(false) }))
                        {
                            if (selectorSwitch)
                            {
                                EditorWindow.GetWindow(typeof(BoardLayoutChooserWindow), false, "Choose Type");
                                BoardLayoutChooserWindow.setDisplayType(count, false);
                            }
                            else
                            {
                                if (Event.current.button == 0)
                                {
                                    bl.togglePanel(count, 1);
                                }
                                else
                                {
                                    bl.togglePanel(count, -1);
                                }
                            }
                        }
                    }

                    // pieces selection
                    int type = pieceArray.GetArrayElementAtIndex(count).intValue;
                    if (type > bl.pieceScripts.Length - 1)
                    { // script out of bounds, auto-fix!
                        bl.togglePiece(count, -1);
                        type = bl.pieceArray[count];
                    }
                    if (bl.pieceEditVisuals[type] != null && bl.pieceEditVisuals[type].texture != null)
                    { // assigned texture version
                        if (GUILayout.Button(bl.pieceEditVisuals[type].texture, GUI.skin.label, layoutParams))
                        {
                            if (selectorSwitch)
                            {
                                EditorWindow.GetWindow(typeof(BoardLayoutChooserWindow), false, "Choose Type");
                                BoardLayoutChooserWindow.setDisplayType(count, true);
                            }
                            else
                            {
                                if (Event.current.button == 0)
                                {
                                    bl.togglePiece(count, 1);
                                }
                                else
                                {
                                    bl.togglePiece(count, -1);
                                }
                            }
                        }
                    }
                    else if (bl.pieceScripts[type] != null)
                    { // assigned texture version
                        if (GUILayout.Button(pieces[type].GetType().ToString().Replace("Piece", ""),
                                             new GUILayoutOption[] { GUILayout.ExpandWidth(false) }))
                        {
                            if (selectorSwitch)
                            {
                                EditorWindow.GetWindow(typeof(BoardLayoutChooserWindow), false, "Choose Type");
                                BoardLayoutChooserWindow.setDisplayType(count, true);
                            }
                            else
                            {
                                if (Event.current.button == 0)
                                {
                                    bl.togglePiece(count, 1);
                                }
                                else
                                {
                                    bl.togglePiece(count, -1);
                                }
                            }
                        }
                    }
                    EditorGUILayout.EndHorizontal();
                    EditorGUILayout.Space();
                }
                EditorGUILayout.EndVertical();
            }
            EditorGUILayout.EndHorizontal();

            EditorGUILayout.Space(); EditorGUILayout.Space(); EditorGUILayout.Space();
            EditorGUILayout.EndScrollView();
        }
        GUILayoutOption[] scrollParams2 = { GUILayout.MinHeight(90) };
        scrollPos2.vector2Value = EditorGUILayout.BeginScrollView(scrollPos2.vector2Value, scrollParams2);
        // the bottom buttons for easy board modifications
        EditorGUILayout.BeginHorizontal();
        GUILayoutOption[] layoutParams2 = { GUILayout.Width(80), GUILayout.Height(30) };

        if (GUILayout.Button("Reset All", layoutParams2))
        {
            bl.resetMe();
        }

        if (GUILayout.Button("Click All", layoutParams2))
        {
            if (Event.current.button == 0)
            {
                bl.clickAll(1);
            }
            else
            {
                bl.clickAll(-1);
            }
        }
        if (GUILayout.Button("Randomize!", layoutParams2))
        {
            bl.randomize();
        }
        EditorGUILayout.EndHorizontal();
        EditorGUILayout.BeginHorizontal();
        layoutParams2 = new GUILayoutOption[] { GUILayout.Width(90), GUILayout.Height(30) };
        if (GUILayout.Button("Reset Pieces", layoutParams2))
        {
            bl.resetPieceOnly();
        }
        if (GUILayout.Button("Reset Color", layoutParams2))
        {
            bl.resetColorOnly();
        }
        if (GUILayout.Button("Reset Panels", layoutParams2))
        {
            bl.resetPanelOnly();
        }
        EditorGUILayout.EndHorizontal();
        EditorGUILayout.EndScrollView();
    }