public override void Construct() { Border = "border-fancy"; OnConstruct = (sender) => { sender.Root.RegisterForUpdate(sender); var topRow = AddChild(new Widget { AutoLayout = AutoLayout.DockTop, MinimumSize = new Point(0, 24) }); topRow.AddChild(new Widget { AutoLayout = AutoLayout.DockRight, MinimumSize = new Point(32, 0), Text = "Default Priorities", ChangeColorOnHover = true, Border = "border-button", OnClick = (btn, args) => { var screen = sender.Root.RenderData.VirtualScreen; sender.Root.ShowModalPopup(new DefaultTaskPriority { Overworld = World.Overworld, MinimumSize = new Point(256, 512), Border = "border-fancy", Rect = new Rectangle(screen.Center.X - 128, screen.Center.Y - 256, 256, 512) }); } }); FilterBox = topRow.AddChild(new EditableTextField { AutoLayout = AutoLayout.DockFill, MinimumSize = new Point(0, 24), Text = "" }) as EditableTextField; ListView = AddChild(new WidgetListView { AutoLayout = AutoLayout.DockFill, SelectedItemForegroundColor = new Vector4(0, 0, 0, 1), Border = null, ItemHeight = 16 }) as WidgetListView; ListView.Border = null; // Can't make WidgetListView stop defaulting its border without breaking everywhere else its used. }; OnUpdate = (sender, time) => { if (sender.Hidden) { return; } var upperFilter = FilterBox.Text.ToUpperInvariant(); var tasksToDisplay = World.TaskManager.EnumerateTasks() .Where(t => !t.Hidden) .Where(t => String.IsNullOrEmpty(FilterBox.Text) ? true : t.Name.ToUpperInvariant().Contains(upperFilter)); ListView.ClearItems(); foreach (var task in tasksToDisplay) { var tag = task.GuiTag as Widget; var lambdaCopy = task; if (tag != null) { ListView.AddItem(tag); } else { #region Create gui row tag = Root.ConstructWidget(new Widget { Text = task.Name, MinimumSize = new Point(0, 16), Padding = new Margin(0, 0, 4, 4), TextVerticalAlign = VerticalAlign.Center, OnClick = (_sender, args) => { var loc = lambdaCopy.GetCameraZoomLocation(); if (loc.HasValue) { World.Renderer.Camera.SetZoomTarget(loc.Value); } } }); tag.AddChild(new Widget { Text = "CANCEL", AutoLayout = AutoLayout.DockRight, MinimumSize = new Point(16, 0), TextVerticalAlign = VerticalAlign.Center, OnClick = (_sender, args) => { World.TaskManager.CancelTask(lambdaCopy); } }); Widget priorityDisplay = null; tag.AddChild(new Gui.Widget { Background = new TileReference("round-buttons", 3), MinimumSize = new Point(16, 16), MaximumSize = new Point(16, 16), AutoLayout = AutoLayout.DockRightCentered, OnClick = (_sender, args) => { lambdaCopy.Priority = (TaskPriority)(Math.Min(4, (int)lambdaCopy.Priority + 1)); priorityDisplay.Text = lambdaCopy.Priority.ToString(); priorityDisplay.Invalidate(); }, OnMouseEnter = (_sender, args) => { _sender.BackgroundColor = GameSettings.Current.Colors.GetColor("Highlight", Color.DarkRed).ToVector4(); _sender.Invalidate(); }, OnMouseLeave = (_sender, args) => { _sender.BackgroundColor = Vector4.One; _sender.Invalidate(); } }); priorityDisplay = tag.AddChild(new Gui.Widget { AutoLayout = AutoLayout.DockRight, MinimumSize = new Point(64, 0), Text = lambdaCopy.Priority.ToString(), TextHorizontalAlign = HorizontalAlign.Center, TextVerticalAlign = VerticalAlign.Center }); tag.AddChild(new Gui.Widget { Background = new TileReference("round-buttons", 7), MinimumSize = new Point(16, 16), MaximumSize = new Point(16, 16), AutoLayout = AutoLayout.DockRightCentered, OnClick = (_sender, args) => { lambdaCopy.Priority = (TaskPriority)(Math.Max(0, (int)lambdaCopy.Priority - 1)); priorityDisplay.Text = lambdaCopy.Priority.ToString(); priorityDisplay.Invalidate(); }, OnMouseEnter = (_sender, args) => { _sender.BackgroundColor = GameSettings.Current.Colors.GetColor("Highlight", Color.DarkRed).ToVector4(); _sender.Invalidate(); }, OnMouseLeave = (_sender, args) => { _sender.BackgroundColor = Vector4.One; _sender.Invalidate(); } }); #endregion task.GuiTag = tag; ListView.AddItem(tag); } tag.Text = task.Name; } ListView.Invalidate(); }; base.Construct(); }
public override void Construct() { Border = "border-fancy"; Font = "font10"; OnConstruct = (sender) => { sender.Root.RegisterForUpdate(sender); FilterBox = AddChild(new EditableTextField { AutoLayout = AutoLayout.DockTop, MinimumSize = new Point(0, 24), Text = "" }) as EditableTextField; ListView = AddChild(new WidgetListView { AutoLayout = AutoLayout.DockFill, SelectedItemForegroundColor = new Vector4(0, 0, 0, 1), ChangeColorOnSelected = false, Border = null, ItemHeight = 24 }) as WidgetListView; ListView.Border = null; // Can't make WidgetListView stop defaulting its border without breaking everywhere else its used. }; OnUpdate = (sender, time) => { if (sender.Hidden) { return; } var roomsToDisplay = World.EnumerateZones().Where(r => !String.IsNullOrEmpty(FilterBox.Text) ? r.ID.Contains(FilterBox.Text) : true); int i = 0; ListView.ClearItems(); foreach (var room in roomsToDisplay) { i++; var tag = room.GuiTag as Widget; var lambdaCopy = room; if (tag != null) { ListView.AddItem(tag); } else { #region Create gui row tag = Root.ConstructWidget(new Widget { Text = room.GetDescriptionString(), MinimumSize = new Point(0, 16), Padding = new Margin(0, 0, 4, 4), TextVerticalAlign = VerticalAlign.Center, Background = new TileReference("basic", 0), BackgroundColor = i % 2 == 0 ? new Vector4(0.0f, 0.0f, 0.0f, 0.1f) : new Vector4(0, 0, 0, 0.25f) }); tag.OnUpdate = (sender1, args) => { if (tag.IsAnyParentHidden()) { return; } if (sender1.ComputeBoundingChildRect().Contains(Root.MousePosition)) { Drawer3D.DrawBox(lambdaCopy.GetBoundingBox(), Color.White, 0.1f, true); } }; Root.RegisterForUpdate(tag); tag.AddChild(new Button { Text = "Destroy", AutoLayout = AutoLayout.DockRight, MinimumSize = new Point(16, 0), ChangeColorOnHover = true, TextVerticalAlign = VerticalAlign.Center, OnClick = (_sender, args) => { World.UserInterface.Gui.ShowModalPopup(new Gui.Widgets.Confirm { Text = "Do you want to destroy this " + lambdaCopy.Type.Name + "?", OnClose = (_sender2) => DestroyZoneTool.DestroyRoom((_sender2 as Gui.Widgets.Confirm).DialogResult, lambdaCopy, World) }); } }); tag.AddChild(new Widget { MinimumSize = new Point(4, 0), AutoLayout = AutoLayout.DockRight }); tag.AddChild(new Button { Text = "Go to", AutoLayout = AutoLayout.DockRight, ChangeColorOnHover = true, MinimumSize = new Point(16, 0), TextVerticalAlign = VerticalAlign.Center, OnClick = (_sender, args) => { World.Renderer.Camera.ZoomTargets.Clear(); World.Renderer.Camera.ZoomTargets.Add(lambdaCopy.GetBoundingBox().Center()); } }); if (lambdaCopy is Stockpile && !(lambdaCopy is Graveyard)) { tag.AddChild(new Button { Text = "Resources...", AutoLayout = AutoLayout.DockRight, ChangeColorOnHover = true, MinimumSize = new Point(16, 0), TextVerticalAlign = VerticalAlign.Center, OnClick = (_sender, args) => { List <Resource.ResourceTags> blacklistableResources = new List <Resource.ResourceTags>() { Resource.ResourceTags.Alcohol, Resource.ResourceTags.Meat, Resource.ResourceTags.Metal, Resource.ResourceTags.Gem, Resource.ResourceTags.Magical, Resource.ResourceTags.Wood, Resource.ResourceTags.Soil, Resource.ResourceTags.Sand, Resource.ResourceTags.Fruit, Resource.ResourceTags.Gourd, Resource.ResourceTags.Grain, Resource.ResourceTags.Fungus, Resource.ResourceTags.Fuel, Resource.ResourceTags.Craft, Resource.ResourceTags.CraftItem, Resource.ResourceTags.Bone, Resource.ResourceTags.Potion, Resource.ResourceTags.PreparedFood, Resource.ResourceTags.Rail, Resource.ResourceTags.Seed }.OrderBy(t => t.ToString()).ToList(); int sqr = (int)Math.Sqrt(blacklistableResources.Count); int minWidth = Math.Min(sqr * 200 + 64, Root.RenderData.VirtualScreen.Width); int minHeight = Math.Min(sqr * 32 + 232, Root.RenderData.VirtualScreen.Height); var widget = Root.ConstructWidget(new Widget() { Border = "border-fancy", Font = "font10", Rect = new Rectangle(Root.RenderData.VirtualScreen.X + (Root.RenderData.VirtualScreen.Width - minWidth) / 2, Root.RenderData.VirtualScreen.Y + (Root.RenderData.VirtualScreen.Height - minHeight) / 2, minWidth, minHeight) }); widget.AddChild(new Widget() { MinimumSize = new Point(120, 32), Text = "Allowed Resources", Font = "font16", AutoLayout = AutoLayout.DockTop, }); var interiorWidget = widget.AddChild(new Widget() { Rect = new Rectangle(Root.RenderData.VirtualScreen.X + (Root.RenderData.VirtualScreen.Width - minWidth), Root.RenderData.VirtualScreen.Y + (Root.RenderData.VirtualScreen.Height - minHeight), minWidth, minHeight), AutoLayout = AutoLayout.DockTop }); var stockpile = lambdaCopy as Stockpile; var grid = interiorWidget.AddChild(new GridPanel() { AutoLayout = AutoLayout.DockFill, ItemSize = new Point(200, 32), ItemSpacing = new Point(2, 2) }) as GridPanel; List <CheckBox> boxes = new List <CheckBox>(); foreach (Resource.ResourceTags tagType in blacklistableResources) { var resource = Library.FindMedianResourceTypeWithTag(tagType); var resources = Library.EnumerateResourceTypesWithTag(tagType); Resource.ResourceTags lambdaType = tagType; var entry = grid.AddChild(new Widget()); if (resource != null) { entry.AddChild(new ResourceIcon() { MinimumSize = new Point(32, 32), MaximumSize = new Point(32, 32), Layers = resource.GuiLayers, AutoLayout = AutoLayout.DockLeft }); } var numResourcesInGroup = resources.Count(); var extraTooltip = numResourcesInGroup > 0 ? "\ne.g " + TextGenerator.GetListString(resources.Select(s => (string)s.Name).Take(Math.Min(numResourcesInGroup, 4)).ToList()) : ""; boxes.Add(entry.AddChild(new CheckBox() { Text = SplitCamelCase(tagType.ToString()), Tooltip = "Check to allow this stockpile to store " + tagType.ToString() + " resources." + extraTooltip, CheckState = !stockpile.BlacklistResources.Contains(tagType), OnCheckStateChange = (checkSender) => { var checkbox = checkSender as CheckBox; if (checkbox.CheckState && stockpile.BlacklistResources.Contains(lambdaType)) { stockpile.BlacklistResources.Remove(lambdaType); } else if (!stockpile.BlacklistResources.Contains(lambdaType)) { stockpile.BlacklistResources.Add(lambdaType); } }, AutoLayout = AutoLayout.DockLeft } ) as CheckBox); } widget.AddChild(new CheckBox() { Text = "Toggle All", CheckState = boxes.All(b => b.CheckState), OnCheckStateChange = (checkSender) => { foreach (var box in boxes) { box.CheckState = (checkSender as CheckBox).CheckState; } }, AutoLayout = AutoLayout.FloatBottomLeft }); widget.AddChild(new Button() { Text = "OK", AutoLayout = AutoLayout.FloatBottomRight, OnClick = (sender1, args1) => { widget.Close(); } }); widget.Layout(); Root.ShowModalPopup(widget); } }); } #endregion room.GuiTag = tag; ListView.AddItem(tag); } tag.Text = room.GetDescriptionString(); } ListView.Invalidate(); }; base.Construct(); }
public override void Construct() { Border = "border-fancy"; OnConstruct = (sender) => { sender.Root.RegisterForUpdate(sender); FilterBox = AddChild(new EditableTextField { AutoLayout = AutoLayout.DockTop, MinimumSize = new Point(0, 24), Text = "" }) as EditableTextField; ListView = AddChild(new WidgetListView { AutoLayout = AutoLayout.DockFill, SelectedItemForegroundColor = new Vector4(0, 0, 0, 1), Border = null, ItemHeight = 16 }) as WidgetListView; ListView.Border = null; // Can't make WidgetListView stop defaulting its border without breaking everywhere else its used. }; OnUpdate = (sender, time) => { if (sender.Hidden) { return; } //sender.Text = String.Join("\n", World.PlayerFaction.Minions.Select(m => String.Format("{0}: {1}, {2}", m.Name, m.Tasks.Count, (m.CurrentTask == null ? "NULL" : m.CurrentTask.Name)))); //sender.Text += "\n\n"; //sender.Text += String.Join("\n", World.Master.TaskManager.EnumerateTasks().Select(t => t.Name)); //sender.Invalidate(); ListView.ClearItems(); foreach (var task in World.Master.TaskManager.EnumerateTasks().Where(t => String.IsNullOrEmpty(FilterBox.Text) ? true : t.Name.Contains(FilterBox.Text))) { var tag = task.GuiTag as Widget; var lambdaCopy = task; if (tag != null) { ListView.AddItem(tag); } else { tag = Root.ConstructWidget(new Widget { Text = task.Name, MinimumSize = new Point(0, 16), Padding = new Margin(0, 0, 4, 4), TextVerticalAlign = VerticalAlign.Center }); tag.AddChild(new Widget { Text = "CANCEL", AutoLayout = AutoLayout.DockRight, MinimumSize = new Point(16, 0), TextVerticalAlign = VerticalAlign.Center, OnClick = (_sender, args) => { World.Master.TaskManager.CancelTask(lambdaCopy); } }); Widget priorityDisplay = null; tag.AddChild(new Gui.Widget { Background = new TileReference("round-buttons", 3), MinimumSize = new Point(16, 16), MaximumSize = new Point(16, 16), AutoLayout = AutoLayout.DockRightCentered, OnClick = (_sender, args) => { lambdaCopy.Priority = (Task.PriorityType)(Math.Min(4, (int)lambdaCopy.Priority + 1)); priorityDisplay.Text = lambdaCopy.Priority.ToString(); priorityDisplay.Invalidate(); }, OnMouseEnter = (_sender, args) => { _sender.BackgroundColor = GameSettings.Default.Colors.GetColor("Highlight", Color.DarkRed).ToVector4(); _sender.Invalidate(); }, OnMouseLeave = (_sender, args) => { _sender.BackgroundColor = Vector4.One; _sender.Invalidate(); } }); priorityDisplay = tag.AddChild(new Gui.Widget { AutoLayout = AutoLayout.DockRight, MinimumSize = new Point(64, 0), Text = lambdaCopy.Priority.ToString(), TextHorizontalAlign = HorizontalAlign.Center, TextVerticalAlign = VerticalAlign.Center }); tag.AddChild(new Gui.Widget { Background = new TileReference("round-buttons", 7), MinimumSize = new Point(16, 16), MaximumSize = new Point(16, 16), AutoLayout = AutoLayout.DockRightCentered, OnClick = (_sender, args) => { lambdaCopy.Priority = (Task.PriorityType)(Math.Max(0, (int)lambdaCopy.Priority - 1)); priorityDisplay.Text = lambdaCopy.Priority.ToString(); priorityDisplay.Invalidate(); }, OnMouseEnter = (_sender, args) => { _sender.BackgroundColor = GameSettings.Default.Colors.GetColor("Highlight", Color.DarkRed).ToVector4(); _sender.Invalidate(); }, OnMouseLeave = (_sender, args) => { _sender.BackgroundColor = Vector4.One; _sender.Invalidate(); } }); task.GuiTag = tag; ListView.AddItem(tag); } } ListView.Invalidate(); }; base.Construct(); }
public override void Construct() { Border = "border-fancy"; OnConstruct = (sender) => { sender.Root.RegisterForUpdate(sender); FilterBox = AddChild(new EditableTextField { AutoLayout = AutoLayout.DockTop, MinimumSize = new Point(0, 24), Text = "" }) as EditableTextField; ListView = AddChild(new WidgetListView { AutoLayout = AutoLayout.DockFill, SelectedItemForegroundColor = new Vector4(0, 0, 0, 1), Border = null, ItemHeight = 16 }) as WidgetListView; ListView.Border = null; // Can't make WidgetListView stop defaulting its border without breaking everywhere else its used. }; OnUpdate = (sender, time) => { if (sender.Hidden) { return; } var roomsToDisplay = World.PlayerFaction.GetRooms().Where(r => !String.IsNullOrEmpty(FilterBox.Text) ? r.ID.Contains(FilterBox.Text) : true); ListView.ClearItems(); foreach (var room in roomsToDisplay) { var tag = room.GuiTag as Widget; var lambdaCopy = room; if (tag != null) { ListView.AddItem(tag); } else { #region Create gui row tag = Root.ConstructWidget(new Widget { Text = room.GetDescriptionString(), MinimumSize = new Point(0, 16), Padding = new Margin(0, 0, 4, 4), TextVerticalAlign = VerticalAlign.Center }); tag.AddChild(new Widget { Text = "DESTROY", AutoLayout = AutoLayout.DockRight, MinimumSize = new Point(16, 0), ChangeColorOnHover = true, TextVerticalAlign = VerticalAlign.Center, OnClick = (_sender, args) => { World.Gui.ShowModalPopup(new Gui.Widgets.Confirm { Text = "Do you want to destroy this " + lambdaCopy.RoomData.Name + "?", OnClose = (_sender2) => DestroyZoneTool.DestroyRoom((_sender2 as Gui.Widgets.Confirm).DialogResult, lambdaCopy, World.PlayerFaction, World) }); } }); tag.AddChild(new Widget { MinimumSize = new Point(4, 0), AutoLayout = AutoLayout.DockRight }); tag.AddChild(new Widget { Text = "GO TO", AutoLayout = AutoLayout.DockRight, ChangeColorOnHover = true, MinimumSize = new Point(16, 0), TextVerticalAlign = VerticalAlign.Center, OnClick = (_sender, args) => { World.Camera.ZoomTargets.Clear(); World.Camera.ZoomTargets.Add(lambdaCopy.GetBoundingBox().Center()); } }); #endregion room.GuiTag = tag; ListView.AddItem(tag); } tag.Text = room.GetDescriptionString(); } ListView.Invalidate(); }; base.Construct(); }