public LoadState(DwarfGame game, GameStateManager stateManager, WorldSettings settings) : base(game, "LoadState", stateManager) { Settings = settings; EnableScreensaver = true; Runner = new DwarfRunner(game); }
public WorldGeneratorState(DwarfGame game, GameStateManager stateManager) : base(game, "WorldGeneratorState", stateManager) { GenerationComplete = false; ImageMutex = new Mutex(); Input = new InputManager(); Settings = new WorldSettings(); }
public WorldLoaderState(DwarfGame game, GameStateManager stateManager) : base(game, "WorldLoaderState", stateManager) { Settings = new WorldSettings(); IsInitialized = false; Worlds = new List <WorldLoadDescriptor>(); ExitThreads = false; Threads = new List <Thread>(); }
public void LoadDescriptor(WorldLoadDescriptor descriptor, WorldSettings settings) { try { lock (descriptor.Lock) { if (!descriptor.IsLoaded) { return; } descriptor.File = new OverworldFile(descriptor.FileName, true, true); Overworld.Map = descriptor.File.Data.CreateMap(); Overworld.Name = descriptor.File.Data.Name; settings.Width = Overworld.Map.GetLength(1); settings.Height = Overworld.Map.GetLength(0); WorldGeneratorState.worldMap = descriptor.File.Data.CreateTexture(Game.GraphicsDevice, Overworld.Map.GetLength(0), Overworld.Map.GetLength(1), descriptor.File.Data.SeaLevel); JoinThreads(); StateManager.PopState(); StateManager.PushState(new WorldGeneratorState(Game, Game.StateManager) { Settings = Settings }); WorldGeneratorState state = StateManager.GetState <WorldGeneratorState>(); state.Progress.Value = 1.0f; state.GenerationComplete = true; state.DoneGenerating = true; state.Settings.Name = descriptor.WorldName; state.worldData = new Color[Overworld.Map.GetLength(0) * Overworld.Map.GetLength(1)]; state.CreateMesh(); Worlds.Clear(); } } catch (Exception e) { Dialog.Popup(GUI, "ERROR", "Failed to load world: " + e.Message, Dialog.ButtonType.OK); } }
public void MakeDebugWorldMenu() { GuiRoot.RootItem.Clear(); var frame = MakeMenuFrame("DEBUG WORLDS"); MakeMenuItem(frame, "Hills", "Create a hilly world.", (sender, args) => { Overworld.CreateHillsLand(Game.GraphicsDevice); StateManager.ClearState(); WorldSettings settings = new WorldSettings() { ExistingFile = null, ColonySize = new Point3(8, 1, 8), WorldScale = 2.0f, WorldOrigin = new Vector2(Overworld.Map.GetLength(0) / 2.0f, Overworld.Map.GetLength(1) / 2.0f) * 0.5f }; StateManager.PushState(new LoadState(Game, StateManager, settings)); }); MakeMenuItem(frame, "Cliffs", "Create a cliff-y world.", (sender, args) => { Overworld.CreateCliffsLand(Game.GraphicsDevice); StateManager.ClearState(); WorldSettings settings = new WorldSettings() { ExistingFile = null, ColonySize = new Point3(8, 1, 8), WorldScale = 2.0f, WorldOrigin = new Vector2(Overworld.Map.GetLength(0) / 2.0f, Overworld.Map.GetLength(1) / 2.0f) * 0.5f }; StateManager.PushState(new LoadState(Game, StateManager, settings)); }); MakeMenuItem(frame, "Flat", "Create a flat world.", (sender, args) => { Overworld.CreateUniformLand(Game.GraphicsDevice); StateManager.ClearState(); WorldSettings settings = new WorldSettings() { ExistingFile = null, ColonySize = new Point3(8, 1, 8), WorldScale = 2.0f, WorldOrigin = new Vector2(Overworld.Map.GetLength(0) / 2.0f, Overworld.Map.GetLength(1) / 2.0f) * 0.5f }; StateManager.PushState(new LoadState(Game, StateManager, settings)); }); MakeMenuItem(frame, "Ocean", "Create an ocean world", (sender, args) => { Overworld.CreateOceanLand(Game.GraphicsDevice, 0.17f); StateManager.ClearState(); WorldSettings settings = new WorldSettings() { ExistingFile = null, ColonySize = new Point3(8, 1, 8), WorldScale = 2.0f, WorldOrigin = new Vector2(Overworld.Map.GetLength(0) / 2.0f, Overworld.Map.GetLength(1) / 2.0f) * 0.5f }; StateManager.PushState(new LoadState(Game, StateManager, settings)); }); MakeMenuItem(frame, "Back", "Go back to the main menu.", (sender, args) => StateManager.PopState()); GuiRoot.RootItem.Layout(); }
public void CreateGUI() { Settings = new WorldSettings() { Width = 512, Height = 512, Name = GetRandomWorldName(), NumCivilizations = 5, NumFaults = 3, NumRains = 1000, NumVolcanoes = 3, RainfallScale = 1.0f, SeaLevel = 0.17f, TemperatureScale = 1.0f }; Input = new InputManager(); GUI = new DwarfGUI(Game, Game.Content.Load<SpriteFont>(ContentPaths.Fonts.Default), Game.Content.Load<SpriteFont>(ContentPaths.Fonts.Title), Game.Content.Load<SpriteFont>(ContentPaths.Fonts.Small), Input); MainPanel = new Panel(GUI, GUI.RootComponent) { LocalBounds = new Rectangle(128, 64, Game.GraphicsDevice.Viewport.Width - 256, Game.GraphicsDevice.Viewport.Height - 128) }; Layout = new GridLayout(GUI, MainPanel, 8, 6) { HeightSizeMode = GUIComponent.SizeMode.Fit, WidthSizeMode = GUIComponent.SizeMode.Fit }; NameLabel = new Label(GUI, Layout, "World Name: ", GUI.DefaultFont); Layout.SetComponentPosition(NameLabel, 0, 0, 1, 1); NameEdit = new LineEdit(GUI, Layout, Settings.Name); Layout.SetComponentPosition(NameEdit, 1, 0, 4, 1); NameEdit.OnTextModified += NameEdit_OnTextModified; NameRandomButton = new Button(GUI, Layout, "Random", GUI.DefaultFont, Button.ButtonMode.PushButton, null); Layout.SetComponentPosition(NameRandomButton, 5, 0, 1, 1); NameRandomButton.OnClicked += NameRandomButton_OnClicked; OptionsView = new ScrollView(GUI, Layout) { DrawBorder = true }; Layout.SetComponentPosition(OptionsView, 0, 1, 6, 6); OptionsLayout = new FormLayout(GUI, OptionsView) { WidthSizeMode = GUIComponent.SizeMode.Fit, HeightSizeMode = GUIComponent.SizeMode.Fit }; ComboBox sizeBox = CreateOptionsBox("World Size", "Size of the world to generate", OptionsLayout); sizeBox.OnSelectionModified += sizeBox_OnSelectionModified; sizeBox.InvokeSelectionModified(); ComboBox nativeBox = CreateOptionsBox("Natives", "Number of native civilizations", OptionsLayout); nativeBox.OnSelectionModified += nativeBox_OnSelectionModified; nativeBox.InvokeSelectionModified(); ComboBox faultBox = CreateOptionsBox("Faults", "Number of straights, seas, etc.", OptionsLayout); faultBox.OnSelectionModified += faultBox_OnSelectionModified; faultBox.InvokeSelectionModified(); ComboBox rainBox = CreateOptionsBox("Rainfall", "Amount of moisture in the world.", OptionsLayout); rainBox.OnSelectionModified += rainBox_OnSelectionModified; rainBox.InvokeSelectionModified(); ComboBox erosionBox = CreateOptionsBox("Erosion", "More or less eroded landscape.", OptionsLayout); erosionBox.OnSelectionModified += erosionBox_OnSelectionModified; erosionBox.InvokeSelectionModified(); ComboBox seaBox = CreateOptionsBox("Sea Level", "Height of the sea.", OptionsLayout); seaBox.OnSelectionModified += seaBox_OnSelectionModified; seaBox.InvokeSelectionModified(); ComboBox temp = CreateOptionsBox("Temperature", "Average temperature.", OptionsLayout); temp.OnSelectionModified += temp_OnSelectionModified; temp.InvokeSelectionModified(); BackButton = new Button(GUI, Layout, "Back", GUI.DefaultFont, Button.ButtonMode.ToolButton, GUI.Skin.GetSpecialFrame(GUISkin.Tile.LeftArrow)) { ToolTip = "Back to the main menu." }; Layout.SetComponentPosition(BackButton, 0, 7, 1, 1); BackButton.OnClicked += BackButton_OnClicked; AcceptButton = new Button(GUI, Layout, "Next", GUI.DefaultFont, Button.ButtonMode.ToolButton, GUI.Skin.GetSpecialFrame(GUISkin.Tile.RightArrow)) { ToolTip = "Generate a world with these settings" }; AcceptButton.OnClicked += AcceptButton_OnClicked; Layout.SetComponentPosition(AcceptButton, 5, 7, 1, 1); }