115 lines
3.0 KiB
Java
115 lines
3.0 KiB
Java
package de.samdev.colorrunner.screens.menu;
|
|
|
|
import com.badlogic.gdx.Game;
|
|
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.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 buttonPlay = new TextButton("Play", skin),
|
|
buttonExit = new TextButton("Exit", skin),
|
|
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) {
|
|
// TODO Auto-generated method stub
|
|
|
|
}
|
|
|
|
@Override
|
|
public void show() {
|
|
buttonPlay.addListener(new ClickListener(){
|
|
@Override
|
|
public void clicked(InputEvent event, float x, float y){
|
|
((Game)Gdx.app.getApplicationListener()).setScreen(new GameScreen());
|
|
}
|
|
});
|
|
|
|
buttonOption.addListener(new ClickListener(){
|
|
@Override
|
|
public void clicked(InputEvent event, float x, float y) {
|
|
((Game)Gdx.app.getApplicationListener()).setScreen(new OptionMenuScreen());
|
|
}
|
|
});
|
|
|
|
buttonExit.addListener(new ClickListener(){
|
|
@Override
|
|
public void clicked(InputEvent event, float x, float y) {
|
|
Gdx.app.exit();
|
|
// or System.exit(0);
|
|
}
|
|
});
|
|
|
|
table.add(title).padBottom(40).row();
|
|
table.add(buttonPlay).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() {
|
|
// TODO Auto-generated method stub
|
|
|
|
}
|
|
|
|
@Override
|
|
public void resume() {
|
|
// TODO Auto-generated method stub
|
|
|
|
}
|
|
|
|
@Override
|
|
public void dispose() {
|
|
stage.dispose();
|
|
skin.dispose();
|
|
}
|
|
|
|
}
|