com.gmail.bleedobsidian.logicbuilder.screens.builder.BuilderScreen.java Source code

Java tutorial

Introduction

Here is the source code for com.gmail.bleedobsidian.logicbuilder.screens.builder.BuilderScreen.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.screens.builder;

import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.Screen;
import com.badlogic.gdx.assets.loaders.TextureLoader.TextureParameter;
import com.badlogic.gdx.graphics.GL20;
import com.badlogic.gdx.graphics.OrthographicCamera;
import com.badlogic.gdx.graphics.Texture.TextureFilter;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.gmail.bleedobsidian.logicbuilder.LogicBuilder;
import com.gmail.bleedobsidian.logicbuilder.screens.builder.managers.ComponentManager;
import com.gmail.bleedobsidian.logicbuilder.screens.builder.managers.GalleryManager;
import com.gmail.bleedobsidian.logicbuilder.screens.builder.managers.GridManager;
import com.gmail.bleedobsidian.logicbuilder.utils.ResourceManager;
import com.gmail.bleedobsidian.logicbuilder.utils.ResourceManager.ResourceManagerInterface;

/**
 * The builder screen.
 * 
 * @author Jesse Prescott (BleedObsidian)
 */
public class BuilderScreen implements Screen, ResourceManagerInterface {

    /**
     * Gallery Sprite Batch.
     */
    private final SpriteBatch gallerySpriteBatch;

    /**
     * Grid Sprite Batch.
     */
    private final SpriteBatch gridSpriteBatch;

    /**
     * Grid Manager.
     */
    private final GridManager gridManager;

    /**
     * Gallery Manager.
     */
    private final GalleryManager galleryManager;

    /**
     * Component Manager
     */
    private final ComponentManager componentManager;

    public BuilderScreen() {
        this.gallerySpriteBatch = new SpriteBatch();
        this.gridSpriteBatch = new SpriteBatch();

        this.gridManager = new GridManager();
        this.galleryManager = new GalleryManager();
        this.componentManager = new ComponentManager();
    }

    @Override
    public void resume() {
    }

    /**
     * Update.
     * 
     * @param fullScreenCamera Full Screen OrthographicCamera.
     * @param delta Delta Value.
     */
    public void update(OrthographicCamera fullScreenCamera, float delta) {
        this.gridManager.update(delta);
        this.galleryManager.update(delta);
        this.componentManager.update(delta);
    }

    @Override
    public void render(float delta) {
        this.update(null, delta);

        Gdx.gl.glClearColor(1f, 1f, 1f, 1f);
        Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);

        this.gallerySpriteBatch.setProjectionMatrix(LogicBuilder.getInstance().getGalleryCamera().combined);
        this.gridSpriteBatch.setProjectionMatrix(LogicBuilder.getInstance().getGridCamera().combined);

        Gdx.gl20.glEnable(GL20.GL_SCISSOR_TEST);
        Gdx.gl20.glScissor(300, 0, 1000, LogicBuilder.TARGET_HEIGHT);
        this.gridSpriteBatch.begin();
        this.gridManager.render(this.gridSpriteBatch);
        this.componentManager.render(this.gridSpriteBatch);
        this.gridSpriteBatch.end();
        Gdx.gl20.glDisable(GL20.GL_SCISSOR_TEST);
        LogicBuilder.getInstance().getGalleryCamera().update();

        Gdx.gl20.glEnable(GL20.GL_SCISSOR_TEST);
        Gdx.gl20.glScissor(0, 0, 300, LogicBuilder.TARGET_HEIGHT);
        this.gallerySpriteBatch.begin();
        this.galleryManager.render(this.gallerySpriteBatch);
        this.gallerySpriteBatch
                .draw(LogicBuilder.getInstance().getResourceManager().getTexture("Textures/Devider.png"), 293, 0);
        this.gallerySpriteBatch.end();
        Gdx.gl20.glDisable(GL20.GL_SCISSOR_TEST);
    }

    @Override
    public void pause() {
    }

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

    @Override
    public void show() {
    }

    @Override
    public void hide() {
    }

    @Override
    public void dispose() {
    }

    /**
     * @return Gallery Sprite Batch.
     */
    public SpriteBatch getGallerySpriteBatch() {
        return this.gallerySpriteBatch;
    }

    /**
     * @return Grid Sprite Batch.
     */
    public SpriteBatch getGridSpriteBatch() {
        return this.gridSpriteBatch;
    }

    /**
     * @return GalleryManager.
     */
    public GalleryManager getGalleryManager() {
        return this.galleryManager;
    }

    /**
     * @return ComponentManager.
     */
    public ComponentManager getComponentManager() {
        return this.componentManager;
    }

    @Override
    public void loadResources(ResourceManager resourceManager) {
        this.gridManager.loadResources(resourceManager);
        this.galleryManager.loadResources(resourceManager);
        this.componentManager.loadResources(resourceManager);

        TextureParameter filter = new TextureParameter();
        filter.magFilter = TextureFilter.Linear;
        filter.minFilter = TextureFilter.Linear;
        resourceManager.loadTexture("Textures/Devider.png", filter);
    }

    @Override
    public void onResourcesLoaded(ResourceManager resourceManager) {
        this.gridManager.onResourcesLoaded(resourceManager);
        this.galleryManager.onResourcesLoaded(resourceManager);
        this.componentManager.onResourcesLoaded(resourceManager);
    }
}