Android Open Source - DivisionByZero Info 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;
//w w  w  . j  a  v  a 2s . co m
import java.util.ArrayList;
import java.util.List;

import com.ggstudios.divisionbyzero.Tower.OnTowerChangeListener;

import android.graphics.Paint;

/**
 * This is not a true dialog. This "dialog" displays information regarding a tower
 * such as it's range, attack speed and damage dealt so far.
 * @author iDunnololz
 *
 */
public class InfoDialog extends Drawable {
  private static final String TAG = "InfoDialog";
  
  private static final float DEFAULT_WIDTH = 6.5f;
  private static final float DEFAULT_HEIGHT = 2.5f;
  
  private float width, height;
  
  private PictureBox bg;
  
  private List<Drawable> drawables = new ArrayList<Drawable>();
  
  private Label lblDmg;
  private Label lblDmgDealt;
  private Label lblAttackSpeed;
  private Label lblRange;
  private DrawableString name;
  private StatBar statDmg, statRange, statAs;
  private DrawableString dmgDealt;
  
  private float x, y;
  
  private boolean visible = true;
  
  private Tower tower;
  
  public InfoDialog() {}
  
  public void build() {
    width = DEFAULT_WIDTH * Core.SDP;
    height = DEFAULT_HEIGHT * Core.SDP;
    
    bg = new PictureBox(0, 0, width, height, R.drawable.window_bg);
    
    final float margin = Core.SDP / 4f;
    final float maxH = Core.fm.getHeight();
    float y = margin;
    float x = margin + Core.SDP * 3f;
    float statW = Core.SDP * 3f;
    float statH = Core.SDP * 0.25f;
    float statMargin = Core.SDP * 0.1f;
    
    Paint textPaint = new Paint();
    textPaint.setColor(0xFFFFFFFF);
    textPaint.setTextSize(Core.fm.getFontSize() * 0.9f);
    textPaint.setAntiAlias(true);
    
    name = new DrawableString(margin, y, Core.fm, "");
    y += maxH;
    lblDmg = new Label(margin, y, textPaint, "Damage");
    statDmg = new StatBar(x, y + statMargin, statW, statH);
    statDmg.setMaxValue(TowerLibrary.MAX_DMG);
    y += lblDmg.h;
    lblRange = new Label(margin, y, textPaint, "Range");
    statRange = new StatBar(x, y + statMargin, statW, statH);
    statRange.setMaxValue(TowerLibrary.MAX_RANGE);
    y += lblRange.h;
    lblAttackSpeed = new Label(margin, y, textPaint, "Attack Speed");
    statAs = new StatBar(x, y + statMargin, statW, statH);
    statAs.setMaxValue(TowerLibrary.MAX_ATK_SPEED);
    y += lblAttackSpeed.h;
    lblDmgDealt = new Label(margin, y, textPaint, "Dmg Dealt");
    dmgDealt = new DrawableString(x + statW, y, Core.fm, "", DrawableString.ALIGN_RIGHT);
    dmgDealt.setTextSize(textPaint.getTextSize());
    
    drawables.add(bg);
    drawables.add(name);
    drawables.add(lblDmg);
    drawables.add(lblRange);
    drawables.add(lblAttackSpeed);
    drawables.add(lblDmgDealt);
    drawables.add(statDmg);
    drawables.add(statRange);
    drawables.add(statAs);
    drawables.add(dmgDealt);
  }
  
  public void setInfo(Tower t) {
    if(tower != null) {
      // we need to unregister our listener from the
      // other tower...
      tower.setTowerChangeListener(null);
    }
    
    this.tower = t;
    
    tower.setTowerChangeListener(new OnTowerChangeListener() {

      @Override
      public void onDamageDealtChange(int totalDmgDealt) {
        dmgDealt.setText(String.valueOf(totalDmgDealt));
      }

      @Override
      public void onStatChange() {
        setInfo(tower);
      }
      
    });
    
    name.setText(t.getName());
    dmgDealt.setText(String.valueOf(t.getTotalDmgDealt()));
    
    int level = tower.level + 1;
    if(tower.level + 1 != tower.evoTree.maxLevel) {
      statDmg.setSecondaryValue(tower.evoTree.dmg[level]);
      statRange.setSecondaryValue(tower.evoTree.range[level]);
      statAs.setSecondaryValue(1/tower.evoTree.as[level]);
    }
    
    final float b1 = statDmg.getValue();
    final float b2 = statRange.getValue();
    final float b3 = statAs.getValue();
    
    final float c1 = t.getDamage() - statDmg.getValue();
    final float c2 = t.getGridRange() - statRange.getValue();
    final float c3 = 1/t.getAttackSpeed() - statAs.getValue();
    
    Core.gu.addUiUpdatable(new Updatable() {
      final float DURATION = 0.5f;
      float time = 0f;

      @Override
      public boolean update(float dt) {
        time += dt;
        if(time < DURATION) {
          float t = time / DURATION * 2;
          if (t < 1) {
            final float temp = t*t/2;
            statDmg.setValue(c1*temp + b1);
            statRange.setValue(c2*temp + b2);
            statAs.setValue(c3*temp + b3);
          } else {
            t--;
            final float temp = -(t*(t-2)-1)/2;
            statDmg.setValue(c1*temp + b1);
            statRange.setValue(c2*temp + b2);
            statAs.setValue(c3*temp + b3);
          }
          return true;
        } else {
          statDmg.setValue(b1+c1);
          statRange.setValue(b2+c2);
          statAs.setValue(b3+c3);
          return false;
        }
      }
    });
  }
  
  @Override
  public void draw(float offX, float offY) {
    if(!visible) return; 
    
    for(Drawable d : drawables)
      d.draw(x, y);
  }

  @Override
  public void refresh() {
    bg.refresh();

    for(Drawable d : drawables)
      d.refresh();
  }
  
  
  public void setVisible(boolean visible) {
    this.visible = visible;
    if(!visible) {
      if(tower != null) {
        tower.setTowerChangeListener(null);
        tower = null;
      }
      statDmg.setValue(0);
      statRange.setValue(0);
      statAs.setValue(0);
    }
  }
}




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