Skip to content

Commit

Permalink
Prevent disasters caused by scrolling over the beacon-count inputs.
Browse files Browse the repository at this point in the history
  • Loading branch information
DaleStan committed Jun 29, 2024
1 parent c3d0d56 commit c343bd7
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
4 changes: 2 additions & 2 deletions Yafc/Widgets/ImmediateWidgets.cs
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ public static void BuildObjectSelectDropDownWithNone<T>(this ImGui gui, ICollect
/// <param name="amount">Display this value, formatted appropriately for <paramref name="unit"/>.</param>
/// <param name="unit">Use this unit of measure when formatting <paramref name="amount"/> for display.</param>
/// <param name="newAmount">The new value entered by the user, if this returns <see cref="GoodsWithAmountEvent.TextEditing"/>. Otherwise, the original <paramref name="amount"/>.</param>
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;
Expand All @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ private ModuleFillerParametersScreen(ModuleFillerParameters modules) {

private void ListDrawer(ImGui gui, KeyValuePair<EntityCrafter, BeaconOverrideConfiguration> 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) {
Expand Down

0 comments on commit c343bd7

Please sign in to comment.