Exemplo n.º 1
0
        private static IEnumerable <StatDrawEntry> StatsToDraw(AbilityDef def)
        {
            yield return(DescriptionEntry(def));

            StatRequest statRequest = StatRequest.For(def);

            foreach (StatDef item in DefDatabase <StatDef> .AllDefs.Where((StatDef st) => st.Worker.ShouldShowFor(statRequest)))
            {
                yield return(new StatDrawEntry(item.category, item, def.GetStatValueAbstract(item), StatRequest.For(def)));
            }
        }
Exemplo n.º 2
0
        private static void DrawStatsWorker(Rect rect, Thing optionalThing, WorldObject optionalWorldObject)
        {
            Rect outRect = new Rect(rect);

            outRect.width *= 0.5f;
            Rect rect2 = new Rect(rect);

            rect2.x     = outRect.xMax;
            rect2.width = rect.xMax - rect2.x;
            Text.Font   = GameFont.Small;
            Rect viewRect = new Rect(0f, 0f, outRect.width - 16f, StatsReportUtility.listHeight);

            Widgets.BeginScrollView(outRect, ref StatsReportUtility.scrollPosition, viewRect, true);
            float  num = 0f;
            string b   = null;

            foreach (StatDrawEntry ent in StatsReportUtility.cachedDrawEntries)
            {
                if (ent.category.LabelCap != b)
                {
                    Widgets.ListSeparator(ref num, viewRect.width, ent.category.LabelCap);
                    b = ent.category.LabelCap;
                }
                num += ent.Draw(8f, num, viewRect.width - 8f, StatsReportUtility.selectedEntry == ent, delegate
                {
                    StatsReportUtility.SelectEntry(ent, true);
                });
            }
            StatsReportUtility.listHeight = num + 100f;
            Widgets.EndScrollView();
            Rect rect3 = rect2.ContractedBy(10f);

            GUI.BeginGroup(rect3);
            if (StatsReportUtility.selectedEntry != null)
            {
                StatRequest optionalReq;
                if (StatsReportUtility.selectedEntry.hasOptionalReq)
                {
                    optionalReq = StatsReportUtility.selectedEntry.optionalReq;
                }
                else if (optionalThing != null)
                {
                    optionalReq = StatRequest.For(optionalThing);
                }
                else
                {
                    optionalReq = StatRequest.ForEmpty();
                }
                string explanationText = StatsReportUtility.selectedEntry.GetExplanationText(optionalReq);
                Rect   rect4           = rect3.AtZero();
                Widgets.Label(rect4, explanationText);
            }
            GUI.EndGroup();
        }
Exemplo n.º 3
0
 public static void DrawStatsReport(Rect rect, RoyalTitleDef title, Faction faction)
 {
     if (cachedDrawEntries.NullOrEmpty())
     {
         cachedDrawEntries.AddRange(title.SpecialDisplayStats(StatRequest.For(title, faction)));
         cachedDrawEntries.AddRange(from r in StatsToDraw(title, faction)
                                    where r.ShouldDisplay
                                    select r);
         FinalizeCachedDrawEntries(cachedDrawEntries);
     }
     DrawStatsWorker(rect, null, null);
 }
Exemplo n.º 4
0
 public override float GetValueUnfinalized(StatRequest req, bool applyPostProcess = true)
 {
     if (req.HasThing && req.Thing is Pawn)
     {
         return(base.GetValueUnfinalized(StatRequest.For(req.BuildableDef, req.StuffDef), applyPostProcess) * PriceUtility.PawnQualityPriceFactor((Pawn)req.Thing) + PriceUtility.PawnQualityPriceOffset((Pawn)req.Thing));
     }
     if (req.StatBases.StatListContains(StatDefOf.MarketValue))
     {
         return(base.GetValueUnfinalized(req));
     }
     return(CalculatedBaseMarketValue(req.BuildableDef, req.StuffDef));
 }
Exemplo n.º 5
0
 public static void DrawStatsReport(Rect rect, Thing thing)
 {
     if (cachedDrawEntries.NullOrEmpty())
     {
         cachedDrawEntries.AddRange(thing.def.SpecialDisplayStats(StatRequest.For(thing)));
         cachedDrawEntries.AddRange(from r in StatsToDraw(thing)
                                    where r.ShouldDisplay
                                    select r);
         cachedDrawEntries.RemoveAll((StatDrawEntry de) => de.stat != null && !de.stat.showNonAbstract);
         FinalizeCachedDrawEntries(cachedDrawEntries);
     }
     DrawStatsWorker(rect, thing, null);
 }
Exemplo n.º 6
0
 public static void DrawStatsReport(Rect rect, Def def, ThingDef stuff)
 {
     if (cachedDrawEntries.NullOrEmpty())
     {
         BuildableDef buildableDef = def as BuildableDef;
         StatRequest  req          = (buildableDef != null) ? StatRequest.For(buildableDef, stuff) : StatRequest.ForEmpty();
         cachedDrawEntries.AddRange(def.SpecialDisplayStats(req));
         cachedDrawEntries.AddRange(from r in StatsToDraw(def, stuff)
                                    where r.ShouldDisplay
                                    select r);
         FinalizeCachedDrawEntries(cachedDrawEntries);
     }
     DrawStatsWorker(rect, null, null);
 }
Exemplo n.º 7
0
        private static IEnumerable <StatDrawEntry> StatsToDraw(Def def, ThingDef stuff)
        {
            yield return(DescriptionEntry(def));

            BuildableDef eDef = def as BuildableDef;

            if (eDef != null)
            {
                StatRequest statRequest = StatRequest.For(eDef, stuff);
                foreach (StatDef item in DefDatabase <StatDef> .AllDefs.Where((StatDef st) => st.Worker.ShouldShowFor(statRequest)))
                {
                    yield return(new StatDrawEntry(item.category, item, eDef.GetStatValueAbstract(item, stuff), StatRequest.For(eDef, stuff)));
                }
            }
        }
Exemplo n.º 8
0
        private static IEnumerable <StatDrawEntry> StatsToDraw(Def def, ThingDef stuff)
        {
            yield return(StatsReportUtility.DescriptionEntry(def));

            BuildableDef eDef = def as BuildableDef;

            if (eDef != null)
            {
                StatRequest statRequest = StatRequest.For(eDef, stuff, QualityCategory.Normal);
                foreach (StatDef stat in from st in DefDatabase <StatDef> .AllDefs
                         where st.Worker.ShouldShowFor(statRequest)
                         select st)
                {
                    yield return(new StatDrawEntry(stat.category, stat, eDef.GetStatValueAbstract(stat, stuff), StatRequest.For(eDef, stuff, QualityCategory.Normal), ToStringNumberSense.Undefined));
                }
            }
        }
        public static float GetMinMarketValue(ThingDef thingDef, TechLevel stuffTechLevel)
        {
            float num = float.MaxValue;

            if (thingDef.MadeFromStuff)
            {
                foreach (ThingDef item in GenStuff.AllowedStuffsFor(thingDef, stuffTechLevel))
                {
                    if (item.stuffProps.commonality > 0f)
                    {
                        num = Mathf.Min(num, StatDefOf.MarketValue.Worker.GetValue(StatRequest.For(thingDef, item, QualityCategory.Awful)));
                    }
                }
                return(num);
            }
            return(Mathf.Min(num, StatDefOf.MarketValue.Worker.GetValue(StatRequest.For(thingDef, null, QualityCategory.Awful))));
        }
Exemplo n.º 10
0
        public override float GetValueUnfinalized(StatRequest req, bool applyPostProcess = true)
        {
            float result;

            if (req.HasThing && req.Thing is Pawn)
            {
                result = base.GetValueUnfinalized(StatRequest.For(req.Def, req.StuffDef, QualityCategory.Normal), applyPostProcess) * PriceUtility.PawnQualityPriceFactor((Pawn)req.Thing);
            }
            else if (req.Def.statBases.StatListContains(StatDefOf.MarketValue))
            {
                result = base.GetValueUnfinalized(req, true);
            }
            else
            {
                result = StatWorker_MarketValue.CalculatedMarketValue(req.Def, req.StuffDef);
            }
            return(result);
        }
