Esempio n. 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();
 }
Esempio n. 2
0
        private void SetupList(WidgetListView listA, WidgetListView listB, List <TradeableItem> resourcesA, List <TradeableItem> 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;
                    }

                    var movedItems = lambdaResource.Resources.Take(toMove).ToList();
                    lambdaResource.Resources.RemoveRange(0, toMove);
                    SoundManager.PlaySound(ContentPaths.Audio.Oscar.sfx_gui_change_selection, 0.1f, MathFunctions.Rand() * 0.25f);

                    var existingEntry = resourcesB.FirstOrDefault(r => r.Prototype.DisplayName == lambdaResource.Prototype.DisplayName);
                    if (existingEntry == null)
                    {
                        existingEntry = new TradeableItem {
                            Resources = movedItems, ResourceType = lambdaResource.ResourceType, Prototype = movedItems[0]
                        };
                        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;
                            }

                            var _movedItems = existingEntry.Resources.Take(_toMove).ToList();
                            existingEntry.Resources.RemoveRange(0, _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.ResourceType == existingEntry.ResourceType);
                            int idx         = resourcesA.IndexOf(sourceEntry);
                            sourceEntry.Resources.AddRange(_movedItems);
                            if (idx >= 0)
                            {
                                UpdateLineItemText(
                                    listB.GetChild(resourcesA.IndexOf(sourceEntry) + 1),
                                    sourceEntry);
                            }
                            Root.SafeCall(OnTotalSelectedChanged, this);
                        };
                    }
                    else
                    {
                        existingEntry.Resources.AddRange(movedItems);
                    }

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

                    Root.SafeCall(OnTotalSelectedChanged, this);
                };

                listB.AddItem(lineItem);
            }
        }
Esempio n. 3
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();
        }
Esempio n. 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;
                }

                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();
        }