Пример #1
0
        public override void Render(DwarfTime gameTime)
        {
            DwarfGame.SpriteBatch.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend);

            Vector2 screenCenter = new Vector2(Game.GraphicsDevice.Viewport.Width / 2 - Logo.Width / 2, Game.GraphicsDevice.Viewport.Height / 2 - Logo.Height / 2);
            switch(Transitioning)
            {
                case TransitionMode.Running:
                    DwarfGame.SpriteBatch.Draw(Logo, screenCenter, null, new Color(1f, 1f, 1f));
                    break;
                case TransitionMode.Entering:
                    DwarfGame.SpriteBatch.Draw(Logo, screenCenter, null, new Color(1f, 1f, 1f, TransitionValue));
                    break;
                case TransitionMode.Exiting:
                    DwarfGame.SpriteBatch.Draw(Logo, screenCenter, null, new Color(1f, 1f, 1f, 1.0f - TransitionValue));
                    break;
            }
            DwarfGame.SpriteBatch.End();

            base.Render(gameTime);
        }
Пример #2
0
        /// <summary>
        /// Called when a frame is to be drawn to the screen
        /// </summary>
        /// <param name="DwarfTime">The current time</param>
        public override void Render(DwarfTime gameTime)
        {
            // If we are simulating the game before starting, just display black.
                if (!PreSimulateTimer.HasTriggered)
                {
                    PreSimulateTimer.Update(gameTime);
                    base.Render(gameTime);
                    return;
                }

                CompositeLibrary.Render(GraphicsDevice, DwarfGame.SpriteBatch);
                CompositeLibrary.Update();
                GraphicsDevice.DepthStencilState = DepthStencilState.Default;
                GraphicsDevice.BlendState = BlendState.Opaque;

                GUI.PreRender(gameTime, DwarfGame.SpriteBatch);
                // Keeping track of a running FPS buffer (averaged)
                if (lastFps.Count > 100)
                {
                    lastFps.RemoveAt(0);
                }

                // Controls the sky fog
                float x = (1.0f - Sky.TimeOfDay);
                x = x*x;
                DefaultShader.Parameters["xFogColor"].SetValue(new Vector3(0.32f*x, 0.58f*x, 0.9f*x));
                DefaultShader.Parameters["xLightPositions"].SetValue(LightPositions);

                // Computes the water height.
                float wHeight = WaterRenderer.GetVisibleWaterHeight(ChunkManager, Camera, GraphicsDevice.Viewport,
                    lastWaterHeight);
                lastWaterHeight = wHeight;
                // Draw reflection/refraction images
                WaterRenderer.DrawRefractionMap(gameTime, this, wHeight + 1.0f, Camera.ViewMatrix, DefaultShader,
                    GraphicsDevice);
                WaterRenderer.DrawReflectionMap(gameTime, this, wHeight - 0.1f, GetReflectedCameraMatrix(wHeight),
                    DefaultShader, GraphicsDevice);

                // Start drawing the bloom effect
                if (GameSettings.Default.EnableGlow)
                {
                    bloom.BeginDraw();
                }
                else if (UseFXAA)
                {
                    fxaa.Begin(DwarfTime.LastTime, fxaa.RenderTarget);
                }

                // Draw the sky
                GraphicsDevice.Clear(new Color(DefaultShader.Parameters["xFogColor"].GetValueVector3()));
                DrawSky(gameTime, Camera.ViewMatrix, 1.0f);

                // Defines the current slice for the GPU
                float level = ChunkManager.ChunkData.MaxViewingLevel + 2.0f;
                if (level > ChunkManager.ChunkData.ChunkSizeY)
                {
                    level = 1000;
                }

                Plane slicePlane = WaterRenderer.CreatePlane(level, new Vector3(0, -1, 0), Camera.ViewMatrix, false);

                // Draw the whole world, and make sure to handle slicing
                DefaultShader.Parameters["ClipPlane0"].SetValue(new Vector4(slicePlane.Normal, slicePlane.D));
                DefaultShader.Parameters["Clipping"].SetValue(1);
                //Blue ghost effect above the current slice.
                DefaultShader.Parameters["GhostMode"].SetValue(1);
                Draw3DThings(gameTime, DefaultShader, Camera.ViewMatrix);

                // Now we want to draw the water on top of everything else
                DefaultShader.Parameters["Clipping"].SetValue(1);
                DefaultShader.Parameters["GhostMode"].SetValue(0);
                WaterRenderer.DrawWater(
                    GraphicsDevice,
                    (float)gameTime.TotalGameTime.TotalSeconds,
                    DefaultShader,
                    Camera.ViewMatrix,
                    GetReflectedCameraMatrix(wHeight),
                    Camera.ProjectionMatrix,
                    new Vector3(0.1f, 0.0f, 0.1f),
                    Camera,
                    ChunkManager);

                DefaultShader.CurrentTechnique = DefaultShader.Techniques["Textured"];
                DefaultShader.Parameters["Clipping"].SetValue(0);

                //ComponentManager.CollisionManager.DebugDraw();

                // Render simple geometry (boxes, etc.)
                Drawer3D.Render(GraphicsDevice, DefaultShader, true);

                // Now draw all of the entities in the game
                DefaultShader.Parameters["ClipPlane0"].SetValue(new Vector4(slicePlane.Normal, slicePlane.D));
                DefaultShader.Parameters["Clipping"].SetValue(1);
                DefaultShader.Parameters["GhostMode"].SetValue(1);
                DrawComponents(gameTime, DefaultShader, Camera.ViewMatrix, ComponentManager.WaterRenderType.None,
                    lastWaterHeight);
                DefaultShader.Parameters["Clipping"].SetValue(0);

                if (GameSettings.Default.EnableGlow)
                {
                    bloom.DrawTarget = UseFXAA ? fxaa.RenderTarget : null;
                    bloom.Draw(gameTime.ToGameTime());
                    if (UseFXAA)
                        fxaa.End(DwarfTime.LastTime, fxaa.RenderTarget);
                }
                else if (UseFXAA)
                {
                    fxaa.End(DwarfTime.LastTime, fxaa.RenderTarget);
                }

                frameTimer.Update(gameTime);

                if (frameTimer.HasTriggered)
                {
                    fps = frameCounter;

                    lastFps.Add(fps);
                    frameCounter = 0;
                    frameTimer.Reset(1.0f);
                }
                else
                {
                    frameCounter++;
                }

                RasterizerState rasterizerState = new RasterizerState()
                {
                    ScissorTestEnable = true
                };

                DwarfGame.SpriteBatch.Begin(SpriteSortMode.Immediate, BlendState.AlphaBlend, SamplerState.PointClamp,
                    null, rasterizerState);

                drawer2D.Render(DwarfGame.SpriteBatch, Camera, GraphicsDevice.Viewport);

                GUI.Render(gameTime, DwarfGame.SpriteBatch, Vector2.Zero);

                bool drawDebugData = GameSettings.Default.DrawDebugData;
                if (drawDebugData)
                {
                    DwarfGame.SpriteBatch.DrawString(Game.Content.Load<SpriteFont>("Default"),
                        "Num Chunks " + ChunkManager.ChunkData.ChunkMap.Values.Count, new Vector2(5, 5), Color.White);
                    DwarfGame.SpriteBatch.DrawString(Game.Content.Load<SpriteFont>("Default"),
                        "Max Viewing Level " + ChunkManager.ChunkData.MaxViewingLevel, new Vector2(5, 20), Color.White);
                    DwarfGame.SpriteBatch.DrawString(Game.Content.Load<SpriteFont>("Default"), "FPS " + Math.Round(fps),
                        new Vector2(5, 35), Color.White);
                    DwarfGame.SpriteBatch.DrawString(Game.Content.Load<SpriteFont>("Default"), "60",
                        new Vector2(5, 150 - 65), Color.White);
                    DwarfGame.SpriteBatch.DrawString(Game.Content.Load<SpriteFont>("Default"), "30",
                        new Vector2(5, 150 - 35), Color.White);
                    DwarfGame.SpriteBatch.DrawString(Game.Content.Load<SpriteFont>("Default"), "10",
                        new Vector2(5, 150 - 15), Color.White);
                    for (int i = 0; i < lastFps.Count; i++)
                    {
                        DwarfGame.SpriteBatch.Draw(pixel,
                            new Rectangle(30 + i*2, 150 - (int) lastFps[i], 2, (int) lastFps[i]),
                            new Color(1.0f - lastFps[i]/60.0f, lastFps[i]/60.0f, 0.0f, 0.5f));
                    }
                }

                if (Paused)
                {
                    Drawer2D.DrawStrokedText(DwarfGame.SpriteBatch, "Paused", GUI.DefaultFont,
                        new Vector2(GraphicsDevice.Viewport.Width - 100, 10), Color.White, Color.Black);
                }
                //DwarfGame.SpriteBatch.Draw(Shadows.ShadowTexture, new Rectangle(0, 0, 512, 512), Color.White);
                IndicatorManager.Render(gameTime);
                GUI.PostRender(gameTime);
                DwarfGame.SpriteBatch.End();
                Master.Render(Game, gameTime, GraphicsDevice);
                DwarfGame.SpriteBatch.GraphicsDevice.ScissorRectangle =
                    DwarfGame.SpriteBatch.GraphicsDevice.Viewport.Bounds;

                /*
            int dx = 0;
            foreach (var composite in CompositeLibrary.Composites)
            {
                composite.Value.DebugDraw(DwarfGame.SpriteBatch, dx, 128);
                dx += 256;
            }
            */

                GraphicsDevice.DepthStencilState = DepthStencilState.Default;
                GraphicsDevice.BlendState = BlendState.Opaque;

            lock(ScreenshotLock)
            {
                foreach (Screenshot shot in Screenshots)
                {
                    TakeScreenshot(shot.FileName, shot.Resolution);
                }

                Screenshots.Clear();
            }

            base.Render(gameTime);
        }
