Package transientlibs.preui.agents.rendering

Source Code of transientlibs.preui.agents.rendering.GDXMapDrawGridAgent

/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package transientlibs.preui.agents.rendering;

import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.OrthographicCamera;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.badlogic.gdx.graphics.g2d.TextureRegion;
import com.badlogic.gdx.maps.tiled.TiledMapRenderer;
import com.badlogic.gdx.maps.tiled.renderers.OrthogonalTiledMapRenderer;

import com.badlogic.gdx.math.Matrix4;
//import org.lwjgl.input.Mouse;
import transientlibs.slick2d.util.Log;
import transientlibs.bindedobjects.gamecontent.Terrain;
import transientlibs.processors.misc.ClickProcessor;
import transientlibs.processors.misc.Detonator;
import transientlibs.preui.objects.states.TransientGame;
import transientlibs.maps.units.GenericUnit;
import transientlibs.maps.container.TransientAssembledMap;
import transientlibs.maps.container.TiledMapGDXContainer;
import transientlibs.maps.units.Unit;
import transientlibs.maps.utils.grid.FOVScreenGrid;
import transientlibs.maps.utils.grid.UnitScreenGrid;
import transientlibs.preui.gdx.gui.MouseHack;
import transientlibs.preui.objects.gui.interfaces.IFont;
import transientlibs.preui.objects.gui.interfaces.IImage;
import transientlibs.preui.objects.states.IState;

/**
*
* @author alta
*/
public class GDXMapDrawGridAgent extends GDXGenericStateDrawAgent {

    private OrthographicCamera camera;
    public TiledMapGDXContainer map;
    //public SpriteBatch spriteBatch;
    public Unit player = null;
    public TransientGame game;
    public IFont font;
    //public IState state;
   
    int fogX;
    int fogY;
   
    public IImage fog;
   
    private TiledMapRenderer mapRenderer;
   
    public FOVScreenGrid FOVGrid;
    public UnitScreenGrid unitGrid;


    public GDXMapDrawGridAgent(TransientGame setGame, TransientAssembledMap setMap, GenericUnit setPlayer, IState setState) {
        super (setState);
        game = setGame;
        player = (Unit) setPlayer;
        map = (TiledMapGDXContainer) setMap;
        //Matrix4 projection = new Matrix4();
        //projection.setToOrtho(0, game.screenSizeX, game.screenSizeY, 0, -1, 1);

        fog = Detonator.INSTANCE.imageProvider.getImage("fog");
                       
        camera = (OrthographicCamera) map.camera;
        //map.camera = camera;
     
        //Log.info("Map: "+(map != null));
        //Log.info("Internal Map: "+(map.getTiledMapGDX() != null));
        //Log.info("Internal Map2: "+(map.getTiledMapGDX().gdxMap != null));
       
        mapRenderer = new OrthogonalTiledMapRenderer(map.getTiledMapGDX().gdxMap);
        mapRenderer.setView(camera);       
       
        //spriteBatch = new SpriteBatch(100);
       
        font = Detonator.INSTANCE.fontProvider.getFont("djvu_16_sans");
        font.setBatch(spriteBatch);
        //spriteBatch.setProjectionMatrix(projection);
       
        FOVGrid = new FOVScreenGrid(map, spriteBatch);
        FOVGrid.fog = fog;
       
        unitGrid = new UnitScreenGrid(map, spriteBatch);
       
       
        if (player == null) {
            Log.warn("Player is not set!");
        }
    }

    public void draw(TextureRegion region, float x, float y) {
        int width = region.getRegionWidth();
        if (width < 0) {
            width = -width;
        }
        spriteBatch.draw(region, x, y, width, region.getRegionHeight());
    }

    @Override
    public void centerCameraOnPlayer (){
       
        float cameraX = player.getScreenCoords().x -                
                (Gdx.graphics.getWidth()-Terrain.tileWidth)/2.0f;
        cameraX -= (Terrain.tileWidth / 2);
       
        float cameraY = player.getScreenCoords().y -                
                (Gdx.graphics.getHeight()-Terrain.tileHeight)/2.0f;
       
        cameraY -= (Terrain.tileHeight / 2);
       
        //Log.info("Camera position: "+cameraX+"/"+cameraY);
       
        camera.position.set(cameraX, cameraY, 0);

        camera.update();       
    }
   
