Skip to content
Snippets Groups Projects
Commit 7bde0211 authored by Petter Selfors Rølvåg's avatar Petter Selfors Rølvåg
Browse files

UI, buttons, listeners, ++

parent 1324c888
No related branches found
No related tags found
1 merge request!3Main menu lobby menu
......@@ -4,19 +4,30 @@ import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.assets.AssetManager;
import com.badlogic.gdx.audio.Sound;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.Sprite;
import com.badlogic.gdx.graphics.g2d.TextureRegion;
import com.badlogic.gdx.graphics.glutils.FrameBuffer;
import com.badlogic.gdx.graphics.glutils.ShapeRenderer;
import com.badlogic.gdx.math.MathUtils;
import com.badlogic.gdx.scenes.scene2d.Actor;
import com.badlogic.gdx.scenes.scene2d.InputEvent;
import com.badlogic.gdx.scenes.scene2d.InputListener;
import com.badlogic.gdx.scenes.scene2d.Stage;
import com.badlogic.gdx.scenes.scene2d.ui.Button;
import com.badlogic.gdx.scenes.scene2d.ui.Dialog;
import com.badlogic.gdx.scenes.scene2d.ui.Image;
import com.badlogic.gdx.scenes.scene2d.ui.Label;
import com.badlogic.gdx.scenes.scene2d.ui.SelectBox;
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.TextField;
import com.badlogic.gdx.utils.Align;
import com.mygdx.game.controllers.PlayerController;
import com.mygdx.game.views.enums.LobbyAssets;
import com.mygdx.game.views.enums.MenuAssets;
import java.util.Arrays;
import java.util.List;
public class LobbyView extends View{
......@@ -29,16 +40,30 @@ public class LobbyView extends View{
private Sound sound;
private Button setUserNameButton;
private Image backgroundImage;
private TextField usernameTextField;
private FrameBuffer previousScreenFrameBuffer;
private float fadeTransitionLength = 0.75f;
private float fadeTransitionTimer = 1;
private Image fadeImage;
private TextureRegion fadeTextureRegion;
private boolean transitionFinished = false;
private boolean fadeIn = true;
private boolean fadeOut = true;
private Label mrServerBubbleLabel;
private Sound buttonClickAudio;
private TextField lobbyCreateTextField;
private Button joinLobbyButton;
private Button createLobbyButton;
private Button lobbyRefreshButton;
private Button lobbyBackButton;
private Dialog lobbyCreateDialogue;
private SelectBox<Integer> lobbyCreateSizeSelectBox;
private boolean transitionFinished = false;
int Help_Guides = 12;
int row_height = Gdx.graphics.getHeight() / Help_Guides;
......@@ -49,20 +74,11 @@ public class LobbyView extends View{
super(gvm, playerController, assetManager, stage, skin);
this.previousScreenFrameBuffer = previousScreenFrameBuffer;
fadeTextureRegion = new TextureRegion(previousScreenFrameBuffer.getColorBufferTexture());
fadeTextureRegion.flip(false, true);
fadeImage = new Image(fadeTextureRegion);
fadeImage.setColor(1, 1, 1, 1f);
background = (Texture) assetManager.get(LobbyAssets.BACKGROUND.path, LobbyAssets.BACKGROUND.classType);
Texture lobbyListTexture = (Texture) assetManager.get(LobbyAssets.LOBBYLIST.path, LobbyAssets.LOBBYLIST.classType);
this.lobbyListBubbleImage = new Image(lobbyListTexture);
lobbyListBubbleImage.setPosition(col_width*0.25f, row_height*5.5f);
rocketTexture = (Texture) assetManager.get(LobbyAssets.ROCKET.path, LobbyAssets.ROCKET.classType);
exhaustTexture = (Texture) assetManager.get(LobbyAssets.ROCKETEXHAUST.path, LobbyAssets.ROCKETEXHAUST.classType);
buttonClickAudio = (Sound) assetManager.get(MenuAssets.BUTTON_CLICK_AUDIO.path, MenuAssets.BUTTON_CLICK_AUDIO.classType);
Texture lobbyListTexture = (Texture) assetManager.get(LobbyAssets.LOBBYLIST.path, LobbyAssets.LOBBYLIST.classType);
rocketImage = new Image(rocketTexture);
exhaustImage = new Image(exhaustTexture);
......@@ -71,8 +87,13 @@ public class LobbyView extends View{
exhaustImage.setSize(col_width*0.6f, row_height*2f);
exhaustImage.setPosition(rocketImage.getX()+rocketImage.getWidth()/2-exhaustImage.getWidth()/2, rocketImage.getY()-exhaustImage.getHeight());
fadeTextureRegion = new TextureRegion(previousScreenFrameBuffer.getColorBufferTexture());
fadeTextureRegion.flip(false, true);
fadeImage = new Image(fadeTextureRegion);
fadeImage.setColor(1, 1, 1, 1f);
lobbyListBubbleImage = new Image(lobbyListTexture);
lobbyListBubbleImage.setPosition(col_width*0.25f, row_height*5.5f);
backgroundImage = new Image(background);
outputLabel = new Label("Press a Button",skin,"black");
......@@ -81,58 +102,184 @@ public class LobbyView extends View{
outputLabel.setAlignment(Align.topLeft);
outputLabel.setFontScale(2);
/*
mrServerBubbleLabel = new Label("Hi, I am mr. Server. I allow creation and joining of lobby rooms.", skin,"black");
mrServerBubbleLabel.setSize(col_width*2.5f, row_height*3f);
mrServerBubbleLabel.setPosition(lobbyListBubbleImage.getX()+lobbyListBubbleImage.getWidth()*0.1f, row_height*8f);
mrServerBubbleLabel.setWrap(true);
mrServerBubbleLabel.setFontScale(2);
createLobbyButton = new TextButton("Create Lobby",skin,"small");
createLobbyButton.setSize(col_width*1f,(float)(row_height*0.65));
createLobbyButton.setPosition(lobbyListBubbleImage.getX()+lobbyListBubbleImage.getWidth()*0.1f,lobbyListBubbleImage.getY()+lobbyListBubbleImage.getHeight()*0.125f+row_height*1);
joinLobbyButton = new TextButton("Join Lobby",skin,"small");
joinLobbyButton.setSize(col_width*1f,(float)(row_height*0.65));
joinLobbyButton.setPosition(lobbyListBubbleImage.getX()+lobbyListBubbleImage.getWidth()*0.6f,lobbyListBubbleImage.getY()+lobbyListBubbleImage.getHeight()*0.125f+row_height*1);
lobbyRefreshButton = new TextButton("Refresh",skin,"small");
lobbyRefreshButton.setSize(col_width*1f,(float)(row_height*0.65));
lobbyRefreshButton.setPosition(lobbyListBubbleImage.getX()+lobbyListBubbleImage.getWidth()*0.1f,lobbyListBubbleImage.getY()+lobbyListBubbleImage.getHeight()*0.125f+row_height*1);
lobbyBackButton = new TextButton("Back",skin,"small");
lobbyBackButton.setSize(col_width*1f,(float)(row_height*0.65));
lobbyBackButton.setPosition(lobbyListBubbleImage.getX()+lobbyListBubbleImage.getWidth()*0.6f,lobbyListBubbleImage.getY()+lobbyListBubbleImage.getHeight()*0.125f+row_height*1);
setUserNameButton = new TextButton("Text Button",skin,"small");
setUserNameButton.setSize(col_width*2,(float)(row_height*0.5));
setUserNameButton.setPosition(col_width*5,Gdx.graphics.getHeight()-row_height*4);
usernameTextField = new TextField("Your name ..", skin);
lobbyCreateTextField = new TextField("", skin);
lobbyCreateTextField.setMessageText("Name of your lobby.");
lobbyCreateTextField.setPosition(col_width*5,Gdx.graphics.getHeight()-row_height*3);
lobbyCreateTextField.setSize(col_width*2,(float)(row_height*0.75));
lobbyCreateTextField.scaleBy(1000);
lobbyCreateSizeSelectBox =new SelectBox<>(skin);
lobbyCreateSizeSelectBox.setItems(2, 4, 6, 8);
lobbyCreateTextField = new TextField("", skin);
lobbyCreateTextField.setMessageText("Enter lobby name.");
lobbyCreateTextField.setSize(col_width*1.5f,row_height*0.8f);
lobbyCreateTextField.setPosition(lobbyRefreshButton.getX(), lobbyRefreshButton.getY()+row_height*1.25f);
lobbyCreateSizeSelectBox.setPosition(lobbyBackButton.getX(), lobbyCreateTextField.getY());
lobbyCreateSizeSelectBox.setSize(lobbyBackButton.getWidth(), lobbyBackButton.getHeight());
usernameTextField.setMessageText("Enter your username");
usernameTextField.setPosition(col_width*5,Gdx.graphics.getHeight()-row_height*3);
usernameTextField.setSize(col_width*2,(float)(row_height*0.75));
usernameTextField.scaleBy(1000);
backgroundImage.setZIndex(1);
lobbyListBubbleImage.setZIndex(2);
fadeImage.setZIndex(3);
outputLabel.setZIndex(3);
stage.addActor(fadeImage);
stage.addActor(outputLabel);
createLobbyButton.addListener(new InputListener(){
@Override
public boolean touchDown (InputEvent event, float x, float y, int pointer, int button) {
return true;
}
@Override
public void touchUp (InputEvent event, float x, float y, int pointer, int button) {
buttonClickAudio.play(0.8f);
outputLabel.setText("Create Lobby");
showCreateLobbyWindow();
setUserNameButton.addListener(new InputListener(){
}
});
joinLobbyButton.addListener(new InputListener(){
@Override
public boolean touchDown (InputEvent event, float x, float y, int pointer, int button) {
return true;
}
@Override
public void touchUp (InputEvent event, float x, float y, int pointer, int button) {
buttonClickAudio.play(0.8f);
outputLabel.setText("Touch up a Button");
showJoinLobbyWindow();
}
});
lobbyBackButton.addListener(new InputListener(){
@Override
public boolean touchDown (InputEvent event, float x, float y, int pointer, int button) {
return true;
}
@Override
public void touchUp (InputEvent event, float x, float y, int pointer, int button) {
outputLabel.setText("Press a Button");
buttonClickAudio.play(0.8f);
outputLabel.setText("Back button");
showMainLobbyWindow();
}
});
lobbyRefreshButton.addListener(new InputListener(){
@Override
public boolean touchDown (InputEvent event, float x, float y, int pointer, int button) {
outputLabel.setText("Touch down a Button");
return true;
}
@Override
public void touchUp (InputEvent event, float x, float y, int pointer, int button) {
buttonClickAudio.play(0.8f);
outputLabel.setText("Lobby refreshed!");
lobbyRefresh();
}
});
usernameTextField.addListener(new InputListener(){
lobbyCreateTextField.addListener(new InputListener(){
@Override
public boolean touchDown (InputEvent event, float x, float y, int pointer, int button) {
outputLabel.setText("Write your name");
return true;
}
@Override
public void touchUp (InputEvent event, float x, float y, int pointer, int button) {
buttonClickAudio.play(0.8f);
}
@Override
public void enter(InputEvent event, float x, float y, int pointer, Actor fromActor) {
if(usernameTextField.getText().isEmpty()){
playerController.setPlayerName(usernameTextField.getText());
outputLabel.setText("");
buttonClickAudio.play(0.8f);
if(lobbyCreateTextField.getText().isEmpty()){
outputLabel.setText(lobbyCreateTextField.getText());
}
}
});
}
usernameTextField.setZIndex(2);
setUserNameButton.setZIndex(2);
*/
private void showCreateLobbyWindow(){
mrServerBubbleLabel.remove();
joinLobbyButton.remove();
createLobbyButton.remove();
backgroundImage.setZIndex(1);
lobbyListBubbleImage.setZIndex(2);
fadeImage.setZIndex(3);
outputLabel.setZIndex(3);
stage.addActor(fadeImage);
stage.addActor(outputLabel);
stage.addActor(lobbyBackButton);
stage.addActor(lobbyCreateTextField);
stage.addActor(lobbyCreateSizeSelectBox);
}
private Table lobbyRoomTable;
private void showJoinLobbyWindow(){
lobbyRoomTable = new Table();
mrServerBubbleLabel.remove();
joinLobbyButton.remove();
createLobbyButton.remove();
stage.addActor(lobbyRoomTable);
stage.addActor(lobbyBackButton);
stage.addActor(lobbyRefreshButton);
lobbyRefresh();
}
List<String> lobbyNames = Arrays.asList("Hello", "World!", "How", "Are", "You", "Lobby1", "Norway", "Oh yes", "No girls", "Only boys", "NTNU");
List<String> lobbySize = Arrays.asList("2", "4", "6");
private void lobbyRefresh(){
if(lobbyRoomTable != null){
lobbyRoomTable.clear();
// models.get(availableLobbies);
lobbyRoomTable.setSize(col_width*2.5f, row_height*3f);
lobbyRoomTable.setPosition(lobbyListBubbleImage.getX()+lobbyListBubbleImage.getWidth()*0.1f, row_height*8f);
Label availableLobbyLabel = new Label("Available Lobbies", skin);
lobbyRoomTable.addActor(availableLobbyLabel);
for (int i=0; i<4; i++) {
Label lobbyEntry = new Label("LobbyName: "+ lobbyNames.get((int) MathUtils.random(lobbyNames.size()-1)) + ", LobbySize = " + lobbySize.get((int) MathUtils.random(lobbySize.size()-1)), skin);
lobbyEntry.setWrap(true);
lobbyRoomTable.addActor(lobbyEntry);
}
}
}
private void showMainLobbyWindow(){
if(lobbyRoomTable != null){
lobbyRoomTable.remove();
}
stage.addActor(createLobbyButton);
stage.addActor(joinLobbyButton);
stage.addActor(mrServerBubbleLabel);
try {
lobbyBackButton.remove();
lobbyRefreshButton.remove();
lobbyCreateTextField.remove();
lobbyCreateSizeSelectBox.remove();
} finally {
// Do nothing here
}
}
@Override
public void handleInput() {
if(Gdx.input.isTouched()) {
......@@ -168,9 +315,12 @@ public class LobbyView extends View{
private void addActorsAfterTransition(){
stage.addActor(backgroundImage);
stage.addActor(outputLabel);
stage.addActor(lobbyListBubbleImage);
stage.addActor(rocketImage);
stage.addActor(exhaustImage);
stage.addActor(lobbyListBubbleImage);
stage.addActor(createLobbyButton);
stage.addActor(joinLobbyButton);
stage.addActor(mrServerBubbleLabel);
}
private float alphaFade1 = 1;
......
......@@ -2,6 +2,7 @@ package com.mygdx.game.views;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.assets.AssetManager;
import com.badlogic.gdx.audio.Music;
import com.badlogic.gdx.audio.Sound;
import com.badlogic.gdx.graphics.Pixmap;
import com.badlogic.gdx.graphics.Texture;
......@@ -36,6 +37,7 @@ public class MenuView extends View{
private Sound buttonClickAudio;
private Sound transitionAudio;
private Music music;
private ShapeRenderer shapeRenderer;
int Help_Guides = 12;
......@@ -59,6 +61,11 @@ public class MenuView extends View{
form = (Texture) assetManager.get(MenuAssets.FORM.path, MenuAssets.FORM.classType);
music = Gdx.audio.newMusic(Gdx.files.internal(MenuAssets.LOOP_AUDIO.path));
music.setVolume(1);
music.setLooping(true);
music.play();
this.formImage = new Image(form);
formImage.setPosition(col_width*5, row_height*5);
formImage.setAlign((Align.center));
......@@ -113,14 +120,15 @@ public class MenuView extends View{
usernameTextField.addListener(new InputListener(){
@Override
public boolean touchDown (InputEvent event, float x, float y, int pointer, int button) {
buttonClickAudio.play(0.8f);
outputLabel.setText("Write your name");
return true;
}
@Override
public void enter(InputEvent event, float x, float y, int pointer, Actor fromActor) {
if(usernameTextField.getText().isEmpty()){
buttonClickAudio.play(0.8f);
if(usernameTextField.getText().isEmpty()){
playerController.setPlayerName(usernameTextField.getText());
outputLabel.setText("");
}
......@@ -136,7 +144,7 @@ public class MenuView extends View{
outputLabel.setZIndex(3);
*/
loopAudio.loop(0.9f);
//loopAudio.loop(0.9f);
// Adding the initial actors in the scene
stage.addActor(backgroundImage);
stage.addActor(outputLabel);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment