test pour faire le plateau+nouveau menu dans testV1+ probleme compilation
This commit is contained in:
@@ -0,0 +1,43 @@
|
||||
package fr.monkhanny.dorfromantik.gui;
|
||||
|
||||
import fr.monkhanny.dorfromantik.Options;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
|
||||
public class ButtonHoverAnimationListener implements ActionListener {
|
||||
|
||||
private int step = 0;
|
||||
private final float scaleIncrement;
|
||||
private final boolean entering;
|
||||
private final JButton button;
|
||||
private final Color originalColor;
|
||||
private final Font originalFont;
|
||||
private float currentScale = 1.0f;
|
||||
|
||||
public ButtonHoverAnimationListener(boolean entering, JButton button, Color originalColor, Font originalFont) {
|
||||
this.entering = entering;
|
||||
this.button = button;
|
||||
this.originalColor = originalColor;
|
||||
this.originalFont = originalFont;
|
||||
this.scaleIncrement = (Options.HOVER_FONT_SCALE - 1.0f) / Options.ANIMATION_STEPS;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
currentScale = entering ? (1.0f + step * scaleIncrement) : (Options.HOVER_FONT_SCALE - step * scaleIncrement);
|
||||
|
||||
button.setForeground(entering ? Options.BUTTON_HOVER_COLOR : originalColor);
|
||||
button.setFont(originalFont.deriveFont(originalFont.getSize2D() * currentScale));
|
||||
|
||||
step++;
|
||||
if (step >= Options.ANIMATION_STEPS) {
|
||||
((Timer) e.getSource()).stop();
|
||||
if (!entering) {
|
||||
button.setFont(originalFont); // Restore the original font
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,29 @@
|
||||
package fr.monkhanny.dorfromantik.controller;
|
||||
|
||||
import fr.monkhanny.dorfromantik.gui.ButtonHoverAnimator;
|
||||
import fr.monkhanny.dorfromantik.utils.MusicPlayer;
|
||||
import fr.monkhanny.dorfromantik.enums.Sounds;
|
||||
|
||||
import java.awt.event.MouseAdapter;
|
||||
import java.awt.event.MouseEvent;
|
||||
|
||||
public class ButtonHoverListener extends MouseAdapter {
|
||||
|
||||
private final ButtonHoverAnimator animator;
|
||||
|
||||
public ButtonHoverListener(ButtonHoverAnimator animator) {
|
||||
this.animator = animator;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void mouseEntered(MouseEvent e) {
|
||||
animator.startAnimation(true);
|
||||
MusicPlayer.loadSound(Sounds.SOUNDS1); // Charge le son
|
||||
MusicPlayer.playSound(); // Joue le son
|
||||
}
|
||||
|
||||
@Override
|
||||
public void mouseExited(MouseEvent e) {
|
||||
animator.startAnimation(false);
|
||||
}
|
||||
}
|
@@ -0,0 +1,99 @@
|
||||
package fr.monkhanny.dorfromantik.controller;
|
||||
|
||||
import fr.monkhanny.dorfromantik.Options;
|
||||
import fr.monkhanny.dorfromantik.gui.SettingsPanel;
|
||||
import fr.monkhanny.dorfromantik.gui.MainMenu;
|
||||
import fr.monkhanny.dorfromantik.gui.ButtonPanel;
|
||||
import fr.monkhanny.dorfromantik.listeners.SettingsWindowListener;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
import java.awt.Dimension;
|
||||
import java.awt.Point;
|
||||
|
||||
public class MainMenuButtonController implements ActionListener {
|
||||
|
||||
private MainMenu mainMenu;
|
||||
|
||||
private JFrame settingsFrame;
|
||||
|
||||
public MainMenuButtonController(MainMenu mainMenu, JFrame settingsFrame) {
|
||||
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);
|
||||
|
||||
// Créer la fenêtre des paramètres
|
||||
this.settingsFrame = settingsFrame;
|
||||
this.settingsFrame.setLocationRelativeTo(null);
|
||||
this.settingsFrame.setVisible(false);
|
||||
}
|
||||
|
||||
@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 exitGame() {
|
||||
System.exit(0); // Fermer l'application
|
||||
}
|
||||
|
||||
private void openSettings() {
|
||||
// Récupérer la taille et la position de la fenêtre du menu principal
|
||||
Dimension mainMenuSize = this.mainMenu.getSize();
|
||||
Point mainMenuLocation = this.mainMenu.getLocation();
|
||||
|
||||
// Ajuster la fenêtre des paramètres pour qu'elle ait la même taille et position
|
||||
this.settingsFrame.setSize(mainMenuSize);
|
||||
this.settingsFrame.setLocation(mainMenuLocation);
|
||||
|
||||
// Cacher la fenêtre du menu principal
|
||||
this.mainMenu.setVisible(false);
|
||||
|
||||
// Afficher la fenêtre des paramètres
|
||||
this.settingsFrame.setVisible(true);
|
||||
}
|
||||
}
|
@@ -0,0 +1,31 @@
|
||||
package fr.monkhanny.dorfromantik.controller;
|
||||
|
||||
import fr.monkhanny.dorfromantik.gui.ButtonPanel;
|
||||
import fr.monkhanny.dorfromantik.gui.ButtonHoverAnimator;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.event.MouseAdapter;
|
||||
import java.awt.event.MouseEvent;
|
||||
|
||||
public class MainMenuMouseController {
|
||||
|
||||
private final ButtonPanel buttonPanel;
|
||||
|
||||
public MainMenuMouseController(ButtonPanel buttonPanel) {
|
||||
this.buttonPanel = buttonPanel;
|
||||
initMouseListeners();
|
||||
}
|
||||
|
||||
private void initMouseListeners() {
|
||||
addButtonHoverListener(buttonPanel.getNewGameButton());
|
||||
addButtonHoverListener(buttonPanel.getContinueGameButton());
|
||||
addButtonHoverListener(buttonPanel.getHowToPlayButton());
|
||||
addButtonHoverListener(buttonPanel.getSettingsButton());
|
||||
addButtonHoverListener(buttonPanel.getExitButton());
|
||||
}
|
||||
|
||||
private void addButtonHoverListener(JButton button) {
|
||||
ButtonHoverAnimator animator = new ButtonHoverAnimator(button);
|
||||
button.addMouseListener(new ButtonHoverListener(animator));
|
||||
}
|
||||
}
|
@@ -0,0 +1,19 @@
|
||||
package fr.monkhanny.dorfromantik.controller;
|
||||
|
||||
import fr.monkhanny.dorfromantik.gui.MainMenu;
|
||||
|
||||
public class MainMenuResizeController {
|
||||
|
||||
private MainMenu mainMenu;
|
||||
private MainMenuResizeHandler resizeHandler;
|
||||
|
||||
public MainMenuResizeController(MainMenu mainMenu) {
|
||||
this.mainMenu = mainMenu;
|
||||
this.resizeHandler = new MainMenuResizeHandler(mainMenu);
|
||||
addComponentListener();
|
||||
}
|
||||
|
||||
private void addComponentListener() {
|
||||
mainMenu.addComponentListener(resizeHandler);
|
||||
}
|
||||
}
|
@@ -0,0 +1,31 @@
|
||||
package fr.monkhanny.dorfromantik.controller;
|
||||
|
||||
import fr.monkhanny.dorfromantik.gui.MainMenu;
|
||||
import fr.monkhanny.dorfromantik.Options;
|
||||
import fr.monkhanny.dorfromantik.gui.ButtonHoverAnimator;
|
||||
|
||||
import java.awt.event.ComponentAdapter;
|
||||
import java.awt.event.ComponentEvent;
|
||||
import javax.swing.JButton;
|
||||
|
||||
public class MainMenuResizeHandler extends ComponentAdapter {
|
||||
|
||||
private MainMenu mainMenu;
|
||||
|
||||
public MainMenuResizeHandler(MainMenu mainMenu) {
|
||||
this.mainMenu = mainMenu;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void componentResized(ComponentEvent e) {
|
||||
int mainMenuWidth = mainMenu.getWidth();
|
||||
|
||||
// Ajuster la taille de la police du titre en fonction de la taille de la fenêtre
|
||||
float newFontSize = Options.BASE_TITLE_FONT_SIZE * (mainMenuWidth / 900f);
|
||||
mainMenu.getTitleLabel().updateTitleFont(newFontSize);
|
||||
|
||||
// Mettre à jour les polices des boutons
|
||||
mainMenu.getButtonPanel().updateButtonFonts(mainMenuWidth);
|
||||
ButtonHoverAnimator.updateOriginalFont(mainMenuWidth / 30f); // On passe la nouvelle taille de police pour chaque bouton
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user