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
|
// 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);
|
||||||
|
@@ -14,18 +14,22 @@ 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);
|
||||||
@@ -58,6 +62,38 @@ public class GameModeSelectionPanel extends JPanel {
|
|||||||
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);
|
||||||
@@ -74,6 +110,7 @@ public class GameModeSelectionPanel extends JPanel {
|
|||||||
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);
|
||||||
button.setFont(new Font("Arial", Font.BOLD, 24));
|
button.setFont(new Font("Arial", Font.BOLD, 24));
|
||||||
|
Reference in New Issue
Block a user