diff --git a/ressources/images/Settings/speaker-high-volume.png b/ressources/images/Settings/speaker-high-volume.png deleted file mode 100644 index 34f36e9..0000000 Binary files a/ressources/images/Settings/speaker-high-volume.png and /dev/null differ diff --git a/ressources/images/Settings/speaker-mute-volume.png b/ressources/images/Settings/speaker-mute-volume.png deleted file mode 100644 index 5ebcb07..0000000 Binary files a/ressources/images/Settings/speaker-mute-volume.png and /dev/null differ diff --git a/src/fr/monkhanny/dorfromantik/Main.java b/src/fr/monkhanny/dorfromantik/Main.java index d2a3a35..6fe8c50 100644 --- a/src/fr/monkhanny/dorfromantik/Main.java +++ b/src/fr/monkhanny/dorfromantik/Main.java @@ -11,6 +11,7 @@ import fr.monkhanny.dorfromantik.controller.TutorialController; import fr.monkhanny.dorfromantik.controller.GameModeController; import fr.monkhanny.dorfromantik.gui.GameModeSelectionPanel; +import javax.swing.ImageIcon; import javax.swing.JFrame; /** @@ -76,14 +77,21 @@ public class Main { isMusicPlayed = true; // Marquer la musique comme jouée } + // 4. Créer les fenêtres à nouveau comme au début + ImageIcon icon = new ImageIcon("./ressources/images/Application/Application_Icon.jpg"); + gameModeFrame = new JFrame("Choix des séries - Dorfromantik"); gameModeFrame.setMinimumSize(Options.MINIMUM_FRAME_SIZE); + gameModeFrame.setIconImage(icon.getImage()); gameFrame = new JFrame("Jeu - Dorfromantik"); + gameFrame.setIconImage(icon.getImage()); gameFrame.setMinimumSize(Options.MINIMUM_FRAME_SIZE); settingsFrame = new JFrame("Paramètres - Dorfromantik"); + settingsFrame.setIconImage(icon.getImage()); settingsFrame.setMinimumSize(Options.MINIMUM_FRAME_SIZE); howToPlayFrame = new JFrame("Comment jouer ? - Dorfromantik"); + howToPlayFrame.setIconImage(icon.getImage()); howToPlayFrame.setMinimumSize(Options.MINIMUM_FRAME_SIZE); // Re-créer et réinitialiser les panels et les contrôleurs diff --git a/src/fr/monkhanny/dorfromantik/gui/BarChartPanel.java b/src/fr/monkhanny/dorfromantik/gui/BarChartPanel.java index f44aa53..6128f8a 100644 --- a/src/fr/monkhanny/dorfromantik/gui/BarChartPanel.java +++ b/src/fr/monkhanny/dorfromantik/gui/BarChartPanel.java @@ -2,69 +2,131 @@ package fr.monkhanny.dorfromantik.gui; import java.awt.*; import java.util.List; +import java.util.Objects; import javax.swing.*; public class BarChartPanel extends JPanel { - private List groupAverages; - private int highlightedGroup; - - public BarChartPanel(List groupAverages, int highlightedGroup, JPanel mainPanel) { - this.groupAverages = groupAverages; + private final List groupAverages; + private final int highlightedGroup; + private static final Color PLAYER_GROUP_COLOR = new Color(204, 0, 0); + private static final Color OTHER_GROUP_COLOR = new Color(0, 0, 204); + private static final Color SHADOW_COLOR = new Color(0, 0, 0, 60); + private static final Color TEXT_COLOR = Color.BLACK; + private static final Font AVERAGE_FONT = new Font("Arial", Font.ITALIC, 12); + private static final Font GROUP_LABEL_FONT = new Font("Arial", Font.BOLD, 16); + private static final Font SCORE_FONT = new Font("Arial", Font.BOLD, 14); + private static final int PADDING = 30; + private static final int SHADOW_OFFSET = 2; + + public BarChartPanel(List groupAverages, int highlightedGroup) { + this.groupAverages = Objects.requireNonNull(groupAverages, "Group averages cannot be null"); this.highlightedGroup = highlightedGroup; - // Rendre le fond transparent et ajouter une bordure noire - setBackground(new Color(0, 0, 0, 0)); // Fond transparent - setAlignmentX(Component.CENTER_ALIGNMENT); // Centrer horizontalement + // Configuration du panneau + setOpaque(false); + setBackground(new Color(0, 0, 0, 0)); + setAlignmentX(Component.CENTER_ALIGNMENT); } - + @Override protected void paintComponent(Graphics g) { super.paintComponent(g); - int width = getWidth(); - int height = getHeight(); - int barWidth = width / (groupAverages.size() + 1); // Espacement entre les groupes - int maxScore = groupAverages.stream().max(Integer::compare).orElse(0); + + if (groupAverages.isEmpty()) { + return; + } - // Dessiner les barres et leurs étiquettes (moyennes des scores) - for (int i = 0; i < groupAverages.size(); i++) { - int barHeight = (int) ((double) groupAverages.get(i) / maxScore * (height - 50)); // Ajuster la hauteur des barres - int xPosition = (i + 1) * barWidth; // Espacement entre les groupes + Graphics2D g2d = (Graphics2D) g.create(); + try { + g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); - // Appliquer une couleur de barre (mettre en évidence le groupe du joueur en rouge, les autres en bleu) - if (i == highlightedGroup) { - g.setColor(new Color(204, 0, 0)); // Couleur rouge pour le groupe du joueur - } else { - g.setColor(new Color(0, 0, 204)); // Bleu pour les autres groupes + int width = getWidth(); + int height = getHeight(); + int barWidth = width / (groupAverages.size() + 1); + int maxScore = groupAverages.stream() + .mapToInt(Integer::intValue) + .max() + .orElse(0); + + for (int i = 0; i < groupAverages.size(); i++) { + int barHeight = calculateBarHeight(maxScore, height, groupAverages.get(i)); + int xPosition = (i + 1) * barWidth; + + Color barColor = (i == highlightedGroup) ? PLAYER_GROUP_COLOR : OTHER_GROUP_COLOR; + + g2d.setColor(SHADOW_COLOR); + g2d.fillRect(xPosition + SHADOW_OFFSET, height - barHeight - PADDING + SHADOW_OFFSET, barWidth - 5, barHeight); + + g2d.setColor(barColor); + g2d.fillRect(xPosition, height - barHeight - PADDING, barWidth - 5, barHeight); + + // Ajustez dynamiquement la position des textes + int textY = height - barHeight - PADDING - 20; // Score position + if (textY < PADDING) { + textY = PADDING - 2; // Éviter le chevauchement au sommet + } + + String avgScoreText = String.valueOf(groupAverages.get(i)); + g2d.setFont(SCORE_FONT); + g2d.setColor(TEXT_COLOR); + drawCenteredString(g2d, avgScoreText, xPosition, barWidth, textY); + + // Position de "Score moyen" + int labelY = textY - 15; // Placer légèrement au-dessus du score + if (labelY < PADDING) { + labelY = PADDING - 17; // Éviter les débordements + } + + g2d.setFont(AVERAGE_FONT); + drawCenteredString(g2d, "Score moyen : ", xPosition, barWidth, labelY); + + g2d.setFont(GROUP_LABEL_FONT); + String groupLabel = "Groupe " + (i + 1); + drawCenteredString(g2d, groupLabel, xPosition, barWidth, height - 10); + } + } finally { + g2d.dispose(); } + } - // Ajouter des ombres à la barre pour un effet 3D - g.fillRect(xPosition, height - barHeight - 30, barWidth - 5, barHeight); - g.setColor(new Color(0, 0, 0, 60)); // Ombre - g.fillRect(xPosition + 2, height - barHeight - 28, barWidth - 5, barHeight); - // Dessiner le texte (moyenne) au-dessus de chaque barre - String avgScoreText = String.valueOf(groupAverages.get(i)); - FontMetrics metrics = g.getFontMetrics(); - int textWidth = metrics.stringWidth(avgScoreText); - int textX = xPosition + (barWidth - textWidth) / 2; // Centrer le texte - int textY = height - barHeight - 35; // Placer le texte juste au-dessus de la barre + /** + * Calcule la hauteur d'une barre proportionnellement au score maximum. + * + * @param maxScore Le score maximum parmi tous les groupes + * @param height La hauteur totale du composant + * @param score Le score du groupe courant + * @return La hauteur de la barre + */ + private int calculateBarHeight(int maxScore, int height, int score) { + return (int) ((double) score / maxScore * (height - 2 * PADDING)); + } - g.setColor(Color.BLACK); // Couleur du texte - g.drawString(avgScoreText, textX, textY); - - // Ajouter un label pour préciser que c'est la "moyenne" - g.setFont(new Font("Arial", Font.ITALIC, 12)); // Police italique plus petite pour le label "Moyenne" - String label = "Score moyen : "; - int labelWidth = metrics.stringWidth(label); - g.drawString(label, xPosition + (barWidth - labelWidth) / 2, textY - 15); // Placer "Moyenne" au-dessus du score - - // Dessiner l'étiquette de groupe (Groupe 1, Groupe 2, ...) - String groupLabel = "Groupe " + (i + 1); - g.setColor(Color.BLACK); - g.setFont(new Font("Arial", Font.PLAIN, 14)); // Police plus petite pour les étiquettes - int groupLabelWidth = g.getFontMetrics().stringWidth(groupLabel); - g.drawString(groupLabel, xPosition + (barWidth - groupLabelWidth) / 2, height - 10); // Positionner l'étiquette sous la barre - } -} + /** + * Dessine une chaîne centrée horizontalement dans une section de la largeur du composant. + * + * @param g2d Le contexte graphique + * @param text Le texte à dessiner + * @param xOffset La position x de départ de la section + * @param sectionWidth La largeur de la section + * @param y La position y où dessiner le texte + */ + private void drawCenteredString(Graphics2D g2d, String text, int xOffset, int sectionWidth, int y) { + FontMetrics metrics = g2d.getFontMetrics(); + int textWidth = metrics.stringWidth(text); + int textX = xOffset + (sectionWidth - textWidth) / 2; + g2d.drawString(text, textX, y); + } + /** + * Retourne la taille préférée du panneau. + * + * @return La taille préférée + * @see Dimension + */ + @Override + public Dimension getPreferredSize() { + // Définir une taille préférée par défaut si non spécifiée + return new Dimension(400, 200); + } } \ No newline at end of file diff --git a/src/fr/monkhanny/dorfromantik/gui/GameOver.java b/src/fr/monkhanny/dorfromantik/gui/GameOver.java index 35942f8..d352543 100644 --- a/src/fr/monkhanny/dorfromantik/gui/GameOver.java +++ b/src/fr/monkhanny/dorfromantik/gui/GameOver.java @@ -120,7 +120,7 @@ public class GameOver extends JPanel { groupTitleLabel.setAlignmentX(Component.CENTER_ALIGNMENT); groupPanel.add(groupTitleLabel); - BarChartPanel barChartPanel = new BarChartPanel(groupAverages, playerGroup - 1, mainPanel); + BarChartPanel barChartPanel = new BarChartPanel(groupAverages, playerGroup - 1); barChartPanel.setPreferredSize(new Dimension(700, 400)); barChartPanel.setAlignmentX(Component.CENTER_ALIGNMENT); // Centrer horizontalement groupPanel.add(barChartPanel);