Esempio n. 1
0
 protected void PopulateBackstoriesFromSlot(CustomPawn pawn, BackstorySlot slot, out List <Backstory> backstories,
                                            out Backstory backstory)
 {
     backstory   = (slot == BackstorySlot.Childhood) ? pawn.Childhood : pawn.Adulthood;
     backstories = (slot == BackstorySlot.Childhood) ? providerBackstories.GetChildhoodBackstoriesForPawn(pawn)
         : providerBackstories.GetAdulthoodBackstoriesForPawn(pawn);
 }
Esempio n. 2
0
        protected void ShowBackstoryDialog(CustomPawn customPawn, BackstorySlot slot)
        {
            Backstory originalBackstory       = (slot == BackstorySlot.Childhood) ? customPawn.Childhood : customPawn.Adulthood;
            Backstory selectedBackstory       = originalBackstory;
            Dialog_Options <Backstory> dialog = new Dialog_Options <Backstory>(slot == BackstorySlot.Childhood ?
                                                                               this.providerBackstories.ChildhoodBackstories
                    : this.providerBackstories.AdulthoodBackstories)
            {
                NameFunc = (Backstory backstory) => {
                    return(backstory.Title);
                },
                DescriptionFunc = (Backstory backstory) => {
                    return(backstory.FullDescriptionFor(customPawn.Pawn));
                },
                SelectedFunc = (Backstory backstory) => {
                    return(selectedBackstory == backstory);
                },
                SelectAction = (Backstory backstory) => {
                    selectedBackstory = backstory;
                },
                CloseAction = () => {
                    if (slot == BackstorySlot.Childhood)
                    {
                        BackstoryUpdated(BackstorySlot.Childhood, selectedBackstory);
                    }
                    else
                    {
                        BackstoryUpdated(BackstorySlot.Adulthood, selectedBackstory);
                    }
                }
            };

            Find.WindowStack.Add(dialog);
        }
 public static void ShuffleableBackstoryList(BackstorySlot slot, List <string> tags, List <Backstory> outBackstories)
 {
     outBackstories.Clear();
     if (tags.Count == 0)
     {
         return;
     }
     if (tags.Count == 1)
     {
         outBackstories.AddRange(BackstoryDatabase.ShuffleableBackstoryList(slot, tags[0]));
         return;
     }
     BackstoryDatabase.tmpUniqueBackstories.Clear();
     for (int i = 0; i < tags.Count; i++)
     {
         List <Backstory> list = BackstoryDatabase.ShuffleableBackstoryList(slot, tags[i]);
         for (int j = 0; j < list.Count; j++)
         {
             BackstoryDatabase.tmpUniqueBackstories.Add(list[j]);
         }
     }
     foreach (Backstory current in BackstoryDatabase.tmpUniqueBackstories)
     {
         outBackstories.Add(current);
     }
     BackstoryDatabase.tmpUniqueBackstories.Clear();
 }
Esempio n. 4
0
 public static void ShuffleableBackstoryList(BackstorySlot slot, List <string> tags, List <Backstory> outBackstories)
 {
     outBackstories.Clear();
     if (tags.Count != 0)
     {
         if (tags.Count == 1)
         {
             outBackstories.AddRange(ShuffleableBackstoryList(slot, tags[0]));
         }
         else
         {
             tmpUniqueBackstories.Clear();
             for (int i = 0; i < tags.Count; i++)
             {
                 List <Backstory> list = ShuffleableBackstoryList(slot, tags[i]);
                 for (int j = 0; j < list.Count; j++)
                 {
                     tmpUniqueBackstories.Add(list[j]);
                 }
             }
             foreach (Backstory tmpUniqueBackstory in tmpUniqueBackstories)
             {
                 outBackstories.Add(tmpUniqueBackstory);
             }
             tmpUniqueBackstories.Clear();
         }
     }
 }
        private static void FillBackstorySlotShuffled(Pawn pawn, BackstorySlot slot, ref Backstory backstory, List <string> backstoryCategories, FactionDef factionType)
        {
            AM_PawnBioAndNameGenerator_GiveShuffledBioTo_AdultAge_Patch.tmpBackstories.Clear();
            BackstoryDatabase.ShuffleableBackstoryList(slot, backstoryCategories, AM_PawnBioAndNameGenerator_GiveShuffledBioTo_AdultAge_Patch.tmpBackstories);
            IEnumerable <Backstory> source = from bs in AM_PawnBioAndNameGenerator_GiveShuffledBioTo_AdultAge_Patch.tmpBackstories.TakeRandom(20)
                                             where slot != BackstorySlot.Adulthood || !bs.requiredWorkTags.OverlapsWithOnAnyWorkType(pawn.story.childhood.workDisables)
                                             select bs;

            if (AM_PawnBioAndNameGenerator_GiveShuffledBioTo_AdultAge_Patch.funcA == null)
            {
                AM_PawnBioAndNameGenerator_GiveShuffledBioTo_AdultAge_Patch.funcA = new Func <Backstory, float>(AM_PawnBioAndNameGenerator_GiveShuffledBioTo_AdultAge_Patch.BackstorySelectionWeight);
            }
            if (!source.TryRandomElementByWeight(AM_PawnBioAndNameGenerator_GiveShuffledBioTo_AdultAge_Patch.funcA, out backstory))
            {
                Log.Error(string.Concat(new object[]
                {
                    "No shuffled ",
                    slot,
                    " found for ",
                    pawn.ToStringSafe <Pawn>(),
                    " of ",
                    factionType.ToStringSafe <FactionDef>(),
                    ". Defaulting."
                }), false);
                backstory = (from kvp in BackstoryDatabase.allBackstories
                             where kvp.Value.slot == slot
                             select kvp).RandomElement <KeyValuePair <string, Backstory> >().Value;
            }
            AM_PawnBioAndNameGenerator_GiveShuffledBioTo_AdultAge_Patch.tmpBackstories.Clear();
        }
 public Backstory GetBackstory(BackstorySlot slot)
 {
     if (slot == BackstorySlot.Childhood)
     {
         return(this.childhood);
     }
     return(this.adulthood);
 }
