Android Open Source - DivisionByZero Wave Control Dialog






From Project

Back to project page DivisionByZero.

License

The source code is released under:

Apache License

If you think the Android project DivisionByZero 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

package com.ggstudios.divisionbyzero;
//from   w  ww  .ja  va 2s .c  om
import java.text.DecimalFormat;
import java.util.ArrayList;
import java.util.List;

import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.RectF;

import com.ggstudios.divisionbyzero.Button.OnClickListener;
import com.ggstudios.divisionbyzero.LevelManager.SpawnEvent;

public class WaveControlDialog extends BaseDialog implements Clickable, Updatable {

  private static final float WIDTH = 10f;
  private static final float HEIGHT = 6f;
  
  private static final DecimalFormat df = new DecimalFormat("#.##");
  
  private List<Drawable> drawables = new ArrayList<Drawable>();
  private List<DrawableString> vals = new ArrayList<DrawableString>();
  
  private Label lblDesc;
  
  private Button btnClose;
  private RectF rect = new RectF();
  
  public WaveControlDialog () { }
  
  public void build() {
    setBackgroundTexture(R.drawable.panel);
    
    drawables.clear();
    vals.clear();
    
    w = WIDTH * Core.SDP;
    h = HEIGHT * Core.SDP;
    
    x = (Core.canvasWidth - w) / 2f;
    y = (Core.canvasHeight - h) / 2f;
    
    Paint paint = new Paint();
    paint.setAntiAlias(true);
    paint.setColor(Color.WHITE);
    paint.setTextSize(Core.fm.getFontSize());
    
    float marginL = Core.SDP_H;
    float marginR = w - Core.SDP_H; 
    float marginT = Core.SDP_H;
    
    rect.left = 0;
    rect.top = 0;
    rect.right = w;
    rect.bottom = h;
    
    float bw = Core.SDP_H;
    btnClose = new Button(w - bw - Core.SDP_H * 0.9f, Core.SDP_H * 0.9f, bw, bw, R.drawable.close);
    btnClose.setPadding((int)Core.SDP_H);
    btnClose.setOnClickListener(new OnClickListener() {

      @Override
      public void onClick(Button sender) {
        hide();
      }
      
    });
    
    DrawableString str = new DrawableString(marginL, marginT, Core.fm, "");
    str.setTextSize(Core.SDP_H);
    marginT += Core.SDP_H * 1.3f;
    Label lblHealth = new Label(marginL, marginT, paint, "Health");
    DrawableString valHealth = new DrawableString(marginR, marginT, Core.fm, "", DrawableString.ALIGN_RIGHT);
    marginT += Core.SDP_H * 1.1f;
    Label lblMs = new Label(marginL, marginT, paint, "Movement speed");
    DrawableString valMs = new DrawableString(marginR, marginT, Core.fm, "", DrawableString.ALIGN_RIGHT);
    marginT += Core.SDP_H * 1.1f;
    Label lblGold = new Label(marginL, marginT, paint, "Gold reward");
    DrawableString valGold = new DrawableString(marginR, marginT, Core.fm, "", DrawableString.ALIGN_RIGHT);
    marginT += Core.SDP_H * 1.1f;
    Label lblCount = new Label(marginL, marginT, paint, "Enemies");
    DrawableString valCount = new DrawableString(marginR, marginT, Core.fm, "", DrawableString.ALIGN_RIGHT);
    
    marginT += Core.SDP_H * 1.2f;
    
    Paint p2 = new Paint(paint);
    p2.setColor(Color.LTGRAY);
    
    lblDesc = new Label(marginL, marginT, p2, "Desc");
    lblDesc.setMaxWidth(w - Core.SDP);

    drawables.add(btnClose);
    drawables.add(lblHealth);
    drawables.add(lblMs);
    drawables.add(lblGold);
    drawables.add(lblCount);
    drawables.add(lblDesc);
    
    vals.add(str);
    vals.add(valHealth);
    vals.add(valMs);
    vals.add(valGold);
    vals.add(valCount);
    
    super.refresh();
  }
  
  @Override
  public void draw(float offX, float offY) {
    super.draw(0, 0);
    
    for(Drawable d : drawables) {
      d.draw(x, y);
    }
    
    for(Drawable d : vals) {
      d.draw(x, y);
    }
  }
  
  @Override
  public boolean update(float dt) {
    // TODO Auto-generated method stub
    return false;
  }
  
  @Override
  public boolean onTouchEvent(int action, float x_, float y_) {
    final float x = Core.originalTouchX - this.x;
    final float y = Core.originalTouchY - this.y;
    
    return btnClose.onTouchEvent(action, x, y) || rect.contains(x, y);    
  }
  
  @Override
  public void refresh() {
    super.refresh();
    
    for(Drawable d : drawables) {
      d.refresh();
    }
    
    for(Drawable d : vals) {
      d.refresh();
    }
  }
  
