diff --git a/core/src/fr/evolving/UI/ServerList.java b/core/src/fr/evolving/UI/ServerList.java new file mode 100644 index 0000000..b039266 --- /dev/null +++ b/core/src/fr/evolving/UI/ServerList.java @@ -0,0 +1,81 @@ +package fr.evolving.UI; + +import java.util.HashMap; +import java.util.Iterator; + +import com.badlogic.gdx.Gdx; +import com.badlogic.gdx.Net.HttpMethods; +import com.badlogic.gdx.Net.HttpRequest; +import com.badlogic.gdx.Net.HttpResponse; +import com.badlogic.gdx.Net.HttpResponseListener; +import com.badlogic.gdx.net.HttpParametersUtils; +import com.badlogic.gdx.scenes.scene2d.ui.List; +import com.badlogic.gdx.scenes.scene2d.ui.Skin; +import com.badlogic.gdx.utils.Array; +import com.badlogic.gdx.utils.Base64Coder; +import com.badlogic.gdx.utils.XmlReader; +import com.badlogic.gdx.utils.XmlReader.Element; + +import fr.evolving.database.Base; +import fr.evolving.database.Base.datatype; +import fr.evolving.database.LocalBase; +import fr.evolving.database.SqlBase; + +public class ServerList extends List { + HashMap parameters; + String url; + Base.datatype model; + + public ServerList(String url,Base.datatype model,Skin skin) { + super(skin); + this.url=url; + this.model=model; + parameters = new HashMap(); + parameters.put("version", "last"); + Refresh(); + } + + public boolean getBackend(String base,datatype model) { + String[] realbase=base.split(":"); + if (realbase[0].contains("mysql")) + return SqlBase.isHandling(model); + else + return LocalBase.isHandling(model); + } + + public void Refresh() { + HttpRequest httpGet = new HttpRequest(HttpMethods.GET); + httpGet.setUrl(url); + httpGet.setContent(HttpParametersUtils.convertHttpParameters(parameters)); + //If you want basic authentication, add this header + String authHeader = "Basic " + Base64Coder.encodeString("evolving:--evolvE2016__"); + httpGet.setHeader("Authorization", authHeader); + httpGet.setHeader("Content-Type", "text/xml"); + httpGet.setHeader("Accept", "text/xml"); + + + Gdx.net.sendHttpRequest (httpGet, new HttpResponseListener() { + public void handleHttpResponse(HttpResponse httpResponse) { + String Response = ""; + Array resultxml; + Array resultstring=new Array(); + if (httpResponse.getStatus().getStatusCode()==200) + Response = httpResponse.getResultAsString(); + XmlReader xml = new XmlReader(); + XmlReader.Element xml_element = xml.parse(Response); + resultxml= xml_element.getChildrenByName("server"); + for(Element child : resultxml) + if (getBackend(child.getText(),ServerList.this.model)) + resultstring.add(child.getText()); + ServerList.this.setItems(resultstring); + + } + @Override + public void failed(Throwable t) { + } + + public void cancelled() { + } + }); + } +} diff --git a/core/src/fr/evolving/assets/AssetLoader.java b/core/src/fr/evolving/assets/AssetLoader.java index 13133cf..df53a7c 100644 --- a/core/src/fr/evolving/assets/AssetLoader.java +++ b/core/src/fr/evolving/assets/AssetLoader.java @@ -53,6 +53,7 @@ import fr.evolving.automata.Positiver_I; import fr.evolving.automata.Positiver_II; import fr.evolving.automata.Positiver_III; import fr.evolving.automata.Transmuter; +import fr.evolving.database.LocalBase; import fr.evolving.screens.GameScreen; public class AssetLoader { diff --git a/core/src/fr/evolving/automata/Transmuter.java b/core/src/fr/evolving/automata/Transmuter.java index b637ea8..5aade6c 100644 --- a/core/src/fr/evolving/automata/Transmuter.java +++ b/core/src/fr/evolving/automata/Transmuter.java @@ -1,5 +1,6 @@ package fr.evolving.automata; +import java.io.Serializable; import java.util.HashMap; import java.util.Iterator; @@ -10,7 +11,7 @@ import com.badlogic.gdx.utils.ObjectMap.Entry; import com.badlogic.gdx.utils.ObjectMap.Values; import com.badlogic.gdx.utils.OrderedMap; -public abstract class Transmuter implements Cloneable { +public abstract class Transmuter implements Cloneable,Serializable { public enum CaseType{Rien,Cuivre_seul,Fibre_seul,Cuivre,Fibre,Tout,Nimporte}; public enum Class{Structure,Charge,Direction,Filtrage,Synthese,Detection,Divers,Scenario}; public enum Angular{A00,A90,A180,A270}; diff --git a/core/src/fr/evolving/automata/World.java b/core/src/fr/evolving/automata/World.java deleted file mode 100644 index ffd4cc4..0000000 --- a/core/src/fr/evolving/automata/World.java +++ /dev/null @@ -1,49 +0,0 @@ -package fr.evolving.automata; - -import java.io.Serializable; - -public class World implements Serializable{ - String Name; - String Description; - String Element; - Integer[] Current; - Integer[] Victory; - Integer X; - Integer Y; - Integer Tech; - Integer Cout; - Grid World; - Integer Cycle; - Integer Temp; - Integer Rayon; - Integer Nrj; - Integer Maxcycle; - Integer Maxtemp; - Integer Maxrayon; - Integer Maxnrj; - String Tuto; - Integer[][] Link; - -public void World(String Name,String Description,String Element,Integer[] Current,Integer[] Victory,Integer X,Integer Y,Integer Tech,Integer Cout,Grid World,Integer Cycle,Integer Temp,Integer Rayon,Integer Nrj,Integer Maxcycle,Integer Maxtemp,Integer Maxrayon,Integer Maxnrj,String Tuto,Integer[][] Link){ - this.Name=Name; - this.Description=Description; - this.Element=Element; - this.Current=Current; - this.Victory=Victory; - this.X=X; - this.Y=Y; - this.Tech=Tech; - this.Cout=Cout; - this.World=World; - this.Cycle=Cycle; - this.Temp=Temp; - this.Rayon=Rayon; - this.Nrj=Nrj; - this.Maxcycle=Maxcycle; - this.Maxtemp=Maxtemp; - this.Maxrayon=Maxrayon; - this.Maxnrj=Maxnrj; - this.Tuto=Tuto; - this.Link=Link; -} -} diff --git a/core/src/fr/evolving/database/Base.java b/core/src/fr/evolving/database/Base.java new file mode 100644 index 0000000..e288c1e --- /dev/null +++ b/core/src/fr/evolving/database/Base.java @@ -0,0 +1,92 @@ +package fr.evolving.database; + +import com.badlogic.gdx.utils.Array; + +import fr.evolving.automata.Grid; +import fr.evolving.automata.Level; +import fr.evolving.automata.Transmuter; + +public abstract class Base { + public enum datatype{statdata,userdata,gamedata} + + public Base(datatype model,String param) { + } + + //Gestion type Gamebase + + public Array getworlds() { + return null; + } + + public Array getworld(String description) { + return null; + } + + public boolean setworld(Array world, String description) { + return false; + } + + public boolean deleteworld(String description) { + return false; + } + + //Gestion type Userbase + public boolean getlevellock(int user,int level){ + return false; + } + + public boolean setlevelunlock(int user,int level){ + return false; + } + + public Array getTransmuters(int user){ + return null; + } + + public boolean setTransmuters(int user,Array transmuters){ + return false; + } + + public int getResearchpoint(int user){ + return 0; + } + + public boolean setResearchpoint(int user, int point){ + return false; + } + + public Grid getGrid(int user,int level, int place){ + return null; + } + + public boolean setGrid(int user,int level, Grid data){ + return false; + } + + public Array getGrids(int user, int level){ + return null; + } + + //Gestion type Stat + + + //Commun + + public boolean Eraseall(datatype base){ + return false; + } + + public static boolean isHandling(datatype base){ + return false; + } + + public void Close() { + } + + public String getprefix() { + return ""; + } + + + +} diff --git a/core/src/fr/evolving/database/LocalBase.java b/core/src/fr/evolving/database/LocalBase.java new file mode 100644 index 0000000..5e36d14 --- /dev/null +++ b/core/src/fr/evolving/database/LocalBase.java @@ -0,0 +1,308 @@ +package fr.evolving.database; + +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; +import java.io.ObjectInputStream; +import java.io.ObjectOutputStream; +import java.nio.charset.Charset; + +import javax.xml.bind.DatatypeConverter; + +import com.badlogic.gdx.Gdx; +import com.badlogic.gdx.sql.Database; +import com.badlogic.gdx.sql.DatabaseCursor; +import com.badlogic.gdx.sql.DatabaseFactory; +import com.badlogic.gdx.sql.SQLiteGdxException; +import com.badlogic.gdx.utils.Array; + +import fr.evolving.automata.Grid; +import fr.evolving.automata.Level; +import fr.evolving.automata.Transmuter; +import fr.evolving.database.Base.datatype; + +public class LocalBase extends Base { + private static Database dbHandler; + private String databasename = "base.db"; + private String creation; + + //Contructeur de la base de donnée + + public LocalBase(datatype model,String param) { + super(model,param); + String[] params=param.split(":"); + if (params.length>1) + databasename=params[1]; + if (dbHandler!=null) + Gdx.app.log("Local", "Reprise de la base '"+databasename+"', table:"+model.toString()); + else + { + Gdx.app.log("Local", "Utilisation de la base '"+databasename+"', table:"+model.toString()); + dbHandler = DatabaseFactory.getNewDatabase(databasename,1, "", null); + dbHandler.setupDatabase(); + + try { + dbHandler.openOrCreateDatabase(); + } + catch (SQLiteGdxException e) { + e.printStackTrace(); + } + } + try { + if (model==datatype.statdata) + creation = "create table if not exists stat (id integer)"; + else if (model==datatype.userdata) { + dbHandler.execSQL("CREATE TABLE if not exists locks(date DATETIME DEFAULT CURRENT_TIMESTAMP, level INTEGER NOT NULL, user INTEGER NOT NULL, PRIMARY KEY(level,user));"); + dbHandler.execSQL("CREATE TABLE if not exists grids(date DATETIME DEFAULT CURRENT_TIMESTAMP, level INTEGER NOT NULL, user INTEGER NOT NULL, object TEXT, PRIMARY KEY(level,user,date));"); + dbHandler.execSQL("CREATE TABLE if not exists transmuters(date DATETIME DEFAULT CURRENT_TIMESTAMP, user INTEGER NOT NULL, object TEXT, PRIMARY KEY(user));"); + dbHandler.execSQL("CREATE TABLE if not exists research(date DATETIME DEFAULT CURRENT_TIMESTAMP, user INTEGER NOT NULL, value INT, PRIMARY KEY(user));"); + + } + else + dbHandler.execSQL("CREATE TABLE if not exists worlds(date DATETIME DEFAULT CURRENT_TIMESTAMP, desc TEXT NOT NULL, object TEXT, PRIMARY KEY(desc));"); + } catch (SQLiteGdxException e) { + e.printStackTrace(); + } + } + + //Gestion model type gamedata + + public Array getworlds() { + DatabaseCursor cursor=null; + try { + cursor = dbHandler.rawQuery("select desc,date from worlds;"); + } catch (SQLiteGdxException e) { + return null; + } + Array returnvalue=new Array(); + while (cursor.next()) + returnvalue.add(cursor.getString(0)); + return returnvalue; + } + + public Array getworld(String description) { + DatabaseCursor cursor=null; + try { + cursor = dbHandler.rawQuery("select object from worlds where desc='"+description+"';"); + } catch (SQLiteGdxException e) { + return null; + } + Level[] mc=null; + if (cursor.next()) + try { + byte[] bytes = DatatypeConverter.parseBase64Binary(cursor.getString(0)); + ByteArrayInputStream bais = new ByteArrayInputStream(bytes); + ObjectInputStream ins = new ObjectInputStream(bais); + mc=(Level[]) ins.readObject(); + ins.close(); + return new Array(mc); + } + catch (Exception e) { + e.printStackTrace(); + } + return null; + } + + public boolean deleteworld(String description) { + try { + dbHandler.rawQuery("delete from worlds where desc='"+description+"';"); + } catch (SQLiteGdxException e) { + return false; + } + return true; + } + + public boolean setworld(Array world, String description) { + String encoded = ""; + try { + ByteArrayOutputStream bos = new ByteArrayOutputStream(); + ObjectOutputStream oos = new ObjectOutputStream(bos); + oos.writeObject(world.toArray()); + oos.flush(); + oos.close(); + bos.close(); + byte[] bytes = bos.toByteArray(); + encoded = DatatypeConverter.printBase64Binary(bytes); + dbHandler.rawQuery("replace into worlds (desc,object) values ('"+description+"','"+encoded+"');"); + } catch (Exception e) { + return false; + } + return true; + } + + //Gestion de données type userdata + + public boolean getlevellock(int user,int level) { + DatabaseCursor cursor=null; + try { + cursor=dbHandler.rawQuery("select user from locks where user="+user+" and level="+level+";"); + } catch (SQLiteGdxException e) { + return false; + } + if (cursor.next()) + return true; + else return false; + } + + public boolean setlevelunlock(int user,int level){ + try { + dbHandler.rawQuery("insert into locks (user,level) values ("+user+","+level+");"); + } catch (SQLiteGdxException e) { + return false; + } + return true; + } + + public Array getTransmuters(int user){ + DatabaseCursor cursor=null; + try { + cursor = dbHandler.rawQuery("select object from transmuters where user="+user+";"); + } catch (SQLiteGdxException e) { + return null; + } + Transmuter[] mc=null; + if (cursor.next()) + try { + byte[] bytes = DatatypeConverter.parseBase64Binary(cursor.getString(0)); + ByteArrayInputStream bais = new ByteArrayInputStream(bytes); + ObjectInputStream ins = new ObjectInputStream(bais); + mc=(Transmuter[]) ins.readObject(); + ins.close(); + return new Array(mc); + } + catch (Exception e) { + e.printStackTrace(); + } + return null; + } + + public boolean setTransmuters(int user,Array transmuters){ + String encoded = ""; + try { + ByteArrayOutputStream bos = new ByteArrayOutputStream(); + ObjectOutputStream oos = new ObjectOutputStream(bos); + oos.writeObject(transmuters.toArray()); + oos.flush(); + oos.close(); + bos.close(); + byte[] bytes = bos.toByteArray(); + encoded = DatatypeConverter.printBase64Binary(bytes); + dbHandler.rawQuery("replace into transmuters (user,object) values ("+user+",'"+encoded+"');"); + } catch (Exception e) { + return false; + } + return true; + } + + + public int getResearchpoint(int user){ + DatabaseCursor cursor=null; + try { + cursor = dbHandler.rawQuery("select value from research where user="+user+";"); + } catch (SQLiteGdxException e) { + return 0; + } + if (cursor.next()) + return cursor.getInt(0); + else + return 0; + } + + public boolean setResearchpoint(int user, int point){ + try { + dbHandler.rawQuery("replace into research (user,value) values ("+user+","+point+");"); + } catch (Exception e) { + return false; + } + return true; + } + + public Grid getGrid(int user,int level,int place){ + DatabaseCursor cursor=null; + try { + cursor = dbHandler.rawQuery("select object from grids where user="+user+" and level="+level+" order by date desc limit "+place+",1;"); + } catch (SQLiteGdxException e) { + return null; + } + Grid mc=null; + if (cursor.next()) + try { + byte[] bytes = DatatypeConverter.parseBase64Binary(cursor.getString(0)); + ByteArrayInputStream bais = new ByteArrayInputStream(bytes); + ObjectInputStream ins = new ObjectInputStream(bais); + mc=(Grid) ins.readObject(); + ins.close(); + return mc; + } + catch (Exception e) { + e.printStackTrace(); + } + return null; + } + + public boolean setGrid(int user,int level, Grid data){ + String encoded = ""; + try { + ByteArrayOutputStream bos = new ByteArrayOutputStream(); + ObjectOutputStream oos = new ObjectOutputStream(bos); + oos.writeObject(data); + oos.flush(); + oos.close(); + bos.close(); + byte[] bytes = bos.toByteArray(); + encoded = DatatypeConverter.printBase64Binary(bytes); + dbHandler.rawQuery("insert into grids (user,level,object) values ("+user+","+level+",'"+encoded+"');"); + } catch (Exception e) { + return false; + } + return true; + } + + public Array getGrids(int user, int level){ + DatabaseCursor cursor=null; + try { + cursor = dbHandler.rawQuery("select date from grids order by date desc;"); + } catch (SQLiteGdxException e) { + return null; + } + Array returnvalue=new Array(); + while (cursor.next()) + returnvalue.add(cursor.getString(0)); + return returnvalue; + } + + //Gestion type Stat + + + //Commun + + public boolean Eraseall(datatype base){ + try { + dbHandler.execSQL("drop table if exists stat;"); + dbHandler.execSQL("drop table if exists locks;"); + dbHandler.execSQL("drop table if exists grids;"); + dbHandler.execSQL("drop table if exists global;"); + dbHandler.execSQL("drop table if exists worlds;"); + return true; + } catch (SQLiteGdxException e1) { + return false; + } + } + + public void Close() { + try { + dbHandler.closeDatabase(); + } catch (SQLiteGdxException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + + public String getprefix() { + return "local"; + } + + public static boolean isHandling(datatype base){ + return true; + } + +} diff --git a/core/src/fr/evolving/database/SqlBase.java b/core/src/fr/evolving/database/SqlBase.java new file mode 100644 index 0000000..2d49d91 --- /dev/null +++ b/core/src/fr/evolving/database/SqlBase.java @@ -0,0 +1,21 @@ +package fr.evolving.database; + +import com.badlogic.gdx.Gdx; +import com.badlogic.gdx.sql.DatabaseFactory; +import com.badlogic.gdx.sql.SQLiteGdxException; + +import fr.evolving.database.Base.datatype; + +public class SqlBase extends Base{ + + public SqlBase(datatype model,String param) { + super(model,param); + } + + public static boolean isHandling(datatype base){ + if (base==datatype.statdata) + return false; + else + return true; + } +} \ No newline at end of file diff --git a/core/src/fr/evolving/screens/GameScreen.java b/core/src/fr/evolving/screens/GameScreen.java index 94b7091..eab59fb 100644 --- a/core/src/fr/evolving/screens/GameScreen.java +++ b/core/src/fr/evolving/screens/GameScreen.java @@ -72,6 +72,8 @@ import fr.evolving.automata.Positiver_III; import fr.evolving.automata.Transmuter; import fr.evolving.automata.Transmuter.Angular; import fr.evolving.automata.Transmuter.CaseType; +import fr.evolving.database.LocalBase; +import fr.evolving.database.Base.datatype; import fr.evolving.inputs.InputHandler; public class GameScreen implements Screen { @@ -530,13 +532,15 @@ public class GameScreen implements Screen { void map_cleaner(float realx, float realy,int x, int y,boolean alone,int button,calling call) { for(x=0;x=2) map.initzoom(); } else if (caller.getName()=="raz") { + LocalBase test2=new LocalBase(datatype.userdata,"local:test.db"); + level.Grid=test2.getGrid(0,0, 1); + level.Grid.tiling_transmuter(); + level.Grid.tiling_copper(); + map.redraw(53); } else if (caller.getName()=="save") { + LocalBase test2=new LocalBase(datatype.userdata,"local:test.db"); + for(String tester :test2.getGrids(0,0)) + Gdx.app.debug("test",tester); } else if (caller.getName()=="levels") { Gdx.app.debug("Barre","Affichage des niveaux."); diff --git a/core/src/fr/evolving/screens/LevelScreen.java b/core/src/fr/evolving/screens/LevelScreen.java index abb99a2..105c414 100644 --- a/core/src/fr/evolving/screens/LevelScreen.java +++ b/core/src/fr/evolving/screens/LevelScreen.java @@ -9,6 +9,8 @@ import com.badlogic.gdx.scenes.scene2d.InputEvent; import com.badlogic.gdx.scenes.scene2d.Stage; import com.badlogic.gdx.scenes.scene2d.ui.Button; import com.badlogic.gdx.scenes.scene2d.ui.ImageButton; +import com.badlogic.gdx.scenes.scene2d.ui.List; +import com.badlogic.gdx.scenes.scene2d.ui.Label; import com.badlogic.gdx.scenes.scene2d.ui.Skin; import com.badlogic.gdx.scenes.scene2d.ui.Table; import com.badlogic.gdx.scenes.scene2d.ui.TextArea; @@ -18,6 +20,7 @@ import com.badlogic.gdx.scenes.scene2d.ui.TextField; import com.badlogic.gdx.scenes.scene2d.utils.ChangeListener; import com.badlogic.gdx.scenes.scene2d.utils.ClickListener; import com.badlogic.gdx.scenes.scene2d.Actor; +import com.badlogic.gdx.utils.Array; import com.badlogic.gdx.utils.viewport.FillViewport; import com.badlogic.gdx.utils.viewport.FitViewport; import com.badlogic.gdx.utils.viewport.ScalingViewport; @@ -26,16 +29,21 @@ import com.badlogic.gdx.utils.viewport.StretchViewport; import fr.evolving.worlds.LevelRenderer; import fr.evolving.UI.ButtonLevel; import fr.evolving.UI.Objectives; +import fr.evolving.UI.ServerList; import fr.evolving.game.main; import fr.evolving.inputs.InputHandler; + import java.util.Timer; import java.util.TimerTask; import fr.evolving.assets.AssetLoader; import fr.evolving.assets.SaveObject; import fr.evolving.automata.Level; +import fr.evolving.automata.Transmuter; +import fr.evolving.database.Base; +import fr.evolving.database.Base.datatype; +import fr.evolving.database.LocalBase; import fr.evolving.effects.Laser; - public class LevelScreen implements Screen { public ButtonLevel[] buttonLevels; private LevelRenderer Renderer; @@ -48,6 +56,8 @@ public class LevelScreen implements Screen { public ImageButton logosmall; private ImageTextButton cout,tech,cycle,temp,rayon,nrj; private TextButton buttonConnect,buttonPlay,buttonStat; + private ServerList Statdata,Userdata,Gamedata; + private Label Statdatalabel, Userdatalabel, Gamedatalabel; private Level[] thelevels; private TextArea TextDescriptive; public int world; @@ -62,6 +72,43 @@ public class LevelScreen implements Screen { return max; } + public void menu() { + cout.setVisible(false); + tech.setVisible(false); + cycle.setVisible(false); + temp.setVisible(false); + rayon.setVisible(false); + nrj.setVisible(false); + Previous.setVisible(false); + Next.setVisible(false); + Exit.setVisible(false); + buttonPlay.setVisible(false); + TextDescriptive.setVisible(false); + SetButtonStat(); + } + + public void SetButtonConnect() { + buttonStat.setColor(buttonConnect.getColor()); + buttonConnect.setColor(1f,0,0,1f); + Statdata.setVisible(true); + Userdata.setVisible(true); + Gamedata.setVisible(true); + Statdatalabel.setVisible(true); + Userdatalabel.setVisible(true); + Gamedatalabel.setVisible(true); + } + + public void SetButtonStat() { + buttonConnect.setColor(buttonStat.getColor()); + buttonStat.setColor(1f,0,0,1f); + Statdata.setVisible(false); + Userdata.setVisible(false); + Gamedata.setVisible(false); + Statdatalabel.setVisible(false); + Userdatalabel.setVisible(false); + Gamedatalabel.setVisible(false); + } + public void loadWorld(int aworld) { int i=0; if (buttonLevels!=null) @@ -98,7 +145,6 @@ public class LevelScreen implements Screen { } }); } - } for (int j=0;j<10;j++) { if (buttonLevels[j]!=null) { @@ -133,18 +179,30 @@ public class LevelScreen implements Screen { logosmall.setPosition(20, AssetLoader.height-175+logosmall.getHeight()/2); TextDescriptive = new TextArea("Descriptif", AssetLoader.Skin_level,"Descriptif"); TextDescriptive.setBounds(15, 15, 1185, 100); - buttonConnect = new TextButton("Connexions", AssetLoader.Skin_level,"Bouton"); + buttonConnect = new TextButton("Connexions", AssetLoader.Skin_ui); buttonConnect.setBounds(1480, AssetLoader.height-60, 190, 40); - buttonPlay = new TextButton("Jouer", AssetLoader.Skin_level,"Bouton"); + buttonConnect.addListener(new ClickListener() { + public void clicked(InputEvent event, float x, float y) { + if (!Statdata.isVisible()) + SetButtonConnect(); + } + }); + buttonPlay = new TextButton("Jouer", AssetLoader.Skin_ui); buttonPlay.setBounds(1040, 20, 150, 40); buttonPlay.addListener(new ClickListener(){ @Override - public void touchUp(InputEvent event, float x, float y, int pointer, int button) { + public void clicked(InputEvent event, float x, float y) { ((Game)Gdx.app.getApplicationListener()).setScreen(new GameScreen(selected.level)); } }); - buttonStat = new TextButton("Statistiques", AssetLoader.Skin_level,"Bouton"); + buttonStat = new TextButton("Statistiques", AssetLoader.Skin_ui); buttonStat.setBounds(1710, AssetLoader.height-60, 190, 40); + buttonStat.addListener(new ClickListener() { + public void clicked(InputEvent event, float x, float y) { + if (Statdata.isVisible()) + SetButtonStat(); + } + }); Exit=new ImageButton(AssetLoader.Skin_level,"Exit"); Exit.setPosition(1110, AssetLoader.height-Exit.getHeight()-5); Exit.addListener(new ClickListener(){ @@ -193,9 +251,47 @@ public class LevelScreen implements Screen { Victory=new Objectives(); Victory.setVictory(new int[]{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}); Victory.setPosition(1216, 185); - Gdx.app.debug(getClass().getSimpleName(),"Création des boutons de niveau."); - thelevels= SaveObject.initObject(); + String url="http://evolving.fr/servers/list.xml"; + Statdata=new ServerList(url,Base.datatype.statdata,AssetLoader.Skin_ui); + Statdatalabel=new Label("Stockage des statistiques:", AssetLoader.Skin_ui, "grey"); + Statdata.setBounds(1480, AssetLoader.height-300, 420, 200); + Statdatalabel.setPosition(1480, AssetLoader.height-100); + Userdata=new ServerList(url,Base.datatype.userdata,AssetLoader.Skin_ui); + Userdatalabel=new Label("Stockage des données du joueur:", AssetLoader.Skin_ui, "grey"); + Userdata.setBounds(1480, AssetLoader.height-600, 420, 200); + Userdatalabel.setPosition(1480, AssetLoader.height-400); + Gamedata=new ServerList(url,Base.datatype.gamedata,AssetLoader.Skin_ui); + Gamedatalabel=new Label("Stockage des données du jeu:", AssetLoader.Skin_ui, "grey"); + Gamedata.setBounds(1480, AssetLoader.height-900, 420, 200); + Gamedatalabel.setPosition(1480, AssetLoader.height-700); + //menu(); + //Gdx.app.debug(getClass().getSimpleName(),"Création des boutons de niveau."); + //thelevels= SaveObject.initObject(); + //loadWorld(world); + LocalBase test=new LocalBase(datatype.gamedata,"local:test.db"); + //for(String tester :test.getworlds()) + // Gdx.app.debug("test",tester); + //test.setworld(thelevels, "test pour voir"); + + + //thelevels=null; + thelevels=test.getworld("test pour voir").toArray(); + test.getworld("test pour voire"); + //thelevels[0].Name="anus vivant"; + //test.setworld(thelevels, "test pour voir"); + //test.deleteworld("pop"); loadWorld(world); + + LocalBase test2=new LocalBase(datatype.userdata,"local:test.db"); + test.setlevelunlock(0, 1); + Gdx.app.debug("lock",String.valueOf(test.getlevellock(0, 1))); + Gdx.app.debug("lock",String.valueOf(test.getlevellock(110, 1))); + Gdx.app.debug("research",String.valueOf(test.getResearchpoint(0))); + test.setResearchpoint(0, 5000); + Gdx.app.debug("research",String.valueOf(test.getResearchpoint(0))); + test.setTransmuters(0, AssetLoader.allTransmuter); + Array retest=test.getTransmuters(0); + Gdx.app.debug("research",String.valueOf(test.getResearchpoint(0))); } @Override @@ -214,11 +310,6 @@ public class LevelScreen implements Screen { @Override public void show() { Gdx.app.log("*****","Affichage du choix des mondes & niveaux."); - for (int i=0;i<10;i++) { - if (buttonLevels[i]!=null) { - stage.addActor(buttonLevels[i]); - } - } table.setFillParent(true); stage.addActor(TextDescriptive); stage.addActor(Exit); @@ -235,6 +326,12 @@ public class LevelScreen implements Screen { stage.addActor(rayon); stage.addActor(Victory); stage.addActor(logosmall); + stage.addActor(Statdata); + stage.addActor(Statdatalabel); + stage.addActor(Userdata); + stage.addActor(Userdatalabel); + stage.addActor(Gamedata); + stage.addActor(Gamedatalabel); Gdx.input.setInputProcessor(stage); Gdx.app.debug("AssetLoader","Début dans la bande son \'intro\'"); AssetLoader.intro.setLooping(true); diff --git a/core/src/fr/evolving/worlds/LevelRenderer.java b/core/src/fr/evolving/worlds/LevelRenderer.java index 1af2dbf..ef0364a 100644 --- a/core/src/fr/evolving/worlds/LevelRenderer.java +++ b/core/src/fr/evolving/worlds/LevelRenderer.java @@ -83,38 +83,42 @@ public class LevelRenderer { batcher2.setColor(Color.WHITE); Texture_logobig=AssetLoader.Skin_level.getRegion("logo3"); batcher2.draw(Texture_logobig,120, AssetLoader.height-Texture_logobig.getRegionHeight()); - font.draw(batcher2, LevelScreen.selected.level.Name, 15, 145); - if (LevelScreen.selected!=null && LevelScreen.selected.level.Tech>0) - font.draw(batcher2, "Recompenses", 1215, AssetLoader.height-15); - if (LevelScreen.selected!=null && LevelScreen.selected.level.Cout>0) { - font.draw(batcher2, "Ressources", 1215, 145); - font.draw(batcher2, "Objectifs", 1215, 295); - } - if (LevelScreen.selected!=null && LevelScreen.selected.level.aWorld>0) - font.draw(batcher2, "Handicaps", 1215, 605); - font.draw(batcher2, "", 1215, 145); + if (LevelScreen.selected!=null) { + font.draw(batcher2, LevelScreen.selected.level.Name, 15, 145); + if (LevelScreen.selected.level.Tech>0) + font.draw(batcher2, "Recompenses", 1215, AssetLoader.height-15); + if (LevelScreen.selected.level.Cout>0) { + font.draw(batcher2, "Ressources", 1215, 145); + font.draw(batcher2, "Objectifs", 1215, 295); + } + + if (LevelScreen.selected.level.aWorld>0) + font.draw(batcher2, "Handicaps", 1215, 605); + font.draw(batcher2, "", 1215, 145); + } batcher2.end(); - Gdx.gl.glEnable(GL20.GL_BLEND); + Gdx.gl.glEnable(GL20.GL_BLEND); shapeRenderer.begin(ShapeType.Filled); shapeRenderer.setProjectionMatrix(AssetLoader.Camera.combined); shapeRenderer.setColor(0.5f, 0.5f, 0.5f, 0.5f); - shapeRenderer.rect(10, 10, 1190, 140); - if (LevelScreen.selected!=null && LevelScreen.selected.level.Cout>0) { - shapeRenderer.rect(1210, 10, 250, 140); - shapeRenderer.rect(1210, 160,250, 140); + if (LevelScreen.selected!=null) { + shapeRenderer.rect(10, 10, 1190, 140); + if (LevelScreen.selected.level.Cout>0) { + shapeRenderer.rect(1210, 10, 250, 140); + shapeRenderer.rect(1210, 160,250, 140); + } + if (LevelScreen.selected.level.aWorld>0) + shapeRenderer.rect(1210, 310,250, 300); + if (LevelScreen.selected.level.Tech>0) + shapeRenderer.rect(1210, 620,250, AssetLoader.height-630); } - if (LevelScreen.selected!=null && LevelScreen.selected.level.aWorld>0) - shapeRenderer.rect(1210, 310,250, 300); - if (LevelScreen.selected!=null && LevelScreen.selected.level.Tech>0) - shapeRenderer.rect(1210, 620,250, AssetLoader.height-630); shapeRenderer.rect(1470, 10, 440, AssetLoader.height-20); shapeRenderer.end(); - + if (LevelScreen.buttonLevels!=null) for (int i=0;i