Esempio n. 7
0
        protected int FindBackstoryIndex(CustomPawn pawn, BackstorySlot slot)
        {
            Backstory        backstory;
            List <Backstory> backstories;

            PopulateBackstoriesFromSlot(pawn, slot, out backstories, out backstory);
            return(backstories.IndexOf(backstory));
        }
Esempio n. 8
0
 public static void FillBackstorySlotShuffled(Verse.Pawn pawn, BackstorySlot slot, ref Backstory backstory, Backstory backstoryOtherSlot, List <BackstoryCategoryFilter> backstoryCategories, FactionDef factionType)
 {
     ReflectionCache.Instance.PawnBioAndNameGenerator_FillBackstorySlotShuffled.Invoke(null,
                                                                                       new object[] {
         pawn, slot, backstory, backstoryOtherSlot, backstoryCategories, factionType
     }
                                                                                       );
 }
Esempio n. 9
0
        public static List <Backstory> ShuffleableBackstoryList(BackstorySlot slot, BackstoryCategoryFilter group)
        {
            Pair <BackstorySlot, BackstoryCategoryFilter> key = new Pair <BackstorySlot, BackstoryCategoryFilter>(slot, group);

            if (!shuffleableBackstoryList.ContainsKey(key))
            {
                shuffleableBackstoryList[key] = allBackstories.Values.Where((Backstory bs) => bs.shuffleable && bs.slot == slot && group.Matches(bs)).ToList();
            }
            return(shuffleableBackstoryList[key]);
        }
Esempio n. 10
0
 private static void SetBackstoryInSlot(Pawn pawn, BackstorySlot slot, ref Backstory backstory, PawnKindDef pawntype)
 {
     if (!(from kvp in BackstoryDatabase.allBackstories
           where kvp.Value.shuffleable && kvp.Value.spawnCategories.Contains(pawntype.backstoryCategory) && kvp.Value.slot == slot
           select kvp.Value).TryRandomElement(out backstory))
     {
         backstory = (from kvp in BackstoryDatabase.allBackstories
                      where kvp.Value.slot == slot
                      select kvp).RandomElement <KeyValuePair <string, Backstory> >().Value;
     }
 }
Esempio n. 11
0
 // Backstory-related actions.
 public void UpdateBackstory(BackstorySlot slot, Backstory backstory)
 {
     if (slot == BackstorySlot.Childhood)
     {
         state.CurrentPawn.Childhood = backstory;
     }
     else if (slot == BackstorySlot.Adulthood)
     {
         state.CurrentPawn.Adulthood = backstory;
     }
 }
        public static bool Prefix(Pawn pawn, BackstorySlot slot, ref Backstory backstory, Backstory backstoryOtherSlot, List <BackstoryCategoryFilter> backstoryCategories, FactionDef factionType)
        {
            bool act = pawn.def.modContentPack != null && pawn.def.modContentPack.Name.Contains("Adeptus Mechanicus");

            if (act || pawn.def.defName.StartsWith("OG_") || pawn.kindDef.defName.StartsWith("OG_") || pawn.kindDef.defName.Contains("_OG_"))
            {
                FillBackstorySlotShuffled(pawn, slot, ref backstory, backstoryOtherSlot, backstoryCategories, factionType);
                return(false);
            }
            return(true);
        }
Esempio n. 13
0
        public static List <Backstory> ShuffleableBackstoryList(BackstorySlot slot, string tag)
        {
            Pair <BackstorySlot, string> key = new Pair <BackstorySlot, string>(slot, tag);

            if (!BackstoryDatabase.shuffleableBackstoryList.ContainsKey(key))
            {
                BackstoryDatabase.shuffleableBackstoryList[key] = (from bs in BackstoryDatabase.allBackstories.Values
                                                                   where bs.shuffleable && bs.slot == slot && bs.spawnCategories.Contains(tag)
                                                                   select bs).ToList <Backstory>();
            }
            return(BackstoryDatabase.shuffleableBackstoryList[key]);
        }
        public Backstory GetBackstory(BackstorySlot slot)
        {
            Backstory result;

            if (slot == BackstorySlot.Childhood)
            {
                result = this.childhood;
            }
            else
            {
                result = this.adulthood;
            }
            return(result);
        }
Esempio n. 15
0
 public BackstoryStats(Backstory b)
 {
     this.backstory        = b;
     this.identifier       = b.identifier;
     this.shuffleable      = b.shuffleable;
     this.slot             = b.slot;
     this.workDisables     = b.workDisables;
     this.requiredWorkTags = b.requiredWorkTags;
     Util.AssignDefStat(GetBodyTypeGlobal(b), out this.bodyTypeGlobal);
     Util.AssignDefStat(GetBodyTypeMale(b), out this.bodyTypeMale);
     Util.AssignDefStat(GetBodyTypeFemale(b), out this.bodyTypeFemale);
     Util.Populate(out this.skillGains, b.skillGainsResolved, v => new IntValueDefStat <SkillDef>(v.Key, v.Value));
     Util.Populate(out this.forcedTraits, b.forcedTraits, v => new IntValueDefStat <TraitDef>(v.def, v.degree));
     Util.Populate(out this.disallowedTraits, b.disallowedTraits, v => new IntValueDefStat <TraitDef>(v.def, v.degree));
     Util.Populate(out this.spawnCategories, b.spawnCategories);
 }
        private static void FillBackstorySlotShuffled(Pawn pawn, BackstorySlot slot, ref Backstory backstory, Backstory backstoryOtherSlot, List <BackstoryCategoryFilter> backstoryCategories, FactionDef factionType)
        {
            BackstoryCategoryFilter backstoryCategoryFilter = backstoryCategories.RandomElementByWeight((BackstoryCategoryFilter c) => c.commonality);

            if (backstoryCategoryFilter == null)
            {
                backstoryCategoryFilter = FallbackCategoryGroup;
            }
            if (!(from bs in BackstoryDatabase.ShuffleableBackstoryList(slot, backstoryCategoryFilter).TakeRandom(20)
                  where (slot != BackstorySlot.Adulthood || !bs.requiredWorkTags.OverlapsWithOnAnyWorkType(pawn.story.childhood.workDisables)) ? true : false
                  select bs).TryRandomElementByWeight(BackstorySelectionWeight, out backstory))
            {
                Log.Error(string.Concat("No shuffled ", slot, " found for ", pawn.ToStringSafe(), " of ", factionType.ToStringSafe(), ". Choosing random."));
                backstory = BackstoryDatabase.allBackstories.Where((KeyValuePair <string, Backstory> kvp) => kvp.Value.slot == slot).RandomElement().Value;
            }
        }
