|
204 | 204 | public class GameUi implements Ui { |
205 | 205 | public static final int ICONS_PER_COLUMN = 3; |
206 | 206 | public static final int TOOLTIP_ICON_SIZE = 32; |
| 207 | + private static final float RECIPE_CONTENT_WIDTH = 320f; |
207 | 208 | public static final int RESOURCES_ICON_SIZE = 24; |
208 | 209 |
|
209 | 210 | static DecimalFormat intFormat; |
@@ -2482,6 +2483,19 @@ public static NinePatchDrawable getDrawable(Skin skin, String name, int padTop, |
2482 | 2483 | return d; |
2483 | 2484 | } |
2484 | 2485 |
|
| 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 | + |
2485 | 2499 | // TODO: resolve actual used items and not only the general recipe |
2486 | 2500 | // Also see ProductionStructure.updateUI() |
2487 | 2501 | public static Table renderRecipe(Skin skin, Recipe recipe, |
@@ -2512,7 +2526,7 @@ public static Table renderRecipe(Skin skin, Recipe recipe, |
2512 | 2526 | else |
2513 | 2527 | inputs.add(createResourceTable(TOOLTIP_ICON_SIZE, skin, a.getItem(), text)).padRight(5); |
2514 | 2528 | } |
2515 | | - table.add(inputs).expandX(); |
| 2529 | + shrinkRecipeRow(inputs, table.add(inputs).expandX().fillX()); |
2516 | 2530 | } |
2517 | 2531 |
|
2518 | 2532 | table.row(); |
@@ -2570,6 +2584,7 @@ public static Table renderRecipe(Skin skin, Recipe recipe, |
2570 | 2584 | Cell<?> c = table.add(outputs).center(); |
2571 | 2585 | if (recipe.getInput() == null) |
2572 | 2586 | c.expandX(); |
| 2587 | + shrinkRecipeRow(outputs, c); |
2573 | 2588 | } |
2574 | 2589 |
|
2575 | 2590 | return table; |
|
0 commit comments