From cdbd5bbaf9e0d604c01cea9649d1843af1bb7a9f Mon Sep 17 00:00:00 2001 From: Dale McCoy <21223975+DaleStan@users.noreply.github.com> Date: Wed, 25 Jan 2023 19:16:17 -0500 Subject: [PATCH] Prevent disasters caused by scrolling over the beacon-count inputs. --- Yafc/Widgets/ImmediateWidgets.cs | 6 +++--- .../ProductionTable/ModuleFillerParametersScreen.cs | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Yafc/Widgets/ImmediateWidgets.cs b/Yafc/Widgets/ImmediateWidgets.cs index 2bdf1136..d8306f2d 100644 --- a/Yafc/Widgets/ImmediateWidgets.cs +++ b/Yafc/Widgets/ImmediateWidgets.cs @@ -45,7 +45,7 @@ public static void BuildFactorioObjectIcon(this ImGui gui, FactorioObject? obj, gui.DrawIcon(rect.Expand(size * (Project.current.preferences.iconScale - 1) / 2), obj.icon, color); } else { - gui.BuildIcon(obj.icon, size, color); + gui.BuildIcon(obj.icon, size, color); } if (gui.isBuilding && display != MilestoneDisplay.None) { bool contain = (display & MilestoneDisplay.Contained) != 0; @@ -262,7 +262,7 @@ public static void BuildObjectSelectDropDownWithNone(this ImGui gui, ICollect /// Display this value, formatted appropriately for . /// Use this unit of measure when formatting for display. /// The new value entered by the user, if this returns . Otherwise, the original . - public static GoodsWithAmountEvent BuildFactorioObjectWithEditableAmount(this ImGui gui, FactorioObject? obj, float amount, UnitOfMeasure unit, out float newAmount, SchemeColor color = SchemeColor.None, bool useScale = true) { + public static GoodsWithAmountEvent BuildFactorioObjectWithEditableAmount(this ImGui gui, FactorioObject? obj, float amount, UnitOfMeasure unit, out float newAmount, SchemeColor color = SchemeColor.None, bool useScale = true, bool allowScroll = true) { using var group = gui.EnterGroup(default, RectAllocator.Stretch, spacing: 0f); group.SetWidth(3f); newAmount = amount; @@ -274,7 +274,7 @@ public static GoodsWithAmountEvent BuildFactorioObjectWithEditableAmount(this Im } } - if (gui.action == ImGuiAction.MouseScroll && gui.ConsumeEvent(gui.lastRect)) { + if (allowScroll && gui.action == ImGuiAction.MouseScroll && gui.ConsumeEvent(gui.lastRect)) { float digit = MathF.Pow(10, MathF.Floor(MathF.Log10(amount) - 2f)); newAmount = MathF.Round((amount / digit) + gui.actionParameter) * digit; evt = GoodsWithAmountEvent.TextEditing; diff --git a/Yafc/Workspace/ProductionTable/ModuleFillerParametersScreen.cs b/Yafc/Workspace/ProductionTable/ModuleFillerParametersScreen.cs index 60a8772b..af291402 100644 --- a/Yafc/Workspace/ProductionTable/ModuleFillerParametersScreen.cs +++ b/Yafc/Workspace/ProductionTable/ModuleFillerParametersScreen.cs @@ -21,7 +21,7 @@ private ModuleFillerParametersScreen(ModuleFillerParameters modules) { private void ListDrawer(ImGui gui, KeyValuePair element, int index) { var (crafter, config) = element; - GoodsWithAmountEvent click = gui.BuildFactorioObjectWithEditableAmount(crafter, config.beaconCount, UnitOfMeasure.None, out float newAmount); + GoodsWithAmountEvent click = gui.BuildFactorioObjectWithEditableAmount(crafter, config.beaconCount, UnitOfMeasure.None, out float newAmount, allowScroll: false); gui.DrawIcon(new(gui.lastRect.X, gui.lastRect.Y, 1.25f, 1.25f), config.beacon.icon, SchemeColor.Source); gui.DrawIcon(new(gui.lastRect.TopRight - new Vector2(1.25f, 0), new Vector2(1.25f, 1.25f)), config.beaconModule.icon, SchemeColor.Source); switch (click) {