Esempio n. 1
0
  private void removeCard(Actor toRemove) {
    int removeIndex = cards.getChildren().indexOf(toRemove, true);

    // save the old positions of the cards
    SnapshotArray<Actor> currentCards = cards.getChildren();
    currentCards.removeIndex(removeIndex);
    List<Vector2> oldPositions = getPositions(currentCards);

    // 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, toRemove.getWidth()));
    newGroup.align(Align.bottom);
    cards.removeActor(toRemove);
    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);
  }
Esempio n. 2
0
  /**
   * makes space for a card (adds an invisible card)
   *
   * @param index index to make space for a card at
   */
  private void makeSpace(int index) {
    if (cards.getChildren().size > 0) {
      stopMakingSpace();
      invisibleCard = new Group();
      invisibleCard.setBounds(
          0, 0, cards.getChildren().get(0).getWidth(), cards.getChildren().get(0).getHeight());

      // save the old positions of the cards
      List<Vector2> oldPositions = getPositions(cards.getChildren());
      oldPositions.add(index, new Vector2(invisibleCard.getX(), invisibleCard.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, invisibleCard.getWidth()));
      newGroup.align(Align.bottom);

      cards.addActorAt(index, invisibleCard);

      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));
      }

      // interpolate all but the invisible card
      cards
          .getChildren()
          .get(index)
          .setPosition(newPositions.get(index).x, newPositions.get(index).y);
      cards.removeActor(invisibleCard);
      oldPositions.remove(index);
      newPositions.remove(index);

      interpolateActorPositions(
          cards.getChildren(),
          oldPositions,
          newPositions,
          centerOffset,
          Interpolation.linear,
          0.2f);
      cards.addActor(invisibleCard);
    }
  }
Esempio n. 3
0
 public void removeChild(Actor parent, Actor child) {
   ((Group) parent).removeActor(child);
 }
Esempio n. 4
0
 /**
  * Removes this actor from its parent, if it has a parent.
  *
  * @see Group#removeActor(Actor)
  */
 public boolean remove() {
   if (parent != null) return parent.removeActor(this);
   return false;
 }
 public void removeTransfert(TransfertActor actor) {
   groupTransferts.removeActor(actor);
 }