Skip to content

Commit 83e6449

Browse files
committed
made the research project info tab scrollable, because some people literally got a metric ton of research projects.
1 parent 3753a88 commit 83e6449

2 files changed

Lines changed: 18 additions & 4 deletions

File tree

512 Bytes
Binary file not shown.

TechAdvancing_Config_Tab.cs

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,10 @@ public class TechAdvancing_Config_Tab : Window
3636
private readonly string descriptionB2_s = "configRuleBSliderdesc".Translate(); //Description for the Slider thats used to change the threshold of the rule B
3737
private readonly string descriptionA2_calc = "configRuleAdesc".Translate();
3838
private readonly string descriptionB2_calc = "configRuleBdesc".Translate();
39+
40+
private Vector2 scrollPosPageProjectInfo = Vector2.zero;
41+
private float scrollPosPageProjectInfoSize = 0;
42+
3943
private bool settingsChanged = false;
4044
// private static float _iconSize = 30f;
4145
// private static float _margin = 6f;
@@ -309,6 +313,11 @@ void AddSliderSettingRef(ref float val, string name, float leftValue, float righ
309313

310314
case 2: // project info
311315
{
316+
var scrollViewDrawCanvasInner = new Rect(canvas.x, canvas.y + drawpos, canvas.width - 50, this.scrollPosPageProjectInfoSize);
317+
var scrollViewArea = new Rect(canvas.x, canvas.y + 25, canvas.width, 500);
318+
319+
float scrollViewDrawpos = 0f;
320+
Widgets.BeginScrollView(scrollViewArea, ref this.scrollPosPageProjectInfo, scrollViewDrawCanvasInner, true);
312321
var techs = (TechLevel[])Enum.GetValues(typeof(TechLevel));
313322
var allProjects = Rules.nonIgnoredTechs.GroupBy(x => x.techLevel).ToDictionary(x => x.Key, x => x.ToList());
314323
for (int i = 0; i < techs.Length; i++)
@@ -322,18 +331,22 @@ void AddSliderSettingRef(ref float val, string name, float leftValue, float righ
322331

323332
if (unfinishedTechs.Count != Rules.researchProjectStoreTotal[tl] - Rules.researchProjectStoreFinished[tl])
324333
{
325-
LogOutput.WriteLogMessage(Errorlevel.Error, "Count mismatch.");
334+
LogOutput.WriteLogMessage(Errorlevel.Error, $"Count mismatch: {unfinishedTechs.Count} != {Rules.researchProjectStoreTotal[tl] - Rules.researchProjectStoreFinished[tl]}");
326335
}
327336

328337
string percentageResearched = (100 - unfinishedTechs.Count * 100f / allProjects[tl].Count).ToString("N0");
329338

330339
var translationToUse = unfinishedTechs.Count == 0 ? "configResearchProjectInfo_TechsRemainingNone" : (unfinishedTechs.Count == 1 ? "configResearchProjectInfo_TechsRemainingSingular" : "configResearchProjectInfo_TechsRemainingPlural");
331340

332-
var contentTranslated = translationToUse.Translate(unfinishedTechs.Count, percentageResearched, string.Join(", ", unfinishedTechs.Select(x => x.label.CapitalizeFirst())));
333-
DrawText(canvas, tlNameTranslated + ":\n" + contentTranslated, ref drawpos);
341+
var contentTranslated = translationToUse.Translate(unfinishedTechs.Count, percentageResearched,
342+
string.Join(", ", unfinishedTechs.Select(x => x.label.Replace("\r\n", "\n").Replace("\r", "\n").Replace("\n", " ").Trim(' ').CapitalizeFirst())));
343+
DrawText(scrollViewDrawCanvasInner, tlNameTranslated + ":\n" + contentTranslated, ref scrollViewDrawpos);
334344

335-
AddSpace(ref drawpos, 10f);
345+
AddSpace(ref scrollViewDrawpos, 10f);
336346
}
347+
348+
Widgets.EndScrollView();
349+
this.scrollPosPageProjectInfoSize = scrollViewDrawpos;
337350
}
338351
break;
339352

@@ -479,6 +492,7 @@ public override void PreOpen()
479492
this.settingsChanged = false;
480493
this.previewTechLevels = GetTechlevelPreview();
481494
this.menuButtonSelected = null; // reset the last clicked button for selecting pages. This will show the normal view.
495+
this.scrollPosPageProjectInfo = Vector2.zero; // reset scrollpos just in case
482496
}
483497

484498
public override Vector2 InitialSize

0 commit comments

Comments
 (0)