Esempio n. 17
0
 public static bool FillBackstorySlotShuffled(Pawn pawn, BackstorySlot slot, ref Backstory backstory, Backstory backstoryOtherSlot, List <BackstoryCategoryFilter> backstoryCategories, FactionDef factionType)
 {
     if (pawn.def.defName.StartsWith("OG_"))
     {
         //    Log.Message(pawn.NameShortColored + " is " +pawn.def + " in " + pawn.Faction);
         BackstoryCategoryFilter backstoryCategoryFilter = backstoryCategories.RandomElementByWeight((BackstoryCategoryFilter c) => c.commonality);
         if (backstoryCategoryFilter == null)
         {
             //    Log.Message(pawn.def + " in " + pawn.Faction + " backstoryCategoryFilter == null");
             backstoryCategoryFilter = FallbackCategoryGroup;
             //    Log.Message(pawn.def + " in " + pawn.Faction + " backstoryCategoryFilter == " + backstoryCategoryFilter);
         }
         List <string> lista = new List <string>();
         foreach (BackstoryCategoryFilter filter in backstoryCategories)
         {
             foreach (string str in filter.categories)
             {
                 if (!lista.Contains(str))
                 {
                     lista.Add(str);
                 }
             }
         }
         if (!(from bs in BackstoryDatabase.ShuffleableBackstoryList(slot, backstoryCategoryFilter).TakeRandom(20)
               where slot != BackstorySlot.Adulthood || !bs.requiredWorkTags.OverlapsWithOnAnyWorkType(pawn.story.childhood.workDisables)
               select bs).TryRandomElementByWeight(new Func <Backstory, float>(BackstorySelectionWeight), out backstory))
         {
             //    Log.Message(string.Format("backstoryCategories: {0}, used backstoryCategoryFilter: {1}", lista.ToCommaList(), backstoryCategoryFilter.categories.ToCommaList()));
             Log.Error(string.Concat(new object[]
                 {
                     "No shuffled ",
                     slot,
                     " found for ",
                     pawn.ToStringSafe <Pawn>(),
                     " of ",
                     factionType.ToStringSafe <FactionDef>(),
                     ". Choosing random."
                 }), false);
             backstory = (from kvp in BackstoryDatabase.allBackstories
                          where kvp.Value.slot == slot
                          select kvp).RandomElement <KeyValuePair <string, Backstory> >().Value;
         }
         return(false);
     }
     return(true);
 }
Esempio n. 18
0
 private static void FillBackstorySlotShuffled(Pawn pawn, BackstorySlot slot, ref Backstory backstory, List <string> backstoryCategories, FactionDef factionType)
 {
     tmpBackstories.Clear();
     BackstoryDatabase.ShuffleableBackstoryList(slot, backstoryCategories, tmpBackstories);
     if (!tmpBackstories.TakeRandom(20).Where(delegate(Backstory bs)
     {
         if (slot == BackstorySlot.Adulthood && bs.requiredWorkTags.OverlapsWithOnAnyWorkType(pawn.story.childhood.workDisables))
         {
             return(false);
         }
         return(true);
     }).TryRandomElementByWeight(BackstorySelectionWeight, out backstory))
     {
         Log.Error("No shuffled " + slot + " found for " + pawn.ToStringSafe() + " of " + factionType.ToStringSafe() + ". Defaulting.");
         backstory = (from kvp in BackstoryDatabase.allBackstories
                      where kvp.Value.slot == slot
                      select kvp).RandomElement().Value;
     }
     tmpBackstories.Clear();
 }
Esempio n. 19
0
        protected void NextBackstory(CustomPawn pawn, BackstorySlot slot, int direction)
        {
            Backstory        backstory;
            List <Backstory> backstories;

            PopulateBackstoriesFromSlot(pawn, slot, out backstories, out backstory);

            int currentIndex = FindBackstoryIndex(pawn, slot);

            currentIndex += direction;
            if (currentIndex >= backstories.Count)
            {
                currentIndex = 0;
            }
            else if (currentIndex < 0)
            {
                currentIndex = backstories.Count - 1;
            }
            BackstoryUpdated(slot, backstories[currentIndex]);
        }
 private static void FillBackstorySlotShuffled(Pawn pawn, BackstorySlot slot, ref Backstory backstory, FactionDef factionType)
 {
     if (!(from kvp in BackstoryDatabase.allBackstories
           where kvp.Value.shuffleable && kvp.Value.spawnCategories.Contains(factionType.backstoryCategory) && kvp.Value.slot == slot && (slot != BackstorySlot.Adulthood || !kvp.Value.requiredWorkTags.OverlapsWithOnAnyWorkType(pawn.story.childhood.workDisables))
           select kvp.Value).TryRandomElementByWeight(new Func <Backstory, float>(PawnBioAndNameGenerator.BackstorySelectionWeight), out backstory))
     {
         Log.Error(string.Concat(new object[]
         {
             "No shuffled ",
             slot,
             " found for ",
             pawn,
             " of ",
             factionType,
             ". Defaulting."
         }));
         backstory = (from kvp in BackstoryDatabase.allBackstories
                      where kvp.Value.slot == slot
                      select kvp).RandomElement <KeyValuePair <string, Backstory> >().Value;
     }
 }
Esempio n. 21
0
 private static void FillBackstorySlotShuffled(Pawn pawn, BackstorySlot slot, ref Backstory backstory, FactionDef factionType)
 {
     if (!(from kvp in BackstoryDatabase.allBackstories.Where(delegate(KeyValuePair <string, Backstory> kvp)
     {
         if (kvp.Value.shuffleable && kvp.Value.spawnCategories.Contains(factionType.backstoryCategory) && kvp.Value.slot == slot)
         {
             if (slot == BackstorySlot.Adulthood && kvp.Value.requiredWorkTags.OverlapsWithOnAnyWorkType(pawn.story.childhood.workDisables))
             {
                 return(false);
             }
             return(true);
         }
         return(false);
     })
           select kvp.Value).TryRandomElementByWeight <Backstory>((Func <Backstory, float>)PawnBioAndNameGenerator.BackstorySelectionWeight, out backstory))
     {
         Log.Error("No shuffled " + slot + " found for " + pawn + " of " + factionType + ". Defaulting.");
         backstory = (from kvp in BackstoryDatabase.allBackstories
                      where kvp.Value.slot == slot
                      select kvp).RandomElement().Value;
     }
 }
Esempio n. 22
0
 static bool Prefix(Pawn pawn, BackstorySlot slot, ref Backstory backstory, List <string> backstoryCategories, FactionDef factionType)
 {
     if (!(from kvp in BackstoryDatabase.allBackstories
           where kvp.Value.shuffleable &&
           kvp.Value.spawnCategories.Intersect(factionType.backstoryCategories).Count() > 0 &&
           (!kvp.Value.spawnCategories.Contains("Uncommon") ||
            (kvp.Value.spawnCategories.Contains("Uncommon") && (Rand.Value < 0.333333))) &&
           (!kvp.Value.spawnCategories.Contains("Rare") ||
            (kvp.Value.spawnCategories.Contains("Rare") && (Rand.Value < 0.111111))) &&
           (!kvp.Value.spawnCategories.Contains("Legendary") ||
            (kvp.Value.spawnCategories.Contains("Legendary") && (Rand.Value < 0.037037))) &&
           (!kvp.Value.spawnCategories.Contains("AgeOver40") ||
            (kvp.Value.spawnCategories.Contains("AgeOver40") && pawn.ageTracker.AgeBiologicalYearsFloat > 40f)) &&
           (!kvp.Value.spawnCategories.Contains("AgeOver60") ||
            (kvp.Value.spawnCategories.Contains("AgeOver60") && pawn.ageTracker.AgeBiologicalYearsFloat > 60f)) &&
           (!kvp.Value.spawnCategories.Contains("AgeOver80") ||
            (kvp.Value.spawnCategories.Contains("AgeOver80") && pawn.ageTracker.AgeBiologicalYearsFloat > 80f)) &&
           (!kvp.Value.spawnCategories.Contains("Male") ||
            (kvp.Value.spawnCategories.Contains("Male") && pawn.gender == Gender.Male)) &&
           (!kvp.Value.spawnCategories.Contains("Female") ||
            (kvp.Value.spawnCategories.Contains("Female") && pawn.gender == Gender.Female)) &&
           kvp.Value.slot == slot &&
           (slot != BackstorySlot.Adulthood ||
            (!SkillGainsConflict(kvp.Value.skillGainsResolved, pawn.story.childhood.skillGainsResolved, kvp.Value.workDisables, pawn.story.childhood.workDisables, kvp.Value.forcedTraits, pawn.story.childhood.forcedTraits, kvp.Value.requiredWorkTags, pawn.story.childhood.requiredWorkTags) &&
             SameFilterSet(kvp.Value.spawnCategories, pawn.story.childhood.spawnCategories)))
           select kvp.Value).TryRandomElement(out backstory))
     {
         Log.Error(string.Concat(new object[] {
             "No shuffled ", slot, " found for ", pawn, " of ", factionType, ". Defaulting."
         }));
         backstory = (from kvp in BackstoryDatabase.allBackstories
                      where kvp.Value.slot == slot
                      select kvp).RandomElement <KeyValuePair <string, Backstory> >().Value;
     }
     return(false);
 }
        public static void DrawCharacterCard(Rect rect, Pawn pawn, Action randomizeCallback = null, Rect creationRect = default(Rect))
        {
            bool flag = randomizeCallback != null;

            GUI.BeginGroup((!flag) ? rect : creationRect);
            Rect       rect2      = new Rect(0f, 0f, 300f, 30f);
            NameTriple nameTriple = pawn.Name as NameTriple;

            if (flag && nameTriple != null)
            {
                Rect rect3 = new Rect(rect2);
                rect3.width *= 0.333f;
                Rect rect4 = new Rect(rect2);
                rect4.width *= 0.333f;
                rect4.x     += rect4.width;
                Rect rect5 = new Rect(rect2);
                rect5.width *= 0.333f;
                rect5.x     += rect4.width * 2f;
                string first = nameTriple.First;
                string nick  = nameTriple.Nick;
                string last  = nameTriple.Last;
                CharacterCardUtility.DoNameInputRect(rect3, ref first, 12);
                if (nameTriple.Nick == nameTriple.First || nameTriple.Nick == nameTriple.Last)
                {
                    GUI.color = new Color(1f, 1f, 1f, 0.5f);
                }
                CharacterCardUtility.DoNameInputRect(rect4, ref nick, 16);
                GUI.color = Color.white;
                CharacterCardUtility.DoNameInputRect(rect5, ref last, 12);
                if (nameTriple.First != first || nameTriple.Nick != nick || nameTriple.Last != last)
                {
                    pawn.Name = new NameTriple(first, nick, last);
                }
                TooltipHandler.TipRegion(rect3, "FirstNameDesc".Translate());
                TooltipHandler.TipRegion(rect4, "ShortIdentifierDesc".Translate());
                TooltipHandler.TipRegion(rect5, "LastNameDesc".Translate());
            }
            else
            {
                rect2.width = 999f;
                Text.Font   = GameFont.Medium;
                Widgets.Label(rect2, pawn.Name.ToStringFull);
                Text.Font = GameFont.Small;
            }
            if (randomizeCallback != null)
            {
                Rect rect6 = new Rect(creationRect.width - 24f - 100f, 0f, 100f, rect2.height);
                if (Widgets.ButtonText(rect6, "Randomize".Translate(), true, false, true))
                {
                    SoundDefOf.Tick_Tiny.PlayOneShotOnCamera(null);
                    randomizeCallback();
                }
                UIHighlighter.HighlightOpportunity(rect6, "RandomizePawn");
            }
            if (flag)
            {
                Widgets.InfoCardButton(creationRect.width - 24f, 0f, pawn);
            }
            else if (!pawn.health.Dead)
            {
                float num = CharacterCardUtility.PawnCardSize.x - 85f;
                if ((pawn.Faction == Faction.OfPlayer || pawn.IsPrisonerOfColony) && pawn.Spawned)
                {
                    Rect rect7 = new Rect(num, 0f, 30f, 30f);
                    TooltipHandler.TipRegion(rect7, PawnBanishUtility.GetBanishButtonTip(pawn));
                    if (Widgets.ButtonImage(rect7, TexButton.Banish))
                    {
                        if (pawn.Downed)
                        {
                            Messages.Message("MessageCantBanishDownedPawn".Translate(new object[]
                            {
                                pawn.LabelShort
                            }).AdjustedFor(pawn, "PAWN"), pawn, MessageTypeDefOf.RejectInput, false);
                        }
                        else
                        {
                            PawnBanishUtility.ShowBanishPawnConfirmationDialog(pawn);
                        }
                    }
                    num -= 40f;
                }
                if (pawn.IsColonist)
                {
                    Rect rect8 = new Rect(num, 0f, 30f, 30f);
                    TooltipHandler.TipRegion(rect8, "RenameColonist".Translate());
                    if (Widgets.ButtonImage(rect8, TexButton.Rename))
                    {
                        Find.WindowStack.Add(new Dialog_NamePawn(pawn));
                    }
                    num -= 40f;
                }
            }
            string label = pawn.MainDesc(true);
            Rect   rect9 = new Rect(0f, 45f, rect.width, 60f);

            Widgets.Label(rect9, label);
            TooltipHandler.TipRegion(rect9, () => pawn.ageTracker.AgeTooltipString, 6873641);
            Rect position  = new Rect(0f, 100f, 250f, 450f);
            Rect position2 = new Rect(position.xMax, 100f, 258f, 450f);

            GUI.BeginGroup(position);
            float num2 = 0f;

            Text.Font = GameFont.Medium;
            Widgets.Label(new Rect(0f, 0f, 200f, 30f), "Backstory".Translate());
            num2     += 30f;
            Text.Font = GameFont.Small;
            IEnumerator enumerator = Enum.GetValues(typeof(BackstorySlot)).GetEnumerator();

            try
            {
                while (enumerator.MoveNext())
                {
                    object        obj           = enumerator.Current;
                    BackstorySlot backstorySlot = (BackstorySlot)obj;
                    Backstory     backstory     = pawn.story.GetBackstory(backstorySlot);
                    if (backstory != null)
                    {
                        Rect rect10 = new Rect(0f, num2, position.width, 24f);
                        if (Mouse.IsOver(rect10))
                        {
                            Widgets.DrawHighlight(rect10);
                        }
                        TooltipHandler.TipRegion(rect10, backstory.FullDescriptionFor(pawn));
                        Text.Anchor = TextAnchor.MiddleLeft;
                        string str = (backstorySlot != BackstorySlot.Adulthood) ? "Childhood".Translate() : "Adulthood".Translate();
                        Widgets.Label(rect10, str + ":");
                        Text.Anchor = TextAnchor.UpperLeft;
                        Rect rect11 = new Rect(rect10);
                        rect11.x     += 90f;
                        rect11.width -= 90f;
                        string label2 = backstory.TitleCapFor(pawn.gender);
                        Widgets.Label(rect11, label2);
                        num2 += rect10.height + 2f;
                    }
                }
            }
            finally
            {
                IDisposable disposable;
                if ((disposable = (enumerator as IDisposable)) != null)
                {
                    disposable.Dispose();
                }
            }
            if (pawn.story != null && pawn.story.title != null)
            {
                Rect rect12 = new Rect(0f, num2, position.width, 24f);
                Text.Anchor = TextAnchor.MiddleLeft;
                Widgets.Label(rect12, "Current".Translate() + ":");
                Text.Anchor = TextAnchor.UpperLeft;
                Rect rect13 = new Rect(rect12);
                rect13.x     += 90f;
                rect13.width -= 90f;
                Widgets.Label(rect13, pawn.story.title);
                num2 += rect12.height + 2f;
            }
            num2     += 25f;
            Text.Font = GameFont.Medium;
            Widgets.Label(new Rect(0f, num2, 200f, 30f), "IncapableOf".Translate());
            num2     += 30f;
            Text.Font = GameFont.Small;
            StringBuilder stringBuilder            = new StringBuilder();
            WorkTags      combinedDisabledWorkTags = pawn.story.CombinedDisabledWorkTags;

            if (combinedDisabledWorkTags == WorkTags.None)
            {
                stringBuilder.Append("(" + "NoneLower".Translate() + "), ");
            }
            else
            {
                List <WorkTags> list  = CharacterCardUtility.WorkTagsFrom(combinedDisabledWorkTags).ToList <WorkTags>();
                bool            flag2 = true;
                foreach (WorkTags tags in list)
                {
                    if (flag2)
                    {
                        stringBuilder.Append(tags.LabelTranslated().CapitalizeFirst());
                    }
                    else
                    {
                        stringBuilder.Append(tags.LabelTranslated());
                    }
                    stringBuilder.Append(", ");
                    flag2 = false;
                }
            }
            string text = stringBuilder.ToString();

            text = text.Substring(0, text.Length - 2);
            Rect rect14 = new Rect(0f, num2, position.width, 999f);

            Widgets.Label(rect14, text);
            num2     += 100f;
            Text.Font = GameFont.Medium;
            Widgets.Label(new Rect(0f, num2, 200f, 30f), "Traits".Translate());
            num2     += 30f;
            Text.Font = GameFont.Small;
            for (int i = 0; i < pawn.story.traits.allTraits.Count; i++)
            {
                Trait trait  = pawn.story.traits.allTraits[i];
                Rect  rect15 = new Rect(0f, num2, position.width, 24f);
                if (Mouse.IsOver(rect15))
                {
                    Widgets.DrawHighlight(rect15);
                }
                Widgets.Label(rect15, trait.LabelCap);
                num2 += rect15.height + 2f;
                Trait     trLocal = trait;
                TipSignal tip     = new TipSignal(() => trLocal.TipString(pawn), (int)num2 * 37);
                TooltipHandler.TipRegion(rect15, tip);
            }
            GUI.EndGroup();
            GUI.BeginGroup(position2);
            Text.Font = GameFont.Medium;
            Widgets.Label(new Rect(0f, 0f, 200f, 30f), "Skills".Translate());
            SkillUI.SkillDrawMode mode;
            if (Current.ProgramState == ProgramState.Playing)
            {
                mode = SkillUI.SkillDrawMode.Gameplay;
            }
            else
            {
                mode = SkillUI.SkillDrawMode.Menu;
            }
            SkillUI.DrawSkillsOf(pawn, new Vector2(0f, 35f), mode);
            GUI.EndGroup();
            GUI.EndGroup();
        }
