@Override public void onScalingCompleted(BasicBall ball, boolean growingOrShrinking) { if (growingOrShrinking) return; for (ButtonBall buttonBall : mMenuOptionBalls) { if (buttonBall == ball) { switch (buttonBall.getMenuOption()) { case MusicOn: mMenuOptionBalls[MenuBallOption.MusicOff.ordinal()].grow(); break; case MusicOff: mMenuOptionBalls[MenuBallOption.MusicOn.ordinal()].grow(); break; case SoundEffectsOn: mMenuOptionBalls[MenuBallOption.SoundEffectsOff.ordinal()].grow(); break; case SoundEffectsOff: mMenuOptionBalls[MenuBallOption.SoundEffectsOn.ordinal()].grow(); break; default: throw new IllegalArgumentException("Invalid menu option"); } } } }
/** Resets menu items to an initial state to be animated again. */ public void resetMenuItems() { for (ButtonBall option : mMenuOptionBalls) option.hide(); if (MusicManager.isMusicPlaybackEnabled()) mMenuOptionBalls[MenuBallOption.MusicOn.ordinal()].grow(); else mMenuOptionBalls[MenuBallOption.MusicOff.ordinal()].grow(); if (MusicManager.isSoundEffectPlaybackEnabled()) mMenuOptionBalls[MenuBallOption.SoundEffectsOn.ordinal()].grow(); else mMenuOptionBalls[MenuBallOption.SoundEffectsOff.ordinal()].grow(); }
/** * Updates the logic of the main menu based on the current state. * * @param gameState state of the game * @param gameInput player's input events * @param delta number of seconds the last rendering took */ public void tick(GameScreen.GameState gameState, GameInputProcessor gameInput, float delta) { if (gameState != GameScreen.GameState.Ended && gameState != GameScreen.GameState.GamePaused && gameState != GameScreen.GameState.MainMenu) throw new IllegalStateException("Invalid state for updating menu."); boolean optionSelected = false; for (ButtonBall option : mMenuOptionBalls) { option.tick(delta); if (option.wasClicked(gameInput)) { optionSelected = true; switch (option.getMenuOption()) { case MusicOn: mMenuOptionBalls[MenuBallOption.MusicOn.ordinal()].shrink(); if (mCallback != null) mCallback.setMusicEnabled(false); break; case MusicOff: mMenuOptionBalls[MenuBallOption.MusicOff.ordinal()].shrink(); if (mCallback != null) mCallback.setMusicEnabled(true); break; case SoundEffectsOn: mMenuOptionBalls[MenuBallOption.SoundEffectsOn.ordinal()].shrink(); if (mCallback != null) mCallback.setSoundEffectsEnabled(false); break; case SoundEffectsOff: mMenuOptionBalls[MenuBallOption.SoundEffectsOff.ordinal()].shrink(); if (mCallback != null) mCallback.setSoundEffectsEnabled(true); break; default: throw new IllegalArgumentException("menu option not valid."); } // Only one option can be selected, so the loop exits break; } } if (!optionSelected) { // Starts the game if no other option was selected if (gameInput.clickOccurred() && mCallback != null) { if (gameState == GameScreen.GameState.GamePaused) mCallback.resumeGame(); else mCallback.prepareNewGame(); } } }
/** * Sets up a new main menu. * * @param callback instance of callback interface * @param textureManager to get textures to draw */ public MenuManager(MenuCallback callback, TextureManager textureManager) { mCallback = callback; mTextureManager = textureManager; BasicBall.initialize(GameScreen.getScreenWidth(), GameScreen.getScreenHeight()); mMenuOptionBalls = new ButtonBall[MenuBallOption.getSize()]; mMenuOptionBalls[MenuBallOption.MusicOn.ordinal()] = new ButtonBall( MenuBallOption.MusicOn, TextureManager.GameColor.Green, textureManager.getMenuButtonIconTexture(MenuBallOption.MusicOn), GameScreen.getScreenWidth() / 2 - BasicBall.getDefaultBallRadius() * 2, GameScreen.getScreenHeight() / 2); mMenuOptionBalls[MenuBallOption.MusicOff.ordinal()] = new ButtonBall( MenuBallOption.MusicOff, TextureManager.GameColor.Red, textureManager.getMenuButtonIconTexture(MenuBallOption.MusicOff), GameScreen.getScreenWidth() / 2 - BasicBall.getDefaultBallRadius() * 2, GameScreen.getScreenHeight() / 2); mMenuOptionBalls[MenuBallOption.SoundEffectsOn.ordinal()] = new ButtonBall( MenuBallOption.SoundEffectsOn, TextureManager.GameColor.Green, textureManager.getMenuButtonIconTexture(MenuBallOption.SoundEffectsOn), GameScreen.getScreenWidth() / 2 + BasicBall.getDefaultBallRadius() * 2, GameScreen.getScreenHeight() / 2); mMenuOptionBalls[MenuBallOption.SoundEffectsOff.ordinal()] = new ButtonBall( MenuBallOption.SoundEffectsOff, TextureManager.GameColor.Red, textureManager.getMenuButtonIconTexture(MenuBallOption.SoundEffectsOff), GameScreen.getScreenWidth() / 2 + BasicBall.getDefaultBallRadius() * 2, GameScreen.getScreenHeight() / 2); for (ButtonBall ball : mMenuOptionBalls) ball.setScalingCompleteListener(mMenuOptionBallsListener); }