Ajouts d'une page de tutoriel pour savoir comment jouer. ATTENTION, IL FAUT RAJOUTER LE BACKGROUND DE FOND

This commit is contained in:
2024-11-13 20:10:27 +01:00
parent 8a27da6bd1
commit b3d49aea11
10 changed files with 193 additions and 6 deletions

View File

@@ -7,6 +7,7 @@ import fr.monkhanny.dorfromantik.utils.MusicPlayer;
import fr.monkhanny.dorfromantik.enums.Musics;
import fr.monkhanny.dorfromantik.listeners.SettingsWindowListener;
import fr.monkhanny.dorfromantik.gui.SettingsPanel;
import fr.monkhanny.dorfromantik.controller.TutorialController;
import javax.swing.JFrame;
@@ -26,12 +27,15 @@ public class Main {
// Créer la fenêtre des paramètres
JFrame settingsFrame = new JFrame("Paramètres");
// Créer la fenêtre du tutoriel
JFrame howToPlayFrame = new JFrame("Tutoriel");
// Menu principal
MusicPlayer.loadMusic(Musics.MAIN_MENU_MUSIC);
MusicPlayer.playMusic();
MainMenu mainMenu = new MainMenu();
MainMenuResizeController MainMenuResizeController = new MainMenuResizeController(mainMenu);
MainMenuButtonController MainMenuButtonController = new MainMenuButtonController(mainMenu,settingsFrame);
MainMenuButtonController MainMenuButtonController = new MainMenuButtonController(mainMenu,settingsFrame,howToPlayFrame);
// Fenêtre des paramètres
@@ -41,5 +45,11 @@ public class Main {
settingsFrame.add(settingsPanel);
settingsFrame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
// Fenêtre du tutoriel
TutorialController tutorialController = new TutorialController();
howToPlayFrame.addWindowListener(windowListener);
howToPlayFrame.add(tutorialController.getTutorialPanel());
howToPlayFrame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
}
}

View File

