diff --git a/TestV2/ressources/images/MainMenu/backgroundBlured.jpg b/TestV2/ressources/images/MainMenu/backgroundBlured.jpg new file mode 100644 index 0000000..fa9808e Binary files /dev/null and b/TestV2/ressources/images/MainMenu/backgroundBlured.jpg differ diff --git a/TestV2/src/fr/monkhanny/dorfromantik/Options.java b/TestV2/src/fr/monkhanny/dorfromantik/Options.java index 1be87b7..e07f263 100644 --- a/TestV2/src/fr/monkhanny/dorfromantik/Options.java +++ b/TestV2/src/fr/monkhanny/dorfromantik/Options.java @@ -1,6 +1,7 @@ package fr.monkhanny.dorfromantik; import java.awt.Color; +import java.awt.Dimension; public class Options { @@ -48,4 +49,6 @@ public class Options { * Volume des bruitages */ public static int SOUNDS_VOLUME = 60; + + public static final Dimension MINIMUM_FRAME_SIZE = new Dimension(700, 700); } diff --git a/TestV2/src/fr/monkhanny/dorfromantik/controller/MainMenuButtonController.java b/TestV2/src/fr/monkhanny/dorfromantik/controller/MainMenuButtonController.java index edff115..d9fbdb3 100644 --- a/TestV2/src/fr/monkhanny/dorfromantik/controller/MainMenuButtonController.java +++ b/TestV2/src/fr/monkhanny/dorfromantik/controller/MainMenuButtonController.java @@ -4,10 +4,13 @@ import fr.monkhanny.dorfromantik.Options; import fr.monkhanny.dorfromantik.gui.SettingsPanel; import fr.monkhanny.dorfromantik.gui.MainMenu; import fr.monkhanny.dorfromantik.gui.ButtonPanel; +import fr.monkhanny.dorfromantik.listeners.SettingsWindowListener; import javax.swing.*; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; +import java.awt.Dimension; +import java.awt.Point; public class MainMenuButtonController implements ActionListener { @@ -79,10 +82,28 @@ public class MainMenuButtonController implements ActionListener { } private void openSettings() { + // Récupérer la taille et la position de la fenêtre du menu principal + Dimension mainMenuSize = this.mainMenu.getSize(); + Point mainMenuLocation = this.mainMenu.getLocation(); + + // Ajuster la fenêtre des paramètres pour qu'elle ait la même taille et position + this.settingsFrame.setSize(mainMenuSize); + this.settingsFrame.setLocation(mainMenuLocation); this.settingsFrame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); - this.settingsFrame.setSize(500, 500); - SettingsPanel settingsPanel = new SettingsPanel(); + + // Ajouter l'écouteur pour gérer la fermeture de la fenêtre des paramètres + SettingsWindowListener windowListener = new SettingsWindowListener(mainMenu, settingsFrame); + this.settingsFrame.addWindowListener(windowListener); + + // Cacher la fenêtre du menu principal + this.mainMenu.setVisible(false); + + // Créer et ajouter le panneau des paramètres + SettingsPanel settingsPanel = new SettingsPanel(mainMenu, settingsFrame); this.settingsFrame.add(settingsPanel); + + // Afficher la fenêtre des paramètres this.settingsFrame.setVisible(true); + return; } } diff --git a/TestV2/src/fr/monkhanny/dorfromantik/gui/ButtonPanel.java b/TestV2/src/fr/monkhanny/dorfromantik/gui/ButtonPanel.java index f6c096f..70f1dcc 100644 --- a/TestV2/src/fr/monkhanny/dorfromantik/gui/ButtonPanel.java +++ b/TestV2/src/fr/monkhanny/dorfromantik/gui/ButtonPanel.java @@ -42,7 +42,7 @@ public class ButtonPanel extends JPanel { this.add(howToPlayButton); this.add(Box.createVerticalStrut(10)); this.add(settingsButton); - this.add(Box.createVerticalStrut(25)); + this.add(Box.createVerticalStrut(10)); this.add(exitButton); // Espacement extensible pour maintenir les icônes en bas diff --git a/TestV2/src/fr/monkhanny/dorfromantik/gui/MainMenu.java b/TestV2/src/fr/monkhanny/dorfromantik/gui/MainMenu.java index 9952219..ec2624b 100644 --- a/TestV2/src/fr/monkhanny/dorfromantik/gui/MainMenu.java +++ b/TestV2/src/fr/monkhanny/dorfromantik/gui/MainMenu.java @@ -25,6 +25,7 @@ public class MainMenu extends JFrame { this.setTitle("Dorfromantik - Menu Principal"); this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); super.setIconImage(ImageLoader.APPLICATION_ICON); + this.setMinimumSize(Options.MINIMUM_FRAME_SIZE); this.setSize(1200, 800); this.setLocationRelativeTo(null); // Centrer la fenêtre this.setLayout(new BorderLayout()); diff --git a/TestV2/src/fr/monkhanny/dorfromantik/gui/SettingsPanel.java b/TestV2/src/fr/monkhanny/dorfromantik/gui/SettingsPanel.java index 36940dc..ce10788 100644 --- a/TestV2/src/fr/monkhanny/dorfromantik/gui/SettingsPanel.java +++ b/TestV2/src/fr/monkhanny/dorfromantik/gui/SettingsPanel.java @@ -1,133 +1,142 @@ package fr.monkhanny.dorfromantik.gui; import fr.monkhanny.dorfromantik.Options; -import fr.monkhanny.dorfromantik.enums.Fonts; -import fr.monkhanny.dorfromantik.utils.FontManager; -import fr.monkhanny.dorfromantik.utils.MusicPlayer; import fr.monkhanny.dorfromantik.components.Title; +import fr.monkhanny.dorfromantik.listeners.*; +import fr.monkhanny.dorfromantik.utils.MusicPlayer; import javax.swing.*; import java.awt.*; -import java.awt.event.ActionEvent; -import java.awt.event.ActionListener; -import javax.swing.event.ChangeEvent; import javax.swing.event.ChangeListener; -import javax.swing.plaf.basic.BasicSliderUI; public class SettingsPanel extends JPanel { - private JCheckBox muteMusicCheckBox; - private JCheckBox muteSoundsCheckBox; - private JSlider musicVolumeSlider; - private JSlider soundsVolumeSlider; - public SettingsPanel() { - // Layout général du panneau - this.setLayout(new BoxLayout(this, BoxLayout.Y_AXIS)); - this.setBackground(new Color(255, 239, 214)); // Fond pastel (beige clair) - this.setBorder(BorderFactory.createEmptyBorder(20, 40, 20, 40)); + private MainMenu mainMenu; + private JFrame settingsFrame; - // Titre centré avec une police moderne - Title title = new Title("Paramètres", 45, new Color(255, 179, 128)); // Rose pastel - title.setAlignmentX(Component.CENTER_ALIGNMENT); // Centré - JPanel titlePanel = new JPanel(); - titlePanel.setOpaque(false); // Pour garder le fond transparent - titlePanel.setLayout(new FlowLayout(FlowLayout.CENTER)); // Centrer horizontalement - titlePanel.add(title); + public SettingsPanel(MainMenu mainMenu, JFrame settingsFrame) { + this.mainMenu = mainMenu; + this.settingsFrame = settingsFrame; - this.add(titlePanel); - this.add(Box.createVerticalStrut(30)); // Espacement entre le titre et les options + initializeSettingsFrame(); + setupBackground(); + setupMainPanel(); + } - // Section 1: Couper la musique + Slider musique - JPanel musicPanel = new JPanel(); - musicPanel.setLayout(new BoxLayout(musicPanel, BoxLayout.Y_AXIS)); - musicPanel.setBackground(new Color(255, 179, 128)); // Fond vert pastel + private void initializeSettingsFrame() { + settingsFrame.setMinimumSize(Options.MINIMUM_FRAME_SIZE); + } - muteMusicCheckBox = new JCheckBox("Couper la Musique"); - muteMusicCheckBox.setSelected(Options.MUSIC_MUTED); - muteMusicCheckBox.setForeground(new Color(0, 0, 0)); // Rose pastel - muteMusicCheckBox.setBackground(new Color(255, 182, 193)); // Fond vert pastel - muteMusicCheckBox.setFont(new Font("Roboto", Font.PLAIN, 18)); // Police moderne - muteMusicCheckBox.setFocusPainted(false); - muteMusicCheckBox.setBorderPainted(false); - muteMusicCheckBox.setContentAreaFilled(false); - muteMusicCheckBox.addActionListener(new ActionListener() { - @Override - public void actionPerformed(ActionEvent e) { - Options.MUSIC_MUTED = muteMusicCheckBox.isSelected(); - if (Options.MUSIC_MUTED) { - MusicPlayer.pauseMusic(); - } else { - MusicPlayer.playMusic(); - } - } - }); + private void setupBackground() { + JLabel background = new JLabel(new ImageIcon("./ressources/images/MainMenu/backgroundBlured.jpg")); + background.setLayout(new GridBagLayout()); + this.setLayout(new BorderLayout()); + this.add(background); + } - musicVolumeSlider = new JSlider(0, 100, Options.MUSIC_VOLUME); - musicVolumeSlider.setForeground(new Color(0, 0, 0)); // Rose pastel - musicVolumeSlider.setBackground(new Color(255, 224, 204)); // Fond vert pastel - musicVolumeSlider.setMajorTickSpacing(25); - musicVolumeSlider.setMinorTickSpacing(5); - musicVolumeSlider.setPaintTicks(true); - musicVolumeSlider.setPaintLabels(true); - musicVolumeSlider.setFont(new Font("Roboto", Font.PLAIN, 14)); // Police moderne - musicVolumeSlider.setUI(new BasicSliderUI(musicVolumeSlider)); - musicVolumeSlider.addChangeListener(new ChangeListener() { - @Override - public void stateChanged(ChangeEvent e) { - Options.MUSIC_VOLUME = musicVolumeSlider.getValue(); - MusicPlayer.setVolume(MusicPlayer.getMusicClip(), Options.MUSIC_VOLUME); - } - }); + private void setupMainPanel() { + JPanel mainPanel = createMainPanel(); + JLabel title = createTitle(); - musicPanel.add(muteMusicCheckBox); - musicPanel.add(Box.createVerticalStrut(10)); // Espacement - musicPanel.add(musicVolumeSlider); + mainPanel.add(title, createGridBagConstraints(0, 0, 2)); + mainPanel.add(Box.createVerticalStrut(30), createGridBagConstraints(0, 1, 1)); - this.add(musicPanel); // Ajouter le panneau musique - this.add(Box.createVerticalStrut(30)); // Espacement entre la musique et les bruitages + // Musique Panel + JSlider musicSlider = new JSlider(0, 100, Options.MUSIC_MUTED ? 0 : Options.MUSIC_VOLUME); + JPanel musicPanel = createSoundPanel("Musique", Options.MUSIC_MUTED, Options.MUSIC_VOLUME, musicSlider, new MusicVolumeChangeListener(musicSlider), new MuteCheckBoxListener("Musique")); + mainPanel.add(musicPanel, createGridBagConstraints(0, 2, 1)); - // Section 2: Couper les bruitages + Slider bruitages - JPanel soundsPanel = new JPanel(); - soundsPanel.setLayout(new BoxLayout(soundsPanel, BoxLayout.Y_AXIS)); - soundsPanel.setBackground(new Color(255, 179, 128)); // Fond orange pastel + mainPanel.add(Box.createVerticalStrut(30), createGridBagConstraints(0, 3, 1)); - muteSoundsCheckBox = new JCheckBox("Couper les Bruitages"); - muteSoundsCheckBox.setSelected(Options.SOUNDS_MUTED); - muteSoundsCheckBox.setForeground(new Color(0, 0, 0)); // Rose pastel - muteSoundsCheckBox.setBackground(new Color(255, 224, 204)); // Fond orange pastel - muteSoundsCheckBox.setFont(new Font("Roboto", Font.PLAIN, 18)); // Police moderne - muteSoundsCheckBox.setFocusPainted(false); - muteSoundsCheckBox.setBorderPainted(false); - muteSoundsCheckBox.setContentAreaFilled(false); - muteSoundsCheckBox.addActionListener(new ActionListener() { - @Override - public void actionPerformed(ActionEvent e) { - Options.SOUNDS_MUTED = muteSoundsCheckBox.isSelected(); - } - }); + // SFX Panel + JSlider sfxSlider = new JSlider(0, 100, Options.SOUNDS_MUTED ? 0 : Options.SOUNDS_VOLUME); + JPanel sfxPanel = createSoundPanel("SFX", Options.SOUNDS_MUTED, Options.SOUNDS_VOLUME, sfxSlider, new SoundsVolumeChangeListener(sfxSlider), new MuteCheckBoxListener("SFX")); + mainPanel.add(sfxPanel, createGridBagConstraints(0, 4, 1)); - soundsVolumeSlider = new JSlider(0, 100, Options.SOUNDS_VOLUME); - soundsVolumeSlider.setForeground(new Color(0, 0, 0)); // Rose pastel - soundsVolumeSlider.setBackground(new Color(255, 224, 204)); // Fond orange pastel - soundsVolumeSlider.setMajorTickSpacing(25); - soundsVolumeSlider.setMinorTickSpacing(5); - soundsVolumeSlider.setPaintTicks(true); - soundsVolumeSlider.setPaintLabels(true); - soundsVolumeSlider.setFont(new Font("Roboto", Font.PLAIN, 14)); // Police moderne - soundsVolumeSlider.setUI(new BasicSliderUI(soundsVolumeSlider)); - soundsVolumeSlider.addChangeListener(new ChangeListener() { - @Override - public void stateChanged(ChangeEvent e) { - Options.SOUNDS_VOLUME = soundsVolumeSlider.getValue(); - MusicPlayer.setVolume(MusicPlayer.getSoundClip(), Options.SOUNDS_VOLUME); - } - }); + // Close Button + JButton closeButton = createCloseButton(); + mainPanel.add(closeButton, createGridBagConstraints(0, 5, 1)); - soundsPanel.add(muteSoundsCheckBox); - soundsPanel.add(Box.createVerticalStrut(10)); // Espacement - soundsPanel.add(soundsVolumeSlider); + // Add to background + ((JLabel) this.getComponent(0)).add(mainPanel); + } - this.add(soundsPanel); // Ajouter le panneau bruitages - this.add(Box.createVerticalStrut(30)); // Espacement entre les sections + private JPanel createMainPanel() { + JPanel mainPanel = new JPanel(new GridBagLayout()); + mainPanel.setOpaque(false); + return mainPanel; + } + + private Title createTitle() { + Title title = new Title("Paramètres", 70, Color.WHITE); + return title; + } + + 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 JPanel createSoundPanel(String labelText, boolean isMuted, int initialVolume, JSlider volumeSlider, ChangeListener sliderChangeListener, MuteCheckBoxListener muteCheckBoxListener) { + JPanel panel = new JPanel(new GridBagLayout()); + panel.setOpaque(false); + + GridBagConstraints gbc = new GridBagConstraints(); + gbc.insets = new Insets(10, 10, 10, 10); + gbc.gridx = 0; + + JCheckBox muteCheckBox = new JCheckBox(); + muteCheckBox.setSelected(!isMuted); + muteCheckBox.addActionListener(muteCheckBoxListener); + + panel.add(new JLabel(labelText), gbc); + gbc.gridx++; + panel.add(muteCheckBox, gbc); + + volumeSlider.setPreferredSize(new Dimension(200, 50)); + volumeSlider.setMajorTickSpacing(50); + volumeSlider.setPaintTicks(true); + volumeSlider.setPaintLabels(true); + volumeSlider.setFont(new Font("Roboto", Font.PLAIN, 16)); + volumeSlider.addChangeListener(sliderChangeListener); + + gbc.gridx++; + panel.add(createSliderPanel(volumeSlider), gbc); + + return panel; + } + + private JPanel createSliderPanel(JSlider volumeSlider) { + JPanel sliderPanel = new JPanel(new BorderLayout()); + sliderPanel.setOpaque(false); + + JLabel lowLabel = new JLabel("Low"); + lowLabel.setFont(new Font("Roboto", Font.PLAIN, 18)); + sliderPanel.add(lowLabel, BorderLayout.WEST); + + sliderPanel.add(volumeSlider, BorderLayout.CENTER); + + JLabel highLabel = new JLabel("High"); + highLabel.setFont(new Font("Roboto", Font.PLAIN, 18)); + sliderPanel.add(highLabel, BorderLayout.EAST); + + return sliderPanel; + } + + private JButton createCloseButton() { + JButton closeButton = new JButton("Retour"); + closeButton.setFont(new Font("Roboto", Font.BOLD, 24)); + closeButton.setForeground(Color.BLACK); + closeButton.setBackground(Color.WHITE); + closeButton.setOpaque(true); + closeButton.setPreferredSize(new Dimension(75, 50)); + closeButton.setBorder(BorderFactory.createLineBorder(Color.BLACK, 2)); + closeButton.addActionListener(new CloseButtonListener(mainMenu, settingsFrame)); + return closeButton; } } diff --git a/TestV2/src/fr/monkhanny/dorfromantik/listeners/CloseButtonListener.java b/TestV2/src/fr/monkhanny/dorfromantik/listeners/CloseButtonListener.java new file mode 100644 index 0000000..70d2012 --- /dev/null +++ b/TestV2/src/fr/monkhanny/dorfromantik/listeners/CloseButtonListener.java @@ -0,0 +1,24 @@ +package fr.monkhanny.dorfromantik.listeners; + +import fr.monkhanny.dorfromantik.gui.MainMenu; + +import javax.swing.*; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; + +public class CloseButtonListener implements ActionListener { + private MainMenu mainMenu; + private JFrame settingsFrame; + + public CloseButtonListener(MainMenu mainMenu, JFrame settingsFrame) { + this.mainMenu = mainMenu; + this.settingsFrame = settingsFrame; + } + + @Override + public void actionPerformed(ActionEvent e) { + // Réafficher la fenêtre du menu principal + mainMenu.setVisible(true); + settingsFrame.setVisible(false); // Fermer la fenêtre des paramètres + } +} \ No newline at end of file diff --git a/TestV2/src/fr/monkhanny/dorfromantik/listeners/MusicVolumeChangeListener.java b/TestV2/src/fr/monkhanny/dorfromantik/listeners/MusicVolumeChangeListener.java new file mode 100644 index 0000000..0d01523 --- /dev/null +++ b/TestV2/src/fr/monkhanny/dorfromantik/listeners/MusicVolumeChangeListener.java @@ -0,0 +1,24 @@ +package fr.monkhanny.dorfromantik.listeners; + +import fr.monkhanny.dorfromantik.Options; +import fr.monkhanny.dorfromantik.utils.MusicPlayer; + +import javax.swing.event.ChangeEvent; +import javax.swing.event.ChangeListener; +import javax.swing.JSlider; + +public class MusicVolumeChangeListener implements ChangeListener { + private JSlider slider; + + public MusicVolumeChangeListener(JSlider slider) { + this.slider = slider; + } + + @Override + public void stateChanged(ChangeEvent e) { + // Récupérer la valeur du slider spécifique + int volume = slider.getValue(); + Options.MUSIC_VOLUME = volume; // Mettre à jour le volume dans Options + MusicPlayer.setVolume(MusicPlayer.getMusicClip(), volume); // Appliquer la nouvelle valeur du volume à la musique + } +} diff --git a/TestV2/src/fr/monkhanny/dorfromantik/listeners/MuteCheckBoxListener.java b/TestV2/src/fr/monkhanny/dorfromantik/listeners/MuteCheckBoxListener.java new file mode 100644 index 0000000..13bc5ca --- /dev/null +++ b/TestV2/src/fr/monkhanny/dorfromantik/listeners/MuteCheckBoxListener.java @@ -0,0 +1,32 @@ +package fr.monkhanny.dorfromantik.listeners; + +import fr.monkhanny.dorfromantik.Options; +import fr.monkhanny.dorfromantik.utils.MusicPlayer; + +import javax.swing.*; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; + +public class MuteCheckBoxListener implements ActionListener { + private String label; + + public MuteCheckBoxListener(String label) { + this.label = label; + } + + @Override + public void actionPerformed(ActionEvent e) { + JCheckBox checkBox = (JCheckBox) e.getSource(); + + if ("Musique".equals(label)) { + Options.MUSIC_MUTED = !checkBox.isSelected(); + if (Options.MUSIC_MUTED) { + MusicPlayer.pauseMusic(); + } else { + MusicPlayer.playMusic(); + } + } else if ("SFX".equals(label)) { + Options.SOUNDS_MUTED = !checkBox.isSelected(); + } + } +} diff --git a/TestV2/src/fr/monkhanny/dorfromantik/listeners/SettingsWindowListener.java b/TestV2/src/fr/monkhanny/dorfromantik/listeners/SettingsWindowListener.java new file mode 100644 index 0000000..93f1c46 --- /dev/null +++ b/TestV2/src/fr/monkhanny/dorfromantik/listeners/SettingsWindowListener.java @@ -0,0 +1,25 @@ +package fr.monkhanny.dorfromantik.listeners; + +import fr.monkhanny.dorfromantik.gui.MainMenu; + +import java.awt.event.WindowAdapter; +import java.awt.event.WindowEvent; +import javax.swing.*; + +public class SettingsWindowListener extends WindowAdapter { + + private MainMenu mainMenu; + private JFrame settingsFrame; + + public SettingsWindowListener(MainMenu mainMenu, JFrame settingsFrame) { + this.mainMenu = mainMenu; + this.settingsFrame = settingsFrame; + } + + @Override + public void windowClosing(WindowEvent e) { + // Réafficher la fenêtre du menu principal + mainMenu.setVisible(true); + settingsFrame.setVisible(false); // Fermer la fenêtre des paramètres + } +} diff --git a/TestV2/src/fr/monkhanny/dorfromantik/listeners/SoundsVolumeChangeListener.java b/TestV2/src/fr/monkhanny/dorfromantik/listeners/SoundsVolumeChangeListener.java new file mode 100644 index 0000000..952d3b6 --- /dev/null +++ b/TestV2/src/fr/monkhanny/dorfromantik/listeners/SoundsVolumeChangeListener.java @@ -0,0 +1,23 @@ +package fr.monkhanny.dorfromantik.listeners; + +import fr.monkhanny.dorfromantik.Options; +import fr.monkhanny.dorfromantik.utils.MusicPlayer; + +import javax.swing.event.ChangeEvent; +import javax.swing.event.ChangeListener; +import javax.swing.JSlider; + +public class SoundsVolumeChangeListener implements ChangeListener { + private JSlider slider; + + public SoundsVolumeChangeListener(JSlider slider) { + this.slider = slider; + } + + @Override + public void stateChanged(ChangeEvent e) { + // Récupérer la valeur du slider spécifique + Options.SOUNDS_VOLUME = slider.getValue(); + MusicPlayer.setVolume(MusicPlayer.getSoundClip(), Options.SOUNDS_VOLUME); + } +}