Пример #1
0
        public static void TryAbandonOrBanishViaInterface(Thing t, Caravan caravan)
        {
            Pawn p = t as Pawn;

            if (p != null)
            {
                if (!caravan.PawnsListForReading.Any((Pawn x) => x != p && caravan.IsOwner(x)))
                {
                    Messages.Message("MessageCantBanishLastColonist".Translate(), caravan, MessageTypeDefOf.RejectInput, historical: false);
                }
                else
                {
                    PawnBanishUtility.ShowBanishPawnConfirmationDialog(p);
                }
            }
            else
            {
                Dialog_MessageBox window = Dialog_MessageBox.CreateConfirmation("ConfirmAbandonItemDialog".Translate(t.Label), delegate
                {
                    Pawn ownerOf = CaravanInventoryUtility.GetOwnerOf(caravan, t);
                    if (ownerOf == null)
                    {
                        Log.Error("Could not find owner of " + t);
                    }
                    else
                    {
                        ownerOf.inventory.innerContainer.Remove(t);
                        t.Destroy();
                        caravan.RecacheImmobilizedNow();
                        caravan.RecacheDaysWorthOfFood();
                    }
                }, destructive: true);
                Find.WindowStack.Add(window);
            }
        }
        protected override IEnumerable <Toil> MakeNewToils()
        {
            this.FailOnDestroyedOrNull(TargetIndex.A);
            this.FailOnBurningImmobile(TargetIndex.B);
            this.FailOn(() => ((Pawn)(Thing)GetActor().CurJob.GetTarget(TargetIndex.A)).guest.interactionMode != PrisonerInteractionModeDefOf.Release);
            this.FailOnDowned(TargetIndex.A);
            this.FailOnAggroMentalState(TargetIndex.A);
            yield return(Toils_Goto.GotoThing(TargetIndex.A, PathEndMode.ClosestTouch).FailOn(() => !Prisoner.IsPrisonerOfColony || !Prisoner.guest.PrisonerIsSecure).FailOnSomeonePhysicallyInteracting(TargetIndex.A));

            yield return(Toils_Haul.StartCarryThing(TargetIndex.A));

            Toil carryToCell = Toils_Haul.CarryHauledThingToCell(TargetIndex.B);

            yield return(carryToCell);

            yield return(Toils_Haul.PlaceHauledThingInCell(TargetIndex.B, carryToCell, storageMode: false));

            Toil setReleased = new Toil();

            setReleased.initAction = delegate
            {
                Pawn pawn = setReleased.actor.jobs.curJob.targetA.Thing as Pawn;
                GenGuest.PrisonerRelease(pawn);
                pawn.guest.ClearLastRecruiterData();
                if (!PawnBanishUtility.WouldBeLeftToDie(pawn, pawn.Map.Tile))
                {
                    GenGuest.AddHealthyPrisonerReleasedThoughts(pawn);
                }
            };
            yield return(setReleased);
        }
Пример #3
0
        private static void PassPawnsToWorld(Map map)
        {
            bool        flag = map.ParentFaction != null && map.ParentFaction.HostileTo(Faction.OfPlayer);
            List <Pawn> list = map.mapPawns.AllPawns.ToList();

            for (int i = 0; i < list.Count; i++)
            {
                try
                {
                    Pawn pawn = list[i];
                    if (pawn.Spawned)
                    {
                        pawn.DeSpawn();
                    }
                    if (pawn.IsColonist && flag)
                    {
                        map.ParentFaction.kidnapped.KidnapPawn(pawn, null);
                    }
                    else
                    {
                        if (pawn.Faction == Faction.OfPlayer || pawn.HostFaction == Faction.OfPlayer)
                        {
                            PawnBanishUtility.Banish(pawn, map.Tile);
                        }
                        MapDeiniter.CleanUpAndPassToWorld(pawn);
                    }
                }
                catch (Exception ex)
                {
                    Log.Error("Could not despawn and pass to world " + list[i] + ": " + ex);
                }
            }
        }
        public static string GetAbandonOrBanishButtonTooltip(Thing t, Caravan caravan, bool abandonSpecificCount)
        {
            Pawn pawn = t as Pawn;

            if (pawn != null)
            {
                return(PawnBanishUtility.GetBanishButtonTip(pawn));
            }
            StringBuilder stringBuilder = new StringBuilder();

            if (t.stackCount == 1)
            {
                stringBuilder.AppendLine("AbandonTip".Translate());
            }
            else if (abandonSpecificCount)
            {
                stringBuilder.AppendLine("AbandonSpecificCountTip".Translate());
            }
            else
            {
                stringBuilder.AppendLine("AbandonAllTip".Translate());
            }
            stringBuilder.AppendLine();
            stringBuilder.Append("AbandonItemTipExtraText".Translate());
            return(stringBuilder.ToString());
        }
Пример #5
0
        public static string GetAbandonOrBanishButtonTooltip(TransferableImmutable t, bool abandonSpecificCount)
        {
            Pawn pawn = t.AnyThing as Pawn;

            if (pawn != null)
            {
                return(PawnBanishUtility.GetBanishButtonTip(pawn));
            }
            return(GetAbandonItemButtonTooltip(t.TotalStackCount, abandonSpecificCount));
        }
