Skip to content

Commit 0d0f1c3

Browse files
authored
Merge pull request #29 from wmioch/codex/fix-recipe-display-overflow-issue
Scale recipe rows to fit their containers
2 parents 30090b8 + d16d4e1 commit 0d0f1c3

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

core/src/de/dakror/quarry/scenes/GameUi.java

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,7 @@
204204
public class GameUi implements Ui {
205205
public static final int ICONS_PER_COLUMN = 3;
206206
public static final int TOOLTIP_ICON_SIZE = 32;
207+
private static final float RECIPE_CONTENT_WIDTH = 320f;
207208
public static final int RESOURCES_ICON_SIZE = 24;
208209

209210
static DecimalFormat intFormat;
@@ -2482,6 +2483,19 @@ public static NinePatchDrawable getDrawable(Skin skin, String name, int padTop,
24822483
return d;
24832484
}
24842485

2486+
private static void shrinkRecipeRow(Table row, Cell<?> cell) {
2487+
row.pack();
2488+
float prefWidth = row.getPrefWidth();
2489+
if (prefWidth > RECIPE_CONTENT_WIDTH) {
2490+
float scale = RECIPE_CONTENT_WIDTH / prefWidth;
2491+
row.setTransform(true);
2492+
row.setScale(scale);
2493+
row.setOrigin(Align.left);
2494+
cell.width(RECIPE_CONTENT_WIDTH);
2495+
cell.height(row.getPrefHeight() * scale);
2496+
}
2497+
}
2498+
24852499
// TODO: resolve actual used items and not only the general recipe
24862500
// Also see ProductionStructure.updateUI()
24872501
public static Table renderRecipe(Skin skin, Recipe recipe,
@@ -2512,7 +2526,7 @@ public static Table renderRecipe(Skin skin, Recipe recipe,
25122526
else
25132527
inputs.add(createResourceTable(TOOLTIP_ICON_SIZE, skin, a.getItem(), text)).padRight(5);
25142528
}
2515-
table.add(inputs).expandX();
2529+
shrinkRecipeRow(inputs, table.add(inputs).expandX().fillX());
25162530
}
25172531

25182532
table.row();
@@ -2570,6 +2584,7 @@ public static Table renderRecipe(Skin skin, Recipe recipe,
25702584
Cell<?> c = table.add(outputs).center();
25712585
if (recipe.getInput() == null)
25722586
c.expandX();
2587+
shrinkRecipeRow(outputs, c);
25732588
}
25742589

25752590
return table;

0 commit comments

Comments
 (0)