Coverage Summary for Class: MenuScreen (com.mygdx.game.UI)
| Class | Method, % | Line, % |
|---|---|---|
| MenuScreen | 0% (0/7) | 0% (0/49) |
| MenuScreen$1 | 0% (0/2) | 0% (0/9) |
| MenuScreen$2 | 0% (0/2) | 0% (0/5) |
| MenuScreen$3 | 0% (0/2) | 0% (0/3) |
| Total | 0% (0/13) | 0% (0/66) |
1 package com.mygdx.game.UI; 2 3 import com.badlogic.gdx.Gdx; 4 import com.badlogic.gdx.scenes.scene2d.Actor; 5 import com.badlogic.gdx.scenes.scene2d.ui.Label; 6 import com.badlogic.gdx.scenes.scene2d.ui.SelectBox; 7 import com.badlogic.gdx.scenes.scene2d.ui.Table; 8 import com.badlogic.gdx.scenes.scene2d.ui.TextButton; 9 import com.badlogic.gdx.scenes.scene2d.utils.ChangeListener; 10 import com.badlogic.gdx.scenes.scene2d.utils.TextureRegionDrawable; 11 import com.mygdx.game.Entitys.Player; 12 import com.mygdx.game.Managers.DifficultyManager; 13 import com.mygdx.game.Managers.GameManager; 14 import com.mygdx.game.Managers.ResourceManager; 15 import com.mygdx.game.PirateGame; 16 import com.mygdx.utils.SaveObject; 17 18 19 import javax.swing.*; 20 21 import java.awt.*; 22 import java.io.File; 23 import java.io.FileNotFoundException; 24 25 import static com.mygdx.utils.Constants.VIEWPORT_HEIGHT; 26 27 /** 28 * Contains widgets defining the start-of-game menu screen. 29 */ 30 public class MenuScreen extends Page { 31 public MenuScreen(PirateGame parent) { 32 super(parent); 33 } 34 35 /** 36 * Create menu widgets such as start button, labels, etc. 37 */ 38 @Override 39 protected void CreateActors() { 40 Table t = new Table(); 41 t.setFillParent(true); 42 43 float space = VIEWPORT_HEIGHT * 0.10f; 44 45 t.setBackground(new TextureRegionDrawable(ResourceManager.getTexture("newmenuBG.jpg"))); 46 Label l = new Label("Pirates the movie the game", parent.skin); 47 l.setFontScale(2); 48 t.add(l).top().spaceBottom(space * 0.5f); 49 t.row(); 50 51 TextButton play = new TextButton("Play", parent.skin); 52 t.add(play).top().size(100, 25); 53 t.row(); 54 55 final SelectBox<String> selectBox=new SelectBox<String>(parent.skin); 56 selectBox.setItems("Select Difficulty","Easy","Normal","Hard"); 57 58 t.add(selectBox).top().size(100, 25).spaceBottom(space); 59 t.row(); 60 61 62 play.addListener(new ChangeListener() { 63 @Override 64 public void changed(ChangeEvent event, Actor actor) { 65 switch (selectBox.getSelected()){ 66 case "Select Difficulty": 67 return; 68 case "Easy": 69 DifficultyManager.SelectEasy(); 70 break; 71 case "Normal": 72 DifficultyManager.SelectNormal(); 73 break; 74 case "Hard": 75 DifficultyManager.SelectHard(); 76 break; 77 } 78 parent.setScreen(parent.game); 79 GameManager.getPlayer().updateHealth(); 80 } 81 }); 82 83 84 TextButton load = new TextButton("Load", parent.skin); 85 load.addListener(new ChangeListener() { 86 @Override 87 public void changed(ChangeEvent event, Actor actor) { 88 try { 89 showLoadMenu(); 90 } catch (FileNotFoundException e) { 91 e.printStackTrace(); 92 } 93 } 94 }); 95 t.add(load).top().size(100, 25).spaceBottom(space); 96 t.row(); 97 98 99 TextButton quit = new TextButton("Quit", parent.skin); 100 quit.addListener(new ChangeListener() { 101 @Override 102 public void changed(ChangeEvent event, Actor actor) { 103 Gdx.app.exit(); 104 System.exit(0); 105 } 106 }); 107 t.add(quit).size(100, 25).top().spaceBottom(space); 108 109 t.top(); 110 111 actors.add(t); 112 } 113 114 @Override 115 public void show() { 116 super.show(); 117 } 118 119 120 @Override 121 public void hide() { 122 super.hide(); 123 } 124 125 /** 126 * Resize background and game window to the inputted scale 127 * @param width new dim x the width of the game window 128 * @param height new dom y the height of the game window 129 */ 130 @Override 131 public void resize(int width, int height) { 132 super.resize(width, height); 133 Table t = (Table) actors.get(0); 134 t.setBackground(new TextureRegionDrawable(ResourceManager.getTexture("newmenuBG.jpg"))); // prevent the bg being stretched 135 } 136 137 /**NEW 138 * Shows the load menu for windows 139 * for mac loads from macs save file 140 * 141 * @throws FileNotFoundException 142 */ 143 private void showLoadMenu() throws FileNotFoundException { 144 if(System.getProperty("os.name").contains("Mac")){ 145 //Get ABSOLOUTE file for mac 146 File f = new File("mac_save.xml"); 147 148 if(!f.exists()){ 149 throw new FileNotFoundException(); 150 } 151 SaveObject.readXML("SAVED_GAME.xml"); 152 //to be removed upon implementation in save 153 DifficultyManager.SelectEasy(); 154 parent.setScreen(parent.game); 155 //to be removed upon implementation in save 156 GameManager.getPlayer().updateHealth(); 157 158 } 159 else{ 160 JFileChooser fileChooser = new JFileChooser(); 161 162 int value = fileChooser.showOpenDialog(null); 163 if (value == JFileChooser.APPROVE_OPTION){ 164 File selected= fileChooser.getSelectedFile(); 165 166 SaveObject.readXML(selected.getAbsolutePath()); 167 //to be removed upon implementation in save 168 DifficultyManager.SelectEasy(); 169 parent.setScreen(parent.game); 170 //to be removed upon implementation in save 171 GameManager.getPlayer().updateHealth(); 172 173 } 174 175 } 176 177 178 } 179 }