Пример #6
0
        public static string GetAbandonOrBanishButtonTooltip(Thing t, bool abandonSpecificCount)
        {
            Pawn pawn = t as Pawn;

            if (pawn != null)
            {
                return(PawnBanishUtility.GetBanishButtonTip(pawn));
            }
            return(GetAbandonItemButtonTooltip(t.stackCount, abandonSpecificCount));
        }
        public static string GetAbandonOrBanishButtonTooltip(Thing t, bool abandonSpecificCount)
        {
            Pawn   pawn = t as Pawn;
            string result;

            if (pawn != null)
            {
                result = PawnBanishUtility.GetBanishButtonTip(pawn);
            }
            else
            {
                result = CaravanAbandonOrBanishUtility.GetAbandonItemButtonTooltip(t.stackCount, abandonSpecificCount);
            }
            return(result);
        }
        public static bool Prefix(Caravan_NeedsTracker __instance, Pawn pawn)
        {
            var extension = pawn.def.GetModExtension <MechanoidExtension>();

            if (extension != null && pawn.def.GetModExtension <MechanoidExtension>().isCaravanRiddable)
            {
                if (pawn.needs.TryGetNeed <Need_Power>().CurLevel <= 0)
                {
                    PawnBanishUtility.Banish(pawn);
                    pawn.Kill(null);
                    Messages.Message("VFEM.CaravanMachineRanOutPower".Translate(pawn.Named("MACHINE")), __instance.caravan, MessageTypeDefOf.CautionInput);
                }
                return(false);
            }
            return(true);
        }
 private void DoArrivalAction()
 {
     for (int i = 0; i < pods.Count; i++)
     {
         pods[i].savePawnsWithReferenceMode = false;
         pods[i].parent = null;
     }
     if (arrivalAction != null)
     {
         try
         {
             arrivalAction.Arrived(pods, destinationTile);
         }
         catch (Exception arg)
         {
             Log.Error("Exception in transport pods arrival action: " + arg);
         }
         arrivalAction = null;
     }
     else
     {
         for (int j = 0; j < pods.Count; j++)
         {
             for (int k = 0; k < pods[j].innerContainer.Count; k++)
             {
                 Pawn pawn = pods[j].innerContainer[k] as Pawn;
                 if (pawn != null && (pawn.Faction == Faction.OfPlayer || pawn.HostFaction == Faction.OfPlayer))
                 {
                     PawnBanishUtility.Banish(pawn, destinationTile);
                 }
             }
         }
         for (int l = 0; l < pods.Count; l++)
         {
             pods[l].innerContainer.ClearAndDestroyContentsOrPassToWorld();
         }
         string key = "MessageTransportPodsArrivedAndLost";
         if (def == WorldObjectDefOf.TravelingShuttle)
         {
             key = "MessageShuttleArrivedContentsLost";
         }
         Messages.Message(key.Translate(), new GlobalTargetInfo(destinationTile), MessageTypeDefOf.NegativeEvent);
     }
     pods.Clear();
     Destroy();
 }
Пример #10
0
        public static void DrawBanishButton(Rect rect, ref float lineEndWidth)
        {
            try
            {
                if (Find.Selector.NumSelected != 1)
                {
                    return;
                }

                Thing singleSelectedThing = Find.Selector.SingleSelectedThing;

                if (singleSelectedThing == null)
                {
                    return;
                }
                if (!(singleSelectedThing is Pawn pawn) || pawn.Faction != Faction.OfPlayer || !pawn.RaceProps.Animal)
                {
                    return;
                }
                lineEndWidth += 24f;

                var       rect2 = new Rect(rect.width - lineEndWidth, 0f, 24f, 24f);
                Texture2D ico   = ContentFinder <Texture2D> .Get("UI/Buttons/Banish");

                TooltipHandler.TipRegion(rect2, PawnBanishUtility.GetBanishButtonTip(pawn));

                if (!Widgets.ButtonImage(rect2, ico))
                {
                    return;
                }
                if (pawn.Downed)
                {
                    Messages.Message("MessageCantBanishDownedPawn".Translate(pawn.LabelShort, pawn).AdjustedFor(pawn), pawn, MessageTypeDefOf.RejectInput, historical: false);
                }
                else
                {
                    PawnBanishUtility.ShowBanishPawnConfirmationDialog(pawn);
                }
            }
            catch (System.Exception e)
            {
                Log.Message($"BanishAnimals : BanishButton.DrawBanishButton error - {e.Message}", true);
            }
        }
Пример #11
0
 private void DoArrivalAction()
 {
     for (int i = 0; i < this.pods.Count; i++)
     {
         this.pods[i].savePawnsWithReferenceMode = false;
         this.pods[i].parent = null;
     }
     if (this.arrivalAction != null)
     {
         try
         {
             this.arrivalAction.Arrived(this.pods, this.destinationTile);
         }
         catch (Exception arg)
         {
             Log.Error("Exception in transport pods arrival action: " + arg, false);
         }
         this.arrivalAction = null;
     }
     else
     {
         for (int j = 0; j < this.pods.Count; j++)
         {
             for (int k = 0; k < this.pods[j].innerContainer.Count; k++)
             {
                 Pawn pawn = this.pods[j].innerContainer[k] as Pawn;
                 if (pawn != null && (pawn.Faction == Faction.OfPlayer || pawn.HostFaction == Faction.OfPlayer))
                 {
                     PawnBanishUtility.Banish(pawn, this.destinationTile);
                 }
             }
         }
         for (int l = 0; l < this.pods.Count; l++)
         {
             this.pods[l].innerContainer.ClearAndDestroyContentsOrPassToWorld(DestroyMode.Vanish);
         }
         Messages.Message("MessageTransportPodsArrivedAndLost".Translate(), new GlobalTargetInfo(this.destinationTile), MessageTypeDefOf.NegativeEvent, true);
     }
     this.pods.Clear();
     Find.WorldObjects.Remove(this);
 }
