Example #1
0
 /// <summary>
 /// Retourne la reférence du tile à la position spécifiée et retourne 'null' si inexistant
 /// </summary>
 /// <param name="x">La position horizontale X du tile</param>
 /// <param name="y">La position verticale Y du tile</param>
 /// <returns>La reférence vers le tile, ou null</returns>
 public GameMapTile this[int x, int y]
 {
     get
     {
         if (GameMap.InBounds(new GameVector2(x, y)))
         {
             int index = GameMapTile.EncodeFormattedIndex(new Point(x, y), GlobalData.MapSize.Width);
             if (index < this.tiles.Count)
             {
                 return(this.tiles[index]);
             }
         }
         return(null);
     }
     set
     {
         if (GameMap.InBounds(new GameVector2(x, y)))
         {
             int index = GameMapTile.EncodeFormattedIndex(new Point(x, y), GlobalData.MapSize.Width);
             if (index < this.tiles.Count)
             {
                 this.tiles[index] = value;
                 this.LayerChanged?.Invoke(this, EventArgs.Empty);
             }
         }
     }
 }
Example #2
0
        /// <summary>
        /// Dessine la selection du tileset si l'état du document est par défaut, sinon dessine l'effet de l'état courant du document
        /// </summary>
        /// <param name="state">L'état de dessin</param>
        /// <param name="e">Les données de dessin</param>
        private void DrawSelection(bool state, PaintEventArgs e)
        {
            if (state)
            {
                GameVector2 location = this.GetTilePosition(this.mouseLocation.X + this.mapOrigin.X, this.mouseLocation.Y + this.mapOrigin.Y);

                if (this.State == GameEditorState.Default)
                {
                    if (this.texture?.BitmapSelection != null)
                    {
                        ImageAttributes attributes = new ImageAttributes();
                        attributes.SetOpacity(0.5f);

                        /*************** Affichage uniquement à l'interieur de la carte *****************/

                        /*int limitX = this.texture.BitmapSelection.Width / GlobalData.TileSize.Width;
                         * int limitY = this.texture.BitmapSelection.Height / GlobalData.TileSize.Height;
                         *
                         * for (int x = 0; x < limitX; x++)
                         * {
                         *  for (int y = 0; y < limitY; y++)
                         *  {
                         *      if (location.X + x >= 0 && location.X + x < GlobalData.MapSize.Width &&
                         *          location.Y + y >= 0 && location.Y + y < GlobalData.MapSize.Height)
                         *      {
                         *          e.Graphics.DrawImage(this.texture.BitmapSelection,
                         *              new Rectangle(
                         *                  (location.X + x) * GlobalData.TileSize.Width - this.mapOrigin.X,
                         *                  (location.Y + y) * GlobalData.TileSize.Height - this.mapOrigin.Y,
                         *                  GlobalData.TileSize.Width,
                         *                  GlobalData.TileSize.Height),
                         *                      x * GlobalData.TileSize.Width,
                         *                      y * GlobalData.TileSize.Height,
                         *                      GlobalData.TileSize.Width,
                         *                      GlobalData.TileSize.Height,
                         *                      GraphicsUnit.Pixel,
                         *                      attributes);
                         *      }
                         *  }
                         * }*/

                        /*************** Affichage possible à l'exterieur de la carte *****************/
                        e.Graphics.DrawImage(this.texture.BitmapSelection,
                                             new Rectangle(
                                                 location.X * GlobalData.TileSize.Width - this.mapOrigin.X,
                                                 location.Y * GlobalData.TileSize.Height - this.mapOrigin.Y,
                                                 this.texture.BitmapSelection.Width,
                                                 this.texture.BitmapSelection.Height),
                                             0, 0,
                                             this.texture.BitmapSelection.Width,
                                             this.texture.BitmapSelection.Height,
                                             GraphicsUnit.Pixel,
                                             attributes);
                    }
                }
                else if (this.State == GameEditorState.Erase && GameMap.InBounds(location))
                {
                    e.Graphics.FillRectangle(new SolidBrush(Color.FromArgb(100, 255, 45, 45)),
                                             location.X * GlobalData.TileSize.Width - this.mapOrigin.X,
                                             location.Y * GlobalData.TileSize.Height - this.mapOrigin.Y,
                                             GlobalData.TileSize.Width,
                                             GlobalData.TileSize.Height);
                }
            }
        }