diff --git a/YAFC/Widgets/ImmediateWidgets.cs b/YAFC/Widgets/ImmediateWidgets.cs index 0ba79306..144a0885 100644 --- a/YAFC/Widgets/ImmediateWidgets.cs +++ b/YAFC/Widgets/ImmediateWidgets.cs @@ -69,7 +69,7 @@ public static bool BuildFactorioObjectButton(this ImGui gui, Rect rect, Factorio if (gui.actionParameter == SDL.SDL_BUTTON_MIDDLE && obj != null) { if (obj is Goods goods && obj.IsAccessible()) - NeverEnoughItemsPanel.Show(goods, null); + NeverEnoughItemsPanel.Show(goods); else DependencyExplorer.Show(obj); } else if (gui.actionParameter == SDL.SDL_BUTTON_LEFT) diff --git a/YAFC/Windows/MainScreen.cs b/YAFC/Windows/MainScreen.cs index e9a0fa75..6d64bc32 100644 --- a/YAFC/Windows/MainScreen.cs +++ b/YAFC/Windows/MainScreen.cs @@ -281,7 +281,7 @@ public void BuildSubHeader(ImGui gui, string text) private void ShowNeie() { - SelectObjectPanel.Select(Database.goods.all, "Open NEIE", x => NeverEnoughItemsPanel.Show(x, null)); + SelectObjectPanel.Select(Database.goods.all, "Open NEIE", NeverEnoughItemsPanel.Show); } private void SetSearch(SearchQuery searchQuery) diff --git a/YAFC/Windows/NeverEnoughItemsPanel.cs b/YAFC/Windows/NeverEnoughItemsPanel.cs index d2eee8cd..d7c592e9 100644 --- a/YAFC/Windows/NeverEnoughItemsPanel.cs +++ b/YAFC/Windows/NeverEnoughItemsPanel.cs @@ -4,21 +4,15 @@ namespace YAFC { - public interface IRecipeItemFlowProvider - { - float GetRecipeFlow(Recipe recipe); - float GetGoodsFlow(Goods goods); - } - - public class NeverEnoughItemsPanel : PseudoScreen, IRecipeItemFlowProvider, IComparer + public class NeverEnoughItemsPanel : PseudoScreen, IComparer { private static NeverEnoughItemsPanel Instance = new NeverEnoughItemsPanel(); - private IRecipeItemFlowProvider provider; private Goods current; private Goods changing; private float currentFlow; private EntryStatus showRecipesRange; private readonly List recent = new List(); + private bool atCurrentMilestones; private readonly VerticalScrollCustom productionList; private readonly VerticalScrollCustom usageList; @@ -40,11 +34,11 @@ private readonly struct RecipeEntry public readonly float specificEfficiency; public readonly EntryStatus entryStatus; - public RecipeEntry(Recipe recipe, bool isProduction, IRecipeItemFlowProvider provider, Goods currentItem) + public RecipeEntry(Recipe recipe, bool isProduction, Goods currentItem, bool atCurrentMilestones) { this.recipe = recipe; var amount = isProduction ? recipe.GetProduction(currentItem) : recipe.GetConsumption(currentItem); - recipeFlow = provider.GetRecipeFlow(recipe); + recipeFlow = recipe.ApproximateFlow(atCurrentMilestones); flow = recipeFlow * amount; specificEfficiency = isProduction ? recipe.Cost() / amount : 0f; if (!recipe.IsAccessible()) @@ -82,14 +76,14 @@ private void SetItem(Goods current) if (this.current != null) recent.Add(this.current); this.current = current; - currentFlow = provider.GetGoodsFlow(current); + currentFlow = current.ApproximateFlow(atCurrentMilestones); productions.Clear(); foreach (var recipe in current.production) - productions.Add(new RecipeEntry(recipe, true, provider, current)); + productions.Add(new RecipeEntry(recipe, true, current, atCurrentMilestones)); productions.Sort(this); usages.Clear(); foreach (var usage in current.usages) - usages.Add(new RecipeEntry(usage, false, provider, current)); + usages.Add(new RecipeEntry(usage, false, current, atCurrentMilestones)); usages.Sort(this); showRecipesRange = EntryStatus.Normal; if (productions.Count > 0 && productions[0].entryStatus < showRecipesRange) @@ -189,7 +183,7 @@ private void DrawRecipeEntry(ImGui gui, RecipeEntry entry, bool production) gui.allocator = RectAllocator.Stretch; gui.spacing = 0f; gui.BuildFactorioObjectButton(entry.recipe, 4f, MilestoneDisplay.Contained); - gui.BuildText(DataUtils.FormatAmount(recipe.Cost(), UnitOfMeasure.None, "¥"), align:RectAlignment.Middle); + gui.BuildText(DataUtils.FormatAmount(recipe.Cost(atCurrentMilestones), UnitOfMeasure.None, "¥"), align:RectAlignment.Middle); } gui.AllocateSpacing(); gui.allocator = production ? RectAllocator.LeftAlign : RectAllocator.RightAlign; @@ -336,27 +330,29 @@ public override void Build(ImGui gui) using (gui.EnterRow()) { gui.BuildText("Legend:"); - gui.BuildText("This color is flow (Estimated fraction of item production/consumption)"); + gui.BuildText("This color is estimated fraction of item production/consumption"); gui.DrawRectangle(gui.lastRect, SchemeColor.Primary); gui.BuildText("This color is estimated recipe efficiency"); gui.DrawRectangle(gui.lastRect, SchemeColor.Secondary); + if (gui.BuildCheckBox("Current milestones only", atCurrentMilestones, out atCurrentMilestones, allocator:RectAllocator.RightRow)) + { + var item = current; + current = null; + SetItem(item); + } } } - public static void Show(Goods goods, IRecipeItemFlowProvider provider) + public static void Show(Goods goods) { if (Instance.opened) { Instance.changing = goods; return; } - Instance.provider = provider ?? Instance; Instance.SetItem(goods); MainScreen.Instance.ShowPseudoScreen(Instance); } - - public float GetRecipeFlow(Recipe recipe) => recipe.ApproximateFlow(); - public float GetGoodsFlow(Goods goods) => goods.ApproximateFlow(); int IComparer.Compare(RecipeEntry x, RecipeEntry y) { if (x.entryStatus != y.entryStatus) diff --git a/YAFCmodel/Analysis/Analysis.cs b/YAFCmodel/Analysis/Analysis.cs index a6d6715b..bab81c3a 100644 --- a/YAFCmodel/Analysis/Analysis.cs +++ b/YAFCmodel/Analysis/Analysis.cs @@ -40,10 +40,10 @@ public static class AnalysisExtensions public static bool IsAccessibleWithCurrentMilestones(this FactorioObject obj) => Milestones.Instance.IsAccessibleWithCurrentMilesones(obj); public static bool IsAutomatable(this FactorioObject obj) => AutomationAnalysis.Instance.automatable[obj] != AutomationStatus.NotAutomatable; public static bool IsAutomatableWithCurrentMilestones(this FactorioObject obj) => AutomationAnalysis.Instance.automatable[obj] == AutomationStatus.AutomatableNow; - public static float Cost(this FactorioObject goods, bool atCurrentMilestones = false) => (atCurrentMilestones ? CostAnalysis.InstanceAtMilestones : CostAnalysis.Instance).cost[goods]; - public static float ApproximateFlow(this FactorioObject recipe) => CostAnalysis.Instance.flow[recipe]; - public static float ProductCost(this Recipe recipe) => CostAnalysis.Instance.recipeProductCost[recipe]; - public static float RecipeWaste(this Recipe recipe) => CostAnalysis.Instance.recipeWastePercentage[recipe]; - public static float RecipeBaseCost(this Recipe recipe) => CostAnalysis.Instance.recipeCost[recipe]; + public static float Cost(this FactorioObject goods, bool atCurrentMilestones = false) => CostAnalysis.Get(atCurrentMilestones).cost[goods]; + public static float ApproximateFlow(this FactorioObject recipe, bool atCurrentMilestones = false) => CostAnalysis.Get(atCurrentMilestones).flow[recipe]; + public static float ProductCost(this Recipe recipe, bool atCurrentMilestones = false) => CostAnalysis.Get(atCurrentMilestones).recipeProductCost[recipe]; + public static float RecipeWaste(this Recipe recipe, bool atCurrentMilestones = false) => CostAnalysis.Get(atCurrentMilestones).recipeWastePercentage[recipe]; + public static float RecipeBaseCost(this Recipe recipe, bool atCurrentMilestones = false) => CostAnalysis.Get(atCurrentMilestones).recipeCost[recipe]; } } \ No newline at end of file diff --git a/YAFCmodel/Analysis/CostAnalysis.cs b/YAFCmodel/Analysis/CostAnalysis.cs index 69135669..c35d411b 100644 --- a/YAFCmodel/Analysis/CostAnalysis.cs +++ b/YAFCmodel/Analysis/CostAnalysis.cs @@ -13,6 +13,7 @@ public class CostAnalysis : Analysis { public static readonly CostAnalysis Instance = new CostAnalysis(false); public static readonly CostAnalysis InstanceAtMilestones = new CostAnalysis(true); + public static CostAnalysis Get(bool atCurrentMilestones) => atCurrentMilestones ? InstanceAtMilestones : Instance; private const float CostPerSecond = 0.1f; private const float CostPerIngredient = 0.2f; diff --git a/YAFCui/ImGui/ImGuiUtils.cs b/YAFCui/ImGui/ImGuiUtils.cs index 18101ab0..7303946b 100644 --- a/YAFCui/ImGui/ImGuiUtils.cs +++ b/YAFCui/ImGui/ImGuiUtils.cs @@ -139,9 +139,9 @@ public static bool BuildButton(this ImGui gui, Icon icon, SchemeColor normal = S return gui.BuildButton(gui.lastRect, normal, over, down) == Event.Click; } - public static bool BuildCheckBox(this ImGui gui, string text, bool value, out bool newValue, SchemeColor color = SchemeColor.None) + public static bool BuildCheckBox(this ImGui gui, string text, bool value, out bool newValue, SchemeColor color = SchemeColor.None, RectAllocator allocator = RectAllocator.LeftRow) { - using (gui.EnterRow()) + using (gui.EnterRow(allocator:allocator)) { gui.BuildIcon(value ? Icon.CheckBoxCheck : Icon.CheckBoxEmpty, 1.5f, color); gui.BuildText(text, Font.text, color:color);