Example #1
0
        /// <summary>
        /// Handles when the mouse button is raised on a map.
        /// </summary>
        /// <param name="sender">The <see cref="IToolTargetMapContainer"/> the event came from. Cannot be null.</param>
        /// <param name="map">The <see cref="EditorMap"/>. Cannot be null.</param>
        /// <param name="camera">The <see cref="ICamera2D"/>. Cannot be null.</param>
        /// <param name="e">The <see cref="System.Windows.Forms.MouseEventArgs"/> instance containing the event data. Cannot be null.</param>
        protected override void MapContainer_MouseDown(IToolTargetMapContainer sender, EditorMap map, ICamera2D camera, MouseEventArgs e)
        {
            var cursorPos = e.Position();
            var worldPos = camera.ToWorld(cursorPos);

            if (e.Button == MouseButtons.Right)
            {
                var ga = GridAligner.Instance;

                var entity = new WallEntity(worldPos, ga.GridSize);

                ga.Fit(entity);

                map.AddEntity(entity);
                SOM.SetSelected(entity);
            }

            base.MapContainer_MouseDown(sender, map, camera, e);
        }
Example #2
0
        void RebuildMapGrhWalls(IEnumerable<KeyValuePair<GrhData, GrhData.FileTags>> grhDataFileTags)
        {
            MapGrhWalls.Clear();

            foreach (var kvp in grhDataFileTags)
            {
                if (kvp.Value.Walls == null || kvp.Value.Walls.Count == 0)
                    continue;

                List<WallEntityBase> wallList = new List<WallEntityBase>();
                GrhData gd = kvp.Key;

                // Create the wall entities
                foreach (var wallInfo in kvp.Value.Walls)
                {
                    GrhData.BoundWallType wallType = wallInfo.Item1;
                    Rectangle? area = wallInfo.Item2;

                    Vector2 position;
                    Vector2 size;

                    if (area.HasValue)
                    {
                        position = new Vector2(area.Value.X, area.Value.Y);
                        size = new Vector2(area.Value.Width, area.Value.Height);
                    }
                    else
                    {
                        position = Vector2.Zero;
                        size = Vector2.Zero;
                    }

                    if (wallType == GrhData.BoundWallType.Solid || wallType == GrhData.BoundWallType.Platform)
                    {
                        WallEntity wall = new WallEntity(position, size) { IsPlatform = wallType == GrhData.BoundWallType.Platform };
                        wallList.Add(wall);
                    }
                }

                // If there are any walls, trim the list and set it
                if (wallList.Count > 0)
                {
                    wallList.TrimExcess();
                    MapGrhWalls[gd] = wallList;
                }
            }
        }
            /// <summary>
            /// When overridden in the derived class, handles drawing to the map after all of the map drawing finishes.
            /// </summary>
            /// <param name="map">The map the drawing is taking place on.</param>
            /// <param name="spriteBatch">The <see cref="ISpriteBatch"/> to draw to.</param>
            /// <param name="camera">The <see cref="ICamera2D"/> that describes the view of the map being drawn.</param>
            protected override void HandleDrawAfterMap(IDrawableMap map, ISpriteBatch spriteBatch, ICamera2D camera)
            {
                var p = Parent;
                if (p == null)
                    return;

                // Ensure the map is valid
                var clientMap = map as EditorMap;
                if (clientMap == null)
                    return;

                var viewArea = camera.GetViewArea();

                // Draw the walls
                if (p.DrawWalls)
                {
                    var visibleWalls = map.Spatial.GetMany<WallEntityBase>(viewArea);
                    foreach (var wall in visibleWalls)
                    {
                        EntityDrawer.Draw(spriteBatch, camera, wall);
                    }
                }

                // Draw the MapGrh walls
                if (p.DrawMapGrhWalls)
                {
                    var mapGrhWalls = GlobalState.Instance.MapGrhWalls;
                    var toDraw = clientMap.Spatial.GetMany<MapGrh>(viewArea);
                    var tmpWall = new WallEntity(Vector2.Zero, Vector2.Zero);

                    foreach (var mg in toDraw)
                    {
                        var boundWalls = mapGrhWalls[mg.Grh.GrhData];
                        if (boundWalls == null)
                            continue;

                        foreach (var wall in boundWalls)
                        {
                            tmpWall.Size = wall.Size != Vector2.Zero ? wall.Size * mg.Scale : mg.Size;
                            tmpWall.Position = mg.Position + (wall.Position * mg.Scale);
                            tmpWall.IsPlatform = wall.IsPlatform;
                            EntityDrawer.Draw(spriteBatch, camera, tmpWall);
                        }
                    }
                }
            }
Example #4
0
        void BuyWallMenuEntrySelected(object sender, PlayerIndexEventArgs e)
        {
            if (Tile_Engine.SelectedTile.IsBlocked == false &&
                Tile_Engine.SelectedTile.DrawEntityList.Count() == 1 &&
                this.player_CurrentGold >= WallEntity.GoldCost &&
                this.player_CurrentEnergy >= WallEntity.EnergyCost)
            {
                Tile_Engine.PlayerEntity.Gold -= WallEntity.GoldCost;
                Tile_Engine.PlayerEntity.Energy -= WallEntity.EnergyCost;

                WallEntity entity = new WallEntity(Tile_Engine.SelectedTile,
                    wallTexture[random.Next(0, 2)],
                    Color.White,
                    true);

                Tile_Engine.SelectedTile.AddEntity(entity);
            }
        }