예제 #1
0
    private bool LoadVersionOne(BinaryReader reader, out string name, out string description)
    {
        //string; Level Name
        name = reader.ReadString();
        //string; Description
        description = reader.ReadString();
        //byte; cols
        byte cols = reader.ReadByte();
        //byte; rows
        byte rows = reader.ReadByte();

        //Create new board with just-read dimentions
        DestroyCurrentBoard();
        BoardTiles = new BasicTile[cols, rows];

        //4 bytes per tile
        for (int c = 0; c < cols; ++c)
        {
            for (int r = 0; r < rows; ++r)
            {
                //4bytes -> 2byte type; 1bytes color; 1byte other
                ushort type  = reader.ReadUInt16();
                byte   color = reader.ReadByte();
                byte   other = reader.ReadByte();

                BoardTiles[c, r] = CreateNewTileOfType(TileTypes.GetTileInfo(type), (TeamsInfo.Colour)color, c, r);
            }
        }

        return(true);
    }
예제 #2
0
    public bool SaveBoard(string name, string description, string folderPath)
    {
        try
        {
            //Make filepath
            string fullPath = folderPath;
            if (!folderPath.EndsWith("/"))
            {
                fullPath += "/";
            }
            fullPath += name + ".mwm";

            //Save the actual file
            Directory.CreateDirectory(folderPath);
            using (FileStream stream = new FileStream(fullPath, FileMode.Create))
            {
                using (BinaryWriter writer = new BinaryWriter(stream))
                {
                    //4bytes; File Version
                    writer.Write((uint)1);
                    //string; Level Name
                    writer.Write(name);
                    //string; Description
                    writer.Write(description);
                    //byte; cols
                    writer.Write((byte)GetNumberOfColumns());
                    //byte; rows
                    writer.Write((byte)GetNumberOfRows());
                    //4 bytes per tile
                    for (int c = 0, cols = GetNumberOfColumns(); c < cols; ++c)
                    {
                        for (int r = 0, rows = GetNumberOfRows(); r < rows; ++r)
                        {
                            BasicTile tile  = GetTileOnPos(c, r);
                            ushort    type  = TileTypes.GetTileInfo(tile.tag).Number;
                            byte      col   = (byte)tile.Colour;
                            byte      other = 100;
                            //4bytes -> 2byte type; 1bytes color; 1byte other
                            writer.Write(type);
                            writer.Write(col);
                            writer.Write(other);
                        }
                    }
                    //Close the write (automaticly also closes the stream)
                    writer.Close();
                }
            }

            UnityGrowl.Show("Saved !\nYour level has succesfully been saved.");
            return(true);
        }
        catch
        {
            UnityGrowl.Show("Save error\nAn error has occured during saving.\nMake sure the map/file is not read-only.", 5);
            return(false);
        }
    }
예제 #3
0
    private void ChangeTileToType(TileInfo newTileInfo, TeamsInfo.Colour newColour, int col, int row)
    {
        TileInfo oldTileInfo = TileTypes.GetTileInfo(_boardScript.BoardTiles[col, row].tag);

        TeamsInfo.Colour oldColour = _boardScript.BoardTiles[col, row].Colour;
        if (oldTileInfo.Number == newTileInfo.Number && oldColour == newColour)
        {
            return;
        }
        else if (oldTileInfo.Number == newTileInfo.Number && oldColour != newColour)
        {
            _boardScript.BoardTiles[col, row].Colour = newColour;
        }
        else
        {
            Destroy(_boardScript.BoardTiles[col, row].gameObject);
            _boardScript.BoardTiles[col, row] = CreateNewTileOfType(newTileInfo, newColour, col, row);
            //Play Sound
            SoundManager.PlayEditorTileChange();
        }
    }
예제 #4
0
    void ChangeBoardSize(int newNumCols, int newNumRows, int dir, TileInfo tileInfo)
    {
//		0=UL 1=UM 2=UR
//		3=L 4=M 5=R
//		6=LL 7=LM 8=LR
        //Check if there is a resizing
        if (newNumCols == _boardScript.GetNumberOfColumns() && newNumRows == _boardScript.GetNumberOfRows())
        {
            return;
        }
        //Backup the old array
        BasicTile[,] backupArr = (BasicTile[, ])_boardScript.BoardTiles.Clone();

        //Set begin position for copy depending on the direction

        // COLUMNS //
        int beginColNew;
        int beginColBackup;

        if (newNumCols == _boardScript.GetNumberOfColumns())
        {
            beginColNew    = 0;
            beginColBackup = 0;
        }
        else if (newNumCols > _boardScript.GetNumberOfColumns())
        {
            if (dir == 0 || dir == 3 || dir == 6)
            {
                beginColNew = 0;
            }
            else if (dir == 1 || dir == 4 || dir == 7)
            {
                beginColNew = (newNumCols - _boardScript.GetNumberOfColumns()) / 2;
            }
            else
            {
                beginColNew = newNumCols - _boardScript.GetNumberOfColumns();
            }

            beginColBackup = 0;
        }
        else
        {
            if (dir == 0 || dir == 3 || dir == 6)
            {
                beginColBackup = 0;
            }
            else if (dir == 1 || dir == 4 || dir == 7)
            {
                beginColBackup = (_boardScript.GetNumberOfColumns() - newNumCols) / 2;
            }
            else
            {
                beginColBackup = _boardScript.GetNumberOfColumns() - newNumCols;
            }

            beginColNew = 0;
        }

        // ROWS //
        int beginRowNew;
        int beginRowBackup;

        if (newNumRows == _boardScript.GetNumberOfRows())
        {
            beginRowNew    = 0;
            beginRowBackup = 0;
        }
        else if (newNumRows > _boardScript.GetNumberOfRows())
        {
            if (dir == 6 || dir == 7 || dir == 8)           // || newNumRows <= _boardScript.GetNumberOfRows())
            {
                beginRowNew = 0;
            }
            else if (dir == 3 || dir == 4 || dir == 5)
            {
                beginRowNew = (newNumRows - _boardScript.GetNumberOfRows()) / 2;
            }
            else
            {
                beginRowNew = newNumRows - _boardScript.GetNumberOfRows();
            }

            beginRowBackup = 0;
        }
        else
        {
            if (dir == 6 || dir == 7 || dir == 8)           // || newNumRows <= _boardScript.GetNumberOfRows())
            {
                beginRowBackup = 0;
            }
            else if (dir == 3 || dir == 4 || dir == 5)
            {
                beginRowBackup = (_boardScript.GetNumberOfRows() - newNumRows) / 2;
            }
            else
            {
                beginRowBackup = _boardScript.GetNumberOfRows() - newNumRows;
            }

            beginRowNew = 0;
        }

        //Create the new board
        CreateNewBoard(newNumCols, newNumRows, tileInfo);

        //To copy (when reducing size)
        int colsToCopy = Mathf.Min(backupArr.GetLength(0), newNumCols);
        int rowsToCopy = Mathf.Min(backupArr.GetLength(1), newNumRows);;

        //Copy backup into new with proper begin position
        for (int col = 0; col < colsToCopy; ++col)
        {
            for (int row = 0; row < rowsToCopy; ++row)
            {
                TileInfo         oldTileInfo = TileTypes.GetTileInfo(backupArr[beginColBackup + col, beginRowBackup + row].tag);
                TeamsInfo.Colour oldColour   = backupArr[beginColBackup + col, beginRowBackup + row].Colour;
                ChangeTileToType(oldTileInfo, oldColour, beginColNew + col, beginRowNew + row);
            }
        }
    }
예제 #5
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));
    }