Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Hide non-functional fixed counts on disabled recipe rows. #341

Merged
merged 1 commit into from
Oct 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 24 additions & 22 deletions Yafc/Workspace/ProductionTable/ProductionTableView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,7 @@ public override void BuildElement(ImGui gui, RecipeRow recipe) {
Click click;
using (var group = gui.EnterGroup(default, RectAllocator.Stretch, spacing: 0f)) {
group.SetWidth(3f);
if (recipe.fixedBuildings > 0 && !recipe.fixedFuel && recipe.fixedIngredient == null && recipe.fixedProduct == null) {
if (recipe is { fixedBuildings: > 0, fixedFuel: false, fixedIngredient: null, fixedProduct: null, hierarchyEnabled: true }) {
DisplayAmount amount = recipe.fixedBuildings;
GoodsWithAmountEvent evt = gui.BuildFactorioObjectWithEditableAmount(recipe.entity, amount, ButtonDisplayStyle.ProductionTableUnscaled,
setKeyboardFocus: recipe.ShouldFocusFixedCountThisTime());
Expand Down Expand Up @@ -400,7 +400,7 @@ private static void ShowEntityDropdown(ImGui imgui, RecipeRow recipe) => imgui.S

gui.AllocateSpacing(0.5f);

if (recipe.fixedBuildings > 0f && (recipe.fixedFuel || recipe.fixedIngredient != null || recipe.fixedProduct != null)) {
if (recipe.fixedBuildings > 0f && (recipe.fixedFuel || recipe.fixedIngredient != null || recipe.fixedProduct != null || !recipe.hierarchyEnabled)) {
ButtonEvent evt = gui.BuildButton("Clear fixed recipe multiplier");
if (willResetFixed) {
_ = evt.WithTooltip(gui, "Shortcut: right-click");
Expand All @@ -410,28 +410,30 @@ private static void ShowEntityDropdown(ImGui imgui, RecipeRow recipe) => imgui.S
}
}

string fixedBuildingsTip = "Tell YAFC how many buildings it must use when solving this page.\n" +
"Use this to ask questions like 'What does it take to handle the output of ten miners?'";
if (recipe.hierarchyEnabled) {
string fixedBuildingsTip = "Tell YAFC how many buildings it must use when solving this page.\n" +
"Use this to ask questions like 'What does it take to handle the output of ten miners?'";

using (gui.EnterRowWithHelpIcon(fixedBuildingsTip)) {
gui.allocator = RectAllocator.RemainingRow;
if (recipe.fixedBuildings > 0f && !recipe.fixedFuel && recipe.fixedIngredient == null && recipe.fixedProduct == null) {
ButtonEvent evt = gui.BuildButton("Clear fixed building count");
using (gui.EnterRowWithHelpIcon(fixedBuildingsTip)) {
gui.allocator = RectAllocator.RemainingRow;
if (recipe.fixedBuildings > 0f && !recipe.fixedFuel && recipe.fixedIngredient == null && recipe.fixedProduct == null) {
ButtonEvent evt = gui.BuildButton("Clear fixed building count");

if (willResetFixed) {
_ = evt.WithTooltip(gui, "Shortcut: right-click");
}
if (willResetFixed) {
_ = evt.WithTooltip(gui, "Shortcut: right-click");
}

if (evt && gui.CloseDropdown()) {
recipe.RecordUndo().fixedBuildings = 0f;
if (evt && gui.CloseDropdown()) {
recipe.RecordUndo().fixedBuildings = 0f;
}
}
else if (gui.BuildButton("Set fixed building count") && gui.CloseDropdown()) {
recipe.RecordUndo().fixedBuildings = recipe.buildingCount <= 0f ? 1f : recipe.buildingCount;
recipe.fixedFuel = false;
recipe.fixedIngredient = null;
recipe.fixedProduct = null;
recipe.FocusFixedCountOnNextDraw();
}
}
else if (gui.BuildButton("Set fixed building count") && gui.CloseDropdown()) {
recipe.RecordUndo().fixedBuildings = recipe.buildingCount <= 0f ? 1f : recipe.buildingCount;
recipe.fixedFuel = false;
recipe.fixedIngredient = null;
recipe.fixedProduct = null;
recipe.FocusFixedCountOnNextDraw();
}
}

Expand Down Expand Up @@ -987,7 +989,7 @@ void dropDownContent(ImGui gui) {
#endregion

#region Fixed production/consumption
if (goods != null && recipe != null) {
if (goods != null && recipe != null && recipe.hierarchyEnabled) {
if (recipe.fixedBuildings == 0
|| (type == ProductDropdownType.Fuel && !recipe.fixedFuel)
|| (type == ProductDropdownType.Ingredient && recipe.fixedIngredient != goods)
Expand Down Expand Up @@ -1162,7 +1164,7 @@ private void BuildGoodsIcon(ImGui gui, Goods? goods, ProductionLink? link, float
};
}

if (recipe != null && recipe.fixedBuildings > 0
if (recipe != null && recipe.fixedBuildings > 0 && recipe.hierarchyEnabled
&& ((dropdownType == ProductDropdownType.Fuel && recipe.fixedFuel)
|| (dropdownType == ProductDropdownType.Ingredient && recipe.fixedIngredient == goods)
|| (dropdownType == ProductDropdownType.Product && recipe.fixedProduct == goods))) {
Expand Down
2 changes: 2 additions & 0 deletions changelog.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ Version:
Date:
Features:
- Add pseudo-items representing a recipe's total sushi-inputs and sushi-outputs.
Bugfixes:
- Fixed counts are hidden on disabled recipes, since editing them won't work properly.
----------------------------------------------------------------------------------------------------------------------
Version: 2.1.0
Date: October 29th 2024
Expand Down