diff --git a/frontend/core/src/com/gameware/game/states/MenuState.java b/frontend/core/src/com/gameware/game/states/MenuState.java index abf75d9a768d8e945f0c7a4fb4b19685d7797052..b188d4a7acc1c43758b4879db7f83f23b9a60a4d 100644 --- a/frontend/core/src/com/gameware/game/states/MenuState.java +++ b/frontend/core/src/com/gameware/game/states/MenuState.java @@ -75,7 +75,13 @@ public class MenuState extends State{ TextButton highScoreBtn = new TextButton(highScoreBtnText, skin); highScoreBtn.addListener(new ClickListener() { @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; } @@ -131,7 +137,7 @@ public class MenuState extends State{ gsm.set(new SinglePlayerSelectGameState(gsm)); } - private void handleHighscoreBtnClick(){ + private void handleHighscoreBtnClick() throws IOException { gsm.set(new ViewHighScoreState(gsm)); } diff --git a/frontend/core/src/com/gameware/game/states/ViewHighScoreState.java b/frontend/core/src/com/gameware/game/states/ViewHighScoreState.java index 7d17cf6c4075d3937c71eac9ff32947e28154baa..7ce02c06753b6c407bec74b9c2cefce9f17b9e00 100644 --- a/frontend/core/src/com/gameware/game/states/ViewHighScoreState.java +++ b/frontend/core/src/com/gameware/game/states/ViewHighScoreState.java @@ -2,59 +2,48 @@ package com.gameware.game.states; import com.badlogic.gdx.graphics.g2d.SpriteBatch; 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.Table; import com.badlogic.gdx.scenes.scene2d.ui.TextButton; 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 { private Table table; + private List<Game> games; private String backBtnText = "Back"; - private String colorRushHighScoreBtnText = "Color Rush"; - private String bubbleWrapHighScoreBtnText = "Bubble Wrap"; - - public ViewHighScoreState(GameStateManager gsm) { + public ViewHighScoreState(GameStateManager gsm) throws IOException { super(gsm); - System.out.println("Du er i view high score state :0"); + + games = getGames(); table = new Table(); table.setFillParent(true); table.row(); - table.add(makeBackBtn()); - //TODO: autogenerer fra QI get - 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); + 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.add(makeBackBtn()).spaceBottom(spacingOnBottom); stage.addActor(table); } - 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; - } - @Override protected void handleInput() { @@ -85,9 +74,38 @@ public class ViewHighScoreState extends State { 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(){ 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