Android Open Source - block-composer Mode






From Project

Back to project page block-composer.

License

The source code is released under:

MIT License

If you think the Android project block-composer 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 bwr.blockcomposer.modes;
// w  w w .j av  a 2  s . c  o m
import java.util.LinkedList;
import java.util.concurrent.ConcurrentLinkedQueue;

import javax.microedition.khronos.opengles.GL10;

import bwr.blockcomposer.BlockComposer;
import bwr.blockcomposer.Camera;
import bwr.blockcomposer.GameResources;
import bwr.blockcomposer.OnUpdateAction;
import bwr.blockcomposer.R;
import bwr.blockcomposer.ui.UIElementPicture;
import bwr.blockcomposer.ui.UIElementText;

import android.content.Context;
import android.view.KeyEvent;
import android.view.MenuItem;

public abstract class Mode {
  protected final LinkedList<UIElementText> uiElements = new LinkedList<UIElementText>();
  protected final LinkedList<UIElementPicture> buttons = new LinkedList<UIElementPicture>();

  protected final ConcurrentLinkedQueue<OnUpdateAction> updateActions = new ConcurrentLinkedQueue<OnUpdateAction>();
  
  protected final Context context;
  protected final ModeController modeController;
  protected final GameResources gameResources;
  
  private final int id;
  private boolean initialized = false;

  protected final static int BUTTON_TEXT_SIZE = 32;
  protected final static int DIALOG_TEXT_SIZE = 26;
  
  protected int displayWidth, displayHeight;
  protected BlockComposer application;
  
  private static int nextId = 0;
  
  public Mode(ModeController modeController, GameResources gameResources) {
    this.context = gameResources.getContext();
    this.application = gameResources.getBlockComposer();
    this.modeController = modeController;
    this.gameResources = gameResources;
    this.id = nextId++;
  }
  
  public int getId() {
    return id;
  }
  
  public boolean isInitialized() {
    return initialized;
  }
  
  public void setInitialized(boolean initialized) {
    this.initialized = initialized;
  }
  
  public abstract void update(long dt);
  
  public void onModeCreate(GL10 gl, int displayWidth, int displayHeight) {
    initialized = true;
    this.displayHeight = displayHeight;
    this.displayWidth = displayWidth;
  }
  
  public void buildUserInterface(GL10 gl) {
    
  }
  
  public abstract void render3D(GL10 gl);
  
  public abstract Camera getCamera();
  
  public void render2D(GL10 gl) {
        gl.glDisableClientState(GL10.GL_NORMAL_ARRAY);
        gl.glEnableClientState(GL10.GL_VERTEX_ARRAY);
    gl.glEnableClientState(GL10.GL_TEXTURE_COORD_ARRAY);
        gl.glColor4f(1f, 1f, 1f, 1f);
    for(UIElementText e : uiElements) {
      if(!e.hidden) e.render(gl);
    }
    for(UIElementPicture b : buttons) {
      if(!b.hidden) b.draw(gl, gameResources);
    }
    gl.glDisableClientState(GL10.GL_TEXTURE_COORD_ARRAY);
  }
  
  protected boolean handleUIEvent(int id, int action) {
    return false;
  }
  
  public boolean onTouchEvent(int x, int y, int action) {
    for(UIElementText e : uiElements) {
      if(!e.hidden && e.isHit(x, y)) if(handleUIEvent(e.getId(), action)) return true;
    }
    
    for(UIElementPicture b : buttons) {
      if(!b.hidden && b.isHit(x, y)) if(handleUIEvent(b.id, action)) return true;
    }
    
    return false;
  }

  public boolean onKeyDown(int keyCode, KeyEvent event) {
    return false;
  }

  public void onModePop() {
    
  }
  
  public int optionsMenu() {
    return R.menu.optionsmenu;
  }
  
  public boolean onOptionsItemSelected(Context context, MenuItem item) {
      return false;
  }

  public void onModeBecomeActive(GL10 gl) {
    if(!uiElements.isEmpty()) {
      for(UIElementText uie : uiElements) {
        uie.refresh(context, gl);
      }
    }
  }
  
}




Java Source Code List

bwr.blockcomposer.AnimationFinishedListener.java
bwr.blockcomposer.BlockComposerActivity.java
bwr.blockcomposer.BlockComposerRenderer.java
bwr.blockcomposer.BlockComposer.java
bwr.blockcomposer.Camera.java
bwr.blockcomposer.GameResources.java
bwr.blockcomposer.OnUpdateAction.java
bwr.blockcomposer.gamedata.Block.java
bwr.blockcomposer.gamedata.GameEntity.java
bwr.blockcomposer.gamedata.GameState.java
bwr.blockcomposer.gamedata.LevelDimensions.java
bwr.blockcomposer.gamedata.LevelMask.java
bwr.blockcomposer.gamedata.LevelMetadata.java
bwr.blockcomposer.gamedata.LevelStore.java
bwr.blockcomposer.gamedata.Level.java
bwr.blockcomposer.gamedata.Move.java
bwr.blockcomposer.gamedata.StaticLevelStore.java
bwr.blockcomposer.gamedata.UserLevelStore.java
bwr.blockcomposer.misc.GLUtility.java
bwr.blockcomposer.misc.Timer.java
bwr.blockcomposer.models.AxisRenderer.java
bwr.blockcomposer.models.Model.java
bwr.blockcomposer.models.SelectBoxRenderer.java
bwr.blockcomposer.modes.EditMode.java
bwr.blockcomposer.modes.GameDialogMode.java
bwr.blockcomposer.modes.GameMode.java
bwr.blockcomposer.modes.LevelImportMode.java
bwr.blockcomposer.modes.LevelSelectMode.java
bwr.blockcomposer.modes.LogoDisplayMode.java
bwr.blockcomposer.modes.ModeController.java
bwr.blockcomposer.modes.Mode.java
bwr.blockcomposer.modes.OverlayMode.java
bwr.blockcomposer.types.FlipRotateFloat.java
bwr.blockcomposer.types.FloatValueVector3.java
bwr.blockcomposer.types.FloatValue.java
bwr.blockcomposer.types.IntVector.java
bwr.blockcomposer.types.RotatingFloat.java
bwr.blockcomposer.ui.TextRenderer.java
bwr.blockcomposer.ui.UIElementPicture.java
bwr.blockcomposer.ui.UIElementText.java
bwr.blockcomposer.ui.UIElement.java