Jour de congé ! : Modification de la SAé

This commit is contained in:
2024-11-27 14:41:48 +01:00
parent 29d3dd946d
commit ac87b891ed
6 changed files with 133 additions and 39 deletions

View File

@@ -95,7 +95,7 @@ public class Main {
// Fenêtre des récompenses
CloseWindowListener rewardsWindowListener = new CloseWindowListener(Options.mainMenu, rewardsFrame);
rewardsFrame.addWindowListener(rewardsWindowListener);
RewardsPanel rewardsPanel = new RewardsPanel();
RewardsPanel rewardsPanel = new RewardsPanel(Options.mainMenu,rewardsFrame);
rewardsFrame.setContentPane(rewardsPanel);
rewardsFrame.pack();

View File

@@ -34,7 +34,7 @@ public class Options {
/**
* 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;

View File

@@ -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);
}
};
}
}

View File

@@ -240,7 +240,7 @@ public class Board extends JPanel{
// Vérifie si deux tuiles sont connectées par un même biome
private boolean areTilesConnected(Tile tile1, Tile tile2) {
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)
// Exemple : si elles partagent un côté commun
return tile1.isAdjacentTo(tile2);

View File

@@ -72,10 +72,20 @@ public class GameOver extends JPanel {
int playerGroup = 0;
// Check if there are less than 20 players
String funnyQuote;
String funnyQuote = "";
if (totalPlayers < 20) {
// 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
JLabel quoteLabel = new JLabel(funnyQuote);
quoteLabel.setFont(Fonts.SCORE.getFont(24));

View File

@@ -1,6 +1,6 @@
package fr.monkhanny.dorfromantik.gui;
import fr.monkhanny.dorfromantik.utils.Database;
import fr.monkhanny.dorfromantik.controller.RewardsPanelController;
import fr.monkhanny.dorfromantik.components.Title;
import javax.swing.*;
@@ -12,23 +12,39 @@ 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);
public RewardsPanel() {
setLayout(new BorderLayout());
// Ajouter le fond d'écran
JLabel background = new JLabel(new ImageIcon("./ressources/images/MainMenu/backgroundBlured.jpg"));
background.setLayout(new GridBagLayout());
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();
background.add(titlePanel, createGridBagConstraints(0, 0, 1));
topPanel.add(titlePanel, BorderLayout.CENTER);
// Panel principal
JPanel mainPanel = createMainPanel();
background.add(mainPanel, createGridBagConstraints(0, 1, 1));
background.add(mainPanel, BorderLayout.CENTER);
// Panel d'entrée (nom d'utilisateur)
JPanel inputPanel = createInputPanel();
@@ -36,7 +52,7 @@ public class RewardsPanel extends JPanel {
// Panel pour afficher les récompenses
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));
// Action du bouton pour afficher les récompenses
@@ -46,22 +62,9 @@ public class RewardsPanel extends JPanel {
fetchButton.setForeground(Color.WHITE);
fetchButton.setBorder(BorderFactory.createLineBorder(Color.WHITE, 2));
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
updateRewardsPanel(rewards);
} catch (Exception ex) {
JOptionPane.showMessageDialog(this, "Error fetching rewards: " + ex.getMessage());
}
}
});
// Utilisation du controller pour gérer l'action du bouton
fetchButton.addActionListener(controller.getFetchRewardsAction());
// Ajouter le bouton en bas
JPanel buttonPanel = new JPanel();
@@ -70,13 +73,33 @@ public class RewardsPanel extends JPanel {
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);
// Création du titre
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);
return titlePanel;
@@ -117,23 +140,32 @@ public class RewardsPanel extends JPanel {
return inputPanel;
}
private void updateRewardsPanel(List<Reward> rewards) {
rewardsDisplayPanel.removeAll(); // Clear previous contents
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()) {
// If no rewards, show a message
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)); // Ajustez la taille comme nécessaire
this.scrollPane.setPreferredSize(new Dimension(600, 300));
this.scrollPane.setMinimumSize(new Dimension(600, 300));
// Otherwise, display the rewards
rewardsDisplayPanel.setLayout(new GridLayout(0, 3, 10, 10));
// Add each reward to the panel
for (Reward reward : rewards) {
JPanel rewardPanel = createRewardPanel(reward);
rewardsDisplayPanel.add(rewardPanel);