feat: creation de l'élement horizbar et amélioration de menu afin d'alléger le gamerenderer et gamescreen

This commit is contained in:
Nicolas Hordé 2016-01-23 00:19:36 +01:00
parent 46c2627314
commit aa9afa4cc5
6 changed files with 465 additions and 205 deletions

View File

@ -0,0 +1,157 @@
package fr.evolving.UI;
import java.lang.reflect.InvocationTargetException;
import java.util.Timer;
import java.util.TimerTask;
import com.badlogic.gdx.Game;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.g2d.Batch;
import com.badlogic.gdx.graphics.g2d.TextureRegion;
import com.badlogic.gdx.scenes.scene2d.Actor;
import com.badlogic.gdx.scenes.scene2d.InputEvent;
import com.badlogic.gdx.scenes.scene2d.Touchable;
import com.badlogic.gdx.scenes.scene2d.ui.HorizontalGroup;
import com.badlogic.gdx.scenes.scene2d.ui.ImageButton;
import com.badlogic.gdx.scenes.scene2d.ui.Tooltip;
import com.badlogic.gdx.scenes.scene2d.utils.ClickListener;
import com.badlogic.gdx.scenes.scene2d.utils.ChangeListener.ChangeEvent;
import com.badlogic.gdx.utils.reflect.Method;
import fr.evolving.assets.AssetLoader;
import fr.evolving.screens.GameScreen;
import fr.evolving.screens.GameScreen.calling;
public class HorizBarre extends Actor {
private ImageButton[] Barre;
private HorizontalGroup table;
private java.lang.reflect.Method method;
private TextureRegion oneselection;
private Timer RotateTimer;
private TimerTask RotateTask;
private Actor selected;
private float rotation;
ChangeEvent event;
public HorizBarre(String[] tocreate, String methodname) {
Class<?> base;
try {
Class<?>[] params = {String.class, int.class};
base = Class.forName("fr.evolving.screens.GameScreen");
method = base.getDeclaredMethod(methodname, params);
} catch (ClassNotFoundException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
} catch (NoSuchMethodException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (SecurityException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
Gdx.app.debug(getClass().getSimpleName(), "Mise en place du timer de rotation.");
oneselection = AssetLoader.Atlas_level.findRegion("circle");
rotation=0;
RotateTimer = new Timer();
RotateTask = new TimerTask() {
@Override
public void run() {
rotation += 5;
}
};
RotateTimer.scheduleAtFixedRate(RotateTask, 0, 30);
this.setBounds(0, 0, 1920, 80);
Barre = new ImageButton[tocreate.length];
int i = 0;
Gdx.app.debug(getClass().getSimpleName(), "Barre bas:" + Barre.length
+ " elements");
for (String item : tocreate) {
final String itemtocreate=item.replace("#", "");
Barre[i] = new ImageButton(AssetLoader.Skin_level, itemtocreate);
Barre[i].setTouchable(Touchable.enabled);
Barre[i].setName(itemtocreate);
if (item.contains("#"))
{
Barre[i++].addListener(new ClickListener() {
@Override
public void clicked(InputEvent event, float x, float y) {
onchanged();
if (selected==null) selected = new Actor();
selected.setName(itemtocreate);
selected.setBounds(event.getListenerActor().getX(), event.getListenerActor().getY(), 64, 64);
}
});
}
else
Barre[i++].addListener(new ClickListener() {
@Override
public void clicked(InputEvent event, float x, float y) {
String caller = event.getListenerActor().getName();
Gdx.app.debug("Barre", "Selection dans la Barre bas:"
+ caller);
try {
method.invoke(((Game) Gdx.app.getApplicationListener()).getScreen(), caller, this.getTapCount());
} catch (IllegalAccessException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IllegalArgumentException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (InvocationTargetException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
});
}
Barre[15].setChecked(Gdx.graphics.isFullscreen());
Barre[16].setChecked(AssetLoader.intro.getVolume() > 0);
Barre[17].setChecked(AssetLoader.Tooltipmanager.enabled == true);
table = new HorizontalGroup();
table.bottom().padLeft(5f).padBottom(8f).space(10f);
this.setTouchable(Touchable.enabled);
table.setTouchable(Touchable.enabled);
for (i = 0; i < Barre.length; i++)
table.addActor(Barre[i]);
}
public void unSelect() {
selected=null;
}
public String getSelection() {
if (selected!=null)
return selected.getName();
else
return null;
}
public void onchanged() {
ChangeEvent event=new ChangeEvent();
event.setTarget(this);
event.setListenerActor(this);
event.setStage(this.getStage());
if (event.getStage()!=null)
this.fire(event);
}
public Actor hit(float x, float y, boolean touchable) {
return table.hit(x, y, touchable);
}
@Override
public void draw(Batch batch, float parentAlpha) {
table.draw(batch, parentAlpha);
if (selected != null) {
batch.setColor(1f, 0f, 0f, 1f);
batch.draw(oneselection, selected.getX()+this.getX(),
selected.getY()+this.getY(),
selected.getWidth() / 2,
selected.getHeight() / 2,
selected.getWidth(),
selected.getHeight(), 1f, 1f, rotation);
}
}
}

View File

@ -1,10 +1,13 @@
package fr.evolving.UI;
import java.util.Iterator;
import java.util.Timer;
import java.util.TimerTask;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.OrthographicCamera;
import com.badlogic.gdx.graphics.g2d.Batch;
import com.badlogic.gdx.graphics.g2d.TextureRegion;
import com.badlogic.gdx.maps.MapLayers;
import com.badlogic.gdx.maps.MapProperties;
import com.badlogic.gdx.maps.tiled.TiledMap;
@ -13,6 +16,9 @@ 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.scenes.scene2d.InputEvent;
import com.badlogic.gdx.scenes.scene2d.utils.ChangeListener.ChangeEvent;
import com.badlogic.gdx.scenes.scene2d.utils.ClickListener;
import com.badlogic.gdx.utils.ObjectMap.Entries;
import com.badlogic.gdx.utils.ObjectMap.Entry;
import com.badlogic.gdx.utils.OrderedMap;
@ -36,6 +42,13 @@ public class Menu extends Actor {
private float decy;
private int size = 32;
private Level level;
private Actor selected;
private Transmuter selected_transmuter;
private TextureRegion oneselection;
private Timer RotateTimer;
private TimerTask RotateTask;
private float rotation;
ChangeEvent event;
public Menu(Level level) {
this.tilesizex = 4;
@ -44,50 +57,168 @@ public class Menu extends Actor {
this.selpage=0;
this.seltype=0;
this.level=level;
Gdx.app.debug(getClass().getSimpleName(), "Création du Tiledmap et Maprenderer");
map = new TiledMap[3][Transmuter.Class.values().length];
clear();
MapRenderer = new OrthogonalTiledMapRenderer(map[selpage][seltype], 1 / (float) size);
Gdx.app.debug(getClass().getSimpleName(), "Caméra pour tilemap:"+ (tilesizex * size) + "x" + (tilesizey * size));
camera = new OrthographicCamera();
camera.setToOrtho(false, tilesizex * 32, tilesizex * 32
* AssetLoader.height / AssetLoader.width);
Gdx.app.debug(getClass().getSimpleName(), "Caméra pour tilemap:"
+ (tilesizex * size) + "x" + (tilesizey * size));
camera.setToOrtho(false, tilesizex * 32, tilesizex * 32 * AssetLoader.height / AssetLoader.width);
decx = -102f;
decy = -20f;
if (AssetLoader.ratio == 1.44f) decy -= 24;
camera.translate(decx, decy);
Gdx.app.debug(getClass().getSimpleName(), "Décalage:" + decx + "x"+ decy);
camera.translate(decx, decy);
Gdx.app.debug(getClass().getSimpleName(), "Ajout des éléments de menu");
init();
Gdx.app.debug(getClass().getSimpleName(), "Mise en place du timer de rotation.");
oneselection = AssetLoader.Atlas_level.findRegion("circle");
selected = new Actor();
rotation=0;
RotateTimer = new Timer();
RotateTask = new TimerTask() {
@Override
public void run() {
rotation += 5;
}
};
RotateTimer.scheduleAtFixedRate(RotateTask, 0, 30);
Gdx.app.debug(getClass().getSimpleName(), "Ajout de l'évènements clicked");
this.addListener(new ClickListener() {
@Override
public void clicked(InputEvent event, float x, float y) {
Gdx.app.debug("treetree", "xy"+x+","+y);
Vector2 coords = screentoworld(x, y);
MapProperties tile = getMenubyTile((int) coords.x,
(int) coords.y);
if (tile != null && tile.containsKey("name")) {
selected_transmuter=null;
EraseSurtile();
if (selected==null)
selected=new Actor();
if (tile.get("type").toString().startsWith("transmuter")) {
if (tile.containsKey("movetox")) {
coords.x += (Integer) tile.get("movetox");
coords.y += (Integer) tile.get("movetoy");
}
MapProperties tilenew = getMenubyTile((int) coords.x, (int) coords.y);
selected_transmuter = (Transmuter) ((Transmuter) tilenew.get("transmuter")).clone();
if (selected_transmuter != null) {
selected.setName("transmuter");
setSurtile((int) coords.x,(int) coords.y, selected_transmuter);
Gdx.app.debug("menu", "Choix transmuter:"+ selected_transmuter.getName());
}
}
else
selected.setName(tile.get("name").toString());
Vector2 coords2 = worldtoscreen((int) coords.x,
(int) coords.y);
Gdx.app.debug("menu","Coordonnées:" + x + "x" + y + " Menu:" + coords.x
+ "," + coords.y + " Ecran :" + coords2.x
+ "x" + coords2.y + " type:"
+ tile.get("type"));
selected.setBounds(coords2.x, coords2.y, 60, 60);
onchanged();
}
}
});
}
public void unSelect() {
selected=null;
selected_transmuter=null;
EraseSurtile();
}
public String getSelection() {
if (selected!=null)
return selected.getName();
else
return null;
}
public Transmuter getTransmuter() {
return selected_transmuter;
}
public void onchanged() {
ChangeEvent event=new ChangeEvent();
event.setTarget(this);
event.setListenerActor(this);
event.setStage(this.getStage());
if (event.getStage()!=null)
this.fire(event);
}
public void setPage(int page) {
selected=null;
this.selpage=page;
this.MapRenderer.setMap(map[selpage][seltype]);
EraseSurtile();
onchanged();
}
public void setPageType(int page,int type) {
selected=null;
this.selpage=page;
this.seltype=type;
this.MapRenderer.setMap(map[selpage][seltype]);
EraseSurtile();
onchanged();
}
public boolean isNextEmpty() {
if (this.selpage>=this.nbpages-2) return true;
TiledMapTileLayer layer=(TiledMapTileLayer)map[selpage+1][seltype].getLayers().get(0);
boolean test=layer.getProperties().containsKey("noempty");
return (!layer.getProperties().containsKey("noempty"));
}
public boolean isPreviousEmpty() {
if (this.selpage<1) return true;
TiledMapTileLayer layer=(TiledMapTileLayer)map[selpage-1][seltype].getLayers().get(0);
return (!layer.getProperties().containsKey("noempty"));
}
public void NextPage() {
if (this.selpage<nbpages-1)
if (this.selpage<nbpages-1) {
selected=null;
this.selpage++;
this.MapRenderer.setMap(map[selpage][seltype]);
this.MapRenderer.setMap(map[selpage][seltype]);
EraseSurtile();
onchanged();
}
}
public void PreviousPage() {
if (this.selpage>0)
if (this.selpage>0) {
selected=null;
this.selpage--;
this.MapRenderer.setMap(map[selpage][seltype]);
EraseSurtile();
this.MapRenderer.setMap(map[selpage][seltype]);
EraseSurtile();
onchanged();
}
}
public int getPage() {
return this.selpage;
}
public int getMaxPage() {
return this.nbpages;
}
public void setType(int type) {
this.seltype=type;
selected=null;
this.MapRenderer.setMap(map[selpage][seltype]);
onchanged();
}
public int getType() {
@ -148,19 +279,21 @@ public class Menu extends Actor {
}
private void setMenuTile(int x, int y, int tile, String title, int page) {
Cell cell = ((TiledMapTileLayer) map[page][0].getLayers().get(0)).getCell(x, y);
TiledMapTileLayer layer = ((TiledMapTileLayer) map[page][0].getLayers().get(0));
Cell cell = layer.getCell(x, y);
if (cell != null) {
cell.setTile(AssetLoader.tileSet.getTile(tile));
cell.getTile().getProperties().put("name", title);
cell.setRotation(0);
Gdx.app.debug(getClass().getSimpleName(), "Tile find:" + tile
+ " coords" + x + "," + y);
layer.getProperties().put("noempty", false);
}
}
public void setSurtile(int x, int y, Transmuter transmuter) {
if (transmuter != null) {
Cell cell = ((TiledMapTileLayer) map[selpage][seltype].getLayers().get(1)).getCell(x,y);
Cell cell = ((TiledMapTileLayer) map[selpage][seltype].getLayers().get(1)).getCell(x, y);
OrderedMap<Vector2, Integer> tiles = transmuter.getTilesidrotated();
Entries<Vector2, Integer> iterator = tiles.iterator();
while (iterator.hasNext()) {
@ -172,7 +305,6 @@ public class Menu extends Actor {
tiles.keys().toArray().indexOf(all.key, false))
.ordinal() + 80));
}
}
}
@ -195,22 +327,21 @@ public class Menu extends Actor {
Transmuter transmuter = AssetLoader.getTransmuter(Name);
if (transmuter != null) {
int type=transmuter.getaClass().ordinal();
Cell cell = ((TiledMapTileLayer) map[page][type].getLayers().get(0)).getCell(x, y);
TiledMapTileLayer layer = ((TiledMapTileLayer) map[page][type].getLayers().get(0));
Cell cell = layer.getCell(x, y);
if (cell != null) {
Gdx.app.debug(getClass().getSimpleName(), "Transmuter find:"
+ transmuter.getName() + " Angle:" + Angle + " coords"
+ x + "," + y+" page:"+page+" type:"+type);
if (transmuter.getTechnology()<=level.Tech) {
Gdx.app.debug(getClass().getSimpleName(), "Autorisé par le niveau");
layer.getProperties().put("noempty", false);
transmuter.setRotation(Angle);
Iterator<Entry<Vector2, Integer>> keySetIterator = transmuter
.getTilesidrotated().iterator();
while (keySetIterator.hasNext()) {
Entry<Vector2, Integer> all = keySetIterator.next();
Cell subcell = ((TiledMapTileLayer) map[page][type].getLayers().get(0))
.getCell((int) (x + all.key.x),
(int) (y + all.key.y));
Cell subcell = layer.getCell((int) (x + all.key.x), (int) (y + all.key.y));
subcell.setTile(AssetLoader.tileSet.getTile(all.value));
subcell.setRotation(Angle.ordinal());
subcell.getTile().getProperties()
@ -233,14 +364,14 @@ public class Menu extends Actor {
}
public Vector2 screentoworld(float x, float y) {
int xx = (int) ((x - 1531f) / 60f);
int yy = (int) ((y - (AssetLoader.height - 776f)) / 60f);
int xx = (int) (x / 60f);
int yy = (int) (y / 60f);
return new Vector2(xx, yy);
}
public Vector2 worldtoscreen(int x, int y) {
float xx = 1531.0f + x * 60f;
float yy = AssetLoader.height - 776.0f + y * 60f;
float xx = x * 60f;
float yy = y * 60f;
return new Vector2(xx, yy);
}
@ -251,6 +382,15 @@ public class Menu extends Actor {
MapRenderer.setView(camera);
MapRenderer.render();
batch.begin();
if (selected != null) {
batch.setColor(1f, 0f, 0f, 1f);
batch.draw(oneselection, selected.getX()+this.getX(),
selected.getY()+this.getY(),
selected.getWidth() / 2,
selected.getHeight() / 2,
selected.getWidth(),
selected.getHeight(), 1f, 1f, rotation);
}
}
}

View File

@ -8,7 +8,9 @@ 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.Rectangle;
import com.badlogic.gdx.math.Vector2;
import com.badlogic.gdx.math.Vector3;
import com.badlogic.gdx.scenes.scene2d.Actor;
import fr.evolving.assets.AssetLoader;

View File

@ -107,7 +107,7 @@ public class Positiver_II extends Transmuter {
public void Upgrade() {
if (this.Upgrade == null)
return;
this.Unlock.SetShowed(true);
this.Upgrade.SetShowed(true);
this.SetShowed(false);
}

View File

@ -14,8 +14,6 @@ public class GameRenderer {
private ShapeRenderer shapeRenderer;
private SpriteBatch batcher;
private GameScreen GameScreen;
private TextureRegion oneselection;
private float rotation;
public GameRenderer(GameScreen GameScreen) {
this.GameScreen = GameScreen;
@ -23,12 +21,6 @@ public class GameRenderer {
batcher.setProjectionMatrix(AssetLoader.Camera.combined);
shapeRenderer = new ShapeRenderer();
shapeRenderer.setProjectionMatrix(AssetLoader.Camera.combined);
oneselection = AssetLoader.Atlas_level.findRegion("circle");
rotation = 0f;
}
public void evolve() {
rotation += 5;
}
public void render(float delta, float runTime, int layer) {
@ -52,17 +44,6 @@ public class GameRenderer {
} else if (layer == 2) {
shapeRenderer.begin(ShapeType.Filled);
shapeRenderer.end();
batcher.begin();
if (GameScreen.selected != null) {
batcher.setColor(1f, 0f, 0f, 1f);
batcher.draw(oneselection, GameScreen.selected.getX(),
GameScreen.selected.getY(),
GameScreen.selected.getWidth() / 2,
GameScreen.selected.getHeight() / 2,
GameScreen.selected.getWidth(),
GameScreen.selected.getHeight(), 1f, 1f, rotation);
}
batcher.end();
}
}

View File

@ -53,6 +53,7 @@ import com.badlogic.gdx.utils.ObjectMap.Entry;
import com.badlogic.gdx.utils.OrderedMap;
import fr.evolving.UI.ButtonLevel;
import fr.evolving.UI.HorizBarre;
import fr.evolving.UI.Menu;
import fr.evolving.UI.Objectives;
import fr.evolving.UI.TouchMaptiles;
@ -69,17 +70,13 @@ import fr.evolving.renderers.GameRenderer;
public class GameScreen implements Screen {
private InputMultiplexer multiplexer;
private Array<InputProcessor> processors;
private Timer ScrollTimer;
private WarnDialog dialog;
private TimerTask ScrollTask;
private Stage stage, stage_menu, stage_info, stage_tooltip;
private HorizontalGroup table;
private Stage stage, stage_map, stage_info, stage_tooltip;
private VerticalGroup table2;
private GameRenderer Renderer;
private float runTime;
public Level level;
private Window winOptions, winSave;
private ImageButton[] Barre;
private CheckBox SetSound, SetVsynch, SetFullscreen, SetAnimation, Settuto,
Setdebog, Setrefresh;
private Slider SetEffectvolume, SetMusicvolume;
@ -88,23 +85,21 @@ public class GameScreen implements Screen {
private SelectBox<quality> selTexturequal;
private SelectBox<adaptation> selAdaptscreen;
private List selSaved;
private ImageButton Setflag, info_up_nrj, info_up_temp, info_up_rayon,
private ImageButton Setflag, info_up_nrj, info_up_temp, info_up, info_up_rayon,
info_up_cycle, info_up_nrjval, info_up_tempval, info_up_rayonval,
info_up_cycleval, SetFlag, nextpage, previouspage;
info_up_cycleval, nextpage, previouspage;
private ImageTextButton cycle, temp, nrj, rayon, cout, tech, research,
info_cout, info_tech, info_research, info_activation;
private ImageTextButton[] Barre2;
String[] tocreate = { "run", "stop", "speed", "separator", "move", "zoomp",
"zoomm", "infos", "separator", "raz", "save", "levels", "tree",
String[] tocreate = { "run", "stop", "speed", "separator", "move#", "zoomp#",
"zoomm#", "infos#", "separator", "raz", "save", "levels", "tree",
"exits", "separator", "screen", "sound", "tuto", "settings",
"separator", "stat" };
public Actor selected;
public Transmuter selected_transmuter;
private ButtonLevel buttonlevel;
private Objectives objectives;
private TouchMaptiles map;
private Menu menu;
private Actor menuactor;
private HorizBarre horizbar;
private float oldx, oldy;
private Label fpsLabel, info_nom;
private TextArea info_desc, tooltip;
@ -219,12 +214,19 @@ public class GameScreen implements Screen {
this.level.Grid.tiling_copper();
this.level.Grid.tiling_transmuter();
}
Gdx.app.debug(getClass().getSimpleName(),
"Création des Barres verticales & horizontales.");
table = new HorizontalGroup();
table.bottom().padLeft(5f).padBottom(8f).space(10f);
Gdx.app.debug(getClass().getSimpleName(),"Création des Barres verticales & horizontales.");
horizbar=new HorizBarre(tocreate,"preparebarre");
horizbar.addListener(new ChangeListener() {
@Override
public void changed(ChangeEvent event, Actor actor) {
Gdx.app.debug("Barre", "Element changé");
map.tempclear();
map.fillempty(60);
menu.unSelect();
}
});
table2 = new VerticalGroup();
table2.setPosition(AssetLoader.width, AssetLoader.height - 360);
table2.setPosition(AssetLoader.width, AssetLoader.height - 375);
table2.right();
table2.space(10f);
Gdx.app.debug(
@ -235,49 +237,21 @@ public class GameScreen implements Screen {
multiplexer = new InputMultiplexer();
processors = new Array<InputProcessor>();
stage = new Stage(AssetLoader.viewport);
stage_menu = new Stage(AssetLoader.viewport);
stage_map = new Stage(AssetLoader.viewport);
stage_info = new Stage(AssetLoader.viewport);
stage_tooltip = new Stage(AssetLoader.viewport);
oldx = 0;
oldy = 0;
unroll = false;
Renderer = new GameRenderer(this);
Gdx.app.debug(getClass().getSimpleName(), "Mise en place du timer.");
ScrollTimer = new Timer();
ScrollTask = new TimerTask() {
@Override
public void run() {
Renderer.evolve();
}
};
ScrollTimer.scheduleAtFixedRate(ScrollTask, 0, 30);
Gdx.app.debug(getClass().getSimpleName(), "Création des barres");
tooltip = new TextArea("tooltip:x\r\n tooltip:y",
AssetLoader.Skin_level, "info_tooltip");
tooltip.setBounds(541, 27, 100, 50);
Barre = new ImageButton[tocreate.length];
int i = 0;
Gdx.app.debug(getClass().getSimpleName(), "Barre bas:" + Barre.length
+ " elements");
for (String tocreateitem : tocreate) {
Barre[i] = new ImageButton(AssetLoader.Skin_level, tocreateitem);
Barre[i].setName(tocreateitem);
Barre[i].addListener(new ClickListener() {
@Override
public void clicked(InputEvent event, float x, float y) {
Actor caller = event.getListenerActor();
Gdx.app.debug("Barre", "Selection dans la Barre bas:"
+ caller.getName());
preparebarre(caller, this.getTapCount());
}
});
Barre[i++].addListener(new Tooltip(tooltip,
AssetLoader.Tooltipmanager));
}
Barre2 = new ImageTextButton[Transmuter.Class.values().length];
Gdx.app.debug(getClass().getSimpleName(), "Menu:" + Barre2.length
+ " elements");
for (i = 0; i < Barre2.length; i++) {
for (int i = 0; i < Barre2.length; i++) {
Barre2[i] = new ImageTextButton(
AssetLoader.language.get(Transmuter.Class.values()[i]
.toString()), AssetLoader.Skin_level);
@ -293,35 +267,41 @@ public class GameScreen implements Screen {
}
});
}
Barre[15].setChecked(Gdx.graphics.isFullscreen());
Barre[16].setChecked(AssetLoader.intro.getVolume() > 0);
Barre[17].setChecked(AssetLoader.Tooltipmanager.enabled == true);
Gdx.app.debug(getClass().getSimpleName(),
"Création de la barre de gestion du haut");
cycle = new ImageTextButton(String.valueOf(level.Cycle),
AssetLoader.Skin_level, "cycle2");
cycle.setVisible(level.aWorld>=1);
cycle.setPosition(10, AssetLoader.height - 74);
temp = new ImageTextButton(String.valueOf(level.Temp),
AssetLoader.Skin_level, "temp2");
temp.setVisible(level.aWorld>=2);
temp.setPosition(210, AssetLoader.height - 74);
nrj = new ImageTextButton(String.valueOf(level.Nrj),
AssetLoader.Skin_level, "nrj2");
nrj.setPosition(410, AssetLoader.height - 74);
rayon = new ImageTextButton(String.valueOf(level.Rayon),
AssetLoader.Skin_level, "rayon2");
rayon.setPosition(610, AssetLoader.height - 74);
rayon.setVisible(level.aWorld>=3);
rayon.setPosition(410, AssetLoader.height - 74);
nrj = new ImageTextButton(String.valueOf(level.Nrj),
AssetLoader.Skin_level, "nrj2");
nrj.setVisible(level.aWorld>=4);
nrj.setPosition(610, AssetLoader.height - 74);
tech = new ImageTextButton(String.valueOf(level.Tech),
AssetLoader.Skin_level, "tech2");
tech.setPosition(1345, AssetLoader.height - 74);
tech.setVisible(level.Tech==1);
cout = new ImageTextButton(String.valueOf(level.Cout),
AssetLoader.Skin_level, "cout2");
cout.setVisible(level.Cout>0);
cout.setPosition(1445, AssetLoader.height - 74);
research = new ImageTextButton(String.valueOf(0),
AssetLoader.Skin_level, "research2");
research.setPosition(1545, AssetLoader.height - 74);
research.setVisible(level.Special || level.aWorld>0);
objectives = new Objectives();
objectives.setVictory(level.Victory);
objectives.setPosition(890, AssetLoader.height - 95);
objectives.setVisible(level.Cout>0);
buttonlevel = new ButtonLevel(level, true, 1.0f);
buttonlevel.setPosition(1760, AssetLoader.height - 125);
buttonlevel.addListener(new ClickListener() {
@ -383,6 +363,15 @@ public class GameScreen implements Screen {
"Description Description Description Description Description Description Description Description Description Description Description Description Description Description Description Description Description Description Description Description Description Description Description Description Description Description Description Description Description Description Description Description",
AssetLoader.Skin_level, "info_desc");
info_desc.setBounds(1220, AssetLoader.height - 965, 575, 150);
info_up=new ImageButton(AssetLoader.Skin_level,"evolution");
info_up.setPosition(1375, AssetLoader.height - 720);
info_up.addListener(new ClickListener() {
@Override
public void clicked(InputEvent event, float x, float y) {
if (menu.getTransmuter()!=null && menu.getTransmuter().isUpgradable())
menu.getTransmuter().Upgrade();
}
});
dialog = new WarnDialog(AssetLoader.Skin_ui);
Gdx.app.debug(getClass().getSimpleName(), "Création d'une tilemap");
map = new TouchMaptiles(level, 128, 128);
@ -459,89 +448,75 @@ public class GameScreen implements Screen {
});
Gdx.app.debug(getClass().getSimpleName(), "Création du menu");
nextpage=new ImageButton(AssetLoader.Skin_level,"extend");
nextpage.setPosition(1860, AssetLoader.height - 350);
nextpage.setPosition(1850, AssetLoader.height - 370);
nextpage.addListener(new ClickListener() {
@Override
public void clicked(InputEvent event, float x, float y) {
if (!nextpage.isDisabled()) {
menu.NextPage();
Gdx.app.debug("menu", "Page suivante:"+menu.getPage());
map.tempclear();
map.fillempty(53);
selected = null;
hideInfo();
nextpage.setDisabled(menu.isNextEmpty());
previouspage.setDisabled(menu.isPreviousEmpty());
}
}
});
previouspage=new ImageButton(AssetLoader.Skin_level,"extend2");
previouspage.setPosition(1830, AssetLoader.height - 350);
previouspage.setPosition(1800, AssetLoader.height - 370);
previouspage.addListener(new ClickListener() {
@Override
public void clicked(InputEvent event, float x, float y) {
if (!previouspage.isDisabled()) {
menu.PreviousPage();
Gdx.app.debug("menu", "Page précédente:"+menu.getPage());
map.tempclear();
map.fillempty(53);
selected = null;
hideInfo();
}
});
menu = new Menu(level);
map.addListener(new ClickListener() {
@Override
public void clicked(InputEvent event, float x, float y) {
mapexit = true;
Vector2 coords = menu.screentoworld(x, y);
MapProperties tile = menu.getMenubyTile((int) coords.x,
(int) coords.y);
if (tile != null && tile.containsKey("name")) {
menu.EraseSurtile();
map.tempclear();
if (menuactor == null)
menuactor = new Actor();
map.fillempty(60);
selected = menuactor;
if (tile.get("type").toString().startsWith("transmuter")) {
if (tile.containsKey("movetox")) {
coords.x += (Integer) tile.get("movetox");
coords.y += (Integer) tile.get("movetoy");
}
MapProperties tilenew = menu.getMenubyTile(
(int) coords.x, (int) coords.y);
selected_transmuter = (Transmuter) ((Transmuter) tilenew
.get("transmuter")).clone();
if (selected_transmuter != null) {
selected.setName("transmuter");
showInfo(selected_transmuter);
menu.setSurtile((int) coords.x,
(int) coords.y, selected_transmuter);
Gdx.app.debug("menu", "Choix transmuter:"
+ selected_transmuter.getName());
}
} else
selected.setName(tile.get("name").toString());
Vector2 coords2 = menu.worldtoscreen((int) coords.x,
(int) coords.y);
Gdx.app.debug(
"menu",
"Coordonnées:" + x + "x" + y + " Menu:" + coords.x
+ "," + coords.y + " Ecran :" + coords2.x
+ "x" + coords2.y + " type:"
+ tile.get("type"));
menuactor.setBounds(coords2.x, coords2.y, 60, 60);
nextpage.setDisabled(menu.isNextEmpty());
previouspage.setDisabled(menu.isPreviousEmpty());
}
}
});
menu = new Menu(level);
menu.setBounds(1531f, AssetLoader.height-780, 264, 480);
menu.addListener(new ChangeListener() {
@Override
public void changed(ChangeEvent event, Actor actor) {
Gdx.app.debug("Menu", "Element changé");
map.tempclear();
map.fillempty(60);
if (menu.getTransmuter() != null)
showInfo(menu.getTransmuter());
else
hideInfo();
horizbar.unSelect();
}
});
}
public String getselected() {
if (menu.getSelection()==null)
if (horizbar.getSelection()==null)
return null;
else
return horizbar.getSelection();
else
return menu.getSelection();
}
boolean event_coordination(float x, float y, int button, calling call,
String[] exec) {
if (selected != null) {
if (Arrays.asList(exec).contains(selected.getName())) {
Gdx.app.debug("menu", "xy"+x+","+y);
if (getselected() != null) {
if (Arrays.asList(exec).contains(getselected())) {
Vector2 coords = map.screentoworld(x, y);
if (level.Grid.GetXY(coords.x, coords.y) != null) {
mapexit = false;
if (call != calling.mouseover)
Gdx.app.debug("evenement", "mode:" + call + " outil:"
+ selected.getName() + " X: " + coords.x
+ getselected() + " X: " + coords.x
+ " Y: " + coords.y + " button:" + button);
Method method;
try {
@ -551,7 +526,7 @@ public class GameScreen implements Screen {
int.class, int.class, boolean.class, int.class,
calling.class };
method = base.getDeclaredMethod(
"map_" + selected.getName(), params);
"map_" + getselected(), params);
method.invoke(this, (float) x, (float) y,
(int) coords.x, (int) coords.y, true,
(int) button, (calling) call);
@ -575,45 +550,45 @@ public class GameScreen implements Screen {
int button, calling call) {
if (call == calling.taptap && button == 0
|| (call == calling.mouseclick && button == 1)) {
Angular angle = selected_transmuter.getRotation();
Angular angle = menu.getTransmuter().getRotation();
if (angle == Angular.A00)
selected_transmuter.setRotation(Angular.A90);
menu.getTransmuter().setRotation(Angular.A90);
else if (angle == Angular.A90)
selected_transmuter.setRotation(Angular.A180);
menu.getTransmuter().setRotation(Angular.A180);
else if (angle == Angular.A180)
selected_transmuter.setRotation(Angular.A270);
menu.getTransmuter().setRotation(Angular.A270);
else if (angle == Angular.A270)
selected_transmuter.setRotation(Angular.A00);
menu.getTransmuter().setRotation(Angular.A00);
}
map.tempclear();
boolean positionisgood = true;
int color = 0;
OrderedMap<Vector2, Integer> tiles = selected_transmuter
OrderedMap<Vector2, Integer> tiles = menu.getTransmuter()
.getTilesidrotated();
Entries<Vector2, Integer> iterator = tiles.iterator();
while (iterator.hasNext()) {
Entry<Vector2, Integer> all = iterator.next();
color = 63;
int index = tiles.keys().toArray().indexOf(all.key, false);
if (((selected_transmuter.getTilestype(index) == CaseType.Nimporte)
if ((( menu.getTransmuter().getTilestype(index) == CaseType.Nimporte)
|| (!level.Grid.getFiber(x + all.key.x, y + all.key.y)
&& !level.Grid.getCopper(x + all.key.x, y
+ all.key.y) && selected_transmuter
+ all.key.y) && menu.getTransmuter()
.getTilestype(index) == CaseType.Rien)
|| (level.Grid.getFiber(x + all.key.x, y + all.key.y)
&& level.Grid.getCopper(x + all.key.x, y
+ all.key.y) && selected_transmuter
+ all.key.y) && menu.getTransmuter()
.getTilestype(index) == CaseType.Tout)
|| (level.Grid.getCopper(x + all.key.x, y + all.key.y) && selected_transmuter
|| (level.Grid.getCopper(x + all.key.x, y + all.key.y) && menu.getTransmuter()
.getTilestype(index) == CaseType.Cuivre)
|| (level.Grid.getFiber(x + all.key.x, y + all.key.y) && selected_transmuter
|| (level.Grid.getFiber(x + all.key.x, y + all.key.y) && menu.getTransmuter()
.getTilestype(index) == CaseType.Fibre)
|| (level.Grid.getFiber(x + all.key.x, y + all.key.y)
&& !level.Grid.getCopper(x + all.key.x, y
+ all.key.y) && selected_transmuter
+ all.key.y) && menu.getTransmuter()
.getTilestype(index) == CaseType.Fibre_seul) || (level.Grid
.getCopper(x + all.key.x, y + all.key.y)
&& !level.Grid.getFiber(x + all.key.x, y + all.key.y) && selected_transmuter
&& !level.Grid.getFiber(x + all.key.x, y + all.key.y) && menu.getTransmuter()
.getTilestype(index) == CaseType.Cuivre_seul))
&& (level.Grid.getTransmutercalc(x + all.key.x, y
+ all.key.y) == 0))
@ -621,10 +596,10 @@ public class GameScreen implements Screen {
else
positionisgood = false;
map.tempdraw(x + all.key.x, y + all.key.y, all.value,
selected_transmuter.getRotation().ordinal(), color);
menu.getTransmuter().getRotation().ordinal(), color);
}
if ((call == calling.longpress && button == 0) && positionisgood) {
level.Grid.GetXY(x, y).Transmuter = (Transmuter) selected_transmuter
level.Grid.GetXY(x, y).Transmuter = (Transmuter) menu.getTransmuter()
.clone();
if (alone)
level.Grid.tiling_transmuter();
@ -803,7 +778,7 @@ public class GameScreen implements Screen {
if (Preference.prefs.getBoolean("Refresh"))
fpsLabel.setText(Gdx.graphics.getFramesPerSecond() + "FPS");
Renderer.render(delta, runTime, 0);
stage_menu.draw();
stage_map.draw();
Renderer.render(delta, runTime, 1);
stage.draw();
if (unroll)
@ -828,8 +803,6 @@ public class GameScreen implements Screen {
Gdx.app.log("*****", "Affichage du niveau.");
for (int i = 0; i < Barre2.length; i++)
table2.addActor(Barre2[i]);
for (int i = 0; i < Barre.length; i++)
table.addActor(Barre[i]);
stage_info.addActor(info_tech);
stage_info.addActor(info_research);
stage_info.addActor(info_activation);
@ -843,9 +816,11 @@ public class GameScreen implements Screen {
stage_info.addActor(info_up_cycleval);
stage_info.addActor(info_nom);
stage_info.addActor(info_cout);
stage_info.addActor(info_up);
stage_info.addActor(info_desc);
stage_menu.addActor(map);
// stage_tooltip.addActor(tooltip);
stage_map.addActor(map);
//stage_tooltip.addActor(tooltip);
stage.addActor(horizbar);
stage.addActor(nextpage);
stage.addActor(previouspage);
stage.addActor(objectives);
@ -857,67 +832,72 @@ public class GameScreen implements Screen {
stage.addActor(temp);
stage.addActor(cycle);
stage.addActor(table2);
stage.addActor(table);
stage.addActor(tech);
stage.addActor(cout);
stage.addActor(research);
stage.addActor(menu);
// gesturedetector=new GestureDetector(null);
// processors.add(gesturedetector);
//processors.add(stage_tooltip);
processors.add(stage_info);
processors.add(stage);
processors.add(stage_menu);
processors.add(stage_map);
multiplexer.setProcessors(processors);
Gdx.input.setInputProcessor(multiplexer);
preparemenu(0);
}
public void preparebarre(Actor caller, int count) {
public void preparebarre(String caller, int count) {
map.fillempty(53);
map.tempclear();
menu.EraseSurtile();
hideInfo();
if (caller.getName() == "run") {
} else if (caller.getName() == "stop") {
} else if (caller.getName() == "speed") {
} else if (caller.getName() == "move") {
selected = caller;
if (caller == "run") {
Gdx.app.debug("pop", menu.getX()+","+menu.getY()+","+menu.getWidth()+","+menu.getHeight());
menu.setWidth(1920);
menu.setHeight(1080);
} else if (caller == "stop") {
map.setBounds(500, 200, 500, 400);
} else if (caller == "speed") {
} else if (caller == "move") {
//selected = caller;
if (count >= 2)
map.initzoom();
} else if (caller.getName() == "zoomp") {
selected = caller;
} else if (caller == "zoomp") {
//selected = caller;
if (count >= 2)
map.initzoom();
} else if (caller.getName() == "zoomm") {
selected = caller;
} else if (caller == "zoomm") {
//selected = caller;
if (count >= 2)
map.initzoom();
} else if (caller.getName() == "infos") {
selected = caller;
} else if (caller == "infos") {
//selected = caller;
if (count >= 2)
map.initzoom();
} else if (caller.getName() == "raz") {
} else if (caller == "raz") {
winOptions.setVisible(false);
winSave.setVisible(!winSave.isVisible());
if (winSave.isVisible())
readsaved();
} else if (caller.getName() == "save") {
} else if (caller == "save") {
Gdx.app.log("save", "Ok");
Gdx.app.debug("Barre", "Sauvegarde de la grille.");
Gdx.app.debug("Barre", AssetLoader.Datahandler.user().toString());
AssetLoader.Datahandler.user().setGrid(0, level.id, level.Grid);
readsaved();
} else if (caller.getName() == "levels") {
} else if (caller == "levels") {
Gdx.app.debug("Barre", "Affichage des niveaux.");
AssetLoader.Datahandler.user().setGrid(0, level.id, "LAST",
this.level.Grid);
((Game) Gdx.app.getApplicationListener())
.setScreen(new LevelScreen(level.aWorld));
} else if (caller.getName() == "tree") {
} else if (caller.getName() == "exits") {
} else if (caller == "tree") {
} else if (caller == "exits") {
AssetLoader.Datahandler.user().setGrid(0, level.id, "LAST",
this.level.Grid);
Gdx.app.exit();
} else if (caller.getName() == "screen") {
} else if (caller == "screen") {
DisplayMode currentMode = Gdx.graphics.getDesktopDisplayMode();
if (Gdx.graphics.isFullscreen()) {
Gdx.app.debug("Barre", "vers fenetre.");
@ -928,8 +908,8 @@ public class GameScreen implements Screen {
Gdx.graphics.setDisplayMode(currentMode.width,
currentMode.height, true);
}
((ImageButton) caller).setChecked(Gdx.graphics.isFullscreen());
} else if (caller.getName() == "sound") {
//((ImageButton) caller).setChecked(Gdx.graphics.isFullscreen());
} else if (caller == "sound") {
if (AssetLoader.intro.getVolume() > 0) {
Gdx.app.debug("Barre", "arret son.");
AssetLoader.intro.setVolume(0f);
@ -937,9 +917,9 @@ public class GameScreen implements Screen {
Gdx.app.debug("Barre", "marche son.");
AssetLoader.intro.setVolume(1f);
}
((ImageButton) caller)
.setChecked(AssetLoader.intro.getVolume() > 0);
} else if (caller.getName() == "tuto") {
//((ImageButton) caller)
//.setChecked(AssetLoader.intro.getVolume() > 0);
} else if (caller == "tuto") {
if (AssetLoader.Tooltipmanager.enabled) {
Gdx.app.debug("Barre", "arret tuto.");
AssetLoader.Tooltipmanager.enabled = false;
@ -947,14 +927,14 @@ public class GameScreen implements Screen {
Gdx.app.debug("Barre", "marche tuto.");
AssetLoader.Tooltipmanager.enabled = true;
}
((ImageButton) caller)
.setChecked(AssetLoader.Tooltipmanager.enabled);
} else if (caller.getName() == "settings") {
//((ImageButton) caller)
//.setChecked(AssetLoader.Tooltipmanager.enabled);
} else if (caller == "settings") {
winOptions.setVisible(!winOptions.isVisible());
winSave.setVisible(false);
if (winOptions.isVisible())
readpref();
} else if (caller.getName() == "flag") {
} else if (caller == "flag") {
if (AssetLoader.language.getLocale().getDisplayName()
.contains("français")) {
Gdx.app.debug("Barre", "Langue USA");
@ -963,9 +943,9 @@ public class GameScreen implements Screen {
Gdx.app.debug("Barre", "Langue FR");
AssetLoader.language = AssetLoader.french;
}
((ImageButton) caller).setChecked(AssetLoader.language.getLocale()
.getDisplayName().contains("français"));
} else if (caller.getName() == "stat") {
//((ImageButton) caller).setChecked(AssetLoader.language.getLocale()
// .getDisplayName().contains("français"));
} else if (caller == "stat") {
}
}
@ -973,11 +953,11 @@ public class GameScreen implements Screen {
checkMenu(menuitem, true);
map.tempclear();
map.fillempty(53);
selected = null;
menu.EraseSurtile();
horizbar.unSelect();
hideInfo();
menu.setType(menuitem);
menu.setPage(0);
menu.setPageType(0,menuitem);
nextpage.setDisabled(menu.isNextEmpty());
previouspage.setDisabled(true);
}
public void showInfo(Transmuter transmuter) {