Exemple #1
0
        public void Draw(RendererParams rendererParams)
        {
            if (rendererParams.Camera == null)
            {
                return;
            }

            var level = IoC.Model.Level;

            if (!level.Visible)
            {
                return;
            }

            var game = ObjectFactory.GetInstance <IGame>( );

            game.GraphicsDevice.Clear(Constants.Instance.ColorBackground);

            var extensibility = ObjectFactory.GetInstance <IExtensibility>( );

            IEnumerable <IRenderer> otherRenderers = extensibility.Renderers.ToList(  );

            if (!otherRenderers.Any( ))
            {
                render(rendererParams);
                return;
            }

            otherRenderers.ForEach(r => r.Render(rendererParams, render));
        }
Exemple #2
0
        void drawAllItems(RendererParams rendererParams)
        {
            var level = IoC.Model.Level;

            foreach (LayerEditor eachLayer in level.Layers)
            {
                Vector2 mainCameraPosition = rendererParams.Camera.Position;

                rendererParams.Camera.Position *= eachLayer.ScrollSpeed;

                _game.SpriteBatch.Begin(
                    SpriteSortMode.Deferred,
                    BlendState.AlphaBlend,
                    null,
                    null,
                    null,
                    null,
                    rendererParams.Camera.Matrix);

                eachLayer.DrawInEditor(_game.SpriteBatch);

                if (eachLayer == level.ActiveLayer)
                {
                    //drawSelectionBoxIfNeeded( rendererParams.UserActionInEditor, rendererParams.SelectionRectangle ) ;

                    drawCurrentItemBeingCreatedIfNeeded(rendererParams.UserActionInEditor, rendererParams.EntityCreation);
                }

                _game.SpriteBatch.End( );

                //restore main camera position
                rendererParams.Camera.Position = mainCameraPosition;
            }
        }
Exemple #3
0
        void drawAllItems( RendererParams rendererParams )
        {
            var level = IoC.Model.Level ;

            foreach( LayerEditor eachLayer in level.Layers )
            {
                Vector2 mainCameraPosition = rendererParams.Camera.Position ;

                rendererParams.Camera.Position *= eachLayer.ScrollSpeed ;

                _game.SpriteBatch.Begin(
                    SpriteSortMode.Deferred,
                    BlendState.AlphaBlend,
                    null,
                    null,
                    null,
                    null,
                    rendererParams.Camera.Matrix ) ;

                eachLayer.DrawInEditor( _game.SpriteBatch ) ;

                if( eachLayer == level.ActiveLayer )
                {
                    //drawSelectionBoxIfNeeded( rendererParams.UserActionInEditor, rendererParams.SelectionRectangle ) ;

                    drawCurrentItemBeingCreatedIfNeeded( rendererParams.UserActionInEditor, rendererParams.EntityCreation ) ;
                }

                _game.SpriteBatch.End( ) ;

                //restore main camera position
                rendererParams.Camera.Position = mainCameraPosition ;
            }
        }
Exemple #4
0
        void drawSelectionBoxIfNeeded(RendererParams rendererParams)
        {
            if (rendererParams.UserActionInEditor != UserActionInEditor.CreatingSelectionBoxByDragging)
            {
                return;
            }

            Camera camera = rendererParams.Camera;

            Vector2 mainCameraPosition = camera.Position;

            camera.Position *= IoC.Model.ActiveLayer.ScrollSpeed;

            _game.SpriteBatch.Begin(
                SpriteSortMode.Deferred,
                BlendState.AlphaBlend,
                null,
                null,
                null,
                null,
                camera.Matrix);

            _drawing.DrawBoxFilled(_game.SpriteBatch, rendererParams.SelectionRectangle, Constants.Instance.ColorSelectionBox);

            _game.SpriteBatch.End(  );

            camera.Position = mainCameraPosition;
        }
