示例#1
0
 /// <summary>
 /// Releases unmanaged and - optionally - managed resources
 /// </summary>
 /// <param name="disposing"><c>true</c> to release both managed and unmanaged resources; <c>false</c> to release only unmanaged resources.</param>
 protected override void Dispose(bool disposing)
 {
     if (!IsDisposed)
     {
         //Dispose of managed resources
         if (disposing)
         {
             if (_rasterizerState != null)
             {
                 _rasterizerState.Dispose();
             }
         }
     }
     base.Dispose(disposing);
 }
示例#2
0
        /// <summary>
        /// This is called when the game should draw itself.
        /// </summary>
        /// <param name="gameTime">Provides a snapshot of timing values.</param>
        public override void Draw(GameTime gameTime)
        {
            _spriteBatch.GraphicsDevice.ScissorRectangle = _displayRect;
            RasterizerState rstate = new RasterizerState();
            rstate.ScissorTestEnable = true;

            _spriteBatch.Begin(SpriteSortMode.Immediate,
                        BlendState.AlphaBlend,
                        null,
                        null,
                        rstate,
                        null);
            if (_hasBorder || _focus)
            {
                _spriteBatch.Draw(_background, _displayRect, new Rectangle(39, 6, 1, 1), _focus ? Color.Blue : Color.White);
                _spriteBatch.Draw(_background, new Rectangle(_displayRect.X + 2, _displayRect.Y + 1, _displayRect.Width - 3, _displayRect.Height - 2), new Rectangle(39, 6, 1, 1), Color.Black);
            }
            //_startPos = 2;
            for (int count = _startPos; count < Math.Min(_numLines + _startPos, _text.Count); ++count)
            {
                int centerX = _displayRect.Left + 5;
                if (_center)
                {
                    centerX = 5 + _displayRect.X + ((int)(_displayRect.Width - 55 - _font.MeasureString(_text[count]).X) / 2);
                }

                _spriteBatch.DrawString(_font, _text[count], new Vector2(centerX, _displayRect.Top + 5 +
                    (count - _startPos) * _lineHeight), _color[count]);

            }
            if (_numLines < _text.Count)
            {
                _spriteBatch.Draw(_arrows, new Rectangle(_displayRect.Right - 22, _displayRect.Top + 2, 20, 20), new Rectangle(32, 0, 28, 28), Color.White);
                _spriteBatch.Draw(_arrows, new Rectangle(_displayRect.Right - 22, _displayRect.Bottom - 22, 20, 20), new Rectangle(0, 0, 28, 28), Color.White);
            }
            _spriteBatch.End();
            _spriteBatch.GraphicsDevice.RasterizerState.ScissorTestEnable = false;

            rstate.Dispose();
        }
示例#3
0
        protected void Draw(Scene drawnScene, RenderTarget2D renderTarget)
        {
            Device.SetRenderTarget(renderTarget);
            try
            {
                Device.Viewport = drawnScene.Viewport;
            }
            catch (ArgumentException)
            {
                UpdateSceneViewport(drawnScene);
                Device.Viewport = drawnScene.Viewport;

            }

            annotationOverlayEffect.RenderTargetSize = drawnScene.Viewport;

            #if DEBUG
            if (renderTarget != null)
            {
                Debug.Assert(renderTarget.Bounds.Width >= drawnScene.Viewport.Width &&
                             renderTarget.Bounds.Height >= drawnScene.Viewport.Height);

            }
            #endif

            if (DefaultDepthState == null || DefaultDepthState.IsDisposed)
            {
                DefaultDepthState = new DepthStencilState();

                DefaultDepthState.DepthBufferEnable = true;
                DefaultDepthState.DepthBufferFunction = CompareFunction.LessEqual;
                DefaultDepthState.StencilEnable = false;
                DefaultDepthState.DepthBufferWriteEnable = true;
            }

            Device.DepthStencilState = DefaultDepthState;

            if (DefaultBlendState == null || DefaultBlendState.IsDisposed)
            {
                DefaultBlendState = new BlendState();
                DefaultBlendState.AlphaSourceBlend = Blend.SourceAlpha;
                DefaultBlendState.AlphaDestinationBlend = Blend.InverseSourceAlpha;
                DefaultBlendState.ColorSourceBlend = Blend.SourceAlpha;
                DefaultBlendState.ColorDestinationBlend = Blend.InverseSourceAlpha;
            }

            Device.BlendState = DefaultBlendState;

            SamplerState sampleState = Device.SamplerStates[0];

            if (sampleState == null || sampleState.IsDisposed ||
                (sampleState.AddressU != TextureAddressMode.Clamp || sampleState.AddressV != TextureAddressMode.Clamp))
            {
                try
                {
                    sampleState = new SamplerState();
                    sampleState.AddressU = TextureAddressMode.Clamp;    //Compatability with Reach
                    sampleState.AddressV = TextureAddressMode.Clamp;
                    Device.SamplerStates[0] = sampleState;
                }
                catch (Exception)
                {
                    if (sampleState != null)
                    {
                        sampleState.Dispose();
                        sampleState = null;
                    }
                }
            }

            Device.Clear(ClearOptions.Target | ClearOptions.DepthBuffer, Color.Black, float.MaxValue, 0);

            if (Device.RasterizerState == null ||
                Device.RasterizerState.IsDisposed ||
                Device.RasterizerState.CullMode != CullMode.None)
            {
                RasterizerState rState = null;
                try
                {
                    rState = new RasterizerState();
                    rState.CullMode = CullMode.None;
                    Device.RasterizerState = rState;
                }
                catch (Exception)
                {
                    if (rState != null)
                    {
                        rState.Dispose();
                        rState = null;
                    }
                }
            }

            Matrix worldViewProj = drawnScene.WorldViewProj;

            //Enables some basic effect characteristics, such as vertex coloring and default lighting.
            basicEffect.Projection = drawnScene.Projection;
            basicEffect.View = drawnScene.Camera.View;
            basicEffect.World = drawnScene.World;

            tileLayoutEffect.WorldViewProjMatrix = worldViewProj;
            this.channelOverlayEffect.WorldViewProjMatrix = worldViewProj;
            this.mergeHSVImagesEffect.WorldViewProjMatrix = worldViewProj;
            this.annotationOverlayEffect.WorldViewProjMatrix = worldViewProj;

            if (this.spriteBatch == null || this.spriteBatch.GraphicsDevice.IsDisposed)
            {
                IGraphicsDeviceService IService = this.Services.GetService(typeof(IGraphicsDeviceService)) as IGraphicsDeviceService;
                if (IService != null)
                {
                    spriteBatch = new SpriteBatch(IService.GraphicsDevice);
                    fontArial = Content.Load<SpriteFont>(@"Arial");
                }
            }

            //            GridRectangle Bounds = VisibleBounds();

            #if !DEBUG
            try
            {
            #endif
                //Since draw can be called from other methods than paint calls,
                //such as screencaptures, increment the PaintCallRefCount here
                PaintCallRefCount++;

                // Draw the control using the GraphicsDevice.
                Draw(drawnScene);
            #if !DEBUG
            }
            catch (Exception except)
            {
                throw except;
            }
            finally
            {
            #endif
                PaintCallRefCount--;
            #if !DEBUG
            }
            #endif
        }
