NavigationBetweenViewController: rm setMenuView
This commit is contained in:
parent
99db8d4956
commit
aa32caaf42
@ -9,135 +9,134 @@ import fr.enssat.BoulderDash.helpers.LevelSaveHelper;
|
|||||||
import fr.enssat.BoulderDash.models.LevelModel;
|
import fr.enssat.BoulderDash.models.LevelModel;
|
||||||
import fr.enssat.BoulderDash.views.HelpView;
|
import fr.enssat.BoulderDash.views.HelpView;
|
||||||
import fr.enssat.BoulderDash.views.LevelEditorView;
|
import fr.enssat.BoulderDash.views.LevelEditorView;
|
||||||
import fr.enssat.BoulderDash.controllers.NavigationBetweenViewController;
|
|
||||||
|
|
||||||
import javax.swing.*;
|
import javax.swing.*;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* LevelEditorController
|
* LevelEditorController
|
||||||
*
|
* <p>
|
||||||
* Manages the level editor controller.
|
* Manages the level editor controller.
|
||||||
*
|
*
|
||||||
* @author Valerian Saliou <valerian@valeriansaliou.name>
|
* @author Valerian Saliou <valerian@valeriansaliou.name>
|
||||||
* @since 2015-06-19
|
* @since 2015-06-19
|
||||||
*/
|
*/
|
||||||
public class LevelEditorController implements ActionListener {
|
public class LevelEditorController implements ActionListener {
|
||||||
private LevelModel levelModel;
|
private LevelModel levelModel;
|
||||||
private LevelEditorView levelEditorView;
|
private LevelEditorView levelEditorView;
|
||||||
private NavigationBetweenViewController nav;
|
private NavigationBetweenViewController nav;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class constructor'
|
* Class constructor'
|
||||||
*
|
*
|
||||||
* @param levelModel Level model
|
* @param levelModel Level model
|
||||||
*/
|
*/
|
||||||
public LevelEditorController(LevelModel levelModel, NavigationBetweenViewController nav) {
|
public LevelEditorController(LevelModel levelModel, NavigationBetweenViewController nav) {
|
||||||
this.levelModel = levelModel;
|
this.levelModel = levelModel;
|
||||||
this.levelModel.setShowCursor(true);
|
this.levelModel.setShowCursor(true);
|
||||||
|
|
||||||
this.nav = nav;
|
this.nav = nav;
|
||||||
this.nav.getAudioLoadHelper().stopMusic();
|
this.nav.getAudioLoadHelper().stopMusic();
|
||||||
|
|
||||||
this.levelEditorView = new LevelEditorView(this, levelModel, nav);
|
|
||||||
|
|
||||||
// Pre-bind event watcher (hack to fix a Java issue)
|
this.levelEditorView = new LevelEditorView(this, levelModel, nav);
|
||||||
this.levelModel.decrementCursorXPosition();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
// Pre-bind event watcher (hack to fix a Java issue)
|
||||||
* Handles the 'action performed' event
|
this.levelModel.decrementCursorXPosition();
|
||||||
*
|
}
|
||||||
* @param event Action event
|
|
||||||
*/
|
|
||||||
public void actionPerformed(ActionEvent event) {
|
|
||||||
switch(event.getActionCommand()) {
|
|
||||||
case "menu":
|
|
||||||
this.levelEditorView.setVisible(false);
|
|
||||||
this.nav.setMenuView();
|
|
||||||
this.nav.getAudioLoadHelper().startMusic("game");
|
|
||||||
|
|
||||||
break;
|
/**
|
||||||
|
* Handles the 'action performed' event
|
||||||
|
*
|
||||||
|
* @param event Action event
|
||||||
|
*/
|
||||||
|
public void actionPerformed(ActionEvent event) {
|
||||||
|
switch (event.getActionCommand()) {
|
||||||
|
case "menu":
|
||||||
|
this.levelEditorView.setVisible(false);
|
||||||
|
this.nav.getMenuView().setVisible(true);
|
||||||
|
this.nav.getAudioLoadHelper().startMusic("game");
|
||||||
|
|
||||||
case "save":
|
break;
|
||||||
// Check constraints
|
|
||||||
try {
|
|
||||||
this.levelModel.checkConstraints();
|
|
||||||
|
|
||||||
// Save action (direct save)
|
case "save":
|
||||||
String levelId = this.levelEditorView.getSelectedLevel();
|
// Check constraints
|
||||||
LevelSaveHelper levelSave;
|
try {
|
||||||
|
this.levelModel.checkConstraints();
|
||||||
|
|
||||||
if(levelId == null || levelId.isEmpty()) {
|
// Save action (direct save)
|
||||||
// Create a new level
|
String levelId = this.levelEditorView.getSelectedLevel();
|
||||||
levelSave = new LevelSaveHelper(levelModel.getGroundLevelModel());
|
LevelSaveHelper levelSave;
|
||||||
} else {
|
|
||||||
// Overwrite existing level
|
|
||||||
levelSave = new LevelSaveHelper(levelId, levelModel.getGroundLevelModel());
|
|
||||||
}
|
|
||||||
|
|
||||||
JFrame frameDialog = new JFrame("Info");
|
if (levelId == null || levelId.isEmpty()) {
|
||||||
JOptionPane.showMessageDialog(frameDialog, "Level saved");
|
// Create a new level
|
||||||
|
levelSave = new LevelSaveHelper(levelModel.getGroundLevelModel());
|
||||||
|
} else {
|
||||||
|
// Overwrite existing level
|
||||||
|
levelSave = new LevelSaveHelper(levelId, levelModel.getGroundLevelModel());
|
||||||
|
}
|
||||||
|
|
||||||
this.levelEditorView.openedLevelChange(levelSave.getLevelId());
|
JFrame frameDialog = new JFrame("Info");
|
||||||
} catch(LevelConstraintNotRespectedException e) {
|
JOptionPane.showMessageDialog(frameDialog, "Level saved");
|
||||||
JFrame frameDialog = new JFrame("Error");
|
|
||||||
JOptionPane.showMessageDialog(frameDialog, e.getMessage());
|
|
||||||
}
|
|
||||||
|
|
||||||
break;
|
this.levelEditorView.openedLevelChange(levelSave.getLevelId());
|
||||||
|
} catch (LevelConstraintNotRespectedException e) {
|
||||||
case "delete":
|
JFrame frameDialog = new JFrame("Error");
|
||||||
String levelId = this.levelEditorView.getSelectedLevel();
|
JOptionPane.showMessageDialog(frameDialog, e.getMessage());
|
||||||
JFrame frameDialog = new JFrame("Info");
|
|
||||||
|
|
||||||
if(levelId == null || levelId.isEmpty()) {
|
|
||||||
JOptionPane.showMessageDialog(frameDialog, "Level not yet saved, no need to delete it!");
|
|
||||||
} else {
|
|
||||||
new LevelRemoveHelper(levelId);
|
|
||||||
JOptionPane.showMessageDialog(frameDialog, "Level deleted!");
|
|
||||||
|
|
||||||
this.levelEditorView.openedLevelChange(null);
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
|
|
||||||
case "help":
|
|
||||||
new HelpView();
|
|
||||||
break;
|
|
||||||
|
|
||||||
case "new":
|
|
||||||
this.levelEditorView.openedLevelChange(null);
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
this.getLevelEditorView().getLevelEditorGroundView().grabFocus();
|
break;
|
||||||
|
|
||||||
|
case "delete":
|
||||||
|
String levelId = this.levelEditorView.getSelectedLevel();
|
||||||
|
JFrame frameDialog = new JFrame("Info");
|
||||||
|
|
||||||
|
if (levelId == null || levelId.isEmpty()) {
|
||||||
|
JOptionPane.showMessageDialog(frameDialog, "Level not yet saved, no need to delete it!");
|
||||||
|
} else {
|
||||||
|
new LevelRemoveHelper(levelId);
|
||||||
|
JOptionPane.showMessageDialog(frameDialog, "Level deleted!");
|
||||||
|
|
||||||
|
this.levelEditorView.openedLevelChange(null);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
case "help":
|
||||||
|
new HelpView();
|
||||||
|
break;
|
||||||
|
|
||||||
|
case "new":
|
||||||
|
this.levelEditorView.openedLevelChange(null);
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
this.getLevelEditorView().getLevelEditorGroundView().grabFocus();
|
||||||
* Gets the level editor view
|
}
|
||||||
*
|
|
||||||
* @return Level editor view
|
/**
|
||||||
*/
|
* Gets the level editor view
|
||||||
public LevelEditorView getLevelEditorView() {
|
*
|
||||||
return levelEditorView;
|
* @return Level editor view
|
||||||
}
|
*/
|
||||||
|
public LevelEditorView getLevelEditorView() {
|
||||||
|
return levelEditorView;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets level model
|
||||||
|
*
|
||||||
|
* @return Level model
|
||||||
|
*/
|
||||||
|
public LevelModel getLevelModel() {
|
||||||
|
return this.levelModel;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the level editor view
|
||||||
|
*
|
||||||
|
* @param levelEditorView Level editor view
|
||||||
|
*/
|
||||||
|
public void setLevelEditorView(LevelEditorView levelEditorView) {
|
||||||
|
this.levelEditorView = levelEditorView;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Gets level model
|
|
||||||
*
|
|
||||||
* @return Level model
|
|
||||||
*/
|
|
||||||
public LevelModel getLevelModel() {
|
|
||||||
return this.levelModel;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Sets the level editor view
|
|
||||||
*
|
|
||||||
* @param levelEditorView Level editor view
|
|
||||||
*/
|
|
||||||
public void setLevelEditorView(LevelEditorView levelEditorView) {
|
|
||||||
this.levelEditorView = levelEditorView;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
@ -6,127 +6,121 @@ import java.awt.event.ActionListener;
|
|||||||
import fr.enssat.BoulderDash.helpers.AudioLoadHelper;
|
import fr.enssat.BoulderDash.helpers.AudioLoadHelper;
|
||||||
import fr.enssat.BoulderDash.models.LevelModel;
|
import fr.enssat.BoulderDash.models.LevelModel;
|
||||||
import fr.enssat.BoulderDash.views.MenuView;
|
import fr.enssat.BoulderDash.views.MenuView;
|
||||||
import fr.enssat.BoulderDash.controllers.LevelEditorController;
|
|
||||||
import fr.enssat.BoulderDash.controllers.GameController;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Controller to navigate between the different views
|
* Controller to navigate between the different views
|
||||||
*
|
|
||||||
* @author Colin Leverger <me@colinleverger.fr>
|
|
||||||
*
|
*
|
||||||
|
* @author Colin Leverger <me@colinleverger.fr>
|
||||||
*/
|
*/
|
||||||
public class NavigationBetweenViewController implements ActionListener {
|
public class NavigationBetweenViewController implements ActionListener {
|
||||||
private LevelEditorController levelEditorController;
|
private LevelEditorController levelEditorController;
|
||||||
private MenuView menuView;
|
private MenuView menuView;
|
||||||
private AudioLoadHelper audioLoadHelper;
|
private AudioLoadHelper audioLoadHelper;
|
||||||
private LevelModel levelModelForGame, levelModelForEditor;
|
private LevelModel levelModelForGame, levelModelForEditor;
|
||||||
private GameController gameController;
|
private GameController gameController;
|
||||||
private String pickedLevelIdentifier;
|
private String pickedLevelIdentifier;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class constructor
|
* Class constructor
|
||||||
*/
|
*/
|
||||||
public NavigationBetweenViewController() {
|
public NavigationBetweenViewController() {
|
||||||
this.audioLoadHelper = new AudioLoadHelper();
|
this.audioLoadHelper = new AudioLoadHelper();
|
||||||
|
|
||||||
// Play game music
|
// Play game music
|
||||||
this.getAudioLoadHelper().startMusic("game");
|
this.getAudioLoadHelper().startMusic("game");
|
||||||
|
|
||||||
// Creation of the first view
|
// Creation of the first view
|
||||||
this.menuView = new MenuView(this);
|
this.menuView = new MenuView(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Action performed event handler
|
* Action performed event handler
|
||||||
*
|
*
|
||||||
* @param event Action event
|
* @param event Action event
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void actionPerformed(ActionEvent event) {
|
public void actionPerformed(ActionEvent event) {
|
||||||
switch (event.getActionCommand()) {
|
switch (event.getActionCommand()) {
|
||||||
case "quit":
|
case "quit":
|
||||||
System.exit(0);
|
System.exit(0);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case "editor":
|
case "editor":
|
||||||
// New blank model for editor
|
// New blank model for editor
|
||||||
this.levelModelForEditor = new LevelModel(audioLoadHelper);
|
this.levelModelForEditor = new LevelModel(audioLoadHelper);
|
||||||
this.levelEditorController = new LevelEditorController(this.levelModelForEditor, this);
|
this.levelEditorController = new LevelEditorController(this.levelModelForEditor, this);
|
||||||
|
|
||||||
this.levelEditorController.getLevelEditorView().setVisible(true);
|
this.levelEditorController.getLevelEditorView().setVisible(true);
|
||||||
this.levelEditorController.getLevelEditorView().getLevelEditorGroundView().grabFocus();
|
this.levelEditorController.getLevelEditorView().getLevelEditorGroundView().grabFocus();
|
||||||
|
|
||||||
if (gameController != null) {
|
if (gameController != null) {
|
||||||
this.gameController.getGameView().setVisible(false);
|
this.gameController.getGameView().setVisible(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case "game":
|
case "game":
|
||||||
// Reinit the levelModelForGame...
|
// Reinit the levelModelForGame...
|
||||||
pickedLevelIdentifier = this.menuView.getLevelIdentifier();
|
pickedLevelIdentifier = this.menuView.getLevelIdentifier();
|
||||||
|
|
||||||
this.levelModelForGame = new LevelModel(pickedLevelIdentifier, audioLoadHelper);
|
this.levelModelForGame = new LevelModel(pickedLevelIdentifier, audioLoadHelper);
|
||||||
this.gameController = new GameController(levelModelForGame, audioLoadHelper, this);
|
this.gameController = new GameController(levelModelForGame, audioLoadHelper, this);
|
||||||
|
|
||||||
if (levelEditorController != null) {
|
if (levelEditorController != null) {
|
||||||
this.levelEditorController.getLevelEditorView().setVisible(false);
|
this.levelEditorController.getLevelEditorView().setVisible(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
this.gameController.getGameView().setVisible(true);
|
this.gameController.getGameView().setVisible(true);
|
||||||
this.gameController.getGameView().getGameFieldView().grabFocus();
|
this.gameController.getGameView().getGameFieldView().grabFocus();
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
|
||||||
|
|
||||||
this.menuView.setVisible(false);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get the audio load helper
|
|
||||||
*
|
|
||||||
* @return Audio load helper
|
|
||||||
*/
|
|
||||||
public AudioLoadHelper getAudioLoadHelper() {
|
|
||||||
return this.audioLoadHelper;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
this.menuView.setVisible(false);
|
||||||
* Get the first view
|
}
|
||||||
*
|
|
||||||
* @return First view
|
|
||||||
*/
|
|
||||||
public MenuView getMenuView() {
|
|
||||||
return this.menuView;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set the first view
|
* Get the audio load helper
|
||||||
*
|
*
|
||||||
* @param menuView
|
* @return Audio load helper
|
||||||
*/
|
*/
|
||||||
public MenuView setMenuView() {
|
public AudioLoadHelper getAudioLoadHelper() {
|
||||||
this.menuView = new MenuView(this);
|
return this.audioLoadHelper;
|
||||||
return menuView;
|
}
|
||||||
}
|
|
||||||
|
/**
|
||||||
|
* Get the first view
|
||||||
|
*
|
||||||
|
* @return First view
|
||||||
|
*/
|
||||||
|
public MenuView getMenuView() {
|
||||||
|
return this.menuView;
|
||||||
|
}
|
||||||
|
|
||||||
|
// menuView has already been created in the constructor! No need to recreate it.
|
||||||
|
//
|
||||||
|
//public MenuView setMenuView() {
|
||||||
|
// this.menuView = new MenuView(this);
|
||||||
|
// return menuView;
|
||||||
|
//}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the pickedLevel
|
||||||
|
*
|
||||||
|
* @return pickedLevelIdentifier Picked level identifier
|
||||||
|
*/
|
||||||
|
public String getPickedLevelIdentifier() {
|
||||||
|
return pickedLevelIdentifier;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set the pickedLevelIdentifier
|
||||||
|
*
|
||||||
|
* @param pickedLevelIdentifier Picked level identifier
|
||||||
|
*/
|
||||||
|
public void setPickedLevelIdentifier(String pickedLevelIdentifier) {
|
||||||
|
this.pickedLevelIdentifier = pickedLevelIdentifier;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Get the pickedLevel
|
|
||||||
*
|
|
||||||
* @return pickedLevelIdentifier Picked level identifier
|
|
||||||
*/
|
|
||||||
public String getPickedLevelIdentifier() {
|
|
||||||
return pickedLevelIdentifier;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Set the pickedLevelIdentifier
|
|
||||||
*
|
|
||||||
* @param pickedLevelIdentifier Picked level identifier
|
|
||||||
*/
|
|
||||||
public void setPickedLevelIdentifier(String pickedLevelIdentifier) {
|
|
||||||
this.pickedLevelIdentifier = pickedLevelIdentifier;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user