Esempio n. 24
0
 public static Backstory RandomBackstory(BackstorySlot slot)
 {
     return((from bs in allBackstories
             where bs.Value.slot == slot
             select bs).RandomElement().Value);
 }
Esempio n. 25
0
 public static Backstory RandomBackstory(BackstorySlot slot)
 {
     return(allBackstories.Where((KeyValuePair <string, Backstory> bs) => bs.Value.slot == slot).RandomElement().Value);
 }
Esempio n. 26
0
        protected void ShowBackstoryDialog(CustomPawn customPawn, BackstorySlot slot)
        {
            Backstory          originalBackstory = (slot == BackstorySlot.Childhood) ? customPawn.Childhood : customPawn.Adulthood;
            Backstory          selectedBackstory = originalBackstory;
            Filter <Backstory> filterToRemove    = null;
            bool             filterListDirtyFlag = true;
            List <Backstory> fullOptionsList     = slot == BackstorySlot.Childhood ?
                                                   this.providerBackstories.GetChildhoodBackstoriesForPawn(customPawn) : this.providerBackstories.GetAdulthoodBackstoriesForPawn(customPawn);
            List <Backstory>           filteredBackstories = new List <Backstory>(fullOptionsList.Count);
            Dialog_Options <Backstory> dialog = new Dialog_Options <Backstory>(filteredBackstories)
            {
                NameFunc = (Backstory backstory) => {
                    return(backstory.TitleCapFor(customPawn.Gender));
                },
                DescriptionFunc = (Backstory backstory) => {
                    return(backstory.FullDescriptionFor(customPawn.Pawn));
                },
                SelectedFunc = (Backstory backstory) => {
                    return(selectedBackstory == backstory);
                },
                SelectAction = (Backstory backstory) => {
                    selectedBackstory = backstory;
                },
                CloseAction = () => {
                    if (slot == BackstorySlot.Childhood)
                    {
                        BackstoryUpdated(BackstorySlot.Childhood, selectedBackstory);
                    }
                    else
                    {
                        BackstoryUpdated(BackstorySlot.Adulthood, selectedBackstory);
                    }
                }
            };

            dialog.DrawHeader = (Rect rect) => {
                if (filterToRemove != null)
                {
                    activeFilters.Remove(filterToRemove);
                    filterToRemove      = null;
                    filterListDirtyFlag = true;
                }
                if (filterListDirtyFlag)
                {
                    filteredBackstories.Clear();
                    filteredBackstories.AddRange(fullOptionsList.Where(p => { foreach (var f in activeFilters)
                                                                              {
                                                                                  if (f.FilterFunction(p) == false)
                                                                                  {
                                                                                      return(false);
                                                                                  }
                                                                              }
                                                                              return(true); }));
                    filterListDirtyFlag = false;
                    dialog.ScrollToTop();
                }

                float   filterHeight  = 18;
                float   filterPadding = 4;
                float   maxWidth      = rect.width - 32;
                Vector2 cursor        = new Vector2(0, 0);

                string addFilterLabel = "EdB.PC.Dialog.Backstory.Filter.Add".Translate();
                float  width          = Text.CalcSize(addFilterLabel).x;
                Rect   addFilterRect  = new Rect(rect.x, rect.y, width + 30, filterHeight);
                Widgets.DrawAtlas(addFilterRect, Textures.TextureFilterAtlas1);
                Text.Font = GameFont.Tiny;
                if (addFilterRect.Contains(Event.current.mousePosition))
                {
                    GUI.color = Style.ColorButtonHighlight;
                }
                else
                {
                    GUI.color = Style.ColorText;
                }
                Widgets.Label(addFilterRect.InsetBy(10, 0, 20, 0).OffsetBy(0, 1), addFilterLabel);
                GUI.DrawTexture(new Rect(addFilterRect.xMax - 20, addFilterRect.y + 6, 11, 8), Textures.TextureDropdownIndicator);

                if (Widgets.ButtonInvisible(addFilterRect, true))
                {
                    List <FloatMenuOption> list = new List <FloatMenuOption>();
                    foreach (var filter in availableFilters)
                    {
                        if (activeFilters.FirstOrDefault((f) => {
                            if (f == filter || f.ConflictsWith(filter))
                            {
                                return(true);
                            }
                            return(false);
                        }) == null)
                        {
                            list.Add(new FloatMenuOption(filter.LabelFull, () => {
                                activeFilters.Add(filter);
                                filterListDirtyFlag = true;
                            }, MenuOptionPriority.Default, null, null, 0, null, null));
                        }
                    }
                    Find.WindowStack.Add(new FloatMenu(list, null, false));
                }

                cursor.x += addFilterRect.width + filterPadding;
                Text.Font = GameFont.Tiny;
                foreach (var filter in activeFilters)
                {
                    GUI.color = Style.ColorText;
                    float labelWidth = Text.CalcSize(filter.LabelShort).x;
                    if (cursor.x + labelWidth > maxWidth)
                    {
                        cursor.x  = 0;
                        cursor.y += filterHeight + filterPadding;
                    }
                    Rect filterRect = new Rect(cursor.x, cursor.y, labelWidth + 30, filterHeight);
                    Widgets.DrawAtlas(filterRect, Textures.TextureFilterAtlas2);
                    Rect closeButtonRect = new Rect(filterRect.xMax - 15, filterRect.y + 5, 9, 9);
                    if (filterRect.Contains(Event.current.mousePosition))
                    {
                        GUI.color = Style.ColorButtonHighlight;
                    }
                    else
                    {
                        GUI.color = Style.ColorText;
                    }
                    Widgets.Label(filterRect.InsetBy(10, 0, 20, 0).OffsetBy(0, 1), filter.LabelShort);
                    GUI.DrawTexture(closeButtonRect, Textures.TextureButtonCloseSmall);
                    if (Widgets.ButtonInvisible(filterRect))
                    {
                        filterToRemove      = filter;
                        filterListDirtyFlag = true;
                        SoundDefOf.Tick_High.PlayOneShotOnCamera();
                    }
                    cursor.x += filterRect.width + filterPadding;
                }

                Text.Font = GameFont.Small;
                GUI.color = Color.white;

                return(cursor.y + filterHeight + 4);
            };
            Find.WindowStack.Add(dialog);
        }
Esempio n. 27
0
 public static Backstory RandomBackstory(BackstorySlot slot)
 {
     return((from bs in BackstoryDatabase.allBackstories
             where bs.Value.slot == slot
             select bs).RandomElement <KeyValuePair <string, Backstory> >().Value);
 }
        public static bool FillBackstorySlotShuffled(Pawn pawn, BackstorySlot slot, ref Backstory backstory, Backstory backstoryOtherSlot, List <BackstoryCategoryFilter> backstoryCategories, FactionDef factionType)
        {
            bool act = pawn.def.modContentPack != null && pawn.def.modContentPack.Name.Contains("Adeptus Mechanicus");

            if (act || pawn.def.defName.StartsWith("OG_") || pawn.kindDef.defName.StartsWith("OG_") || pawn.kindDef.defName.Contains("_OG_"))
            {
                BackstoryCategoryFilter backstoryCategoryFilter = backstoryCategories.RandomElementByWeight((BackstoryCategoryFilter c) => c.commonality);
                if (backstoryCategoryFilter == null)
                {
                    backstoryCategoryFilter = PawnBioAndNameGenerator_FillBackstorySlotShuffled_Controller_Patch.FallbackCategoryGroup;
                }
                List <string> lista = new List <string>();
                foreach (BackstoryCategoryFilter filter in backstoryCategories)
                {
                    foreach (string str in filter.categories)
                    {
                        if (!lista.Contains(str))
                        {
                            lista.Add(str);
                        }
                    }
                }
                if (!(from bs in BackstoryDatabase.ShuffleableBackstoryList(slot, backstoryCategoryFilter).TakeRandom(20)
                      where slot != BackstorySlot.Adulthood || !bs.requiredWorkTags.OverlapsWithOnAnyWorkType(pawn.story.childhood.workDisables)
                      select bs).TryRandomElementByWeight(new Func <Backstory, float>(PawnBioAndNameGenerator_FillBackstorySlotShuffled_Controller_Patch.BackstorySelectionWeight), out backstory))
                {
                    Log.Warning(string.Concat(new object[]
                    {
                        "low number of backstories ",
                        slot,
                        " categories used ",
                        backstoryCategoryFilter.categories.ToCommaList(),
                        " found for ",
                        pawn.ToStringSafe <Pawn>(),
                        " of ",
                        factionType.ToStringSafe <FactionDef>(),
                        ". trying random."
                    }));
                    if (!BackstoryDatabase.allBackstories.Where(bs => backstoryCategoryFilter.categories.Any(cat => bs.Value.spawnCategories.Contains(cat)) && bs.Value.slot == slot && (slot != BackstorySlot.Adulthood || !bs.Value.requiredWorkTags.OverlapsWithOnAnyWorkType(pawn.story.childhood.workDisables))).TryRandomElementByWeight <KeyValuePair <string, Backstory> >(new Func <KeyValuePair <string, Backstory>, float>(PawnBioAndNameGenerator_FillBackstorySlotShuffled_Controller_Patch.BackstorySelectionWeight), out KeyValuePair <string, Backstory> b))
                    {
                        Log.Error(string.Concat(new object[]
                        {
                            "No shuffled ",
                            slot,
                            " categories used ",
                            backstoryCategoryFilter.categories.ToCommaList(),
                            " found for ",
                            pawn.ToStringSafe <Pawn>(),
                            " of ",
                            factionType.ToStringSafe <FactionDef>(),
                            ". Choosing random."
                        }), false);
                        backstory = (from kvp in BackstoryDatabase.allBackstories
                                     where kvp.Value.slot == slot
                                     select kvp).RandomElement <KeyValuePair <string, Backstory> >().Value;
                    }
                    else
                    {
                        backstory = b.Value;
                    }
                }
                return(false);
            }
            return(true);
        }