Exemple #5
0
        public void Draw( RendererParams rendererParams )
        {
            if( rendererParams.Camera == null )
            {
                return ;
            }

            var level = IoC.Model.Level ;

            if( !level.Visible )
            {
                return ;
            }

            var game = ObjectFactory.GetInstance<IGame>( ) ;

            game.GraphicsDevice.Clear( Constants.Instance.ColorBackground ) ;

            var extensibility = ObjectFactory.GetInstance<IExtensibility>( ) ;

            IEnumerable<IRenderer> otherRenderers = extensibility.Renderers.ToList(  ) ;

            if( !otherRenderers.Any( ) )
            {
                render( rendererParams ) ;
                return ;
            }

            otherRenderers.ForEach( r => r.Render( rendererParams, render ) ) ;
        }
Exemple #6
0
        void render(RendererParams rendererParams)
        {
            if (rendererParams.ItemsToRender.Has(ItemsToRender.SelectionRectangle))
            {
                drawSelectionBoxIfNeeded(rendererParams);
            }

            if (rendererParams.ItemsToRender.Has(ItemsToRender.Items))
            {
                drawAllItems(rendererParams);
            }

            if (rendererParams.ItemsToRender.Has(ItemsToRender.HooksOnSelectedItems))
            {
                drawFramesAroundSelectedEditors(rendererParams);
            }

            if (rendererParams.SnapPoint.Visible && rendererParams.ItemsToRender.Has(ItemsToRender.SnapPoint))
            {
                _game.SpriteBatch.Begin( );

                var snappedPoint = Vector2.Transform(rendererParams.SnapPoint.Position, rendererParams.Camera.Matrix);

                _drawing.DrawBoxFilled(
                    _game.SpriteBatch, snappedPoint.X - 5, snappedPoint.Y - 5, 10, 10, Constants.Instance.ColorSelectionFirst);

                _game.SpriteBatch.End( );
            }

            if (Constants.Instance.ShowWorldOrigin)
            {
                if (rendererParams.ItemsToRender.Has(ItemsToRender.WorldOrigin))
                {
                    drawWorldOrigin(rendererParams.Camera);
                }
            }

            if (Constants.Instance.ShowGrid)
            {
                if (rendererParams.ItemsToRender.Has(ItemsToRender.Grid))
                {
                    drawGrid(rendererParams.Camera);
                }
            }

            if (_debugDrawActions.Any())
            {
                _game.SpriteBatch.Begin( );

                _debugDrawActions.ForEach(a => a());

                _game.SpriteBatch.End( );

                _debugDrawActions.Clear(  );
            }
        }
Exemple #7
0
        void drawFramesAroundSelectedEditors(RendererParams rendererParams)
        {
            LevelEditor level = IoC.Model.Level;

            IEnumerable <ItemEditor> selectedEditors = level.SelectedEditors.ToList(  );

            if (selectedEditors.Any( ))
            {
                Vector2 maincameraposition = rendererParams.Camera.Position;

                rendererParams.Camera.Position *= selectedEditors.First( ).ParentLayer.ScrollSpeed;

                _game.SpriteBatch.Begin(
                    SpriteSortMode.Deferred,
                    BlendState.AlphaBlend,
                    null,
                    null,
                    null,
                    null,
                    rendererParams.Camera.Matrix);

                bool first = true;

                foreach (ItemEditor item in selectedEditors)
                {
                    if (item.ItemProperties.Visible && item.ParentLayer.Visible && KeyboardStatus.IsKeyUp(Keys.Space))
                    {
                        Color color = first ? Constants.Instance.ColorSelectionFirst : Constants.Instance.ColorSelectionRest;

                        item.DrawSelectionFrame(_game.SpriteBatch, color);

                        bool rotatingOrScaling =
                            rendererParams.UserActionInEditor == UserActionInEditor.RotatingItems ||
                            rendererParams.UserActionInEditor == UserActionInEditor.ScalingItems;

                        if (first && rotatingOrScaling)
                        {
                            //Vector2 center = Vector2.Transform( item.ItemProperties.Position, rendererParams.Camera.Matrix ) ;
                            //Vector2 mouse = Vector2.Transform( MouseStatus.WorldPosition, rendererParams.Camera.Matrix ) ;

                            //todo move the line drawing into each shape and remove the matrix parameter when drawing the frame
                            //_drawing.DrawLine( _game.SpriteBatch, item.ItemProperties.Position, MouseStatus.WorldPosition, Constants.Instance.ColorSelectionFirst, 1 ) ;
                        }
                    }

                    first = false;
                }

                _game.SpriteBatch.End( );

                //restore main camera position
                rendererParams.Camera.Position = maincameraposition;
            }
        }
