Android Open Source - BlastWords Popup






From Project

Back to project page BlastWords.

License

The source code is released under:

Apache License

If you think the Android project BlastWords listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

/**
 * BlastWords//from w  w  w  .java2 s .com
 * Popup.java
 * 
 * Created by Lou Foster
 * Copyright Studio332 2013. All rights reserved.
 */
package com.studio332.blastwords.screens;

import static com.badlogic.gdx.scenes.scene2d.actions.Actions.fadeIn;

import com.badlogic.gdx.scenes.scene2d.Action;
import com.badlogic.gdx.scenes.scene2d.InputEvent;
import com.badlogic.gdx.scenes.scene2d.InputListener;
import com.badlogic.gdx.scenes.scene2d.actions.Actions;
import com.badlogic.gdx.scenes.scene2d.ui.Image;
import com.badlogic.gdx.scenes.scene2d.utils.Drawable;
import com.studio332.blastwords.BlastWords;
import com.studio332.blastwords.util.Assets;


public final class Popup extends Image {
   
   private enum Mode {PAUSE, GIVE_UP};
   private final Mode mode;
   private GameStateListener listener;

   /**
    * Create an instance of the popup image in PAUSE mode
    * @return
    */
   public static Popup createPausePopup() {
      Popup p = new Popup(Mode.PAUSE, Assets.instance().getDrawable("pauseMenu"));
      p.getColor().a = 0;
      p.addAction( fadeIn(0.5f) );
      p.setPosition( 
            (BlastWords.TGT_WIDTH-p.getWidth())*0.5f, 
            (BlastWords.TGT_HEIGHT-p.getHeight())*0.65f);
      return p;
   }
   
   /**
    * Create an instance of the popup image in Give Up mode
    * @return
    */
   public static Popup createGiveUpPopup() {
      Popup p = new Popup(Mode.GIVE_UP,  Assets.instance().getDrawable("giveUpMenu"));
      p.getColor().a = 0;
      p.addAction( fadeIn(0.5f) );
      p.setPosition( 
            (BlastWords.TGT_WIDTH-p.getWidth())*0.5f, 
            (BlastWords.TGT_HEIGHT-p.getHeight())*0.65f);
      return p;
   }
   
   private Popup(Mode m, Drawable drawable) {
      super( drawable );
      this.mode = m;

      addListener( new InputListener() {
         @Override
         public void touchUp(InputEvent event, float x, float y, int pointer, int button) {
            if ( mode.equals(Mode.PAUSE )) {
               handlePauseTap(x,y);
            } else {
               handleGiveUpTap(x,y);
            }
         }
         
         @Override
         public boolean touchDown(InputEvent event, float x, float y, int pointer, int button) {
            return true;
         }
      });
   }
   
   private void handlePauseTap( float x, float y) {
      if ( listener == null || x < 110 || x > 210 ) {
         return;
      }
      
      if ( y <= 85 ) {
         listener.helpTapped();
      } else if ( y <= 130 ) {
         listener.quitTapped();
      } else if ( y <= 175 ) {
         listener.restartTapped();
      } else if ( y <= 220 ) {
         listener.resumeTapped();
      }
   }
   
   private void handleGiveUpTap(float x, float y) {
      if ( listener == null || x < 95 || x > 250 ) {
         return;
      }
      
      if ( y >= 65 && y <= 105 ) {
         listener.giveUpTapped();
      } else if ( y <= 155 ) {
         listener.resumeTapped();
      } 
   }

   public void setListener(GameStateListener l) {
      this.listener = l;
   }
   
   public void fadeOut() {
      addAction( Actions.sequence(Actions.fadeOut(0.25f), new Action() {
         @Override
         public boolean act(float delta) {
            Popup.this.remove();
            return false;
         }}));
   }
}




Java Source Code List

com.studio332.blastwords.BlastWords.java
com.studio332.blastwords.MainActivity.java
com.studio332.blastwords.Main.java
com.studio332.blastwords.model.BlastWordsGame.java
com.studio332.blastwords.model.LetterInfo.java
com.studio332.blastwords.model.Settings.java
com.studio332.blastwords.objects.Blaster.java
com.studio332.blastwords.objects.Bomb.java
com.studio332.blastwords.objects.Digit.java
com.studio332.blastwords.objects.GameTimer.java
com.studio332.blastwords.objects.ScoreBoard.java
com.studio332.blastwords.objects.Tile.java
com.studio332.blastwords.screens.AbstractScreen.java
com.studio332.blastwords.screens.GameOver.java
com.studio332.blastwords.screens.GameScreen.java
com.studio332.blastwords.screens.GameStateListener.java
com.studio332.blastwords.screens.MainMenuScreen.java
com.studio332.blastwords.screens.Popup.java
com.studio332.blastwords.screens.SplashScreen.java
com.studio332.blastwords.util.Assets.java
com.studio332.blastwords.util.BlastWordsActions.java
com.studio332.blastwords.util.Overlay.java
com.studio332.blastwords.util.ParticleEffectActor.java
com.studio332.blastwords.util.SoundManager.java