Package org.gbcpainter.view.menu

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

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 level lost menu
* <p/>
* This menu allows the player to retry the level of give up
*
* @author Lorenzo Pellegrini
*/
public class LevelLostMenu extends Panel {

  /**
   * Creates the game over menu with the given game holder
   *
   * @param holder The game holder of the level
   */
  public LevelLostMenu( @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 youLostLabel = new FixedSizeMenuElement(
        LanguageDictionary.YOU_LOST_LEVEL_STRING,
        Color.RED,
        Color.RED,
        Color.BLACK );
    this.add( youLostLabel, constraints );
    constraints.gridy++;
    final MenuElement retryLevelButton = new FixedSizeMenuElement(
        LanguageDictionary.RETRY_STRING,
        Color.RED,
        Color.GREEN,
        Color.BLACK );
    this.add( retryLevelButton, 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() );
      }
    } );

    retryLevelButton.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(
                                              youLostLabel ) );
    this.addComponentListener( GraphicsEnv.getInstance()
                                          .utilGetSmallElementsResizeHandler(
                                              retryLevelButton,
                                              backToMenuButton ) );

  }
}
TOP

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

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.