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