Пример #3
0
        public override void Update(DwarfTime gameTime)
        {
            if (StateManager.CurrentState == Name)
            {
                GUI.Update(gameTime);
                Input.Update();

                GUI.EnableMouseEvents = !IsGenerating;

                if (!IsGenerating && !DoneGenerating)
                {
                    Generate();
                }
            }
            TransitionValue = 1.0f;

            base.Update(gameTime);
        }
Пример #4
0
        private void DrawGUI(DwarfTime gameTime, float dx)
        {
            RasterizerState rasterizerState = new RasterizerState()
            {
                ScissorTestEnable = true
            };

            GUI.PreRender(gameTime, DwarfGame.SpriteBatch);
            DwarfGame.SpriteBatch.Begin(SpriteSortMode.Immediate, BlendState.AlphaBlend, SamplerState.PointClamp, null, rasterizerState);
            GUI.Render(gameTime, DwarfGame.SpriteBatch, new Vector2(dx, 0));
            GUI.PostRender(gameTime);
            DwarfGame.SpriteBatch.End();

            DwarfGame.SpriteBatch.GraphicsDevice.ScissorRectangle = DwarfGame.SpriteBatch.GraphicsDevice.Viewport.Bounds;
        }
Пример #5
0
        public override void Render(DwarfTime gameTime)
        {
            switch (Transitioning)
            {
                case TransitionMode.Running:
                    DrawGUI(gameTime, 0);
                    break;
                case TransitionMode.Entering:
                    {
                        float dx = Easing.CubeInOut(TransitionValue, -Game.GraphicsDevice.Viewport.Width, Game.GraphicsDevice.Viewport.Width, 1.0f);
                        DrawGUI(gameTime, dx);
                    }
                    break;
                case TransitionMode.Exiting:
                    {
                        float dx = Easing.CubeInOut(TransitionValue, 0, Game.GraphicsDevice.Viewport.Width, 1.0f);
                        DrawGUI(gameTime, dx);
                    }
                    break;
            }

            base.Render(gameTime);
        }
Пример #6
0
 public virtual void Update(DwarfTime gameTime)
 {
 }
Пример #7
0
 public override void Render(DwarfTime gameTime)
 {
     DrawGUI(gameTime, 0);
     base.Render(gameTime);
 }
Пример #8
0
        public void FillClosestLights(DwarfTime time)
        {
            List<Vector3> positions = ( from light in DynamicLight.Lights select light.Position).ToList();
            positions.AddRange(( from light in DynamicLight.TempLights select light.Position));
            positions.Sort((a, b) =>
            {
                float dA = MathFunctions.L1(a, Camera.Position);
                float dB = MathFunctions.L1(b, Camera.Position);
                return dA.CompareTo(dB);
            });
            int numLights = Math.Min(16, positions.Count + 1);
            for (int i = 1; i < numLights; i++)
            {
                if (i > positions.Count)
                {
                    LightPositions[i] = new Vector3(0, 0, 0);
                }
                else
                {
                    LightPositions[i] = positions[i - 1];
                }
            }

            for (int j = numLights; j < 16; j++)
            {
                LightPositions[j] = new Vector3(0, 0, 0);
            }

            DynamicLight.TempLights.Clear();
        }
Пример #9
0
        public override void Update(DwarfTime gameTime)
        {
            Input.Update();
            GUI.Update(gameTime);
            GUI.IsMouseVisible = true;

            base.Update(gameTime);
        }
Пример #10
0
        public override void Render(DwarfTime gameTime)
        {
            if(Transitioning == TransitionMode.Running)
            {
                DrawGUI(gameTime, 0);
            }
            else if(Transitioning == TransitionMode.Entering)
            {
                float dx = Easing.CubeInOut(TransitionValue, -Game.GraphicsDevice.Viewport.Width, Game.GraphicsDevice.Viewport.Width, 1.0f);
                DrawGUI(gameTime, dx);
            }
            else if(Transitioning == TransitionMode.Exiting)
            {
                float dx = Easing.CubeInOut(TransitionValue, 0, Game.GraphicsDevice.Viewport.Width, 1.0f);
                DrawGUI(gameTime, dx);
            }

            base.Render(gameTime);
        }
Пример #11
0
        public void Update(DwarfTime time)
        {
            PushParticipants();
            switch (State)
            {
            case Status.WaitingForPlayers:
            {
                Participants.RemoveAll(creature => creature == null || creature.IsDead || creature.Status.Money < 10.0m || creature.Physics.IsInLiquid);
                WaitTimer.Update(time);
                if (WaitTimer.HasTriggered || Participants.Count >= 4)
                {
                    if (Participants.Count >= 2)
                    {
                        foreach (var participant in Participants)
                        {
                            if ((Location - participant.AI.Position).Length() > 4)
                            {
                                return;
                            }
                        }
                        Participants[0].World.LogEvent("A new game of dice has started.", String.Format("There are {0} players.", Participants.Count));
                        State = Status.Gaming;
                        RoundTimer.Reset();
                        CurrentRound = 1;
                        if (PotFixture == null)
                        {
                            PotFixture = new CoinPileFixture(Participants[0].Manager, Location)
                            {
                                Name = "Gambling pot"
                            };
                            PotFixture.SetFullness(0);
                            Participants[0].Manager.RootComponent.AddChild(PotFixture);
                        }
                    }
                    else
                    {
                        if (Participants.Count > 0)
                        {
                            Participants[0].World.LogEvent("The dice game ended prematurely.", "The dice players couldn't meet up.");
                        }
                        EndGame();
                    }
                    return;
                }
                break;
            }

            case Status.Gaming:
            {
                RoundTimer.Update(time);
                if (RoundTimer.HasTriggered)
                {
                    NextRound();
                }
                return;
            }

            case Status.Ended:
            {
                WaitTimer.Reset();
                return;
            }
            }
        }
Пример #12
0
        public override void Update(DwarfTime gameTime)
        {
            if (DoneLoading)
            {
                // Todo: Decouple gui/input from world.
                // Copy important bits to PlayState - This is a hack; decouple world from gui and input instead.
                PlayState.Input = Input;
                GameStateManager.PopState(false);
                GameStateManager.PushState(new PlayState(Game, World));

                World.OnSetLoadingMessage = null;
            }
            else
            {
                if (LoadType == LoadTypes.GenerateOverworld)
                {
                    if (Generator.CurrentState == OverworldGenerator.GenerationState.Finished && World == null)
                    {
                        CreateWorld();
                    }
                    else
                    {
                        if (!LoadTicker.HasMesssage(Generator.LoadingMessage))
                        {
                            LoadTicker.AddMessage(Generator.LoadingMessage);
                        }
                    }
                }

                foreach (var item in DwarfGame.GumInputMapper.GetInputQueue())
                {
                    GuiRoot.HandleInput(item.Message, item.Args);
                    if (item.Message == Gui.InputEvents.KeyPress)
                    {
                        Runner.Jump();
                    }
                }

                GuiRoot.Update(gameTime.ToRealTime());
                Runner.Update(gameTime);

                if (World != null && World.LoadStatus == WorldManager.LoadingStatus.Failure && !DisplayException)
                {
                    DisplayException = true;
                    string exceptionText = World.LoadingException == null
                        ? "Unknown exception."
                        : World.LoadingException.ToString();
                    GuiRoot.MouseVisible        = true;
                    GuiRoot.MousePointer        = new Gui.MousePointer("mouse", 4, 0);
                    DwarfTime.LastTime.IsPaused = false;
                    DwarfTime.LastTime.Speed    = 1.0f;
                    World = null;
                    DwarfGame.LogSentryBreadcrumb("Loading", "Loading failed.", SharpRaven.Data.BreadcrumbLevel.Error);
                    GuiRoot.ShowModalPopup(new Gui.Widgets.Confirm()
                    {
                        CancelText = "",
                        Text       = "Oh no! Loading failed :( This crash has been automatically reported to the developers: " + exceptionText,
                        OnClick    = (s, a) =>
                        {
                            DwarfGame.LogSentryBreadcrumb("Loading", "Loading failed. Player going back to start.");
                            GameStateManager.ClearState();
                        },
                        OnClose = (s) =>
                        {
                            DwarfGame.LogSentryBreadcrumb("Loading", "Loading failed. Player going back to start.");
                            GameStateManager.ClearState();
                        },
                        Rect = GuiRoot.RenderData.VirtualScreen
                    });
                }
            }

            base.Update(gameTime);
        }
Пример #13
0
 public override void Update(DwarfTime Time, ChunkManager Chunks, Camera Camera)
 {
     base.Update(Time, Chunks, Camera);
 }
Пример #14
0
        public void PreRender(DwarfTime time, SpriteBatch sprites)
        {
            if (sprites.IsDisposed || sprites.GraphicsDevice.IsDisposed)
            {
                return;
            }
            try
            {
                ValidateShader();
                if (RenderTarget.IsDisposed || RenderTarget.IsContentLost)
                {
                    World.ChunkManager.NeedsMinimapUpdate = true;
                    RenderTarget = new RenderTarget2D(GameState.Game.GraphicsDevice, RenderWidth, RenderHeight, false, SurfaceFormat.Color, DepthFormat.Depth24);
                    return;
                }

                if (!HomeSet)
                {
                    if (World.PlayerFaction.GetRooms().Count > 0)
                    {
                        HomePosition = World.PlayerFaction.GetRooms().First().GetBoundingBox().Center();
                    }
                    HomeSet = true;
                }
                ReDrawChunks(time);
                World.GraphicsDevice.SetRenderTarget(RenderTarget);
                World.GraphicsDevice.Clear(Color.Black);
                Camera.Target = World.Camera.Target;
                Vector3 cameraToTarget = World.Camera.Target - World.Camera.Position;
                cameraToTarget.Normalize();
                Camera.Position = World.Camera.Target + Vector3.Up * 50 - cameraToTarget * 4;
                Camera.UpdateViewMatrix();
                Camera.UpdateProjectionMatrix();
                World.DefaultShader.View       = Camera.ViewMatrix;
                World.DefaultShader.Projection = Camera.ProjectionMatrix;
                var bounds = World.ChunkManager.Bounds;
                DrawShader.Texture            = TerrainTexture;
                DrawShader.TextureEnabled     = true;
                DrawShader.LightingEnabled    = false;
                DrawShader.Projection         = Camera.ProjectionMatrix;
                DrawShader.View               = Camera.ViewMatrix;
                DrawShader.World              = Matrix.Identity;
                DrawShader.VertexColorEnabled = false;
                DrawShader.Alpha              = 1.0f;

                if (quad == null)
                {
                    quad = new VertexPositionTexture[]
                    {
                        new VertexPositionTexture(new Vector3(bounds.Min.X, 0, bounds.Min.Z), new Vector2(0, 0)),
                        new VertexPositionTexture(new Vector3(bounds.Max.X, 0, bounds.Min.Z), new Vector2(1, 0)),
                        new VertexPositionTexture(new Vector3(bounds.Max.X, 0, bounds.Max.Z), new Vector2(1, 1)),
                        new VertexPositionTexture(new Vector3(bounds.Max.X, 0, bounds.Max.Z), new Vector2(1, 1)),
                        new VertexPositionTexture(new Vector3(bounds.Min.X, 0, bounds.Max.Z), new Vector2(0, 1)),
                        new VertexPositionTexture(new Vector3(bounds.Min.X, 0, bounds.Min.Z), new Vector2(0, 0)),
                    };
                }
                foreach (var pass in DrawShader.CurrentTechnique.Passes)
                {
                    pass.Apply();
                    World.GraphicsDevice.DrawUserPrimitives(PrimitiveType.TriangleList, quad, 0, 2);
                }

                World.DefaultShader.EnbleFog = true;
                try
                {
                    DwarfGame.SafeSpriteBatchBegin(SpriteSortMode.Deferred,
                                                   BlendState.NonPremultiplied, Drawer2D.PointMagLinearMin, null, RasterizerState.CullNone, null,
                                                   Matrix.Identity);
                    Viewport viewPort = new Viewport(RenderTarget.Bounds);

                    foreach (var icon in World.ComponentManager.GetMinimapIcons())
                    {
                        if (!icon.Parent.IsVisible)
                        {
                            continue;
                        }

                        Vector3 screenPos = viewPort.Project(icon.GlobalTransform.Translation, Camera.ProjectionMatrix, Camera.ViewMatrix, Matrix.Identity);

                        if (RenderTarget.Bounds.Contains((int)screenPos.X, (int)screenPos.Y))
                        {
                            Body parentBody = icon.Parent as Body;
                            if (parentBody != null)
                            {
                                if (parentBody.Position.Y > World.Master.MaxViewingLevel + 1)
                                {
                                    continue;
                                }
                                var firstVisible = VoxelHelpers.FindFirstVisibleVoxelOnRay(World.ChunkManager.ChunkData, parentBody.Position, parentBody.Position + Vector3.Up * VoxelConstants.ChunkSizeY);
                                if (firstVisible.IsValid)
                                {
                                    continue;
                                }
                            }

                            DwarfGame.SpriteBatch.Draw(icon.Icon.SafeGetImage(), new Vector2(screenPos.X, screenPos.Y), icon.Icon.SourceRect, Color.White, 0.0f, new Vector2(icon.Icon.SourceRect.Width / 2.0f, icon.Icon.SourceRect.Height / 2.0f), icon.IconScale, SpriteEffects.None, 0);
                        }
                    }
                }

                finally
                {
                    sprites.End();
                }

                World.GraphicsDevice.BlendState        = BlendState.NonPremultiplied;
                World.GraphicsDevice.DepthStencilState = DepthStencilState.Default;
                World.GraphicsDevice.RasterizerState   = RasterizerState.CullCounterClockwise;
                World.GraphicsDevice.SamplerStates[0]  = Drawer2D.PointMagLinearMin;
                World.GraphicsDevice.SetRenderTarget(null);
            }
            catch (Exception exception)
            {
                Console.Out.WriteLine(exception);
            }
        }
