Exemple #1
0
        public override void Update(DwarfTime gameTime)
        {
            foreach (var item in DwarfGame.GumInputMapper.GetInputQueue())
            {
                if (item.Message == Gum.InputEvents.KeyPress)
                {
                    Runner.Jump();
                }
            }

            GuiRoot.Update(gameTime.ToGameTime());
            Runner.Update(gameTime);
            base.Update(gameTime);
        }
Exemple #2
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.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;

                    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);
        }
Exemple #3
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)
                    {
                        // World generation is finished!
                        LoadTicker.AddMessage("Checking spawn position...");
                        while (InitialCell.Bounds.Width == 8 && InitialCell.Bounds.Height == 8 && !IsGoodSpawn())
                        {
                            LoadTicker.AddMessage("Selecting new spawn...");
                            InitialCell = Settings.ColonyCells.EnumerateCells().Where(c => c.Bounds.Width == 8 && c.Bounds.Height == 8).SelectRandom();
                        }

                        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);
        }