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

Class Method, % Branch, % Line, %
InfoBar 0% (0/4) 0% (0/10) 0% (0/109)
InfoBar$1 0% (0/2) 0% (0/2) 0% (0/6)
InfoBar$2 0% (0/2) 0% (0/4)
InfoBar$3 0% (0/2) 0% (0/4)
Total 0% (0/10) 0% (0/12) 0% (0/123)


 package io.github.unisim.ui;
 
 import com.badlogic.gdx.Gdx;
 import com.badlogic.gdx.graphics.Texture;
 import com.badlogic.gdx.scenes.scene2d.Stage;
 import com.badlogic.gdx.scenes.scene2d.ui.Cell;
 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.utils.ClickListener;
 import com.badlogic.gdx.utils.Align;
 import io.github.unisim.*;
 import io.github.unisim.building.BuildingType;
 import io.github.unisim.world.World;
 
 /**
  * Create a Title bar with basic info.
  */
 public class InfoBar {
   private ShapeActor bar;
   private Table infoTable = new Table();
   private Table titleTable = new Table();
   private Table buildingCountersTable = new Table();
   private Label[] buildingCounterLabels = new Label[4];
   private Skin skin = new Skin(Gdx.files.internal("ui/uiskin.json"));
   private Label scoreLabel;
   private Label titleLabel = new Label("UniSim", skin);
   private Label realTimeLabel;
   private Label gameTimeLabel;
   private Label eventTimeLabel;
   private Label moneyLabel;
   private Label repLabel;
   private Texture pauseTexture = new Texture("ui/pause.png");
   private Texture playTexture = new Texture("ui/play.png");
   private Texture gearTexture = new Texture("ui/gear.png");
   private Image pauseImage = new Image(pauseTexture);
   private Image playImage = new Image(playTexture);
   private Image gearImage = new Image(gearTexture);
   private Timer timer;
   private MoneyClass money;
   private ReputationClass rep;
   private Score score;
   private GameScreen gameScreen;
   private Cell<Label> realTimeLabelCell;
   private Cell<Label> gameTimeLabelCell;
   private Cell<Label> eventTimeLabelCell;
   private Cell<Label> moneyLabelCell;
   private Cell<Label> repLabelCell;
   private Cell<Label> scoreLabelCell;
   private Cell<Image> pauseButtonCell;
   private Cell<Table> buildingCountersTableCell;
   private Cell<Image> settingsButtonCell;
   @SuppressWarnings("rawtypes")
   private Cell[] buildingCounterCells;
   private World world;
 
   /**
    * Create a new infoBar and draws its' components onto the provided stage.
    *
    * @param stage      - The stage on which to draw the InfoBar.
    * @param timer      - The game timer
    * @param world      - Current world
    * @param score      - Score class
    * @param moneyClass - Money class
    * @param repClass   - Reputation class
    * @param gameScreen - Current game screen
    */
   public InfoBar(Stage stage, Timer timer, World world, Score score, MoneyClass moneyClass,
       ReputationClass repClass, GameScreen gameScreen) {
     this.timer = timer;
     this.world = world;
     this.money = moneyClass;
     this.rep = repClass;
     this.score = score;
     this.gameScreen = gameScreen;
     buildingCounterCells = new Cell[4];
 
     // Building counter table
     for (int i = 0; i < 4; i++) {
       buildingCounterLabels[i] = new Label("", skin);
     }
     buildingCounterCells[0] = buildingCountersTable.add(buildingCounterLabels[0]);
     buildingCounterCells[1] = buildingCountersTable.add(buildingCounterLabels[1]);
     buildingCountersTable.row();
     buildingCounterCells[2] = buildingCountersTable.add(buildingCounterLabels[2]);
     buildingCounterCells[3] = buildingCountersTable.add(buildingCounterLabels[3]);
 
     // Info Table
     realTimeLabel = new Label(timer.getRemTime(), skin);
     gameTimeLabel = new Label(timer.getGameTime(), skin);
     moneyLabel = new Label("$" + money.getMoney(), skin);
     repLabel = new Label(rep.getRep() + "%", skin);
     eventTimeLabel = new Label("Next event in: " + timer.getCurrRemSeconds(), skin);
     scoreLabel = new Label("Score: " + this.score.getScore(), skin);
     infoTable.center().center();
     pauseButtonCell = infoTable.add(playImage).align(Align.center);
     settingsButtonCell = infoTable.add(gearImage).align(Align.center);
     realTimeLabelCell = infoTable.add(realTimeLabel).align(Align.center);
     gameTimeLabelCell = infoTable.add(gameTimeLabel).align(Align.center);
     moneyLabelCell = infoTable.add(moneyLabel).align(Align.center);
     repLabelCell = infoTable.add(repLabel).align(Align.center);
     infoTable.add(titleLabel).expandX().align(Align.center).padLeft(100);
     eventTimeLabelCell = infoTable.add(eventTimeLabel).align(Align.right);
     scoreLabelCell = infoTable.add(scoreLabel).align(Align.right);
     buildingCountersTableCell = infoTable.add(buildingCountersTable).align(Align.right).padLeft(130);
 
     // Settings button
     gearImage.addListener(new ClickListener() {
       @Override
       public void clicked(com.badlogic.gdx.scenes.scene2d.InputEvent event, float x, float y) {
         if (world.selectedBuilding == null) {
           GameState.pushScreen(GameState.settingScreen);
           GameState.musicManager.pauseMusic();
           GameState.settingScreen.render(Gdx.graphics.getDeltaTime());
         } else {
           world.setPopup("building");
         }
       }
     });
 
     // Pause button
     pauseImage.addListener(new ClickListener() {
       @Override
       public void clicked(com.badlogic.gdx.scenes.scene2d.InputEvent event, float x, float y) {
         GameState.paused = true;
         GameState.musicManager.pauseMusic();
         pauseButtonCell.setActor(playImage);
       }
     });
 
     // Play button
     playImage.addListener(new ClickListener() {
       @Override
       public void clicked(com.badlogic.gdx.scenes.scene2d.InputEvent event, float x, float y) {
         GameState.paused = false;
         GameState.musicManager.resumeMusic();
         pauseButtonCell.setActor(pauseImage);
       }
     });
 
     // Add tables to the stage
     bar = new ShapeActor(GameState.UIPrimaryColour);
     stage.addActor(bar);
     stage.addActor(infoTable);
     stage.addActor(titleTable);
   }
 
   /**
    * Called when the UI needs to be updated, usually on every frame.
    */
   public void update() {
     realTimeLabel.setText(timer.getRemTime());
     gameTimeLabel.setText(timer.getGameTime());
     moneyLabel.setText("Money: $" + money.getMoney());
     repLabel.setText("Reputation: " + rep.getRep() + "%");
     eventTimeLabel.setText("Next event in: " + timer.getCurrRemSeconds());
     scoreLabel.setText("Score: " + this.score.getScore());
     buildingCounterLabels[0].setText("Recreation: "
         + Integer.toString(world.getBuildingCount(BuildingType.RECREATION)));
     buildingCounterLabels[1].setText("Learning: "
         + Integer.toString(world.getBuildingCount(BuildingType.LEARNING)));
     buildingCounterLabels[2].setText("Eating: "
         + Integer.toString(world.getBuildingCount(BuildingType.EATING)));
     buildingCounterLabels[3].setText("Sleeping: "
         + Integer.toString(world.getBuildingCount(BuildingType.SLEEPING)));
     GameState.gameOverData.setBuildings(BuildingType.RECREATION, world.getBuildingCount(BuildingType.RECREATION));
     GameState.gameOverData.setBuildings(BuildingType.LEARNING, world.getBuildingCount(BuildingType.LEARNING));
     GameState.gameOverData.setBuildings(BuildingType.EATING, world.getBuildingCount(BuildingType.EATING));
     GameState.gameOverData.setBuildings(BuildingType.SLEEPING, world.getBuildingCount(BuildingType.SLEEPING));
     pauseButtonCell.setActor(GameState.paused ? playImage : pauseImage);
     settingsButtonCell.setActor(gearImage);
     if (world.getBuildingCount(BuildingType.RECREATION) >= 4) {
       if (AchievementManager.getInstance().getAchievements().get(2).isUnlocked() == false) {
         gameScreen.addMoneyRep(3000, 10);
         String reward = "<html><p>Achievement: F is for fun</p><p>You have received $3000 and 10% rep</p><html>";
         AchievementManager.getInstance().setReward(reward);
         AchievementManager.getInstance().checkAchievement("F_FOR_FUN");
         world.setPopup("reward");
       }
     }
   }
 
   /**
    * Update the bounds of the background & table actors to fit the new size of the
    * screen.
    *
    * @param width  - The new width of the screen in pixels.
    * @param height - The enw height of the screen in pixels.
    */
   public void resize(int width, int height) {
     bar.setBounds(0, height * 0.95f, width, height * 0.05f);
     infoTable.setBounds(0, height * 0.95f, width, height * 0.05f);
     titleTable.setBounds(0, height * 0.95f, width, height * 0.05f);
 
     float counterTableWidth = height * 0.27f;
     buildingCountersTableCell.width(counterTableWidth).height(height * 0.05f);
     for (int i = 0; i < 4; i++) {
       buildingCounterLabels[i].setFontScale(height * 0.0015f);
       buildingCounterCells[i].width(counterTableWidth * 0.5f).height(height * 0.025f);
     }
 
     realTimeLabel.setFontScale(height * 0.002f);
     realTimeLabelCell.width(height * 0.08f).height(height * 0.05f);
     realTimeLabelCell.padLeft(height * 0.005f);
     gameTimeLabel.setFontScale(height * 0.002f);
     gameTimeLabelCell.width(height * 0.08f).height(height * 0.05f);
     gameTimeLabelCell.padLeft(height * 0.005f);
     moneyLabel.setFontScale(height * 0.002f);
     moneyLabelCell.width(height * 0.08f).height(height * 0.05f);
     moneyLabelCell.padLeft(height * 0.07f);
     repLabel.setFontScale(height * 0.002f);
     repLabelCell.width(height * 0.08f).height(height * 0.05f);
     repLabelCell.padLeft(height * 0.14f);
     eventTimeLabel.setFontScale(height * 0.002f);
     eventTimeLabelCell.width(height * 0.08f).height(height * 0.05f);
     eventTimeLabelCell.padLeft(height * 0.02f);
     scoreLabel.setFontScale(height * 0.002f);
     scoreLabelCell.width(height * 0.04f).height(height * 0.05f);
     scoreLabelCell.padLeft(Math.min(width, height * 2) * 0.1f);
     settingsButtonCell.width(height * 0.03f).height(height * 0.03f);
     pauseButtonCell.width(height * 0.03f).height(height * 0.03f)
         .padLeft(height * 0.02f).padRight(height * 0.01f);
 
     titleLabel.setFontScale(height * 0.003f);
   }
 
   public void reset() {
     pauseButtonCell.setActor(playImage);
   }
 }