package ruscz.game.gameOfProd.BattleUI; import ruscz.game.gameOfProd.Image.ImageCell; import ruscz.game.gameOfProd.Inventory.InventoryManager; import ruscz.game.gameOfProd.Inventory.Item; import ruscz.game.gameOfProd.Inventory.ItemAction; import ruscz.game.gameOfProd.Inventory.ItemPanel; import ruscz.game.gameOfProd.Windows.WindowOfBattle; import javax.swing.*; import java.awt.*; import static ruscz.game.gameOfProd.Windows.WindowOfBattle.CELL_SIZE; public class ItemsInventory extends JPanel { private final JPanel items; private final ImageCell imageCell; private final WindowOfBattle windowOfBattle; public ItemsInventory(WindowOfBattle window){ imageCell = new ImageCell(); imageCell.imageItem("TransparentIcons.png"); windowOfBattle = window; setSize(CELL_SIZE * 8, CELL_SIZE * 6); setLocation(CELL_SIZE * 4, CELL_SIZE * 2); setBackground(new Color(255, 255, 255, 150)); setBorder(BorderFactory.createLineBorder(new Color(213, 108, 18), 2)); setVisible(false); items = new JPanel(); JButton returnToMenu = window.style(new JButton(" x ")); returnToMenu.addActionListener(e -> { window.getMenuOfActions().getAttack().setEnabled(true); window.getMenuOfActions().getConsole().setEnabled(true); window.getMenuOfActions().getInventory().setEnabled(true); window.getMenuOfActions().getEscape().setEnabled(true); setVisible(false); }); add(items); add(returnToMenu); } public void refreshItemsInField() { for (Component c: items.getComponents()) items.remove(c); System.out.println(InventoryManager.getInventory()); for (Item item: InventoryManager.getInventory()){ JPanel jPanel = new JPanel(); jPanel.setLayout(new GridLayout(1, 5)); jPanel.setSize(CELL_SIZE * 8, 32); ItemPanel itemPanel = new ItemPanel(imageCell, item.getImage()); itemPanel.setSize(32, 32); jPanel.add(itemPanel); jPanel.add(new JLabel(item.getName())); jPanel.add(new JLabel(String.valueOf(item.getMultiplicity()))); jPanel.add(new JLabel(String.valueOf(item.getItemAction()))); if (item.getItemAction().equals(ItemAction.HEAL)){ JButton use = windowOfBattle.style(new JButton("Use")); use.addActionListener(e -> { setVisible(false); windowOfBattle.getBattle().getHeroes().getFirst().heal(100); windowOfBattle.getMenuOfActions().setVisible(false); windowOfBattle.getEnemyDescription().setVisible(false); windowOfBattle.getSituationText().setVisible(true); windowOfBattle.writeToOutput(windowOfBattle.getBattle().getHeroes().getFirst().getName() + " heals 100 HP"); InventoryManager.removeItem(item, 1); windowOfBattle.getBattle().addToTurnOrder(windowOfBattle.getBattle().getHeroes().getFirst()); windowOfBattle.getBattle().setTurnBelongTo(null); windowOfBattle.getBattle().setDelay(2); windowOfBattle.getBattle().getTimer().start(); }); jPanel.add(use); } items.add(jPanel); } items.setVisible(true); if (items.getComponents().length == 0) items.setVisible(false); } }