Jour de congé ! : Modification de la SAé
This commit is contained in:
@@ -95,7 +95,7 @@ public class Main {
|
|||||||
// Fenêtre des récompenses
|
// Fenêtre des récompenses
|
||||||
CloseWindowListener rewardsWindowListener = new CloseWindowListener(Options.mainMenu, rewardsFrame);
|
CloseWindowListener rewardsWindowListener = new CloseWindowListener(Options.mainMenu, rewardsFrame);
|
||||||
rewardsFrame.addWindowListener(rewardsWindowListener);
|
rewardsFrame.addWindowListener(rewardsWindowListener);
|
||||||
RewardsPanel rewardsPanel = new RewardsPanel();
|
RewardsPanel rewardsPanel = new RewardsPanel(Options.mainMenu,rewardsFrame);
|
||||||
rewardsFrame.setContentPane(rewardsPanel);
|
rewardsFrame.setContentPane(rewardsPanel);
|
||||||
rewardsFrame.pack();
|
rewardsFrame.pack();
|
||||||
|
|
||||||
|
@@ -34,7 +34,7 @@ public class Options {
|
|||||||
/**
|
/**
|
||||||
* Couleur de subrillance des boutons
|
* Couleur de subrillance des boutons
|
||||||
*/
|
*/
|
||||||
public static final Color BUTTON_HOVER_COLOR = new Color(70, 130, 180);
|
public static final Color BUTTON_HOVER_COLOR = new Color(0, 130, 180);
|
||||||
|
|
||||||
|
|
||||||
public static final float HOVER_FONT_SCALE = 1.1f;
|
public static final float HOVER_FONT_SCALE = 1.1f;
|
||||||
|
@@ -0,0 +1,52 @@
|
|||||||
|
package fr.monkhanny.dorfromantik.controller;
|
||||||
|
|
||||||
|
import fr.monkhanny.dorfromantik.gui.RewardsPanel;
|
||||||
|
import fr.monkhanny.dorfromantik.gui.Reward;
|
||||||
|
import fr.monkhanny.dorfromantik.utils.Database;
|
||||||
|
|
||||||
|
import javax.swing.*;
|
||||||
|
import java.awt.event.ActionEvent;
|
||||||
|
import java.awt.event.ActionListener;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
|
||||||
|
public class RewardsPanelController {
|
||||||
|
|
||||||
|
private RewardsPanel rewardsPanel;
|
||||||
|
|
||||||
|
public RewardsPanelController(RewardsPanel rewardsPanel) {
|
||||||
|
this.rewardsPanel = rewardsPanel;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ActionListener getFetchRewardsAction() {
|
||||||
|
return new ActionListener() {
|
||||||
|
@Override
|
||||||
|
public void actionPerformed(ActionEvent e) {
|
||||||
|
String username = rewardsPanel.getUsername();
|
||||||
|
if (!username.isEmpty()) {
|
||||||
|
try {
|
||||||
|
// Récupérer les récompenses pour l'utilisateur
|
||||||
|
Database db = new Database();
|
||||||
|
List<Reward> rewards = db.getRewardsByUsername(username);
|
||||||
|
db.close();
|
||||||
|
|
||||||
|
// Mettre à jour le panneau
|
||||||
|
rewardsPanel.updateRewardsPanel(rewards);
|
||||||
|
} catch (Exception ex) {
|
||||||
|
JOptionPane.showMessageDialog(rewardsPanel, "Error fetching rewards: " + ex.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
public ActionListener getBackButtonAction() {
|
||||||
|
return new ActionListener() {
|
||||||
|
@Override
|
||||||
|
public void actionPerformed(ActionEvent e) {
|
||||||
|
rewardsPanel.getMainMenuFrame().setVisible(true);
|
||||||
|
rewardsPanel.getRewardsFrame().setVisible(false);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
@@ -240,7 +240,7 @@ public class Board extends JPanel{
|
|||||||
// Vérifie si deux tuiles sont connectées par un même biome
|
// Vérifie si deux tuiles sont connectées par un même biome
|
||||||
private boolean areTilesConnected(Tile tile1, Tile tile2) {
|
private boolean areTilesConnected(Tile tile1, Tile tile2) {
|
||||||
for (TileOrientation orientation : TileOrientation.values()) {
|
for (TileOrientation orientation : TileOrientation.values()) {
|
||||||
if (tile1.getBiome(orientation).equals(tile2.getBiome(orientation))) {
|
if (tile1.getBiome(orientation).equals(tile2.getBiome(orientation.oppositeOrientation()))) {
|
||||||
// Vérifier si les tuiles sont adjacentes (logique à adapter selon vos besoins)
|
// Vérifier si les tuiles sont adjacentes (logique à adapter selon vos besoins)
|
||||||
// Exemple : si elles partagent un côté commun
|
// Exemple : si elles partagent un côté commun
|
||||||
return tile1.isAdjacentTo(tile2);
|
return tile1.isAdjacentTo(tile2);
|
||||||
|
@@ -72,10 +72,20 @@ public class GameOver extends JPanel {
|
|||||||
int playerGroup = 0;
|
int playerGroup = 0;
|
||||||
|
|
||||||
// Check if there are less than 20 players
|
// Check if there are less than 20 players
|
||||||
String funnyQuote;
|
String funnyQuote = "";
|
||||||
if (totalPlayers < 20) {
|
if (totalPlayers < 20) {
|
||||||
// Only show the funny quote if there are less than 20 players
|
// Only show the funny quote if there are less than 20 players
|
||||||
funnyQuote = "Vous n'êtes que " + totalPlayers + " à avoir joué à cette partie personalisée...";
|
if(totalPlayers == 0){
|
||||||
|
funnyQuote = "Vous êtes le premier joueur à jouer à cette partie personalisée...";
|
||||||
|
}
|
||||||
|
|
||||||
|
if(totalPlayers == 1){
|
||||||
|
funnyQuote = "Vous êtes le deuxième joueur à jouer à cette partie personalisée...";
|
||||||
|
}
|
||||||
|
|
||||||
|
if(totalPlayers > 1){
|
||||||
|
funnyQuote = "À part vous, il y a " + totalPlayers + " joueurs qui à joué à cette partie personalisée...";
|
||||||
|
}
|
||||||
// Display the funny quote directly
|
// Display the funny quote directly
|
||||||
JLabel quoteLabel = new JLabel(funnyQuote);
|
JLabel quoteLabel = new JLabel(funnyQuote);
|
||||||
quoteLabel.setFont(Fonts.SCORE.getFont(24));
|
quoteLabel.setFont(Fonts.SCORE.getFont(24));
|
||||||
|
@@ -1,6 +1,6 @@
|
|||||||
package fr.monkhanny.dorfromantik.gui;
|
package fr.monkhanny.dorfromantik.gui;
|
||||||
|
|
||||||
import fr.monkhanny.dorfromantik.utils.Database;
|
import fr.monkhanny.dorfromantik.controller.RewardsPanelController;
|
||||||
import fr.monkhanny.dorfromantik.components.Title;
|
import fr.monkhanny.dorfromantik.components.Title;
|
||||||
|
|
||||||
import javax.swing.*;
|
import javax.swing.*;
|
||||||
@@ -12,23 +12,39 @@ public class RewardsPanel extends JPanel {
|
|||||||
private JTextField usernameField;
|
private JTextField usernameField;
|
||||||
private JPanel rewardsDisplayPanel;
|
private JPanel rewardsDisplayPanel;
|
||||||
private JScrollPane scrollPane;
|
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);
|
||||||
|
|
||||||
public RewardsPanel() {
|
|
||||||
setLayout(new BorderLayout());
|
setLayout(new BorderLayout());
|
||||||
|
|
||||||
// Ajouter le fond d'écran
|
// Ajouter le fond d'écran
|
||||||
JLabel background = new JLabel(new ImageIcon("./ressources/images/MainMenu/backgroundBlured.jpg"));
|
JLabel background = new JLabel(new ImageIcon("./ressources/images/MainMenu/backgroundBlured.jpg"));
|
||||||
background.setLayout(new GridBagLayout());
|
background.setLayout(new BorderLayout());
|
||||||
this.setLayout(new BorderLayout());
|
this.setLayout(new BorderLayout());
|
||||||
this.add(background);
|
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
|
// Titre du panneau
|
||||||
JPanel titlePanel = createTitlePanel();
|
JPanel titlePanel = createTitlePanel();
|
||||||
background.add(titlePanel, createGridBagConstraints(0, 0, 1));
|
topPanel.add(titlePanel, BorderLayout.CENTER);
|
||||||
|
|
||||||
// Panel principal
|
// Panel principal
|
||||||
JPanel mainPanel = createMainPanel();
|
JPanel mainPanel = createMainPanel();
|
||||||
background.add(mainPanel, createGridBagConstraints(0, 1, 1));
|
background.add(mainPanel, BorderLayout.CENTER);
|
||||||
|
|
||||||
// Panel d'entrée (nom d'utilisateur)
|
// Panel d'entrée (nom d'utilisateur)
|
||||||
JPanel inputPanel = createInputPanel();
|
JPanel inputPanel = createInputPanel();
|
||||||
@@ -36,7 +52,7 @@ public class RewardsPanel extends JPanel {
|
|||||||
|
|
||||||
// Panel pour afficher les récompenses
|
// Panel pour afficher les récompenses
|
||||||
rewardsDisplayPanel = new JPanel(new GridLayout(0, 3, 10, 10));
|
rewardsDisplayPanel = new JPanel(new GridLayout(0, 3, 10, 10));
|
||||||
this.scrollPane = new JScrollPane(rewardsDisplayPanel); // Taille minimale pour éviter la réduction
|
this.scrollPane = new JScrollPane(rewardsDisplayPanel);
|
||||||
mainPanel.add(this.scrollPane, createGridBagConstraints(0, 1, 1));
|
mainPanel.add(this.scrollPane, createGridBagConstraints(0, 1, 1));
|
||||||
|
|
||||||
// Action du bouton pour afficher les récompenses
|
// Action du bouton pour afficher les récompenses
|
||||||
@@ -46,22 +62,9 @@ public class RewardsPanel extends JPanel {
|
|||||||
fetchButton.setForeground(Color.WHITE);
|
fetchButton.setForeground(Color.WHITE);
|
||||||
fetchButton.setBorder(BorderFactory.createLineBorder(Color.WHITE, 2));
|
fetchButton.setBorder(BorderFactory.createLineBorder(Color.WHITE, 2));
|
||||||
fetchButton.setPreferredSize(new Dimension(500, 50));
|
fetchButton.setPreferredSize(new Dimension(500, 50));
|
||||||
fetchButton.addActionListener(e -> {
|
|
||||||
String username = usernameField.getText().trim();
|
|
||||||
if (!username.isEmpty()) {
|
|
||||||
try {
|
|
||||||
// Récupérer les récompenses pour l'utilisateur
|
|
||||||
Database db = new Database();
|
|
||||||
List<Reward> rewards = db.getRewardsByUsername(username);
|
|
||||||
db.close();
|
|
||||||
|
|
||||||
// Mettre à jour le panneau
|
// Utilisation du controller pour gérer l'action du bouton
|
||||||
updateRewardsPanel(rewards);
|
fetchButton.addActionListener(controller.getFetchRewardsAction());
|
||||||
} catch (Exception ex) {
|
|
||||||
JOptionPane.showMessageDialog(this, "Error fetching rewards: " + ex.getMessage());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
// Ajouter le bouton en bas
|
// Ajouter le bouton en bas
|
||||||
JPanel buttonPanel = new JPanel();
|
JPanel buttonPanel = new JPanel();
|
||||||
@@ -70,13 +73,33 @@ public class RewardsPanel extends JPanel {
|
|||||||
mainPanel.add(buttonPanel, createGridBagConstraints(0, 2, 1));
|
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() {
|
private JPanel createTitlePanel() {
|
||||||
JPanel titlePanel = new JPanel(new BorderLayout());
|
JPanel titlePanel = new JPanel(new BorderLayout());
|
||||||
titlePanel.setOpaque(false);
|
titlePanel.setOpaque(false);
|
||||||
|
|
||||||
// Création du titre
|
|
||||||
Title title = new Title("Récompenses", 70, Color.WHITE);
|
Title title = new Title("Récompenses", 70, Color.WHITE);
|
||||||
title.setHorizontalAlignment(JLabel.CENTER); // Centrer le titre
|
title.setHorizontalAlignment(JLabel.CENTER);
|
||||||
titlePanel.add(title, BorderLayout.CENTER);
|
titlePanel.add(title, BorderLayout.CENTER);
|
||||||
|
|
||||||
return titlePanel;
|
return titlePanel;
|
||||||
@@ -117,23 +140,32 @@ public class RewardsPanel extends JPanel {
|
|||||||
return inputPanel;
|
return inputPanel;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void updateRewardsPanel(List<Reward> rewards) {
|
public String getUsername() {
|
||||||
rewardsDisplayPanel.removeAll(); // Clear previous contents
|
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()) {
|
if (rewards.isEmpty()) {
|
||||||
// If no rewards, show a message
|
|
||||||
JLabel noRewardsLabel = new JLabel("Aucune récompense trouvée...", JLabel.CENTER);
|
JLabel noRewardsLabel = new JLabel("Aucune récompense trouvée...", JLabel.CENTER);
|
||||||
noRewardsLabel.setFont(new Font("Arial", Font.BOLD, 18));
|
noRewardsLabel.setFont(new Font("Arial", Font.BOLD, 18));
|
||||||
noRewardsLabel.setForeground(Color.RED);
|
noRewardsLabel.setForeground(Color.RED);
|
||||||
rewardsDisplayPanel.add(noRewardsLabel);
|
rewardsDisplayPanel.add(noRewardsLabel);
|
||||||
} else {
|
} else {
|
||||||
|
this.scrollPane.setPreferredSize(new Dimension(600, 300));
|
||||||
this.scrollPane.setPreferredSize(new Dimension(600, 300)); // Ajustez la taille comme nécessaire
|
|
||||||
this.scrollPane.setMinimumSize(new Dimension(600, 300));
|
this.scrollPane.setMinimumSize(new Dimension(600, 300));
|
||||||
// Otherwise, display the rewards
|
|
||||||
rewardsDisplayPanel.setLayout(new GridLayout(0, 3, 10, 10));
|
rewardsDisplayPanel.setLayout(new GridLayout(0, 3, 10, 10));
|
||||||
|
|
||||||
// Add each reward to the panel
|
|
||||||
for (Reward reward : rewards) {
|
for (Reward reward : rewards) {
|
||||||
JPanel rewardPanel = createRewardPanel(reward);
|
JPanel rewardPanel = createRewardPanel(reward);
|
||||||
rewardsDisplayPanel.add(rewardPanel);
|
rewardsDisplayPanel.add(rewardPanel);
|
||||||
|
Reference in New Issue
Block a user