Refactored/optimized SexStatusWindow

This commit is contained in:
amevarashi 2023-04-16 12:09:50 +05:00
parent e9ca084680
commit cdc79acfa3
16 changed files with 1178 additions and 797 deletions

View File

@ -43,6 +43,7 @@
<RS_Ago>ago</RS_Ago>
<RS_LastSex>last sex</RS_LastSex>
<RS_HadBestSexDaysAgo>Had best sex {0}.</RS_HadBestSexDaysAgo>
<RS_PawnLockDesc>Lock displayed pawn.\n\nWhen unlocked, window will automatically switch to a currently selected pawn.</RS_PawnLockDesc>
<!-- Settings tab labels -->
<RSTabLabelMain>Main</RSTabLabelMain>

View File

@ -9,12 +9,14 @@ namespace RJWSexperience
public static class Keyed
{
public static string RS_LostVirgin(string pawn, string partner) => "RS_LostVirgin".Translate(pawn.Colorize(Color.yellow), partner.Colorize(Color.yellow));
public static string RS_Sex_Info(string sextype, string sexcount) => "RS_Sex_Info".Translate(sextype, sexcount);
public static string RS_SAT_AVG(string avgsat) => "RS_SAT_AVG".Translate(avgsat);
public static string RS_SexInfo(string sextype, int sexcount) => string.Format(RS_Sex_Info, sextype, sexcount);
public static string RS_SatAVG(float avgsat) => string.Format(RS_SAT_AVG, avgsat.ToStringPercent());
public static string RS_HadBestSexDaysAgo(string days) => "RS_HadBestSexDaysAgo".Translate(days);
public static readonly string Mod_Title = "RS_Mod_Title".Translate();
public static readonly string RSTotalGatheredCum = "RSTotalGatheredCum".Translate();
public static readonly string RS_Sex_Info = "RS_Sex_Info".Translate();
public static readonly string RS_SAT_AVG = "RS_SAT_AVG".Translate();
public static readonly string RS_Best_Sextype = "RS_Best_Sextype".Translate();
public static readonly string RS_Recent_Sextype = "RS_Recent_Sextype".Translate();
public static readonly string RS_Sex_Partners = "RS_Sex_Partners".Translate();
@ -51,7 +53,8 @@ namespace RJWSexperience
public static readonly string RS_SexSkill = "RS_SexSkill".Translate();
public static readonly string RS_NumofTimes = "RS_NumofTimes".Translate();
public static readonly string RS_Ago = "RS_Ago".Translate();
public static readonly string RS_LastSex = "RS_LastSex".Translate();
public static readonly string RS_LastSex = "RS_LastSex".Translate().CapitalizeFirst();
public static readonly string RS_PawnLockDesc = "RS_PawnLockDesc".Translate();
[MayRequireRoyalty] public static readonly string Slave = "Slave".Translate();
public static readonly string TabLabelMain = "RSTabLabelMain".Translate();

View File

@ -30,6 +30,9 @@
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup>
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
</PropertyGroup>
<ItemGroup>
<Reference Include="RJW">
<HintPath>..\..\..\rjw\1.4\Assemblies\RJW.dll</HintPath>
@ -64,6 +67,12 @@
<Compile Include="Settings\SettingsContainer.cs" />
<Compile Include="Settings\SettingsTab.cs" />
<Compile Include="Settings\SettingsTabMain.cs" />
<Compile Include="SexHistory\UI\BarInfo.cs" />
<Compile Include="SexHistory\UI\PartnerPortraitInfo.cs" />
<Compile Include="SexHistory\UI\PreferedRaceCard.cs" />
<Compile Include="SexHistory\UI\InfoCard.cs" />
<Compile Include="SexHistory\UI\PartnerOrderMode.cs" />
<Compile Include="SexHistory\UI\SexStatusViewModel.cs" />
<Compile Include="Virginity\Recipe_HymenSurgery.cs" />
<Compile Include="Settings\SettingsTabHistory.cs" />
<Compile Include="Settings\SettingsTabDebug.cs" />
@ -86,8 +95,8 @@
<Compile Include="Cum\Thought_AteCum.cs" />
<Compile Include="Thoughts\Thought_Recordbased.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="SexHistory\UI\RJWUIUtility.cs" />
<Compile Include="SexHistory\UI\SexStatus.cs" />
<Compile Include="SexHistory\UI\UIUtility.cs" />
<Compile Include="SexHistory\UI\SexStatusWindow.cs" />
<Compile Include="Utility.cs" />
<Compile Include="VariousDefOf.cs" />
<Compile Include="Virginity\TraitDegree.cs" />

View File

@ -1,5 +1,4 @@
using RimWorld;
using System;
using UnityEngine;
using Verse;

View File

@ -90,15 +90,15 @@ namespace RJWSexperience.SexHistory
}
}
public int VirginsTaken => virginsTaken;
public List<SexPartnerHistoryRecord> PartnerList
public IEnumerable<SexPartnerHistoryRecord> PartnerList
{
get
{
List<SexPartnerHistoryRecord> res = null;
IEnumerable<SexPartnerHistoryRecord> res = Enumerable.Empty<SexPartnerHistoryRecord>();
Update();
if (!histories.NullOrEmpty())
{
res = histories.Values.ToList();
res = histories.Values;
}
return res;
}
@ -443,10 +443,7 @@ namespace RJWSexperience.SexHistory
icon = HistoryUtility.HistoryIcon,
defaultIconColor = HistoryUtility.HistoryColor,
hotKey = VariousDefOf.OpenSexStatistics,
action = delegate
{
UI.SexStatusWindow.ToggleWindow(ParentPawn, this);
}
action = () => UI.SexStatusWindow.ToggleWindow(this)
};
}
}

View File

@ -1,6 +1,5 @@
using rjw;
using RJWSexperience.ExtensionMethods;
using System.Collections.Generic;
using Verse;
namespace RJWSexperience.SexHistory
@ -131,33 +130,5 @@ namespace RJWSexperience.SexHistory
}
partner = Find.WorldPawns.AllPawnsAliveOrDead.Find(x => x.ThingID.Equals(partnerID));
}
#region OrderComparers
public class RecentOrderComparer : IComparer<SexPartnerHistoryRecord>
{
public int Compare(SexPartnerHistoryRecord x, SexPartnerHistoryRecord y)
{
return y.RecentSexTickAbs.CompareTo(x.RecentSexTickAbs);
}
}
public class MostOrderComparer : IComparer<SexPartnerHistoryRecord>
{
public int Compare(SexPartnerHistoryRecord x, SexPartnerHistoryRecord y)
{
return y.TotalSexCount.CompareTo(x.TotalSexCount);
}
}
public class NameOrderComparer : IComparer<SexPartnerHistoryRecord>
{
public int Compare(SexPartnerHistoryRecord x, SexPartnerHistoryRecord y)
{
return x.Label.CompareTo(y.Label);
}
}
#endregion OrderComparers
}
}

View File

@ -0,0 +1,35 @@
using UnityEngine;
using Verse;
namespace RJWSexperience.SexHistory.UI
{
public readonly struct 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;
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;
}
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;
}
}
}

View File

@ -0,0 +1,86 @@
using RimWorld;
using rjw;
using System;
using UnityEngine;
using Verse;
namespace RJWSexperience.SexHistory.UI
{
public readonly struct InfoCard
{
public readonly SexPartnerHistoryRecord partnerRecord;
public readonly string label;
public readonly string lastSexTime;
public readonly string name;
public readonly string sexCount;
public readonly string orgasms;
public readonly string relations;
public readonly BarInfo bestSextype;
public readonly PartnerPortraitInfo portraitInfo;
public readonly TipSignal tooltip;
public InfoCard(Pawn pawn, SexPartnerHistoryRecord partnerRecord, string label, string tooltipLabel, int lastSexTimeTicks)
{
this.partnerRecord = partnerRecord;
this.label = label;
lastSexTime = UIUtility.GetSexDays(lastSexTimeTicks);
portraitInfo = new PartnerPortraitInfo(pawn, partnerRecord);
if (partnerRecord != null)
{
name = partnerRecord.Partner?.Name?.ToStringFull ?? partnerRecord.Label.CapitalizeFirst();
sexCount = Keyed.RS_Sex_Count + partnerRecord.TotalSexCount;
if (partnerRecord.Raped > 0)
{
sexCount += " " + Keyed.RS_Raped + partnerRecord.Raped;
}
if (partnerRecord.RapedMe > 0)
{
sexCount += " " + Keyed.RS_RapedMe + partnerRecord.RapedMe;
}
orgasms = Keyed.RS_Orgasms + partnerRecord.OrgasmCount;
relations = pawn.GetRelationsString(partnerRecord.Partner);
tooltip = new TipSignal(() =>
{
string completeTip = tooltipLabel;
if (partnerRecord.Incest)
{
completeTip += " - " + Keyed.Incest;
}
if (partnerRecord.IamFirst)
{
completeTip += "\n" + Keyed.RS_LostVirgin(partnerRecord.Label, pawn.LabelShort);
}
if (partnerRecord.BestSexTickAbs != 0)
{
completeTip += "\n" + Keyed.RS_HadBestSexDaysAgo(partnerRecord.BestSexElapsedTicks.ToStringTicksToDays() + " " + Keyed.RS_Ago);
}
return completeTip;
}, tooltipLabel.GetHashCode());
float relativeBestSatisfaction = partnerRecord.BestSatisfaction / UIUtility.BASESAT;
bestSextype = new BarInfo(
label: Keyed.RS_Best_Sextype + ": " + Keyed.Sextype[(int)partnerRecord.BestSextype],
fillPercent: relativeBestSatisfaction / 2,
fillTexture: HistoryUtility.SextypeColor[(int)partnerRecord.BestSextype],
labelRight: relativeBestSatisfaction.ToStringPercent());
}
else
{
name = Keyed.Unknown;
sexCount = Keyed.RS_Sex_Count + "?";
orgasms = Keyed.RS_Orgasms + "?";
relations = string.Empty;
tooltip = default;
bestSextype = new BarInfo(
label: String.Format(Keyed.RS_Best_Sextype + ": {0}", Keyed.Sextype[(int)xxx.rjwSextype.None]),
fillPercent: 0f,
fillTexture: Texture2D.linearGrayTexture);
}
}
}
}