Пример #15
0
        /// <summary>
        /// Called every frame
        /// </summary>
        /// <param name="DwarfTime">The current time</param>
        public override void Update(DwarfTime gameTime)
        {
            // If this playstate is not supposed to be running,
            // just exit.
            if(!Game.IsActive || !IsActiveState)
            {
                return;
            }

            // Handles time foward + backward TODO: Replace with input manager
            if(Keyboard.GetState().IsKeyDown(ControlSettings.Mappings.TimeForward))
            {
                Time.Speed = 10000;
            }
            else if(Keyboard.GetState().IsKeyDown(ControlSettings.Mappings.TimeBackward))
            {
                Time.Speed = -10000;
            }
            else
            {
                Time.Speed = 100;
            }

            if (FastForwardToDay)
            {
                if (Time.IsDay())
                {
                    FastForwardToDay = false;
                    foreach (CreatureAI minion in Master.Faction.Minions)
                    {
                        minion.Status.Energy.CurrentValue = minion.Status.Energy.MaxValue;
                    }
                }
                else
                {
                    Time.Speed = 10000;
                }
            }

            // Handles pausing and unpausing TODO: replace with input manager
            if(Keyboard.GetState().IsKeyDown(ControlSettings.Mappings.Pause))
            {
                if(!pausePressed)
                {
                    pausePressed = true;
                }
            }
            else
            {
                if(pausePressed)
                {
                    pausePressed = false;
                    Paused = !Paused;
                }
            }

            // Turns the gui on and off TODO: replace with input manager
            if(Keyboard.GetState().IsKeyDown(ControlSettings.Mappings.ToggleGUI))
            {
                if(!bPressed)
                {
                    bPressed = true;
                }
            }
            else
            {
                if(bPressed)
                {
                    bPressed = false;
                    GUI.RootComponent.IsVisible = !GUI.RootComponent.IsVisible;
                }
            }

            FillClosestLights(gameTime);
            IndicatorManager.Update(gameTime);
            AspectRatio = GraphicsDevice.Viewport.AspectRatio;
            Camera.AspectRatio = AspectRatio;

            Camera.Update(gameTime, PlayState.ChunkManager);

            if (KeyManager.RotationEnabled())
                Mouse.SetPosition(GameState.Game.GraphicsDevice.Viewport.Width / 2, GameState.Game.GraphicsDevice.Viewport.Height / 2);

            Master.Update(Game, gameTime);
            // If not paused, we want to just update the rest of the game.
            if (!Paused)
            {
                Time.Update(gameTime);

                ComponentManager.Update(gameTime, ChunkManager, Camera);
                Sky.TimeOfDay = Time.GetSkyLightness();
                Sky.CosTime = (float)(Time.GetTotalHours() * 2 * Math.PI / 24.0f);
                DefaultShader.Parameters["xTimeOfDay"].SetValue(Sky.TimeOfDay);
                MonsterSpawner.Update(gameTime);
                bool allAsleep = Master.AreAllEmployeesAsleep();
                if (SleepPrompt && allAsleep && !FastForwardToDay && Time.IsNight())
                {
                    Dialog sleepingPrompt = Dialog.Popup(GUI, "Employees Asleep",
                        "All of your employees are asleep. Skip to daytime?", Dialog.ButtonType.OkAndCancel);
                    SleepPrompt = false;
                    sleepingPrompt.OnClosed += sleepingPrompt_OnClosed;
                }
                else if(!allAsleep)
                {
                    SleepPrompt = true;
                }
            }

            // These things are updated even when the game is paused
            GUI.Update(gameTime);
            ChunkManager.Update(gameTime, Camera, GraphicsDevice);
            InstanceManager.Update(gameTime, Camera, GraphicsDevice);
            Input.Update();

            SoundManager.Update(gameTime, Camera);

            // Updates some of the GUI status
            if(Game.IsActive)
            {
                CurrentLevelLabel.Text = "Slice: " + ChunkManager.ChunkData.MaxViewingLevel + "/" + ChunkHeight;
                TimeLabel.Text = Time.CurrentDate.ToShortDateString() + " " + Time.CurrentDate.ToShortTimeString();
            }

            // Make sure that the slice slider snaps to the current viewing level (an integer)
            //if(!LevelSlider.IsMouseOver)
            {
             //   LevelSlider.SliderValue = ChunkManager.ChunkData.MaxViewingLevel;
            }
            base.Update(gameTime);
        }
Пример #16
0
 /// <summary>
 /// Draws all of the game entities
 /// </summary>
 /// <param name="DwarfTime">The current time</param>
 /// <param name="effect">The shader</param>
 /// <param name="view">The view matrix</param>
 /// <param name="waterRenderType">Whether we are rendering for reflection/refraction or nothing</param>
 /// <param name="waterLevel">The estimated height of water</param>
 public void DrawComponents(DwarfTime gameTime, Effect effect, Matrix view, ComponentManager.WaterRenderType waterRenderType, float waterLevel)
 {
     effect.Parameters["xView"].SetValue(view);
     ComponentManager.Render(gameTime, ChunkManager, Camera, DwarfGame.SpriteBatch, GraphicsDevice, effect, waterRenderType, waterLevel);
     bool reset = waterRenderType == ComponentManager.WaterRenderType.None;
     InstanceManager.Render(GraphicsDevice, effect, Camera, reset);
 }
