Ajouts de beaucoup de modifications - ATTENTION, IL FAUT CORRIGER LE BUG DES SONS

This commit is contained in:
2024-11-12 20:16:45 +01:00
parent 2a1bef990b
commit 951a25e295
11 changed files with 273 additions and 111 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 231 KiB

View File

@@ -1,6 +1,7 @@
package fr.monkhanny.dorfromantik; package fr.monkhanny.dorfromantik;
import java.awt.Color; import java.awt.Color;
import java.awt.Dimension;
public class Options { public class Options {
@@ -48,4 +49,6 @@ public class Options {
* Volume des bruitages * Volume des bruitages
*/ */
public static int SOUNDS_VOLUME = 60; public static int SOUNDS_VOLUME = 60;
public static final Dimension MINIMUM_FRAME_SIZE = new Dimension(700, 700);
} }

View File

@@ -4,10 +4,13 @@ import fr.monkhanny.dorfromantik.Options;
import fr.monkhanny.dorfromantik.gui.SettingsPanel; import fr.monkhanny.dorfromantik.gui.SettingsPanel;
import fr.monkhanny.dorfromantik.gui.MainMenu; import fr.monkhanny.dorfromantik.gui.MainMenu;
import fr.monkhanny.dorfromantik.gui.ButtonPanel; import fr.monkhanny.dorfromantik.gui.ButtonPanel;
import fr.monkhanny.dorfromantik.listeners.SettingsWindowListener;
import javax.swing.*; import javax.swing.*;
import java.awt.event.ActionEvent; import java.awt.event.ActionEvent;
import java.awt.event.ActionListener; import java.awt.event.ActionListener;
import java.awt.Dimension;
import java.awt.Point;
public class MainMenuButtonController implements ActionListener { public class MainMenuButtonController implements ActionListener {
@@ -79,10 +82,28 @@ public class MainMenuButtonController implements ActionListener {
} }
private void openSettings() { 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.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); this.settingsFrame.add(settingsPanel);
// Afficher la fenêtre des paramètres
this.settingsFrame.setVisible(true); this.settingsFrame.setVisible(true);
return;
} }
} }

View File

