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
{
public readonly struct BarInfo
public class BarInfo
{
public readonly string label;
public readonly float fillPercent;
public readonly Texture2D fillTexture;
public readonly TipSignal tooltip;
public readonly string labelRight;
public readonly Texture2D border;
private string _label;
private float _fillPercent;
private string _labelRight;
public string Label
{
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)
{
this.label = label.CapitalizeFirst();
this.fillPercent = Mathf.Clamp01(fillPercent);
this.fillTexture = fillTexture;
this.tooltip = tooltip;
this.labelRight = labelRight.CapitalizeFirst();
this.border = border;
_label = label.CapitalizeFirst();
_fillPercent = Mathf.Clamp01(fillPercent);
FillTexture = fillTexture;
Tooltip = tooltip;
_labelRight = labelRight.CapitalizeFirst();
Border = border;
}
public BarInfo(string label, float fillPercent, Texture2D fillTexture, string labelRight = "")
{
this.label = label.CapitalizeFirst();
this.fillPercent = Mathf.Clamp01(fillPercent);
this.fillTexture = fillTexture;
this.tooltip = default;
this.labelRight = labelRight.CapitalizeFirst();
this.border = null;
_label = label.CapitalizeFirst();
_fillPercent = Mathf.Clamp01(fillPercent);
FillTexture = fillTexture;
Tooltip = default;
_labelRight = labelRight.CapitalizeFirst();
Border = null;
}
}
}

View File

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

View File

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

View File

@ -240,7 +240,7 @@ namespace RJWSexperience.SexHistory.UI
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.RecentSextype);
if (_context.Incest.fillPercent < _context.Necro.fillPercent)
if (_context.Incest.FillPercent < _context.Necro.FillPercent)
{
listmain.FillableBarLabeled(_context.Necro);
}
@ -315,16 +315,16 @@ namespace RJWSexperience.SexHistory.UI
listmain.FillableBarLabeled(_context.ConsumedCum);
if (_context.CumHediff != null)
if (_context.CumHediff.Label != "")
{
listmain.FillableBarLabeled((BarInfo)_context.CumHediff);
listmain.FillableBarLabeled(_context.CumHediff);
}
else
{
listmain.Gap(FONTHEIGHT + 1f);
}
if (_context.Raped.fillPercent < _context.BeenRaped.fillPercent)
if (_context.Raped.FillPercent < _context.BeenRaped.FillPercent)
{
listmain.FillableBarLabeled(_context.BeenRaped);
}

View File

@ -52,22 +52,22 @@ namespace RJWSexperience.SexHistory.UI
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);
Text.Anchor = TextAnchor.MiddleLeft;
Widgets.Label(labelRect, context.label);
if (context.labelRight != "")
Widgets.Label(labelRect, context.Label);
if (context.LabelRight != "")
{
Text.Anchor = TextAnchor.MiddleRight;
Widgets.Label(labelRect, context.labelRight);
Widgets.Label(labelRect, context.LabelRight);
}
GenUI.ResetLabelAlign();
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);
}
}