/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package transientlibs.preui.agents.rendering;
import com.badlogic.gdx.graphics.OrthographicCamera;
import com.badlogic.gdx.graphics.g2d.TextureRegion;
import com.badlogic.gdx.math.Matrix4;
import com.badlogic.gdx.math.Rectangle;
import transientlibs.bindedobjects.gamecontent.Terrain;
import transientlibs.processors.misc.Detonator;
import transientlibs.maps.units.GenericUnit;
import transientlibs.maps.container.TransientAssembledMap;
import transientlibs.maps.container.TiledMapGDXContainer;
import transientlibs.maps.entities.Landmark;
import transientlibs.maps.utils.grid.FOVScreenGrid;
import transientlibs.maps.utils.grid.TerrainScreenGrid;
import transientlibs.maps.utils.grid.UnitScreenGrid;
import transientlibs.objects.primitives.Coords;
import transientlibs.preui.objects.gui.interfaces.IFont;
import transientlibs.preui.objects.gui.interfaces.IImage;
import transientlibs.preui.objects.states.IState;
/**
*
* @author alta
*/
public class GDXMapDrawAgentFixedCamera extends GDXGenericStateDrawAgent {
//private OrthographicCamera camera;
public TiledMapGDXContainer map;
Matrix4 projection;
public IFont font;
//public int sizeX = 200;
//public int sizeY = 400;
public int positionX = 0;
public int positionY = 0;
int fogX;
int fogY;
public IImage fog;
public IImage fog_00000000;
public IImage fog_00000101;
public IImage fog_00000111;
public IImage fog_00010001;
public IImage fog_00010101;
public IImage fog_00010111;
public IImage fog_00011100;
public IImage fog_00011101;
public IImage fog_00011111;
public IImage fog_01000001;
public IImage fog_01000100;
public IImage fog_01000111;
public IImage fog_01010001;
public IImage fog_01010100;
public IImage fog_01010101;
public IImage fog_01011100;
public IImage fog_01011111;
private TransientMapRenderer mapRenderer;
public FOVScreenGrid FOVGrid;
public UnitScreenGrid unitGrid;
public TerrainScreenGrid terrainGrid;
public GDXMapDrawAgentFixedCamera(TransientAssembledMap setMap, IState setState, int setOffsetX, int setOffsetY) {
super (setState);
positionX = setOffsetX;
positionY = setOffsetY;
//sizeX = setSizeX;
//sizeY = setSizeY;
if (setMap != null) {
setMap (setMap);
}
//fog = Detonator.INSTANCE.imageProvider.getImage("fog-default");
fog = Detonator.INSTANCE.imageProvider.getImage("fog-11000111");
this.fog_00000000 = Detonator.INSTANCE.imageProvider.getImage("fog-00000000");
fog_00000101 = Detonator.INSTANCE.imageProvider.getImage("fog-00000101");
fog_00000111 = Detonator.INSTANCE.imageProvider.getImage("fog-00000111");
fog_00010001 = Detonator.INSTANCE.imageProvider.getImage("fog-00010001");
fog_00010101 = Detonator.INSTANCE.imageProvider.getImage("fog-00010101");
fog_00010111 = Detonator.INSTANCE.imageProvider.getImage("fog-00010111");
fog_00011100 = Detonator.INSTANCE.imageProvider.getImage("fog-00011100");
fog_00011101 = Detonator.INSTANCE.imageProvider.getImage("fog-00011101");
fog_00011111 = Detonator.INSTANCE.imageProvider.getImage("fog-00011111");
fog_01000001 = Detonator.INSTANCE.imageProvider.getImage("fog-01000001");
fog_01000100 = Detonator.INSTANCE.imageProvider.getImage("fog-01000100");
fog_01000111 = Detonator.INSTANCE.imageProvider.getImage("fog-01000111");
fog_01010001 = Detonator.INSTANCE.imageProvider.getImage("fog-01010001");
fog_01010100 = Detonator.INSTANCE.imageProvider.getImage("fog-01010100");
fog_01010101 = Detonator.INSTANCE.imageProvider.getImage("fog-01010101");
fog_01011100 = Detonator.INSTANCE.imageProvider.getImage("fog-01011100");
fog_01011111 = Detonator.INSTANCE.imageProvider.getImage("fog-01011111");
//FOVGrid = new FOVScreenGrid (null, spriteBatch);
//camera = (OrthographicCamera) map.camera;
//camera.position.x = 0 + positionX;
// camera.position.y = 0 + positionY;
font = Detonator.INSTANCE.fontProvider.getFont("djvu_16_sans");
font.setBatch(spriteBatch);
//spriteBatch.setProjectionMatrix(projection);
}
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 process() {
//Log.warn("Map overlay");
//mapRenderer.setView(camera);
mapRenderer.render();
//terrainGrid.render();
spriteBatch.begin();
for (Landmark u : map.landmarks) {
float x = u.getScreenCoords().x;
float y = Detonator.INSTANCE.ScreenSizeY - Terrain.tileHeight - u.getScreenCoords().y;// - u.getImage().getHeight()
draw(u.getImage().getAtlasRegion(), x, y);
}
if (FOVGrid != null) {
FOVGrid.render();
}
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: "+Mouse.getX()+"/"+(Detonator.INSTANCE.ScreenSizeY - Mouse.getY()), null);
//spriteBatch.end();
}
public void setSize(int setX, int setY) {
//sizeX = setX;
//sizeY = setY;
projection.setToOrtho(0, Detonator.INSTANCE.ScreenSizeX, Detonator.INSTANCE.ScreenSizeY, 0, -1, 1);
mapRenderer.setView(projection, positionX, positionY, Detonator.INSTANCE.ScreenSizeX, Detonator.INSTANCE.ScreenSizeY);
}
public void setOffset(int setX, int setY) {
positionX = setX;
positionY = setY;
//camera.position.x = setX;
//camera.position.y = -setY;
//projection.setToOrtho(0, Detonator.INSTANCE.ScreenSizeX, 0, Detonator.INSTANCE.ScreenSizeY, -1, 1);
//mapRenderer.setView(projection, positionX, positionY, Detonator.INSTANCE.ScreenSizeX, Detonator.INSTANCE.ScreenSizeY);
//mapRenderer.setView(camera);
}
public final void setMap(TransientAssembledMap setMap) {
map = (TiledMapGDXContainer) setMap;
mapRenderer = new TransientMapRenderer(map.getTiledMapGDX().gdxMap, new Coords(positionX, positionY));
FOVGrid = new FOVScreenGrid(map, spriteBatch);
FOVGrid.fog = fog;
FOVGrid.fog_00000101 = Detonator.INSTANCE.imageProvider.getImage("fog-00000101");
FOVGrid.fog_00000111 = Detonator.INSTANCE.imageProvider.getImage("fog-00000111");
FOVGrid.fog_00010001 = Detonator.INSTANCE.imageProvider.getImage("fog-00010001");
FOVGrid.fog_00010101 = Detonator.INSTANCE.imageProvider.getImage("fog-00010101");
FOVGrid.fog_00010111 = Detonator.INSTANCE.imageProvider.getImage("fog-00010111");
FOVGrid.fog_00011100 = Detonator.INSTANCE.imageProvider.getImage("fog-00011100");
FOVGrid.fog_00011101 = Detonator.INSTANCE.imageProvider.getImage("fog-00011101");
FOVGrid.fog_00011111 = Detonator.INSTANCE.imageProvider.getImage("fog-00011111");
FOVGrid.fog_01000001 = Detonator.INSTANCE.imageProvider.getImage("fog-01000001");
FOVGrid.fog_01000100 = Detonator.INSTANCE.imageProvider.getImage("fog-01000100");
FOVGrid.fog_01000111 = Detonator.INSTANCE.imageProvider.getImage("fog-01000111");
FOVGrid.fog_01010001 = Detonator.INSTANCE.imageProvider.getImage("fog-01010001");
FOVGrid.fog_01010100 = Detonator.INSTANCE.imageProvider.getImage("fog-01010100");
FOVGrid.fog_01010101 = Detonator.INSTANCE.imageProvider.getImage("fog-01010101");
FOVGrid.fog_01011100 = Detonator.INSTANCE.imageProvider.getImage("fog-01011100");
FOVGrid.fog_01011111 = Detonator.INSTANCE.imageProvider.getImage("fog-01011111");
terrainGrid = new TerrainScreenGrid(map, spriteBatch);
unitGrid = new UnitScreenGrid(map, spriteBatch);
mapRenderer.setViewBounds (new Rectangle(positionX, positionY, Detonator.INSTANCE.ScreenSizeX, Detonator.INSTANCE.ScreenSizeY));
}
}