Skip to content
Snippets Groups Projects
Commit 6f2c5a6c authored by Turid Cecilie Dahl's avatar Turid Cecilie Dahl
Browse files

#50 makes ViewHighScoreForGameState prettier

parent d4faee67
No related branches found
No related tags found
1 merge request!66Resolve "Make it look pretty"
...@@ -2,13 +2,18 @@ package com.gameware.game.states; ...@@ -2,13 +2,18 @@ package com.gameware.game.states;
import com.badlogic.gdx.Gdx; import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.Input; import com.badlogic.gdx.Input;
import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.graphics.Pixmap;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.SpriteBatch; import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.badlogic.gdx.graphics.g2d.TextureRegion;
import com.badlogic.gdx.scenes.scene2d.InputEvent; import com.badlogic.gdx.scenes.scene2d.InputEvent;
import com.badlogic.gdx.scenes.scene2d.ui.Label; import com.badlogic.gdx.scenes.scene2d.ui.Label;
import com.badlogic.gdx.scenes.scene2d.ui.ScrollPane; import com.badlogic.gdx.scenes.scene2d.ui.ScrollPane;
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.badlogic.gdx.scenes.scene2d.utils.TextureRegionDrawable;
import com.gameware.game.GameWare; import com.gameware.game.GameWare;
import com.gameware.game.QueryIntermediate; import com.gameware.game.QueryIntermediate;
import com.gameware.game.models.Game; import com.gameware.game.models.Game;
...@@ -31,10 +36,17 @@ public class ViewHighScoreForGameState extends State { ...@@ -31,10 +36,17 @@ public class ViewHighScoreForGameState extends State {
private double playerHS; private double playerHS;
private static List<Highscore> highscores = new ArrayList<>(); private static List<Highscore> highscores = new ArrayList<>();
private Boolean isNoHS = true; private Boolean isNoHS = true;
private Label gameNameText;
private Label stateNameText;
private ScrollPane scrollPane;
private String backBtnText = "Back"; private String backBtnText = "Back";
private String playerLabelText = "You"; private String playerLabelText = "Your score: ";
private String noHSLabelText = ""; private String noHSLabelText = "";
private String globalHighScoresText = "Global High Scores";
private String colOneText = "Place";
private String colTwoText = "Name";
private String colThreeText = "Score";
protected ViewHighScoreForGameState(GameStateManager gsm, Game game) { protected ViewHighScoreForGameState(GameStateManager gsm, Game game) {
super(gsm); super(gsm);
...@@ -52,6 +64,9 @@ public class ViewHighScoreForGameState extends State { ...@@ -52,6 +64,9 @@ public class ViewHighScoreForGameState extends State {
isNoHS = true; isNoHS = true;
} }
gameNameText = new Label(game.getName(), skin, "big");
stateNameText = new Label(globalHighScoresText, skin, "big");
makeStage(); makeStage();
} }
...@@ -113,7 +128,25 @@ public class ViewHighScoreForGameState extends State { ...@@ -113,7 +128,25 @@ public class ViewHighScoreForGameState extends State {
private void makeStage() { private void makeStage() {
outerTable = new Table(); outerTable = new Table();
outerTable.setFillParent(true); outerTable.setFillParent(true);
outerTable.setBackground(background);
stateNameText.setFontScale(tinierTitleFontBigScale);
gameNameText.setFontScale(tinierTitleFontBigScale);
outerTable.add(gameNameText);
outerTable.row();
outerTable.add(stateNameText).spaceBottom(spacingOnBottomInputFIeld);
outerTable.row();
innerTable = new Table(); innerTable = new Table();
Pixmap bgPixmap = new Pixmap(1,1, Pixmap.Format.RGB565);
bgPixmap.setColor(Color.SKY);
bgPixmap.fill();
TextureRegionDrawable textureRegionDrawableBg = new TextureRegionDrawable(new TextureRegion(new Texture(bgPixmap)));
innerTable.setBackground(textureRegionDrawableBg);
innerTable.setFillParent(true);
if(isNoHS){ if(isNoHS){
noHSLabelText = "No high scores recorded."; noHSLabelText = "No high scores recorded.";
...@@ -132,6 +165,20 @@ public class ViewHighScoreForGameState extends State { ...@@ -132,6 +165,20 @@ public class ViewHighScoreForGameState extends State {
outerTable.add(hsPane).spaceBottom(spacingOnBottomInputFIeld); outerTable.add(hsPane).spaceBottom(spacingOnBottomInputFIeld);
outerTable.getCell(hsPane).size(Gdx.graphics.getWidth()/1.1f, Gdx.graphics.getWidth()/2.5f); outerTable.getCell(hsPane).size(Gdx.graphics.getWidth()/1.1f, Gdx.graphics.getWidth()/2.5f);
outerTable.row();
Table secondInnerTable = new Table();
Pixmap secondBgPixmap = new Pixmap(1,1, Pixmap.Format.RGB565);
secondBgPixmap.setColor(Color.SKY);
secondBgPixmap.fill();
TextureRegionDrawable secondTextureRegionDrawableBg = new TextureRegionDrawable(new TextureRegion(new Texture(secondBgPixmap)));
secondInnerTable.setBackground(secondTextureRegionDrawableBg);
Label playerLabel = new Label(playerLabelText,skin);
Label playerScoreLabel = new Label(String.valueOf(playerHS),skin);
secondInnerTable.add(playerLabel).spaceTop(spacingOnBottom).pad(50);
secondInnerTable.add(playerScoreLabel).spaceTop(spacingOnBottom).pad(50);
outerTable.add(secondInnerTable);
stage.addActor(outerTable); stage.addActor(outerTable);
stage.addActor(makeBackBtn()); stage.addActor(makeBackBtn());
} }
...@@ -145,12 +192,17 @@ public class ViewHighScoreForGameState extends State { ...@@ -145,12 +192,17 @@ public class ViewHighScoreForGameState extends State {
e.printStackTrace(); e.printStackTrace();
} }
innerTable.add(new Label(colOneText, skin));
innerTable.add(new Label(colTwoText, skin)).spaceRight(spacingOnBottom);
innerTable.add(new Label(colThreeText, skin));
innerTable.row();
int length = Math.min(highscores.size(),5); int length = Math.min(highscores.size(),5);
for (int i = 0; i < length; i++){ for (int i = 0; i < length; i++){
Highscore hs = highscores.get(i); Highscore hs = highscores.get(i);
Label placementLabel = new Label(String.valueOf(i+1)+". place: ",skin); Label placementLabel = new Label(String.valueOf(i+1)+". ",skin);
Label nameLabel = new Label(hs.getName()+" ",skin); Label nameLabel = new Label(hs.getName()+" ",skin);
Label scoreLabel = new Label(String.valueOf(hs.getValue()),skin); Label scoreLabel = new Label(String.valueOf(hs.getValue()),skin);
...@@ -159,13 +211,6 @@ public class ViewHighScoreForGameState extends State { ...@@ -159,13 +211,6 @@ public class ViewHighScoreForGameState extends State {
innerTable.add(scoreLabel); innerTable.add(scoreLabel);
innerTable.row(); innerTable.row();
} }
Label playerLabel = new Label(playerLabelText,skin);
Label playerScoreLabel = new Label(String.valueOf(playerHS),skin);
innerTable.add(playerLabel).spaceTop(spacingOnBottom);
innerTable.add(playerScoreLabel).spaceTop(spacingOnBottom);
innerTable.row();
} }
} }
\ 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