scenes.GameSummary.java Source code

Java tutorial

Introduction

Here is the source code for scenes.GameSummary.java

Source

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package scenes;

import com.badlogic.gdx.ApplicationAdapter;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.graphics.g2d.BitmapFont;
import com.badlogic.gdx.graphics.g2d.GlyphLayout;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.badlogic.gdx.graphics.g2d.TextureAtlas;
import com.badlogic.gdx.graphics.g2d.freetype.FreeTypeFontGenerator;
import com.badlogic.gdx.scenes.scene2d.InputEvent;
import com.badlogic.gdx.scenes.scene2d.Stage;
import com.badlogic.gdx.scenes.scene2d.ui.Label;
import com.badlogic.gdx.scenes.scene2d.ui.Skin;
import com.badlogic.gdx.scenes.scene2d.ui.Table;
import com.badlogic.gdx.scenes.scene2d.ui.TextButton;
import com.badlogic.gdx.scenes.scene2d.utils.ClickListener;
import com.badlogic.gdx.utils.Align;
import com.circle.game.Circle;
import com.circle.game.Config;
import match.Match;
import match.Player;
import misc.CircleColors;
import networking.GameClient;

/**
 *
 * @author <a href="mailto:martin.drost@student.fontys.nl">Martin Dorst</a>
 */
public class GameSummary extends ApplicationAdapter {
    private Stage stage; //done
    private TextureAtlas atlas; //done
    private Skin skin; //done
    private Table table; // Align all buttons
    private TextButton buttonBack;
    private BitmapFont font60;
    private BitmapFont font25;
    private BitmapFont font30;
    private BitmapFont font30Fade;
    private Match match;
    private GlyphLayout layout;
    private SpriteBatch batch;

    public GameSummary(Match match) {
        this.match = match;
        create();
    }

    @Override
    public void create() {

        layout = new GlyphLayout();
        batch = new SpriteBatch();

        //initialize fonts
        FreeTypeFontGenerator generator = new FreeTypeFontGenerator(Gdx.files.internal("fonts/MunroSmall.ttf"));
        FreeTypeFontGenerator.FreeTypeFontParameter parameter = new FreeTypeFontGenerator.FreeTypeFontParameter();
        parameter.size = 60;
        font60 = generator.generateFont(parameter); // font size 12 pixels
        font60.setColor(Color.BLACK);
        parameter.size = 40;
        font30 = generator.generateFont(parameter); // font size 12 pixels
        font30.setColor(0.5f, 0.5f, 0.5f, 255);
        font30Fade = generator.generateFont(parameter); // font size 12 pixels
        font30Fade.setColor(0.5f, 0.5f, 0.5f, 255);
        parameter.size = 25;
        font25 = generator.generateFont(parameter); // font size 12 pixels
        font25.setColor(Color.BLACK);
        generator.dispose(); // don't forget to dispose to avoid memory leaks!

        //prepare buttons
        stage = new Stage();
        Gdx.input.setInputProcessor(stage);
        atlas = new TextureAtlas("ui/buttonPack.pack");
        skin = new Skin(atlas);
        table = new Table();

        Label.LabelStyle headStyle = new Label.LabelStyle(font60, Color.BLACK);
        Label.LabelStyle headStyleOptions = new Label.LabelStyle(font25, CircleColors.black);
        Label heading = new Label("Highscores", headStyle);

        table.row();
        table.add(new Label("", headStyle)).colspan(2).width(600);
        table.row();
        table.add(heading).colspan(2).align(Align.center);
        table.row();
        table.add(new Label("Map: " + match.getMap().getName(), headStyleOptions)).align(Align.left);
        table.row();
        table.add(new Label("Gamemode: " + match.getGameMode().getName(), headStyleOptions)).align(Align.left);

        Label.LabelStyle headingStyle = new Label.LabelStyle(font25, Color.BLACK);

        table.row();
        table.add(new Label("Player", headingStyle)).align(Align.left).padTop(15);
        table.add(new Label("Score", headingStyle)).align(Align.right).padTop(15);

        for (Player player : match.getPlayers()) {
            table.row();
            table.add(new Label(player.getName(), headingStyle)).align(Align.left).padTop(10);
            table.add(new Label(Integer.toString(player.getScore()), headingStyle)).align(Align.right).padTop(10);
        }

        final TextButton.TextButtonStyle textButtonStyle = new TextButton.TextButtonStyle();
        textButtonStyle.downFontColor = new Color(0f, 0.57f, 0.92f, 1f);
        textButtonStyle.overFontColor = new Color(0f, 0.57f, 1f, 1f);
        textButtonStyle.font = font30;
        textButtonStyle.fontColor = Color.BLACK;

        buttonBack = new TextButton("Main menu", textButtonStyle);
        buttonBack.addListener(new ClickListener() {
            @Override
            public void clicked(InputEvent event, float x, float y) {
                textButtonStyle.font = font30;
                GameClient.leaveGames();
                //Config.page = new MainMenu();
            }

        });
        buttonBack.pad(20);

        table.row();
        table.add(buttonBack).colspan(2).align(Align.center).padTop(30);
        table.setBounds(Gdx.graphics.getWidth() / 2 - 300, Gdx.graphics.getHeight() / 2 - table.getHeight() / 2,
                600, 0);
        stage.addActor(table);
    }

    @Override
    public void render() {

        stage.act();
        stage.draw();

    }
}