protected void ShowChildDialogForGroup(CustomParentChildGroup group, CustomParentChildPawn selected, Action <CustomParentChildPawn> action)
        {
            CustomParentChildPawn           selectedPawn = selected;
            HashSet <CustomParentChildPawn> disabled     = new HashSet <CustomParentChildPawn>();

            if (group != null)
            {
                disabled.AddRange(group.Parents);
                disabled.AddRange(group.Children);
            }
            rowGroups.Clear();
            rowGroups.Add(new WidgetTable <CustomParentChildPawn> .RowGroup("EdB.PC.AddParentChild.Header.SelectColonist".Translate(), PrepareCarefully.Instance.RelationshipManager.ColonyPawns));
            rowGroups.Add(new WidgetTable <CustomParentChildPawn> .RowGroup("EdB.PC.AddParentChild.Header.SelectHidden".Translate(), PrepareCarefully.Instance.RelationshipManager.HiddenPawns));
            WidgetTable <CustomParentChildPawn> .RowGroup newPawnGroup = new WidgetTable <CustomParentChildPawn> .RowGroup(null, newPawns);

            rowGroups.Add(newPawnGroup);
            DialogSelectParentChildPawn pawnDialog = new DialogSelectParentChildPawn()
            {
                HeaderLabel       = "EdB.PC.AddParentChild.Header.AddChild".Translate(),
                SelectAction      = (CustomParentChildPawn pawn) => { selectedPawn = pawn; },
                RowGroups         = rowGroups,
                DisabledPawns     = disabled,
                ConfirmValidation = () => {
                    if (selectedPawn == null)
                    {
                        return("EdB.PC.AddParentChild.Error.ChildRequired");
                    }
                    else
                    {
                        return(null);
                    }
                },
                CloseAction = () => {
                    // If the user selected a new pawn, replace the pawn in the new pawn list with another one.
                    int index = newPawnGroup.Rows.FirstIndexOf((CustomParentChildPawn p) => {
                        return(p == selectedPawn);
                    });
                    if (index > -1 && index < newPawns.Count)
                    {
                        selectedPawn = ReplaceNewHiddenCharacter(index);
                    }
                    action(selectedPawn);
                }
            };

            Find.WindowStack.Add(pawnDialog);
        }
        protected void ShowAddRelationshipDialogs()
        {
            CustomPawn      sourceParentChildPawn = null;
            PawnRelationDef selectedRelationship  = null;
            CustomPawn      targetParentChildPawn = null;

            Dialog_Options <PawnRelationDef> relationshipDialog =
                new Dialog_Options <PawnRelationDef>(null)
            {
                ConfirmButtonLabel = "EdB.PC.Common.Next".Translate(),
                CancelButtonLabel  = "EdB.PC.Common.Cancel".Translate(),
                HeaderLabel        = "EdB.PC.AddRelationship.Header.Relationship".Translate(),
                NameFunc           = (PawnRelationDef def) => {
                    return(def.GetGenderSpecificLabelCap(sourceParentChildPawn.Pawn));
                },
                SelectedFunc = (PawnRelationDef def) => {
                    return(def == selectedRelationship);
                },
                SelectAction = (PawnRelationDef def) => {
                    selectedRelationship = def;
                },
                EnabledFunc = (PawnRelationDef d) => {
                    return(!disabledRelationships.Contains(d));
                },
                ConfirmValidation = () => {
                    if (selectedRelationship == null)
                    {
                        return("EdB.PC.AddRelationship.Error.RelationshipRequired");
                    }
                    else
                    {
                        return(null);
                    }
                }
            };

            List <WidgetTable <CustomPawn> .RowGroup> sourceRowGroups = new List <WidgetTable <CustomPawn> .RowGroup>();

            sourceRowGroups.Add(new WidgetTable <CustomPawn> .RowGroup("EdB.PC.AddParentChild.Header.SelectColonist".Translate(),
                                                                       PrepareCarefully.Instance.RelationshipManager.ColonyAndWorldPawns.Where((CustomPawn pawn) => {
                return(pawn.Type == CustomPawnType.Colonist);
            })));
            List <CustomPawn> hiddenPawnsForSource = PrepareCarefully.Instance.RelationshipManager.HiddenPawns.ToList();

            hiddenPawnsForSource.Sort((a, b) => {
                if (a.Type != b.Type)
                {
                    return(a.Type == CustomPawnType.Hidden ? -1 : 1);
                }
                else
                {
                    int aInt = a.Index == null ? 0 : a.Index.Value;
                    int bInt = b.Index == null ? 0 : b.Index.Value;
                    return(aInt.CompareTo(bInt));
                }
            });
            sourceRowGroups.Add(new WidgetTable <CustomPawn> .RowGroup("<b>" + "EdB.PC.AddParentChild.Header.SelectWorldPawn".Translate() + "</b>",
                                                                       PrepareCarefully.Instance.RelationshipManager.ColonyAndWorldPawns.Where((CustomPawn pawn) => {
                return(pawn.Type != CustomPawnType.Colonist);
            }).Concat(hiddenPawnsForSource)));
            WidgetTable <CustomPawn> .RowGroup sourceNewPawnGroup = new WidgetTable <CustomPawn> .RowGroup("EdB.PC.AddParentChild.Header.CreateTemporaryPawn".Translate(), PrepareCarefully.Instance.RelationshipManager.TemporaryPawns);

            sourceRowGroups.Add(sourceNewPawnGroup);

            DialogSelectParentChildPawn sourcePawnDialog = new DialogSelectParentChildPawn()
            {
                HeaderLabel       = "EdB.PC.AddRelationship.Header.Source".Translate(),
                SelectAction      = (CustomPawn pawn) => { sourceParentChildPawn = pawn; },
                RowGroups         = sourceRowGroups,
                DisabledPawns     = null,
                ConfirmValidation = () => {
                    if (sourceParentChildPawn == null)
                    {
                        return("EdB.PC.AddRelationship.Error.SourceRequired");
                    }
                    else
                    {
                        return(null);
                    }
                },
                CloseAction = () => {
                    // If the user selected a new pawn, replace the pawn in the new pawn list with another one.
                    int index = sourceNewPawnGroup.Rows.FirstIndexOf((CustomPawn p) => {
                        return(p == targetParentChildPawn);
                    });
                    if (index > -1 && index < PrepareCarefully.Instance.RelationshipManager.TemporaryPawns.Count)
                    {
                        targetParentChildPawn = PrepareCarefully.Instance.RelationshipManager.ReplaceNewTemporaryCharacter(index);
                    }
                }
            };

            DialogSelectParentChildPawn targetPawnDialog = new DialogSelectParentChildPawn()
            {
                HeaderLabel       = "EdB.PC.AddRelationship.Header.Target".Translate(),
                SelectAction      = (CustomPawn pawn) => { targetParentChildPawn = pawn; },
                RowGroups         = null, // To be filled out later
                DisabledPawns     = null, // To be filled out later
                ConfirmValidation = () => {
                    if (sourceParentChildPawn == null)
                    {
                        return("EdB.PC.AddRelationship.Error.TargetRequired");
                    }
                    else
                    {
                        return(null);
                    }
                }
            };

            WidgetTable <CustomPawn> .RowGroup targetNewPawnGroup = null;

            sourcePawnDialog.CloseAction = () => {
                List <PawnRelationDef> relationDefs = PrepareCarefully.Instance.RelationshipManager.AllowedRelationships.Select((PawnRelationDef def) => {
                    return(def);
                }).ToList();
                relationDefs.Sort((PawnRelationDef a, PawnRelationDef b) => {
                    return(a.GetGenderSpecificLabelCap(sourceParentChildPawn.Pawn).CompareTo(b.GetGenderSpecificLabelCap(sourceParentChildPawn.Pawn)));
                });
                relationshipDialog.Options = relationDefs;
                Find.WindowStack.Add(relationshipDialog);
            };
            relationshipDialog.CloseAction = () => {
                SetDisabledTargets(sourceParentChildPawn, selectedRelationship);
                targetPawnDialog.DisabledPawns = disabledTargets;

                List <WidgetTable <CustomPawn> .RowGroup> targetRowGroups = new List <WidgetTable <CustomPawn> .RowGroup>();
                targetRowGroups.Add(new WidgetTable <CustomPawn> .RowGroup("EdB.PC.AddParentChild.Header.SelectColonist".Translate(),
                                                                           PrepareCarefully.Instance.RelationshipManager.ColonyAndWorldPawns.Where((CustomPawn pawn) => {
                    return(pawn.Type == CustomPawnType.Colonist && pawn != sourceParentChildPawn);
                })));
                List <CustomPawn> hiddenPawnsForTarget = PrepareCarefully.Instance.RelationshipManager.HiddenPawns.ToList();
                hiddenPawnsForTarget.Sort((a, b) => {
                    if (a.Type != b.Type)
                    {
                        return(a.Type == CustomPawnType.Hidden ? -1 : 1);
                    }
                    else
                    {
                        int aInt = a.Index == null ? 0 : a.Index.Value;
                        int bInt = b.Index == null ? 0 : b.Index.Value;
                        return(aInt.CompareTo(bInt));
                    }
                });
                targetRowGroups.Add(new WidgetTable <CustomPawn> .RowGroup("<b>" + "EdB.PC.AddParentChild.Header.SelectWorldPawn".Translate() + "</b>",
                                                                           PrepareCarefully.Instance.RelationshipManager.ColonyAndWorldPawns.Where((CustomPawn pawn) => {
                    return(pawn.Type != CustomPawnType.Colonist && pawn != sourceParentChildPawn);
                }).Concat(hiddenPawnsForTarget)));
                targetNewPawnGroup = new WidgetTable <CustomPawn> .RowGroup("EdB.PC.AddParentChild.Header.CreateTemporaryPawn".Translate(), PrepareCarefully.Instance.RelationshipManager.TemporaryPawns);

                targetRowGroups.Add(targetNewPawnGroup);
                targetPawnDialog.RowGroups = targetRowGroups;

                Find.WindowStack.Add(targetPawnDialog);
            };
            targetPawnDialog.CloseAction = () => {
                // If the user selected a new pawn, replace the pawn in the new pawn list with another one.
                int index = targetNewPawnGroup.Rows.FirstIndexOf((CustomPawn p) => {
                    return(p == targetParentChildPawn);
                });
                if (index > -1 && index < PrepareCarefully.Instance.RelationshipManager.TemporaryPawns.Count)
                {
                    targetParentChildPawn = PrepareCarefully.Instance.RelationshipManager.ReplaceNewTemporaryCharacter(index);
                }
                this.RelationshipAdded(PrepareCarefully.Instance.RelationshipManager.FindInverseRelationship(selectedRelationship), sourceParentChildPawn, targetParentChildPawn);
            };
            Find.WindowStack.Add(sourcePawnDialog);
        }
        protected void ShowChildDialogForGroup(ParentChildGroup group, CustomPawn selected, Action <CustomPawn> action)
        {
            CustomPawn           selectedPawn = selected;
            HashSet <CustomPawn> disabled     = new HashSet <CustomPawn>();

            if (group != null)
            {
                disabled.AddRange(group.Parents);
                disabled.AddRange(group.Children);
            }
            rowGroups.Clear();
            rowGroups.Add(new WidgetTable <CustomPawn> .RowGroup("<b>" + "EdB.PC.AddParentChild.Header.SelectColonist".Translate() + "</b>",
                                                                 PrepareCarefully.Instance.RelationshipManager.ColonyAndWorldPawns.Where((CustomPawn pawn) => {
                return(pawn.Type == CustomPawnType.Colonist);
            })));
            List <CustomPawn> sortedHiddenPawns = PrepareCarefully.Instance.RelationshipManager.HiddenPawns.ToList();

            sortedHiddenPawns.Sort((a, b) => {
                if (a.Type != b.Type)
                {
                    return(a.Type == CustomPawnType.Hidden ? -1 : 1);
                }
                else
                {
                    int aInt = a.Index == null ? 0 : a.Index.Value;
                    int bInt = b.Index == null ? 0 : b.Index.Value;
                    return(aInt.CompareTo(bInt));
                }
            });
            rowGroups.Add(new WidgetTable <CustomPawn> .RowGroup("<b>" + "EdB.PC.AddParentChild.Header.SelectWorldPawn".Translate() + "</b>",
                                                                 PrepareCarefully.Instance.RelationshipManager.ColonyAndWorldPawns.Where((CustomPawn pawn) => {
                return(pawn.Type != CustomPawnType.Colonist);
            }).Concat(sortedHiddenPawns)));
            WidgetTable <CustomPawn> .RowGroup newPawnGroup = new WidgetTable <CustomPawn> .RowGroup("EdB.PC.AddParentChild.Header.CreateTemporaryPawn".Translate(), PrepareCarefully.Instance.RelationshipManager.TemporaryPawns);

            rowGroups.Add(newPawnGroup);
            DialogSelectParentChildPawn pawnDialog = new DialogSelectParentChildPawn()
            {
                HeaderLabel       = "EdB.PC.AddParentChild.Header.AddChild".Translate(),
                SelectAction      = (CustomPawn pawn) => { selectedPawn = pawn; },
                RowGroups         = rowGroups,
                DisabledPawns     = disabled,
                ConfirmValidation = () => {
                    if (selectedPawn == null)
                    {
                        return("EdB.PC.AddParentChild.Error.ChildRequired");
                    }
                    else
                    {
                        return(null);
                    }
                },
                CloseAction = () => {
                    // If the user selected a new pawn, replace the pawn in the new pawn list with another one.
                    int index = newPawnGroup.Rows.FirstIndexOf((CustomPawn p) => {
                        return(p == selectedPawn);
                    });
                    if (index > -1 && index < PrepareCarefully.Instance.RelationshipManager.TemporaryPawns.Count)
                    {
                        selectedPawn = PrepareCarefully.Instance.RelationshipManager.ReplaceNewTemporaryCharacter(index);
                    }
                    action(selectedPawn);
                }
            };

            Find.WindowStack.Add(pawnDialog);
        }