Example #1
0
        /// <summary>
        /// Call HandleInput on the screen managers.
        /// </summary>
        /// <param name="elapsedGameTime">The time in seconds since the last frame</param>
        /// <param name="mousePosition">The current screen space position of the mouse</param>
        public override void HandleInput(float elapsedGameTime, Vector2 mousePosition)
        {
            base.HandleInput(elapsedGameTime, mousePosition);

            Vector2 gameMouseCoords = Camera.ScreenToGameCoords(mousePosition);

            if (ScreenUIObjects.ShouldHandleInput)
            {
                ScreenUIObjects.HandleInput(elapsedGameTime, mousePosition);
            }
            if (InGameUIObjects.ShouldHandleInput)
            {
                InGameUIObjects.HandleInput(elapsedGameTime, gameMouseCoords);
            }
            if (GameObjects.ShouldHandleInput)
            {
                GameObjects.HandleInput(elapsedGameTime, gameMouseCoords);
            }
            if (EnvironmentObjects.ShouldHandleInput)
            {
                EnvironmentObjects.HandleInput(elapsedGameTime, gameMouseCoords);
            }

            if (Modules.ShouldHandleInput)
            {
                Modules.HandleInput(elapsedGameTime, mousePosition);
            }
        }
        /// <summary>
        /// Call HandleInput on the screen managers.
        /// </summary>
        /// <param name="elapsedGameTime">The time in seconds since the last frame</param>
        /// <param name="mousePosition">The current screen space position of the mouse</param>
        public override void HandleInput(float elapsedGameTime, Vector2 mousePosition)
        {
            base.HandleInput(elapsedGameTime, mousePosition);

            Vector2 gameMouseCoords = Camera.Instance.ScreenToGameCoords(mousePosition);

            // Handle these in this order so we respect the depth elements implied here
            if (ScreenUIObjects.ShouldHandleInput)
            {
                ScreenUIObjects.HandleInput(elapsedGameTime, mousePosition);
            }
            if (InGameUIObjects.ShouldHandleInput)
            {
                InGameUIObjects.HandleInput(elapsedGameTime, gameMouseCoords);
            }
            if (GameObjects.ShouldHandleInput)
            {
                GameObjects.HandleInput(elapsedGameTime, gameMouseCoords);
            }
            if (EnvironmentObjects.ShouldHandleInput)
            {
                EnvironmentObjects.HandleInput(elapsedGameTime, gameMouseCoords);
            }

            if (Modules.ShouldHandleInput)
            {
                Modules.HandleInput(elapsedGameTime, mousePosition);
            }
        }
Example #3
0
        /// <summary>
        /// Call die on our ObjectManagers
        /// </summary>
        public override void Die()
        {
            base.Die();

            EnvironmentObjects.Die();
            GameObjects.Die();
            InGameUIObjects.Die();
            ScreenUIObjects.Die();

            Modules.Die();
        }
Example #4
0
        /// <summary>
        /// Calls Initialise on the screen Managers and ScriptManager.
        /// Adds Initial Scripts to the ScriptManager
        /// </summary>
        public override void Initialise()
        {
            CheckShouldInitialise();

            Lights.Initialise();
            EnvironmentObjects.Initialise();
            GameObjects.Initialise();
            InGameUIObjects.Initialise();
            ScreenUIObjects.Initialise();

            Modules.Initialise();

            base.Initialise();
        }
Example #5
0
        /// <summary>
        /// Queues up any music for this screen
        /// </summary>
        public override void Begin()
        {
            base.Begin();

            Lights.Begin();
            EnvironmentObjects.Begin();
            GameObjects.Begin();
            InGameUIObjects.Begin();
            ScreenUIObjects.Begin();

            Modules.Begin();

            AddMusic();
            AddInitialCommands();
        }
Example #6
0
        /// <summary>
        /// Creates GameObjects, Lights and then UI and then calls LoadContent on the screen Managers.
        /// </summary>
        public override void LoadContent()
        {
            // Check if we should load
            CheckShouldLoad();

            // Create the objects then lights first as our UI will probably depend on their values
            AddInitialGameObjects();
            GameObjects.LoadContent();

            AddInitialLights();

            AddInitialUI();
            // Should move this to before this - currently screwing up because we add the lights from the generation engine in AddInitialUI - probably should not do this
            Lights.LoadContent();
            EnvironmentObjects.LoadContent();
            InGameUIObjects.LoadContent();
            ScreenUIObjects.LoadContent();

            Modules.LoadContent();

            base.LoadContent();
        }
Example #7
0
        /// <summary>
        /// Call Update on the screen managers and check their visibility against the camera viewport.
        /// </summary>
        /// <param name="elapsedGameTime">The time in seconds since the last frame</param>
        public override void Update(float elapsedGameTime)
        {
            base.Update(elapsedGameTime);

            if (Lights.ShouldUpdate)
            {
                Lights.Update(elapsedGameTime);
            }
            if (EnvironmentObjects.ShouldUpdate)
            {
                EnvironmentObjects.Update(elapsedGameTime);
            }
            if (GameObjects.ShouldUpdate)
            {
                GameObjects.Update(elapsedGameTime);
            }
            if (InGameUIObjects.ShouldUpdate)
            {
                InGameUIObjects.Update(elapsedGameTime);
            }
            if (ScreenUIObjects.ShouldUpdate)
            {
                ScreenUIObjects.Update(elapsedGameTime);
            }

            if (Modules.ShouldUpdate)
            {
                Modules.Update(elapsedGameTime);
            }

            /*Camera.CheckVisibility(Lights, false);
             * Camera.CheckVisibility(EnvironmentObjects, false);
             * Camera.CheckVisibility(GameObjects, false);
             * Camera.CheckVisibility(InGameUIObjects, false);
             * Camera.CheckVisibility(ScreenUIObjects, true);*/
        }
Example #8
0
 /// <summary>
 /// Extracts an InGameUIObject in this screen's InGameUIObjects manager without killing it
 /// </summary>
 /// <typeparam name="K">The type we wish to return the found object as</typeparam>
 /// <param name="uiObjectName">The predicate we will use to find our UIObject</param>
 /// <returns>Returns he found object casted to type K, or null</returns>
 public K ExtractInGameUIObject <K>(K childToExtract) where K : BaseObject
 {
     return(InGameUIObjects.ExtractChild(childToExtract));
 }
Example #9
0
 /// <summary>
 /// Finds an InGameUIObject in this screen's InGameUIObjects manager
 /// </summary>
 /// <typeparam name="K">The type we wish to return the found object as</typeparam>
 /// <param name="predicate">The predicate we will use to find our UIObject</param>
 /// <returns>Returns the found object casted to type K, or null</returns>
 public K FindInGameUIObject <K>(Predicate <BaseObject> predicate) where K : BaseObject
 {
     return(InGameUIObjects.FindChild <K>(predicate));
 }
Example #10
0
 /// <summary>
 /// Removes an InGameUIObject from this screen's InGameUIObjects manager
 /// </summary>
 /// <param name="uiObjectToRemove"></param>
 public void RemoveInGameUIObject(BaseObject uiObjectToRemove)
 {
     InGameUIObjects.RemoveChild(uiObjectToRemove);
 }
Example #11
0
 /// <summary>
 /// Adds an InGameUIObject to this screen's InGameUIObjects manager
 /// </summary>
 /// <param name="uiObjectToAdd">The object to add</param>
 /// <param name="load">A flag to indicate whether LoadContent should be called on this object when adding</param>
 /// <param name="initialise">A flag to indicate whether Initialise should be called on this object when adding</param>
 public T AddInGameUIObject <T>(T uiObjectToAdd, bool load = false, bool initialise = false) where T : BaseObject
 {
     return(InGameUIObjects.AddChild(uiObjectToAdd, load, initialise));
 }
Example #12
0
        /// <summary>
        /// Draws the background first.
        /// Calls draw on the screen objects in the order: Lights, Background, GameObjects, InGameUIObjects, ScreenUIObjects.
        /// Draws the mouse at the after everything else.
        /// </summary>
        /// <param name="spriteBatch">The SpriteBatch we should use for drawing sprites</param>
        public override void Draw(SpriteBatch spriteBatch)
        {
            base.Draw(spriteBatch);

            GraphicsDevice graphicsDevice = ScreenManager.Instance.GraphicsDeviceManager.GraphicsDevice;

            // Draw our lighting
            {
                graphicsDevice.SetRenderTarget(LightRenderTarget);

                if (Lights.ShouldDraw)
                {
                    graphicsDevice.Clear(Color.Black);

                    spriteBatch.Begin(SpriteSortMode.Immediate, BlendState.Additive, null, null, null, null, Camera.TransformationMatrix);
                    Lights.Draw(spriteBatch);
                    spriteBatch.End();
                }
                else
                {
                    graphicsDevice.Clear(Color.White);
                }
            }

            // Draw our game world
            {
                graphicsDevice.SetRenderTarget(GameWorldRenderTarget);
                graphicsDevice.Clear(Color.White);

                if (Background != null)
                {
                    spriteBatch.Begin();
                    {
                        if (Background.ShouldDraw)
                        {
                            Background.Draw(spriteBatch);
                        }
                    }

                    spriteBatch.End();
                }

                // Draw the camera dependent objects using the camera transformation matrix
                spriteBatch.Begin(SpriteSortMode.Immediate, BlendState.AlphaBlend, null, null, null, null, Camera.TransformationMatrix);
                {
                    if (EnvironmentObjects.ShouldDraw)
                    {
                        EnvironmentObjects.Draw(spriteBatch);
                    }
                    if (GameObjects.ShouldDraw)
                    {
                        GameObjects.Draw(spriteBatch);
                    }
                }

                spriteBatch.End();
            }

            // Draw our InGameUI
            {
                graphicsDevice.SetRenderTarget(InGameUIRenderTarget);
                graphicsDevice.Clear(Color.Transparent);

                spriteBatch.Begin(SpriteSortMode.Immediate, BlendState.AlphaBlend, null, null, null, null, Camera.TransformationMatrix);
                {
                    if (InGameUIObjects.ShouldDraw)
                    {
                        InGameUIObjects.Draw(spriteBatch);
                    }
                }

                spriteBatch.End();
            }

            // Draw our Screen UI
            {
                graphicsDevice.SetRenderTarget(ScreenUIRenderTarget);
                graphicsDevice.Clear(Color.Transparent);

                // Draw the camera independent objects and the mouse last
                spriteBatch.Begin();
                {
                    if (ScreenUIObjects.ShouldDraw)
                    {
                        ScreenUIObjects.Draw(spriteBatch);
                    }
                    if (GameMouse.Instance.ShouldDraw)
                    {
                        GameMouse.Instance.Draw(spriteBatch);
                    }
                }

                spriteBatch.End();
            }

            // Combine the separate render targets together using the appropriate effects
            {
                graphicsDevice.SetRenderTarget(null);
                graphicsDevice.Clear(Color.Black);

                // Combine the Light and Game World render targets
                spriteBatch.Begin(SpriteSortMode.Immediate, BlendState.AlphaBlend);
                Lights.LightEffect.Parameters["lightMask"].SetValue(LightRenderTarget);
                Lights.LightEffect.Parameters["ambientLight"].SetValue(Lights.AmbientLight.ToVector4());
                Lights.LightEffect.CurrentTechnique.Passes[0].Apply();
                spriteBatch.Draw(GameWorldRenderTarget, Vector2.Zero, Color.White);
                spriteBatch.End();

                // Draw our UI render targets
                spriteBatch.Begin(SpriteSortMode.Immediate, BlendState.AlphaBlend);
                spriteBatch.Draw(InGameUIRenderTarget, Vector2.Zero, Color.White);
                spriteBatch.Draw(ScreenUIRenderTarget, Vector2.Zero, Color.White);
                spriteBatch.End();
            }
        }