Esempio n. 1
0
        public override void SetTarget(GameObject target)
        {
            this.target = target;
            if (target == null)
            {
                PUtil.LogError("The target object provided was null");
                return;
            }

            targetFilterable = target.GetComponent <UncategorizedFilterable>();
            if (targetFilterable == null)
            {
                PUtil.LogError("The target provided does not have a Uncategorized Filterable component");
                return;
            }

            if (!targetFilterable.showUserMenu || (IsStorage && !storage.showInUI))
            {
                DetailsScreen.Instance.DeactivateSideContent();
            }
            else
            {
                storage = targetFilterable.GetComponent <Storage>();
                if (control == null)
                {
                    InitSideScreen();
                }
                control.Update(target);
            }
        }
        private static void OnCopySettings(UncategorizedFilterable filterable, object data)
        {
            UncategorizedFilterable component = ((GameObject)data).GetComponent <UncategorizedFilterable>();

            if (component == null)
            {
                return;
            }
            filterable.UpdateFilters(component.GetTags());
        }
Esempio n. 3
0
        public void Initialize(UncategorizedFilterable target)
        {
            if (target == null)
            {
                PUtil.LogError("UNCATEGORIZED SELECT CONTROL: provided was null.");
            }

            PUtil.LogDebug("UNCATEGORIZED SELECT CONTROL: Initialized");
            targetFilterable = target;
            gameObject.SetActive(true);
        }
        public UncategorizedFilteredStorage(
            KMonoBehaviour root,
            Tag[] required_tags,
            Tag[] forbidden_tags,
            IUserControlledCapacity capacity_control,
            bool use_logic_meter,
            ChoreType fetch_chore_type)
        {
            this.root            = root;
            this.requiredTags    = required_tags;
            this.forbiddenTags   = forbidden_tags;
            this.capacityControl = capacity_control;
            this.useLogicMeter   = use_logic_meter;
            this.choreType       = fetch_chore_type;
            root.Subscribe(-1697596308, new Action <object>(OnStorageChanged));
            root.Subscribe(-543130682, new Action <object>(OnUserSettingsChanged));
            this.filterable             = root.FindOrAdd <UncategorizedFilterable>();
            filterable.OnFilterChanged += new Action <Tag[]>(OnFilterChanged);
            this.storage = root.GetComponent <Storage>();
            storage.Subscribe(644822890, new Action <object>(OnOnlyFetchMarkedItemsSettingChanged));
            if (capacityStatusItem == null)
            {
                capacityStatusItem = new StatusItem("StorageLocker", "BUILDING", string.Empty, StatusItem.IconType.Info, NotificationType.Neutral, false, OverlayModes.None.ID, true, 129022);
                capacityStatusItem.resolveStringCallback = (str, data) =>
                {
                    UncategorizedFilteredStorage filteredStorage = (UncategorizedFilteredStorage)data;
                    float  amountStored = filteredStorage.GetAmountStored();
                    float  b            = filteredStorage.storage.capacityKg;
                    string newValue1    = Util.FormatWholeNumber(amountStored <= b - filteredStorage.storage.storageFullMargin || amountStored >= b ? Mathf.Floor(amountStored) : b);
                    IUserControlledCapacity component = filteredStorage.root.GetComponent <IUserControlledCapacity>();
                    if (component != null)
                    {
                        b = Mathf.Min(component.UserMaxCapacity, b);
                    }
                    string newValue2 = Util.FormatWholeNumber(b);
                    str = str.Replace("{Stored}", newValue1);
                    str = str.Replace("{Capacity}", newValue2);
                    str = component == null?str.Replace("{Units}", (string)GameUtil.GetCurrentMassUnit(false)) : str.Replace("{Units}", (string)component.CapacityUnits);

                    return(str);
                };
                noFilterStatusItem = new StatusItem("NoStorageFilterSet", "BUILDING", "status_item_no_filter_set", StatusItem.IconType.Custom, NotificationType.BadMinor, false, OverlayModes.None.ID, true, 129022);
            }
            root.GetComponent <KSelectable>().SetStatusItem(Db.Get().StatusItemCategories.Main, capacityStatusItem, this);
        }
