mmb.menu.world.craft.CraftingRecipeView Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of multimachinebuilder Show documentation
Show all versions of multimachinebuilder Show documentation
Dependency for the MultiMachineBuilder, a voxel game about building an industrial empire in a finite world.
THIS RELEASE IS NOT PLAYABLE. To play the game, donwload from >ITCH.IO LINK HERE< or >GH releases link here<
/**
*
*/
package mmb.menu.world.craft;
import net.miginfocom.swing.MigLayout;
import javax.swing.JLabel;
import java.awt.Dimension;
import java.awt.Graphics;
import javax.swing.JComponent;
import monniasza.collects.grid.Grid;
import javax.swing.JList;
import mmb.engine.craft.rgroups.CraftingRecipeGroup.CraftingRecipe;
import mmb.engine.inv.ItemStack;
import mmb.engine.item.ItemEntry;
import java.awt.Color;
/**
* Represents a recipe view for crafting recipes
* @author oskar
*/
public class CraftingRecipeView extends RecipeView{
private static final long serialVersionUID = 5070877744489415798L;
private ItemGrid grid;
private JList out;
private JList in;
/** Creates recipe view for crafting recipes */
public CraftingRecipeView() {
setLayout(new MigLayout("", "[grow][grow][grow]", "[][grow]"));
JLabel lblI = new JLabel(CRConstants.IN);
lblI.setBackground(Color.ORANGE);
lblI.setOpaque(true);
add(lblI, "cell 0 0 2 1,growx");
JLabel lblO = new JLabel(CRConstants.OUT);
lblO.setBackground(Color.BLUE);
lblO.setOpaque(true);
add(lblO, "cell 2 0,growx");
grid = new ItemGrid();
add(grid, "cell 0 1,growx");
in = new JList<>();
in.setCellRenderer(ItemStackCellRenderer.instance);
add(in, "cell 1 1,grow");
out = new JList<>();
out.setCellRenderer(ItemStackCellRenderer.instance);
add(out, "cell 2 1,grow");
}
@Override
public void set(CraftingRecipe recipe) {
grid.setGrid(recipe.grid);
out.setListData(VectorUtils.list2arr(recipe.out));
in.setListData(VectorUtils.list2arr(recipe.in));
}
/**
* @author oskar
*
*/
public static class ItemGrid extends JComponent{
private static final long serialVersionUID = 952344490217533557L;
private transient Grid grid;
/**
* @return the grid
*/
public Grid getGrid() {
return grid;
}
/**
* @param grid the grid to set
*/
public void setGrid(Grid grid) {
this.grid = grid;
}
@Override
public void paint(@SuppressWarnings("null") Graphics g) {
if(grid == null) return;
for(int x = 0; x < grid.width(); x++) {
for(int y = 0; y < grid.height(); y++) {
ItemEntry item = grid.get(x, y);
if(item != null) item.icon().paintIcon(this, g, x*32, y*32);
}
}
}
@Override
public Dimension getPreferredSize() {
return new Dimension(grid.width() * 32, grid.height() * 32);
}
}
}