Ajouts de music de fond + modification des boutons (quand on survole le bouton, sa taille grandis progressivement et la couleur change
This commit is contained in:
@@ -0,0 +1,75 @@
|
||||
package fr.monkhanny.dorfromantik.controller;
|
||||
|
||||
import fr.monkhanny.dorfromantik.gui.MainMenu;
|
||||
import fr.monkhanny.dorfromantik.gui.ButtonPanel;
|
||||
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
|
||||
public class MainMenuButtonController implements ActionListener {
|
||||
|
||||
private MainMenu mainMenu;
|
||||
|
||||
public MainMenuButtonController(MainMenu mainMenu) {
|
||||
this.mainMenu = mainMenu;
|
||||
// Ajouter les écouteurs d'événements sur les boutons
|
||||
ButtonPanel buttonPanel = mainMenu.getButtonPanel();
|
||||
|
||||
// Attacher les actions aux boutons
|
||||
buttonPanel.getNewGameButton().addActionListener(this);
|
||||
buttonPanel.getContinueGameButton().addActionListener(this);
|
||||
buttonPanel.getHowToPlayButton().addActionListener(this);
|
||||
buttonPanel.getSettingsButton().addActionListener(this);
|
||||
buttonPanel.getExitButton().addActionListener(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
String command = e.getActionCommand();
|
||||
|
||||
switch (command) {
|
||||
case "Nouvelle partie":
|
||||
startNewGame();
|
||||
break;
|
||||
case "Continuer une partie":
|
||||
continueGame();
|
||||
break;
|
||||
case "Comment jouer ?":
|
||||
showHowToPlay();
|
||||
break;
|
||||
case "Paramètres":
|
||||
openSettings();
|
||||
break;
|
||||
case "Quitter":
|
||||
exitGame();
|
||||
break;
|
||||
default:
|
||||
System.out.println("Commande inconnue: " + command);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
private void startNewGame() {
|
||||
System.out.println("Démarrer une nouvelle partie...");
|
||||
// Logic to start a new game
|
||||
}
|
||||
|
||||
private void continueGame() {
|
||||
System.out.println("Continuer une partie...");
|
||||
// Logic to continue the game
|
||||
}
|
||||
|
||||
private void showHowToPlay() {
|
||||
System.out.println("Afficher comment jouer...");
|
||||
// Logic to show how to play
|
||||
}
|
||||
|
||||
private void openSettings() {
|
||||
System.out.println("Ouvrir les paramètres...");
|
||||
// Logic to open settings
|
||||
}
|
||||
|
||||
private void exitGame() {
|
||||
System.exit(0); // Fermer l'application
|
||||
}
|
||||
}
|
@@ -0,0 +1,94 @@
|
||||
package fr.monkhanny.dorfromantik.controller;
|
||||
|
||||
import fr.monkhanny.dorfromantik.gui.ButtonPanel;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
import java.awt.event.MouseAdapter;
|
||||
import java.awt.event.MouseEvent;
|
||||
|
||||
public class MainMenuMouseController {
|
||||
|
||||
private final ButtonPanel buttonPanel;
|
||||
|
||||
// Couleur et échelle au survol
|
||||
private static final Color BUTTON_HOVER_COLOR = new Color(70, 130, 180);
|
||||
private static final float HOVER_FONT_SCALE = 1.1f;
|
||||
private static final int ANIMATION_STEPS = 10;
|
||||
private static final int ANIMATION_DELAY = 15; // Délai entre chaque étape en ms
|
||||
|
||||
public MainMenuMouseController(ButtonPanel buttonPanel) {
|
||||
this.buttonPanel = buttonPanel;
|
||||
initMouseListeners();
|
||||
}
|
||||
|
||||
private void initMouseListeners() {
|
||||
buttonPanel.getNewGameButton().addMouseListener(new ButtonHoverListener(buttonPanel.getNewGameButton()));
|
||||
buttonPanel.getContinueGameButton().addMouseListener(new ButtonHoverListener(buttonPanel.getContinueGameButton()));
|
||||
buttonPanel.getHowToPlayButton().addMouseListener(new ButtonHoverListener(buttonPanel.getHowToPlayButton()));
|
||||
buttonPanel.getSettingsButton().addMouseListener(new ButtonHoverListener(buttonPanel.getSettingsButton()));
|
||||
buttonPanel.getExitButton().addMouseListener(new ButtonHoverListener(buttonPanel.getExitButton()));
|
||||
}
|
||||
|
||||
// Classe interne pour la gestion des événements de survol de la souris avec animation
|
||||
private static class ButtonHoverListener extends MouseAdapter {
|
||||
private final JButton button;
|
||||
private final Color originalColor;
|
||||
private final Font originalFont;
|
||||
private Timer animationTimer;
|
||||
private boolean isHovered = false;
|
||||
private float currentScale = 1.0f;
|
||||
|
||||
public ButtonHoverListener(JButton button) {
|
||||
this.button = button;
|
||||
this.originalColor = button.getForeground();
|
||||
this.originalFont = button.getFont();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void mouseEntered(MouseEvent e) {
|
||||
isHovered = true;
|
||||
startAnimation(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void mouseExited(MouseEvent e) {
|
||||
isHovered = false;
|
||||
startAnimation(false);
|
||||
}
|
||||
|
||||
private void startAnimation(boolean entering) {
|
||||
if (animationTimer != null && animationTimer.isRunning()) {
|
||||
animationTimer.stop();
|
||||
}
|
||||
|
||||
animationTimer = new Timer(ANIMATION_DELAY, new ActionListener() {
|
||||
int step = 0;
|
||||
final float scaleIncrement = (HOVER_FONT_SCALE - 1.0f) / ANIMATION_STEPS;
|
||||
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
// Calculer la nouvelle échelle du texte
|
||||
currentScale = entering ? (1.0f + step * scaleIncrement) : (HOVER_FONT_SCALE - step * scaleIncrement);
|
||||
|
||||
// Mettre à jour la couleur et la police
|
||||
button.setForeground(entering ? BUTTON_HOVER_COLOR : originalColor);
|
||||
button.setFont(originalFont.deriveFont(originalFont.getSize2D() * currentScale));
|
||||
|
||||
// Augmenter le compteur d'étapes
|
||||
step++;
|
||||
if (step >= ANIMATION_STEPS) {
|
||||
animationTimer.stop();
|
||||
if (!entering) {
|
||||
// Restaurer la police d'origine après l'animation de sortie
|
||||
button.setFont(originalFont);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
animationTimer.start();
|
||||
}
|
||||
}
|
||||
}
|
@@ -6,11 +6,11 @@ import fr.monkhanny.dorfromantik.Options;
|
||||
import java.awt.event.ComponentAdapter;
|
||||
import java.awt.event.ComponentEvent;
|
||||
|
||||
public class MainMenuController {
|
||||
public class MainMenuResizeController {
|
||||
|
||||
private MainMenu mainMenu;
|
||||
|
||||
public MainMenuController(MainMenu mainMenu) {
|
||||
public MainMenuResizeController(MainMenu mainMenu) {
|
||||
this.mainMenu = mainMenu;
|
||||
addComponentListener();
|
||||
}
|
Reference in New Issue
Block a user