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); MakeMenu(); Progress = GuiRoot.RootItem.AddChild(new Gui.Widgets.ProgressBar { Rect = new Rectangle(0, 0, GuiRoot.RenderData.VirtualScreen.Width, 32) }) as Gui.Widgets.ProgressBar; Dictionary <GameMaster.ToolMode, Gui.Widget> ToolbarItems = new Dictionary <GameMaster.ToolMode, Gui.Widget>(); //ToolbarItems[GameMaster.ToolMode.SelectUnits] = CreateIcon(5, GameMaster.ToolMode.SelectUnits); // ToolbarItems[GameMaster.ToolMode.Dig] = CreateIcon(0, GameMaster.ToolMode.Dig); // ToolbarItems[GameMaster.ToolMode.Build] = CreateIcon(2, GameMaster.ToolMode.Build); // ToolbarItems[GameMaster.ToolMode.Cook] = CreateIcon(3, GameMaster.ToolMode.Cook); // ToolbarItems[GameMaster.ToolMode.Farm] = CreateIcon(5, GameMaster.ToolMode.Farm); // ToolbarItems[GameMaster.ToolMode.Magic] = CreateIcon(6, GameMaster.ToolMode.Magic); // ToolbarItems[GameMaster.ToolMode.Gather] = CreateIcon(6, GameMaster.ToolMode.Gather); // ToolbarItems[GameMaster.ToolMode.Chop] = CreateIcon(1, GameMaster.ToolMode.Chop); // ToolbarItems[GameMaster.ToolMode.Guard] = CreateIcon(4, GameMaster.ToolMode.Guard); // ToolbarItems[GameMaster.ToolMode.Attack] = CreateIcon(3, GameMaster.ToolMode.Attack); var Tilesheet = AssetManager.GetContentTexture(ContentPaths.Terrain.terrain_tiles); VoxelLibrary.InitializeDefaultLibrary(Game.GraphicsDevice); var bottomRightTray = GuiRoot.RootItem.AddChild(new Gui.Widgets.ToolTray.Tray { IsRootTray = true, Corners = Gui.Scale9Corners.Left | Gui.Scale9Corners.Top, AutoLayout = Gui.AutoLayout.FloatBottom, ItemSource = new Gui.Widget[] { new Gui.Widgets.ToolTray.Icon { Icon = new TileReference("tool-icons", 5), KeepChildVisible = true, ExpansionChild = new Gui.Widgets.ToolTray.Tray { ItemSource = RoomLibrary.GetRoomTypes().Select(name => RoomLibrary.GetData(name)) .Select(data => new Gui.Widgets.ToolTray.Icon { Icon = data.NewIcon, ExpansionChild = new Gui.Widgets.BuildRoomInfo { Data = data, Rect = new Rectangle(0, 0, 256, 128) }, OnClick = (sender, args) => { (sender as Gui.Widgets.FramedIcon).Enabled = false; } }) } }, new Gui.Widgets.ToolTray.Icon { Icon = new TileReference("tool-icons", 6), KeepChildVisible = true, ExpansionChild = new Gui.Widgets.ToolTray.Tray { ItemSource = VoxelLibrary.GetTypes().Where(voxel => voxel.IsBuildable) .Select(data => new Gui.Widgets.ToolTray.Icon { Icon = new TileReference("rooms", 0), ExpansionChild = new Gui.Widgets.BuildWallInfo { Data = data, Rect = new Rectangle(0, 0, 256, 128) } }) } } } }); bottomRightTray.Hidden = false; GuiRoot.RootItem.Layout(); IsInitialized = true; base.OnEnter(); }
public override void Construct() { Rect = Root.VirtualScreen; Border = "border-fancy"; AddChild(new Widget { Text = "CLOSE", TextHorizontalAlign = HorizontalAlign.Center, TextVerticalAlign = VerticalAlign.Center, Border = "border-button", OnClick = (sender, args) => this.Close(), AutoLayout = AutoLayout.FloatBottomRight }); var tabPanel = AddChild(new Gum.Widgets.TabPanel { AutoLayout = AutoLayout.DockFill, Font = "outline-font", TextColor = new Vector4(1, 1, 1, 1), SelectedTabColor = new Vector4(1, 0, 0, 1), OnLayout = (sender) => sender.Rect.Height -= 36 // Keep it from overlapping bottom buttons. }) as Gum.Widgets.TabPanel; #region Room Tab if (BuildType.HasFlag(BuildTypes.Room)) { var iconSheet = Root.GetTileSheet("rooms") as Gum.TileSheet; BuildTab(tabPanel, "Rooms", RoomLibrary.GetRoomTypes().Select(name => RoomLibrary.GetData(name)).Select(data => new BuildableItem { Icon = data.NewIcon, Name = data.Name, Data = data }), (item, description, buildButton) => { var data = item.Data as RoomData; var builder = new StringBuilder(); builder.AppendLine(data.Description); if (!data.CanBuildAboveGround) { builder.AppendLine("* Must be built below ground."); } if (!data.CanBuildBelowGround) { builder.AppendLine("* Must be built above ground."); } if (data.MustBeBuiltOnSoil) { builder.AppendLine("* Must be built on soil."); } builder.AppendLine("Required per 4 tiles:"); foreach (var requirement in data.RequiredResources) { builder.AppendLine(String.Format("{0}: {1}", requirement.Key, requirement.Value.NumResources)); } if (data.RequiredResources.Count == 0) { builder.AppendLine("Nothing!"); } description.AddChild(new Gum.Widget { Background = item.Icon, MinimumSize = new Point(32, 32), AutoLayout = Gum.AutoLayout.DockTop, MaximumSize = new Point(32, 32) }); description.AddChild(new Gum.Widget { Font = "outline-font", Text = builder.ToString(), AutoLayout = Gum.AutoLayout.DockFill }); buildButton.OnClick = (sender, args) => { Master.Faction.RoomBuilder.CurrentRoomData = item.Data as RoomData; Master.VoxSelector.SelectionType = VoxelSelectionType.SelectFilled; Master.Faction.WallBuilder.CurrentVoxelType = null; Master.Faction.CraftBuilder.IsEnabled = false; Master.CurrentToolMode = GameMaster.ToolMode.Build; World.ShowToolPopup("Click and drag to build " + item.Name); this.Close(); }; }); } #endregion #region Wall tab if (BuildType.HasFlag(BuildTypes.Wall)) { var wallTypes = VoxelLibrary.GetTypes().Where(voxel => voxel.IsBuildable); BuildTab(tabPanel, "Walls", wallTypes.Select(wall => new BuildableItem { Icon = null, Name = wall.Name, Data = wall }), (item, description, buildButton) => { var data = item.Data as VoxelType; var builder = new StringBuilder(); builder.AppendLine(String.Format("{0} Wall", data.Name)); builder.AppendLine(String.Format("Strength: {0}", data.StartingHealth)); builder.AppendLine(String.Format("Requires: {0}", ResourceLibrary.Resources[data.ResourceToRelease].ResourceName)); description.AddChild(new Gum.Widget { Font = "outline-font", Text = builder.ToString(), AutoLayout = AutoLayout.DockFill }); buildButton.OnClick = (sender, args) => { Master.Faction.RoomBuilder.CurrentRoomData = null; Master.VoxSelector.SelectionType = VoxelSelectionType.SelectEmpty; Master.Faction.WallBuilder.CurrentVoxelType = item.Data as VoxelType; Master.Faction.CraftBuilder.IsEnabled = false; Master.CurrentToolMode = GameMaster.ToolMode.Build; World.ShowToolPopup("Click and drag to build " + item.Name + " wall."); this.Close(); }; }); } #endregion #region Item Tab if (BuildType.HasFlag(BuildTypes.Item)) { var iconSheet = Root.GetTileSheet("crafts") as Gum.TileSheet; BuildTab(tabPanel, "Objects", CraftLibrary.CraftItems.Values.Where(item => item.Type == CraftItem.CraftType.Object).Select(craft => new BuildableItem { Icon = craft.Icon, Name = craft.Name, Data = craft }), (item, description, buildButton) => { var data = item.Data as CraftItem; var builder = new StringBuilder(); builder.AppendLine(data.Name); builder.AppendLine(data.Description); builder.AppendLine("Required:"); description.AddChild(new Gum.Widget { Background = item.Icon, MinimumSize = new Point(32, 32), AutoLayout = AutoLayout.DockTop, MaximumSize = new Point(32, 32) }); description.AddChild(new Gum.Widget { Font = "outline-font", Text = builder.ToString(), AutoLayout = Gum.AutoLayout.DockTop }); var nearestBuildLocation = World.PlayerFaction.FindNearestItemWithTags(data.CraftLocation, Vector3.Zero, false); if (nearestBuildLocation == null) { description.AddChild(new Gum.Widget { Font = "outline-font", Text = String.Format("Needs {0} to build!", data.CraftLocation), TextColor = new Vector4(1, 0, 0, 1), AutoLayout = Gum.AutoLayout.DockTop }); } else { foreach (var resourceAmount in data.RequiredResources) { var resourceSelector = description.AddChild(new Gum.Widgets.ComboBox { Font = "outline-font", Items = Master.Faction.ListResourcesWithTag(resourceAmount.ResourceType).Select(r => r.ResourceType.ToString()).ToList(), AutoLayout = AutoLayout.DockTop }) as Gum.Widgets.ComboBox; if (resourceSelector.Items.Count == 0) { resourceSelector.Items.Add("<Not enough!>"); } } } }); } #endregion Layout(); }