Skip to content

Commit

Permalink
NEIE "At current milestones" flag
Browse files Browse the repository at this point in the history
  • Loading branch information
ShadowTheAge committed Aug 29, 2020
1 parent fbcd359 commit aab2a42
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 29 deletions.
2 changes: 1 addition & 1 deletion YAFC/Widgets/ImmediateWidgets.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion YAFC/Windows/MainScreen.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
36 changes: 16 additions & 20 deletions YAFC/Windows/NeverEnoughItemsPanel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,15 @@

namespace YAFC
{
public interface IRecipeItemFlowProvider
{
float GetRecipeFlow(Recipe recipe);
float GetGoodsFlow(Goods goods);
}

public class NeverEnoughItemsPanel : PseudoScreen, IRecipeItemFlowProvider, IComparer<NeverEnoughItemsPanel.RecipeEntry>
public class NeverEnoughItemsPanel : PseudoScreen, IComparer<NeverEnoughItemsPanel.RecipeEntry>
{
private static NeverEnoughItemsPanel Instance = new NeverEnoughItemsPanel();
private IRecipeItemFlowProvider provider;
private Goods current;
private Goods changing;
private float currentFlow;
private EntryStatus showRecipesRange;
private readonly List<Goods> recent = new List<Goods>();
private bool atCurrentMilestones;

private readonly VerticalScrollCustom productionList;
private readonly VerticalScrollCustom usageList;
Expand All @@ -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())
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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<RecipeEntry>.Compare(RecipeEntry x, RecipeEntry y)
{
if (x.entryStatus != y.entryStatus)
Expand Down
10 changes: 5 additions & 5 deletions YAFCmodel/Analysis/Analysis.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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];
}
}
1 change: 1 addition & 0 deletions YAFCmodel/Analysis/CostAnalysis.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions YAFCui/ImGui/ImGuiUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit aab2a42

Please sign in to comment.