NavigationBetweenViewController: rm setMenuView

This commit is contained in:
Daniel Langbein 2024-11-07 13:28:17 +01:00
parent 99db8d4956
commit aa32caaf42
Signed by: langfingaz
GPG Key ID: 6C47C753F0823002
2 changed files with 197 additions and 204 deletions

View File

@ -9,13 +9,12 @@ 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>
@ -50,10 +49,10 @@ public class LevelEditorController implements ActionListener {
* @param event Action event * @param event Action event
*/ */
public void actionPerformed(ActionEvent event) { public void actionPerformed(ActionEvent event) {
switch(event.getActionCommand()) { switch (event.getActionCommand()) {
case "menu": case "menu":
this.levelEditorView.setVisible(false); this.levelEditorView.setVisible(false);
this.nav.setMenuView(); this.nav.getMenuView().setVisible(true);
this.nav.getAudioLoadHelper().startMusic("game"); this.nav.getAudioLoadHelper().startMusic("game");
break; break;
@ -67,7 +66,7 @@ public class LevelEditorController implements ActionListener {
String levelId = this.levelEditorView.getSelectedLevel(); String levelId = this.levelEditorView.getSelectedLevel();
LevelSaveHelper levelSave; LevelSaveHelper levelSave;
if(levelId == null || levelId.isEmpty()) { if (levelId == null || levelId.isEmpty()) {
// Create a new level // Create a new level
levelSave = new LevelSaveHelper(levelModel.getGroundLevelModel()); levelSave = new LevelSaveHelper(levelModel.getGroundLevelModel());
} else { } else {
@ -79,7 +78,7 @@ public class LevelEditorController implements ActionListener {
JOptionPane.showMessageDialog(frameDialog, "Level saved"); JOptionPane.showMessageDialog(frameDialog, "Level saved");
this.levelEditorView.openedLevelChange(levelSave.getLevelId()); this.levelEditorView.openedLevelChange(levelSave.getLevelId());
} catch(LevelConstraintNotRespectedException e) { } catch (LevelConstraintNotRespectedException e) {
JFrame frameDialog = new JFrame("Error"); JFrame frameDialog = new JFrame("Error");
JOptionPane.showMessageDialog(frameDialog, e.getMessage()); JOptionPane.showMessageDialog(frameDialog, e.getMessage());
} }
@ -90,7 +89,7 @@ public class LevelEditorController implements ActionListener {
String levelId = this.levelEditorView.getSelectedLevel(); String levelId = this.levelEditorView.getSelectedLevel();
JFrame frameDialog = new JFrame("Info"); JFrame frameDialog = new JFrame("Info");
if(levelId == null || levelId.isEmpty()) { if (levelId == null || levelId.isEmpty()) {
JOptionPane.showMessageDialog(frameDialog, "Level not yet saved, no need to delete it!"); JOptionPane.showMessageDialog(frameDialog, "Level not yet saved, no need to delete it!");
} else { } else {
new LevelRemoveHelper(levelId); new LevelRemoveHelper(levelId);

View File

@ -6,14 +6,11 @@ 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;
@ -100,15 +97,12 @@ public class NavigationBetweenViewController implements ActionListener {
return this.menuView; return this.menuView;
} }
/** // menuView has already been created in the constructor! No need to recreate it.
* Set the first view //
* //public MenuView setMenuView() {
* @param menuView // this.menuView = new MenuView(this);
*/ // return menuView;
public MenuView setMenuView() { //}
this.menuView = new MenuView(this);
return menuView;
}
/** /**
* Get the pickedLevel * Get the pickedLevel