@@ -42,7 +42,7 @@ public class ButtonPanel extends JPanel {
this.add(howToPlayButton); this.add(howToPlayButton);
this.add(Box.createVerticalStrut(10)); this.add(Box.createVerticalStrut(10));
this.add(settingsButton); this.add(settingsButton);
this.add(Box.createVerticalStrut(25)); this.add(Box.createVerticalStrut(10));
this.add(exitButton); this.add(exitButton);
// Espacement extensible pour maintenir les icônes en bas // Espacement extensible pour maintenir les icônes en bas

View File

@@ -25,6 +25,7 @@ public class MainMenu extends JFrame {
this.setTitle("Dorfromantik - Menu Principal"); this.setTitle("Dorfromantik - Menu Principal");
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
super.setIconImage(ImageLoader.APPLICATION_ICON); super.setIconImage(ImageLoader.APPLICATION_ICON);
this.setMinimumSize(Options.MINIMUM_FRAME_SIZE);
this.setSize(1200, 800); this.setSize(1200, 800);
this.setLocationRelativeTo(null); // Centrer la fenêtre this.setLocationRelativeTo(null); // Centrer la fenêtre
this.setLayout(new BorderLayout()); this.setLayout(new BorderLayout());

View File

@@ -1,133 +1,142 @@
package fr.monkhanny.dorfromantik.gui; package fr.monkhanny.dorfromantik.gui;
import fr.monkhanny.dorfromantik.Options; 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.components.Title;
import fr.monkhanny.dorfromantik.listeners.*;
import fr.monkhanny.dorfromantik.utils.MusicPlayer;
import javax.swing.*; import javax.swing.*;
import java.awt.*; 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.event.ChangeListener;
import javax.swing.plaf.basic.BasicSliderUI;
public class SettingsPanel extends JPanel { public class SettingsPanel extends JPanel {
private JCheckBox muteMusicCheckBox;
private JCheckBox muteSoundsCheckBox;
private JSlider musicVolumeSlider;
private JSlider soundsVolumeSlider;
public SettingsPanel() { private MainMenu mainMenu;
// Layout général du panneau private JFrame settingsFrame;
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));
// Titre centré avec une police moderne public SettingsPanel(MainMenu mainMenu, JFrame settingsFrame) {
Title title = new Title("Paramètres", 45, new Color(255, 179, 128)); // Rose pastel this.mainMenu = mainMenu;
title.setAlignmentX(Component.CENTER_ALIGNMENT); // Centré this.settingsFrame = settingsFrame;
JPanel titlePanel = new JPanel();
titlePanel.setOpaque(false); // Pour garder le fond transparent
titlePanel.setLayout(new FlowLayout(FlowLayout.CENTER)); // Centrer horizontalement
titlePanel.add(title);
this.add(titlePanel); initializeSettingsFrame();
this.add(Box.createVerticalStrut(30)); // Espacement entre le titre et les options setupBackground();
setupMainPanel();
}
// Section 1: Couper la musique + Slider musique private void initializeSettingsFrame() {
JPanel musicPanel = new JPanel(); settingsFrame.setMinimumSize(Options.MINIMUM_FRAME_SIZE);
musicPanel.setLayout(new BoxLayout(musicPanel, BoxLayout.Y_AXIS)); }
musicPanel.setBackground(new Color(255, 179, 128)); // Fond vert pastel
muteMusicCheckBox = new JCheckBox("Couper la Musique"); private void setupBackground() {
muteMusicCheckBox.setSelected(Options.MUSIC_MUTED); JLabel background = new JLabel(new ImageIcon("./ressources/images/MainMenu/backgroundBlured.jpg"));
muteMusicCheckBox.setForeground(new Color(0, 0, 0)); // Rose pastel background.setLayout(new GridBagLayout());
muteMusicCheckBox.setBackground(new Color(255, 182, 193)); // Fond vert pastel this.setLayout(new BorderLayout());
muteMusicCheckBox.setFont(new Font("Roboto", Font.PLAIN, 18)); // Police moderne this.add(background);
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();
}
}
});
musicVolumeSlider = new JSlider(0, 100, Options.MUSIC_VOLUME); private void setupMainPanel() {
musicVolumeSlider.setForeground(new Color(0, 0, 0)); // Rose pastel JPanel mainPanel = createMainPanel();
musicVolumeSlider.setBackground(new Color(255, 224, 204)); // Fond vert pastel JLabel title = createTitle();
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);
}
});
musicPanel.add(muteMusicCheckBox); mainPanel.add(title, createGridBagConstraints(0, 0, 2));
musicPanel.add(Box.createVerticalStrut(10)); // Espacement mainPanel.add(Box.createVerticalStrut(30), createGridBagConstraints(0, 1, 1));
musicPanel.add(musicVolumeSlider);
this.add(musicPanel); // Ajouter le panneau musique // Musique Panel
this.add(Box.createVerticalStrut(30)); // Espacement entre la musique et les bruitages 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 mainPanel.add(Box.createVerticalStrut(30), createGridBagConstraints(0, 3, 1));
JPanel soundsPanel = new JPanel();
soundsPanel.setLayout(new BoxLayout(soundsPanel, BoxLayout.Y_AXIS));
soundsPanel.setBackground(new Color(255, 179, 128)); // Fond orange pastel
muteSoundsCheckBox = new JCheckBox("Couper les Bruitages"); // SFX Panel
muteSoundsCheckBox.setSelected(Options.SOUNDS_MUTED); JSlider sfxSlider = new JSlider(0, 100, Options.SOUNDS_MUTED ? 0 : Options.SOUNDS_VOLUME);
muteSoundsCheckBox.setForeground(new Color(0, 0, 0)); // Rose pastel JPanel sfxPanel = createSoundPanel("SFX", Options.SOUNDS_MUTED, Options.SOUNDS_VOLUME, sfxSlider, new SoundsVolumeChangeListener(sfxSlider), new MuteCheckBoxListener("SFX"));
muteSoundsCheckBox.setBackground(new Color(255, 224, 204)); // Fond orange pastel mainPanel.add(sfxPanel, createGridBagConstraints(0, 4, 1));
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();
}
});
soundsVolumeSlider = new JSlider(0, 100, Options.SOUNDS_VOLUME); // Close Button
soundsVolumeSlider.setForeground(new Color(0, 0, 0)); // Rose pastel JButton closeButton = createCloseButton();
soundsVolumeSlider.setBackground(new Color(255, 224, 204)); // Fond orange pastel mainPanel.add(closeButton, createGridBagConstraints(0, 5, 1));
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);
}
});
soundsPanel.add(muteSoundsCheckBox); // Add to background
soundsPanel.add(Box.createVerticalStrut(10)); // Espacement ((JLabel) this.getComponent(0)).add(mainPanel);
soundsPanel.add(soundsVolumeSlider); }
this.add(soundsPanel); // Ajouter le panneau bruitages private JPanel createMainPanel() {
this.add(Box.createVerticalStrut(30)); // Espacement entre les sections 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;
} }
} }

View File

@@ -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
}
}

View File

@@ -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
}
}

View File

@@ -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();
}
}
}

View File

@@ -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
}
}

View File

@@ -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);
}
}