Пример #17
0
        private void DrawGUI(DwarfTime gameTime, float dx)
        {
            RasterizerState rasterizerState = new RasterizerState()
            {
                ScissorTestEnable = true
            };

            GUI.PreRender(gameTime, DwarfGame.SpriteBatch);
            DwarfGame.SpriteBatch.Begin(SpriteSortMode.Immediate, BlendState.AlphaBlend, SamplerState.PointClamp, null, rasterizerState);
            DwarfGame.SpriteBatch.Draw(Logo, new Vector2(Game.GraphicsDevice.Viewport.Width / 2 - Logo.Width / 2 + dx, 10), null, Color.White);
            Drawer.Render(DwarfGame.SpriteBatch, null, Game.GraphicsDevice.Viewport);
            GUI.Render(gameTime, DwarfGame.SpriteBatch, new Vector2(dx, 0));

            DwarfGame.SpriteBatch.DrawString(GUI.DefaultFont, Program.Version, new Vector2(15, 15), Color.White);
            GUI.PostRender(gameTime);
            DwarfGame.SpriteBatch.End();
            DwarfGame.SpriteBatch.GraphicsDevice.ScissorRectangle = DwarfGame.SpriteBatch.GraphicsDevice.Viewport.Bounds;
        }
Пример #18
0
 public override void Update(DwarfTime gameTime)
 {
     MainWindow.LocalBounds = new Rectangle(EdgePadding, EdgePadding, Game.GraphicsDevice.Viewport.Width - EdgePadding * 2, Game.GraphicsDevice.Viewport.Height - EdgePadding * 2);
     Input.Update();
     GUI.Update(gameTime);
     base.Update(gameTime);
 }
Пример #19
0
        public override void Update(DwarfGame game, DwarfTime time)
        {
            if (Player.IsCameraRotationModeActive())
            {
                Player.VoxSelector.Enabled = false;
                Player.World.SetMouse(null);
                Player.BodySelector.Enabled = false;
                return;
            }

            Player.VoxSelector.Enabled       = true;
            Player.BodySelector.Enabled      = false;
            Player.VoxSelector.DrawBox       = false;
            Player.VoxSelector.DrawVoxel     = false;
            Player.VoxSelector.SelectionType = VoxelSelectionType.SelectEmpty;

            if (Player.World.IsMouseOverGui)
            {
                Player.World.SetMouse(Player.World.MousePointer);
            }
            else
            {
                Player.World.SetMouse(new Gui.MousePointer("mouse", 1, 4));
            }

            // Don't attempt any control if the user is trying to type into a focus item.
            if (Player.World.Gui.FocusItem != null && !Player.World.Gui.FocusItem.IsAnyParentTransparent() && !Player.World.Gui.FocusItem.IsAnyParentHidden())
            {
                return;
            }

            KeyboardState state    = Keyboard.GetState();
            bool          leftKey  = state.IsKeyDown(ControlSettings.Mappings.RotateObjectLeft);
            bool          rightKey = state.IsKeyDown(ControlSettings.Mappings.RotateObjectRight);

            if (LeftPressed && !leftKey)
            {
                Pattern = Pattern.Rotate(Rail.PieceOrientation.East);
            }
            if (RightPressed && !rightKey)
            {
                Pattern = Pattern.Rotate(Rail.PieceOrientation.West);
            }
            LeftPressed  = leftKey;
            RightPressed = rightKey;

            var tint = Color.White;

            for (var i = 0; i < PreviewBodies.Count && i < Pattern.Pieces.Count; ++i)
            {
                PreviewBodies[i].UpdatePiece(Pattern.Pieces[i], Player.VoxSelector.VoxelUnderMouse);
            }

            if (RailHelper.CanPlace(Player, PreviewBodies))
            {
                tint = GameSettings.Default.Colors.GetColor("Positive", Color.Green);
            }
            else
            {
                tint = GameSettings.Default.Colors.GetColor("Negative", Color.Red);
            }

            foreach (var body in PreviewBodies)
            {
                body.SetVertexColorRecursive(tint);
            }
        }
Пример #20
0
 public virtual void RenderUnitialized(DwarfTime gameTime)
 {
 }
Пример #21
0
 public override void Render(DwarfGame game, GraphicsDevice graphics, DwarfTime time)
 {
 }
Пример #22
0
        public override void Update(DwarfTime gameTime)
        {
            GUI.MouseMode = GUISkin.MousePointer.Wait;

            if (!WaitThread.IsAlive && StateManager.CurrentState == Name && !Done)
            {
                StateManager.PopState();
                Done = true;
            }

            base.Update(gameTime);
        }
