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) {
case tech:
this.setText(String.valueOf(worlds.getInformations().Tech));
this.setVisible(worlds.getInformations().Tech>=1 || worlds.isDebug());
this.setText(String.valueOf(worlds.getLevelData().Tech));
this.setVisible(worlds.getLevelData().Tech>=1 || worlds.isDebug());
break;
case cout:
worlds.getInformations().Cout=worlds.getInformations().Cout_orig-worlds.getInformations().Cout_copperfiber-worlds.getInformations().Cout_transmuter;
this.setText(String.valueOf(worlds.getInformations().Cout));
if (worlds.getInformations().Cout>0.25*worlds.getInformations().Cout_orig)
worlds.getLevelData().Cout=worlds.getLevelData().Cout_orig-worlds.getLevelData().Cout_copperfiber-worlds.getLevelData().Cout_transmuter;
this.setText(String.valueOf(worlds.getLevelData().Cout));
if (worlds.getLevelData().Cout>0.25*worlds.getLevelData().Cout_orig)
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);
else
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;
case research:
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;
case cycle:
this.setVisible(worlds.getWorld()>=1 || worlds.isDebug());
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
this.setText(String.valueOf(worlds.getInformations().Cycle));
this.setText(String.valueOf(worlds.getLevelData().Cycle));
break;
case temp:
this.setVisible(worlds.getWorld()>=2 || worlds.isDebug());
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
this.setText(String.valueOf(worlds.getInformations().Temp));
this.setText(String.valueOf(worlds.getLevelData().Temp));
break;
case rayon:
this.setVisible(worlds.getWorld()>=3 || worlds.isDebug());
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
this.setText(String.valueOf(worlds.getInformations().Rayon));
this.setText(String.valueOf(worlds.getLevelData().Rayon));
break;
case nrj:
this.setVisible(worlds.getWorld()>=4 || worlds.isDebug());
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
this.setText(String.valueOf(worlds.getInformations().Nrj));
this.setText(String.valueOf(worlds.getLevelData().Nrj));
break;
}

View File

