package editor.model;
import beans.serializable.EventBloc;
import beans.serializable.Objet;
import java.awt.Point;
import java.util.List;
import javax.swing.JPanel;
import editor.screen.souspanel.InitEventModeScreen;
/**
* Model de la popUp de creation d'un nouvel evenement
* @author mastersnes
*/
public class EventModel {
private final EditorModel editorModel;
private final Point position;
private final InitEventModeScreen offScreen;
private final InitEventModeScreen onScreen;
/**
* Constructeur simple d'un evenement
* @param editorModel model d'edition de la map
* @param position position de l'evenement
* @see EditorModel
*/
public EventModel(final EditorModel editorModel, final Point position) {
this.editorModel = editorModel;
this.position = position;
this.onScreen = new InitEventModeScreen();
this.offScreen = new InitEventModeScreen();
}
/**
* Constructeur qui permet de charger un evenement deja existant à cette position
* @param editorModel
* @param position
* @param eventBloc
* @see EventBloc
* @see EditorModel
*/
public EventModel(final EditorModel editorModel, final Point position, final EventBloc eventBloc) {
this(editorModel, position);
onScreen.setColision(eventBloc.isColisionOn());
offScreen.setColision(eventBloc.isColisionOff());
onScreen.setTransporteur(eventBloc.isTransporteurOn(), eventBloc.getDestinationTransportOn(), eventBloc.getDestinationPointOn());
offScreen.setTransporteur(eventBloc.isTransporteurOff(), eventBloc.getDestinationTransportOff(), eventBloc.getDestinationPointOff());
}
/**
* Retourne la popUp concernant le mode ON de l'evenement
* @return La sous popUp
*/
public JPanel getOnScreen() {
return onScreen;
}
/**
* Retourne la popUp concernant le mode OFF de l'evenement
* @return La sous popUp
*/
public JPanel getOffScreen() {
return offScreen;
}
/**
* Permet d'envoyer à l'editeur de map la reponse de la popUp d'evenement ainsi que ses informations
* @param id
* @param automatic
* @param content
* @param imagePath
* @param cyclic
* @param idToActivate
* @param playerPosition
*/
public void submitResponse(final String id, final boolean automatic, final List<Objet> content, final String imagePath, final boolean cyclic, final String idToActivate, final boolean playerPosition) {
final boolean colisionOn = onScreen.isColision();
final boolean transporterOn = onScreen.isTransporteur();
String destinationTransportOn = "";
Point destinationPointOn = null;
if (transporterOn) {
destinationTransportOn = onScreen.getTransportDestination();
destinationPointOn = onScreen.getTransportDestinationPoint();
}
final boolean colisionOff = offScreen.isColision();
final boolean transporterOff = offScreen.isTransporteur();
String destinationTransportOff = "";
Point destinationPointOff = null;
if (transporterOn) {
destinationTransportOff = offScreen.getTransportDestination();
destinationPointOff = offScreen.getTransportDestinationPoint();
}
final EventBloc event = new EventBloc(id, automatic, content, imagePath, cyclic, idToActivate);
event.setOn(colisionOn, transporterOn, destinationTransportOn, destinationPointOn);
event.setOff(colisionOff, transporterOff, destinationTransportOff, destinationPointOff);
event.setPlayerPosition(playerPosition);
editorModel.addEventResponse(position, event);
}
}