diff --git a/Docs/ContributorsGuide.md b/Docs/ContributorsGuide.md index 6935f07c..563ef6b6 100644 --- a/Docs/ContributorsGuide.md +++ b/Docs/ContributorsGuide.md @@ -5,6 +5,7 @@ To make your experience better, there are a couple of things to keep in mind whe Coding phase: * Please use the same code style as the rest of the codebase. * Please prioritize maintainability. Aim for understandable code without dirty hacks. +* Please separate refactoring and the change of behavior into different commits, so it is easier to review the PR. * Please document the code. If you can also document the existing code, we would be thankful. Better documentation allows others to understand the code faster and thus to contribute more. * In a programmers' haven, there's a spot for devs who write tests. diff --git a/YAFC/Widgets/ImmediateWidgets.cs b/YAFC/Widgets/ImmediateWidgets.cs index dca0d656..1f2f09c1 100644 --- a/YAFC/Widgets/ImmediateWidgets.cs +++ b/YAFC/Widgets/ImmediateWidgets.cs @@ -120,7 +120,7 @@ public static bool BuildInlineObjectList(this ImGui gui, IEnumerable list, return selected != null; } - public static void BuildInlineObejctListAndButton(this ImGui gui, ICollection list, IComparer ordering, Action select, string header, int count = 6, bool multiple = false, Predicate checkmark = null, bool allowNone = false, Func extra = null) where T : FactorioObject { + public static void BuildInlineObjectListAndButton(this ImGui gui, ICollection list, IComparer ordering, Action select, string header, int count = 6, bool multiple = false, Predicate checkmark = null, bool allowNone = false, Func extra = null) where T : FactorioObject { using (gui.EnterGroup(default, RectAllocator.Stretch)) { if (gui.BuildInlineObjectList(list, ordering, header, out var selected, count, checkmark, extra)) { select(selected); @@ -144,13 +144,13 @@ public static bool BuildFactorioObjectWithAmount(this ImGui gui, FactorioObject if (goods != null) { gui.BuildText(DataUtils.FormatAmount(amount, unit), Font.text, false, RectAlignment.Middle); if (InputSystem.Instance.control && gui.BuildButton(gui.lastRect, SchemeColor.None, SchemeColor.Grey) == ButtonEvent.MouseOver) - ShowPrecisionValueTootlip(gui, amount, unit, goods); + ShowPrecisionValueTooltip(gui, amount, unit, goods); } return clicked; } } - public static void ShowPrecisionValueTootlip(ImGui gui, float amount, UnitOfMeasure unit, FactorioObject goods) { + public static void ShowPrecisionValueTooltip(ImGui gui, float amount, UnitOfMeasure unit, FactorioObject goods) { string text; switch (unit) { case UnitOfMeasure.PerSecond: @@ -173,8 +173,11 @@ public static void ShowPrecisionValueTootlip(ImGui gui, float amount, UnitOfMeas }, 10f); } - public static void BuildObjectSelectDropDown(this ImGui gui, ICollection list, IComparer ordering, Action select, string header, int count = 6, bool multiple = false, Predicate checkmark = null, bool allowNone = false, Func extra = null) where T : FactorioObject { - gui.ShowDropDown(imGui => imGui.BuildInlineObejctListAndButton(list, ordering, select, header, count, multiple, checkmark, allowNone, extra)); + /// Shows a dropdown containing the (partial) of elements, with an action for when an element is selected. + /// Maximum number of elements in the list. If there are more another popup can be opened by the user to show the full list. + /// Width of the popup. Make sure the header text fits! + public static void BuildObjectSelectDropDown(this ImGui gui, ICollection list, IComparer ordering, Action select, string header, float width = 20f, int count = 6, bool multiple = false, Predicate checkmark = null, bool allowNone = false, Func extra = null) where T : FactorioObject { + gui.ShowDropDown(imGui => imGui.BuildInlineObjectListAndButton(list, ordering, select, header, count, multiple, checkmark, allowNone, extra), width); } public static GoodsWithAmountEvent BuildFactorioObjectWithEditableAmount(this ImGui gui, FactorioObject obj, float amount, UnitOfMeasure unit, out float newAmount, SchemeColor color = SchemeColor.None) { diff --git a/YAFC/Windows/NeverEnoughItemsPanel.cs b/YAFC/Windows/NeverEnoughItemsPanel.cs index c0ef2b4c..c3949a29 100644 --- a/YAFC/Windows/NeverEnoughItemsPanel.cs +++ b/YAFC/Windows/NeverEnoughItemsPanel.cs @@ -90,7 +90,7 @@ private void DrawIngredients(ImGui gui, Recipe recipe) { foreach (var ingredient in recipe.ingredients) if (gui.BuildFactorioObjectWithAmount(ingredient.goods, ingredient.amount, UnitOfMeasure.None)) { if (ingredient.variants != null) - gui.ShowDropDown(imGui => imGui.BuildInlineObejctListAndButton(ingredient.variants, DataUtils.DefaultOrdering, SetItem, "Accepted fluid variants")); + gui.ShowDropDown(imGui => imGui.BuildInlineObjectListAndButton(ingredient.variants, DataUtils.DefaultOrdering, SetItem, "Accepted fluid variants")); else changing = ingredient.goods; } diff --git a/YAFC/Windows/PreferencesScreen.cs b/YAFC/Windows/PreferencesScreen.cs index 88e06be7..9b4040f7 100644 --- a/YAFC/Windows/PreferencesScreen.cs +++ b/YAFC/Windows/PreferencesScreen.cs @@ -61,7 +61,7 @@ public override void Build(ImGui gui) { ChoiceObject(gui, "Target technology for cost analysis: ", Database.technologies.all, prefs.targetTechnology, x => { prefs.RecordUndo().targetTechnology = x; gui.Rebuild(); - }); + }, width: 25f); if (gui.BuildButton("Done")) Close(); @@ -71,11 +71,14 @@ public override void Build(ImGui gui) { Project.current.RecalculateDisplayPages(); } - private void ChoiceObject(ImGui gui, string text, T[] list, T current, Action select) where T : FactorioObject { + /// Add a GUI element that opens a popup to allow the user to choose from the , which triggers . + /// Label to show. + /// Width of the popup. Make sure it is wide enough to fit text! + private void ChoiceObject(ImGui gui, string text, T[] list, T current, Action select, float width = 20f) where T : FactorioObject { using (gui.EnterRow()) { gui.BuildText(text, topOffset: 0.5f); if (gui.BuildFactorioObjectButtonWithText(current)) - gui.BuildObjectSelectDropDown(list, DataUtils.DefaultOrdering, select, text); + gui.BuildObjectSelectDropDown(list, DataUtils.DefaultOrdering, select, text, width: width); } } diff --git a/YAFC/Workspace/ProductionSummary/ProductionSummaryView.cs b/YAFC/Workspace/ProductionSummary/ProductionSummaryView.cs index c9aa789a..e42e82c9 100644 --- a/YAFC/Workspace/ProductionSummary/ProductionSummaryView.cs +++ b/YAFC/Workspace/ProductionSummary/ProductionSummaryView.cs @@ -190,7 +190,7 @@ public override void BuildElement(ImGui gui, ProductionSummaryEntry data) { if (evt == ButtonEvent.Click) view.AddOrRemoveColumn(goods); else if (evt == ButtonEvent.MouseOver) - ImmediateWidgets.ShowPrecisionValueTootlip(gui, amount, goods.flowUnitOfMeasure, goods); + ImmediateWidgets.ShowPrecisionValueTooltip(gui, amount, goods.flowUnitOfMeasure, goods); } } } diff --git a/YAFC/Workspace/ProductionTable/ProductionTableView.cs b/YAFC/Workspace/ProductionTable/ProductionTableView.cs index 1bc95ea9..69fb393a 100644 --- a/YAFC/Workspace/ProductionTable/ProductionTableView.cs +++ b/YAFC/Workspace/ProductionTable/ProductionTableView.cs @@ -257,7 +257,7 @@ private void BuildSolarPanelAccumulatorView(ImGui gui, RecipeRow recipe) { private void ShowAccumulatorDropdown(ImGui gui, RecipeRow recipe, Entity accumulator) { gui.ShowDropDown(imGui => { - imGui.BuildInlineObejctListAndButton(Database.allAccumulators, DataUtils.DefaultOrdering, + imGui.BuildInlineObjectListAndButton(Database.allAccumulators, DataUtils.DefaultOrdering, accum => recipe.RecordUndo().ChangeVariant(accumulator, accum), "Select accumulator", extra: x => DataUtils.FormatAmount(x.accumulatorCapacity, UnitOfMeasure.Megajoule)); }); @@ -265,7 +265,7 @@ private void ShowAccumulatorDropdown(ImGui gui, RecipeRow recipe, Entity accumul private void ShowEntityDropPown(ImGui imgui, RecipeRow recipe) { imgui.ShowDropDown(gui => { - gui.BuildInlineObejctListAndButton(recipe.recipe.crafters, DataUtils.FavouriteCrafter, sel => { + gui.BuildInlineObjectListAndButton(recipe.recipe.crafters, DataUtils.FavouriteCrafter, sel => { if (recipe.entity == sel) return; recipe.RecordUndo().entity = sel; @@ -464,7 +464,7 @@ private void ShowModuleDropDown(ImGui gui, RecipeRow recipe) { } if (recipe.entity?.moduleSlots > 0) - dropGui.BuildInlineObejctListAndButton(modules, DataUtils.FavouriteModule, recipe.SetFixedModule, "Select fixed module"); + dropGui.BuildInlineObjectListAndButton(modules, DataUtils.FavouriteModule, recipe.SetFixedModule, "Select fixed module"); if (moduleTemplateList.data.Count > 0) { dropGui.BuildText("Use module template:", wrap: true, font: Font.subheader); @@ -606,7 +606,7 @@ void DropDownContent(ImGui gui) { gui.BuildText("This entity has no known fuels"); else if (recipe.entity.energy.fuels.Length > 1 || recipe.entity.energy.fuels[0] != recipe.fuel) { BuildFavourites(gui, recipe.fuel, "Add fuel to favourites"); - gui.BuildInlineObejctListAndButton(recipe.entity.energy.fuels, DataUtils.FavouriteFuel, selectFuel, "Select fuel", extra: fuelDisplayFunc); + gui.BuildInlineObjectListAndButton(recipe.entity.energy.fuels, DataUtils.FavouriteFuel, selectFuel, "Select fuel", extra: fuelDisplayFunc); } } @@ -644,7 +644,7 @@ void DropDownContent(ImGui gui) { } if (type != ProductDropdownType.Product && goods != null && allProduction.Length > 0) { - gui.BuildInlineObejctListAndButton(allProduction, comparer, addRecipe, "Add production recipe", 6, true, recipeExists); + gui.BuildInlineObjectListAndButton(allProduction, comparer, addRecipe, "Add production recipe", 6, true, recipeExists); if (link == null) { var iconRect = new Rect(gui.lastRect.Right - 2f, gui.lastRect.Top, 2f, 2f); gui.DrawIcon(iconRect.Expand(-0.2f), Icon.OpenNew, gui.textColor); @@ -657,10 +657,10 @@ void DropDownContent(ImGui gui) { } if (type != ProductDropdownType.Fuel && goods != null && type != ProductDropdownType.Ingredient && goods.usages.Length > 0) - gui.BuildInlineObejctListAndButton(goods.usages, DataUtils.DefaultRecipeOrdering, addRecipe, "Add consumption recipe", type == ProductDropdownType.Product ? 6 : 3, true, recipeExists); + gui.BuildInlineObjectListAndButton(goods.usages, DataUtils.DefaultRecipeOrdering, addRecipe, "Add consumption recipe", type == ProductDropdownType.Product ? 6 : 3, true, recipeExists); if (type == ProductDropdownType.Product && goods != null && allProduction.Length > 0) - gui.BuildInlineObejctListAndButton(allProduction, comparer, addRecipe, "Add production recipe", 1, true, recipeExists); + gui.BuildInlineObjectListAndButton(allProduction, comparer, addRecipe, "Add production recipe", 1, true, recipeExists); if (link != null && gui.BuildCheckBox("Allow overproduction", link.algorithm == LinkAlgorithm.AllowOverProduction, out var newValue)) link.RecordUndo().algorithm = newValue ? LinkAlgorithm.AllowOverProduction : LinkAlgorithm.Match; diff --git a/YAFCui/ImGui/ImGuiBuilding.cs b/YAFCui/ImGui/ImGuiBuilding.cs index 001a1ea9..8a98b730 100644 --- a/YAFCui/ImGui/ImGuiBuilding.cs +++ b/YAFCui/ImGui/ImGuiBuilding.cs @@ -168,7 +168,7 @@ private void BuildGui(float width) { rebuildRequested = false; ClearDrawCommandList(); DoGui(ImGuiAction.Build); - contentSize = new Vector2(lastContentRect.Width, lastContentRect.Height); + contentSize = new Vector2(lastContentRect.Right, lastContentRect.Height); if (boxColor != SchemeColor.None) { var rect = new Rect(default, contentSize); rects.Add(new DrawCommand(rect, boxShadow, boxColor)); diff --git a/changelog.txt b/changelog.txt index dd90305f..062de5b6 100644 --- a/changelog.txt +++ b/changelog.txt @@ -6,7 +6,8 @@ Date: soon(tm) - Checkbox to show only goods with 'issues': different consuming/producing amounts - Balance producing side to match the consuming when clicking an 'issue' - Support the search box (ctrl+F) - + - Fix text alignment of about screen + - Fix width of 'Target technology for cost analysis' preference popup ---------------------------------------------------------------------------------------------------------------------- Version: 0.6.1 Date: Feb 2024