Пример #12
0
        private static void PassPawnsToWorld(Map map)
        {
            List <Pawn> list  = new List <Pawn>();
            List <Pawn> list2 = new List <Pawn>();
            bool        flag  = map.ParentFaction != null && map.ParentFaction.HostileTo(Faction.OfPlayer);
            List <Pawn> list3 = map.mapPawns.AllPawns.ToList <Pawn>();

            for (int i = 0; i < list3.Count; i++)
            {
                Find.Storyteller.Notify_PawnEvent(list3[i], AdaptationEvent.LostBecauseMapClosed, null);
                try
                {
                    Pawn pawn = list3[i];
                    if (pawn.Spawned)
                    {
                        pawn.DeSpawn(DestroyMode.Vanish);
                    }
                    if (pawn.IsColonist && flag)
                    {
                        list.Add(pawn);
                        map.ParentFaction.kidnapped.Kidnap(pawn, null);
                    }
                    else
                    {
                        if (pawn.Faction == Faction.OfPlayer || pawn.HostFaction == Faction.OfPlayer)
                        {
                            list2.Add(pawn);
                            PawnBanishUtility.Banish(pawn, map.Tile);
                        }
                        MapDeiniter.CleanUpAndPassToWorld(pawn);
                    }
                }
                catch (Exception ex)
                {
                    Log.Error(string.Concat(new object[]
                    {
                        "Could not despawn and pass to world ",
                        list3[i],
                        ": ",
                        ex
                    }), false);
                }
            }
            if (list.Any <Pawn>() || list2.Any <Pawn>())
            {
                StringBuilder stringBuilder = new StringBuilder();
                if (list.Any <Pawn>())
                {
                    list.SortByDescending((Pawn x) => x.RaceProps.Humanlike);
                    for (int j = 0; j < list.Count; j++)
                    {
                        stringBuilder.AppendLine(string.Concat(new string[]
                        {
                            "  - ",
                            list[j].LabelCap,
                            " (",
                            "capturedBy".Translate(map.ParentFaction.Name),
                            ")"
                        }));
                    }
                }
                if (list2.Any <Pawn>())
                {
                    list2.SortByDescending((Pawn x) => x.RaceProps.Humanlike);
                    for (int k = 0; k < list2.Count; k++)
                    {
                        stringBuilder.AppendLine("  - " + list2[k].LabelCap);
                    }
                }
                string label;
                string text;
                if (map.IsPlayerHome)
                {
                    label = "LetterLabelPawnsLostBecauseMapClosed_Home".Translate();
                    text  = "LetterPawnsLostBecauseMapClosed_Home".Translate();
                }
                else
                {
                    label = "LetterLabelPawnsLostBecauseMapClosed_Caravan".Translate();
                    text  = "LetterPawnsLostBecauseMapClosed_Caravan".Translate();
                }
                text = text + ":\n\n" + stringBuilder.ToString().TrimEndNewlines();
                Find.LetterStack.ReceiveLetter(label, text, LetterDefOf.NegativeEvent, new GlobalTargetInfo(map.Tile), null, null);
            }
        }
        public static void DrawCharacterCard(Rect rect, Pawn pawn, Action randomizeCallback = null, Rect creationRect = default(Rect))
        {
            bool creationMode = randomizeCallback != null;

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

            if (creationMode && 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 name  = nameTriple.First;
                string name2 = nameTriple.Nick;
                string name3 = nameTriple.Last;
                DoNameInputRect(rect3, ref name, 12);
                if (nameTriple.Nick == nameTriple.First || nameTriple.Nick == nameTriple.Last)
                {
                    GUI.color = new Color(1f, 1f, 1f, 0.5f);
                }
                DoNameInputRect(rect4, ref name2, 16);
                GUI.color = Color.white;
                DoNameInputRect(rect5, ref name3, 12);
                if (nameTriple.First != name || nameTriple.Nick != name2 || nameTriple.Last != name3)
                {
                    pawn.Name = new NameTriple(name, string.IsNullOrEmpty(name2) ? name : name2, name3);
                }
                TooltipHandler.TipRegionByKey(rect3, "FirstNameDesc");
                TooltipHandler.TipRegionByKey(rect4, "ShortIdentifierDesc");
                TooltipHandler.TipRegionByKey(rect5, "LastNameDesc");
            }
            else
            {
                rect2.width = 999f;
                Text.Font   = GameFont.Medium;
                Widgets.Label(rect2, pawn.Name.ToStringFull);
                Text.Font = GameFont.Small;
            }
            if (!pawn.health.Dead)
            {
                float num = rect.x + 50f;
                if (pawn.IsFreeColonist && pawn.Spawned && !pawn.IsQuestLodger())
                {
                    Rect rect7 = new Rect(num, 0f, 30f, 30f);
                    if (Mouse.IsOver(rect7))
                    {
                        TooltipHandler.TipRegion(rect7, PawnBanishUtility.GetBanishButtonTip(pawn));
                    }
                    if (Widgets.ButtonImage(rect7, Banish))
                    {
                        if (pawn.Downed)
                        {
                            Messages.Message("MessageCantBanishDownedPawn".Translate(pawn.LabelShort, pawn).AdjustedFor(pawn), pawn, MessageTypeDefOf.RejectInput, historical: false);
                        }
                        else
                        {
                            PawnBanishUtility.ShowBanishPawnConfirmationDialog(pawn);
                        }
                    }
                    num -= 35f;
                }
                if (pawn.IsColonist)
                {
                    Rect rect8 = new Rect(num, 0f, 30f, 30f);
                    TooltipHandler.TipRegionByKey(rect8, "RenameColonist");
                    if (Widgets.ButtonImage(rect8, Rename))
                    {
                        Find.WindowStack.Add(new Dialog_NamePawn(pawn));
                    }
                    num -= 35f;
                }
                //if (pawn.IsFreeColonist && !pawn.IsQuestLodger() && pawn.royalty != null && pawn.royalty.AllTitlesForReading.Count > 0)
                //{
                //	Rect rect9 = new Rect(num, 0f, 30f, 30f);
                //	TooltipHandler.TipRegionByKey(rect9, "RenounceTitle");
                //	if (Widgets.ButtonImage(rect9, RenounceTitle))
                //	{
                //		FloatMenuUtility.MakeMenu(pawn.royalty.AllTitlesForReading, (RoyalTitle title) => "RenounceTitle".Translate() + ": " + "TitleOfFaction".Translate(title.def.GetLabelCapFor(pawn), title.faction.GetCallLabel()), delegate (RoyalTitle title)
                //		{
                //			return delegate
                //			{
                //				RoyalTitleUtility.FindLostAndGainedPermits(title.def, null, out List<RoyalTitlePermitDef> _, out List<RoyalTitlePermitDef> lostPermits);
                //				StringBuilder stringBuilder = new StringBuilder();
                //				if (lostPermits.Count > 0)
                //				{
                //					stringBuilder.AppendLine("RenounceTitleWillLoosePermits".Translate(pawn.Named("PAWN")) + ":");
                //					foreach (RoyalTitlePermitDef item2 in lostPermits)
                //					{
                //						stringBuilder.AppendLine("- " + item2.LabelCap + " (" + FirstTitleWithPermit(item2).GetLabelFor(pawn) + ")");
                //					}
                //					stringBuilder.AppendLine();
                //				}
                //				if (!title.faction.def.renounceTitleMessage.NullOrEmpty())
                //				{
                //					stringBuilder.AppendLine(title.faction.def.renounceTitleMessage);
                //				}
                //				Find.WindowStack.Add(Dialog_MessageBox.CreateConfirmation("RenounceTitleDescription".Translate(pawn.Named("PAWN"), "TitleOfFaction".Translate(title.def.GetLabelCapFor(pawn), title.faction.GetCallLabel()).Named("TITLE"), stringBuilder.ToString().TrimEndNewlines().Named("EFFECTS")), delegate
                //				{
                //					pawn.royalty.SetTitle(title.faction, null, grantRewards: false);
                //					pawn.royalty.ResetPermitsAndPoints(title.faction, title.def);
                //				}, destructive: true));
                //			};
                //			RoyalTitleDef FirstTitleWithPermit(RoyalTitlePermitDef permitDef)
                //			{
                //				return title.faction.def.RoyalTitlesAwardableInSeniorityOrderForReading.First((RoyalTitleDef t) => t.permits != null && t.permits.Contains(permitDef));
                //			}
                //		});
                //	}
                //	num -= 40f;
                //}
            }
            List <GenUI.AnonymousStackElement> stackElements = new List <GenUI.AnonymousStackElement>();

            Text.Font = GameFont.Small;
            string  text   = pawn.MainDesc(writeFaction: false);
            Vector2 vector = Text.CalcSize(text);
            Rect    rect10 = new Rect(0f, 30f, vector.x + 5f, 24f);

            Widgets.Label(rect10, text);
            float height = Text.CalcHeight(text, rect10.width);
            Rect  rect11 = new Rect(rect10.x, rect10.y, rect10.width, height);

            if (Mouse.IsOver(rect11))
            {
                TooltipHandler.TipRegion(rect11, () => pawn.ageTracker.AgeTooltipString, 6873641);
            }

            GenUI.DrawElementStack(new Rect(vector.x + 10f, 45f, 999f, 24f), 22f, stackElements, delegate(Rect r, GenUI.AnonymousStackElement obj)
            {
                obj.drawer(r);
            }, (GenUI.AnonymousStackElement obj) => obj.width, 4f, 5f, allowOrderOptimization: false);
            stackElements.Clear();
            float curY = 30f;

            if (pawn.royalty != null && pawn.royalty.AllTitlesForReading.Count > 0)
            {
                foreach (RoyalTitle title2 in pawn.royalty.AllTitlesForReading)
                {
                    RoyalTitle localTitle = title2;
                    string     titleLabel = localTitle.def.GetLabelCapFor(pawn) + " (" + pawn.royalty.GetFavor(localTitle.faction) + ")";
                    stackElements.Add(new GenUI.AnonymousStackElement
                    {
                        drawer = delegate(Rect r)
                        {
                            r.x         += 100f;
                            Color color5 = GUI.color;
                            Rect rect18  = new Rect(r.x, r.y, r.width + 22f, r.height);
                            GUI.color    = StackElementBackground;
                            GUI.DrawTexture(rect18, BaseContent.WhiteTex);
                            GUI.color = color5;
                            int favor = pawn.royalty.GetFavor(localTitle.faction);
                            if (Mouse.IsOver(rect18))
                            {
                                Widgets.DrawHighlight(rect18);
                            }
                            Rect rect19    = new Rect(r.x, r.y, r.width + 22f, r.height);
                            Rect position2 = new Rect(r.x + 1f, r.y + 1f, 20f, 20f);
                            GUI.color      = title2.faction.Color;
                            GUI.DrawTexture(position2, localTitle.faction.def.FactionIcon);
                            GUI.color = color5;
                            Widgets.Label(new Rect(rect19.x + rect19.height + 5f, rect19.y, rect19.width - 10f, rect19.height), titleLabel);
                            if (Widgets.ButtonInvisible(rect18))
                            {
                                Find.WindowStack.Add(new Dialog_InfoCard(localTitle.def, localTitle.faction));
                            }
                            if (Mouse.IsOver(rect18))
                            {
                                TipSignal tip4 = new TipSignal(() => GetTitleTipString(pawn, localTitle.faction, localTitle, favor), (int)curY * 37);
                                TooltipHandler.TipRegion(rect18, tip4);
                            }
                        },
                        width = Text.CalcSize(titleLabel).x + 15f
                    });
                }
            }
            QuestUtility.AppendInspectStringsFromQuestParts(delegate(string str, Quest quest)
            {
                stackElements.Add(new GenUI.AnonymousStackElement
                {
                    drawer = delegate(Rect r)
                    {
                        Color color4 = GUI.color;
                        GUI.color    = StackElementBackground;
                        GUI.DrawTexture(r, BaseContent.WhiteTex);
                        GUI.color = color4;
                        DoQuestLine(r, str, quest);
                    },
                    width = GetQuestLineSize(str, quest).x
                });
            }, pawn, out int _);
            curY += GenUI.DrawElementStack(new Rect(0f, curY, rect.width - 5f, 50f), 22f, stackElements, delegate(Rect r, GenUI.AnonymousStackElement obj)
            {
                obj.drawer(r);
            }, (GenUI.AnonymousStackElement obj) => obj.width).height;
            //if (stackElements.Any())
            //{
            //	curY += 10f;
            //}
            Rect leftRect = new Rect(0f, curY, 250f, 355f);
            Rect position = new Rect(leftRect.xMax, curY, 258f, 355f);

            GUI.BeginGroup(leftRect);
            curY = 0f;
            Pawn           pawnLocal = pawn;
            List <Ability> abilities = (from a in pawn.abilities.abilities
                                        orderby a.def.level, a.def.EntropyGain
                                        select a).ToList();
            int   numSections = abilities.Any() ? 5 : 4;
            float num6        = (float)Enum.GetValues(typeof(BackstorySlot)).Length * 22f;

            if (pawn.story != null && pawn.story.title != null)
            {
                num6 += 22f;
            }
            List <LeftRectSection> list = new List <LeftRectSection>();
            LeftRectSection        item = new LeftRectSection
            {
                rect   = new Rect(0f, 0f, leftRect.width, num6),
                drawer = delegate(Rect sectionRect)
                {
                    float num12 = sectionRect.y;
                    Text.Font = GameFont.Small;
                    foreach (BackstorySlot value6 in Enum.GetValues(typeof(BackstorySlot)))
                    {
                        Backstory backstory = pawn.story.GetBackstory(value6);
                        if (backstory != null)
                        {
                            Rect rect14 = new Rect(sectionRect.x, num12, leftRect.width, 22f);
                            if (Mouse.IsOver(rect14))
                            {
                                Widgets.DrawHighlight(rect14);
                            }
                            if (Mouse.IsOver(rect14))
                            {
                                TooltipHandler.TipRegion(rect14, backstory.FullDescriptionFor(pawn).Resolve());
                            }
                            Text.Anchor = TextAnchor.MiddleLeft;
                            string str2 = (value6 == BackstorySlot.Adulthood) ? "Adulthood".Translate() : "Childhood".Translate();
                            Widgets.Label(rect14, str2 + ":");
                            Text.Anchor = TextAnchor.UpperLeft;
                            Rect rect15 = new Rect(rect14);
                            rect15.x     += 90f;
                            rect15.width -= 90f;
                            string str3 = backstory.TitleCapFor(pawn.gender);
                            Widgets.Label(rect15, str3.Truncate(rect15.width));
                            num12 += rect14.height;
                        }
                    }
                    if (pawn.story != null && pawn.story.title != null)
                    {
                        Rect rect16 = new Rect(sectionRect.x, num12, leftRect.width, 22f);
                        Text.Anchor = TextAnchor.MiddleLeft;
                        Widgets.Label(rect16, "Current".Translate() + ":");
                        Text.Anchor = TextAnchor.UpperLeft;
                        Rect rect17 = new Rect(rect16);
                        rect17.x     += 90f;
                        rect17.width -= 90f;
                        Widgets.Label(rect17, pawn.story.title);
                        num12 += rect16.height;
                    }
                }
            };

            list.Add(item);
            num6 = 30f;
            List <Trait> traits = pawn.story.traits.allTraits;

            num6 = ((traits != null && traits.Count != 0) ? (num6 + GenUI.DrawElementStack(new Rect(0f, 0f, leftRect.width - 5f, leftRect.height), 22f, pawn.story.traits.allTraits, delegate
            {
            }, (Trait trait) => Text.CalcSize(trait.LabelCap).x + 10f).height) : (num6 + 22f));
            num6 -= 5f;
            item  = new LeftRectSection
            {
                rect   = new Rect(0f, 0f, leftRect.width, num6),
                drawer = delegate(Rect sectionRect)
                {
                    Text.Font = GameFont.Medium;
                    float currentY2 = sectionRect.y;
                    Widgets.Label(new Rect(sectionRect.x, currentY2 - 7f, 200f, 26f), "Traits".Translate());
                    currentY2 += 21f;
                    Text.Font  = GameFont.Small;
                    if (traits == null || traits.Count == 0)
                    {
                        Color color = GUI.color;
                        GUI.color = Color.gray;
                        Rect rect12 = new Rect(sectionRect.x, currentY2, leftRect.width, 24f);
                        if (Mouse.IsOver(rect12))
                        {
                            Widgets.DrawHighlight(rect12);
                        }
                        Widgets.Label(rect12, "None".Translate());
                        currentY2 += rect12.height + 2f;
                        TooltipHandler.TipRegionByKey(rect12, "None");
                        GUI.color = color;
                    }
                    else
                    {
                        GenUI.DrawElementStack(new Rect(sectionRect.x, currentY2, leftRect.width - 5f, leftRect.height / (float)numSections), 22f, pawn.story.traits.allTraits,
                                               delegate(Rect r, Trait trait)
                        {
                            Color color2 = GUI.color;
                            GUI.color    = StackElementBackground;
                            GUI.DrawTexture(r, BaseContent.WhiteTex);
                            GUI.color = color2;
                            if (Mouse.IsOver(r))
                            {
                                Widgets.DrawHighlight(r);
                            }
                            Widgets.Label(new Rect(r.x + 5f, r.y, r.width - 10f, r.height), trait.LabelCap);
                            if (Mouse.IsOver(r))
                            {
                                TooltipHandler.TipRegion(tip: new TipSignal(() => trait.TipString(pawn), (int)currentY2 * 37), rect: r);
                            }
                        }, (Trait trait) => Text.CalcSize(trait.LabelCap).x + 10f);
                    }
                }
            };
            list.Add(item);
            num6 = 30f;
            WorkTags        disabledTags               = pawn.CombinedDisabledWorkTags;
            List <WorkTags> disabledTagsList           = WorkTagsFrom(disabledTags).ToList();
            bool            allowWorkTagVerticalLayout = false;

            GenUI.StackElementWidthGetter <WorkTags> workTagWidthGetter = (WorkTags tag) => Text.CalcSize(tag.LabelTranslated().CapitalizeFirst()).x + 10f;
            if (disabledTags == WorkTags.None)
            {
                num6 += 22f;
            }
            else
            {
                disabledTagsList.Sort(delegate(WorkTags a, WorkTags b)
                {
                    int num11  = GetWorkTypeDisableCauses(pawn, a).Any((object c) => c is RoyalTitleDef) ? 1 : (-1);
                    int value5 = GetWorkTypeDisableCauses(pawn, b).Any((object c) => c is RoyalTitleDef) ? 1 : (-1);
                    return(num11.CompareTo(value5));
                });
                num6 += GenUI.DrawElementStack(new Rect(0f, 0f, leftRect.width - 5f, leftRect.height), 22f, disabledTagsList, delegate
                {
                }, workTagWidthGetter, 4f, 5f, allowOrderOptimization: false).height;
                num6 += 12f;
                allowWorkTagVerticalLayout = (GenUI.DrawElementStackVertical(new Rect(0f, 0f, rect.width, leftRect.height / (float)numSections), 22f, disabledTagsList, delegate
                {
                }, workTagWidthGetter).width <= leftRect.width);
            }
            item = new LeftRectSection
            {
                rect   = new Rect(0f, 0f, leftRect.width, num6),
                drawer = delegate(Rect sectionRect)
                {
                    Text.Font = GameFont.Medium;
                    float currentY3 = sectionRect.y;
                    Widgets.Label(new Rect(sectionRect.x, currentY3 - 7f, 200f, 26f), "IncapableOf".Translate(pawn));
                    currentY3 += 21f;
                    Text.Font  = GameFont.Small;
                    if (disabledTags == WorkTags.None)
                    {
                        GUI.color = Color.gray;
                        Rect rect13 = new Rect(sectionRect.x, currentY3, leftRect.width, 24f);
                        if (Mouse.IsOver(rect13))
                        {
                            Widgets.DrawHighlight(rect13);
                        }
                        Widgets.Label(rect13, "None".Translate());
                        TooltipHandler.TipRegionByKey(rect13, "None");
                    }
                    else
                    {
                        GenUI.StackElementDrawer <WorkTags> drawer = delegate(Rect r, WorkTags tag)
                        {
                            Color color3 = GUI.color;
                            GUI.color = StackElementBackground;
                            GUI.DrawTexture(r, BaseContent.WhiteTex);
                            GUI.color = color3;
                            GUI.color = GetDisabledWorkTagLabelColor(pawn, tag);
                            if (Mouse.IsOver(r))
                            {
                                Widgets.DrawHighlight(r);
                            }
                            Widgets.Label(new Rect(r.x + 5f, r.y, r.width - 10f, r.height), tag.LabelTranslated().CapitalizeFirst());
                            if (Mouse.IsOver(r))
                            {
                                TooltipHandler.TipRegion(tip: new TipSignal(() => GetWorkTypeDisabledCausedBy(pawnLocal, tag) + "\n" + GetWorkTypesDisabledByWorkTag(tag), (int)currentY3 * 32), rect: r);
                            }
                        };
                        if (allowWorkTagVerticalLayout)
                        {
                            GenUI.DrawElementStackVertical(new Rect(sectionRect.x, currentY3, leftRect.width - 5f, leftRect.height / (float)numSections), 22f, disabledTagsList, drawer, workTagWidthGetter);
                        }
                        else
                        {
                            GenUI.DrawElementStack(new Rect(sectionRect.x, currentY3, leftRect.width - 5f, leftRect.height / (float)numSections), 22f, disabledTagsList, drawer, workTagWidthGetter, 5f);
                        }
                    }
                    GUI.color = Color.white;
                }
            };
            list.Add(item);
            //if (abilities.Any())
            //{
            //	num6 = 30f;
            //	num6 += GenUI.DrawElementStack(new Rect(0f, 0f, leftRect.width - 5f, leftRect.height), 32f, abilities, delegate
            //	{
            //	}, (Ability abil) => 32f).height;
            //	item = new LeftRectSection
            //	{
            //		rect = new Rect(0f, 0f, leftRect.width, num6),
            //		drawer = delegate (Rect sectionRect)
            //		{
            //			Text.Font = GameFont.Medium;
            //			float currentY = sectionRect.y;
            //			Widgets.Label(new Rect(sectionRect.x, currentY, 200f, 30f), "Abilities".Translate(pawn));
            //			currentY += 30f;
            //			Text.Font = GameFont.Small;
            //			GenUI.DrawElementStack(new Rect(sectionRect.x, currentY, leftRect.width - 5f, leftRect.height), 32f, abilities, delegate (Rect r, Ability abil)
            //			{
            //				GUI.DrawTexture(r, BaseContent.ClearTex);
            //				if (Mouse.IsOver(r))
            //				{
            //					Widgets.DrawHighlight(r);
            //				}
            //				if (Widgets.ButtonImage(r, abil.def.uiIcon, doMouseoverSound: false))
            //				{
            //					Find.WindowStack.Add(new Dialog_InfoCard(abil.def));
            //				}
            //				if (Mouse.IsOver(r))
            //				{
            //					TipSignal tip = new TipSignal(() => abil.def.GetTooltip() + "\n\n" + "ClickToLearnMore".Translate(), (int)currentY * 37);
            //					TooltipHandler.TipRegion(r, tip);
            //				}
            //			}, (Ability abil) => 32f);
            //			GUI.color = Color.white;
            //		}
            //	};
            //	list.Add(item);
            //}
            float num7 = 1f;            // leftRect.height / (float)list.Count;
            float num8 = 0f;

            for (int i = 0; i < list.Count; i++)
            {
                LeftRectSection value = list[i];
                if (value.rect.height > num7)
                {
                    num8 += value.rect.height - num7;
                    value.calculatedSize = value.rect.height;
                }
                else
                {
                    value.calculatedSize = num7;
                }
                list[i] = value;
            }
            bool  flag2 = false;
            float num9  = 0f;

            if (num8 > 0f)
            {
                LeftRectSection value2 = list[0];
                float           num10  = value2.rect.height + 2f;
                num8 -= value2.calculatedSize - num10;
                value2.calculatedSize = num10;
                list[0] = value2;
            }
            while (num8 > 0f)
            {
                bool flag3 = true;
                for (int j = 0; j < list.Count; j++)
                {
                    LeftRectSection value3 = list[j];
                    if (value3.calculatedSize - value3.rect.height > 0f)
                    {
                        value3.calculatedSize -= 1f;
                        num8 -= 1f;
                        flag3 = false;
                    }
                    list[j] = value3;
                }
                if (!flag3)
                {
                    continue;
                }
                for (int k = 0; k < list.Count; k++)
                {
                    LeftRectSection value4 = list[k];
                    if (k > 0)
                    {
                        value4.calculatedSize = Mathf.Max(value4.rect.height, num7);
                    }
                    else
                    {
                        value4.calculatedSize = value4.rect.height + 2f;
                    }
                    num9   += value4.calculatedSize;
                    list[k] = value4;
                }
                flag2 = true;
                break;
            }
            if (flag2)
            {
                Widgets.BeginScrollView(new Rect(0f, 0f, leftRect.width, leftRect.height), ref leftRectScrollPos, new Rect(0f, 0f, leftRect.width - 16f, num9));
            }
            curY = 0f;
            for (int l = 0; l < list.Count; l++)
            {
                LeftRectSection leftRectSection = list[l];
                leftRectSection.drawer(new Rect(0f, curY, leftRect.width, leftRectSection.rect.height));
                curY += leftRectSection.calculatedSize;
            }
            if (flag2)
            {
                Widgets.EndScrollView();
            }
            GUI.EndGroup();
            GUI.EndGroup();
        }
