Skip to content

Commit

Permalink
Added credits screen, refactored SelectionMenuRenderComponent
Browse files Browse the repository at this point in the history
  • Loading branch information
retrodaredevil committed Oct 13, 2018
1 parent c6c63b8 commit 17f093c
Show file tree
Hide file tree
Showing 18 changed files with 498 additions and 213 deletions.
79 changes: 79 additions & 0 deletions core/src/me/retrodaredevil/game/trackshooter/CreditsScreen.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
package me.retrodaredevil.game.trackshooter;

import com.badlogic.gdx.ScreenAdapter;
import com.badlogic.gdx.scenes.scene2d.Stage;
import com.badlogic.gdx.scenes.scene2d.ui.Table;
import com.badlogic.gdx.utils.viewport.FitViewport;

import java.util.List;

import me.retrodaredevil.game.trackshooter.input.GameInput;
import me.retrodaredevil.game.trackshooter.render.RenderObject;
import me.retrodaredevil.game.trackshooter.render.RenderParts;
import me.retrodaredevil.game.trackshooter.render.Renderer;

public class CreditsScreen extends ScreenAdapter implements UsableScreen {

private final List<GameInput> gameInputs;
private final GameInput gameInput;
private final RenderObject renderObject;
private final RenderParts renderParts;
private final Stage stage;
private boolean done = false;

public CreditsScreen(List<GameInput> gameInputs, RenderObject renderObject, RenderParts renderParts){
this.gameInputs = gameInputs;
this.gameInput = gameInputs.get(0);
this.renderObject = renderObject;
this.renderParts = renderParts;
this.stage = new Stage(new FitViewport(640, 640), renderObject.getBatch());
Table table = new Table(renderObject.getUISkin());
table.setFillParent(true);
stage.addActor(table);

table.add("Game made by Joshua Shannon").center().row();
table.add("Game made using LibGDX").center().row();
table.add("This game is still in beta, please report any bugs you find").center().row();
table.add("and requests features that are not currently in the game").center().row();
table.add("").center().row();
table.add("Default (mobile) control scheme:").center().row();
table.add("Use the joystick on the left to move").center().row();
table.add("Use the Y axis on the right side of the screen to rotate").center().row();
table.add("Release the right side of the screen to shoot").center().row();
table.add("The back button is used to exit menus and pause the game").center().row();
table.add("").center().row();
table.add("The control scheme can be changed in options").center().row();
}
private Renderer createRenderer(){
Renderer r = new Renderer(renderObject.getBatch(), stage);
r.addRenderable(renderParts.getBackground());
r.addRenderable(renderParts.getOverlay());
r.addMainStage(); // chances are, the main stage has already been added
return r;
}

@Override
public void render(float delta) {
createRenderer().render(delta);

if(gameInput.getBackButton().isPressed()){
done = true;
}
}

@Override
public void resize(int width, int height) {
stage.getViewport().update(width, height, true);
renderParts.resize(width, height);
}

@Override
public boolean isScreenDone() {
return done;
}

@Override
public UsableScreen createNextScreen() {
return new StartScreen(gameInputs, renderObject, renderParts);
}
}
18 changes: 13 additions & 5 deletions core/src/me/retrodaredevil/game/trackshooter/GameScreen.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package me.retrodaredevil.game.trackshooter;

import com.badlogic.gdx.scenes.scene2d.Stage;
import com.badlogic.gdx.scenes.scene2d.ui.Button;
import com.badlogic.gdx.scenes.scene2d.ui.TextButton;

