feat: ajout du composant transhower qui permet de visualiser un transmuteur complet au sein d'un actor sur un fond coloré.
This commit is contained in:
parent
a598faece3
commit
ea15e1e37c
|
@ -139,13 +139,10 @@ public class TouchMaptiles extends Actor implements GestureListener,InputProcess
|
|||
}
|
||||
|
||||
public void tempdraw(float x, float y, int tile, int rotation, int surtile) {
|
||||
Cell cell = ((TiledMapTileLayer) map.getLayers().get(3)).getCell(
|
||||
(int) x, (int) y);
|
||||
Cell cell = ((TiledMapTileLayer) map.getLayers().get(3)).getCell((int) x, (int) y);
|
||||
if (cell != null) {
|
||||
((TiledMapTileLayer) map.getLayers().get(4)).getCell((int) x,
|
||||
(int) y).setTile(AssetLoader.tileSet.getTile(tile));
|
||||
((TiledMapTileLayer) map.getLayers().get(4)).getCell((int) x,
|
||||
(int) y).setRotation(rotation);
|
||||
((TiledMapTileLayer) map.getLayers().get(4)).getCell((int) x,(int) y).setTile(AssetLoader.tileSet.getTile(tile));
|
||||
((TiledMapTileLayer) map.getLayers().get(4)).getCell((int) x,(int) y).setRotation(rotation);
|
||||
if (surtile != 0)
|
||||
((TiledMapTileLayer) map.getLayers().get(3)).getCell((int) x,
|
||||
(int) y).setTile(AssetLoader.tileSet.getTile(surtile));
|
||||
|
|
|
@ -0,0 +1,185 @@
|
|||
package fr.evolving.UI;
|
||||
|
||||
import com.badlogic.gdx.Gdx;
|
||||
import com.badlogic.gdx.graphics.Color;
|
||||
import com.badlogic.gdx.graphics.OrthographicCamera;
|
||||
import com.badlogic.gdx.graphics.g2d.Batch;
|
||||
import com.badlogic.gdx.graphics.glutils.ShapeRenderer;
|
||||
import com.badlogic.gdx.graphics.glutils.ShapeRenderer.ShapeType;
|
||||
import com.badlogic.gdx.maps.MapLayers;
|
||||
import com.badlogic.gdx.maps.tiled.TiledMap;
|
||||
import com.badlogic.gdx.maps.tiled.TiledMapTileLayer;
|
||||
import com.badlogic.gdx.maps.tiled.TiledMapTileLayer.Cell;
|
||||
import com.badlogic.gdx.maps.tiled.renderers.OrthogonalTiledMapRenderer;
|
||||
import com.badlogic.gdx.math.Vector2;
|
||||
import com.badlogic.gdx.scenes.scene2d.Actor;
|
||||
import com.badlogic.gdx.utils.OrderedMap;
|
||||
import com.badlogic.gdx.utils.ObjectMap.Entries;
|
||||
import com.badlogic.gdx.utils.ObjectMap.Entry;
|
||||
|
||||
import fr.evolving.assets.AssetLoader;
|
||||
import fr.evolving.automata.Transmuter;
|
||||
import fr.evolving.automata.Transmuter.Angular;
|
||||
import fr.evolving.automata.Transmuter.CaseType;
|
||||
import fr.evolving.screens.GameScreen.calling;
|
||||
|
||||
public class Transhower extends Actor {
|
||||
|
||||
private Transmuter transmuter;
|
||||
private TiledMap map;
|
||||
private OrthogonalTiledMapRenderer MapRenderer;
|
||||
private OrthographicCamera camera;
|
||||
private TiledMapTileLayer layer;
|
||||
private ShapeRenderer shaperenderer;
|
||||
private Transmuter.Angular angle;
|
||||
boolean keepaspectratio;
|
||||
Color color;
|
||||
|
||||
public Transhower(Transmuter transmuter, Transmuter.Angular angle, boolean keepaspectratio,Color color) {
|
||||
this.color=color;
|
||||
this.keepaspectratio=keepaspectratio;
|
||||
this.angle=angle;
|
||||
shaperenderer= new ShapeRenderer();
|
||||
map = new TiledMap();
|
||||
map.getTileSets().addTileSet(AssetLoader.tileSet);
|
||||
MapRenderer = new OrthogonalTiledMapRenderer(map, 1 / 128.0f);
|
||||
camera = new OrthographicCamera();
|
||||
layer = new TiledMapTileLayer(4, 7, 128, 128);
|
||||
super.setBounds(-500, -500, 256, 256);
|
||||
map.getLayers().add(layer);
|
||||
setTransmuter(transmuter);
|
||||
}
|
||||
|
||||
public void clear() {
|
||||
this.transmuter=null;
|
||||
for (int x = 0; x < layer.getWidth(); x++) {
|
||||
for (int y = 0; y < layer.getHeight(); y++) {
|
||||
Cell cell = new Cell();
|
||||
layer.setCell(x, y, cell);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void redraw() {
|
||||
this.transmuter.setRotation(angle);
|
||||
OrderedMap<Vector2, Integer> tiles = transmuter.getTilesidrotated();
|
||||
Entries<Vector2, Integer> iterator = tiles.iterator();
|
||||
float minx=15000;
|
||||
float miny=15000;
|
||||
float maxx=-15000;
|
||||
float maxy=-15000;
|
||||
while (iterator.hasNext()) {
|
||||
Entry<Vector2, Integer> all = iterator.next();
|
||||
if (all.key.x<minx)
|
||||
minx=all.key.x;
|
||||
if (all.key.y<miny)
|
||||
miny=all.key.y;
|
||||
if (all.key.x>maxx)
|
||||
maxx=all.key.x;
|
||||
if (all.key.y>maxy)
|
||||
maxy=all.key.y;
|
||||
}
|
||||
int deltax=(int)(maxx-minx)+1;
|
||||
int deltay=(int)(maxy-miny)+1;
|
||||
float change=0;
|
||||
boolean dir=false;
|
||||
if (keepaspectratio) {
|
||||
change=Math.abs(deltax-deltay);
|
||||
if (change<0) {
|
||||
deltay=deltax;
|
||||
dir=true;
|
||||
}
|
||||
else if (change>0) {
|
||||
deltax=deltay;
|
||||
dir=false;
|
||||
}
|
||||
}
|
||||
iterator.reset();
|
||||
while (iterator.hasNext()) {
|
||||
Entry<Vector2, Integer> all = iterator.next();
|
||||
Gdx.app.debug("wirechem-Transhower", "Transmuter placement:"+(all.key.x-minx)+","+(all.key.y-miny)+" angle:"+this.angle);
|
||||
layer.getCell((int)(all.key.x-minx),(int)(all.key.y-miny)).setTile(AssetLoader.tileSet.getTile(all.value));
|
||||
layer.getCell((int)(all.key.x-minx),(int)(all.key.y-miny)).setRotation(this.angle.ordinal());
|
||||
}
|
||||
float sizex=AssetLoader.width/(this.getWidth()/deltax);
|
||||
float sizey=AssetLoader.height/(this.getHeight()/deltay);
|
||||
float decx = -this.getX()/AssetLoader.width*sizex;
|
||||
float decy = -this.getY()/AssetLoader.height*sizey;
|
||||
if (change!=0)
|
||||
if (dir)
|
||||
decy=decy-change/2;
|
||||
else
|
||||
decx=decx-change/2;
|
||||
Gdx.app.debug("wirechem-Transhower", "Camera dec:"+decx+","+decy+" view:"+sizex+","+sizey+" change:"+change+","+dir);
|
||||
camera.setToOrtho(false, sizex, sizey);
|
||||
camera.translate(decx,decy);
|
||||
}
|
||||
|
||||
public void setBounds(float x, float y, float width, float height) {
|
||||
super.setBounds(x, y, width, height);
|
||||
redraw();
|
||||
}
|
||||
|
||||
public void setHeight(float height) {
|
||||
super.setHeight(height);
|
||||
redraw();
|
||||
}
|
||||
|
||||
public void setPosition(float x, float y) {
|
||||
super.setPosition(x, y);
|
||||
redraw();
|
||||
}
|
||||
|
||||
public void setWidth(float width) {
|
||||
super.setWidth(width);
|
||||
redraw();
|
||||
}
|
||||
|
||||
public void setTransmuter(Transmuter transmuter) {
|
||||
this.clear();
|
||||
this.transmuter=transmuter;
|
||||
this.redraw();
|
||||
}
|
||||
|
||||
public void setAngle(Transmuter.Angular angle)
|
||||
{
|
||||
this.angle=angle;
|
||||
this.transmuter.setRotation(angle);
|
||||
this.redraw();
|
||||
}
|
||||
|
||||
public Transmuter.Angular getAngle() {
|
||||
return this.angle;
|
||||
}
|
||||
|
||||
public void setColor(Color color)
|
||||
{
|
||||
this.color=color;
|
||||
this.redraw();
|
||||
}
|
||||
|
||||
|
||||
public Color getColor()
|
||||
{
|
||||
return this.color;
|
||||
}
|
||||
|
||||
public Transmuter getTransmuter() {
|
||||
return this.transmuter;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void draw(Batch batch, float parentAlpha) {
|
||||
batch.end();
|
||||
shaperenderer.begin(ShapeType.Filled);
|
||||
shaperenderer.setProjectionMatrix(AssetLoader.Camera.combined);
|
||||
shaperenderer.rect(this.getX(),this.getY(),this.getWidth(),this.getHeight());
|
||||
shaperenderer.setColor(this.color);
|
||||
shaperenderer.end();
|
||||
camera.update();
|
||||
MapRenderer.setView(camera);
|
||||
MapRenderer.render();
|
||||
batch.begin();
|
||||
}
|
||||
|
||||
}
|
|
@ -7,6 +7,7 @@ import com.badlogic.gdx.Game;
|
|||
import com.badlogic.gdx.Gdx;
|
||||
import com.badlogic.gdx.Screen;
|
||||
import com.badlogic.gdx.Application;
|
||||
import com.badlogic.gdx.graphics.Color;
|
||||
import com.badlogic.gdx.scenes.scene2d.Actor;
|
||||
import com.badlogic.gdx.scenes.scene2d.InputEvent;
|
||||
import com.badlogic.gdx.scenes.scene2d.Stage;
|
||||
|
@ -26,12 +27,14 @@ import com.badlogic.gdx.utils.Array;
|
|||
import fr.evolving.UI.ButtonLevel;
|
||||
import fr.evolving.UI.Objectives;
|
||||
import fr.evolving.UI.ServerList;
|
||||
import fr.evolving.UI.Transhower;
|
||||
import fr.evolving.UI.WarnDialog;
|
||||
import fr.evolving.UI.Worldlist;
|
||||
import fr.evolving.assets.AssetLoader;
|
||||
import fr.evolving.assets.InitWorlds;
|
||||
import fr.evolving.assets.Preference;
|
||||
import fr.evolving.automata.Level;
|
||||
import fr.evolving.automata.Transmuter;
|
||||
import fr.evolving.automata.Worlds;
|
||||
import fr.evolving.automata.Worlds.State;
|
||||
import fr.evolving.database.Base;
|
||||
|
@ -59,6 +62,8 @@ public class LevelScreen implements Screen {
|
|||
private Objectives Victory;
|
||||
public ButtonLevel selected;
|
||||
public int addervalue;
|
||||
|
||||
public Transhower test;
|
||||
|
||||
|
||||
public void play() {
|
||||
|
@ -266,6 +271,10 @@ public class LevelScreen implements Screen {
|
|||
}
|
||||
|
||||
public LevelScreen(Worlds aworlds) {
|
||||
test=new Transhower(AssetLoader.getTransmuter("<>"),Transmuter.Angular.A90,true, new Color(0,1f,0f,1f));
|
||||
test.setPosition(1920/2, 70);
|
||||
test.setWidth(512);
|
||||
test.setHeight(512);
|
||||
this.worlds = aworlds;
|
||||
addervalue=1;
|
||||
worlds.addListener(new ChangeListener() {
|
||||
|
@ -619,7 +628,7 @@ public class LevelScreen implements Screen {
|
|||
}
|
||||
});
|
||||
cycle = new ImageTextButton("10", AssetLoader.Skin_level, "cycle");
|
||||
cycle.setPosition(1250, 360);
|
||||
cycle.setPosition(1240, 360);
|
||||
cycle.addListener(new ClickListener() {
|
||||
@Override
|
||||
public void clicked(InputEvent event, float x, float y) {
|
||||
|
@ -643,7 +652,7 @@ public class LevelScreen implements Screen {
|
|||
}
|
||||
});
|
||||
rayon = new ImageTextButton("10", AssetLoader.Skin_level, "rayon");
|
||||
rayon.setPosition(1250, 490);
|
||||
rayon.setPosition(1240, 490);
|
||||
rayon.addListener(new ClickListener() {
|
||||
@Override
|
||||
public void clicked(InputEvent event, float x, float y) {
|
||||
|
@ -655,7 +664,7 @@ public class LevelScreen implements Screen {
|
|||
}
|
||||
});
|
||||
up_cycle = new ImageTextButton("10", AssetLoader.Skin_level, "up_cycle");
|
||||
up_cycle.setPosition(1250, AssetLoader.height-250);
|
||||
up_cycle.setPosition(1240, AssetLoader.height-250);
|
||||
up_cycle.addListener(new ClickListener() {
|
||||
@Override
|
||||
public void clicked(InputEvent event, float x, float y) {
|
||||
|
@ -679,7 +688,7 @@ public class LevelScreen implements Screen {
|
|||
}
|
||||
});
|
||||
up_rayon = new ImageTextButton("10", AssetLoader.Skin_level, "up_rayon");
|
||||
up_rayon.setPosition(1250, AssetLoader.height-120);
|
||||
up_rayon.setPosition(1240, AssetLoader.height-120);
|
||||
up_rayon.addListener(new ClickListener() {
|
||||
@Override
|
||||
public void clicked(InputEvent event, float x, float y) {
|
||||
|
@ -703,7 +712,7 @@ public class LevelScreen implements Screen {
|
|||
}
|
||||
});
|
||||
up = new ImageTextButton("10", AssetLoader.Skin_level, "up");
|
||||
up.setPosition(1250, AssetLoader.height-380);
|
||||
up.setPosition(1240, AssetLoader.height-380);
|
||||
up.addListener(new ClickListener() {
|
||||
@Override
|
||||
public void clicked(InputEvent event, float x, float y) {
|
||||
|
@ -881,6 +890,10 @@ public class LevelScreen implements Screen {
|
|||
stage.addActor(up_temp);
|
||||
stage.addActor(up_rayon);
|
||||
stage.addActor(research);
|
||||
|
||||
stage.addActor(test);
|
||||
|
||||
|
||||
Gdx.input.setInputProcessor(stage);
|
||||
Gdx.app.debug("wirechem-LevelScreen", "Début dans la bande son \'intro\'");
|
||||
AssetLoader.intro.setLooping(true);
|
||||
|
|
Loading…
Reference in New Issue