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

been busy

parent 06dcf518
No related branches found
No related tags found
1 merge request!8Dev
Showing
with 327 additions and 58 deletions
No preview for this file type
<component name="libraryTable">
<library name="Gradle: CheckersClient.core.core-1.0">
<CLASSES>
<root url="jar://$PROJECT_DIR$/core/build/libs/core-1.0.jar!/" />
</CLASSES>
<JAVADOC />
<SOURCES />
</library>
</component>
\ No newline at end of file
File added
File added
......@@ -59,5 +59,7 @@ public class PlayerController {
public PlayerController getPlayerController(){ return this; }
public void leaveLobby(int id) { net.sendToServer(new cLobbyLeave(id)); }
public NetworkController getNetWorkController() { return net; }
}
......@@ -33,6 +33,14 @@ public class Lobby {
return name;
}
public int getMaxPlayers(){
return MAX_PLAYERS;
}
public ArrayList<Player> getPlayers(){
return players;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
......
......@@ -36,7 +36,7 @@ public class Player {
this.indexAvatar = indexAvatar;
}
public int getPlayerAvatar(int indexAvatar){
public int getIndexAvatar(){
return this.indexAvatar;
}
......
......@@ -5,7 +5,6 @@ import com.badlogic.gdx.assets.AssetManager;
import com.badlogic.gdx.audio.Sound;
import com.badlogic.gdx.graphics.Pixmap;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.TextureRegion;
import com.badlogic.gdx.graphics.glutils.ShapeRenderer;
import com.badlogic.gdx.scenes.scene2d.Actor;
import com.badlogic.gdx.scenes.scene2d.InputEvent;
......@@ -24,14 +23,16 @@ import com.badlogic.gdx.scenes.scene2d.ui.TextField;
import com.badlogic.gdx.utils.Align;
import com.mygdx.game.controllers.PlayerController;
import com.mygdx.game.model.Lobby;
import com.mygdx.game.model.Player;
import com.mygdx.game.views.enums.LobbyAssets;
import com.mygdx.game.views.enums.MenuAssets;
import com.mygdx.game.views.tokens.PlayerAvatar;
import java.util.ArrayList;
import java.util.Arrays;
public class LobbyView extends View{
private final ArrayList<Lobby> lobbyList;
private final ArrayList<Actor> mainUIActors = new ArrayList<>();
private ScrollPane scroller;
private Table lobbyTable;
......@@ -42,9 +43,12 @@ public class LobbyView extends View{
private boolean startRocketTransition;
private Button createLobbyButton;
private Button lobbyListBackButton;
private Button joinLobbyButton;
private Button lobbyBackButton;
private Button lobbyListRefreshButton;
private Button lobbyRefreshButton;
private Button joinLobbyButton;
private Button lobbyListButton;
private Button setUserNameButton;
private Button startLobbyButton;
......@@ -60,8 +64,6 @@ public class LobbyView extends View{
private Label mrServerBubbleLabel;
private Label outputLabel;
private final Lobby lobby;
private Sound buttonClickAudio;
private Texture background;
......@@ -75,9 +77,11 @@ public class LobbyView extends View{
private ShapeRenderer shapeRenderer;
public LobbyView(GameViewManager gvm, final PlayerController playerController, AssetManager assetManager, final Stage stage, Skin skin) {
public LobbyView(GameViewManager gvm, final PlayerController playerController, AssetManager assetManager, final Stage stage, Skin skin, ArrayList<PlayerAvatar> availableAvatars) {
super(gvm, playerController, assetManager, stage, skin);
this.availableAvatars = availableAvatars;
Pixmap tablePixmap = new Pixmap(1,1, Pixmap.Format.RGB565);
tablePixmap.setColor(1, 1, 1, 1);
tablePixmap.fill();
......@@ -102,11 +106,6 @@ public class LobbyView extends View{
lobbyListBubbleImage.setPosition(col_width*0.25f, row_height*5.5f);
backgroundImage = new Image(background);
lobby = playerController.getLobby();
lobbyList = playerController.getLobbyList();
//lobbyTable.setBackground(textureRegionDrawableBg);
outputLabel = new Label("Press a Button",skin,"black");
outputLabel.setSize(Gdx.graphics.getWidth(),row_height);
outputLabel.setPosition(col_width*0.25f,row_height*11);
......@@ -123,9 +122,13 @@ public class LobbyView extends View{
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);
lobbyListButton = new TextButton("Join Lobby",skin,"small");
lobbyListButton.setSize(col_width*1f,(float)(row_height*0.65));
lobbyListButton.setPosition(lobbyListBubbleImage.getX()+lobbyListBubbleImage.getWidth()*0.6f,lobbyListBubbleImage.getY()+lobbyListBubbleImage.getHeight()*0.125f+row_height*1);
lobbyListRefreshButton = new TextButton("Refresh",skin,"small");
lobbyListRefreshButton.setSize(col_width*1f,(float)(row_height*0.65));
lobbyListRefreshButton.setPosition(lobbyListBubbleImage.getX()+lobbyListBubbleImage.getWidth()*0.1f,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));
......@@ -135,6 +138,14 @@ public class LobbyView extends View{
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);
lobbyListBackButton = new TextButton("Back",skin,"small");
lobbyListBackButton.setSize(col_width*1f,(float)(row_height*0.65));
lobbyListBackButton.setPosition(lobbyListBubbleImage.getX()+lobbyListBubbleImage.getWidth()*0.6f,lobbyListBubbleImage.getY()+lobbyListBubbleImage.getHeight()*0.125f+row_height*1);
joinLobbyButton = new TextButton("Back",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*2);
startLobbyButton = new TextButton("Start",skin,"small");
startLobbyButton.setSize(col_width*1f,(float)(row_height*0.65));
startLobbyButton.setPosition(lobbyListBubbleImage.getX()+lobbyListBubbleImage.getWidth()*0.1f,lobbyListBubbleImage.getY()+lobbyListBubbleImage.getHeight()*0.125f+row_height*1);
......@@ -146,12 +157,12 @@ public class LobbyView extends View{
lobbyCreateTextField = new TextField("", skin);
lobbyCreateTextField.setMessageText("Enter lobby name.");
lobbyCreateTextField.setSize(col_width*1f,row_height*1f);
lobbyCreateTextField.setPosition(lobbyRefreshButton.getX(), lobbyRefreshButton.getY()+row_height*1.25f);
lobbyCreateTextField.setPosition(lobbyListRefreshButton.getX(), lobbyListRefreshButton.getY()+row_height*1.25f);
lobbyCreateSizeSelectBox =new SelectBox<>(skin);
lobbyCreateSizeSelectBox.setItems(2, 4, 6, 8);
lobbyCreateSizeSelectBox.setPosition(lobbyBackButton.getX(), lobbyCreateTextField.getY());
lobbyCreateSizeSelectBox.setSize(lobbyBackButton.getWidth(), lobbyBackButton.getHeight());
lobbyCreateSizeSelectBox.setPosition(lobbyListBackButton.getX(), lobbyCreateTextField.getY());
lobbyCreateSizeSelectBox.setSize(lobbyListBackButton.getWidth(), lobbyListBackButton.getHeight());
backgroundImage.setZIndex(1);
lobbyListBubbleImage.setZIndex(2);
......@@ -165,7 +176,7 @@ public class LobbyView extends View{
stage.addActor(exhaustImage);
stage.addActor(lobbyListBubbleImage);
mainUIActors.add(createLobbyButton);
mainUIActors.add(joinLobbyButton);
mainUIActors.add(lobbyListButton);
mainUIActors.add(mrServerBubbleLabel);
for (Actor actor: mainUIActors){
stage.addActor(actor);
......@@ -185,10 +196,57 @@ public class LobbyView extends View{
buttonClickAudio.play(0.8f);
outputLabel.setText("Create Lobby");
showCreateLobbyWindow();
}
@Override
public void enter(InputEvent event, float x, float y, int pointer, Actor fromActor) {
outputLabel.setText("createLobbyButton");
}
});
lobbyListButton.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);
showLobbyListWindow();
}
@Override
public void enter(InputEvent event, float x, float y, int pointer, Actor fromActor) {
outputLabel.setText("lobbyListButton");
}
});
lobbyListBackButton.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);
Gdx.input.setOnscreenKeyboardVisible(false);
stage.unfocusAll();
try{
if(lobby.getPlayers().size() == 1){
playerController.deleteLobby(lobby.getID());
}
else{
playerController.leaveLobby(lobby.getID());
}
}catch(NullPointerException e){
}
showMainLobbyWindow();
}
@Override
public void enter(InputEvent event, float x, float y, int pointer, Actor fromActor) {
outputLabel.setText("lobbyListBackButton");
}
});
joinLobbyButton.addListener(new InputListener(){
lobbyListRefreshButton.addListener(new InputListener(){
@Override
public boolean touchDown (InputEvent event, float x, float y, int pointer, int button) {
return true;
......@@ -196,10 +254,15 @@ public class LobbyView extends View{
@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();
outputLabel.setText("Lobby refreshed!");
lobbyListRefresh();
}
@Override
public void enter(InputEvent event, float x, float y, int pointer, Actor fromActor) {
outputLabel.setText("lobbyListRefreshButton");
}
});
lobbyBackButton.addListener(new InputListener(){
@Override
public boolean touchDown (InputEvent event, float x, float y, int pointer, int button) {
......@@ -208,12 +271,70 @@ public class LobbyView extends View{
@Override
public void touchUp (InputEvent event, float x, float y, int pointer, int button) {
buttonClickAudio.play(0.8f);
outputLabel.setText("Back button");
Gdx.input.setOnscreenKeyboardVisible(false);
stage.unfocusAll();
try{
if(lobby.getPlayers().size() == 1){
playerController.deleteLobby(lobby.getID());
}
else{
playerController.leaveLobby(lobby.getID());
}
}catch(NullPointerException e){
}
mainUIActors.clear();
showMainLobbyWindow();
}
@Override
public void enter(InputEvent event, float x, float y, int pointer, Actor fromActor) {
outputLabel.setText("lobbyListBackButton");
}
});
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) {
if(lobby != null) playerController.leaveLobby(lobby.getID());
if(lobbyListStrings.getSelectedIndex()>=0){
Thread thread2 = new Thread(){
public void run(){
playerController.joinLobby(lobbyListStrings.getSelectedIndex());
System.out.println("joining lobby");
while (playerController.getLobby() == null) {
System.out.println("Waiting for lobby");
}
Lobby lobby = playerController.getLobby();
System.out.println("Lobby loaded " + lobby);
}
};
thread2.start();
try {
thread2.join();
} catch (InterruptedException e) {
e.printStackTrace();
}
Gdx.input.setOnscreenKeyboardVisible(false);
showLobbyWindow();
lobbyRefresh();
}
else{
outputLabel.setText("Lobby has no name, hehe");
}
}
@Override
public void enter(InputEvent event, float x, float y, int pointer, Actor fromActor) {
outputLabel.setText("lobbyListBackButton");
}
});
lobbyRefreshButton.addListener(new InputListener(){
@Override
public boolean touchDown (InputEvent event, float x, float y, int pointer, int button) {
......@@ -225,7 +346,12 @@ public class LobbyView extends View{
outputLabel.setText("Lobby refreshed!");
lobbyRefresh();
}
@Override
public void enter(InputEvent event, float x, float y, int pointer, Actor fromActor) {
outputLabel.setText("lobbyRefreshButton");
}
});
lobbyCreateTextField.addListener(new InputListener(){
@Override
public boolean touchDown (InputEvent event, float x, float y, int pointer, int button) {
......@@ -249,8 +375,26 @@ public class LobbyView extends View{
public boolean touchDown (InputEvent event, float x, float y, int pointer, int button) {
buttonClickAudio.play(0.80f);
if(!lobbyCreateTextField.getText().isEmpty()){
Thread thread2 = new Thread(){
public void run(){
playerController.createLobby(lobbyCreateTextField.getText(), lobbyCreateSizeSelectBox.getSelected());
System.out.println("Creating lobby");
while (playerController.getLobby() == null) {
System.out.println("Waiting for lobby");
}
Lobby lobby = playerController.getLobby();
System.out.println("Lobby loaded " + lobby);
}
};
thread2.start();
try {
thread2.join();
} catch (InterruptedException e) {
e.printStackTrace();
}
Gdx.input.setOnscreenKeyboardVisible(false);
showLobbyWindow();
lobbyRefresh();
}
else{
outputLabel.setText("Lobby has no name, hehe");
......@@ -281,49 +425,129 @@ public class LobbyView extends View{
}
private ScrollPane scrollPane;
public void lobbyRefresh(){
List<String> myList = new List(skin, "plain");
myList.setColor(1f, 1f, 1f, 1);
private volatile ArrayList<Lobby> lobbyList;
private List<String> lobbyListStrings;
public void lobbyListRefresh(){
Thread thread2 = new Thread(){
public void run(){
playerController.lobbyGetList();
while (playerController.getLobbyList() == null) {
System.out.println("Waiting for lobby" + lobbyList);
}
lobbyList = playerController.getLobbyList();
System.out.println("Lobby loaded " + lobbyList);
}
};
thread2.start();
try {
thread2.join();
} catch (InterruptedException e) {
e.printStackTrace();
}
String[] strings = new String[50];
for (int i = 0, k = 0; i < 50; i++) {
strings[k++] = "String: " + i;
lobbyListStrings = new List(skin, "plain");
lobbyListStrings.setColor(1f, 1f, 1f, 1);
ArrayList<String> listText = new ArrayList<>();
if(lobbyList.size() > 0){
for (Lobby lobby: lobbyList) {
listText.add(lobby.getName() + "\t" + lobby.getPlayers().size()+ "/" + lobby.getMaxPlayers());
}
}
myList.setItems(strings);
scrollPane = new ScrollPane(myList);
else{
listText.add("No lobbies currently available");
}
String[] strings = new String[listText.size()];
strings = listText.toArray(strings);
lobbyListStrings.setItems(strings);
scrollPane = new ScrollPane(lobbyListStrings);
scrollPane.setBounds(0, 0, col_width*4f, row_height*4);
scrollPane.setPosition(col_width*0.25f, row_height*6);
scrollPane.setSmoothScrolling(false);
scrollPane.setTransform(true);
stage.addActor(scrollPane);
mainUIActors.add(scrollPane);
for (Actor actor: mainUIActors){
stage.addActor(actor);
}
}
private void showCreateLobbyWindow(){
clearActors();
mainUIActors.add(lobbyBackButton);
mainUIActors.add(lobbyListBackButton);
mainUIActors.add(lobbyCreateTextField);
mainUIActors.add(lobbyCreateSizeSelectBox);
mainUIActors.add(startLobbyButton);
lobbyListBackButton.setY(startLobbyButton.getY());
for (Actor actor: mainUIActors){
stage.addActor(actor);
}
}
private void showJoinLobbyWindow(){
private void showLobbyListWindow(){
clearActors();
/*
mainUIActors.add(lobbyScrollTable);
mainUIActors.add(lobbyBackButton);
mainUIActors.add(lobbyRefreshButton);
*/
mainUIActors.add(lobbyListBackButton);
mainUIActors.add(lobbyListRefreshButton);
mainUIActors.add(joinLobbyButton);
joinLobbyButton.setPosition(col_width*4, row_height*3);
lobbyListRefreshButton.setY(row_height*3);
lobbyListBackButton.setY(row_height*3);
for (Actor actor: mainUIActors){
stage.addActor(actor);
}
lobbyRefresh();
lobbyListRefresh();
}
Lobby lobby;
ArrayList<Player> playersInLobby;
float[] player1Pos = {col_width*3.75f, row_height*2};
float[] player2Pos = {col_width*3.5f, row_height*1.5f};
float[] player3Pos = {col_width*4.3f, row_height*2};
float[] player4Pos = {col_width*4.1f, row_height*1.5f};
float[] player5Pos = {col_width*5, row_height*2};
float[] player6Pos = {col_width*4.8f, row_height*1.5f};
ArrayList<float[]> playerPositions= new ArrayList<>(Arrays.asList(player1Pos, player2Pos, player3Pos, player4Pos, player5Pos, player6Pos));;
private final ArrayList<PlayerAvatar> availableAvatars;
private ArrayList<PlayerAvatar> lobbyAvatars = new ArrayList<>();
private void lobbyRefresh(){
try{
lobbyAvatars.clear();
lobby = playerController.getLobby();
playersInLobby = lobby.getPlayers();
System.out.println("My avatar Index: "+ playerController.getPlayer().getIndexAvatar());
System.out.println("Number of players in lobby: "+ lobby.getPlayers().size());
for(int i = 0; i<playersInLobby.size(); i++){
System.out.println("This players ID: "+ playersInLobby.get(i).getID() + " avatarIndex: "+ playersInLobby.get(i).getIndexAvatar());
PlayerAvatar pa = availableAvatars.get(playersInLobby.get(i).getIndexAvatar());
pa.setScale(0.3f, 0.3f);
pa.setOrigin(0, 0);
pa.setPosition(playerPositions.get(i)[0], playerPositions.get(i)[1]);
lobbyAvatars.add(pa);
}
}catch (Exception e){
System.out.println("Cannot refresh lobby at this time.");
}
}
private void showLobbyWindow(){
clearActors();
mainUIActors.add(lobbyBackButton);
lobby = playerController.getLobby();
playerController.joinLobby(lobby.getID());
mainUIActors.add(lobbyListBackButton);
mainUIActors.add(lobbyRefreshButton);
for (Actor actor: mainUIActors){
stage.addActor(actor);
}
......@@ -332,11 +556,9 @@ public class LobbyView extends View{
clearActors();
mainUIActors.add(createLobbyButton);
mainUIActors.add(createLobbyButton);
mainUIActors.add(joinLobbyButton);
mainUIActors.add(lobbyListButton);
mainUIActors.add(mrServerBubbleLabel);
Button tempButton = new TextButton("some text", skin);
tempButton.setPosition(col_width*5, row_height*5);
mainUIActors.add(tempButton);
for (Actor actor: mainUIActors){
stage.addActor(actor);
}
......@@ -355,14 +577,12 @@ public class LobbyView extends View{
if(Gdx.input.isTouched()) {
int x = Gdx.input.getX();
int y = Gdx.input.getY();
}/*
if(Gdx.input.isButtonJustPressed(1)){
sound.stop();
gvm.set(new PlayView(gvm, playerController, assetManager));
dispose();
}
*/
}
float updateAvatarTimer = 0;
float updateAvatarFrequency = 0.110f; //update every 250ms
@Override
public void render(float dt) {
Gdx.gl.glClearColor(1, 1, 1, 1);
......@@ -378,16 +598,32 @@ public class LobbyView extends View{
else if(startRocketTransition){
}
stage.draw();
updateAvatarTimer += dt;
stage.getBatch().begin();
for(PlayerAvatar playerAvatar : lobbyAvatars){
if(updateAvatarTimer>= updateAvatarFrequency){
//System.out.println("Updating avatars. Number of avatars: "+ lobbyAvatars.size());
playerAvatar.updateTexture();
updateAvatarTimer=0;
System.out.println("AvPos"+ playerAvatar.getX()+ ", " +playerAvatar.getY());
}
playerAvatar.draw(stage.getBatch());
}
stage.getBatch().end();
drawGrid();
}
@Override
public void update(float dt) {
stage.act(dt);
handleInput();
}
}
......@@ -308,10 +308,12 @@ public class MenuView extends View{
outputLabel.setText("alphaFadeValue: " +alphaFadeValue);
if(alphaFadeValue >= 1){
startFadeFromBlankToWhite = false;
gvm.push(new LobbyView(gvm, playerController, assetManager, stage, skin));
gvm.push(new LobbyView(gvm, playerController, assetManager, stage, skin, availableAvatars));
}
}
if(playerController.getPlayer() != null){
stage.addActor(connectionBarGreenCircle);
connectionBarRedCircle.remove();
......
......@@ -17,9 +17,11 @@ public class PlayerAvatar extends Sprite {
private boolean reversed = false;
public PlayerAvatar(ArrayList<Texture> textureArray, Texture portrait, String name) {
super(textureArray.get(0));
this.textureArray = textureArray;
this.portrait = portrait;
this.name = name;
setTexture(textureArray.get(currentTexture));
}
public void updateTexture() {
......@@ -34,7 +36,8 @@ public class PlayerAvatar extends Sprite {
this.reversed = true;
}
}
//System.out.println("Updating texture. Current texture Int: " + currentTexture + " numOfTextures: " + textureArray.size());
setTexture(textureArray.get(currentTexture));
}
public ArrayList<Texture> getTextures() {
......
No preview for this file type
<component name="libraryTable">
<library name="Gradle: CheckersServer.core.core-1.0">
<CLASSES>
<root url="jar://$PROJECT_DIR$/core/build/libs/core-1.0.jar!/" />
</CLASSES>
<JAVADOC />
<SOURCES />
</library>
</component>
\ No newline at end of file
......@@ -14,7 +14,7 @@ import java.util.ArrayList;
public class NetworkController {
private final int MAX_PLAYERS = 2;
private final int MAX_LOBBIES = 2;
private final int MAX_LOBBIES = 40;
private ArrayList<Player> players;
private ArrayList<Lobby> lobbies;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment