public List <ThingDefCount> GetRequirementsTotals(TotalsSortModes modeToSortCountsBy = TotalsSortModes.Absolute, bool ascending = false) { if (!cachedTotalsAreUpdated) { List <ThingDefCount> protoRequirementsTotals = new List <ThingDefCount>(); foreach (IConstructible tracked in trackedConstructibles) { foreach (ThingDefCount requirements in tracked.GetMaterialsNeededSafely()) { int thingCountWithSameThingDefIndex = protoRequirementsTotals.FindIndex(x => x.ThingDef == requirements.ThingDef); if (thingCountWithSameThingDefIndex == -1) { protoRequirementsTotals.Add(requirements); } else { ThingDefCount tcWithSameThingDef = protoRequirementsTotals[thingCountWithSameThingDefIndex]; protoRequirementsTotals[thingCountWithSameThingDefIndex] = BlueprintReportUtility.AddThingCounts(tcWithSameThingDef, requirements); } } } cachedRequirementsTotals = protoRequirementsTotals; cachedTotalsAreUpdated = true; } SortTotalsIfNecessary(modeToSortCountsBy, ascending); return(cachedRequirementsTotals); }
private void DoModeButton(Rect baseRect) { Rect buttonRect = new Rect(baseRect.x, baseRect.y, buttonWidth, listDistanceFromTop / buttonNum - 2.5f); string modeButtonString = "Error - currentSortMode does not match cases"; switch (currentSortMode) { case TotalsSortModes.Absolute: modeButtonString = "TotalsSortModes_Absolute".Translate(); TooltipHandler.TipRegion(buttonRect, new TipSignal("TotalsSortModes_AbsoluteTip".Translate())); break; case TotalsSortModes.Difference: modeButtonString = "TotalsSortModes_Difference".Translate(); TooltipHandler.TipRegion(buttonRect, new TipSignal("TotalsSortModes_DifferenceTip".Translate())); break; } if (Widgets.ButtonText(buttonRect, modeButtonString, true, true, true)) { currentSortMode = (TotalsSortModes.Absolute == currentSortMode) ? TotalsSortModes.Difference : TotalsSortModes.Absolute; } }
private void SortTotalsIfNecessary(TotalsSortModes sortMode, bool descending) { if (sortMode == cachedTotalsSortMode && sortDescending == descending) { return; } switch (sortMode) { case TotalsSortModes.Absolute: cachedRequirementsTotals.Sort((x, y) => x.Count.CompareTo(y.Count)); break; case TotalsSortModes.Difference: cachedRequirementsTotals.Sort((x, y) => (Find.CurrentMap.GetCountOnMapDifference(x)).CompareTo( Find.CurrentMap.GetCountOnMapDifference(y))); break; } if (descending) { cachedRequirementsTotals.Reverse(); } cachedTotalsSortMode = sortMode; sortDescending = descending; }
public void ForceCacheRegeneration() { cachedTotalsAreUpdated = false; cachedTotalsSortMode = TotalsSortModes.Unsorted; }