private void EditorLoadLayoutButton_Click(object sender, EventArgs e)
        {
            OpenFileDialog openFileDialog = new OpenFileDialog
            {
                Filter           = "Binaries | *.bin",
                Title            = "Open custom dungeon layout",
                RestoreDirectory = true
            };

            if (openFileDialog.ShowDialog() == DialogResult.OK)
            {
                Stream fs   = openFileDialog.OpenFile();
                byte[] data = new byte[1536];
                fs.Read(data, 0, 1536);

                for (int i = 0; i < data.Length; i++)
                {
                    Vector2 pos = new Vector2(i % 32, (int)Math.Floor((double)i / 32)); //32 is the width of the grid
                    pos.x *= 2;

                    Tile.DomainTileTypeOld tileType = Tile.DomainTileTypeOld.Empty;
                    tileType = (Tile.DomainTileTypeOld)data[i].GetRightNiblet();
                    EditorLayoutRendererOld.UpdateTile(pos, tileType);

                    pos     += Vector2.Right;
                    tileType = (Tile.DomainTileTypeOld)data[i].GetLeftNiblet();
                    EditorLayoutRendererOld.UpdateTile(pos, tileType);
                }

                fs.Close();
                fs.Dispose();
            }
        }
        private void EditorTileTypeButton_Click(object sender, EventArgs e)
        {
            PictureBox pictureBox = (PictureBox)sender;
            string     tileName   = pictureBox.Name.Replace("TileTypePictureBox", "");

            EditorSelectedTileType    = (Tile.DomainTileTypeOld)Enum.Parse(typeof(Tile.DomainTileTypeOld), tileName);
            PlaceModeCheckbox.Checked = true;

            EditorSelectedTileTypePicturebox.Location = new Point(pictureBox.Location.X - 3, pictureBox.Location.Y - 3);
        }
Example #3
0
        public static void UpdateTile(Vector2 position, Tile.DomainTileTypeOld tileType)
        {
            Color tileColour = Tile.TileTypeColourOld[tileType];
            //TODO: This needs to update the actual tile too, not just the displayed pixel
            DomainTileCombo selectedCombo = tiles.FirstOrDefault(o => o.leftTile.Position == position);
            Tile            selectedTile  = null;

            if (selectedCombo == null)
            {
                selectedCombo = tiles.FirstOrDefault(o => o.rightTile.Position == position);
                selectedTile  = selectedCombo.rightTile;
            }
            else
            {
                selectedTile = selectedCombo.leftTile;
            }

            byte currentByteValue = selectedCombo.TileValueDec;

            if (selectedTile.Position.x % 2 == 0)
            {
                //we've got the left tile, meaning we need to set the right nibblet
                currentByteValue = (byte)((currentByteValue & 0xF0) | (byte)selectedTile.GetTileTypeBasedOnColour(tileColour));
            }
            else
            {
                currentByteValue = (byte)((currentByteValue & 0x0F) | ((byte)selectedTile.GetTileTypeBasedOnColour(tileColour) << 0x04));
                //With the right tile we need to edit the right nibblet
            }
            selectedCombo.TileValueDec = currentByteValue;
            selectedCombo.TileValueHex = currentByteValue.ToString("X2");

            //byte b = 0x11;
            //var nibbleValue = 0x02;
            //b = (byte)((b & 0xF0) | nibbleValue);
            //b = (byte)((b & 0x0F) | (nibbleValue << 0x04));

            for (int i = 0; i < tileSize; i++)
            {
                for (int j = 0; j < tileSize; j++)
                {
                    //floorLayoutLayer.SetPixel((position.x * tileSize) + i, (position.y * tileSize) + j, tileColour);
                    //floorLayoutLayer.SetPixel((position.x * tileSize) + i, (position.y * tileSize) + j, tileColour);
                    floorLayoutLayer.SetPixel((position.x * tileSize) + i, (position.y * tileSize) + j, tileColour);
                }
            }


            DigimonWorld2ToolForm.EditorLayoutRenderTab.MapRenderLayer.Image = floorLayoutLayer;
        }