View File

@ -0,0 +1,18 @@
namespace RJWSexperience.SexHistory.UI
{
public enum PartnerOrderMode
{
Normal = 0,
Recent = 1,
Most = 2,
Name = 3
};
public static class PartnerOrderModeExtension
{
public static PartnerOrderMode Next(this PartnerOrderMode mode)
{
return (PartnerOrderMode)(((int)mode + 1) % 4);
}
}
}

View File

@ -0,0 +1,34 @@
using RimWorld;
using System;
using UnityEngine;
using Verse;
namespace RJWSexperience.SexHistory.UI
{
public readonly struct PartnerPortraitInfo
{
public readonly SexPartnerHistoryRecord partnerRecord;
public readonly bool lover;
public readonly Func<Vector2, Texture> portraitGetter;
public PartnerPortraitInfo(Pawn pawn, SexPartnerHistoryRecord partnerRecord)
{
this.partnerRecord = partnerRecord;
lover = false;
if (partnerRecord?.Partner != null)
{
portraitGetter = (size) => PortraitsCache.Get(partnerRecord.Partner, size, Rot4.South, default, 1, true, true, false, false);
lover = LovePartnerRelationUtility.LovePartnerRelationExists(pawn, partnerRecord.Partner);
}
else if (partnerRecord?.Race?.uiIcon != null)
{
portraitGetter = (_) => partnerRecord.Race.uiIcon;
}
else
{
portraitGetter = (_) => HistoryUtility.UnknownPawn;
}
}
}
}

View File

@ -0,0 +1,56 @@
using System;
using UnityEngine;
namespace RJWSexperience.SexHistory.UI
{
public readonly struct PreferedRaceCard
{
public readonly string preferRaceLabel;
public readonly string preferRaceTypeLabel;
public readonly string sexCount;
public readonly BarInfo? barInfo;
public readonly Func<Vector2, Texture> portraitGetter;
public PreferedRaceCard(SexHistoryComp sexHistory)
{
if (sexHistory.PreferRace == null)
{
preferRaceLabel = Keyed.None;
preferRaceTypeLabel = null;
sexCount = null;
barInfo = null;
portraitGetter = (_) => HistoryUtility.UnknownPawn;
return;
}
preferRaceLabel = sexHistory.PreferRace.LabelCap;
sexCount = Keyed.RS_Sex_Count + sexHistory.PreferRaceSexCount;
portraitGetter = (size) => UIUtility.GetRaceIcon(sexHistory.PreferRacePawn, size);
if (sexHistory.PreferRace != sexHistory.ParentPawn.def)
{
if (sexHistory.PreferRace.race.Animal != sexHistory.ParentPawn.def.race.Animal)
{
preferRaceTypeLabel = Keyed.RS_Bestiality;
barInfo = new BarInfo(
label: Keyed.RS_SexInfo(Keyed.RS_Bestiality, sexHistory.BestialityCount),
fillPercent: sexHistory.BestialityCount / 100f,
fillTexture: Texture2D.linearGrayTexture);
}
else
{
preferRaceTypeLabel = Keyed.RS_Interspecies;
barInfo = new BarInfo(
label: Keyed.RS_SexInfo(Keyed.RS_Interspecies, sexHistory.InterspeciesCount),
fillPercent: sexHistory.InterspeciesCount / 100f,
fillTexture: Texture2D.linearGrayTexture);
}
}
else
{
preferRaceTypeLabel = null;
barInfo = null;
}
}
}
}

View File

@ -1,101 +0,0 @@
using RimWorld;
using rjw;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using UnityEngine;
using Verse;
namespace RJWSexperience.SexHistory.UI
{
public static class RJWUIUtility
{
public const float FONTHEIGHT = 22f;
public const float CARDHEIGHT = 110f;
public const float LISTPAWNSIZE = 100f;
public const float BASESAT = 0.40f;
public const float ICONSIZE = 30f;
public static void DrawQuirk(this Rect rect, Pawn pawn)
{
List<Quirk> quirks = Quirk.All.FindAll(x => pawn.Has(x));
string quirkstr = quirks.Select(x => x.Key).ToCommaList();
string tooltip = "";
Widgets.Label(rect, "Quirks".Translate() + quirkstr);
if (Mouse.IsOver(rect))
{
if (quirks.NullOrEmpty())
{
tooltip = "NoQuirks".Translate();
}
else
{
StringBuilder stringBuilder = new StringBuilder();
foreach (var q in quirks)
{
stringBuilder.AppendLine(q.Key.Colorize(Color.yellow));
stringBuilder.AppendLine(q.LocaliztionKey.Translate(pawn.Named("pawn")).AdjustedFor(pawn).Resolve());
stringBuilder.AppendLine("");
}
tooltip = stringBuilder.ToString().TrimEndNewlines();
}
Widgets.DrawHighlight(rect);
}
TooltipHandler.TipRegion(rect, tooltip);
}
public static void DrawSexuality(this Rect rect, CompRJW comp)
{
if (comp != null)
{
string sexuality = Keyed.Sexuality[(int)comp.orientation];
Widgets.Label(rect, Keyed.RS_Sexuality + ": " + sexuality);
Widgets.DrawHighlightIfMouseover(rect);
}
}
public static string GetRelationsString(this Pawn pawn, Pawn otherpawn)
{
if (otherpawn != null)
{
IEnumerable<PawnRelationDef> relations = pawn.GetRelations(otherpawn);
if (!relations.EnumerableNullOrEmpty()) return relations.Select(x => x.GetGenderSpecificLabel(otherpawn)).ToCommaList().CapitalizeFirst();
}
return "";
}
public static void DrawBorder(this Rect rect, Texture border, float thickness = 1f)
{
GUI.DrawTexture(new Rect(rect.x, rect.y, rect.width, thickness), border);
GUI.DrawTexture(new Rect(rect.x + rect.width - thickness, rect.y, thickness, rect.height), border);
GUI.DrawTexture(new Rect(rect.x, rect.y + rect.height - thickness, rect.width, thickness), border);
GUI.DrawTexture(new Rect(rect.x, rect.y, thickness, rect.height), border);
}
public static string GetStatExplanation(Pawn pawn, StatDef stat, float val)
{
if (!pawn.Dead)
return stat.description + "\n" + stat.Worker.GetExplanationFull(StatRequest.For(pawn), ToStringNumberSense.Undefined, val);
return "Dead".Translate();
}
public static string GetSexDays(int absticks, bool printUnknown = false)
{
if (absticks != 0)
return GenDate.ToStringTicksToDays(GenTicks.TicksAbs - absticks) + " " + Keyed.RS_Ago;
else if (printUnknown)
return Keyed.Unknown;
return "";
}
public static Texture GetRaceIcon(Pawn pawn, Vector2 size)
{
if (pawn != null)
return PortraitsCache.Get(pawn, size, Rot4.South, default, 1, true, true, false, false);
return HistoryUtility.UnknownPawn;
}
}
}

View File

