This repository has been archived by the owner on Sep 7, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
147 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using UnityEngine; | ||
|
||
namespace FilterExtensions | ||
{ | ||
class Category : IEquatable<Category> | ||
{ | ||
internal string categoryTitle; | ||
internal string iconName; | ||
internal Color colour; | ||
|
||
public Category(ConfigNode node) | ||
{ | ||
categoryTitle = node.GetValue("title"); | ||
iconName = node.GetValue("icon"); | ||
convertToColor(node.GetValue("colour")); | ||
} | ||
|
||
internal void initialise() | ||
{ | ||
if (categoryTitle == null) | ||
return; | ||
|
||
PartCategorizer.Icon icon = Core.getIcon(iconName); | ||
PartCategorizer.AddCustomFilter(categoryTitle, icon, colour); | ||
} | ||
|
||
private void convertToColor(string hex_ARGB) | ||
{ | ||
hex_ARGB = hex_ARGB.Replace("#", ""); | ||
|
||
if (hex_ARGB.Length == 8) | ||
{ | ||
Color c = new Color(); | ||
c.a = (int)byte.Parse(hex_ARGB.Substring(0, 2), System.Globalization.NumberStyles.HexNumber) / 255; | ||
c.r = (int)byte.Parse(hex_ARGB.Substring(2, 2), System.Globalization.NumberStyles.HexNumber) / 255; | ||
c.g = (int)byte.Parse(hex_ARGB.Substring(4, 2), System.Globalization.NumberStyles.HexNumber) / 255; | ||
c.b = (int)byte.Parse(hex_ARGB.Substring(6, 2), System.Globalization.NumberStyles.HexNumber) / 255; | ||
colour = c; | ||
} | ||
else if (hex_ARGB.Length == 6) | ||
{ | ||
Color c = new Color(); | ||
c.a = 1; | ||
c.r = (int)byte.Parse(hex_ARGB.Substring(0, 2), System.Globalization.NumberStyles.HexNumber) / 255; | ||
c.g = (int)byte.Parse(hex_ARGB.Substring(2, 2), System.Globalization.NumberStyles.HexNumber) / 255; | ||
c.b = (int)byte.Parse(hex_ARGB.Substring(3, 2), System.Globalization.NumberStyles.HexNumber) / 255; | ||
colour = c; | ||
} | ||
} | ||
|
||
public bool Equals(Category other) | ||
{ | ||
if (other == null) | ||
return false; | ||
|
||
if (this.categoryTitle == other.categoryTitle) | ||
return true; | ||
else | ||
return false; | ||
} | ||
|
||
public override bool Equals(System.Object obj) | ||
{ | ||
if (obj == null) | ||
return false; | ||
|
||
Category CObj = obj as Category; | ||
if (CObj == null) | ||
return false; | ||
else | ||
return Equals(CObj); | ||
} | ||
|
||
public override int GetHashCode() | ||
{ | ||
return categoryTitle.GetHashCode(); | ||
} | ||
|
||
public static bool operator ==(Category c1, Category c2) | ||
{ | ||
return c1.Equals(c2); | ||
} | ||
|
||
public static bool operator !=(Category c1, Category c2) | ||
{ | ||
return !c1.Equals(c2); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 6 additions & 0 deletions
6
GameData/Filter Extensions/Filter definitions/TestCategory.cfg
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
CATEGORY | ||
{ | ||
title = TestCategory | ||
icon = R&D_node_icon_experimentalmotors | ||
colour = #FF0000FF | ||
} |
15 changes: 15 additions & 0 deletions
15
GameData/Filter Extensions/Filter definitions/TestCategorySubCategory.cfg
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
SUBCATEGORY | ||
{ | ||
category = TestCategory | ||
title = TestTitle | ||
icon = R&D_node_icon_experimentalmotors | ||
FILTER | ||
{ | ||
CHECK | ||
{ | ||
type = title | ||
value = Cargo Bay | ||
pass = true | ||
} | ||
} | ||
} |
Binary file not shown.