resolution bug score dans le mode 1 mais bug dans le mode 2,3 et 4

This commit is contained in:
Lenny FOULOU
2024-11-30 13:33:16 +01:00
parent 7452d8ea7f
commit 0e6450f8c8
80 changed files with 48188 additions and 737 deletions

View File

@@ -3,7 +3,7 @@ package fr.monkhanny.dorfromantik.gui;
import fr.monkhanny.dorfromantik.Options;
import fr.monkhanny.dorfromantik.components.Title;
import fr.monkhanny.dorfromantik.listeners.*;
import fr.monkhanny.dorfromantik.utils.MusicPlayer;
import fr.monkhanny.dorfromantik.enums.Images;
import javax.swing.*;
import java.awt.*;
@@ -18,9 +18,11 @@ public class SettingsPanel extends JPanel {
this.mainMenu = mainMenu;
this.settingsFrame = settingsFrame;
setLayout(new BorderLayout());
initializeSettingsFrame();
setupBackground();
setupMainPanel();
setupTopPanel(); // Nouveau panneau pour le titre et le bouton de retour
setupMainPanel(); // Configuration du panneau principal pour les sliders et boutons
}
private void initializeSettingsFrame() {
@@ -30,87 +32,161 @@ public class SettingsPanel extends JPanel {
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);
this.add(background, BorderLayout.CENTER); // Déplacer l'ajout du fond au centre
}
private void setupTopPanel() {
JPanel topPanel = new JPanel(new BorderLayout());
topPanel.setOpaque(false);
Title title = new Title("Paramètres", 70, Color.WHITE);
title.setHorizontalAlignment(JLabel.CENTER);
topPanel.add(title, BorderLayout.CENTER);
JButton returnButton = createReturnButtonWithIcon();
JPanel leftPanel = new JPanel(new FlowLayout(FlowLayout.LEFT));
leftPanel.setOpaque(false);
leftPanel.add(returnButton);
topPanel.add(leftPanel, BorderLayout.WEST);
this.add(topPanel, BorderLayout.NORTH);
}
@Override
protected void paintComponent(Graphics g) {
super.paintComponent(g);
ImageIcon backgroundImage = new ImageIcon("./ressources/images/MainMenu/backgroundBlured.jpg");
g.drawImage(backgroundImage.getImage(), 0, 0, getWidth(), getHeight(), this);
}
private void setupMainPanel() {
JPanel mainPanel = createMainPanel();
JLabel title = createTitle();
mainPanel.add(title, createGridBagConstraints(0, 0, 2));
mainPanel.add(Box.createVerticalStrut(30), createGridBagConstraints(0, 1, 1));
// Musique Panel
JSlider musicSlider = new JSlider(0, 100, Options.MUSIC_MUTED ? 0 : Options.MUSIC_VOLUME);
JPanel musicPanel = createSoundPanel("Musique", musicSlider, new MusicVolumeChangeListener(musicSlider), new MuteCheckBoxListener("Musique"));
mainPanel.add(musicPanel, createGridBagConstraints(0, 2, 1));
mainPanel.add(Box.createVerticalStrut(30), createGridBagConstraints(0, 3, 1));
// SFX Panel
JSlider sfxSlider = new JSlider(0, 100, Options.SOUNDS_MUTED ? 0 : Options.SOUNDS_VOLUME);
JPanel sfxPanel = createSoundPanel("SFX", sfxSlider, new SoundsVolumeChangeListener(sfxSlider), new MuteCheckBoxListener("SFX"));
mainPanel.add(sfxPanel, createGridBagConstraints(0, 4, 1));
// Close Button
JButton closeButton = createCloseButton();
mainPanel.add(closeButton, createGridBagConstraints(0, 5, 1));
// Add to background
((JLabel) this.getComponent(0)).add(mainPanel);
}
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;
}
// Section Musique
JSlider musicSlider = new JSlider(0, 100, Options.MUSIC_MUTED ? 0 : Options.MUSIC_VOLUME);
JPanel musicPanel = createSoundPanel("Musique", musicSlider, new MusicVolumeChangeListener(musicSlider), new MuteCheckBoxListener("Musique"));
mainPanel.add(musicPanel, createGridBagConstraints(0, 0, 1));
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;
// Section SFX
JSlider sfxSlider = new JSlider(0, 100, Options.SOUNDS_MUTED ? 0 : Options.SOUNDS_VOLUME);
JPanel sfxPanel = createSoundPanel("SFX", sfxSlider, new SoundsVolumeChangeListener(sfxSlider), new MuteCheckBoxListener("SFX"));
mainPanel.add(sfxPanel, createGridBagConstraints(0, 1, 1));
// Section Auto Focus
JPanel autoFocusPanel = createAutoFocusPanel();
mainPanel.add(autoFocusPanel, createGridBagConstraints(0, 2, 1));
mainPanel.add(Box.createVerticalStrut(30), createGridBagConstraints(0, 3, 1));
this.add(mainPanel, BorderLayout.CENTER);
}
private JPanel createSoundPanel(String labelText, JSlider volumeSlider, ChangeListener sliderChangeListener, MuteCheckBoxListener muteCheckBoxListener) {
JPanel panel = new JPanel(new GridBagLayout());
JPanel panel = new JPanel();
panel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS)); // Utilisation de BoxLayout pour une disposition verticale
panel.setOpaque(false);
GridBagConstraints gbc = new GridBagConstraints();
gbc.insets = new Insets(10, 10, 10, 10);
gbc.gridx = 0;
// Titre de la section (ex: "Musique" ou "SFX")
JLabel titleLabel = new JLabel(labelText);
titleLabel.setFont(new Font("Roboto", Font.BOLD, 30));
titleLabel.setAlignmentX(Component.CENTER_ALIGNMENT); // Alignement à gauche
panel.add(titleLabel);
panel.add(Box.createVerticalStrut(10)); // Espacement vertical
// Panneau pour le bouton "Couper le son"
JPanel mutePanel = new JPanel();
mutePanel.setLayout(new BoxLayout(mutePanel, BoxLayout.X_AXIS)); // Disposition horizontale pour inverser l'ordre
mutePanel.setOpaque(false);
JLabel muteLabel = new JLabel("Couper le son");
muteLabel.setFont(new Font("Roboto", Font.PLAIN, 18)); // Augmentation de la taille du texte
muteLabel.setAlignmentX(Component.LEFT_ALIGNMENT); // Aligner le texte à gauche
mutePanel.add(muteLabel);
// Ajouter la checkbox après le texte pour qu'elle soit à droite
JCheckBox muteCheckBox = new JCheckBox();
muteCheckBox.setFont(new Font("Roboto", Font.PLAIN, 18)); // Optionnel, si le style du texte dans la case est souhaité
muteCheckBox.setFocusPainted(false);
muteCheckBox.setOpaque(false);
muteCheckBox.setBorderPainted(false);
muteCheckBox.setMargin(new Insets(5, 5, 5, 5));
muteCheckBox.setSelected(!("Musique".equals(labelText) ? Options.MUSIC_MUTED : Options.SOUNDS_MUTED));
muteCheckBox.addActionListener(muteCheckBoxListener);
panel.add(new JLabel(labelText), gbc);
gbc.gridx++;
panel.add(muteCheckBox, gbc);
mutePanel.add(Box.createHorizontalGlue()); // Espace flexible entre le texte et la checkbox
mutePanel.add(muteCheckBox);
panel.add(mutePanel);
panel.add(Box.createVerticalStrut(10)); // Espace vertical
// Panneau pour le slider "Gérer le son"
JPanel volumePanel = new JPanel(new BorderLayout());
volumePanel.setOpaque(false);
JLabel manageVolumeLabel = new JLabel("Gérer le son");
manageVolumeLabel.setFont(new Font("Roboto", Font.PLAIN, 18));
volumePanel.add(manageVolumeLabel, BorderLayout.NORTH);
// Création et ajout du slider
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);
volumePanel.add(createSliderPanel(volumeSlider), BorderLayout.CENTER);
gbc.gridx++;
panel.add(createSliderPanel(volumeSlider), gbc);
panel.add(volumePanel);
return panel;
}
private JPanel createAutoFocusPanel() {
JPanel panel = new JPanel();
panel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS)); // Disposition verticale
panel.setOpaque(false); // Assurer que le fond est transparent
// Titre de la section
JLabel titleLabel = new JLabel("Focus Automatique");
titleLabel.setFont(new Font("Roboto", Font.BOLD, 30));
titleLabel.setAlignmentX(Component.CENTER_ALIGNMENT); // Aligner le texte au centre
panel.add(titleLabel);
panel.add(Box.createVerticalStrut(10)); // Espacement vertical
// Panneau contenant texte et case à cocher sur la même ligne
JPanel checkBoxPanel = new JPanel();
checkBoxPanel.setLayout(new BoxLayout(checkBoxPanel, BoxLayout.X_AXIS)); // Disposition horizontale
checkBoxPanel.setOpaque(false); // Assurer que le fond est transparent
// Texte explicatif avant la case à cocher
JLabel descriptionLabel = new JLabel("Gestion du focus automatique (nécessite une bonne carte graphique) :");
descriptionLabel.setFont(new Font("Roboto", Font.PLAIN, 18));
descriptionLabel.setAlignmentX(Component.LEFT_ALIGNMENT); // Aligner à gauche
checkBoxPanel.add(descriptionLabel); // Ajouter le texte dans le panneau
// Ajouter un espace flexible entre le texte et la case à cocher
checkBoxPanel.add(Box.createHorizontalGlue()); // Cela pousse la case à cocher vers la droite
// Case à cocher
JCheckBox autoFocusCheckBox = new JCheckBox();
autoFocusCheckBox.setFont(new Font("Roboto", Font.PLAIN, 18));
autoFocusCheckBox.setFocusPainted(false);
autoFocusCheckBox.setOpaque(false);
autoFocusCheckBox.setBorderPainted(false);
autoFocusCheckBox.setMargin(new Insets(5, 5, 5, 5));
autoFocusCheckBox.setSelected(Options.AUTO_FOCUS); // État initial selon la valeur actuelle de AUTO_FOCUS
autoFocusCheckBox.addActionListener(e -> {
Options.AUTO_FOCUS = autoFocusCheckBox.isSelected(); // Mettre à jour la variable auto-focus
});
checkBoxPanel.add(autoFocusCheckBox); // Ajouter la case à cocher
// Ajouter le panneau contenant texte + case à cocher
panel.add(checkBoxPanel);
return panel;
}
private JPanel createSliderPanel(JSlider volumeSlider) {
JPanel sliderPanel = new JPanel(new BorderLayout());
sliderPanel.setOpaque(false);
@@ -128,15 +204,31 @@ public class SettingsPanel extends JPanel {
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;
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 JButton createReturnButtonWithIcon() {
ImageIcon originalIcon = new ImageIcon(Images.EXIT_ICON.getImagePath());
// Redimensionner l'image à la taille du bouton
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)); // Ajuster la taille du bouton selon l'icône
returnButton.setContentAreaFilled(false); // Bouton transparent
returnButton.setBorderPainted(false); // Pas de bordure
returnButton.setFocusPainted(false); // Pas de focus
returnButton.addActionListener(new CloseButtonListener(mainMenu, settingsFrame));
return returnButton;
}
}