Пример #23
0
        override public void Render(DwarfTime gameTime, ChunkManager chunks, Camera camera, SpriteBatch spriteBatch, GraphicsDevice graphicsDevice, Shader effect, bool renderingForWater)
        {
            base.Render(gameTime, chunks, camera, spriteBatch, graphicsDevice, effect, renderingForWater);

            if (Debugger.Switches.DrawRailNetwork)
            {
                //Drawer3D.DrawBox(GetContainingVoxel().GetBoundingBox(), Color.White, 0.01f, true);
                //Drawer3D.DrawLine(GetContainingVoxel().GetBoundingBox().Center(), GlobalTransform.Translation, Color.White, 0.01f);
                var transform = Matrix.CreateRotationY((float)Math.PI * 0.5f * (float)Piece.Orientation) * GlobalTransform;
                if (Library.GetRailPiece(Piece.RailPiece).HasValue(out var piece))
                {
                    foreach (var spline in piece.SplinePoints)
                    {
                        for (var i = 1; i < spline.Count; ++i)
                        {
                            Drawer3D.DrawLine(Vector3.Transform(spline[i - 1], transform),
                                              Vector3.Transform(spline[i], transform), Color.Purple, 0.1f);
                        }
                    }

                    foreach (var connection in piece.EnumerateConnections())
                    {
                        Drawer3D.DrawLine(Vector3.Transform(connection.Item1, transform) + new Vector3(0.0f, 0.2f, 0.0f),
                                          Vector3.Transform(connection.Item2, transform) + new Vector3(0.0f, 0.2f, 0.0f),
                                          Color.Brown, 0.1f);
                    }


                    //foreach (var neighborConnection in NeighborRails)
                    //{
                    //    var neighbor = Manager.FindComponent(neighborConnection.NeighborID);
                    //    if (neighbor == null)
                    //        Drawer3D.DrawLine(Position, Position + Vector3.UnitY, Color.CornflowerBlue, 0.1f);
                    //    else
                    //        Drawer3D.DrawLine(Position + new Vector3(0.0f, 0.5f, 0.0f), (neighbor as Body).Position + new Vector3(0.0f, 0.5f, 0.0f), Color.Teal, 0.1f);
                    //}
                }
            }

            if (!IsVisible)
            {
                return;
            }

            if (Primitive == null)
            {
                var bounds = Vector4.Zero;
                var uvs    = Sheet.GenerateTileUVs(Frame, out bounds);

                if (Library.GetRailPiece(Piece.RailPiece).HasValue(out var rawPiece))
                {
                    var transform = Matrix.CreateRotationY((float)Math.PI * 0.5f * (float)Piece.Orientation);
                    var realShape = 0;

                    if (rawPiece.AutoSlope)
                    {
                        var transformedConnections = GetTransformedConnections();
                        var matchingNeighbor1      = NeighborRails.FirstOrDefault(n => (n.Position - transformedConnections[0].Item1 - new Vector3(0.0f, 1.0f, 0.0f)).LengthSquared() < 0.001f);
                        var matchingNeighbor2      = NeighborRails.FirstOrDefault(n => (n.Position - transformedConnections[1].Item1 - new Vector3(0.0f, 1.0f, 0.0f)).LengthSquared() < 0.001f);

                        if (matchingNeighbor1 != null && matchingNeighbor2 != null)
                        {
                            realShape = 3;
                        }
                        else if (matchingNeighbor1 != null)
                        {
                            realShape = 1;
                        }
                        else if (matchingNeighbor2 != null)
                        {
                            realShape = 2;
                        }
                    }

                    Primitive = new RawPrimitive();
                    Primitive.AddVertex(new ExtendedVertex(Vector3.Transform(new Vector3(-0.5f, VertexHeightOffsets[realShape, 0], 0.5f), transform), Color.White, Color.White, uvs[0], bounds));
                    Primitive.AddVertex(new ExtendedVertex(Vector3.Transform(new Vector3(0.5f, VertexHeightOffsets[realShape, 1], 0.5f), transform), Color.White, Color.White, uvs[1], bounds));
                    Primitive.AddVertex(new ExtendedVertex(Vector3.Transform(new Vector3(0.5f, VertexHeightOffsets[realShape, 2], -0.5f), transform), Color.White, Color.White, uvs[2], bounds));
                    Primitive.AddVertex(new ExtendedVertex(Vector3.Transform(new Vector3(-0.5f, VertexHeightOffsets[realShape, 3], -0.5f), transform), Color.White, Color.White, uvs[3], bounds));
                    Primitive.AddIndicies(new short[] { 0, 1, 3, 1, 2, 3 });

                    var       sideBounds = Vector4.Zero;
                    Vector2[] sideUvs    = null;

                    sideUvs = Sheet.GenerateTileUVs(new Point(3, 4), out sideBounds);

                    AddScaffoldGeometry(transform, sideBounds, sideUvs, -1.0f, false);

                    if (realShape == 3)
                    {
                        AddScaffoldGeometry(transform, sideBounds, sideUvs, 0.0f, false);
                    }
                    else if (realShape == 1)
                    {
                        sideUvs = Sheet.GenerateTileUVs(new Point(0, 4), out sideBounds);
                        AddScaffoldGeometry(transform, sideBounds, sideUvs, 0.0f, true);
                    }
                    else if (realShape == 2)
                    {
                        sideUvs = Sheet.GenerateTileUVs(new Point(0, 4), out sideBounds);
                        AddScaffoldGeometry(transform, sideBounds, sideUvs, 0.0f, false);
                    }

                    // Todo: Make these static and avoid recalculating them constantly.
                    var bumperBackBounds  = Vector4.Zero;
                    var bumperBackUvs     = Sheet.GenerateTileUVs(new Point(0, 5), out bumperBackBounds);
                    var bumperFrontBounds = Vector4.Zero;
                    var bumperFrontUvs    = Sheet.GenerateTileUVs(new Point(1, 5), out bumperFrontBounds);
                    var bumperSideBounds  = Vector4.Zero;
                    var bumperSideUvs     = Sheet.GenerateTileUVs(new Point(2, 5), out bumperSideBounds);

                    foreach (var connection in GetTransformedConnections())
                    {
                        var matchingNeighbor = NeighborRails.FirstOrDefault(n => (n.Position - connection.Item1).LengthSquared() < 0.001f);
                        if (matchingNeighbor == null && rawPiece.AutoSlope)
                        {
                            matchingNeighbor = NeighborRails.FirstOrDefault(n => (n.Position - connection.Item1 - new Vector3(0.0f, 1.0f, 0.0f)).LengthSquared() < 0.001f);
                        }

                        if (matchingNeighbor == null)
                        {
                            var bumperOffset = connection.Item1 - GlobalTransform.Translation;
                            var bumperGap    = Vector3.Normalize(bumperOffset) * 0.1f;
                            var bumperAngle  = AngleBetweenVectors(new Vector2(bumperOffset.X, bumperOffset.Z), new Vector2(0, 0.5f));

                            var xDiag = bumperOffset.X <-0.001f || bumperOffset.X> 0.001f;
                            var zDiag = bumperOffset.Z <-0.001f || bumperOffset.Z> 0.001f;

                            if (xDiag && zDiag)
                            {
                                var y = bumperOffset.Y;
                                bumperOffset  *= sqrt2;
                                bumperOffset.Y = y;

                                var endBounds = Vector4.Zero;
                                var endUvs    = Sheet.GenerateTileUVs(new Point(6, 2), out endBounds);
                                Primitive.AddQuad(
                                    Matrix.CreateRotationY((float)Math.PI * 1.25f)
                                    * Matrix.CreateRotationY(bumperAngle)
                                    // This offset would not be correct if diagonals could slope.
                                    * Matrix.CreateTranslation(new Vector3(Sign(bumperOffset.X), 0.0f, Sign(bumperOffset.Z))),
                                    Color.White, Color.White, endUvs, endBounds);
                            }

                            Primitive.AddQuad(
                                Matrix.CreateRotationX(-(float)Math.PI * 0.5f)
                                * Matrix.CreateTranslation(0.0f, 0.3f, -0.2f)
                                * Matrix.CreateRotationY(bumperAngle)
                                * Matrix.CreateTranslation(bumperOffset + bumperGap),
                                Color.White, Color.White, bumperBackUvs, bumperBackBounds);

                            Primitive.AddQuad(
                                Matrix.CreateRotationX(-(float)Math.PI * 0.5f)
                                * Matrix.CreateTranslation(0.0f, 0.3f, -0.2f)
                                * Matrix.CreateRotationY(bumperAngle)
                                * Matrix.CreateTranslation(bumperOffset),
                                Color.White, Color.White, bumperFrontUvs, bumperFrontBounds);

                            var firstVoxelBelow = VoxelHelpers.FindFirstVoxelBelow(GetContainingVoxel());
                            if (firstVoxelBelow.IsValid && firstVoxelBelow.RampType == RampType.None)

                            //     if (VoxelHelpers.FindFirstVoxelBelow(GetContainingVoxel()).RampType == RampType.None)
                            {
                                Primitive.AddQuad(
                                    Matrix.CreateRotationX(-(float)Math.PI * 0.5f)
                                    * Matrix.CreateRotationY(-(float)Math.PI * 0.5f)
                                    * Matrix.CreateTranslation(0.3f, 0.3f, 0.18f)
                                    * Matrix.CreateRotationY(bumperAngle)
                                    * Matrix.CreateTranslation(bumperOffset),
                                    Color.White, Color.White, bumperSideUvs, bumperSideBounds);

                                Primitive.AddQuad(
                                    Matrix.CreateRotationX(-(float)Math.PI * 0.5f)
                                    * Matrix.CreateRotationY(-(float)Math.PI * 0.5f)
                                    * Matrix.CreateTranslation(-0.3f, 0.3f, 0.18f)
                                    * Matrix.CreateRotationY(bumperAngle)
                                    * Matrix.CreateTranslation(bumperOffset),
                                    Color.White, Color.White, bumperSideUvs, bumperSideBounds);
                            }
                        }
                    }
                }
            }

            // Everything that draws should set it's tint, making this pointless.

            var under = new VoxelHandle(chunks, GlobalVoxelCoordinate.FromVector3(Position));

            if (under.IsValid)
            {
                Color color = new Color(under.Sunlight ? 255 : 0, 255, 0);
                LightRamp = color;
            }
            else
            {
                LightRamp = new Color(200, 255, 0);
            }

            Color origTint = effect.VertexColorTint;

            if (!Active)
            {
                DoStipple(effect);
            }
            effect.VertexColorTint = VertexColor;
            effect.LightRamp       = LightRamp;
            effect.World           = GlobalTransform;

            effect.MainTexture = Sheet.GetTexture();


            effect.EnableWind = false;

            foreach (EffectPass pass in effect.CurrentTechnique.Passes)
            {
                pass.Apply();
                Primitive.Render(graphicsDevice);
            }

            effect.VertexColorTint = origTint;
            if (!Active)
            {
                EndDraw(effect);
            }
        }