Exemplo n.º 11
0
        public static float StatOffsetFromGear(Thing gear, StatDef stat)
        {
            float val = gear.def.equippedStatOffsets.GetStatOffsetFromList(stat);
            CompBladelinkWeapon compBladelinkWeapon = gear.TryGetComp <CompBladelinkWeapon>();

            if (compBladelinkWeapon != null)
            {
                List <WeaponTraitDef> traitsListForReading = compBladelinkWeapon.TraitsListForReading;
                for (int i = 0; i < traitsListForReading.Count; i++)
                {
                    val += traitsListForReading[i].equippedStatOffsets.GetStatOffsetFromList(stat);
                }
            }
            if (Math.Abs(val) > float.Epsilon && !stat.parts.NullOrEmpty())
            {
                foreach (StatPart part in stat.parts)
                {
                    part.TransformValue(StatRequest.For(gear), ref val);
                }
                return(val);
            }
            return(val);
        }
 public float GetStatValue(StatDef stat)
 {
     return(stat.Worker.GetValue(StatRequest.For(this.thing, this.stuff, this.Quality), true));
 }
Exemplo n.º 13
0
        private static IEnumerable <StatDrawEntry> StatsToDraw(Thing thing)
        {
            yield return(DescriptionEntry(thing));

            StatDrawEntry statDrawEntry = QualityEntry(thing);

            if (statDrawEntry != null)
            {
                yield return(statDrawEntry);
            }
            foreach (StatDef item in DefDatabase <StatDef> .AllDefs.Where((StatDef st) => st.Worker.ShouldShowFor(StatRequest.For(thing))))
            {
                if (!item.Worker.IsDisabledFor(thing))
                {
                    float statValue = thing.GetStatValue(item);
                    if (item.showOnDefaultValue || statValue != item.defaultBaseValue)
                    {
                        yield return(new StatDrawEntry(item.category, item, statValue, StatRequest.For(thing)));
                    }
                }
                else
                {
                    yield return(new StatDrawEntry(item.category, item));
                }
            }
            if (thing.def.useHitPoints)
            {
                yield return(new StatDrawEntry(StatCategoryDefOf.BasicsImportant, "HitPointsBasic".Translate().CapitalizeFirst(), thing.HitPoints.ToString() + " / " + thing.MaxHitPoints.ToString(), "Stat_HitPoints_Desc".Translate(), 99998));
            }
            foreach (StatDrawEntry item2 in thing.SpecialDisplayStats())
            {
                yield return(item2);
            }
            if (!thing.def.IsStuff)
            {
                yield break;
            }
            if (!thing.def.stuffProps.statFactors.NullOrEmpty())
            {
                for (int j = 0; j < thing.def.stuffProps.statFactors.Count; j++)
                {
                    yield return(new StatDrawEntry(StatCategoryDefOf.StuffStatFactors, thing.def.stuffProps.statFactors[j].stat, thing.def.stuffProps.statFactors[j].value, StatRequest.ForEmpty(), ToStringNumberSense.Factor));
                }
            }
            if (!thing.def.stuffProps.statOffsets.NullOrEmpty())
            {
                for (int j = 0; j < thing.def.stuffProps.statOffsets.Count; j++)
                {
                    yield return(new StatDrawEntry(StatCategoryDefOf.StuffStatOffsets, thing.def.stuffProps.statOffsets[j].stat, thing.def.stuffProps.statOffsets[j].value, StatRequest.ForEmpty(), ToStringNumberSense.Offset));
                }
            }
        }
