Un peu de ménage dans le git
This commit is contained in:
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;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user