Example #1
0
    void DrawTerrainAndBuildingsGUI(int WindowID)
    {
        //
        //Draw Buttons and catch the button on which is pressed in these new ints
        int terrainListEntry   = -1;
        int buildingsListEntry = -1;

        //Terrain
        GUI.Label(new Rect(10, 20, 200, 20), "Terrain");
        terrainListEntry = GUI.SelectionGrid(new Rect(10, 40, 200, 160), -1, TileTypes.TerrainGUIContentList, 3);
        //Buildings
        GUI.Label(new Rect(10, 210, 200, 20), "Buildings");
        _selectedBuildingsColour = (TeamsInfo.Colour)GUI.SelectionGrid(new Rect(10, 230, 200, 20), (int)_selectedBuildingsColour, TeamsInfo.ColourGUIContentList, 7);
        buildingsListEntry       = GUI.SelectionGrid(new Rect(10, 260, 200, 80), -1, TileTypes.BuildingsGUIContentList, 3);
        //
        //See if any button was hit this time
        if (terrainListEntry != -1 || buildingsListEntry != -1)
        {
            //If left button was pressed
            if (Event.current.button == 0)             //LEFT
            {
                //Convert terrain id to list id
                int id = TileTypes.TerrainIDToListID(terrainListEntry);
                //See if it is a proper ListID
                if (id >= 0)
                {
                    //Set the left type
                    _leftType = TileTypes.GetTileInfo(id);
                }
                //If it is not a proper listID try the same for buildingsListEntry
                else
                {
                    id = TileTypes.BuildingsIDToListID(buildingsListEntry);
                    if (id >= 0)
                    {
                        _leftType = TileTypes.GetTileInfo(id);
                    }
                }

                //Remember id to be able to draw the mouse icons.
                _leftListEntry = id;
            }
            //And the same for the right button
            else if (Event.current.button == 1)             //RIGHT
            {
                int id = TileTypes.TerrainIDToListID(terrainListEntry);
                if (id >= 0)
                {
                    _rightType = TileTypes.GetTileInfo(id);
                }
                else
                {
                    id = TileTypes.BuildingsIDToListID(buildingsListEntry);
                    if (id >= 0)
                    {
                        _rightType = TileTypes.GetTileInfo(id);
                    }
                }

                //Remember id to be able to draw the mouse icons.
                _rightListEntry = id;
            }
        }

        //
        //Draw the mouse icons on the correct button
        //------------------------------------------------------------------------------------
        Rect leftPos  = new Rect(0, 0, 11, 14),
             rightPos = new Rect(0, 0, 11, 14);
        //Calculate the x-positions
        int step   = 68;
        int offset = -6;

        if (_leftListEntry < TileTypes.NumberOfTerrainTypes())
        {
            leftPos.x = (_leftListEntry % 3 + 1) * step + offset;
        }
        else
        {
            leftPos.x = ((_leftListEntry - TileTypes.NumberOfTerrainTypes()) % 3 + 1) * step + offset;
        }
        if (_rightListEntry < TileTypes.NumberOfTerrainTypes())
        {
            rightPos.x = (_rightListEntry % 3 + 1) * step + offset;
        }
        else
        {
            rightPos.x = ((_rightListEntry - TileTypes.NumberOfTerrainTypes()) % 3 + 1) * step + offset;
        }

        //Now calculate the y-positions
        int stepY       = 41;
        int buildingsY  = 220;
        int extraY      = 3;
        int rightExtraY = 16;

        if (_leftListEntry < TileTypes.NumberOfTerrainTypes())
        {
            leftPos.y = (_leftListEntry / 3 + 1) * stepY + extraY;
        }
        else
        {
            leftPos.y = ((_leftListEntry - TileTypes.NumberOfTerrainTypes()) / 3 + 1) * stepY + buildingsY + extraY;
        }
        if (_rightListEntry < TileTypes.NumberOfTerrainTypes())
        {
            rightPos.y = (_rightListEntry / 3 + 1) * stepY + rightExtraY + extraY;
        }
        else
        {
            rightPos.y = ((_rightListEntry - TileTypes.NumberOfTerrainTypes()) / 3 + 1) * stepY + buildingsY + rightExtraY + extraY;
        }

        //Draw Left
        GUI.DrawTexture(leftPos, _mouseLeft);
        //Draw Right
        GUI.DrawTexture(rightPos, _mouseRight);

        DrawGUIWindowCloseButton(ref _drawTerrainAndBuildingsWindow);
        GUI.DragWindow(new Rect(0, 0, 10000, 20));
    }