Esempio n. 1
0
        private Widget CreateLineItem(TradeableItem Resource)
        {
            var r = Root.ConstructWidget(new Gui.Widget
            {
                MinimumSize = new Point(1, 32),
                Background  = new TileReference("basic", 0)
            });

            r.AddChild(new Play.ResourceIcon()
            {
                MinimumSize         = new Point(32, 32),
                MaximumSize         = new Point(32, 32),
                Resource            = Resource.Prototype,
                AutoLayout          = AutoLayout.DockLeft,
                BackgroundColor     = Resource.Count > 0 ? Resource.Prototype.Tint.ToVector4() : new Vector4(0.5f, 0.5f, 0.5f, 0.5f),
                TextColor           = Color.White.ToVector4(),
                TextHorizontalAlign = HorizontalAlign.Right,
                TextVerticalAlign   = VerticalAlign.Bottom
            });

            r.AddChild(new Gui.Widget
            {
                AutoLayout          = AutoLayout.DockLeft,
                MinimumSize         = new Point(128 / GameSettings.Current.GuiScale, 0),
                MaximumSize         = new Point(128 / GameSettings.Current.GuiScale, 32),
                TextColor           = Resource.Count > 0 ? Color.Black.ToVector4() : new Vector4(0.5f, 0.5f, 0.5f, 0.5f),
                TextVerticalAlign   = VerticalAlign.Center,
                TextHorizontalAlign = HorizontalAlign.Left,
                HoverTextColor      = GameSettings.Current.Colors.GetColor("Highlight", Color.DarkRed).ToVector4(),
                Font = GameSettings.Current.GuiScale == 1 ? "font10" : "font8",
                ChangeColorOnHover = true,
                WrapText           = true
            });

            r.AddChild(new Gui.Widget
            {
                AutoLayout = AutoLayout.DockRight,
                //Text = String.Format("{0} at ${1}e", Resource.NumResources, resourceInfo.MoneyValue),
                //Font = "font18-outline",
                //TextColor = new Vector4(1,1,1,1),
                TextColor         = Resource.Count > 0 ? Color.Black.ToVector4() : new Vector4(0.5f, 0.5f, 0.5f, 0.5f),
                TextVerticalAlign = VerticalAlign.Center,
                HoverTextColor    = GameSettings.Current.Colors.GetColor("Highlight", Color.DarkRed).ToVector4(),
                Font = GameSettings.Current.GuiScale == 1 ? "font10" : "font8",
                ChangeColorOnHover = true,
            });


            r.Layout();
            UpdateLineItemText(r, Resource);

            return(r);
        }
Esempio n. 2
0
 private void UpdateLineItemText(Widget LineItem, TradeableItem Resource)
 {
     if (Resource.Prototype != null)
     {
         var font  = LineItem.Root.GetTileSheet("font10");
         var label = Resource.Prototype.DisplayName;
         if (font != null)
         {
             Point measurements = font.MeasureString(label);
             label = font.WordWrapString(label, 1.0f, 128 / GameSettings.Current.GuiScale, LineItem.WrapWithinWords);
             if (128 / GameSettings.Current.GuiScale < measurements.X)
             {
                 LineItem.MinimumSize.Y = font.TileHeight * label.Split('\n').Length;
             }
         }
         LineItem.GetChild(1).Text = label;
         LineItem.GetChild(1).Invalidate();
         LineItem.GetChild(2).Text = String.Format("{0}", ValueSourceEntity.ComputeValue(Resource.Prototype));
         LineItem.GetChild(0).Text = Resource.Count.ToString();
         LineItem.GetChild(0).Invalidate();
         LineItem.Tooltip = Resource.Prototype.DisplayName + "\n" + Resource.Prototype.Description;
         for (int i = 0; i < 3; i++)
         {
             if (i > 0)
             {
                 LineItem.GetChild(i).TextColor = Resource.Count > 0
                     ? Color.Black.ToVector4()
                     : new Vector4(0.5f, 0.5f, 0.5f, 0.5f);
             }
             LineItem.GetChild(i).BackgroundColor = Resource.Count > 0
                 ? Resource.Prototype.Tint.ToVector4()
                 : new Vector4(0.5f, 0.5f, 0.5f, 0.5f);
             LineItem.GetChild(i).Tooltip = Resource.Prototype.DisplayName + "\n" + Resource.Prototype.Description;
             LineItem.GetChild(i).Invalidate();
         }
     }
 }
Esempio n. 3
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);
            }
        }