예제 #1
0
  public WinnerScreen(ArrayList<Integer> playerPositions, Game game, Client client, Server server) {
    super(game, client, server);

    // Set input and viewpoint
    stage = new Stage(new StretchViewport(Constants.SCREENWIDTH, Constants.SCREENHEIGHT));
    Gdx.input.setInputProcessor(stage);

    // Unhides the cursor
    Gdx.input.setCursorCatched(false);

    this.playerPositions = playerPositions;

    // Set background
    rootTable.background(
        new TextureRegionDrawable(new TextureRegion(TextureManager.hostBackground)));
    rootTable.setFillParent(true);
    stage.addActor(rootTable);

    // Initialise Font
    FreeTypeFontGenerator.FreeTypeFontParameter fontOptions =
        new FreeTypeFontGenerator.FreeTypeFontParameter();
    fontOptions.size = 11;
    BitmapFont font = TextureManager.menuFont.generateFont(fontOptions);

    /** ------------------------LABEL STYLE------------------------* */
    Label.LabelStyle labelStyle = new Label.LabelStyle();
    fontOptions.size = 60;
    labelStyle.font = TextureManager.menuFont.generateFont(fontOptions);
    labelStyle.fontColor = Color.GOLD;

    /** ------------------------PLAYER DISPLAY WIDGET------------------------* */
    // Table options
    Table table = new Table();
    table.setFillParent(true);

    // P1 spawn field
    p1Field = new Container();
    p1Field.background(new TextureRegionDrawable(TextureManager.p1WalkingDownAnim.getKeyFrame(0)));
    table.add(p1Field).width(64).height(64);

    // P2 spawn field
    p2Field = new Container();
    p2Field.setVisible(false);
    p2Field.background(new TextureRegionDrawable(TextureManager.p2WalkingDownAnim.getKeyFrame(0)));
    table.add(p2Field).width(64).height(64).padLeft(96);

    // P3 spawn field
    p3Field = new Container();
    p3Field.setVisible(false);
    p3Field.background(new TextureRegionDrawable(TextureManager.p3WalkingDownAnim.getKeyFrame(0)));
    table.add(p3Field).width(64).height(64).padLeft(96);

    // P4 spawn field
    p4Field = new Container();
    p4Field.setVisible(false);
    p4Field.background(new TextureRegionDrawable(TextureManager.p4WalkingDownAnim.getKeyFrame(0)));
    table.add(p4Field).width(64).height(64).padLeft(96);

    // Stage & group options
    joinedPlayerGroup.addActor(table);
    joinedPlayerGroup.setPosition(443, 150);
    stage.addActor(joinedPlayerGroup);

    /** ------------------------PLAYER HIGHLIGHT WIDGET------------------------* */
    // Table options
    Table table2 = new Table();
    table2.setFillParent(true);

    // P1 spawn field
    p1FieldHighlight = new Container();
    p1FieldHighlight.setVisible(false);
    p1FieldHighlight.background(
        new TextureRegionDrawable(new TextureRegion(TextureManager.playerMarker)));
    table2.add(p1FieldHighlight).width(80).height(77);

    // P2 spawn field
    p2FieldHighlight = new Container();
    p2FieldHighlight.setVisible(false);
    p2FieldHighlight.background(
        new TextureRegionDrawable(new TextureRegion(TextureManager.playerMarker)));
    table2.add(p2FieldHighlight).width(80).height(77).padLeft(80);

    // P3 spawn field
    p3FieldHighlight = new Container();
    p3FieldHighlight.setVisible(false);
    p3FieldHighlight.background(
        new TextureRegionDrawable(new TextureRegion(TextureManager.playerMarker)));
    table2.add(p3FieldHighlight).width(80).height(77).padLeft(80);

    // P4 spawn field
    p4FieldHighlight = new Container();
    p4FieldHighlight.setVisible(false);
    p4FieldHighlight.background(
        new TextureRegionDrawable(new TextureRegion(TextureManager.playerMarker)));
    table2.add(p4FieldHighlight).width(80).height(77).padLeft(80);

    // Stage & group options
    playerhighlightWidget.addActor(table2);
    playerhighlightWidget.setPosition(442, 152);
    stage.addActor(playerhighlightWidget);

    /** ------------------------LABELS------------------------* */

    // Titel
    titel = new Label("", labelStyle);
    titel.setAlignment(Align.center);
    titel.setPosition((Constants.SCREENWIDTH - titel.getWidth()) / 2 + 50, 385);
    stage.addActor(titel);

    // If you are the winner
    if (Constants.PLAYERID == playerPositions.get(playerPositions.size() - 1)) {
      titel.setText("YOU WON!");
      isWinner = true;
    } else {
      isWinner = false;
      titel.setText("YOU LOOSE!");
      titel.setColor(Color.RED);
    }

    if (-1 == playerPositions.get(playerPositions.size() - 1)) {
      titel.setText("DRAW!");
      titel.setColor(Color.DARK_GRAY);
      isWinner = false;
    }

    Table positionTable = new Table();
    positionTable.setFillParent(true);

    p1Position = new Label("", labelStyle);
    p1Position.setAlignment(Align.center);

    p2Position = new Label("", labelStyle);
    p2Position.setAlignment(Align.center);

    p3Position = new Label("", labelStyle);
    p3Position.setAlignment(Align.center);

    p4Position = new Label("", labelStyle);
    p4Position.setAlignment(Align.center);

    positionTable.add(p1Position).width(64).height(64);
    positionTable.add(p2Position).width(64).height(64).padLeft(96);
    positionTable.add(p3Position).width(64).height(64).padLeft(96);
    positionTable.add(p4Position).width(64).height(64).padLeft(96);

    positionPlayerWidget.addActor(positionTable);
    positionPlayerWidget.setPosition(443, 230);
    stage.addActor(positionPlayerWidget);

    /** ------------------------MUSIC------------------------* */
    if (isWinner == false) {
      AudioManager.setCurrentMusic(AudioManager.getLooserMusic());
      AudioManager.getCurrentMusic().setLooping(true);
      AudioManager.getCurrentMusic().play();
      AudioManager.getCurrentMusic().setVolume(AudioManager.getMusicVolume() * 4);
    } else {
      AudioManager.setCurrentMusic(AudioManager.getWinnerMusic());
      AudioManager.getCurrentMusic().setLooping(true);
      AudioManager.getCurrentMusic().play();
      AudioManager.getCurrentMusic().setVolume(AudioManager.getMusicVolume() * 6);
    }

    /** ------------------------BUTTONS------------------------* */
    TextButton.TextButtonStyle textButtonStyleBack = new TextButton.TextButtonStyle();
    textButtonStyleBack.font = font;
    textButtonStyleBack.up = backSkin.getDrawable("button_up");
    textButtonStyleBack.down = backSkin.getDrawable("button_down");
    textButtonStyleBack.over = backSkin.getDrawable("button_checked");

    // Back button
    backButton = new TextButton("", textButtonStyleBack);
    backButton.setPosition(0, Constants.SCREENHEIGHT - backButton.getHeight() + 7);
    stage.addActor(backButton);

    renderPlayers();

    // Add click listener --> Back button
    backButton.addListener(
        new ChangeListener() {
          @Override
          public void changed(ChangeListener.ChangeEvent event, Actor actor) {
            // Add click musik
            AudioManager.playClickSound();

            // Wait till sound is done
            try {
              Thread.sleep(100);

            } catch (InterruptedException ex) {

            }

            if (isWinner) {
              AudioManager.getCurrentMusic().stop();
            } else {
              AudioManager.getCurrentMusic().stop();
            }

            server.stopServer();
            game.setScreen(new MenuScreen(game, client, server));
          }
        });
  }
  public HotbarInventoryView(
      Stage stage,
      Skin skin,
      Inventory hotbarInventory,
      Inventory inventory,
      DragAndDrop dragAndDrop,
      OreClient client) {
    m_skin = skin;
    m_inventory = inventory;
    m_client = client;
    m_stage = stage;

    m_hotbarInventory = hotbarInventory;
    // attach to the inventory model
    m_hotbarInventory.addListener(this);

    container = new Table(m_skin);
    container.setFillParent(true);
    container.top().left().setSize(800, 100);
    container.padLeft(10).padTop(10);

    container.defaults().space(4);

    stage.addActor(container);

    Image dragImage = new Image();
    dragImage.setSize(32, 32);

    for (byte i = 0; i < Inventory.maxHotbarSlots; ++i) {

      Image slotImage = new Image();

      SlotElement element = new SlotElement();
      m_slots[i] = element;

      element.itemImage = slotImage;

      Table slotTable = new Table(m_skin);
      element.table = slotTable;
      slotTable.setTouchable(Touchable.enabled);
      slotTable.addListener(new SlotClickListener(this, i));
      slotTable.addListener(new SlotInputListener(this, i));

      slotTable.add(slotImage);
      slotTable.background("default-pane");

      slotTable.row();

      Label itemCount = new Label(null, m_skin);
      slotTable.add(itemCount).bottom().fill();
      element.itemCountLabel = itemCount;

      //            container.add(slotTable).size(50, 50);
      container.add(slotTable).fill().size(50, 50);
      setHotbarSlotVisible(i, false);

      dragAndDrop.addSource(new HotbarDragSource(slotTable, i, dragImage, this));

      dragAndDrop.addTarget(new HotbarDragTarget(slotTable, i, this));
    }

    m_tooltip = new Label(null, m_skin);
    stage.addActor(m_tooltip);
  }