private Widget LabelAndDockWidget(string Label, Widget Widget) { var r = GuiRoot.ConstructWidget(new Widget { MinimumSize = new Point(0, 20), AutoLayout = AutoLayout.DockTop, Padding = new Margin(0, 0, 4, 4), ChangeColorOnHover = true, HoverTextColor = new Vector4(0.5f, 0, 0, 1.0f) }); var label = new Widget { Text = Label, AutoLayout = AutoLayout.DockLeft, }; r.AddChild(label); Widget.AutoLayout = AutoLayout.DockFill; r.AddChild(Widget); Widget.OnMouseEnter += (sender, args) => { label.TextColor = Color.DarkRed.ToVector4(); label.Invalidate(); }; Widget.OnMouseLeave += (sender, args) => { label.TextColor = Color.Black.ToVector4(); label.Invalidate(); }; return(r); }
public void MakeMenu() { GuiRoot.RootItem.Clear(); var frame = MakeMenuFrame("GUI DEBUG"); MakeMenuItem(frame, "View Atlas \u00DF", "", (sender, args) => { var pane = GuiRoot.ConstructWidget(new ShowTextureDialog()); GuiRoot.ShowDialog(pane); GuiRoot.RootItem.Layout(); }); MakeMenuItem(frame, "BACK", "Goodbye.", (sender, args) => StateManager.PopState()); }
public void Update(Gui.Root Gui) { if (!TutorialHidden && TutorialEnabled && !String.IsNullOrEmpty(PendingTutorial) && Gui != null && !Entries[PendingTutorial].Shown) { if (TutorialVisible && ExistingTutorial != null) { ExistingTutorial.Close(); ExistingTutorial = null; } var entry = Entries[PendingTutorial]; entry.Shown = true; entry.Name = PendingTutorial; TutorialVisible = true; var popup = Gui.ConstructWidget(new Gui.Widgets.TutorialPopup { Message = entry, OnClose = (sender) => { TutorialEnabled = !(sender as Gui.Widgets.TutorialPopup).DisableChecked; TutorialVisible = false; Gui.ClearSpecials(); if (!String.IsNullOrEmpty(entry.NextTutorial)) { ShowTutorial(entry.NextTutorial); } }, OnLayout = (sender) => { sender.Rect.X = Gui.RenderData.VirtualScreen.Width - sender.Rect.Width; sender.Rect.Y = 64; } }); if (entry.Popup) { Gui.ShowMinorPopup(popup); popup.PopupDestructionType = PopupDestructionType.Keep; } else { Gui.RootItem.AddChild(popup); } ExistingTutorial = popup; PendingTutorial = null; Gui.SpecialHiliteWidgetName = entry.GuiHilite; } if ((HighlightWidget != null) && HighlightWidget.IsAnyParentHidden() && TutorialVisible && (ExistingTutorial != null)) { Gui.ClearSpecials(); ExistingTutorial.Close(); } }
public static Widget CreateCombo <T>(Gui.Root Root, String Name, String Tooltip, T[] Values, Action <T> Setter, Func <T> Getter) { System.Diagnostics.Debug.Assert(Values.Length == LevelStrings.Length); var r = Root.ConstructWidget(new Widget { AutoLayout = AutoLayout.DockTop, MinimumSize = new Point(0, 30), Tooltip = Tooltip }); r.AddChild(new Widget { AutoLayout = AutoLayout.DockLeft, MinimumSize = new Point(64, 0), Text = Name }); var combo = r.AddChild(new Gui.Widgets.ComboBox { AutoLayout = AutoLayout.DockFill, Items = new List <String>(LevelStrings), OnSelectedIndexChanged = (sender) => { var box = sender as ComboBox; if (box.SelectedIndex >= 0 && box.SelectedIndex < Values.Length) { Setter(Values[box.SelectedIndex]); } } }) as Gui.Widgets.ComboBox; var index = (new List <T>(Values)).IndexOf(Getter()); if (index == -1) { combo.SelectedIndex = 2; } else { combo.SelectedIndex = index; } return(r); }
public override void OnEnter() { DwarfGame.GumInputMapper.GetInputQueue(); World.Tutorial("trade_screen"); GuiRoot = new Gui.Root(DwarfGame.GuiSkin); GuiRoot.MousePointer = new Gui.MousePointer("mouse", 4, 0); GuiRoot.RootItem.Font = "font8"; TradePanel = GuiRoot.ConstructWidget(new Gui.Widgets.TradePanel { Rect = GuiRoot.RenderData.VirtualScreen, Envoy = new Trade.EnvoyTradeEntity(Envoy), Player = new Trade.PlayerTradeEntity(PlayerFaction), }) as Gui.Widgets.TradePanel; TradePanel.Layout(); GuiRoot.ShowDialog(TradePanel); IsInitialized = true; base.OnEnter(); }
public void Reset() { mainPanel.Clear(); Rectangle rect = GuiRoot.RenderData.VirtualScreen; 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, }); var widgetList = mainPanel.AddChild(new WidgetListView() { AutoLayout = AutoLayout.DockTop, SelectedItemForegroundColor = Color.Black.ToVector4(), SelectedItemBackgroundColor = new Vector4(0, 0, 0, 0), ItemBackgroundColor2 = new Vector4(0, 0, 0, 0.1f), ItemBackgroundColor1 = new Vector4(0, 0, 0, 0), ItemHeight = 64, MinimumSize = new Point(0, 3 * GuiRoot.RenderData.VirtualScreen.Height / 4) }) as WidgetListView; var factions = World.Factions.Factions.Where(f => !f.Value.IsRaceFaction && f.Value.Race.IsIntelligent && f.Value != World.PlayerFaction).OrderBy(k => { if (k.Value.Race.Name == "Dwarf") { return(0); } var currentExpedition = World.Diplomacy.Adventures.Where(a => a.DestinationFaction == k.Key).FirstOrDefault(); if (currentExpedition != null) { return(k.Value.DistanceToCapital); } return(k.Value.DistanceToCapital + 100000.0f); }); foreach (var faction in factions) { var diplomacy = World.Diplomacy.GetPolitics(faction.Value, World.PlayerFaction); var details = diplomacy.RecentEvents.Select(e => string.Format("{0} ({1})", TextGenerator.ToSentenceCase(e.Description), e.Change > 0 ? "+" + e.Change.ToString() : e.Change.ToString())); var entry = widgetList.AddItem(new Widget() { Background = new TileReference("basic", 0), }); StringBuilder sb = new StringBuilder(); foreach (var detail in details) { sb.AppendLine(detail); } entry.Tooltip = "Recent events:\n" + sb.ToString(); if (sb.ToString() == "") { entry.Tooltip = "No recent events."; } var titlebar = entry.AddChild(new Widget() { InteriorMargin = new Margin(5, 5, 5, 5), MinimumSize = new Point(512, 36), AutoLayout = AutoLayout.DockTop, }); titlebar.AddChild(new Widget() { Background = new TileReference("map-icons", faction.Value.Race.Icon), MaximumSize = new Point(32, 32), MinimumSize = new Point(32, 32), AutoLayout = AutoLayout.DockLeft, }); titlebar.AddChild(new Widget() { Text = System.String.Format("{0} ({1}){2}", faction.Value.Name, faction.Value.Race.Name, diplomacy.WasAtWar ? " -- At war!" : ""), TextHorizontalAlign = HorizontalAlign.Right, TextVerticalAlign = VerticalAlign.Bottom, Font = "font10", AutoLayout = AutoLayout.DockLeft }); var currentAdventure = World.Diplomacy.Adventures.Where(a => a.DestinationFaction == faction.Key).FirstOrDefault(); if (currentAdventure == null && World.PlayerFaction.Minions.Count > 0) { titlebar.AddChild(new Button() { Text = "Send Expedition...", TextHorizontalAlign = HorizontalAlign.Center, TextVerticalAlign = VerticalAlign.Center, Font = "font10", AutoLayout = AutoLayout.DockRight, OnClick = (sender, args) => { World.Tutorial("adventures"); GuiRoot.ShowModalPopup(GuiRoot.ConstructWidget(new PrepareExpeditionDialog() { Faction = World.PlayerFaction, World = World, DestinationFaction = faction.Value, Rect = GuiRoot.RenderData.VirtualScreen.Interior(128, 128, 128, 128), OnProceed = (dialog) => { GuiRoot.ShowModalPopup(GuiRoot.ConstructWidget(new SelectEmployeesDialog() { Faction = World.PlayerFaction, World = World, Rect = GuiRoot.RenderData.VirtualScreen.Interior(32, 32, 32, 32), OnProceed = (selectEmployees) => { GuiRoot.ShowModalPopup(new SelectResourcesDialog() { Rect = GuiRoot.RenderData.VirtualScreen.Interior(32, 32, 32, 32), Faction = World.PlayerFaction, OnProceed = (selectResources) => { var adventure = dialog.SelectedAdventure; adventure.Party = selectEmployees.GoingCreatures; adventure.Money = selectResources.SelectedMoney; adventure.Resources = selectResources.SelectedResources; adventure.DestinationFaction = faction.Key; adventure.OwnerFaction = World.PlayerFaction.Name; adventure.Position = World.WorldOrigin; adventure.Start = World.WorldOrigin; World.Diplomacy.Adventures.Add(adventure); World.PlayerFaction.RemoveResources(selectResources.SelectedResources, Vector3.Zero, false); World.PlayerFaction.AddMoney(-selectResources.SelectedMoney); Reset(); } }); } })); } })); } }); } else if (currentAdventure != null) { var eta = currentAdventure.GetStatusString(World); titlebar.AddChild(new TextProgressBar() { MinimumSize = new Point(128, 32), Percentage = currentAdventure.GetProgress(World), SegmentCount = 10, AutoLayout = AutoLayout.DockRight }); titlebar.AddChild(new Widget() { Text = string.Format("Expedition underway ...\n {0}", eta), TextHorizontalAlign = HorizontalAlign.Center, TextVerticalAlign = VerticalAlign.Center, Font = "font10", AutoLayout = AutoLayout.DockRight, }); } var relation = diplomacy.GetCurrentRelationship(); var relationshipColor = Color.Black.ToVector4(); if (relation == Relationship.Loving) { relationshipColor = GameSettings.Default.Colors.GetColor("Positive", Color.DarkGreen).ToVector4(); } else if (relation == Relationship.Hateful) { relationshipColor = GameSettings.Default.Colors.GetColor("Negative", Color.Red).ToVector4(); } entry.AddChild(new Widget() { Text = System.String.Format(" Relationship: {0}{1}", diplomacy.GetCurrentRelationship(), faction.Value.ClaimsColony ? " (Claims this territory)" : ""), TextHorizontalAlign = HorizontalAlign.Left, TextVerticalAlign = VerticalAlign.Top, Font = "font8", AutoLayout = AutoLayout.DockTop, TextColor = relationshipColor }); entry.AddChild(new Widget() { Text = System.String.Format(" GDP: {0} Size: {1} Distance to capital: {2} miles", faction.Value.TradeMoney, faction.Value.TerritorySize, (int)faction.Value.DistanceToCapital), TextHorizontalAlign = HorizontalAlign.Left, TextVerticalAlign = VerticalAlign.Top, Font = "font8", AutoLayout = AutoLayout.DockTop }); } mainPanel.Layout(); }
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(); }
public override void Update(DwarfTime gameTime) { foreach (var @event in DwarfGame.GumInputMapper.GetInputQueue()) { GuiRoot.HandleInput(@event.Message, @event.Args); if ([email protected]) { // Pass event to game... } } if (NeedsRefresh) { NeedsRefresh = false; Grid.ClearItems(); int i = 0; foreach (var item in Items) { var itemWidget = new ChooserWidget { Item = item, Background = new TileReference("basic", 0), BackgroundColor = i % 2 == 0 ? new Vector4(0, 0, 0, 0.1f) : new Vector4(0, 0, 0, 0.2f) }; Grid.AddItem(itemWidget); itemWidget.DeleteButton.OnClick = (sender, args) => { var confirm = GuiRoot.ConstructWidget(new Gui.Widgets.Confirm { OkayText = "Delete", CancelText = "Keep", Text = "Are you sure you want to delete this?", OnClose = (s) => { if ((s as Gui.Widgets.Confirm).DialogResult == Gui.Widgets.Confirm.Result.OKAY) { var selectedItem = itemWidget.Item; Items.Remove(selectedItem); try { global::System.IO.Directory.Delete(selectedItem.Path, true); } catch (Exception e) { GuiRoot.ShowModalPopup(new Gui.Widgets.Confirm() { OkayText = "Ok", CancelText = "", Text = e.Message }); } NeedsRefresh = true; } } }); GuiRoot.ShowModalPopup(confirm); }; if (itemWidget.LoadButton != null) { itemWidget.LoadButton.OnClick = (sender, args) => { if (String.IsNullOrEmpty(itemWidget.Item.Valid) && OnProceedClicked != null) { OnProceedClicked(itemWidget.Item.Path); } } } ; i++; } Grid.OnSelectedIndexChanged = (widget) => { this.ItemSelected = Grid.SelectedIndex; NeedsRefresh = true; }; if (Grid.SelectedIndex > Items.Count - 1 || Grid.SelectedIndex < 0) { Grid.SelectedIndex = 0; } ItemSelected = Grid.SelectedIndex; if (Items.Count > 0) { DateTime directoryTime; try { directoryTime = global::System.IO.File.GetLastWriteTime(Items[ItemSelected].Path + System.IO.Path.DirectorySeparatorChar + "meta.txt"); } catch (Exception) { directoryTime = DateTime.MinValue; } BottomBar.Text = Items[ItemSelected].Path; if (!String.IsNullOrEmpty(Items[ItemSelected].Valid)) { BottomBar.Text += "\n" + Items[ItemSelected].Valid; } else { BottomBar.Text += "\n" + directoryTime.ToShortDateString() + " " + directoryTime.ToShortTimeString(); } } else { BottomBar.Text = NoItemsText; } } GuiRoot.Update(gameTime.ToRealTime()); base.Update(gameTime); }
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(); }
public override void OnEnter() { if (ItemSource != null) { foreach (var path in ItemSource()) { Items.Add(new ChooserItem { Path = path, Valid = ValidateItem == null ? true : ValidateItem(path) }); } } // 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.Transparent = false; GuiRoot.RootItem.Background = new Gui.TileReference("basic", 0); GuiRoot.RootItem.InteriorMargin = new Gui.Margin(16, 16, 16, 16); // CONSTRUCT GUI HERE... BottomBar = GuiRoot.RootItem.AddChild(new Gui.Widget { AutoLayout = Gui.AutoLayout.DockBottom, MinimumSize = new Point(0, 60), TextHorizontalAlign = Gui.HorizontalAlign.Center, Font = "font10" }); if (Items.Count == 0) { BottomBar.Text = NoItemsText; } LoadButton = BottomBar.AddChild(new Gui.Widgets.Button { AutoLayout = Gui.AutoLayout.FloatBottomRight, Border = "border-button", Text = ProceedButtonText, OnClick = (sender, args) => { var selectedItem = Items[PreviewOffset + ItemSelected]; if (selectedItem.Valid && OnProceedClicked != null) { OnProceedClicked(selectedItem.Path); } } }); NextButton = BottomBar.AddChild(new Gui.Widgets.Button { AutoLayout = Gui.AutoLayout.FloatTopRight, Border = "border-button", Text = "Next >", OnClick = (sender, args) => { if (PreviewOffset + Grid.ItemsThatFit < Items.Count) { NeedsRefresh = true; PreviewOffset += Grid.ItemsThatFit; } } }); PrevButton = BottomBar.AddChild(new Gui.Widgets.Button { AutoLayout = Gui.AutoLayout.FloatTopLeft, Border = "border-button", Text = "< Prev", OnClick = (sender, args) => { if (PreviewOffset > 0) { NeedsRefresh = true; PreviewOffset -= Grid.ItemsThatFit; } } }); DeleteButton = BottomBar.AddChild(new Gui.Widgets.Button { AutoLayout = AutoLayout.FloatBottom, Border = "border-button", Text = "Delete", OnClick = (sender, args) => { var confirm = GuiRoot.ConstructWidget(new Gui.Widgets.Confirm { OkayText = "Delete", CancelText = "Keep", Text = "Are you sure you want to delete this?", OnClose = (s) => { if ((s as Gui.Widgets.Confirm).DialogResult == Gui.Widgets.Confirm.Result.OKAY) { var selectedItem = Items[PreviewOffset + ItemSelected]; Items.Remove(selectedItem); try { System.IO.Directory.Delete(selectedItem.Path, true); } catch (Exception e) { GuiRoot.ShowModalPopup(new Gui.Widgets.Confirm() { OkayText = "Ok", CancelText = "", Text = e.Message }); } NeedsRefresh = true; } } }); GuiRoot.ShowModalPopup(confirm); } }); BottomBar.AddChild(new Gui.Widgets.Button { AutoLayout = Gui.AutoLayout.FloatBottomLeft, Border = "border-button", Text = "< Back", OnClick = (sender, args) => { StateManager.PopState(); } }); Grid = GuiRoot.RootItem.AddChild(new Gui.Widgets.GridPanel { ItemSize = new Point(128, 128), ItemSpacing = new Point(8, 8), AutoLayout = Gui.AutoLayout.DockFill, Border = "border-one", Font = "font10", InteriorMargin = new Gui.Margin(32, 0, 0, 0), TextHorizontalAlign = HorizontalAlign.Center, TextVerticalAlign = VerticalAlign.Top }) as Gui.Widgets.GridPanel; GuiRoot.RootItem.Layout(); var gridSpaces = Grid.ItemsThatFit; for (var i = 0; i < gridSpaces; ++i) { var lambda_index = i; Grid.AddChild(new Gui.Widget { Border = "border-one", Text = "No Image", TextHorizontalAlign = HorizontalAlign.Center, TextVerticalAlign = VerticalAlign.Center, OnClick = (sender, args) => { ItemSelected = lambda_index; NeedsRefresh = true; } }); } GuiRoot.RootItem.Layout(); // Must be true or Render will not be called. IsInitialized = true; base.OnEnter(); }
public void Update(Gui.Root Gui) { if (TutorialEnabled && !String.IsNullOrEmpty(PendingTutorial) && Gui != null && !Entries[PendingTutorial].Shown) { if (TutorialVisible && ExistingTutorial != null) { ExistingTutorial.Close(); ExistingTutorial = null; } var entry = Entries[PendingTutorial]; entry.Shown = true; TutorialVisible = true; var popup = Gui.ConstructWidget(new Gui.Widgets.TutorialPopup { Message = entry, OnClose = (sender) => { TutorialEnabled = !(sender as Gui.Widgets.TutorialPopup).DisableChecked; TutorialVisible = false; Gui.ClearSpecials(); }, OnLayout = (sender) => { sender.Rect.X = Gui.RenderData.VirtualScreen.Width - sender.Rect.Width; sender.Rect.Y = 64; } }); if (entry.Popup) { Gui.ShowMinorPopup(popup); popup.PopupDestructionType = PopupDestructionType.Keep; } else { Gui.RootItem.AddChild(popup); } ExistingTutorial = popup; PendingTutorial = null; if (!String.IsNullOrEmpty(entry.GuiHilite)) { var widget = Gui.RootItem.EnumerateTree().FirstOrDefault(w => w.Tag is String && (w.Tag as String) == entry.GuiHilite); HighlightWidget = widget; if (widget != null) { Gui.SpecialHiliteRegion = widget.Rect; Gui.SpecialHighligtedWidget = widget; Gui.SpecialHiliteSheet = "border-hilite"; if (widget.Rect.Right < Gui.RenderData.VirtualScreen.Width / 2 || widget.Rect.Left < 64) { Gui.SpecialIndicatorPosition = new Microsoft.Xna.Framework.Point( widget.Rect.Right, widget.Rect.Center.Y - 16); Gui.SpecialIndicator = new Gui.MousePointer("hand", 1, 10); } else { Gui.SpecialIndicatorPosition = new Microsoft.Xna.Framework.Point( widget.Rect.Left - 32, widget.Rect.Center.Y - 16); Gui.SpecialIndicator = new Gui.MousePointer("hand", 4, 14); } widget.OnClick += (sender, args) => { popup.Close(); }; } else { Console.Error.WriteLine("GUI highlight {0} does not exist.", entry.GuiHilite); } } } if (HighlightWidget != null && HighlightWidget.IsAnyParentHidden() && TutorialVisible && ExistingTutorial != null) { Gui.SpecialHiliteRegion = null; ExistingTutorial.Close(); } }