Android Open Source - Gloomy-Dungeons-3D Labels






From Project

Back to project page Gloomy-Dungeons-3D.

License

The source code is released under:

MIT License

If you think the Android project Gloomy-Dungeons-3D 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 zame.game.engine;
//from ww  w  . ja  v  a  2  s . com
import android.graphics.Paint;
import android.graphics.Typeface;
import java.util.Locale;
import javax.microedition.khronos.opengles.GL10;
import zame.game.Config;
import zame.game.R;
import zame.game.ZameApplication;
import zame.libs.LabelMaker;
import zame.libs.NumericSprite;

public class Labels
{
  public static final int LABEL_FPS = 1;
  public static final int LABEL_CANT_OPEN = 2;
  public static final int LABEL_NEED_BLUE_KEY = 3;
  public static final int LABEL_NEED_RED_KEY = 4;
  public static final int LABEL_NEED_GREEN_KEY = 5;
  public static final int LABEL_SECRET_FOUND = 6;
  public static final int LABEL_LAST = 7;

  public static final int MSG_PRESS_FORWARD = 1;
  public static final int MSG_PRESS_ROTATE = 2;
  public static final int MSG_PRESS_ACTION_TO_OPEN_DOOR = 3;
  public static final int MSG_SWITCH_AT_RIGHT = 4;
  public static final int MSG_PRESS_ACTION_TO_SWITCH = 5;
  public static final int MSG_KEY_AT_LEFT = 6;
  public static final int MSG_PRESS_ACTION_TO_FIGHT = 7;
  public static final int MSG_PRESS_MAP = 8;
  public static final int MSG_PRESS_NEXT_WEAPON = 9;
  public static final int MSG_OPEN_DOOR_USING_KEY = 10;
  public static final int MSG_PRESS_END_LEVEL_SWITCH = 11;
  public static final int MSG_GO_TO_DOOR = 12;
  public static final int MSG_LAST = 13;

  public static int[] map = new int[LABEL_LAST];

  public static final int[] MSG_MAP = new int[] {
    0,
    R.string.lblm_press_forward, // MSG_PRESS_FORWARD
    R.string.lblm_press_rotate, // MSG_PRESS_ROTATE
    R.string.lblm_press_action_to_open_door, // MSG_PRESS_ACTION_TO_OPEN_DOOR
    R.string.lblm_switch_at_right, // MSG_SWITCH_AT_RIGHT
    R.string.lblm_press_action_to_switch, // MSG_PRESS_ACTION_TO_SWITCH
    R.string.lblm_key_at_left, // MSG_KEY_AT_LEFT
    R.string.lblm_press_action_to_fight, // MSG_PRESS_ACTION_TO_FIGHT
    R.string.lblm_press_map, // MSG_PRESS_MAP
    R.string.lblm_press_next_weapon, // MSG_PRESS_NEXT_WEAPON
    R.string.lblm_open_door_using_key, // MSG_OPEN_DOOR_USING_KEY
    R.string.lblm_press_end_level_switch, // MSG_PRESS_END_LEVEL_SWITCH
    R.string.lblm_go_to_door, // MSG_GO_TO_DOOR
  };

  public static LabelMaker maker;
  public static LabelMaker msgMaker;
  public static NumericSprite numeric;
  public static NumericSprite statsNumeric;

  private static Typeface labelTypeface;
  private static Paint labelPaint;
  private static Paint msgPaint;
  private static Paint statsPaint;
  private static int currentMessageId;
  private static int currentMessageLabelId;
  private static String currentMessageString;

  public static void init()
  {
    labelTypeface = Typeface.createFromAsset(Game.assetManager, "fonts/" + ZameApplication.self.getString(R.string.font_name));

    labelPaint = new Paint();
    labelPaint.setTypeface(labelTypeface);
    labelPaint.setAntiAlias(true);
    labelPaint.setARGB(0xFF, 0xFF, 0xFF, 0xFF);

    msgPaint = new Paint();
    msgPaint.setTypeface(labelTypeface);
    msgPaint.setAntiAlias(true);
    msgPaint.setARGB(0xFF, 0xFF, 0xFF, 0xFF);

    statsPaint = new Paint();
    statsPaint.setTypeface(labelTypeface);
    statsPaint.setAntiAlias(true);
    statsPaint.setARGB(0xFF, 0xFF, 0xFF, 0xFF);
  }

  private static int getInt(int resId)
  {
    return Integer.parseInt(ZameApplication.self.getString(resId));
  }

  public static void surfaceSizeChanged(int width)
  {
    labelPaint.setTextSize(getInt(width < 480
      ? R.string.font_lbl_size_sm
      : (width < 800
        ? R.string.font_lbl_size_md
        : R.string.font_lbl_size_lg
      )
    ));

    msgPaint.setTextSize(getInt(width < 480
      ? R.string.font_msg_size_sm
      : (width < 800
        ? R.string.font_msg_size_md
        : R.string.font_msg_size_lg
      )
    ));

    statsPaint.setTextSize(getInt(width < 480
      ? R.string.font_stats_size_sm
      : (width < 800
        ? R.string.font_stats_size_md
        : R.string.font_stats_size_lg
      )
    ));
  }

