Esempio n. 1
0
 public WorldGeneratorState(DwarfGame Game, GameStateManager StateManager, WorldGenerationSettings Settings, bool AutoGenerate) :
     base(Game, "NewWorldGeneratorState", StateManager)
 {
     this.AutoGenerate = AutoGenerate;
     this.Settings     = Settings;
     if (this.Settings == null)
     {
         this.Settings = new WorldGenerationSettings()
         {
             Width            = 512,
             Height           = 512,
             Name             = TextGenerator.GenerateRandom(TextGenerator.GetAtoms(ContentPaths.Text.Templates.worlds)),
             NumCivilizations = 5,
             NumFaults        = 3,
             NumRains         = 1000,
             NumVolcanoes     = 3,
             RainfallScale    = 1.0f,
             SeaLevel         = 0.17f,
             TemperatureScale = 1.0f
         }
     }
     ;
 }
Esempio n. 2
0
        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 Gui.MousePointer("mouse", 4, 0);
            GuiRoot.RootItem.Font = "font8";

            int w = System.Math.Min(GuiRoot.RenderData.VirtualScreen.Width - 256, 550);
            int h = System.Math.Min(GuiRoot.RenderData.VirtualScreen.Height - 256, 300);
            int x = GuiRoot.RenderData.VirtualScreen.Width / 2 - w / 2;
            int y = System.Math.Max(GuiRoot.RenderData.VirtualScreen.Height / 2 - h / 2, 280);

            int bgx = x - 258;
            int bgy = y - 128;

            DialogueContext.SpeechBubble = GuiRoot.RootItem.AddChild(new Gui.Widget
            {
                Rect      = new Rectangle(bgx + 258, bgy, w + 50, 128),
                Border    = "speech-bubble-reverse",
                Font      = "font16",
                TextColor = Color.Black.ToVector4()
            });

            var bg = GuiRoot.RootItem.AddChild(new Widget()
            {
                Border = "border-dark",
                Rect   = new Rectangle(bgx, bgy, 258, 258)
            });


            DialogueContext.ChoicePanel = GuiRoot.RootItem.AddChild(new Gui.Widget
            {
                Rect       = new Rectangle(x, y, w, h),
                Border     = "border-fancy",
                AutoLayout = AutoLayout.DockFill
            });

            SpeakerAnimation                 = AnimationLibrary.CreateAnimation(DialogueContext.Envoy.OwnerFaction.Race.TalkAnimation);
            SpeakerAnimationPlayer           = new AnimationPlayer(SpeakerAnimation);
            DialogueContext.SpeakerAnimation = SpeakerAnimationPlayer;


            SpeakerWidget = bg.AddChild(new Widget()
            {
                Background  = new TileReference(SpeakerAnimation.SpriteSheet.AssetName, 0),
                AutoLayout  = AutoLayout.DockFill,
                MinimumSize = new Point(256, 256),
                Rect        = new Rectangle(bgx, bgy - 5, 256, 256)
            });

            DialogueContext.Politics = World.Diplomacy.GetPolitics(
                DialogueContext.PlayerFaction, DialogueContext.Envoy.OwnerFaction);
            DialogueContext.World = World;

            if (!DialogueContext.Politics.HasMet)
            {
                DialogueContext.Politics.HasMet = true;

                DialogueContext.Politics.RecentEvents.Add(new Diplomacy.PoliticalEvent()
                {
                    Change      = 0.0f,
                    Description = "we just met",
                    Duration    = new TimeSpan(1, 0, 0, 0),
                    Time        = World.Time.CurrentDate
                });
            }

            DialogueContext.EnvoyName = TextGenerator.GenerateRandom(Datastructures.SelectRandom(DialogueContext.Envoy.OwnerFaction.Race.NameTemplates).ToArray());

            DialogueContext.Transition(DialogueTree.ConversationRoot);

            IsInitialized = true;
            base.OnEnter();
        }
Esempio n. 3
0
 public static string GetRandomWorldName()
 {
     return(TextGenerator.GenerateRandom(TextGenerator.GetAtoms(ContentPaths.Text.Templates.worlds)));
 }
