public IEnumerator DoTheThing() { MemoryUsageByMod.Clear(); int count = CurrentMods.Count(); int k = 0; while (shouldStop || k < count) { if (shouldStop) { yield return(null); continue; } var mod = CurrentMods.ElementAt(k); MemoryUsageByMod.Add(mod, 0); Dictionary <string, FileInfo> allFilesForMod = ModContentPack.GetAllFilesForMod(mod, GenFilePaths.ContentPath <Texture2D>(), (ModContentLoader <Texture2D> .IsAcceptableExtension)); int i = 0; while (shouldStop || i < allFilesForMod.Count) { if (shouldStop) { yield return(null); continue; } var pair = allFilesForMod.ElementAt(i); MemoryUsageByMod[mod] += StaticTools.TextureSize(new VirtualFileWrapper(pair.Value)); i++; if (i % 3 == 0) { yield return(null); } } LargestModSize = MemoryUsageByMod[mod] > LargestModSize ? MemoryUsageByMod[mod] : LargestModSize; k++; } shouldRecalc = false; GraphicSetter.settings.CausedMemOverflow = MEMOVERFLOW; }
public void DrawModList(Rect rect) { Widgets.DrawBoxSolid(rect, ListingBG); GUI.color = Color.gray; Widgets.DrawBox(rect, 1); GUI.color = Color.white; Rect newRect = rect.ContractedBy(5); GUI.BeginGroup(newRect); int y = 0; Rect viewRect = new Rect(0, 0, newRect.width, CurrentMods.Count() * 20); Widgets.BeginScrollView(new Rect(0, 0, newRect.width, newRect.height), ref scrollview, viewRect, false); var list = MemoryUsageByMod.ToList(); list.Sort((p1, p2) => p2.Value.CompareTo(p1.Value)); foreach (var mod in list) { var pct = MemoryPctOf(mod.Key, out long memUsage); var text = mod.Key.Name + " (" + MemoryString(memUsage) + ") " + pct.ToStringPercent(); var tipRect = new Rect(0, y, rect.width, 20); StaticTools.FillableBarLabeled(new Rect(0, y, newRect.width, 18), pct, text, GetColorFor(mod.Key), Color.clear, false); //WidgetRow row = new WidgetRow(0, y, UIDirection.RightThenDown); //row.FillableBar(newRect.width, 18, pct, text, GetColorFor(pct), StaticContent.clear); Widgets.DrawHighlightIfMouseover(tipRect); TooltipHandler.TipRegion(tipRect, text); y += 20; } if (!MemoryUsageByMod.Any()) { string text = CurrentMods.Any() ? $"{CurrentMods.Count()} mods to process...": "No mods to process."; float textHeight = Text.CalcHeight(text, rect.width); Widgets.Label(new Rect(0, y, rect.width, textHeight), text); } Widgets.EndScrollView(); GUI.EndGroup(); }
public void WriteProcessingData(Rect rect) { GUI.BeginGroup(rect); Rect buttonRect = new Rect(0, 5, rect.width * 0.2f, 22); Rect barRect = new Rect(buttonRect.xMax + 5, 5, rect.width - buttonRect.width - 5, 22); float curY = buttonRect.height; string text = shouldRecalc ? (shouldStop ? "Continue" : "Stop") : "Recalculate"; if (Widgets.ButtonText(buttonRect, text, true, false, CurrentMods.Any())) { Notify_ChangeState(); } Widgets.FillableBar(barRect, TotalPctUsage, StaticContent.blue, Texture2D.blackTexture, true); Text.Anchor = TextAnchor.MiddleCenter; string label = MEMOVERFLOW ? "Not Enough VRAM" : MemoryString(TotalBytes) + "/" + MemoryString(TotalVRAM); Widgets.Label(barRect, label); Text.Anchor = default; if (Calculating) { string calcLabel = "Calculating... Please wait. (" + MemoryUsageByMod.Count + "/" + CurrentMods.Count() + ")"; var textSize = Text.CalcHeight(calcLabel, rect.width); Rect textRect = new Rect(0, curY + 5, rect.width, textSize); Widgets.Label(textRect, calcLabel); curY = textRect.yMax; } /*else if (GraphicSetter.settings.AnySettingsChanged()) * { * string settingsChangedLabel = "Settings changed, recalculate to check the memory use!"; * var textSize = Text.CalcHeight(settingsChangedLabel, rect.width); * Rect textRect = new Rect(0, curY + 5, rect.width, textSize); * Widgets.Label(textRect, settingsChangedLabel); * curY = textRect.yMax; * } */ if (Critical) { Text.Font = GameFont.Small; string warningLabel = "Warning:\n" + (MEMOVERFLOW ? "Your system cannot support these settings.\nCompression will be enabled on startup." : "Your system may struggle with these settings."); var textSize = Text.CalcHeight(warningLabel, rect.width); Rect warningLabelRect = new Rect(0, curY + 5, rect.width, textSize); Widgets.Label(warningLabelRect, warningLabel); Text.Font = default; } GUI.EndGroup(); }