ajout d'aide
BIN
ressources/images/Icone/Keyboard-Mouse/ctrl.png
Normal file
After Width: | Height: | Size: 8.1 KiB |
BIN
ressources/images/Icone/Keyboard-Mouse/esc.png
Normal file
After Width: | Height: | Size: 9.5 KiB |
BIN
ressources/images/Icone/Keyboard-Mouse/keyboard-arrows.png
Normal file
After Width: | Height: | Size: 10 KiB |
BIN
ressources/images/Icone/Keyboard-Mouse/mouse-left.png
Normal file
After Width: | Height: | Size: 10 KiB |
BIN
ressources/images/Icone/Keyboard-Mouse/mouse-middle.png
Normal file
After Width: | Height: | Size: 9.9 KiB |
BIN
ressources/images/Icone/Keyboard-Mouse/mouse-right.png
Normal file
After Width: | Height: | Size: 10 KiB |
BIN
ressources/images/Icone/Keyboard-Mouse/shift.png
Normal file
After Width: | Height: | Size: 9.5 KiB |
BIN
ressources/images/Icone/Keyboard-Mouse/space.png
Normal file
After Width: | Height: | Size: 10 KiB |
BIN
ressources/images/Icone/Keyboard-Mouse/t.png
Normal file
After Width: | Height: | Size: 6.5 KiB |
@@ -11,22 +11,11 @@ import fr.monkhanny.dorfromantik.enums.Fonts;
|
|||||||
import fr.monkhanny.dorfromantik.enums.TileOrientation;
|
import fr.monkhanny.dorfromantik.enums.TileOrientation;
|
||||||
import fr.monkhanny.dorfromantik.utils.Database;
|
import fr.monkhanny.dorfromantik.utils.Database;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Random;
|
import java.util.*;
|
||||||
import java.awt.Graphics;
|
import javax.swing.*;
|
||||||
import javax.swing.JPanel;
|
import java.awt.*;
|
||||||
import javax.swing.JFrame;
|
|
||||||
import java.awt.Point;
|
|
||||||
import java.awt.Color;
|
|
||||||
import java.awt.Graphics2D;
|
|
||||||
import java.awt.Font;
|
|
||||||
|
|
||||||
// TEMPORAIRE :
|
|
||||||
import java.awt.event.MouseMotionAdapter; // Import pour MouseMotionAdapter
|
|
||||||
import java.awt.AlphaComposite;
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -50,6 +39,7 @@ public class Board extends JPanel{
|
|||||||
private Database database;
|
private Database database;
|
||||||
private RemainingTilesIndicator remainingTilesIndicator;
|
private RemainingTilesIndicator remainingTilesIndicator;
|
||||||
private ScoreDisplay scoreDisplay;
|
private ScoreDisplay scoreDisplay;
|
||||||
|
private ControlsMenu controlsMenu;
|
||||||
|
|
||||||
|
|
||||||
// Constructeur avec seed
|
// Constructeur avec seed
|
||||||
@@ -80,24 +70,31 @@ public class Board extends JPanel{
|
|||||||
gameFrame.setFocusable(true);
|
gameFrame.setFocusable(true);
|
||||||
|
|
||||||
this.addMouseWheelListener(new GameMouseWheelListener(this));
|
this.addMouseWheelListener(new GameMouseWheelListener(this));
|
||||||
|
|
||||||
|
|
||||||
gameFrame.addKeyListener(new GameSpaceKeyListener(this));
|
gameFrame.addKeyListener(new GameSpaceKeyListener(this));
|
||||||
|
|
||||||
this.addMouseListener(new GameMouseClickListener(this));
|
this.addMouseListener(new GameMouseClickListener(this));
|
||||||
|
|
||||||
gameFrame.addKeyListener(new PauseGame(gameFrame, game));
|
gameFrame.addKeyListener(new PauseGame(gameFrame, game));
|
||||||
gameFrame.setFocusable(true);
|
gameFrame.setFocusable(true);
|
||||||
|
|
||||||
this.remainingTilesIndicator = new RemainingTilesIndicator(Options.MAX_TILE_NUMBER);
|
this.remainingTilesIndicator = new RemainingTilesIndicator(Options.MAX_TILE_NUMBER);
|
||||||
|
|
||||||
this.addMouseMotionListener(new MouseMotionAdapter() {
|
// Remplacer l'adaptateur anonyme par notre classe CustomMouseMotionAdapter
|
||||||
@Override
|
this.addMouseMotionListener(new CustomMouseMotionAdapter(this));
|
||||||
public void mouseMoved(java.awt.event.MouseEvent e) {
|
|
||||||
handleMouseMove(e);
|
// Ajouter le menu des contrôles
|
||||||
}
|
controlsMenu = new ControlsMenu();
|
||||||
});
|
setLayout(null); // Utiliser un layout absolu pour placer le menu
|
||||||
|
|
||||||
|
// Ajouter le menu au panneau principal
|
||||||
|
controlsMenu.setBounds(10, getHeight() + 350, 400, 400);
|
||||||
|
add(controlsMenu);
|
||||||
|
|
||||||
|
// Remplacer l'adaptateur anonyme par notre classe CustomKeyAdapter
|
||||||
|
gameFrame.addKeyListener(new CustomKeyAdapter(this));
|
||||||
|
}
|
||||||
|
|
||||||
|
public ControlsMenu getControlsMenu() {
|
||||||
|
return controlsMenu;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void handleMouseMove(java.awt.event.MouseEvent e) {
|
public void handleMouseMove(java.awt.event.MouseEvent e) {
|
||||||
@@ -116,6 +113,7 @@ public class Board extends JPanel{
|
|||||||
for (Point position : availablePositions) {
|
for (Point position : availablePositions) {
|
||||||
if (new Point(adjustedX, adjustedY).distance(position) < 20) {
|
if (new Point(adjustedX, adjustedY).distance(position) < 20) {
|
||||||
mousePosition = position;
|
mousePosition = position;
|
||||||
|
controlsMenu.setControlsMenuVisible(false);
|
||||||
repaint(); // Redessiner le plateau avec la tuile transparente
|
repaint(); // Redessiner le plateau avec la tuile transparente
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -123,10 +121,10 @@ public class Board extends JPanel{
|
|||||||
|
|
||||||
// Si la souris n'est pas proche d'une position valide, ne rien faire
|
// Si la souris n'est pas proche d'une position valide, ne rien faire
|
||||||
mousePosition = null;
|
mousePosition = null;
|
||||||
|
controlsMenu.setControlsMenuVisible(false);
|
||||||
repaint(); // Redessiner sans la tuile transparente
|
repaint(); // Redessiner sans la tuile transparente
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private void initializeNextTile() {
|
private void initializeNextTile() {
|
||||||
int offsetX = 50; // Décalage pour la position en haut à gauche
|
int offsetX = 50; // Décalage pour la position en haut à gauche
|
||||||
int offsetY = 50; // Décalage pour la position en haut à gauche
|
int offsetY = 50; // Décalage pour la position en haut à gauche
|
||||||
|
104
src/fr/monkhanny/dorfromantik/game/ControlsMenu.java
Normal file
@@ -0,0 +1,104 @@
|
|||||||
|
package fr.monkhanny.dorfromantik.game;
|
||||||
|
|
||||||
|
import javax.swing.*;
|
||||||
|
import java.awt.*;
|
||||||
|
import java.net.URL;
|
||||||
|
|
||||||
|
public class ControlsMenu extends JPanel {
|
||||||
|
private boolean isVisible = true;
|
||||||
|
|
||||||
|
// Chemin de base pour les icônes
|
||||||
|
private static final String ICON_PATH = "/ressources/images/Icone/Keyboard-Mouse/";
|
||||||
|
|
||||||
|
public ControlsMenu() {
|
||||||
|
setLayout(new BoxLayout(this, BoxLayout.Y_AXIS)); // Mise en page verticale
|
||||||
|
setBackground(new Color(0, 0, 0, 150)); // Fond semi-transparent
|
||||||
|
|
||||||
|
// Augmenter la taille du menu
|
||||||
|
setPreferredSize(new Dimension(350, 400)); // Taille du menu augmentée
|
||||||
|
|
||||||
|
// Ajouter des instructions avec des icônes pour chaque touche
|
||||||
|
add(createPanel("Cacher/Montrer ce menu", "t.png"));
|
||||||
|
add(createPanelWithMultipleIcons("Zoom avant/arrière", "ctrl.png", "mouse-middle.png"));
|
||||||
|
add(createPanel("Déplacer le plateau", "keyboard-arrows.png"));
|
||||||
|
add(createPanel("Ajuster la vue", "space.png"));
|
||||||
|
add(createPanel("Placer une tuile", "mouse-left.png"));
|
||||||
|
add(createPanel("Afficher le menu de pause", "esc.png"));
|
||||||
|
|
||||||
|
// Rendre le texte plus lisible
|
||||||
|
setForeground(Color.WHITE);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Crée un JPanel avec l'icône et le texte aligné horizontalement
|
||||||
|
private JPanel createPanel(String text, String iconName) {
|
||||||
|
JPanel panel = new JPanel();
|
||||||
|
panel.setLayout(new FlowLayout(FlowLayout.LEFT, 10, 5)); // Alignement à gauche
|
||||||
|
panel.setOpaque(false); // Transparent pour le fond
|
||||||
|
|
||||||
|
// Ajouter l'icône redimensionnée
|
||||||
|
JLabel iconLabel = new JLabel(loadIcon(iconName));
|
||||||
|
panel.add(iconLabel);
|
||||||
|
|
||||||
|
// Ajouter le texte avec une taille de police plus grande
|
||||||
|
JLabel textLabel = new JLabel(text);
|
||||||
|
textLabel.setForeground(Color.WHITE);
|
||||||
|
textLabel.setFont(new Font("Arial", Font.PLAIN, 18)); // Augmenter la taille de la police
|
||||||
|
panel.add(textLabel);
|
||||||
|
|
||||||
|
return panel;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Crée un JPanel avec plusieurs icônes et un texte, en ajoutant un "+" entre les icônes
|
||||||
|
private JPanel createPanelWithMultipleIcons(String text, String... iconNames) {
|
||||||
|
JPanel panel = new JPanel();
|
||||||
|
panel.setLayout(new FlowLayout(FlowLayout.LEFT, 10, 5)); // Alignement à gauche
|
||||||
|
panel.setOpaque(false); // Transparent pour le fond
|
||||||
|
|
||||||
|
// Ajouter les icônes et le signe "+" entre elles
|
||||||
|
for (int i = 0; i < iconNames.length; i++) {
|
||||||
|
JLabel iconLabel = new JLabel(loadIcon(iconNames[i]));
|
||||||
|
panel.add(iconLabel);
|
||||||
|
|
||||||
|
// Si ce n'est pas la dernière icône, ajouter un "+" entre les icônes
|
||||||
|
if (i < iconNames.length - 1) {
|
||||||
|
JLabel plusLabel = new JLabel("+");
|
||||||
|
plusLabel.setForeground(Color.WHITE); // Vous pouvez aussi styliser le "+"
|
||||||
|
panel.add(plusLabel);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Ajouter le texte avec une taille de police plus grande
|
||||||
|
JLabel textLabel = new JLabel(text);
|
||||||
|
textLabel.setForeground(Color.WHITE);
|
||||||
|
textLabel.setFont(new Font("Arial", Font.PLAIN, 18)); // Augmenter la taille de la police
|
||||||
|
panel.add(textLabel);
|
||||||
|
|
||||||
|
return panel;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Charge l'icône depuis le répertoire spécifié et la redimensionne
|
||||||
|
private ImageIcon loadIcon(String iconName) {
|
||||||
|
// Utilisation de getClass().getResource() pour charger l'icône depuis le classpath
|
||||||
|
URL iconURL = getClass().getResource(ICON_PATH + iconName);
|
||||||
|
if (iconURL != null) {
|
||||||
|
ImageIcon icon = new ImageIcon(iconURL);
|
||||||
|
Image img = icon.getImage();
|
||||||
|
// Redimensionner l'image à une taille plus grande
|
||||||
|
Image scaledImg = img.getScaledInstance(55, 55, Image.SCALE_SMOOTH); // Augmenter la taille des icônes
|
||||||
|
return new ImageIcon(scaledImg);
|
||||||
|
} else {
|
||||||
|
System.out.println("Icone non trouvée : " + iconName);
|
||||||
|
return new ImageIcon();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void toggleVisibility() {
|
||||||
|
isVisible = !isVisible;
|
||||||
|
setVisible(isVisible);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setControlsMenuVisible(boolean visible) {
|
||||||
|
isVisible = visible;
|
||||||
|
setVisible(visible);
|
||||||
|
}
|
||||||
|
}
|
19
src/fr/monkhanny/dorfromantik/game/CustomKeyAdapter.java
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
package fr.monkhanny.dorfromantik.game;
|
||||||
|
|
||||||
|
import java.awt.event.KeyAdapter;
|
||||||
|
import java.awt.event.KeyEvent;
|
||||||
|
|
||||||
|
public class CustomKeyAdapter extends KeyAdapter {
|
||||||
|
private Board board;
|
||||||
|
|
||||||
|
public CustomKeyAdapter(Board board) {
|
||||||
|
this.board = board;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void keyPressed(KeyEvent e) {
|
||||||
|
if (e.getKeyCode() == KeyEvent.VK_T) { // Touche 'T' pour cacher/montrer le menu
|
||||||
|
board.getControlsMenu().toggleVisibility();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@@ -0,0 +1,17 @@
|
|||||||
|
package fr.monkhanny.dorfromantik.game;
|
||||||
|
|
||||||
|
import java.awt.event.MouseMotionAdapter;
|
||||||
|
import java.awt.event.MouseEvent;
|
||||||
|
|
||||||
|
public class CustomMouseMotionAdapter extends MouseMotionAdapter {
|
||||||
|
private Board board;
|
||||||
|
|
||||||
|
public CustomMouseMotionAdapter(Board board) {
|
||||||
|
this.board = board;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void mouseMoved(MouseEvent e) {
|
||||||
|
board.handleMouseMove(e);
|
||||||
|
}
|
||||||
|
}
|