2024-10-25 00:28:51 +02:00
|
|
|
package controller;
|
|
|
|
|
|
|
|
import javax.swing.*;
|
|
|
|
import java.awt.*;
|
|
|
|
|
|
|
|
public class CameraController {
|
|
|
|
|
|
|
|
private Point mouseDragStart = null; // Stocke la position de départ du clic droit
|
|
|
|
private Point viewOffset = new Point(0, 0); // Stocke le décalage actuel de la vue
|
|
|
|
private JPanel gridPanel;
|
2024-10-25 20:22:35 +02:00
|
|
|
private GameContext context;
|
2024-10-25 00:28:51 +02:00
|
|
|
|
|
|
|
public CameraController(JPanel gridPanel, GameContext context) {
|
|
|
|
this.gridPanel = gridPanel;
|
2024-10-25 20:22:35 +02:00
|
|
|
this.context = context;
|
|
|
|
setupMouseDragToMove(); // Initialise les écouteurs pour gérer le déplacement
|
2024-10-25 00:28:51 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public Point getViewOffset() {
|
|
|
|
return viewOffset;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void updateViewOffset(int deltaX, int deltaY) {
|
2024-10-25 20:22:35 +02:00
|
|
|
viewOffset.translate(deltaX, deltaY);
|
|
|
|
gridPanel.setLocation(viewOffset);
|
2024-10-25 00:28:51 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
private void setupMouseDragToMove() {
|
|
|
|
MousePressHandler mousePressHandler = new MousePressHandler(this, context);
|
|
|
|
MouseDragHandler mouseDragHandler = new MouseDragHandler(this, context);
|
2024-10-25 20:22:35 +02:00
|
|
|
|
2024-10-25 00:28:51 +02:00
|
|
|
gridPanel.addMouseListener(mousePressHandler);
|
|
|
|
gridPanel.addMouseMotionListener(mouseDragHandler);
|
|
|
|
}
|
|
|
|
|
|
|
|
public void setMouseDragStart(Point point) {
|
|
|
|
this.mouseDragStart = point;
|
|
|
|
}
|
|
|
|
|
|
|
|
public Point getMouseDragStart() {
|
|
|
|
return mouseDragStart;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void resetMouseDragStart() {
|
|
|
|
this.mouseDragStart = null;
|
|
|
|
}
|
|
|
|
|
|
|
|
public JPanel getGridPanel() {
|
|
|
|
return gridPanel;
|
|
|
|
}
|
|
|
|
}
|