示例#1
0
            /// <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 msc = MapScreenControl.TryFindInstance(map);

                if (msc == null)
                {
                    return;
                }

                var dm = msc.DrawingManager;

                if (dm == null)
                {
                    return;
                }

                var lm = dm.LightManager;

                if (lm == null)
                {
                    return;
                }

                var lightSprite = SystemSprites.Lightblub;

                var offset = lightSprite.Size / 2f;

                foreach (var light in lm)
                {
                    lightSprite.Draw(spriteBatch, light.Center - offset);
                }
            }
示例#2
0
        /// <summary>
        /// Handles when a key 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_KeyUp(IToolTargetMapContainer sender, EditorMap map, ICamera2D camera, KeyEventArgs e)
        {
            // Handle deletes
            if (e.KeyCode == Keys.Delete)
            {
                // Only delete when it is an Entity that is on this map
                var removed = new List <object>();
                foreach (var x in SOM.SelectedObjects.OfType <ILight>().ToImmutable())
                {
                    if (map.Lights.Contains(x))
                    {
                        map.RemoveLight(x);
                        removed.Add(x);

                        // Remove the graphic and effect from the map
                        var msc = MapScreenControl.TryFindInstance(map);
                        if (msc != null)
                        {
                            var dm = msc.DrawingManager;
                            if (dm != null)
                            {
                                dm.LightManager.Remove(x);
                            }
                        }
                    }
                }

                SOM.SetManySelected(SOM.SelectedObjects.Except(removed).ToImmutable());
            }

            base.MapContainer_KeyUp(sender, map, camera, e);
        }
        /// <summary>
        /// Handles when a mouse button is pressed 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)
        {
            base.MapContainer_MouseDown(sender, map, camera, e);

            if (IsSelecting)
            {
                return;
            }

            // Left-click
            if (e.Button == MouseButtons.Left)
            {
                // Place light
                if (Input.IsKeyDown(_placeLightKey))
                {
                    var msc = MapScreenControl.TryFindInstance(map);
                    if (msc != null)
                    {
                        var dm = msc.DrawingManager;
                        if (dm != null)
                        {
                            var pos = camera.ToWorld(e.Position());
                            pos = GridAligner.Instance.Align(pos);

                            var light = new Light {
                                Center = pos, IsEnabled = true, Tag = map
                            };

                            map.AddLight(light);
                            dm.LightManager.Add(light);
                        }
                    }
                }
            }
        }