Пример #24
0
        public override void Update(DwarfTime gameTime)
        {
            iter++;
            Input.Update();
            GUI.Update(gameTime);
            GUI.IsMouseVisible = true;

            foreach (GameLoadDescriptor t in Games)
            {
                t.Lock.WaitOne();

                if (!t.IsLoaded)
                {
                    t.Button.Text = "Loading";
                    for (int j = 0; j < (iter / 10) % 4; j++)
                    {
                        t.Button.Text += ".";
                    }
                }

                t.Lock.ReleaseMutex();
            }

            base.Update(gameTime);
        }
Пример #25
0
 public virtual void RenderUnitialized(DwarfTime gameTime)
 {
 }
Пример #26
0
        public override void Render(DwarfTime gameTime)
        {
            if(Transitioning == TransitionMode.Running)
            {
                Game.GraphicsDevice.SamplerStates[0] = SamplerState.PointClamp;
                DrawGUI(gameTime, 0);
            }
            else if(Transitioning == TransitionMode.Entering)
            {
                float dx = Easing.CubeInOut(TransitionValue, -Game.GraphicsDevice.Viewport.Height, Game.GraphicsDevice.Viewport.Height, 1.0f);
                DrawGUI(gameTime, dx);
            }
            else if(Transitioning == TransitionMode.Exiting)
            {
                float dx = Easing.CubeInOut(TransitionValue, 0, Game.GraphicsDevice.Viewport.Height, 1.0f);
                DrawGUI(gameTime, dx);
            }

            base.Render(gameTime);
        }
Пример #27
0
 public virtual void Update(DwarfTime gameTime)
 {
 }
Пример #28
0
        private void DrawGUI(DwarfTime gameTime, float dx)
        {
            GUI.PreRender(gameTime, DwarfGame.SpriteBatch);
            DwarfGame.SpriteBatch.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend, SamplerState.PointClamp,
                null, null);
            Drawer.Render(DwarfGame.SpriteBatch, null, Game.GraphicsDevice.Viewport);
            GUI.Render(gameTime, DwarfGame.SpriteBatch, new Vector2(0, dx));

            Progress.Message = !GenerationComplete ? LoadingMessage : "";

            if(GenerationComplete)
            {
                Rectangle imageBounds = MapPanel.GetImageBounds();
                float scaleX = ((float)imageBounds.Width / (float)PlayState.WorldWidth);
                float scaleY = ((float)imageBounds.Height / (float)PlayState.WorldHeight);
                Rectangle spawnRect = GetSpawnRectangle();
                Rectangle spawnRectOnImage = GetSpawnRectangleOnImage();
                Drawer2D.DrawRect(DwarfGame.SpriteBatch, spawnRectOnImage, Color.Yellow, 3.0f);
                Drawer2D.DrawStrokedText(DwarfGame.SpriteBatch, "Spawn", DefaultFont, new Vector2(spawnRectOnImage.X - 5, spawnRectOnImage.Y - 20), Color.White, Color.Black);

                //ImageMutex.WaitOne();
                /*
                DwarfGame.SpriteBatch.Draw(MapPanel.Image.Image,
                    new Rectangle(MapPanel.GetImageBounds().Right + 2, MapPanel.GetImageBounds().Top,  spawnRect.Width * 4, spawnRect.Height * 4),
                   spawnRect, Color.White);
                 */
                //ImageMutex.ReleaseMutex();
                CloseupPanel.Image.Image = MapPanel.Image.Image;
                CloseupPanel.Image.SourceRect = spawnRect;

                if (ViewSelectionBox.CurrentValue == "Factions")
                {
                    foreach (Faction civ in NativeCivilizations)
                    {
                        Point start = civ.Center;
                        Vector2 measure = Datastructures.SafeMeasure(GUI.SmallFont, civ.Name);
                        Rectangle snapped =
                            MathFunctions.SnapRect(
                                new Vector2(start.X*scaleX + imageBounds.X, start.Y*scaleY + imageBounds.Y) -
                                measure*0.5f, measure, imageBounds);

                        Drawer2D.DrawStrokedText(DwarfGame.SpriteBatch, civ.Name, GUI.SmallFont, new Vector2(snapped.X, snapped.Y), Color.White, Color.Black);
                    }
                }
            }

            GUI.PostRender(gameTime);
            DwarfGame.SpriteBatch.End();
        }
Пример #29
0
 public virtual void Render(DwarfTime gameTime)
 {
 }
Пример #30
0
        /// <summary>
        /// If the game is not loaded yet, just draws a loading message centered
        /// </summary>
        /// <param name="DwarfTime">The current time</param>
        public override void RenderUnitialized(DwarfTime gameTime)
        {
            TipTimer.Update(gameTime);
            if (TipTimer.HasTriggered)
            {
                LoadingTip = LoadingTips[Random.Next(LoadingTips.Count)];
                TipIndex++;
            }

            DwarfGame.SpriteBatch.Begin();
            float t = (float)(Math.Sin(gameTime.TotalGameTime.TotalSeconds * 2.0f) + 1.0f) * 0.5f + 0.5f;
            Color toDraw = new Color(t, t, t);
            SpriteFont font = Game.Content.Load<SpriteFont>(ContentPaths.Fonts.Default);
            Vector2 measurement = Datastructures.SafeMeasure(font, LoadingMessage);
            Drawer2D.DrawStrokedText(DwarfGame.SpriteBatch, LoadingMessage, font, new Vector2(Game.GraphicsDevice.Viewport.Width / 2 - measurement.X / 2, Game.GraphicsDevice.Viewport.Height / 2), toDraw, new Color(50, 50, 50));

            if (!string.IsNullOrEmpty(LoadingTip))
            {
                Vector2 tipMeasurement = Datastructures.SafeMeasure(font, LoadingTip);
                Drawer2D.DrawStrokedText(DwarfGame.SpriteBatch, "Tip: " + LoadingTip, font,
                    new Vector2(Game.GraphicsDevice.Viewport.Width/2 - tipMeasurement.X/2,
                        Game.GraphicsDevice.Viewport.Height - tipMeasurement.Y*2), toDraw, new Color(50, 50, 50));
            }
            DwarfGame.SpriteBatch.End();

            base.RenderUnitialized(gameTime);
        }
