/// <summary> /// Creates a new tile switch from a selected region in a tilemap and adds it to the collection. /// </summary> /// <param name="select">The selection in the tilemap.</param> /// <param name="tilemap">The tilemap to create the tile switch from.</param> public void AddNew(Overlay.Selection select, Tilemap tilemap) { bool alternate = false; if (treeView.SelectedNode != null && treeView.SelectedNode.Nodes.Count == 0 && treeView.SelectedNode.Parent == null) { var result = MessageBox.Show("Create as an alternate tile switch?", "LAZY SHELL", MessageBoxButtons.YesNo, MessageBoxIcon.Question); alternate = result == DialogResult.Yes; } if (!alternate && !AddNew()) { return; } if (alternate && !AddNewAlternate()) { return; } if (!alternate) { this.x.Value = select.X / 16; this.y.Value = select.Y / 16; this.width.Value = select.Width / 16; this.height.Value = select.Height / 16; } bool[] empty = new bool[3]; byte[][] tilemaps = new byte[3][]; int width = alternate ? TileSwitch.Width : select.Width / 16; int height = alternate ? TileSwitch.Height : select.Height / 16; for (int l = 0; l < 3; l++) { if (l < 2) { tilemaps[l] = new byte[(width * height) * 2]; } else { tilemaps[l] = new byte[width * height]; } for (int y = 0; y < height; y++) { for (int x = 0; x < width; x++) { int tileX = select.Location.X + (x * 16); int tileY = select.Location.Y + (y * 16); int tile = tilemap.GetTileNum(l, tileX, tileY); if (tile != 0) { empty[l] = false; } int index = y * width + x; if (l < 2) { Bits.SetShort(tilemaps[l], index * 2, (ushort)tile); } else { tilemaps[l][index] = (byte)tile; } } } if (!alternate) { layers.SetItemChecked(l, !empty[l]); layers.SelectedIndex = -1; TileSwitch.Tilemaps_bytesA[l] = tilemaps[l]; } else { TileSwitch.Tilemaps_bytesB[l] = tilemaps[l]; } } if (!alternate) { TileSwitch.TilemapA = new AreaTilemap(area, tileset, TileSwitch, false); } else { TileSwitch.TilemapB = new AreaTilemap(area, tileset, TileSwitch, true); } }
private void InitializeVariables() { selection = new Overlay.Selection(); collision = Collision.Instance; tileset = new OverlapTileset(); }