Exemple #8
0
        public void Render( RendererParams rendererParams, Action<RendererParams> defaultRenderer )
        {
            var lightingState = ObjectFactory.GetInstance<ILightingState>( ) ;
            if( !lightingState.LightingOn )
            {
                defaultRenderer( rendererParams ) ;

                return ;
            }

            // Create a world view projection matrix to use with krypton
            // Assign the matrix and pre-render the lightmap.
            // Make sure not to change the position of any lights or shadow hulls after this call, as it won't take effect till the next frame!
            _krypton.Matrix = rendererParams.Camera.Matrix;

            _krypton.AmbientColor = new Color( 64, 64, 64 ) ;
            _krypton.SpriteBatchCompatablityEnabled = true ;
            _krypton.Bluriness = 23 ;
            _krypton.CullMode = CullMode.None ;

            _krypton.LightMapPrepare();

            _game.GraphicsDevice.Clear( Color.White ) ;

            // ----- DRAW STUFF HERE ----- //
            // By drawing here, you ensure that your scene is properly lit by krypton.
            // Drawing after KryptonEngine.Draw will cause you objects to be drawn on top of the lightmap (can be useful, fyi)
            // ----- DRAW STUFF HERE ----- //
            rendererParams.ItemsToRender = ItemsToRender.Everything ;
            defaultRenderer( rendererParams ) ;

            // Draw hulls
            debugDrawHulls( true);

            // Draw krypton (This can be omited if krypton is in the Component list. It will simply draw krypton when base.Draw is called
            _krypton.Draw(_game.GameTime);

            const ItemsToRender everythingExceptItemsThemselves = ItemsToRender.Everything ^ ItemsToRender.Items ;

            rendererParams.ItemsToRender = everythingExceptItemsThemselves ;

            defaultRenderer( rendererParams ) ;

            if (Keyboard.GetState().IsKeyDown(Keys.H))
            {
                // Draw hulls
                debugDrawHulls( false);
            }

            if (Keyboard.GetState().IsKeyDown(Keys.L))
            {
                debugDrawLights();
            }
        }
Exemple #9
0
        void render(RendererParams rendererParams)
        {
            if( rendererParams.ItemsToRender.Has( ItemsToRender.SelectionRectangle ) )
            {
                drawSelectionBoxIfNeeded( rendererParams );
            }

            if( Constants.Instance.ShowGrid )
            {
                if(rendererParams.ItemsToRender.Has( ItemsToRender.Grid))
                {
                    drawGrid( rendererParams.Camera ) ;
                }
            }

            if( rendererParams.ItemsToRender.Has( ItemsToRender.Items ) )
            {
                drawAllItems( rendererParams ) ;
            }

            if(rendererParams.ItemsToRender.Has( ItemsToRender.HooksOnSelectedItems))
            {
                drawFramesAroundSelectedEditors( rendererParams ) ;
            }

            if( rendererParams.SnapPoint.Visible && rendererParams.ItemsToRender.Has( ItemsToRender.SnapPoint ) )
            {
                _game.SpriteBatch.Begin( ) ;

                var snappedPoint = Vector2.Transform( rendererParams.SnapPoint.Position, rendererParams.Camera.Matrix ) ;

                _drawing.DrawBoxFilled(
                    _game.SpriteBatch, snappedPoint.X - 5, snappedPoint.Y - 5, 10, 10, Constants.Instance.ColorSelectionFirst ) ;

                _game.SpriteBatch.End( ) ;
            }

            if( Constants.Instance.ShowWorldOrigin )
            {
                if(rendererParams.ItemsToRender.Has( ItemsToRender.WorldOrigin))
                {
                    drawWorldOrigin( rendererParams.Camera ) ;
                }
            }

            if( _debugDrawActions.Any() )
            {
                _game.SpriteBatch.Begin( ) ;

                _debugDrawActions.ForEach( a=>a() );

                _game.SpriteBatch.End( ) ;

                _debugDrawActions.Clear(  );
            }
        }
