From 85dcfd538c5b9f89e58b5973ff2267b26e03152d Mon Sep 17 00:00:00 2001 From: amevarashi Date: Sun, 9 Oct 2022 14:16:22 +0500 Subject: [PATCH] Fix history window crashing from a modded passion --- .../SexHistory/HistoryUtility.cs | 30 ++++++++++++++++--- .../RJWSexperience/SexHistory/UI/SexStatus.cs | 10 +++---- 2 files changed, 31 insertions(+), 9 deletions(-) diff --git a/Source/RJWSexperience/SexHistory/HistoryUtility.cs b/Source/RJWSexperience/SexHistory/HistoryUtility.cs index 359b1a6..9e06c28 100644 --- a/Source/RJWSexperience/SexHistory/HistoryUtility.cs +++ b/Source/RJWSexperience/SexHistory/HistoryUtility.cs @@ -1,4 +1,6 @@ -using UnityEngine; +using RimWorld; +using System; +using UnityEngine; using Verse; namespace RJWSexperience.SexHistory @@ -47,11 +49,31 @@ namespace RJWSexperience.SexHistory Texture2D.linearGrayTexture //? = 20 }; - public static readonly Texture2D[] PassionBG = new Texture2D[] + private static readonly Texture2D[] PassionBG = new Texture2D[] { Texture2D.blackTexture, //None = 0, - SolidColorMaterials.NewSolidColorTexture(0.800f, 0.800f, 0.800f, 1.0f), //Minor = 1, - SolidColorMaterials.NewSolidColorTexture(1.000f, 0.875f, 0.000f, 1.0f) //Major = 2, + SolidColorMaterials.NewSolidColorTexture(0.800f, 0.800f, 0.800f, 1.0f), //Minor = 1, Gray + SolidColorMaterials.NewSolidColorTexture(1.000f, 0.875f, 0.000f, 1.0f), //Major = 2, Golden + Texture2D.blackTexture, // VSE Apathy = 3 + SolidColorMaterials.NewSolidColorTexture(0.500f, 0.875f, 0.000f, 1.0f), //VSE Natural = 4, Light Green + SolidColorMaterials.NewSolidColorTexture(1.000f, 0.375f, 0.000f, 1.0f), //VSE Critical = 5, Reddish }; + + public static Texture2D GetPassionBG(Passion? passion) + { + int passionIndex = (int)(passion ?? 0); + + // Vanilla Skills Expanded adds new passion levels + if (passionIndex < 0) + { + passionIndex = 0; + } + else if (passionIndex >= PassionBG.Length) + { + passionIndex = 0; + } + + return PassionBG[passionIndex]; + } } } diff --git a/Source/RJWSexperience/SexHistory/UI/SexStatus.cs b/Source/RJWSexperience/SexHistory/UI/SexStatus.cs index 3c35e6f..4d8c65a 100644 --- a/Source/RJWSexperience/SexHistory/UI/SexStatus.cs +++ b/Source/RJWSexperience/SexHistory/UI/SexStatus.cs @@ -408,7 +408,7 @@ namespace RJWSexperience.SexHistory.UI tmp = listmain.GetRect(FONTHEIGHT); p = pawn.records.GetValue(VariousDefOf.Lust); - FillableBarLabeled(tmp, String.Format(Keyed.Lust + ": {0:0.00}", p), Mathf.Clamp01(p.Normalization(-SexperienceMod.Settings.LustLimit * 3, SexperienceMod.Settings.LustLimit * 3)), HistoryUtility.Slaanesh, Texture2D.blackTexture, null, String.Format(xxx.sex_drive_stat.LabelCap.CapitalizeFirst() + ": {0:P2}", pawn.Dead ? 0 : pawn.GetStatValue(xxx.sex_drive_stat))); + FillableBarLabeled(tmp, String.Format(Keyed.Lust + ": {0:0.00}", p), Mathf.Clamp01(p.Normalization(-SexperienceMod.Settings.LustLimit * 3, SexperienceMod.Settings.LustLimit * 3)), HistoryUtility.Slaanesh, Texture2D.blackTexture, null, String.Format(xxx.sex_drive_stat.LabelCap + ": {0:P2}", pawn.Dead ? 0 : pawn.GetStatValue(xxx.sex_drive_stat))); listmain.Gap(1f); if (Mouse.IsOver(tmp)) { @@ -458,12 +458,12 @@ namespace RJWSexperience.SexHistory.UI if (p < history.BeenRapedCount) { p = history.BeenRapedCount; - FillableBarLabeled(tmp, String.Format(Keyed.RS_BeenRaped + ": {0}", p), p / 50, Texture2D.grayTexture, Texture2D.blackTexture, null, String.Format(xxx.vulnerability_stat.LabelCap.CapitalizeFirst() + ": {0:P2}", pawn.Dead ? 0 : pawn.GetStatValue(xxx.vulnerability_stat))); + FillableBarLabeled(tmp, String.Format(Keyed.RS_BeenRaped + ": {0}", p), p / 50, Texture2D.grayTexture, Texture2D.blackTexture, null, String.Format(xxx.vulnerability_stat.LabelCap + ": {0:P2}", pawn.Dead ? 0 : pawn.GetStatValue(xxx.vulnerability_stat))); listmain.Gap(1f); } else { - FillableBarLabeled(tmp, String.Format(Keyed.RS_RapedSomeone + ": {0}", p), p / 50, HistoryUtility.Khorne, Texture2D.blackTexture, null, String.Format(xxx.vulnerability_stat.LabelCap.CapitalizeFirst() + ": {0:P2}", pawn.Dead ? 0 : pawn.GetStatValue(xxx.vulnerability_stat))); + FillableBarLabeled(tmp, String.Format(Keyed.RS_RapedSomeone + ": {0}", p), p / 50, HistoryUtility.Khorne, Texture2D.blackTexture, null, String.Format(xxx.vulnerability_stat.LabelCap + ": {0:P2}", pawn.Dead ? 0 : pawn.GetStatValue(xxx.vulnerability_stat))); listmain.Gap(1f); } if (Mouse.IsOver(tmp)) @@ -473,7 +473,7 @@ namespace RJWSexperience.SexHistory.UI p = pawn.Dead ? 0 : pawn.GetStatValue(xxx.sex_satisfaction); tmp = listmain.GetRect(FONTHEIGHT); - FillableBarLabeled(tmp, String.Format(xxx.sex_satisfaction.LabelCap.CapitalizeFirst() + ": {0:P2}", p), p / 2, HistoryUtility.Satisfaction, Texture2D.blackTexture); + FillableBarLabeled(tmp, String.Format(xxx.sex_satisfaction.LabelCap + ": {0:P2}", p), p / 2, HistoryUtility.Satisfaction, Texture2D.blackTexture); listmain.Gap(1f); if (Mouse.IsOver(tmp)) { @@ -483,7 +483,7 @@ namespace RJWSexperience.SexHistory.UI SkillRecord skill = pawn.skills?.GetSkill(VariousDefOf.Sex); p = skill?.Level ?? 0; tmp = listmain.GetRect(FONTHEIGHT); - FillableBarLabeled(tmp, $"{Keyed.RS_SexSkill}: {p}, {skill?.xpSinceLastLevel / skill?.XpRequiredForLevelUp:P2}", p / 20, HistoryUtility.Tzeentch, Texture2D.blackTexture, null, $"{VariousDefOf.SexAbility.LabelCap.CapitalizeFirst()}: {pawn.GetSexStat():P2}", HistoryUtility.PassionBG[(int)(skill?.passion ?? 0)]); + FillableBarLabeled(tmp, $"{Keyed.RS_SexSkill}: {p}, {skill?.xpSinceLastLevel / skill?.XpRequiredForLevelUp:P2}", p / 20, HistoryUtility.Tzeentch, Texture2D.blackTexture, null, $"{VariousDefOf.SexAbility.LabelCap}: {pawn.GetSexStat():P2}", HistoryUtility.GetPassionBG(skill?.passion)); if (Mouse.IsOver(tmp)) { TooltipHandler.TipRegion(tmp, RJWUIUtility.GetStatExplanation(pawn, VariousDefOf.SexAbility, pawn.GetSexStat()));