@ -231,18 +231,18 @@ public class Menu extends Actor {
this.setMenuTile(0, 4, 87, "gold_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(1, 7, 72, "copper_brush",0);
this.setMenuTile(2, 7, 73, "copper_eraser",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);
}
if (worlds.getInformations().Tech>=2 || worlds.isDebug())
if (worlds.getLevelData().Tech>=2 || worlds.isDebug())
{
this.setMenuTile(1, 5, 70, "blank",0);
this.setMenuTile(0, 6, 74, "fiber_pen",0);
@ -356,7 +356,7 @@ public class Menu extends Actor {
if (transmuter != null) {
int type=transmuter.getaClass().ordinal();
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");
if (!transmuter.isShowed() && transmuter.isUpgraded() && !worlds.isDebug())
layer = ((TiledMapTileLayer) map[page][type].getLayers().get(2));

View File

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

View File

@ -35,7 +35,7 @@ public class VertiBarre extends Actor {
Gdx.app.debug("wirechem-VertiBarre", "Menu:" + Barre.length+ " elements");
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);
table.addActor(Barre[i]);

View File

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

View File

@ -33,7 +33,7 @@ public class GameRenderer {
} else if (layer == 1) {
batcher.begin();
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("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.glutils.ShapeRenderer;
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.effects.Laser;
import fr.evolving.screens.LevelScreen;
@ -121,56 +123,18 @@ public class LevelRenderer {
shapeRenderer.rect(1470, 10, 440, AssetLoader.height - 20);
shapeRenderer.end();
if (LevelScreen.buttonLevels != null)
for (int i = 0; i < LevelScreen.buttonLevels.length; i++) {
if (LevelScreen.buttonLevels[i] != null) {
for (int[] item : LevelScreen.buttonLevels[i].level.Link) {
int found = -1;
for (int j = 0; j < LevelScreen.buttonLevels.length; j++) {
if ((item.length == 2)
&& (LevelScreen.buttonLevels[j] != null)
&& (LevelScreen.buttonLevels[j].level.aWorld == item[0])
&& (LevelScreen.buttonLevels[j].level.aLevel == item[1])) {
found = j;
break;
}
}
if (found != -1) {
for (int i=0;i<LevelScreen.buttonLevels.size;i++)
{
ButtonLevel button1=LevelScreen.buttonLevels.get(i);
for (int[] item : button1.level.Link)
for (ButtonLevel button2 : LevelScreen.buttonLevels)
if ((item.length == 2) && (button2.level.aWorld == item[0]) && (button2.level.aLevel == item[1]))
if (!LevelScreen.worlds.isDebug())
Laser.draw(
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());
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());
else
Laser.drawnotsoold(
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());
}
}
}
}
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());
}
}
}

View File

@ -204,7 +204,7 @@ public class GameScreen implements Screen {
Gdx.app.debug("wirechem-GameScreen","Préparation du screen");
this.worlds = aworlds;
this.worlds.prepareLevel(false);
this.level=worlds.getInformations();
this.level=worlds.getLevelData();
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" };
else if (level.Tech<1)
@ -248,7 +248,7 @@ public class GameScreen implements Screen {
@Override
public void clicked(InputEvent event, float x, float y) {
if (worlds.isDebug())
worlds.getInformations().Cycle=5000;
worlds.getLevelData().Cycle=5000;
}
});
temp = new IconValue(Icon.temp,worlds, AssetLoader.Skin_level);
@ -257,7 +257,7 @@ public class GameScreen implements Screen {
@Override
public void clicked(InputEvent event, float x, float y) {
if (worlds.isDebug())
worlds.getInformations().Temp=5000;
worlds.getLevelData().Temp=5000;
}
});
rayon = new IconValue(Icon.rayon,worlds, AssetLoader.Skin_level);
@ -266,7 +266,7 @@ public class GameScreen implements Screen {
@Override
public void clicked(InputEvent event, float x, float y) {
if (worlds.isDebug())
worlds.getInformations().Rayon=5000;
worlds.getLevelData().Rayon=5000;
}
});
nrj = new IconValue(Icon.nrj,worlds, AssetLoader.Skin_level);
@ -275,7 +275,7 @@ public class GameScreen implements Screen {
@Override
public void clicked(InputEvent event, float x, float y) {
if (worlds.isDebug())
worlds.getInformations().Nrj=5000;
worlds.getLevelData().Nrj=5000;
}
});
tech = new IconValue(Icon.tech,worlds, AssetLoader.Skin_level);
@ -284,7 +284,7 @@ public class GameScreen implements Screen {
@Override
public void clicked(InputEvent event, float x, float y) {
if (worlds.isDebug())
worlds.getInformations().Tech=12;
worlds.getLevelData().Tech=12;
}
});
cout = new IconValue(Icon.cout,worlds, AssetLoader.Skin_level);
@ -293,7 +293,7 @@ public class GameScreen implements Screen {
@Override
public void clicked(InputEvent event, float x, float y) {
if (worlds.isDebug())
worlds.getInformations().Cout_orig=5000;
worlds.getLevelData().Cout_orig=5000;
}
});
research = new IconValue(Icon.research,worlds, AssetLoader.Skin_level);
@ -813,7 +813,7 @@ public class GameScreen implements Screen {
stage_info.addActor(info_choose);
//stage_tooltip.addActor(tooltip);
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(buttonlevel);
stage.addActor(menu);

View File

@ -35,6 +35,7 @@ import fr.evolving.UI.Worldlist;
import fr.evolving.assets.AssetLoader;
import fr.evolving.assets.InitWorlds;
import fr.evolving.assets.Preference;
import fr.evolving.automata.Grid;
import fr.evolving.automata.Level;
import fr.evolving.automata.Transmuter;
import fr.evolving.automata.Worlds;
@ -44,7 +45,7 @@ import fr.evolving.dialogs.WarningDialog;
import fr.evolving.renderers.LevelRenderer;
public class LevelScreen implements Screen {
public ButtonLevel[] buttonLevels;
public Array<ButtonLevel> buttonLevels;
private LevelRenderer Renderer;
private float runTime;
private Timer ScrollTimer;
@ -52,7 +53,7 @@ public class LevelScreen implements Screen {
private Stage stage;
private Table table;
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;
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;
@ -66,7 +67,7 @@ public class LevelScreen implements Screen {
public int addervalue;
public ButtonGroup chooser;
public Group group_init, group_stat, group_level, group_base, group_debug, group_choose, group_other;
public ClickListener buttonLevelslistener;
public void play() {
if (worlds.getState()!=State.notloaded && worlds.getState()!=State.databasefailed) {
if (worlds.getWorld() < 0)
@ -114,12 +115,11 @@ public class LevelScreen implements Screen {
public void initlevel() {
selected = null;
if (buttonLevels != null)
for (int j = 0; j < 10; j++)
if (buttonLevels[j] != null) {
buttonLevels[j].remove();
buttonLevels[j] = null;
}
if (buttonLevels==null)
buttonLevels=new Array<ButtonLevel>();
for(ButtonLevel button: buttonLevels)
button.remove();
buttonLevels.clear();
}
public void level() {
@ -148,29 +148,8 @@ public class LevelScreen implements Screen {
group_base.setVisible(false);
}
public void loadWorld() {
int i = 0;
if (buttonLevels != null)
for (int j = 0; j < 10; j++) {
if (buttonLevels[j] != null) {
buttonLevels[j].remove();
buttonLevels[j] = null;
}
}
buttonLevels = null;
buttonLevels = new ButtonLevel[10];
Array<Level> levels=worlds.getLevels();
if (levels!=null)
for (Level level : levels) {
if (level != null) {
if (level.Name.isEmpty())
level.Name=AssetLoader.language.get("[level"+(level.aWorld+1)+"/"+(level.aLevel+1)+"-name]");
if (level.Description.isEmpty())
level.Description=AssetLoader.language.get("[level"+(level.aWorld+1)+"/"+(level.aLevel+1)+"-desc]");
buttonLevels[i] = new ButtonLevel(level, AssetLoader.ratio, true);
if (worlds.isDebug()) buttonLevels[i].setDisabled(false);
Gdx.app.debug("wirechem-LevelScreen", "Ajout du niveau :"+ level.Name + "" + String.valueOf(level.aLevel));
buttonLevels[i++].addListener(new ClickListener() {
public ClickListener buttonLevelslistener() {
return new ClickListener() {
@Override
public void enter(InputEvent event, float x, float y,
int pointer, Actor fromActor) {
@ -197,14 +176,29 @@ public class LevelScreen implements Screen {
abutton.setPosition(event.getStageX() - 56, event.getStageY() - 20);
}
}
});
}
}
for (int j = 0; j < 10; j++) {
if (buttonLevels[j] != null) {
stage.addActor(buttonLevels[j]);
};
}
public void loadWorld() {
initlevel();
Array<Level> levels=worlds.getLevels();
if (levels!=null)
for (Level level : levels) {
if (level != null) {
if (level.Name.isEmpty())
level.Name=AssetLoader.language.get("[level"+(level.aWorld+1)+"/"+(level.aLevel+1)+"-name]");
if (level.Description.isEmpty())
level.Description=AssetLoader.language.get("[level"+(level.aWorld+1)+"/"+(level.aLevel+1)+"-desc]");
ButtonLevel buttonlevel= new ButtonLevel(level, AssetLoader.ratio, true);
buttonLevels.add(buttonlevel);
if (worlds.isDebug()) buttonlevel.setDisabled(false);
Gdx.app.debug("wirechem-LevelScreen", "Ajout du niveau :"+ level.Name + "" + String.valueOf(level.aLevel));
buttonlevel.addListener(buttonLevelslistener());
}
}
for (ButtonLevel button : buttonLevels)
stage.addActor(button);
}
public LevelScreen(Worlds aworlds) {
@ -215,20 +209,32 @@ public class LevelScreen implements Screen {
public void changed(ChangeEvent event, Actor actor) {
if (worlds.getState()!=Worlds.State.notloaded && worlds.getWorld()>=0)
{
LevelScreen.this.loadWorld();
if (buttonLevels!=null)
for (int j = 0; j < 10; j++)
Level changed=worlds.getChange();
if (changed!=null) {
for (int i=0;i<buttonLevels.size;i++)
if (buttonLevels.get(i).level.aLevel==changed.aLevel)
{
if (buttonLevels[j]!=null) {
buttonLevels[j].setChecked(false);
if (worlds.getInformations()!=null && buttonLevels[j].level.id == worlds.getInformations().id) {
selected=buttonLevels[j];
buttonLevels.get(i).remove();
buttonLevels.removeIndex(i);
return;
}
ButtonLevel button=new ButtonLevel(changed, AssetLoader.ratio, true);
buttonLevels.add(button);
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.getInformations()==null)
selected=buttonLevels[0];
if (worlds.getLevelData()==null)
selected=buttonLevels.first();
if (selected!=null) {
selected.setChecked(true);
buttonPlay.setVisible(true);
@ -751,9 +757,8 @@ public class LevelScreen implements Screen {
if (!group_init.isVisible())
if (logosmall.isChecked()) {
if (buttonLevels != null)
for (int j = 0; j < 10; j++)
if (buttonLevels[j] != null)
buttonLevels[j].setDisabled(false);
for (ButtonLevel button : buttonLevels)
button.setDisabled(false);
worlds.ActivateDebug();
Next.setVisible(!worlds.isRealLastWorld());
group_debug.setVisible(true);
@ -764,9 +769,8 @@ public class LevelScreen implements Screen {
}
else {
if (buttonLevels != null)
for (int j = 0; j < 10; j++)
if (buttonLevels[j] != null)
buttonLevels[j].setDisabled(buttonLevels[j].level.Locked);
for (ButtonLevel button : buttonLevels)
button.setDisabled(button.level.Locked);
worlds.DesactivateDebug();
worlds.updateUnlockLevels();
worlds.setMaxWorldLevel();
@ -787,6 +791,94 @@ public class LevelScreen implements Screen {
//Group 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.setPosition(1660, 40);
signer.addListener(new ClickListener() {
@ -839,7 +931,12 @@ public class LevelScreen implements Screen {
group_debug.addActor(databaseSave);
group_debug.addActor(adder);
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.");
if (worlds.getWorld() != -1)
level();
@ -962,6 +1059,12 @@ public class LevelScreen implements Screen {
up.setVisible(false);
Victory.setVisible(button.level.Cout_orig > 0 || worlds.isDebug());
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)
selected.setChecked(false);
selected = button;