protected void DrawUsableMinMaxNumericField <T>(UsableMinMaxNumericItem <T> numericItem, string label, float min = 0f, float max = 1E+09f) where T : struct, IComparable, IConvertible { var tmpCheckedOn = numericItem.Use; var textMin = "PLINT_UsableMinMaxNumFieldMin".Translate(); var textMax = "PLINT_UsableMinMaxNumFieldMax".Translate(); ListingStandard.Gap(); ListingStandard.CheckboxLabeled(label, ref tmpCheckedOn, $"{"PLINT_UsableMinMaxNumFieldUse".Translate()} {textMin}/{textMax} {label}"); numericItem.Use = tmpCheckedOn; var minValue = numericItem.Min; var minValueString = numericItem.MinString; var minValueLabelRect = ListingStandard.GetRect(DefaultElementHeight); Verse.Widgets.TextFieldNumericLabeled(minValueLabelRect, $"{textMin}: ", ref minValue, ref minValueString, min, max); numericItem.Min = minValue; numericItem.MinString = minValueString; var maxValue = numericItem.Max; var maxValueString = numericItem.MaxString; var maxValueLabelRect = ListingStandard.GetRect(DefaultElementHeight); Verse.Widgets.TextFieldNumericLabeled(maxValueLabelRect, $"{textMax}: ", ref maxValue, ref maxValueString, min, max); numericItem.Max = maxValue; numericItem.MaxString = maxValueString; }
protected virtual void DrawUsableMinMaxNumericField <T>(UsableMinMaxNumericItem <T> numericItem, string label, float min = 0f, float max = 1E+09f) where T : struct, IComparable, IConvertible { var tmpCheckedOn = numericItem.Use; ListingStandard.Gap(DefaultGapHeight); ListingStandard.CheckboxLabeled(label, ref tmpCheckedOn, $"Use Min/Max {label}"); numericItem.Use = tmpCheckedOn; var minValue = numericItem.Min; var minValueString = numericItem.MinString; var minValueLabelRect = ListingStandard.GetRect(DefaultElementHeight); Widgets.TextFieldNumericLabeled(minValueLabelRect, "Min: ", ref minValue, ref minValueString, min, max); numericItem.Min = minValue; numericItem.MinString = minValueString; var maxValue = numericItem.Max; var maxValueString = numericItem.MaxString; var maxValueLabelRect = ListingStandard.GetRect(DefaultElementHeight); Widgets.TextFieldNumericLabeled(maxValueLabelRect, "Max: ", ref maxValue, ref maxValueString, min, max); numericItem.Max = maxValue; numericItem.MaxString = maxValueString; }
protected static void FilterMovementTime(int tileId, float yearPct, UsableMinMaxNumericItem <float> item, List <int> resultList) { var ticks = Mathf.Min(GenDate.TicksPerHour + WorldPathGrid.CalculatedCostAt(tileId, false, yearPct), Caravan_PathFollower.MaxMoveTicks); ticks.TicksToPeriod(out var years, out var quadrums, out var days, out var hours); // combine everything into hours; note that we shouldn't get anything other than 'hours' and 'days'. Technically, a tile is should be passable in less than 48 hours. var totalHours = hours + days * GenDate.HoursPerDay + quadrums * GenDate.DaysPerQuadrum * GenDate.HoursPerDay + years * GenDate.DaysPerTwelfth * GenDate.TwelfthsPerYear * GenDate.HoursPerDay; //TODO: see how RimWorld rounds movement time numbers; e.g 4.06 is 4.1, does that mean that 4.02 is 4? if (item.InRange(totalHours)) { resultList.Add(tileId); } }
private static void SaveUsableMinMax <T>(XContainer xRoot, string elementName, UsableMinMaxNumericItem <T> item) where T : struct, IComparable, IConvertible { if (!item.Use) { return; } var xElement = new XElement(elementName); xRoot.Add(xElement); xElement.Add(new XElement(UseNode, item.Use)); xElement.Add(new XElement(MinNode, item.Min)); xElement.Add(new XElement(MaxNode, item.Max)); }
private static void LoadUsableMinMax <T>(XContainer xParent, string elementName, UsableMinMaxNumericItem <T> item) where T : struct, IComparable, IConvertible { var xFoundElement = xParent.Element(elementName); var xUse = xFoundElement?.Element(UseNode); if (xUse == null) { return; } if (!Load(xFoundElement, UseNode, out bool use)) { return; } if (!use) { return; } item.Use = true; if (!Load(xFoundElement, MinNode, out T value)) { return; } item.Min = value; item.MinString = xFoundElement.Element(MinNode)?.Value; if (!Load(xFoundElement, MaxNode, out value)) { return; } item.Max = value; item.MaxString = xFoundElement.Element(MaxNode)?.Value; }