Skip to content

Commit

Permalink
Add ideo and some small refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
eth0net committed Apr 1, 2023
1 parent 63960f3 commit e792029
Show file tree
Hide file tree
Showing 16 changed files with 82 additions and 42 deletions.
1 change: 1 addition & 0 deletions About/About.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ This mod was inspired by the wonderful Mr Samuel Streamer and his Biotech series
== Features ==

- Subcores and mechs store info about scanned pawns
- Stored info: Title, Name, Faction, and Ideology
- Info is shown in the tooltip for subcores and mechs
- Scanning a pawn saves their info to the subcore
- Subcores from traders get random info generated
Expand Down
Binary file modified Assemblies/SubcoreInfo.dll
Binary file not shown.
Binary file modified Images/MechInfo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Images/MechStats.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified Images/Settings.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified Images/SubcoreInfo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Images/SubcoreStats.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions Languages/English/Keyed/SubcoreInfo.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<LanguageData>
<SubcoreInfo>SubcoreInfo</SubcoreInfo>
<Ideoligion>Ideoligion</Ideoligion>
<Unknown>Unknown</Unknown>
</LanguageData>
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,16 @@ Track which unfortunate pawn your subcores came from!

![Subcore Info](./Images/SubcoreInfo.png)
![Mech Info](./Images/MechInfo.png)
![Subcore Stats](./Images/SubcoreStats.png)
![Mech Stats](./Images/MechStats.png)
![Settings](./Images/Settings.png)

**This mod was inspired by the wonderful Mr Samuel Streamer and his Biotech series!**

## Features

- Subcores and mechs store info about scanned pawns
- Stored info: Title, Name, Faction, and Ideology
- Info is shown in the tooltip for subcores and mechs
- Scanning a pawn saves their info to the subcore
- Subcores from traders get random info generated
Expand All @@ -23,13 +26,14 @@ This mod is safe to add or remove from saves!

Use this to add data to existing mechs or subcores in your save file:
```xml
<titleName>Supreme Leader</titleName>
<patternName Class="NameTriple">
<first>Poor</first>
<nick>Unfortunate</nick>
<last>Pawn</last>
</patternName>
<titleName>Supreme Leader</titleName>
<factionName>Some Faction</factionName>
<ideoName>Some Ideology</ideoName>
```