import java.util.ArrayList;
import java.util.Iterator;
Expand All @@ -23,21 +25,22 @@ public class GameScreen implements UsableScreen {
// private final GameInput gameInput;
private final List<Player> players = new ArrayList<>(); // elements may be removed // initialized in constructor
private final List<GameInput> gameInputs;
private final Stage stage;
private final World world;

private final RenderObject renderObject;
private final RenderParts renderParts;

private final Stage stage;

private boolean shouldExit = false;
private boolean paused = false;

public GameScreen(List<GameInput> gameInputs, RenderObject renderObject, RenderParts renderParts){
this.gameInputs = gameInputs;
this.world = new World(new GameLevelGetter(players), 18, 18, renderObject);
this.stage = new Stage(new WorldViewport(world), renderObject.getBatch());
this.renderParts = renderParts;
this.renderObject = renderObject;
stage = new Stage(new WorldViewport(world), renderObject.getBatch());

{
int i = 0;
Expand Down Expand Up @@ -67,6 +70,10 @@ private void doUpdate(float delta){
break;
}
}
renderParts.getOverlay().setPauseVisible(true);
if(renderParts.getOverlay().isPausePressed()){
paused = !paused;
}
renderParts.getOptionsMenu().closeMenu(); // stop displaying options menu
renderParts.getOverlay().update(delta, world);
if(paused){
Expand Down Expand Up @@ -143,9 +150,10 @@ private void doRender(float delta){

inputFocuser.add(inGameFocuser);
}
if(paused){

}
inputFocuser.addParallel(renderParts.getOverlay());
// if(paused){ // TODO pause menu
//
// }
inputFocuser.giveFocus(stage, renderParts.getInputMultiplexer());
}
public void setToExit(){
Expand Down
45 changes: 25 additions & 20 deletions core/src/me/retrodaredevil/game/trackshooter/StartScreen.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import java.util.Objects;

import me.retrodaredevil.game.trackshooter.input.GameInput;
import me.retrodaredevil.game.trackshooter.render.ComponentRenderable;
import me.retrodaredevil.game.trackshooter.render.RenderObject;
import me.retrodaredevil.game.trackshooter.render.RenderParts;
import me.retrodaredevil.game.trackshooter.render.Renderable;
Expand All @@ -26,6 +27,8 @@
import me.retrodaredevil.game.trackshooter.render.selection.PlainActorSingleOption;
import me.retrodaredevil.game.trackshooter.render.selection.SelectionMenuRenderComponent;
import me.retrodaredevil.game.trackshooter.render.selection.SingleOption;
import me.retrodaredevil.game.trackshooter.render.selection.options.MultiActorOptionProvider;
import me.retrodaredevil.game.trackshooter.render.selection.tables.PlainTable;

public class StartScreen extends ScreenAdapter implements UsableScreen{
private static final int BUTTON_WIDTH = 220;
Expand All @@ -34,13 +37,14 @@ public class StartScreen extends ScreenAdapter implements UsableScreen{
private final GameInput gameInput;
private final RenderParts renderParts;
private final RenderObject renderObject;
private boolean start;
private UsableScreen nextScreen = null;

private final Stage uiStage;
private final Renderable menuRenderable;

private final Button startButton;
private final Button optionsButton;
private final Button creditsButton;
private boolean optionsDown = false;

public StartScreen(List<GameInput> gameInputs, RenderObject renderObject, RenderParts renderParts){
Expand All @@ -53,9 +57,11 @@ public StartScreen(List<GameInput> gameInputs, RenderObject renderObject, Render
final TextButton.TextButtonStyle style = renderObject.getUISkin().get(TextButton.TextButtonStyle.class);
startButton = new TextButton("start", style); // do stuff with getStartButton.getStyle()
optionsButton = new TextButton("options", style);
creditsButton = new TextButton("info", style);

// this is initialized after each button because it uses them
this.menuRenderable = new StartScreenRenderable();
this.menuRenderable = new ComponentRenderable(new SelectionMenuRenderComponent(renderObject, gameInput,
new PlainTable(), Collections.singleton(new MultiActorOptionProvider((float) BUTTON_WIDTH, (float) BUTTON_HEIGHT, startButton, optionsButton, creditsButton)), () -> {}));

}
private Renderer createRenderer(){
Expand All @@ -68,13 +74,23 @@ private Renderer createRenderer(){
}
@Override
public void render(float delta) {
if(gameInput.getStartButton().isPressed() || startButton.isPressed()){
if(nextScreen == null) {
nextScreen = new GameScreen(gameInputs, renderObject, renderParts);
}
return;
}
if(creditsButton.isPressed()){
nextScreen = new CreditsScreen(gameInputs, renderObject, renderParts);
return;
}
if(optionsDown && !optionsButton.isPressed()){ // just released options button
renderParts.getOptionsMenu().setToController(gameInput, gameInput);
}
optionsDown = optionsButton.isPressed();
renderParts.getOverlay().setPauseVisible(false);
InputFocuser focuser = new InputFocuser();
focuser.add(renderParts.getOptionsMenu());
// System.out.println("wants to focus: " + renderParts.getOptionsMenu().isWantsToFocus());
focuser.add(renderParts.getOptionsMenu()); // may or may not get focus
focuser.giveFocus(uiStage, renderParts.getInputMultiplexer());


Expand All @@ -95,24 +111,15 @@ public void dispose() {

@Override
public boolean isScreenDone() {
return start && !startButton.isPressed();
return nextScreen != null && !startButton.isPressed() && !creditsButton.isPressed();
}

@Override
public UsableScreen createNextScreen() {
return new GameScreen(gameInputs, renderObject, renderParts);
return nextScreen;
}

class StartScreenRenderable implements Renderable {
private final RenderComponent renderComponent = new StartScreenMenuRenderComponent();

@Override
public RenderComponent getRenderComponent() {
return renderComponent;
}

}
class StartScreenMenuRenderComponent extends SelectionMenuRenderComponent{
/*class StartScreenMenuRenderComponent extends SelectionMenuRenderComponent{
private final Table table = new Table(){{
setFillParent(true);
center();
Expand All @@ -126,9 +133,6 @@ class StartScreenMenuRenderComponent extends SelectionMenuRenderComponent{
@Override
public void render(float delta, Stage stage) {
if(menuController.getStartButton().isPressed() || startButton.isPressed()){
start = true;
}
stage.addActor(table);
Collection<? extends SingleOption> options = getOptions();
Expand All @@ -151,6 +155,7 @@ protected Collection<? extends SingleOption> getOptionsToAdd() {
List<SingleOption> r = new ArrayList<>();
tryAddActorAsSingleOption(startButton, r);
tryAddActorAsSingleOption(optionsButton, r);
tryAddActorAsSingleOption(creditsButton, r);
return r;
}
private void tryAddActorAsSingleOption(Actor actor, Collection<? super SingleOption> optionCollection){
Expand All @@ -165,5 +170,5 @@ private void tryAddActorAsSingleOption(Actor actor, Collection<? super SingleOpt
protected boolean shouldKeep(SingleOption singleOption) {
return true;
}
}
}*/
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package me.retrodaredevil.game.trackshooter.render;

import com.badlogic.gdx.scenes.scene2d.Stage;

import me.retrodaredevil.game.trackshooter.render.components.RenderComponent;

public class ComponentRenderable implements Renderable {

private final RenderComponent renderComponent;
private final Stage preferredStage;

public ComponentRenderable(RenderComponent renderComponent, Stage preferredStage){
this.renderComponent = renderComponent;
this.preferredStage = preferredStage;
}
public ComponentRenderable(RenderComponent renderComponent){
this(renderComponent, null);
}

@Override
public RenderComponent getRenderComponent() {
return renderComponent;
}

@Override
public Stage getPreferredStage() {
return preferredStage;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@
* A short lived class that helps with the rendering of {@link Renderable}s and {@link Stage}s.
* <p>
* Renderables are rendered first, in order, and then, stages are rendered, in order.
* <p>
* Because most Renderables utilize stages, renderables or stages added last will be shown on top.
* Some Renderables don't use stages meaning they will be drawn under everything.
*/
public class Renderer {
private final Batch batch;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,26 @@

import java.util.Collection;
import java.util.Collections;
import java.util.Objects;

import me.retrodaredevil.controller.options.ConfigurableControllerPart;
import me.retrodaredevil.game.trackshooter.input.GameInput;
import me.retrodaredevil.game.trackshooter.InputFocusable;
import me.retrodaredevil.game.trackshooter.render.RenderObject;
import me.retrodaredevil.game.trackshooter.render.Renderable;
import me.retrodaredevil.game.trackshooter.render.components.RenderComponent;
import me.retrodaredevil.game.trackshooter.render.selection.SelectionMenuRenderComponent;
import me.retrodaredevil.game.trackshooter.render.selection.options.ConfigurableObjectOptionProvider;
import me.retrodaredevil.game.trackshooter.render.selection.tables.DialogTable;
import me.retrodaredevil.game.trackshooter.save.SaveObject;

public class OptionMenu implements Renderable, InputFocusable {
private final RenderObject renderObject;
private final SaveObject saveObject;
private final Stage preferredStage;
private OptionMenuRenderComponent renderComponent = null;
private SelectionMenuRenderComponent renderComponent = null;
private ConfigurableControllerPart currentController = null;

public OptionMenu(RenderObject renderObject, SaveObject saveObject) {
this.renderObject = renderObject;
this.saveObject = saveObject;
Expand All @@ -33,8 +39,8 @@ public RenderComponent getRenderComponent() {
}
public void setToController(ConfigurableControllerPart configController, GameInput menuController){
if (renderComponent != null) {
if(renderComponent.getConfigController() == configController){
System.out.println("it's the same!");
if(currentController == configController){
System.err.println("it's the same!");
return; // don't do anything, it's the same
}
renderComponent.dispose();
Expand All @@ -43,7 +49,10 @@ public void setToController(ConfigurableControllerPart configController, GameInp
renderComponent = null;
return;
}
renderComponent = new OptionMenuRenderComponent(renderObject, menuController, configController, this, saveObject);
renderComponent = new SelectionMenuRenderComponent(renderObject, menuController,
new DialogTable("Options", renderObject),
Collections.singleton(new ConfigurableObjectOptionProvider(menuController, renderObject, saveObject)), this::closeMenu);
currentController = menuController; // TODO I believe I originally set this up to check for errors, but this may be unnecessary
}
public void closeMenu(){
setToController(null, null);
Expand All @@ -53,8 +62,6 @@ public boolean isOpen() {
return renderComponent != null;
}

//region loading/saving
//endregion

@Override
public Stage getPreferredStage() {
Expand Down
Loading

0 comments on commit 17f093c

Please sign in to comment.