Beispiel #1
0
  /**
   * @param group an empty group to be the parent
   * @return the group with the current selection
   */
  public Group createGroup(Group group) {
    // New group has the same transformation as this
    group.setBounds(getX(), getY(), getWidth(), getHeight());
    group.setOrigin(getOriginX(), getOriginY());
    group.setRotation(getRotation());
    group.setScale(getScaleX(), getScaleY());

    // Each children in the group must be contained by the new group
    Array<Actor> children = getChildren();
    children.sort(
        new Comparator<Actor>() {
          @Override
          public int compare(Actor actor, Actor actor2) {
            return ((SelectionGhost) actor).getRepresentedActor().getZIndex()
                - ((SelectionGhost) actor2).getRepresentedActor().getZIndex();
          }
        });

    for (Actor actor : children) {
      SelectionGhost ghost = (SelectionGhost) actor;
      Actor representedActor = ghost.getRepresentedActor();
      representedActor.setPosition(ghost.getX(), ghost.getY());
      representedActor.setRotation(ghost.getRotation());
      representedActor.setScale(ghost.getScaleX(), ghost.getScaleY());
      group.addActor(representedActor);
    }
    return group;
  }
Beispiel #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);
    }
  }
Beispiel #3
0
  /** Adjusts the position and size of the given group to its children */
  public static void adjustGroup(Actor root) {
    if (!(root instanceof Group)) {
      return;
    }

    Group group = (Group) root;
    if (group.getChildren().size == 0) {
      return;
    }

    Vector2 origin = Pools.obtain(Vector2.class);
    Vector2 size = Pools.obtain(Vector2.class);
    Vector2 tmp3 = Pools.obtain(Vector2.class);
    Vector2 tmp4 = Pools.obtain(Vector2.class);

    calculateBounds(group.getChildren(), origin, size);

    /*
     * minX and minY are the new origin (new 0, 0), so everything inside the
     * group must be translated that much.
     */
    for (Actor actor : group.getChildren()) {
      actor.setPosition(actor.getX() - origin.x, actor.getY() - origin.y);
    }

    /*
     * Now, we calculate the current origin (0, 0) and the new origin (minX,
     * minY), and group is translated by that difference.
     */
    group.localToParentCoordinates(tmp3.set(0, 0));
    group.localToParentCoordinates(tmp4.set(origin.x, origin.y));
    tmp4.sub(tmp3);
    group.setBounds(group.getX() + tmp4.x, group.getY() + tmp4.y, size.x, size.y);
    group.setOrigin(size.x / 2.0f, size.y / 2.0f);

    Pools.free(origin);
    Pools.free(size);
    Pools.free(tmp3);
    Pools.free(tmp4);
  }
Beispiel #4
0
  public void create() {
    WIDTH = Gdx.graphics.getWidth();
    HEIGHT = Gdx.graphics.getHeight();

    stage = new Stage();
    skin = new Skin(Gdx.files.internal("data/mainMenu/uiskin.json"));

    Table table = new Table();
    table.setFillParent(true);
    table.setSize(WIDTH, HEIGHT);

    ipTextField = new TextField("lodow.net", skin);
    portTextField = new TextField("4242", skin);

    Label ipLabel = new Label("Ip   : ", skin);
    Label portLabel = new Label("port : ", skin);

    connectionButton = new TextButton("Connect", skin);
    connectionButton.setDisabled(true);
    connectionButton.addListener(new ConnectListener(CONNECT_BUTTON_ID));

    background = new Group();
    background.setBounds(0, 0, WIDTH, HEIGHT);
    background.addActor(new Image(new Texture(Gdx.files.internal("data/mainMenu/zappy_main.png"))));

    Texture cross = new Texture(Gdx.files.internal("data/mainMenu/remove_cross.png"));

    Image cross_ip = new Image(cross);
    cross_ip.addListener(
        new ClickListener() {
          public boolean touchDown(InputEvent event, float x, float y, int pointer, int button) {
            ipTextField.setText("");
            return true;
          }
        });

    Image cross_port = new Image(cross);
    cross_port.addListener(
        new ClickListener() {
          public boolean touchDown(InputEvent event, float x, float y, int pointer, int button) {
            portTextField.setText("");
            return true;
          }
        });

    table.add(ipLabel).padBottom(20);
    table.add(ipTextField).width(WIDTH / 4).padBottom(20).padRight(20);
    table.add(cross_ip).padBottom(20);
    table.row();
    table.add(portLabel).padBottom(20);
    table.add(portTextField).width(WIDTH / 4).padBottom(40).padRight(20);
    table.add(cross_port).padBottom(30);
    table.row();
    table.add(connectionButton).colspan(5).width(WIDTH / 4);
    table.left().bottom().padBottom(150);

    stage.addActor(background);
    stage.addActor(table);

    batch = new SpriteBatch();

    Gdx.input.setInputProcessor(stage);

    Assets.menuMusic.play();
  }