Пример #31
0
        public override void Update(DwarfTime gameTime)
        {
            if (DoneLoading)
            {
                // Todo: Decouple gui/input from world.
                // Copy important bits to PlayState - This is a hack; decouple world from gui and input instead.
                PlayState.Input = Input;
                StateManager.PopState();
                StateManager.PushState(new PlayState(Game, StateManager, World));

                World.OnSetLoadingMessage = null;
                Overworld.NativeFactions  = World.Natives;
            }
            else
            {
                if (Settings.GenerateFromScratch && Generator.CurrentState == WorldGenerator.GenerationState.Finished && World == null)
                {
                    Settings = Generator.Settings;
                    CreateWorld();
                }
                else if (Settings.GenerateFromScratch)
                {
                    if (!LoadTicker.HasMesssage(Generator.LoadingMessage))
                    {
                        LoadTicker.AddMessage(Generator.LoadingMessage);
                    }
                }

                foreach (var item in DwarfGame.GumInputMapper.GetInputQueue())
                {
                    GuiRoot.HandleInput(item.Message, item.Args);
                    if (item.Message == Gui.InputEvents.KeyPress)
                    {
                        Runner.Jump();
                    }
                }

                GuiRoot.Update(gameTime.ToGameTime());
                Runner.Update(gameTime);

                if (World != null && World.LoadStatus == WorldManager.LoadingStatus.Failure && !DisplayException)
                {
                    DisplayException = true;
                    string exceptionText = World.LoadingException == null
                        ? "Unknown exception."
                        : World.LoadingException.ToString();
                    GuiRoot.MouseVisible        = true;
                    GuiRoot.MousePointer        = new Gui.MousePointer("mouse", 4, 0);
                    DwarfTime.LastTime.IsPaused = false;
                    DwarfTime.LastTime.Speed    = 1.0f;
                    World = null;

                    GuiRoot.ShowModalPopup(new Gui.Widgets.Confirm()
                    {
                        CancelText = "",
                        Text       = "Oh no! Loading failed :( This crash has been automatically reported to Completely Fair Games: " + exceptionText,
                        OnClick    = (s, a) =>
                        {
                            StateManager.PopState();
                            StateManager.ClearState();
                            StateManager.PushState(new MainMenuState(Game, StateManager));
                        },
                        OnClose = (s) =>
                        {
                            StateManager.PopState();
                            StateManager.ClearState();
                            StateManager.PushState(new MainMenuState(Game, StateManager));
                        },
                        Rect = GuiRoot.RenderData.VirtualScreen
                    });
                }
            }

            base.Update(gameTime);
        }
Пример #32
0
        /// <summary>
        /// Draws all the 3D terrain and entities
        /// </summary>
        /// <param name="DwarfTime">The current time</param>
        /// <param name="cubeEffect">The textured shader</param>
        /// <param name="view">The view matrix of the camera</param> 
        public void Draw3DThings(DwarfTime gameTime, Effect cubeEffect, Matrix view)
        {
            Matrix viewMatrix = Camera.ViewMatrix;
            Camera.ViewMatrix = view;

            GraphicsDevice.SamplerStates[0] = SamplerState.PointClamp;
            cubeEffect.Parameters["xView"].SetValue(view);
            cubeEffect.Parameters["xProjection"].SetValue(Camera.ProjectionMatrix);
            cubeEffect.CurrentTechnique = cubeEffect.Techniques["Textured"];
            GraphicsDevice.BlendState = BlendState.AlphaBlend;
            ChunkManager.Render(Camera, gameTime, GraphicsDevice, cubeEffect, Matrix.Identity);

            if (Master.CurrentToolMode == GameMaster.ToolMode.Build)
            {
                cubeEffect.Parameters["xView"].SetValue(view);
                cubeEffect.Parameters["xProjection"].SetValue(Camera.ProjectionMatrix);
                cubeEffect.CurrentTechnique = cubeEffect.Techniques["Textured"];
                GraphicsDevice.BlendState = BlendState.AlphaBlend;
                Master.Faction.WallBuilder.Render(gameTime, GraphicsDevice, cubeEffect);
                Master.Faction.CraftBuilder.Render(gameTime, GraphicsDevice, cubeEffect);
            }
            Camera.ViewMatrix = viewMatrix;
        }
Пример #33
0
 public override void Render(DwarfTime gameTime)
 {
     GuiRoot.Draw();
     base.Render(gameTime);
 }
Пример #34
0
 /// <summary>
 /// Draws the sky box
 /// </summary>
 /// <param name="time">The current time</param>
 /// <param name="view">The camera view matrix</param>
 public void DrawSky(DwarfTime time, Matrix view, float scale)
 {
     Matrix oldView = Camera.ViewMatrix;
     Camera.ViewMatrix = view;
     Sky.Render(time, GraphicsDevice, Camera, scale);
     GraphicsDevice.RasterizerState = RasterizerState.CullCounterClockwise;
     GraphicsDevice.DepthStencilState = DepthStencilState.Default;
     Camera.ViewMatrix = oldView;
 }
Пример #35
0
        public override void Update(DwarfTime gameTime)
        {
            Game.IsMouseVisible = false;
            IntroTimer.Update(gameTime);

            if(IntroTimer.HasTriggered && Transitioning == TransitionMode.Running)
            {
                StateManager.PushState("MainMenuState");
            }

            if(Keyboard.GetState().GetPressedKeys().Length > 0 && Transitioning == TransitionMode.Running)
            {
                StateManager.PushState("MainMenuState");
            }

            base.Update(gameTime);
        }
Пример #36
0
 public override void Render(DwarfTime gameTime)
 {
     DrawGUI(gameTime, 0);
     base.Render(gameTime);
 }
Пример #37
0
 public virtual void Render(DwarfTime gameTime)
 {
 }
Пример #38
0
        private void DrawGUI(DwarfTime gameTime, float dx)
        {
            RasterizerState rasterizerState = new RasterizerState()
            {
                ScissorTestEnable = true
            };

            GUI.PreRender(gameTime, DwarfGame.SpriteBatch);

            DwarfGame.SpriteBatch.Begin(SpriteSortMode.Immediate, BlendState.AlphaBlend, SamplerState.PointClamp, DepthStencilState.None, rasterizerState);

            Drawer2D.FillRect(DwarfGame.SpriteBatch, Game.GraphicsDevice.Viewport.Bounds, new Color(0, 0, 0, 200));

            GUI.Render(gameTime, DwarfGame.SpriteBatch, new Vector2(dx, 0));

            Drawer.Render(DwarfGame.SpriteBatch, null, Game.GraphicsDevice.Viewport);
            GUI.PostRender(gameTime);
            DwarfGame.SpriteBatch.End();
        }
Пример #39
0
 private void DrawGUI(DwarfTime gameTime, float dx)
 {
     GUI.PreRender(gameTime, DwarfGame.SpriteBatch);
     DwarfGame.SpriteBatch.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend, SamplerState.PointClamp, null, null);
     Drawer.Render(DwarfGame.SpriteBatch, null, Game.GraphicsDevice.Viewport);
     GUI.Render(gameTime, DwarfGame.SpriteBatch, new Vector2(dx, 0));
     GUI.PostRender(gameTime);
     DwarfGame.SpriteBatch.End();
 }