public LoadState(DwarfGame game, Overworld settings, LoadTypes LoadType) : base(game) { this.LoadType = LoadType; Settings = settings; EnableScreensaver = true; InitialEmbarkment = settings.InstanceSettings.InitalEmbarkment; InitialCell = settings.InstanceSettings.Cell; Runner = new DwarfRunner(game); }
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); }