Settings
This commit is contained in:
BIN
TestV2/ressources/images/Settings/speaker-high-volume.png
Normal file
BIN
TestV2/ressources/images/Settings/speaker-high-volume.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 16 KiB |
BIN
TestV2/ressources/images/Settings/speaker-mute-volume.png
Normal file
BIN
TestV2/ressources/images/Settings/speaker-mute-volume.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 8.2 KiB |
@@ -22,12 +22,12 @@ public class Options {
|
||||
/**
|
||||
* Musique en sourdine ou non
|
||||
*/
|
||||
public static final boolean MUSIC_MUTED = false;
|
||||
public static boolean MUSIC_MUTED = false;
|
||||
|
||||
/**
|
||||
* Sons en sourdine ou non
|
||||
*/
|
||||
public static final boolean SOUNDS_MUTED = false;
|
||||
public static boolean SOUNDS_MUTED = false;
|
||||
|
||||
/**
|
||||
* Couleur de subrillance des boutons
|
||||
@@ -38,4 +38,14 @@ public class Options {
|
||||
public static final float HOVER_FONT_SCALE = 1.1f;
|
||||
public static final int ANIMATION_STEPS = 10;
|
||||
public static final int ANIMATION_DELAY = 15;
|
||||
|
||||
/**
|
||||
* Volume de la musique
|
||||
*/
|
||||
public static int MUSIC_VOLUME = 60;
|
||||
|
||||
/**
|
||||
* Volume des bruitages
|
||||
*/
|
||||
public static int SOUNDS_VOLUME = 60;
|
||||
}
|
||||
|
@@ -1,8 +1,11 @@
|
||||
package fr.monkhanny.dorfromantik.controller;
|
||||
|
||||
import fr.monkhanny.dorfromantik.Options;
|
||||
import fr.monkhanny.dorfromantik.gui.SettingsPanel;
|
||||
import fr.monkhanny.dorfromantik.gui.MainMenu;
|
||||
import fr.monkhanny.dorfromantik.gui.ButtonPanel;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
|
||||
@@ -10,6 +13,8 @@ public class MainMenuButtonController implements ActionListener {
|
||||
|
||||
private MainMenu mainMenu;
|
||||
|
||||
private JFrame settingsFrame;
|
||||
|
||||
public MainMenuButtonController(MainMenu mainMenu) {
|
||||
this.mainMenu = mainMenu;
|
||||
// Ajouter les écouteurs d'événements sur les boutons
|
||||
@@ -21,6 +26,11 @@ public class MainMenuButtonController implements ActionListener {
|
||||
buttonPanel.getHowToPlayButton().addActionListener(this);
|
||||
buttonPanel.getSettingsButton().addActionListener(this);
|
||||
buttonPanel.getExitButton().addActionListener(this);
|
||||
|
||||
// Créer la fenêtre des paramètres
|
||||
this.settingsFrame = new JFrame("Paramètres");
|
||||
this.settingsFrame.setLocationRelativeTo(null);
|
||||
this.settingsFrame.setVisible(false);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -64,12 +74,15 @@ public class MainMenuButtonController implements ActionListener {
|
||||
// Logic to show how to play
|
||||
}
|
||||
|
||||
private void openSettings() {
|
||||
System.out.println("Ouvrir les paramètres...");
|
||||
// Logic to open settings
|
||||
}
|
||||
|
||||
private void exitGame() {
|
||||
System.exit(0); // Fermer l'application
|
||||
}
|
||||
|
||||
private void openSettings() {
|
||||
this.settingsFrame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
|
||||
this.settingsFrame.setSize(500, 500);
|
||||
SettingsPanel settingsPanel = new SettingsPanel();
|
||||
this.settingsFrame.add(settingsPanel);
|
||||
this.settingsFrame.setVisible(true);
|
||||
}
|
||||
}
|
||||
|
133
TestV2/src/fr/monkhanny/dorfromantik/gui/SettingsPanel.java
Normal file
133
TestV2/src/fr/monkhanny/dorfromantik/gui/SettingsPanel.java
Normal file
@@ -0,0 +1,133 @@
|
||||
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 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));
|
||||
|
||||
// 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);
|
||||
|
||||
this.add(titlePanel);
|
||||
this.add(Box.createVerticalStrut(30)); // Espacement entre le titre et les options
|
||||
|
||||
// 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
|
||||
|
||||
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();
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
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);
|
||||
}
|
||||
});
|
||||
|
||||
musicPanel.add(muteMusicCheckBox);
|
||||
musicPanel.add(Box.createVerticalStrut(10)); // Espacement
|
||||
musicPanel.add(musicVolumeSlider);
|
||||
|
||||
this.add(musicPanel); // Ajouter le panneau musique
|
||||
this.add(Box.createVerticalStrut(30)); // Espacement entre la musique et les bruitages
|
||||
|
||||
// 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
|
||||
|
||||
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();
|
||||
}
|
||||
});
|
||||
|
||||
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);
|
||||
}
|
||||
});
|
||||
|
||||
soundsPanel.add(muteSoundsCheckBox);
|
||||
soundsPanel.add(Box.createVerticalStrut(10)); // Espacement
|
||||
soundsPanel.add(soundsVolumeSlider);
|
||||
|
||||
this.add(soundsPanel); // Ajouter le panneau bruitages
|
||||
this.add(Box.createVerticalStrut(30)); // Espacement entre les sections
|
||||
}
|
||||
}
|
@@ -18,7 +18,7 @@ public class MusicPlayer {
|
||||
if (music == Musics.MAIN_MENU_MUSIC) {
|
||||
musicClip = SoundLoader.loadMusic(Musics.MAIN_MENU_MUSIC.getSoundsPath());
|
||||
if (musicClip != null) {
|
||||
setVolume(musicClip, Options.DEFAULT_VOLUME);
|
||||
setVolume(musicClip, Options.MUSIC_VOLUME);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -27,20 +27,20 @@ public class MusicPlayer {
|
||||
if (sound == Sounds.SOUNDS1) {
|
||||
soundClip = SoundLoader.loadMusic(Sounds.SOUNDS1.getSoundsPath()); // Utilise soundClip pour les bruitages
|
||||
if (soundClip != null) {
|
||||
setVolume(soundClip, Options.DEFAULT_VOLUME);
|
||||
setVolume(soundClip, Options.SOUNDS_VOLUME);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void playMusic() {
|
||||
if (musicClip != null && !isPlayingMusic) {
|
||||
if (musicClip != null && !isPlayingMusic && !Options.MUSIC_MUTED) {
|
||||
musicClip.start();
|
||||
isPlayingMusic = true;
|
||||
}
|
||||
}
|
||||
|
||||
public static void playSound() {
|
||||
if (soundClip != null && !isPlayingSound) {
|
||||
if (soundClip != null && !isPlayingSound && !Options.SOUNDS_MUTED) {
|
||||
soundClip.start();
|
||||
isPlayingSound = true;
|
||||
soundClip.addLineListener(event -> { // Réinitialiser isPlayingSound à la fin du son
|
||||
@@ -83,4 +83,12 @@ public class MusicPlayer {
|
||||
public static boolean isPlayingSound() {
|
||||
return isPlayingSound;
|
||||
}
|
||||
|
||||
public static Clip getMusicClip() {
|
||||
return musicClip;
|
||||
}
|
||||
|
||||
public static Clip getSoundClip() {
|
||||
return soundClip;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user