Exemplo n.º 14
0
        private static void DrawStatsWorker(Rect rect, Thing optionalThing, WorldObject optionalWorldObject)
        {
            Rect rect2 = new Rect(rect);

            rect2.width *= 0.5f;
            Rect rect3 = new Rect(rect);

            rect3.x     = rect2.xMax;
            rect3.width = rect.xMax - rect3.x;
            Text.Font   = GameFont.Small;
            Rect viewRect = new Rect(0f, 0f, rect2.width - 16f, listHeight);

            Widgets.BeginScrollView(rect2, ref scrollPosition, viewRect);
            float  curY = 0f;
            string b    = null;

            mousedOverEntry = null;
            for (int i = 0; i < cachedDrawEntries.Count; i++)
            {
                StatDrawEntry ent = cachedDrawEntries[i];
                if ((string)ent.category.LabelCap != b)
                {
                    Widgets.ListSeparator(ref curY, viewRect.width, ent.category.LabelCap);
                    b = ent.category.LabelCap;
                }
                curY += ent.Draw(8f, curY, viewRect.width - 8f, selectedEntry == ent, delegate
                {
                    SelectEntry(ent);
                }, delegate
                {
                    mousedOverEntry = ent;
                }, scrollPosition, rect2);
            }
            listHeight = curY + 100f;
            Widgets.EndScrollView();
            Rect          outRect       = rect3.ContractedBy(10f);
            StatDrawEntry statDrawEntry = selectedEntry ?? mousedOverEntry ?? cachedDrawEntries.FirstOrDefault();

            if (statDrawEntry != null)
            {
                Rect        rect4           = new Rect(0f, 0f, outRect.width - 16f, rightPanelHeight);
                StatRequest statRequest     = statDrawEntry.hasOptionalReq ? statDrawEntry.optionalReq : ((optionalThing == null) ? StatRequest.ForEmpty() : StatRequest.For(optionalThing));
                string      explanationText = statDrawEntry.GetExplanationText(statRequest);
                float       num             = 0f;
                Widgets.BeginScrollView(outRect, ref scrollPositionRightPanel, rect4);
                Rect rect5 = rect4;
                rect5.width -= 4f;
                Widgets.Label(rect5, explanationText);
                float num2 = Text.CalcHeight(explanationText, rect5.width) + 10f;
                num += num2;
                IEnumerable <Dialog_InfoCard.Hyperlink> hyperlinks = statDrawEntry.GetHyperlinks(statRequest);
                if (hyperlinks != null)
                {
                    Rect  rect6 = new Rect(rect5.x, rect5.y + num2, rect5.width, rect5.height - num2);
                    Color color = GUI.color;
                    GUI.color = Widgets.NormalOptionColor;
                    foreach (Dialog_InfoCard.Hyperlink item in hyperlinks)
                    {
                        float num3 = Text.CalcHeight(item.Label, rect6.width);
                        Widgets.HyperlinkWithIcon(new Rect(rect6.x, rect6.y, rect6.width, num3), item, "ViewHyperlink".Translate(item.Label));
                        rect6.y      += num3;
                        rect6.height -= num3;
                        num          += num3;
                    }
                    GUI.color = color;
                }
                rightPanelHeight = num;
                Widgets.EndScrollView();
            }
        }
Exemplo n.º 15
0
 public float GetValue(Thing thing, bool applyPostProcess = true)
 {
     return(this.GetValue(StatRequest.For(thing), true));
 }
        private Thing GenerateReward(float value, TechLevel techLevel, Predicate <ThingDef> validator = null)
        {
            if (Rand.Chance(0.5f) && (validator == null || validator(ThingDefOf.Silver)))
            {
                Thing thing = ThingMaker.MakeThing(ThingDefOf.Silver, null);
                thing.stackCount = ThingUtility.RoundedResourceStackCount(Mathf.Max(GenMath.RoundRandom(value), 1));
                return(thing);
            }
            ThingDef thingDef = default(ThingDef);

            if (Rand.Chance(0.35f) && (from x in ItemCollectionGeneratorUtility.allGeneratableItems
                                       where x.itemGeneratorTags != null && x.itemGeneratorTags.Contains(ItemCollectionGeneratorUtility.SpecialRewardTag) && (validator == null || validator(x)) && Mathf.Abs((float)(1.0 - x.BaseMarketValue / value)) <= 0.34999999403953552
                                       select x).TryRandomElement <ThingDef>(out thingDef))
            {
                Thing       thing2      = ThingMaker.MakeThing(thingDef, GenStuff.RandomStuffFor(thingDef));
                CompQuality compQuality = thing2.TryGetComp <CompQuality>();
                if (compQuality != null)
                {
                    compQuality.SetQuality(QualityUtility.RandomBaseGenItemQuality(), ArtGenerationContext.Outsider);
                }
                return(thing2);
            }
            if (Rand.Chance(0.13f))
            {
                float    minExpensiveMineableResourceMarketValue = ThingDefOf.Uranium.BaseMarketValue;
                ThingDef thingDef2 = default(ThingDef);
                if ((from x in ItemCollectionGenerator_Meteorite.mineables
                     where x.building.isResourceRock && x.building.mineableThing.BaseMarketValue >= minExpensiveMineableResourceMarketValue && (validator == null || validator(x.building.mineableThing))
                     select x).TryRandomElement <ThingDef>(out thingDef2))
                {
                    float    num           = (float)(value * 0.89999997615814209);
                    ThingDef mineableThing = thingDef2.building.mineableThing;
                    Thing    thing3        = ThingMaker.MakeThing(mineableThing, null);
                    thing3.stackCount = Mathf.Max(GenMath.RoundRandom(num / mineableThing.BaseMarketValue), 1);
                    return(thing3);
                }
            }
            Option option2 = (from option in ItemCollectionGeneratorUtility.allGeneratableItems.Select(delegate(ThingDef td)
            {
                if ((int)td.techLevel > (int)techLevel)
                {
                    return(null);
                }
                if (td.itemGeneratorTags != null && td.itemGeneratorTags.Contains(ItemCollectionGeneratorUtility.SpecialRewardTag))
                {
                    return(null);
                }
                if (!td.IsWithinCategory(ThingCategoryDefOf.Apparel) && !td.IsWithinCategory(ThingCategoryDefOf.Weapons) && !td.IsWithinCategory(ThingCategoryDefOf.Art) && (td.building == null || !td.Minifiable) && (td.tradeTags == null || !td.tradeTags.Contains("Exotic")))
                {
                    return(null);
                }
                if (validator != null && !validator(td))
                {
                    return(null);
                }
                ThingDef stuff = null;
                if (td.MadeFromStuff && !GenStuff.TryRandomStuffByCommonalityFor(td, out stuff, techLevel))
                {
                    return(null);
                }
                Option option3 = new Option();
                option3.thingDef = td;
                option3.quality = ((!td.HasComp(typeof(CompQuality))) ? QualityCategory.Normal : QualityUtility.RandomQuality());
                option3.stuff = stuff;
                return(option3);
            })
                              where option != null
                              select option).MinBy(delegate(Option option)
            {
                float value2 = StatDefOf.MarketValue.Worker.GetValue(StatRequest.For(option.thingDef, option.stuff, option.quality), true);
                return(Mathf.Abs(value - value2));
            });
            Thing       thing4       = ThingMaker.MakeThing(option2.thingDef, option2.stuff);
            CompQuality compQuality2 = thing4.TryGetComp <CompQuality>();

            if (compQuality2 != null)
            {
                compQuality2.SetQuality(option2.quality, ArtGenerationContext.Outsider);
            }
            return(thing4);
        }
Exemplo n.º 17
0
 public float GetValueAbstract(BuildableDef def, ThingDef stuffDef = null)
 {
     return(GetValue(StatRequest.For(def, stuffDef)));
 }
Exemplo n.º 18
0
 public float GetValueAbstract(BuildableDef def, ThingDef stuffDef = null)
 {
     return(this.GetValue(StatRequest.For(def, stuffDef, QualityCategory.Normal), true));
 }
            public bool MoveNext()
            {
                uint num = (uint)this.$PC;

                this.$PC = -1;
                bool flag = false;

                switch (num)
                {
                case 0u:
                    this.$current = StatsReportUtility.DescriptionEntry(def);
                    if (!this.$disposing)
                    {
                        this.$PC = 1;
                    }
                    return(true);

                case 1u:
                {
                    eDef = (def as BuildableDef);
                    if (eDef == null)
                    {
                        goto IL_179;
                    }
                    StatRequest statRequest = StatRequest.For(eDef, stuff, QualityCategory.Normal);
                    enumerator = (from st in DefDatabase <StatDef> .AllDefs
                                  where st.Worker.ShouldShowFor(statRequest)
                                  select st).GetEnumerator();
                    num = 4294967293u;
                    break;
                }

                case 2u:
                    break;

                default:
                    return(false);
                }
                try
                {
                    switch (num)
                    {
                    }
                    if (enumerator.MoveNext())
                    {
                        stat          = enumerator.Current;
                        this.$current = new StatDrawEntry(stat.category, stat, eDef.GetStatValueAbstract(stat, stuff), StatRequest.For(eDef, stuff, QualityCategory.Normal), ToStringNumberSense.Undefined);
                        if (!this.$disposing)
                        {
                            this.$PC = 2;
                        }
                        flag = true;
                        return(true);
                    }
                }
                finally
                {
                    if (!flag)
                    {
                        if (enumerator != null)
                        {
                            enumerator.Dispose();
                        }
                    }
                }
IL_179:
                this.$PC = -1;
                return(false);
            }
