Cleanup SexStatusWindow code

This commit is contained in:
amevarashi 2022-04-10 13:56:07 +05:00
parent 89439d1f32
commit 8f881a21e1
1 changed files with 624 additions and 658 deletions

View File

@ -1,14 +1,11 @@
using System;
using RimWorld;
using rjw;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using UnityEngine;
using Verse;
using Verse.Sound;
using RimWorld;
using rjw;
using RJWSexperience.ExtensionMethods;
namespace RJWSexperience.UI
{
@ -17,26 +14,27 @@ namespace RJWSexperience.UI
Normal = 0,
Recent = 1,
Most = 2,
Name, Maxvlaue = 3
Name, MaxValue = 3
};
public static class PartnerOrderModeExtension
{
public static PartnerOrderMode Next(this PartnerOrderMode mode)
{
return (PartnerOrderMode)(((int)mode + 1) % ((int)PartnerOrderMode.Maxvlaue+1));
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,
@ -56,7 +54,6 @@ namespace RJWSexperience.UI
(int)xxx.rjwSextype.Sixtynine
};
protected Pawn pawn;
protected SexPartnerHistoryRecord selectedPawn;
protected SexPartnerHistory history;
@ -64,18 +61,17 @@ namespace RJWSexperience.UI
protected List<SexPartnerHistoryRecord> partnerList;
protected PartnerOrderMode orderMode;
private static GUIStyleState fontstylestate = new GUIStyleState() { textColor = Color.white };
private static GUIStyleState boxstylestate = GUI.skin.textArea.normal;
private static GUIStyleState buttonstylestate = GUI.skin.button.normal;
private static GUIStyle fontstylecenter = new GUIStyle() { alignment = TextAnchor.MiddleCenter, normal = fontstylestate };
private static GUIStyle fontstyleright = new GUIStyle() { alignment = TextAnchor.MiddleRight, normal = fontstylestate };
private static GUIStyle fontstyleleft = new GUIStyle() { alignment = TextAnchor.MiddleLeft, normal = fontstylestate };
private static GUIStyle boxstyle = new GUIStyle(GUI.skin.textArea) { hover = boxstylestate, onHover = boxstylestate, onNormal = boxstylestate };
private static GUIStyle buttonstyle = new GUIStyle(GUI.skin.button) { hover = buttonstylestate, onHover = buttonstylestate, onNormal = buttonstylestate };
private static readonly GUIStyleState fontstylestate = new GUIStyleState() { textColor = Color.white };
private static readonly GUIStyleState boxstylestate = GUI.skin.textArea.normal;
private static readonly GUIStyleState buttonstylestate = GUI.skin.button.normal;
private static readonly GUIStyle fontstylecenter = new GUIStyle() { alignment = TextAnchor.MiddleCenter, normal = fontstylestate };
private static readonly GUIStyle fontstyleright = new GUIStyle() { alignment = TextAnchor.MiddleRight, normal = fontstylestate };
private static readonly GUIStyle fontstyleleft = new GUIStyle() { alignment = TextAnchor.MiddleLeft, normal = fontstylestate };
private static readonly GUIStyle boxstyle = new GUIStyle(GUI.skin.textArea) { hover = boxstylestate, onHover = boxstylestate, onNormal = boxstylestate };
private static readonly GUIStyle buttonstyle = new GUIStyle(GUI.skin.button) { hover = buttonstylestate, onHover = buttonstylestate, onNormal = buttonstylestate };
private static Vector2 pos;
private static Vector2 scroll;
private static bool opened;
private static Vector2 LastWindowPosition { get; set; }
private Vector2 scroll;
public SexStatusWindow(Pawn pawn, SexPartnerHistory history)
{
@ -86,44 +82,36 @@ namespace RJWSexperience.UI
this.partnerList = history?.PartnerList;
orderMode = PartnerOrderMode.Recent;
SortPartnerList(orderMode);
}
protected override void SetInitialSizeAndPosition()
{
Vector2 initialSize = InitialSize;
if (!opened)
{
windowRect = new Rect((Verse.UI.screenWidth - initialSize.x) / 2f, ((float)Verse.UI.screenHeight - initialSize.y) / 2f, initialSize.x, initialSize.y);
opened = true;
}
else
{
windowRect = new Rect(pos, initialSize);
}
windowRect = windowRect.Rounded();
}
public override Vector2 InitialSize
{
get
{
float width = 900f;
float height = 600f;
soundClose = SoundDefOf.CommsWindow_Close;
absorbInputAroundWindow = false;
forcePause = false;
preventCameraMotion = false;
draggable = true;
doCloseX = true;
return new Vector2(width, height);
}
}
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 PreClose()
{
base.PreClose();
LastWindowPosition = windowRect.position;
}
public override void DoWindowContents(Rect inRect)
{
pos = windowRect.position;
if (!SexperienceMod.Settings.SelectionLocked)
{
List<Pawn> selected = Find.Selector.SelectedPawns;
@ -138,7 +126,6 @@ namespace RJWSexperience.UI
}
}
DrawSexStatus(inRect, history);
}
@ -162,10 +149,14 @@ namespace RJWSexperience.UI
public void ChangePawn(Pawn pawn, SexPartnerHistory history)
{
List<Pawn> selected = Find.Selector.SelectedPawns;
if (!selected.NullOrEmpty()) foreach(Pawn p in selected)
if (!selected.NullOrEmpty())
{
foreach (Pawn p in selected)
{
Find.Selector.Deselect(p);
}
}
this.pawn = pawn;
this.history = history;
this.selectedPawn = null;
@ -204,7 +195,7 @@ namespace RJWSexperience.UI
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);
Rect rightRect = new Rect(mainrect.x + (sectionwidth * 2), mainrect.y, sectionwidth, mainrect.height);
if (history != null)
{
@ -217,9 +208,6 @@ namespace RJWSexperience.UI
//Right section
DrawBaseSexInfoRight(rightRect.ContractedBy(4f));
}
}
protected void DrawInfoWithPortrait(Rect rect, SexPartnerHistoryRecord history, string tooltip = "")
@ -229,8 +217,8 @@ namespace RJWSexperience.UI
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);
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)
{
@ -246,7 +234,10 @@ namespace RJWSexperience.UI
ChangePawn(partner, pawnhistory);
SoundDefOf.Click.PlayOneShotOnCamera();
}
else SoundDefOf.ClickReject.PlayOneShotOnCamera();
else
{
SoundDefOf.ClickReject.PlayOneShotOnCamera();
}
}
GUI.Label(nameRect, partner?.Name?.ToStringFull ?? history.Label.CapitalizeFirst(), fontstyleleft);
GUI.Label(sexinfoRect, Keyed.RS_Sex_Count + history.TotalSexCount + " " + history.RapeInfo, fontstyleleft);
@ -259,7 +250,6 @@ namespace RJWSexperience.UI
str += "\n" + history.BestSexDays;
TooltipHandler.TipRegion(rect, str);
}
else
{
@ -278,8 +268,6 @@ namespace RJWSexperience.UI
GUI.Label(labelRect, label, fontstyleleft);
GUI.Label(labelRect, rightlabel, fontstyleright);
DrawInfoWithPortrait(infoRect, history, tooltip);
}
/// <summary>
@ -296,8 +284,6 @@ namespace RJWSexperience.UI
GUI.Label(listmain.GetRect(FONTHEIGHT), Keyed.RS_PreferRace, fontstyleleft);
DrawPreferRace(listmain.GetRect(66f + 15f));
listmain.GetRect(15f);
listmain.End();
}
@ -307,7 +293,7 @@ namespace RJWSexperience.UI
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);
Rect infoRect3 = new Rect(rect.x + portraitRect.width, rect.y + (FONTHEIGHT * 2), rect.width - portraitRect.width - 2f, FONTHEIGHT);
if (history.PreferRace != null)
{
@ -335,14 +321,13 @@ namespace RJWSexperience.UI
}
}
/// <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 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;
@ -359,7 +344,6 @@ namespace RJWSexperience.UI
}
}
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);
@ -394,7 +378,6 @@ namespace RJWSexperience.UI
}
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.CapitalizeFirst() + ": {0:P2}", pawn.Dead ? 0 : pawn.GetStatValue(xxx.sex_drive_stat)));
@ -466,7 +449,6 @@ namespace RJWSexperience.UI
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.CapitalizeFirst() + ": {0:P2}", p), p / 2, HistoryUtility.Satisfaction, Texture2D.blackTexture);
@ -485,7 +467,6 @@ namespace RJWSexperience.UI
TooltipHandler.TipRegion(tmp, RJWUIUtility.GetStatExplanation(pawn, xxx.sex_stat, pawn.Dead ? 0 : pawn.GetStatValue(xxx.sex_stat)));
}
listmain.Gap(1f);
if (selectedPawn != null) DrawSexInfoCard(listmain.GetRect(CARDHEIGHT), selectedPawn, Keyed.RS_Selected_Partner, Keyed.RS_Selected_Partner, RJWUIUtility.GetSexDays(selectedPawn.RecentSexTickAbs));
@ -505,16 +486,9 @@ namespace RJWSexperience.UI
listmain.Gap(1f);
listmain.GetRect(FONTHEIGHT).DrawQuirk(pawn);
listmain.Gap(1f);
listmain.End();
}
/// <summary>
/// Left section
/// </summary>
@ -609,7 +583,7 @@ namespace RJWSexperience.UI
if (history != null)
{
bool drawheart = false;
Rect iconRect = new Rect(rect.x + rect.width * 3 / 4, rect.y, rect.width / 4, rect.height / 4);
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)
@ -622,10 +596,9 @@ namespace RJWSexperience.UI
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 != null && history.Race.uiIcon != null)
else if (history.Race?.uiIcon != null)
{
img = history.Race.uiIcon;
}
@ -644,9 +617,6 @@ namespace RJWSexperience.UI
}
}
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);
@ -658,10 +628,6 @@ namespace RJWSexperience.UI
{
rect.DrawBorder(border, 2f);
}
}
}
}