Esempio n. 4
0
        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 Gui.MousePointer("mouse", 4, 0);

            Rectangle rect = GuiRoot.RenderData.VirtualScreen;

            rect.Inflate(-rect.Width / 3, -rect.Height / 3);
            var mainPanel = GuiRoot.RootItem.AddChild(new Gui.Widget
            {
                Rect           = rect,
                MinimumSize    = new Point(512, 256),
                AutoLayout     = AutoLayout.FloatCenter,
                Border         = "border-fancy",
                Padding        = new Margin(4, 4, 4, 4),
                InteriorMargin = new Margin(2, 0, 0, 0),
                TextSize       = 1,
                Font           = "font10"
            });

            mainPanel.AddChild(new Gui.Widgets.Button
            {
                Text = "Create!",
                Font = "font16",
                TextHorizontalAlign = HorizontalAlign.Center,
                TextVerticalAlign   = VerticalAlign.Center,
                Border  = "border-button",
                OnClick = (sender, args) =>
                {
                    // Grab string values from widgets!
                    CompanyInformation.Name  = NameField.Text;
                    CompanyInformation.Motto = MottoField.Text;

                    // Why are they stored as statics on this class???
                    StateManager.PushState(new NewGameChooseWorldState(Game, Game.StateManager));
                },
                AutoLayout = AutoLayout.FloatBottomRight
            });

            mainPanel.AddChild(new Gui.Widgets.Button
            {
                Text = "< Back",
                TextHorizontalAlign = HorizontalAlign.Center,
                TextVerticalAlign   = VerticalAlign.Center,
                Border  = "border-button",
                Font    = "font16",
                OnClick = (sender, args) =>
                {
                    StateManager.PopState();
                },
                AutoLayout = AutoLayout.FloatBottomLeft,
            });

            #region Name

            mainPanel.AddChild(new Widget()
            {
                Text       = "Create a Company",
                Font       = "font16",
                AutoLayout = AutoLayout.DockTop,
            });

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

            nameRow.AddChild(new Gui.Widget
            {
                MinimumSize         = new Point(64, 0),
                Text                = "Name",
                AutoLayout          = AutoLayout.DockLeft,
                TextHorizontalAlign = HorizontalAlign.Right,
                TextVerticalAlign   = VerticalAlign.Center
            });

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

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

            #region Motto
            var mottoRow = mainPanel.AddChild(new Widget
            {
                MinimumSize = new Point(0, 24),
                AutoLayout  = AutoLayout.DockTop,
                Padding     = new Margin(0, 0, 2, 2)
            });

            mottoRow.AddChild(new Widget
            {
                MinimumSize         = new Point(64, 0),
                Text                = "Motto",
                AutoLayout          = AutoLayout.DockLeft,
                TextHorizontalAlign = HorizontalAlign.Right,
                TextVerticalAlign   = VerticalAlign.Center
            });

            mottoRow.AddChild(new Button
            {
                Text       = "Randomize",
                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 EditableTextField
            {
                Text       = CompanyInformation.Motto,
                AutoLayout = AutoLayout.DockFill
            }) as EditableTextField;
            #endregion

            #region Logo

            var logoRow = mainPanel.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 = CompanyInformation
            }) as Gui.Widgets.CompanyLogo;

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

            logoRow.AddChild(new Widget
            {
                Background  = CompanyInformation.LogoBackground,
                MinimumSize = new Point(32, 32),
                MaximumSize = new Point(32, 32),
                AutoLayout  = AutoLayout.DockLeft,
                OnClick     = (sender, args) =>
                {
                    var source  = GuiRoot.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();
                                CompanyInformation.LogoBackground = gc.SelectedItem.Background;
                                CompanyLogoDisplay.Invalidate();
                            }
                        },
                        PopupDestructionType = PopupDestructionType.DestroyOnOffClick
                    };
                    GuiRoot.ShowModalPopup(chooser);
                }
            });

            logoRow.AddChild(new Widget
            {
                Background      = new TileReference("basic", 1),
                BackgroundColor = CompanyInformation.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();
                                CompanyInformation.LogoBackgroundColor = gc.SelectedItem.BackgroundColor;
                                CompanyLogoDisplay.Invalidate();
                            }
                        },
                        PopupDestructionType = PopupDestructionType.DestroyOnOffClick
                    };
                    GuiRoot.ShowModalPopup(chooser);
                }
            });

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

            logoRow.AddChild(new Widget
            {
                Background  = CompanyInformation.LogoSymbol,
                MinimumSize = new Point(32, 32),
                MaximumSize = new Point(32, 32),
                AutoLayout  = AutoLayout.DockLeft,
                OnClick     = (sender, args) =>
                {
                    var source  = GuiRoot.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();
                                CompanyInformation.LogoSymbol = gc.SelectedItem.Background;
                                CompanyLogoDisplay.Invalidate();
                            }
                        },
                        PopupDestructionType = PopupDestructionType.DestroyOnOffClick
                    };
                    GuiRoot.ShowModalPopup(chooser);
                }
            });

            logoRow.AddChild(new Widget
            {
                Background      = new TileReference("basic", 1),
                BackgroundColor = CompanyInformation.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();
                                CompanyInformation.LogoSymbolColor = gc.SelectedItem.BackgroundColor;
                                CompanyLogoDisplay.Invalidate();
                            }
                        },
                        PopupDestructionType = PopupDestructionType.DestroyOnOffClick
                    };
                    GuiRoot.ShowModalPopup(chooser);
                }
            });


            #endregion

            GuiRoot.RootItem.Layout();

            IsInitialized = true;

            base.OnEnter();
        }
