Example #1
0
        private void addCategory(string title, string icon, string colour)
        {
            customCategory c = new customCategory(title, icon, colour);

            c.initialise();

            customSubCategory dummySC = new customSubCategory("all", title, "");

            dummySC.initialise();
        }
Example #2
0
        void Awake()
        {
            instance = this;
            Log("Version 1.16");

            // Add event for when the Editor GUI becomes active. This is never removed because we need it to fire every time
            GameEvents.onGUIEditorToolbarReady.Add(editor);

            // generate the associations between parts and folders, create all the mod categories, get all propellant combinations
            associateParts();

            // mod categories key: title, value: folder
            // used for adding the folder check to subCategories
            Dictionary <string, string> folderToCategoryDict = new Dictionary <string, string>();

            // load all category configs
            foreach (ConfigNode node in GameDatabase.Instance.GetConfigNodes("CATEGORY"))
            {
                customCategory C = new customCategory(node);
                if (Categories.Find(n => n.categoryName == C.categoryName) == null)
                {
                    Categories.Add(C);
                    if (C.value != null)
                    {
                        if (!folderToCategoryDict.ContainsKey(C.categoryName))
                        {
                            folderToCategoryDict.Add(C.categoryName, C.value.Trim());
                        }
                    }
                }
            }

            List <customSubCategory> editList = new List <customSubCategory>();

            // load all subCategory configs
            foreach (ConfigNode node in GameDatabase.Instance.GetConfigNodes("SUBCATEGORY"))
            {
                // if multiple categories are specified, create multiple subCategories
                string[] categories = node.GetValue("category").Split(',');
                foreach (string s in categories)
                {
                    customSubCategory sC = new customSubCategory(node, s.Trim());
                    if (sC.hasFilters && folderToCategoryDict.ContainsKey(sC.category))
                    {
                        foreach (Filter f in sC.filters)
                        {
                            f.checks.Add(new Check("folder", folderToCategoryDict[sC.category]));
                        }
                    }
                    if (sC.hasFilters && checkForConflicts(sC))
                    {
                        subCategories.Add(sC);
                    }
                    if (!sC.hasFilters)
                    {
                        editList.Add(sC);
                    }
                }
            }
            customSCEditDelete(editList);

            foreach (KeyValuePair <string, customSubCategory> kvp in categoryAllSub)
            {
                customSubCategory sC = kvp.Value;
                if (folderToCategoryDict.ContainsKey(kvp.Key))
                {
                    foreach (Filter f in sC.filters)
                    {
                        f.checks.Add(new Check("folder", folderToCategoryDict[sC.category]));
                    }
                }

                subCategories.Insert(0, sC);
            }

            checkForEmptySubCategories();
            loadIcons();
        }
Example #3
0
        /// <summary>
        /// turn the loaded category and subcategory nodes into useable data
        /// </summary>
        private void processFilterDefinitions()
        {
            ConfigNode[] nodes = GameDatabase.Instance.GetConfigNodes("CATEGORY");
            for (int i = 0; i < nodes.Length; i++)
            {
                ConfigNode node = nodes[i];
                customCategory C = new customCategory(node);
                if (C.subCategories == null)
                    continue;
                if (!Categories.Any(n => n.categoryName == C.categoryName))
                    Categories.Add(C);
            }

            //load all subCategory configs
            nodes = GameDatabase.Instance.GetConfigNodes("SUBCATEGORY");
            for (int i = 0; i < nodes.Length; i++)
            {
                ConfigNode node = nodes[i];
                customSubCategory sC = new customSubCategory(node);
                if (!sC.hasFilters || string.IsNullOrEmpty(sC.subCategoryTitle))
                    continue;

                customSubCategory subcategory;
                if (subCategoriesDict.TryGetValue(sC.subCategoryTitle, out subcategory)) // if something does have the same title
                    subcategory.filters.AddRange(sC.filters);
                else // if nothing else has the same title
                    subCategoriesDict.Add(sC.subCategoryTitle, sC);
            }

            customCategory Cat = Categories.Find(C => C.categoryName == "Filter by Resource");
            if (Cat != null)
            {
                for (int i = 0; i < resources.Count; i++)
                {
                    string s = resources[i];
                    // add spaces before each capital letter
                    string name = System.Text.RegularExpressions.Regex.Replace(s, @"\B([A-Z])", " $1");

                    customSubCategory subcategory;
                    if (subCategoriesDict.TryGetValue(name, out subcategory))
                    {
                        // if the collision is already looking for the specified resource
                        if (customSubCategory.checkForCheckMatch(subcategory, CheckType.resource, s))
                            continue;
                        name = "res_" + name;
                    }
                    if (!string.IsNullOrEmpty(name) && !subCategoriesDict.ContainsKey(name))
                    {
                        customSubCategory sC = new customSubCategory(name, name);
                        Check c = new Check("resource", s);
                        Filter f = new Filter(false);
                        f.checks.Add(c);
                        sC.filters.Add(f);
                        subCategoriesDict.Add(name, sC);
                    }
                    if (!string.IsNullOrEmpty(name))
                        Cat.subCategories.AddUnique(new subCategoryItem(name));
                }
            }

            for (int i = 0; i < Categories.Count; i++)
            {
                customCategory C = Categories[i];
                if (C == null || !C.all)
                    continue;

                List<Filter> filterList = new List<Filter>();
                if (C.subCategories != null)
                {
                    for (int j = 0; j < C.subCategories.Count; j++)
                    {
                        subCategoryItem s = C.subCategories[j];
                        if (s == null)
                            continue;

                        customSubCategory subcategory;
                        if (subCategoriesDict.TryGetValue(s.subcategoryName, out subcategory))
                            filterList.AddUniqueRange(subcategory.filters);
                    }
                }
                customSubCategory newSub = new customSubCategory("All parts in " + C.categoryName, C.iconName);
                newSub.filters = filterList;
                subCategoriesDict.Add(newSub.subCategoryTitle, newSub);
                C.subCategories.Insert(0, new subCategoryItem(newSub.subCategoryTitle));
            }
        }