  public void lightSetup(SpawnEvent event) {
    Sprite.SpriteStats stats = Sprite.getSpriteStats(event.enemyType);
    vals.get(0).setText(stats.name);
    vals.get(1).setText(String.valueOf(event.hp));
    vals.get(2).setText(df.format(stats.speed));
    vals.get(3).setText(String.valueOf(event.gold));
    vals.get(4).setText(String.valueOf(event.numUnits));
    
    lblDesc.setText(stats.desc);
  }
}




Java Source Code List

com.ggstudios.divisionbyzero.ActivityAbout.java
com.ggstudios.divisionbyzero.ActivityLevelSelection.java
com.ggstudios.divisionbyzero.ActivityMainMenu.java
com.ggstudios.divisionbyzero.ActivitySettings.java
com.ggstudios.divisionbyzero.ActivitySplashScreen.java
com.ggstudios.divisionbyzero.ApplicationMain.java
com.ggstudios.divisionbyzero.BaseActivity.java
com.ggstudios.divisionbyzero.BaseDialog.java
com.ggstudios.divisionbyzero.BulletManager.java
com.ggstudios.divisionbyzero.Bullet.java
com.ggstudios.divisionbyzero.Button.java
com.ggstudios.divisionbyzero.Circle.java
com.ggstudios.divisionbyzero.ClickableCollection.java
com.ggstudios.divisionbyzero.Clickable.java
com.ggstudios.divisionbyzero.ConfirmDialog.java
com.ggstudios.divisionbyzero.Core.java
com.ggstudios.divisionbyzero.CustomGLSurfaceView.java
com.ggstudios.divisionbyzero.DialogManager.java
com.ggstudios.divisionbyzero.DrawableCollection.java
com.ggstudios.divisionbyzero.DrawableString.java
com.ggstudios.divisionbyzero.Drawable.java
com.ggstudios.divisionbyzero.EndDialog.java
com.ggstudios.divisionbyzero.Event.java
com.ggstudios.divisionbyzero.ExplosionGenerator.java
com.ggstudios.divisionbyzero.ExtrasManager.java
com.ggstudios.divisionbyzero.FontManager.java
com.ggstudios.divisionbyzero.GameRenderer.java
com.ggstudios.divisionbyzero.GameUpdater.java
com.ggstudios.divisionbyzero.Game.java
com.ggstudios.divisionbyzero.Grid.java
com.ggstudios.divisionbyzero.Hud.java
com.ggstudios.divisionbyzero.InGameMenu.java
com.ggstudios.divisionbyzero.InfoDialog.java
com.ggstudios.divisionbyzero.Label.java
com.ggstudios.divisionbyzero.LevelManager.java
com.ggstudios.divisionbyzero.LevelMap.java
com.ggstudios.divisionbyzero.LineGuide.java
com.ggstudios.divisionbyzero.MainActivity.java
com.ggstudios.divisionbyzero.Map.java
com.ggstudios.divisionbyzero.MessageDialog.java
com.ggstudios.divisionbyzero.ParticleEngine.java
com.ggstudios.divisionbyzero.PathFinder.java
com.ggstudios.divisionbyzero.PauseMenu.java
com.ggstudios.divisionbyzero.PictureBox.java
com.ggstudios.divisionbyzero.Player.java
com.ggstudios.divisionbyzero.PopupMenu.java
com.ggstudios.divisionbyzero.Rectangle.java
com.ggstudios.divisionbyzero.Shader.java
com.ggstudios.divisionbyzero.SpawnManager.java
com.ggstudios.divisionbyzero.SpriteAnimation.java
com.ggstudios.divisionbyzero.SpriteManager.java
com.ggstudios.divisionbyzero.Sprite.java
com.ggstudios.divisionbyzero.Statbar.java
com.ggstudios.divisionbyzero.StateManager.java
com.ggstudios.divisionbyzero.TargetRectangle.java
com.ggstudios.divisionbyzero.TextureManager.java
com.ggstudios.divisionbyzero.TowerInfoDialog.java
com.ggstudios.divisionbyzero.TowerLibrary.java
com.ggstudios.divisionbyzero.TowerManager.java
com.ggstudios.divisionbyzero.TowerMenu.java
com.ggstudios.divisionbyzero.Tower.java
com.ggstudios.divisionbyzero.UpdatableCollection.java
com.ggstudios.divisionbyzero.Updatable.java
com.ggstudios.divisionbyzero.UpgradeDialog.java
com.ggstudios.divisionbyzero.Utils.java
com.ggstudios.divisionbyzero.VBO.java
com.ggstudios.divisionbyzero.WaveControlDialog.java
com.ggstudios.divisionbyzero.WaveControlHud.java
com.ggstudios.divisionbyzero.ZoomControl.java
com.ggstudios.utils.BitmapUtils.java
com.ggstudios.utils.BufferUtils.java
com.ggstudios.utils.DebugLog.java
com.ggstudios.utils.ShaderUtils.java
com.ggstudios.widget.LevelMapBackground.java
fix.android.opengl.GLES20.java