Jour de congé ! : Ajout d'une flèche de retour au menu de choix des modes de jeu

This commit is contained in:
2024-11-27 14:58:36 +01:00
parent ac87b891ed
commit dec141f290
2 changed files with 55 additions and 18 deletions

View File

@@ -87,7 +87,7 @@ public class Main {
// Fenêtre du choix des modes de jeu // Fenêtre du choix des modes de jeu
CloseWindowListener gameModeWindowListener = new CloseWindowListener(Options.mainMenu, gameModeFrame); CloseWindowListener gameModeWindowListener = new CloseWindowListener(Options.mainMenu, gameModeFrame);
GameModeController gameModeController = new GameModeController(gameFrame, Options.mainMenu, gameModeFrame); GameModeController gameModeController = new GameModeController(gameFrame, Options.mainMenu, gameModeFrame);
GameModeSelectionPanel gameModeSelectionPanel = new GameModeSelectionPanel(gameModeController); GameModeSelectionPanel gameModeSelectionPanel = new GameModeSelectionPanel(gameModeController,gameModeFrame, Options.mainMenu);
gameModeFrame.addWindowListener(gameModeWindowListener); gameModeFrame.addWindowListener(gameModeWindowListener);
gameModeController.setGameModeSelectionPanel(gameModeSelectionPanel); gameModeController.setGameModeSelectionPanel(gameModeSelectionPanel);
gameModeFrame.add(gameModeSelectionPanel); gameModeFrame.add(gameModeSelectionPanel);

View File

@@ -14,56 +14,92 @@ public class GameModeSelectionPanel extends JPanel {
private JTextField seedField; private JTextField seedField;
private JButton startButton; private JButton startButton;
public GameModeSelectionPanel(ActionListener buttonListener) {
public GameModeSelectionPanel(ActionListener buttonListener, JFrame gameModeFrame, MainMenu mainMenu) {
setLayout(new BorderLayout()); setLayout(new BorderLayout());
// Add background image // Ajouter l'image de fond
JLabel background = new JLabel(new ImageIcon("./ressources/images/MainMenu/backgroundBlured.jpg")); JLabel background = new JLabel(new ImageIcon("./ressources/images/MainMenu/backgroundBlured.jpg"));
background.setLayout(new GridBagLayout()); background.setLayout(new BorderLayout()); // Utilisation de BorderLayout ici
this.setLayout(new BorderLayout());
this.add(background); this.add(background);
// Main content panel // Créer un topPanel avec le bouton de retour
JPanel topPanel = createTopPanel(gameModeFrame, mainMenu);
background.add(topPanel, BorderLayout.NORTH); // Placer topPanel en haut à gauche
// Panel principal (au centre)
JPanel mainPanel = createMainPanel(); JPanel mainPanel = createMainPanel();
background.add(mainPanel); background.add(mainPanel, BorderLayout.CENTER); // Placer le contenu principal sous le bouton
// Title // Title
titleLabel = new JLabel("Choisissez un mode de jeu", JLabel.CENTER); titleLabel = new JLabel("Choisissez un mode de jeu", JLabel.CENTER);
titleLabel.setFont(new Font("Arial", Font.BOLD, 40)); titleLabel.setFont(new Font("Arial", Font.BOLD, 40));
titleLabel.setForeground(Color.WHITE); titleLabel.setForeground(Color.WHITE);
mainPanel.add(titleLabel, createGridBagConstraints(0, 0, 2)); mainPanel.add(titleLabel, createGridBagConstraints(0, 0, 2));
mainPanel.add(Box.createVerticalStrut(30), createGridBagConstraints(0, 1, 1)); mainPanel.add(Box.createVerticalStrut(30), createGridBagConstraints(0, 1, 1));
// Mode buttons - now horizontally aligned // Mode buttons - now horizontally aligned
JPanel modePanel = new JPanel(new FlowLayout(FlowLayout.CENTER, 20, 10)); // Centered with horizontal spacing JPanel modePanel = new JPanel(new FlowLayout(FlowLayout.CENTER, 20, 10)); // Centered with horizontal spacing
modePanel.setOpaque(false); modePanel.setOpaque(false);
mode1Button = createGameModeButton("Mode 1", buttonListener); mode1Button = createGameModeButton("Mode 1", buttonListener);
mode2Button = createGameModeButton("Mode 2", buttonListener); mode2Button = createGameModeButton("Mode 2", buttonListener);
mode3Button = createGameModeButton("Mode 3", buttonListener); mode3Button = createGameModeButton("Mode 3", buttonListener);
mode4Button = createGameModeButton("Mode 4", buttonListener); mode4Button = createGameModeButton("Mode 4", buttonListener);
modePanel.add(mode1Button); modePanel.add(mode1Button);
modePanel.add(mode2Button); modePanel.add(mode2Button);
modePanel.add(mode3Button); modePanel.add(mode3Button);
modePanel.add(mode4Button); modePanel.add(mode4Button);
mainPanel.add(modePanel, createGridBagConstraints(0, 2, 2)); // Span across 2 columns mainPanel.add(modePanel, createGridBagConstraints(0, 2, 2)); // Span across 2 columns
mainPanel.add(Box.createVerticalStrut(30), createGridBagConstraints(0, 3, 1)); mainPanel.add(Box.createVerticalStrut(30), createGridBagConstraints(0, 3, 1));
// Seed input and start button // Seed input and start button
JPanel seedPanel = createSeedPanel(buttonListener); JPanel seedPanel = createSeedPanel(buttonListener);
mainPanel.add(seedPanel, createGridBagConstraints(0, 4, 2)); mainPanel.add(seedPanel, createGridBagConstraints(0, 4, 2));
} }
private JPanel createTopPanel(JFrame gameModeFrame, MainMenu mainMenu) {
// Utilisation de BorderLayout pour aligner correctement le bouton à gauche
JPanel topPanel = new JPanel(new BorderLayout());
topPanel.setOpaque(false);
// Création du bouton de retour
JButton returnButton = createReturnButtonWithIcon(gameModeFrame, mainMenu);
// Ajouter le bouton de retour à gauche (West)
topPanel.add(returnButton, BorderLayout.WEST);
return topPanel;
}
private JButton createReturnButtonWithIcon(JFrame gameModeFrame, MainMenu mainMenu) {
ImageIcon originalIcon = new ImageIcon("./ressources/images/Icone/ExitIcon.png");
Image scaledImage = originalIcon.getImage().getScaledInstance(50, 50, Image.SCALE_SMOOTH);
ImageIcon resizedIcon = new ImageIcon(scaledImage);
JButton returnButton = new JButton(resizedIcon);
returnButton.setPreferredSize(new Dimension(50, 50));
returnButton.setContentAreaFilled(false);
returnButton.setBorderPainted(false);
returnButton.setFocusPainted(false);
returnButton.addActionListener(e -> {
gameModeFrame.setVisible(false);
mainMenu.setVisible(true);
});
return returnButton;
}
private JPanel createMainPanel() { private JPanel createMainPanel() {
JPanel mainPanel = new JPanel(new GridBagLayout()); JPanel mainPanel = new JPanel(new GridBagLayout());
mainPanel.setOpaque(false); mainPanel.setOpaque(false);
return mainPanel; return mainPanel;
} }
private GridBagConstraints createGridBagConstraints(int x, int y, int gridWidth) { private GridBagConstraints createGridBagConstraints(int x, int y, int gridWidth) {
GridBagConstraints gbc = new GridBagConstraints(); GridBagConstraints gbc = new GridBagConstraints();
gbc.gridx = x; gbc.gridx = x;
@@ -73,6 +109,7 @@ public class GameModeSelectionPanel extends JPanel {
gbc.insets = new Insets(20, 30, 20, 30); gbc.insets = new Insets(20, 30, 20, 30);
return gbc; return gbc;
} }
private JButton createGameModeButton(String modeName, ActionListener buttonListener) { private JButton createGameModeButton(String modeName, ActionListener buttonListener) {
JButton button = new JButton(modeName); JButton button = new JButton(modeName);