Coverage Summary for Class: StartMenuScreen (io.github.unisim.ui)

Class Method, % Branch, % Line, %
StartMenuScreen 0% (0/8) 0% (0/4) 0% (0/64)
StartMenuScreen$1 0% (0/2) 0% (0/2)
StartMenuScreen$2 0% (0/2) 0% (0/2)
StartMenuScreen$3 0% (0/2) 0% (0/3)
StartMenuScreen$4 0% (0/2) 0% (0/2)
StartMenuScreen$5 0% (0/2) 0% (0/4)
StartMenuScreen$6 0% (0/2) 0% (0/4)
Total 0% (0/20) 0% (0/4) 0% (0/81)


 package io.github.unisim.ui;
 
 import com.badlogic.gdx.Gdx;
 import com.badlogic.gdx.InputMultiplexer;
 import com.badlogic.gdx.Screen;
 import com.badlogic.gdx.graphics.Texture;
 import com.badlogic.gdx.scenes.scene2d.Stage;
 import com.badlogic.gdx.scenes.scene2d.ui.Image;
 import com.badlogic.gdx.scenes.scene2d.ui.Label;
 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.badlogic.gdx.utils.ScreenUtils;
 import io.github.unisim.GameState;
 
 /**
  * The start menu screen which presents the player with the option to start the
  * game, access the settings menu, acievements screen, leaderboard screen, how
  * to play screen and an option to exit the game
  */
 public class StartMenuScreen implements Screen {
   private Stage stage;
   private Table mainTable;
   private Table secTable;
   private Skin altskin;
   private TextButton playButton;
   private TextButton settingsButton;
   private TextButton exitButton;
   private TextButton howToButton;
   private TextButton achieveButton;
   private TextButton leaderButton;
   private InputMultiplexer inputMultiplexer = new InputMultiplexer();
   private Popups popup = new Popups(null);
 
   /**
    * Create a new StartMenuScreen and draw the initial UI layout.
    */
   public StartMenuScreen() {
     stage = new Stage();
     mainTable = new Table();
     secTable = new Table();
     altskin = GameState.altSkin;
     // Create an Image for the background
     Image backgroundImage = new Image(new Texture(Gdx.files.internal("ui/mainmenubackground.gif")));
     backgroundImage.setFillParent(true); // Fill the screen with image
     stage.addActor(backgroundImage); // Add the background to the stage
 
     // Play button
     playButton = new TextButton("Play", altskin);
     playButton.addListener(new ClickListener() {
       @Override
       public void clicked(com.badlogic.gdx.scenes.scene2d.InputEvent event, float x, float y) {
         // Switch to the game screen
         popup.namePopup();
       }
     });
 
     // How to play button
     howToButton = new TextButton("How to play", altskin);
     howToButton.addListener(new ClickListener() {
       @Override
       public void clicked(com.badlogic.gdx.scenes.scene2d.InputEvent event, float x, float y) {
         GameState.currentScreen = GameState.howToPlayScreen;
       }
     });
 
     // Settings button
     settingsButton = new TextButton("Settings", altskin);
     settingsButton.addListener(new ClickListener() {
       @Override
       public void clicked(com.badlogic.gdx.scenes.scene2d.InputEvent event, float x, float y) {
         // Switch to the settings screen
         GameState.pushScreen(GameState.settingScreen);
         GameState.currentScreen = GameState.settingScreen;
       }
     });
 
     // Exit button
     exitButton = new TextButton("Exit", altskin);
     exitButton.addListener(new ClickListener() {
       @Override
       public void clicked(com.badlogic.gdx.scenes.scene2d.InputEvent event, float x, float y) {
         // Exit game
         Gdx.app.exit();
       }
     });
 
     // Achievements button
     achieveButton = new TextButton("Achievements", altskin);
     achieveButton.addListener(new ClickListener() {
       @Override
       public void clicked(com.badlogic.gdx.scenes.scene2d.InputEvent event, float x, float y) {
         GameState.achievementScreen = new AchievementScreen();
         GameState.pushScreen(GameState.achievementScreen);
         GameState.currentScreen = GameState.achievementScreen;
       }
     });
 
     // Leaderboard button
     leaderButton = new TextButton("Leaderboard", altskin);
     leaderButton.addListener(new ClickListener() {
       @Override
       public void clicked(com.badlogic.gdx.scenes.scene2d.InputEvent event, float x, float y) {
         GameState.leaderboardScreen = new LeaderboardScreen();
         GameState.pushScreen(GameState.leaderboardScreen);
         GameState.currentScreen = GameState.leaderboardScreen;
       }
     });
 
     // Add UI elements to the stage
     Label title = new Label("UniSim", altskin);
     title.setFontScale(2f);
     title.setPosition(Gdx.graphics.getWidth() / 2 - 110,
         Gdx.graphics.getHeight() - 170);
     stage.addActor(title);
 
     // Main table containing play,howToPlay, settings, and exit buttons
     mainTable.setFillParent(true);
     mainTable.center().center();
     mainTable.pad(100, 100, 100, 100);
     mainTable.add(playButton).center().width(250).height(40).padBottom(10);
     mainTable.row().padTop(10);
     mainTable.add(howToButton).center().width(250).height(40).padBottom(10);
     mainTable.row().padTop(10);
     mainTable.add(settingsButton).center().width(250).height(40).padBottom(10);
     mainTable.row().padTop(10);
     mainTable.add(exitButton).center().width(250).height(40);
     stage.addActor(mainTable);
 
     // Secondary table for the achievement and leaderboard buttons
     secTable.setFillParent(true);
     secTable.pad(680, 1070, 100, 100);
     secTable.add(achieveButton).center().width(300).height(40);
     secTable.row();
     secTable.row();
     secTable.add(leaderButton).center().width(300).height(40).padTop(20);
     stage.addActor(secTable);
 
     inputMultiplexer.addProcessor(GameState.fullscreenInputProcessor);
     inputMultiplexer.addProcessor(stage);
   }
 
   @Override
   public void show() {
     GameState.gameScreen = new GameScreen();
     popup.setActive(false);
     if (GameState.musicManager.getMusic() == null) { // Plays menu music
       GameState.musicManager.stopMusic();
       GameState.musicManager.playMenuMusic();
     }
   }
 
   @Override
   public void render(float delta) {
     // Clear the screen
     ScreenUtils.clear(GameState.UISecondaryColour);
 
     // Draw the stage containing buttons
     stage.act(delta);
     stage.draw();
 
     // Disables any interaction with menu screen when a popup is active
     if (popup.getActive()) {
       Gdx.input.setInputProcessor(null);
     } else {
       Gdx.input.setInputProcessor(inputMultiplexer);
     }
   }
 
   @Override
   public void resize(int width, int height) {
     stage.getViewport().update(width, height, true);
   }
 
   @Override
   public void pause() {
   }
 
   @Override
   public void resume() {
     Gdx.input.setInputProcessor(inputMultiplexer);
   }
 
   @Override
   public void hide() {
   }
 
   @Override
   public void dispose() {
     stage.dispose();
     altskin.dispose();
   }
 }