From cc9bdbc746b6f5ed17bdf655ef2f8b01150f78ba Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicolas=20Hord=C3=A9?= Date: Tue, 2 Feb 2016 21:09:32 +0100 Subject: [PATCH] =?UTF-8?q?fix:=20r=C3=A9elle=20gestion=20de=20d=C3=A9bloc?= =?UTF-8?q?age=20des=20niveaux=20le=20mode=20"debogue"=20permet=20d'acc?= =?UTF-8?q?=C3=A9der=20=C3=A0=20tout=20les=20niveaux=20ou=20monde=20m?= =?UTF-8?q?=C3=AAme=20bloqu=C3=A9s?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- core/src/fr/evolving/UI/ButtonLevel.java | 11 ++- core/src/fr/evolving/automata/Level.java | 1 + core/src/fr/evolving/automata/Worlds.java | 49 +++++++++- core/src/fr/evolving/database/LocalBase.java | 4 +- .../fr/evolving/renderers/LevelRenderer.java | 4 +- core/src/fr/evolving/screens/LevelScreen.java | 89 +++++++++++-------- 6 files changed, 108 insertions(+), 50 deletions(-) diff --git a/core/src/fr/evolving/UI/ButtonLevel.java b/core/src/fr/evolving/UI/ButtonLevel.java index 7a65964..c4ce9ad 100644 --- a/core/src/fr/evolving/UI/ButtonLevel.java +++ b/core/src/fr/evolving/UI/ButtonLevel.java @@ -24,15 +24,14 @@ public class ButtonLevel extends ImageTextButton { public ButtonLevel(Level level, float ratio, boolean modifyxy) { super(level.Name, AssetLoader.Skin_level, "world" + String.valueOf(level.aWorld)); + Locked = AssetLoader.Skin_level.getAtlas().findRegion("locked"); + Finalled = AssetLoader.Skin_level.getAtlas().findRegion("boss"); this.modifyxy=modifyxy; this.level = level; this.ratio = ratio; - if (level.Special == true) { - Finalled = AssetLoader.Skin_level.getAtlas().findRegion("boss"); - } - if (level.Locked == false) { + if (level.Locked) { this.setDisabled(true); - Locked = AssetLoader.Skin_level.getAtlas().findRegion("locked"); + } this.setColor(1f, 0.47f + (float) level.X / 1024f * 0.529f, 0.607f + (float) level.X / 768f * 0.392f, 1f); @@ -88,7 +87,7 @@ public class ButtonLevel extends ImageTextButton { Finalled.getRegionWidth() * scale, Finalled.getRegionHeight() * scale); } - if (!level.Locked) { + if (level.Locked) { batch.draw( Locked, getX() + this.getWidth() - Locked.getRegionWidth(), diff --git a/core/src/fr/evolving/automata/Level.java b/core/src/fr/evolving/automata/Level.java index 99599a3..9cd13a1 100644 --- a/core/src/fr/evolving/automata/Level.java +++ b/core/src/fr/evolving/automata/Level.java @@ -35,6 +35,7 @@ public class Level implements Serializable { public transient int Rayon; public transient int Nrj; public transient boolean Locked; + public transient boolean Locked_old; public Level(int aWorld, int aLevel, int id, String Name, String Description, String Element, int[] Current, int[] Victory, diff --git a/core/src/fr/evolving/automata/Worlds.java b/core/src/fr/evolving/automata/Worlds.java index 10ac942..c0b43e0 100644 --- a/core/src/fr/evolving/automata/Worlds.java +++ b/core/src/fr/evolving/automata/Worlds.java @@ -134,9 +134,7 @@ public class Worlds extends Actor { if (level!=null && level.aWorld==usedworld) { if (level.aLevel==0) - level.Locked=true; - else - level.Locked=AssetLoader.Datahandler.user().getLevellock(0, level.aLevel); + level.Locked=false; tempworld.add(level); } return tempworld; @@ -145,6 +143,12 @@ public class Worlds extends Actor { return null; } + public void updateUnlockLevels() { + for(Level level:levels) + if (level!=null) + level.Locked=AssetLoader.Datahandler.user().getLevellock(0, level.id); + } + public State getState() { 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() { if (state!=State.notloaded) if (usedworldmaxworld) + maxworld=level.aWorld; + return maxworld; + } + + public Level getMaxUnlockLevel() { + Array 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() { return this.name; } diff --git a/core/src/fr/evolving/database/LocalBase.java b/core/src/fr/evolving/database/LocalBase.java index 5e120da..9a9f457 100644 --- a/core/src/fr/evolving/database/LocalBase.java +++ b/core/src/fr/evolving/database/LocalBase.java @@ -178,9 +178,9 @@ public class LocalBase extends Base { return false; } if (cursor.next()) - return true; - else return false; + else + return true; } public boolean setLevelunlock(int user, int level) { diff --git a/core/src/fr/evolving/renderers/LevelRenderer.java b/core/src/fr/evolving/renderers/LevelRenderer.java index 1282ad0..5c6f941 100644 --- a/core/src/fr/evolving/renderers/LevelRenderer.java +++ b/core/src/fr/evolving/renderers/LevelRenderer.java @@ -146,7 +146,7 @@ public class LevelRenderer { * AssetLoader.ratio, 10, 0.5f, - LevelScreen.buttonLevels[i].level.Locked, + !LevelScreen.buttonLevels[i].level.Locked, LevelScreen.buttonLevels[i] .getLevelcolor(), LevelScreen.buttonLevels[found] @@ -162,7 +162,7 @@ public class LevelRenderer { * AssetLoader.ratio, 10, 0.5f, - LevelScreen.buttonLevels[i].level.Locked, + !LevelScreen.buttonLevels[i].level.Locked, LevelScreen.buttonLevels[i] .getLevelcolor(), LevelScreen.buttonLevels[found] diff --git a/core/src/fr/evolving/screens/LevelScreen.java b/core/src/fr/evolving/screens/LevelScreen.java index f9f9ebc..fc1d83e 100644 --- a/core/src/fr/evolving/screens/LevelScreen.java +++ b/core/src/fr/evolving/screens/LevelScreen.java @@ -51,7 +51,7 @@ public class LevelScreen implements Screen { public Image MenuSolo, MenuMulti, MenuScenario; private ImageTextButton cout, tech, cycle, temp, rayon, nrj; private TextButton buttonConnect, buttonPlay, buttonStat, buttonSave, - buttonApply, buttonPlaythis; + buttonApply, buttonPlaythis; private ServerList Statdata, Userdata, Gamedata; private Worldlist Worlddata; private Label Statdatalabel, Userdatalabel, Gamedatalabel, Worlddatalabel; @@ -63,9 +63,9 @@ public class LevelScreen implements Screen { public void play() { if (worlds.getState()!=State.notloaded && worlds.getState()!=State.databasefailed) { - Gdx.app.debug(getClass().getSimpleName(),"Afficher le monde 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(); } } @@ -208,17 +208,16 @@ public class LevelScreen implements Screen { 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); - Gdx.app.debug(getClass().getSimpleName(), "Ajout du niveau :" - + level.Name + " N°" + String.valueOf(level.aLevel)); + if (worlds.isDebug()) buttonLevels[i].setDisabled(false); + Gdx.app.debug(getClass().getSimpleName(), "Ajout du niveau :"+ level.Name + " N°" + 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(event.getListenerActor().toString(), - "Enter button "); - if (!abutton.isChecked()) + Gdx.app.debug(event.getListenerActor().toString(),"Enter button "); + if (!abutton.isChecked() && (!abutton.level.Locked || worlds.isDebug())) showlevel(abutton); } @@ -226,19 +225,16 @@ public class LevelScreen implements Screen { int pointer, Actor fromActor) { ButtonLevel abutton = (ButtonLevel) event .getListenerActor(); - Gdx.app.debug(event.getListenerActor().toString(), - "Enter button "); - if (!abutton.isChecked()) + Gdx.app.debug(event.getListenerActor().toString(),"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(); + ButtonLevel abutton = (ButtonLevel) event.getListenerActor(); if (worlds.isDebug()) { - abutton.setPosition(event.getStageX() - 56, - event.getStageY() - 20); + abutton.setPosition(event.getStageX() - 56, event.getStageY() - 20); } } }); @@ -277,8 +273,11 @@ public class LevelScreen implements Screen { selected=buttonLevels[0]; selected.setChecked(true); showlevel(selected); - Previous.setVisible(true); - Next.setVisible(true); + Previous.setVisible(!worlds.isFirstWorld()); + if (worlds.isDebug()) + Next.setVisible(!worlds.isRealLastWorld()); + else + Next.setVisible(!worlds.isLastWorld()); buttonPlay.setVisible(true); TextDescriptive.setVisible(true); } @@ -290,8 +289,7 @@ public class LevelScreen implements Screen { } } }); - Gdx.app.debug(getClass().getSimpleName(), - "Création des elements primordiaux du screen (stage, renderer, table)"); + Gdx.app.debug(getClass().getSimpleName(),"Création des elements primordiaux du screen (stage, renderer, table)"); stage = new Stage(AssetLoader.viewport); table = new Table(); Renderer = new LevelRenderer(this); @@ -315,16 +313,16 @@ public class LevelScreen implements Screen { MenuSolo.addAction(Actions.sequence( Actions.parallel(Actions.rotateBy(640, 0.5f), Actions.scaleTo(0.05f, 0.05f, 0.5f)), - Actions.run(new Runnable() { - public void run() { - level(); - } - }))); + Actions.run(new Runnable() { + public void run() { + level(); + } + }))); } }); MenuMulti = new Image(AssetLoader.Skin_level, "menu2"); MenuMulti - .setOrigin(MenuMulti.getWidth() / 2, MenuMulti.getHeight() / 2); + .setOrigin(MenuMulti.getWidth() / 2, MenuMulti.getHeight() / 2); MenuMulti.addListener(new ClickListener() { public void clicked(InputEvent event, float x, float y) { MenuSolo.addAction(Actions.fadeOut(0.5f)); @@ -332,11 +330,11 @@ public class LevelScreen implements Screen { MenuMulti.addAction(Actions.sequence( Actions.parallel(Actions.rotateBy(640, 0.5f), Actions.scaleTo(0.05f, 0.05f, 0.5f)), - Actions.run(new Runnable() { - public void run() { - level(); - } - }))); + Actions.run(new Runnable() { + public void run() { + level(); + } + }))); } }); MenuScenario = new Image(AssetLoader.Skin_level, "menu3"); @@ -349,11 +347,11 @@ public class LevelScreen implements Screen { MenuScenario.addAction(Actions.sequence( Actions.parallel(Actions.rotateBy(640, 0.5f), Actions.scaleTo(0.05f, 0.05f, 0.5f)), - Actions.run(new Runnable() { - public void run() { - level(); - } - }))); + Actions.run(new Runnable() { + public void run() { + level(); + } + }))); } }); Gdx.app.debug(getClass().getSimpleName(), "Création des boutons."); @@ -362,10 +360,27 @@ public class LevelScreen implements Screen { logosmall.setChecked(worlds.isDebug()); logosmall.addListener(new ClickListener() { 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(); - 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.updateUnlockLevels(); + worlds.setMaxWorldLevel(); + loadWorld(); + + } } }); TextDescriptive = new TextArea("Descriptif", AssetLoader.Skin_level,