package com.dic.Screens;
import aurelienribon.tweenengine.Tween;
import aurelienribon.tweenengine.TweenManager;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.Screen;
import com.badlogic.gdx.graphics.GL20;
import com.badlogic.gdx.graphics.OrthographicCamera;
import com.badlogic.gdx.graphics.g2d.BitmapFont;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.badlogic.gdx.graphics.g2d.TextureRegion;
import com.badlogic.gdx.graphics.glutils.ShapeRenderer;
import com.badlogic.gdx.scenes.scene2d.InputEvent;
import com.badlogic.gdx.scenes.scene2d.Stage;
import com.badlogic.gdx.scenes.scene2d.actions.Actions;
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.ui.TextButton.TextButtonStyle;
import com.badlogic.gdx.scenes.scene2d.utils.ClickListener;
import com.badlogic.gdx.scenes.scene2d.utils.TextureRegionDrawable;
import com.badlogic.gdx.utils.viewport.FitViewport;
import com.dic.Helpers.AssetLoader;
import com.dic.Mikmakfly.MyGdxGame;
import com.dic.TweenAccessors.TableAccessor;
import com.dic.TweenAccessors.TextButtonAccessor;
public class MainMenuScreen implements Screen {
private ShapeRenderer shapeRenderer;
private SpriteBatch batcher;
private OrthographicCamera cam;
private TextureRegion menu;
private float screenWidth;
private float screenHeight;
private float gameWidth;
private float gameHeight;
private Stage stage;
private Skin skin;
private TweenManager manager;
private TextButton connectButton;
private TextButton gameButton;
private TextButton loginButton;
private TextButton connect3;
public MainMenuScreen(final MyGdxGame game)
{
screenWidth = Gdx.graphics.getWidth();
screenHeight = Gdx.graphics.getHeight();
gameWidth=136;
gameHeight = screenHeight / (screenWidth / gameWidth);
cam = new OrthographicCamera();
cam.setToOrtho(true, 136, gameHeight);
batcher = new SpriteBatch();
batcher.setProjectionMatrix(cam.combined);
shapeRenderer = new ShapeRenderer();
shapeRenderer.setProjectionMatrix(cam.combined);
stage = new Stage(new FitViewport(gameWidth, gameHeight));
Gdx.input.setInputProcessor(stage);
skin = new Skin(Gdx.files.internal("uiskin.json"));
manager = new TweenManager();
Tween.registerAccessor(TextButton.class, new TextButtonAccessor());
Tween.registerAccessor(Table.class, new TableAccessor());
menu = AssetLoader.menu;
TextureRegion upRegion = AssetLoader.logout;
TextureRegion downRegion = AssetLoader.login;
TextButtonStyle style = new TextButtonStyle();
style.up = new TextureRegionDrawable(upRegion);
style.down = new TextureRegionDrawable(downRegion);
BitmapFont lb= new BitmapFont();
style.font = lb;
connectButton= new TextButton("",style);
gameButton= new TextButton("",style);
loginButton= new TextButton("",style);
connect3= new TextButton("",style);
final Table table= new Table(skin);
table.setPosition(gameWidth/2, gameHeight/2);
table.add(gameButton).width(30).height(15).padBottom(3).row();
table.add(loginButton).width(30).height(15).padBottom(3).row();
table.add(connectButton).width(30).height(15).padBottom(3).row();
table.add(connect3).width(30).height(15).padBottom(3).row();
stage.addActor(table);
connectButton.addListener(new ClickListener()
{
@Override
public void clicked(InputEvent event, float x, float y)
{
game.setScreen(new GameScreen(1, game));
/*
Tween.from(table, TableAccessor.SCALE, .8f).target(40,40) // the target can be relative to the current values
.ease(Quad.IN) // the easing function can be modified
.start(manager);
login();
*/
}
});
gameButton.addListener(new ClickListener()
{
@Override
public void clicked(InputEvent event, float x, float y)
{
stage.addAction(Actions.sequence(Actions.fadeOut(1), Actions.run(new Runnable() {
@Override
public void run() {
game.setScreen(new GameScreen(2 , game));
}
})));
}
});
connect3.addListener(new ClickListener()
{
@Override
public void clicked(InputEvent event, float x, float y)
{
stage.addAction(Actions.sequence(Actions.fadeOut(1), Actions.run(new Runnable() {
@Override
public void run() {
game.setScreen(new GameScreen(6, game));
}
})));
}
});
loginButton.addListener(new ClickListener()
{
@Override
public void clicked(InputEvent event, float x, float y)
{
stage.addAction(Actions.sequence(Actions.fadeOut(1), Actions.run(new Runnable() {
@Override
public void run() {
game.setScreen(new GameScreen(4, game));
}
})));
}
});
}
@Override
public void render(float delta) {
Gdx.gl.glClearColor(0, 0, 0, 1);
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
batcher.begin();
batcher.draw(menu,0,0, gameWidth, gameHeight);
batcher.end();
manager.update(delta);
stage.act(delta);
stage.draw();
}
@Override
public void resize(int width, int height) {
}
@Override
public void show() {
// TODO Auto-generated method stub
}
@Override
public void hide() {
// TODO Auto-generated method stub
}
@Override
public void pause() {
// TODO Auto-generated method stub
}
@Override
public void resume() {
// TODO Auto-generated method stub
}
@Override
public void dispose() {
// TODO Auto-generated method stub
}
}