Ajouts d'une version BETA du menu principal qui respecte le modèle MVC et la responsabilité unique + Modifications du README.md
This commit is contained in:
59
TestV2/src/fr/monkhanny/dorfromantik/gui/ButtonPanel.java
Normal file
59
TestV2/src/fr/monkhanny/dorfromantik/gui/ButtonPanel.java
Normal file
@@ -0,0 +1,59 @@
|
||||
package fr.monkhanny.dorfromantik.gui;
|
||||
|
||||
import fr.monkhanny.dorfromantik.utils.FontManager;
|
||||
import fr.monkhanny.dorfromantik.components.Button;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
|
||||
public class ButtonPanel extends JPanel {
|
||||
|
||||
private JButton newGameButton;
|
||||
private JButton continueGameButton;
|
||||
private JButton howToPlayButton;
|
||||
|
||||
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.createStyledButton("Nouvelle partie", fontSize);
|
||||
continueGameButton = Button.createStyledButton("Continuer une partie", fontSize);
|
||||
howToPlayButton = Button.createStyledButton("Comment jouer ?", fontSize);
|
||||
|
||||
// Ajouter les boutons au panneau
|
||||
this.add(newGameButton);
|
||||
this.add(Box.createVerticalStrut(20)); // Espace entre les boutons
|
||||
this.add(continueGameButton);
|
||||
this.add(Box.createVerticalStrut(20));
|
||||
this.add(howToPlayButton);
|
||||
|
||||
// Espacement extensible pour maintenir les icônes en bas
|
||||
this.add(Box.createVerticalGlue());
|
||||
}
|
||||
|
||||
public JButton getNewGameButton() {
|
||||
return newGameButton;
|
||||
}
|
||||
|
||||
public JButton getContinueGameButton() {
|
||||
return continueGameButton;
|
||||
}
|
||||
|
||||
public JButton getHowToPlayButton() {
|
||||
return howToPlayButton;
|
||||
}
|
||||
|
||||
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));
|
||||
}
|
||||
}
|
55
TestV2/src/fr/monkhanny/dorfromantik/gui/MainMenu.java
Normal file
55
TestV2/src/fr/monkhanny/dorfromantik/gui/MainMenu.java
Normal file
@@ -0,0 +1,55 @@
|
||||
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.*;
|
||||
import java.awt.event.ComponentAdapter;
|
||||
import java.awt.event.ComponentEvent;
|
||||
|
||||
public class MainMenu extends JFrame {
|
||||
|
||||
private Title titleLabel;
|
||||
private ButtonPanel buttonPanel;
|
||||
|
||||
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.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é
|
||||
this.buttonPanel = new ButtonPanel(Options.BASE_BUTTON_FONT_SIZE);
|
||||
background.add(buttonPanel, BorderLayout.WEST);
|
||||
|
||||
setVisible(true);
|
||||
}
|
||||
|
||||
public Title getTitleLabel() {
|
||||
return titleLabel;
|
||||
}
|
||||
|
||||
public ButtonPanel getButtonPanel() {
|
||||
return buttonPanel;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user