Commit c37dde89 authored by Ciliste's avatar Ciliste
Browse files

Update MultiplayerGamePanel.java

parent a29ad9c6
Loading
Loading
Loading
Loading
+315 B (572 B)
Loading image diff...
+65 −0
Changes for jeuAssemblage/src/view/component/MultiplayerGamePanel.java: 65 added lines, 0 removed lines.
Original line number Diff line number Diff line
package view.component;

import javax.swing.BoxLayout;
import javax.swing.JPanel;
import javax.swing.JScrollPane;

import model.PlayBoard;
import view.MainFrame;
import view.component.board.Grid;
import view.component.board.TimerPanel.Timer;
import view.screen.AIGameCreation.BotDescriptor;
import view.utils.SwingUtils;

public class MultiplayerGamePanel extends JPanel {

	private final GamePanel gamePanel;

	private final JScrollPane scrollPane = new JScrollPane();

	public MultiplayerGamePanel(MainFrame mainFrame, PlayBoard playBoard, Timer timer, Iterable<BotDescriptor> botDescriptors) {

		super();

		this.gamePanel = new GamePanel(mainFrame, playBoard, timer);

		JPanel bots = new JPanel();
		bots.setLayout(new BoxLayout(bots, BoxLayout.Y_AXIS));

		for (BotDescriptor botDescriptor : botDescriptors) {

			System.out.println(botDescriptor);

			Grid grid = new Grid(PlayBoard.constructCopyPlayBoard(playBoard), true);

			bots.add(grid);
		}

		scrollPane.setViewportView(bots);

		setLayout(null);

		this.add(this.gamePanel);
		this.add(scrollPane);
	}

	@Override
	public void doLayout() {

		super.doLayout();

		this.gamePanel.setBounds(
			0,
		 	0,
		 	SwingUtils.getWidthTimesPourcent(this, .8f),
			getHeight()
		);

		this.scrollPane.setBounds(
			SwingUtils.getWidthTimesPourcent(this, .8f),
			0,
			SwingUtils.getWidthTimesPourcent(this, .2f),
			getHeight()
		);
	}
}
+67 −32
Changes for jeuAssemblage/src/view/screen/AIGameCreation.java: 67 added lines, 32 removed lines.
Original line number Diff line number Diff line
@@ -3,32 +3,43 @@ package view.screen;
import static view.utils.SwingUtils.getHeightTimesPourcent;
import static view.utils.SwingUtils.getWidthTimesPourcent;

import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;

import javax.swing.BoxLayout;
import javax.swing.JButton;
import javax.swing.JList;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.JComboBox;
import javax.swing.JLabel;
import javax.swing.JList;
import javax.swing.JPanel;
import javax.swing.JScrollPane;

import model.PlayBoard;
import model.ProfileUtils;
import view.MainFrame;
import view.component.MultiplayerGamePanel;
import view.component.board.TimerPanel.Timer;
import view.utils.SwingUtils;

public class AIGameCreation extends SoloGameCreation {
	
	private final JList<BotDescriptor> bots = new JList<>();
	private final JPanel bots = new JPanel();
	private final List<BotDescriptor> botDescriptors = new LinkedList<>();

	private final JButton btnAddBot = new JButton("Ajouter un robot");

	private final JScrollPane scrollPane = new JScrollPane(bots);

	private final MainFrame mainFrame;

	public AIGameCreation(MainFrame mainFrame) {
		
		super(mainFrame);

		this.mainFrame = mainFrame;

		bots.setLayout(new BoxLayout(bots, BoxLayout.Y_AXIS));

		add(scrollPane);
		add(btnAddBot);

@@ -38,34 +49,13 @@ public class AIGameCreation extends SoloGameCreation {

			BotDescriptor bot = new BotDescriptor(botName, 1);

			BotDescriptor[] botDescriptors = new BotDescriptor[bots.getModel().getSize() + 1];
			for (int i = 0; i < bots.getModel().getSize(); i++) {
			JPanel renderer = createBotDescriptorRenderer(bot);

				botDescriptors[i] = bots.getModel().getElementAt(i);
			}

			botDescriptors[bots.getModel().getSize()] = bot;

			bots.setListData(botDescriptors);
		});

		// Change list component renderer
		bots.setCellRenderer((list, value, index, isSelected, cellHasFocus) -> {

			JPanel panel = new JPanel();

			panel.setLayout(new BoxLayout(panel, BoxLayout.X_AXIS));

			JLabel label = new JLabel(value.getName());
			label.setAlignmentX(LEFT_ALIGNMENT);
			panel.add(label);

			JLabel label2 = new JLabel(" (" + value.getDifficulty() + ")");
			label2.setAlignmentX(LEFT_ALIGNMENT);
			panel.add(label2);

			return panel;
			bots.add(renderer);
			botDescriptors.add(bot);

			bots.revalidate();
			bots.repaint();
		});
	}

@@ -77,7 +67,7 @@ public class AIGameCreation extends SoloGameCreation {
		final int PADDING_LEFT = getWidthTimesPourcent(this, .05f);
		final int PADDING_TOP = getHeightTimesPourcent(this, .05f);
		
		final int SCROLLPANE_WIDTH = getWidthTimesPourcent(this, .15f);
		final int SCROLLPANE_WIDTH = getWidthTimesPourcent(this, .25f);
		final int SCROLLPANE_HEIGHT = getHeightTimesPourcent(this, .15f);

		scrollPane.setBounds(
@@ -95,6 +85,51 @@ public class AIGameCreation extends SoloGameCreation {
		);
	}

	@Override
	protected void startGame(PlayBoard playBoard, Timer timer) {

		mainFrame.setContentPane(new MultiplayerGamePanel(mainFrame, playBoard, timer, botDescriptors));
	}

	private JPanel createBotDescriptorRenderer(BotDescriptor botDescriptor) {

		JPanel panel = new JPanel();

		panel.setMaximumSize(new java.awt.Dimension(32767, 20));

		panel.setLayout(new BoxLayout(panel, BoxLayout.X_AXIS));

		JLabel label = new JLabel(botDescriptor.getName());
		label.setAlignmentX(LEFT_ALIGNMENT);
		panel.add(label);

		JComboBox<Integer> comboBox = new JComboBox<>(new Integer[] { 1, 2, 3, 4, 5 });
		comboBox.setSelectedItem(botDescriptor.getDifficulty());

		comboBox.addActionListener(e -> {

			botDescriptor.setDifficulty((int) comboBox.getSelectedItem());
		});

		panel.add(comboBox);

		JButton btnRemove = new JButton("X");

		btnRemove.addActionListener(e -> {

			botDescriptors.remove(botDescriptor);

			bots.remove(panel);

			bots.revalidate();
			bots.repaint();
		});

		panel.add(btnRemove);

		return panel;
	}

	public static class BotDescriptor {

		private String name;
−408 B (2.32 KiB)
Loading image diff...