Esempio n. 5
0
        private void OnCheck(GameObject source, int state)
        {
            UncategorizedFilterable uncategorizedFilterable = Parent.Parent.Target.GetComponent <UncategorizedFilterable>();

            switch (state)
            {
            case PCheckBox.STATE_UNCHECKED:
                // Clicked when unchecked, check and possibly check all
                PCheckBox.SetCheckState(CheckBox, PCheckBox.STATE_CHECKED);
                uncategorizedFilterable.AddTagToFilter(ElementTag);
                break;

            default:
                // Clicked when checked, clear and possibly uncheck
                PCheckBox.SetCheckState(CheckBox, PCheckBox.STATE_UNCHECKED);
                uncategorizedFilterable.RemoveTagFromFilter(ElementTag);
                break;
            }
            Parent.UpdateFromChildren();
        }
        /// <summary>
        /// Updates the list of available elements.
        /// </summary>
        public void Update(GameObject target)
        {
            Target = target;
            Storage storage = Target.GetComponent <Storage>();

            if (storage.storageFilters == null || storage.storageFilters.Count < 1)
            {
                PUtil.LogError("If you're filtering, your storage filter should have the filters set on it");
                return;
            }

            HashSet <Tag> containedTags = ContainedTags();
            HashSet <Tag> goalTags      = new HashSet <Tag>(storage.storageFilters.Where(tag => WorldInventory.Instance.IsDiscovered(tag)));

            // if this is not supposed to display the exact same UI elements rebuild the entire UI
            // not the *most* performant way to handle things but trying to perform multiple insertions/deletions into this
            // row system is probably *less* performant
            if (!containedTags.SetEquals(goalTags))
            {
                // clear the UI
                foreach (var row in rows)
                {
                    // null the parent of the entity and disable it
                    foreach (var entity in row.entities)
                    {
                        PUIElements.SetParent(entity.CheckBox, null);
                        entity.CheckBox.SetActive(false);
                        entity.Parent = null;
                    }
                    // clear all the entities from this row
                    row.entities.Clear();
                    // do not null the parent of the row since it will be reused in same spot but do disable it
                    row.ChildPanel.SetActive(false);
                }

                // build the UI with tags in alphabetic order
                List <Tag> goalList = goalTags.ToList();
                goalList.Sort(TagAlphabetComparer.INSTANCE);
                int rowIndex = 0;
                foreach (Tag tag in goalList)
                {
                    // wrap around when rows are full
                    if (rowIndex < rows.Count && rows[rowIndex].RowSize >= PER_ROW)
                    {
                        rowIndex++;
                    }
                    // build new rows as needed
                    if (rows.Count <= rowIndex)
                    {
                        UncategorizedFilterableRow newRow = new UncategorizedFilterableRow(this);
                        rows.Add(newRow);
                        PUIElements.SetParent(newRow.ChildPanel, childPanel);
                        PUIElements.SetAnchors(newRow.ChildPanel, PUIAnchoring.Stretch, PUIAnchoring.Stretch);
                    }
                    var row = rows[rowIndex];
                    row.ChildPanel.SetActive(true);
                    // build new entity for tag when it is first encountered
                    if (!entities.ContainsKey(tag))
                    {
                        UncategorizedFilterableEntity newEntity = new UncategorizedFilterableEntity(null, tag, tag.ProperName());
                        if (PCheckBox.GetCheckState(newEntity.CheckBox) == PCheckBox.STATE_CHECKED)
                        {
                            // Set to checked
                            PCheckBox.SetCheckState(newEntity.CheckBox, PCheckBox.STATE_CHECKED);
                        }
                        entities[tag] = newEntity;
                    }
                    var entity = entities[tag];
                    row.entities.Add(entity);
                    PUIElements.SetParent(entity.CheckBox, row.ChildPanel);
                    entity.CheckBox.SetActive(true);
                    entity.Parent = row;
                }
            }

            // with the right elements in the UI it is now necessary to set the properties for each entity correctly based on
            // if they are checked already and if they are present in the world
            UncategorizedFilterable filterable = Target.GetComponent <UncategorizedFilterable>();

            foreach (var row in rows)
            {
                foreach (var entity in row.entities)
                {
                    // set checkbox state
                    if (filterable.AcceptedTags.Contains(entity.ElementTag))
                    {
                        PCheckBox.SetCheckState(entity.CheckBox, PCheckBox.STATE_CHECKED);
                    }
                    else
                    {
                        PCheckBox.SetCheckState(entity.CheckBox, PCheckBox.STATE_UNCHECKED);
                    }
                    // set active state
                    var button = entity.CheckBox.GetComponentInChildren <KButton>();
                    button.isInteractable = WorldInventory.Instance.GetTotalAmount(entity.ElementTag) > 0.0;
                }
            }
            UpdateFromChildren();
        }