Exemplo n.º 1
0
        public static void Postfix(Designator_Build __instance, ref string __result)
        {
            try
            {
                BuildableDef entDef   = Traverse.Create(__instance)?.Field("entDef")?.GetValue <BuildableDef>();
                ThingDef     stuffDef = Traverse.Create(__instance)?.Field("stuffDef")?.GetValue <ThingDef>();

                string walkspeed   = "";
                string fertility   = "";
                string beauty      = "";
                string cleanliness = "";

                //FertileFields terraforming
                if (MoreInfoBox.fertileFields)
                {
                    entDef = TryGetFertileFieldsTerrainDef(entDef);
                }

                if (entDef is TerrainDef)
                {
                    if (entDef.passability != Traversability.Impassable)
                    {
                        walkspeed = "MIB.Speed".Translate(SpeedPercentString(entDef.pathCost));
                    }
                    else
                    {
                        walkspeed = "MIB.Impassable".Translate();
                    }

                    if (entDef.fertility > 0)
                    {
                        fertility =
                            "MIB.Fertility".Translate(entDef.fertility.ToStringPercent());
                    }
                }

                if (entDef.HasStat(StatDefOf.Beauty))
                {
                    beauty = "MIB.Beauty".Translate(entDef.GetStat(stuffDef, StatDefOf.Beauty).ToStringByStyle(ToStringStyle.Integer));
                }

                if (entDef.HasStat(StatDefOf.Cleanliness))
                {
                    cleanliness = "MIB.Cleanliness".Translate(entDef.GetStat(stuffDef, StatDefOf.Cleanliness).ToStringByStyle(ToStringStyle.FloatOne));
                }

                //extra linebreak
                bool extraLineBreak = Text.Font == GameFont.Tiny;
                if (extraLineBreak)
                {
                    var tmp = Text.Font;
                    Text.Font      = GameFont.Small;
                    extraLineBreak = Text.CalcHeight(__instance.LabelCap, ArchitectCategoryTab.InfoRect.width - 7 * 2) > 25;
                    Text.Font      = tmp;
                }

                __result = (extraLineBreak ? "\n" : "") + walkspeed + fertility + beauty + cleanliness + "\n" + __result;
            }
            catch (Exception e)
            {
                Log.Error(e.ToString());
            }
        }