Beispiel #1
0
 public override void Construct()
 {
     Border = "border-fancy";
     AddChild(new Gui.Widget()
     {
         Text        = "Events",
         Font        = "font16",
         AutoLayout  = AutoLayout.DockTop,
         MinimumSize = new Point(256, 32)
     });
     Gui.Widgets.WidgetListView listView = AddChild(new Gui.Widgets.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  = 32,
         MinimumSize = new Point(0, 3 * Root.RenderData.VirtualScreen.Height / 4)
     }) as Gui.Widgets.WidgetListView;
     foreach (var logged in Log.GetEntries().Reverse())
     {
         listView.AddItem(Root.ConstructWidget(new Widget()
         {
             Background        = new TileReference("basic", 0),
             Text              = TextGenerator.AgeToString(Now - logged.Date) + " " + logged.Text,
             Tooltip           = logged.Details,
             TextColor         = logged.TextColor.ToVector4(),
             Font              = "font10",
             MinimumSize       = new Point(640, 32),
             Padding           = new Margin(0, 0, 4, 4),
             TextVerticalAlign = VerticalAlign.Center
         }));
     }
     CloseButton = AddChild(new Gui.Widgets.Button()
     {
         Text        = "Close",
         Font        = "font10",
         Border      = "border-button",
         MinimumSize = new Point(128, 32),
         AutoLayout  = AutoLayout.FloatBottomRight
     });
     Layout();
     base.Construct();
 }
Beispiel #2
0
        private void SetupList(WidgetListView listA, WidgetListView listB, List <ResourceAmount> resourcesA,
                               List <ResourceAmount> resourcesB)
        {
            foreach (var resource in resourcesA)
            {
                var lineItem = CreateLineItem(resource);

                var lambdaResource = resource;
                lineItem.TriggerOnChildClick = true;
                lineItem.EnableHoverClick();
                lineItem.OnClick = (sender, args) =>
                {
                    if (lambdaResource.Count <= 0)
                    {
                        return;
                    }
                    var toMove = 1;
                    if (args.Control)
                    {
                        toMove = lambdaResource.Count;
                    }
                    if (args.Shift)
                    {
                        toMove = Math.Min(5, lambdaResource.Count);
                    }
                    if (lambdaResource.Count - toMove < 0)
                    {
                        return;
                    }
                    lambdaResource.Count -= toMove;
                    SoundManager.PlaySound(ContentPaths.Audio.Oscar.sfx_gui_change_selection, 0.1f, MathFunctions.Rand() * 0.25f);
                    var existingEntry = resourcesB.FirstOrDefault(r => r.Type == lambdaResource.Type);
                    if (existingEntry == null)
                    {
                        existingEntry = new ResourceAmount(lambdaResource.Type, toMove);
                        resourcesB.Add(existingEntry);
                        var rightLineItem = CreateLineItem(existingEntry);
                        rightLineItem.EnableHoverClick();
                        listA.AddItem(rightLineItem);

                        rightLineItem.TriggerOnChildClick = true;
                        rightLineItem.OnClick             = (_sender, _args) =>
                        {
                            var _toMove = 1;
                            if (_args.Control)
                            {
                                _toMove = existingEntry.Count;
                            }
                            if (_args.Shift)
                            {
                                _toMove = Math.Min(5, existingEntry.Count);
                            }
                            if (existingEntry.Count - _toMove < 0)
                            {
                                return;
                            }
                            existingEntry.Count -= _toMove;
                            SoundManager.PlaySound(ContentPaths.Audio.Oscar.sfx_gui_change_selection, 0.1f, MathFunctions.Rand() * 0.25f);
                            if (existingEntry.Count == 0)
                            {
                                var index = resourcesB.IndexOf(existingEntry);
                                if (index >= 0)
                                {
                                    resourcesB.RemoveAt(index);
                                    listA.RemoveChild(listA.GetChild(index + 1));
                                }
                            }

                            UpdateColumn(listA, resourcesB);

                            var sourceEntry = resourcesA.FirstOrDefault(
                                r => r.Type == existingEntry.Type);
                            int idx = resourcesA.IndexOf(sourceEntry);
                            sourceEntry.Count += _toMove;
                            if (idx >= 0)
                            {
                                UpdateLineItemText(
                                    listB.GetChild(resourcesA.IndexOf(sourceEntry) + 1),
                                    sourceEntry);
                            }
                            Root.SafeCall(OnTotalSelectedChanged, this);
                        };
                    }
                    else
                    {
                        existingEntry.Count += toMove;
                    }

                    UpdateColumn(listA, resourcesB);
                    UpdateLineItemText(lineItem, lambdaResource);

                    Root.SafeCall(OnTotalSelectedChanged, this);
                };

                listB.AddItem(lineItem);
            }
        }
        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();
        }
Beispiel #4
0
        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();
        }
        private void SetupList(WidgetListView rightList, WidgetListView leftList, List <ResourceAmount> sourceResources,
                               List <ResourceAmount> selectedResources)
        {
            foreach (var resource in sourceResources)
            {
                var lineItem = CreateLineItem(resource);

                var lambdaResource = resource;
                lineItem.TriggerOnChildClick = true;
                lineItem.OnClick             = (sender, args) =>
                {
                    if (lambdaResource.NumResources == 0)
                    {
                        return;
                    }

                    var toMove = 1;
                    if (args.Control)
                    {
                        toMove = lambdaResource.NumResources;
                    }
                    if (args.Shift)
                    {
                        toMove = Math.Min(5, lambdaResource.NumResources);
                    }
                    lambdaResource.NumResources -= toMove;

                    var existingEntry = selectedResources.FirstOrDefault(r => r.ResourceType == lambdaResource.ResourceType);
                    if (existingEntry == null)
                    {
                        existingEntry = new ResourceAmount(lambdaResource.ResourceType, 0);
                        selectedResources.Add(existingEntry);
                        var rightLineItem = CreateLineItem(existingEntry);
                        rightList.AddItem(rightLineItem);

                        rightLineItem.TriggerOnChildClick = true;
                        rightLineItem.OnClick             = (_sender, _args) =>
                        {
                            var _toMove = 1;
                            if (_args.Control)
                            {
                                _toMove = existingEntry.NumResources;
                            }
                            if (_args.Shift)
                            {
                                _toMove = Math.Min(5, existingEntry.NumResources);
                            }
                            existingEntry.NumResources -= _toMove;

                            if (existingEntry.NumResources == 0)
                            {
                                var index = selectedResources.IndexOf(existingEntry);
                                selectedResources.RemoveAt(index);
                                rightList.RemoveChild(rightList.GetChild(index + 1));
                            }

                            UpdateColumn(rightList, selectedResources);

                            var sourceEntry = sourceResources.FirstOrDefault(
                                r => r.ResourceType == existingEntry.ResourceType);
                            sourceEntry.NumResources += _toMove;
                            UpdateLineItemText(
                                leftList.GetChild(sourceResources.IndexOf(sourceEntry) + 1),
                                sourceEntry);

                            Root.SafeCall(OnTotalSelectedChanged, this);
                        };
                    }
                    existingEntry.NumResources += toMove;

                    UpdateColumn(rightList, selectedResources);
                    UpdateLineItemText(lineItem, lambdaResource);

                    Root.SafeCall(OnTotalSelectedChanged, this);
                };

                leftList.AddItem(lineItem);
            }
        }
Beispiel #6
0
        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();
        }
Beispiel #7
0
        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();
        }