Example #1
0
        // TODO : Optimisation requise (Division en sous-methodes, calculs et déroulement impératif unique)
        /// <summary>
        /// Modifie de façon intelligente les données de la carte selon la selection du tileset, à partir de la position donnée
        /// </summary>
        /// <param name="position">La position du premier tile en haut à gauche à modifier</param>
        public void SetTiles(int layerIndex, GameVector2 position, TextureInfo texture, bool raiseChanged = true)
        {
#if DEBUG
            Stopwatch watch = new Stopwatch();
            watch.Start();
#endif
            if (layerIndex >= 0 && layerIndex < this.layers.Count)
            {
                if (texture != null && texture.BitmapSelection != null && texture.BitmapSource != null)
                {
                    int tmpWidth = texture.BitmapSelection.Width / GlobalData.TileSize.Width;
                    int tmpHeight = texture.BitmapSelection.Height / GlobalData.TileSize.Height;
                    int tilesCount = texture.BitmapSource.Width / GlobalData.TileSize.Width;

                    for (int x = 0; x < tmpWidth; x++)
                    {
                        for (int y = 0; y < tmpHeight; y++)
                        {
                            GameMapTile tile = this.layers.ElementAt(layerIndex)[position.X + x, position.Y + y];
                            if (tile != null)
                            {
                                Rectangle selection = new Rectangle(
                                    GlobalData.TileSize.Width * x,
                                    GlobalData.TileSize.Height * y,
                                    GlobalData.TileSize.Width,
                                    GlobalData.TileSize.Height);

                                GraphicsUnit unit = GraphicsUnit.Pixel;
                                RectangleF bounds = texture.BitmapSource.GetBounds(ref unit);

                                if (bounds.Contains(selection))
                                {
                                    // OutOfMemory eventuel, par usage de textures inexistantes (OutOfRange extension)

                                    tile.Texture = texture.BitmapSelection.Clone(selection, PixelFormat.DontCare);

                                    Point location = new Point(
                                        (selection.Location.X + texture.Selection.X) / GlobalData.TileSize.Width,
                                        (selection.Location.Y + texture.Selection.Y) / GlobalData.TileSize.Height);

                                    tile.FormattedIndex = GameMapTile.EncodeFormattedIndex(location, tilesCount);
                                    tile.TextureIndex = this.RetrieveTextureIndex(texture.Path);
                                }
                            }
                        }
                    }
                }
                else
                {
                    GameMapTile tile = this.layers.ElementAt(layerIndex)[position.X, position.Y];
                    if (tile != null)
                    {
                        tile.FormattedIndex = GameMapTile.EMPTY;
                        tile.Texture = null;
                    }
                }

                if(raiseChanged)
                    this.MapChanged?.Invoke(this);
            }
#if DEBUG
            watch.Stop();
            Console.WriteLine($"SetTile : {watch.ElapsedMilliseconds.ToString()} ms");
#endif
        }
Example #2
0
        /// <summary>
        /// Remplis la map par la texture selectionnée du tileset
        /// </summary>
        public void Fill(int layerIndex, TextureInfo texture)
        {
            if (texture.BitmapSelection.Width >= GlobalData.TileSize.Width &&
                texture.BitmapSelection.Height >= GlobalData.TileSize.Height)
            {
                int tmpWidth = texture.BitmapSelection.Width / GlobalData.TileSize.Width;
                int tmpHeight = texture.BitmapSelection.Height / GlobalData.TileSize.Height;

                for (int y = 0; y < GlobalData.MapSize.Height; y += tmpHeight)
                    for (int x = 0; x < GlobalData.MapSize.Width; x += tmpWidth)
                        this.SetTiles(layerIndex, new GameVector2(x, y), texture, false);

                this.MapChanged?.Invoke(this);
            }
        }
Example #3
0
 public MapPanel(TextureInfo tilesetImage, GameMap map)
 {
     this.Initialize();
     this.TextureInfo = tilesetImage;
     this.Open(map);
 }
Example #4
0
 public MapPanel(TextureInfo tilesetInfo, string mapName)
 {
     this.Initialize();
     this.TextureInfo = tilesetInfo;
     this.Create(mapName);
 }
Example #5
0
 private void TilesetPanel_TilesetChanged(object sender, TextureInfo texture)
 {
     MapPanels.ForEach(x => x.TextureInfo = texture);
 }
 private void comboTilesetFileSelecter_SelectedIndexChanged(object sender, EventArgs e)
 {
     if (this.textures.Count > this.comboTilesetFileSelecter.SelectedIndex)
     {
         this.textureInfo = this.textures[this.comboTilesetFileSelecter.SelectedIndex];
         this.textureInfo.BitmapSelection = null;
         this.textureInfo.Selection = new Rectangle();
         this.TilesetChanged?.Invoke(this, this.textureInfo);
         this.TilesetSelectionChanged?.Invoke(this, this.textureInfo.Selection);
         this.RefreshScrollComponents();
     }
 }