Skip to content
This repository has been archived by the owner on Sep 7, 2021. It is now read-only.

Commit

Permalink
fixing some dds icon sizes, splitting category type and extra behavio…
Browse files Browse the repository at this point in the history
…urs up
  • Loading branch information
Crzyrndm committed Apr 23, 2016
1 parent 785447f commit 9b4de9f
Show file tree
Hide file tree
Showing 16 changed files with 164 additions and 149 deletions.
8 changes: 4 additions & 4 deletions FilterExtension/ConfigNodes/Check.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ namespace FilterExtensions.ConfigNodes
{
using Utility;

public class Check : ICloneable
public class Check : IEquatable<Check>, ICloneable
{
public enum CheckType
{
Expand Down Expand Up @@ -139,18 +139,18 @@ public Check(ConfigNode node)
public Check(Check c)
{
type = c.type;
if (c.values != null)
values = (string[])c.values.Clone();
invert = c.invert;
contains = c.contains;
equality = c.equality;

if (c.values != null)
values = (string[])c.values.Clone();
if (c.checks != null)
{
checks = new List<Check>(c.checks.Count);
for (int i = 0; i < c.checks.Count; ++i)
checks.Add(new Check(c.checks[i]));
}
equality = c.equality;
}

public Check(string Type, string Value, bool Invert = false, bool Contains = true, Equality Compare = Equality.Equals)
Expand Down
2 changes: 1 addition & 1 deletion FilterExtension/ConfigNodes/Filter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

namespace FilterExtensions.ConfigNodes
{
public class Filter : ICloneable
public class Filter : IEquatable<Filter>, ICloneable
{
public List<Check> checks { get; set; } // checks are processed in serial (a && b), inversion gives (!a || !b) logic
public bool invert { get; set; }
Expand Down
135 changes: 83 additions & 52 deletions FilterExtension/ConfigNodes/customCategory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,39 +8,44 @@ namespace FilterExtensions.ConfigNodes
using Utility;
using KSP.UI.Screens;

public enum categoryTypeAndBehaviour
public class customCategory : IEquatable<customCategory>, ICloneable
{
None,
Engines,
StockAdd,
StockReplace,
ModAdd,
ModReplace
}
public enum categoryType
{
New = 1, // new category
Stock = 2, // modification to stock category
Mod = 4, // modification to a mod cateogry
}

public enum categoryBehaviour
{
Add = 1, // only add to existing categories
Replace = 2, // wipe existing categories
Engines = 4 // generate unique engine types
}

public class customCategory : IEquatable<customCategory>
{
public string categoryName { get; set; }
public string iconName { get; set; }
public Color colour { get; set; }
public categoryTypeAndBehaviour behaviour { get; set; }
public categoryType type { get; set; }
public categoryBehaviour behaviour { get; set; }
public bool all { get; set; } // has an all parts subCategory
public List<subCategoryItem> subCategories { get; set; } // array of subcategories
public List<Filter> templates { get; set; } // Checks to add to every Filter in a category with the template tag

private static readonly List<string> categoryNames = new List<string> { "Pods", "Engines", "Fuel Tanks", "Command and Control", "Structural", "Aerodynamics", "Utility", "Science" };

public customCategory(ConfigNode node)
{
bool tmp;
bool tmpBool;
string tmpStr = string.Empty;

categoryName = node.GetValue("name");
iconName = node.GetValue("icon");
colour = convertToColor(node.GetValue("colour"));

makeTemplate(node);

bool.TryParse(node.GetValue("all"), out tmp);
this.all = tmp;
bool.TryParse(node.GetValue("all"), out tmpBool);
this.all = tmpBool;

ConfigNode[] subcategoryList = node.GetNodes("SUBCATEGORIES");
subCategories = new List<subCategoryItem>();
Expand Down Expand Up @@ -84,7 +89,62 @@ public customCategory(ConfigNode node)
subCategories.AddUniqueRange(unorderedSubCats); // tack unordered subcats on to the end
subCategories.RemoveAll(s => s == null);
}
typeSwitch(node.GetValue("type"), node.GetValue("value"));

if (node.TryGetValue("type", ref tmpStr))
tmpStr = tmpStr.ToLower();
switch (tmpStr)
{
case "stock":
type = categoryType.Stock;
break;
case "mod":
type = categoryType.Mod;
break;
case "new":
default:
type = categoryType.New;
break;
}
if (node.TryGetValue("value", ref tmpStr))
{
if (string.Equals(tmpStr, "replace", StringComparison.OrdinalIgnoreCase))
behaviour = categoryBehaviour.Replace;
else if (string.Equals(tmpStr, "engine", StringComparison.OrdinalIgnoreCase))
{
behaviour = categoryBehaviour.Engines;
foreach (List<string> combo in Core.Instance.propellantCombos)
{
string dummy = string.Empty, subcatName = string.Join(",", combo.ToArray());
Core.Instance.SetNameAndIcon(ref subcatName, ref dummy);
subCategories.AddUnique(new subCategoryItem(subcatName));
}
}
else
behaviour = categoryBehaviour.Add;
}
}

public customCategory(customCategory c)
{
categoryName = c.categoryName;
iconName = c.iconName;
colour = c.colour;
type = c.type;
behaviour = c.behaviour;
all = c.all;

subCategories = new List<subCategoryItem>();
for (int i = 0; i < c.subCategories.Count; ++i)
subCategories.Add(new subCategoryItem(c.subCategories[i].subcategoryName, c.subCategories[i].applyTemplate));

templates = new List<Filter>();
for (int i = 0; i < c.templates.Count; ++i)
templates.Add(new Filter(c.templates[i]));
}

public object Clone()
{
return new customCategory(this);
}

public void initialise()
Expand All @@ -100,7 +160,7 @@ public void initialise()
return;
}
PartCategorizer.Category category;
if (behaviour == categoryTypeAndBehaviour.None || behaviour == categoryTypeAndBehaviour.Engines)
if (type == categoryType.New)
{
RUI.Icons.Selectable.Icon icon = Core.getIcon(iconName);
PartCategorizer.AddCustomFilter(categoryName, icon, colour);
Expand All @@ -116,11 +176,8 @@ public void initialise()
Core.Log("No category of this name was found to manipulate: " + categoryName);
return;
}
else
{
if (behaviour == categoryTypeAndBehaviour.StockReplace || behaviour == categoryTypeAndBehaviour.ModReplace)
category.subcategories.Clear();
}
else if (behaviour == categoryBehaviour.Replace)
category.subcategories.Clear();
}

List<string> subcategoryNames = new List<string>();
Expand Down Expand Up @@ -162,7 +219,7 @@ public void initialise()

try
{
if (Core.checkSubCategoryHasParts(sC, categoryName))
if (Editor.subcategoriesChecked || sC.checkSubCategoryHasParts(categoryName))
sC.initialise(category);
}
catch (Exception ex)
Expand All @@ -175,35 +232,9 @@ public void initialise()
}
}

private void typeSwitch(string type, string value)
private void typeSwitch(string Type, string Replace)
{
switch (type)
{
case "engine":
behaviour = categoryTypeAndBehaviour.Engines;
foreach (List<string> combo in Core.Instance.propellantCombos)
{
string dummy = string.Empty, subcatName = string.Join(",", combo.ToArray());
Core.Instance.SetNameAndIcon(ref subcatName, ref dummy);
subCategories.AddUnique(new subCategoryItem(subcatName));
}
break;
case "stock":
if (value == "replace")
behaviour = categoryTypeAndBehaviour.StockReplace;
else
behaviour = categoryTypeAndBehaviour.StockAdd;
break;
case "mod":
if (value == "replace")
behaviour = categoryTypeAndBehaviour.ModReplace;
else
behaviour = categoryTypeAndBehaviour.ModAdd;
break;
default:
behaviour = categoryTypeAndBehaviour.None;
break;
}

}

private void makeTemplate(ConfigNode node)
Expand Down
42 changes: 41 additions & 1 deletion FilterExtension/ConfigNodes/customSubCategory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
namespace FilterExtensions.ConfigNodes
{
using KSP.UI.Screens;
public class customSubCategory : ICloneable
public class customSubCategory : IEquatable<customSubCategory>, ICloneable
{
public string subCategoryTitle { get; set; } // title of this subcategory
public string iconName { get; set; } // default icon to use
Expand Down Expand Up @@ -123,6 +123,46 @@ public bool checkFilters(AvailablePart part, int depth = 0)
return ((!template.Any() || template.Any(t => t.checkFilter(part, depth))) && filters.Any(f => f.checkFilter(part, depth))); // part passed a template if present, and a subcategory filter
}

/// <summary>
/// if a subcategory doesn't have any parts, it shouldn't be used. Doesn't account for the blackListed parts the first time the editor is entered
/// </summary>
/// <param name="sC">the subcat to check</param>
/// <param name="category">the category for logging purposes</param>
/// <returns>true if the subcategory contains any parts</returns>
public bool checkSubCategoryHasParts(string category)
{
PartModuleFilter pmf;
AvailablePart p;
for (int i = 0; i < PartLoader.Instance.parts.Count; i++)
{
pmf = null;
p = PartLoader.Instance.parts[i];
if (Core.Instance.filterModules.TryGetValue(p.name, out pmf))
{
if (pmf.CheckForForceAdd(subCategoryTitle))
return true;
if (pmf.CheckForForceBlock(subCategoryTitle))
return false;
}
if (checkFilters(PartLoader.Instance.parts[i]))
return true;
}

// only need to do this the first time we hit the editor
customCategory C = Core.Instance.Categories.FirstOrDefault(c => c.categoryName == category);
if (C != null)
C.subCategories.RemoveAll(s => s.subcategoryName == subCategoryTitle);

if (Settings.debug)
{
if (!string.IsNullOrEmpty(category))
Core.Log(subCategoryTitle + " in category " + category + " has no valid parts and was not initialised");
else
Core.Log(subCategoryTitle + " has no valid parts and was not initialised");
}
return false;
}

/// <summary>
/// check to see if any checks in a subcategory match a given check
/// </summary>
Expand Down
Loading

0 comments on commit 9b4de9f

Please sign in to comment.