Exemple #10
0
        void drawSelectionBoxIfNeeded(RendererParams rendererParams)
        {
            if( rendererParams.UserActionInEditor != UserActionInEditor.CreatingSelectionBoxByDragging )
            {
                return ;
            }

            Camera camera = rendererParams.Camera ;

            Vector2 mainCameraPosition = camera.Position ;

            camera.Position *= IoC.Model.ActiveLayer.ScrollSpeed ;

            _game.SpriteBatch.Begin(
                SpriteSortMode.Deferred,
                BlendState.AlphaBlend,
                null,
                null,
                null,
                null,
                camera.Matrix ) ;

            _drawing.DrawBoxFilled( _game.SpriteBatch, rendererParams.SelectionRectangle, Constants.Instance.ColorSelectionBox) ;

            _game.SpriteBatch.End(  );

            camera.Position =mainCameraPosition ;
        }
Exemple #11
0
        void drawFramesAroundSelectedEditors(RendererParams rendererParams )
        {
            LevelEditor level = IoC.Model.Level ;

            IEnumerable<ItemEditor> selectedEditors = level.SelectedEditors.ToList(  ) ;

            if( selectedEditors.Any( ) )
            {
                Vector2 maincameraposition = rendererParams.Camera.Position ;

                rendererParams.Camera.Position *= selectedEditors.First( ).ParentLayer.ScrollSpeed ;

            _game.SpriteBatch.Begin(
                SpriteSortMode.Deferred,
                BlendState.AlphaBlend,
                null,
                null,
                null,
                null,
                rendererParams.Camera.Matrix ) ;

                bool first = true ;

                foreach( ItemEditor item in selectedEditors )
                {
                    if( item.ItemProperties.Visible && item.ParentLayer.Visible && KeyboardStatus.IsKeyUp( Keys.Space ) )
                    {
                        Color color = first ? Constants.Instance.ColorSelectionFirst : Constants.Instance.ColorSelectionRest ;

                        item.DrawSelectionFrame( _game.SpriteBatch, color ) ;

                        bool rotatingOrScaling =
                            rendererParams.UserActionInEditor == UserActionInEditor.RotatingItems ||
                            rendererParams.UserActionInEditor == UserActionInEditor.ScalingItems ;

                        if( first  && rotatingOrScaling )
                        {
                            //Vector2 center = Vector2.Transform( item.ItemProperties.Position, rendererParams.Camera.Matrix ) ;
                            //Vector2 mouse = Vector2.Transform( MouseStatus.WorldPosition, rendererParams.Camera.Matrix ) ;

                            //todo move the line drawing into each shape and remove the matrix parameter when drawing the frame
                            //_drawing.DrawLine( _game.SpriteBatch, item.ItemProperties.Position, MouseStatus.WorldPosition, Constants.Instance.ColorSelectionFirst, 1 ) ;
                        }
                    }

                    first = false ;
                }

                _game.SpriteBatch.End( ) ;

                //restore main camera position
                rendererParams.Camera.Position = maincameraposition ;
            }
        }