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 cdbd5bb
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
6 changes: 3 additions & 3 deletions Yafc/Widgets/ImmediateWidgets.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down 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 cdbd5bb

Please sign in to comment.