181 lines
6.8 KiB
Java
181 lines
6.8 KiB
Java
package fr.monkhanny.dorfromantik.gui;
|
|
|
|
import fr.monkhanny.dorfromantik.components.Title;
|
|
import fr.monkhanny.dorfromantik.listeners.CloseButtonListener;
|
|
import fr.monkhanny.dorfromantik.listeners.TutorialButtonHoverListener;
|
|
import fr.monkhanny.dorfromantik.enums.Images;
|
|
|
|
import javax.swing.*;
|
|
import java.awt.*;
|
|
import java.util.List;
|
|
|
|
public class TutorialPanel extends JPanel {
|
|
|
|
private List<Step> steps;
|
|
private int currentStepIndex;
|
|
private Title title;
|
|
private JLabel stepText;
|
|
private JLabel stepImage;
|
|
private JButton nextButton;
|
|
private JButton prevButton;
|
|
private MainMenu mainMenu;
|
|
private JFrame tutorialFrame;
|
|
|
|
public TutorialPanel(List<Step> steps, MainMenu mainMenu, JFrame tutorialFrame) {
|
|
this.steps = steps;
|
|
this.currentStepIndex = 0;
|
|
this.mainMenu = mainMenu;
|
|
this.tutorialFrame = tutorialFrame;
|
|
|
|
// Utiliser BorderLayout pour la disposition principale
|
|
setLayout(new BorderLayout());
|
|
|
|
// Création du titre centré en haut
|
|
title = new Title("Comment jouer ?", 70f, Color.WHITE);
|
|
title.setHorizontalAlignment(JLabel.CENTER);
|
|
title.setOpaque(false);
|
|
|
|
// Panneau contenant le titre et le bouton de retour
|
|
JPanel northPanel = new JPanel(new BorderLayout());
|
|
northPanel.setOpaque(false);
|
|
northPanel.add(title, BorderLayout.CENTER);
|
|
|
|
// Ajouter l'icône de retour à droite du panneau nord
|
|
JButton returnButton = createReturnButtonWithIcon();
|
|
JPanel topRightPanel = new JPanel(new FlowLayout(FlowLayout.RIGHT));
|
|
topRightPanel.setOpaque(false);
|
|
topRightPanel.add(returnButton);
|
|
northPanel.add(topRightPanel, BorderLayout.WEST);
|
|
|
|
add(northPanel, BorderLayout.NORTH);
|
|
|
|
// Conteneur principal pour les étapes, centré
|
|
JPanel centerPanel = new JPanel();
|
|
centerPanel.setLayout(new GridBagLayout());
|
|
centerPanel.setOpaque(false); // Rendre le conteneur transparent
|
|
|
|
// Utiliser GridBagConstraints pour centrer le contenu verticalement
|
|
GridBagConstraints gbc = new GridBagConstraints();
|
|
gbc.gridx = 0;
|
|
gbc.gridy = 0;
|
|
gbc.fill = GridBagConstraints.HORIZONTAL;
|
|
gbc.insets = new Insets(10, 0, 10, 0);
|
|
|
|
// Conteneur pour le texte et l'image
|
|
JPanel stepContainer = new JPanel();
|
|
stepContainer.setLayout(new BoxLayout(stepContainer, BoxLayout.Y_AXIS));
|
|
stepContainer.setOpaque(false); // Transparent
|
|
|
|
stepText = new JLabel();
|
|
stepText.setFont(new Font("Arial", Font.BOLD, 28));
|
|
stepText.setForeground(Color.WHITE);
|
|
stepText.setAlignmentX(Component.CENTER_ALIGNMENT); // Centrer le texte horizontalement
|
|
|
|
stepImage = new JLabel();
|
|
stepImage.setAlignmentX(Component.CENTER_ALIGNMENT); // Centrer l'image horizontalement
|
|
|
|
// Ajouter les composants au conteneur d'étapes
|
|
stepContainer.add(stepText);
|
|
stepContainer.add(Box.createVerticalStrut(10)); // Espace entre texte et image
|
|
stepContainer.add(stepImage);
|
|
|
|
// Ajouter le conteneur d'étapes au centre du panel
|
|
centerPanel.add(stepContainer, gbc);
|
|
add(centerPanel, BorderLayout.CENTER);
|
|
|
|
// Panneau pour les boutons de navigation
|
|
JPanel buttonPanel = new JPanel();
|
|
buttonPanel.setLayout(new FlowLayout(FlowLayout.CENTER)); // Centrer les boutons
|
|
buttonPanel.setOpaque(false); // Transparent
|
|
|
|
prevButton = new JButton("Précédent");
|
|
nextButton = new JButton("Suivant");
|
|
|
|
// Personnalisation des boutons
|
|
styleButton(prevButton);
|
|
styleButton(nextButton);
|
|
|
|
prevButton.addActionListener(e -> showPreviousStep());
|
|
nextButton.addActionListener(e -> showNextStep());
|
|
|
|
buttonPanel.add(prevButton);
|
|
buttonPanel.add(nextButton);
|
|
|
|
// Ajouter le panneau des boutons en bas
|
|
add(buttonPanel, BorderLayout.SOUTH);
|
|
|
|
// Affichage initial de l'étape
|
|
updateStepDisplay();
|
|
}
|
|
|
|
@Override
|
|
protected void paintComponent(Graphics g) {
|
|
super.paintComponent(g); // Appel à super pour s'assurer que le panneau est dessiné
|
|
|
|
// Dessin de l'image de fond pour couvrir tout le panneau
|
|
ImageIcon backgroundImage = new ImageIcon("./ressources/images/MainMenu/backgroundBlured.jpg");
|
|
Image image = backgroundImage.getImage();
|
|
g.drawImage(image, 0, 0, getWidth(), getHeight(), this); // Dessiner l'image pour couvrir tout le panneau
|
|
}
|
|
|
|
private void updateStepDisplay() {
|
|
Step currentStep = steps.get(currentStepIndex);
|
|
stepText.setText(currentStep.getText());
|
|
stepImage.setIcon(new ImageIcon(currentStep.getImagePath()));
|
|
stepImage.setHorizontalAlignment(JLabel.CENTER);
|
|
stepImage.setVerticalAlignment(JLabel.CENTER);
|
|
prevButton.setEnabled(currentStepIndex > 0);
|
|
nextButton.setEnabled(currentStepIndex < steps.size() - 1);
|
|
}
|
|
|
|
private void styleButton(JButton button) {
|
|
// Police et taille
|
|
button.setFont(new Font("Arial", Font.BOLD, 18));
|
|
button.setForeground(Color.WHITE);
|
|
|
|
// Taille et forme des boutons
|
|
button.setPreferredSize(new Dimension(150, 50)); // Ajuster la taille des boutons
|
|
button.setBackground(new Color(34, 34, 34)); // Couleur de fond sombre
|
|
button.setBorder(BorderFactory.createLineBorder(Color.WHITE, 2)); // Bordure blanche
|
|
|
|
// Effet au survol
|
|
button.setRolloverEnabled(true);
|
|
button.setContentAreaFilled(true);
|
|
button.setFocusPainted(false); // Pas de focus visible
|
|
|
|
// Ajout de l'effet de survol
|
|
button.addMouseListener(new TutorialButtonHoverListener(button, new Color(60,60,60), new Color(34,34,34)));
|
|
}
|
|
|
|
private void showPreviousStep() {
|
|
if (currentStepIndex > 0) {
|
|
currentStepIndex--;
|
|
updateStepDisplay();
|
|
}
|
|
}
|
|
|
|
private void showNextStep() {
|
|
if (currentStepIndex < steps.size() - 1) {
|
|
currentStepIndex++;
|
|
updateStepDisplay();
|
|
}
|
|
}
|
|
|
|
private JButton createReturnButtonWithIcon() {
|
|
ImageIcon originalIcon = new ImageIcon(Images.EXIT_ICON.getImagePath());
|
|
|
|
// Redimensionnement de 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)); // Ajuste 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, tutorialFrame));
|
|
|
|
return returnButton;
|
|
}
|
|
}
|