Package org.gbcpainter.view.menu

Source Code of org.gbcpainter.view.menu.PauseMenu

package org.gbcpainter.view.menu;

import org.gbcpainter.env.GraphicsEnv;
import org.gbcpainter.env.LanguageDictionary;
import org.gbcpainter.view.GameHolder;
import org.gbcpainter.view.ViewManager;
import org.jetbrains.annotations.NotNull;

import java.awt.*;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;

/**
* The pause menu
* <p/>
* This menu allows the player to resume the level or go back to menu
*
* @author Lorenzo Pellegrini
*/
public class PauseMenu extends Panel {

  public PauseMenu( @NotNull final GameHolder holder ) {
    super( new GridBagLayout() );

    this.setBackground( Color.BLACK );

    GridBagConstraints constraints = new GridBagConstraints();
    constraints.gridx = 0;
    constraints.gridy = 0;
    constraints.weightx = 1.0;
    constraints.weighty = 1.0;
    constraints.fill = GridBagConstraints.BOTH;

    final MenuElement pauseLabel = new FixedSizeMenuElement(
        LanguageDictionary.PAUSE_LEVEL_STRING,
        Color.RED,
        Color.RED,
        Color.BLACK );
    this.add( pauseLabel, constraints );
    constraints.gridy++;
    final MenuElement continueLevelButton = new FixedSizeMenuElement(
        LanguageDictionary.CONTINUE_STRING,
        Color.RED,
        Color.GREEN,
        Color.BLACK );
    this.add( continueLevelButton, constraints );
    constraints.gridy++;
    final MenuElement backToMenuButton = new FixedSizeMenuElement(
        LanguageDictionary.BACK_TO_MENU_STRING,
        Color.RED,
        Color.GREEN,
        Color.BLACK );
    this.add( backToMenuButton, constraints );


    backToMenuButton.addMouseListener( new MouseAdapter() {
      @Override
      public void mouseReleased( final MouseEvent e ) {
        ViewManager.getMainView().swap( new MainMenu() );
      }
    } );

    continueLevelButton.addMouseListener( new MouseAdapter() {
      @Override
      public void mouseReleased( final MouseEvent e ) {
        final GameHolder aNewInstanceBecauseMacOSXSucks = new GameHolder(
            holder.getLevel() );
        ViewManager.getMainView()
                   .swapToFullView( aNewInstanceBecauseMacOSXSucks );
      }
    } );

    this.addComponentListener( GraphicsEnv.getInstance()
                                          .utilGetBigElementsResizeHandler(
                                              pauseLabel ) );
    this.addComponentListener( GraphicsEnv.getInstance()
                                          .utilGetSmallElementsResizeHandler(
                                              continueLevelButton,
                                              backToMenuButton ) );

  }


}
TOP

Related Classes of org.gbcpainter.view.menu.PauseMenu

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.