diff --git a/Assemblies/PawnEditor.dll b/Assemblies/PawnEditor.dll index bbca47b..f00e5b8 100644 Binary files a/Assemblies/PawnEditor.dll and b/Assemblies/PawnEditor.dll differ diff --git a/Source/PawnEditor/Tabs/Humanlike/Bio/Randomization.cs b/Source/PawnEditor/Tabs/Humanlike/Bio/Randomization.cs index 4bd87d6..eb49389 100644 --- a/Source/PawnEditor/Tabs/Humanlike/Bio/Randomization.cs +++ b/Source/PawnEditor/Tabs/Humanlike/Bio/Randomization.cs @@ -10,41 +10,30 @@ public partial class TabWorker_Bio_Humanlike { public override IEnumerable GetRandomizationOptions(Pawn pawn) { - // yield return new("PawnEditor.All".Translate(), () => RandomizeAll(pawn)); + yield return new("PawnEditor.All".Translate(), () => RandomizeAll(pawn)); yield return new("Appearance".Translate(), () => RandomizeAppearance(pawn)); - yield return new("PawnEditor.Shape".Translate(), () => RandomizeShape(pawn)); + // yield return new("PawnEditor.Shape".Translate(), () => RandomizeShape(pawn)); yield return new("Relations".Translate(), () => RandomizeRelations(pawn)); yield return new("Traits".Translate(), () => RandomizeTraits(pawn)); yield return new("Skills".Translate(), () => RandomizeSkills(pawn)); } - private static void RandomizeAll(Pawn pawn) + public static void RandomizeAll(Pawn pawn) { - // RandomizeAppearance(pawn); - // RandomizeTraits(pawn); - // RandomizeRelations(pawn); - // RandomizeSkills(pawn); - - var req = new PawnGenerationRequest(pawn.kindDef, pawn.Faction); - var newPawn = PawnGenerator.GeneratePawn(req); - - pawn.skills = newPawn.skills; - pawn.story = newPawn.story; - pawn.relations = newPawn.relations; - pawn.abilities = newPawn.abilities; - pawn.style = newPawn.style; - pawn.apparel = newPawn.apparel; - pawn.inventory = newPawn.inventory; - pawn.equipment = newPawn.equipment; - pawn.health = newPawn.health; - pawn.mindState = newPawn.mindState; - pawn.ageTracker = newPawn.ageTracker; - pawn.gender = newPawn.gender; - pawn.royalty = newPawn.royalty; - pawn.genes = newPawn.genes; - pawn.ideo = newPawn.ideo; - pawn.Name = newPawn.Name; - + // Delete + var oldPawn = pawn; + var position = oldPawn.Position; + var map = oldPawn.Map; + PawnEditor.PawnList.OnDelete(oldPawn); + // Replace + pawn = PawnGenerator.GeneratePawn(new PawnGenerationRequest(pawn.kindDef, PawnEditor.selectedFaction)); + PawnEditor.AddPawn(pawn, PawnEditor.selectedCategory).HandleResult(); + if (!PawnEditor.Pregame && map != null) + { + GenSpawn.Spawn(pawn, position, map); + PawnEditor.PawnList.UpdateCache(PawnEditor.selectedFaction, PawnEditor.selectedCategory); + } + TabWorker_FactionOverview.RecachePawns(PawnEditor.selectedFaction); } public static void RandomizeAppearance(Pawn pawn) @@ -74,23 +63,7 @@ public static void RandomizeAppearance(Pawn pawn) public static void RandomizeShape(Pawn pawn) { - var bodyTypes = DefDatabase.AllDefs - .Where(bodyType => - pawn.DevelopmentalStage switch - { - DevelopmentalStage.Baby or DevelopmentalStage.Newborn => bodyType == BodyTypeDefOf.Baby, - DevelopmentalStage.Child => bodyType == BodyTypeDefOf.Child, - DevelopmentalStage.Adult => bodyType != BodyTypeDefOf.Baby && bodyType != BodyTypeDefOf.Child, - _ => true - }); - - if (HARCompat.Active) - { - var allowedBodyTypes = HARCompat.AllowedBodyTypes(pawn); - if (!allowedBodyTypes.NullOrEmpty()) bodyTypes = bodyTypes.Intersect(allowedBodyTypes); - } - - var headTypes = DefDatabase.AllDefs; + var headTypes = DefDatabase.AllDefs.Where(h => h.gender != pawn.gender.Opposite() && h.randomChosen); if (HARCompat.Active) { headTypes = HARCompat.FilterHeadTypes(headTypes, pawn); @@ -98,7 +71,7 @@ public static void RandomizeShape(Pawn pawn) headTypes = headTypes.Where(type => type.gender == Gender.None || type.gender == pawn.gender); } - pawn.story.bodyType = bodyTypes.RandomElement(); + pawn.story.bodyType = PawnGenerator.GetBodyTypeFor(pawn); pawn.story.headType = headTypes.RandomElement(); pawn.drawer.renderer.SetAllGraphicsDirty(); diff --git a/Source/PawnEditor/UI/LeftPanel.cs b/Source/PawnEditor/UI/LeftPanel.cs index 5ab313f..04d4c8c 100644 --- a/Source/PawnEditor/UI/LeftPanel.cs +++ b/Source/PawnEditor/UI/LeftPanel.cs @@ -229,7 +229,7 @@ AddResult AddPawnKind(PawnKindDef pawnKind) => Find.WindowStack.Add(new FloatMenu(list)); } - private static AddResult AddPawn(Pawn addedPawn, PawnCategory category) + public static AddResult AddPawn(Pawn addedPawn, PawnCategory category) { return new ConditionalInfo(CanUsePoints(addedPawn), new SuccessInfo(() => { diff --git a/Source/PawnEditor/UI/PawnEditorUI.cs b/Source/PawnEditor/UI/PawnEditorUI.cs index e9d18f7..4d8091d 100644 --- a/Source/PawnEditor/UI/PawnEditorUI.cs +++ b/Source/PawnEditor/UI/PawnEditorUI.cs @@ -16,10 +16,10 @@ public static partial class PawnEditor public static bool RenderHeadgear = true; private static bool usePointLimit; private static float remainingPoints; - private static Faction selectedFaction; + public static Faction selectedFaction; private static Pawn selectedPawn; private static bool showFactionInfo; - private static PawnCategory selectedCategory; + public static PawnCategory selectedCategory; private static float cachedValue; private static FloatMenuOption lastRandomization; private static TabGroupDef tabGroup; @@ -134,40 +134,17 @@ public static void DoBottomButtons(Rect inRect, Action onLeftButton, Action onRi var randomRect = new Rect(Vector2.zero, Page.BottomButSize).CenteredOnXIn(inRect).CenteredOnYIn(inRect); var buttonRect = new Rect(randomRect); - + var options = GetRandomizationOptions().ToList(); if (lastRandomization != null && Widgets.ButtonImageWithBG(randomRect.TakeRightPart(20), TexUI.RotRightTex, new Vector2(12, 12))) { + var label = lastRandomization.Label.ToLower(); + lastRandomization = options.First(op => op.Label.Contains(label)); lastRandomization.action(); randomRect.TakeRightPart(1); } if (Widgets.ButtonText(randomRect, "Randomize".Translate())) { - var options = GetRandomizationOptions().ToList(); - if (!showFactionInfo && selectedPawn.RaceProps.Humanlike) - { - options.Insert(0, new FloatMenuOption("Randomize".Translate() + " " + "PawnEditor.All".Translate().ToLower(), () => - { - // List, for updating left panel - var (pawns, _, _) = PawnList.GetLists(); - // Copy values - var map = selectedPawn.Map; - var position = selectedPawn.Position; - var req = new PawnGenerationRequest(selectedPawn.kindDef, selectedPawn.Faction); - var index = pawns.IndexOf(selectedPawn); - // Delete - DeletePawn(selectedPawn, pawns); - TabWorker_FactionOverview.RecachePawns(selectedFaction); - PawnLister.FullyRemove(selectedPawn); - selectedPawn.Destroy(); - // Replace - selectedPawn = PawnGenerator.GeneratePawn(req); - GenSpawn.Spawn(selectedPawn, position, map); - pawns.Insert(index, selectedPawn); - Select(selectedPawn); - })); - } - if (options.Count > 0) Find.WindowStack.Add(new FloatMenu(options)); else