Skip to content
Open
Show file tree
Hide file tree
Changes from 2 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
2 changes: 2 additions & 0 deletions Yafc/Data/locale/en/yafc.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,8 @@ tooltip-entity-absorbs-pollution=Absorption: __1__ __2__ per minute
tooltip-entity-emits-pollution=Emission: __1__ __2__ per minute
tooltip-entity-requires-heat=Requires __1__ heat on cold planets.
tooltip-item-spoils=After __1__, spoils into
tooltip-copy-building-blueprint=Press Ctrl+C to copy building blueprint
button-copy-blueprint=Copy blueprint

; AboutScreen.cs
about-yafc=About YAFC-CE
Expand Down
66 changes: 65 additions & 1 deletion Yafc/Workspace/ProductionTable/ProductionTableView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ namespace Yafc;

public class ProductionTableView : ProjectPageView<ProductionTable> {
private readonly FlatHierarchy<RecipeRow, ProductionTable> flatHierarchyBuilder;
private RecipeRow? hoveredRecipe;

public ProductionTableView() {
DataGrid<RecipeRow> grid = new DataGrid<RecipeRow>(new RecipePadColumn(this), new RecipeColumn(this), new EntityColumn(this),
Expand Down Expand Up @@ -120,7 +121,22 @@ private static void BuildRowMarker(ImGui gui, RecipeRow row) {
private class RecipeColumn(ProductionTableView view) : ProductionTableDataColumn(view, LSs.ProductionTableHeaderRecipe, 13f, 13f, 30f, widthStorage: nameof(Preferences.recipeColumnWidth)) {
public override void BuildElement(ImGui gui, RecipeRow recipe) {
gui.spacing = 0.5f;
switch (gui.BuildFactorioObjectButton(recipe.recipe, ButtonDisplayStyle.ProductionTableUnscaled)) {
var buttonEvent = gui.BuildFactorioObjectButton(recipe.recipe, ButtonDisplayStyle.ProductionTableUnscaled);

// Track hovered recipe for Ctrl+C functionality and show tooltip
if (gui.IsMouseOver(gui.lastRect)) {
view.hoveredRecipe = recipe;

// Show tooltip with Ctrl+C hint if the recipe has an entity (can generate blueprint)
if (recipe.entity != null) {
gui.ShowTooltip(gui.lastRect, tooltip => {
tooltip.BuildText(recipe.recipe.target.locName, Font.subheader);
tooltip.BuildText(LSs.TooltipCopyBuildingBlueprint, TextBlockDisplayStyle.WrappedText);
});
}
}

switch (buttonEvent) {
case Click.Left:
gui.ShowDropDown(delegate (ImGui imgui) {
DrawRecipeTagSelect(imgui, recipe);
Expand All @@ -145,6 +161,11 @@ public override void BuildElement(ImGui gui, RecipeRow recipe) {
view.BuildShoppingList(recipe);
}

// Add "Copy blueprint" button if recipe has an entity
if (recipe.entity != null && imgui.BuildButton(LSs.ButtonCopyBlueprint) && imgui.CloseDropdown()) {
view.CopyRecipeBlueprint(recipe);
}

if (imgui.BuildCheckBox(LSs.ProductionTableShowTotalIo, recipe.showTotalIO, out bool newShowTotalIO)) {
recipe.RecordUndo().showTotalIO = newShowTotalIO;
}
Expand Down Expand Up @@ -1657,4 +1678,47 @@ void initializeGrid(ImGui gui) {
}
}
}

public override bool ControlKey(SDL.SDL_Scancode code) {
// Handle Ctrl+C to copy blueprint for hovered recipe
if (code == SDL.SDL_Scancode.SDL_SCANCODE_C && hoveredRecipe?.entity != null) {
CopyRecipeBlueprint(hoveredRecipe);
return true;
}

return base.ControlKey(code);
}

private void CopyRecipeBlueprint(RecipeRow recipe) {
if (recipe.entity == null) return;

BlueprintEntity entity = new BlueprintEntity { index = 1, name = recipe.entity.target.name };

if (!recipe.recipe.Is<Mechanics>()) {
entity.recipe = recipe.recipe.target.name;
entity.recipe_quality = recipe.recipe.quality.name;
}

var modules = recipe.usedModules.modules;

if (modules != null) {
int idx = 0;
foreach (var (module, count, beacon) in modules) {
if (!beacon) {
BlueprintItem item = new BlueprintItem { id = { name = module.target.name, quality = module.quality.name } };
item.items.inInventory.AddRange(Enumerable.Range(idx, count).Select(i => new BlueprintInventoryItem { stack = i }));
entity.items.Add(item);
idx += count;
}
}
}

if (Preferences.Instance.exportEntitiesWithFuelFilter && recipe.fuel is not null && !recipe.fuel.target.isPower) {
entity.SetFuel(recipe.fuel.target.name, recipe.fuel.quality.name);
}

// Use the existing utility function to generate and copy the blueprint
// This automatically handles proper base64 encoding
_ = BlueprintUtilities.ExportRecipiesAsBlueprint(recipe.recipe.target.locName, [recipe], Preferences.Instance.exportEntitiesWithFuelFilter);
}
}
4 changes: 3 additions & 1 deletion changelog.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@
Version:
Date:
Features:

- Add Ctrl+C shortcut to copy building blueprint for hovered recipe in production table.
- Add "Copy blueprint" button to recipe dropdown menu in production table.
- Add tooltip showing Ctrl+C hint when hovering over recipes with buildings.
Fixes:
- Fix icon rendering.
- Hide fluid temperature options when not part of a recipe or not accepted by that recipe.
Expand Down
Loading