Exemplo n.º 20
0
 public static void DrawStatsReport(Rect rect, Def def, ThingDef stuff)
 {
     if (StatsReportUtility.cachedDrawEntries.NullOrEmpty <StatDrawEntry>())
     {
         BuildableDef buildableDef = def as BuildableDef;
         StatRequest  req          = (buildableDef == null) ? StatRequest.ForEmpty() : StatRequest.For(buildableDef, stuff, QualityCategory.Normal);
         StatsReportUtility.cachedDrawEntries.AddRange(def.SpecialDisplayStats(req));
         StatsReportUtility.cachedDrawEntries.AddRange(from r in StatsReportUtility.StatsToDraw(def, stuff)
                                                       where r.ShouldDisplay
                                                       select r);
         StatsReportUtility.FinalizeCachedDrawEntries(StatsReportUtility.cachedDrawEntries);
     }
     StatsReportUtility.DrawStatsWorker(rect, null, null);
 }
        private static IEnumerable <StatDrawEntry> StatsToDraw(Thing thing)
        {
            yield return(StatsReportUtility.DescriptionEntry(thing));

            StatDrawEntry qe = StatsReportUtility.QualityEntry(thing);

            if (qe != null)
            {
                yield return(qe);
            }
            foreach (StatDef stat in from st in DefDatabase <StatDef> .AllDefs
                     where st.Worker.ShouldShowFor(StatRequest.For(thing))
                     select st)
            {
                if (!stat.Worker.IsDisabledFor(thing))
                {
                    yield return(new StatDrawEntry(stat.category, stat, thing.GetStatValue(stat, true), StatRequest.For(thing), ToStringNumberSense.Undefined));
                }
                else
                {
                    yield return(new StatDrawEntry(stat.category, stat));
                }
            }
            if (thing.def.useHitPoints)
            {
                yield return(new StatDrawEntry(StatCategoryDefOf.BasicsNonPawn, "HitPointsBasic".Translate().CapitalizeFirst(), thing.HitPoints.ToString() + " / " + thing.MaxHitPoints.ToString(), 0, "")
                {
                    overrideReportText = string.Concat(new string[]
                    {
                        "HitPointsBasic".Translate().CapitalizeFirst(),
                        ":\n\n",
                        thing.HitPoints.ToString(),
                        "\n\n",
                        StatDefOf.MaxHitPoints.LabelCap,
                        ":\n\n",
                        StatDefOf.MaxHitPoints.Worker.GetExplanationUnfinalized(StatRequest.For(thing), ToStringNumberSense.Absolute)
                    })
                });
            }
            foreach (StatDrawEntry stat2 in thing.SpecialDisplayStats())
            {
                yield return(stat2);
            }
            if (!thing.def.equippedStatOffsets.NullOrEmpty <StatModifier>())
            {
                for (int i = 0; i < thing.def.equippedStatOffsets.Count; i++)
                {
                    yield return(new StatDrawEntry(StatCategoryDefOf.EquippedStatOffsets, thing.def.equippedStatOffsets[i].stat, thing.def.equippedStatOffsets[i].value, StatRequest.ForEmpty(), ToStringNumberSense.Offset));
                }
            }
            if (thing.def.IsStuff)
            {
                if (!thing.def.stuffProps.statFactors.NullOrEmpty <StatModifier>())
                {
                    for (int j = 0; j < thing.def.stuffProps.statFactors.Count; j++)
                    {
                        yield return(new StatDrawEntry(StatCategoryDefOf.StuffStatFactors, thing.def.stuffProps.statFactors[j].stat, thing.def.stuffProps.statFactors[j].value, StatRequest.ForEmpty(), ToStringNumberSense.Factor));
                    }
                }
                if (!thing.def.stuffProps.statOffsets.NullOrEmpty <StatModifier>())
                {
                    for (int k = 0; k < thing.def.stuffProps.statOffsets.Count; k++)
                    {
                        yield return(new StatDrawEntry(StatCategoryDefOf.StuffStatOffsets, thing.def.stuffProps.statOffsets[k].stat, thing.def.stuffProps.statOffsets[k].value, StatRequest.ForEmpty(), ToStringNumberSense.Offset));
                    }
                }
            }
            yield break;
        }
        private static void DrawStatsWorker(Rect rect, Thing optionalThing, WorldObject optionalWorldObject)
        {
            Rect rect2 = new Rect(rect);

            rect2.width *= 0.5f;
            Rect rect3 = new Rect(rect);

            rect3.x     = rect2.xMax;
            rect3.width = rect.xMax - rect3.x;
            Text.Font   = GameFont.Small;
            Rect viewRect = new Rect(0f, 0f, rect2.width - 16f, StatsReportUtility.listHeight);

            Widgets.BeginScrollView(rect2, ref StatsReportUtility.scrollPosition, viewRect, true);
            float  num = 0f;
            string b   = null;

            StatsReportUtility.mousedOverEntry = null;
            for (int i = 0; i < StatsReportUtility.cachedDrawEntries.Count; i++)
            {
                StatDrawEntry ent = StatsReportUtility.cachedDrawEntries[i];
                if (ent.category.LabelCap != b)
                {
                    Widgets.ListSeparator(ref num, viewRect.width, ent.category.LabelCap);
                    b = ent.category.LabelCap;
                }
                num += ent.Draw(8f, num, viewRect.width - 8f, StatsReportUtility.selectedEntry == ent, delegate
                {
                    StatsReportUtility.SelectEntry(ent, true);
                }, delegate
                {
                    StatsReportUtility.mousedOverEntry = ent;
                }, StatsReportUtility.scrollPosition, rect2);
            }
            StatsReportUtility.listHeight = num + 100f;
            Widgets.EndScrollView();
            Rect rect4 = rect3.ContractedBy(10f);

            GUI.BeginGroup(rect4);
            StatDrawEntry statDrawEntry;

            if ((statDrawEntry = StatsReportUtility.selectedEntry) == null)
            {
                statDrawEntry = (StatsReportUtility.mousedOverEntry ?? StatsReportUtility.cachedDrawEntries.FirstOrDefault <StatDrawEntry>());
            }
            StatDrawEntry statDrawEntry2 = statDrawEntry;

            if (statDrawEntry2 != null)
            {
                StatRequest optionalReq;
                if (statDrawEntry2.hasOptionalReq)
                {
                    optionalReq = statDrawEntry2.optionalReq;
                }
                else if (optionalThing != null)
                {
                    optionalReq = StatRequest.For(optionalThing);
                }
                else
                {
                    optionalReq = StatRequest.ForEmpty();
                }
                string explanationText = statDrawEntry2.GetExplanationText(optionalReq);
                Rect   rect5           = rect4.AtZero();
                Widgets.Label(rect5, explanationText);
            }
            GUI.EndGroup();
        }
 public float GetStatValue(StatDef stat)
 {
     return(stat.Worker.GetValue(StatRequest.For(thing, stuff, Quality)));
 }