@ -1,654 +0,0 @@
using RimWorld;
using rjw;
using System;
using System.Collections.Generic;
using System.Linq;
using UnityEngine;
using Verse;
using Verse.Sound;
namespace RJWSexperience.SexHistory.UI
{
public enum PartnerOrderMode
{
Normal = 0,
Recent = 1,
Most = 2,
Name, MaxValue = 3
};
public static class PartnerOrderModeExtension
{
public static PartnerOrderMode Next(this PartnerOrderMode mode)
{
return (PartnerOrderMode)(((int)mode + 1) % ((int)PartnerOrderMode.MaxValue + 1));
}
}
public class SexStatusWindow : Window
{
public const float WINDOW_WIDTH = 900f;
public const float WINDOW_HEIGHT = 600f;
public const float FONTHEIGHT = RJWUIUtility.FONTHEIGHT;
public const float CARDHEIGHT = RJWUIUtility.CARDHEIGHT;
public const float LISTPAWNSIZE = RJWUIUtility.LISTPAWNSIZE;
public const float BASESAT = RJWUIUtility.BASESAT;
public const float ICONSIZE = RJWUIUtility.ICONSIZE;
public static readonly int[] Sextype =
{
(int)xxx.rjwSextype.Vaginal,
(int)xxx.rjwSextype.Anal,
(int)xxx.rjwSextype.Oral,
(int)xxx.rjwSextype.Fellatio,
(int)xxx.rjwSextype.Cunnilingus,
(int)xxx.rjwSextype.DoublePenetration,
(int)xxx.rjwSextype.Boobjob,
(int)xxx.rjwSextype.Handjob,
(int)xxx.rjwSextype.Footjob,
(int)xxx.rjwSextype.Fingering,
(int)xxx.rjwSextype.Scissoring,
(int)xxx.rjwSextype.MutualMasturbation,
(int)xxx.rjwSextype.Fisting,
(int)xxx.rjwSextype.Rimming,
(int)xxx.rjwSextype.Sixtynine
};
protected Pawn pawn;
protected SexPartnerHistoryRecord selectedPawn;
protected SexHistoryComp history;
protected CompRJW rjwcomp;
protected List<SexPartnerHistoryRecord> partnerList;
protected PartnerOrderMode orderMode;
private static GUIStyle fontStyleCenter;
private static GUIStyle fontStyleRight;
private static GUIStyle fontStyleLeft;
private static GUIStyle boxStyle;
private static GUIStyle buttonStyle;
private static Vector2 LastWindowPosition { get; set; }
private Vector2 scroll;
private static void InitStyles()
{
if (fontStyleCenter != null)
{
return;
}
GUIStyleState fontStyleState = new GUIStyleState() { textColor = Color.white };
GUIStyleState boxStyleState = GUI.skin.textArea.normal;
GUIStyleState buttonStyleState = GUI.skin.button.normal;
fontStyleCenter = new GUIStyle() { alignment = TextAnchor.MiddleCenter, normal = fontStyleState };
fontStyleRight = new GUIStyle() { alignment = TextAnchor.MiddleRight, normal = fontStyleState };
fontStyleLeft = new GUIStyle() { alignment = TextAnchor.MiddleLeft, normal = fontStyleState };
boxStyle = new GUIStyle(GUI.skin.textArea) { hover = boxStyleState, onHover = boxStyleState, onNormal = boxStyleState };
buttonStyle = new GUIStyle(GUI.skin.button) { hover = buttonStyleState, onHover = buttonStyleState, onNormal = buttonStyleState };
}
public SexStatusWindow(Pawn pawn, SexHistoryComp history)
{
this.pawn = pawn;
this.history = history;
this.selectedPawn = null;
this.rjwcomp = pawn.TryGetComp<CompRJW>();
this.partnerList = history?.PartnerList;
orderMode = PartnerOrderMode.Recent;
SortPartnerList(orderMode);
soundClose = SoundDefOf.CommsWindow_Close;
absorbInputAroundWindow = false;
forcePause = false;
preventCameraMotion = false;
draggable = true;
doCloseX = true;
}
protected override void SetInitialSizeAndPosition()
{
base.SetInitialSizeAndPosition();
if (LastWindowPosition == Vector2.zero)
return;
windowRect.x = LastWindowPosition.x;
windowRect.y = LastWindowPosition.y;
}
public override Vector2 InitialSize => new Vector2(WINDOW_WIDTH, WINDOW_HEIGHT);
public override void PreOpen()
{
base.PreOpen();
InitStyles();
}
public override void PreClose()
{
base.PreClose();
LastWindowPosition = windowRect.position;
}
public override void DoWindowContents(Rect inRect)
{
if (!SexperienceMod.Settings.SelectionLocked)
{
List<Pawn> selected = Find.Selector.SelectedPawns;
if (selected.Count == 1)
{
Pawn p = selected.First();
if (p != pawn)
{
SexHistoryComp h = p.TryGetComp<SexHistoryComp>();
if (h != null) ChangePawn(p, h);
}
}
}
DrawSexStatus(inRect, history);
}
public static void ToggleWindow(Pawn pawn, SexHistoryComp history)
{
SexStatusWindow window = (SexStatusWindow)Find.WindowStack.Windows.FirstOrDefault(x => x.GetType() == typeof(SexStatusWindow));
if (window != null)
{
if (window.pawn != pawn)
{
SoundDefOf.TabOpen.PlayOneShotOnCamera();
window.ChangePawn(pawn, history);
}
}
else
{
Find.WindowStack.Add(new SexStatusWindow(pawn, history));
}
}
public void ChangePawn(Pawn pawn, SexHistoryComp history)
{
List<Pawn> selected = Find.Selector.SelectedPawns;
if (!selected.NullOrEmpty())
{
foreach (Pawn p in selected)
{
Find.Selector.Deselect(p);
}
}
this.pawn = pawn;
this.history = history;
this.selectedPawn = null;
this.rjwcomp = pawn.TryGetComp<CompRJW>();
this.partnerList = history?.PartnerList;
if (!pawn.DestroyedOrNull() && Find.CurrentMap == pawn.Map) Find.Selector.Select(pawn);
SortPartnerList(orderMode);
}
public void SortPartnerList(PartnerOrderMode mode)
{
if (partnerList.NullOrEmpty()) return;
switch (mode)
{
default:
partnerList = history?.PartnerList;
break;
case PartnerOrderMode.Recent:
partnerList.Sort(new SexPartnerHistoryRecord.RecentOrderComparer());
break;
case PartnerOrderMode.Most:
partnerList.Sort(new SexPartnerHistoryRecord.MostOrderComparer());
break;
case PartnerOrderMode.Name:
partnerList.Sort(new SexPartnerHistoryRecord.NameOrderComparer());
break;
}
}
/// <summary>
/// Main contents
/// </summary>
protected void DrawSexStatus(Rect mainrect, SexHistoryComp history)
{
float sectionwidth = mainrect.width / 3;
Rect leftRect = new Rect(mainrect.x, mainrect.y, sectionwidth, mainrect.height);
Rect centerRect = new Rect(mainrect.x + sectionwidth, mainrect.y, sectionwidth, mainrect.height);
Rect rightRect = new Rect(mainrect.x + (sectionwidth * 2), mainrect.y, sectionwidth, mainrect.height);
if (history != null)
{
//Left section
DrawBaseSexInfoLeft(leftRect.ContractedBy(4f));
//Center section
DrawBaseSexInfoCenter(centerRect.ContractedBy(4f), history.ParentPawn);
//Right section
DrawBaseSexInfoRight(rightRect.ContractedBy(4f));
}
}
protected void DrawInfoWithPortrait(Rect rect, SexPartnerHistoryRecord history, string tooltip = "")
{
Widgets.DrawMenuSection(rect);
string str = tooltip;
Rect portraitRect = new Rect(rect.x, rect.y, rect.height - FONTHEIGHT, rect.height - FONTHEIGHT);
Rect nameRect = new Rect(rect.x + portraitRect.width, rect.y, rect.width - portraitRect.width, FONTHEIGHT);
Rect sexinfoRect = new Rect(rect.x + portraitRect.width, rect.y + FONTHEIGHT, rect.width - portraitRect.width, FONTHEIGHT);
Rect sexinfoRect2 = new Rect(rect.x + portraitRect.width, rect.y + (FONTHEIGHT * 2), rect.width - portraitRect.width, FONTHEIGHT);
Rect bestsexRect = new Rect(rect.x + 2f, rect.y + (FONTHEIGHT * 3), rect.width - 4f, FONTHEIGHT - 2f);
if (history != null)
{
if (history.Incest) str += " - " + Keyed.Incest;
Pawn partner = history.Partner;
DrawPawn(portraitRect, history);
Widgets.DrawHighlightIfMouseover(portraitRect);
if (Widgets.ButtonInvisible(portraitRect))
{
SexHistoryComp pawnhistory = partner?.TryGetComp<SexHistoryComp>();
if (pawnhistory != null)
{
ChangePawn(partner, pawnhistory);
SoundDefOf.Click.PlayOneShotOnCamera();
}
else
{
SoundDefOf.ClickReject.PlayOneShotOnCamera();
}
}
string rapeInfo = "";
if (history.Raped > 0) rapeInfo += Keyed.RS_Raped + history.Raped + " ";
if (history.RapedMe > 0) rapeInfo += Keyed.RS_RapedMe + history.RapedMe;
GUI.Label(nameRect, partner?.Name?.ToStringFull ?? history.Label.CapitalizeFirst(), fontStyleLeft);
GUI.Label(sexinfoRect, Keyed.RS_Sex_Count + history.TotalSexCount + " " + rapeInfo, fontStyleLeft);
GUI.Label(sexinfoRect2, Keyed.RS_Orgasms + history.OrgasmCount, fontStyleLeft);
GUI.Label(sexinfoRect2, pawn.GetRelationsString(partner) + " ", fontStyleRight);
float p = history.BestSatisfaction / BASESAT;
FillableBarLabeled(bestsexRect, String.Format(Keyed.RS_Best_Sextype + ": {0}", Keyed.Sextype[(int)history.BestSextype]), p / 2, HistoryUtility.SextypeColor[(int)history.BestSextype], Texture2D.blackTexture, null, String.Format("{0:P2}", p));
if (history.IamFirst)
str += "\n" + Keyed.RS_LostVirgin(history.Label, pawn.LabelShort);
if (history.BestSexTickAbs != 0)
str += "\n" + Keyed.RS_HadBestSexDaysAgo(history.BestSexElapsedTicks.ToStringTicksToDays() + " " + Keyed.RS_Ago);
TooltipHandler.TipRegion(rect, str);
}
else
{
Widgets.DrawTextureFitted(portraitRect, HistoryUtility.UnknownPawn, 1.0f);
Widgets.Label(nameRect, Keyed.Unknown);
Widgets.Label(sexinfoRect, Keyed.RS_Sex_Count + "?");
Widgets.Label(sexinfoRect2, Keyed.RS_Orgasms + "?");
FillableBarLabeled(bestsexRect, String.Format(Keyed.RS_Best_Sextype + ": {0}", Keyed.Sextype[(int)xxx.rjwSextype.None]), 0, Texture2D.linearGrayTexture, Texture2D.blackTexture);
}
}
protected void DrawSexInfoCard(Rect rect, SexPartnerHistoryRecord history, string label, string tooltip, string rightlabel = "")
{
Rect labelRect = new Rect(rect.x, rect.y, rect.width, FONTHEIGHT);
Rect infoRect = new Rect(rect.x, rect.y + FONTHEIGHT, rect.width, rect.height - FONTHEIGHT);
GUI.Label(labelRect, label, fontStyleLeft);
GUI.Label(labelRect, rightlabel, fontStyleRight);
DrawInfoWithPortrait(infoRect, history, tooltip);
}
/// <summary>
/// Right section
/// </summary>
protected void DrawBaseSexInfoRight(Rect rect)
{
Listing_Standard listmain = new Listing_Standard();
listmain.Begin(rect.ContractedBy(4f));
DrawSexInfoCard(listmain.GetRect(CARDHEIGHT), history.GetRecentPartnersHistory, Keyed.RS_Recent_Sex_Partner, Keyed.RS_Recent_Sex_Partner_ToolTip, RJWUIUtility.GetSexDays(history.RecentSexTickAbs));
DrawSexInfoCard(listmain.GetRect(CARDHEIGHT), history.GetFirstPartnerHistory, Keyed.RS_First_Sex_Partner, Keyed.RS_First_Sex_Partner_ToolTip, RJWUIUtility.GetSexDays(history.FirstSexTickAbs));
DrawSexInfoCard(listmain.GetRect(CARDHEIGHT), history.GetMostPartnerHistory, Keyed.RS_Most_Sex_Partner, Keyed.RS_Most_Sex_Partner_ToolTip, RJWUIUtility.GetSexDays(history.MostSexTickAbs));
DrawSexInfoCard(listmain.GetRect(CARDHEIGHT), history.GetBestSexPartnerHistory, Keyed.RS_Best_Sex_Partner, Keyed.RS_Best_Sex_Partner_ToolTip, RJWUIUtility.GetSexDays(history.BestSexTickAbs));
GUI.Label(listmain.GetRect(FONTHEIGHT), Keyed.RS_PreferRace, fontStyleLeft);
DrawPreferRace(listmain.GetRect(66f + 15f));
listmain.GetRect(15f);
listmain.End();
}
protected void DrawPreferRace(Rect rect)
{
Widgets.DrawMenuSection(rect);
Rect portraitRect = new Rect(rect.x, rect.y, rect.height - 15f, rect.height - 15f);
Rect infoRect1 = new Rect(rect.x + portraitRect.width, rect.y, rect.width - portraitRect.width, FONTHEIGHT);
Rect infoRect2 = new Rect(rect.x + portraitRect.width, rect.y + FONTHEIGHT, rect.width - portraitRect.width, FONTHEIGHT);
Rect infoRect3 = new Rect(rect.x + portraitRect.width, rect.y + (FONTHEIGHT * 2), rect.width - portraitRect.width - 2f, FONTHEIGHT);
if (history.PreferRace != null)
{
Widgets.DrawTextureFitted(portraitRect, RJWUIUtility.GetRaceIcon(history.PreferRacePawn, portraitRect.size), 1.0f);
GUI.Label(infoRect1, history.PreferRace?.label.CapitalizeFirst() ?? Keyed.None, fontStyleLeft);
GUI.Label(infoRect2, Keyed.RS_Sex_Count + history.PreferRaceSexCount, fontStyleLeft);
if (history.PreferRace != pawn.def)
{
if (history.PreferRace.race.Animal ^ pawn.def.race.Animal)
{
GUI.Label(infoRect1, Keyed.RS_Bestiality + " ", fontStyleRight);
FillableBarLabeled(infoRect3, Keyed.RS_Sex_Info(Keyed.RS_Bestiality, history.BestialityCount.ToString()), history.BestialityCount / 100f, Texture2D.linearGrayTexture, Texture2D.blackTexture);
}
else
{
GUI.Label(infoRect1, Keyed.RS_Interspecies + " ", fontStyleRight);
FillableBarLabeled(infoRect3, Keyed.RS_Sex_Info(Keyed.RS_Interspecies, history.InterspeciesCount.ToString()), history.InterspeciesCount / 100f, Texture2D.linearGrayTexture, Texture2D.blackTexture);
}
}
}
else
{
Widgets.DrawTextureFitted(portraitRect, HistoryUtility.UnknownPawn, 1.0f);
GUI.Label(infoRect1, Keyed.None, fontStyleLeft);
}
}
/// <summary>
/// Center section
/// </summary>
protected void DrawBaseSexInfoCenter(Rect rect, Pawn pawn)
{
Rect portraitRect = new Rect(rect.x + (rect.width / 4), rect.y, rect.width / 2, rect.width / 1.5f);
Rect nameRect = new Rect(portraitRect.x, portraitRect.yMax - (FONTHEIGHT * 2), portraitRect.width, FONTHEIGHT * 2);
Rect infoRect = new Rect(rect.x, rect.y + portraitRect.height, rect.width, rect.height - portraitRect.height);
Rect lockRect = new Rect(portraitRect.xMax - ICONSIZE, portraitRect.y, ICONSIZE, ICONSIZE);
Rect tmp;
if (Mouse.IsOver(portraitRect))
{
Configurations settings = SexperienceMod.Settings;
Texture lockicon = settings.SelectionLocked ? HistoryUtility.Locked : HistoryUtility.Unlocked;
Widgets.DrawTextureFitted(lockRect, lockicon, 1.0f);
if (Widgets.ButtonInvisible(lockRect))
{
SoundDefOf.Click.PlayOneShotOnCamera();
settings.SelectionLocked.Value = !settings.SelectionLocked.Value;
}
}
GUI.Box(portraitRect, "", boxStyle);
Widgets.DrawTextureFitted(portraitRect, PortraitsCache.Get(pawn, portraitRect.size, Rot4.South, default, 1, true, true, false, false), 1.0f);
Widgets.DrawHighlightIfMouseover(portraitRect);
if (Widgets.ButtonInvisible(portraitRect))
{
SoundDefOf.Click.PlayOneShotOnCamera();
selectedPawn = null;
}
GUI.Box(nameRect, "", boxStyle);
GUI.Label(nameRect.TopHalf(), pawn.Name?.ToStringFull ?? pawn.Label, fontStyleCenter);
if (pawn.story != null) GUI.Label(nameRect.BottomHalf(), pawn.ageTracker.AgeBiologicalYears + ", " + pawn.story.Title, fontStyleCenter);
else GUI.Label(nameRect.BottomHalf(), pawn.ageTracker.AgeBiologicalYears + ", " + pawn.def.label, fontStyleCenter);
Listing_Standard listmain = new Listing_Standard();
listmain.Begin(infoRect);
listmain.Gap(20f);
float p;
Trait virginity = pawn.story?.traits?.GetTrait(VariousDefOf.Virgin);
if (virginity != null && virginity.Degree != Virginity.TraitDegree.FemaleAfterSurgery)
{
tmp = listmain.GetRect(FONTHEIGHT);
GUI.color = Color.red;
GUI.Box(tmp, "", boxStyle);
GUI.color = Color.white;
GUI.Label(tmp, virginity.Label, fontStyleCenter);
}
else
{
p = history.TotalSexHad;
FillableBarLabeled(listmain.GetRect(FONTHEIGHT), String.Format(Keyed.RS_TotalSexHad + ": {0:0} ({1:0})", p, pawn.records.GetValue(xxx.CountOfSex)), p / 100, HistoryUtility.TotalSex, Texture2D.blackTexture, null, Keyed.RS_SAT_AVG(String.Format("{0:P2}", history.AVGSat)));
}
listmain.Gap(1f);
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 + ": {0:P2}", pawn.Dead ? 0 : pawn.GetStatValue(xxx.sex_drive_stat)));
listmain.Gap(1f);
if (Mouse.IsOver(tmp))
{
TooltipHandler.TipRegion(tmp, RJWUIUtility.GetStatExplanation(pawn, xxx.sex_drive_stat, pawn.Dead ? 0 : pawn.GetStatValue(xxx.sex_drive_stat)));
}
p = history.GetBestSextype(out xxx.rjwSextype sextype) / BASESAT;
FillableBarLabeled(listmain.GetRect(FONTHEIGHT), String.Format(Keyed.RS_Best_Sextype + ": {0}", Keyed.Sextype[(int)sextype]), p / 2, HistoryUtility.SextypeColor[(int)sextype], Texture2D.blackTexture, null, Keyed.RS_SAT_AVG(String.Format("{0:P2}", p)));
listmain.Gap(1f);
p = history.GetRecentSextype(out sextype) / BASESAT;
FillableBarLabeled(listmain.GetRect(FONTHEIGHT), String.Format(Keyed.RS_Recent_Sextype + ": {0}", Keyed.Sextype[(int)sextype]), p / 2, HistoryUtility.SextypeColor[(int)sextype], Texture2D.blackTexture, null, String.Format("{0:P2}", p));
listmain.Gap(1f);
if (history.IncestuousCount < history.CorpseFuckCount)
{
p = history.CorpseFuckCount;
FillableBarLabeled(listmain.GetRect(FONTHEIGHT), String.Format(Keyed.RS_Necrophile + ": {0}", p), p / 50, HistoryUtility.Nurgle, Texture2D.blackTexture);
listmain.Gap(1f);
}
else
{
p = history.IncestuousCount;
FillableBarLabeled(listmain.GetRect(FONTHEIGHT), String.Format(Keyed.Incest + ": {0}", p), p / 50, HistoryUtility.Nurgle, Texture2D.blackTexture);
listmain.Gap(1f);
}
p = pawn.records.GetValue(VariousDefOf.AmountofEatenCum);
FillableBarLabeled(listmain.GetRect(FONTHEIGHT), String.Format(Keyed.RS_Cum_Swallowed + ": {0} mL, {1} " + Keyed.RS_NumofTimes, p, pawn.records.GetValue(VariousDefOf.NumofEatenCum)), p / 1000, Texture2D.linearGrayTexture, Texture2D.blackTexture);
listmain.Gap(1f);
Hediff addiction = pawn.health.hediffSet.GetFirstHediffOfDef(VariousDefOf.CumAddiction)
?? pawn.health.hediffSet.GetFirstHediffOfDef(VariousDefOf.CumTolerance);
if (addiction != null)
{
p = addiction.Severity;
FillableBarLabeled(listmain.GetRect(FONTHEIGHT), $"{addiction.Label}: {p.ToStringPercent()}", p, Texture2D.linearGrayTexture, Texture2D.blackTexture, addiction.GetTooltip(pawn, false));
}
else
{
listmain.GetRect(FONTHEIGHT);
}
listmain.Gap(1f);
p = history.RapedCount;
tmp = listmain.GetRect(FONTHEIGHT);
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 + ": {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 + ": {0:P2}", pawn.Dead ? 0 : pawn.GetStatValue(xxx.vulnerability_stat)));
listmain.Gap(1f);
}
if (Mouse.IsOver(tmp))
{
TooltipHandler.TipRegion(tmp, RJWUIUtility.GetStatExplanation(pawn, xxx.vulnerability_stat, pawn.Dead ? 0 : pawn.GetStatValue(xxx.vulnerability_stat)));
}
p = pawn.Dead ? 0 : pawn.GetStatValue(xxx.sex_satisfaction);
tmp = listmain.GetRect(FONTHEIGHT);
FillableBarLabeled(tmp, String.Format(xxx.sex_satisfaction.LabelCap + ": {0:P2}", p), p / 2, HistoryUtility.Satisfaction, Texture2D.blackTexture);
listmain.Gap(1f);
if (Mouse.IsOver(tmp))
{
TooltipHandler.TipRegion(tmp, RJWUIUtility.GetStatExplanation(pawn, xxx.sex_satisfaction, pawn.Dead ? 0 : pawn.GetStatValue(xxx.sex_satisfaction)));
}
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}: {pawn.GetSexStat():P2}", HistoryUtility.GetPassionBG(skill?.passion));
if (Mouse.IsOver(tmp))
{
TooltipHandler.TipRegion(tmp, RJWUIUtility.GetStatExplanation(pawn, VariousDefOf.SexAbility, pawn.GetSexStat()));
}
listmain.Gap(1f);
if (selectedPawn != null) DrawSexInfoCard(listmain.GetRect(CARDHEIGHT), selectedPawn, Keyed.RS_Selected_Partner, Keyed.RS_Selected_Partner, RJWUIUtility.GetSexDays(selectedPawn.RecentSexTickAbs));
else DrawExtraInfo(listmain.GetRect(CARDHEIGHT));
listmain.End();
}
protected void DrawExtraInfo(Rect rect)
{
Widgets.DrawMenuSection(rect);
Rect inRect = rect.ContractedBy(4f);
Listing_Standard listmain = new Listing_Standard();
listmain.Begin(inRect);
listmain.Gap(4f);
listmain.GetRect(FONTHEIGHT).DrawSexuality(rjwcomp);
listmain.Gap(1f);
listmain.GetRect(FONTHEIGHT * 3f).DrawQuirk(pawn);
listmain.End();
}
/// <summary>
/// Left section
/// </summary>
protected void DrawBaseSexInfoLeft(Rect rect)
{
Listing_Standard listmain = new Listing_Standard();
listmain.Begin(rect);
float p;
//Sex statistics
GUI.Label(listmain.GetRect(FONTHEIGHT), " " + Keyed.RS_Statistics, fontStyleLeft);
listmain.Gap(1f);
float maxSatisfaction = history.GetBestSextype(out _);
if (maxSatisfaction == 0f) maxSatisfaction = BASESAT;
for (int i = 0; i < Sextype.Length; i++)
{
int sexindex = Sextype[i];
float relativeSat = history.GetAVGSat(sexindex) / maxSatisfaction;
p = history.GetAVGSat(sexindex) / BASESAT;
string label = Keyed.RS_Sex_Info(Keyed.Sextype[sexindex], history.GetSexCount(sexindex).ToString());
Rect tmpRect = listmain.GetRect(FONTHEIGHT);
FillableBarLabeled(tmpRect, label, relativeSat, HistoryUtility.SextypeColor[sexindex], Texture2D.blackTexture, null, Keyed.RS_SAT_AVG(String.Format("{0:P2}", p)));
if (Mouse.IsOver(tmpRect))
{
TooltipHandler.TipRegion(tmpRect, Keyed.RS_LastSex.CapitalizeFirst() + ": " + RJWUIUtility.GetSexDays(history.GetSextypeRecentTickAbs(Sextype[i]), true));
}
listmain.Gap(1f);
}
p = history.PartnerCount;
FillableBarLabeled(listmain.GetRect(FONTHEIGHT), String.Format(Keyed.RS_Sex_Partners + ": {0} ({1})", p, pawn.records.GetValue(VariousDefOf.SexPartnerCount)), p / 50, HistoryUtility.Partners, Texture2D.blackTexture);
listmain.Gap(1f);
p = history.VirginsTaken;
FillableBarLabeled(listmain.GetRect(FONTHEIGHT), String.Format(Keyed.RS_VirginsTaken + ": {0:0}", p), p / 100, HistoryUtility.Partners, Texture2D.blackTexture);
listmain.Gap(1f);
//Partner list
Rect listLabelRect = listmain.GetRect(FONTHEIGHT);
Rect sortbtnRect = new Rect(listLabelRect.xMax - 80f, listLabelRect.y, 80f, listLabelRect.height);
GUI.Label(listLabelRect, " " + Keyed.RS_PartnerList, fontStyleLeft);
if (Widgets.ButtonText(sortbtnRect, orderMode.Translate()))
{
SoundDefOf.Click.PlayOneShotOnCamera();
orderMode = orderMode.Next();
SortPartnerList(orderMode);
}
listmain.Gap(1f);
Rect scrollRect = listmain.GetRect(CARDHEIGHT + 1f);
GUI.Box(scrollRect, "", buttonStyle);
if (!partnerList.NullOrEmpty())
{
Rect listRect = new Rect(scrollRect.x, scrollRect.y, LISTPAWNSIZE * partnerList.Count, scrollRect.height - 30f);
Widgets.ScrollHorizontal(scrollRect, ref scroll, listRect);
Widgets.BeginScrollView(scrollRect, ref scroll, listRect);
DrawPartnerList(listRect, partnerList);
Widgets.EndScrollView();
}
listmain.End();
}
protected void DrawPartnerList(Rect rect, List<SexPartnerHistoryRecord> partnerList)
{
Rect pawnRect = new Rect(rect.x, rect.y, LISTPAWNSIZE, LISTPAWNSIZE);
for (int i = 0; i < partnerList.Count; i++)
{
Rect labelRect = new Rect(pawnRect.x, pawnRect.yMax - FONTHEIGHT, pawnRect.width, FONTHEIGHT);
DrawPawn(pawnRect, partnerList[i]);
Widgets.DrawHighlightIfMouseover(pawnRect);
GUI.Label(labelRect, partnerList[i].Label, fontStyleCenter);
if (Widgets.ButtonInvisible(pawnRect))
{
selectedPawn = partnerList[i];
SoundDefOf.Click.PlayOneShotOnCamera();
}
if (partnerList[i] == selectedPawn)
{
Widgets.DrawHighlightSelected(pawnRect);
}
pawnRect.x += LISTPAWNSIZE;
}
}
protected void DrawPawn(Rect rect, SexPartnerHistoryRecord history)
{
if (history != null)
{
bool drawheart = false;
Rect iconRect = new Rect(rect.x + (rect.width * 3 / 4), rect.y, rect.width / 4, rect.height / 4);
Texture img = HistoryUtility.UnknownPawn;
if (history.IamFirst)
{
GUI.color = HistoryUtility.HistoryColor;
Widgets.DrawTextureFitted(rect, HistoryUtility.FirstOverlay, 1.0f);
GUI.color = Color.white;
}
if (history.Partner != null)
{
img = PortraitsCache.Get(history.Partner, rect.size, Rot4.South, default, 1, true, true, false, false);
drawheart = LovePartnerRelationUtility.LovePartnerRelationExists(pawn, history.Partner);
}
else if (history.Race?.uiIcon != null)
{
img = history.Race.uiIcon;
}
if (history.Incest)
{
Widgets.DrawTextureFitted(iconRect, HistoryUtility.Incest, 1.0f);
iconRect.x -= iconRect.width;
}
Widgets.DrawTextureFitted(rect, img, 1.0f);
if (drawheart)
{
Widgets.DrawTextureFitted(iconRect, HistoryUtility.Heart, 1.0f);
iconRect.x -= iconRect.width;
}
}
}
public static void FillableBarLabeled(Rect rect, string label, float fillPercent, Texture2D filltexture, Texture2D bgtexture, string tooltip = null, string rightlabel = "", Texture2D border = null)
{
Widgets.FillableBar(rect, Math.Min(fillPercent, 1.0f), filltexture, bgtexture, true);
GUI.Label(rect, " " + label.CapitalizeFirst(), fontStyleLeft);
GUI.Label(rect, rightlabel.CapitalizeFirst() + " ", fontStyleRight);
Widgets.DrawHighlightIfMouseover(rect);
if (tooltip != null) TooltipHandler.TipRegion(rect, tooltip);
if (border != null)
{
rect.DrawBorder(border, 2f);
}
}
}
}

