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

Commit

Permalink
Fix a few issues causing icons to not be found
Browse files Browse the repository at this point in the history
- Update Mk2.5 flat bottom to align with mod
  • Loading branch information
Crzyrndm committed Jun 5, 2017
1 parent d9fb8d4 commit 51d35c0
Show file tree
Hide file tree
Showing 9 changed files with 50 additions and 54 deletions.
16 changes: 13 additions & 3 deletions FilterExtension/ConfigNodes/SubcategoryNode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,24 @@ public class SubcategoryNode : IEquatable<SubcategoryNode>

public bool HasFilters { get => (Filters?.Count ?? 0) > 0; }

public SubcategoryNode(ConfigNode node)
public SubcategoryNode(ConfigNode node, LoadAndProcess data)
{
SubCategoryTitle = node.GetValue("name");
string nameTemp = node.GetValue("name");
if (!string.IsNullOrEmpty(nameTemp) && data.Rename.ContainsKey(nameTemp))
{
nameTemp = data.Rename[nameTemp];
}
SubCategoryTitle = nameTemp;
if (SubCategoryTitle == string.Empty)
{
SubCategoryTitle = node.GetValue("categoryName"); // for playing nice with stock generated subcats
}
IconName = node.GetValue("icon");
string iconTemp = IconName = node.GetValue("icon");
if (!string.IsNullOrEmpty(SubCategoryTitle) && data.setIcon.ContainsKey(SubCategoryTitle))
{
iconTemp = data.setIcon[SubCategoryTitle];
}
IconName = iconTemp;

bool.TryParse(node.GetValue("showUnpurchased"), out bool tmp);
UnPurchasedOverride = tmp;
Expand Down
39 changes: 8 additions & 31 deletions FilterExtension/IconLib.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ public static class IconLib
{
// Dictionary of icons created on entering the main menu
public static Dictionary<string, RUI.Icons.Selectable.Icon> IconDict = new Dictionary<string, RUI.Icons.Selectable.Icon>();
//
// if the icon isn't present, use this one
private const string fallbackIcon = "stockIcon_fallback";

Expand Down Expand Up @@ -57,40 +58,16 @@ public static void Load()
/// <returns>the icon if it is found, or the fallback icon if it is not</returns>
public static RUI.Icons.Selectable.Icon GetIcon(string name)
{
if (string.IsNullOrEmpty(name))
if (!string.IsNullOrEmpty(name))
{
return PartCategorizer.Instance.iconLoader.iconDictionary[fallbackIcon];
}
if (IconDict.TryGetValue(name, out RUI.Icons.Selectable.Icon icon) || PartCategorizer.Instance.iconLoader.iconDictionary.TryGetValue(name, out icon))
{
return icon;
name = name.Trim();
if (IconDict.TryGetValue(name, out RUI.Icons.Selectable.Icon icon)
|| PartCategorizer.Instance.iconLoader.iconDictionary.TryGetValue(name, out icon))
{
return icon;
}
}
return PartCategorizer.Instance.iconLoader.iconDictionary[fallbackIcon];
}

/// <summary>
/// get icon following the TryGet* syntax
/// </summary>
/// <param name="name">the icon name</param>
/// <param name="icon">the icon that matches the name, or the fallback if no matches were found</param>
/// <returns>true if a matching icon was found, false if fallback was required</returns>
public static bool TryGetIcon(string name, out RUI.Icons.Selectable.Icon icon)
{
if (string.IsNullOrEmpty(name))
{
icon = PartCategorizer.Instance.iconLoader.iconDictionary[fallbackIcon];
return false;
}
if (IconDict.TryGetValue(name, out icon))
{
return true;
}
if (PartCategorizer.Instance.iconLoader.iconDictionary.TryGetValue(name, out icon))
{
return true;
}
icon = PartCategorizer.Instance.iconLoader.iconDictionary[fallbackIcon];
return false;
}
}
}
18 changes: 9 additions & 9 deletions FilterExtension/LoadAndProcess.cs
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq; // Majority of Core only runs once.
using System.Linq;
using UnityEngine;

