fix: modification du code pour fonctionnement de la base sous android correction de bogue sur la base de donnée animation du menu

This commit is contained in:
Nicolas Hordé 2016-01-16 01:57:24 +01:00
parent 3a6ac43a75
commit b53166cca0
6 changed files with 456 additions and 301 deletions

View File

@ -61,10 +61,11 @@ public class ServerList extends List {
Gdx.net.sendHttpRequest (httpGet, new HttpResponseListener() { Gdx.net.sendHttpRequest (httpGet, new HttpResponseListener() {
public void handleHttpResponse(HttpResponse httpResponse) { public void handleHttpResponse(HttpResponse httpResponse) {
String Response = "";
Array<Element> resultxml;
Array<String> resultstring=new Array<String>();
if (httpResponse.getStatus().getStatusCode()==200) if (httpResponse.getStatus().getStatusCode()==200)
{
String Response = "";
Array<Element> resultxml;
Array<String> resultstring=new Array<String>();
Response = httpResponse.getResultAsString(); Response = httpResponse.getResultAsString();
XmlReader xml = new XmlReader(); XmlReader xml = new XmlReader();
XmlReader.Element xml_element = xml.parse(Response); XmlReader.Element xml_element = xml.parse(Response);
@ -79,6 +80,7 @@ public class ServerList extends List {
ServerList.this.setSelectedIndex(resultstring.indexOf(old, false)); ServerList.this.setSelectedIndex(resultstring.indexOf(old, false));
if (list!=null && ServerList.this.model==Base.datatype.gamedata) if (list!=null && ServerList.this.model==Base.datatype.gamedata)
list.Refresh(); list.Refresh();
}
} }
@Override @Override
public void failed(Throwable t) { public void failed(Throwable t) {

View File

@ -1,5 +1,6 @@
package fr.evolving.UI; package fr.evolving.UI;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.scenes.scene2d.ui.List; import com.badlogic.gdx.scenes.scene2d.ui.List;
import com.badlogic.gdx.scenes.scene2d.ui.Skin; import com.badlogic.gdx.scenes.scene2d.ui.Skin;
import com.badlogic.gdx.utils.Array; import com.badlogic.gdx.utils.Array;
@ -15,10 +16,11 @@ public class Worldlist extends List {
} }
public void Refresh() { public void Refresh() {
Array<String> worlds=AssetLoader.Datahandler.game().getworlds(); Array<String> worlds=null;
String world=Preference.prefs.getString("world"); if (AssetLoader.Datahandler.game()!=null)
if (!worlds.contains(world, false)) worlds=AssetLoader.Datahandler.game().getworlds();
worlds.add(world); if (worlds==null)
worlds=new Array<String>();
this.setItems(worlds); this.setItems(worlds);
} }
} }

View File

@ -205,12 +205,21 @@ public class AssetLoader {
Datahandler.RegisterBackend(SqlBase.class); Datahandler.RegisterBackend(SqlBase.class);
Databasemanagerfrompref(); Databasemanagerfrompref();
} }
public static void Databasemanagerfrompref() { public static void Databasemanagerfrompref() {
Datahandler.CloseAll(); Datahandler.CloseAll();
Datahandler.Attach(datatype.userdata, Preference.prefs.getString("userdata")); if (Datahandler.Attach(datatype.userdata, Preference.prefs.getString("userdata")))
Datahandler.Attach(datatype.statdata, Preference.prefs.getString("statdata")); Gdx.app.debug("AssetLoader","Base user ok");
Datahandler.Attach(datatype.gamedata, Preference.prefs.getString("gamedata")); else
Gdx.app.debug("AssetLoader","Base user erreur");
if (Datahandler.Attach(datatype.statdata, Preference.prefs.getString("statdata")))
Gdx.app.debug("AssetLoader","Base stat ok");
else
Gdx.app.debug("AssetLoader","Base stat erreur");
if (Datahandler.Attach(datatype.gamedata, Preference.prefs.getString("gamedata")))
Gdx.app.debug("AssetLoader","Base jeu ok");
else
Gdx.app.debug("AssetLoader","Base jeu erreur");
} }
public static Transmuter getTransmuter(String Name) { public static Transmuter getTransmuter(String Name) {

View File

@ -25,6 +25,10 @@ public class DatabaseManager {
return bases[Base.datatype.gamedata.ordinal()]; return bases[Base.datatype.gamedata.ordinal()];
} }
public boolean verifyall() {
return (bases[0]!=null && bases[1]!=null && bases[2]!=null);
}
public DatabaseManager(){ public DatabaseManager(){
bases=new Base[3]; bases=new Base[3];
old=new String[3]; old=new String[3];
@ -53,7 +57,11 @@ public class DatabaseManager {
return true; return true;
} }
else else
{
bases[model.ordinal()]=null;
old[model.ordinal()]=null;
return false; return false;
}
} }
public Base getBackend(Base.datatype model, String Url) { public Base getBackend(Base.datatype model, String Url) {
@ -64,9 +72,11 @@ public class DatabaseManager {
for(Class<?> classe:backends) { for(Class<?> classe:backends) {
Base back; Base back;
try { try {
back = (Base) classe.getDeclaredConstructor(cArg).newInstance(model,Url); back = (Base) classe.newInstance();
if (back.getprefix().equals(Type)) if (back.getprefix().equals(Type)) {
back = (Base) classe.getDeclaredConstructor(cArg).newInstance(model,Url);
return back; return back;
}
} catch (InstantiationException | IllegalAccessException } catch (InstantiationException | IllegalAccessException
| IllegalArgumentException | InvocationTargetException | IllegalArgumentException | InvocationTargetException
| NoSuchMethodException | SecurityException e) { | NoSuchMethodException | SecurityException e) {

View File

@ -20,6 +20,7 @@ import com.badlogic.gdx.sql.DatabaseCursor;
import com.badlogic.gdx.sql.DatabaseFactory; import com.badlogic.gdx.sql.DatabaseFactory;
import com.badlogic.gdx.sql.SQLiteGdxException; import com.badlogic.gdx.sql.SQLiteGdxException;
import com.badlogic.gdx.utils.Array; import com.badlogic.gdx.utils.Array;
import com.badlogic.gdx.utils.Base64Coder;
import fr.evolving.assets.AssetLoader; import fr.evolving.assets.AssetLoader;
import fr.evolving.automata.Grid; import fr.evolving.automata.Grid;
@ -30,203 +31,214 @@ import fr.evolving.database.Base.datatype;
public class LocalBase extends Base { public class LocalBase extends Base {
private static Database dbHandler; private static Database dbHandler;
private String databasename = "base.db"; private String databasename = "base.db";
private String creation; private String creation;
private String param; private String param;
//Contructeur de la base de donnée //Contructeur de la base de donnée
public String getParam() { public String getParam() {
return this.param; return this.param;
} }
public LocalBase() { public LocalBase() {
} }
public LocalBase(datatype model,String param) { public LocalBase(datatype model,String param) {
super(model,param); super(model,param);
String[] params=param.split(":"); String[] params=param.split(":");
this.param=param; this.param=param;
if (params.length>1) if (params.length>1)
databasename=params[1]; databasename=params[1];
switch(Gdx.app.getType()) { switch(Gdx.app.getType()) {
case Android: case Android:
try { try {
FileChannel source = ((FileInputStream) Gdx.files.internal("bases/"+databasename).read()).getChannel(); if (!Gdx.files.absolute("/data/data/fr.evolving.game.android/databases/"+databasename).exists()) {
FileChannel destination = new FileOutputStream("/data/data/fr.evolving.game.android/databases/"+databasename).getChannel(); Gdx.app.log("Base", "Copie de la base de donnee android");
destination.transferFrom(source, 0, source.size()); byte[] ByteSource = Gdx.files.internal("bases/"+databasename).readBytes();
source.close(); FileOutputStream destination = new FileOutputStream("/data/data/fr.evolving.game.android/databases/"+databasename);
destination.close(); destination.write(ByteSource);
destination.close();
}
} catch (IOException e1) { } catch (IOException e1) {
// TODO Auto-generated catch block // TODO Auto-generated catch block
e1.printStackTrace(); e1.printStackTrace();
} }
case Desktop: break;
FileHandle newbase=Gdx.files.local(databasename); case Desktop:
if (!newbase.exists()) Gdx.app.log("Base", "Copie de la base de donnee desktop");
Gdx.files.internal("bases/"+databasename).copyTo(newbase); FileHandle newbase=Gdx.files.local(databasename);
} try {
if (dbHandler!=null) if (!newbase.exists())
Gdx.app.log("Local", "Reprise de la base '"+databasename+"', table:"+model.toString()); Gdx.files.internal("bases/"+databasename).copyTo(newbase);
else } catch (Exception e1) {
{ e1.printStackTrace();
Gdx.app.log("Local", "Utilisation de la base '"+databasename+"', table:"+model.toString()); }
dbHandler = DatabaseFactory.getNewDatabase(databasename,1, "", null); break;
dbHandler.setupDatabase(); }
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, null);
dbHandler.setupDatabase();
try { try {
dbHandler.openOrCreateDatabase(); dbHandler.openOrCreateDatabase();
} }
catch (SQLiteGdxException e) { catch (SQLiteGdxException e) {
e.printStackTrace(); e.printStackTrace();
} Gdx.app.log("Local", "Erreur à l'ouverture de la base");
} }
try { }
if (model==datatype.statdata) try {
creation = "create table if not exists stat (id integer)"; if (model==datatype.statdata)
else if (model==datatype.userdata) { creation = "create table if not exists stat (id integer)";
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));"); else if (model==datatype.userdata) {
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 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 transmuters(date DATETIME DEFAULT CURRENT_TIMESTAMP, user INTEGER NOT NULL, object TEXT, PRIMARY KEY(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 research(date DATETIME DEFAULT CURRENT_TIMESTAMP, user INTEGER NOT NULL, value INT, PRIMARY KEY(user));"); 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 else
dbHandler.execSQL("CREATE TABLE if not exists worlds(date DATETIME DEFAULT CURRENT_TIMESTAMP, desc TEXT NOT NULL, object TEXT, PRIMARY KEY(desc));"); 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) { } catch (SQLiteGdxException e) {
e.printStackTrace(); e.printStackTrace();
} }
} }
//Gestion model type gamedata
public Array<String> getworlds() { //Gestion model type gamedata
DatabaseCursor cursor=null;
try { public Array<String> getworlds() {
cursor = dbHandler.rawQuery("select desc,date from worlds;"); DatabaseCursor cursor=null;
} catch (SQLiteGdxException e) { try {
return null; cursor = dbHandler.rawQuery("select desc,date from worlds;");
} } catch (SQLiteGdxException e) {
Array<String> returnvalue=new Array<String>(); return null;
while (cursor.next()) }
returnvalue.add(cursor.getString(0)); Array<String> returnvalue=new Array<String>();
return returnvalue; while (cursor.next())
} returnvalue.add(cursor.getString(0));
return returnvalue;
}
public Array<Level> 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 {
Gdx.app.debug(getClass().getSimpleName(),"TEST2");
byte[] bytes = Base64Coder.decodeLines(cursor.getString(0));
Gdx.app.debug(getClass().getSimpleName(),"TEST3");
ByteArrayInputStream bais = new ByteArrayInputStream(bytes);
ObjectInputStream ins = new ObjectInputStream(bais);
mc=(Level[]) ins.readObject();
ins.close();
return new Array<Level>(mc);
}
catch (Exception e) {
e.printStackTrace();
}
return null;
}
public Array<Level> 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<Level>(mc);
}
catch (Exception e) {
e.printStackTrace();
}
return null;
}
public boolean deleteworld(String description) { public boolean deleteworld(String description) {
try { try {
dbHandler.rawQuery("delete from worlds where desc='"+description+"';"); dbHandler.rawQuery("delete from worlds where desc='"+description+"';");
} catch (SQLiteGdxException e) { } catch (SQLiteGdxException e) {
return false; return false;
} }
return true; return true;
} }
public boolean setworld(Array<Level> 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 = Base64Coder.encodeLines(bytes);
dbHandler.rawQuery("replace into worlds (desc,object) values ('"+description+"','"+encoded+"');");
} catch (Exception e) {
return false;
}
return true;
}
public boolean setworld(Array<Level> 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 //Gestion de données type userdata
public boolean getlevellock(int user,int level) { public boolean getlevellock(int user,int level) {
DatabaseCursor cursor=null; DatabaseCursor cursor=null;
try { try {
cursor=dbHandler.rawQuery("select user from locks where user="+user+" and level="+level+";"); cursor=dbHandler.rawQuery("select user from locks where user="+user+" and level="+level+";");
} catch (SQLiteGdxException e) { } catch (SQLiteGdxException e) {
return false; return false;
} }
if (cursor.next()) if (cursor.next())
return true; return true;
else return false; else return false;
} }
public boolean setlevelunlock(int user,int level){ public boolean setlevelunlock(int user,int level){
try { try {
dbHandler.rawQuery("insert into locks (user,level) values ("+user+","+level+");"); dbHandler.rawQuery("insert into locks (user,level) values ("+user+","+level+");");
} catch (SQLiteGdxException e) { } catch (SQLiteGdxException e) {
return false; return false;
} }
return true; return true;
} }
public Array<Transmuter> getTransmuters(int user){ public Array<Transmuter> getTransmuters(int user){
DatabaseCursor cursor=null; DatabaseCursor cursor=null;
try { try {
cursor = dbHandler.rawQuery("select object from transmuters where user="+user+";"); cursor = dbHandler.rawQuery("select object from transmuters where user="+user+";");
} catch (SQLiteGdxException e) { } catch (SQLiteGdxException e) {
return null; return null;
} }
Transmuter[] mc=null; Transmuter[] mc=null;
if (cursor.next()) if (cursor.next())
try { try {
byte[] bytes = DatatypeConverter.parseBase64Binary(cursor.getString(0)); byte[] bytes = DatatypeConverter.parseBase64Binary(cursor.getString(0));
ByteArrayInputStream bais = new ByteArrayInputStream(bytes); ByteArrayInputStream bais = new ByteArrayInputStream(bytes);
ObjectInputStream ins = new ObjectInputStream(bais); ObjectInputStream ins = new ObjectInputStream(bais);
mc=(Transmuter[]) ins.readObject(); mc=(Transmuter[]) ins.readObject();
ins.close(); ins.close();
return new Array<Transmuter>(mc); return new Array<Transmuter>(mc);
} }
catch (Exception e) { catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
} }
return null; return null;
}
public boolean setTransmuters(int user,Array<Transmuter> 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 boolean setTransmuters(int user,Array<Transmuter> 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){ public int getResearchpoint(int user){
DatabaseCursor cursor=null; DatabaseCursor cursor=null;
try { try {
@ -239,88 +251,88 @@ public class LocalBase extends Base {
else else
return 0; return 0;
} }
public boolean setResearchpoint(int user, int point){ public boolean setResearchpoint(int user, int point){
try { try {
dbHandler.rawQuery("replace into research (user,value) values ("+user+","+point+");"); dbHandler.rawQuery("replace into research (user,value) values ("+user+","+point+");");
} catch (Exception e) { } catch (Exception e) {
return false; return false;
} }
return true; return true;
} }
public Grid getGrid(int user,int level,int place){ public Grid getGrid(int user,int level,int place){
DatabaseCursor cursor=null; DatabaseCursor cursor=null;
try { try {
cursor = dbHandler.rawQuery("select object from grids where user="+user+" and level="+level+" order by date desc limit "+place+",1;"); cursor = dbHandler.rawQuery("select object from grids where user="+user+" and level="+level+" order by date desc limit "+place+",1;");
} catch (SQLiteGdxException e) { } catch (SQLiteGdxException e) {
return null; return null;
} }
Grid mc=null; Grid mc=null;
if (cursor.next()) if (cursor.next())
try { try {
byte[] bytes = DatatypeConverter.parseBase64Binary(cursor.getString(0)); byte[] bytes = DatatypeConverter.parseBase64Binary(cursor.getString(0));
ByteArrayInputStream bais = new ByteArrayInputStream(bytes); ByteArrayInputStream bais = new ByteArrayInputStream(bytes);
ObjectInputStream ins = new ObjectInputStream(bais); ObjectInputStream ins = new ObjectInputStream(bais);
mc=(Grid) ins.readObject(); mc=(Grid) ins.readObject();
ins.close(); ins.close();
return mc; return mc;
} }
catch (Exception e) { catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
} }
return null; return null;
} }
public boolean setGrid(int user,int level, Grid data){ public boolean setGrid(int user,int level, Grid data){
String encoded = ""; String encoded = "";
try { try {
ByteArrayOutputStream bos = new ByteArrayOutputStream(); ByteArrayOutputStream bos = new ByteArrayOutputStream();
ObjectOutputStream oos = new ObjectOutputStream(bos); ObjectOutputStream oos = new ObjectOutputStream(bos);
oos.writeObject(data); oos.writeObject(data);
oos.flush(); oos.flush();
oos.close(); oos.close();
bos.close(); bos.close();
byte[] bytes = bos.toByteArray(); byte[] bytes = bos.toByteArray();
encoded = DatatypeConverter.printBase64Binary(bytes); encoded = DatatypeConverter.printBase64Binary(bytes);
dbHandler.rawQuery("insert into grids (user,level,object) values ("+user+","+level+",'"+encoded+"');"); dbHandler.rawQuery("insert into grids (user,level,object) values ("+user+","+level+",'"+encoded+"');");
} catch (Exception e) { } catch (Exception e) {
return false; return false;
} }
return true; return true;
} }
public Array<String> getGrids(int user, int level){ public Array<String> getGrids(int user, int level){
DatabaseCursor cursor=null; DatabaseCursor cursor=null;
try { try {
cursor = dbHandler.rawQuery("select date from grids where level="+level+" and user="+user+" order by date desc;"); cursor = dbHandler.rawQuery("select date from grids where level="+level+" and user="+user+" order by date desc;");
} catch (SQLiteGdxException e) { } catch (SQLiteGdxException e) {
return null; return null;
} }
Array<String> returnvalue=new Array<String>(); Array<String> returnvalue=new Array<String>();
while (cursor.next()) while (cursor.next())
returnvalue.add(cursor.getString(0)); returnvalue.add(cursor.getString(0));
return returnvalue; return returnvalue;
} }
//Gestion type Stat //Gestion type Stat
//Commun //Commun
public boolean Eraseall(datatype base){ public boolean Eraseall(datatype base){
try { try {
dbHandler.execSQL("drop table if exists stat;"); dbHandler.execSQL("drop table if exists stat;");
dbHandler.execSQL("drop table if exists locks;"); dbHandler.execSQL("drop table if exists locks;");
dbHandler.execSQL("drop table if exists grids;"); dbHandler.execSQL("drop table if exists grids;");
dbHandler.execSQL("drop table if exists global;"); dbHandler.execSQL("drop table if exists global;");
dbHandler.execSQL("drop table if exists worlds;"); dbHandler.execSQL("drop table if exists worlds;");
return true; return true;
} catch (SQLiteGdxException e1) { } catch (SQLiteGdxException e1) {
return false; return false;
}
} }
}
public void Close() { public void Close() {
try { try {
if (dbHandler!=null) { if (dbHandler!=null) {
@ -332,12 +344,12 @@ public class LocalBase extends Base {
e.printStackTrace(); e.printStackTrace();
} }
} }
public String getprefix() { public String getprefix() {
return "local"; return "local";
} }
public static boolean isHandling(datatype base){ public static boolean isHandling(datatype base){
return true; return true;
} }

View File

@ -7,7 +7,10 @@ import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.graphics.g2d.TextureAtlas; import com.badlogic.gdx.graphics.g2d.TextureAtlas;
import com.badlogic.gdx.scenes.scene2d.InputEvent; import com.badlogic.gdx.scenes.scene2d.InputEvent;
import com.badlogic.gdx.scenes.scene2d.Stage; import com.badlogic.gdx.scenes.scene2d.Stage;
import com.badlogic.gdx.scenes.scene2d.actions.Actions;
import com.badlogic.gdx.scenes.scene2d.actions.Actions.*;
import com.badlogic.gdx.scenes.scene2d.ui.Button; import com.badlogic.gdx.scenes.scene2d.ui.Button;
import com.badlogic.gdx.scenes.scene2d.ui.Image;
import com.badlogic.gdx.scenes.scene2d.ui.ImageButton; import com.badlogic.gdx.scenes.scene2d.ui.ImageButton;
import com.badlogic.gdx.scenes.scene2d.ui.List; import com.badlogic.gdx.scenes.scene2d.ui.List;
import com.badlogic.gdx.scenes.scene2d.ui.Label; import com.badlogic.gdx.scenes.scene2d.ui.Label;
@ -30,6 +33,7 @@ import fr.evolving.renderers.LevelRenderer;
import fr.evolving.UI.ButtonLevel; import fr.evolving.UI.ButtonLevel;
import fr.evolving.UI.Objectives; import fr.evolving.UI.Objectives;
import fr.evolving.UI.ServerList; import fr.evolving.UI.ServerList;
import fr.evolving.UI.WarnDialog;
import fr.evolving.UI.Worldlist; import fr.evolving.UI.Worldlist;
import fr.evolving.game.main; import fr.evolving.game.main;
@ -55,8 +59,10 @@ public class LevelScreen implements Screen {
private TimerTask ScrollTask; private TimerTask ScrollTask;
private Stage stage; private Stage stage;
private Table table; private Table table;
private WarnDialog dialog;
private ImageButton Previous,Next,Exit; private ImageButton Previous,Next,Exit;
public ImageButton logosmall,MenuSolo,MenuMulti,MenuScenario; public ImageButton logosmall;
public Image MenuSolo,MenuMulti,MenuScenario;
private ImageTextButton cout,tech,cycle,temp,rayon,nrj; private ImageTextButton cout,tech,cycle,temp,rayon,nrj;
private TextButton buttonConnect,buttonPlay,buttonStat,buttonSave, buttonApply, buttonPlaythis; private TextButton buttonConnect,buttonPlay,buttonStat,buttonSave, buttonApply, buttonPlaythis;
private ServerList Statdata,Userdata,Gamedata; private ServerList Statdata,Userdata,Gamedata;
@ -79,22 +85,27 @@ public class LevelScreen implements Screen {
public void play() { public void play() {
//thelevels= InitWorlds.go(); //thelevels= InitWorlds.go();
Gdx.app.debug(getClass().getSimpleName(),"Chargement des mondes depuis la base."); if (!AssetLoader.Datahandler.verifyall())
try { Gdx.app.debug(getClass().getSimpleName(),"Pilotes de bases de donnée défaillant.");
if (world<0) else
world=0; {
thelevels=AssetLoader.Datahandler.game().getworld(Preference.prefs.getString("world")); Gdx.app.debug(getClass().getSimpleName(),"Chargement des mondes depuis la base.");
loadWorld(world); try {
Previous.setVisible(true); if (world<0)
Next.setVisible(true); world=0;
buttonPlay.setVisible(true); thelevels=AssetLoader.Datahandler.game().getworld(Preference.prefs.getString("world"));
TextDescriptive.setVisible(true); loadWorld(world);
} Previous.setVisible(true);
catch (Exception e) { Next.setVisible(true);
Previous.setVisible(false); buttonPlay.setVisible(true);
Next.setVisible(false); TextDescriptive.setVisible(true);
buttonPlay.setVisible(false); }
TextDescriptive.setVisible(false); catch (Exception e) {
Previous.setVisible(false);
Next.setVisible(false);
buttonPlay.setVisible(false);
TextDescriptive.setVisible(false);
}
} }
} }
@ -128,12 +139,44 @@ public class LevelScreen implements Screen {
Worlddata.setVisible(false); Worlddata.setVisible(false);
buttonSave.setVisible(false); buttonSave.setVisible(false);
buttonApply.setVisible(false); buttonApply.setVisible(false);
initlevel();
MenuSolo.setRotation(0);
MenuSolo.setScale(1f);
MenuSolo.setColor(1f, 1f, 1f, 1f);
MenuSolo.setPosition(0, AssetLoader.height*17/20-300);
MenuMulti.setRotation(0);
MenuMulti.setScale(1f);
MenuMulti.setColor(1f, 1f, 1f, 1f);
MenuMulti.setPosition(0, AssetLoader.height*12/20-300);
MenuScenario.setRotation(0);
MenuScenario.setScale(1f);
MenuScenario.setColor(1f, 1f, 1f, 1f);
MenuScenario.setPosition(0, AssetLoader.height*7/20-300);
MenuSolo.addAction(Actions.sequence(Actions.moveTo((AssetLoader.width-MenuSolo.getWidth())/2, AssetLoader.height*17/20-300, 0.25f)));
MenuMulti.addAction(Actions.sequence(Actions.fadeIn(0.1f),Actions.moveTo((AssetLoader.width-MenuMulti.getWidth())/2, AssetLoader.height*12/20-300, 0.25f)));
MenuScenario.addAction(Actions.sequence(Actions.fadeIn(0.2f),Actions.moveTo((AssetLoader.width-MenuScenario.getWidth())/2, AssetLoader.height*7/20-300, 0.25f)));
}
public void initlevel() {
selected=null;
buttonPlay.setVisible(false);
TextDescriptive.setVisible(false);
cout.setVisible(false);
tech.setVisible(false);
cycle.setVisible(false);
temp.setVisible(false);
rayon.setVisible(false);
nrj.setVisible(false);
Previous.setVisible(false);
Next.setVisible(false);
Victory.setVisible(false);
if (buttonLevels!=null) if (buttonLevels!=null)
for (int j=0;j<10;j++) for (int j=0;j<10;j++)
if (buttonLevels[j]!=null) { if (buttonLevels[j]!=null) {
buttonLevels[j].remove(); buttonLevels[j].remove();
buttonLevels[j]=null; buttonLevels[j]=null;
} }
} }
public void level() { public void level() {
@ -149,7 +192,7 @@ public class LevelScreen implements Screen {
} }
public void SetButtonConnect() { public void SetButtonConnect() {
buttonStat.setColor(buttonConnect.getColor()); buttonStat.setColor(1f,1f,1f,1f);
buttonConnect.setColor(1f,0,0,1f); buttonConnect.setColor(1f,0,0,1f);
Statdata.setVisible(true); Statdata.setVisible(true);
Userdata.setVisible(true); Userdata.setVisible(true);
@ -161,11 +204,12 @@ public class LevelScreen implements Screen {
buttonApply.setVisible(true); buttonApply.setVisible(true);
Worlddatalabel.setVisible(true); Worlddatalabel.setVisible(true);
Worlddata.setVisible(true); Worlddata.setVisible(true);
buttonPlaythis.setVisible(true); buttonPlaythis.setVisible(true);
} }
public void SetButtonStat() { public void SetButtonStat() {
buttonConnect.setColor(buttonStat.getColor()); buttonConnect.setColor(1f,1f,1f,1f);
buttonStat.setColor(1f,0,0,1f);
buttonStat.setColor(1f,0,0,1f); buttonStat.setColor(1f,0,0,1f);
Statdata.setVisible(false); Statdata.setVisible(false);
Userdata.setVisible(false); Userdata.setVisible(false);
@ -235,6 +279,7 @@ public class LevelScreen implements Screen {
stage = new Stage(AssetLoader.viewport); stage = new Stage(AssetLoader.viewport);
table = new Table(); table = new Table();
Renderer=new LevelRenderer(this); Renderer=new LevelRenderer(this);
dialog=new WarnDialog(AssetLoader.Skin_ui);
Gdx.app.debug(getClass().getSimpleName(),"Mise en place du timer."); Gdx.app.debug(getClass().getSimpleName(),"Mise en place du timer.");
ScrollTimer=new Timer(); ScrollTimer=new Timer();
ScrollTask = new TimerTask() ScrollTask = new TimerTask()
@ -247,17 +292,48 @@ public class LevelScreen implements Screen {
}; };
ScrollTimer.scheduleAtFixedRate(ScrollTask, 0, 30); ScrollTimer.scheduleAtFixedRate(ScrollTask, 0, 30);
Gdx.app.debug(getClass().getSimpleName(),"Création du menu."); Gdx.app.debug(getClass().getSimpleName(),"Création du menu.");
MenuSolo=new ImageButton(AssetLoader.Skin_level,"MenuSolo"); MenuSolo=new Image(AssetLoader.Skin_level,"menu1");
MenuSolo.setPosition((AssetLoader.width-MenuSolo.getWidth())/2, AssetLoader.height-550); MenuSolo.setOrigin(MenuSolo.getWidth()/2, MenuSolo.getHeight()/2);
MenuSolo.addListener(new ClickListener() { MenuSolo.addListener(new ClickListener() {
public void clicked(InputEvent event, float x, float y) { public void clicked(InputEvent event, float x, float y) {
level(); MenuMulti.addAction(Actions.fadeOut(0.5f));
MenuScenario.addAction(Actions.fadeOut(0.5f));
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();
}
})));
}
});
MenuMulti=new Image(AssetLoader.Skin_level,"menu2");
MenuMulti.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));
MenuScenario.addAction(Actions.fadeOut(0.5f));
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();
}
})));
}
});
MenuScenario=new Image(AssetLoader.Skin_level,"menu3");
MenuScenario.setOrigin(MenuScenario.getWidth()/2, MenuScenario.getHeight()/2);
MenuScenario.addListener(new ClickListener() {
public void clicked(InputEvent event, float x, float y) {
MenuMulti.addAction(Actions.fadeOut(0.5f));
MenuSolo.addAction(Actions.fadeOut(0.5f));
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();
}
})));
} }
}); });
MenuMulti=new ImageButton(AssetLoader.Skin_level,"MenuMulti");
MenuMulti.setPosition((AssetLoader.width-MenuMulti.getWidth())/2, AssetLoader.height-900);
MenuScenario=new ImageButton(AssetLoader.Skin_level,"MenuScenario");
MenuScenario.setPosition((AssetLoader.width-MenuScenario.getWidth())/2, AssetLoader.height-1250);
Gdx.app.debug(getClass().getSimpleName(),"Création des boutons."); Gdx.app.debug(getClass().getSimpleName(),"Création des boutons.");
logosmall=new ImageButton(AssetLoader.Skin_level,"logosmall"); logosmall=new ImageButton(AssetLoader.Skin_level,"logosmall");
logosmall.setPosition(20, AssetLoader.height-175+logosmall.getHeight()/2); logosmall.setPosition(20, AssetLoader.height-175+logosmall.getHeight()/2);
@ -267,11 +343,29 @@ public class LevelScreen implements Screen {
buttonApply.setBounds(1680, 350, 190, 40); buttonApply.setBounds(1680, 350, 190, 40);
buttonApply.addListener(new ClickListener() { buttonApply.addListener(new ClickListener() {
public void clicked(InputEvent event, float x, float y) { public void clicked(InputEvent event, float x, float y) {
menu();
AssetLoader.Datahandler.CloseAll(); AssetLoader.Datahandler.CloseAll();
AssetLoader.Datahandler.Attach(Userdata.getModel(),Userdata.getUrl()); AssetLoader.Datahandler.Attach(Userdata.getModel(),Userdata.getUrl());
AssetLoader.Datahandler.Attach(Gamedata.getModel(),Gamedata.getUrl());
AssetLoader.Datahandler.Attach(Statdata.getModel(),Statdata.getUrl()); AssetLoader.Datahandler.Attach(Statdata.getModel(),Statdata.getUrl());
AssetLoader.Datahandler.Attach(Gamedata.getModel(),Gamedata.getUrl());
if (!AssetLoader.Datahandler.verifyall()) {
dialog.Show("Un problème est survenu lors du changement de base de donnée.",stage);
initlevel();
}
else
menu();
if (AssetLoader.Datahandler.stat()==null)
Statdata.setColor(1f,0,0,1f);
else
Statdata.setColor(1f,1f,1f,1f);
if (AssetLoader.Datahandler.game()==null)
Gamedata.setColor(1f,0,0,1f);
else
Gamedata.setColor(1f,1f,1f,1f);
if (AssetLoader.Datahandler.user()==null)
Userdata.setColor(1f,0,0,1f);
else
Userdata.setColor(1f,1f,1f,1f);
Worlddata.Refresh();
} }
}); });
buttonSave = new TextButton("Sauvegarder", AssetLoader.Skin_ui); buttonSave = new TextButton("Sauvegarder", AssetLoader.Skin_ui);
@ -282,6 +376,7 @@ public class LevelScreen implements Screen {
Preference.prefs.putString("userdata", Userdata.getUrl()); Preference.prefs.putString("userdata", Userdata.getUrl());
Preference.prefs.putString("gamedata", Gamedata.getUrl()); Preference.prefs.putString("gamedata", Gamedata.getUrl());
Preference.prefs.putString("statdata", Statdata.getUrl()); Preference.prefs.putString("statdata", Statdata.getUrl());
dialog.Show("Vous devez redemarrer pour bénéfier des changements.",stage);
} }
}); });
buttonConnect = new TextButton("Connexions", AssetLoader.Skin_ui); buttonConnect = new TextButton("Connexions", AssetLoader.Skin_ui);
@ -312,9 +407,19 @@ public class LevelScreen implements Screen {
buttonPlaythis.setBounds(1480, 50, 190, 40); buttonPlaythis.setBounds(1480, 50, 190, 40);
buttonPlaythis.addListener(new ClickListener() { buttonPlaythis.addListener(new ClickListener() {
public void clicked(InputEvent event, float x, float y) { public void clicked(InputEvent event, float x, float y) {
Preference.prefs.putString("world", (String)Worlddata.getSelected()); if (!AssetLoader.Datahandler.verifyall())
Preference.prefs.flush(); dialog.Show("Impossible de jouer sans bases de données correctement configurée, cliquer sur RAZ si vous ne savez pas revenir à une situation jouable.", stage);
play(); else
{
if (Worlddata.getSelected()==null)
dialog.Show("Aucun monde n'a été sélectionné", stage);
else
{
Preference.prefs.putString("world", (String)Worlddata.getSelected());
Preference.prefs.flush();
play();
}
}
} }
}); });
Exit=new ImageButton(AssetLoader.Skin_level,"Exit"); Exit=new ImageButton(AssetLoader.Skin_level,"Exit");
@ -322,7 +427,10 @@ public class LevelScreen implements Screen {
Exit.addListener(new ClickListener(){ Exit.addListener(new ClickListener(){
@Override @Override
public void clicked(InputEvent event, float x, float y) { public void clicked(InputEvent event, float x, float y) {
Gdx.app.exit(); if (Exit.getX()<1210)
menu();
else
Gdx.app.exit();
} }
}); });
Next=new ImageButton(AssetLoader.Skin_level,"Next"); Next=new ImageButton(AssetLoader.Skin_level,"Next");
@ -384,7 +492,19 @@ public class LevelScreen implements Screen {
Worlddatalabel.setPosition(1480, 300); Worlddatalabel.setPosition(1480, 300);
Gamedata.setWorldlist(Worlddata); Gamedata.setWorldlist(Worlddata);
Statdata.Refresh(); Statdata.Refresh();
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
Userdata.Refresh(); Userdata.Refresh();
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
Gamedata.Refresh(); Gamedata.Refresh();
Gdx.app.debug(getClass().getSimpleName(),"Affichage du menu."); Gdx.app.debug(getClass().getSimpleName(),"Affichage du menu.");
if (aworld!=-1) if (aworld!=-1)