View File

@ -0,0 +1,374 @@
using RimWorld;
using rjw;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using UnityEngine;
using Verse;
namespace RJWSexperience.SexHistory.UI
{
public sealed class SexStatusViewModel
{
private static readonly int[] Sextype =
{
(int)xxx.rjwSextype.Vaginal,
(int)xxx.rjwSextype.Anal,
(int)xxx.rjwSextype.Oral,
(int)xxx.rjwSextype.Fellatio,
(int)xxx.rjwSextype.Cunnilingus,
(int)xxx.rjwSextype.DoublePenetration,
(int)xxx.rjwSextype.Boobjob,
(int)xxx.rjwSextype.Handjob,
(int)xxx.rjwSextype.Footjob,
(int)xxx.rjwSextype.Fingering,
(int)xxx.rjwSextype.Scissoring,
(int)xxx.rjwSextype.MutualMasturbation,
(int)xxx.rjwSextype.Fisting,
(int)xxx.rjwSextype.Rimming,
(int)xxx.rjwSextype.Sixtynine
};
private readonly SexHistoryComp _history;
private readonly CompRJW _rjwComp;
private int _validUntilTick;
public SexStatusViewModel(SexHistoryComp history, PartnerOrderMode mode)
{
_history = history;
_rjwComp = history.ParentPawn.TryGetComp<CompRJW>();
SetPartnerOrder(mode);
Name = Pawn.Name?.ToStringFull ?? Pawn.Label;
if (Pawn.story != null)
{
AgeAndTitle = Pawn.ageTracker.AgeBiologicalYears + ", " + Pawn.story.Title;
}
else
{
AgeAndTitle = Pawn.ageTracker.AgeBiologicalYears + ", " + Pawn.def.label;
}
}
public Pawn Pawn => _history.ParentPawn;
public string Name { get; }
public string AgeAndTitle { get; }
public List<InfoCard> InfoCards { get; } = new List<InfoCard>();
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 string VirginLabel { get; private set; }
public string SexualityLabel { get; private set; }
public string QuirksLabel { get; private set; }
public TipSignal QuirksTooltip { get; private set; }
public SexPartnerHistoryRecord SelectedPartner { get; private set; }
public IEnumerable<PartnerPortraitInfo> Partners { get; private set; }
public void Update()
{
if (Find.TickManager.TicksGame <= _validUntilTick)
{
return;
}
UpdateInfoCards();
UpdateBars();
UpdateQuirks();
UpdateVirginAndSexuality();
PreferedRaceCard = new PreferedRaceCard(_history);
int tickRateMultiplier = (int)Find.TickManager.TickRateMultiplier;
if (tickRateMultiplier == 0) // Paused
{
_validUntilTick = Find.TickManager.TicksGame;
return;
}
_validUntilTick = Find.TickManager.TicksGame + (60 * tickRateMultiplier);
}
private void UpdateInfoCards()
{
InfoCards.Clear();
InfoCards.Add(new InfoCard(
pawn: Pawn,
partnerRecord: _history.GetRecentPartnersHistory,
label: Keyed.RS_Recent_Sex_Partner,
tooltipLabel: Keyed.RS_Recent_Sex_Partner_ToolTip,
lastSexTimeTicks: _history.RecentSexTickAbs));
InfoCards.Add(new InfoCard(
pawn: Pawn,
partnerRecord: _history.GetFirstPartnerHistory,
label: Keyed.RS_First_Sex_Partner,
tooltipLabel: Keyed.RS_First_Sex_Partner_ToolTip,
lastSexTimeTicks: _history.FirstSexTickAbs));
InfoCards.Add(new InfoCard(
pawn: Pawn,
partnerRecord: _history.GetMostPartnerHistory,
label: Keyed.RS_Most_Sex_Partner,
tooltipLabel: Keyed.RS_Most_Sex_Partner_ToolTip,
lastSexTimeTicks: _history.MostSexTickAbs));
InfoCards.Add(new InfoCard(
pawn: Pawn,
partnerRecord: _history.GetBestSexPartnerHistory,
label: Keyed.RS_Best_Sex_Partner,
tooltipLabel: Keyed.RS_Best_Sex_Partner_ToolTip,
lastSexTimeTicks: _history.BestSexTickAbs));
if (SelectedPartner != null)
{
UpdateSelectedPartnerCard();
}
}
private void UpdateBars()
{
float maxSatisfaction = _history.GetBestSextype(out _);
if (maxSatisfaction == 0f)
{
maxSatisfaction = UIUtility.BASESAT;
}
SexTypes.Clear();
for (int i = 0; i < Sextype.Length; i++)
{
int sexIndex = Sextype[i];
float AverageSatisfaction = _history.GetAVGSat(sexIndex);
float relativeSat = AverageSatisfaction / maxSatisfaction;
float satisfactionRelativeToBase = AverageSatisfaction / UIUtility.BASESAT;
SexTypes.Add(new BarInfo(
label: Keyed.RS_SexInfo(Keyed.Sextype[sexIndex], _history.GetSexCount(sexIndex)),
fillPercent: relativeSat,
fillTexture: HistoryUtility.SextypeColor[sexIndex],
tooltip: Keyed.RS_LastSex + ": " + UIUtility.GetSexDays(_history.GetSextypeRecentTickAbs(sexIndex), true),
labelRight: Keyed.RS_SatAVG(satisfactionRelativeToBase)));
}
SexTypes.Add(new BarInfo(
label: String.Format(Keyed.RS_Sex_Partners + ": {0} ({1})", _history.PartnerCount, Pawn.records.GetValue(VariousDefOf.SexPartnerCount)),
fillPercent: _history.PartnerCount / 50,
fillTexture: HistoryUtility.Partners));
SexTypes.Add(new BarInfo(
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));
float lust = Pawn.records.GetValue(VariousDefOf.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());
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));
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());
Necro = new BarInfo(
label: String.Format(Keyed.RS_Necrophile + ": {0}", _history.CorpseFuckCount),
fillPercent: _history.CorpseFuckCount / 50,
fillTexture: HistoryUtility.Nurgle);
Incest = new BarInfo(
label: String.Format(Keyed.Incest + ": {0}", _history.IncestuousCount),
fillPercent: _history.IncestuousCount / 50,
fillTexture: HistoryUtility.Nurgle);
float amountofEatenCum = Pawn.records.GetValue(VariousDefOf.AmountofEatenCum);
ConsumedCum = new BarInfo(
label: String.Format(Keyed.RS_Cum_Swallowed + ": {0} mL, {1} " + Keyed.RS_NumofTimes, amountofEatenCum, Pawn.records.GetValue(VariousDefOf.NumofEatenCum)),
fillPercent: amountofEatenCum / 1000,
fillTexture: Texture2D.linearGrayTexture);
Hediff cumHediff = Pawn.health.hediffSet.GetFirstHediffOfDef(VariousDefOf.CumAddiction)
?? Pawn.health.hediffSet.GetFirstHediffOfDef(VariousDefOf.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()));
}
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);
BeenRaped = new BarInfo(
label: String.Format(Keyed.RS_BeenRaped + ": {0}", _history.BeenRapedCount),
fillPercent: _history.BeenRapedCount / 50,
fillTexture: Texture2D.grayTexture,
tooltip: vulnerabilityTip,
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));
SkillRecord skill = Pawn.skills?.GetSkill(VariousDefOf.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(VariousDefOf.SexAbility, sexStat),
labelRight: VariousDefOf.SexAbility.LabelCap + ": " + sexStat.ToStringPercent(),
border: HistoryUtility.GetPassionBG(skill?.passion));
}
private void UpdateQuirks()
{
List<Quirk> quirks = Quirk.All.FindAll(x => Pawn.Has(x));
string quirkstr = quirks.Select(x => x.Key).ToCommaList();
QuirksLabel = "Quirks".Translate() + quirkstr;
if (quirks.NullOrEmpty())
{
QuirksTooltip = "NoQuirks".Translate();
}
else
{
QuirksTooltip = new TipSignal(() =>
{
StringBuilder stringBuilder = new StringBuilder();
foreach (Quirk q in quirks)
{
stringBuilder.AppendLine(q.Key.Colorize(Color.yellow));
stringBuilder.AppendLine(q.LocaliztionKey.Translate(Pawn.Named("pawn")).AdjustedFor(Pawn).Resolve());
stringBuilder.AppendLine("");
}
return stringBuilder.ToString().TrimEndNewlines();
}, "Quirks".GetHashCode());
}
}
private void UpdateVirginAndSexuality()
{
Trait virginity = Pawn.story?.traits?.GetTrait(VariousDefOf.Virgin);
if (virginity != null && virginity.Degree != Virginity.TraitDegree.FemaleAfterSurgery)
{
VirginLabel = virginity.Label;
}
else
{
VirginLabel = null;
}
if (_rjwComp != null)
{
SexualityLabel = Keyed.RS_Sexuality + ": " + Keyed.Sexuality[(int)_rjwComp.orientation];
}
}
public void SetPartnerOrder(PartnerOrderMode mode)
{
if (_history == null)
{
return;
}
var partners = _history.PartnerList.Select(x => new PartnerPortraitInfo(Pawn, x));
switch (mode)
{
default:
Partners = partners;
break;
case PartnerOrderMode.Recent:
Partners = partners.OrderBy(x => x.partnerRecord.RecentSexTickAbs);
break;
case PartnerOrderMode.Most:
Partners = partners.OrderBy(x => x.partnerRecord.TotalSexCount);
break;
case PartnerOrderMode.Name:
Partners = partners.OrderBy(x => x.partnerRecord.Label);
break;
}
}
public void SetSelectedPartner(SexPartnerHistoryRecord sexPartner)
{
SelectedPartner = sexPartner;
UpdateSelectedPartnerCard();
}
private void UpdateSelectedPartnerCard()
{
if (SelectedPartner == null)
{
SelectedPartnerCard = default;
return;
}
SelectedPartnerCard = new InfoCard(
pawn: Pawn,
partnerRecord: SelectedPartner,
label: Keyed.RS_Selected_Partner,
tooltipLabel: Keyed.RS_Selected_Partner,
lastSexTimeTicks: SelectedPartner.RecentSexTickAbs);
}
private float GetStatValue(StatDef statDef) => Pawn.Dead ? 0f : Pawn.GetStatValue(statDef);
private TipSignal GetStatTooltip(StatDef stat, float val)
{
if (!Pawn.Dead)
{
return new TipSignal(
textGetter: () => stat.description + "\n\n" + stat.Worker.GetExplanationFull(StatRequest.For(Pawn), ToStringNumberSense.Undefined, val),
uniqueId: stat.GetHashCode());
}
return "Dead".Translate();
}
}
}