Exemplo n.º 24
0
        private static IEnumerable <StatDrawEntry> StatsToDraw(Thing thing)
        {
            yield return(DescriptionEntry(thing));

            StatDrawEntry statDrawEntry = QualityEntry(thing);

            if (statDrawEntry != null)
            {
                yield return(statDrawEntry);
            }
            foreach (StatDef item in DefDatabase <StatDef> .AllDefs.Where((StatDef st) => st.Worker.ShouldShowFor(StatRequest.For(thing))))
            {
                if (!item.Worker.IsDisabledFor(thing))
                {
                    float statValue = thing.GetStatValue(item);
                    if (item.showOnDefaultValue || statValue != item.defaultBaseValue)
                    {
                        yield return(new StatDrawEntry(item.category, item, statValue, StatRequest.For(thing)));
                    }
                }
                else
                {
                    yield return(new StatDrawEntry(item.category, item));
                }
            }
            if (thing.def.useHitPoints)
            {
                yield return(new StatDrawEntry(StatCategoryDefOf.BasicsImportant, "HitPointsBasic".Translate().CapitalizeFirst(), thing.HitPoints + " / " + thing.MaxHitPoints, "Stat_HitPoints_Desc".Translate(), 99998));
            }
            foreach (StatDrawEntry item2 in thing.SpecialDisplayStats())
            {
                yield return(item2);
            }
            if (!thing.def.IsStuff)
            {
                yield break;
            }
            foreach (StatDrawEntry item3 in StuffStats(thing.def))
            {
                yield return(item3);
            }
        }
Exemplo n.º 25
0
 public float GetValueAbstract(AbilityDef def)
 {
     return(GetValue(StatRequest.For(def)));
 }
