fix: réelle gestion de déblocage des niveaux le mode "debogue" permet d'accéder à tout les niveaux ou monde même bloqués

This commit is contained in:
Nicolas Hordé 2016-02-02 21:09:32 +01:00
parent 7efec490f4
commit cc9bdbc746
6 changed files with 108 additions and 50 deletions

View File

@ -24,15 +24,14 @@ public class ButtonLevel extends ImageTextButton {
public ButtonLevel(Level level, float ratio, boolean modifyxy) { public ButtonLevel(Level level, float ratio, boolean modifyxy) {
super(level.Name, AssetLoader.Skin_level, "world" super(level.Name, AssetLoader.Skin_level, "world"
+ String.valueOf(level.aWorld)); + String.valueOf(level.aWorld));
Locked = AssetLoader.Skin_level.getAtlas().findRegion("locked");
Finalled = AssetLoader.Skin_level.getAtlas().findRegion("boss");
this.modifyxy=modifyxy; this.modifyxy=modifyxy;
this.level = level; this.level = level;
this.ratio = ratio; this.ratio = ratio;
if (level.Special == true) { if (level.Locked) {
Finalled = AssetLoader.Skin_level.getAtlas().findRegion("boss");
}
if (level.Locked == false) {
this.setDisabled(true); this.setDisabled(true);
Locked = AssetLoader.Skin_level.getAtlas().findRegion("locked");
} }
this.setColor(1f, 0.47f + (float) level.X / 1024f * 0.529f, this.setColor(1f, 0.47f + (float) level.X / 1024f * 0.529f,
0.607f + (float) level.X / 768f * 0.392f, 1f); 0.607f + (float) level.X / 768f * 0.392f, 1f);
@ -88,7 +87,7 @@ public class ButtonLevel extends ImageTextButton {
Finalled.getRegionWidth() * scale, Finalled.getRegionWidth() * scale,
Finalled.getRegionHeight() * scale); Finalled.getRegionHeight() * scale);
} }
if (!level.Locked) { if (level.Locked) {
batch.draw( batch.draw(
Locked, Locked,
getX() + this.getWidth() - Locked.getRegionWidth(), getX() + this.getWidth() - Locked.getRegionWidth(),

View File

@ -35,6 +35,7 @@ public class Level implements Serializable {
public transient int Rayon; public transient int Rayon;
public transient int Nrj; public transient int Nrj;
public transient boolean Locked; public transient boolean Locked;
public transient boolean Locked_old;
public Level(int aWorld, int aLevel, int id, String Name, public Level(int aWorld, int aLevel, int id, String Name,
String Description, String Element, int[] Current, int[] Victory, String Description, String Element, int[] Current, int[] Victory,

View File

@ -134,9 +134,7 @@ public class Worlds extends Actor {
if (level!=null && level.aWorld==usedworld) if (level!=null && level.aWorld==usedworld)
{ {
if (level.aLevel==0) if (level.aLevel==0)
level.Locked=true; level.Locked=false;
else
level.Locked=AssetLoader.Datahandler.user().getLevellock(0, level.aLevel);
tempworld.add(level); tempworld.add(level);
} }
return tempworld; return tempworld;
@ -145,6 +143,12 @@ public class Worlds extends Actor {
return null; return null;
} }
public void updateUnlockLevels() {
for(Level level:levels)
if (level!=null)
level.Locked=AssetLoader.Datahandler.user().getLevellock(0, level.id);
}
public State getState() { public State getState() {
return state; return state;
} }
@ -183,6 +187,24 @@ public class Worlds extends Actor {
} }
} }
public void setMaxWorldLevel() {
usedworld=getMaxUnlockWorlds();
usedlevel=getMaxUnlockLevel();
}
public boolean isFirstWorld() {
return (usedworld==0);
}
public boolean isLastWorld() {
return (usedworld==getMaxUnlockWorlds());
}
public boolean isRealLastWorld() {
return (usedworld==getMaxWorlds());
}
public void NextWorld() { public void NextWorld() {
if (state!=State.notloaded) if (state!=State.notloaded)
if (usedworld<getMaxWorlds()) { if (usedworld<getMaxWorlds()) {
@ -218,6 +240,7 @@ public class Worlds extends Actor {
public void load(String campaign) { public void load(String campaign) {
Gdx.app.log("*****", "Chargement de la compagne "+campaign); Gdx.app.log("*****", "Chargement de la compagne "+campaign);
levels=AssetLoader.Datahandler.game().getCampaign(campaign); levels=AssetLoader.Datahandler.game().getCampaign(campaign);
updateUnlockLevels();
name=campaign; name=campaign;
if (levels==null) if (levels==null)
state=State.notloaded; state=State.notloaded;
@ -257,6 +280,26 @@ public class Worlds extends Actor {
return max; return max;
} }
public int getMaxUnlockWorlds() {
int maxworld=0;
for (Level level : levels)
if (!level.Locked && level.aWorld>maxworld)
maxworld=level.aWorld;
return maxworld;
}
public Level getMaxUnlockLevel() {
Array<Level> tempworld=getLevels();
int maxlevel=0;
Level themaxlevel=null;
for (Level level : tempworld)
if (!level.Locked && level.aLevel>maxlevel) {
maxlevel=level.aLevel;
themaxlevel=level;
}
return themaxlevel;
}
public String getName() { public String getName() {
return this.name; return this.name;
} }

View File

@ -178,9 +178,9 @@ public class LocalBase extends Base {
return false; return false;
} }
if (cursor.next()) if (cursor.next())
return true;
else
return false; return false;
else
return true;
} }
public boolean setLevelunlock(int user, int level) { public boolean setLevelunlock(int user, int level) {

View File

@ -146,7 +146,7 @@ public class LevelRenderer {
* AssetLoader.ratio, * AssetLoader.ratio,
10, 10,
0.5f, 0.5f,
LevelScreen.buttonLevels[i].level.Locked, !LevelScreen.buttonLevels[i].level.Locked,
LevelScreen.buttonLevels[i] LevelScreen.buttonLevels[i]
.getLevelcolor(), .getLevelcolor(),
LevelScreen.buttonLevels[found] LevelScreen.buttonLevels[found]
@ -162,7 +162,7 @@ public class LevelRenderer {
* AssetLoader.ratio, * AssetLoader.ratio,
10, 10,
0.5f, 0.5f,
LevelScreen.buttonLevels[i].level.Locked, !LevelScreen.buttonLevels[i].level.Locked,
LevelScreen.buttonLevels[i] LevelScreen.buttonLevels[i]
.getLevelcolor(), .getLevelcolor(),
LevelScreen.buttonLevels[found] LevelScreen.buttonLevels[found]

View File

@ -63,9 +63,9 @@ public class LevelScreen implements Screen {
public void play() { public void play() {
if (worlds.getState()!=State.notloaded && worlds.getState()!=State.databasefailed) { if (worlds.getState()!=State.notloaded && worlds.getState()!=State.databasefailed) {
Gdx.app.debug(getClass().getSimpleName(),"Afficher le monde 0");
if (worlds.getWorld() < 0) if (worlds.getWorld() < 0)
worlds.setWorld(0); worlds.setMaxWorldLevel();
Gdx.app.debug(getClass().getSimpleName(),"Afficher derniere réalisation, monde :"+worlds.getWorld()+" niveau:"+worlds.getLevel());
worlds.Forcereload(); worlds.Forcereload();
} }
} }
@ -208,17 +208,16 @@ public class LevelScreen implements Screen {
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); buttonLevels[i] = new ButtonLevel(level, AssetLoader.ratio, true);
Gdx.app.debug(getClass().getSimpleName(), "Ajout du niveau :" if (worlds.isDebug()) buttonLevels[i].setDisabled(false);
+ level.Name + "" + String.valueOf(level.aLevel)); Gdx.app.debug(getClass().getSimpleName(), "Ajout du niveau :"+ level.Name + "" + String.valueOf(level.aLevel));
buttonLevels[i++].addListener(new ClickListener() { buttonLevels[i++].addListener(new ClickListener() {
@Override @Override
public void enter(InputEvent event, float x, float y, public void enter(InputEvent event, float x, float y,
int pointer, Actor fromActor) { int pointer, Actor fromActor) {
ButtonLevel abutton = (ButtonLevel) event ButtonLevel abutton = (ButtonLevel) event
.getListenerActor(); .getListenerActor();
Gdx.app.debug(event.getListenerActor().toString(), Gdx.app.debug(event.getListenerActor().toString(),"Enter button ");
"Enter button "); if (!abutton.isChecked() && (!abutton.level.Locked || worlds.isDebug()))
if (!abutton.isChecked())
showlevel(abutton); showlevel(abutton);
} }
@ -226,19 +225,16 @@ public class LevelScreen implements Screen {
int pointer, Actor fromActor) { int pointer, Actor fromActor) {
ButtonLevel abutton = (ButtonLevel) event ButtonLevel abutton = (ButtonLevel) event
.getListenerActor(); .getListenerActor();
Gdx.app.debug(event.getListenerActor().toString(), Gdx.app.debug(event.getListenerActor().toString(),"Enter button ");
"Enter button "); if (!abutton.isChecked() && (!abutton.level.Locked || worlds.isDebug()))
if (!abutton.isChecked())
showlevel(abutton); showlevel(abutton);
} }
public void touchDragged(InputEvent event, float x, public void touchDragged(InputEvent event, float x,
float y, int pointer) { float y, int pointer) {
ButtonLevel abutton = (ButtonLevel) event ButtonLevel abutton = (ButtonLevel) event.getListenerActor();
.getListenerActor();
if (worlds.isDebug()) { if (worlds.isDebug()) {
abutton.setPosition(event.getStageX() - 56, abutton.setPosition(event.getStageX() - 56, event.getStageY() - 20);
event.getStageY() - 20);
} }
} }
}); });
@ -277,8 +273,11 @@ public class LevelScreen implements Screen {
selected=buttonLevels[0]; selected=buttonLevels[0];
selected.setChecked(true); selected.setChecked(true);
showlevel(selected); showlevel(selected);
Previous.setVisible(true); Previous.setVisible(!worlds.isFirstWorld());
Next.setVisible(true); if (worlds.isDebug())
Next.setVisible(!worlds.isRealLastWorld());
else
Next.setVisible(!worlds.isLastWorld());
buttonPlay.setVisible(true); buttonPlay.setVisible(true);
TextDescriptive.setVisible(true); TextDescriptive.setVisible(true);
} }
@ -290,8 +289,7 @@ public class LevelScreen implements Screen {
} }
} }
}); });
Gdx.app.debug(getClass().getSimpleName(), Gdx.app.debug(getClass().getSimpleName(),"Création des elements primordiaux du screen (stage, renderer, table)");
"Création des elements primordiaux du screen (stage, renderer, table)");
stage = new Stage(AssetLoader.viewport); stage = new Stage(AssetLoader.viewport);
table = new Table(); table = new Table();
Renderer = new LevelRenderer(this); Renderer = new LevelRenderer(this);
@ -362,10 +360,27 @@ public class LevelScreen implements Screen {
logosmall.setChecked(worlds.isDebug()); logosmall.setChecked(worlds.isDebug());
logosmall.addListener(new ClickListener() { logosmall.addListener(new ClickListener() {
public void clicked(InputEvent event, float x, float y) { public void clicked(InputEvent event, float x, float y) {
if (logosmall.isChecked()) if (logosmall.isChecked()) {
if (buttonLevels != null)
for (int j = 0; j < 10; j++) {
if (buttonLevels[j] != null)
buttonLevels[j].setDisabled(false);
}
worlds.ActivateDebug(); worlds.ActivateDebug();
else Next.setVisible(!worlds.isRealLastWorld());
}
else {
if (buttonLevels != null)
for (int j = 0; j < 10; j++) {
if (buttonLevels[j] != null)
buttonLevels[j].setDisabled(buttonLevels[j].level.Locked);
}
worlds.DesactivateDebug(); worlds.DesactivateDebug();
worlds.updateUnlockLevels();
worlds.setMaxWorldLevel();
loadWorld();
}
} }
}); });
TextDescriptive = new TextArea("Descriptif", AssetLoader.Skin_level, TextDescriptive = new TextArea("Descriptif", AssetLoader.Skin_level,