Esempio n. 29
0
        protected override void FillTab()
        {
            Pawn pawnToShowInfoAbout = this.PawnToShowInfoAbout;

            try
            {
                GUI.BeginGroup(new Rect(ITab_Pawn_Character_Alternate.PaddingSize.x, ITab_Pawn_Character_Alternate.PaddingSize.y, ITab_Pawn_Character_Alternate.ContentSize.x, ITab_Pawn_Character_Alternate.ContentSize.y));
                float num         = 0f;
                float num2        = 12f;
                bool  allowRename = !pawnToShowInfoAbout.Dead && !pawnToShowInfoAbout.Destroyed;
                num      += TabDrawer.DrawNameAndBasicInfo(0f, num, this.PawnToShowInfoAbout, ITab_Pawn_Character_Alternate.ContentSize.x, allowRename);
                num      += num2;
                num      += TabDrawer.DrawHeader(0f, num, ITab_Pawn_Character_Alternate.ContentSize.x, "Backstory".Translate(), true, TextAnchor.UpperLeft);
                num      += 2f;
                Text.Font = GameFont.Small;
                GUI.color = TabDrawer.TextColor;
                Vector2     vector     = new Vector2(ITab_Pawn_Character_Alternate.ContentSize.x, 24f);
                Vector2     vector2    = new Vector2(90f, 24f);
                Vector2     vector3    = new Vector2(3f, 2f);
                int         num3       = 0;
                IEnumerator enumerator = Enum.GetValues(typeof(BackstorySlot)).GetEnumerator();
                try
                {
                    while (enumerator.MoveNext())
                    {
                        BackstorySlot backstorySlot = (BackstorySlot)enumerator.Current;
                        Rect          rect          = new Rect(0f, num, vector.x, vector.y);
                        if (rect.Contains(Event.current.mousePosition))
                        {
                            Widgets.DrawHighlight(rect);
                        }
                        TooltipHandler.TipRegion(rect, pawnToShowInfoAbout.story.GetBackstory(backstorySlot).FullDescriptionFor(pawnToShowInfoAbout));
                        rect.x     += vector3.x;
                        rect.width -= vector3.x * 2f;
                        rect.y     += vector3.y;
                        GUI.skin.label.alignment = TextAnchor.MiddleLeft;
                        string str = (backstorySlot == BackstorySlot.Adulthood) ? "Adulthood".Translate() : "Childhood".Translate();
                        Widgets.Label(rect, str + ":");
                        GUI.skin.label.alignment = TextAnchor.UpperLeft;
                        Rect   rect2 = new Rect(rect.x + vector2.x, rect.y, vector.x - vector2.x, vector.y);
                        string title = pawnToShowInfoAbout.story.GetBackstory(backstorySlot).title;
                        Widgets.Label(rect2, title);
                        num += vector.y + 2f;
                        num3++;
                    }
                }
                finally
                {
                    IDisposable disposable;
                    if ((disposable = (enumerator as IDisposable)) != null)
                    {
                        disposable.Dispose();
                    }
                }
                num -= 6f;
                num += num2;
                num += TabDrawer.DrawHeader(0f, num, ITab_Pawn_Character_Alternate.ContentSize.x, "Skills".Translate(), true, TextAnchor.UpperLeft);
                num += 6f;
                float height = (float)DefDatabase <SkillDef> .AllDefs.Count <SkillDef>() * 24f;

                Rect position = new Rect(0f, num, 390f, height);
                GUI.color = TabDrawer.TextColor;
                GUI.BeginGroup(position);
                this.skillDrawer.DrawSkillsOf(pawnToShowInfoAbout, new Vector2(0f, 0f));
                GUI.EndGroup();
                num += position.height;
                num += num2;
                float num4 = num;
                float num5 = ITab_Pawn_Character_Alternate.ContentSize.x * 0.4f - ITab_Pawn_Character_Alternate.PaddingSize.x / 2f;
                float num6 = ITab_Pawn_Character_Alternate.ContentSize.x * 0.6f - ITab_Pawn_Character_Alternate.PaddingSize.x / 2f;
                float left = num5 + ITab_Pawn_Character_Alternate.PaddingSize.x;
                num += TabDrawer.DrawHeader(0f, num, num5, "IncapableOf".Translate(), true, TextAnchor.UpperLeft);
                num += 4f;
                Vector2 vector4 = new Vector2(num5, 22f);
                Text.Font = GameFont.Small;
                GUI.color = TabDrawer.TextColor;
                List <WorkTags> list = pawnToShowInfoAbout.story.DisabledWorkTags.ToList <WorkTags>();
                GUI.skin.label.alignment = TextAnchor.UpperLeft;
                if (list.Count == 0)
                {
                    Rect rect3 = new Rect(0f, num, num5, vector4.y);
                    GUI.color = TabDrawer.SeparatorColor;
                    Widgets.Label(rect3, "NoneLower".Translate());
                    GUI.color = TabDrawer.TextColor;
                    num      += rect3.height - 1f;
                }
                else
                {
                    foreach (WorkTags current in list)
                    {
                        Rect rect4 = new Rect(0f, num, num5, vector4.y);
                        Widgets.Label(rect4, current.LabelTranslated());
                        num += vector4.y - 1f;
                    }
                }
                num  = num4;
                num += TabDrawer.DrawHeader(left, num, num6, "Traits".Translate(), true, TextAnchor.UpperLeft);
                num += 4f;
                Vector2 vector5 = new Vector2(num6, 22f);
                Text.Font = GameFont.Small;
                GUI.color = TabDrawer.TextColor;
                float num7 = 0f;
                foreach (Trait current2 in pawnToShowInfoAbout.story.traits.allTraits)
                {
                    num7 += vector5.y + 2f;
                    Rect rect5 = new Rect(left, num, num6, vector5.y);
                    if (rect5.Contains(Event.current.mousePosition))
                    {
                        Widgets.DrawHighlight(rect5);
                    }
                    rect5.x += 2f;
                    Widgets.Label(rect5, current2.LabelCap);
                    TooltipHandler.TipRegion(rect5, current2.TipString(pawnToShowInfoAbout));
                    num += vector5.y - 1f;
                }
            }
            finally
            {
                GUI.EndGroup();
            }
            if (this.PreferenceTabBrowseButtons != null && this.PreferenceTabBrowseButtons.Value && pawnToShowInfoAbout != null)
            {
                BrowseButtonDrawer.DrawBrowseButtons(this.size, pawnToShowInfoAbout);
            }
            GUI.color = Color.white;
        }
 public BackstoryModel(PawnBio bio, BackstorySlot slot)
 {
     this.bio       = bio;
     this.backstory = slot == BackstorySlot.Childhood ? bio.childhood : bio.adulthood;
 }