Beispiel #1
0
        void Populate()
        {
            IEnumerable <InventoryCollectible> items    = null;
            IEnumerable <InventoryCollectible> catItems = null;

            if (!ShowAllItems)
            {
                Table.Clear();
                m_existingItems.Clear();
            }

            if (!string.IsNullOrEmpty(CatalogName))
            {
                catItems = Inventory.Instance.GetItemsFromCatalog(CatalogName, ShowAllItems);
            }
            else if (!string.IsNullOrEmpty(ItemAttribute))
            {
                catItems = Inventory.Instance.GetItemsWithAttributes(ItemAttribute, ShowAllItems);
            }

            if (catItems != null)
            {
                items = catItems != null?catItems.OrderBy(_i => _i.Collectible.InventoryOrder.GetValueOrDefault(99999)) : catItems;
            }
            else
            {
                items = Inventory.Instance.AllItems;
            }

            int itemIdx = 0;

            if (items == null)
            {
                return;
            }

            foreach (var item in items)
            {
                if (item.Collectible != null)
                {
                    InventoryTableItem obj = null;

                    m_existingItems.TryGetValue(item.Collectible.Id, out obj);

                    if (!obj)
                    {
                        obj = Table.AddItem <InventoryTableItem>(ItemPrefab);
                        m_existingItems[item.Collectible.Id] = obj;
                    }

                    obj.Populate(item);

                    itemIdx++;
                }
            }
        }
        protected override void SelectItem(InventoryTableItem item)
        {
            IEnumerable <Recipe> recipes;

            if (NeedActivatedRecipeToCraft)
            {
                recipes = ActivatedRecipeManager.Instance.GetRecipesForCollectible(item.InventoryCollectible.Collectible.Id);
            }
            else
            {
                recipes = RecipeDirectory.Instance.GetRecipesForCollectible(item.InventoryCollectible.Collectible.Id);
            }

            // For now only look at one recipe per collectible
            var recipe = (recipes == null) ? null : recipes.FirstOrDefault();

            if (recipe != null)
            {
                PopulateComponent <ExecuteRecipeComponent>(recipe);
            }
            else
            {
                var recipeExists = RecipeDirectory.Instance.HasRecipes(item.InventoryCollectible.Collectible.Id);
                if (recipeExists)
                {
                    if (OnSelectPlayerNeedsRecipe != null)
                    {
                        OnSelectPlayerNeedsRecipe.Invoke();
                    }
                }
                else
                {
                    if (OnSelectNotCraftableItem != null)
                    {
                        OnSelectNotCraftableItem.Invoke();
                    }
                }
            }
        }
        public override void Populate()
        {
            if (!PrePopulated)
            {
                Table.Clear();
            }
            else
            {
                foreach (var item in Table.GetComponentsInChildren <InventoryTableItem>())
                {
                    if (item.EmptyObject)
                    {
                        item.EmptyObject.SetActive(true);
                    }

                    if (item.PopulatedObject)
                    {
                        item.PopulatedObject.SetActive(false);
                    }
                }
            }

            IEnumerable <InventoryCollectible> items = null;

            if (ItemAttributesFilter != null && ItemAttributesFilter.Count() > 0)
            {
                items = Inventory.Instance.GetItemsWithAttributes(ItemAttributesFilter, ShowAllItems);
            }
            else if (ShowAllItems)
            {
                items = Inventory.Instance.GetItems(CollectibleDirectory.Instance.AllItems);
            }
            else
            {
                items = Inventory.Instance.AllItems;
            }
            items = FilterItems(items);

            int itemIdx = 0;

            InventoryTableItem selectItem = null;

            if (PrePopulated)
            {
                for (int i = 0; i < Table.transform.childCount; i++)
                {
                    var item = Table.transform.GetChild(i).GetComponent <InventoryTableItem>();

                    if (item)
                    {
                        item.OnSelected.RemoveAllListeners();

                        item.PopulatedObject.SetActive(false);
                    }
                }
            }

            foreach (var item in items)
            {
                if (item.Collectible != null)
                {
                    InventoryTableItem obj = null;

                    if (PrePopulated)
                    {
                        int idx = item.Collectible.InventoryOrder.GetValueOrDefault(itemIdx);

                        if (idx >= Table.transform.childCount)
                        {
                            continue;
                        }

                        obj = Table.transform.GetChild(idx).gameObject.GetComponent <InventoryTableItem>();

                        if (!obj)
                        {
                            return;
                        }

                        obj.OnSelected.AddListener(() => { SelectItem(obj); });
                    }
                    else
                    {
                        obj = AddSelectableItem(InventoryItem, (_item) => { SelectItem(_item); });
                    }

                    obj.Populate(item);

                    itemIdx++;

                    if (selectItem == null)
                    {
                        selectItem = obj;
                    }
                    else if (item.Collectible.Id == m_selectedItemId)
                    {
                        selectItem = obj;
                    }
                }

                if (selectItem != null && AutoSelectItem)
                {
                    m_selectedItemId = selectItem.Collectible.Id;

                    selectItem.Select();
                }
            }
        }
 protected virtual void SelectItem(InventoryTableItem item)
 {
     PopulateComponent <InventoryDetailsComponent>(item);
 }