Jour de congé ! : Ajout d'une flèche de retour au menu de choix des modes de jeu
This commit is contained in:
@@ -87,7 +87,7 @@ public class Main {
|
||||
// Fenêtre du choix des modes de jeu
|
||||
CloseWindowListener gameModeWindowListener = new CloseWindowListener(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);
|
||||
gameModeController.setGameModeSelectionPanel(gameModeSelectionPanel);
|
||||
gameModeFrame.add(gameModeSelectionPanel);
|
||||
|
@@ -14,56 +14,92 @@ public class GameModeSelectionPanel extends JPanel {
|
||||
private JTextField seedField;
|
||||
private JButton startButton;
|
||||
|
||||
public GameModeSelectionPanel(ActionListener buttonListener) {
|
||||
|
||||
public GameModeSelectionPanel(ActionListener buttonListener, JFrame gameModeFrame, MainMenu mainMenu) {
|
||||
setLayout(new BorderLayout());
|
||||
|
||||
// Add background image
|
||||
// Ajouter l'image de fond
|
||||
JLabel background = new JLabel(new ImageIcon("./ressources/images/MainMenu/backgroundBlured.jpg"));
|
||||
background.setLayout(new GridBagLayout());
|
||||
this.setLayout(new BorderLayout());
|
||||
background.setLayout(new BorderLayout()); // Utilisation de BorderLayout ici
|
||||
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();
|
||||
background.add(mainPanel);
|
||||
|
||||
background.add(mainPanel, BorderLayout.CENTER); // Placer le contenu principal sous le bouton
|
||||
|
||||
// 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 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() {
|
||||
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;
|
||||
@@ -73,6 +109,7 @@ public class GameModeSelectionPanel extends JPanel {
|
||||
gbc.insets = new Insets(20, 30, 20, 30);
|
||||
return gbc;
|
||||
}
|
||||
|
||||
|
||||
private JButton createGameModeButton(String modeName, ActionListener buttonListener) {
|
||||
JButton button = new JButton(modeName);
|
||||
|
Reference in New Issue
Block a user