diff --git a/Patches/ItemPanelPatches.cs b/Patches/ItemPanelPatches.cs index 0605879..30c9b64 100644 --- a/Patches/ItemPanelPatches.cs +++ b/Patches/ItemPanelPatches.cs @@ -277,18 +277,22 @@ namespace UIFixes var match = Regex.Match(text, @" %\((.*)\)"); if (match.Success) { - float value = float.Parse(match.Groups[1].Value); - string sign = value > 0 ? "+" : ""; - string color = (attribute.LessIsGood && value < 0) || (!attribute.LessIsGood && value > 0) ? increasingColorHex : decreasingColorHex; + float value; + // If this fails to parse, I don't know what it is, leave it be + if (float.TryParse(match.Groups[1].Value, out value)) + { + string sign = value > 0 ? "+" : ""; + string color = (attribute.LessIsGood && value < 0) || (!attribute.LessIsGood && value > 0) ? increasingColorHex : decreasingColorHex; - // Except some that have a space weren't actually formatted with P1 and are 0-100 with a manually added " %" - if (NonPercentPercents.Contains((EItemAttributeId)attribute.Id)) - { - text = Regex.Replace(text, @"%\(.*\)", "%(" + sign + value + "%)"); - } - else - { - text = Regex.Replace(text, @"%\(.*\)", "%(" + sign + value.ToString("P1") + ")"); + // Except some that have a space weren't actually formatted with P1 and are 0-100 with a manually added " %" + if (NonPercentPercents.Contains((EItemAttributeId)attribute.Id)) + { + text = Regex.Replace(text, @"%\(.*\)", "%(" + sign + value + "%)"); + } + else + { + text = Regex.Replace(text, @"%\(.*\)", "%(" + sign + value.ToString("P1") + ")"); + } } } else @@ -297,10 +301,14 @@ namespace UIFixes match = Regex.Match(text, @"(\S)%\((.*)\)"); if (match.Success) { - float value = float.Parse(match.Groups[2].Value); - string sign = value > 0 ? "+" : ""; - string color = (attribute.LessIsGood && value < 0) || (!attribute.LessIsGood && value > 0) ? increasingColorHex : decreasingColorHex; - text = Regex.Replace(text, @"(\S)%\((.*)\)", match.Groups[1].Value + "%(" + sign + value + "%)"); + float value; + // If this fails to parse, I don't know what it is, leave it be + if (float.TryParse(match.Groups[2].Value, out value)) + { + string sign = value > 0 ? "+" : ""; + string color = (attribute.LessIsGood && value < 0) || (!attribute.LessIsGood && value > 0) ? increasingColorHex : decreasingColorHex; + text = Regex.Replace(text, @"(\S)%\((.*)\)", match.Groups[1].Value + "%(" + sign + value + "%)"); + } } else { @@ -308,17 +316,20 @@ namespace UIFixes match = Regex.Match(text, @"\((.*)\)"); if (match.Success) { - float value = float.Parse(match.Groups[1].Value); - string sign = value > 0 ? "+" : ""; - string color = (attribute.LessIsGood && value < 0) || (!attribute.LessIsGood && value > 0) ? increasingColorHex : decreasingColorHex; - text = Regex.Replace(text, @"\((.*)\)", "(" + sign + value + ")"); + float value; + // If this fails to parse, I don't know what it is, leave it be + if (float.TryParse(match.Groups[1].Value, out value)) + { + string sign = value > 0 ? "+" : ""; + string color = (attribute.LessIsGood && value < 0) || (!attribute.LessIsGood && value > 0) ? increasingColorHex : decreasingColorHex; + text = Regex.Replace(text, @"\((.*)\)", "(" + sign + value + ")"); + } } } } // Remove trailing 0s - text = Regex.Replace(text, @"\.([1-9]*)0+\b", ".$1"); - text = Regex.Replace(text, @"\.\B", ""); + text = Regex.Replace(text, @"(\d)(\.[0-9]*[^0])?\.?0+\b", "$1$2"); // Fix spacing text = text.Replace(" %", "%"); diff --git a/Patches/SwapPatch.cs b/Patches/SwapPatch.cs index a3a90ba..93ae0d3 100644 --- a/Patches/SwapPatch.cs +++ b/Patches/SwapPatch.cs @@ -160,7 +160,7 @@ namespace UIFixes } [PatchPostfix] - private static void Postfix(GridView __instance, ItemContextClass itemContext, ItemContextAbstractClass targetItemContext, ref object operation, ref bool __result) + private static void Postfix(GridView __instance, ItemContextClass itemContext, ItemContextAbstractClass targetItemContext, ref object operation, ref bool __result, Dictionary ___dictionary_0) { if (!ValidPrerequisites(itemContext, targetItemContext, operation)) { @@ -177,6 +177,16 @@ namespace UIFixes return; } + // Repair kits are special + ItemView targetItemView; + if (___dictionary_0.TryGetValue(targetItem.Id, out targetItemView)) + { + if (targetItemView.CanInteract(itemContext)) + { + return; + } + } + // This is the location you're dragging it over, including rotation LocationInGrid itemToLocation = __instance.CalculateItemLocation(itemContext);