diff --git a/NC Reactor Planner/Fuel.cs b/NC Reactor Planner/Fuel.cs index af07bae..33ec217 100644 --- a/NC Reactor Planner/Fuel.cs +++ b/NC Reactor Planner/Fuel.cs @@ -1,10 +1,11 @@ using System; using System.Collections.Generic; +using System.Text.RegularExpressions; namespace NC_Reactor_Planner { - public class Fuel - { + public class Fuel : IComparable + { public string Name { get ; private set; } public double BaseHeat { get => Configuration.Fuels[Name].BaseHeat; } public double FuelTime { get => Configuration.Fuels[Name].FuelTime; } @@ -26,5 +27,56 @@ public override string ToString() { return string.Format("{0}{1}{2}{3}", (Name + (SelfPriming ? "*" : "")).PadRight(14), BaseEfficiency.ToString().PadRight(6), BaseHeat.ToString().PadRight(5), CriticalityFactor.ToString().PadRight(4)); } - } + + private string getModifier() + { + Match match = Regex.Match(Name, @"\[([a-zA-Z]+)\]"); + if (match.Success) + return match.Groups[0].Value; + else + return ""; + } + + private int getIsotope() + { + Match match = Regex.Match(Name, @"-([0-9]+)"); + if (match.Success) + return Int32.Parse(match.Groups[0].Value); + else + return -1; + } + + private string getElement() + { + Match match = Regex.Match(Name, @"([a-zA-Z]+)(?!\])\b"); + if (match.Success) + return match.Groups[0].Value; + else + return ""; + } + + public int CompareTo(Fuel right) + { + if (right == null) + return 1; + + int leftIsotope = getIsotope(); + int rightIsotope = right.getIsotope(); + int compareIsotope = leftIsotope.CompareTo(rightIsotope); + if (compareIsotope != 0) + return compareIsotope; + + string leftElement = getElement(); + string rightElement = right.getElement(); + int compareElement = leftElement.CompareTo(rightElement); + if (compareIsotope != 0) + return compareIsotope; + + string leftModifier = getModifier(); + string rightModifier = right.getModifier(); + int compareModifier = leftModifier.CompareTo(rightModifier); + + return compareModifier; + } + } } diff --git a/NC Reactor Planner/PlannerUI.cs b/NC Reactor Planner/PlannerUI.cs index 7fc5b94..0e213a0 100644 --- a/NC Reactor Planner/PlannerUI.cs +++ b/NC Reactor Planner/PlannerUI.cs @@ -123,7 +123,11 @@ private void Form1_Load(object sender, EventArgs e) #if !DEBUG SetUpdateAvailableTextAsync(); #endif - fuelSelector.Items.AddRange(Palette.FuelPalette.Values.ToArray()); + fuelSelector.Sorted = false; + List fuels = new List(); + fuels.AddRange(Palette.FuelPalette.Values.ToArray()); + fuels.Sort(); + fuelSelector.Items.AddRange(fuels.ToArray()); coolantRecipeSelector.Items.AddRange(Configuration.CoolantRecipes.Keys.ToArray()); UpdateStatsUIPosition();