Skip to content

Instantly share code, notes, and snippets.

@madigan
Created December 26, 2016 23:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save madigan/db7e22cb184bc1a59627ca7d84d0171d to your computer and use it in GitHub Desktop.
Save madigan/db7e22cb184bc1a59627ca7d84d0171d to your computer and use it in GitHub Desktop.
Example View
package tech.otter.merchant.view;
import com.badlogic.gdx.Application.ApplicationType;
import com.badlogic.gdx.Gdx;
import com.kotcrab.vis.ui.widget.VisTable;
import com.kotcrab.vis.ui.widget.VisTextButton;
import tech.otter.merchant.controller.Controller;
import tech.otter.merchant.model.Model;
public class MainMenuScreen extends View {
private VisTextButton btnContinue;
private final VisTextButton btnLoadGame;
private final VisTextButton btnSaveGame;
private final VisTextButton btnOptions;
private final VisTextButton btnExit;
private final VisTextButton btnNewGame;
public MainMenuScreen(Controller controller, Model world) {
super(controller, world);
btnContinue = makeNavButton("Continue Game", StationScreen.class);
btnNewGame = makeNavButton("New Game", IntroScreen.class);
btnLoadGame = makeNavButton("Load Game", null);
btnSaveGame = makeNavButton("Save Game", null);
btnOptions = makeNavButton("Options", null);
btnExit = makeButton("Exit", () -> Gdx.app.exit());
// Create the layout
VisTable tblButtons = new VisTable();
tblButtons.setFillParent(true);
tblButtons.columnDefaults(0).pad(2f).width(300f);
// Only give the option to continue if a game is active
tblButtons.add(btnContinue);
tblButtons.row();
tblButtons.add(btnNewGame);
tblButtons.row();
tblButtons.add(btnLoadGame);
tblButtons.row();
tblButtons.add(btnSaveGame);
tblButtons.row();
tblButtons.add(btnOptions);
// Web and mobile devices don't need no exit buttons!
if(Gdx.app.getType().equals(ApplicationType.Desktop)) {
tblButtons.row();
tblButtons.add(btnExit);
}
ui.addActor(tblButtons);
}
@Override
public void init() {
super.show();
// Only show the continue button if there is a game to continue
btnContinue.setVisible(controller.getWorld().isActive());
// Only show save/load on platforms that support it
btnLoadGame.setVisible(!Gdx.app.getType().equals(ApplicationType.WebGL));
btnSaveGame.setVisible(!Gdx.app.getType().equals(ApplicationType.WebGL));
btnExit.setVisible(!Gdx.app.getType().equals(ApplicationType.WebGL) && !Gdx.app.getType().equals(ApplicationType.Android));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment