Started reusing objects in SexStatusViewModel

This commit is contained in:
amevarashi 2023-07-09 12:02:20 +05:00
parent 4e44d42c4f
commit 5138e11cb2
5 changed files with 128 additions and 109 deletions

View File

@ -3,33 +3,69 @@ using Verse;
namespace RJWSexperience.SexHistory.UI namespace RJWSexperience.SexHistory.UI
{ {
public readonly struct BarInfo public class BarInfo
{ {
public readonly string label; private string _label;
public readonly float fillPercent; private float _fillPercent;
public readonly Texture2D fillTexture; private string _labelRight;
public readonly TipSignal tooltip;
public readonly string labelRight; public string Label
public readonly Texture2D border; {
get => _label;
set => _label = value.CapitalizeFirst();
}
public float FillPercent
{
get => _fillPercent;
set => _fillPercent = Mathf.Clamp01(value);
}
public Texture2D FillTexture { get; set; }
public TipSignal Tooltip { get; set; }
public string LabelRight
{
get => _labelRight;
set => _labelRight = value.CapitalizeFirst();
}
public Texture2D Border { get; set; }
public BarInfo()
{
_label = "";
_fillPercent = 0f;
FillTexture = Texture2D.grayTexture;
Tooltip = default;
_labelRight = "";
Border = null;
}
public BarInfo(Texture2D fillTexture)
{
_label = "";
_fillPercent = 0f;
FillTexture = fillTexture;
Tooltip = default;
_labelRight = "";
Border = null;
}
public BarInfo(string label, float fillPercent, Texture2D fillTexture, TipSignal tooltip, string labelRight = "", Texture2D border = null) public BarInfo(string label, float fillPercent, Texture2D fillTexture, TipSignal tooltip, string labelRight = "", Texture2D border = null)
{ {
this.label = label.CapitalizeFirst(); _label = label.CapitalizeFirst();
this.fillPercent = Mathf.Clamp01(fillPercent); _fillPercent = Mathf.Clamp01(fillPercent);
this.fillTexture = fillTexture; FillTexture = fillTexture;
this.tooltip = tooltip; Tooltip = tooltip;
this.labelRight = labelRight.CapitalizeFirst(); _labelRight = labelRight.CapitalizeFirst();
this.border = border; Border = border;
} }
public BarInfo(string label, float fillPercent, Texture2D fillTexture, string labelRight = "") public BarInfo(string label, float fillPercent, Texture2D fillTexture, string labelRight = "")
{ {
this.label = label.CapitalizeFirst(); _label = label.CapitalizeFirst();
this.fillPercent = Mathf.Clamp01(fillPercent); _fillPercent = Mathf.Clamp01(fillPercent);
this.fillTexture = fillTexture; FillTexture = fillTexture;
this.tooltip = default; Tooltip = default;
this.labelRight = labelRight.CapitalizeFirst(); _labelRight = labelRight.CapitalizeFirst();
this.border = null; Border = null;
} }
} }
} }

View File

@ -8,7 +8,7 @@ namespace RJWSexperience.SexHistory.UI
public readonly string preferRaceLabel; public readonly string preferRaceLabel;
public readonly string preferRaceTypeLabel; public readonly string preferRaceTypeLabel;
public readonly string sexCount; public readonly string sexCount;
public readonly BarInfo? barInfo; public readonly BarInfo barInfo;
public readonly Func<Vector2, Texture> portraitGetter; public readonly Func<Vector2, Texture> portraitGetter;
public PreferedRaceCard(SexHistoryComp sexHistory) public PreferedRaceCard(SexHistoryComp sexHistory)

View File

@ -1,6 +1,5 @@
using RimWorld; using RimWorld;
using rjw; using rjw;
using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
@ -58,18 +57,18 @@ namespace RJWSexperience.SexHistory.UI
public InfoCard SelectedPartnerCard { get; private set; } public InfoCard SelectedPartnerCard { get; private set; }
public PreferedRaceCard PreferedRaceCard { get; private set; } public PreferedRaceCard PreferedRaceCard { get; private set; }
public List<BarInfo> SexTypes { get; } = new List<BarInfo>(); public List<BarInfo> SexTypes { get; } = new List<BarInfo>();
public BarInfo TotalSex { get; private set; } public BarInfo TotalSex { get; } = new BarInfo(HistoryUtility.TotalSex);
public BarInfo Lust { get; private set; } public BarInfo Lust { get; } = new BarInfo(HistoryUtility.Slaanesh);
public BarInfo BestSextype { get; private set; } public BarInfo BestSextype { get; } = new BarInfo();
public BarInfo RecentSextype { get; private set; } public BarInfo RecentSextype { get; } = new BarInfo();
public BarInfo Necro { get; private set; } public BarInfo Necro { get; } = new BarInfo(HistoryUtility.Nurgle);
public BarInfo Incest { get; private set; } public BarInfo Incest { get; } = new BarInfo(HistoryUtility.Nurgle);
public BarInfo ConsumedCum { get; private set; } public BarInfo ConsumedCum { get; } = new BarInfo(Texture2D.linearGrayTexture);
public BarInfo? CumHediff { get; private set; } public BarInfo CumHediff { get; } = new BarInfo(Texture2D.linearGrayTexture);
public BarInfo BeenRaped { get; private set; } public BarInfo BeenRaped { get; } = new BarInfo(Texture2D.grayTexture);
public BarInfo Raped { get; private set; } public BarInfo Raped { get; } = new BarInfo(HistoryUtility.Khorne);
public BarInfo SexSatisfaction { get; private set; } public BarInfo SexSatisfaction { get; } = new BarInfo(HistoryUtility.Satisfaction);
public BarInfo SexSkill { get; private set; } public BarInfo SexSkill { get; } = new BarInfo(HistoryUtility.Tzeentch);
public string VirginLabel { get; private set; } public string VirginLabel { get; private set; }
public string SexualityLabel { get; private set; } public string SexualityLabel { get; private set; }
public string QuirksLabel { get; private set; } public string QuirksLabel { get; private set; }
@ -163,107 +162,91 @@ namespace RJWSexperience.SexHistory.UI
} }
SexTypes.Add(new BarInfo( SexTypes.Add(new BarInfo(
label: String.Format(Keyed.RS_Sex_Partners + ": {0} ({1})", _history.PartnerCount, Pawn.records.GetValue(RsDefOf.Record.SexPartnerCount)), label: string.Format(Keyed.RS_Sex_Partners + ": {0} ({1})", _history.PartnerCount, Pawn.records.GetValue(RsDefOf.Record.SexPartnerCount)),
fillPercent: _history.PartnerCount / 50, fillPercent: _history.PartnerCount / 50,
fillTexture: HistoryUtility.Partners)); fillTexture: HistoryUtility.Partners));
SexTypes.Add(new BarInfo( SexTypes.Add(new BarInfo(
label: String.Format(Keyed.RS_VirginsTaken + ": {0:0}", _history.VirginsTaken), label: string.Format(Keyed.RS_VirginsTaken + ": {0:0}", _history.VirginsTaken),
fillPercent: _history.VirginsTaken / 100, fillPercent: _history.VirginsTaken / 100,
fillTexture: HistoryUtility.Partners)); fillTexture: HistoryUtility.Partners));
TotalSex = new BarInfo( TotalSex.Label = string.Format(Keyed.RS_TotalSexHad + ": {0:0} ({1:0})", _history.TotalSexHad, Pawn.records.GetValue(xxx.CountOfSex));
label: String.Format(Keyed.RS_TotalSexHad + ": {0:0} ({1:0})", _history.TotalSexHad, Pawn.records.GetValue(xxx.CountOfSex)), TotalSex.FillPercent = _history.TotalSexHad / 100;
fillPercent: _history.TotalSexHad / 100, TotalSex.LabelRight = Keyed.RS_SatAVG(_history.AVGSat);
fillTexture: HistoryUtility.TotalSex,
labelRight: Keyed.RS_SatAVG(_history.AVGSat));
float lust = Pawn.records.GetValue(RsDefOf.Record.Lust); float lust = Pawn.records.GetValue(RsDefOf.Record.Lust);
float sexDrive = GetStatValue(xxx.sex_drive_stat); float sexDrive = GetStatValue(xxx.sex_drive_stat);
float lustLimit = SexperienceMod.Settings.LustLimit * 3f; float lustLimit = SexperienceMod.Settings.LustLimit * 3f;
Lust = new BarInfo( Lust.Label = string.Format(Keyed.Lust + ": {0:0.00}", lust);
label: String.Format(Keyed.Lust + ": {0:0.00}", lust), Lust.FillPercent = lust.Normalization(-lustLimit, lustLimit);
fillPercent: Mathf.Clamp01(lust.Normalization(-lustLimit, lustLimit)), Lust.Tooltip = GetStatTooltip(xxx.sex_drive_stat, sexDrive);
fillTexture: HistoryUtility.Slaanesh, Lust.LabelRight = xxx.sex_drive_stat.LabelCap + ": " + sexDrive.ToStringPercent();
tooltip: GetStatTooltip(xxx.sex_drive_stat, sexDrive),
labelRight: xxx.sex_drive_stat.LabelCap + ": " + sexDrive.ToStringPercent());
float bestSextypeRelativeSatisfaction = _history.GetBestSextype(out xxx.rjwSextype bestSextype) / UIUtility.BASESAT; float bestSextypeRelativeSatisfaction = _history.GetBestSextype(out xxx.rjwSextype bestSextype) / UIUtility.BASESAT;
BestSextype = new BarInfo( BestSextype.Label = string.Format(Keyed.RS_Best_Sextype + ": {0}", Keyed.Sextype[(int)bestSextype]);
label: String.Format(Keyed.RS_Best_Sextype + ": {0}", Keyed.Sextype[(int)bestSextype]), BestSextype.FillPercent = bestSextypeRelativeSatisfaction / 2;
fillPercent: bestSextypeRelativeSatisfaction / 2, BestSextype.FillTexture = HistoryUtility.SextypeColor[(int)bestSextype];
fillTexture: HistoryUtility.SextypeColor[(int)bestSextype], BestSextype.LabelRight = Keyed.RS_SatAVG(bestSextypeRelativeSatisfaction);
labelRight: Keyed.RS_SatAVG(bestSextypeRelativeSatisfaction));
float recentSextypeRelativeSatisfaction = _history.GetRecentSextype(out xxx.rjwSextype recentSextype) / UIUtility.BASESAT; float recentSextypeRelativeSatisfaction = _history.GetRecentSextype(out xxx.rjwSextype recentSextype) / UIUtility.BASESAT;
RecentSextype = new BarInfo( RecentSextype.Label = string.Format(Keyed.RS_Recent_Sextype + ": {0}", Keyed.Sextype[(int)recentSextype]);
label: String.Format(Keyed.RS_Recent_Sextype + ": {0}", Keyed.Sextype[(int)recentSextype]), RecentSextype.FillPercent = recentSextypeRelativeSatisfaction / 2;
fillPercent: recentSextypeRelativeSatisfaction / 2, RecentSextype.FillTexture = HistoryUtility.SextypeColor[(int)recentSextype];
fillTexture: HistoryUtility.SextypeColor[(int)recentSextype], RecentSextype.LabelRight = recentSextypeRelativeSatisfaction.ToStringPercent();
labelRight: recentSextypeRelativeSatisfaction.ToStringPercent());
Necro = new BarInfo( Necro.Label = string.Format(Keyed.RS_Necrophile + ": {0}", _history.CorpseFuckCount);
label: String.Format(Keyed.RS_Necrophile + ": {0}", _history.CorpseFuckCount), Necro.FillPercent = _history.CorpseFuckCount / 50f;
fillPercent: _history.CorpseFuckCount / 50,
fillTexture: HistoryUtility.Nurgle);
Incest = new BarInfo( Incest.Label = string.Format(Keyed.Incest + ": {0}", _history.IncestuousCount);
label: String.Format(Keyed.Incest + ": {0}", _history.IncestuousCount), Incest.FillPercent = _history.IncestuousCount / 50f;
fillPercent: _history.IncestuousCount / 50,
fillTexture: HistoryUtility.Nurgle);
float amountofEatenCum = Pawn.records.GetValue(RsDefOf.Record.AmountofEatenCum); float amountofEatenCum = Pawn.records.GetValue(RsDefOf.Record.AmountofEatenCum);
ConsumedCum = new BarInfo( ConsumedCum.Label = string.Format(Keyed.RS_Cum_Swallowed + ": {0} mL, {1} " + Keyed.RS_NumofTimes, amountofEatenCum, Pawn.records.GetValue(RsDefOf.Record.NumofEatenCum));
label: String.Format(Keyed.RS_Cum_Swallowed + ": {0} mL, {1} " + Keyed.RS_NumofTimes, amountofEatenCum, Pawn.records.GetValue(RsDefOf.Record.NumofEatenCum)), ConsumedCum.FillPercent = amountofEatenCum / 1000;
fillPercent: amountofEatenCum / 1000,
fillTexture: Texture2D.linearGrayTexture);
Hediff cumHediff = Pawn.health.hediffSet.GetFirstHediffOfDef(RsDefOf.Hediff.CumAddiction) Hediff cumHediff = Pawn.health.hediffSet.GetFirstHediffOfDef(RsDefOf.Hediff.CumAddiction)
?? Pawn.health.hediffSet.GetFirstHediffOfDef(RsDefOf.Hediff.CumTolerance); ?? Pawn.health.hediffSet.GetFirstHediffOfDef(RsDefOf.Hediff.CumTolerance);
if (cumHediff != null) if (cumHediff != null)
{ {
CumHediff = new BarInfo( CumHediff.Label = $"{cumHediff.Label}: {cumHediff.Severity.ToStringPercent()}";
label: $"{cumHediff.Label}: {cumHediff.Severity.ToStringPercent()}", CumHediff.FillPercent = cumHediff.Severity;
fillPercent: cumHediff.Severity, CumHediff.Tooltip = new TipSignal(() => cumHediff.GetTooltip(Pawn, false), cumHediff.Label.GetHashCode());
fillTexture: Texture2D.linearGrayTexture, }
tooltip: new TipSignal(() => cumHediff.GetTooltip(Pawn, false), cumHediff.Label.GetHashCode())); else
{
CumHediff.Label = "";
CumHediff.FillPercent = 0f;
CumHediff.Tooltip = default;
} }
float vulnerability = GetStatValue(xxx.vulnerability_stat); float vulnerability = GetStatValue(xxx.vulnerability_stat);
string vulnerabilityLabel = xxx.vulnerability_stat.LabelCap + ": " + vulnerability.ToStringPercent(); string vulnerabilityLabel = xxx.vulnerability_stat.LabelCap + ": " + vulnerability.ToStringPercent();
TipSignal vulnerabilityTip = GetStatTooltip(xxx.vulnerability_stat, vulnerability); TipSignal vulnerabilityTip = GetStatTooltip(xxx.vulnerability_stat, vulnerability);
Raped = new BarInfo( Raped.Label = string.Format(Keyed.RS_RapedSomeone + ": {0}", _history.RapedCount);
label: String.Format(Keyed.RS_RapedSomeone + ": {0}", _history.RapedCount), Raped.FillPercent = _history.RapedCount / 50f;
fillPercent: _history.RapedCount / 50, Raped.Tooltip = vulnerabilityTip;
fillTexture: HistoryUtility.Khorne, Raped.LabelRight = vulnerabilityLabel;
tooltip: vulnerabilityTip,
labelRight: vulnerabilityLabel);
BeenRaped = new BarInfo( BeenRaped.Label = string.Format(Keyed.RS_BeenRaped + ": {0}", _history.BeenRapedCount);
label: String.Format(Keyed.RS_BeenRaped + ": {0}", _history.BeenRapedCount), BeenRaped.FillPercent = _history.BeenRapedCount / 50f;
fillPercent: _history.BeenRapedCount / 50, BeenRaped.Tooltip = vulnerabilityTip;
fillTexture: Texture2D.grayTexture, BeenRaped.LabelRight = vulnerabilityLabel;
tooltip: vulnerabilityTip,
labelRight: vulnerabilityLabel);
float sexSatisfaction = GetStatValue(xxx.sex_satisfaction); float sexSatisfaction = GetStatValue(xxx.sex_satisfaction);
SexSatisfaction = new BarInfo( SexSatisfaction.Label = xxx.sex_satisfaction.LabelCap + ": " + sexSatisfaction.ToStringPercent();
label: xxx.sex_satisfaction.LabelCap + ": " + sexSatisfaction.ToStringPercent(), SexSatisfaction.FillPercent = sexSatisfaction / 2;
fillPercent: sexSatisfaction / 2, SexSatisfaction.Tooltip = GetStatTooltip(xxx.sex_satisfaction, sexSatisfaction);
fillTexture: HistoryUtility.Satisfaction,
tooltip: GetStatTooltip(xxx.sex_satisfaction, sexSatisfaction));
SkillRecord skill = Pawn.skills?.GetSkill(RsDefOf.Skill.Sex); SkillRecord skill = Pawn.skills?.GetSkill(RsDefOf.Skill.Sex);
float sexSkillLevel = skill?.Level ?? 0f; float sexSkillLevel = skill?.Level ?? 0f;
float sexStat = Pawn.GetSexStat(); float sexStat = Pawn.GetSexStat();
SexSkill = new BarInfo( SexSkill.Label = $"{Keyed.RS_SexSkill}: {sexSkillLevel}, {skill?.xpSinceLastLevel / skill?.XpRequiredForLevelUp:P2}";
label: $"{Keyed.RS_SexSkill}: {sexSkillLevel}, {skill?.xpSinceLastLevel / skill?.XpRequiredForLevelUp:P2}", SexSkill.FillPercent = sexSkillLevel / 20;
fillPercent: sexSkillLevel / 20, SexSkill.Tooltip = GetStatTooltip(RsDefOf.Stat.SexAbility, sexStat);
fillTexture: HistoryUtility.Tzeentch, SexSkill.LabelRight = RsDefOf.Stat.SexAbility.LabelCap + ": " + sexStat.ToStringPercent();
tooltip: GetStatTooltip(RsDefOf.Stat.SexAbility, sexStat), SexSkill.Border = HistoryUtility.GetPassionBG(skill?.passion);
labelRight: RsDefOf.Stat.SexAbility.LabelCap + ": " + sexStat.ToStringPercent(),
border: HistoryUtility.GetPassionBG(skill?.passion));
} }
private void UpdateQuirks() private void UpdateQuirks()

View File

@ -240,7 +240,7 @@ namespace RJWSexperience.SexHistory.UI
if (preferedRaceCard.barInfo != null) if (preferedRaceCard.barInfo != null)
{ {
UIUtility.FillableBarLabeled(infoRect3, (BarInfo)preferedRaceCard.barInfo); UIUtility.FillableBarLabeled(infoRect3, preferedRaceCard.barInfo);
} }
} }
@ -304,7 +304,7 @@ namespace RJWSexperience.SexHistory.UI
listmain.FillableBarLabeled(_context.BestSextype); listmain.FillableBarLabeled(_context.BestSextype);
listmain.FillableBarLabeled(_context.RecentSextype); listmain.FillableBarLabeled(_context.RecentSextype);
if (_context.Incest.fillPercent < _context.Necro.fillPercent) if (_context.Incest.FillPercent < _context.Necro.FillPercent)
{ {
listmain.FillableBarLabeled(_context.Necro); listmain.FillableBarLabeled(_context.Necro);
} }
@ -315,16 +315,16 @@ namespace RJWSexperience.SexHistory.UI
listmain.FillableBarLabeled(_context.ConsumedCum); listmain.FillableBarLabeled(_context.ConsumedCum);
if (_context.CumHediff != null) if (_context.CumHediff.Label != "")
{ {
listmain.FillableBarLabeled((BarInfo)_context.CumHediff); listmain.FillableBarLabeled(_context.CumHediff);
} }
else else
{ {
listmain.Gap(FONTHEIGHT + 1f); listmain.Gap(FONTHEIGHT + 1f);
} }
if (_context.Raped.fillPercent < _context.BeenRaped.fillPercent) if (_context.Raped.FillPercent < _context.BeenRaped.FillPercent)
{ {
listmain.FillableBarLabeled(_context.BeenRaped); listmain.FillableBarLabeled(_context.BeenRaped);
} }