  public static int getMessageLabelId(GL10 gl, int messageId)
  {
    if (currentMessageId == messageId) {
      return currentMessageLabelId;
    }

    String message;

    if ((Config.controlsType == Controls.TYPE_EXPERIMENTAL_A || Config.controlsType == Controls.TYPE_EXPERIMENTAL_B)
      && messageId == MSG_PRESS_ROTATE
    ) {
      message = ZameApplication.self.getString(R.string.lblm_slide_rotate);
    } else if (messageId > 0 && messageId < MSG_LAST) {
      message = ZameApplication.self.getString(MSG_MAP[messageId]);
    } else {
      message = String.format(Locale.US, "[message #%d]", messageId);
    }

    msgMaker.beginAdding(gl);
    currentMessageLabelId = msgMaker.add(gl, message, msgPaint);
    msgMaker.endAdding(gl);

    currentMessageId = messageId;
    currentMessageString = "";

    return currentMessageLabelId;
  }

  public static int getMessageLabelIdForString(GL10 gl, String message)
  {
    if (currentMessageString.equals(message)) {
      return currentMessageLabelId;
    }

    msgMaker.beginAdding(gl);
    currentMessageLabelId = msgMaker.add(gl, message, labelPaint);
    msgMaker.endAdding(gl);

    currentMessageId = 0;
    currentMessageString = message;

    return currentMessageLabelId;
  }

  public static void createLabels(GL10 gl)
  {
    if (maker == null) {
      maker = new LabelMaker(true, 512, 256);
    } else {
      maker.shutdown(gl);
    }

    maker.initialize(gl);
    maker.beginAdding(gl);
    map[LABEL_FPS] = maker.add(gl, ZameApplication.self.getString(R.string.lbl_fps), labelPaint);
    map[LABEL_CANT_OPEN] = maker.add(gl, ZameApplication.self.getString(R.string.lbl_cant_open_door), labelPaint);
    map[LABEL_NEED_BLUE_KEY] = maker.add(gl, ZameApplication.self.getString(R.string.lbl_need_blue_key), labelPaint);
    map[LABEL_NEED_RED_KEY] = maker.add(gl, ZameApplication.self.getString(R.string.lbl_need_red_key), labelPaint);
    map[LABEL_NEED_GREEN_KEY] = maker.add(gl, ZameApplication.self.getString(R.string.lbl_need_green_key), labelPaint);
    map[LABEL_SECRET_FOUND] = maker.add(gl, ZameApplication.self.getString(R.string.lbl_secret_found), labelPaint);
    maker.endAdding(gl);

    if (msgMaker == null) {
      msgMaker = new LabelMaker(true, 1024, 64);
    } else {
      msgMaker.shutdown(gl);
    }

    msgMaker.initialize(gl);
    currentMessageId = 0;
    currentMessageString = "";

    if (numeric == null) {
      numeric = new NumericSprite();
    } else {
      numeric.shutdown(gl);
    }

    numeric.initialize(gl, labelPaint);

    if (statsNumeric == null) {
      statsNumeric = new NumericSprite();
    } else {
      statsNumeric.shutdown(gl);
    }

    statsNumeric.initialize(gl, statsPaint);
  }
}




Java Source Code List

zame.game.AppConfig.java
zame.game.AppConfig.java
zame.game.Common.java
zame.game.ConfigZeemote.java
zame.game.ConfigZeemote.java
zame.game.Config.java
zame.game.GameActivityZeemoteHelper.java
zame.game.GameActivityZeemoteHelper.java
zame.game.GameActivity.java
zame.game.GamePreferencesActivity.java
zame.game.GamePreferencesActivity.java
zame.game.MenuActivityHelper.java
zame.game.MenuActivityHelper.java
zame.game.MenuActivity.java
zame.game.Renderer.java
zame.game.SoundManager.java
zame.game.ZameApplicationAnalyticsHelper.java
zame.game.ZameApplicationAnalyticsHelper.java
zame.game.ZameApplication.java
zame.game.ZameGame.java
zame.game.ZameJniRenderer.java
zame.game.engine.Action.java
zame.game.engine.AutoWall.java
zame.game.engine.Controls.java
zame.game.engine.Door.java
zame.game.engine.GameHelper.java
zame.game.engine.GameHelper.java
zame.game.engine.Game.java
zame.game.engine.Labels.java
zame.game.engine.LevelConfig.java
zame.game.engine.LevelRenderer.java
zame.game.engine.Level.java
zame.game.engine.Mark.java
zame.game.engine.Monster.java
zame.game.engine.Overlay.java
zame.game.engine.PortalTracer.java
zame.game.engine.State.java
zame.game.engine.Stats.java
zame.game.engine.TextureLoader.java
zame.game.engine.Weapons.java
zame.game.views.EndLevelView.java
zame.game.views.GameOverView.java
zame.game.views.GameView.java
zame.game.views.IZameView.java
zame.game.views.MenuViewHelper.java
zame.game.views.MenuViewHelper.java
zame.game.views.MenuView.java
zame.game.views.PreLevelView.java
zame.game.views.ZameGameView.java
zame.libs.FrameLayout.java
zame.libs.GLSurfaceView21.java
zame.libs.Grid.java
zame.libs.KeyMapPreference.java
zame.libs.LabelMaker.java
zame.libs.ListPreference.java
zame.libs.NumericSprite.java
zame.libs.SeekBarPreference.java
zame.promo.PromoView.java