Beispiel #1
0
        private bool filterCategoriesMulti(AvailablePart part, PartCategories[] categories, int index)
        {
            if (index >= KerbetrotterConfiguration.Instance().FilterSettings.Length)
            {
                Debug.LogError("[KerbetrotterTools] invalid index for category filter: " + index);
                return(false);
            }

            KerbetrotterFilterSettings filterSettings = KerbetrotterConfiguration.Instance().FilterSettings[index];

            //return false when the part is not included by the filter
            if (!part.name.StartsWith(filterSettings.IncludeFilter) || (!string.IsNullOrEmpty(filterSettings.ExcludeFilter) && part.name.StartsWith(filterSettings.ExcludeFilter)))
            {
                return(false);
            }
            for (int i = 0; i < categories.Length; i++)
            {
                if (partCategories[index][part.name] == categories[i])
                {
                    return(true);
                }
            }

            return(false);
        }
        // The constructor for this class reading the settings
        private KerbetrotterConfiguration()
        {
            Debug.Log("[KerbetrotterTools]Init settings");

            ConfigNode[] nodes = null;


            //try to get the config node
            try
            {
                nodes = GameDatabase.Instance.GetConfigNodes("KerbetrotterFilterConfig");
            }
            catch (Exception e)
            {
                Debug.Log("[KerbetrotterTools]Config node Exception: " + e.Message);
            }

            //when ne node is null, report an error
            if (nodes == null)
            {
                Debug.Log("[KerbetrotterTools] ERROR config node is null");
            }

            //try to read and set all the settings
            try
            {
                filterSettings = new KerbetrotterFilterSettings[nodes.Length];

                for (int i = 0; i < nodes.Length; i++)
                {
                    bool showModFilter = bool.Parse(nodes[i].GetValue("showModCategory"));
                    bool showSeparateFunctionCategory = bool.Parse(nodes[i].GetValue("separateFunctionFilter"));

                    string modName        = nodes[i].GetValue("name");
                    string includedFilter = nodes[i].GetValue("includeFilter");
                    string excludedFilter = nodes[i].GetValue("excludeFilter");

                    bool disableForCCK = false;

                    string exlcudeWithCCKStr = nodes[i].GetValue("disableForCCK");
                    if (!string.IsNullOrEmpty(exlcudeWithCCKStr))
                    {
                        disableForCCK = bool.Parse(exlcudeWithCCKStr);
                    }

                    Color color = new Color(0.5f, 0.5f, 0.5f);

                    string colorStr = nodes[i].GetValue("iconColor");
                    if (!string.IsNullOrEmpty(colorStr))
                    {
                        string[] colorStrings = colorStr.Split(',');
                        if (colorStrings.Length == 3)
                        {
                            try
                            {
                                float r = float.Parse(colorStrings[0], CultureInfo.InvariantCulture.NumberFormat);
                                float g = float.Parse(colorStrings[1], CultureInfo.InvariantCulture.NumberFormat);
                                float b = float.Parse(colorStrings[2], CultureInfo.InvariantCulture.NumberFormat);
                                color = new Color(r, g, b);
                            }
                            catch
                            {
                                Debug.LogError("[KerbetrotterTools] Invalid color definition");
                            }
                        }
                    }

                    bool   filterLifeSupport    = false;
                    string filterLifeSupportStr = nodes[i].GetValue("filterLifeSupport");
                    if (!string.IsNullOrEmpty(filterLifeSupportStr))
                    {
                        filterLifeSupport = bool.Parse(filterLifeSupportStr);
                    }

                    bool   oneFilterOnly       = false;
                    string oneFilterOnlyString = nodes[i].GetValue("showInOneCategoryOnly");
                    if (!string.IsNullOrEmpty(oneFilterOnlyString))
                    {
                        oneFilterOnly = bool.Parse(oneFilterOnlyString);
                    }

                    string filterIcon = nodes[i].GetValue("filterIcon");

                    filterSettings[i] = new KerbetrotterFilterSettings(modName, filterIcon, includedFilter, excludedFilter, showModFilter, showSeparateFunctionCategory, disableForCCK, filterLifeSupport, oneFilterOnly, color);
                }
            }
            catch (ArgumentNullException exception)
            {
                Debug.LogError("[KerbetrotterTools] ERROR config node argument is null " + exception.Message);
            }
            catch (FormatException exception)
            {
                Debug.LogError("[KerbetrotterTools] ERROR config node argument malformed " + exception.Message);
            }
        }
        /*/// <summary>
         * /// Update the settings from the filters
         * /// </summary>
         * public void updateFilterSettings()
         * {
         *  Debug.Log("[KerbetrotterTools] updateFilterSettings");
         *  GameEvents.onGUIEditorToolbarReady.Remove(KerbetrotterFunctionFilter);
         *
         *  if (HighLogic.CurrentGame != null)
         *  {
         *      RemoveFunctionFilter();
         *      AddPartCategories();
         *
         *      if (HighLogic.CurrentGame.Parameters.CustomParams<KerbetrotterSettings>().groupParts)
         *      {
         *          RemovePartCategories();
         *          GameEvents.onGUIEditorToolbarReady.Add(KerbetrotterFunctionFilter);
         *      }
         *  }
         * }*/


        /// <summary>
        /// Filters parts by their names
        /// </summary>
        /// <param name="part">the part which has to be filtered</param>
        /// <returns></returns>
        private bool filterPart(AvailablePart part, int index)
        {
            KerbetrotterFilterSettings filterSettings = KerbetrotterConfiguration.Instance().FilterSettings[index];

            return(part.name.StartsWith(filterSettings.IncludeFilter) && (string.IsNullOrEmpty(filterSettings.ExcludeFilter) || !part.name.StartsWith(filterSettings.ExcludeFilter)));
        }