@Override
  public void render() {
    Gdx.gl.glClearColor(
        background.rgb.getRed() / 255f,
        background.rgb.getGreen() / 255f,
        background.rgb.getBlue() / 255f,
        background.rgb.getAlpha() / 255f);

    Gdx.gl.glClear(GL10.GL_COLOR_BUFFER_BIT);

    boolean hasUserInput = false;
    if (input.getText() != null && input.getText().length() != 0) hasUserInput = true;
    final String text =
        hasUserInput ? input.getText() : "The quick brown fox jumps over the lazy dog";

    float scale = scaleSlider.getValue();

    cam.setToOrtho(false, Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
    batch.setProjectionMatrix(cam.combined);

    batch.getProjectionMatrix().scale(scale, scale, 0.0f);

    //		batch.getTransformMatrix().scale(scale, scale, 0.0f);

    if (fonts != null) {
      batch.begin();

      int x = 5;
      int y = 0;

      for (FontElement e : fonts) {
        y += e.font.getLineHeight() + 5;
        String str = hasUserInput ? text : e.name + " " + e.size + ": " + text;
        e.font.draw(batch, str, x, y);
      }

      batch.end();
    }

    input.setY(Gdx.graphics.getHeight() - input.getHeight() - 5);
    labelInput.setY(Gdx.graphics.getHeight() - input.getHeight() - 5);

    labelScale.setY(labelInput.getY() - labelInput.getHeight() - 5);
    scaleSlider.setY(input.getY() - input.getHeight() - 5);
    scaleAmt.setY(scaleSlider.getY());

    linearFiltering.setY(scaleSlider.getY() - scaleSlider.getHeight() - 10);

    stage.act();
    stage.draw();
  }
Beispiel #2
0
 /** returns the title and positions it in the default position */
 public Label getTitle() {
   Label title = new Label(Constants.TITLE, new LabelStyle(new BitmapFont(), Color.RED));
   title.setFontScale(2);
   title.setX(Gdx.graphics.getWidth() / 2 - title.getWidth());
   float offsetTitle = Gdx.graphics.getHeight() * 0.1f;
   title.setY(Gdx.graphics.getHeight() / 2 + offsetTitle);
   return title;
 }
  @Override
  public void create(Object... args) {
    super.create(args);

    Label versionLabel =
        FontManager.Default.makeLabel(
            String.format(
                "v%s (%s, %s)",
                TowerConsts.VERSION,
                TowerConsts.GIT_SHA.substring(0, 8),
                TowerGameService.getDeviceOSMarketName()));
    versionLabel.setColor(Color.LIGHT_GRAY);
    versionLabel.setX(getStage().getWidth() - versionLabel.getWidth() - 5);
    versionLabel.setY(getStage().getHeight() - versionLabel.getHeight() - 5);
    addActor(versionLabel);
  }
  /**
   * Creates a new LoadingScreenView.
   *
   * <p><b>Note:</b> This will load textures directly, and it is therefore important to remember to
   * dispose this view!
   */
  public LoadingScreenView() {
    // Background
    screenBgTexture = new Texture(Gdx.files.internal("data/loadingScreenBg.png"));
    Image screenBg = new Image(screenBgTexture);
    screenBg.setFillParent(true);
    addActor(screenBg);

    // The loading bar background
    loadBarBgTexture = new Texture(Gdx.files.internal("data/loadingBarBg.png"));
    loadBarBgTexture.setFilter(TextureFilter.Linear, TextureFilter.Linear);
    loadBarBg = new Image(loadBarBgTexture);
    loadBarBg.setY(LOAD_BAR_BOTTOM_MARGIN);
    loadBarBg.setWidth(LOAD_BAR_MAX_WIDTH);
    loadBarBg.setX(1280 / 2 - LOAD_BAR_MAX_WIDTH / 2);
    addActor(loadBarBg);

    // The loading bar
    loadBarTexture = new Texture(Gdx.files.internal("data/loadingBar.png"));
    loadBarTexture.setFilter(TextureFilter.Linear, TextureFilter.Linear);
    loadBar = new Image(loadBarTexture);
    loadBar.setY(LOAD_BAR_BOTTOM_MARGIN);
    loadBar.setX(loadBarBg.getX());
    loadBar.setWidth(LOAD_BAR_MAX_WIDTH);
    addActor(loadBar);

    // Progress label
    progressLabelFont = new BitmapFont(Gdx.files.internal("data/fonts/arial_bold_32.fnt"), false);
    progressLabelFont
        .getRegion()
        .getTexture()
        .setFilter(TextureFilter.Linear, TextureFilter.Linear);
    LabelStyle ls = new LabelStyle(progressLabelFont, Color.BLACK);
    progressLabel = new Label("", ls);
    progressLabel.setY(65);
    addActor(progressLabel);
  }
Beispiel #5
0
  public void initView() {
    clear();
    float currPos = 0;
    for (int i = 0; i < tabs.size(); i++) {
      boolean isSelected = false;
      if (i == selectedTabIndex) isSelected = true;
      String imgName = "tab";
      if (isSelected) {
        imgName = "tabS";
      }
      Image img = new Image(s.textureManager.getEditorAsset(imgName));
      img.setX(currPos);
      img.setY(0);

      Label lbl = new Label(tabs.get(i), s.textureManager.editorSkin);
      lbl.setX(currPos + 6);
      lbl.setY(2);
      lbl.setTouchable(Touchable.disabled);

      img.setScaleX(lbl.getWidth() + 12);
      currPos += lbl.getWidth() + 12;

      addActor(img);
      addActor(lbl);

      Image sep = new Image(s.textureManager.getEditorAsset("tabSep"));
      sep.setX(img.getX() + img.getScaleX());
      addActor(sep);
      currPos += 1;

      if (isSelected) {
        lbl.setColor(1, 1, 1, 1);
      } else {
        lbl.setColor(1, 1, 1, 0.65f);
      }

      final int currIndex = i;

      img.addListener(
          new ClickListener() {
            public void clicked(InputEvent event, float x, float y) {
              selectedTabIndex = currIndex;
              initView();
              if (tabEventListener != null) {
                tabEventListener.tabOpened(currIndex);
              }
            }
          });

      setHeight(img.getHeight());
    }

    float currWidth = currPos;
    if (getWidth() > currWidth) {
      float diff = getWidth() - currWidth;
      Image rest = new Image(s.textureManager.getEditorAsset("tab"));
      rest.setX(currPos);
      rest.setScaleX(diff);
      addActor(rest);
    }
  }
Beispiel #6
0
  @Override
  public void onSelectionSucceeded(final List<BallActor> selection) {
    // Extract the data from the selection.
    List<Ball> balls = new ArrayList<>();
    for (BallActor selectedBall : selection) balls.add(selectedBall.getBall());
    final Bounds bounds = Bounds.fromBallList(balls);

    // Change the colors of the selected region.
    board.addAction(
        Actions.sequence(
            board.hideRegion(bounds),
            Actions.run(
                new Runnable() {
                  @Override
                  public void run() {
                    for (BallActor selectedBall : selection) {
                      selectedBall.setColor(Color.WHITE);
                    }
                    generate(bounds);
                    // Reset the cheat
                    game.getState().setCheatSeen(false);
                    game.getState().setWiggledBounds(null);
                  }
                })));

    // Give some score to the user.
    ScoreCalculator calculator = new ScoreCalculator(game.getState().getBoard(), bounds);
    int givenScore = calculator.calculate();
    game.getState().addScore(givenScore);
    score.giveScore(givenScore);

    // Put information about this combination in the stats.
    int rows = bounds.maxY - bounds.minY + 1;
    int cols = bounds.maxX - bounds.minX + 1;
    String size = Math.max(rows, cols) + "x" + Math.min(rows, cols);
    game.statistics.getSizesData().incrementValue(size);

    BallColor color = board.getBall(bounds.minX, bounds.minY).getBall().getColor();
    game.statistics.getColorData().incrementValue(color.toString().toLowerCase());
    game.statistics.getTotalData().incrementValue("balls", rows * cols);
    game.statistics.getTotalData().incrementValue("combinations");

    // Now, display the score to the user. If the combination is a
    // PERFECT combination, just display PERFECT.
    int boardSize = game.getState().getBoard().getSize() - 1;
    if (bounds.equals(new Bounds(0, 0, boardSize, boardSize))) {
      // Give score
      Label label = new Label("PERFECT", game.getSkin(), "monospace");
      label.setX((getStage().getViewport().getWorldWidth() - label.getWidth()) / 2);
      label.setY((getStage().getViewport().getWorldHeight() - label.getHeight()) / 2);
      label.setFontScale(3);
      label.setAlignment(Align.center);
      label.addAction(Actions.sequence(Actions.moveBy(0, 80, 0.5f), Actions.removeActor()));
      getStage().addActor(label);
      game.player.playSound(SoundCode.PERFECT);

      // Give time
      float givenTime = Constants.SECONDS - timer.getSeconds();
      timer.giveTime(givenTime, 4f);
    } else {
      // Was special?
      boolean special = givenScore != rows * cols;
      // Give score
      showPartialScore(givenScore, bounds, special);
      game.player.playSound(SoundCode.SUCCESS);

      // Give time
      float givenTime = 4f;
      timer.giveTime(givenTime, 0.25f);
    }
  }