se.theodor.quiz.screen.CreateOrLoadQuiz.java Source code

Java tutorial

Introduction

Here is the source code for se.theodor.quiz.screen.CreateOrLoadQuiz.java

Source

/********************************************************************************
 * 
 *   Copyright 2014 Theodor Angergard
 *
 *   Licensed under the Apache License, Version 2.0 (the "License");
 *   you may not use this file except in compliance with the License.
 *   You may obtain a copy of the License at
 *
 *       http://www.apache.org/licenses/LICENSE-2.0
 *
 *   Unless required by applicable law or agreed to in writing, software
 *   distributed under the License is distributed on an "AS IS" BASIS,
 *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *   See the License for the specific language governing permissions and
 *   limitations under the License.
 *
 *******************************************************************************/

package se.theodor.quiz.screen;

import static se.theodor.quiz.util.Objects.GREEN_TEXT_BUTTON_STYLE;

import se.theodor.quiz.Quiz;
import se.theodor.quiz.util.Objects;
import se.theodor.quiz.util.Values;

import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.Input.Buttons;
import com.badlogic.gdx.Screen;
import com.badlogic.gdx.graphics.GL20;
import com.badlogic.gdx.graphics.OrthographicCamera;
import com.badlogic.gdx.scenes.scene2d.InputEvent;
import com.badlogic.gdx.scenes.scene2d.InputListener;
import com.badlogic.gdx.scenes.scene2d.Stage;
import com.badlogic.gdx.scenes.scene2d.ui.Table;
import com.badlogic.gdx.scenes.scene2d.ui.TextButton;

public class CreateOrLoadQuiz implements Screen {

    public CreateOrLoadQuiz(Quiz quiz) {
        this.quiz = quiz;
    }

    private Quiz quiz;
    private Stage stage;

    @Override
    public void render(float delta) {
        stage.act(delta);
        stage.draw();
    }

    @Override
    public void resize(int width, int height) {

    }

    @Override
    public void show() {
        TextButton createGame = new TextButton("Skapa nytt spel", GREEN_TEXT_BUTTON_STYLE);
        createGame.addListener(new InputListener() {
            @Override
            public boolean touchDown(InputEvent event, float x, float y, int pointer, int button) {
                if (button == Buttons.LEFT) {
                    return true;
                }
                return false;
            }

            @Override
            public void touchUp(InputEvent event, float x, float y, int pointer, int button) {
                quiz.setScreen(new CreateTeams(quiz));
            }
        });

        TextButton loadGame = new TextButton("Ladda sparat spel", GREEN_TEXT_BUTTON_STYLE);
        loadGame.addListener(new InputListener() {
            @Override
            public boolean touchDown(InputEvent event, float x, float y, int pointer, int button) {
                if (button == Buttons.LEFT) {
                    return true;
                }
                return false;
            }

            @Override
            public void touchUp(InputEvent event, float x, float y, int pointer, int button) {
                quiz.setScreen(new LoadGame(quiz));
            }
        });

        TextButton back = new TextButton("Tillbaka", GREEN_TEXT_BUTTON_STYLE);
        back.addListener(new InputListener() {
            @Override
            public boolean touchDown(InputEvent event, float x, float y, int pointer, int button) {
                if (button == Buttons.LEFT) {
                    return true;
                }
                return false;
            }

            @Override
            public void touchUp(InputEvent event, float x, float y, int pointer, int button) {
                quiz.setScreen(new MainMenu(quiz));
            }
        });

        Table table = new Table();
        table.setBounds(0, 0, quiz.getWidth(), quiz.getHeight());
        stage = Objects.STAGE;
        stage.clear();

        table.add(createGame).pad(Values.PAD);
        table.row();
        table.add(loadGame).pad(Values.PAD);
        table.row();
        table.add(back).pad(Values.PAD);

        stage.addActor(table);
    }

    @Override
    public void hide() {

    }

    @Override
    public void pause() {

    }

    @Override
    public void resume() {

    }

    @Override
    public void dispose() {

    }

}