Skip to content

Commit

Permalink
Tooplip improvements, NEIE improvements, furnaces now can't do recipe…
Browse files Browse the repository at this point in the history
…s with more than 1 input
  • Loading branch information
ShadowTheAge committed Aug 31, 2020
1 parent aab2a42 commit 0dac21f
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 15 deletions.
18 changes: 12 additions & 6 deletions YAFC/Widgets/ObjectTooltip.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,19 +61,25 @@ private void BuildIconRow(ImGui gui, IReadOnlyList<FactorioObject> objects, int
return;
}

var arr = new List<FactorioObject>(count);
arr.AddRange(objects);
arr.Sort(DataUtils.DefaultOrdering);

if (count <= maxRows)
{
for (var i = 0; i < count; i++)
gui.BuildFactorioObjectButtonWithText(objects[i]);
gui.BuildFactorioObjectButtonWithText(arr[i]);
return;
}

var arr = new List<FactorioObject>(count);
arr.AddRange(objects);
arr.Sort(DataUtils.DefaultOrdering);

var index = 0;
var rows = Math.Min(((count-1) / itemsPerRow)+1, maxRows);
if (count - 1 < (maxRows - 1) * itemsPerRow)
{
gui.BuildFactorioObjectButtonWithText(arr[0]);
index++;
}

var rows = Math.Min(((count-1-index) / itemsPerRow)+1, maxRows);
for (var i = 0; i < rows; i++)
{
using (gui.EnterRow())
Expand Down
10 changes: 5 additions & 5 deletions YAFC/Windows/NeverEnoughItemsPanel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public RecipeEntry(Recipe recipe, bool isProduction, Goods currentItem, bool atC
entryStatus = EntryStatus.NotAccessibleWithCurrentMilestones;
else
{
var waste = recipe.RecipeWaste();
var waste = recipe.RecipeWaste(atCurrentMilestones);
if (waste > 0.95f)
entryStatus = EntryStatus.Wasteful;
else if (waste > 0f)
Expand Down Expand Up @@ -158,7 +158,7 @@ private void DrawRecipeEntry(ImGui gui, RecipeEntry entry, bool production)
var bgColor = SchemeColor.Background;
var isBuilding = gui.isBuilding;
var recipe = entry.recipe;
var waste = recipe.RecipeWaste();
var waste = recipe.RecipeWaste(atCurrentMilestones);
if (isBuilding)
{
if (entry.entryStatus == EntryStatus.NotAccessible)
Expand Down Expand Up @@ -231,7 +231,7 @@ private void DrawRecipeEntry(ImGui gui, RecipeEntry entry, bool production)
bgColor = SchemeColor.Secondary;
else
{
rect.Width *= (1f - entry.recipe.RecipeWaste());
rect.Width *= (1f - waste);
gui.DrawRectangle(rect, SchemeColor.Secondary);
}
gui.DrawRectangle(gui.lastRect, bgColor);
Expand Down Expand Up @@ -334,7 +334,7 @@ public override void Build(ImGui gui)
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))
if (gui.BuildCheckBox("Current milestones info", atCurrentMilestones, out atCurrentMilestones, allocator:RectAllocator.RightRow))
{
var item = current;
current = null;
Expand All @@ -359,7 +359,7 @@ int IComparer<RecipeEntry>.Compare(RecipeEntry x, RecipeEntry y)
return y.entryStatus - x.entryStatus;
if (x.flow != y.flow)
return y.flow.CompareTo(x.flow);
return x.recipe.RecipeWaste().CompareTo(y.recipe.RecipeWaste());
return x.recipe.RecipeWaste(atCurrentMilestones).CompareTo(y.recipe.RecipeWaste(atCurrentMilestones));
}
}
}
4 changes: 2 additions & 2 deletions YAFCmodel/Analysis/CostAnalysis.cs
Original file line number Diff line number Diff line change
Expand Up @@ -315,8 +315,8 @@ public override void Compute(Project project, ErrorCollector warnings)
continue;
var productCost = 0f;
foreach (var product in recipe.products)
productCost += product.amount * product.goods.Cost();
recipeWastePercentage[recipe] = 1f - productCost / cost[recipe];
productCost += product.amount * export[product.goods];
recipeWastePercentage[recipe] = 1f - productCost / export[recipe];
}
}
else
Expand Down
19 changes: 18 additions & 1 deletion YAFCmodel/Data/DataUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,24 @@ namespace YAFC.Model
{
public static class DataUtils
{
public static readonly FactorioObjectComparer<FactorioObject> DefaultOrdering = new FactorioObjectComparer<FactorioObject>((x, y) => x.Cost().CompareTo(y.Cost()));
public static readonly FactorioObjectComparer<FactorioObject> DefaultOrdering = new FactorioObjectComparer<FactorioObject>((x, y) =>
{
var yflow = y.ApproximateFlow();
var xflow = x.ApproximateFlow();
if (xflow != yflow)
return xflow.CompareTo(yflow);

var rx = x as Recipe;
var ry = y as Recipe;
if (rx != null || ry != null)
{
var xwaste = rx?.RecipeWaste() ?? 0;
var ywaste = ry?.RecipeWaste() ?? 0;
return xwaste.CompareTo(ywaste);
}

return y.Cost().CompareTo(x.Cost());
});
public static readonly FactorioObjectComparer<Goods> FuelOrdering = new FactorioObjectComparer<Goods>((x, y) =>
{
if (x.fuelValue <= 0f && y.fuelValue <= 0f)
Expand Down
2 changes: 1 addition & 1 deletion YAFCparser/Data/FactorioDataDeserializer_Entity.cs
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ private void DeserializeEntity(LuaTable table)
ParseModules(table, entity);
entity.power = ParseEnergy(usesPower);
entity.craftingSpeed = table.Get("crafting_speed", 1f);
entity.itemInputs = table.Get("ingredient_count", 255);
entity.itemInputs = entity.factorioType == "furnace" ? table.Get("source_inventory_size", 1) : table.Get("ingredient_count", 255);
if (table.Get("fluid_boxes", out LuaTable fluidBoxes))
entity.fluidInputs = CountFluidBoxes(fluidBoxes, true);
Recipe fixedRecipe = null;
Expand Down

0 comments on commit 0dac21f

Please sign in to comment.