Skip to content

Commit

Permalink
Force NEIE to refresh more often (#127)
Browse files Browse the repository at this point in the history
This forces the NEIE screen to redo its calculations more often. It also
makes sure the milestone displays reflect the settings in the current
project, instead of the settings in the first-loaded project.

Fixes #77
  • Loading branch information
shpaass authored May 12, 2024
2 parents e1ca158 + c85e242 commit 46fcb2d
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 9 deletions.
5 changes: 5 additions & 0 deletions Yafc/Windows/DependencyExplorer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -130,15 +130,18 @@ public override void Build(ImGui gui) {
gui.BuildText("Manually marked as accessible.");
if (gui.BuildLink("Clear mark")) {
SetFlag(ProjectPerItemFlags.MarkedAccessible, false);
NeverEnoughItemsPanel.Refresh();
}
}
else {
if (gui.BuildLink("Mark as inaccessible")) {
SetFlag(ProjectPerItemFlags.MarkedInaccessible, true);
NeverEnoughItemsPanel.Refresh();
}

if (gui.BuildLink("Mark as accessible without milestones")) {
SetFlag(ProjectPerItemFlags.MarkedAccessible, true);
NeverEnoughItemsPanel.Refresh();
}
}
}
Expand All @@ -147,12 +150,14 @@ public override void Build(ImGui gui) {
gui.BuildText("Status: Marked as inaccessible");
if (gui.BuildLink("Clear mark")) {
SetFlag(ProjectPerItemFlags.MarkedInaccessible, false);
NeverEnoughItemsPanel.Refresh();
}
}
else {
gui.BuildText("Status: Not accessible. Wrong?");
if (gui.BuildLink("Manually mark as accessible")) {
SetFlag(ProjectPerItemFlags.MarkedAccessible, true);
NeverEnoughItemsPanel.Refresh();
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions Yafc/Windows/MainScreen.cs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ private void SetProject(Project project) {
DataUtils.SetupForProject(project);
this.project = project;
if (project.justCreated) {
_ = ShowPseudoScreen(MilestonesPanel.Instance);
_ = ShowPseudoScreen(new MilestonesPanel());
}

if (project.pages.Count == 0) {
Expand Down Expand Up @@ -401,7 +401,7 @@ private void SettingsDropdown(ImGui gui) {

BuildSubHeader(gui, "Tools");
if (gui.BuildContextMenuButton("Milestones") && gui.CloseDropdown()) {
_ = ShowPseudoScreen(MilestonesPanel.Instance);
_ = ShowPseudoScreen(new MilestonesPanel());
}

if (gui.BuildContextMenuButton("Preferences") && gui.CloseDropdown()) {
Expand Down
7 changes: 2 additions & 5 deletions Yafc/Windows/MilestonesPanel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@

namespace Yafc {
public class MilestonesWidget : VirtualScrollList<FactorioObject> {
public static readonly MilestonesWidget Instance = new MilestonesWidget();

public MilestonesWidget() : base(30f, new Vector2(3f, 3f), MilestoneDrawer) => data = Project.current.settings.milestones;

private static void MilestoneDrawer(ImGui gui, FactorioObject element, int index) {
Expand All @@ -31,18 +29,17 @@ private static void MilestoneDrawer(ImGui gui, FactorioObject element, int index
gui.DrawIcon(gui.lastRect, Icon.Check, SchemeColor.Error);
}
}

}

public class MilestonesPanel : PseudoScreen {
public static readonly MilestonesPanel Instance = new MilestonesPanel();
private readonly MilestonesWidget milestonesWidget = new();

public override void Build(ImGui gui) {
gui.spacing = 1f;
BuildHeader(gui, "Milestones");
gui.BuildText("Please select objects that you already have access to:");
gui.AllocateSpacing(2f);
MilestonesWidget.Instance.Build(gui);
milestonesWidget.Build(gui);
gui.AllocateSpacing(2f);
gui.BuildText("For your convenience, YAFC will show objects you DON'T have access to based on this selection", wrap: true);
gui.BuildText("These are called 'Milestones'. By default all science packs are added as milestones, but this does not have to be this way! " +
Expand Down
16 changes: 15 additions & 1 deletion Yafc/Windows/NeverEnoughItemsPanel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,21 @@ public RecipeEntry(Recipe recipe, bool isProduction, Goods currentItem, bool atC
private readonly List<RecipeEntry> productions = [];
private readonly List<RecipeEntry> usages = [];

public NeverEnoughItemsPanel() : base(76f) {
private NeverEnoughItemsPanel() : base(76f) {
productionList = new ScrollArea(40f, BuildItemProduction, new Padding(0.5f));
usageList = new ScrollArea(40f, BuildItemUsages, new Padding(0.5f));
}

/// <summary>
/// Call to make sure that any recent setting changes (e.g. object accessibility) are reflected in the NEIE display.
/// It is only necessary to call this from screens that could be displayed on top of the NEIE display.
/// </summary>
public static void Refresh() {
var item = Instance.current;
Instance.current = null;
Instance.SetItem(item);
}

private void SetItem(Goods current) {
if (current == this.current) {
return;
Expand Down Expand Up @@ -368,6 +378,10 @@ public override void Build(ImGui gui) {
}

public static void Show(Goods goods) {
// This call handles any updates required by milestone changes. The milestones window can't
// easily handle that since the setting updates happen after the milestones screens are closed.
Refresh();

if (Instance.opened) {
Instance.changing = goods;
return;
Expand Down
2 changes: 1 addition & 1 deletion Yafc/Workspace/AutoPlannerView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ void Page1(ImGui gui, ref bool valid) {
}
gui.AllocateSpacing(2f);
gui.BuildText("Review active milestones, as they will restrict recipes that are considered:", wrap: true);
MilestonesWidget.Instance.Build(gui);
new MilestonesWidget().Build(gui);
gui.AllocateSpacing(2f);
valid = !string.IsNullOrEmpty(pageName) && goal.Count > 0;
}
Expand Down
2 changes: 2 additions & 0 deletions changelog.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ Date: soon
- Removed default pollution cost from calculation. Added a setting to customize pollution cost.
- Add fuel consumption recipe for products
- Fix list displays below search boxes. If necessary, they now scroll up until items are visible.
- Fix the milestones display and the milestones editor displaying different milestones.
- Fix the NEI Explorer not always reflecting milestone unlocks and changed accessibility flags.
----------------------------------------------------------------------------------------------------------------------
Version: 0.6.4
Date: April 16th 2024
Expand Down

0 comments on commit 46fcb2d

Please sign in to comment.