/// <summary>
        /// Handles drawing to the map after the given <see cref="MapRenderLayer"/> is drawn.
        /// </summary>
        /// <param name="map">The map the drawing is taking place on.</param>
        /// <param name="e">The <see cref="NetGore.Graphics.DrawableMapDrawLayerEventArgs"/> containing the drawing event arguments.</param>
        void IMapDrawingExtension.DrawAfterLayer(IDrawableMap map, DrawableMapDrawLayerEventArgs e)
        {
            if (!Enabled)
                return;

            if (map == null)
            {
                Debug.Fail("map is null.");
                return;
            }

            if (e.SpriteBatch == null)
            {
                Debug.Fail("spriteBatch is null.");
                return;
            }

            if (e.Camera == null)
            {
                Debug.Fail("camera is null.");
                return;
            }

            Debug.Assert(EnumHelper<MapRenderLayer>.IsDefined(e.Layer), "Invalid layer specified.");
            Debug.Assert(!e.SpriteBatch.IsDisposed, "spriteBatch is disposed.");

            HandleDrawAfterLayer(map, e);
        }
示例#2
0
        /// <summary>
        /// Handles drawing to the map after the given <see cref="MapRenderLayer"/> is drawn.
        /// </summary>
        /// <param name="map">The map the drawing is taking place on.</param>
        /// <param name="e">The <see cref="NetGore.Graphics.DrawableMapDrawLayerEventArgs"/> containing the drawing event arguments.</param>
        void IMapDrawingExtension.DrawAfterLayer(IDrawableMap map, DrawableMapDrawLayerEventArgs e)
        {
            if (!Enabled)
            {
                return;
            }

            if (map == null)
            {
                Debug.Fail("map is null.");
                return;
            }

            if (e.SpriteBatch == null)
            {
                Debug.Fail("spriteBatch is null.");
                return;
            }

            if (e.Camera == null)
            {
                Debug.Fail("camera is null.");
                return;
            }

            Debug.Assert(EnumHelper <MapRenderLayer> .IsDefined(e.Layer), "Invalid layer specified.");
            Debug.Assert(!e.SpriteBatch.IsDisposed, "spriteBatch is disposed.");

            HandleDrawAfterLayer(map, e);
        }
        /// <summary>
        /// Handles the <see cref="IDrawableMap.EndDrawMapLayer"/> event from the current map.
        /// </summary>
        /// <param name="map">The map.</param>
        /// <param name="e">The <see cref="NetGore.Graphics.DrawableMapDrawLayerEventArgs"/> instance containing the event data.</param>
        void EndDrawMapLayerCallback(IDrawableMap map, DrawableMapDrawLayerEventArgs e)
        {
            Debug.Assert(Map == map, "How did we get an event from the wrong map?");
            Debug.Assert(e.SpriteBatch != null && !e.SpriteBatch.IsDisposed);

            foreach (var extension in _extensions)
            {
                extension.DrawAfterLayer(map, e);
            }
        }
        /// <summary>
        /// Handles the <see cref="IDrawableMap.BeginDrawMapLayer"/> event from the current map.
        /// </summary>
        /// <param name="sender">The sender.</param>
        /// <param name="e">The <see cref="NetGore.Graphics.DrawableMapDrawLayerEventArgs"/> instance containing the event data.</param>
        void BeginDrawMapLayerCallback(IDrawableMap sender, DrawableMapDrawLayerEventArgs e)
        {
            Debug.Assert(Map == sender, "How did we get an event from the wrong map?");
            Debug.Assert(e.SpriteBatch != null && !e.SpriteBatch.IsDisposed);

            foreach (var extension in _extensions)
            {
                extension.DrawBeforeLayer(sender, e);
            }
        }
示例#5
0
        /// <summary>
        /// When overridden in the derived class, handles drawing to the map after the given <see cref="MapRenderLayer"/> is drawn.
        /// </summary>
        /// <param name="map">The map the drawing is taking place on.</param>
        /// <param name="e">The <see cref="NetGore.Graphics.DrawableMapDrawLayerEventArgs"/> instance containing the event data.</param>
        protected override void HandleDrawAfterLayer(IDrawableMap map, DrawableMapDrawLayerEventArgs e)
        {
            if (e.Layer != MapRenderLayer.SpriteForeground)
                return;

            var visibleArea = e.Camera.GetViewArea();
            var visibleWalls = map.Spatial.GetMany<WallEntityBase>(visibleArea);
            foreach (var wall in visibleWalls)
            {
                EntityDrawer.Draw(e.SpriteBatch, e.Camera, wall);
            }
        }
示例#6
0
        /// <summary>
        /// When overridden in the derived class, handles drawing to the map after the given <see cref="MapRenderLayer"/> is drawn.
        /// </summary>
        /// <param name="map">The map the drawing is taking place on.</param>
        /// <param name="e">The <see cref="NetGore.Graphics.DrawableMapDrawLayerEventArgs"/> instance containing the event data.</param>
        protected override void HandleDrawAfterLayer(IDrawableMap map, DrawableMapDrawLayerEventArgs e)
        {
            if (e.Layer != MapRenderLayer.SpriteForeground)
                return;

            if (MapSpawns == null)
                return;

            foreach (var item in MapSpawns)
            {
                var rect = item.SpawnArea.ToRectangle(map);
                if (e.Camera.InView(rect))
                    RenderRectangle.Draw(e.SpriteBatch, rect, _drawColor);
            }
        }