View File

@ -0,0 +1,473 @@
using RimWorld;
using System.Collections.Generic;
using System.Linq;
using UnityEngine;
using Verse;
using Verse.Sound;
namespace RJWSexperience.SexHistory.UI
{
public class SexStatusWindow : Window
{
public const float WINDOW_WIDTH = 900f;
public const float WINDOW_HEIGHT = 600f;
public const float FONTHEIGHT = UIUtility.FONTHEIGHT;
public const float CARDHEIGHT = UIUtility.CARDHEIGHT;
public const float LISTPAWNSIZE = UIUtility.LISTPAWNSIZE;
public const float BASESAT = UIUtility.BASESAT;
public const float ICONSIZE = UIUtility.ICONSIZE;
private static GUIStyle fontStyleCenter;
private static GUIStyle fontStyleRight;
private static GUIStyle fontStyleLeft;
private static GUIStyle boxStyle;
private static GUIStyle buttonStyle;
private SexStatusViewModel _context;
protected PartnerOrderMode orderMode;
private static Vector2 LastWindowPosition { get; set; }
private Vector2 scroll;
private static void InitStyles()
{
if (fontStyleCenter != null)
{
return;
}
GUIStyleState fontStyleState = new GUIStyleState() { textColor = Color.white };
GUIStyleState boxStyleState = GUI.skin.textArea.normal;
GUIStyleState buttonStyleState = GUI.skin.button.normal;
fontStyleCenter = new GUIStyle() { alignment = TextAnchor.MiddleCenter, normal = fontStyleState };
fontStyleRight = new GUIStyle() { alignment = TextAnchor.MiddleRight, normal = fontStyleState };
fontStyleLeft = new GUIStyle() { alignment = TextAnchor.MiddleLeft, normal = fontStyleState };
boxStyle = new GUIStyle(GUI.skin.textArea) { hover = boxStyleState, onHover = boxStyleState, onNormal = boxStyleState };
buttonStyle = new GUIStyle(GUI.skin.button) { hover = buttonStyleState, onHover = buttonStyleState, onNormal = buttonStyleState };
}
public SexStatusWindow(SexHistoryComp history)
{
orderMode = PartnerOrderMode.Recent;
_context = new SexStatusViewModel(history, orderMode);
soundClose = SoundDefOf.CommsWindow_Close;
absorbInputAroundWindow = false;
forcePause = false;
preventCameraMotion = false;
draggable = true;
doCloseX = true;
}
protected override void SetInitialSizeAndPosition()
{
base.SetInitialSizeAndPosition();
if (LastWindowPosition == Vector2.zero)
return;
windowRect.x = LastWindowPosition.x;
windowRect.y = LastWindowPosition.y;
}
public override Vector2 InitialSize => new Vector2(WINDOW_WIDTH, WINDOW_HEIGHT);
public override void PreOpen()
{
base.PreOpen();
InitStyles();
}
public override void PreClose()
{
base.PreClose();
LastWindowPosition = windowRect.position;
}
public override void DoWindowContents(Rect inRect)
{
if (!SexperienceMod.Settings.SelectionLocked)
{
List<Pawn> selectedPawns = Find.Selector.SelectedPawns;
if (selectedPawns.Count == 1)
{
Pawn selectedPawn = selectedPawns[0];
if (selectedPawn != _context.Pawn)
{
SexHistoryComp h = selectedPawn.TryGetComp<SexHistoryComp>();
if (h != null) ChangePawn(h);
}
}
}
_context.Update();
DrawSexStatus(inRect);
}
public static void ToggleWindow(SexHistoryComp history)
{
SexStatusWindow window = Find.WindowStack.WindowOfType<SexStatusWindow>();
if (window != null)
{
if (window._context.Pawn != history.ParentPawn)
{
SoundDefOf.TabOpen.PlayOneShotOnCamera();
window.ChangePawn(history);
}
}
else
{
Find.WindowStack.Add(new SexStatusWindow(history));
}
}
public void ChangePawn(SexHistoryComp history)
{
Find.Selector.ClearSelection();
_context = new SexStatusViewModel(history, orderMode);
if (!_context.Pawn.DestroyedOrNull() && Find.CurrentMap == _context.Pawn.Map)
{
Find.Selector.Select(_context.Pawn);
}
}
/// <summary>
/// Main contents
/// </summary>
protected void DrawSexStatus(Rect mainrect)
{
float sectionwidth = mainrect.width / 3;
Rect leftRect = new Rect(mainrect.x, mainrect.y, sectionwidth, mainrect.height);
Rect centerRect = new Rect(mainrect.x + sectionwidth, mainrect.y, sectionwidth, mainrect.height);
Rect rightRect = new Rect(mainrect.x + (sectionwidth * 2), mainrect.y, sectionwidth, mainrect.height);
//Left section
DrawBaseSexInfoLeft(leftRect.ContractedBy(4f));
//Center section
DrawBaseSexInfoCenter(centerRect.ContractedBy(4f), _context.Pawn);
//Right section
DrawBaseSexInfoRight(rightRect.ContractedBy(4f));
}
protected void DrawInfoWithPortrait(Rect rect, InfoCard context)
{
Widgets.DrawMenuSection(rect);
Rect portraitRect = new Rect(rect.x, rect.y, rect.height - FONTHEIGHT, rect.height - FONTHEIGHT);
Rect nameRect = new Rect(rect.x + portraitRect.width, rect.y, rect.width - portraitRect.width, FONTHEIGHT);
Rect sexinfoRect = new Rect(rect.x + portraitRect.width, rect.y + FONTHEIGHT, rect.width - portraitRect.width, FONTHEIGHT);
Rect sexinfoRect2 = new Rect(rect.x + portraitRect.width, rect.y + (FONTHEIGHT * 2), rect.width - portraitRect.width, FONTHEIGHT);
Rect bestsexRect = new Rect(rect.x + 2f, rect.y + (FONTHEIGHT * 3), rect.width - 4f, FONTHEIGHT - 2f);
if (context.partnerRecord != null)
{
DrawPartnerPortrait(portraitRect, context.portraitInfo);
Widgets.DrawHighlightIfMouseover(portraitRect);
if (Widgets.ButtonInvisible(portraitRect))
{
SexHistoryComp partnerHistory = context.partnerRecord.Partner?.TryGetComp<SexHistoryComp>();
if (partnerHistory != null)
{
ChangePawn(partnerHistory);
SoundDefOf.Click.PlayOneShotOnCamera();
}
else
{
SoundDefOf.ClickReject.PlayOneShotOnCamera();
}
}
GUI.Label(sexinfoRect2, context.relations + " ", fontStyleRight);
TooltipHandler.TipRegion(rect, context.tooltip);
}
else
{
Widgets.DrawTextureFitted(portraitRect, HistoryUtility.UnknownPawn, 1.0f);
}
Widgets.Label(nameRect, context.name);
Widgets.Label(sexinfoRect, context.sexCount);
Widgets.Label(sexinfoRect2, context.orgasms);
UIUtility.FillableBarLabeled(bestsexRect, context.bestSextype);
}
protected void DrawSexInfoCard(Rect rect, InfoCard context)
{
rect.SplitHorizontally(FONTHEIGHT, out Rect labelRect, out Rect infoRect);
GUI.Label(labelRect, context.label, fontStyleLeft);
GUI.Label(labelRect, context.lastSexTime, fontStyleRight);
DrawInfoWithPortrait(infoRect, context);
}
/// <summary>
/// Right section
/// </summary>
protected void DrawBaseSexInfoRight(Rect rect)
{
Listing_Standard listmain = new Listing_Standard();
listmain.Begin(rect.ContractedBy(4f));
foreach(InfoCard infoCard in _context.InfoCards)
{
DrawSexInfoCard(listmain.GetRect(CARDHEIGHT), infoCard);
}
GUI.Label(listmain.GetRect(FONTHEIGHT), Keyed.RS_PreferRace, fontStyleLeft);
DrawPreferRace(listmain.GetRect(66f + 15f), _context.PreferedRaceCard);
listmain.End();
}
protected void DrawPreferRace(Rect rect, PreferedRaceCard preferedRaceCard)
{
Widgets.DrawMenuSection(rect);
rect.SplitVertically(rect.height - 15f, out Rect portraitRect, out Rect infoRect);
portraitRect.height = portraitRect.width;
Rect infoRect1 = new Rect(infoRect.x, infoRect.y, infoRect.width, FONTHEIGHT);
Rect infoRect2 = new Rect(infoRect.x, infoRect.y + FONTHEIGHT, infoRect.width, FONTHEIGHT);
Rect infoRect3 = new Rect(infoRect.x, infoRect.y + (FONTHEIGHT * 2), infoRect.width - 2f, FONTHEIGHT);
Widgets.DrawTextureFitted(portraitRect, preferedRaceCard.portraitGetter(portraitRect.size), 1.0f);
GUI.Label(infoRect1, preferedRaceCard.preferRaceLabel, fontStyleLeft);
if (preferedRaceCard.preferRaceTypeLabel != null)
{
GUI.Label(infoRect1, preferedRaceCard.preferRaceTypeLabel + " ", fontStyleRight);
}
if (preferedRaceCard.sexCount != null)
{
GUI.Label(infoRect2, preferedRaceCard.sexCount, fontStyleLeft);
}
if (preferedRaceCard.barInfo != null)
{
UIUtility.FillableBarLabeled(infoRect3, (BarInfo)preferedRaceCard.barInfo);
}
}
/// <summary>
/// Center section
/// </summary>
protected void DrawBaseSexInfoCenter(Rect rect, Pawn pawn)
{
Rect portraitRect = new Rect(rect.x + (rect.width / 4), rect.y, rect.width / 2, rect.width / 1.5f);
Rect nameRect = new Rect(portraitRect.x, portraitRect.yMax - (FONTHEIGHT * 2), portraitRect.width, FONTHEIGHT * 2);
Rect infoRect = rect.BottomPartPixels(rect.height - portraitRect.height - 20f);
if (Mouse.IsOver(portraitRect))
{
Rect lockRect = new Rect(portraitRect.xMax - ICONSIZE, portraitRect.y, ICONSIZE, ICONSIZE);
Configurations settings = SexperienceMod.Settings;
Texture lockIcon = settings.SelectionLocked ? HistoryUtility.Locked : HistoryUtility.Unlocked;
Widgets.DrawTextureFitted(lockRect, lockIcon, 1.0f);
TooltipHandler.TipRegion(lockRect, Keyed.RS_PawnLockDesc);
if (Widgets.ButtonInvisible(lockRect))
{
SoundDefOf.Click.PlayOneShotOnCamera();
settings.SelectionLocked.Value = !settings.SelectionLocked.Value;
}
}
GUI.Box(portraitRect, "", boxStyle);
Widgets.DrawTextureFitted(portraitRect, PortraitsCache.Get(pawn, portraitRect.size, Rot4.South, default, 1, true, true, false, false), 1.0f);
if (_context.SelectedPartner != null)
{
Widgets.DrawHighlightIfMouseover(portraitRect);
if (Widgets.ButtonInvisible(portraitRect))
{
SoundDefOf.Click.PlayOneShotOnCamera();
_context.SetSelectedPartner(null);
}
}
GUI.Box(nameRect, "", boxStyle);
GUI.Label(nameRect.TopHalf(), _context.Name, fontStyleCenter);
GUI.Label(nameRect.BottomHalf(), _context.AgeAndTitle, fontStyleCenter);
Listing_Standard listmain = new Listing_Standard();
listmain.Begin(infoRect);
//listmain.Gap(20f);
if (_context.VirginLabel != null)
{
Rect tmp = listmain.GetRect(FONTHEIGHT);
GUI.color = Color.red;
GUI.Box(tmp, "", boxStyle);
GUI.color = Color.white;
GUI.Label(tmp, _context.VirginLabel, fontStyleCenter);
listmain.Gap(1f);
}
else
{
listmain.FillableBarLabeled(_context.TotalSex);
}
listmain.FillableBarLabeled(_context.Lust);
listmain.FillableBarLabeled(_context.BestSextype);
listmain.FillableBarLabeled(_context.RecentSextype);
if (_context.Incest.fillPercent < _context.Necro.fillPercent)
{
listmain.FillableBarLabeled(_context.Necro);
}
else
{
listmain.FillableBarLabeled(_context.Incest);
}
listmain.FillableBarLabeled(_context.ConsumedCum);
if (_context.CumHediff != null)
{
listmain.FillableBarLabeled((BarInfo)_context.CumHediff);
}
else
{
listmain.Gap(FONTHEIGHT + 1f);
}
if (_context.Raped.fillPercent < _context.BeenRaped.fillPercent)
{
listmain.FillableBarLabeled(_context.BeenRaped);
}
else
{
listmain.FillableBarLabeled(_context.Raped);
}
listmain.FillableBarLabeled(_context.SexSatisfaction);
listmain.FillableBarLabeled(_context.SexSkill);
if (_context.SelectedPartner != null)
{
DrawSexInfoCard(listmain.GetRect(CARDHEIGHT), _context.SelectedPartnerCard);
}
else
{
DrawExtraInfo(listmain.GetRect(CARDHEIGHT));
}
listmain.End();
}
/// <summary>
/// Sexuality and quirks
/// </summary>
protected void DrawExtraInfo(Rect rect)
{
Widgets.DrawMenuSection(rect);
Rect inRect = rect.ContractedBy(4f);
Listing_Standard listmain = new Listing_Standard();
listmain.Begin(inRect);
listmain.Gap(4f);
Rect sexualityRect = listmain.GetRect(FONTHEIGHT);
if (_context.SexualityLabel != null)
{
Widgets.Label(sexualityRect, _context.SexualityLabel);
Widgets.DrawHighlightIfMouseover(sexualityRect);
}
listmain.Gap(1f);
Rect quirkRect = listmain.GetRect(FONTHEIGHT * 3f);
Widgets.Label(quirkRect, _context.QuirksLabel);
Widgets.DrawHighlightIfMouseover(quirkRect);
TooltipHandler.TipRegion(quirkRect, _context.QuirksTooltip);
listmain.End();
}
/// <summary>
/// Left section
/// </summary>
protected void DrawBaseSexInfoLeft(Rect rect)
{
Listing_Standard listmain = new Listing_Standard();
listmain.Begin(rect);
//Sex statistics
GUI.Label(listmain.GetRect(FONTHEIGHT), " " + Keyed.RS_Statistics, fontStyleLeft);
listmain.Gap(1f);
for (int i = 0; i < _context.SexTypes.Count; i++)
{
listmain.FillableBarLabeled(_context.SexTypes[i]);
}
//Partner list
Rect listLabelRect = listmain.GetRect(FONTHEIGHT);
Rect sortbtnRect = new Rect(listLabelRect.xMax - 80f, listLabelRect.y, 80f, listLabelRect.height);
GUI.Label(listLabelRect, " " + Keyed.RS_PartnerList, fontStyleLeft);
if (Widgets.ButtonText(sortbtnRect, orderMode.Translate()))
{
SoundDefOf.Click.PlayOneShotOnCamera();
orderMode = orderMode.Next();
_context.SetPartnerOrder(orderMode);
}
listmain.Gap(1f);
Rect scrollRect = listmain.GetRect(CARDHEIGHT + 1f);
GUI.Box(scrollRect, "", buttonStyle);
if (!_context.Partners.EnumerableNullOrEmpty())
{
Rect listRect = new Rect(scrollRect.x, scrollRect.y, LISTPAWNSIZE * _context.Partners.Count(), scrollRect.height - 30f);
Widgets.ScrollHorizontal(scrollRect, ref scroll, listRect);
Widgets.BeginScrollView(scrollRect, ref scroll, listRect);
DrawPartnerList(listRect, _context.Partners);
Widgets.EndScrollView();
}
listmain.End();
}
/// <summary>
/// Partners at the bottom of the left section
/// </summary>
protected void DrawPartnerList(Rect rect, IEnumerable<PartnerPortraitInfo> partners)
{
Rect pawnRect = new Rect(rect.x, rect.y, LISTPAWNSIZE, LISTPAWNSIZE);
foreach (PartnerPortraitInfo partner in partners)
{
Rect labelRect = new Rect(pawnRect.x, pawnRect.yMax - FONTHEIGHT, pawnRect.width, FONTHEIGHT);
DrawPartnerPortrait(pawnRect, partner);
Widgets.DrawHighlightIfMouseover(pawnRect);
GUI.Label(labelRect, partner.partnerRecord.Label, fontStyleCenter);
if (Widgets.ButtonInvisible(pawnRect))
{
_context.SetSelectedPartner(partner.partnerRecord);
SoundDefOf.Click.PlayOneShotOnCamera();
}
if (partner.partnerRecord == _context.SelectedPartner)
{
Widgets.DrawHighlightSelected(pawnRect);
}
pawnRect.x += LISTPAWNSIZE;
}
}
protected void DrawPartnerPortrait(Rect rect, PartnerPortraitInfo context)
{
Rect iconRect = new Rect(rect.x + (rect.width * 3 / 4), rect.y, rect.width / 4, rect.height / 4);
Texture img = context.portraitGetter(rect.size);
if (context.partnerRecord.IamFirst)
{
GUI.color = HistoryUtility.HistoryColor;
Widgets.DrawTextureFitted(rect, HistoryUtility.FirstOverlay, 1.0f);
GUI.color = Color.white;
}
if (context.partnerRecord.Incest)
{
Widgets.DrawTextureFitted(iconRect, HistoryUtility.Incest, 1.0f);
iconRect.x -= iconRect.width;
}
Widgets.DrawTextureFitted(rect, img, 1.0f);
if (context.lover)
{
Widgets.DrawTextureFitted(iconRect, HistoryUtility.Heart, 1.0f);
}
}
}
}