    @Override
    public void process() {

        Log.warn("GDX MAP RENDER");
       
        //Log.info("Player: "+player.getMapCoords().toString());
        //Log.info("Camera: "+(camera != null));
       
        //camera.position.set(player.getMapCoords().x + 32, player.getMapCoords().y + 32, 0);
        //camera.update();
        //camera.apply(Gdx.graphics.getGL10());


        // spriteBatch.begin();
        //draw(Art.bg, 0, 0);
        //spriteBatch.end();
        //map.render(this, camera);
        //renderer.render(camera);

        //Log.info("Player: "+(player != null));
        //Log.info("Player position: "+ (player.getScreenCoords().toString()));
        //Log.info("Player dimensions: "+ player.getWidth()+"/"+player.getHeight());
       
        //Log.info("Camera position: "+ (player.getScreenCoords().x -
                //(Gdx.graphics.getWidth()-player.getWidth())/2.0f) + ":" +
                //(player.getScreenCoords().y -
                //(Gdx.graphics.getHeight()-player.getHeight())/2.0f));
       
        centerCameraOnPlayer();
       
        mapRenderer.setView(camera);
        mapRenderer.render();
        //Log.info("MAP RENDERED");
       
        spriteBatch.begin();
        //camera.apply(Gdx.graphics.getGL11());
        //if (mayRespawn) {
        //    String msg = "PRESS X TO TRY AGAIN";
        //    drawString(msg, 160 - msg.length() * 3, 120 - 3);
        //  }



        //for (GenericUnit u : map.units) {
            //Log.info("Drawing unit here!");
            //draw (u.creature.image.imageGDX.image, u.screenCoords.getIntY(), u.screenCoords.getIntY());

            //float x = u.getScreenCoords().x - camera.position.x;
            //float y = u.getScreenCoords().y - camera.position.y;

            //float x = u.getScreenCoords().x;
            //float y = u.getScreenCoords().y;
           
            //Log.warn("Unit draw coords: "+x+":"+y);
           
            //Log.info("Now drawing: "+u.getName());
           
            //Log.info("Unit not null: "+(u != null));
            //Log.info("Image not null: "+(u.getImage() != null));
            //Log.info("Atlas not null: "+(u.getImage().getAtlasRegion() != null));
           
            //if (u.getCreatures().visualInformation.cutImage == null) {
            //draw(u.getImage().getAtlasRegion(), x, y);
            //} else {
            //draw(u.getCreatures().visualInformation.cutImage.get(0).get(0).referencedImages.getTextureRegion(), x, y);   
            //}
           
        //
       
        if (unitGrid != null) {
        unitGrid.render();
        }
       
       
        if (FOVGrid != null) {
        FOVGrid.render();
        }

       
       
                //if (!(player.fov.wasVisited(1, 1))) {
        //    draw (fog.getAtlasRegion(), 400, 1);
        //}

        //draw(TransientImages.getTransientImagesByCode("tile_creature_submarine").atlasRegion, 1, 1);

        //if (player != null) {
        //    draw (player.getCreatures().image.imageGDX.image,  player.getScreenCoords().getIntX(), player.getScreenCoords().getIntY());
        //}

        spriteBatch.end();
       
        //game.state.render();
       
        super.process();
       
        spriteBatch.begin();
        font.drawString(50, 50, "MapCoords: "+player.getMapCoords().toRoundedString(), null);
        font.drawString(50, 100, "ScreenCoords: "+player.getScreenCoords().toRoundedString(), null);
        font.drawString(50, 150, "Mouse: "+MouseHack.getX()+"/"+(Detonator.INSTANCE.ScreenSizeY - MouseHack.getY()), null);
        spriteBatch.end();


    }
}
TOP

Related Classes of transientlibs.preui.agents.rendering.GDXMapDrawGridAgent

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.