## Bugs and Requests
Expand Down
36 changes: 28 additions & 8 deletions Source/SubcoreInfo/Comps/CompPatternBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,50 +5,70 @@ namespace SubcoreInfo.Comps
public class CompPatternBase : ThingComp
{
/// <summary>
/// PatternName tracks the name of the pawn scanned.
/// TitleName tracks the title of the pawn scanned.
/// </summary>
public Name PatternName;
public string TitleName;

/// <summary>
/// TitleName tracks the title of the pawn scanned.
/// PawnName tracks the name of the pawn scanned.
/// </summary>
public string TitleName;
public Name PawnName;

/// <summary>
/// FactionName tracks the name of the faction of the pawn scanned.
/// </summary>
public string FactionName;

/// <summary>
/// IdeoName tracks the name of the ideologion of the pawn scanned.
/// </summary>
public string IdeoName;

/// <summary>
/// PostExposeData is used to save our component state.
/// </summary>
public override void PostExposeData()
{
Scribe_Deep.Look(ref PatternName, "patternName");
Scribe_Values.Look(ref TitleName, "titleName");
Scribe_Deep.Look(ref PawnName, "patternName");
Scribe_Values.Look(ref FactionName, "factionName");
Scribe_Values.Look(ref IdeoName, "ideoName");
base.PostExposeData();
}

/// <summary>
/// Copy loads the data from another comp into this one to ease data transfer.
/// Copy the data from a pawn into this comp to ease data transfer.
/// </summary>
/// <param name="pawn"></param>
public void Copy(Pawn pawn)
{
TitleName = pawn?.royalty?.MainTitle()?.GetLabelCapFor(pawn);
PawnName = pawn?.Name;
FactionName = pawn?.Faction?.Name;
IdeoName = pawn?.Ideo?.name;
}

/// <summary>
/// Copy the data from another comp into this one to ease data transfer.
/// </summary>
/// <param name="src"></param>
public void Copy(CompPatternBase src)
{
PatternName = src.PatternName;
TitleName = src.TitleName;
PawnName = src.PawnName;
FactionName = src.FactionName;
IdeoName = src.IdeoName;
}

/// <summary>
/// Reset clears all data in this comp.
/// </summary>
public void Reset()
{
PatternName = null;
TitleName = null;
PawnName = null;
FactionName = null;
IdeoName = null;
}
}
}
39 changes: 20 additions & 19 deletions Source/SubcoreInfo/Comps/CompPatternInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,10 @@ namespace SubcoreInfo.Comps
/// </summary>
public class CompPatternInfo : CompPatternBase
{
static TaggedString textName = "Name".Translate();
static TaggedString textTitle = "Title".Translate();
static TaggedString textName = "Name".Translate();
static TaggedString textFaction = "Faction".Translate();
static TaggedString textIdeo = "Ideoligion".Translate();
static TaggedString textUnknown = "Unknown".Translate();

/// <summary>
Expand All @@ -22,47 +23,47 @@ public override string CompInspectStringExtra()
{
StringBuilder sb = new StringBuilder();

if (SubcoreInfoSettings.showTitle && ModsConfig.RoyaltyActive)
{
sb.AppendLine(textTitle + ": " + (TitleName ?? textUnknown));
}

if (SubcoreInfoSettings.showFullName)
{
sb.AppendLine(textName + ": " + (PatternName?.ToStringFull ?? textUnknown));
sb.AppendLine(textName + ": " + (PawnName?.ToStringFull ?? textUnknown));
}
else
{
sb.AppendLine(textName + ": " + (PatternName?.ToStringShort ?? textUnknown));
sb.AppendLine(textName + ": " + (PawnName?.ToStringShort ?? textUnknown));
}

if (SubcoreInfoSettings.showTitle)
if (SubcoreInfoSettings.showFaction)
{
sb.AppendLine(textTitle + ": " + (TitleName ?? textUnknown));
sb.AppendLine(textFaction + ": " + (FactionName ?? textUnknown));
}

if (SubcoreInfoSettings.showFaction)
if (SubcoreInfoSettings.showIdeo && ModsConfig.IdeologyActive)
{
sb.AppendLine(textFaction + ": " + (FactionName ?? textUnknown));
sb.AppendLine(textIdeo + ": " + (IdeoName ?? textUnknown));
}

return sb.ToString().TrimEnd();
}

public override IEnumerable<RimWorld.StatDrawEntry> SpecialDisplayStats()
{
if (SubcoreInfoSettings.showFullName)
{
yield return new RimWorld.StatDrawEntry(StatCategoryDefOf.SubcoreInfo, textName, PatternName?.ToStringFull ?? textUnknown, "The full name of the pawn scanned to make this subcore.", 40);
}
else
if (ModsConfig.RoyaltyActive)
{
yield return new RimWorld.StatDrawEntry(StatCategoryDefOf.SubcoreInfo, textName, PatternName?.ToStringShort ?? textUnknown, "The short name of the pawn scanned to make this subcore.", 30);
yield return new RimWorld.StatDrawEntry(StatCategoryDefOf.SubcoreInfo, textTitle, TitleName ?? textUnknown, "The title of the pawn scanned to make this subcore.", 50);
}

if (SubcoreInfoSettings.showTitle)
{
yield return new RimWorld.StatDrawEntry(StatCategoryDefOf.SubcoreInfo, textTitle, TitleName ?? textUnknown, "The title of the pawn scanned to make this subcore.", 20);
}
yield return new RimWorld.StatDrawEntry(StatCategoryDefOf.SubcoreInfo, textName, PawnName?.ToStringFull ?? textUnknown, "The full name of the pawn scanned to make this subcore.", 40);

if (SubcoreInfoSettings.showFaction)
yield return new RimWorld.StatDrawEntry(StatCategoryDefOf.SubcoreInfo, textFaction, FactionName ?? textUnknown, "The faction of the pawn scanned to make this subcore.", 20);

if (ModsConfig.IdeologyActive)
{
yield return new RimWorld.StatDrawEntry(StatCategoryDefOf.SubcoreInfo, textFaction, FactionName ?? textUnknown, "The faction of the pawn scanned to make this subcore.", 10);
yield return new RimWorld.StatDrawEntry(StatCategoryDefOf.SubcoreInfo, textIdeo, IdeoName ?? textUnknown, "The ideoligion of the pawn scanned to make this subcore.", 10);
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions Source/SubcoreInfo/Comps/CompSubcoreInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public override bool AllowStackWith(Thing other)
CompSubcoreInfo otherComp = other?.TryGetComp<CompSubcoreInfo>();
if (otherComp == null) { return false; }

return PatternName == otherComp.PatternName && TitleName == otherComp.TitleName && FactionName == otherComp.FactionName;
return PawnName == otherComp.PawnName && TitleName == otherComp.TitleName && FactionName == otherComp.FactionName;
}

/// <summary>
Expand All @@ -42,7 +42,7 @@ public override void PostPostGeneratedForTrader(TraderKindDef trader, int forTil
RulePackDef pawnKindNameMaker = pawnKind.GetNameMaker(gender);
RulePackDef raceNameGenerator = pawnKind.RaceProps.GetNameGenerator(gender);

PatternName = PawnBioAndNameGenerator.GenerateFullPawnName(parent.def, pawnKindNameMaker, null, null, raceNameGenerator, null, gender);
PawnName = PawnBioAndNameGenerator.GenerateFullPawnName(parent.def, pawnKindNameMaker, null, null, raceNameGenerator, null, gender);
FactionName = forFaction.Name;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,7 @@ internal static class Harmony_Building_SubcoreScanner_TryAcceptPawn
/// <param name="pawn"></param>
internal static void Postfix(Building_SubcoreScanner __instance, Pawn pawn)
{
CompPatternBase comp = __instance.GetComp<CompPatternBase>();
comp.PatternName = pawn?.Name;
comp.FactionName = pawn?.Faction?.Name;
comp.TitleName = pawn?.royalty?.MainTitle()?.GetLabelCapFor(pawn);
__instance.GetComp<CompPatternBase>().Copy(pawn);
}
}

Expand Down
2 changes: 1 addition & 1 deletion Source/SubcoreInfo/Harmony/Harmony_Pawn.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ static bool validator(Thing subcore)
{
CompSubcoreInfo comp = subcore.TryGetComp<CompSubcoreInfo>();
if (comp == null) { return false; }
return comp.PatternName == null && comp.TitleName == null && comp.FactionName == null;
return comp.PawnName == null && comp.TitleName == null && comp.FactionName == null;
}

Thing subcore = GenClosest.ClosestThingReachable(mech.Position, mech.Map, ThingRequest.ForDef(subcoreClass.thingDef), PathEndMode.ClosestTouch, TraverseParms.For(TraverseMode.ByPawn), 9999, validator);
Expand Down
9 changes: 8 additions & 1 deletion Source/SubcoreInfo/SubcoreInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,16 @@ public override void DoSettingsWindowContents(Rect inRect)
listing.Label("Interface Settings");
listing.GapLine();

if (ModsConfig.RoyaltyActive)
{
listing.CheckboxLabeled("Show pawn title", ref SubcoreInfoSettings.showTitle);
}
listing.CheckboxLabeled("Show pawn full name", ref SubcoreInfoSettings.showFullName);
listing.CheckboxLabeled("Show pawn title", ref SubcoreInfoSettings.showTitle);
listing.CheckboxLabeled("Show pawn faction", ref SubcoreInfoSettings.showFaction);
if (ModsConfig.IdeologyActive)
{
listing.CheckboxLabeled("Show pawn ideoligion", ref SubcoreInfoSettings.showIdeo);
}

listing.GapLine();
listing.Label("Misc Settings");
Expand Down
21 changes: 15 additions & 6 deletions Source/SubcoreInfo/SubcoreInfoSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,27 +15,36 @@ internal class SubcoreInfoSettings : ModSettings
public static bool randomTraderPatterns = true;

/// <summary>
/// Show pawn full name in the subcore info oanel.
/// Show pawn title in the subcore info panel.
/// </summary>
public static bool showFullName = true;
public static bool showTitle = true;

/// <summary>
/// Show pawn title in the subcore info panel.
/// Show pawn full name in the subcore info oanel.
/// </summary>
public static bool showTitle = true;
public static bool showFullName = true;

/// <summary>
/// Show pawn faction in the subcore info panel.
/// </summary>
public static bool showFaction = true;

/// <summary>
/// Show pawn ideoligion in the subcore info panel.
/// </summary>
public static bool showIdeo = true;

/// <summary>
/// ExposeData saves and loads the settings.
/// </summary>
public override void ExposeData()
{
Scribe_Values.Look(ref separatePatternStacks, "separatePatternStacks", true, true);
Scribe_Values.Look(ref randomTraderPatterns, "randomTraderPatterns", true, true);
Scribe_Values.Look(ref separatePatternStacks, "separatePatternStacks", true);
Scribe_Values.Look(ref randomTraderPatterns, "randomTraderPatterns", true);
Scribe_Values.Look(ref showTitle, "showTitle", true);
Scribe_Values.Look(ref showFullName, "showFullName", true);
Scribe_Values.Look(ref showFaction, "showFaction", true);
Scribe_Values.Look(ref showIdeo, "showIdeo", true);
base.ExposeData();
}
}
Expand Down

0 comments on commit e792029

Please sign in to comment.