View File

@ -0,0 +1,80 @@
using RimWorld;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Remoting.Contexts;
using UnityEngine;
using Verse;
namespace RJWSexperience.SexHistory.UI
{
public static class UIUtility
{
public const float FONTHEIGHT = 22f;
public const float CARDHEIGHT = 110f;
public const float LISTPAWNSIZE = 100f;
public const float BASESAT = 0.40f;
public const float ICONSIZE = 30f;
public static string GetRelationsString(this Pawn pawn, Pawn otherpawn)
{
if (otherpawn != null)
{
IEnumerable<PawnRelationDef> relations = pawn.GetRelations(otherpawn);
if (!relations.EnumerableNullOrEmpty())
return relations.Select(x => x.GetGenderSpecificLabel(otherpawn)).ToCommaList().CapitalizeFirst();
}
return "";
}
public static void DrawBorder(this Rect rect, Texture border, float thickness = 1f)
{
GUI.DrawTexture(new Rect(rect.x, rect.y, rect.width, thickness), border);
GUI.DrawTexture(new Rect(rect.x + rect.width - thickness, rect.y, thickness, rect.height), border);
GUI.DrawTexture(new Rect(rect.x, rect.y + rect.height - thickness, rect.width, thickness), border);
GUI.DrawTexture(new Rect(rect.x, rect.y, thickness, rect.height), border);
}
public static string GetSexDays(int absticks, bool printUnknown = false)
{
if (absticks != 0)
return GenDate.ToStringTicksToDays(GenTicks.TicksAbs - absticks) + " " + Keyed.RS_Ago;
else if (printUnknown)
return Keyed.Unknown;
return "";
}
public static Texture GetRaceIcon(Pawn pawn, Vector2 size)
{
if (pawn != null)
return PortraitsCache.Get(pawn, size, Rot4.South, default, 1, true, true, false, false);
return HistoryUtility.UnknownPawn;
}
public static void FillableBarLabeled(Rect rect, BarInfo context)
{
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 != "")
{
Text.Anchor = TextAnchor.MiddleRight;
Widgets.Label(labelRect, context.labelRight);
}
GenUI.ResetLabelAlign();
Widgets.DrawHighlightIfMouseover(rect);
TooltipHandler.TipRegion(rect, context.tooltip);
if (context.border != null)
{
rect.DrawBorder(context.border, 2f);
}
}
public static void FillableBarLabeled(this Listing_Standard list, BarInfo context)
{
FillableBarLabeled(list.GetRect(FONTHEIGHT), context);
list.Gap(1f);
}
}
}