diff --git a/.editorconfig b/.editorconfig index bf087438..cc77be63 100644 --- a/.editorconfig +++ b/.editorconfig @@ -72,6 +72,7 @@ dotnet_style_prefer_conditional_expression_over_return = false:none ############################### # Style Definitions dotnet_naming_style.pascal_case_style.capitalization = pascal_case +dotnet_naming_style.camel_case_style.capitalization = camel_case # Use PascalCase for constant fields dotnet_naming_rule.constant_fields_should_be_pascal_case.severity = suggestion dotnet_naming_rule.constant_fields_should_be_pascal_case.symbols = constant_fields @@ -79,6 +80,11 @@ dotnet_naming_rule.constant_fields_should_be_pascal_case.style = pascal_case_ dotnet_naming_symbols.constant_fields.applicable_kinds = field dotnet_naming_symbols.constant_fields.applicable_accessibilities = * dotnet_naming_symbols.constant_fields.required_modifiers = const +# Use camcel case for local variable +dotnet_naming_rule.use_camel_case_rule.symbols = use_camel_case +dotnet_naming_rule.use_camel_case_rule.style = camel_case_style +dotnet_naming_rule.use_camel_case_rule.severity = suggestion +dotnet_naming_symbols.use_camel_case.applicable_kinds = parameter,local,local_function ############################### # C# Coding Conventions # ############################### diff --git a/YAFC/Data/Mod-fixes/EvenMoreTextPlates.globals.lua b/YAFC/Data/Mod-fixes/EvenMoreTextPlates.globals.lua new file mode 100644 index 00000000..3383d144 --- /dev/null +++ b/YAFC/Data/Mod-fixes/EvenMoreTextPlates.globals.lua @@ -0,0 +1,7 @@ +local evenmoretextplates = ...; + +for _,plate in pairs(evenmoretextplates.new_types) do + plate.symbols = {} +end + +return evenmoretextplates; diff --git a/YAFC/Data/Mod-fixes/textplates.textplates.lua b/YAFC/Data/Mod-fixes/textplates.textplates.lua new file mode 100644 index 00000000..a487c804 --- /dev/null +++ b/YAFC/Data/Mod-fixes/textplates.textplates.lua @@ -0,0 +1,7 @@ +local textplates = ...; + +for _,plate in pairs(textplates.types) do + plate.symbols = {} +end + +return textplates; diff --git a/Yafc.Model/Data/DataUtils.cs b/Yafc.Model/Data/DataUtils.cs index fa7aee7e..d0a7a217 100644 --- a/Yafc.Model/Data/DataUtils.cs +++ b/Yafc.Model/Data/DataUtils.cs @@ -45,6 +45,7 @@ public static class DataUtils { return x.RecipeWaste().CompareTo(y.RecipeWaste()); }); + public static readonly FactorioObjectComparer AlreadySortedRecipe = new FactorioObjectComparer(DefaultRecipeOrdering.Compare); public static readonly FactorioObjectComparer CrafterOrdering = new FactorioObjectComparer((x, y) => { if (x.energy.type != y.energy.type) { return x.energy.type.CompareTo(y.energy.type); diff --git a/Yafc.UI/Rendering/Font.cs b/Yafc.UI/Rendering/Font.cs index 58ce3fb3..9fa36110 100644 --- a/Yafc.UI/Rendering/Font.cs +++ b/Yafc.UI/Rendering/Font.cs @@ -6,6 +6,7 @@ namespace Yafc.UI { public class Font { public static Font header; public static Font subheader; + public static Font productionTableHeader; public static Font text; public readonly float size; diff --git a/Yafc/Program.cs b/Yafc/Program.cs index e756a98e..fa869e77 100644 --- a/Yafc/Program.cs +++ b/Yafc/Program.cs @@ -25,6 +25,7 @@ private static void Main(string[] args) { Font.header = new Font(overriddenFontFile ?? new FontFile("Data/Roboto-Light.ttf"), 2f); var regular = overriddenFontFile ?? new FontFile("Data/Roboto-Regular.ttf"); Font.subheader = new Font(regular, 1.5f); + Font.productionTableHeader = new Font(regular, 1.23f); Font.text = new Font(regular, 1f); ProjectDefinition cliProject = CommandLineParser.Parse(args); diff --git a/Yafc/Widgets/ImmediateWidgets.cs b/Yafc/Widgets/ImmediateWidgets.cs index 805f4b73..765209a9 100644 --- a/Yafc/Widgets/ImmediateWidgets.cs +++ b/Yafc/Widgets/ImmediateWidgets.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.Linq; using System.Numerics; using SDL2; using Yafc.Model; @@ -114,16 +115,16 @@ public static bool BuildFactorioObjectButtonWithText(this ImGui gui, FactorioObj public static bool BuildInlineObjectList(this ImGui gui, IEnumerable list, IComparer ordering, string header, out T selected, int maxCount = 10, Predicate checkMark = null, Func extra = null) where T : FactorioObject { - gui.BuildText(header, Font.subheader); - List sortedList = new List(list); - sortedList.Sort(ordering ?? DataUtils.DefaultOrdering); + gui.BuildText(header, Font.productionTableHeader); + IEnumerable sortedList; + if (ordering == DataUtils.AlreadySortedRecipe) { + sortedList = list.AsEnumerable(); + } + else { + sortedList = list.OrderBy(e => e, ordering ?? DataUtils.DefaultOrdering); + } selected = null; - int count = 0; - foreach (var elem in sortedList) { - if (count++ >= maxCount) { - break; - } - + foreach (var elem in sortedList.Take(maxCount)) { string extraText = extra?.Invoke(elem); if (gui.BuildFactorioObjectButtonWithText(elem, extraText)) { selected = elem; @@ -157,10 +158,6 @@ public static void BuildInlineObjectListAndButton(this ImGui gui, ICollection SelectSingleObjectPanel.Select(list, header, select, ordering, allowNone); } } - - if (multiple && list.Count > 1) { - gui.BuildText("Hint: ctrl+click to add multiple", wrap: true, color: SchemeColor.BackgroundTextFaint); - } } } diff --git a/Yafc/Workspace/ProductionTable/ProductionTableView.cs b/Yafc/Workspace/ProductionTable/ProductionTableView.cs index b5e2992e..55049216 100644 --- a/Yafc/Workspace/ProductionTable/ProductionTableView.cs +++ b/Yafc/Workspace/ProductionTable/ProductionTableView.cs @@ -595,12 +595,13 @@ public override void CreateModelDropdown(ImGui gui, Type type, Project project) } private static readonly IComparer DefaultVariantOrdering = new DataUtils.FactorioObjectComparer((x, y) => (y.ApproximateFlow() / MathF.Abs(y.Cost())).CompareTo(x.ApproximateFlow() / MathF.Abs(x.Cost()))); - private RecipeRow AddRecipe(ProductionTable table, Recipe recipe) { + private RecipeRow AddRecipe(ProductionTable table, Recipe recipe, Goods selectedFuel = null) { RecipeRow recipeRow = new RecipeRow(table, recipe); table.RecordUndo().recipes.Add(recipeRow); - recipeRow.entity = recipe.crafters.AutoSelect(DataUtils.FavoriteCrafter); + EntityCrafter selectedFuelCrafter = selectedFuel?.fuelFor.OfType().Where(e => e.recipes.OfType().Any(e => e == recipe)).AutoSelect(DataUtils.FavoriteCrafter); + recipeRow.entity = selectedFuelCrafter ?? recipe.crafters.AutoSelect(DataUtils.FavoriteCrafter); if (recipeRow.entity != null) { - recipeRow.fuel = recipeRow.entity.energy.fuels.AutoSelect(DataUtils.FavoriteFuel); + recipeRow.fuel = recipeRow.entity.energy.fuels.FirstOrDefault(e => e == selectedFuel) ?? recipeRow.entity.energy.fuels.AutoSelect(DataUtils.FavoriteFuel); } foreach (var ingr in recipeRow.recipe.ingredients) { @@ -657,6 +658,7 @@ bool recipeExists(Recipe rec) { return allRecipes.Contains(rec); } + Goods selectedFuel = null; async void addRecipe(Recipe rec) { if (variants == null) { CreateLink(context, goods); @@ -674,7 +676,7 @@ async void addRecipe(Recipe rec) { } } if (!allRecipes.Contains(rec) || (await MessageBox.Show("Recipe already exists", $"Add a second copy of {rec.locName}?", "Add a copy", "Cancel")).choice) { - _ = AddRecipe(context, rec); + _ = AddRecipe(context, rec, selectedFuel); } } @@ -692,6 +694,7 @@ async void addRecipe(Recipe rec) { recipe.RecordUndo().fuel = fuel; }); var allProduction = goods == null ? Array.Empty() : variants == null ? goods.production : variants.SelectMany(x => x.production).Distinct().ToArray(); + Recipe[] fuelUseList = goods?.fuelFor.AsEnumerable().OfType().SelectMany(e => e.recipes).OfType().Distinct().OrderBy(e => e, DataUtils.DefaultRecipeOrdering).ToArray() ?? []; var fuelDisplayFunc = recipe?.entity?.energy.type == EntityEnergyType.FluidHeat ? (Func)(g => DataUtils.FormatAmount(g.fluid?.heatValue ?? 0, UnitOfMeasure.Megajoule)) : g => DataUtils.FormatAmount(g.fuelValue, UnitOfMeasure.Megajoule); @@ -753,8 +756,10 @@ void DropDownContent(ImGui gui) { } } + int numberOfShownRecipes = 0; if (type != ProductDropdownType.Product && goods != null && allProduction.Length > 0) { gui.BuildInlineObjectListAndButton(allProduction, comparer, addRecipe, "Add production recipe", 6, true, recipeExists); + numberOfShownRecipes += allProduction.Length; if (link == null) { Rect iconRect = new Rect(gui.lastRect.Right - 2f, gui.lastRect.Top, 2f, 2f); gui.DrawIcon(iconRect.Expand(-0.2f), Icon.OpenNew, gui.textColor); @@ -770,10 +775,21 @@ void DropDownContent(ImGui gui) { if (type != ProductDropdownType.Fuel && goods != null && type != ProductDropdownType.Ingredient && goods.usages.Length > 0) { gui.BuildInlineObjectListAndButton(goods.usages, DataUtils.DefaultRecipeOrdering, addRecipe, "Add consumption recipe", type == ProductDropdownType.Product ? 6 : 3, true, recipeExists); + numberOfShownRecipes += goods.usages.Length; + } + + if (type != ProductDropdownType.Fuel && goods != null && type != ProductDropdownType.Ingredient && fuelUseList.Length > 0) { + gui.BuildInlineObjectListAndButton(fuelUseList, DataUtils.AlreadySortedRecipe, (x) => { selectedFuel = goods; addRecipe(x); }, "Add fuel usage", type == ProductDropdownType.Product ? 6 : 3, true, recipeExists); + numberOfShownRecipes += fuelUseList.Length; } if (type == ProductDropdownType.Product && goods != null && allProduction.Length > 0) { gui.BuildInlineObjectListAndButton(allProduction, comparer, addRecipe, "Add production recipe", 1, true, recipeExists); + numberOfShownRecipes += allProduction.Length; + } + + if (numberOfShownRecipes > 1) { + gui.BuildText("Hint: ctrl+click to add multiple", wrap: true, color: SchemeColor.BackgroundTextFaint); } if (link != null && gui.BuildCheckBox("Allow overproduction", link.algorithm == LinkAlgorithm.AllowOverProduction, out bool newValue)) { diff --git a/changelog.txt b/changelog.txt index c5aacc6b..db94e2fa 100644 --- a/changelog.txt +++ b/changelog.txt @@ -4,6 +4,7 @@ Date: soon Changes: - Add a help message and proper handling for command line arguments - Removed default pollution cost from calculation. Added a setting to customize pollution cost. + - Add fuel consumption recipe for products ---------------------------------------------------------------------------------------------------------------------- Version: 0.6.4 Date: April 16th 2024