diff --git a/core/src/com/galaxytrucker/galaxytruckerreloaded/View/Buttons/InGameButtons/OptionButtons/OptionenBackButton.java b/core/src/com/galaxytrucker/galaxytruckerreloaded/View/Buttons/InGameButtons/OptionButtons/OptionenBackButton.java index 82b3c65d828a101d5bd404d9c5407b437a2b1a32..366d6edc9c8c787924c2109ffaa70442a94987af 100644 --- a/core/src/com/galaxytrucker/galaxytruckerreloaded/View/Buttons/InGameButtons/OptionButtons/OptionenBackButton.java +++ b/core/src/com/galaxytrucker/galaxytruckerreloaded/View/Buttons/InGameButtons/OptionButtons/OptionenBackButton.java @@ -30,6 +30,8 @@ public class OptionenBackButton extends ImButton { @Override public void leftClick() { optionUI.disposeOptionsUI(); - pauseMenuUI.showPauseMenuUI(); + if(pauseMenuUI!=null) { + pauseMenuUI.showPauseMenuUI(); + } } } diff --git a/core/src/com/galaxytrucker/galaxytruckerreloaded/View/Buttons/MenuButtons/OptionButton.java b/core/src/com/galaxytrucker/galaxytruckerreloaded/View/Buttons/MenuButtons/OptionButton.java index f74c059226520101df17623c9f7cb777b4266b43..ff2b741ccab8455bb7b5f75ac3a2d7895863f45f 100644 --- a/core/src/com/galaxytrucker/galaxytruckerreloaded/View/Buttons/MenuButtons/OptionButton.java +++ b/core/src/com/galaxytrucker/galaxytruckerreloaded/View/Buttons/MenuButtons/OptionButton.java @@ -19,10 +19,6 @@ public class OptionButton extends ImButton{ */ private Sound clickSound; - private PauseMenuUI pauseMenuUI; - - private OptionUI optionUI; - /** Menu object */ private MainMenu mainMenu; @@ -30,14 +26,13 @@ public class OptionButton extends ImButton{ * Constructor * */ - public OptionButton(float x, float y, float width, float height, PauseMenuUI ui, MainMenu mainMenu) { + public OptionButton(float x, float y, float width, float height, MainMenu mainMenu) { super(new Texture("options_select2.png"), x, y, width, height); this.addListener(new ClickListener() { public void clicked(InputEvent event, float x, float y) { leftClick(); } }); - this.pauseMenuUI = ui; this.mainMenu = mainMenu; } diff --git a/core/src/com/galaxytrucker/galaxytruckerreloaded/View/Screen/GamePlay.java b/core/src/com/galaxytrucker/galaxytruckerreloaded/View/Screen/GamePlay.java index 9136f768bdeaf29910851a73761d63c97b56a113..e43207dfc9ec899e539de4d174ebd349d00d98e9 100644 --- a/core/src/com/galaxytrucker/galaxytruckerreloaded/View/Screen/GamePlay.java +++ b/core/src/com/galaxytrucker/galaxytruckerreloaded/View/Screen/GamePlay.java @@ -253,9 +253,7 @@ public class GamePlay implements Screen { * handles input to pause game, open options */ public void updateInput() { - System.out.println("touched"); if(Gdx.input.isKeyJustPressed(Input.Keys.ESCAPE)) { - System.out.println("Where"); // Pause-menu Gdx.input.setInputProcessor(pauseStage); createPauseMenu(); @@ -340,7 +338,7 @@ public class GamePlay implements Screen { * opens in game general options */ public void createGeneralUI() { - generalUI = new GeneralUI(main, pauseStage, this); + generalUI = new GeneralUI(main, pauseStage, this, null); } /** @@ -354,7 +352,7 @@ public class GamePlay implements Screen { * opens in game video options */ public void createVideoUI() { - videoUI = new VideoUI(main, pauseStage, this); + videoUI = new VideoUI(main, pauseStage, this, null); } /** diff --git a/core/src/com/galaxytrucker/galaxytruckerreloaded/View/Screen/MainMenu.java b/core/src/com/galaxytrucker/galaxytruckerreloaded/View/Screen/MainMenu.java index 8dbd2b59f05ecb955ea73dc45e4524f878942066..00d62ff700d6b9919e0b2698952679e9f690b230 100644 --- a/core/src/com/galaxytrucker/galaxytruckerreloaded/View/Screen/MainMenu.java +++ b/core/src/com/galaxytrucker/galaxytruckerreloaded/View/Screen/MainMenu.java @@ -11,8 +11,12 @@ import com.galaxytrucker.galaxytruckerreloaded.Main; import com.galaxytrucker.galaxytruckerreloaded.View.Buttons.MenuButtons.NewGameButton; import com.galaxytrucker.galaxytruckerreloaded.View.Buttons.MenuButtons.OptionButton; import com.galaxytrucker.galaxytruckerreloaded.View.Buttons.MenuButtons.QuitButton; +import com.galaxytrucker.galaxytruckerreloaded.View.UI.Options.GeneralUI; import com.galaxytrucker.galaxytruckerreloaded.View.UI.Options.OptionUI; import com.galaxytrucker.galaxytruckerreloaded.View.UI.Options.PauseMenuUI; +import com.galaxytrucker.galaxytruckerreloaded.View.UI.Options.VideoUI; + +import javax.swing.text.html.Option; /** * Main menu screen @@ -27,9 +31,12 @@ public class MainMenu implements Screen { private Viewport viewport; - private PauseMenuUI ui; private OptionUI optionUI; + private GeneralUI generalUI; + + private VideoUI videoUI; + private NewGameButton newGame; private OptionButton optionButton; private QuitButton quit; @@ -40,7 +47,7 @@ public class MainMenu implements Screen { this.main = main; background = new Texture("1080p.png"); newGame = new NewGameButton(main.WIDTH/2 - 124, main.HEIGHT/2 - 25, 248, 50, this); - optionButton = new OptionButton(main.WIDTH/2 - 97, main.HEIGHT/2 -50 - 25, 194, 50, ui,this); + optionButton = new OptionButton(main.WIDTH/2 - 97, main.HEIGHT/2 -50 - 25, 194, 50,this); quit = new QuitButton(main.WIDTH/2 - 124 , main.HEIGHT/2 - 100 - 25, 248, 50, this); viewport = new FitViewport(main.WIDTH, main.HEIGHT); @@ -58,7 +65,9 @@ public class MainMenu implements Screen { */ @Override public void show() { - + newGame.setVisible(true); + optionButton.setVisible(true); + quit.setVisible(true); } /** @@ -73,6 +82,9 @@ public class MainMenu implements Screen { main.batch.begin(); main.batch.draw(background, 0, 0, main.WIDTH, main.HEIGHT); main.batch.end(); + if(optionUI!=null) { + optionUI.render(); + } stage.draw(); } @@ -105,7 +117,9 @@ public class MainMenu implements Screen { */ @Override public void hide() { - + newGame.setVisible(false); + optionButton.setVisible(false); + quit.setVisible(false); } /** @@ -115,6 +129,9 @@ public class MainMenu implements Screen { public void dispose() { background.dispose(); stage.dispose(); + if(optionUI!=null) { + optionUI.disposeOptionsUI(); + } } /** @@ -127,14 +144,40 @@ public class MainMenu implements Screen { } public void createOptions(){ - optionUI = new OptionUI(main,stage,null, this); - + if(optionUI==null) { + hide(); + optionUI = new OptionUI(main, stage, null, this); + } } public void deleteOptions(){ + show(); optionUI = null; } + public OptionUI getOptionUI() { + return optionUI; + } + + public void createGeneralUI() { + if(generalUI == null) { + generalUI = new GeneralUI(main, stage, null, this); + } + } + + public void deleteGeneralUI() { + generalUI = null; + } + + public void createVideoUI() { + if(videoUI == null) { + videoUI = new VideoUI(main, stage, null, this); + } + } + + public void deleteVideoUI() { + videoUI = null; + } /** * resumes the existing game. diff --git a/core/src/com/galaxytrucker/galaxytruckerreloaded/View/UI/Options/GeneralUI.java b/core/src/com/galaxytrucker/galaxytruckerreloaded/View/UI/Options/GeneralUI.java index 85a2e0637f02ae1e2cc5234f87fd4d84400274d5..112ff7d2984a0f4a3648f1c26be8ceba1ffb6688 100644 --- a/core/src/com/galaxytrucker/galaxytruckerreloaded/View/UI/Options/GeneralUI.java +++ b/core/src/com/galaxytrucker/galaxytruckerreloaded/View/UI/Options/GeneralUI.java @@ -7,6 +7,7 @@ import com.badlogic.gdx.scenes.scene2d.Stage; import com.galaxytrucker.galaxytruckerreloaded.Main; import com.galaxytrucker.galaxytruckerreloaded.View.Buttons.InGameButtons.OptionButtons.General.BackButton; import com.galaxytrucker.galaxytruckerreloaded.View.Screen.GamePlay; +import com.galaxytrucker.galaxytruckerreloaded.View.Screen.MainMenu; /** @@ -29,6 +30,8 @@ public class GeneralUI { */ private GamePlay gamePlay; + private MainMenu mainMenu; + /** * OptionUI of the running Optionmenu. */ @@ -52,11 +55,17 @@ public class GeneralUI { * @param stage current stage instance * @param gamePlay current gameplay instance */ - public GeneralUI (Main main, Stage stage, GamePlay gamePlay) { + public GeneralUI (Main main, Stage stage, GamePlay gamePlay, MainMenu mainMenu) { this.main = main; this.gamePlay = gamePlay; + this.mainMenu = mainMenu; this.stage = stage; - this.optionUI = gamePlay.getOptionUI(); + if(gamePlay != null) { + this.optionUI = gamePlay.getOptionUI(); + } + else if(mainMenu != null) { + this.optionUI = mainMenu.getOptionUI(); + } generalBackgroundTexture = new Texture("options/general.png"); x = main.WIDTH / 2 - generalBackgroundTexture.getWidth() / 2; @@ -86,7 +95,12 @@ public class GeneralUI { public void disposeGeneralUI() { generalBackgroundTexture.dispose(); backButton.remove(); - gamePlay.deleteGeneralUI(); + if(gamePlay != null) { + gamePlay.deleteGeneralUI(); + } + else if(mainMenu != null) { + mainMenu.deleteGeneralUI(); + } } /** diff --git a/core/src/com/galaxytrucker/galaxytruckerreloaded/View/UI/Options/OptionUI.java b/core/src/com/galaxytrucker/galaxytruckerreloaded/View/UI/Options/OptionUI.java index 21d2c440f0a86da14c58d050edfa1b7b3efc9711..106ae5889c3995f0b70631359c329bafca243a6d 100644 --- a/core/src/com/galaxytrucker/galaxytruckerreloaded/View/UI/Options/OptionUI.java +++ b/core/src/com/galaxytrucker/galaxytruckerreloaded/View/UI/Options/OptionUI.java @@ -74,7 +74,6 @@ public class OptionUI { main.batch.draw(optionsBackgroundTexture, x, y, 601, 471); main.batch.end(); stage.draw(); - } /** @@ -89,7 +88,7 @@ public class OptionUI { game.deleteOptions(); } else{ - mainMenu.(); + mainMenu.deleteOptions(); } } @@ -123,17 +122,29 @@ public class OptionUI { public void updateInput() { if(Gdx.input.isKeyJustPressed(Input.Keys.ESCAPE)) { disposeOptionsUI(); - pauseMenuUI.showPauseMenuUI(); + if(pauseMenuUI!=null) { + pauseMenuUI.showPauseMenuUI(); + } } } public void openGeneral() { this.hideOptionsUI(); - game.createGeneralUI(); + if(game!=null) { + game.createGeneralUI(); + } + else if(mainMenu!=null) { + mainMenu.createGeneralUI(); + } } public void openVideo() { this.hideOptionsUI(); - game.createVideoUI(); + if(game!=null) { + game.createVideoUI(); + } + else if(mainMenu!=null) { + mainMenu.createVideoUI(); + } } } diff --git a/core/src/com/galaxytrucker/galaxytruckerreloaded/View/UI/Options/VideoUI.java b/core/src/com/galaxytrucker/galaxytruckerreloaded/View/UI/Options/VideoUI.java index 503f72a2d17fe2ff22f77365cb166cc8c8859a5d..7a2193f12d120676b0f912de575ba4446be46536 100644 --- a/core/src/com/galaxytrucker/galaxytruckerreloaded/View/UI/Options/VideoUI.java +++ b/core/src/com/galaxytrucker/galaxytruckerreloaded/View/UI/Options/VideoUI.java @@ -9,6 +9,7 @@ import com.galaxytrucker.galaxytruckerreloaded.View.Buttons.InGameButtons.Option import com.galaxytrucker.galaxytruckerreloaded.View.Buttons.InGameButtons.OptionButtons.Video.WindowedButton; import com.galaxytrucker.galaxytruckerreloaded.View.Buttons.InGameButtons.OptionButtons.Video.FullscreenEnableButton; import com.galaxytrucker.galaxytruckerreloaded.View.Screen.GamePlay; +import com.galaxytrucker.galaxytruckerreloaded.View.Screen.MainMenu; public class VideoUI { @@ -27,6 +28,8 @@ public class VideoUI { */ private GamePlay gamePlay; + private MainMenu mainMenu; + /** * OptionUI of the running Optionmenu. */ @@ -54,10 +57,16 @@ public class VideoUI { * @param stage current stage instance * @param gamePlay current gameplay instance */ - public VideoUI (Main main, Stage stage, GamePlay gamePlay) { + public VideoUI (Main main, Stage stage, GamePlay gamePlay, MainMenu mainMenu) { this.main = main; this.gamePlay = gamePlay; - this.optionUI = gamePlay.getOptionUI(); + this.mainMenu = mainMenu; + if(gamePlay!=null) { + this.optionUI = gamePlay.getOptionUI(); + } + else if(mainMenu != null) { + this.optionUI = mainMenu.getOptionUI(); + } this.stage = stage; backgroundTexture = new Texture("options/video.png"); @@ -95,7 +104,12 @@ public class VideoUI { backButton.remove(); fullscreenEnableButton.remove(); windowedButton.remove(); - gamePlay.deleteVideoUI(); + if(gamePlay != null) { + gamePlay.deleteVideoUI(); + } + else if(mainMenu != null) { + mainMenu.deleteVideoUI(); + } } /**