Beispiel #5
0
  @Override
  public void create() {
    texture = new Texture(Gdx.files.internal("data/badlogicsmall.jpg"));
    texture.setFilter(TextureFilter.Linear, TextureFilter.Linear);
    font = new BitmapFont(Gdx.files.internal("data/arial-15.fnt"), false);

    stage = new Stage(new ScreenViewport());

    float loc = (NUM_SPRITES * (32 + SPACING) - SPACING) / 2;
    for (int i = 0; i < NUM_GROUPS; i++) {
      Group group = new Group();
      group.setX((float) Math.random() * (stage.getWidth() - NUM_SPRITES * (32 + SPACING)));
      group.setY((float) Math.random() * (stage.getHeight() - NUM_SPRITES * (32 + SPACING)));
      group.setOrigin(loc, loc);

      fillGroup(group, texture);
      stage.addActor(group);
    }

    uiTexture = new Texture(Gdx.files.internal("data/ui.png"));
    uiTexture.setFilter(TextureFilter.Linear, TextureFilter.Linear);
    ui = new Stage(new ScreenViewport());

    Image blend = new Image(new TextureRegion(uiTexture, 0, 0, 64, 32));
    blend.setAlign(Align.center);
    blend.setScaling(Scaling.none);
    blend.addListener(
        new InputListener() {
          public boolean touchDown(InputEvent event, float x, float y, int pointer, int button) {
            if (stage.getBatch().isBlendingEnabled()) stage.getBatch().disableBlending();
            else stage.getBatch().enableBlending();
            return true;
          }
        });
    blend.setY(ui.getHeight() - 64);

    Image rotate = new Image(new TextureRegion(uiTexture, 64, 0, 64, 32));
    rotate.setAlign(Align.center);
    rotate.setScaling(Scaling.none);
    rotate.addListener(
        new InputListener() {
          public boolean touchDown(InputEvent event, float x, float y, int pointer, int button) {
            rotateSprites = !rotateSprites;
            return true;
          }
        });
    rotate.setPosition(64, blend.getY());

    Image scale = new Image(new TextureRegion(uiTexture, 64, 32, 64, 32));
    scale.setAlign(Align.center);
    scale.setScaling(Scaling.none);
    scale.addListener(
        new InputListener() {
          public boolean touchDown(InputEvent event, float x, float y, int pointer, int button) {
            scaleSprites = !scaleSprites;
            return true;
          }
        });
    scale.setPosition(128, blend.getY());

    {
      Actor shapeActor =
          new Actor() {
            public void drawDebug(ShapeRenderer shapes) {
              shapes.set(ShapeType.Filled);
              shapes.setColor(getColor());
              shapes.rect(
                  getX(),
                  getY(),
                  getOriginX(),
                  getOriginY(),
                  getWidth(),
                  getHeight(),
                  getScaleX(),
                  getScaleY(),
                  getRotation());
            }
          };
      shapeActor.setBounds(0, 0, 100, 150);
      shapeActor.setOrigin(50, 75);
      shapeActor.debug();
      sprites.add(shapeActor);

      Group shapeGroup = new Group();
      shapeGroup.setBounds(300, 300, 300, 300);
      shapeGroup.setOrigin(50, 75);
      shapeGroup.setTouchable(Touchable.childrenOnly);
      shapeGroup.addActor(shapeActor);
      stage.addActor(shapeGroup);
    }

    ui.addActor(blend);
    ui.addActor(rotate);
    ui.addActor(scale);

    fps = new Label("fps: 0", new Label.LabelStyle(font, Color.WHITE));
    fps.setPosition(10, 30);
    fps.setColor(0, 1, 0, 1);
    ui.addActor(fps);

    renderer = new ShapeRenderer();
    Gdx.input.setInputProcessor(this);
  }
Beispiel #6
0
  public HandGroup(GameEventNotifier notifier) {
    super(notifier);

    cards = new Group();
    cards.setBounds(0, 0, UIConstants.WORLD_WIDTH, UIConstants.WORLD_HEIGHT / 2);

    addActor(cards);

    // set up the images and buttons for the zoom menu
    selectButton = new Image(selectTexture);
    selectButton.setScale(1.5f);
    selectButton.setPosition(220, 700);
    cancelButton = new Image(cancelTexture);
    cancelButton.setScale(1.5f);
    cancelButton.setPosition(220, 100);
    cancelButton.addListener(
        new InputListener() {
          @Override
          public boolean touchDown(InputEvent event, float x, float y, int pointer, int button) {
            // return the zoomed card
            unzoom();
            return true;
          }
        });
    nextCardImage = new Image(arrowTexture);
    nextCardImage.setScale(2f);
    nextCardImage.setPosition(1200, 300);
    nextCardImage.addListener(
        new InputListener() {
          @Override
          public boolean touchDown(InputEvent event, float x, float y, int pointer, int button) {
            changeZoomedCard(1);
            return true;
          }
        });

    previousCardImage = new Image(arrowTexture);
    previousCardImage.rotateBy(180);
    previousCardImage.setScale(2f);
    previousCardImage.setPosition(500, 400);
    previousCardImage.addListener(
        new InputListener() {
          @Override
          public boolean touchDown(InputEvent event, float x, float y, int pointer, int button) {
            changeZoomedCard(-1);
            return true;
          }
        });
    rotateImage = new Image(rotateTexture);
    rotateImage.setScale(0.5f);
    rotateImage.setPosition(350, 500);
    rotateImage.addListener(
        new InputListener() {
          @Override
          public boolean touchDown(InputEvent event, float x, float y, int pointer, int button) {
            zoomCard.rotate();
            return true;
          }
        });
    zoomGroup = new Group();
    zoomGroup.addActor(selectButton);
    zoomGroup.addActor(cancelButton);
    zoomGroup.addActor(nextCardImage);
    zoomGroup.addActor(previousCardImage);
    zoomGroup.addActor(rotateImage);
    zoomGroup.setTouchable(Touchable.disabled);
    zoomGroup.setVisible(false);

    addActor(zoomGroup);
  }