Exemple #1
0
        public WorldLoaderState(DwarfGame Game, GameStateManager StateManager) :
            base(Game, StateManager)
        {
            this.ProceedButtonText = "Load";
            this.NoItemsText       = "No worlds found.";

            this.InvalidItemText = "This world was saved by an earlier version of DwarfCorp and is not compatible.";
            this.ValidateItem    = (item) =>
            {
                return(NewOverworldFile.CheckCompatibility(item) ? "" : "Incompatible save file.");
            };
            this.GetItemName = (item) =>
            {
                return(NewOverworldFile.GetOverworldName(item));
            };

            this.ItemSource = () =>
            {
                System.IO.DirectoryInfo worldDirectory = System.IO.Directory.CreateDirectory(DwarfGame.GetWorldDirectory());
                var dirs = worldDirectory.EnumerateDirectories().ToList();
                dirs.Sort((a, b) => b.LastWriteTime.CompareTo(a.LastWriteTime));
                return(dirs);
            };

            this.ScreenshotSource = (path) =>
            {
                try
                {
                    return(AssetManager.LoadUnbuiltTextureFromAbsolutePath(path + ProgramData.DirChar + "screenshot.png"));
                }
                catch (Exception exception)
                {
                    Console.Error.WriteLine(exception.ToString());
                    return(null);
                }
            };

            this.OnProceedClicked = (path) =>
            {
                var file = new NewOverworldFile(path);
                Overworld.Map            = file.Data.CreateMap();
                Overworld.Name           = file.Data.Name;
                Overworld.NativeFactions = new List <Faction>();
                foreach (var faction in file.Data.FactionList)
                {
                    Overworld.NativeFactions.Add(new Faction(faction));
                }
                var settings = new WorldGenerationSettings();
                settings.Width  = Overworld.Map.GetLength(1);
                settings.Height = Overworld.Map.GetLength(0);
                settings.Name   = System.IO.Path.GetFileName(path);
                StateManager.PopState();
                settings.Natives = Overworld.NativeFactions;
                var genState = new WorldGeneratorState(Game, Game.StateManager, settings, false);
                StateManager.PushState(genState);
            };
        }
        public WorldLoaderState(DwarfGame Game) :
            base(Game)
        {
            this.ProceedButtonText = "Load";
            this.NoItemsText       = "No worlds found.";
            this.InvalidItemText   = "This world was saved by an earlier version of DwarfCorp and is not compatible.";

            this.ValidateItem = (item) =>
            {
                return(NewOverworldFile.CheckCompatibility(item) ? "" : "Incompatible save file.");
            };

            this.GetItemName = (item) =>
            {
                return(NewOverworldFile.GetOverworldName(item));
            };

            this.ItemSource = () =>
            {
                System.IO.DirectoryInfo worldDirectory = System.IO.Directory.CreateDirectory(DwarfGame.GetWorldDirectory());
                var dirs = worldDirectory.EnumerateDirectories().ToList();
                dirs.Sort((a, b) =>
                {
                    var aMeta = a.GetFiles("meta.txt");
                    var bMeta = b.GetFiles("meta.txt");
                    if (aMeta.Length > 0 && bMeta.Length > 0)
                    {
                        return(bMeta[0].LastWriteTime.CompareTo(aMeta[0].LastWriteTime));
                    }

                    return(b.LastWriteTime.CompareTo(a.LastWriteTime));
                });
                return(dirs);
            };

            this.ScreenshotSource = (path) =>
            {
                try
                {
                    return(AssetManager.LoadUnbuiltTextureFromAbsolutePath(path + global::System.IO.Path.DirectorySeparatorChar + "screenshot.png"));
                }
                catch (Exception exception)
                {
                    Console.Error.WriteLine(exception.ToString());
                    return(null);
                }
            };

            this.OnProceedClicked = (path) =>
            {
                var file = NewOverworldFile.Load(path);
                GameStateManager.PopState();
                var genState = new WorldGeneratorState(Game, file.CreateSettings(), WorldGeneratorState.PanelStates.Launch);
                GameStateManager.PushState(genState);
            };
        }
        public override void OnEnter()
        {
            // Clear the input queue... cause other states aren't using it and it's been filling up.
            DwarfGame.GumInputMapper.GetInputQueue();

            GuiRoot = new Gui.Root(DwarfGame.GuiSkin);
            GuiRoot.MousePointer = new MousePointer("mouse", 15.0f, 16, 17, 18, 19, 20, 21, 22, 23);

            var mainPanel = GuiRoot.RootItem.AddChild(new Gui.Widget
            {
                Rect           = GuiRoot.RenderData.VirtualScreen,
                Border         = "border-fancy",
                Text           = Settings.Name,
                Font           = "font16",
                TextColor      = new Vector4(0, 0, 0, 1),
                Padding        = new Gui.Margin(4, 4, 4, 4),
                InteriorMargin = new Gui.Margin(24, 0, 0, 0),
            });

            var rightPanel = mainPanel.AddChild(new Gui.Widget
            {
                AutoLayout  = Gui.AutoLayout.DockRight,
                MinimumSize = new Point(256, 0),
                Padding     = new Gui.Margin(2, 2, 2, 2)
            });

            rightPanel.AddChild(new Gui.Widget
            {
                Text               = "Regenerate",
                Border             = "border-button",
                ChangeColorOnHover = true,
                TextColor          = new Vector4(0, 0, 0, 1),
                Font               = "font16",
                AutoLayout         = Gui.AutoLayout.DockTop,
                OnClick            = (sender, args) => { Settings = new WorldGenerationSettings();  RestartGeneration(); }
            });

            rightPanel.AddChild(new Gui.Widget
            {
                Text               = "Save World",
                Border             = "border-button",
                ChangeColorOnHover = true,
                TextColor          = new Vector4(0, 0, 0, 1),
                Font               = "font16",
                AutoLayout         = Gui.AutoLayout.DockTop,
                OnClick            = (sender, args) =>
                {
                    if (Generator.CurrentState != WorldGenerator.GenerationState.Finished)
                    {
                        GuiRoot.ShowTooltip(GuiRoot.MousePosition, "Generator is not finished.");
                    }
                    else
                    {
                        System.IO.DirectoryInfo worldDirectory = System.IO.Directory.CreateDirectory(DwarfGame.GetWorldDirectory() + System.IO.Path.DirectorySeparatorChar + Settings.Name);
                        NewOverworldFile file = new NewOverworldFile(Game.GraphicsDevice, Overworld.Map, Settings.Name, Settings.SeaLevel);
                        file.WriteFile(worldDirectory.FullName);
                        file.SaveScreenshot(worldDirectory.FullName + System.IO.Path.DirectorySeparatorChar + "screenshot.png");
                        GuiRoot.ShowModalPopup(GuiRoot.ConstructWidget(new Gui.Widgets.Popup
                        {
                            Text = "File saved."
                        }));
                    }
                }
            });

            rightPanel.AddChild(new Gui.Widget
            {
                Text               = "Advanced",
                Border             = "border-button",
                ChangeColorOnHover = true,
                TextColor          = new Vector4(0, 0, 0, 1),
                Font               = "font16",
                AutoLayout         = Gui.AutoLayout.DockTop,
                OnClick            = (sender, args) =>
                {
                    var advancedSettingsEditor = GuiRoot.ConstructWidget(new Gui.Widgets.WorldGenerationSettingsDialog
                    {
                        Settings = Settings,
                        OnClose  = (s) =>
                        {
                            if ((s as Gui.Widgets.WorldGenerationSettingsDialog).Result == Gui.Widgets.WorldGenerationSettingsDialog.DialogResult.Okay)
                            {
                                RestartGeneration();
                            }
                        }
                    });

                    GuiRoot.ShowModalPopup(advancedSettingsEditor);
                }
            });

            rightPanel.AddChild(new Gui.Widget
            {
                Text               = "Back",
                Border             = "border-button",
                ChangeColorOnHover = true,
                TextColor          = new Vector4(0, 0, 0, 1),
                Font               = "font16",
                AutoLayout         = Gui.AutoLayout.DockTop,
                OnClick            = (sender, args) =>
                {
                    Generator.Abort();
                    StateManager.PopState();
                }
            });

            StartButton = rightPanel.AddChild(new Gui.Widget
            {
                Text               = "Start Game",
                Border             = "border-button",
                ChangeColorOnHover = true,
                TextColor          = new Vector4(0, 0, 0, 1),
                Font               = "font16",
                AutoLayout         = Gui.AutoLayout.DockBottom,
                OnClick            = (sender, args) =>
                {
                    if (Generator.CurrentState != WorldGenerator.GenerationState.Finished)
                    {
                        GuiRoot.ShowTooltip(GuiRoot.MousePosition, "World generation is not finished.");
                    }
                    else
                    {
                        Overworld.Name        = Settings.Name;
                        Settings.ExistingFile = null;
                        Settings.WorldOrigin  = Settings.WorldGenerationOrigin;
                        Settings.SpawnRect    = Generator.GetSpawnRectangle();
                        if (Settings.Natives == null || Settings.Natives.Count == 0)
                        {
                            Settings.Natives = Generator.NativeCivilizations;
                        }
                        //Settings.StartUnderground = StartUnderground.CheckState;
                        //Settings.RevealSurface = RevealSurface.CheckState;

                        foreach (var faction in Settings.Natives)
                        {
                            Vector2 center            = new Vector2(faction.Center.X, faction.Center.Y);
                            Vector2 spawn             = new Vector2(Generator.GetSpawnRectangle().Center.X, Generator.GetSpawnRectangle().Center.Y);
                            faction.DistanceToCapital = (center - spawn).Length();
                            faction.ClaimsColony      = false;
                        }

                        foreach (var faction in Generator.GetFactionsInSpawn())
                        {
                            faction.ClaimsColony = true;
                        }

                        StateManager.ClearState();
                        StateManager.PushState(new LoadState(Game, StateManager, Settings));
                    }
                }
            });

            rightPanel.AddChild(new Gui.Widget
            {
                Text       = "Territory size",
                AutoLayout = Gui.AutoLayout.DockTop,
                Font       = "font8",
                TextColor  = new Vector4(0, 0, 0, 1),
            });

            var colonySizeCombo = rightPanel.AddChild(new Gui.Widgets.ComboBox
            {
                AutoLayout             = Gui.AutoLayout.DockTop,
                Items                  = new List <string>(new string[] { "Small", "Medium", "Large" }),
                Font                   = "font8",
                TextColor              = new Vector4(0, 0, 0, 1),
                OnSelectedIndexChanged = (sender) =>
                {
                    switch ((sender as Gui.Widgets.ComboBox).SelectedItem)
                    {
                    case "Small": Settings.ColonySize = new Point3(4, 1, 4); break;

                    case "Medium": Settings.ColonySize = new Point3(8, 1, 8); break;

                    case "Large": Settings.ColonySize = new Point3(10, 1, 10); break;
                    }

                    var worldSize = Settings.ColonySize.ToVector3() * VoxelConstants.ChunkSizeX / Settings.WorldScale;

                    float w = worldSize.X;
                    float h = worldSize.Z;

                    float clickX = System.Math.Max(System.Math.Min(Settings.WorldGenerationOrigin.X, Settings.Width - w), 0);
                    float clickY = System.Math.Max(System.Math.Min(Settings.WorldGenerationOrigin.Y, Settings.Height - h), 0);

                    Settings.WorldGenerationOrigin = new Vector2((int)(clickX), (int)(clickY));
                }
            }) as Gui.Widgets.ComboBox;

            rightPanel.AddChild(new Gui.Widget
            {
                Text       = "Difficulty",
                AutoLayout = Gui.AutoLayout.DockTop,
                Font       = "font8",
                TextColor  = new Vector4(0, 0, 0, 1)
            });

            var difficultySelectorCombo = rightPanel.AddChild(new Gui.Widgets.ComboBox
            {
                AutoLayout             = Gui.AutoLayout.DockTop,
                Items                  = EmbarkmentLibrary.Embarkments.Select(e => e.Key).ToList(),
                TextColor              = new Vector4(0, 0, 0, 1),
                Font                   = "font8",
                OnSelectedIndexChanged = (sender) =>
                {
                    Settings.InitalEmbarkment = EmbarkmentLibrary.Embarkments[(sender as Gui.Widgets.ComboBox).SelectedItem];
                }
            }) as Gui.Widgets.ComboBox;

            /*
             * StartUnderground = rightPanel.AddChild(new Gui.Widgets.CheckBox
             * {
             *  AutoLayout = Gui.AutoLayout.DockTop,
             *  Font = "font8",
             *  Text = "@world-generation-start-underground"
             * }) as Gui.Widgets.CheckBox;
             *
             * RevealSurface = rightPanel.AddChild(new Gui.Widgets.CheckBox
             * {
             *  AutoLayout = Gui.AutoLayout.DockTop,
             *  Font = "font8",
             *  Text = "@world-generation-reveal-surface",
             *  CheckState = true
             * }) as Gui.Widgets.CheckBox;
             */

            rightPanel.AddChild(new Gui.Widget
            {
                Text       = "Cave Layers",
                AutoLayout = Gui.AutoLayout.DockTop,
                Font       = "font8",
                TextColor  = new Vector4(0, 0, 0, 1),
            });

            var layerSetting = rightPanel.AddChild(new Gui.Widgets.ComboBox
            {
                AutoLayout             = AutoLayout.DockTop,
                Items                  = new List <string>(new string[] { "Barely any", "Few", "Normal", "Lots", "Way too many" }),
                Font                   = "font8",
                TextColor              = new Vector4(0, 0, 0, 1),
                OnSelectedIndexChanged = (sender) =>
                {
                    switch ((sender as Gui.Widgets.ComboBox).SelectedItem)
                    {
                    case "Barely any": Settings.NumCaveLayers = 2; break;

                    case "Few": Settings.NumCaveLayers = 3; break;

                    case "Normal": Settings.NumCaveLayers = 4; break;

                    case "Lots": Settings.NumCaveLayers = 6; break;

                    case "Way too many": Settings.NumCaveLayers = 9; break;
                    }
                }
            }) as Gui.Widgets.ComboBox;

            ZoomedPreview = rightPanel.AddChild(new Gui.Widget
            {
                AutoLayout = Gui.AutoLayout.DockBottom,
                OnLayout   = (sender) =>
                {
                    var space = System.Math.Min(
                        layerSetting.Rect.Width, StartButton.Rect.Top - layerSetting.Rect.Bottom - 4);
                    sender.Rect.Height = space;
                    sender.Rect.Width  = space;
                    sender.Rect.Y      = layerSetting.Rect.Bottom + 2;
                    sender.Rect.X      = layerSetting.Rect.X +
                                         ((layerSetting.Rect.Width - space) / 2);
                }
            });

            GenerationProgress = mainPanel.AddChild(new Gui.Widgets.ProgressBar
            {
                AutoLayout          = Gui.AutoLayout.DockBottom,
                TextHorizontalAlign = Gui.HorizontalAlign.Center,
                TextVerticalAlign   = Gui.VerticalAlign.Center,
                Font      = "font10",
                TextColor = new Vector4(1, 1, 1, 1)
            }) as Gui.Widgets.ProgressBar;

            Preview = mainPanel.AddChild(new WorldGeneratorPreview(Game.GraphicsDevice)
            {
                Border     = "border-thin",
                AutoLayout = Gui.AutoLayout.DockFill
            }) as WorldGeneratorPreview;

            GuiRoot.RootItem.Layout();

            difficultySelectorCombo.SelectedIndex = difficultySelectorCombo.Items.IndexOf("Normal");
            colonySizeCombo.SelectedIndex         = colonySizeCombo.Items.IndexOf("Medium");
            layerSetting.SelectedIndex            = layerSetting.Items.IndexOf("Normal");

            IsInitialized = true;

            if (AutoGenerate)
            {
                RestartGeneration();
            }
            else // Setup a dummy generator for now.
            {
                Generator = new WorldGenerator(Settings);
                Generator.LoadDummy(
                    new Color[Overworld.Map.GetLength(0) * Overworld.Map.GetLength(1)],
                    Game.GraphicsDevice);
                Preview.SetGenerator(Generator);
            }

            base.OnEnter();
        }
