Example #1
0
        internal void ProcessRequest(PortObject requestor, PortFilter request)
        {
            if (requestor.AttachedChest == null)
            {
                return;
            }

            int amountHave   = requestor.AmountMatching(request);
            int amountNeeded = request.RequestAmount - amountHave;

            if (amountNeeded <= 0)
            {
                return;
            }

            foreach (PortObject provider in Ports)
            {
                if (provider == requestor)
                {
                    continue;
                }
                requestor.RequestFrom(provider, request, ref amountNeeded);
                if (amountNeeded <= 0)
                {
                    break;
                }
            }
        }
Example #2
0
        internal PortFilterComponent(PortFilter filter, PortFilterType type, PortDeleteFilter onDeleted)
        {
            this.Filter = filter;

            int selected = 0;

            if (ItemCategories.NumToName.TryGetValue(this.Filter.Category, out string category))
            {
                selected = ItemCategories.Names.IndexOf(category);
            }

            this.Dropdown = new DropdownComponent(ItemCategories.Names, "", 300)
            {
                visible = true, SelectionIndex = selected
            };
            this.Dropdown.DropDownOptionSelected += DropDownOptionSelected;

            this.DeleteButton = new ButtonComponent("", Sprites.Icons.Sheet, Sprites.Icons.Clear, 2, true)
            {
                visible = true, HoverText = "Delete"
            };
            this.DeleteButton.ButtonPressed += () => onDeleted(Filter);

            if (type == PortFilterType.REQUESTS)
            {
                BuildSlider();
            }
        }
Example #3
0
        internal void AddFilter()
        {
            PortFilter filter = new PortFilter();

            Filters.Add(filter);
            Components.Add(new PortFilterComponent(filter, Type, DeleteFilter));
            OnChanged();
        }
Example #4
0
        internal void DeleteFilter(PortFilter filter)
        {
            int index = Filters.IndexOf(filter);

            Filters.RemoveAt(index);
            Components.RemoveAt(index);
            OnChanged();
            Game1.playSound("hammer");
        }