示例#7
0
        /// <summary>
        /// When overridden in the derived class, handles drawing to the map after the given <see cref="MapRenderLayer"/> is drawn.
        /// </summary>
        /// <param name="map">The map the drawing is taking place on.</param>
        /// <param name="e">The <see cref="NetGore.Graphics.DrawableMapDrawLayerEventArgs"/> instance containing the event data.</param>
        protected override void HandleDrawAfterLayer(IDrawableMap map, DrawableMapDrawLayerEventArgs e)
        {
            if (e.Layer != MapRenderLayer.SpriteForeground)
                return;

            // Get the visible area
            var visibleArea = e.Camera.GetViewArea();

            // Get and draw all entities, skipping those that we will never draw () and those that
            // we will always draw (_alwaysDrawTypes)
            var toDraw = map.Spatial.GetMany<Entity>(visibleArea, GetEntitiesToDrawFilter);

            // Add the entities we will always draw
            toDraw = toDraw.Concat(map.Spatial.GetMany<Entity>(GetEntitiesToAlwaysDrawFilter));

            // Draw
            foreach (var entity in toDraw)
            {
                EntityDrawer.Draw(e.SpriteBatch, e.Camera, entity);
            }
        }
示例#8
0
        public void Draw(ISpriteBatch sb)
        {
            var cam = Camera;
            if (cam == null)
            {
                const string errmsg = "The camera on map `{0}` was null - cannot draw map.";
                if (log.IsErrorEnabled)
                    log.ErrorFormat(errmsg, this);
                Debug.Fail(string.Format(errmsg, this));
                return;
            }

            // Find the drawable objects that are in view and pass the filter (if one is provided)
            var viewArea = cam.GetViewArea();

            IEnumerable<IDrawable> drawableInView;
            IEnumerable<IDrawable> bgInView;
            if (DrawFilter != null)
            {
                drawableInView = Spatial.GetMany<IDrawable>(viewArea, x => DrawFilter(x));
                bgInView = _backgroundImages.Cast<IDrawable>().Where(x => DrawFilter(x) && x.InView(cam));
            }
            else
            {
                drawableInView = Spatial.GetMany<IDrawable>(viewArea);
                bgInView = _backgroundImages.Cast<IDrawable>().Where(x => x.InView(cam));
            }

            // Concat the background images (to the start of the list) since they aren't in any spatials
            drawableInView = bgInView.Concat(drawableInView);

            if (BeginDrawMap != null)
                BeginDrawMap.Raise(this, new DrawableMapDrawEventArgs(sb, cam));

            // Sort all the items, then start drawing them layer-by-layer, item-by-item
            foreach (var layer in _drawableSorter.GetSorted(drawableInView))
            {
                var layerEventArgs = new DrawableMapDrawLayerEventArgs(layer.Key, sb, cam);

                // Notify the layer has started drawing
                if (BeginDrawMapLayer != null)
                    BeginDrawMapLayer.Raise(this, layerEventArgs);

                // Draw the normal map objects
                foreach (var drawable in layer.Value)
                {
                    drawable.Draw(sb);
                }

                // Get the effects to draw, then draw them (if possible)
                IEnumerable<ITemporaryMapEffect> tempMapEffects;
                switch (layer.Key)
                {
                    case MapRenderLayer.SpriteBackground:
                        tempMapEffects = _mapEffects.Where(x => !x.IsForeground);
                        break;
                    case MapRenderLayer.SpriteForeground:
                        tempMapEffects = _mapEffects.Where(x => x.IsForeground);
                        break;
                    default:
                        tempMapEffects = null;
                        break;
                }

                if (tempMapEffects != null)
                {
                    foreach (var mapEffect in tempMapEffects)
                    {
                        mapEffect.Draw(sb);
                    }
                }

                // Notify the layer has finished drawing
                if (EndDrawMapLayer != null)
                    EndDrawMapLayer.Raise(this, layerEventArgs);
            }

            // Draw the particle effects
            if (DrawParticles)
            {
                foreach (var pe in ParticleEffects)
                {
                    pe.Draw(sb);
                }
            }

            if (EndDrawMap != null)
                EndDrawMap.Raise(this, new DrawableMapDrawEventArgs(sb, cam));
        }
 /// <summary>
 /// When overridden in the derived class, handles drawing to the map before the given <see cref="MapRenderLayer"/> is drawn.
 /// </summary>
 /// <param name="map">The map the drawing is taking place on.</param>
 /// <param name="e">The <see cref="NetGore.Graphics.DrawableMapDrawLayerEventArgs"/> instance containing the event data.</param>
 protected virtual void HandleDrawBeforeLayer(IDrawableMap map, DrawableMapDrawLayerEventArgs e)
 {
 }
示例#10
0
 /// <summary>
 /// When overridden in the derived class, handles drawing to the map before the given <see cref="MapRenderLayer"/> is drawn.
 /// </summary>
 /// <param name="map">The map the drawing is taking place on.</param>
 /// <param name="e">The <see cref="NetGore.Graphics.DrawableMapDrawLayerEventArgs"/> instance containing the event data.</param>
 protected virtual void HandleDrawBeforeLayer(IDrawableMap map, DrawableMapDrawLayerEventArgs e)
 {
 }