com.gmail.bleedobsidian.logicbuilder.LogicBuilder.java Source code

Java tutorial

Introduction

Here is the source code for com.gmail.bleedobsidian.logicbuilder.LogicBuilder.java

Source

/*
 *  Logic-Builder.
 *  Copyright (C) 2016 Jesse Prescott (BleedObsidian)
 *
 *  This program is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation, either version 3 of the License, or
 *  (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 * 
 *  You should have received a copy of the GNU General Public License
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

package com.gmail.bleedobsidian.logicbuilder;

import com.badlogic.gdx.Game;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.Screen;
import com.badlogic.gdx.graphics.OrthographicCamera;
import com.gmail.bleedobsidian.logicbuilder.screens.builder.BuilderScreen;
import com.gmail.bleedobsidian.logicbuilder.screens.loading.LoadingScreen;
import com.gmail.bleedobsidian.logicbuilder.utils.ResourceManager;

/**
 * Logic-Builder.
 * 
 * @author Jesse Prescott (BleedObsidian)
 */
public class LogicBuilder extends Game {
    /**
     * Target screen width.
     */
    public static final int TARGET_WIDTH = 1300;

    /**
     * Target screen height.
     */
    public static final int TARGET_HEIGHT = 720;

    /**
     * Running instance of LogicBuilder.
     */
    private static LogicBuilder instance;

    /**
     * Full screen OrthographicCamera.
     */
    private OrthographicCamera fullScreenCamera;

    /**
     * Gallery OrthographicCamera.
     */
    private OrthographicCamera galleryCamera;

    /**
     * Grid OrthographicCamera.
     */
    private OrthographicCamera gridCamera;

    /**
     * Resource Manager.
     */
    private ResourceManager resourceManager;

    /**
     * Loading Screen.
     */
    private LoadingScreen loadingScreen;

    /**
     * Builder Screen.
     */
    private BuilderScreen builderScreen;

    /**
     * New LogicBuilder.
     */
    public LogicBuilder() {
        LogicBuilder.instance = this;
    }

    @Override
    public void create() {
        this.resourceManager = new ResourceManager();

        this.fullScreenCamera = new OrthographicCamera();
        this.fullScreenCamera.setToOrtho(false, LogicBuilder.TARGET_WIDTH, LogicBuilder.TARGET_HEIGHT);
        this.fullScreenCamera.update();

        this.galleryCamera = new OrthographicCamera();
        this.galleryCamera.setToOrtho(false, LogicBuilder.TARGET_WIDTH, LogicBuilder.TARGET_HEIGHT);
        this.galleryCamera.update();

        this.gridCamera = new OrthographicCamera();
        this.gridCamera.setToOrtho(false, LogicBuilder.TARGET_WIDTH, LogicBuilder.TARGET_HEIGHT);
        this.gridCamera.translate(-300, 0, 0);
        this.gridCamera.update();

        this.loadingScreen = new LoadingScreen();

        this.builderScreen = new BuilderScreen();
        this.resourceManager.addResourceManagerInterface(this.builderScreen);

        this.resourceManager.load();
        this.gotoLoadingScreen();
    }

    /**
     * On ResourceManager finished.
     */
    public void finishedLoading() {
        this.resourceManager.complete();
        this.gotoBuilderScreen();
    }

    @Override
    public void setScreen(Screen screen) {
        super.setScreen(screen);
    }

    @Override
    public void dispose() {
        this.loadingScreen.dispose();
        this.resourceManager.dispose();
        Gdx.app.exit();
    }

    /**
     * Go to Loading Screen.
     */
    public void gotoLoadingScreen() {
        if (!(this.getCurrentScreen() instanceof LoadingScreen)) {
            this.setScreen(this.loadingScreen);
        }
    }

    /**
     * Go to Builder Screen.
     */
    public void gotoBuilderScreen() {
        if (!(this.getCurrentScreen() instanceof BuilderScreen)) {
            this.setScreen(this.builderScreen);
        }
    }

    /**
     * @return Current screen.
     */
    public Screen getCurrentScreen() {
        return this.getScreen();
    }

    /**
     * @return Builder Screen.
     */
    public BuilderScreen getBuilderScreen() {
        return this.builderScreen;
    }

    /**
     * @return ResourceManager.
     */
    public ResourceManager getResourceManager() {
        return this.resourceManager;
    }

    /**
     * @return Full screen OrthographicCamera.
     */
    public OrthographicCamera getFullScreenCamera() {
        return this.fullScreenCamera;
    }

    /**
     * @return Gallery OrthographicCamera.
     */
    public OrthographicCamera getGalleryCamera() {
        return this.galleryCamera;
    }

    /**
     * @return Grid OrthographicCamera.
     */
    public OrthographicCamera getGridCamera() {
        return this.gridCamera;
    }

    /**
     * @return Running instance of Logic-Builder.
     */
    public static LogicBuilder getInstance() {
        return LogicBuilder.instance;
    }
}