Esempio n. 1
0
 /*
  *  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);
 }
Esempio n. 2
0
        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);
        }
Esempio n. 4
0
        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;
        }
Esempio n. 5
0
 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;
 }
Esempio n. 6
0
        public int[] TransformIDs(Tileset from, int[] id)
        {
            if (id.Length == 0)
                return new int[] { };

            return GetIDsFromCells(from.GetCellsFromIDs(id));
        }
Esempio n. 7
0
        public int TransformID(Tileset from, int id)
        {
            if (id == -1)
                return -1;

            return GetIDFromCell(from.GetCellFromID(id));
        }
Esempio n. 8
0
 public Tileset Clone()
 {
     Tileset set = new Tileset();
     set.Name = Name;
     set.FilePath = FilePath;
     set.TileSize = TileSize;
     set.TileSep = TileSep;
     return set;
 }
Esempio n. 9
0
 public void SetTileset(Tileset to)
 {
     tilesetsComboBox.SelectedItem = to;
     tileSelector.Tileset = to;
 }
Esempio n. 10
0
        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();
        }
Esempio n. 11
0
 public TileSetTilesetAction(TileLayer tileLayer, Tileset setTo)
     : base(tileLayer)
 {
     this.setTo = setTo;
 }