Coverage Summary for Class: Page (com.mygdx.game.UI)

Class Class, % Method, % Line, %
Page 0% (0/1) 0% (0/6) 0% (0/24)


1 package com.mygdx.game.UI; 2  3 import com.badlogic.gdx.Gdx; 4 import com.badlogic.gdx.Input; 5 import com.badlogic.gdx.ScreenAdapter; 6 import com.badlogic.gdx.scenes.scene2d.Actor; 7 import com.mygdx.game.PirateGame; 8  9 import java.util.ArrayList; 10  11 import static com.mygdx.utils.Constants.UPDATE_VIEWPORT; 12  13 /** 14  * Base class for UI screens. Contains and draws UI actors added in subclasses. 15  */ 16 public abstract class Page extends ScreenAdapter { 17  PirateGame parent; 18  19  protected ArrayList<Actor> actors; 20  21  /** 22  * Creates a Page Object 23  * @param parent The Game which this is attached to 24  */ 25  public Page(PirateGame parent) { 26  this.parent = parent; 27  actors = new ArrayList<>(); 28  CreateActors(); 29  } 30  31  protected abstract void CreateActors(); 32  33  /** 34  * Called once the page is show sets input handler and adds actors 35  */ 36  @Override 37  public void show() { 38  // button.addListener(new ChangeListener() { 39  // public void changed (ChangeEvent event, Actor actor) { 40  // System.out.println("Clicked! Is checked: " + button.isChecked()); 41  // button.setText("Good job!"); 42  // } 43  // }); 44  super.show(); 45  Gdx.input.setInputProcessor(parent.stage); 46  for (Actor a : actors) { 47  parent.stage.addActor(a); 48  } 49  } 50  51  /** 52  * draws the stage and acts upon it also calls update 53  * @param delta delta time 54  */ 55  @Override 56  public void render(float delta) { 57  update(); 58  super.render(delta); 59  parent.stage.act(delta); 60  parent.stage.draw(); 61  if (Gdx.input.isKeyJustPressed(Input.Keys.ENTER)) { 62  parent.setScreen(parent.game); 63  } 64  } 65  66  /** 67  * Called once the page is hidden. sets input handler to null and clears teh stage 68  */ 69  @Override 70  public void hide() { 71  super.hide(); 72  Gdx.input.setInputProcessor(null); 73  parent.stage.clear(); 74  } 75  76  /** 77  * Called once the window is resized - updates constants and stage 78  * @param width new dim x 79  * @param height new dom y 80  */ 81  @Override 82  public void resize(int width, int height) { 83  super.resize(width, height); 84  UPDATE_VIEWPORT(width, height); 85  parent.stage.getCamera().viewportWidth = width; 86  parent.stage.getCamera().viewportHeight = height; 87  parent.stage.getViewport().update(width, height, true); 88  } 89  90  /** 91  * Called once per frame 92  */ 93  protected void update() { 94  95  } 96 }