Skip to content

Commit

Permalink
fix: Use a scroll list for the productivity tech levels.
Browse files Browse the repository at this point in the history
  • Loading branch information
DaleStan committed Nov 27, 2024
1 parent 5c5b09f commit 16430d2
Showing 1 changed file with 29 additions and 13 deletions.
42 changes: 29 additions & 13 deletions Yafc/Windows/PreferencesScreen.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ namespace Yafc;
public class PreferencesScreen : PseudoScreen {
private static readonly PreferencesScreen Instance = new PreferencesScreen();
private const int GENERAL_PAGE = 0, PROGRESSION_PAGE = 1;
private readonly TabControl tabControl = new(("General", DrawGeneral), ("Progression", DrawProgression));
private readonly TabControl tabControl;

private PreferencesScreen() => tabControl = new(("General", DrawGeneral), ("Progression", DrawProgression));

public override void Build(ImGui gui) {
BuildHeader(gui, "Preferences");
Expand All @@ -29,7 +31,9 @@ public override void Build(ImGui gui) {
}
}

private static void DrawProgression(ImGui gui) {
private static VirtualScrollList<Technology>? technologyList;

private void DrawProgression(ImGui gui) {
ProjectPreferences preferences = Project.current.preferences;

ChooseObject(gui, "Default belt:", Database.allBelts, preferences.defaultBelt, s => {
Expand Down Expand Up @@ -75,17 +79,29 @@ private static void DrawProgression(ImGui gui) {
}
}

IEnumerable<Technology> productivityTech = Database.technologies.all
.Where(x => x.changeRecipeProductivity.Count != 0)
.OrderBy(x => x.locName);
foreach (var tech in productivityTech) {
using (gui.EnterRow()) {
gui.BuildFactorioObjectButton(tech, ButtonDisplayStyle.Default);
gui.BuildText($"{tech.locName} Level: ", topOffset: 0.5f);
int currentLevel = Project.current.settings.productivityTechnologyLevels.GetValueOrDefault(tech, 0);
if (gui.BuildIntegerInput(currentLevel, out int newLevel) && newLevel >= 0) {
Project.current.settings.RecordUndo().productivityTechnologyLevels[tech] = newLevel;
}
int count = technologyList?.data.Count ?? Database.technologies.all.Count(x => x.changeRecipeProductivity.Count != 0);
float height = tabControl.GetRemainingContentHeight(Math.Min(count, 6) * 2.75f + 0.25f);
if (technologyList?.height != height) {
technologyList = new(height, new(gui.layoutRect.Width, 2.75f), DrawTechnology) {
data = [.. Database.technologies.all
.Where(x => x.changeRecipeProductivity.Count != 0)
.OrderBy(x => x.locName)]
};
}

technologyList.Build(gui);
technologyList.RebuildContents();
}

private void DrawTechnology(ImGui gui, Technology tech, int _) {
using (gui.EnterGroup(new(0, .25f, 0, .75f)))
using (gui.EnterRow()) {
gui.allocator = RectAllocator.LeftRow;
gui.BuildFactorioObjectButton(tech, ButtonDisplayStyle.Default);
gui.BuildText($"{tech.locName} Level: ");
int currentLevel = Project.current.settings.productivityTechnologyLevels.GetValueOrDefault(tech, 0);
if (gui.BuildIntegerInput(currentLevel, out int newLevel) && newLevel >= 0) {
Project.current.settings.RecordUndo().productivityTechnologyLevels[tech] = newLevel;
}
}
}
Expand Down

0 comments on commit 16430d2

Please sign in to comment.