179 lines
5.4 KiB
Java
179 lines
5.4 KiB
Java
package de.samdev.colorrunner.screens.menu;
|
|
|
|
import com.badlogic.gdx.Gdx;
|
|
import com.badlogic.gdx.Preferences;
|
|
import com.badlogic.gdx.Screen;
|
|
import com.badlogic.gdx.audio.Music;
|
|
import com.badlogic.gdx.graphics.GL20;
|
|
import com.badlogic.gdx.graphics.OrthographicCamera;
|
|
import com.badlogic.gdx.graphics.Texture;
|
|
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.StaticMapProvider;
|
|
import de.samdev.colorrunner.screens.gameScreen.GameScreen;
|
|
|
|
public class MainMenu implements Screen {
|
|
|
|
private Preferences prefs = Gdx.app.getPreferences("settings");
|
|
private Preferences ingameprefs = Gdx.app.getPreferences("ingamepreferences");
|
|
private Stage stage = new Stage();
|
|
private Table table = new Table();
|
|
|
|
private OrthographicCamera cam = new OrthographicCamera();
|
|
private Texture background = new Texture("images/background2.jpg");
|
|
|
|
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 Levels", skin);
|
|
private TextButton buttonPlay2 = new TextButton("Play Endless", skin);
|
|
private TextButton buttonOption = new TextButton("Option", skin);
|
|
private TextButton buttonExit = new TextButton("Exit", skin);
|
|
|
|
|
|
// folgendes mal als Beispiel :)
|
|
/*
|
|
button3.setSize(col_width*4,(float)(row_height*2));
|
|
button3.getStyle().imageUp = new TextureRegionDrawable(new TextureRegion(new Texture(Gdx.files.internal("switch_off.png"))));
|
|
button3.getStyle().imageDown = new TextureRegionDrawable(new TextureRegion(new Texture(Gdx.files.internal("switch_on.png"))));
|
|
button3.setPosition(col_width,Gdx.graphics.getHeight()-row_height*6);
|
|
button3.addListener(new InputListener(){
|
|
@Override
|
|
public void touchUp (InputEvent event, float x, float y, int pointer, int button) {
|
|
outputLabel.setText("Press a Button");
|
|
}
|
|
@Override
|
|
public boolean touchDown (InputEvent event, float x, float y, int pointer, int button) {
|
|
outputLabel.setText("Pressed Image Button");
|
|
return true;
|
|
}
|
|
});
|
|
|
|
|
|
|
|
*/
|
|
|
|
private Label title = new Label("Color Runner" , skin);
|
|
private Label highestscore = new Label("Highest Level: " + ingameprefs.getInteger("highestlevel", 1), skin);
|
|
|
|
public Music music;
|
|
|
|
public MainMenu() {
|
|
music = CRGame.manager.get("sound/menusound.mp3", Music.class);
|
|
music.setLooping(true);
|
|
|
|
if(prefs.getBoolean("sound", true))
|
|
music.play();
|
|
else
|
|
music.stop();
|
|
}
|
|
|
|
@Override
|
|
public void render(float delta) {
|
|
Gdx.gl.glClearColor(0, 0, 0, 1);
|
|
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
|
|
|
|
cam.setToOrtho(false, (float)Gdx.graphics.getWidth() / 2.0F, (float)Gdx.graphics.getHeight() / 2.0F);
|
|
|
|
SpriteBatch sb = new SpriteBatch();
|
|
sb.setProjectionMatrix(cam.combined);
|
|
sb.begin();
|
|
sb.draw(background, 0, 0);
|
|
sb.end();
|
|
|
|
|
|
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){
|
|
|
|
//int level = ingameprefs.getInteger("highestlevel", 1);
|
|
|
|
ingameprefs.putInteger("currantlvl", 1);
|
|
int currantlvl = ingameprefs.getInteger("currantlvl", 1);
|
|
|
|
CRGame.Inst().setScreen(new GameScreen(new StaticMapProvider(CRMapStorage.map_map.get(currantlvl))));
|
|
music.stop();
|
|
}
|
|
});
|
|
|
|
buttonPlay2.addListener(new ClickListener(){
|
|
@Override
|
|
public void clicked(InputEvent event, float x, float y){
|
|
//CRGame.Inst().setScreen(new GameScreen(new EndlessMapProvider(System.currentTimeMillis())));
|
|
CRGame.Inst().setScreen(new EndlessGameMenu(music));
|
|
}
|
|
});
|
|
|
|
buttonOption.addListener(new ClickListener(){
|
|
@Override
|
|
public void clicked(InputEvent event, float x, float y) {
|
|
CRGame.Inst().setScreen(new OptionMenuScreen(music));
|
|
}
|
|
});
|
|
|
|
buttonExit.addListener(new ClickListener(){
|
|
@Override
|
|
public void clicked(InputEvent event, float x, float y) {
|
|
Gdx.app.exit();
|
|
}
|
|
});
|
|
|
|
table.add(buttonPlay1).size((int)((double)Gdx.graphics.getWidth() / 2.0D),250);
|
|
table.add(buttonPlay2).size((int)((double)Gdx.graphics.getWidth() / 2.0D),250).row();
|
|
table.add(title).size((int)((double)Gdx.graphics.getWidth() / 2.0D), 62);
|
|
table.add(highestscore).size((int)((double)Gdx.graphics.getWidth() / 2.0D),62).row();
|
|
table.add(buttonOption).size((int)((double)Gdx.graphics.getWidth() / 2.0D),250);
|
|
table.add(buttonExit).size((int)((double)Gdx.graphics.getWidth() / 2.0D),250);
|
|
|
|
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();
|
|
}
|
|
|
|
}
|