示例#4
0
        /// <summary>
        /// This is called when the game should draw itself.
        /// </summary>
        /// <param name="gameTime">Provides a snapshot of timing values.</param>
        public override void Draw(GameTime gameTime)
        {
            _spriteBatch.Begin();
            _spriteBatch.Draw(_mapIcon, _displayRect, new Rectangle(39, 6, 1, 1), Color.White);
            _spriteBatch.Draw(_mapIcon, new Rectangle(_displayRect.X + 1, _displayRect.Y + 1, _displayRect.Width - 2, _displayRect.Height - 2), new Rectangle(39, 6, 1, 1), Color.Black);
            _spriteBatch.End();
            _spriteBatch.GraphicsDevice.ScissorRectangle = new Rectangle(_displayRect.Left + 3, _displayRect.Top + 3, _displayRect.Width - 6, _displayRect.Height - 6);
            RasterizerState rstate = new RasterizerState();
            rstate.ScissorTestEnable = true;

            _spriteBatch.Begin(SpriteSortMode.BackToFront,
                  BlendState.AlphaBlend,
                  null,
                  null,
                  rstate,
                  null,
                  _camera.matrix);
            if (_map != null)
            {
                for (int y = 0; y < _map.height; ++y)
                {
                    for (int x = 0; x < _map.width; ++x)
                    {
                        if (_map[x, y].visible)
                        {
                            if (!_map[x, y].canEnter)
                            {
                                _spriteBatch.Draw(_mapIcon, new Rectangle(_displayRect.Left + 2 + x * 16, _displayRect.Top + 2 + y * 16, 15, 15), new Rectangle(32, 0, 16, 16), Color.White);
                            }
                            else
                            {
                                if (_map[x, y].hasPlayer)
                                {
                                    _spriteBatch.Draw(_mapIcon, new Rectangle(_displayRect.Left + 2 + x * 16, _displayRect.Top + 2 + y * 16, 16, 16), new Rectangle(48, 16, 16, 16), Color.White);

                                }
                                else
                                {
                                    if ((_map[x, y].hasEnemy) && (_map.actors[_playerID].tile.coords.DistanceFrom(x, y) < Math.Max(_map.actors[_playerID].viewRange, _map.light)))
                                    {
                                        _spriteBatch.Draw(_mapIcon, new Rectangle(_displayRect.Left + x * 16, _displayRect.Top + y * 16, 16, 16), new Rectangle(64, 16, 16, 16), Color.White);
                                    }
                                    else
                                    {
                                        if (_map[x, y].hasTreasure)
                                        {
                                            _spriteBatch.Draw(_mapIcon, new Rectangle(_displayRect.Left + x * 16, _displayRect.Top + y * 16, 16, 16), new Rectangle(64, 0, 16, 16), Color.White);
                                        }
                                        else
                                        {
                                            if (_map[x, y].hasTeleport)
                                            {
                                                if (x == 0)
                                                {
                                                    _spriteBatch.Draw(_mapIcon, new Rectangle(_displayRect.Left + x * 16, _displayRect.Top + y * 16, 16, 16), new Rectangle(0, 0, 16, 16), Color.White);
                                                }
                                                if (y == 0)
                                                {
                                                    _spriteBatch.Draw(_mapIcon, new Rectangle(_displayRect.Left + x * 16, _displayRect.Top + y * 16, 16, 16), new Rectangle(16, 0, 16, 16), Color.White);
                                                }
                                                if (x == _map.width - 1)
                                                {
                                                    _spriteBatch.Draw(_mapIcon, new Rectangle(_displayRect.Left + x * 16, _displayRect.Top + y * 16, 16, 16), new Rectangle(16, 16, 16, 16), Color.White);
                                                }
                                                if (y == _map.height - 1)
                                                {
                                                    _spriteBatch.Draw(_mapIcon, new Rectangle(_displayRect.Left + x * 16, _displayRect.Top + y * 16, 16, 16), new Rectangle(0, 16, 16, 16), Color.White);
                                                }
                                            }
                                            else
                                            {
                                                if (_map[x, y].hasTarget)
                                                {
                                                    _spriteBatch.Draw(_mapIcon, new Rectangle(_displayRect.Left + x * 16, _displayRect.Top + y * 16, 16, 16), new Rectangle(48, 0, 16, 16), Color.White);
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }

            _spriteBatch.End();
            _spriteBatch.GraphicsDevice.RasterizerState.ScissorTestEnable = false;
            rstate.Dispose();
        }
示例#5
0
        /// <summary>
        /// This is called when the game should draw itself.
        /// </summary>
        /// <param name="gameTime">Provides a snapshot of timing values.</param>
        public override void Draw(GameTime gameTime)
        {
            _spriteBatch.GraphicsDevice.ScissorRectangle = _displayRect;
            RasterizerState rstate = new RasterizerState();
            rstate.ScissorTestEnable = true;

            _spriteBatch.Begin(SpriteSortMode.Immediate,
                        BlendState.AlphaBlend,
                        null,
                        null,
                        rstate,
                        null);
            _spriteBatch.Draw(_background, _displayRect, new Rectangle(39, 6, 1, 1), Color.White);
            _spriteBatch.Draw(_background, new Rectangle(_displayRect.X + 2, _displayRect.Y + 2, _displayRect.Width - 4, _displayRect.Height - 4), new Rectangle(39, 6, 1, 1), Color.Black);
            //_startPos = 2;
            for (int count = _startPos; count < Math.Min(_numLines + _startPos, _text.Count); ++count)
            {
                _spriteBatch.DrawString(_font, _text[count], new Vector2(_displayRect.Left + 20, _displayRect.Top +
                    (count - _startPos) * _lineHeight), Color.White);
            }
            _spriteBatch.Draw(_arrows, new Rectangle(_displayRect.Right - 35, _displayRect.Top + 5, 28, 28), new Rectangle(32, 0, 28, 28), Color.White);
            _spriteBatch.Draw(_arrows, new Rectangle(_displayRect.Right - 35, _displayRect.Bottom - 35, 28, 28), new Rectangle(0, 0, 28, 28), Color.White);

            _spriteBatch.End();
            _spriteBatch.GraphicsDevice.RasterizerState.ScissorTestEnable = false;

            rstate.Dispose();
        }
示例#6
0
        /// <summary>
        /// Draw the Map
        /// </summary>
        public override void Draw(GameTime gametime)
        {
            if (_enabled)
            {

                // Rasterizer: Enable cropping at borders (otherwise map would be overlapping everything else)
                RasterizerState rstate = new RasterizerState();
                rstate.ScissorTestEnable = true;

                // Blendstate used for light circle / fog of war
                BlendState blendState = new BlendState();
                blendState.AlphaDestinationBlend = Blend.SourceColor;
                blendState.ColorDestinationBlend = Blend.SourceColor;
                blendState.AlphaSourceBlend = Blend.Zero;
                blendState.ColorSourceBlend = Blend.Zero;

                // Draw border of window (black square in white square)
                _spriteBatch.Begin();
                _spriteBatch.Draw(_background, _displayRect, new Rectangle(39, 6, 1, 1), Color.White);
                _spriteBatch.Draw(_background, new Rectangle(_displayRect.X + 1, _displayRect.Y + 1, _displayRect.Width - 2, _displayRect.Height - 2), new Rectangle(39, 6, 1, 1), Color.Black);
                _spriteBatch.End();

                _spriteBatch.Begin(SpriteSortMode.Deferred,
                            BlendState.AlphaBlend,
                            null,
                            null,
                            rstate,
                            null,
                            _camera.matrix);

                _spriteBatch.GraphicsDevice.ScissorRectangle = new Rectangle(_displayRect.Left + 5, _displayRect.Top + 5, _displayRect.Width - 10, _displayRect.Height - 10);

                _drawFloor(); // Draw the floow

                for (int i = 0; i < _projectiles.Count; ++i)
                {
                    _projectiles[i].Draw(_spriteBatch, _environment[1][(int)Math.Log((double)_projectiles[i].direction, 2)]);
                }

                for (int i = 0; i < _effects.Count; ++i)
                {
                    _effects[i].Draw(_spriteBatch, gametime);
                }

                _drawWalls(gametime); // Draw walls, other objects, player and enemies

                _spriteBatch.End();

                // Draw circle of light / fog of war
                _spriteBatch.Begin(SpriteSortMode.Texture, blendState, null,
                            null,
                            rstate,
                            null,
                            _camera.matrix);
                _spriteBatch.Draw(_circle, new Rectangle(
                    (int)(_actors[_playerID].position.x + 1) - 250 * Math.Max(_map.actors[_playerID].viewRange, _map.light),
                    (int)(_actors[_playerID].position.y + 1) - 250 * Math.Max(_map.actors[_playerID].viewRange, _map.light), 520 * Math.Max(_map.actors[_playerID].viewRange, _map.light), 520 * Math.Max(_map.actors[_playerID].viewRange, _map.light)), Color.White);
                _spriteBatch.End();

                _spriteBatch.GraphicsDevice.RasterizerState.ScissorTestEnable = false;

                rstate.Dispose();
                blendState.Dispose();

                if ((_highlightedTile.x > -1)
                    && (_highlightedTile.x >= _map.actors[_playerID].tile.coords.x - Math.Max(_map.actors[_playerID].viewRange, _map.light))
                    && (_highlightedTile.x <= _map.actors[_playerID].tile.coords.x + Math.Max(_map.actors[_playerID].viewRange, _map.light))
                    && (_highlightedTile.y >= _map.actors[_playerID].tile.coords.y - Math.Max(_map.actors[_playerID].viewRange, _map.light))
                    && (_highlightedTile.y <= _map.actors[_playerID].tile.coords.y + Math.Max(_map.actors[_playerID].viewRange, _map.light)))
                    _tooltip.DisplayToolTip(_map[_highlightedTile.x, _highlightedTile.y]);
                for (int i = 0; i < _floatnumbers.Count; ++i)
                {
                    _floatnumbers[i].Draw();
                }

                if (_bigText != "")
                {
                    _spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend);
                    float opacity = ((float)((_visibility <= 0) ? (100 + _visibility) : (_visibility))) / 100f;
                    _spriteBatch.DrawString(_font, _bigText, new Vector2(_displayRect.Left + 10, _displayRect.Bottom - _font.MeasureString(_bigText).Y - _font.MeasureString(_smallText).Y), new Color(opacity, 0, 0), 0f, Vector2.Zero, 1f, SpriteEffects.None, 1f);
                    _spriteBatch.DrawString(_font, _smallText, new Vector2(_displayRect.Left + 10, _displayRect.Bottom - _font.MeasureString(_smallText).Y), new Color(opacity, opacity, opacity), 0f, Vector2.Zero, 0.6f, SpriteEffects.None, 1f);

                    _spriteBatch.End();
                }
            }
        }