Exemple #4
0
        public void MakeMenu(DirectoryInfo GameToContinue)
        {
            var frame = CreateMenu(Library.GetString("main-menu-title"));

            if (GameToContinue != null && NewOverworldFile.CheckCompatibility(GameToContinue.FullName))
            {
                CreateMenuItem(frame,
                               "Continue",
                               NewOverworldFile.GetOverworldName(GameToContinue.FullName),
                               (sender, args) => {
                    var file = NewOverworldFile.Load(GameToContinue.FullName);
                    GameStateManager.PopState();
                    var overworldSettings = file.CreateSettings();
                    overworldSettings.InstanceSettings.LoadType = LoadType.LoadFromFile;
                    GameStateManager.PushState(new LoadState(Game, overworldSettings, LoadTypes.UseExistingOverworld));
                });
            }

            CreateMenuItem(frame,
                           Library.GetString("new-game"),
                           Library.GetString("new-game-tooltip"),
                           (sender, args) => GameStateManager.PushState(new WorldGeneratorState(Game, Overworld.Create(), WorldGeneratorState.PanelStates.Generate)));

            CreateMenuItem(frame,
                           Library.GetString("load-game"),
                           Library.GetString("load-game-tooltip"),
                           (sender, args) => GameStateManager.PushState(new WorldLoaderState(Game)));

            CreateMenuItem(frame,
                           Library.GetString("options"),
                           Library.GetString("options-tooltip"),
                           (sender, args) => GameStateManager.PushState(new OptionsState(Game)));

            CreateMenuItem(frame,
                           Library.GetString("manage-mods"),
                           Library.GetString("manage-mods-tooltip"),
                           (sender, args) => GameStateManager.PushState(new ModManagement.ManageModsState(Game)));

            CreateMenuItem(frame,
                           Library.GetString("credits"),
                           Library.GetString("credits-tooltip"),
                           (sender, args) => GameStateManager.PushState(new CreditsState(GameState.Game)));

            CreateMenuItem(frame, "QUICKPLAY", "",
                           (sender, args) =>
            {
                DwarfGame.LogSentryBreadcrumb("Menu", "User generating a random world.");

                var overworldSettings = Overworld.Create();
                overworldSettings.InstanceSettings.InitalEmbarkment       = new Embarkment(overworldSettings);
                overworldSettings.InstanceSettings.InitalEmbarkment.Funds = 1000u;
                overworldSettings.InstanceSettings.InitalEmbarkment.Employees.Add(Applicant.Random("Crafter", overworldSettings.Company));
                overworldSettings.InstanceSettings.InitalEmbarkment.Employees.Add(Applicant.Random("Manager", overworldSettings.Company));
                overworldSettings.InstanceSettings.InitalEmbarkment.Employees.Add(Applicant.Random("Miner", overworldSettings.Company));
                overworldSettings.InstanceSettings.InitalEmbarkment.Employees.Add(Applicant.Random("Wizard", overworldSettings.Company));
                overworldSettings.InstanceSettings.InitalEmbarkment.Employees.Add(Applicant.Random("Soldier", overworldSettings.Company));
                overworldSettings.InstanceSettings.InitalEmbarkment.Employees.Add(Applicant.Random("Musketeer", overworldSettings.Company));

                GameStateManager.PushState(new LoadState(Game, overworldSettings, LoadTypes.GenerateOverworld));
            });

            CreateMenuItem(frame, "GIANT QUICKPLAY", "",
                           (sender, args) =>
            {
                GameStateManager.PushState(new CheckMegaWorldState(Game));
            });

            CreateMenuItem(frame, "Dwarf Designer", "Open the dwarf designer.",
                           (sender, args) =>
            {
                GameStateManager.PushState(new Debug.DwarfDesignerState(GameState.Game));
            });

#if DEBUG
            CreateMenuItem(frame, "Yarn test", "", (sender, args) =>
            {
                GameStateManager.PushState(new YarnState(null, "test.conv", "Start", new Yarn.MemoryVariableStore()));
            });

            CreateMenuItem(frame, "Debug GUI", "", (sender, args) =>
            {
                GameStateManager.PushState(new Debug.GuiDebugState(GameState.Game));
            });
#endif

            CreateMenuItem(frame,
                           Library.GetString("quit"),
                           Library.GetString("quit-tooltip"),
                           (sender, args) => Game.Exit());

            FinishMenu();
        }
        public override void OnEnter()
        {
            // Clear the input queue... cause other states aren't using it and it's been filling up.
            DwarfGame.GumInputMapper.GetInputQueue();

            GuiRoot = new Gui.Root(DwarfGame.GumSkin);
            GuiRoot.MousePointer = new MousePointer("mouse", 15.0f, 16, 17, 18, 19, 20, 21, 22, 23);

            var mainPanel = GuiRoot.RootItem.AddChild(new Gui.Widget
            {
                Rect           = GuiRoot.RenderData.VirtualScreen,
                Border         = "border-fancy",
                Text           = Settings.Name,
                Font           = "font16",
                TextColor      = new Vector4(0, 0, 0, 1),
                Padding        = new Gui.Margin(4, 4, 4, 4),
                InteriorMargin = new Gui.Margin(24, 0, 0, 0),
            });

            var rightPanel = mainPanel.AddChild(new Gui.Widget
            {
                AutoLayout  = Gui.AutoLayout.DockRight,
                MinimumSize = new Point(256, 0),
                Padding     = new Gui.Margin(2, 2, 2, 2)
            });

            rightPanel.AddChild(new Gui.Widget
            {
                Text               = "Regenerate",
                Border             = "border-button",
                ChangeColorOnHover = true,
                TextColor          = new Vector4(0, 0, 0, 1),
                Font               = "font16",
                AutoLayout         = Gui.AutoLayout.DockTop,
                OnClick            = (sender, args) => { Settings = new WorldGenerationSettings();  RestartGeneration(); }
            });

            rightPanel.AddChild(new Gui.Widget
            {
                Text               = "Save World",
                Border             = "border-button",
                ChangeColorOnHover = true,
                TextColor          = new Vector4(0, 0, 0, 1),
                Font               = "font16",
                AutoLayout         = Gui.AutoLayout.DockTop,
                OnClick            = (sender, args) =>
                {
                    if (Generator.CurrentState != WorldGenerator.GenerationState.Finished)
                    {
                        GuiRoot.ShowTooltip(GuiRoot.MousePosition, "Generator is not finished.");
                    }
                    else
                    {
                        System.IO.DirectoryInfo worldDirectory = System.IO.Directory.CreateDirectory(DwarfGame.GetWorldDirectory() + ProgramData.DirChar + Settings.Name);
                        NewOverworldFile file = new NewOverworldFile(Game.GraphicsDevice, Overworld.Map, Settings.Name, Settings.SeaLevel);
                        file.WriteFile(worldDirectory.FullName);
                        file.SaveScreenshot(worldDirectory.FullName + ProgramData.DirChar + "screenshot.png");
                        GuiRoot.ShowModalPopup(GuiRoot.ConstructWidget(new Gui.Widgets.Popup
                        {
                            Text = "File saved."
                        }));
                    }
                }
            });

            rightPanel.AddChild(new Gui.Widget
            {
                Text               = "Advanced",
                Border             = "border-button",
                ChangeColorOnHover = true,
                TextColor          = new Vector4(0, 0, 0, 1),
                Font               = "font16",
                AutoLayout         = Gui.AutoLayout.DockTop,
                OnClick            = (sender, args) =>
                {
                    var advancedSettingsEditor = GuiRoot.ConstructWidget(new Gui.Widgets.WorldGenerationSettingsDialog
                    {
                        Settings = Settings,
                        OnClose  = (s) => RestartGeneration()
                    });

                    GuiRoot.ShowModalPopup(advancedSettingsEditor);
                }
            });

            rightPanel.AddChild(new Gui.Widget
            {
                Text               = "Back",
                Border             = "border-button",
                ChangeColorOnHover = true,
                TextColor          = new Vector4(0, 0, 0, 1),
                Font               = "font16",
                AutoLayout         = Gui.AutoLayout.DockTop,
                OnClick            = (sender, args) =>
                {
                    Generator.Abort();
                    StateManager.PopState();
                }
            });

            StartButton = rightPanel.AddChild(new Gui.Widget
            {
                Text               = "Start Game",
                Border             = "border-button",
                ChangeColorOnHover = true,
                TextColor          = new Vector4(0, 0, 0, 1),
                Font               = "font16",
                AutoLayout         = Gui.AutoLayout.DockBottom,
                OnClick            = (sender, args) =>
                {
                    if (Generator.CurrentState != WorldGenerator.GenerationState.Finished)
                    {
                        GuiRoot.ShowTooltip(GuiRoot.MousePosition, "World generation is not finished.");
                    }
                    else
                    {
                        Overworld.Name        = Settings.Name;
                        Settings.ExistingFile = null;
                        Settings.WorldOrigin  = Settings.WorldGenerationOrigin;
                        if (Settings.Natives == null || Settings.Natives.Count == 0)
                        {
                            Settings.Natives = Generator.NativeCivilizations;
                        }

                        StateManager.ClearState();
                        StateManager.PushState(new LoadState(Game, StateManager, Settings));
                    }
                }
            });

            rightPanel.AddChild(new Gui.Widget
            {
                Text       = "Colony size",
                AutoLayout = Gui.AutoLayout.DockTop,
                Font       = "font8",
                TextColor  = new Vector4(0, 0, 0, 1)
            });

            var colonySizeCombo = rightPanel.AddChild(new Gui.Widgets.ComboBox
            {
                AutoLayout             = Gui.AutoLayout.DockTop,
                Items                  = new List <string>(new string[] { "Small", "Medium", "Large" }),
                Font                   = "font8",
                TextColor              = new Vector4(0, 0, 0, 1),
                OnSelectedIndexChanged = (sender) =>
                {
                    switch ((sender as Gui.Widgets.ComboBox).SelectedItem)
                    {
                    case "Small": Settings.ColonySize = new Point3(4, 1, 4); break;

                    case "Medium": Settings.ColonySize = new Point3(8, 1, 8); break;

                    case "Large": Settings.ColonySize = new Point3(10, 1, 10); break;
                    }

                    var worldSize = Settings.ColonySize.ToVector3() * VoxelConstants.ChunkSizeX / Settings.WorldScale;

                    float w = worldSize.X / 2;
                    float h = worldSize.Z / 2;

                    float clickX = System.Math.Max(System.Math.Min(Settings.WorldGenerationOrigin.X, Settings.Width - w), w);
                    float clickY = System.Math.Max(System.Math.Min(Settings.WorldGenerationOrigin.Y, Settings.Height - h), h);

                    Settings.WorldGenerationOrigin = new Vector2((int)(clickX), (int)(clickY));
                }
            }) as Gui.Widgets.ComboBox;

            rightPanel.AddChild(new Gui.Widget
            {
                Text       = "Difficulty",
                AutoLayout = Gui.AutoLayout.DockTop,
                Font       = "font8",
                TextColor  = new Vector4(0, 0, 0, 1)
            });

            var difficultySelectorCombo = rightPanel.AddChild(new Gui.Widgets.ComboBox
            {
                AutoLayout             = Gui.AutoLayout.DockTop,
                Items                  = Embarkment.EmbarkmentLibrary.Select(e => e.Key).ToList(),
                TextColor              = new Vector4(0, 0, 0, 1),
                Font                   = "font8",
                OnSelectedIndexChanged = (sender) =>
                {
                    Settings.InitalEmbarkment = Embarkment.EmbarkmentLibrary[(sender as Gui.Widgets.ComboBox).SelectedItem];
                }
            }) as Gui.Widgets.ComboBox;

            ZoomedPreview = rightPanel.AddChild(new Gui.Widget
            {
                AutoLayout = Gui.AutoLayout.DockBottom,
                OnLayout   = (sender) =>
                {
                    var space = System.Math.Min(
                        difficultySelectorCombo.Rect.Width, StartButton.Rect.Top - difficultySelectorCombo.Rect.Bottom - 4);
                    sender.Rect.Height = space;
                    sender.Rect.Width  = space;
                    sender.Rect.Y      = difficultySelectorCombo.Rect.Bottom + 2;
                    sender.Rect.X      = difficultySelectorCombo.Rect.X +
                                         ((difficultySelectorCombo.Rect.Width - space) / 2);
                }
            });


            StatsLabel = rightPanel.AddChild(new Gui.Widget()
            {
                AutoLayout          = Gui.AutoLayout.DockBottom,
                Font                = "font8",
                TextColor           = new Vector4(1, 1, 1, 1),
                Background          = new TileReference("sbasic", 0),
                BackgroundColor     = new Vector4(0.0f, 0.0f, 0.0f, 0.2f),
                TextHorizontalAlign = HorizontalAlign.Left,
                MinimumSize         = new Point(128, 64),
                WrapText            = true,
                Padding             = new Margin(10, 10, 10, 0)
            });

            GenerationProgress = mainPanel.AddChild(new Gui.Widgets.ProgressBar
            {
                AutoLayout          = Gui.AutoLayout.DockBottom,
                TextHorizontalAlign = Gui.HorizontalAlign.Center,
                TextVerticalAlign   = Gui.VerticalAlign.Center,
                Font      = "font10",
                TextColor = new Vector4(1, 1, 1, 1)
            }) as Gui.Widgets.ProgressBar;

            Preview = mainPanel.AddChild(new WorldGeneratorPreview(Game.GraphicsDevice)
            {
                Border     = "border-thin",
                AutoLayout = Gui.AutoLayout.DockFill
            }) as WorldGeneratorPreview;

            GuiRoot.RootItem.Layout();
            Preview.PreviewPanel.OnClick += (widget, args) =>
            {
                StatsLabel.Text = Generator.GetSpawnStats();

                StatsLabel.Invalidate();
            };

            difficultySelectorCombo.SelectedIndex = difficultySelectorCombo.Items.IndexOf("Normal");
            colonySizeCombo.SelectedIndex         = colonySizeCombo.Items.IndexOf("Medium");

            IsInitialized = true;

            if (AutoGenerate)
            {
                RestartGeneration();
            }
            else // Setup a dummy generator for now.
            {
                Generator = new WorldGenerator(Settings);
                Generator.LoadDummy(
                    new Color[Overworld.Map.GetLength(0) * Overworld.Map.GetLength(1)],
                    Game.GraphicsDevice);
                Preview.SetGenerator(Generator);
            }

            base.OnEnter();
        }
