Settings tab for sex records

This commit is contained in:
amevarashi 2022-05-09 08:16:51 +05:00
parent bc5b9c00b5
commit 4d4f632a7d
10 changed files with 178 additions and 112 deletions

View File

@ -62,6 +62,7 @@
<!-- Settings tab labels -->
<TabLabelMain>Main</TabLabelMain>
<TabLabelHistory>Sex records</TabLabelHistory>
<TabLabelDebug>Debug</TabLabelDebug>
<!-- Mod settings -->

View File

@ -1,151 +1,94 @@
using RimWorld;
using UnityEngine;
using UnityEngine;
using Verse;
using RJWSexperience.Settings;
namespace RJWSexperience
{
public class Configurations : ModSettings, Settings.ITab
public class Configurations : ModSettings, ITab
{
public string Label => Keyed.TabLabelMain;
public const int CurrentSettingsVersion = 1;
// Defaults
public const float MaxInitialLustDefault = 400f;
public const float AvgLustDefault = 0f;
public const float MaxSexCountDeviationDefault = 90f;
public const float LustEffectPowerDefault = 0.5f;
public const float SexPerYearDefault = 30f;
public const bool SlavesBeenRapedExpDefault = true;
public const bool EnableStatRandomizerDefault = true;
public const bool EnableBastardRelationDefault = true;
public const float LustLimitDefault = MaxInitialLustDefault / 3f;
public const float LustLimitDefault = SettingsTabHistory.MaxLustDeviationDefault / 3f;
public const float MaxSingleLustChangeDefault = 0.5f;
public const bool MinSexableFromLifestageDefault = true;
public const float MinSexablePercentDefault = 0.2f;
public const float VirginRatioDefault = 0.01f;
public const bool SexCanFillBucketsDefault = false;
public const bool selectionLockedDefault = false;
// Private attributes
private float maxLustDeviation = MaxInitialLustDefault;
private float avgLust = AvgLustDefault;
private float maxSexCountDeviation = MaxSexCountDeviationDefault;
private float lustEffectPower = LustEffectPowerDefault;
private float sexPerYear = SexPerYearDefault;
private bool slavesBeenRapedExp = SlavesBeenRapedExpDefault;
private bool enableRecordRandomizer = EnableStatRandomizerDefault;
private bool enableBastardRelation = EnableBastardRelationDefault;
private float lustLimit = LustLimitDefault;
private bool minSexableFromLifestage = MinSexableFromLifestageDefault;
private float minSexablePercent = MinSexablePercentDefault;
private float virginRatio = VirginRatioDefault;
private float maxSingleLustChange = MaxSingleLustChangeDefault;
private bool sexCanFillBuckets = SexCanFillBucketsDefault;
private bool selectionLocked = selectionLockedDefault;
private Settings.SettingsTabDebug debug;
private SettingsTabHistory history;
private SettingsTabDebug debug;
//Public read-only properties
public float MaxLustDeviation => maxLustDeviation;
public float AvgLust => avgLust;
public float MaxSexCountDeviation => maxSexCountDeviation;
public float LustEffectPower => lustEffectPower;
public float SexPerYear => sexPerYear;
public bool SlavesBeenRapedExp => slavesBeenRapedExp;
public bool EnableRecordRandomizer => enableRecordRandomizer;
public bool EnableBastardRelation => enableBastardRelation;
public float LustLimit => lustLimit;
public bool MinSexableFromLifestage => minSexableFromLifestage;
public float MinSexablePercent => minSexablePercent;
public float VirginRatio => virginRatio;
public float MaxSingleLustChange => maxSingleLustChange;
public bool SexCanFillBuckets => sexCanFillBuckets;
public Settings.SettingsTabDebug Debug => debug;
public SettingsTabHistory History => history;
public SettingsTabDebug Debug => debug;
[System.Diagnostics.CodeAnalysis.SuppressMessage("Minor Code Smell", "S2292:Trivial properties should be auto-implemented", Justification = "Can't scribe property")]
public bool SelectionLocked { get => selectionLocked; set => selectionLocked = value; }
public void ResetToDefault()
{
maxLustDeviation = MaxInitialLustDefault;
avgLust = AvgLustDefault;
maxSexCountDeviation = MaxSexCountDeviationDefault;
lustEffectPower = LustEffectPowerDefault;
sexPerYear = SexPerYearDefault;
slavesBeenRapedExp = SlavesBeenRapedExpDefault;
enableRecordRandomizer = EnableStatRandomizerDefault;
enableBastardRelation = EnableBastardRelationDefault;
lustLimit = LustLimitDefault;
maxSingleLustChange = MaxSingleLustChangeDefault;
minSexableFromLifestage = MinSexableFromLifestageDefault;
minSexablePercent = MinSexablePercentDefault;
virginRatio = VirginRatioDefault;
sexCanFillBuckets = SexCanFillBucketsDefault;
sexCanFillBuckets = SexCanFillBucketsDefault;
}
public override void ExposeData()
{
Scribe_Values.Look(ref maxLustDeviation, "MaxLustDeviation", MaxInitialLustDefault);
Scribe_Values.Look(ref avgLust, "AvgLust", AvgLustDefault);
Scribe_Values.Look(ref maxSexCountDeviation, "MaxSexCountDeviation", MaxSexCountDeviationDefault);
int version = CurrentSettingsVersion;
Scribe_Values.Look(ref version, "SettingsVersion", 0);
Scribe_Values.Look(ref lustEffectPower, "LustEffectPower", LustEffectPowerDefault);
Scribe_Values.Look(ref sexPerYear, "SexPerYear", SexPerYearDefault);
Scribe_Values.Look(ref slavesBeenRapedExp, "SlavesBeenRapedExp", SlavesBeenRapedExpDefault);
Scribe_Values.Look(ref enableRecordRandomizer, "EnableRecordRandomizer", EnableStatRandomizerDefault);
Scribe_Values.Look(ref enableBastardRelation, "EnableBastardRelation", EnableBastardRelationDefault);
Scribe_Values.Look(ref lustLimit, "LustLimit", LustLimitDefault);
Scribe_Values.Look(ref maxSingleLustChange, "maxSingleLustChange", MaxSingleLustChangeDefault);
Scribe_Values.Look(ref minSexableFromLifestage, "MinSexableFromLifestage", MinSexableFromLifestageDefault);
Scribe_Values.Look(ref minSexablePercent, "MinSexablePercent", MinSexablePercentDefault);
Scribe_Values.Look(ref virginRatio, "VirginRatio", VirginRatioDefault);
Scribe_Values.Look(ref selectionLocked, "SelectionLocked", selectionLockedDefault);
Scribe_Values.Look(ref sexCanFillBuckets, "SexCanFillBuckets", SexCanFillBucketsDefault);
Scribe_Deep.Look(ref history, "History");
Scribe_Deep.Look(ref debug, "Debug");
base.ExposeData();
if (Scribe.mode != LoadSaveMode.LoadingVars)
return;
if (history == null)
{
history = new SettingsTabHistory();
// Previously history settings were in Configurations. Direct call to try read old data
history.ExposeData();
}
if (debug == null)
{
debug = new Settings.SettingsTabDebug();
debug = new SettingsTabDebug();
debug.Reset();
}
}
public void DoTabContents(Rect inRect)
{
const float lineHeight = 24f;
const float lineHeight = SettingsWidgets.lineHeight;
Listing_Standard listmain = new Listing_Standard();
listmain.maxOneColumn = true;
listmain.Begin(inRect);
SliderOption(listmain.GetRect(lineHeight * 2f), Keyed.Option_2_Label + " x" + lustEffectPower, Keyed.Option_2_Desc, ref lustEffectPower, 0f, 2f, 0.01f);
SliderOption(listmain.GetRect(lineHeight * 2f), Keyed.Option_8_Label + " " + lustLimit, Keyed.Option_8_Desc, ref lustLimit, 0f, 5000f, 1f);
SliderOption(listmain.GetRect(lineHeight * 2f), Keyed.Option_MaxSingleLustChange_Label + " " + maxSingleLustChange, Keyed.Option_MaxSingleLustChange_Desc, ref maxSingleLustChange, 0f, 10f, 0.05f);
listmain.CheckboxLabeled(Keyed.Option_1_Label, ref enableRecordRandomizer, Keyed.Option_1_Desc);
if (enableRecordRandomizer)
{
float sectionHeight = 12f;
if (!minSexableFromLifestage) sectionHeight += 2f;
Listing_Standard section = listmain.BeginSection(lineHeight * sectionHeight);
SliderOption(section.GetRect(lineHeight * 2f), Keyed.Option_3_Label + " " + maxLustDeviation, Keyed.Option_3_Desc, ref maxLustDeviation, 0f, 2000f, 1f);
SliderOption(section.GetRect(lineHeight * 2f), Keyed.Option_4_Label + " " + avgLust, Keyed.Option_4_Desc, ref avgLust, -1000f, 1000f, 1f);
SliderOption(section.GetRect(lineHeight * 2f), Keyed.Option_5_Label + " " + maxSexCountDeviation, Keyed.Option_5_Desc, ref maxSexCountDeviation, 0f, 2000f, 1f);
SliderOption(section.GetRect(lineHeight * 2f), Keyed.Option_6_Label + " " + sexPerYear, Keyed.Option_6_Desc, ref sexPerYear, 0f, 2000f, 1f);
section.CheckboxLabeled(Keyed.Option_MinSexableFromLifestage_Label, ref minSexableFromLifestage, Keyed.Option_MinSexableFromLifestage_Desc);
if (!minSexableFromLifestage)
SliderOption(section.GetRect(lineHeight * 2f), $"{Keyed.Option_9_Label} {minSexablePercent:P1} {ThingDefOf.Human.race.lifeExpectancy * minSexablePercent} human years", Keyed.Option_9_Desc, ref minSexablePercent, 0, 1, 0.001f);
SliderOption(section.GetRect(lineHeight * 2f), $"{Keyed.Option_10_Label} {virginRatio:P1}", Keyed.Option_10_Desc, ref virginRatio, 0f, 1f, 0.001f);
section.CheckboxLabeled(Keyed.Option_7_Label, ref slavesBeenRapedExp, Keyed.Option_7_Desc);
listmain.EndSection(section);
}
SettingsWidgets.SliderOption(listmain.GetRect(lineHeight * 2f), Keyed.Option_2_Label + " x" + lustEffectPower, Keyed.Option_2_Desc, ref lustEffectPower, 0f, 2f, 0.01f);
SettingsWidgets.SliderOption(listmain.GetRect(lineHeight * 2f), Keyed.Option_8_Label + " " + lustLimit, Keyed.Option_8_Desc, ref lustLimit, 0f, 5000f, 1f);
SettingsWidgets.SliderOption(listmain.GetRect(lineHeight * 2f), Keyed.Option_MaxSingleLustChange_Label + " " + maxSingleLustChange, Keyed.Option_MaxSingleLustChange_Desc, ref maxSingleLustChange, 0f, 10f, 0.05f);
listmain.CheckboxLabeled(Keyed.Option_EnableBastardRelation_Label, ref enableBastardRelation, Keyed.Option_EnableBastardRelation_Desc);
listmain.CheckboxLabeled(Keyed.Option_SexCanFillBuckets_Label, ref sexCanFillBuckets, Keyed.Option_SexCanFillBuckets_Desc);
@ -156,31 +99,5 @@ namespace RJWSexperience
}
listmain.End();
}
private void LabelwithTextfield(Rect rect, string label, string tooltip, ref float value, float min, float max)
{
Rect textfieldRect = new Rect(rect.xMax - 100f, rect.y, 100f, rect.height);
string valuestr = value.ToString();
Widgets.Label(rect, label);
Widgets.TextFieldNumeric(textfieldRect, ref value, ref valuestr, min, max);
Widgets.DrawHighlightIfMouseover(rect);
TooltipHandler.TipRegion(rect, tooltip);
}
private void SliderOption(Rect doublerect, string label, string tooltip, ref float value, float min, float max, float roundTo = -1f)
{
// Slider was fighting with textfield for "correct" decimals. Causes a repeating slider move sound
float fieldValue = value;
float sliderValue = value;
float minChange = roundTo / 10f;
LabelwithTextfield(doublerect.TopHalf(), label, tooltip, ref fieldValue, min, max);
sliderValue = Widgets.HorizontalSlider(doublerect.BottomHalf(), sliderValue, min, max, roundTo: roundTo);
if (Mathf.Abs(fieldValue - value) > minChange)
value = fieldValue;
else if (Mathf.Abs(sliderValue - value) > minChange)
value = sliderValue;
}
}
}

