/* * Events */ private void addButton_Click(object sender, EventArgs e) { Tileset t = new Tileset(); t.Name = getNewName(); tilesets.Add(t); listBox.SelectedIndex = listBox.Items.Add(t.Name); }
public TileLayer(Level level, TileLayerDefinition definition) : base(level, definition) { Definition = definition; Tileset = Ogmo.Project.Tilesets[0]; int tileWidth = Level.Size.Width / definition.Grid.Width + (Level.Size.Width % definition.Grid.Width != 0 ? 1 : 0); int tileHeight = Level.Size.Height / definition.Grid.Height + (Level.Size.Height % definition.Grid.Height != 0 ? 1 : 0); Tiles = new int[tileWidth, tileHeight]; Clear(); InitCanvas(); }
public override void Do() { base.Do(); was = TileLayer.Tileset; TileLayer.Tileset = setTo; oldIDs = TileLayer.Tiles; TileLayer.Tiles = setTo.TransformMap(was, TileLayer.Tiles); TileLayer.TileCanvas.RefreshAll(); Ogmo.TilePaletteWindow.SetTileset(setTo); }
public override bool SetXML(XmlElement xml) { Clear(); bool cleanXML = true; //Load the tileset string tilesetName = xml.Attributes["tileset"].InnerText; Tileset = Ogmo.Project.Tilesets.Find(t => t.Name == tilesetName); //Get the export mode TileLayerDefinition.TileExportMode exportMode; if (xml.Attributes["exportMode"] != null) exportMode = (TileLayerDefinition.TileExportMode)Enum.Parse(typeof(TileLayerDefinition.TileExportMode), xml.Attributes["exportMode"].InnerText); else exportMode = Definition.ExportMode; if (exportMode == TileLayerDefinition.TileExportMode.CSV || exportMode == TileLayerDefinition.TileExportMode.TrimmedCSV) { //CSV Import string s = xml.InnerText; string[] rows = s.Split('\n'); if (rows.Length > Tiles.GetLength(1)) { Array.Resize(ref rows, Tiles.GetLength(1)); cleanXML = false; } for (int i = 0; i < rows.Length; i++) { string[] tiles = rows[i].Split(','); if (tiles.Length > Tiles.GetLength(0)) { Array.Resize(ref tiles, Tiles.GetLength(0)); cleanXML = false; } if (tiles[0] != "") for (int j = 0; j < tiles.Length; j++) Tiles[j, i] = Convert.ToInt32(tiles[j]); } } else if (exportMode == TileLayerDefinition.TileExportMode.XML || exportMode == TileLayerDefinition.TileExportMode.XMLCoords) { //XML Import foreach (XmlElement tile in xml) { int x = Convert.ToInt32(tile.Attributes["x"].InnerText); int y = Convert.ToInt32(tile.Attributes["y"].InnerText); if (tile.Attributes["id"] != null) { int id = Convert.ToInt32(tile.Attributes["id"].InnerText); Tiles[x, y] = id; } else if (tile.Attributes["tx"] != null && tile.Attributes["ty"] != null) { int tx = Convert.ToInt32(tile.Attributes["tx"].InnerText); int ty = Convert.ToInt32(tile.Attributes["ty"].InnerText); Tiles[x, y] = Tileset.GetIDFromCell(new Point(tx, ty)); } } } TileCanvas.RefreshAll(); return cleanXML; }
public int[,] TransformMap(Tileset from, int[,] ids) { int[,] transformed = new int[ids.GetLength(0), ids.GetLength(1)]; for (int i = 0; i < ids.GetLength(0); i++) for (int j = 0; j < ids.GetLength(1); j++) transformed[i, j] = TransformID(from, ids[i, j]); return transformed; }
public int[] TransformIDs(Tileset from, int[] id) { if (id.Length == 0) return new int[] { }; return GetIDsFromCells(from.GetCellsFromIDs(id)); }
public int TransformID(Tileset from, int id) { if (id == -1) return -1; return GetIDFromCell(from.GetCellFromID(id)); }
public Tileset Clone() { Tileset set = new Tileset(); set.Name = Name; set.FilePath = FilePath; set.TileSize = TileSize; set.TileSep = TileSep; return set; }
public void SetTileset(Tileset to) { tilesetsComboBox.SelectedItem = to; tileSelector.Tileset = to; }
private void setControlsFromTileset(Tileset t) { removeButton.Enabled = true; moveUpButton.Enabled = listBox.SelectedIndex > 0; moveDownButton.Enabled = listBox.SelectedIndex < listBox.Items.Count - 1; imagePreviewer.Enabled = true; nameTextBox.Enabled = true; imageFileTextBox.Enabled = true; imageFileButton.Enabled = true; imageFileWarningLabel.Enabled = true; tileSizeXTextBox.Enabled = true; tileSizeYTextBox.Enabled = true; tileSpacingTextBox.Enabled = true; nameTextBox.Text = t.Name; imageFileTextBox.Text = t.FilePath; tileSizeXTextBox.Text = t.TileSize.Width.ToString(); tileSizeYTextBox.Text = t.TileSize.Height.ToString(); tileSpacingTextBox.Text = t.TileSep.ToString(); imageFileWarningLabel.Visible = !checkImageFile(); loadPreview(); }
public TileSetTilesetAction(TileLayer tileLayer, Tileset setTo) : base(tileLayer) { this.setTo = setTo; }