Esempio n. 5
0
        public override void Construct()
        {
            Settings.Seed        = Settings.Name.GetHashCode();
            PopupDestructionType = PopupDestructionType.Keep;
            Padding = new Margin(2, 2, 2, 2);
            //Set size and center on screen.
            Rect   = new Rectangle(0, 0, 400, 400);
            Rect.X = (Root.RenderData.VirtualScreen.Width / 2) - 200;
            Rect.Y = (Root.RenderData.VirtualScreen.Height / 2) - 200;

            Border = "border-fancy";

            var okayButton = AddChild(new Gui.Widgets.Button
            {
                Text = "Okay",
                TextHorizontalAlign = HorizontalAlign.Center,
                TextVerticalAlign   = VerticalAlign.Center,
                Border  = "border-button",
                OnClick = (sender, args) =>
                {
                    Result = DialogResult.Okay;
                    this.Close();
                },
                AutoLayout = AutoLayout.FloatBottomRight
            });

            AddChild(new Button
            {
                Text = "Cancel",
                TextHorizontalAlign = HorizontalAlign.Center,
                TextVerticalAlign   = VerticalAlign.Center,
                Border  = "border-button",
                OnClick = (sender, args) =>
                {
                    Result = DialogResult.Cancel;
                    this.Close();
                },
                AutoLayout = AutoLayout.FloatBottomRight,
                OnLayout   = (sender) => sender.Rect.X -= okayButton.Rect.Width + 4
            });

            var topRow = AddChild(new Widget
            {
                AutoLayout  = AutoLayout.DockTop,
                MinimumSize = new Point(0, 30)
            });

            topRow.AddChild(new Widget
            {
                AutoLayout  = AutoLayout.DockLeft,
                MinimumSize = new Point(64, 0),
                Text        = "Name"
            });

            topRow.AddChild(new Widget
            {
                AutoLayout = AutoLayout.DockRight,
                Border     = "border-button",
                Text       = "Random",
                OnClick    = (sender, args) =>
                {
                    Settings.Name    = TextGenerator.GenerateRandom(TextGenerator.GetAtoms(ContentPaths.Text.Templates.worlds));
                    NameEditBox.Text = Settings.Name;
                    Settings.Seed    = Settings.Name.GetHashCode();
                }
            });

            NameEditBox = topRow.AddChild(new Gui.Widgets.EditableTextField
            {
                AutoLayout   = AutoLayout.DockFill,
                Text         = Settings.Name,
                OnTextChange = (sender) =>
                {
                    Settings.Name = sender.Text;
                    Settings.Seed = Settings.Name.GetHashCode();
                }
            });


            AddChild(CreateCombo <int>(Root, "World Size", "Size of the world to generate",
                                       new int[] { 256, 384, 512, 1024, 2048 }, (i) =>
            {
                Settings.Width  = i;
                Settings.Height = i;
            }, () => Settings.Width));

            AddChild(CreateCombo <int>(Root, "Natives", "Number of native civilizations",
                                       new int[] { 0, 2, 4, 8, 16 }, (i) => Settings.NumCivilizations = i,
                                       () => Settings.NumCivilizations));


            AddChild(CreateCombo <int>(Root, "Faults", "Number of straights, seas, etc.",
                                       new int[] { 0, 1, 3, 5, 10 }, (i) => Settings.NumFaults = i, () => Settings.NumFaults));

            AddChild(CreateCombo <float>(Root, "Rainfall", "Amount of moisture in the world.",
                                         new float[] { 0.0f, 0.5f, 1.0f, 1.5f, 2.0f }, (f) => Settings.RainfallScale = f,
                                         () => Settings.RainfallScale));

            AddChild(CreateCombo <int>(Root, "Erosion", "How eroded is the landscape.",
                                       new int[] { 50, 1000, 8000, 20000, 50000 }, (i) => Settings.NumRains = i,
                                       () => Settings.NumRains));

            AddChild(CreateCombo <float>(Root, "Sea Level", "Height of the sea.",
                                         new float[] { 0.05f, 0.1f, 0.17f, 0.25f, 0.3f }, (f) => Settings.SeaLevel = f,
                                         () => Settings.SeaLevel));

            AddChild(CreateCombo <float>(Root, "Temperature", "Average temperature.",
                                         new float[] { 0.0f, 0.5f, 1.0f, 1.5f, 2.0f }, (f) => Settings.TemperatureScale = f,
                                         () => Settings.TemperatureScale));

            Layout();
        }
Esempio n. 6
0
        public static string GetRandomWorldName()
        {
            List <List <string> > templates = TextGenerator.GetAtoms(ContentPaths.Text.Templates.worlds);

            return(TextGenerator.GenerateRandom(templates));
        }
Esempio n. 7
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();
        }