Пример #14
0
            public static bool DrawCharacterCardP(ref Rect rect, ref Pawn pawn, ref Action randomizeCallback, ref Rect creationRect)
            {
                rect.position = new Vector2(17f, 17f);
                rect.size     = new Vector2(cardX, cardY);
                bool flag = randomizeCallback != null;

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

                if (flag && nameTriple != null)
                {
                    Rect rect3 = new Rect(rectLabel);
                    rect3.width *= 0.333f;
                    Rect rect4 = new Rect(rectLabel);
                    rect4.width *= 0.333f;
                    rect4.x     += rect4.width;
                    Rect rect5 = new Rect(rectLabel);
                    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, 9);
                    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
                {
                    rectLabel.width = 999f;
                    Text.Font       = GameFont.Medium;
                    Widgets.Label(rectLabel, pawn.Name.ToStringFull);
                    Text.Font = GameFont.Small;
                }
                if (randomizeCallback != null)
                {
                    Rect rectRandomise = new Rect(creationRect.width - 24f - 100f, 0f, 100f, rectLabel.height);
                    if (Widgets.ButtonText(rectRandomise, "Randomize".Translate(), true, false, true))
                    {
                        SoundDefOf.TickTiny.PlayOneShotOnCamera(null);
                        randomizeCallback();
                    }
                    UIHighlighter.HighlightOpportunity(rectRandomise, "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 rectBanish = new Rect(num, 0f, 30f, 30f);
                        TooltipHandler.TipRegion(rectBanish, PawnBanishUtility.GetBanishButtonTip(pawn));
                        if (Widgets.ButtonImage(rectBanish, ContentFinder <Texture2D> .Get("UI/Buttons/Banish", true)))
                        {
                            if (pawn.Downed)
                            {
                                Messages.Message("MessageCantBanishDownedPawn".Translate(new object[]
                                {
                                    pawn.LabelShort
                                }).AdjustedFor(pawn), pawn, MessageTypeDefOf.RejectInput);
                            }
                            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, ContentFinder <Texture2D> .Get("UI/Buttons/Rename", true)))
                        {
                            Find.WindowStack.Add(new Dialog_ChangeNameTriple(pawn));
                        }
                        num -= 40f;
                    }
                }
                string label        = pawn.MainDesc(true);
                Rect   rectMainDesc = new Rect(0f, 45f, rect.width, 60f);

                Widgets.Label(rectMainDesc, label);
                Pawn p = pawn;

                TooltipHandler.TipRegion(rectMainDesc, () => p.ageTracker.AgeTooltipString, 6873641);
                Rect positionLeftHalf  = new Rect(0f, 100f, 250f, cardY);
                Rect positionRightHalf = new Rect(positionLeftHalf.xMax, 100f, 258f, cardY);

                GUI.BeginGroup(positionLeftHalf);
                float currentY = 0f;

                Text.Font = GameFont.Medium;
                Widgets.Label(new Rect(0f, 0f, 200f, 30f), "Backstory".Translate());
                currentY += 30f;
                Text.Font = GameFont.Small;
                foreach (BackstorySlot backstorySlot in Enum.GetValues(typeof(BackstorySlot)))
                {
                    Backstory backstory = pawn.story.GetBackstory(backstorySlot);
                    if (backstory != null)
                    {
                        Rect rect10 = new Rect(0f, currentY, positionLeftHalf.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 title = backstory.Title;
                        Widgets.Label(rect11, title);
                        currentY += rect10.height + 2f;
                    }
                }
                currentY += 25f;
                Text.Font = GameFont.Small;
                Widgets.Label(new Rect(0f, currentY, 200f, 30f), "IncapableOf".Translate());
                currentY += 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  = WorkTagsFrom(combinedDisabledWorkTags).ToList <WorkTags>();
                    bool            flag2 = true;
                    foreach (WorkTags current in list)
                    {
                        if (flag2)
                        {
                            stringBuilder.Append(current.LabelTranslated().CapitalizeFirst());
                        }
                        else
                        {
                            stringBuilder.Append(current.LabelTranslated());
                        }
                        stringBuilder.Append(", ");
                        flag2 = false;
                    }
                }
                string text = stringBuilder.ToString();

                text = text.Substring(0, text.Length - 2);
                Rect rect12 = new Rect(0f, currentY, positionLeftHalf.width, 999f);

                Widgets.Label(rect12, text);
                currentY += 100f;
                Text.Font = GameFont.Medium;
                Widgets.Label(new Rect(0f, currentY, 200f, 30f), "Traits".Translate());
                currentY += 30f;
                Text.Font = GameFont.Small;
                for (int i = 0; i < pawn.story.traits.allTraits.Count; i++)
                {
                    Trait trait            = pawn.story.traits.allTraits[i];
                    Rect  rectCurrentTrait = new Rect(0f, currentY, positionLeftHalf.width, 24f);
                    if (Mouse.IsOver(rectCurrentTrait))
                    {
                        Widgets.DrawHighlight(rectCurrentTrait);
                    }
                    Widgets.Label(rectCurrentTrait, trait.LabelCap);
                    currentY += rectCurrentTrait.height + 2f;
                    Trait     trLocal = trait;
                    TipSignal tip     = new TipSignal(() => trLocal.TipString(p), (int)currentY * 37);
                    TooltipHandler.TipRegion(rectCurrentTrait, tip);
                }
                GUI.EndGroup();
                GUI.BeginGroup(positionRightHalf);
                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();

                return(false);
            }