Skip to content

Commit 15f67a8

Browse files
committed
Fix several places where we should be filtering negative values.
1 parent 52b12a7 commit 15f67a8

File tree

5 files changed

+11
-11
lines changed

5 files changed

+11
-11
lines changed

Yafc/Windows/PreferencesScreen.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ public override void Build(ImGui gui) {
4141
using (gui.EnterRowWithHelpIcon("0 for off, 100% for old default")) {
4242
gui.BuildText("Pollution cost modifier", topOffset: 0.5f);
4343
DisplayAmount amount = new(settings.PollutionCostModifier, UnitOfMeasure.Percent);
44-
if (gui.BuildFloatInput(amount, new Padding(0.5f))) {
44+
if (gui.BuildFloatInput(amount, new Padding(0.5f)) && amount.Value >= 0) {
4545
settings.RecordUndo().PollutionCostModifier = amount.Value;
4646
gui.Rebuild();
4747
}

Yafc/Workspace/ProductionTable/ModuleCustomizationScreen.cs

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -182,13 +182,8 @@ private void DrawRecipeModules(ImGui gui, EntityBeacon? beacon, ref ModuleEffect
182182
}, DataUtils.FavoriteModule);
183183
break;
184184

185-
case GoodsWithAmountEvent.TextEditing:
186-
int amountInt = MathUtils.Floor(amount.Value);
187-
if (amountInt < 0) {
188-
amountInt = 0;
189-
}
190-
191-
rowCustomModule.RecordUndo().fixedCount = amountInt;
185+
case GoodsWithAmountEvent.TextEditing when amount.Value >= 0:
186+
rowCustomModule.RecordUndo().fixedCount = (int)amount.Value;
192187
break;
193188
}
194189

Yafc/Workspace/ProductionTable/ModuleFillerParametersScreen.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ private void ListDrawer(ImGui gui, KeyValuePair<EntityCrafter, BeaconOverrideCon
4949
}
5050
});
5151
break;
52-
case GoodsWithAmountEvent.TextEditing:
52+
case GoodsWithAmountEvent.TextEditing when amount.Value >= 0:
5353
modules.RecordUndo().overrideCrafterBeacons[crafter].beaconCount = (int)amount.Value;
5454
break;
5555
}
@@ -168,7 +168,7 @@ public override void Build(ImGui gui) {
168168
}
169169
}, noneTooltip: "Click here to remove the current override.");
170170
return;
171-
case GoodsWithAmountEvent.TextEditing:
171+
case GoodsWithAmountEvent.TextEditing when amount.Value >= 0:
172172
modules.RecordUndo().overrideCrafterBeacons[crafter].beaconCount = (int)amount.Value;
173173
return;
174174
}

Yafc/Workspace/ProductionTable/ProductionTableView.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -283,7 +283,7 @@ public override void BuildElement(ImGui gui, RecipeRow recipe) {
283283
if (recipe.fixedBuildings > 0) {
284284
DisplayAmount amount = recipe.fixedBuildings;
285285
GoodsWithAmountEvent evt = gui.BuildFactorioObjectWithEditableAmount(recipe.entity, amount, useScale: false);
286-
if (evt == GoodsWithAmountEvent.TextEditing) {
286+
if (evt == GoodsWithAmountEvent.TextEditing && amount.Value >= 0) {
287287
recipe.RecordUndo().fixedBuildings = amount.Value;
288288
}
289289

changelog.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,11 @@
1515
// Internal changes:
1616
// Changes to the code that do not affect the behavior of the program.
1717
----------------------------------------------------------------------------------------------------------------------
18+
Version
19+
Date:
20+
Bugfixes:
21+
- Refuse to accept negative numbers in several places where they don't make sense.
22+
----------------------------------------------------------------------------------------------------------------------
1823
Version 0.8.0
1924
Date: August 3rd 2024
2025
Features:

0 commit comments

Comments
 (0)