View File

@ -60,7 +60,7 @@ namespace RJWSexperience
{
if (!allzero)
{
if (SexperienceMod.Settings.EnableRecordRandomizer && pawn != null && xxx.is_human(pawn))
if (SexperienceMod.Settings.History.EnableRecordRandomizer && pawn != null && xxx.is_human(pawn))
{
RecordRandomizer.Randomize(pawn);
}

View File

@ -64,6 +64,7 @@ namespace RJWSexperience
public static readonly string RS_LastSex = "RS_LastSex".Translate();
public static readonly string TabLabelMain = "TabLabelMain".Translate();
public static readonly string TabLabelHistory = "TabLabelHistory".Translate();
public static readonly string TabLabelDebug = "TabLabelDebug".Translate();
public static readonly string Option_1_Label = "RSOption_1_Label".Translate();

View File

@ -10,7 +10,7 @@ namespace RJWSexperience
{
public static void Postfix(PawnGenerationRequest request, ref Pawn __result)
{
if (SexperienceMod.Settings.EnableRecordRandomizer && __result != null && !request.Newborn && xxx.is_human(__result))
if (SexperienceMod.Settings.History.EnableRecordRandomizer && __result != null && !request.Newborn && xxx.is_human(__result))
{
RecordRandomizer.Randomize(__result);
}

View File

@ -84,9 +84,11 @@
<Compile Include="Logs\LogManager.cs" />
<Compile Include="Patches\DefInjection.cs" />
<Compile Include="Recipe_HymenSurgery.cs" />
<Compile Include="Settings\SettingsTabHistory.cs" />
<Compile Include="Settings\SettingsTabDebug.cs" />
<Compile Include="Settings\IResettable.cs" />
<Compile Include="Settings\ITab.cs" />
<Compile Include="Settings\SettingsWidgets.cs" />
<Compile Include="SexHistory\RecordRandomizer.cs" />
<Compile Include="RJWUtility.cs" />
<Compile Include="SexHistory\HistoryUtility.cs" />

View File

@ -0,0 +1,109 @@
using RimWorld;
using UnityEngine;
using Verse;
namespace RJWSexperience.Settings
{
public class SettingsTabHistory : IExposable, IResettable, ITab
{
public string Label => Keyed.TabLabelHistory;
// Defaults
public const bool EnableStatRandomizerDefault = true;
public const float MaxLustDeviationDefault = 400f;
public const float AvgLustDefault = 0f;
public const float MaxSexCountDeviationDefault = 90f;
public const float SexPerYearDefault = 30f;
public const bool MinSexableFromLifestageDefault = true;
public const float MinSexablePercentDefault = 0.2f;
public const float VirginRatioDefault = 0.01f;
public const bool SlavesBeenRapedExpDefault = true;
// Private attributes
private bool enableRecordRandomizer = EnableStatRandomizerDefault;
private float maxLustDeviation = MaxLustDeviationDefault;
private float avgLust = AvgLustDefault;
private float maxSexCountDeviation = MaxSexCountDeviationDefault;
private float sexPerYear = SexPerYearDefault;
private bool minSexableFromLifestage = MinSexableFromLifestageDefault;
private float minSexablePercent = MinSexablePercentDefault;
private float virginRatio = VirginRatioDefault;
private bool slavesBeenRapedExp = SlavesBeenRapedExpDefault;
//Public read-only properties
public bool EnableRecordRandomizer => enableRecordRandomizer;
public float MaxLustDeviation => maxLustDeviation;
public float AvgLust => avgLust;
public float MaxSexCountDeviation => maxSexCountDeviation;
public float SexPerYear => sexPerYear;
public bool MinSexableFromLifestage => minSexableFromLifestage;
public float MinSexablePercent => minSexablePercent;
public float VirginRatio => virginRatio;
public bool SlavesBeenRapedExp => slavesBeenRapedExp;
public void Reset()
{
enableRecordRandomizer = EnableStatRandomizerDefault;
maxLustDeviation = MaxLustDeviationDefault;
avgLust = AvgLustDefault;
maxSexCountDeviation = MaxSexCountDeviationDefault;
sexPerYear = SexPerYearDefault;
minSexableFromLifestage = MinSexableFromLifestageDefault;
minSexablePercent = MinSexablePercentDefault;
virginRatio = VirginRatioDefault;
slavesBeenRapedExp = SlavesBeenRapedExpDefault;
}
public void ExposeData()
{
Scribe_Values.Look(ref enableRecordRandomizer, "EnableRecordRandomizer", EnableStatRandomizerDefault);
Scribe_Values.Look(ref maxLustDeviation, "MaxLustDeviation", MaxLustDeviationDefault);
Scribe_Values.Look(ref avgLust, "AvgLust", AvgLustDefault);
Scribe_Values.Look(ref maxSexCountDeviation, "MaxSexCountDeviation", MaxSexCountDeviationDefault);
Scribe_Values.Look(ref sexPerYear, "SexPerYear", SexPerYearDefault);
Scribe_Values.Look(ref minSexableFromLifestage, "MinSexableFromLifestage", MinSexableFromLifestageDefault);
Scribe_Values.Look(ref minSexablePercent, "MinSexablePercent", MinSexablePercentDefault);
Scribe_Values.Look(ref virginRatio, "VirginRatio", VirginRatioDefault);
Scribe_Values.Look(ref slavesBeenRapedExp, "SlavesBeenRapedExp", SlavesBeenRapedExpDefault);
}
public void DoTabContents(Rect inRect)
{
const float lineHeight = SettingsWidgets.lineHeight;
Listing_Standard listmain = new Listing_Standard();
listmain.Begin(inRect);
listmain.CheckboxLabeled(Keyed.Option_1_Label, ref enableRecordRandomizer, Keyed.Option_1_Desc);
if (enableRecordRandomizer)
{
float sectionHeight = 12f;
if (!minSexableFromLifestage)
sectionHeight += 2f;
Listing_Standard section = listmain.BeginSection(lineHeight * sectionHeight);
SettingsWidgets.SliderOption(section.GetRect(lineHeight * 2f), Keyed.Option_3_Label + " " + maxLustDeviation, Keyed.Option_3_Desc, ref maxLustDeviation, 0f, 2000f, 1f);
SettingsWidgets.SliderOption(section.GetRect(lineHeight * 2f), Keyed.Option_4_Label + " " + avgLust, Keyed.Option_4_Desc, ref avgLust, -1000f, 1000f, 1f);
SettingsWidgets.SliderOption(section.GetRect(lineHeight * 2f), Keyed.Option_5_Label + " " + maxSexCountDeviation, Keyed.Option_5_Desc, ref maxSexCountDeviation, 0f, 2000f, 1f);
SettingsWidgets.SliderOption(section.GetRect(lineHeight * 2f), Keyed.Option_6_Label + " " + sexPerYear, Keyed.Option_6_Desc, ref sexPerYear, 0f, 2000f, 1f);
section.CheckboxLabeled(Keyed.Option_MinSexableFromLifestage_Label, ref minSexableFromLifestage, Keyed.Option_MinSexableFromLifestage_Desc);
if (!minSexableFromLifestage)
SettingsWidgets.SliderOption(section.GetRect(lineHeight * 2f), $"{Keyed.Option_9_Label} {minSexablePercent:P1} {ThingDefOf.Human.race.lifeExpectancy * minSexablePercent} human years", Keyed.Option_9_Desc, ref minSexablePercent, 0, 1, 0.001f);
SettingsWidgets.SliderOption(section.GetRect(lineHeight * 2f), $"{Keyed.Option_10_Label} {virginRatio:P1}", Keyed.Option_10_Desc, ref virginRatio, 0f, 1f, 0.001f);
section.CheckboxLabeled(Keyed.Option_7_Label, ref slavesBeenRapedExp, Keyed.Option_7_Desc);
listmain.EndSection(section);
}
if (listmain.ButtonText(Keyed.Button_ResetToDefault))
{
Reset();
}
listmain.End();
}
}
}

View File

@ -0,0 +1,36 @@
using UnityEngine;
using Verse;
namespace RJWSexperience.Settings
{
public static class SettingsWidgets
{
public const float lineHeight = 24f;
public static void LabelwithTextfield(Rect rect, string label, string tooltip, ref float value, float min, float max)
{
Rect textfieldRect = new Rect(rect.xMax - 100f, rect.y, 100f, rect.height);
string valuestr = value.ToString();
Widgets.Label(rect, label);
Widgets.TextFieldNumeric(textfieldRect, ref value, ref valuestr, min, max);
Widgets.DrawHighlightIfMouseover(rect);
TooltipHandler.TipRegion(rect, tooltip);
}
public static void SliderOption(Rect doublerect, string label, string tooltip, ref float value, float min, float max, float roundTo)
{
// Slider was fighting with textfield for "correct" decimals. Causes a repeating slider move sound
float fieldValue = value;
float sliderValue = value;
float minChange = roundTo / 10f;
LabelwithTextfield(doublerect.TopHalf(), label, tooltip, ref fieldValue, min, max);
sliderValue = Widgets.HorizontalSlider(doublerect.BottomHalf(), sliderValue, min, max, roundTo: roundTo);
if (Mathf.Abs(fieldValue - value) > minChange)
value = fieldValue;
else if (Mathf.Abs(sliderValue - value) > minChange)
value = sliderValue;
}
}
}

View File

@ -3,13 +3,12 @@ using System;
using Verse;
using RimWorld;
using UnityEngine;
using RJWSexperience.ExtensionMethods;
namespace RJWSexperience
{
public static class RecordRandomizer
{
private static Configurations Settings => SexperienceMod.Settings;
private static Settings.SettingsTabHistory Settings => SexperienceMod.Settings.History;
public static void Randomize(Pawn pawn)
{

View File

@ -35,6 +35,7 @@ namespace RJWSexperience
List<ITab> tabs = new List<ITab>
{
settings,
settings.History,
settings.Debug
};