示例#1
0
        public override void Update(DwarfTime gameTime)
        {
            foreach (var @event in DwarfGame.GumInput.GetInputQueue())
            {
                GuiRoot.HandleInput(@event.Message, @event.Args);
                if ([email protected])
                {
                    // Pass event to game...
                }
            }

            GuiRoot.Update(gameTime.ToGameTime());
            base.Update(gameTime);
        }
示例#2
0
 public override void Update(DwarfTime gameTime)
 {
     World.Tutorial("diplomacy");
     foreach (var @event in DwarfGame.GumInputMapper.GetInputQueue())
     {
         GuiRoot.HandleInput(@event.Message, @event.Args);
         if ([email protected])
         {
             // Pass event to game...
         }
     }
     World.TutorialManager.Update(GuiRoot);
     GuiRoot.Update(gameTime.ToGameTime());
     base.Update(gameTime);
 }
示例#3
0
        public override void Update(DwarfTime gameTime)
        {
            foreach (var @event in DwarfGame.GumInputMapper.GetInputQueue())
            {
                GuiRoot.HandleInput(@event.Message, @event.Args);
                if ([email protected])
                {
                    // Pass event to game...
                }
            }

            SpriteFrame.AnimationPlayer.Update(gameTime, false, Timer.TimerMode.Real);
            SpriteFrame.Sprite.Update(StateManager.Game.GraphicsDevice);
            GuiRoot.Update(gameTime.ToGameTime());

            base.Update(gameTime);
        }
示例#4
0
        public override void Update(DwarfTime gameTime)
        {
            foreach (var @event in DwarfGame.GumInputMapper.GetInputQueue())
            {
                GuiRoot.HandleInput(@event.Message, @event.Args);
                if ([email protected])
                {
                    // Pass event to game...
                }
            }

            Progress.Percentage = (float)gameTime.TotalGameTime.TotalSeconds / 10.0f;
            Progress.Percentage = Progress.Percentage - (float)Math.Floor(Progress.Percentage);

            GuiRoot.Update(gameTime.ToGameTime());

            base.Update(gameTime);
        }
示例#5
0
        public override void Update(DwarfTime gameTime)
        {
            World.Tutorial("economy");

            foreach (var @event in DwarfGame.GumInputMapper.GetInputQueue())
            {
                GuiRoot.HandleInput(@event.Message, @event.Args);
                if ([email protected])
                {
                    // Pass event to game...
                }
            }
            SoundManager.Update(gameTime, World.Camera, World.Time);
            World.TutorialManager.Update(GuiRoot);

            TabPanel.GetTabButton(1).IndicatorValue = World.GoalManager.NewAvailableGoals;
            TabPanel.GetTabButton(3).IndicatorValue = World.GoalManager.NewCompletedGoals;

            GuiRoot.Update(gameTime.ToGameTime());
            base.Update(gameTime);
        }
示例#6
0
 public override void Update(DwarfTime gameTime)
 {
     foreach (var @event in DwarfGame.GumInputMapper.GetInputQueue())
     {
         GuiRoot.HandleInput(@event.Message, @event.Args);
         if ([email protected])
         {
             if (@event.Args.KeyValue > 0)
             {
                 DialogueContext.Skip();
             }
             // Pass event to game...
         }
     }
     SoundManager.Update(gameTime, World.Camera, World.Time);
     GuiRoot.Update(gameTime.ToGameTime());
     DialogueContext.Update(gameTime);
     World.TutorialManager.Update(GuiRoot);
     World.Paused  = true;
     IsInitialized = true;
     base.OnEnter();
 }
示例#7
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);
        }
示例#8
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(false);
                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);
        }
        public override void Update(DwarfTime gameTime)
        {
            foreach (var @event in DwarfGame.GumInputMapper.GetInputQueue())
            {
                GuiRoot.HandleInput(@event.Message, @event.Args);
                if ([email protected])
                {
                    // Pass event to game...
                }
            }

            if (NeedsRefresh)
            {
                NeedsRefresh = false;

                if (PreviewOffset >= Items.Count && Items.Count > 0) // We're looking at an empty last page...
                {
                    PreviewOffset -= Grid.ItemsThatFit;
                }

                // Keep from selecting empty squares on final, incomplete page.
                var pageSize = System.Math.Min(Items.Count - PreviewOffset, Grid.ItemsThatFit);
                if (ItemSelected >= pageSize)
                {
                    ItemSelected = pageSize - 1;
                }

                var totalPages = (int)System.Math.Ceiling((float)Items.Count / (float)Grid.ItemsThatFit);
                Grid.Text = String.Format("Page {0} of {1}", (int)System.Math.Ceiling((float)PreviewOffset / (float)Grid.ItemsThatFit), totalPages);

                PrevButton.Hidden   = PreviewOffset == 0;
                NextButton.Hidden   = (PreviewOffset + Grid.ItemsThatFit >= Items.Count);
                DeleteButton.Hidden = Items.Count == 0;
                LoadButton.Hidden   = Items.Count == 0;

                for (var i = 0; i < Grid.Children.Count; ++i)
                {
                    var square = Grid.GetChild(i);
                    if (i < pageSize)
                    {
                        square.Hidden          = false;
                        square.BackgroundColor = new Vector4(1, 1, 1, 1);
                        if (i == ItemSelected)
                        {
                            square.BackgroundColor = new Vector4(1, 0, 0, 1);
                        }
                    }
                    else
                    {
                        square.Hidden = true;
                    }
                    square.Invalidate();
                }

                if (Items.Count > 0)
                {
                    var directoryTime = System.IO.Directory.GetLastWriteTime(Items[PreviewOffset + ItemSelected].Path);

                    BottomBar.Text = Items[PreviewOffset + ItemSelected].Path;

                    if (!Items[PreviewOffset + ItemSelected].Valid)
                    {
                        BottomBar.Text += "\n" + InvalidItemText;
                    }
                    else
                    {
                        BottomBar.Text += "\n" + directoryTime.ToShortDateString() + " " + directoryTime.ToShortTimeString();
                    }
                }
                else
                {
                    BottomBar.Text = NoItemsText;
                }
            }

            GuiRoot.Update(gameTime.ToGameTime());
            base.Update(gameTime);
        }