Exemple #6
0
        public override void Construct()
        {
            Padding = new Margin(2, 2, 0, 0);

            AddChild(new Gui.Widget
            {
                Text               = "Randomize",
                Border             = "border-button",
                ChangeColorOnHover = true,
                TextColor          = new Vector4(0, 0, 0, 1),
                Font               = "font16",
                AutoLayout         = Gui.AutoLayout.DockTop,
                OnClick            = (sender, args) => {
                    DwarfGame.LogSentryBreadcrumb("WorldGenerator", "User is regenerating the world.");
                    Settings.Seed = MathFunctions.RandInt(Int32.MinValue, Int32.MaxValue);
                    Settings.Name = Overworld.GetRandomWorldName();
                    RestartGeneration();
                }
            });

            AddChild(new Gui.Widget
            {
                Text               = "Save World",
                Border             = "border-button",
                ChangeColorOnHover = true,
                TextColor          = new Vector4(0, 0, 0, 1),
                Font               = "font16",
                AutoLayout         = Gui.AutoLayout.DockTop,
                OnClick            = (sender, args) =>
                {
                    DwarfGame.LogSentryBreadcrumb("WorldGenerator", "User is saving the world.");
                    if (Generator.CurrentState != OverworldGenerator.GenerationState.Finished)
                    {
                        Root.ShowTooltip(Root.MousePosition, "Generator is not finished.");
                    }
                    else
                    {
                        global::System.IO.DirectoryInfo worldDirectory = global::System.IO.Directory.CreateDirectory(DwarfGame.GetWorldDirectory() + global::System.IO.Path.DirectorySeparatorChar + Settings.Name);
                        var file = new NewOverworldFile(Game.GraphicsDevice, Settings);
                        file.WriteFile(worldDirectory.FullName);
                        Root.ShowModalPopup(Root.ConstructWidget(new Gui.Widgets.Popup
                        {
                            Text = "File saved."
                        }));
                    }
                }
            });

            AddChild(new Gui.Widget
            {
                Text               = "Advanced",
                Border             = "border-button",
                ChangeColorOnHover = true,
                TextColor          = new Vector4(0, 0, 0, 1),
                Font               = "font16",
                AutoLayout         = Gui.AutoLayout.DockTop,
                OnClick            = (sender, args) =>
                {
                    DwarfGame.LogSentryBreadcrumb("WorldGenerator", "User is modifying advanced settings.");
                    var advancedSettingsEditor = Root.ConstructWidget(new Gui.Widgets.WorldGenerationSettingsDialog
                    {
                        Settings = Settings,
                        OnClose  = (s) =>
                        {
                            if ((s as Gui.Widgets.WorldGenerationSettingsDialog).Result == Gui.Widgets.WorldGenerationSettingsDialog.DialogResult.Okay)
                            {
                                RestartGeneration();
                            }
                        }
                    });

                    Root.ShowModalPopup(advancedSettingsEditor);
                }
            });

            StartButton = AddChild(new Gui.Widget
            {
                Text               = "Launch",
                Border             = "border-button",
                ChangeColorOnHover = true,
                TextColor          = new Vector4(0, 0, 0, 1),
                Font               = "font16",
                AutoLayout         = Gui.AutoLayout.DockBottom,
                OnClick            = (sender, args) =>
                {
                    Settings.Company.Name  = NameField.Text;
                    Settings.Company.Motto = MottoField.Text;
                    Settings.InstanceSettings.InitalEmbarkment = new Embarkment();
                    Settings.PlayerCorporationFunds            = 1000;
                    Settings.Natives.FirstOrDefault(n => n.Name == "Player").PrimaryColor = new Color(Settings.Company.LogoBackgroundColor);

                    OnVerified?.Invoke();
                }
            });

            AddChild(new Gui.Widget
            {
                Text       = "Difficulty",
                AutoLayout = Gui.AutoLayout.DockTop,
                Font       = "font8",
                TextColor  = new Vector4(0, 0, 0, 1)
            });

            var difficultySelectorCombo = AddChild(new Gui.Widgets.ComboBox
            {
                AutoLayout             = Gui.AutoLayout.DockTop,
                Items                  = Library.EnumerateDifficulties().Select(e => e.Name).ToList(),
                TextColor              = new Vector4(0, 0, 0, 1),
                Font                   = "font8",
                OnSelectedIndexChanged = (sender) =>
                {
                    Settings.Difficulty = Library.GetDifficulty((sender as Gui.Widgets.ComboBox).SelectedItem);
                }
            }) as Gui.Widgets.ComboBox;

            AddChild(new Gui.Widget
            {
                Text       = "Caves",
                AutoLayout = Gui.AutoLayout.DockTop,
                Font       = "font8",
                TextColor  = new Vector4(0, 0, 0, 1),
            });

            var layerSetting = AddChild(new Gui.Widgets.ComboBox
            {
                AutoLayout             = AutoLayout.DockTop,
                Items                  = new List <string>(new string[] { "Barely any", "Few", "Normal", "Lots", "Way too many" }),
                Font                   = "font8",
                TextColor              = new Vector4(0, 0, 0, 1),
                OnSelectedIndexChanged = (sender) =>
                {
                    switch ((sender as Gui.Widgets.ComboBox).SelectedItem)
                    {
                    case "Barely any": Settings.NumCaveLayers = 2; break;

                    case "Few": Settings.NumCaveLayers = 3; break;

                    case "Normal": Settings.NumCaveLayers = 4; break;

                    case "Lots": Settings.NumCaveLayers = 6; break;

                    case "Way too many": Settings.NumCaveLayers = 9; break;
                    }
                }
            }) as Gui.Widgets.ComboBox;

            AddChild(new Gui.Widget
            {
                Text       = "Z Levels",
                AutoLayout = Gui.AutoLayout.DockTop,
                Font       = "font8",
                TextColor  = new Vector4(0, 0, 0, 1),
            });

            var zLevelSetting = AddChild(new Gui.Widgets.ComboBox
            {
                AutoLayout             = AutoLayout.DockTop,
                Items                  = new List <string>(new string[] { "16", "64", "128" }),
                Font                   = "font8",
                TextColor              = new Vector4(0, 0, 0, 1),
                OnSelectedIndexChanged = (sender) =>
                {
                    switch ((sender as Gui.Widgets.ComboBox).SelectedItem)
                    {
                    case "16": Settings.zLevels = 1; break;

                    case "64": Settings.zLevels = 4; break;

                    case "128": Settings.zLevels = 8; break;
                    }
                }
            }) as Gui.Widgets.ComboBox;

            zLevelSetting.SelectedIndex           = 1;
            difficultySelectorCombo.SelectedIndex = difficultySelectorCombo.Items.IndexOf("Normal");
            layerSetting.SelectedIndex            = layerSetting.Items.IndexOf("Normal");

            #region Name

            AddChild(new Gui.Widget
            {
                MinimumSize         = new Point(64, 0),
                Text                = "Company Name",
                Font                = "font8",
                AutoLayout          = AutoLayout.DockTop,
                TextHorizontalAlign = HorizontalAlign.Left,
                TextVerticalAlign   = VerticalAlign.Center
            });

            var nameRow = AddChild(new Widget
            {
                MinimumSize = new Point(0, 32),
                AutoLayout  = AutoLayout.DockTop,
                Padding     = new Margin(0, 0, 2, 2)
            });

            nameRow.AddChild(new Gui.Widgets.Button
            {
                Text       = "?",
                AutoLayout = AutoLayout.DockRight,
                Border     = "border-button",
                OnClick    = (sender, args) =>
                {
                    var templates  = TextGenerator.GetAtoms(ContentPaths.Text.Templates.company);
                    NameField.Text = TextGenerator.GenerateRandom(Datastructures.SelectRandom(templates).ToArray());
                }
            });

            NameField = nameRow.AddChild(new Gui.Widgets.EditableTextField
            {
                Text       = Settings.Company.Name,
                AutoLayout = AutoLayout.DockFill
            }) as Gui.Widgets.EditableTextField;
            #endregion

            #region Motto

            AddChild(new Widget
            {
                MinimumSize         = new Point(64, 0),
                Text                = "Company Motto",
                Font                = "font8",
                AutoLayout          = AutoLayout.DockTop,
                TextHorizontalAlign = HorizontalAlign.Left,
                TextVerticalAlign   = VerticalAlign.Center
            });

            var mottoRow = AddChild(new Widget
            {
                MinimumSize = new Point(0, 32),
                AutoLayout  = AutoLayout.DockTop,
                Padding     = new Margin(0, 0, 2, 2)
            });

            mottoRow.AddChild(new Gui.Widgets.Button
            {
                Text       = "?",
                AutoLayout = AutoLayout.DockRight,
                Border     = "border-button",
                OnClick    = (sender, args) =>
                {
                    var templates   = TextGenerator.GetAtoms(ContentPaths.Text.Templates.mottos);
                    MottoField.Text = TextGenerator.GenerateRandom(Datastructures.SelectRandom(templates).ToArray());
                    // Todo: Doesn't automatically invalidate when text changed??
                    MottoField.Invalidate();
                }
            });

            MottoField = mottoRow.AddChild(new Gui.Widgets.EditableTextField
            {
                Text       = Settings.Company.Motto,
                AutoLayout = AutoLayout.DockFill
            }) as Gui.Widgets.EditableTextField;
            #endregion

            #region Logo

            AddChild(new Widget
            {
                MinimumSize         = new Point(64, 0),
                Text                = "Company Logo",
                Font                = "font8",
                AutoLayout          = AutoLayout.DockTop,
                TextHorizontalAlign = HorizontalAlign.Left,
                TextVerticalAlign   = VerticalAlign.Center
            });

            var logoRow = AddChild(new Widget
            {
                MinimumSize = new Point(0, 64),
                AutoLayout  = AutoLayout.DockTop,
                Padding     = new Margin(0, 0, 2, 2)
            });

            CompanyLogoDisplay = logoRow.AddChild(new Gui.Widgets.CompanyLogo
            {
                AutoLayout         = AutoLayout.DockLeft,
                MinimumSize        = new Point(64, 64),
                MaximumSize        = new Point(64, 64),
                CompanyInformation = Settings.Company
            }) as Gui.Widgets.CompanyLogo;

            var rightBox = logoRow.AddChild(new Widget
            {
                AutoLayout = AutoLayout.DockFill
            });

            var bgBox = rightBox.AddChild(new Widget
            {
                AutoLayout  = AutoLayout.DockTop,
                MinimumSize = new Point(32, 32),
            });

            bgBox.AddChild(new Widget
            {
                Text       = "BG:",
                AutoLayout = AutoLayout.DockLeft
            });

            bgBox.AddChild(new Widget
            {
                Background  = Settings.Company.LogoBackground,
                MinimumSize = new Point(32, 32),
                MaximumSize = new Point(32, 32),
                AutoLayout  = AutoLayout.DockLeft,
                OnClick     = (sender, args) =>
                {
                    var source  = Root.GetTileSheet("company-logo-background") as Gui.TileSheet;
                    var chooser = new Gui.Widgets.GridChooser
                    {
                        ItemSource = Enumerable.Range(0, source.Columns * source.Rows)
                                     .Select(i => new Widget
                        {
                            Background = new TileReference("company-logo-background", i)
                        }),
                        OnClose = (s2) =>
                        {
                            var gc = s2 as Gui.Widgets.GridChooser;
                            if (gc.DialogResult == Gui.Widgets.GridChooser.Result.OKAY &&
                                gc.SelectedItem != null)
                            {
                                sender.Background = gc.SelectedItem.Background;
                                sender.Invalidate();
                                Settings.Company.LogoBackground = gc.SelectedItem.Background;
                                CompanyLogoDisplay.Invalidate();
                            }
                        },
                        PopupDestructionType = PopupDestructionType.DestroyOnOffClick
                    };
                    Root.ShowModalPopup(chooser);
                }
            });

            bgBox.AddChild(new Widget
            {
                Background      = new TileReference("basic", 1),
                BackgroundColor = Settings.Company.LogoBackgroundColor,
                MinimumSize     = new Point(32, 32),
                MaximumSize     = new Point(32, 32),
                AutoLayout      = AutoLayout.DockLeft,
                OnClick         = (sender, args) =>
                {
                    var chooser = new Gui.Widgets.GridChooser
                    {
                        ItemSize    = new Point(16, 16),
                        ItemSpacing = new Point(4, 4),
                        ItemSource  = EnumerateDefaultColors()
                                      .Select(c => new Widget
                        {
                            Background      = new TileReference("basic", 1),
                            BackgroundColor = new Vector4(c.ToVector3(), 1),
                        }),
                        OnClose = (s2) =>
                        {
                            var gc = s2 as Gui.Widgets.GridChooser;
                            if (gc.DialogResult == Gui.Widgets.GridChooser.Result.OKAY &&
                                gc.SelectedItem != null)
                            {
                                sender.BackgroundColor = gc.SelectedItem.BackgroundColor;
                                sender.Invalidate();
                                Settings.Company.LogoBackgroundColor = gc.SelectedItem.BackgroundColor;
                                CompanyLogoDisplay.Invalidate();
                            }
                        },
                        PopupDestructionType = PopupDestructionType.DestroyOnOffClick
                    };
                    Root.ShowModalPopup(chooser);
                }
            });

            var fgBox = rightBox.AddChild(new Widget
            {
                AutoLayout  = AutoLayout.DockFill,
                MinimumSize = new Point(32, 32),
            });

            fgBox.AddChild(new Widget
            {
                Text       = "FG:",
                AutoLayout = AutoLayout.DockLeft
            });

            fgBox.AddChild(new Widget
            {
                Background  = Settings.Company.LogoSymbol,
                MinimumSize = new Point(32, 32),
                MaximumSize = new Point(32, 32),
                AutoLayout  = AutoLayout.DockLeft,
                OnClick     = (sender, args) =>
                {
                    var source  = Root.GetTileSheet("company-logo-symbol") as Gui.TileSheet;
                    var chooser = new Gui.Widgets.GridChooser
                    {
                        ItemSource = Enumerable.Range(0, source.Columns * source.Rows)
                                     .Select(i => new Widget
                        {
                            Background = new TileReference("company-logo-symbol", i)
                        }),
                        OnClose = (s2) =>
                        {
                            var gc = s2 as Gui.Widgets.GridChooser;
                            if (gc.DialogResult == Gui.Widgets.GridChooser.Result.OKAY &&
                                gc.SelectedItem != null)
                            {
                                sender.Background = gc.SelectedItem.Background;
                                sender.Invalidate();
                                Settings.Company.LogoSymbol = gc.SelectedItem.Background;
                                CompanyLogoDisplay.Invalidate();
                            }
                        },
                        PopupDestructionType = PopupDestructionType.DestroyOnOffClick
                    };
                    Root.ShowModalPopup(chooser);
                }
            });

            fgBox.AddChild(new Widget
            {
                Background      = new TileReference("basic", 1),
                BackgroundColor = Settings.Company.LogoSymbolColor,
                MinimumSize     = new Point(32, 32),
                MaximumSize     = new Point(32, 32),
                AutoLayout      = AutoLayout.DockLeft,
                OnClick         = (sender, args) =>
                {
                    var chooser = new Gui.Widgets.GridChooser
                    {
                        ItemSize    = new Point(16, 16),
                        ItemSpacing = new Point(4, 4),
                        ItemSource  = EnumerateDefaultColors()
                                      .Select(c => new Widget
                        {
                            Background      = new TileReference("basic", 1),
                            BackgroundColor = new Vector4(c.ToVector3(), 1),
                        }),
                        OnClose = (s2) =>
                        {
                            var gc = s2 as Gui.Widgets.GridChooser;
                            if (gc.DialogResult == Gui.Widgets.GridChooser.Result.OKAY &&
                                gc.SelectedItem != null)
                            {
                                sender.BackgroundColor = gc.SelectedItem.BackgroundColor;
                                sender.Invalidate();
                                Settings.Company.LogoSymbolColor = gc.SelectedItem.BackgroundColor;
                                CompanyLogoDisplay.Invalidate();
                            }
                        },
                        PopupDestructionType = PopupDestructionType.DestroyOnOffClick
                    };
                    Root.ShowModalPopup(chooser);
                }
            });


            #endregion


            base.Construct();
        }