private void RebuildGui() { // Create and initialize GUI framework. GuiRoot = new Gum.Root(new Point(640, 480), DwarfGame.GumSkin); GuiRoot.MousePointer = new Gum.MousePointer("mouse", 4, 0); // CONSTRUCT GUI HERE... MainPanel = GuiRoot.RootItem.AddChild(new Gum.Widget { Rect = GuiRoot.VirtualScreen, Padding = new Margin(4, 4, 4, 4), Transparent = true }); MainPanel.AddChild(new Widget { Text = "CLOSE", TextHorizontalAlign = HorizontalAlign.Center, TextVerticalAlign = VerticalAlign.Center, Border = "border-button", OnClick = (sender, args) => { // If changes, prompt before closing. if (HasChanges) { var confirm = new NewGui.Confirm { Text = "Apply changes?", OkayText = "YES", CancelText = "NO", OnClose = (s2) => { if ((s2 as NewGui.Confirm).DialogResult == NewGui.Confirm.Result.OKAY) { ApplySettings(); } StateManager.PopState(); } }; GuiRoot.ShowPopup(confirm, false); } else { StateManager.PopState(); } }, AutoLayout = AutoLayout.FloatBottomRight }); MainPanel.AddChild(new Widget { Text = "APPLY", TextHorizontalAlign = HorizontalAlign.Center, TextVerticalAlign = VerticalAlign.Center, Border = "border-button", OnClick = (sender, args) => { ApplySettings(); }, AutoLayout = AutoLayout.FloatBottomRight, OnLayout = s => s.Rect.X -= 128 // Hack to keep it from floating over the other button. }); TabPanel = MainPanel.AddChild(new Gum.Widgets.TabPanel { AutoLayout = AutoLayout.DockFill, TextSize = 2, SelectedTabColor = new Vector4(1, 0, 0, 1), OnLayout = (sender) => sender.Rect.Height -= 36 // Keep it from overlapping bottom buttons. }) as Gum.Widgets.TabPanel; CreateGameplayTab(); CreateAudioTab(); CreateKeysTab(); CreateGraphicsTab(); TabPanel.SelectedTab = 0; GuiRoot.RootItem.Layout(); LoadSettings(); }
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 Gum.Root(new Point(640, 480), DwarfGame.GumSkin); GuiRoot.MousePointer = new Gum.MousePointer("mouse", 4, 0); // CONSTRUCT GUI HERE... var mainPanel = GuiRoot.RootItem.AddChild(new Gum.Widget { Rect = GuiRoot.VirtualScreen, Border = "border-fancy", Text = "Create a Company", Padding = new Margin(4, 4, 4, 4), InteriorMargin = new Margin(24, 0, 0, 0), TextSize = 2 }); mainPanel.AddChild(new Gum.Widgets.Button { Text = "CREATE!", 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 Gum.Widgets.Button { Text = "BACK", TextHorizontalAlign = HorizontalAlign.Center, TextVerticalAlign = VerticalAlign.Center, Border = "border-button", OnClick = (sender, args) => { StateManager.PopState(); }, AutoLayout = AutoLayout.FloatBottomRight, OnLayout = s => s.Rect.X -= 128 // Hack to keep it from floating over the other button. }); #region Name var nameRow = mainPanel.AddChild(new Widget { MinimumSize = new Point(0, 24), AutoLayout = AutoLayout.DockTop, Padding = new Margin(0, 0, 2, 2) }); nameRow.AddChild(new Gum.Widget { MinimumSize = new Point(64, 0), Text = "Name", AutoLayout = AutoLayout.DockLeft, TextHorizontalAlign = HorizontalAlign.Right, TextVerticalAlign = VerticalAlign.Center }); nameRow.AddChild(new Gum.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()); // Todo: Doesn't automatically invalidate when text changed?? NameField.Invalidate(); } }); 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 Widget { 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 NewGui.CompanyLogo { AutoLayout = AutoLayout.DockLeft, MinimumSize = new Point(64, 64), MaximumSize = new Point(64, 64), CompanyInformation = CompanyInformation }) as NewGui.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 Gum.TileSheet; var chooser = new NewGui.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 NewGui.GridChooser; if (gc.DialogResult == NewGui.GridChooser.Result.OKAY && gc.SelectedItem != null) { sender.Background = gc.SelectedItem.Background; sender.Invalidate(); CompanyInformation.LogoBackground = gc.SelectedItem.Background; CompanyLogoDisplay.Invalidate(); } }, PopupDestructionType = PopupDestructionType.DestroyOnOffClick }; GuiRoot.ShowPopup(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 NewGui.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 NewGui.GridChooser; if (gc.DialogResult == NewGui.GridChooser.Result.OKAY && gc.SelectedItem != null) { sender.BackgroundColor = gc.SelectedItem.BackgroundColor; sender.Invalidate(); CompanyInformation.LogoBackgroundColor = gc.SelectedItem.BackgroundColor; CompanyLogoDisplay.Invalidate(); } }, PopupDestructionType = PopupDestructionType.DestroyOnOffClick }; GuiRoot.ShowPopup(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 Gum.TileSheet; var chooser = new NewGui.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 NewGui.GridChooser; if (gc.DialogResult == NewGui.GridChooser.Result.OKAY && gc.SelectedItem != null) { sender.Background = gc.SelectedItem.Background; sender.Invalidate(); CompanyInformation.LogoSymbol = gc.SelectedItem.Background; CompanyLogoDisplay.Invalidate(); } }, PopupDestructionType = PopupDestructionType.DestroyOnOffClick }; GuiRoot.ShowPopup(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 NewGui.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 NewGui.GridChooser; if (gc.DialogResult == NewGui.GridChooser.Result.OKAY && gc.SelectedItem != null) { sender.BackgroundColor = gc.SelectedItem.BackgroundColor; sender.Invalidate(); CompanyInformation.LogoSymbolColor = gc.SelectedItem.BackgroundColor; CompanyLogoDisplay.Invalidate(); } }, PopupDestructionType = PopupDestructionType.DestroyOnOffClick }; GuiRoot.ShowPopup(chooser); } }); #endregion GuiRoot.RootItem.Layout(); // Must be true or Render will not be called. IsInitialized = true; base.OnEnter(); }
private void ApplySettings() { // Copy all the states from widgets to game settings. // Gameplay settings GameSettings.Default.CameraScrollSpeed = this.MoveSpeed.ScrollPosition; GameSettings.Default.CameraZoomSpeed = this.ZoomSpeed.ScrollPosition; GameSettings.Default.EnableEdgeScroll = this.EdgeScrolling.CheckState; GameSettings.Default.FogofWar = this.FogOfWar.CheckState; GameSettings.Default.InvertZoom = this.InvertZoom.CheckState; GameSettings.Default.DisplayIntro = this.PlayIntro.CheckState; // Audio settings GameSettings.Default.MasterVolume = this.MasterVolume.ScrollPosition; GameSettings.Default.SoundEffectVolume = this.SFXVolume.ScrollPosition; GameSettings.Default.MusicVolume = this.SFXVolume.ScrollPosition; // Graphics settings var preResolutionX = GameSettings.Default.ResolutionX; var preResolutionY = GameSettings.Default.ResolutionY; var preFullscreen = GameSettings.Default.Fullscreen; var newDisplayMode = DisplayModes[this.Resolution.SelectedItem]; GameSettings.Default.ResolutionX = newDisplayMode.Width; GameSettings.Default.ResolutionY = newDisplayMode.Height; GameSettings.Default.Fullscreen = this.Fullscreen.CheckState; GameSettings.Default.ChunkDrawDistance = this.ChunkDrawDistance.ScrollPosition + 1.0f; GameSettings.Default.VertexCullDistance = this.VertexCullDistance.ScrollPosition + 0.1f; GameSettings.Default.ChunkGenerateDistance = this.GenerateDistance.ScrollPosition + 1.0f; GameSettings.Default.EnableGlow = this.Glow.CheckState; GameSettings.Default.AntiAliasing = AntialiasingOptions[this.Antialiasing.SelectedItem]; GameSettings.Default.DrawChunksReflected = this.ReflectTerrain.CheckState; GameSettings.Default.DrawEntityReflected = this.ReflectEntities.CheckState; GameSettings.Default.CalculateSunlight = this.Sunlight.CheckState; GameSettings.Default.AmbientOcclusion = this.AmbientOcclusion.CheckState; GameSettings.Default.CalculateRamps = this.Ramps.CheckState; GameSettings.Default.CursorLightEnabled = this.CursorLight.CheckState; GameSettings.Default.EntityLighting = this.EntityLight.CheckState; GameSettings.Default.SelfIlluminationEnabled = this.SelfIllumination.CheckState; GameSettings.Default.ParticlePhysics = this.ParticlePhysics.CheckState; GameSettings.Default.GrassMotes = this.Motes.CheckState; GameSettings.Default.NumMotes = (int)this.NumMotes.ScrollPosition + 100; GameSettings.Default.UseLightmaps = this.LightMap.CheckState; GameSettings.Default.UseDynamicShadows = this.DynamicShadows.CheckState; if (preResolutionX != GameSettings.Default.ResolutionX || preResolutionY != GameSettings.Default.ResolutionY || preFullscreen != GameSettings.Default.Fullscreen) { StateManager.Game.Graphics.PreferredBackBufferWidth = GameSettings.Default.ResolutionX; StateManager.Game.Graphics.PreferredBackBufferHeight = GameSettings.Default.ResolutionY; StateManager.Game.Graphics.IsFullScreen = GameSettings.Default.Fullscreen; try { StateManager.Game.Graphics.ApplyChanges(); RebuildGui(); } catch (NoSuitableGraphicsDeviceException) { GameSettings.Default.ResolutionX = preResolutionX; GameSettings.Default.ResolutionY = preResolutionY; GameSettings.Default.Fullscreen = preFullscreen; this.Resolution.SelectedIndex = this.Resolution.Items.IndexOf(string.Format("{0} x {1}", GameSettings.Default.ResolutionX, GameSettings.Default.ResolutionY)); this.Fullscreen.CheckState = GameSettings.Default.Fullscreen; GuiRoot.ShowPopup(new NewGui.Popup { Text = "Could not change display mode. Previous settings restored.", TextSize = 2 }, false); } } HasChanges = false; GameSettings.Save(); }