Ejemplo n.º 1
0
 /**
  * zoom to the card before or after the current zoomed card (direction = 1 for next, -1 for
  * previous)
  */
 private void changeZoomedCard(int direction) {
   stopMakingSpace();
   zoomCard.addAction(Actions.scaleTo(1.0f, 1.0f, 0.2f, Interpolation.pow2));
   addCard(zoomCard, zoomReturnIndex);
   makeSpace(zoomReturnIndex + direction);
   zoomCard = (CardGroup) cards.getChildren().get(zoomReturnIndex + direction);
   zoomCard.clearActions();
   zoomCard.remove();
   addActor(zoomCard);
   zoomCard.setScale(3.0f);
   zoomCard.setPosition(600, 100);
   zoomReturnIndex += direction;
   updateZoomControls();
 }
Ejemplo n.º 2
0
 /** unzooms the currently zoomed card */
 private void unzoom() {
   stopMakingSpace();
   zoomCard.setTouchable(Touchable.enabled);
   zoomCard.addAction(Actions.scaleTo(1.0f, 1.0f, 0.2f, Interpolation.pow2));
   addCard(zoomCard, zoomReturnIndex);
   zoomCard = null;
   for (Actor actor : getChildren()) {
     actor.setTouchable(Touchable.enabled);
   }
   for (Actor actor : cards.getChildren()) {
     actor.setTouchable(Touchable.enabled);
   }
   zoomGroup.setTouchable(Touchable.disabled);
   zoomGroup.setVisible(false);
 }
Ejemplo n.º 3
0
  /**
   * brings the card up to the front and center, leaving a space where it belongs in the hand.
   * Nothing other than the card and its controls can be clicked during a zoom. Tapping the card
   * unzooms it. There also is a cancel, play, and rotate button, and arrows to see the next and
   * previous cards in the hand.
   *
   * @param toAdd card to zoom in on
   */
  private void zoomCard(CardGroup toAdd) {
    zoomCard = toAdd;
    // remove toAdd from the hand and add it to the root
    zoomReturnIndex = cards.getChildren().indexOf(toAdd, true);
    zoomCard.remove();
    addActor(zoomCard);
    makeSpace(zoomReturnIndex);

    zoomCard.getActions().clear();
    // blow the card up
    zoomCard.addAction(Actions.scaleTo(3.0f, 3.0f, 0.2f, Interpolation.pow2));
    // move it
    zoomCard.addAction(Actions.moveTo(600, 100, 0.2f, Interpolation.pow2));

    // make only the zoom elements touchable
    for (Actor actor : getChildren()) {
      actor.setTouchable(Touchable.disabled);
    }
    zoomGroup.setTouchable(Touchable.enabled);
    zoomGroup.setVisible(true);
    updateZoomControls();
  }
Ejemplo n.º 4
0
  /**
   * animate the card being added to the hand, and add it to the hand. Removes the card from its
   * current parent and adds it to this group. Adds it to the right of the current hand.
   *
   * @param toAdd cardgroup to add to the hand
   * @param index index to add the card at (left is 0)
   */
  public void addCard(final CardGroup toAdd, int index) {
    // click events for the card
    toAdd.getListeners().clear();

    toAdd.addListener(
        new DragListener() {
          public int returnIndex = -1;
          public float offsetX;
          public float offsetY;
          public boolean zoomed = false;

          @Override
          public void dragStart(InputEvent event, float x, float y, int pointer) {
            Vector2 coords = toAdd.localToParentCoordinates(new Vector2(x, y));
            offsetX = coords.x - toAdd.getX();
            offsetY = coords.y - toAdd.getY();
            if (getTouchDownY() > y) {
              if (!toAdd.hasRotated) {
                toAdd.rotate();
                toAdd.hasRotated = true;
              }
            }
          }

          @Override
          public void dragStop(InputEvent event, float x, float y, int pointer) {
            if (toAdd.dragged) {
              stopMakingSpace();
              addCard(toAdd, returnIndex);
            }
          }

          @Override
          public void drag(InputEvent event, float x, float y, int pointer) {
            // Only start dragging the card if we are not dragging down or rotated
            if ((toAdd.dragged || getTouchDownY() <= y) && !toAdd.hasRotated) {
              if (toAdd.dragged == false) {
                toAdd.dragged = true;
                returnIndex = cards.getChildren().indexOf(toAdd, true);
                removeCard(toAdd);
                addActor(toAdd);
              }
              Vector2 coords = toAdd.localToParentCoordinates(new Vector2(x, y));
              toAdd.setPosition(coords.x - offsetX, coords.y - offsetY);

              // check for making space in the hand
              boolean stillNeedsSpace = false;
              for (int i = 0; i < cards.getChildren().size; i++) {
                Actor card = cards.getChildren().get(i);
                Rectangle cardBounds =
                    new Rectangle(card.getX(), card.getY(), card.getWidth(), card.getHeight());
                Rectangle thisBounds =
                    new Rectangle(toAdd.getX(), toAdd.getY(), toAdd.getWidth(), toAdd.getHeight());
                if (cardBounds.overlaps(thisBounds)) {
                  stillNeedsSpace = true;
                  if (card != invisibleCard) {
                    // figure out which side. If the center of the dragged card is to the right
                    // of the center of the collided with card, make space to the right
                    if ((thisBounds.getX() + thisBounds.getWidth() / 2)
                        > (cardBounds.getX() + cardBounds.getWidth() / 2)) {
                      returnIndex = i + 1;
                      makeSpace(i + 1);
                    } else {
                      returnIndex = i;
                      makeSpace(i);
                    }
                  }
                  break;
                }
              }
              if (!stillNeedsSpace) {
                stopMakingSpace();
              }
            }
          }
        });

    toAdd.addListener(
        new InputListener() {

          @Override
          public boolean touchDown(InputEvent event, float x, float y, int pointer, int button) {
            toAdd.hasRotated = false;
            toAdd.dragged = false;
            return true;
          }

          @Override
          public void touchUp(InputEvent event, float x, float y, int pointer, int button) {
            if (!toAdd.dragged && !toAdd.hasRotated) {
              zoomCard(toAdd);
            }
          }
        });

    // save the old positions of the cards
    List<Vector2> oldPositions = getPositions(cards.getChildren());
    oldPositions.add(index, new Vector2(toAdd.getX(), toAdd.getY()));

    // Determine what the new positions would be
    // by adding them to a horizontal group and checking their positions
    HorizontalGroup newGroup =
        new HorizontalGroup()
            .space(calculateSpacing(cards.getChildren().size + 1, toAdd.getWidth()));
    newGroup.align(Align.bottom);

    cards.addActorAt(index, toAdd);

    while (cards.getChildren().size > 0) {
      newGroup.addActor(cards.getChildren().get(0));
    }
    newGroup.layout();

    List<Vector2> newPositions = getPositions(newGroup.getChildren());
    // calculate what is needed to center the cards
    float centerOffset = UIConstants.WORLD_WIDTH / 2 - newGroup.getPrefWidth() / 2;
    // remove them from the horizontal group and add them back to the normal group so it doesn't try
    // to move them around
    while (newGroup.getChildren().size > 0) {
      cards.addActor(newGroup.getChildren().get(0));
    }

    interpolateActorPositions(
        cards.getChildren(), oldPositions, newPositions, centerOffset, Interpolation.pow2, 0.5f);
  }