Skip to content
Snippets Groups Projects
Commit 10e15be6 authored by Haakon Gunleiksrud's avatar Haakon Gunleiksrud
Browse files

#33 Added functionality for fetching games, creating buttons and added empty...

#33 Added functionality for fetching games, creating buttons and added empty event listeners for now.
parent af9762a3
No related branches found
No related tags found
1 merge request!29Resolve "ViewHighScoreState"
...@@ -75,7 +75,13 @@ public class MenuState extends State{ ...@@ -75,7 +75,13 @@ public class MenuState extends State{
TextButton highScoreBtn = new TextButton(highScoreBtnText, skin); TextButton highScoreBtn = new TextButton(highScoreBtnText, skin);
highScoreBtn.addListener(new ClickListener() { highScoreBtn.addListener(new ClickListener() {
@Override @Override
public void clicked(InputEvent e, float x, float y){ handleHighscoreBtnClick(); } public void clicked(InputEvent e, float x, float y){
try {
handleHighscoreBtnClick();
} catch (IOException ex) {
ex.printStackTrace();
}
}
}); });
return highScoreBtn; return highScoreBtn;
} }
...@@ -131,7 +137,7 @@ public class MenuState extends State{ ...@@ -131,7 +137,7 @@ public class MenuState extends State{
gsm.set(new SinglePlayerSelectGameState(gsm)); gsm.set(new SinglePlayerSelectGameState(gsm));
} }
private void handleHighscoreBtnClick(){ private void handleHighscoreBtnClick() throws IOException {
gsm.set(new ViewHighScoreState(gsm)); gsm.set(new ViewHighScoreState(gsm));
} }
......
...@@ -2,57 +2,46 @@ package com.gameware.game.states; ...@@ -2,57 +2,46 @@ package com.gameware.game.states;
import com.badlogic.gdx.graphics.g2d.SpriteBatch; import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.badlogic.gdx.scenes.scene2d.InputEvent; import com.badlogic.gdx.scenes.scene2d.InputEvent;
import java.util.List;
import com.badlogic.gdx.scenes.scene2d.ui.Skin; import com.badlogic.gdx.scenes.scene2d.ui.Skin;
import com.badlogic.gdx.scenes.scene2d.ui.Table; import com.badlogic.gdx.scenes.scene2d.ui.Table;
import com.badlogic.gdx.scenes.scene2d.ui.TextButton; import com.badlogic.gdx.scenes.scene2d.ui.TextButton;
import com.badlogic.gdx.scenes.scene2d.utils.ClickListener; import com.badlogic.gdx.scenes.scene2d.utils.ClickListener;
import com.gameware.game.QueryIntermediate;
import com.gameware.game.GameWare;
import com.gameware.game.models.Game;
import java.io.IOException;
import java.io.IOException;
public class ViewHighScoreState extends State { public class ViewHighScoreState extends State {
private Table table; private Table table;
private List<Game> games;
private String backBtnText = "Back"; private String backBtnText = "Back";
private String colorRushHighScoreBtnText = "Color Rush";
private String bubbleWrapHighScoreBtnText = "Bubble Wrap";
public ViewHighScoreState(GameStateManager gsm) throws IOException {
public ViewHighScoreState(GameStateManager gsm) {
super(gsm); super(gsm);
System.out.println("Du er i view high score state :0");
games = getGames();
table = new Table(); table = new Table();
table.setFillParent(true); table.setFillParent(true);
table.row(); table.row();
table.add(makeBackBtn());
//TODO: autogenerer fra QI get for (Game g : games){
TextButton gameBtn = new TextButton(g.getName(), skin);
gameBtn.addListener(new ViewHighScoreState.MyClickListener(g));
table.add(gameBtn).spaceBottom(spacingOnBottom);
table.row(); table.row();
TextButton colorRushBtn = new TextButton(colorRushHighScoreBtnText, skin);
colorRushBtn.addListener(new ClickListener() {
@Override
public void clicked(InputEvent e, float x, float y){ handleColorRushBtnClick(); }
});
table.add(colorRushBtn);
table.row();
TextButton bubbleWrapBtn = new TextButton(bubbleWrapHighScoreBtnText, skin);
bubbleWrapBtn.addListener(new ClickListener() {
@Override
public void clicked(InputEvent e, float x, float y){ handleBubbleWrapBtnClick(); }
});
table.add(bubbleWrapBtn);
stage.addActor(table);
} }
private TextButton makeBackBtn(){ table.add(makeBackBtn()).spaceBottom(spacingOnBottom);
TextButton backBtn = new TextButton(backBtnText, skin); stage.addActor(table);
backBtn.addListener(new ClickListener() {
@Override
public void clicked(InputEvent e, float x, float y){ handleBackBtnClick(); }
});
return backBtn;
} }
@Override @Override
...@@ -85,9 +74,38 @@ public class ViewHighScoreState extends State { ...@@ -85,9 +74,38 @@ public class ViewHighScoreState extends State {
return this; return this;
} }
private TextButton makeBackBtn(){
TextButton backBtn = new TextButton(backBtnText, skin);
backBtn.addListener(new ClickListener() {
@Override
public void clicked(InputEvent e, float x, float y){ handleBackBtnClick(); }
});
return backBtn;
}
private void handleBackBtnClick(){ private void handleBackBtnClick(){
gsm.set(new MenuState(gsm)); gsm.set(new MenuState(gsm));
} }
private void handleColorRushBtnClick(){}
private void handleBubbleWrapBtnClick(){} private void handleGameBtnClick(){
//TODO: This needs to take in the game object and go to viewHighScoreForGameState. For the next issue.
}
private static List<Game> getGames() throws IOException {
List<Game> games = QueryIntermediate.getGames();
return games;
}
public class MyClickListener extends ClickListener{
private Game game;
public MyClickListener(Game game){
this.game = game;
}
public void clicked(InputEvent event, float x, float y) {
//TODO: Add a new hashmap to GameWare with the gameobjects from the game id from here.
handleGameBtnClick();
};
}
} }
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment