/// <summary>
        /// When overridden in the derived class, draws the graphics to the control.
        /// </summary>
        /// <param name="currentTime">The current time.</param>
        protected override void HandleDraw(TickCount currentTime)
        {
            if (DesignMode)
            {
                base.HandleDraw(currentTime);
                return;
            }

            var pe = ParticleEffect;

            if (pe == null)
            {
                return;
            }

            if (pe.IsExpired)
            {
                pe.Reset();
            }

            // Update
            pe.Update(currentTime);

            // Draw the world
            try
            {
                var worldSB = DrawingManager.BeginDrawWorld(Camera);
                if (worldSB != null)
                {
                    DrawWorld(worldSB);
                }
            }
            finally
            {
                if (DrawingManager.State != DrawingManagerState.Idle)
                {
                    DrawingManager.EndDrawWorld();
                }
            }

            // Draw the GUI
            try
            {
                var guiSB = DrawingManager.BeginDrawGUI();
                if (guiSB != null)
                {
                    DrawGUI(guiSB);
                }
            }
            finally
            {
                if (DrawingManager.State != DrawingManagerState.Idle)
                {
                    DrawingManager.EndDrawGUI();
                }
            }
        }
Example #2
0
        /// <summary>
        /// Handles drawing of the screen. The ScreenManager already provides a GraphicsDevice.Clear() so
        /// there is often no need to clear the screen. This will only be called while the screen is the
        /// active screen.
        /// </summary>
        /// <param name="gameTime">The current game time.</param>
        public override void Draw(TickCount gameTime)
        {
            if (UserChar == null)
            {
                return;
            }

            // Update the ambient light based on the game time
            DrawingManager.LightManager.Ambient = Map.GetModifiedAmbientLight();

            // Update the camera
            World.Camera.Min = World.UserChar.GetCameraPos(World.Camera);

            // Since we only update entities in view, and the draw position is included in that update, make sure
            // that the camera focuses on the user properly if they teleport out of view of the camera.
            if (!World.Camera.InView(World.UserChar))
            {
                World.Camera.CenterOn(World.UserChar);
            }

            // Draw the world layer
            try
            {
                var sb = DrawingManager.BeginDrawWorld(World.Camera);
                if (sb == null)
                {
                    return;
                }

                World.Draw(sb);
                _damageTextPool.Draw(sb, _damageFont);
            }
            finally
            {
                DrawingManager.EndDrawWorld();
            }

            // Draw the HUD layer
            try
            {
                var sb = DrawingManager.BeginDrawGUI();
                _infoBox.Draw(sb);
                GUIManager.Draw(sb);
            }
            finally
            {
                DrawingManager.EndDrawGUI();
            }
        }
Example #3
0
        /// <summary>
        /// When overridden in the derived class, draws the graphics to the control.
        /// </summary>
        /// <param name="currentTime">The current time.</param>
        protected override void HandleDraw(TickCount currentTime)
        {
            base.HandleDraw(currentTime);

            if (DesignMode)
            {
                return;
            }

            if (_drawingManager.RenderWindow == null)
            {
                return;
            }

            if (Grh == null)
            {
                return;
            }

            Grh.Update(currentTime);

            m.Update(currentTime);

            _drawingManager.Update(currentTime);

            var sb = _drawingManager.BeginDrawWorld(_camera);

            if (sb == null)
            {
                return;
            }

            // Change the view
            var oldView = RenderWindow.GetView();

            _drawView.Reset(new FloatRect(Camera.Min.X, Camera.Min.Y, Camera.Size.X, Camera.Size.Y));
            RenderWindow.SetView(_drawView);

            try
            {
                try
                {
                    Grh.Draw(sb, Vector2.Zero, Color.White);
                }
                catch (LoadingFailedException)
                {
                    // A LoadingFailedException is generally fine here since it probably means the graphic file was invalid
                    // or does not exist
                }

                // Draw the walls
                if (Walls != null)
                {
                    foreach (var wall in Walls)
                    {
                        var rect = wall.ToRectangle();
                        RenderRectangle.Draw(sb, rect, _autoWallColor);
                    }
                }

                m.Draw(sb, Camera);
            }
            finally
            {
                _drawingManager.EndDrawWorld();

                // Restore the view
                RenderWindow.SetView(oldView);
            }
        }
        /// <summary>
        /// When overridden in the derived class, draws the graphics to the control.
        /// </summary>
        /// <param name="currentTime">The current time.</param>
        protected override void HandleDraw(TickCount currentTime)
        {
            if (DesignMode)
            {
                base.HandleDraw(currentTime);
                return;
            }

            TransBoxManager.Update(currentTime);
            Cursor = TransBoxManager.CurrentCursor;

            int deltaTime;

            if (_lastUpdateTime == TickCount.MinValue)
            {
                deltaTime = 30;
            }
            else
            {
                deltaTime = Math.Max(5, (int)(currentTime - _lastUpdateTime));
            }

            _lastUpdateTime = currentTime;

            DrawingManager.Update(currentTime);

            _camera.Min += _cameraVelocity * (deltaTime / 1000f);

            // Update
            UpdateMap(currentTime, deltaTime);

            ToolManager.Instance.MapDrawingExtensions.Map = Map;

            // Draw the world
            try
            {
                var worldSB = DrawingManager.BeginDrawWorld(Camera);
                if (worldSB != null)
                {
                    DrawMapWorld(worldSB);
                }
            }
            finally
            {
                if (DrawingManager.State != DrawingManagerState.Idle)
                {
                    DrawingManager.EndDrawWorld();
                }
            }

            // Draw the GUI
            try
            {
                var guiSB = DrawingManager.BeginDrawGUI();
                if (guiSB != null)
                {
                    DrawMapGUI(guiSB);
                }
            }
            finally
            {
                if (DrawingManager.State != DrawingManagerState.Idle)
                {
                    DrawingManager.EndDrawGUI();
                }
            }
        }
Example #5
0
        /// <summary>
        /// When overridden in the derived class, draws the graphics to the control.
        /// </summary>
        /// <param name="currentTime">The current time.</param>
        protected override void HandleDraw(TickCount currentTime)
        {
            if (DesignMode)
            {
                base.HandleDraw(currentTime);
                return;
            }

            TransBoxManager.Update(currentTime);

            // Update the cursor display for the transformation box. Only change the cursor if we are currently
            // under a transbox, or we have just stopped being under one. If we update it every frame, it screws with the
            // UI display for everything else (like when the cursor is over a textbox).
            var transBoxCursor = TransBoxManager.CurrentCursor;

            if (transBoxCursor == null)
            {
                if (_wasUnderTransBox)
                {
                    Cursor            = Cursors.Default;
                    _wasUnderTransBox = false;
                }
            }
            else
            {
                Cursor            = transBoxCursor;
                _wasUnderTransBox = true;
            }

            int deltaTime;

            if (_lastUpdateTime == TickCount.MinValue)
            {
                deltaTime = 30;
            }
            else
            {
                deltaTime = Math.Max(5, (int)(currentTime - _lastUpdateTime));
            }

            _lastUpdateTime = currentTime;

            DrawingManager.Update(currentTime);

            _camera.Min += _cameraVelocity * (deltaTime / 1000f);

            // Update
            UpdateMap(currentTime, deltaTime);

            ToolManager.Instance.MapDrawingExtensions.Map = Map;

            // Draw the world
            try
            {
                var worldSB = DrawingManager.BeginDrawWorld(Camera);
                if (worldSB != null)
                {
                    DrawMapWorld(worldSB);
                }
            }
            finally
            {
                if (DrawingManager.State != DrawingManagerState.Idle)
                {
                    DrawingManager.EndDrawWorld();
                }
            }

            // Draw the GUI
            try
            {
                var guiSB = DrawingManager.BeginDrawGUI();
                if (guiSB != null)
                {
                    DrawMapGUI(guiSB);
                }
            }
            finally
            {
                if (DrawingManager.State != DrawingManagerState.Idle)
                {
                    DrawingManager.EndDrawGUI();
                }
            }
        }