namespace FilterExtensions
{
using ConfigNodes;
using ConfigNodes.CheckNodes;
using KSP.UI.Screens;
using UnityEngine;
using Utility;

[KSPAddon(KSPAddon.Startup.MainMenu, true)]
Expand Down Expand Up @@ -185,7 +184,7 @@ private void ProcessFilterDefinitions()
//load all subCategory configs
foreach (ConfigNode node in GameDatabase.Instance.GetConfigNodes("SUBCATEGORY"))
{
var sC = new SubcategoryNode(node);
var sC = new SubcategoryNode(node, this);
if (!sC.HasFilters || string.IsNullOrEmpty(sC.SubCategoryTitle))
{
Logger.Log($"subcategory format error: {sC.SubCategoryTitle}", Logger.LogLevel.Error);
Expand Down Expand Up @@ -219,7 +218,7 @@ private void ProcessFilterDefinitions()
ConfigNode checkNode = CheckNodeFactory.MakeCheckNode(CheckResource.ID, s);
ConfigNode filtNode = FilterNode.MakeFilterNode(false, new List<ConfigNode>(){ checkNode });
ConfigNode subcatNode = SubcategoryNode.MakeSubcategoryNode(name, name, false, new List<ConfigNode>() { filtNode });
subCategoriesDict.Add(name, new SubcategoryNode(subcatNode));
subCategoriesDict.Add(name, new SubcategoryNode(subcatNode, this));
Cat.SubCategories.AddUnique(new SubCategoryItem(name));
}
}
Expand Down Expand Up @@ -247,7 +246,7 @@ private void ProcessFilterDefinitions()
{
filternodes.Add(f.ToConfigNode());
}
var newSub = new SubcategoryNode(SubcategoryNode.MakeSubcategoryNode("All parts in " + C.CategoryName, C.IconName, false, filternodes));
var newSub = new SubcategoryNode(SubcategoryNode.MakeSubcategoryNode("All parts in " + C.CategoryName, C.IconName, false, filternodes), this);
subCategoriesDict.Add(newSub.SubCategoryTitle, newSub);
C.SubCategories.Insert(0, new SubCategoryItem(newSub.SubCategoryTitle));
}
Expand Down Expand Up @@ -292,7 +291,7 @@ private void GenerateEngineTypes()
{
var checks = new List<ConfigNode>() { CheckNodeFactory.MakeCheckNode(CheckPropellant.ID, propList, exact: true) };
var filters = new List<ConfigNode>() { FilterNode.MakeFilterNode(false, checks) };
var sC = new SubcategoryNode(SubcategoryNode.MakeSubcategoryNode(name, icon, false, filters));
var sC = new SubcategoryNode(SubcategoryNode.MakeSubcategoryNode(name, icon, false, filters), this);
subCategoriesDict.Add(name, sC);
}
}
Expand Down Expand Up @@ -321,7 +320,7 @@ private void ProcessFilterByManufacturer(List<string> modNames)
subCatNames.Add(name);
var checks = new List<ConfigNode>() { CheckNodeFactory.MakeCheckNode(CheckFolder.ID, name) };
var filters = new List<ConfigNode>() { FilterNode.MakeFilterNode(false, checks) };
var sC = new SubcategoryNode(SubcategoryNode.MakeSubcategoryNode(name, icon, false, filters));
var sC = new SubcategoryNode(SubcategoryNode.MakeSubcategoryNode(name, icon, false, filters), this);
subCategoriesDict.Add(name, sC);
}
}
Expand All @@ -339,6 +338,7 @@ private void ProcessFilterByManufacturer(List<string> modNames)
filterByManufacturer.AddNode(manufacturerSubs);
FilterByManufacturer = new CategoryNode(filterByManufacturer, this);
CategoryNodes.Add(FilterByManufacturer);
Logger.Log("Filter by manufacturer");
}

/// <summary>
Expand Down Expand Up @@ -412,7 +412,7 @@ public void CompileCategories()
}
catch (Exception ex)
{
Logger.Log(ex.Message, Logger.LogLevel.Warn);
Logger.Log($"{cn.CategoryName}: {ex.Message}", Logger.LogLevel.Error);
}
}
}
Expand Down
25 changes: 17 additions & 8 deletions FilterExtension/Logger.cs
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using KSP;
using UnityEngine;

namespace FilterExtensions
{
internal static class Logger
{
public static readonly Version version = new Version(3, 0, 0, 0);
public static readonly Version version = new Version(3, 0, 1);
public static readonly string versionString = $"[Filter Extensions {version}]:";

internal enum LogLevel
{
Expand All @@ -18,6 +15,18 @@ internal enum LogLevel
Error
}


/// <summary>
/// format the string to be logged and prefix with mod id + version
/// </summary>
/// <param name="format">string format to be logged</param>
/// <param name="o">params for the format</param>
/// <returns></returns>
static string LogString(string format, params object[] o)
{
return $"{versionString} {string.Format(format, o)}";
}

/// <summary>
/// Debug messages only compiled in debug build. Also much easier to search for once debugging/development complete...
/// </summary>
Expand Down Expand Up @@ -48,15 +57,15 @@ internal static void Log(string format, LogLevel level = LogLevel.Debug, params
{
if (level == LogLevel.Debug)
{
Debug.LogFormat($"[Filter Extensions {version}]: {string.Format(format, o)}");
Debug.Log(LogString(format, o));
}
else if (level == LogLevel.Warn)
{
Debug.LogWarningFormat($"[Filter Extensions {version}]: {string.Format(format, o)}");
Debug.LogWarning(LogString(format, o));
}
else
{
Debug.LogErrorFormat($"[Filter Extensions {version}]: {string.Format(format, o)}");
Debug.LogError(LogString(format, o));
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -281,14 +281,14 @@ SUBCATEGORY
SUBCATEGORY
{
name = Mk 2.5 Flat-Bottom [2.5m]
icon = cs_size25
icon = cs_mk25

FILTER
{
CHECK
{
type = profile
value = size25
value = mk25
}
}
}
Expand Down
Binary file modified GameData/000_FilterExtensions/FilterExtensions.dll
Binary file not shown.
2 changes: 1 addition & 1 deletion GameData/000_FilterExtensions/FilterExtensions.version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"NAME":"Filter Extensions","URL":"https://github.com/Crzyrndm/FilterExtension/blob/master/GameData/000_FilterExtensions/FilterExtensions.version","DOWNLOAD":"https://github.com/Crzyrndm/FilterExtension/releases","VERSION":{"MAJOR":3,"MINOR":0,"PATCH":0},"KSP_VERSION":{"MAJOR":1,"MINOR":3,"PATCH":0}}
{"NAME":"Filter Extensions","URL":"https://github.com/Crzyrndm/FilterExtension/blob/master/GameData/000_FilterExtensions/FilterExtensions.version","DOWNLOAD":"https://github.com/Crzyrndm/FilterExtension/releases","VERSION":{"MAJOR":3,"MINOR":0,"PATCH":1},"KSP_VERSION":{"MAJOR":1,"MINOR":3,"PATCH":0}}
Binary file modified Testing/FE_Testing.dll
Binary file not shown.

0 comments on commit 51d35c0

Please sign in to comment.