Java tutorial
/* * 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.Texture; import com.badlogic.gdx.graphics.g2d.BitmapFont; import com.badlogic.gdx.graphics.g2d.NinePatch; 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.graphics.glutils.ShapeRenderer; import com.badlogic.gdx.scenes.scene2d.InputEvent; import com.badlogic.gdx.scenes.scene2d.Stage; import com.badlogic.gdx.scenes.scene2d.ui.Label.LabelStyle; 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.ui.TextButton.TextButtonStyle; import com.badlogic.gdx.scenes.scene2d.utils.ClickListener; import com.badlogic.gdx.scenes.scene2d.ui.Label; import com.badlogic.gdx.scenes.scene2d.ui.List; import com.badlogic.gdx.scenes.scene2d.ui.List.ListStyle; import com.badlogic.gdx.scenes.scene2d.ui.ScrollPane; import com.badlogic.gdx.scenes.scene2d.ui.ScrollPane.ScrollPaneStyle; import com.badlogic.gdx.scenes.scene2d.utils.Drawable; import com.badlogic.gdx.scenes.scene2d.utils.TextureRegionDrawable; import com.circle.game.Config; import java.util.ArrayList; import map.GameMaps; import map.Map; import networking.GameClient; /** * * @author <a href="mailto:kevin.vanderburg@student.fontys.nl">Kevin van der * Burg</a> */ import networking.ActiveMatch; public class GameLobby extends ApplicationAdapter { private Stage stage; //done private TextureAtlas atlas; //done private Skin skin; //done private Table table; // Align all buttons private Table table2; // Align all buttons private TextButton buttonExit, buttonCreate, buttonNoGame, buttonActiveGame; private BitmapFont font60, font30; //done private Label heading; private Map[] availableMaps; private int selectedGame; private int selectedMap; private ShapeRenderer shapeRenderer; private int xOffset; private int yOffset; private SpriteBatch batch; private Texture barrelTexture = new Texture(Gdx.files.internal("sprites/Barrel.png")); private int playerLimitIndex; private int[] playerLimit = new int[] { 1, 2, 3, 4 }; private List matches; private ScrollPane lobby; public GameLobby() { create(); } @Override public void create() { playerLimitIndex = 0; // shapeRenderer = new ShapeRenderer(); // shapeRenderer.setAutoShapeType(true); GameClient.getAllMaches(true); java.util.List<ActiveMatch> allActiveMatches = GameClient.getAllActiveMatches(); System.out.println(allActiveMatches); batch = new SpriteBatch(); availableMaps = GameMaps.getMaps(); stage = new Stage(); Gdx.input.setInputProcessor(stage); atlas = new TextureAtlas("ui/buttonPack.pack"); skin = new Skin(atlas); table = new Table(skin); table.setBounds(0, 0, Gdx.graphics.getWidth(), Gdx.graphics.getHeight()); //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); generator.dispose(); // don't forget to dispose to avoid memory leaks! ScrollPaneStyle paneStyle = new ScrollPaneStyle(); //Font final TextButtonStyle textButtonStyle = new 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; //System.out.println(atlas.getRegions()); paneStyle.background = new TextureRegionDrawable(atlas.findRegion("up")); table2 = new Table(); TextButton[] aam = new TextButton[allActiveMatches.size()]; for (int i = 0; i < allActiveMatches.size(); i++) { final ActiveMatch am = allActiveMatches.get(i); aam[i] = new TextButton( "Map:" + am.map + " - " + am.getGameMode() + " - Max:" + am.getNumberOfPlayers(), textButtonStyle); aam[i].addListener(new ClickListener() { @Override public void clicked(InputEvent event, float x, float y) { Config.page = new GameWaiting(am.getMap(), am.getGameMode(), am.getNumberOfPlayers()); } }); table2.add(aam[i]); } ScrollPane lobby = new ScrollPane(table2, paneStyle); buttonExit = new TextButton("Back", textButtonStyle); buttonExit.addListener(new ClickListener() { @Override public void clicked(InputEvent event, float x, float y) { Config.page = new MainMenu(); } }); buttonExit.pad(20); buttonCreate = new TextButton("Create", textButtonStyle); buttonCreate.addListener(new ClickListener() { @Override public void clicked(InputEvent event, float x, float y) { Config.page = new GameCreate(); } }); buttonCreate.pad(20); buttonNoGame = new TextButton("No Games found", textButtonStyle); buttonNoGame.addListener(new ClickListener() { @Override public void clicked(InputEvent event, float x, float y) { } }); buttonNoGame.pad(20); LabelStyle headingStyle = new LabelStyle(font60, Color.BLACK); heading = new Label("Lobby", headingStyle); table.add(heading).colspan(2).center(); table.padBottom(100); table.row(); if (allActiveMatches.size() <= 0) { table.add(buttonNoGame).colspan(2).center(); } else { table.add(lobby).colspan(2).center(); } table.padBottom(50); table.row(); table.add(buttonExit); table.add(buttonCreate); stage.addActor(table); } @Override public void render() { stage.act(); stage.draw(); } }