Exemplo n.º 26
0
        private static void DrawStatsWorker(Rect rect, Thing optionalThing, WorldObject optionalWorldObject)
        {
            Rect rect2 = new Rect(rect);

            rect2.width *= 0.5f;
            Rect rect3 = new Rect(rect);

            rect3.x     = rect2.xMax;
            rect3.width = rect.xMax - rect3.x;
            Text.Font   = GameFont.Small;
            Rect viewRect = new Rect(0f, 0f, rect2.width - 16f, listHeight);

            Widgets.BeginScrollView(rect2, ref scrollPosition, viewRect);
            float  curY = 0f;
            string b    = null;

            mousedOverEntry = null;
            for (int i = 0; i < cachedDrawEntries.Count; i++)
            {
                StatDrawEntry ent = cachedDrawEntries[i];
                if (ent.category.LabelCap != b)
                {
                    Widgets.ListSeparator(ref curY, viewRect.width, ent.category.LabelCap);
                    b = ent.category.LabelCap;
                }
                curY += ent.Draw(8f, curY, viewRect.width - 8f, selectedEntry == ent, delegate
                {
                    SelectEntry(ent);
                }, delegate
                {
                    mousedOverEntry = ent;
                }, scrollPosition, rect2);
            }
            listHeight = curY + 100f;
            Widgets.EndScrollView();
            Rect rect4 = rect3.ContractedBy(10f);

            GUI.BeginGroup(rect4);
            StatDrawEntry statDrawEntry = selectedEntry ?? mousedOverEntry ?? cachedDrawEntries.FirstOrDefault();

            if (statDrawEntry != null)
            {
                StatRequest optionalReq     = statDrawEntry.hasOptionalReq ? statDrawEntry.optionalReq : ((optionalThing == null) ? StatRequest.ForEmpty() : StatRequest.For(optionalThing));
                string      explanationText = statDrawEntry.GetExplanationText(optionalReq);
                Rect        rect5           = rect4.AtZero();
                Widgets.Label(rect5, explanationText);
            }
            GUI.EndGroup();
        }
        private void DrawForagedFoodPerDay(Rect rect, TransferableOneWay trad)
        {
            if (!trad.HasAnyThing)
            {
                return;
            }
            Pawn p = trad.AnyThing as Pawn;

            if (p == null)
            {
                return;
            }
            bool  skip;
            float foragedNutritionPerDay = ForagedFoodPerDayCalculator.GetBaseForagedNutritionPerDay(p, out skip);

            if (skip)
            {
                return;
            }
            Widgets.DrawHighlightIfMouseover(rect);
            GUI.color = ((foragedNutritionPerDay == 0f) ? Color.gray : Color.green);
            Widgets.Label(rect, "+" + foragedNutritionPerDay.ToString("0.##"));
            GUI.color = Color.white;
            if (Mouse.IsOver(rect))
            {
                TooltipHandler.TipRegion(rect, () => "NutritionForagedPerDayTip".Translate(StatDefOf.ForagedNutritionPerDay.Worker.GetExplanationFull(StatRequest.For(p), StatDefOf.ForagedNutritionPerDay.toStringNumberSense, foragedNutritionPerDay)), trad.GetHashCode() ^ 0x74BEF43E);
            }
        }
 private void DrawForagedFoodPerDay(Rect rect, TransferableOneWay trad)
 {
     if (trad.HasAnyThing)
     {
         Pawn p = trad.AnyThing as Pawn;
         if (p != null)
         {
             bool  flag;
             float foragedNutritionPerDay = ForagedFoodPerDayCalculator.GetBaseForagedNutritionPerDay(p, out flag);
             if (!flag)
             {
                 Widgets.DrawHighlightIfMouseover(rect);
                 GUI.color = ((foragedNutritionPerDay != 0f) ? Color.green : Color.gray);
                 Widgets.Label(rect, "+" + foragedNutritionPerDay.ToString("0.##"));
                 GUI.color = Color.white;
                 TooltipHandler.TipRegion(rect, () => "NutritionForagedPerDayTip".Translate(new object[]
                 {
                     StatDefOf.ForagedNutritionPerDay.Worker.GetExplanationFull(StatRequest.For(p), StatDefOf.ForagedNutritionPerDay.toStringNumberSense, foragedNutritionPerDay)
                 }), trad.GetHashCode() ^ 1958671422);
             }
         }
     }
 }
Exemplo n.º 29
0
 public float GetValue(Thing thing, Pawn pawn, bool applyPostProcess = true)
 {
     return(GetValue(StatRequest.For(thing, pawn)));
 }