package de.samdev.colorrunner.screens.menu; import com.badlogic.gdx.Gdx; import com.badlogic.gdx.Screen; import com.badlogic.gdx.graphics.GL20; import com.badlogic.gdx.graphics.g2d.SpriteBatch; import com.badlogic.gdx.graphics.g2d.TextureAtlas; import com.badlogic.gdx.scenes.scene2d.InputEvent; import com.badlogic.gdx.scenes.scene2d.Stage; 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.ui.TextButton; import com.badlogic.gdx.scenes.scene2d.utils.ClickListener; import de.samdev.colorrunner.CRGame; import de.samdev.colorrunner.game.world.map.CRMapStorage; import de.samdev.colorrunner.game.world.map.provider.EndlessMapProvider; import de.samdev.colorrunner.game.world.map.provider.StaticMapProvider; import de.samdev.colorrunner.screens.gameScreen.GameScreen; public class MainMenu implements Screen { private Stage stage = new Stage(); private Table table = new Table(); private CRGame game; private Skin skin = new Skin(Gdx.files.internal("skins/menuSkin.json"), new TextureAtlas(Gdx.files.internal("skins/menuSkin.pack"))); private TextButton buttonPlay1 = new TextButton("Play Level 1", skin); private TextButton buttonPlay2 = new TextButton("Play Endless", skin); private TextButton buttonExit = new TextButton("Exit", skin); private TextButton buttonOption = new TextButton("Option", skin); private Label title = new Label("Color Runner", skin); @Override public void render(float delta) { Gdx.gl.glClearColor(0, 0, 0, 1); Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT); stage.act(); stage.draw(); } @Override public void resize(int width, int height) { // NOP } @Override public void show() { buttonPlay1.addListener(new ClickListener(){ @Override public void clicked(InputEvent event, float x, float y){ CRGame.Inst().setScreen(new GameScreen(new StaticMapProvider(CRMapStorage.lvl_01))); } }); buttonPlay2.addListener(new ClickListener(){ @Override public void clicked(InputEvent event, float x, float y){ CRGame.Inst().setScreen(new GameScreen(new EndlessMapProvider(System.currentTimeMillis()))); } }); buttonOption.addListener(new ClickListener(){ @Override public void clicked(InputEvent event, float x, float y) { CRGame.Inst().setScreen(new OptionMenuScreen()); } }); buttonExit.addListener(new ClickListener(){ @Override public void clicked(InputEvent event, float x, float y) { Gdx.app.exit(); } }); table.add(title).padBottom(40).row(); table.add(buttonPlay1).size((int)((double)Gdx.graphics.getWidth() / 2.0D),60).padBottom(20).row(); table.add(buttonPlay2).size((int)((double)Gdx.graphics.getWidth() / 2.0D),60).padBottom(20).row(); table.add(buttonOption).size((int)((double)Gdx.graphics.getWidth() / 2.0D),60).padBottom(20).row(); table.add(buttonExit).size((int)((double)Gdx.graphics.getWidth() / 2.0D),60).padBottom(20).row(); table.setFillParent(true); stage.addActor(table); Gdx.input.setInputProcessor(stage); } @Override public void hide() { dispose(); } @Override public void pause() { // NOP } @Override public void resume() { // NOP } @Override public void dispose() { stage.dispose(); skin.dispose(); } }