feat: réécriture de la classe worlds et ajout de fonctions ajout du mode édition dans levelscreen

This commit is contained in:
Nicolas Hordé 2016-06-19 16:32:52 +02:00
parent d64bcbdfd2
commit ed1c9ee928
9 changed files with 323 additions and 180 deletions

View File

@ -28,51 +28,51 @@ public class IconValue extends ImageTextButton{
{ {
switch(this.icon) { switch(this.icon) {
case tech: case tech:
this.setText(String.valueOf(worlds.getInformations().Tech)); this.setText(String.valueOf(worlds.getLevelData().Tech));
this.setVisible(worlds.getInformations().Tech>=1 || worlds.isDebug()); this.setVisible(worlds.getLevelData().Tech>=1 || worlds.isDebug());
break; break;
case cout: case cout:
worlds.getInformations().Cout=worlds.getInformations().Cout_orig-worlds.getInformations().Cout_copperfiber-worlds.getInformations().Cout_transmuter; worlds.getLevelData().Cout=worlds.getLevelData().Cout_orig-worlds.getLevelData().Cout_copperfiber-worlds.getLevelData().Cout_transmuter;
this.setText(String.valueOf(worlds.getInformations().Cout)); this.setText(String.valueOf(worlds.getLevelData().Cout));
if (worlds.getInformations().Cout>0.25*worlds.getInformations().Cout_orig) if (worlds.getLevelData().Cout>0.25*worlds.getLevelData().Cout_orig)
this.setColor(1f, 1f, 1f, 1f); this.setColor(1f, 1f, 1f, 1f);
else if (worlds.getInformations().Cout>0) else if (worlds.getLevelData().Cout>0)
this.setColor(1f, 0.5f, 0.5f, 1f); this.setColor(1f, 0.5f, 0.5f, 1f);
else else
this.setColor(1f, 0, 0, 1f); this.setColor(1f, 0, 0, 1f);
this.setVisible(worlds.getInformations().Cout_orig>0 || worlds.isDebug()); this.setVisible(worlds.getLevelData().Cout_orig>0 || worlds.isDebug());
break; break;
case research: case research:
this.setText(String.valueOf(worlds.ReadResearch())); this.setText(String.valueOf(worlds.ReadResearch()));
this.setVisible((worlds.getInformations().Tech>=1 && worlds.ReadResearch()>0) || worlds.isDebug()); this.setVisible((worlds.getLevelData().Tech>=1 && worlds.ReadResearch()>0) || worlds.isDebug());
break; break;
case cycle: case cycle:
this.setVisible(worlds.getWorld()>=1 || worlds.isDebug()); this.setVisible(worlds.getWorld()>=1 || worlds.isDebug());
if (showmaximum) if (showmaximum)
this.setText(String.valueOf(worlds.getInformations().Cycle)+"/"+String.valueOf(worlds.getInformations().Maxcycle)); this.setText(String.valueOf(worlds.getLevelData().Cycle)+"/"+String.valueOf(worlds.getLevelData().Maxcycle));
else else
this.setText(String.valueOf(worlds.getInformations().Cycle)); this.setText(String.valueOf(worlds.getLevelData().Cycle));
break; break;
case temp: case temp:
this.setVisible(worlds.getWorld()>=2 || worlds.isDebug()); this.setVisible(worlds.getWorld()>=2 || worlds.isDebug());
if (showmaximum) if (showmaximum)
this.setText(String.valueOf(worlds.getInformations().Temp)+"/"+String.valueOf(worlds.getInformations().Maxtemp)); this.setText(String.valueOf(worlds.getLevelData().Temp)+"/"+String.valueOf(worlds.getLevelData().Maxtemp));
else else
this.setText(String.valueOf(worlds.getInformations().Temp)); this.setText(String.valueOf(worlds.getLevelData().Temp));
break; break;
case rayon: case rayon:
this.setVisible(worlds.getWorld()>=3 || worlds.isDebug()); this.setVisible(worlds.getWorld()>=3 || worlds.isDebug());
if (showmaximum) if (showmaximum)
this.setText(String.valueOf(worlds.getInformations().Rayon)+"/"+String.valueOf(worlds.getInformations().Maxrayon)); this.setText(String.valueOf(worlds.getLevelData().Rayon)+"/"+String.valueOf(worlds.getLevelData().Maxrayon));
else else
this.setText(String.valueOf(worlds.getInformations().Rayon)); this.setText(String.valueOf(worlds.getLevelData().Rayon));
break; break;
case nrj: case nrj:
this.setVisible(worlds.getWorld()>=4 || worlds.isDebug()); this.setVisible(worlds.getWorld()>=4 || worlds.isDebug());
if (showmaximum) if (showmaximum)
this.setText(String.valueOf(worlds.getInformations().Nrj)+"/"+String.valueOf(worlds.getInformations().Maxnrj)); this.setText(String.valueOf(worlds.getLevelData().Nrj)+"/"+String.valueOf(worlds.getLevelData().Maxnrj));
else else
this.setText(String.valueOf(worlds.getInformations().Nrj)); this.setText(String.valueOf(worlds.getLevelData().Nrj));
break; break;
} }

View File

@ -231,18 +231,18 @@ public class Menu extends Actor {
this.setMenuTile(0, 4, 87, "gold_pen",0); this.setMenuTile(0, 4, 87, "gold_pen",0);
this.setMenuTile(1, 4, 88, "lock_pen",0); this.setMenuTile(1, 4, 88, "lock_pen",0);
} }
if (worlds.getInformations().Cout_orig>=0 || worlds.isDebug()) if (worlds.getLevelData().Cout_orig>=0 || worlds.isDebug())
{ {
this.setMenuTile(0, 7, 71, "copper_pen",0); this.setMenuTile(0, 7, 71, "copper_pen",0);
this.setMenuTile(1, 7, 72, "copper_brush",0); this.setMenuTile(1, 7, 72, "copper_brush",0);
this.setMenuTile(2, 7, 73, "copper_eraser",0); this.setMenuTile(2, 7, 73, "copper_eraser",0);
this.setMenuTile(3, 3, 79, "cleaner",0); this.setMenuTile(3, 3, 79, "cleaner",0);
} }
if (worlds.getInformations().Tech>=0 || worlds.isDebug()) if (worlds.getLevelData().Tech>=0 || worlds.isDebug())
{ {
this.setMenuTile(0, 5, 77, "transmuter_eraser",0); this.setMenuTile(0, 5, 77, "transmuter_eraser",0);
} }
if (worlds.getInformations().Tech>=2 || worlds.isDebug()) if (worlds.getLevelData().Tech>=2 || worlds.isDebug())
{ {
this.setMenuTile(1, 5, 70, "blank",0); this.setMenuTile(1, 5, 70, "blank",0);
this.setMenuTile(0, 6, 74, "fiber_pen",0); this.setMenuTile(0, 6, 74, "fiber_pen",0);
@ -356,7 +356,7 @@ public class Menu extends Actor {
if (transmuter != null) { if (transmuter != null) {
int type=transmuter.getaClass().ordinal(); int type=transmuter.getaClass().ordinal();
Gdx.app.debug("wirechem-Menu", "Transmuter find:"+ transmuter.getName() + " Angle:" + Angle + " coords" + x + "," + y+" page:"+page+" type:"+type); Gdx.app.debug("wirechem-Menu", "Transmuter find:"+ transmuter.getName() + " Angle:" + Angle + " coords" + x + "," + y+" page:"+page+" type:"+type);
if (transmuter.getTechnology()<=worlds.getInformations().Tech || worlds.isDebug()) { if (transmuter.getTechnology()<=worlds.getLevelData().Tech || worlds.isDebug()) {
Gdx.app.debug("wirechem-Menu", "Autorisé par le niveau"); Gdx.app.debug("wirechem-Menu", "Autorisé par le niveau");
if (!transmuter.isShowed() && transmuter.isUpgraded() && !worlds.isDebug()) if (!transmuter.isShowed() && transmuter.isUpgraded() && !worlds.isDebug())
layer = ((TiledMapTileLayer) map[page][type].getLayers().get(2)); layer = ((TiledMapTileLayer) map[page][type].getLayers().get(2));

View File

@ -51,8 +51,8 @@ public class Objectives extends Actor {
} }
else else
{ {
thevictory=worlds.getInformations().Victory_orig; thevictory=worlds.getLevelData().Victory_orig;
currentvictory=worlds.getInformations().Victory; currentvictory=worlds.getLevelData().Victory;
} }
for (int i=0;i<thevictory.length;i++) { for (int i=0;i<thevictory.length;i++) {
if (thevictory[i] != 0) { if (thevictory[i] != 0) {

View File

@ -35,7 +35,7 @@ public class VertiBarre extends Actor {
Gdx.app.debug("wirechem-VertiBarre", "Menu:" + Barre.length+ " elements"); Gdx.app.debug("wirechem-VertiBarre", "Menu:" + Barre.length+ " elements");
for (int i = 0; i < Barre.length; i++) for (int i = 0; i < Barre.length; i++)
{ {
if ((Transmuter.Class.values()[i]!=Transmuter.Class.Scenario && (worlds.getInformations().Tech>=0 || Transmuter.Class.values()[i]==Transmuter.Class.Structure)) || worlds.isDebug()) if ((Transmuter.Class.values()[i]!=Transmuter.Class.Scenario && (worlds.getLevelData().Tech>=0 || Transmuter.Class.values()[i]==Transmuter.Class.Structure)) || worlds.isDebug())
{ {
Barre[i] = new ImageTextButton(Transmuter.Class.values()[i].toString(), AssetLoader.Skin_level); Barre[i] = new ImageTextButton(Transmuter.Class.values()[i].toString(), AssetLoader.Skin_level);
table.addActor(Barre[i]); table.addActor(Barre[i]);

View File

@ -19,6 +19,7 @@ public class Worlds extends Actor {
private State state; private State state;
private boolean Debug; private boolean Debug;
private int research; private int research;
private Level lastchange;
public enum State {pause,simulating,notloaded,databasefailed}; public enum State {pause,simulating,notloaded,databasefailed};
@ -43,7 +44,7 @@ public class Worlds extends Actor {
this.ReadTransmuters(); this.ReadTransmuters();
if (state==State.notloaded) if (state==State.notloaded)
create(name); create(name);
onchanged(); onchanged(null);
} }
public void ModResearch(int addsub) { public void ModResearch(int addsub) {
@ -79,13 +80,16 @@ public class Worlds extends Actor {
public void ReadTransmuters() { public void ReadTransmuters() {
Transmuters=AssetLoader.Datahandler.user().getTransmuters(0); Transmuters=AssetLoader.Datahandler.user().getTransmuters(0);
//String test=Transmuters.get(1).getInformations();
if (Transmuters==null) if (Transmuters==null)
state=State.notloaded; state=State.notloaded;
else else
state=State.pause; state=State.pause;
} }
public Array<Transmuter> getTransmuters() {
return Transmuters;
}
public Array<String> ViewGrids() { public Array<String> ViewGrids() {
if (usedlevel!=null) if (usedlevel!=null)
return AssetLoader.Datahandler.user().getGrids(0,usedlevel.id); return AssetLoader.Datahandler.user().getGrids(0,usedlevel.id);
@ -114,24 +118,25 @@ public class Worlds extends Actor {
} }
public void Forcereload() { public void Forcereload() {
onchanged(); onchanged(null);
} }
public void onchanged() { public void onchanged(Level change) {
ChangeEvent event=new ChangeEvent(); ChangeEvent event=new ChangeEvent();
event.setTarget(this); event.setTarget(this);
event.setListenerActor(this); event.setListenerActor(this);
event.setStage(this.getStage()); event.setStage(this.getStage());
lastchange=change;
if (event.getStage()!=null) if (event.getStage()!=null)
this.fire(event); this.fire(event);
} }
public Array<Level> getLevels() { public Array<Level> getLevels(int world) {
Array<Level> tempworld=new Array<Level>(); Array<Level> tempworld=new Array<Level>();
if (state!=State.notloaded && this.levels!=null) if (state!=State.notloaded && this.levels!=null)
{ {
for(Level level:levels) for(Level level:levels)
if (level!=null && level.aWorld==usedworld) if (level!=null && level.aWorld==world)
{ {
if (level.aLevel==0) if (level.aLevel==0)
level.Locked=false; level.Locked=false;
@ -143,6 +148,14 @@ public class Worlds extends Actor {
return null; return null;
} }
public Array<Level> getLevels() {
return getLevels(this.usedworld);
}
public Array<Level> getAllLevels() {
return levels;
}
public void updateUnlockLevels() { public void updateUnlockLevels() {
if (levels!=null) if (levels!=null)
for(Level level:levels) for(Level level:levels)
@ -180,20 +193,25 @@ public class Worlds extends Actor {
usedlevel.Grid_orig = (Grid)usedlevel.Grid.clone(); usedlevel.Grid_orig = (Grid)usedlevel.Grid.clone();
} }
public void setLevel(int alevel) { public Level findLevel(int levelid) {
if (state!=State.notloaded) if (state!=State.notloaded)
if (usedworld>=0) { if (usedworld>=0) {
Array<Level> tempworld=getLevels(); Array<Level> tempworld=getLevels();
for(Level level:tempworld) for(Level level:tempworld)
if (level.aLevel==alevel) if (level.aLevel==levelid)
{ return level;
usedlevel=level; }
return; return null;
}
}
} }
public Level getInformations() { public void setLevel(int levelid) {
Level level=findLevel(levelid);
if (level!=null)
usedlevel=level;
return;
}
public Level getLevelData() {
return usedlevel; return usedlevel;
} }
@ -205,22 +223,49 @@ public class Worlds extends Actor {
} }
public void delLevel() { public void delLevel() {
usedlevel=null; delLevel(this.usedlevel.aLevel);
}
public void delLevel(int levelid) {
Level level=findLevel(levelid);
if (level!=null) {
levels.removeValue(level, false);
if (this.usedlevel!=null && this.usedlevel.aLevel==levelid)
this.usedlevel=null;
onchanged(level);
this.showlevels();
}
}
public Level getChange() {
return lastchange;
}
public void addLevel(Level level) {
levels.add(level);
this.showlevels();
onchanged(level);
}
public void showlevels() {
Gdx.app.debug("wirechem-worlds","Affichage des niveaux:");
for(Level level: levels)
Gdx.app.debug("wirechem-GameScreen","Monde:"+level.aWorld+" Niveau:"+level.aLevel+" Nom:"+level.Name+" Debloque:"+level.Locked+" Special:"+level.Special+" id:"+level.id);
} }
public void setWorld(int world) { public void setWorld(int world) {
if (state!=State.notloaded) if (state!=State.notloaded)
if (world<getMaxWorlds()) { if (world<getMaxWorlds()) {
delLevel(); usedlevel=null;
usedworld=world; usedworld=world;
onchanged(); onchanged(null);
} }
} }
public void setMaxWorldLevel() { public void setMaxWorldLevel() {
usedworld=getMaxUnlockWorlds(); usedworld=getMaxUnlockWorlds();
usedlevel=getMaxUnlockLevel(); usedlevel=getMaxUnlockLevel();
onchanged(); onchanged(null);
} }
public boolean isFirstWorld() { public boolean isFirstWorld() {
@ -239,18 +284,18 @@ public class Worlds extends Actor {
public void NextWorld() { public void NextWorld() {
if (state!=State.notloaded) if (state!=State.notloaded)
if (usedworld<getMaxWorlds()) { if (usedworld<getMaxWorlds()) {
delLevel(); usedlevel=null;
usedworld++; usedworld++;
onchanged(); onchanged(null);
} }
} }
public void PreviousWorld() { public void PreviousWorld() {
if (state!=State.notloaded) if (state!=State.notloaded)
if (usedworld>0) { if (usedworld>0) {
delLevel(); usedlevel=null;
usedworld--; usedworld--;
onchanged(); onchanged(null);
} }
} }
@ -265,6 +310,10 @@ public class Worlds extends Actor {
AssetLoader.Datahandler.user().setLevelunlock(0, usedlevel.id); AssetLoader.Datahandler.user().setLevelunlock(0, usedlevel.id);
} }
public void unLockLevel(int levelid) {
AssetLoader.Datahandler.user().setLevelunlock(0, levelid);
}
public void set(String campaign) { public void set(String campaign) {
Gdx.app.log("wirechem-Worlds", "***** Définition de la compagne "+campaign); Gdx.app.log("wirechem-Worlds", "***** Définition de la compagne "+campaign);
Preference.prefs.putString("world", campaign); Preference.prefs.putString("world", campaign);
@ -315,6 +364,33 @@ public class Worlds extends Actor {
return max; return max;
} }
public int getFreeLevel() {
return getFreeLevel(usedworld);
}
public int getFreeLevel(int world) {
int max = getMaxLevel(world);
if (max==0)
return 0;
int free = 0;
for (;free<=max;free++)
if (findLevel(free)==null)
return free;
return free;
}
public int getMaxLevel() {
return getMaxLevel(usedworld);
}
public int getMaxLevel(int world) {
int max = 0;
for (Level level : levels)
if (level != null && level.aWorld == world && level.aLevel>max)
max = level.aLevel;
return max;
}
public int getMaxUnlockWorlds() { public int getMaxUnlockWorlds() {
int maxworld=0; int maxworld=0;
if (levels!=null) if (levels!=null)

View File

@ -33,7 +33,7 @@ public class GameRenderer {
} else if (layer == 1) { } else if (layer == 1) {
batcher.begin(); batcher.begin();
batcher.setColor(0.25f, 0.25f, 0.25f, 1f); batcher.setColor(0.25f, 0.25f, 0.25f, 1f);
if (GameScreen.worlds.getInformations().Cout>0 || GameScreen.worlds.getInformations().Tech>=1 || GameScreen.worlds.isDebug()) { if (GameScreen.worlds.getLevelData().Cout>0 || GameScreen.worlds.getLevelData().Tech>=1 || GameScreen.worlds.isDebug()) {
batcher.draw(AssetLoader.Atlas_level.findRegion("barrehaut"), 0.0f, AssetLoader.height - 198.0f, 1920.0f, 200.0f); batcher.draw(AssetLoader.Atlas_level.findRegion("barrehaut"), 0.0f, AssetLoader.height - 198.0f, 1920.0f, 200.0f);
batcher.draw(AssetLoader.Atlas_level.findRegion("barrecentre"), 1480f, AssetLoader.height - 785.0f, 590f, 530.0f); batcher.draw(AssetLoader.Atlas_level.findRegion("barrecentre"), 1480f, AssetLoader.height - 785.0f, 590f, 530.0f);
} }

View File

@ -8,7 +8,9 @@ import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.badlogic.gdx.graphics.g2d.TextureRegion; import com.badlogic.gdx.graphics.g2d.TextureRegion;
import com.badlogic.gdx.graphics.glutils.ShapeRenderer; import com.badlogic.gdx.graphics.glutils.ShapeRenderer;
import com.badlogic.gdx.graphics.glutils.ShapeRenderer.ShapeType; import com.badlogic.gdx.graphics.glutils.ShapeRenderer.ShapeType;
import com.badlogic.gdx.utils.Array;
import fr.evolving.UI.ButtonLevel;
import fr.evolving.assets.AssetLoader; import fr.evolving.assets.AssetLoader;
import fr.evolving.effects.Laser; import fr.evolving.effects.Laser;
import fr.evolving.screens.LevelScreen; import fr.evolving.screens.LevelScreen;
@ -121,56 +123,18 @@ public class LevelRenderer {
shapeRenderer.rect(1470, 10, 440, AssetLoader.height - 20); shapeRenderer.rect(1470, 10, 440, AssetLoader.height - 20);
shapeRenderer.end(); shapeRenderer.end();
if (LevelScreen.buttonLevels != null) if (LevelScreen.buttonLevels != null)
for (int i = 0; i < LevelScreen.buttonLevels.length; i++) { for (int i=0;i<LevelScreen.buttonLevels.size;i++)
if (LevelScreen.buttonLevels[i] != null) { {
for (int[] item : LevelScreen.buttonLevels[i].level.Link) { ButtonLevel button1=LevelScreen.buttonLevels.get(i);
int found = -1; for (int[] item : button1.level.Link)
for (int j = 0; j < LevelScreen.buttonLevels.length; j++) { for (ButtonLevel button2 : LevelScreen.buttonLevels)
if ((item.length == 2) if ((item.length == 2) && (button2.level.aWorld == item[0]) && (button2.level.aLevel == item[1]))
&& (LevelScreen.buttonLevels[j] != null)
&& (LevelScreen.buttonLevels[j].level.aWorld == item[0])
&& (LevelScreen.buttonLevels[j].level.aLevel == item[1])) {
found = j;
break;
}
}
if (found != -1) {
if (!LevelScreen.worlds.isDebug()) if (!LevelScreen.worlds.isDebug())
Laser.draw( Laser.draw(batcher,button1.level.X,button1.level.Y* AssetLoader.ratio,button2.level.X,button2.level.Y* AssetLoader.ratio,10,0.5f,!button2.level.Locked, button1.getLevelcolor(),button2.getLevelcolor());
batcher,
LevelScreen.buttonLevels[i].level.X,
LevelScreen.buttonLevels[i].level.Y
* AssetLoader.ratio,
LevelScreen.buttonLevels[found].level.X,
LevelScreen.buttonLevels[found].level.Y
* AssetLoader.ratio,
10,
0.5f,
!LevelScreen.buttonLevels[found].level.Locked,
LevelScreen.buttonLevels[i]
.getLevelcolor(),
LevelScreen.buttonLevels[found]
.getLevelcolor());
else else
Laser.drawnotsoold( Laser.drawnotsoold(shapeRenderer,button1.level.X,button1.level.Y* AssetLoader.ratio,button2.level.X,button2.level.Y* AssetLoader.ratio,10,0.5f,!button2.level.Locked, button1.getLevelcolor(),button2.getLevelcolor());
shapeRenderer,
LevelScreen.buttonLevels[i].level.X,
LevelScreen.buttonLevels[i].level.Y
* AssetLoader.ratio,
LevelScreen.buttonLevels[found].level.X,
LevelScreen.buttonLevels[found].level.Y
* AssetLoader.ratio,
10,
0.5f,
!LevelScreen.buttonLevels[found].level.Locked,
LevelScreen.buttonLevels[i]
.getLevelcolor(),
LevelScreen.buttonLevels[found]
.getLevelcolor());
}
}
}
}
}
}
}
} }

View File

@ -204,7 +204,7 @@ public class GameScreen implements Screen {
Gdx.app.debug("wirechem-GameScreen","Préparation du screen"); Gdx.app.debug("wirechem-GameScreen","Préparation du screen");
this.worlds = aworlds; this.worlds = aworlds;
this.worlds.prepareLevel(false); this.worlds.prepareLevel(false);
this.level=worlds.getInformations(); this.level=worlds.getLevelData();
if (worlds.isDebug()) if (worlds.isDebug())
tocreate = new String[] { "run", "stop", "speed", "separator", "move#", "zoomp#","zoomm#", "infos#", "separator", "raz", "save", "levels", "tree", "exits", "separator", "screen", "sound", "tuto", "grid", "settings", "separator", "stat","separator","unlocked","delrow","delcol","addrow","addcol","database" }; tocreate = new String[] { "run", "stop", "speed", "separator", "move#", "zoomp#","zoomm#", "infos#", "separator", "raz", "save", "levels", "tree", "exits", "separator", "screen", "sound", "tuto", "grid", "settings", "separator", "stat","separator","unlocked","delrow","delcol","addrow","addcol","database" };
else if (level.Tech<1) else if (level.Tech<1)
@ -248,7 +248,7 @@ public class GameScreen implements Screen {
@Override @Override
public void clicked(InputEvent event, float x, float y) { public void clicked(InputEvent event, float x, float y) {
if (worlds.isDebug()) if (worlds.isDebug())
worlds.getInformations().Cycle=5000; worlds.getLevelData().Cycle=5000;
} }
}); });
temp = new IconValue(Icon.temp,worlds, AssetLoader.Skin_level); temp = new IconValue(Icon.temp,worlds, AssetLoader.Skin_level);
@ -257,7 +257,7 @@ public class GameScreen implements Screen {
@Override @Override
public void clicked(InputEvent event, float x, float y) { public void clicked(InputEvent event, float x, float y) {
if (worlds.isDebug()) if (worlds.isDebug())
worlds.getInformations().Temp=5000; worlds.getLevelData().Temp=5000;
} }
}); });
rayon = new IconValue(Icon.rayon,worlds, AssetLoader.Skin_level); rayon = new IconValue(Icon.rayon,worlds, AssetLoader.Skin_level);
@ -266,7 +266,7 @@ public class GameScreen implements Screen {
@Override @Override
public void clicked(InputEvent event, float x, float y) { public void clicked(InputEvent event, float x, float y) {
if (worlds.isDebug()) if (worlds.isDebug())
worlds.getInformations().Rayon=5000; worlds.getLevelData().Rayon=5000;
} }
}); });
nrj = new IconValue(Icon.nrj,worlds, AssetLoader.Skin_level); nrj = new IconValue(Icon.nrj,worlds, AssetLoader.Skin_level);
@ -275,7 +275,7 @@ public class GameScreen implements Screen {
@Override @Override
public void clicked(InputEvent event, float x, float y) { public void clicked(InputEvent event, float x, float y) {
if (worlds.isDebug()) if (worlds.isDebug())
worlds.getInformations().Nrj=5000; worlds.getLevelData().Nrj=5000;
} }
}); });
tech = new IconValue(Icon.tech,worlds, AssetLoader.Skin_level); tech = new IconValue(Icon.tech,worlds, AssetLoader.Skin_level);
@ -284,7 +284,7 @@ public class GameScreen implements Screen {
@Override @Override
public void clicked(InputEvent event, float x, float y) { public void clicked(InputEvent event, float x, float y) {
if (worlds.isDebug()) if (worlds.isDebug())
worlds.getInformations().Tech=12; worlds.getLevelData().Tech=12;
} }
}); });
cout = new IconValue(Icon.cout,worlds, AssetLoader.Skin_level); cout = new IconValue(Icon.cout,worlds, AssetLoader.Skin_level);
@ -293,7 +293,7 @@ public class GameScreen implements Screen {
@Override @Override
public void clicked(InputEvent event, float x, float y) { public void clicked(InputEvent event, float x, float y) {
if (worlds.isDebug()) if (worlds.isDebug())
worlds.getInformations().Cout_orig=5000; worlds.getLevelData().Cout_orig=5000;
} }
}); });
research = new IconValue(Icon.research,worlds, AssetLoader.Skin_level); research = new IconValue(Icon.research,worlds, AssetLoader.Skin_level);
@ -813,7 +813,7 @@ public class GameScreen implements Screen {
stage_info.addActor(info_choose); stage_info.addActor(info_choose);
//stage_tooltip.addActor(tooltip); //stage_tooltip.addActor(tooltip);
stage.addActor(horizbar); stage.addActor(horizbar);
if (worlds.getInformations().Cout>0 || worlds.getInformations().Tech>=1 || worlds.isDebug()) { if (worlds.getLevelData().Cout>0 || worlds.getLevelData().Tech>=1 || worlds.isDebug()) {
stage.addActor(vertibar); stage.addActor(vertibar);
stage.addActor(buttonlevel); stage.addActor(buttonlevel);
stage.addActor(menu); stage.addActor(menu);

View File

@ -35,6 +35,7 @@ import fr.evolving.UI.Worldlist;
import fr.evolving.assets.AssetLoader; import fr.evolving.assets.AssetLoader;
import fr.evolving.assets.InitWorlds; import fr.evolving.assets.InitWorlds;
import fr.evolving.assets.Preference; import fr.evolving.assets.Preference;
import fr.evolving.automata.Grid;
import fr.evolving.automata.Level; import fr.evolving.automata.Level;
import fr.evolving.automata.Transmuter; import fr.evolving.automata.Transmuter;
import fr.evolving.automata.Worlds; import fr.evolving.automata.Worlds;
@ -44,7 +45,7 @@ import fr.evolving.dialogs.WarningDialog;
import fr.evolving.renderers.LevelRenderer; import fr.evolving.renderers.LevelRenderer;
public class LevelScreen implements Screen { public class LevelScreen implements Screen {
public ButtonLevel[] buttonLevels; public Array<ButtonLevel> buttonLevels;
private LevelRenderer Renderer; private LevelRenderer Renderer;
private float runTime; private float runTime;
private Timer ScrollTimer; private Timer ScrollTimer;
@ -52,7 +53,7 @@ public class LevelScreen implements Screen {
private Stage stage; private Stage stage;
private Table table; private Table table;
private WarningDialog dialog; private WarningDialog dialog;
private ImageButton Previous, Next, Exit, logosmall, databaseSave, adder, signer; private ImageButton Previous, Next, Exit, logosmall, databaseSave, adder, signer, finisher, deletelinker, deletebutton, addbutton;
public Image MenuSolo, MenuMulti, MenuScenario; public Image MenuSolo, MenuMulti, MenuScenario;
private ImageTextButton cout, tech, cycle, temp, rayon, nrj, up_cycle, up_temp, up_rayon, up_nrj, research, up; private ImageTextButton cout, tech, cycle, temp, rayon, nrj, up_cycle, up_temp, up_rayon, up_nrj, research, up;
private TextButton buttonConnect, buttonPlay, buttonStat, buttonSave, buttonApply, buttonPlaythis; private TextButton buttonConnect, buttonPlay, buttonStat, buttonSave, buttonApply, buttonPlaythis;
@ -66,7 +67,7 @@ public class LevelScreen implements Screen {
public int addervalue; public int addervalue;
public ButtonGroup chooser; public ButtonGroup chooser;
public Group group_init, group_stat, group_level, group_base, group_debug, group_choose, group_other; public Group group_init, group_stat, group_level, group_base, group_debug, group_choose, group_other;
public ClickListener buttonLevelslistener;
public void play() { public void play() {
if (worlds.getState()!=State.notloaded && worlds.getState()!=State.databasefailed) { if (worlds.getState()!=State.notloaded && worlds.getState()!=State.databasefailed) {
if (worlds.getWorld() < 0) if (worlds.getWorld() < 0)
@ -114,12 +115,11 @@ public class LevelScreen implements Screen {
public void initlevel() { public void initlevel() {
selected = null; selected = null;
if (buttonLevels != null) if (buttonLevels==null)
for (int j = 0; j < 10; j++) buttonLevels=new Array<ButtonLevel>();
if (buttonLevels[j] != null) { for(ButtonLevel button: buttonLevels)
buttonLevels[j].remove(); button.remove();
buttonLevels[j] = null; buttonLevels.clear();
}
} }
public void level() { public void level() {
@ -148,17 +148,39 @@ public class LevelScreen implements Screen {
group_base.setVisible(false); group_base.setVisible(false);
} }
public void loadWorld() { public ClickListener buttonLevelslistener() {
int i = 0; return new ClickListener() {
if (buttonLevels != null) @Override
for (int j = 0; j < 10; j++) { public void enter(InputEvent event, float x, float y,
if (buttonLevels[j] != null) { int pointer, Actor fromActor) {
buttonLevels[j].remove(); ButtonLevel abutton = (ButtonLevel) event
buttonLevels[j] = null; .getListenerActor();
} Gdx.app.debug("wirechem-LevelScreen","Enter button ");
if (!abutton.isChecked() && (!abutton.level.Locked || worlds.isDebug()))
showlevel(abutton);
}
public void exit(InputEvent event, float x, float y,
int pointer, Actor fromActor) {
ButtonLevel abutton = (ButtonLevel) event
.getListenerActor();
Gdx.app.debug("wirechem-LevelScreen","Enter button ");
if (!abutton.isChecked() && (!abutton.level.Locked || worlds.isDebug()))
showlevel(abutton);
}
public void touchDragged(InputEvent event, float x,
float y, int pointer) {
ButtonLevel abutton = (ButtonLevel) event.getListenerActor();
if (worlds.isDebug()) {
abutton.setPosition(event.getStageX() - 56, event.getStageY() - 20);
} }
buttonLevels = null; }
buttonLevels = new ButtonLevel[10]; };
}
public void loadWorld() {
initlevel();
Array<Level> levels=worlds.getLevels(); Array<Level> levels=worlds.getLevels();
if (levels!=null) if (levels!=null)
for (Level level : levels) { for (Level level : levels) {
@ -167,44 +189,16 @@ public class LevelScreen implements Screen {
level.Name=AssetLoader.language.get("[level"+(level.aWorld+1)+"/"+(level.aLevel+1)+"-name]"); level.Name=AssetLoader.language.get("[level"+(level.aWorld+1)+"/"+(level.aLevel+1)+"-name]");
if (level.Description.isEmpty()) if (level.Description.isEmpty())
level.Description=AssetLoader.language.get("[level"+(level.aWorld+1)+"/"+(level.aLevel+1)+"-desc]"); level.Description=AssetLoader.language.get("[level"+(level.aWorld+1)+"/"+(level.aLevel+1)+"-desc]");
buttonLevels[i] = new ButtonLevel(level, AssetLoader.ratio, true); ButtonLevel buttonlevel= new ButtonLevel(level, AssetLoader.ratio, true);
if (worlds.isDebug()) buttonLevels[i].setDisabled(false); buttonLevels.add(buttonlevel);
if (worlds.isDebug()) buttonlevel.setDisabled(false);
Gdx.app.debug("wirechem-LevelScreen", "Ajout du niveau :"+ level.Name + "" + String.valueOf(level.aLevel)); Gdx.app.debug("wirechem-LevelScreen", "Ajout du niveau :"+ level.Name + "" + String.valueOf(level.aLevel));
buttonLevels[i++].addListener(new ClickListener() {
@Override
public void enter(InputEvent event, float x, float y,
int pointer, Actor fromActor) {
ButtonLevel abutton = (ButtonLevel) event
.getListenerActor();
Gdx.app.debug("wirechem-LevelScreen","Enter button ");
if (!abutton.isChecked() && (!abutton.level.Locked || worlds.isDebug()))
showlevel(abutton);
}
public void exit(InputEvent event, float x, float y, buttonlevel.addListener(buttonLevelslistener());
int pointer, Actor fromActor) {
ButtonLevel abutton = (ButtonLevel) event
.getListenerActor();
Gdx.app.debug("wirechem-LevelScreen","Enter button ");
if (!abutton.isChecked() && (!abutton.level.Locked || worlds.isDebug()))
showlevel(abutton);
}
public void touchDragged(InputEvent event, float x,
float y, int pointer) {
ButtonLevel abutton = (ButtonLevel) event.getListenerActor();
if (worlds.isDebug()) {
abutton.setPosition(event.getStageX() - 56, event.getStageY() - 20);
}
}
});
}
}
for (int j = 0; j < 10; j++) {
if (buttonLevels[j] != null) {
stage.addActor(buttonLevels[j]);
} }
} }
for (ButtonLevel button : buttonLevels)
stage.addActor(button);
} }
public LevelScreen(Worlds aworlds) { public LevelScreen(Worlds aworlds) {
@ -215,20 +209,32 @@ public class LevelScreen implements Screen {
public void changed(ChangeEvent event, Actor actor) { public void changed(ChangeEvent event, Actor actor) {
if (worlds.getState()!=Worlds.State.notloaded && worlds.getWorld()>=0) if (worlds.getState()!=Worlds.State.notloaded && worlds.getWorld()>=0)
{ {
LevelScreen.this.loadWorld(); Level changed=worlds.getChange();
if (buttonLevels!=null) if (changed!=null) {
for (int j = 0; j < 10; j++) for (int i=0;i<buttonLevels.size;i++)
{ if (buttonLevels.get(i).level.aLevel==changed.aLevel)
if (buttonLevels[j]!=null) { {
buttonLevels[j].setChecked(false); buttonLevels.get(i).remove();
if (worlds.getInformations()!=null && buttonLevels[j].level.id == worlds.getInformations().id) { buttonLevels.removeIndex(i);
selected=buttonLevels[j]; return;
break;
}
} }
} ButtonLevel button=new ButtonLevel(changed, AssetLoader.ratio, true);
if (worlds.getInformations()==null) buttonLevels.add(button);
selected=buttonLevels[0]; stage.addActor(button);
button.addListener(buttonLevelslistener());
return;
}
LevelScreen.this.loadWorld();
for (ButtonLevel button : buttonLevels)
{
button.setChecked(false);
if (worlds.getLevelData()!=null && button.level.id == worlds.getLevelData().id) {
selected=button;
break;
}
}
if (worlds.getLevelData()==null)
selected=buttonLevels.first();
if (selected!=null) { if (selected!=null) {
selected.setChecked(true); selected.setChecked(true);
buttonPlay.setVisible(true); buttonPlay.setVisible(true);
@ -751,9 +757,8 @@ public class LevelScreen implements Screen {
if (!group_init.isVisible()) if (!group_init.isVisible())
if (logosmall.isChecked()) { if (logosmall.isChecked()) {
if (buttonLevels != null) if (buttonLevels != null)
for (int j = 0; j < 10; j++) for (ButtonLevel button : buttonLevels)
if (buttonLevels[j] != null) button.setDisabled(false);
buttonLevels[j].setDisabled(false);
worlds.ActivateDebug(); worlds.ActivateDebug();
Next.setVisible(!worlds.isRealLastWorld()); Next.setVisible(!worlds.isRealLastWorld());
group_debug.setVisible(true); group_debug.setVisible(true);
@ -764,9 +769,8 @@ public class LevelScreen implements Screen {
} }
else { else {
if (buttonLevels != null) if (buttonLevels != null)
for (int j = 0; j < 10; j++) for (ButtonLevel button : buttonLevels)
if (buttonLevels[j] != null) button.setDisabled(button.level.Locked);
buttonLevels[j].setDisabled(buttonLevels[j].level.Locked);
worlds.DesactivateDebug(); worlds.DesactivateDebug();
worlds.updateUnlockLevels(); worlds.updateUnlockLevels();
worlds.setMaxWorldLevel(); worlds.setMaxWorldLevel();
@ -787,6 +791,94 @@ public class LevelScreen implements Screen {
//Group Debug //Group Debug
//********************************************************** //**********************************************************
Gdx.app.debug("wirechem-LevelScreen", "Création du groupe Debug."); Gdx.app.debug("wirechem-LevelScreen", "Création du groupe Debug.");
deletebutton = new ImageButton(AssetLoader.Skin_level, "boss");
deletebutton.setPosition(1460, 140);
deletebutton.addListener(new ClickListener() {
@Override
public void clicked(InputEvent event, float x, float y) {
if (selected!=null) {
for (int i=0;i<buttonLevels.size;i++) {
ButtonLevel button=buttonLevels.get(i);
Array<int[]> links=new Array<int[]>(button.level.Link);
for(int[] link: links)
if (link.length==2 && link[0]==selected.level.aWorld && link[1]==selected.level.aLevel)
{
if (i==buttonLevels.size-1)
links.removeValue(link, true);
else {
for (int j=i+1;j<buttonLevels.size;j++) {
if (buttonLevels.get(j)!=null) {
link[1]=j;
break;
}
}
}
}
button.level.Link=links.toArray();
}
Gdx.app.debug("wirechem-LevelScreen", "Destruction du bouton :"+selected.level.aLevel);
//buttonLevels.removeValue(selected, true);
worlds.delLevel(selected.level.aLevel);
//selected.remove();
}
}
});
deletelinker = new ImageButton(AssetLoader.Skin_level, "boss");
deletelinker.setPosition(1560, 140);
deletelinker.addListener(new ClickListener() {
@Override
public void clicked(InputEvent event, float x, float y) {
if (selected!=null) {
for (ButtonLevel button : buttonLevels) {
Array<int[]> links=new Array<int[]>(button.level.Link);
for(int[] link: links)
if (link.length==2 && link[0]==selected.level.aWorld && link[1]==selected.level.aLevel)
{
Gdx.app.debug("wirechem-LevelScreen", "Destruction du lien :"+selected.level.aLevel);
links.removeValue(link, true);
}
button.level.Link=links.toArray();
}
}
}
});
addbutton = new ImageButton(AssetLoader.Skin_level, "boss");
addbutton.setPosition(1760, 540);
addbutton.addListener(new ClickListener() {
@Override
public void clicked(InputEvent event, float x, float y) {
Level level=new Level(
worlds.getWorld(),
worlds.getFreeLevel(),
(int) (Math.random() * Integer.MAX_VALUE),
"Unknown",
"Unknown",
"Uk", new int[] { 0, 0, 0, 0, 0, 0 },
new int[] { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, (float)Math.random() * 1000f,
(float)Math.random() * 750f, 0, 0, new Grid(3, 3), 0, 0, 0, 0, 99999, 99999,
99999, 99999, "", false, new int[][] {{}});
worlds.addLevel(level);
//ButtonLevel button=new ButtonLevel(level, AssetLoader.ratio, true);
//buttonLevels.add(button);
//stage.addActor(button);
//button.addListener(buttonLevelslistener());
}
});
finisher = new ImageButton(AssetLoader.Skin_level, "boss");
finisher.setSize(64, 64);
finisher.setPosition(1560, 40);
finisher.addListener(new ClickListener() {
@Override
public void clicked(InputEvent event, float x, float y) {
if (selected!=null) {
selected.level.Special=!selected.level.Special;
if (selected.level.Special)
finisher.setColor(AssetLoader.Skin_level.getColor("red"));
else
finisher.setColor(AssetLoader.Skin_level.getColor("black"));
}
}
});
signer = new ImageButton(AssetLoader.Skin_level, "add"); signer = new ImageButton(AssetLoader.Skin_level, "add");
signer.setPosition(1660, 40); signer.setPosition(1660, 40);
signer.addListener(new ClickListener() { signer.addListener(new ClickListener() {
@ -839,7 +931,12 @@ public class LevelScreen implements Screen {
group_debug.addActor(databaseSave); group_debug.addActor(databaseSave);
group_debug.addActor(adder); group_debug.addActor(adder);
group_debug.addActor(signer); group_debug.addActor(signer);
group_debug.addActor(finisher);
group_debug.addActor(deletelinker);
group_debug.addActor(deletebutton);
group_debug.addActor(addbutton);
//**********************************************************
Gdx.app.debug("wirechem-LevelScreen", "Affichage du menu."); Gdx.app.debug("wirechem-LevelScreen", "Affichage du menu.");
if (worlds.getWorld() != -1) if (worlds.getWorld() != -1)
level(); level();
@ -962,6 +1059,12 @@ public class LevelScreen implements Screen {
up.setVisible(false); up.setVisible(false);
Victory.setVisible(button.level.Cout_orig > 0 || worlds.isDebug()); Victory.setVisible(button.level.Cout_orig > 0 || worlds.isDebug());
Victory.setVictory(button.level.Victory_orig); Victory.setVictory(button.level.Victory_orig);
if (worlds.isDebug()) {
if (button.level.Special)
finisher.setColor(AssetLoader.Skin_level.getColor("red"));
else
finisher.setColor(AssetLoader.Skin_level.getColor("black"));
}
if (selected != null) if (selected != null)
selected.setChecked(false); selected.setChecked(false);
selected = button; selected = button;