View File

@ -52,22 +52,22 @@ namespace RJWSexperience.SexHistory.UI
public static void FillableBarLabeled(Rect rect, BarInfo context) public static void FillableBarLabeled(Rect rect, BarInfo context)
{ {
Widgets.FillableBar(rect, context.fillPercent, context.fillTexture, null, true); Widgets.FillableBar(rect, context.FillPercent, context.FillTexture, null, true);
Rect labelRect = rect.ContractedBy(4f, 0f); Rect labelRect = rect.ContractedBy(4f, 0f);
Text.Anchor = TextAnchor.MiddleLeft; Text.Anchor = TextAnchor.MiddleLeft;
Widgets.Label(labelRect, context.label); Widgets.Label(labelRect, context.Label);
if (context.labelRight != "") if (context.LabelRight != "")
{ {
Text.Anchor = TextAnchor.MiddleRight; Text.Anchor = TextAnchor.MiddleRight;
Widgets.Label(labelRect, context.labelRight); Widgets.Label(labelRect, context.LabelRight);
} }
GenUI.ResetLabelAlign(); GenUI.ResetLabelAlign();
Widgets.DrawHighlightIfMouseover(rect); Widgets.DrawHighlightIfMouseover(rect);
TooltipHandler.TipRegion(rect, context.tooltip); TooltipHandler.TipRegion(rect, context.Tooltip);
if (context.border != null) if (context.Border != null)
{ {
rect.DrawBorder(context.border, 2f); rect.DrawBorder(context.Border, 2f);
} }
} }