@@ -17,8 +17,9 @@ public class MainMenuButtonController implements ActionListener {
private MainMenu mainMenu;
private JFrame settingsFrame;
private JFrame howToPlayFrame;
public MainMenuButtonController(MainMenu mainMenu, JFrame settingsFrame) {
public MainMenuButtonController(MainMenu mainMenu, JFrame settingsFrame, JFrame howToPlayFrame) {
this.mainMenu = mainMenu;
// Ajouter les écouteurs d'événements sur les boutons
ButtonPanel buttonPanel = mainMenu.getButtonPanel();
@@ -34,6 +35,11 @@ public class MainMenuButtonController implements ActionListener {
this.settingsFrame = settingsFrame;
this.settingsFrame.setLocationRelativeTo(null);
this.settingsFrame.setVisible(false);
// Créer la fenêtre du tutoriel
this.howToPlayFrame = howToPlayFrame;
this.howToPlayFrame.setLocationRelativeTo(null);
this.howToPlayFrame.setVisible(false);
}
@Override
@@ -72,11 +78,23 @@ public class MainMenuButtonController implements ActionListener {
// Logic to continue the game
}
private void showHowToPlay() {
System.out.println("Afficher comment jouer...");
// Logic to show how to play
public void showHowToPlay() {
// 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.howToPlayFrame.setSize(mainMenuSize);
this.howToPlayFrame.setLocation(mainMenuLocation);
// Cacher la fenêtre du menu principal
this.mainMenu.setVisible(false);
// Afficher la fenêtre des paramètres
this.howToPlayFrame.setVisible(true);
}
private void exitGame() {
System.exit(0); // Fermer l'application
}

View File

@@ -0,0 +1,27 @@
package fr.monkhanny.dorfromantik.controller;
import fr.monkhanny.dorfromantik.gui.TutorialPanel;
import fr.monkhanny.dorfromantik.gui.Step;
import fr.monkhanny.dorfromantik.enums.Images;
import javax.swing.*;
import java.util.ArrayList;
import java.util.List;
public class TutorialController {
private TutorialPanel tutorialPanel;
public TutorialController() {
List<Step> steps = new ArrayList<>();
steps.add(new Step("Étape 1", "Explication de la première étape.", Images.TUTORIAL_GIF1.getImagePath()));
steps.add(new Step("Étape 2", "Explication de la deuxième étape.", Images.TUTORIAL_GIF2.getImagePath()));
steps.add(new Step("Étape 3", "Explication de la troisième étape.", Images.TUTORIAL_GIF3.getImagePath()));
steps.add(new Step("Étape 4", "Explication de la quatrième étape.", Images.TUTORIAL_GIF4.getImagePath()));
tutorialPanel = new TutorialPanel(steps);
}
public JPanel getTutorialPanel() {
return tutorialPanel;
}
}

View File

@@ -2,7 +2,7 @@ package fr.monkhanny.dorfromantik.enums;
public enum Images {
SETTINGS_ICON, EXIT_ICON;
SETTINGS_ICON, EXIT_ICON, TUTORIAL_GIF1, TUTORIAL_GIF2, TUTORIAL_GIF3, TUTORIAL_GIF4;
public String getImagePath() {
switch (this) {
@@ -10,6 +10,14 @@ public enum Images {
return "./ressources/images/Icone/SettingsIcon.png";
case EXIT_ICON:
return "./ressources/images/Icone/ExitIcon.png";
case TUTORIAL_GIF1:
return "./ressources/images/Tutorial/Gif1.gif";
case TUTORIAL_GIF2:
return "./ressources/images/Tutorial/Gif2.gif";
case TUTORIAL_GIF3:
return "./ressources/images/Tutorial/Gif3.gif";
case TUTORIAL_GIF4:
return "./ressources/images/Tutorial/Gif4.gif";
default:
throw new IllegalArgumentException("Unexpected value: " + this);
}

View File

@@ -0,0 +1,25 @@
package fr.monkhanny.dorfromantik.gui;
public class Step {
private String title;
private String text;
private String imagePath;
public Step(String title, String text, String imagePath) {
this.title = title;
this.text = text;
this.imagePath = imagePath;
}
public String getText() {
return text;
}
public String getImagePath() {
return imagePath;
}
public String getTitle() {
return title;
}
}

View File

@@ -0,0 +1,99 @@
package fr.monkhanny.dorfromantik.gui;
import fr.monkhanny.dorfromantik.components.Title;
import fr.monkhanny.dorfromantik.controller.TutorialController;
import fr.monkhanny.dorfromantik.gui.Step;
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;
public TutorialPanel(List<Step> steps) {
this.steps = steps;
this.currentStepIndex = 0;
// Setup the panel layout
setLayout(new BorderLayout());
// Background setup
setupBackground();
// Setup the title
title = new Title("Tutoriel", 70f, Color.BLACK);
add(title, BorderLayout.NORTH);
// Step text and image container
JPanel stepContainer = new JPanel();
stepContainer.setLayout(new BoxLayout(stepContainer, BoxLayout.Y_AXIS)); // Vertical BoxLayout
stepText = new JLabel();
stepText.setFont(new Font("Arial", Font.PLAIN, 18));
stepText.setForeground(Color.WHITE);
stepImage = new JLabel();
// Center the text and the image
stepText.setAlignmentX(Component.CENTER_ALIGNMENT); // Center the text horizontally
stepImage.setAlignmentX(Component.CENTER_ALIGNMENT); // Center the image horizontally
// Add components to the stepContainer
stepContainer.add(stepText);
stepContainer.add(Box.createVerticalStrut(10)); // Optional space between text and image
stepContainer.add(stepImage);
add(stepContainer, BorderLayout.CENTER);
// Navigation buttons
JPanel buttonPanel = new JPanel();
buttonPanel.setLayout(new FlowLayout());
prevButton = new JButton("Précédent");
nextButton = new JButton("Suivant");
prevButton.addActionListener(e -> showPreviousStep());
nextButton.addActionListener(e -> showNextStep());
buttonPanel.add(prevButton);
buttonPanel.add(nextButton);
add(buttonPanel, BorderLayout.SOUTH);
// Initial step display
updateStepDisplay();
}
private void setupBackground() {
JLabel background = new JLabel(new ImageIcon("./ressources/images/MainMenu/backgroundBlured.jpg"));
background.setLayout(null);
background.setBounds(0, 0, getWidth(), getHeight());
add(background, BorderLayout.CENTER);
}
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 showPreviousStep() {
if (currentStepIndex > 0) {
currentStepIndex--;
updateStepDisplay();
}
}
private void showNextStep() {
if (currentStepIndex < steps.size() - 1) {
currentStepIndex++;
updateStepDisplay();
}
}
}