public int MinAgeForPawn(Pawn pawn) { if (!minAgeLookup.TryGetValue(pawn.def, out int age)) { SimpleCurve simpleCurve = pawn.def.race.ageGenerationCurve; if (simpleCurve == null) { Logger.Warning("No age generation curve defined for " + pawn.def.defName + ". Using default age generation curve to determine minimum age."); simpleCurve = DefaultAgeGenerationCurve; if (simpleCurve == null) { Logger.Warning("Failed to get default age generation curve. Using default minimum age of " + DEFAULT_MIN_AGE); age = DEFAULT_MIN_AGE; } else { age = Mathf.CeilToInt(pawn.def.race.lifeExpectancy * simpleCurve.First().x); } } else { CurvePoint point = simpleCurve.First(); age = (int)point.x; } minAgeLookup.Add(pawn.def, age); } return(age); }
public static void DoCurveEditor(Rect screenRect, SimpleCurve curve, int decimalPlaces = 0, int displayMult = 100, string valueSuffix = "%", Action onChange = null) { Widgets.DrawMenuSection(screenRect); SimpleCurveDrawer.DrawCurve(screenRect, curve, null, null, default(Rect)); Vector2 mousePosition = Event.current.mousePosition - screenRect.position; Vector2 mouseCurveCoords = SimpleCurveDrawer.ScreenToCurveCoords(screenRect, curve.View.rect, mousePosition); if (Mouse.IsOver(screenRect)) { if (Event.current.type == EventType.MouseDown && Event.current.button == 0) { var clampedCoords = mouseCurveCoords; clampedCoords.x = Mathf.Clamp(Mathf.Round(clampedCoords.x), 0, 20); clampedCoords.y = Mathf.Clamp((float)Math.Round(clampedCoords.y, 2), 0, 1); List <FloatMenuOption> list2 = new List <FloatMenuOption>(); if (!curve.Any(point => point.x == clampedCoords.x)) { list2.Add(new FloatMenuOption($"Add point at [{clampedCoords.x:F0} - {(clampedCoords.y * displayMult).ToString($"F{decimalPlaces}")}{valueSuffix}]", () => { curve.Add(new CurvePoint(clampedCoords), true); onChange?.Invoke(); }, MenuOptionPriority.Default, null, null, 0f, null, null, true, 0)); } else { var existingPoint = curve.First(point => point.x == clampedCoords.x); list2.Add(new FloatMenuOption($"Move point at [{existingPoint.x:F0} - {(existingPoint.y * displayMult).ToString($"F{decimalPlaces}")}{valueSuffix}] to [{clampedCoords.x:F0} - {(clampedCoords.y * displayMult).ToString($"F{decimalPlaces}")}{valueSuffix}]", () => { curve.RemovePointNear(existingPoint); curve.Add(new CurvePoint(clampedCoords), true); onChange?.Invoke(); }, MenuOptionPriority.Default, null, null, 0f, null, null, true, 0)); if (Mathf.RoundToInt(existingPoint.x) != 0 && Mathf.RoundToInt(existingPoint.x) != 20) { list2.Add(new FloatMenuOption($"Remove point at [{existingPoint.x:F0} - {(existingPoint.y * displayMult).ToString($"F{decimalPlaces}")}{valueSuffix}]", () => { curve.RemovePointNear(existingPoint); onChange?.Invoke(); }, MenuOptionPriority.Default, null, null, 0f, null, null, true, 0)); } } Find.WindowStack.Add(new FloatMenu(list2)); Event.current.Use(); } } }