com.bossletsplays.rr.screens.MainMenu.java Source code

Java tutorial

Introduction

Here is the source code for com.bossletsplays.rr.screens.MainMenu.java

Source

/*   Copyright 2014 Matthew Rogers "BossLetsPlays"
*
*   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 com.bossletsplays.rr.screens;

import com.badlogic.gdx.Screen;
import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.graphics.GL20;
import com.badlogic.gdx.graphics.g2d.BitmapFont;
import com.badlogic.gdx.graphics.g2d.TextureAtlas;
import com.badlogic.gdx.scenes.scene2d.Actor;
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.Label.LabelStyle;
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.bossletsplays.rr.Ragdoll;
import com.bossletsplays.rr.gfx.Font;
import com.bossletsplays.rr.libs.Reference;
import com.bossletsplays.rr.utils.RenderUtil;
import com.bossletsplays.rr.utils.Util;

/**
 * <strong>Project:</strong> Ragdoll Rick-core <br>
 * 
 * <strong>Class:</strong> MainMenu
 * 
 * @author <a href = "http://www.youtube.com/BossLetsPlays"> BossLetsPlays</a>
 */
public class MainMenu implements Screen {

    private Stage stage;
    private Table table;
    private Label heading;
    private Skin skin;
    private TextButton play, options, exit;
    private BitmapFont buttonFont, headingFont;
    private TextureAtlas atlas;

    @Override
    public void render(float delta) {
        RenderUtil.clearColor(0, 1);
        RenderUtil.clear(GL20.GL_COLOR_BUFFER_BIT);
        if (Reference.DEBUG)
            Table.drawDebug(stage);
        stage.act(delta);
        stage.draw();
    }

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

    @Override
    public void show() {
        stage = new Stage();
        Util.setInput(stage);
        atlas = new TextureAtlas("ui/button.pack");
        skin = new Skin(atlas);
        table = new Table(skin);
        table.setBounds(0, 0, Util.getWidth(), Util.getHeight());
        buttonFont = Font.getFont("04b_08");
        headingFont = Font.getFont("terminal");

        TextButtonStyle buttonStyle = new TextButtonStyle();
        buttonStyle.up = skin.getDrawable("button.up");
        buttonStyle.down = skin.getDrawable("button.down");
        buttonStyle.pressedOffsetX = 1;
        buttonStyle.pressedOffsetY = -1;
        buttonStyle.font = buttonFont;
        buttonStyle.fontColor = Color.BLACK;

        play = new TextButton("Play", buttonStyle);
        play.pad(20);
        options = new TextButton("Options", buttonStyle);
        options.pad(20);
        exit = new TextButton("Exit", buttonStyle);
        exit.addListener(new ClickListener() {
            @Override
            public void clicked(InputEvent event, float x, float y) {
                Ragdoll.exit();
            }
        });
        exit.pad(20);

        LabelStyle headingStyle = new LabelStyle(headingFont, Color.WHITE);
        heading = new Label(Reference.TITLE, headingStyle);
        heading.setFontScale(3);

        addComponent(heading);
        addComponent(play);
        addComponent(options);
        table.add(exit);
        if (Reference.DEBUG)
            table.debug();
        stage.addActor(table);
    }

    private void addComponent(Actor component) {
        table.add(component);
        table.row();
    }

    @Override
    public void hide() {
    }

    @Override
    public void pause() {
    }

    @Override
    public void resume() {
    }

    @Override
    public void dispose() {
    }

}