Beispiel #1
0
        public static void RebuildLists(GameObject GO, InventoryScreenExtender.TabController TabController)
        {
            QudUX_InventoryScreenState SavedInventoryState = GO.RequirePart <QudUX_InventoryScreenState>();
            //TabController.RecalculateWeights(GO);
            Inventory pInventory = GO.GetPart("Inventory") as Inventory;

            CategoryMap.Clear();
            SelectionList.Clear();
            ItemsSkippedByFilter = 0;
            int  listHeightMinusOne = InventoryListHeight - 1;
            bool bIsFiltered        = (FilterString != "");

            if (!Categories.CleanContains("Category"))
            {
                Categories.Add("Category");
            }

            List <GameObject> Objs = pInventory.GetObjectsDirect();

            for (int x = 0; x < Objs.Count; x++)
            {
                GameObject Obj = Objs[x];
                if (!Obj.HasTag("HiddenInInventory"))
                {
                    string iCategory = Obj.GetInventoryCategory();
                    if (bIsFiltered && !Obj.GetCachedDisplayNameStripped().Contains(FilterString, CompareOptions.IgnoreCase))
                    {
                        ItemsSkippedByFilter++;
                        continue;
                    }
                    else if (!bIsFiltered)
                    {
                        if (TabController != null && !TabController.CurrentTabIncludes(iCategory))
                        {
                            //if we're not filtering by string, include only the categories associated with the current tab
                            continue;
                        }
                    }

                    Obj.Seen();

                    if (!CategoryList.ContainsKey(iCategory))
                    {
                        bool bExpandState = SavedInventoryState.GetExpandState(iCategory);
                        CategoryList.Add(iCategory, new QudUX_InventoryCategory(iCategory, bExpandState));
                        Categories.Add(iCategory);
                    }

                    if (!CategoryMap.ContainsKey(iCategory))
                    {
                        CategoryMap.Add(iCategory, new List <GameObject>());
                    }

                    CategoryMap[iCategory].Add(Obj);
                }
            }

            foreach (List <GameObject> MapList in CategoryMap.Values)
            {
                MapList.Sort(displayNameSorter);
            }

            while (CategorySort >= Categories.Count)
            {
                CategorySort--;
            }
            if (CategorySort == -1)
            {
                SortList = pInventory.GetObjects();
                SortList.Sort(displayNameSorter);
            }
            else
            if (Categories[CategorySort] == "Category")
            {
                SortList = pInventory.GetObjects();
                SortList.Sort(categorySorter);
            }
            else
            {
                if (CategoryMap.ContainsKey(Categories[CategorySort]))
                {
                    SortList = CategoryMap[Categories[CategorySort]];
                }
                SortList.Sort(displayNameSorter);
            }

            int nEntries = 0;

            bMore = false;
            if (CategorySort != -1 && Categories[CategorySort] == "Category")
            {
                CategorySelectionList.Clear();
                int nObject = 0;

                char c = 'a';

                List <string> CatNames = new List <string>();
                foreach (string N in CategoryList.Keys)
                {
                    CatNames.Add(N);
                }
                CatNames.Sort();

                for (int n = 0; n < CatNames.Count; n++)
                {
                    string sCat = CatNames[n];
                    QudUX_InventoryCategory Cat = CategoryList[sCat];

                    if (forceCategorySelect != null && Cat == forceCategorySelect)
                    {
                        if (nObject < StartObject)
                        {
                            StartObject = nObject;
                        }

                        nSelected           = nObject - StartObject;
                        forceCategorySelect = null;
                    }

                    if (nObject >= StartObject && nObject <= listHeightMinusOne + StartObject)
                    {
                        CategorySelectionList.Add(c, new QudUX_CategorySelectionListEntry(Cat));
                        c++;
                        nEntries++;
                    }

                    if (Cat.Expanded && CategoryMap.ContainsKey(Cat.Name))
                    {
                        foreach (GameObject Obj in CategoryMap[Cat.Name])
                        {
                            nObject++;
                            nEntries++;

                            if (nObject >= StartObject && nObject <= listHeightMinusOne + StartObject)
                            {
                                CategorySelectionList.Add(c, new QudUX_CategorySelectionListEntry(Obj));
                                c++;
                            }
                            else
                            if (nObject > listHeightMinusOne + StartObject)
                            {
                                bMore = true;
                                break;
                            }
                        }
                    }

                    if (CategoryList.ContainsKey(sCat))
                    {
                        CategoryList[sCat].Weight = 0;
                        CategoryList[sCat].Items  = 0;
                    }

                    if (CategoryMap.ContainsKey(Cat.Name))
                    {
                        foreach (GameObject Obj in CategoryMap[Cat.Name])
                        {
                            if (Obj.pPhysics != null)
                            {
                                CategoryList[sCat].Weight += Obj.pPhysics.Weight;
                            }
                            CategoryList[sCat].Items++;
                        }
                    }

                    if (nObject > listHeightMinusOne + StartObject)
                    {
                        bMore = true;
                        break;
                    }
                    nObject++;
                }
            }
            else
            {
                if (pInventory != null)
                {
                    int nObject = 0;

                    char c = 'a';

                    foreach (GameObject Obj in SortList)
                    {
                        if (nObject >= StartObject && nObject <= listHeightMinusOne + StartObject)
                        {
                            SelectionList.Add(c, Obj);
                            c++;
                        }
                        nObject++;

                        if (nObject > listHeightMinusOne + StartObject)
                        {
                            bMore = true;
                            break;
                        }
                    }
                }
            }

            List <string> RemovedCategories = new List <string>();

            foreach (string sCat in CategoryList.Keys)
            {
                if (!CategoryMap.ContainsKey(sCat))
                {
                    RemovedCategories.Add(sCat);
                }
                else
                if (CategoryMap[sCat].Count == 0)
                {
                    RemovedCategories.Add(sCat);
                }
            }

            foreach (string sRemovedCat in RemovedCategories)
            {
                if (CategoryList.ContainsKey(sRemovedCat))
                {
                    CategoryList.Remove(sRemovedCat);
                }
                if (CategoryMap.ContainsKey(sRemovedCat))
                {
                    CategoryMap.Remove(sRemovedCat);
                }
            }
        }