package fr.monkhanny.dorfromantik.gui; import javax.swing.*; import java.awt.*; import java.awt.event.ActionListener; public class GameModeSelectionPanel extends JPanel { private JLabel titleLabel; private JButton mode1Button; private JButton mode2Button; private JButton mode3Button; private JButton mode4Button; private JTextField seedField; private JButton startButton; public GameModeSelectionPanel(ActionListener buttonListener) { setLayout(new BorderLayout()); // Add background image JLabel background = new JLabel(new ImageIcon("./ressources/images/MainMenu/backgroundBlured.jpg")); background.setLayout(new GridBagLayout()); this.setLayout(new BorderLayout()); this.add(background); // Main content panel JPanel mainPanel = createMainPanel(); background.add(mainPanel); // Title titleLabel = new JLabel("Choisissez un mode de jeu", JLabel.CENTER); titleLabel.setFont(new Font("Arial", Font.BOLD, 40)); titleLabel.setForeground(Color.WHITE); mainPanel.add(titleLabel, createGridBagConstraints(0, 0, 2)); mainPanel.add(Box.createVerticalStrut(30), createGridBagConstraints(0, 1, 1)); // Mode buttons - now horizontally aligned JPanel modePanel = new JPanel(new FlowLayout(FlowLayout.CENTER, 20, 10)); // Centered with horizontal spacing modePanel.setOpaque(false); mode1Button = createGameModeButton("Mode 1", buttonListener); mode2Button = createGameModeButton("Mode 2", buttonListener); mode3Button = createGameModeButton("Mode 3", buttonListener); mode4Button = createGameModeButton("Mode 4", buttonListener); modePanel.add(mode1Button); modePanel.add(mode2Button); modePanel.add(mode3Button); modePanel.add(mode4Button); mainPanel.add(modePanel, createGridBagConstraints(0, 2, 2)); // Span across 2 columns mainPanel.add(Box.createVerticalStrut(30), createGridBagConstraints(0, 3, 1)); // Seed input and start button JPanel seedPanel = createSeedPanel(buttonListener); mainPanel.add(seedPanel, createGridBagConstraints(0, 4, 2)); } private JPanel createMainPanel() { JPanel mainPanel = new JPanel(new GridBagLayout()); mainPanel.setOpaque(false); return mainPanel; } private GridBagConstraints createGridBagConstraints(int x, int y, int gridWidth) { GridBagConstraints gbc = new GridBagConstraints(); gbc.gridx = x; gbc.gridy = y; gbc.gridwidth = gridWidth; gbc.fill = GridBagConstraints.HORIZONTAL; gbc.insets = new Insets(20, 30, 20, 30); return gbc; } private JButton createGameModeButton(String modeName, ActionListener buttonListener) { JButton button = new JButton(modeName); button.setFont(new Font("Arial", Font.BOLD, 24)); button.setBackground(new Color(0, 122, 255)); button.setForeground(Color.WHITE); button.setBorder(BorderFactory.createLineBorder(Color.WHITE, 2)); button.setFocusPainted(false); button.addActionListener(buttonListener); button.setPreferredSize(new Dimension(150, 50)); // Adjust the size of the buttons return button; } private JPanel createSeedPanel(ActionListener buttonListener) { JPanel seedPanel = new JPanel(); seedPanel.setOpaque(false); seedPanel.setLayout(new FlowLayout(FlowLayout.CENTER)); JLabel seedLabel = new JLabel("Entrez votre seed:"); seedLabel.setForeground(Color.WHITE); seedPanel.add(seedLabel); seedField = new JTextField(20); seedField.setFont(new Font("Arial", Font.PLAIN, 18)); seedField.setPreferredSize(new Dimension(250, 40)); seedField.setBorder(BorderFactory.createLineBorder(Color.WHITE, 2)); seedPanel.add(seedField); startButton = new JButton("Démarrer"); startButton.setFont(new Font("Arial", Font.BOLD, 24)); startButton.setBackground(new Color(0, 255, 0)); startButton.setForeground(Color.WHITE); startButton.setBorder(BorderFactory.createLineBorder(Color.WHITE, 2)); startButton.setPreferredSize(new Dimension(150, 50)); startButton.addActionListener(buttonListener); seedPanel.add(startButton); return seedPanel; } public String getSeed() { return seedField.getText(); } }