Un peu de ménage dans le git
This commit is contained in:
36
src/fr/monkhanny/dorfromantik/gui/ButtonHoverAnimator.java
Normal file
36
src/fr/monkhanny/dorfromantik/gui/ButtonHoverAnimator.java
Normal file
@@ -0,0 +1,36 @@
|
||||
package fr.monkhanny.dorfromantik.gui;
|
||||
|
||||
import fr.monkhanny.dorfromantik.Options;
|
||||
import fr.monkhanny.dorfromantik.controller.ButtonHoverAnimationListener;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
|
||||
public class ButtonHoverAnimator {
|
||||
|
||||
private final JButton button;
|
||||
private final Color originalColor;
|
||||
private static Font originalFont;
|
||||
private Timer animationTimer;
|
||||
|
||||
public ButtonHoverAnimator(JButton button) {
|
||||
this.button = button;
|
||||
this.originalColor = button.getForeground();
|
||||
ButtonHoverAnimator.originalFont = button.getFont();
|
||||
}
|
||||
|
||||
public void startAnimation(boolean entering) {
|
||||
if (animationTimer != null && animationTimer.isRunning()) {
|
||||
animationTimer.stop();
|
||||
}
|
||||
|
||||
// Create a new ActionListener instance
|
||||
animationTimer = new Timer(Options.ANIMATION_DELAY, new ButtonHoverAnimationListener(entering, button, originalColor, originalFont));
|
||||
animationTimer.start();
|
||||
}
|
||||
|
||||
public static void updateOriginalFont(float newFontSize) {
|
||||
originalFont = originalFont.deriveFont(newFontSize);
|
||||
}
|
||||
|
||||
}
|
87
src/fr/monkhanny/dorfromantik/gui/ButtonPanel.java
Normal file
87
src/fr/monkhanny/dorfromantik/gui/ButtonPanel.java
Normal file
@@ -0,0 +1,87 @@
|
||||
package fr.monkhanny.dorfromantik.gui;
|
||||
|
||||
import fr.monkhanny.dorfromantik.utils.FontManager;
|
||||
import fr.monkhanny.dorfromantik.components.Button;
|
||||
import fr.monkhanny.dorfromantik.controller.MainMenuMouseController;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.util.List;
|
||||
import java.util.Arrays;
|
||||
|
||||
|
||||
public class ButtonPanel extends JPanel {
|
||||
|
||||
private JButton newGameButton;
|
||||
private JButton continueGameButton;
|
||||
private JButton howToPlayButton;
|
||||
private JButton settingsButton;
|
||||
private JButton exitButton;
|
||||
|
||||
public ButtonPanel(float fontSize) {
|
||||
// Paramétrage de l'apparence du panneau
|
||||
this.setLayout(new BoxLayout(this, BoxLayout.Y_AXIS));
|
||||
this.setOpaque(false); // Rendre le panneau transparent
|
||||
this.setBorder(BorderFactory.createEmptyBorder(50, 30, 30, 30)); // Marge à gauche et en bas
|
||||
|
||||
// Espacement vertical extensible pour centrer les boutons principaux verticalement
|
||||
this.add(Box.createVerticalGlue());
|
||||
|
||||
// Créer les boutons avec un style personnalisé
|
||||
newGameButton = Button.createCustomTextButton("Jouer", fontSize);
|
||||
continueGameButton = Button.createCustomTextButton("Récompenses", fontSize);
|
||||
howToPlayButton = Button.createCustomTextButton("Comment jouer ?", fontSize);
|
||||
settingsButton = Button.createCustomTextButton("Paramètres", fontSize);
|
||||
exitButton = Button.createCustomTextButton("Quitter", fontSize);
|
||||
|
||||
// Ajouter les boutons au panneau
|
||||
this.add(newGameButton);
|
||||
this.add(Box.createVerticalStrut(10)); // Espace entre les boutons
|
||||
this.add(continueGameButton);
|
||||
this.add(Box.createVerticalStrut(10));
|
||||
this.add(howToPlayButton);
|
||||
this.add(Box.createVerticalStrut(10));
|
||||
this.add(settingsButton);
|
||||
this.add(Box.createVerticalStrut(10));
|
||||
this.add(exitButton);
|
||||
|
||||
// Espacement extensible pour maintenir les icônes en bas
|
||||
this.add(Box.createVerticalGlue());
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
MainMenuMouseController gestionSouris = new MainMenuMouseController(this);
|
||||
}
|
||||
|
||||
public JButton getNewGameButton() {
|
||||
return newGameButton;
|
||||
}
|
||||
|
||||
public JButton getContinueGameButton() {
|
||||
return continueGameButton;
|
||||
}
|
||||
|
||||
public JButton getHowToPlayButton() {
|
||||
return howToPlayButton;
|
||||
}
|
||||
|
||||
public JButton getSettingsButton() {
|
||||
return settingsButton;
|
||||
}
|
||||
|
||||
public JButton getExitButton() {
|
||||
return exitButton;
|
||||
}
|
||||
|
||||
public List<JButton> getButtons() {
|
||||
return Arrays.asList(newGameButton, continueGameButton, howToPlayButton, settingsButton, exitButton);
|
||||
}
|
||||
|
||||
public void updateButtonFonts(int windowWidth) {
|
||||
// Mettre à jour la police des boutons avec la taille ajustée
|
||||
float newFontSize = windowWidth / 30f;
|
||||
newGameButton.setFont(FontManager.getTitleFont(newFontSize));
|
||||
continueGameButton.setFont(FontManager.getTitleFont(newFontSize));
|
||||
howToPlayButton.setFont(FontManager.getTitleFont(newFontSize));
|
||||
settingsButton.setFont(FontManager.getTitleFont(newFontSize));
|
||||
exitButton.setFont(FontManager.getTitleFont(newFontSize));
|
||||
}
|
||||
}
|
165
src/fr/monkhanny/dorfromantik/gui/GameModeSelectionPanel.java
Normal file
165
src/fr/monkhanny/dorfromantik/gui/GameModeSelectionPanel.java
Normal file
@@ -0,0 +1,165 @@
|
||||
package fr.monkhanny.dorfromantik.gui;
|
||||
|
||||
import fr.monkhanny.dorfromantik.components.Title;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
import java.awt.event.ActionListener;
|
||||
|
||||
public class GameModeSelectionPanel extends JPanel {
|
||||
|
||||
private JLabel titleLabel;
|
||||
private JButton mode1Button;
|
||||
private JButton mode2Button;
|
||||
private JButton mode3Button;
|
||||
private JButton mode4Button;
|
||||
private JTextField seedField;
|
||||
private JButton startButton;
|
||||
|
||||
|
||||
public GameModeSelectionPanel(ActionListener buttonListener, JFrame gameModeFrame, MainMenu mainMenu) {
|
||||
setLayout(new BorderLayout());
|
||||
|
||||
// Ajouter l'image de fond
|
||||
JLabel background = new JLabel(new ImageIcon("./ressources/images/MainMenu/backgroundBlured.jpg"));
|
||||
background.setLayout(new BorderLayout()); // Utilisation de BorderLayout ici
|
||||
this.add(background);
|
||||
|
||||
// Créer un topPanel avec le bouton de retour
|
||||
JPanel topPanel = createTopPanel(gameModeFrame, mainMenu);
|
||||
background.add(topPanel, BorderLayout.NORTH); // Placer topPanel en haut à gauche
|
||||
|
||||
// Panel principal (au centre)
|
||||
JPanel mainPanel = createMainPanel();
|
||||
background.add(mainPanel, BorderLayout.CENTER); // Placer le contenu principal sous le bouton
|
||||
|
||||
// Title
|
||||
titleLabel = new Title("Choisissez un mode de jeu", 60f, Color.WHITE);
|
||||
mainPanel.add(titleLabel, createGridBagConstraints(0, 0, 2));
|
||||
|
||||
mainPanel.add(Box.createVerticalStrut(30), createGridBagConstraints(0, 1, 1));
|
||||
|
||||
// Mode buttons - now horizontally aligned
|
||||
JPanel modePanel = new JPanel(new FlowLayout(FlowLayout.CENTER, 20, 10)); // Centered with horizontal spacing
|
||||
modePanel.setOpaque(false);
|
||||
|
||||
mode1Button = createGameModeButton("Mode 1", buttonListener);
|
||||
mode2Button = createGameModeButton("Mode 2", buttonListener);
|
||||
mode3Button = createGameModeButton("Mode 3", buttonListener);
|
||||
mode4Button = createGameModeButton("Mode 4", buttonListener);
|
||||
|
||||
modePanel.add(mode1Button);
|
||||
modePanel.add(mode2Button);
|
||||
modePanel.add(mode3Button);
|
||||
modePanel.add(mode4Button);
|
||||
|
||||
mainPanel.add(modePanel, createGridBagConstraints(0, 2, 2)); // Span across 2 columns
|
||||
|
||||
mainPanel.add(Box.createVerticalStrut(30), createGridBagConstraints(0, 3, 1));
|
||||
|
||||
// Seed input and start button
|
||||
JPanel seedPanel = createSeedPanel(buttonListener);
|
||||
mainPanel.add(seedPanel, createGridBagConstraints(0, 4, 2));
|
||||
}
|
||||
|
||||
private JPanel createTopPanel(JFrame gameModeFrame, MainMenu mainMenu) {
|
||||
// Utilisation de BorderLayout pour aligner correctement le bouton à gauche
|
||||
JPanel topPanel = new JPanel(new BorderLayout());
|
||||
topPanel.setOpaque(false);
|
||||
|
||||
// Création du bouton de retour
|
||||
JButton returnButton = createReturnButtonWithIcon(gameModeFrame, mainMenu);
|
||||
|
||||
// Ajouter le bouton de retour à gauche (West)
|
||||
topPanel.add(returnButton, BorderLayout.WEST);
|
||||
|
||||
return topPanel;
|
||||
}
|
||||
|
||||
private JButton createReturnButtonWithIcon(JFrame gameModeFrame, MainMenu mainMenu) {
|
||||
ImageIcon originalIcon = new ImageIcon("./ressources/images/Icone/ExitIcon.png");
|
||||
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));
|
||||
returnButton.setContentAreaFilled(false);
|
||||
returnButton.setBorderPainted(false);
|
||||
returnButton.setFocusPainted(false);
|
||||
returnButton.addActionListener(e -> {
|
||||
gameModeFrame.setVisible(false);
|
||||
mainMenu.setVisible(true);
|
||||
});
|
||||
|
||||
return returnButton;
|
||||
}
|
||||
|
||||
private JPanel createMainPanel() {
|
||||
JPanel mainPanel = new JPanel(new GridBagLayout());
|
||||
mainPanel.setOpaque(false);
|
||||
return mainPanel;
|
||||
}
|
||||
|
||||
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 createGameModeButton(String modeName, ActionListener buttonListener) {
|
||||
JButton button = new JButton(modeName);
|
||||
button.setFont(new Font("Arial", Font.BOLD, 24));
|
||||
button.setBackground(new Color(0, 122, 255));
|
||||
button.setForeground(Color.WHITE);
|
||||
button.setBorder(BorderFactory.createLineBorder(Color.WHITE, 2));
|
||||
button.setFocusPainted(false);
|
||||
button.addActionListener(buttonListener);
|
||||
button.setPreferredSize(new Dimension(150, 50)); // Adjust the size of the buttons
|
||||
return button;
|
||||
}
|
||||
|
||||
private JPanel createSeedPanel(ActionListener buttonListener) {
|
||||
JPanel seedPanel = new JPanel();
|
||||
seedPanel.setOpaque(false);
|
||||
seedPanel.setLayout(new FlowLayout(FlowLayout.CENTER));
|
||||
|
||||
JLabel seedLabel = new JLabel("Entrez votre seed:");
|
||||
seedLabel.setForeground(Color.WHITE);
|
||||
seedPanel.add(seedLabel);
|
||||
|
||||
seedField = new JTextField(20);
|
||||
seedField.setFont(new Font("Arial", Font.PLAIN, 18));
|
||||
seedField.setPreferredSize(new Dimension(250, 40));
|
||||
seedField.setBorder(BorderFactory.createLineBorder(Color.WHITE, 2));
|
||||
seedPanel.add(seedField);
|
||||
|
||||
startButton = new JButton("Démarrer");
|
||||
startButton.setFont(new Font("Arial", Font.BOLD, 24));
|
||||
startButton.setBackground(new Color(0, 255, 0));
|
||||
startButton.setForeground(Color.WHITE);
|
||||
startButton.setBorder(BorderFactory.createLineBorder(Color.WHITE, 2));
|
||||
startButton.setPreferredSize(new Dimension(150, 50));
|
||||
startButton.addActionListener(buttonListener);
|
||||
seedPanel.add(startButton);
|
||||
|
||||
return seedPanel;
|
||||
}
|
||||
|
||||
public String getStringSeed() {
|
||||
return seedField.getText();
|
||||
}
|
||||
|
||||
public long getLongSeed(){
|
||||
try{
|
||||
return Long.parseLong(seedField.getText());
|
||||
} catch (NumberFormatException e){
|
||||
System.err.println("Invalid seed, using current time as seed");
|
||||
return System.currentTimeMillis();
|
||||
}
|
||||
}
|
||||
}
|
12
src/fr/monkhanny/dorfromantik/gui/Leaderboard.java
Normal file
12
src/fr/monkhanny/dorfromantik/gui/Leaderboard.java
Normal file
@@ -0,0 +1,12 @@
|
||||
package fr.monkhanny.dorfromantik.gui;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
|
||||
public abstract class Leaderboard extends JPanel {
|
||||
public Leaderboard() {
|
||||
setLayout(new BorderLayout());
|
||||
}
|
||||
|
||||
public abstract void refresh(); // Méthode pour actualiser le contenu
|
||||
}
|
@@ -0,0 +1,39 @@
|
||||
package fr.monkhanny.dorfromantik.gui;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
|
||||
public class LeaderboardBarChartPanel extends JPanel {
|
||||
private int totalPlayers;
|
||||
private int rank;
|
||||
|
||||
public LeaderboardBarChartPanel(int totalPlayers, int rank) {
|
||||
this.totalPlayers = totalPlayers;
|
||||
this.rank = rank;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void paintComponent(Graphics g) {
|
||||
super.paintComponent(g);
|
||||
int spacing = 10; // Espacement entre les barres
|
||||
int barHeight = 20; // Hauteur de la barre
|
||||
int totalBars = 10; // Nombre de tranches
|
||||
int maxWidth = (getWidth() - (totalBars + 1) * spacing) / totalBars;
|
||||
|
||||
// Dessiner chaque barre pour chaque tranche
|
||||
for (int i = 0; i < totalBars; i++) {
|
||||
int x = spacing + i * (maxWidth + spacing);
|
||||
int y = 50; // Position verticale de la barre
|
||||
|
||||
// Déterminer la couleur : colorier la tranche actuelle
|
||||
if (i == (rank - 1) / (totalPlayers / 10)) {
|
||||
g.setColor(new Color(0, 255, 0)); // Vert pour la tranche actuelle
|
||||
} else {
|
||||
g.setColor(new Color(255, 0, 0)); // Rouge pour les autres tranches
|
||||
}
|
||||
|
||||
// Dessiner la barre
|
||||
g.fillRect(x, y, maxWidth, barHeight);
|
||||
}
|
||||
}
|
||||
}
|
64
src/fr/monkhanny/dorfromantik/gui/LeaderboardByTier.java
Normal file
64
src/fr/monkhanny/dorfromantik/gui/LeaderboardByTier.java
Normal file
@@ -0,0 +1,64 @@
|
||||
package fr.monkhanny.dorfromantik.gui;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
|
||||
// @TODO : MODIFIER CAR C'EST PAS BEAU + BDD
|
||||
public class LeaderboardByTier extends Leaderboard {
|
||||
|
||||
public LeaderboardByTier() {
|
||||
super();
|
||||
refresh(); // Charge les données initiales
|
||||
}
|
||||
|
||||
@Override
|
||||
public void refresh() {
|
||||
removeAll(); // Supprime tout contenu existant
|
||||
setBackground(new Color(64, 0, 128));
|
||||
|
||||
// Titre
|
||||
JLabel titleLabel = new JLabel("CLASSEMENT PAR TRANCHE");
|
||||
titleLabel.setForeground(Color.WHITE);
|
||||
titleLabel.setFont(new Font("Arial", Font.BOLD, 24));
|
||||
titleLabel.setHorizontalAlignment(SwingConstants.CENTER);
|
||||
add(titleLabel, BorderLayout.NORTH);
|
||||
|
||||
// Contenu
|
||||
JPanel tierPanel = new JPanel();
|
||||
tierPanel.setLayout(new BoxLayout(tierPanel, BoxLayout.Y_AXIS));
|
||||
tierPanel.setBackground(new Color(64, 0, 128));
|
||||
|
||||
// Exemple de tranche
|
||||
int totalPlayers = 1000;
|
||||
int rank = 237; // Exemple : rang du joueur
|
||||
int tierSize = totalPlayers / 10;
|
||||
int tier = (rank - 1) / tierSize + 1;
|
||||
|
||||
// Label indiquant la tranche dans laquelle le joueur se trouve
|
||||
JLabel infoLabel = new JLabel("Vous êtes dans la tranche : " + tier);
|
||||
infoLabel.setFont(new Font("Arial", Font.PLAIN, 18));
|
||||
infoLabel.setForeground(Color.WHITE);
|
||||
infoLabel.setAlignmentX(CENTER_ALIGNMENT);
|
||||
|
||||
// Pourcentage du joueur
|
||||
double percentage = (double) rank / totalPlayers * 100;
|
||||
JLabel percentageLabel = new JLabel(String.format("Vous faites partie des %.2f%% des joueurs", percentage));
|
||||
percentageLabel.setFont(new Font("Arial", Font.PLAIN, 18));
|
||||
percentageLabel.setForeground(Color.WHITE);
|
||||
percentageLabel.setAlignmentX(CENTER_ALIGNMENT);
|
||||
|
||||
// Ajouter les labels à la JPanel
|
||||
tierPanel.add(Box.createVerticalStrut(20));
|
||||
tierPanel.add(infoLabel);
|
||||
tierPanel.add(percentageLabel);
|
||||
|
||||
// Ajouter le diagramme en barres pour les tranches
|
||||
LeaderboardBarChartPanel barChartPanel = new LeaderboardBarChartPanel(totalPlayers, rank);
|
||||
tierPanel.add(Box.createVerticalStrut(20)); // Espacement
|
||||
tierPanel.add(barChartPanel);
|
||||
|
||||
add(tierPanel, BorderLayout.CENTER);
|
||||
revalidate();
|
||||
repaint();
|
||||
}
|
||||
}
|
160
src/fr/monkhanny/dorfromantik/gui/LeaderboardWorldWide.java
Normal file
160
src/fr/monkhanny/dorfromantik/gui/LeaderboardWorldWide.java
Normal file
@@ -0,0 +1,160 @@
|
||||
package fr.monkhanny.dorfromantik.gui;
|
||||
|
||||
import fr.monkhanny.dorfromantik.utils.Database;
|
||||
import fr.monkhanny.dorfromantik.utils.PlayerScore;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
import java.sql.SQLException;
|
||||
import java.util.List;
|
||||
|
||||
public class LeaderboardWorldWide extends Leaderboard {
|
||||
|
||||
public LeaderboardWorldWide() {
|
||||
super();
|
||||
refresh(); // Charge les données initiales
|
||||
}
|
||||
|
||||
@Override
|
||||
public void refresh() {
|
||||
removeAll(); // Supprime tout contenu existant
|
||||
setBackground(new Color(245, 245, 245)); // Gris clair plus chaleureux
|
||||
|
||||
// Panel principal pour centrer le leaderboard
|
||||
JPanel mainPanel = new JPanel();
|
||||
mainPanel.setLayout(new BoxLayout(mainPanel, BoxLayout.Y_AXIS));
|
||||
mainPanel.setBackground(new Color(245, 245, 245)); // Gris clair
|
||||
mainPanel.setBorder(BorderFactory.createEmptyBorder(20, 20, 20, 20));
|
||||
|
||||
// Titre
|
||||
JLabel titleLabel = new JLabel("Classement mondial");
|
||||
titleLabel.setForeground(new Color(76, 175, 80)); // Vert plus doux et moderne
|
||||
titleLabel.setFont(new Font("Roboto", Font.BOLD, 32)); // Police moderne
|
||||
titleLabel.setAlignmentX(CENTER_ALIGNMENT);
|
||||
|
||||
// Panel pour les trois premiers
|
||||
JPanel topThreePanel = new JPanel(new GridBagLayout());
|
||||
topThreePanel.setBackground(new Color(245, 245, 245)); // Gris clair
|
||||
GridBagConstraints gbc = new GridBagConstraints();
|
||||
gbc.fill = GridBagConstraints.BOTH;
|
||||
gbc.insets = new Insets(0, 10, 0, 10);
|
||||
|
||||
// Récupérer les meilleurs joueurs depuis la base de données
|
||||
Database db = null;
|
||||
List<PlayerScore> topPlayers = null;
|
||||
try {
|
||||
db = new Database();
|
||||
topPlayers = db.getTopPlayers();
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
} finally {
|
||||
if (db != null) {
|
||||
db.close();
|
||||
}
|
||||
}
|
||||
|
||||
if (topPlayers != null && topPlayers.size() >= 3) {
|
||||
// Ajout des trois premiers joueurs avec médailles
|
||||
gbc.gridx = 0;
|
||||
gbc.weightx = 0.4;
|
||||
topThreePanel.add(createTopPlayerPanel(topPlayers.get(1).getUsername(), topPlayers.get(1).getScore(),
|
||||
"./ressources/images/MainMenu/Leaderboard/2.png", false), gbc);
|
||||
|
||||
gbc.gridx = 1;
|
||||
gbc.weightx = 0.5;
|
||||
topThreePanel.add(createTopPlayerPanel(topPlayers.get(0).getUsername(), topPlayers.get(0).getScore(),
|
||||
"./ressources/images/MainMenu/Leaderboard/1.png", true), gbc);
|
||||
|
||||
gbc.gridx = 2;
|
||||
gbc.weightx = 0.4;
|
||||
topThreePanel.add(createTopPlayerPanel(topPlayers.get(2).getUsername(), topPlayers.get(2).getScore(),
|
||||
"./ressources/images/MainMenu/Leaderboard/3.png", false), gbc);
|
||||
}
|
||||
|
||||
// Panel pour les autres joueurs
|
||||
JPanel playersPanel = new JPanel();
|
||||
playersPanel.setLayout(new BoxLayout(playersPanel, BoxLayout.Y_AXIS));
|
||||
playersPanel.setBackground(new Color(255, 255, 255)); // Blanc cassé
|
||||
|
||||
// Ajout des joueurs restants (de 4 à 10)
|
||||
if (topPlayers != null) {
|
||||
for (int i = 3; i < topPlayers.size(); i++) {
|
||||
PlayerScore player = topPlayers.get(i);
|
||||
playersPanel.add(createPlayerPanel(player.getUsername(), player.getScore(), i + 1));
|
||||
}
|
||||
}
|
||||
|
||||
// Ajoute tout au panneau principal
|
||||
mainPanel.add(titleLabel);
|
||||
mainPanel.add(Box.createRigidArea(new Dimension(0, 20)));
|
||||
mainPanel.add(topThreePanel);
|
||||
mainPanel.add(Box.createRigidArea(new Dimension(0, 20)));
|
||||
mainPanel.add(playersPanel);
|
||||
|
||||
add(mainPanel, BorderLayout.CENTER);
|
||||
|
||||
revalidate();
|
||||
repaint();
|
||||
}
|
||||
|
||||
private JPanel createPlayerPanel(String playerName, int score, int rank) {
|
||||
JPanel panel = new JPanel();
|
||||
panel.setLayout(new BorderLayout());
|
||||
panel.setBackground(new Color(250, 250, 250)); // Blanc cassé
|
||||
panel.setBorder(BorderFactory.createMatteBorder(1, 0, 1, 0, new Color(220, 220, 220))); // Bordure gris clair
|
||||
|
||||
JLabel rankLabel = new JLabel(rank + ". ");
|
||||
rankLabel.setFont(new Font("Roboto", Font.BOLD, 18));
|
||||
rankLabel.setForeground(new Color(76, 175, 80)); // Vert doux pour le rang
|
||||
rankLabel.setPreferredSize(new Dimension(40, 40));
|
||||
|
||||
JLabel nameLabel = new JLabel(playerName);
|
||||
nameLabel.setFont(new Font("Roboto", Font.PLAIN, 18));
|
||||
nameLabel.setForeground(new Color(60, 60, 60)); // Gris foncé pour le nom
|
||||
|
||||
JLabel scoreLabel = new JLabel(Integer.toString(score));
|
||||
scoreLabel.setFont(new Font("Roboto", Font.BOLD, 18));
|
||||
scoreLabel.setForeground(new Color(255, 140, 0)); // Orange moderne pour le score
|
||||
|
||||
panel.add(rankLabel, BorderLayout.WEST);
|
||||
panel.add(nameLabel, BorderLayout.CENTER);
|
||||
panel.add(scoreLabel, BorderLayout.EAST);
|
||||
|
||||
return panel;
|
||||
}
|
||||
|
||||
private ImageIcon resizeIcon(String path, int width, int height) {
|
||||
ImageIcon icon = new ImageIcon(path);
|
||||
Image img = icon.getImage().getScaledInstance(width, height, Image.SCALE_SMOOTH);
|
||||
return new ImageIcon(img);
|
||||
}
|
||||
|
||||
private JPanel createTopPlayerPanel(String playerName, int score, String medalPath, boolean isFirst) {
|
||||
JPanel panel = new JPanel();
|
||||
panel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS));
|
||||
panel.setBackground(isFirst ? new Color(255, 215, 0) : new Color(144, 238, 144)); // Or doré pour le premier, vert clair pour les autres
|
||||
panel.setBorder(BorderFactory.createEmptyBorder(20, 20, 20, 20));
|
||||
|
||||
// Ajout de l'icône de médaille redimensionnée
|
||||
JLabel medalLabel = new JLabel(resizeIcon(medalPath, isFirst ? 80 : 60, isFirst ? 80 : 60));
|
||||
medalLabel.setAlignmentX(CENTER_ALIGNMENT);
|
||||
|
||||
JLabel nameLabel = new JLabel(playerName);
|
||||
nameLabel.setFont(new Font("Roboto", isFirst ? Font.BOLD : Font.PLAIN, 20));
|
||||
nameLabel.setForeground(new Color(76, 175, 80)); // Vert doux pour le nom
|
||||
nameLabel.setAlignmentX(CENTER_ALIGNMENT);
|
||||
|
||||
JLabel scoreLabel = new JLabel(Integer.toString(score));
|
||||
scoreLabel.setFont(new Font("Roboto", Font.BOLD, isFirst ? 32 : 28));
|
||||
scoreLabel.setForeground(new Color(60, 60, 60)); // Gris foncé pour le score
|
||||
scoreLabel.setAlignmentX(CENTER_ALIGNMENT);
|
||||
|
||||
panel.add(medalLabel);
|
||||
panel.add(Box.createRigidArea(new Dimension(0, 5)));
|
||||
panel.add(nameLabel);
|
||||
panel.add(Box.createRigidArea(new Dimension(0, 5)));
|
||||
panel.add(scoreLabel);
|
||||
|
||||
return panel;
|
||||
}
|
||||
}
|
74
src/fr/monkhanny/dorfromantik/gui/MainMenu.java
Normal file
74
src/fr/monkhanny/dorfromantik/gui/MainMenu.java
Normal file
@@ -0,0 +1,74 @@
|
||||
package fr.monkhanny.dorfromantik.gui;
|
||||
|
||||
import fr.monkhanny.dorfromantik.utils.FontManager;
|
||||
import fr.monkhanny.dorfromantik.utils.ImageLoader;
|
||||
import fr.monkhanny.dorfromantik.enums.Fonts;
|
||||
import fr.monkhanny.dorfromantik.components.Title;
|
||||
import fr.monkhanny.dorfromantik.Options;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
|
||||
|
||||
public class MainMenu extends JFrame {
|
||||
|
||||
private Title titleLabel;
|
||||
private ButtonPanel buttonPanel;
|
||||
private JPanel leaderboardContainer; // Conteneur pour le leaderboard
|
||||
private Leaderboard currentLeaderboard; // Référence au leaderboard actuel
|
||||
|
||||
public MainMenu() {
|
||||
// Charger les polices pour le titre et les boutons
|
||||
FontManager.loadCustomFont(Fonts.TITLE); // Charge la police pour le titre
|
||||
FontManager.loadCustomFont(Fonts.BUTTON); // Charge la police pour les boutons
|
||||
|
||||
// Paramétrage de la fenêtre principale
|
||||
this.setTitle("Dorfromantik - Menu Principal");
|
||||
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||
super.setIconImage(ImageLoader.APPLICATION_ICON);
|
||||
this.setMinimumSize(Options.MINIMUM_FRAME_SIZE);
|
||||
this.setSize(1200, 800);
|
||||
this.setLocationRelativeTo(null); // Centrer la fenêtre
|
||||
this.setLayout(new BorderLayout());
|
||||
|
||||
// Arrière plan du menu principal
|
||||
JLabel background = new JLabel(new ImageIcon("./ressources/images/MainMenu/background.jpg"));
|
||||
background.setLayout(new BorderLayout());
|
||||
this.setContentPane(background);
|
||||
|
||||
// Ajouter le titre en haut au centre
|
||||
this.titleLabel = new Title("Dorfromantik", Options.BASE_TITLE_FONT_SIZE);
|
||||
background.add(titleLabel, BorderLayout.NORTH);
|
||||
|
||||
// Panneau des boutons avec style personnalisé (à gauche)
|
||||
this.buttonPanel = new ButtonPanel(Options.BASE_BUTTON_FONT_SIZE);
|
||||
background.add(buttonPanel, BorderLayout.WEST);
|
||||
|
||||
// Panel contenant le leaderboard avec espace à droite (pour pas qu'il soit collé au bord)
|
||||
JPanel leaderboardWrapper = new JPanel();
|
||||
leaderboardWrapper.setLayout(new BorderLayout());
|
||||
leaderboardWrapper.setOpaque(false); // Fond transparent pour laisser voir le background
|
||||
leaderboardWrapper.setBorder(BorderFactory.createEmptyBorder(20, 10, 20, 20)); // Ajout de marges internes
|
||||
|
||||
// Conteneur du leaderboard
|
||||
leaderboardContainer = new JPanel();
|
||||
leaderboardContainer.setLayout(new BorderLayout());
|
||||
leaderboardContainer.setOpaque(false); // Fond transparent pour laisser voir le background
|
||||
leaderboardWrapper.add(leaderboardContainer, BorderLayout.CENTER);
|
||||
background.add(leaderboardWrapper, BorderLayout.EAST);
|
||||
|
||||
// Initialisation du premier leaderboard (LeaderboardWorldwide)
|
||||
currentLeaderboard = new LeaderboardWorldWide();
|
||||
leaderboardContainer.add(currentLeaderboard, BorderLayout.CENTER);
|
||||
|
||||
setVisible(true);
|
||||
}
|
||||
|
||||
public Title getTitleLabel() {
|
||||
return titleLabel;
|
||||
}
|
||||
|
||||
public ButtonPanel getButtonPanel() {
|
||||
return buttonPanel;
|
||||
}
|
||||
}
|
34
src/fr/monkhanny/dorfromantik/gui/Reward.java
Normal file
34
src/fr/monkhanny/dorfromantik/gui/Reward.java
Normal file
@@ -0,0 +1,34 @@
|
||||
package fr.monkhanny.dorfromantik.gui;
|
||||
|
||||
import javax.swing.*;
|
||||
|
||||
// Classe pour représenter une récompense
|
||||
public class Reward {
|
||||
private String name;
|
||||
private String description;
|
||||
private boolean isUnlocked;
|
||||
private ImageIcon icon;
|
||||
|
||||
public Reward(String name, String description, boolean isUnlocked, ImageIcon icon) {
|
||||
this.name = name;
|
||||
this.description = description;
|
||||
this.isUnlocked = isUnlocked;
|
||||
this.icon = icon;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public String getDescription() {
|
||||
return description;
|
||||
}
|
||||
|
||||
public boolean isUnlocked() {
|
||||
return isUnlocked;
|
||||
}
|
||||
|
||||
public ImageIcon getIcon() {
|
||||
return icon;
|
||||
}
|
||||
}
|
217
src/fr/monkhanny/dorfromantik/gui/RewardsPanel.java
Normal file
217
src/fr/monkhanny/dorfromantik/gui/RewardsPanel.java
Normal file
@@ -0,0 +1,217 @@
|
||||
package fr.monkhanny.dorfromantik.gui;
|
||||
|
||||
import fr.monkhanny.dorfromantik.controller.RewardsPanelController;
|
||||
import fr.monkhanny.dorfromantik.components.Title;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
import java.util.List;
|
||||
|
||||
public class RewardsPanel extends JPanel {
|
||||
|
||||
private JTextField usernameField;
|
||||
private JPanel rewardsDisplayPanel;
|
||||
private JScrollPane scrollPane;
|
||||
private JFrame mainMenuFrame;
|
||||
private JFrame rewardsFrame;
|
||||
private RewardsPanelController controller;
|
||||
|
||||
public RewardsPanel(JFrame mainMenuFrame, JFrame rewardsFrame) {
|
||||
this.mainMenuFrame = mainMenuFrame;
|
||||
this.rewardsFrame = rewardsFrame;
|
||||
this.controller = new RewardsPanelController(this);
|
||||
|
||||
setLayout(new BorderLayout());
|
||||
|
||||
// Ajouter le fond d'écran
|
||||
JLabel background = new JLabel(new ImageIcon("./ressources/images/MainMenu/backgroundBlured.jpg"));
|
||||
background.setLayout(new BorderLayout());
|
||||
this.setLayout(new BorderLayout());
|
||||
this.add(background);
|
||||
|
||||
// Créer un panneau pour le bouton de retour en haut
|
||||
JPanel topPanel = new JPanel(new BorderLayout());
|
||||
topPanel.setOpaque(false);
|
||||
background.add(topPanel, BorderLayout.NORTH);
|
||||
|
||||
// Ajouter le bouton de retour en haut à gauche
|
||||
JPanel backButtonPanel = createBackButtonPanel();
|
||||
topPanel.add(backButtonPanel, BorderLayout.WEST);
|
||||
|
||||
// Titre du panneau
|
||||
JPanel titlePanel = createTitlePanel();
|
||||
topPanel.add(titlePanel, BorderLayout.CENTER);
|
||||
|
||||
// Panel principal
|
||||
JPanel mainPanel = createMainPanel();
|
||||
background.add(mainPanel, BorderLayout.CENTER);
|
||||
|
||||
// Panel d'entrée (nom d'utilisateur)
|
||||
JPanel inputPanel = createInputPanel();
|
||||
mainPanel.add(inputPanel, createGridBagConstraints(0, 0, 1));
|
||||
|
||||
// Panel pour afficher les récompenses
|
||||
rewardsDisplayPanel = new JPanel(new GridLayout(0, 3, 10, 10));
|
||||
this.scrollPane = new JScrollPane(rewardsDisplayPanel);
|
||||
mainPanel.add(this.scrollPane, createGridBagConstraints(0, 1, 1));
|
||||
|
||||
// Action du bouton pour afficher les récompenses
|
||||
JButton fetchButton = new JButton("Afficher les récompenses de l'utilisateur");
|
||||
fetchButton.setFont(new Font("Arial", Font.BOLD, 20));
|
||||
fetchButton.setBackground(new Color(0, 122, 255));
|
||||
fetchButton.setForeground(Color.WHITE);
|
||||
fetchButton.setBorder(BorderFactory.createLineBorder(Color.WHITE, 2));
|
||||
fetchButton.setPreferredSize(new Dimension(500, 50));
|
||||
|
||||
// Utilisation du controller pour gérer l'action du bouton
|
||||
fetchButton.addActionListener(controller.getFetchRewardsAction());
|
||||
|
||||
// Ajouter le bouton en bas
|
||||
JPanel buttonPanel = new JPanel();
|
||||
buttonPanel.setOpaque(false);
|
||||
buttonPanel.add(fetchButton);
|
||||
mainPanel.add(buttonPanel, createGridBagConstraints(0, 2, 1));
|
||||
}
|
||||
|
||||
private JPanel createBackButtonPanel() {
|
||||
JPanel backButtonPanel = new JPanel(new FlowLayout(FlowLayout.LEFT, 0, 0));
|
||||
backButtonPanel.setOpaque(false);
|
||||
|
||||
ImageIcon icon = new ImageIcon("./ressources/images/Icone/ExitIcon.png");
|
||||
Image scaledImage = icon.getImage().getScaledInstance(50, 50, Image.SCALE_SMOOTH);
|
||||
ImageIcon scaledIcon = new ImageIcon(scaledImage);
|
||||
|
||||
JButton backButton = new JButton(scaledIcon);
|
||||
backButton.setContentAreaFilled(false);
|
||||
backButton.setBorderPainted(false);
|
||||
backButton.setFocusPainted(false);
|
||||
backButton.setPreferredSize(new Dimension(50, 50));
|
||||
|
||||
// Utilisation du controller pour gérer l'action du bouton retour
|
||||
backButton.addActionListener(controller.getBackButtonAction());
|
||||
|
||||
backButtonPanel.add(backButton);
|
||||
return backButtonPanel;
|
||||
}
|
||||
|
||||
private JPanel createTitlePanel() {
|
||||
JPanel titlePanel = new JPanel(new BorderLayout());
|
||||
titlePanel.setOpaque(false);
|
||||
|
||||
Title title = new Title("Récompenses", 70, Color.WHITE);
|
||||
title.setHorizontalAlignment(JLabel.CENTER);
|
||||
titlePanel.add(title, BorderLayout.CENTER);
|
||||
|
||||
return titlePanel;
|
||||
}
|
||||
|
||||
private JPanel createMainPanel() {
|
||||
JPanel mainPanel = new JPanel(new GridBagLayout());
|
||||
mainPanel.setOpaque(false);
|
||||
return mainPanel;
|
||||
}
|
||||
|
||||
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 createInputPanel() {
|
||||
JPanel inputPanel = new JPanel();
|
||||
inputPanel.setOpaque(false);
|
||||
inputPanel.setLayout(new FlowLayout(FlowLayout.CENTER, 10, 10));
|
||||
|
||||
JLabel usernameLabel = new JLabel("Entrer le nom d'utilisateur :");
|
||||
usernameLabel.setForeground(Color.WHITE);
|
||||
usernameLabel.setFont(new Font("Arial", Font.BOLD, 20));
|
||||
inputPanel.add(usernameLabel);
|
||||
|
||||
usernameField = new JTextField(20);
|
||||
usernameField.setFont(new Font("Arial", Font.PLAIN, 18));
|
||||
usernameField.setPreferredSize(new Dimension(250, 40));
|
||||
usernameField.setBorder(BorderFactory.createLineBorder(Color.WHITE, 2));
|
||||
inputPanel.add(usernameField);
|
||||
|
||||
return inputPanel;
|
||||
}
|
||||
|
||||
public String getUsername() {
|
||||
return usernameField.getText().trim();
|
||||
}
|
||||
|
||||
public JFrame getMainMenuFrame() {
|
||||
return mainMenuFrame;
|
||||
}
|
||||
|
||||
public JFrame getRewardsFrame() {
|
||||
return rewardsFrame;
|
||||
}
|
||||
|
||||
public void updateRewardsPanel(List<Reward> rewards) {
|
||||
rewardsDisplayPanel.removeAll();
|
||||
|
||||
if (rewards.isEmpty()) {
|
||||
JLabel noRewardsLabel = new JLabel("Aucune récompense trouvée...", JLabel.CENTER);
|
||||
noRewardsLabel.setFont(new Font("Arial", Font.BOLD, 18));
|
||||
noRewardsLabel.setForeground(Color.RED);
|
||||
rewardsDisplayPanel.add(noRewardsLabel);
|
||||
} else {
|
||||
this.scrollPane.setPreferredSize(new Dimension(600, 300));
|
||||
this.scrollPane.setMinimumSize(new Dimension(600, 300));
|
||||
|
||||
rewardsDisplayPanel.setLayout(new GridLayout(0, 3, 10, 10));
|
||||
|
||||
for (Reward reward : rewards) {
|
||||
JPanel rewardPanel = createRewardPanel(reward);
|
||||
rewardsDisplayPanel.add(rewardPanel);
|
||||
}
|
||||
}
|
||||
|
||||
rewardsDisplayPanel.revalidate();
|
||||
rewardsDisplayPanel.repaint();
|
||||
this.revalidate();
|
||||
this.repaint();
|
||||
}
|
||||
|
||||
private JPanel createRewardPanel(Reward reward) {
|
||||
JPanel panel = new JPanel(new BorderLayout());
|
||||
panel.setPreferredSize(new Dimension(180, 220));
|
||||
|
||||
Color backgroundColor = reward.isUnlocked() ? new Color(230, 255, 230) : new Color(255, 245, 235);
|
||||
panel.setBackground(backgroundColor);
|
||||
|
||||
panel.setBorder(BorderFactory.createCompoundBorder(
|
||||
BorderFactory.createLineBorder(new Color(150, 200, 150), 1),
|
||||
BorderFactory.createEmptyBorder(10, 10, 10, 10)
|
||||
));
|
||||
|
||||
JLabel iconLabel = new JLabel();
|
||||
if (reward.getIcon() != null) {
|
||||
iconLabel.setIcon(reward.getIcon());
|
||||
} else {
|
||||
iconLabel.setText("No Icon");
|
||||
}
|
||||
iconLabel.setHorizontalAlignment(JLabel.CENTER);
|
||||
panel.add(iconLabel, BorderLayout.CENTER);
|
||||
|
||||
JLabel nameLabel = new JLabel(reward.getName());
|
||||
nameLabel.setHorizontalAlignment(JLabel.CENTER);
|
||||
nameLabel.setFont(new Font("Segoe UI", Font.BOLD, 16));
|
||||
nameLabel.setForeground(new Color(80, 120, 80));
|
||||
nameLabel.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
|
||||
panel.add(nameLabel, BorderLayout.NORTH);
|
||||
|
||||
JLabel descriptionLabel = new JLabel("<html><body style='text-align: center;'>" + reward.getDescription() + "</body></html>");
|
||||
descriptionLabel.setHorizontalAlignment(JLabel.CENTER);
|
||||
descriptionLabel.setFont(new Font("Segoe UI", Font.PLAIN, 12));
|
||||
descriptionLabel.setForeground(new Color(90, 90, 90));
|
||||
panel.add(descriptionLabel, BorderLayout.SOUTH);
|
||||
|
||||
return panel;
|
||||
}
|
||||
}
|
234
src/fr/monkhanny/dorfromantik/gui/SettingsPanel.java
Normal file
234
src/fr/monkhanny/dorfromantik/gui/SettingsPanel.java
Normal file
@@ -0,0 +1,234 @@
|
||||
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.enums.Images;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
import javax.swing.event.ChangeListener;
|
||||
|
||||
public class SettingsPanel extends JPanel {
|
||||
|
||||
private MainMenu mainMenu;
|
||||
private JFrame settingsFrame;
|
||||
|
||||
public SettingsPanel(MainMenu mainMenu, JFrame settingsFrame) {
|
||||
this.mainMenu = mainMenu;
|
||||
this.settingsFrame = settingsFrame;
|
||||
|
||||
setLayout(new BorderLayout());
|
||||
initializeSettingsFrame();
|
||||
setupBackground();
|
||||
setupTopPanel(); // Nouveau panneau pour le titre et le bouton de retour
|
||||
setupMainPanel(); // Configuration du panneau principal pour les sliders et boutons
|
||||
}
|
||||
|
||||
private void initializeSettingsFrame() {
|
||||
settingsFrame.setMinimumSize(Options.MINIMUM_FRAME_SIZE);
|
||||
}
|
||||
|
||||
private void setupBackground() {
|
||||
JLabel background = new JLabel(new ImageIcon("./ressources/images/MainMenu/backgroundBlured.jpg"));
|
||||
background.setLayout(new GridBagLayout());
|
||||
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 = new JPanel(new GridBagLayout());
|
||||
mainPanel.setOpaque(false);
|
||||
|
||||
// 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));
|
||||
|
||||
// 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();
|
||||
panel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS)); // Utilisation de BoxLayout pour une disposition verticale
|
||||
panel.setOpaque(false);
|
||||
|
||||
// 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);
|
||||
|
||||
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);
|
||||
|
||||
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);
|
||||
|
||||
JLabel lowLabel = new JLabel("Faible");
|
||||
lowLabel.setFont(new Font("Roboto", Font.PLAIN, 18));
|
||||
sliderPanel.add(lowLabel, BorderLayout.WEST);
|
||||
|
||||
sliderPanel.add(volumeSlider, BorderLayout.CENTER);
|
||||
|
||||
JLabel highLabel = new JLabel("Élevé");
|
||||
highLabel.setFont(new Font("Roboto", Font.PLAIN, 18));
|
||||
sliderPanel.add(highLabel, BorderLayout.EAST);
|
||||
|
||||
return sliderPanel;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
25
src/fr/monkhanny/dorfromantik/gui/Step.java
Normal file
25
src/fr/monkhanny/dorfromantik/gui/Step.java
Normal 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;
|
||||
}
|
||||
}
|
180
src/fr/monkhanny/dorfromantik/gui/TutorialPanel.java
Normal file
180
src/fr/monkhanny/dorfromantik/gui/TutorialPanel.java
Normal file
@@ -0,0 +1,180 @@
|
||||
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;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user