public FinalStatFilterRange(StatThingInfo info) : base( info, $"allowedFinal{info.statDef.defName}", x => $"{(x.isRequired ? "(!) " : "")}F. {info.statDef.label}", x => $"<i>{info.statDef.category.label}:</i> {info.statDef.label}", (range, thing) => !info.thingDefValues.ContainsKey(thing.def) && !range.isRequired || info.thingDefValues.ContainsKey(thing.def) && range.Includes(thing.GetStatValue(info.statDef))) { }
public BaseStatFilterRange(StatThingInfo info) : base( info, $"allowedBase{info.statDef.defName}", x => $"{(x.isRequired ? "(!) " : "")}B. {info.statDef.label}", x => $"<i>{info.statDef.category.label}:</i> {info.statDef.label}", (range, thing) => !info.thingDefValues.ContainsKey(thing.def) && !range.isRequired || info.thingDefValues.TryGetValue(thing.def, out var value) && range.Includes(value)) { }
static StatThingInfo CreateInstance(StatDef statDef) { float?min = null, max = null; var foundFraction = false; var thingDefValues = new Dictionary <ThingDef, float>(); foreach (var thingDef in DefDatabase <ThingDef> .AllDefsListForReading) { if (!statDef.Worker.ShouldShowFor(StatRequest.For(thingDef, null))) { continue; } // https://github.com/CombatExtendedRWMod/CombatExtended/blob/7768f94edae4ffffdce16cb3bb7b10db0e541a79/Source/CombatExtended/CombatExtended/StatWorkers/StatWorker_MeleeDamageAverage.cs#L31 if (CeToolCeType != null && thingDef.tools != null && thingDef.tools.Any(x => x.GetType() != CeToolCeType)) { continue; } var value = thingDef.GetStatValueAbstract(statDef); if (Mathf.Approximately(value, statDef.hideAtValue)) { continue; } if (!foundFraction && !Mathf.Approximately(value % 1, 0)) { foundFraction = true; } min = Math.Min(min ?? value, value); max = Math.Max(max ?? value, value); thingDefValues.Add(thingDef, value); } if (min == null || float.IsNaN((float)min) || min.Equals(max)) { return(null); } //Debug.WriteLine($"{statDef} \"{statDef.label}\" {min} {max} {statDef.toStringStyle} \"{string.Join(", ", thingDefValues.Select(x => x.ToString()).ToArray())}\""); if (statDef.toStringStyle == default && !explicitlyIntegers.Contains(statDef) && foundFraction) { statDef.toStringStyle = ToStringStyle.FloatTwo; } var result = new StatThingInfo(statDef, thingDefValues, (float)min, (float)max); return(result); }
protected StatFilterRange(StatThingInfo info, string saveLabel, Func <FilterRange, string> widgetLabel, Func <FilterRange, string> menuLabel, Func <FilterRange, Thing, bool> isAllowed) : base(saveLabel, widgetLabel, menuLabel, info.statDef.toStringStyle, info.min, info.max, isAllowed) { }