Android Open Source - DivisionByZero Tower 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;
/*from  ww  w .j  av a 2s. c om*/
import java.util.ArrayList;
import java.util.List;

import com.ggstudios.divisionbyzero.Button.OnClickListener;
import com.ggstudios.divisionbyzero.TowerLibrary.TowerEvoTree;

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

public class TowerInfoDialog extends BaseDialog {
  private static final float DIALOG_WIDTH = 7f;
  private static final float MARGIN = 0.3f;
  
  private List<Drawable> drawables = new ArrayList<Drawable>();
  
  private DrawableString title;
  private Label lblDamage, lblRange, lblAttackSpeed, lblDesc;
  private StatBar statDamage, statRange, statAttackSpeed;
  private Button btnOk;
  
  private float margin;
  
  private RectF rect = new RectF();
  
  public TowerInfoDialog() {}
  
  public void build() {
    w = DIALOG_WIDTH * Core.SDP;
    
    margin = MARGIN * Core.SDP;
    
    float y = margin;
    float x = margin;
    float r = w - margin;
    
    float statW = Core.SDP * 3f;
    float statH = Core.SDP * 0.25f;
    
    Paint paint = new Paint();
    paint.setColor(Color.WHITE);
    paint.setAntiAlias(true);
    paint.setTextSize(Core.fm.getFontSize() * 0.9f);
    
    float statBarMargin = Core.SDP * 0.1f;
    
    title = new DrawableString(x, y, Core.fm, "<title>");
    y += title.height + margin;
    lblDamage = new Label(x, y, paint, "Damage");
    statDamage = new StatBar(r - statW, y + statBarMargin, statW, statH);
    y += lblDamage.h;// + margin;
    lblRange = new Label(x, y, paint, "Range");
    statRange = new StatBar(r - statW, y + statBarMargin, statW, statH);
    y += lblRange.h;// + margin;
    lblAttackSpeed = new Label(x, y, paint, "Attack speed");
    statAttackSpeed = new StatBar(r - statW, y + statBarMargin, statW, statH);
    y += lblAttackSpeed.h + margin;
    lblDesc = new Label(x, y, paint, "", w - margin * 2);
    btnOk = new Button(x, y, w - margin * 2, Core.SDP, R.drawable.custom_button_bg, "Ok", paint);
    
    btnOk.setOnClickListener(new OnClickListener() {

      @Override
      public void onClick(Button sender) {
        hide();
      }
      
    });
    
    h = y + Core.SDP * 4f;
    
    statDamage.setMaxValue(TowerLibrary.MAX_DMG);
    statRange.setMaxValue(TowerLibrary.MAX_RANGE);
    statAttackSpeed.setMaxValue(TowerLibrary.MAX_ATK_SPEED);
    
    drawables.add(title);
    drawables.add(lblDamage);
    drawables.add(lblRange);
    drawables.add(lblAttackSpeed);
    drawables.add(statDamage);
    drawables.add(statRange);
    drawables.add(statAttackSpeed);
    drawables.add(lblDesc);
    drawables.add(btnOk);
    
    setBackgroundTexture(R.drawable.panel);
  }
  
  private void refreshRect() {
    rect.left = 0;
    rect.top = 0;
    rect.right = w;
    rect.bottom = h;
  }
  
  public void lightSetup(TowerEvoTree evoTree, int level) {
    title.setText(evoTree.name[level]);
    statDamage.setValue(evoTree.dmg[level]);
    statRange.setValue(evoTree.range[level]);
    statAttackSpeed.setValue(1f/evoTree.as[level]);
    lblDesc.setText(evoTree.getDescription());
    
    btnOk.y = lblDesc.y + lblDesc.h + margin;
    
    h = btnOk.y + btnOk.h + margin;
    
    x = (Core.canvasWidth - w) / 2f;
    y = (Core.canvasHeight - h) / 2f;
    
    refreshRect();
    notifyChanged();
  }
  
  @Override
  public boolean onTouchEvent(int action, float x_, float y_) {
    final float x = Core.originalTouchX - this.x;
    final float y = Core.originalTouchY - this.y;
    
    @SuppressWarnings("unused")
    boolean unused = btnOk.onTouchEvent(action, x, y) || rect.contains(x, y);
    return true;  // block all touch events...
  }

  @Override
  public void draw(float offX, float offY) {
    super.draw(0, 0);
    
    for(Drawable d : drawables) {
      d.draw(x, y);
    }
  }
  
  @Override
  public void refresh() {
    super.refresh();
    
    for(Drawable d : drawables) {
      d.refresh();
    }
  }
  
  @Override
  public void show() {
    Core.gu.pause();
    super.show();
  }
  
  @Override
  public void hide() {
    super.hide();
    Core.gu.unpause();
  }
}




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