Ejemplo n.º 1
0
        private static float DrawFactionRow(Faction faction, float rowY, Rect fillRect)
        {
            Rect          rect          = new Rect(35f, rowY, 300f, 160f);
            StringBuilder stringBuilder = new StringBuilder();
            RimWarData    rwd           = WorldUtility.GetRimWarDataForFaction(faction);

            if (rwd != null && faction != null)
            {
                bool canDeclareWar      = !rwd.IsAtWarWith(Faction.OfPlayer);
                bool canDeclareAlliance = faction.PlayerRelationKind == FactionRelationKind.Ally && !rwd.AllianceFactions.Contains(Faction.OfPlayer);
                foreach (Faction item in Find.FactionManager.AllFactionsInViewOrder)
                {
                    if (item != faction && ((!item.IsPlayer && !item.def.hidden)) && faction.HostileTo(item))
                    {
                        stringBuilder.Append("HostileTo".Translate(item.Name));
                        stringBuilder.AppendLine();
                    }
                    else if (item != faction && ((!item.IsPlayer && !item.def.hidden)) && faction.RelationKindWith(item) == FactionRelationKind.Ally)
                    {
                        stringBuilder.Append("RW_AllyTo".Translate(item.Name));
                        stringBuilder.AppendLine();
                    }
                    else if (item != faction && ((!item.IsPlayer && !item.def.hidden)) && faction.RelationKindWith(item) == FactionRelationKind.Neutral)
                    {
                        stringBuilder.Append("RW_NeutralTo".Translate(item.Name));
                        stringBuilder.AppendLine();
                    }
                }
                string text     = stringBuilder.ToString();
                float  width    = fillRect.width - rect.xMax;
                float  num      = Text.CalcHeight(text, width);
                float  num2     = Mathf.Max(160f, num);
                Rect   position = new Rect(10f, rowY + 10f, 15f, 15f);
                Rect   rect2    = new Rect(0f, rowY, fillRect.width, num2);
                if (Mouse.IsOver(rect2))
                {
                    GUI.DrawTexture(rect2, TexUI.HighlightTex);
                }
                Text.Font   = GameFont.Small;
                Text.Anchor = TextAnchor.UpperLeft;
                //Widgets.DrawRectFast(position, faction.Color);
                FactionUIUtility.DrawFactionIconWithTooltip(position, faction);
                string label = faction.Name.CapitalizeFirst() + "\n" + faction.def.LabelCap + "\n" + ((faction.leader == null) ? string.Empty : (faction.def.leaderTitle.CapitalizeFirst() + ": "
                                                                                                                                                 + faction.leader.Name.ToStringFull))
                               + "\n" + "RW_FactionBehavior".Translate(rwd == null ? RimWarBehavior.Undefined.ToString() : rwd.behavior.ToString())
                               + "\n" + "RW_FactionPower".Translate(rwd == null ? 0 : rwd.TotalFactionPoints)
                               + "\n" + "RW_SettlementCount".Translate((rwd != null && rwd.FactionSettlements != null && rwd.FactionSettlements.Count > 0) ? rwd.FactionSettlements.Count : 0)
                               + "\n" + "RW_WarObjectCount".Translate((rwd != null && WorldUtility.GetWarObjectsInFaction(faction) != null) ? WorldUtility.GetWarObjectsInFaction(faction).Count : 0)
                               + ((faction != WorldUtility.Get_WCPT().victoryFaction) ? string.Empty : "\n" + (string)"RW_RivalFaction".Translate());
                Widgets.Label(rect, label);
                Rect rect3 = new Rect(rect.xMax, rowY, 40f, 80f);   //Rect rect3 = new Rect(rect.xMax, rowY, 60f, 80f);
                Widgets.InfoCardButton(rect3.x, rect3.y, faction.def);
                Rect rect4 = new Rect(rect3.xMax, rowY, 120f, 80f); //Rect rect4 = new Rect(rect3.xMax, rowY, 250f, 80f);
                if (!faction.IsPlayer)
                {
                    string str = faction.HasGoodwill ? (faction.PlayerGoodwill.ToStringWithSign() + "\n") : "";
                    str += faction.PlayerRelationKind.GetLabel();
                    if (faction.defeated)
                    {
                        str = str + "\n(" + "DefeatedLower".Translate() + ")";
                    }
                    GUI.color = faction.PlayerRelationKind.GetColor();
                    Widgets.Label(rect4, str);
                    GUI.color = Color.white;
                    string str2 = "CurrentGoodwillTip".Translate();
                    if (faction.def.permanentEnemy)
                    {
                        str2 = str2 + "\n\n" + "CurrentGoodwillTip_PermanentEnemy".Translate();
                    }
                    else
                    {
                        str2 += "\n\n";
                        switch (faction.PlayerRelationKind)
                        {
                        case FactionRelationKind.Ally:
                            str2 += "CurrentGoodwillTip_Ally".Translate(0.ToString("F0"));
                            break;

                        case FactionRelationKind.Neutral:
                            str2 += "CurrentGoodwillTip_Neutral".Translate((-75).ToString("F0"), 75.ToString("F0"));
                            break;

                        case FactionRelationKind.Hostile:
                            str2 += "CurrentGoodwillTip_Hostile".Translate(0.ToString("F0"));
                            break;
                        }
                        if (faction.def.goodwillDailyGain > 0f || faction.def.goodwillDailyFall > 0f)
                        {
                            float num3 = faction.def.goodwillDailyGain * 60f;
                            float num4 = faction.def.goodwillDailyFall * 60f;
                            str2 += "\n\n" + "CurrentGoodwillTip_NaturalGoodwill".Translate(faction.def.naturalColonyGoodwill.min.ToString("F0"), faction.def.naturalColonyGoodwill.max.ToString("F0"));
                            if (faction.def.naturalColonyGoodwill.min > -100)
                            {
                                str2 += " " + "CurrentGoodwillTip_NaturalGoodwillRise".Translate(faction.def.naturalColonyGoodwill.min.ToString("F0"), num3.ToString("F0"));
                            }
                            if (faction.def.naturalColonyGoodwill.max < 100)
                            {
                                str2 += " " + "CurrentGoodwillTip_NaturalGoodwillFall".Translate(faction.def.naturalColonyGoodwill.max.ToString("F0"), num4.ToString("F0"));
                            }
                        }
                    }
                    TooltipHandler.TipRegion(rect4, str2);
                }
                Rect rect6 = new Rect(rect4.xMax, rowY + 10, 100f, 28f);
                if (canDeclareWar)
                {
                    bool declareWar = Widgets.ButtonText(rect6, "War", canDeclareWar, false, canDeclareWar);
                    if (declareWar)
                    {
                        DeclareWarOn(Faction.OfPlayer, faction);
                    }
                    TooltipHandler.TipRegion(rect6, "RW_DeclareWarWarning".Translate());
                }
                else
                {
                    bool declarePeace = Widgets.ButtonText(rect6, "Peace", faction.GoodwillWith(Faction.OfPlayer) >= -75, false, true);
                    if (declarePeace && faction.GoodwillWith(Faction.OfPlayer) >= -75)
                    {
                        DeclarePeaceWith(Faction.OfPlayer, faction);
                    }
                    if (faction.GoodwillWith(Faction.OfPlayer) < -75)
                    {
                        TooltipHandler.TipRegion(rect6, "RW_DeclarePeaceInfo".Translate(faction.GoodwillWith(Faction.OfPlayer)));
                    }
                    else
                    {
                        TooltipHandler.TipRegion(rect6, "RW_DeclarePeaceWarning".Translate());
                    }
                }

                Rect rect7 = new Rect(rect4.xMax, rowY + 10 + rect6.height, 100f, 28f);
                if (!rwd.IsAtWarWith(Faction.OfPlayer))
                {
                    bool declareAlly = Widgets.ButtonText(rect7, "Alliance", canDeclareAlliance, false, true);
                    if (declareAlly && canDeclareAlliance)
                    {
                        DeclareAllianceWith(Faction.OfPlayer, faction);
                    }
                    if (canDeclareAlliance)
                    {
                        TooltipHandler.TipRegion(rect7, "RW_DeclareAllianceWarning".Translate());
                    }
                    else
                    {
                        StringBuilder strAlly = new StringBuilder();
                        if (!rwd.IsAlliedWith(Faction.OfPlayer))
                        {
                            if (faction.PlayerRelationKind != FactionRelationKind.Ally)
                            {
                                strAlly.Append("RW_Reason_NotAlly".Translate() + "\n");
                            }
                            List <RimWarData> rwdList        = WorldUtility.GetRimWarData();
                            string            alliedFactions = "";
                            for (int i = 0; i < rwdList.Count; i++)
                            {
                                if (rwdList[i].AllianceFactions.Contains(Faction.OfPlayer) && faction.HostileTo(rwdList[i].RimWarFaction))
                                {
                                    alliedFactions += rwdList[i].RimWarFaction.Name + "\n";
                                }
                            }
                            strAlly.Append(alliedFactions);
                        }
                        else
                        {
                            strAlly.Append("RW_Reason_AlreadyAllied".Translate());
                        }
                        TooltipHandler.TipRegion(rect7, "RW_DeclareAllianceInfo".Translate(strAlly));
                    }
                }
                Rect rect5 = new Rect(rect6.xMax + 20, rowY, width, num);
                Widgets.Label(rect5, text);
                Text.Anchor = TextAnchor.UpperLeft;

                return(num2);
            }
            return(0f);
        }
Ejemplo n.º 2
0
        private static void DrawButtons(Rect rect, ref float lineEndWidth)
        {
            if (Find.Selector.NumSelected != 1)
            {
                return;
            }
            var selected = Find.Selector.SingleSelectedThing;

            if (selected == null)
            {
                return;
            }

            lineEndWidth += ButtonSize;
            Widgets.InfoCardButton(rect.width - lineEndWidth, 0f, selected);

            if (!(selected is Pawn pawn))
            {
                return;
            }

            if (Theme.ShowFactionIcon.Value && pawn.Faction != null)
            {
                lineEndWidth += ButtonSize;
                var factionRect = new Rect(rect.width - lineEndWidth, 0f, ButtonSize, ButtonSize);
                FactionUIUtility.DrawFactionIconWithTooltip(factionRect, pawn.Faction);
                lineEndWidth += GUIPlus.SmallPadding;
            }

            if (Theme.ShowIdeoligionIcon.Value && ModLister.IdeologyInstalled && pawn.Ideo != null)
            {
                lineEndWidth += ButtonSize;
                var ideoligionRect = new Rect(rect.width - lineEndWidth, 0f, ButtonSize, ButtonSize);
                IdeoUIUtility.DoIdeoIcon(ideoligionRect, pawn.Ideo, extraAction: () => IdeoUIUtility.OpenIdeoInfo(pawn.Ideo));
                lineEndWidth += GUIPlus.SmallPadding;
            }

            if (!PlayerControlled(pawn))
            {
                return;
            }

            lineEndWidth += GUIPlus.SmallPadding;

            if (pawn.playerSettings.UsesConfigurableHostilityResponse)
            {
                lineEndWidth += ButtonSize;
                HostilityResponseModeUtility.DrawResponseButton(new Rect(rect.width - lineEndWidth, 0f, ButtonSize, ButtonSize), pawn, false);
                lineEndWidth += GUIPlus.SmallPadding;
            }

            lineEndWidth += ButtonSize;
            var careRect = new Rect(rect.width - lineEndWidth, 0f, ButtonSize, ButtonSize);

            MedicalCareUtility.MedicalCareSelectButton(careRect, pawn);
            GUIPlus.DrawTooltip(careRect, () => Lang.Get("InspectPane.MedicalCare", pawn.KindLabel, pawn.playerSettings.medCare.GetLabel()), true);
            lineEndWidth += GUIPlus.SmallPadding;

            if (!pawn.IsColonist)
            {
                return;
            }

            lineEndWidth += ButtonSize;

            var canDoctor         = !pawn.WorkTypeIsDisabled(WorkTypeDefOf.Doctor);
            var canDoctorPriority = pawn.workSettings == null || pawn.workSettings?.GetPriority(WorkTypeDefOf.Doctor) > 0;

            var selfTendRect = new Rect(rect.width - lineEndWidth, 0f, ButtonSize, ButtonSize);
            var selfTendTip  = "SelfTendTip".Translate(Faction.OfPlayer.def.pawnsPlural, 0.7f.ToStringPercent()).CapitalizeFirst();

            if (!canDoctor)
            {
                selfTendTip += "\n\n" + "MessageCannotSelfTendEver".Translate(pawn.LabelShort, pawn);
            }
            else if (!canDoctorPriority)
            {
                selfTendTip += "\n\n" + "MessageSelfTendUnsatisfied".Translate(pawn.LabelShort, pawn);
            }

            GUIPlus.SetFont(GameFont.Tiny);
            var selfTend = pawn.playerSettings.selfTend;

            selfTend = GUIPlus.DrawToggle(selfTendRect, selfTend, GUIPlus.PrepareTipSignal(() => selfTendTip), canDoctor, Textures.SelfTendOnIcon, Textures.SelfTendOffIcon);
            if (selfTend != pawn.playerSettings.selfTend)
            {
                Mod_Multiplayer.SetSelfTend(pawn, selfTend);
            }
            GUIPlus.ResetFont();
            lineEndWidth += GUIPlus.SmallPadding;
        }