Add tabs in the mod settings

This commit is contained in:
amevarashi 2022-05-06 19:30:26 +05:00
parent 3807441418
commit 9dc47f704a
9 changed files with 154 additions and 41 deletions

View File

@ -60,6 +60,10 @@
<RS_LastSex>last sex</RS_LastSex>
<RS_HadBestSexDaysAgo>Had best sex {0}.</RS_HadBestSexDaysAgo>
<!-- Settings tab labels -->
<TabLabelMain>Main</TabLabelMain>
<TabLabelDebug>Debug</TabLabelDebug>
<!-- Mod settings -->
<RSOption_1_Label>Enable record randomizer</RSOption_1_Label>
<RSOption_1_Desc>Randomize pawn's sex records.</RSOption_1_Desc>

View File

@ -4,8 +4,11 @@ using Verse;
namespace RJWSexperience
{
public class Configurations : ModSettings
public class Configurations : ModSettings, Settings.ITab
{
public string Label => Keyed.TabLabelMain;
// Defaults
public const float MaxInitialLustDefault = 400f;
public const float AvgLustDefault = 0f;
public const float MaxSexCountDeviationDefault = 90f;
@ -19,8 +22,9 @@ namespace RJWSexperience
public const bool MinSexableFromLifestageDefault = true;
public const float MinSexablePercentDefault = 0.2f;
public const float VirginRatioDefault = 0.01f;
public const bool DebugDefault = false;
public const bool selectionLockedDefault = false;
// Private attributes
private float maxLustDeviation = MaxInitialLustDefault;
private float avgLust = AvgLustDefault;
private float maxSexCountDeviation = MaxSexCountDeviationDefault;
@ -34,25 +38,24 @@ namespace RJWSexperience
private float minSexablePercent = MinSexablePercentDefault;
private float virginRatio = VirginRatioDefault;
private float maxSingleLustChange = MaxSingleLustChangeDefault;
private bool debug = DebugDefault;
public float MaxLustDeviation { get => maxLustDeviation; }
public float AvgLust { get => avgLust; }
public float MaxSexCountDeviation { get => maxSexCountDeviation; }
public float LustEffectPower { get => lustEffectPower; }
public float SexPerYear { get => sexPerYear; }
public bool SlavesBeenRapedExp { get => slavesBeenRapedExp; }
public bool EnableRecordRandomizer { get => enableRecordRandomizer; }
public bool EnableBastardRelation { get => enableBastardRelation; }
public float LustLimit { get => lustLimit; }
public bool MinSexableFromLifestage { get => minSexableFromLifestage; }
public float MinSexablePercent { get => minSexablePercent; }
public float VirginRatio { get => virginRatio; }
public float MaxSingleLustChange { get => maxSingleLustChange; }
public bool Debug { get => debug; }
private bool selectionLocked = false;
private bool selectionLocked = selectionLockedDefault;
private Settings.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 Settings.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; }
@ -71,30 +74,38 @@ namespace RJWSexperience
minSexableFromLifestage = MinSexableFromLifestageDefault;
minSexablePercent = MinSexablePercentDefault;
virginRatio = VirginRatioDefault;
debug = DebugDefault;
}
public override void ExposeData()
{
Scribe_Values.Look(ref maxLustDeviation, "MaxLustDeviation", MaxInitialLustDefault, true);
Scribe_Values.Look(ref avgLust, "AvgLust", AvgLustDefault, true);
Scribe_Values.Look(ref maxSexCountDeviation, "MaxSexCountDeviation", MaxSexCountDeviationDefault, true);
Scribe_Values.Look(ref lustEffectPower, "LustEffectPower", LustEffectPowerDefault, true);
Scribe_Values.Look(ref sexPerYear, "SexPerYear", SexPerYearDefault, true);
Scribe_Values.Look(ref slavesBeenRapedExp, "SlavesBeenRapedExp", SlavesBeenRapedExpDefault, true);
Scribe_Values.Look(ref enableRecordRandomizer, "EnableRecordRandomizer", EnableStatRandomizerDefault, true);
Scribe_Values.Look(ref enableBastardRelation, "EnableBastardRelation", EnableBastardRelationDefault, true);
Scribe_Values.Look(ref lustLimit, "LustLimit", LustLimitDefault, true);
Scribe_Values.Look(ref maxSingleLustChange, "maxSingleLustChange", MaxSingleLustChangeDefault, true);
Scribe_Values.Look(ref minSexableFromLifestage, "MinSexableFromLifestage", MinSexableFromLifestageDefault, true);
Scribe_Values.Look(ref minSexablePercent, "MinSexablePercent", MinSexablePercentDefault, true);
Scribe_Values.Look(ref virginRatio, "VirginRatio", VirginRatioDefault, true);
Scribe_Values.Look(ref debug, "Debug", DebugDefault, true);
Scribe_Values.Look(ref selectionLocked, "SelectionLocked");
Scribe_Values.Look(ref maxLustDeviation, "MaxLustDeviation", MaxInitialLustDefault);
Scribe_Values.Look(ref avgLust, "AvgLust", AvgLustDefault);
Scribe_Values.Look(ref maxSexCountDeviation, "MaxSexCountDeviation", MaxSexCountDeviationDefault);
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_Deep.Look(ref debug, "Debug");
base.ExposeData();
if (Scribe.mode != LoadSaveMode.LoadingVars)
return;
if (debug == null)
{
debug = new Settings.SettingsTabDebug();
debug.Reset();
}
}
public void DoSettingsWindowContents(Rect inRect)
public void DoTabContents(Rect inRect)
{
const float lineHeight = 24f;
@ -132,7 +143,6 @@ namespace RJWSexperience
}
listmain.CheckboxLabeled(Keyed.Option_EnableBastardRelation_Label, ref enableBastardRelation, Keyed.Option_EnableBastardRelation_Desc);
listmain.CheckboxLabeled(Keyed.Option_Debug_Label, ref debug, Keyed.Option_Debug_Desc);
if (listmain.ButtonText(Keyed.Button_ResetToDefault))
{

View File

@ -63,6 +63,9 @@ namespace RJWSexperience
public static readonly string RS_Ago = "RS_Ago".Translate();
public static readonly string RS_LastSex = "RS_LastSex".Translate();
public static readonly string TabLabelMain = "TabLabelMain".Translate();
public static readonly string TabLabelDebug = "TabLabelDebug".Translate();
public static readonly string Option_1_Label = "RSOption_1_Label".Translate();
public static readonly string Option_1_Desc = "RSOption_1_Desc".Translate();
public static readonly string Option_2_Label = "RSOption_2_Label".Translate();

View File

@ -4,6 +4,6 @@ namespace RJWSexperience.Logs
{
public class DebugLogProvider : ILogProvider
{
public bool IsActive => SexperienceMod.Settings.Debug;
public bool IsActive => SexperienceMod.Settings.Debug.DevMode;
}
}

View File

@ -69,6 +69,7 @@
<Compile Include="Configurations.cs" />
<Compile Include="Cum\CumUtility.cs" />
<Compile Include="Cum\JobGiver_UseBucket.cs" />
<Compile Include="Cum\WorkGiver_CleanSelfWithBucket.cs" />
<Compile Include="DebugAction.cs" />
<Compile Include="ExtensionMethods\PawnExtensions.cs" />
<Compile Include="ExtensionMethods\SexPropsExtensions.cs" />
@ -84,6 +85,9 @@
<Compile Include="Patches\DefInjection.cs" />
<Compile Include="Patches\GetGizmos.cs" />
<Compile Include="Recipe_HymenSurgery.cs" />
<Compile Include="Settings\SettingsTabDebug.cs" />
<Compile Include="Settings\IResettable.cs" />
<Compile Include="Settings\ITab.cs" />
<Compile Include="SexHistory\RecordRandomizer.cs" />
<Compile Include="RJWUtility.cs" />
<Compile Include="SexHistory\HistoryUtility.cs" />

View File

@ -0,0 +1,7 @@
namespace RJWSexperience.Settings
{
internal interface IResettable
{
void Reset();
}
}

View File

@ -0,0 +1,10 @@
using UnityEngine;
namespace RJWSexperience.Settings
{
public interface ITab
{
string Label { get; }
void DoTabContents(Rect inRect);
}
}

View File

@ -0,0 +1,42 @@
using UnityEngine;
using Verse;
namespace RJWSexperience.Settings
{
public class SettingsTabDebug : IExposable, IResettable, ITab
{
public string Label => Keyed.TabLabelDebug;
// Defaults
public const bool DevModeDefault = false;
// Private attributes
private bool devMode;
//Public read-only properties
public bool DevMode => devMode;
public void Reset()
{
devMode = DevModeDefault;
}
public void ExposeData()
{
Scribe_Values.Look(ref devMode, "DevMode", DevModeDefault);
}
public void DoTabContents(Rect inRect)
{
Listing_Standard listmain = new Listing_Standard();
listmain.Begin(inRect);
listmain.CheckboxLabeled(Keyed.Option_Debug_Label, ref devMode, Keyed.Option_Debug_Desc);
if (listmain.ButtonText(Keyed.Button_ResetToDefault))
{
Reset();
}
listmain.End();
}
}
}

View File

@ -1,17 +1,24 @@
using UnityEngine;
using System.Collections.Generic;
using Verse;
using RJWSexperience.Settings;
namespace RJWSexperience
{
public class SexperienceMod : Mod
{
private static Configurations settings;
public static Configurations Settings { get => settings; }
public ITab CurrentTab { get; private set; }
private readonly List<TabRecord> tabRecords;
public SexperienceMod(ModContentPack content) : base(content)
{
settings = GetSettings<Configurations>();
CurrentTab = settings;
tabRecords = new List<TabRecord>();
}
public override string SettingsCategory()
@ -19,6 +26,32 @@ namespace RJWSexperience
return Keyed.Mod_Title;
}
public override void DoSettingsWindowContents(Rect inRect) => Settings.DoSettingsWindowContents(inRect);
/// <summary>
/// Fills tabRecords list.
/// This method cannot be called in constructor because at that stage language file is not loaded
/// </summary>
private void InitTabRecords()
{
List<ITab> tabs = new List<ITab>
{
settings,
settings.Debug
};
foreach (ITab tab in tabs)
tabRecords.Add(new TabRecord(tab.Label, delegate { this.CurrentTab = tab; }, delegate { return this?.CurrentTab == tab; }));
}
public override void DoSettingsWindowContents(Rect inRect)
{
if (tabRecords.NullOrEmpty())
InitTabRecords();
Rect contentRect = inRect.ContractedBy(TabDrawer.TabHeight);
_ = TabDrawer.DrawTabs(contentRect, tabRecords);
CurrentTab.DoTabContents(contentRect);
}
}
}