Ejemplo n.º 1
0
 /// <summary>
 /// Updates all elements in the specified category.
 /// </summary>
 /// <param name="inv">The inventory of discovered elements.</param>
 /// <param name="category">The category to search.</param>
 /// <param name="overrideName">The name to override the category title</param>
 private void UpdateCategory(WorldInventory inv, Tag category,
                             string overrideName = null)
 {
     if (inv.TryGetDiscoveredResourcesFromTag(category, out HashSet <Tag> found) &&
         found.Count > 0)
     {
         // Attempt to add to type select control
         if (!children.TryGetValue(category, out TypeSelectCategory current))
         {
             current = new TypeSelectCategory(this, category, overrideName);
             children.Add(category, current);
             int        index = 1 + (children.IndexOfKey(category) << 1);
             GameObject header = current.Header, panel = current.ChildPanel;
             // Header goes in even indexes, panel goes in odds
             header.SetParent(childPanel);
             PUIElements.SetAnchors(header, PUIAnchoring.Stretch, PUIAnchoring.Stretch);
             header.transform.SetSiblingIndex(index);
             panel.SetParent(childPanel);
             PUIElements.SetAnchors(panel, PUIAnchoring.Stretch, PUIAnchoring.Stretch);
             panel.transform.SetSiblingIndex(index + 1);
         }
         foreach (var element in found)
         {
             current.TryAddType(element);
         }
     }
 }
Ejemplo n.º 2
0
        protected override void OnSpawn()
        {
            base.OnSpawn();
            // One long linear row
            var panel = new PPanel("MoreModActions")
            {
                BackColor = PUITuning.Colors.DialogDarkBackground, Spacing = 6,
                BackImage = PUITuning.Images.BoxBorder, ImageMode = Image.Type.Sliced,
                Direction = PanelDirection.Horizontal, Margin = new RectOffset(6, 6, 6, 6)
            }.AddChild(MakeButton("MoveToFirst", UI.TOOLTIPS.DNI_TOP,
                                  SpriteRegistry.GetTopIcon(), OnMoveFirst, (obj) =>
                                  buttonFirst = obj.GetComponent <KButton>()))
            .AddChild(MakeButton("MoveUpTen", UI.TOOLTIPS.DNI_UP,
                                 Assets.GetSprite("icon_priority_up_2"), OnMoveUp, (obj) =>
                                 buttonUp = obj.GetComponent <KButton>()))
            .AddChild(MakeButton("MoveDownTen", UI.TOOLTIPS.DNI_DOWN,
                                 Assets.GetSprite("icon_priority_down_2"), OnMoveDown, (obj) =>
                                 buttonDown = obj.GetComponent <KButton>()))
            .AddChild(MakeButton("MoveToLast", UI.TOOLTIPS.DNI_BOTTOM,
                                 SpriteRegistry.GetBottomIcon(), OnMoveLast, (obj) =>
                                 buttonLast = obj.GetComponent <KButton>()))
            .AddChild(new PButton("ManageMod")
            {
                Text    = UI.MODSSCREEN.BUTTON_SUBSCRIPTION, DynamicSize = false,
                OnClick = OnManage, ToolTip = "Manage Mod", Margin = DebugUtils.BUTTON_MARGIN
            }.SetKleiBlueStyle().AddOnRealize((obj) => buttonManage = obj))
            .AddChild(new PButton("UnsubMod")
            {
                Text    = UI.MODSSCREEN.BUTTON_UNSUB, DynamicSize = false,
                OnClick = OnUnsub, ToolTip = UI.TOOLTIPS.DNI_UNSUB, Margin = DebugUtils.
                                                                             BUTTON_MARGIN
            }.SetKleiBlueStyle().AddOnRealize((obj) => buttonUnsub = obj.
                                                                     GetComponent <KButton>()));

#if DEBUG
            panel.AddChild(new PButton("ModifyMod")
            {
                Text    = UI.MODSSCREEN.BUTTON_MODIFY, DynamicSize = false,
                OnClick = OnModify, ToolTip = UI.TOOLTIPS.DNI_MODIFY, Margin = DebugUtils.
                                                                               BUTTON_MARGIN
            }.SetKleiPinkStyle().AddOnRealize((obj) => buttonModify = obj.
                                                                      GetComponent <KButton>()));
#endif
            var actionsObj = panel.AddTo(gameObject);
#if DEBUG
            PButton.SetButtonEnabled(buttonModify.gameObject, false);
#endif
            actionsObj.SetActive(false);
            // Blacklist from auto layout
            actionsObj.AddOrGet <LayoutElement>().ignoreLayout = true;
            PUIElements.SetAnchors(actionsObj, PUIAnchoring.End, PUIAnchoring.Center);
            unsubCaller = new CallResult <RemoteStorageUnsubscribePublishedFileResult_t>(
                OnUnsubComplete);
            actionsScreen = actionsObj.AddComponent <ModActionsScreen>();
            callingButton = null;
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Updates the list of available elements.
        /// </summary>
        public void Update(GridFilterableSideScreen screen)
        {
            Console.WriteLine("updating with the storage");
            Storage    storage = screen.storage;
            GameObject target  = screen.target;

            if (storage.storageFilters != null && storage.storageFilters.Count >= 1)
            {
                // check for which ones aren't added already and add them
                foreach (Tag tag in storage.storageFilters)
                {
                    Console.WriteLine($"Should be checking presence of tag {tag.ToString()}");
                    if (!HasElement(tag))
                    {
                        Console.WriteLine($"Attempted to add {tag.ToString()} to the panel");
                        if (children.Count <= 0)
                        {
                            GridFilterableRow firstRow = new GridFilterableRow(this);
                            children.Add(firstRow);
                            PUIElements.SetParent(firstRow.ChildPanel, childPanel);
                            PUIElements.SetAnchors(firstRow.ChildPanel, PUIAnchoring.Stretch, PUIAnchoring.Stretch);
                        }
                        GridFilterableRow lastRow = children[children.Count - 1];
                        if (lastRow.RowSize >= PER_ROW)
                        {
                            lastRow = new GridFilterableRow(this);
                            PUIElements.SetParent(lastRow.ChildPanel, childPanel);
                            PUIElements.SetAnchors(lastRow.ChildPanel, PUIAnchoring.Stretch, PUIAnchoring.Stretch);
                            children.Add(lastRow);
                        }
                        GridFilterableSelectableEntity entity = new GridFilterableSelectableEntity(lastRow, tag);
                        lastRow.Children.Add(entity);
                        PUIElements.SetParent(entity.CheckBox, lastRow.ChildPanel);
                        if (PCheckBox.GetCheckState(entity.CheckBox) == PCheckBox.STATE_CHECKED)
                        {
                            // Set to checked
                            PCheckBox.SetCheckState(entity.CheckBox, PCheckBox.STATE_CHECKED);
                        }
                    }
                }
            }
            else
            {
                Debug.LogError((object)"If you're filtering, your storage filter should have the filters set on it");
            }
        }
        /// <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();
        }