Coverage Summary for Class: PauseScreen (com.mygdx.game.UI)
| Class | Method, % | Line, % |
|---|---|---|
| PauseScreen | 0% (0/4) | 0% (0/36) |
| PauseScreen$1 | 0% (0/2) | 0% (0/2) |
| PauseScreen$2 | 0% (0/2) | 0% (0/3) |
| PauseScreen$3 | 0% (0/2) | 0% (0/4) |
| PauseScreen$4 | 0% (0/2) | 0% (0/3) |
| Total | 0% (0/12) | 0% (0/48) |
1 package com.mygdx.game.UI; 2 3 import com.badlogic.gdx.Gdx; 4 import com.badlogic.gdx.Input; 5 import com.badlogic.gdx.graphics.Color; 6 import com.badlogic.gdx.graphics.Texture; 7 import com.badlogic.gdx.graphics.g2d.TextureRegion; 8 import com.badlogic.gdx.scenes.scene2d.Actor; 9 import com.badlogic.gdx.scenes.scene2d.ui.Label; 10 import com.badlogic.gdx.scenes.scene2d.ui.Table; 11 import com.badlogic.gdx.scenes.scene2d.ui.TextButton; 12 import com.badlogic.gdx.scenes.scene2d.utils.ChangeListener; 13 import com.badlogic.gdx.scenes.scene2d.utils.TextureRegionDrawable; 14 15 import com.mygdx.game.Managers.SaveManager; 16 import com.mygdx.game.PirateGame; 17 18 import static com.mygdx.utils.Constants.VIEWPORT_HEIGHT; 19 20 /** 21 * New for Assessment 2, added to allow the addition of a restart button without causing screen clutter. 22 * Contains widgets defining the pause screen. 23 */ 24 public class PauseScreen extends Page{ 25 26 /** 27 * Creates a Pause Screen 28 * @param game The game object this screen is viewing 29 */ 30 public PauseScreen(PirateGame game) { 31 super(game); 32 } 33 34 @Override 35 protected void CreateActors() { 36 Table t = new Table(); 37 // t.debug(); 38 39 float space = VIEWPORT_HEIGHT * 0.10f; 40 t.setFillParent(true); 41 actors.add(t); 42 t.add(); 43 t.row(); 44 Label title = new Label("Paused", parent.skin); 45 title.setFontScale(2); 46 t.top(); 47 t.add(title).top().spaceTop(space).spaceBottom(space); 48 t.row(); 49 TextButton resume = new TextButton("Resume", parent.skin); 50 resume.addListener(new ChangeListener() { 51 @Override 52 public void changed(ChangeEvent event, Actor actor) { 53 parent.setScreen(parent.game); 54 } 55 }); 56 t.add(resume).fill().spaceBottom(space); 57 t.row(); 58 TextButton restart = new TextButton("Restart", parent.skin); 59 restart.addListener(new ChangeListener() { 60 @Override 61 public void changed(ChangeEvent event, Actor actor) { 62 parent.game.hide(); 63 parent.restartGame(); 64 } 65 }); 66 t.add(restart).fill().spaceBottom(space); 67 t.row(); 68 69 TextButton SExit = new TextButton("Save + Exit", parent.skin); 70 SExit.addListener(new ChangeListener() { 71 @Override 72 public void changed(ChangeEvent event, Actor actor) { 73 SaveManager.SaveGame(); 74 75 Gdx.app.exit(); 76 System.exit(0); 77 78 } 79 }); 80 t.add(SExit).fill().spaceBottom(space); 81 t.row(); 82 TextButton exit = new TextButton("Exit", parent.skin); 83 exit.addListener(new ChangeListener() { 84 @Override 85 public void changed(ChangeEvent event, Actor actor) { 86 87 Gdx.app.exit(); 88 System.exit(0); 89 90 } 91 }); 92 t.add(exit).fill().spaceBottom(space); 93 } 94 95 /** 96 * Called Once per frame 97 */ 98 @Override 99 protected void update() { 100 super.update(); 101 102 if (Gdx.input.isKeyJustPressed(Input.Keys.ESCAPE)) { 103 Gdx.app.exit(); 104 System.exit(0); 105 } 106 } 107 108 /** 109 * Resizes the viewport 110 * @param width The horizontal dimension of the viewport 111 * @param height The vertical dimension of the viewport 112 */ 113 @Override 114 public void resize(int width, int height) { 115 super.resize(width, height); 116 Table t = (Table) actors.get(0); 117 TextureRegion tex = new TextureRegion(new Texture(parent.game.pixmap)); 118 tex.flip(false, true); 119 t.setBackground((new TextureRegionDrawable(tex)).tint(Color.GRAY)); 120 } 121 } 122