feat: ajout de la gestion des préférences gestion de la journalisation
This commit is contained in:
parent
57c8c042a6
commit
7b8dc70fae
|
@ -3,7 +3,10 @@ package fr.evolving.assets;
|
||||||
import com.badlogic.gdx.Gdx;
|
import com.badlogic.gdx.Gdx;
|
||||||
import com.badlogic.gdx.Preferences;
|
import com.badlogic.gdx.Preferences;
|
||||||
import com.badlogic.gdx.audio.Sound;
|
import com.badlogic.gdx.audio.Sound;
|
||||||
|
import com.badlogic.gdx.graphics.Camera;
|
||||||
import com.badlogic.gdx.graphics.Color;
|
import com.badlogic.gdx.graphics.Color;
|
||||||
|
import com.badlogic.gdx.graphics.OrthographicCamera;
|
||||||
|
import com.badlogic.gdx.graphics.PerspectiveCamera;
|
||||||
import com.badlogic.gdx.graphics.Pixmap;
|
import com.badlogic.gdx.graphics.Pixmap;
|
||||||
import com.badlogic.gdx.graphics.Texture;
|
import com.badlogic.gdx.graphics.Texture;
|
||||||
import com.badlogic.gdx.graphics.Texture.TextureFilter;
|
import com.badlogic.gdx.graphics.Texture.TextureFilter;
|
||||||
|
@ -15,6 +18,9 @@ import com.badlogic.gdx.graphics.g2d.TextureRegion;
|
||||||
import com.badlogic.gdx.graphics.Texture.TextureWrap;
|
import com.badlogic.gdx.graphics.Texture.TextureWrap;
|
||||||
import com.badlogic.gdx.graphics.g2d.TextureAtlas;
|
import com.badlogic.gdx.graphics.g2d.TextureAtlas;
|
||||||
import com.badlogic.gdx.scenes.scene2d.ui.Skin;
|
import com.badlogic.gdx.scenes.scene2d.ui.Skin;
|
||||||
|
import com.badlogic.gdx.utils.viewport.FitViewport;
|
||||||
|
import com.badlogic.gdx.utils.viewport.ScalingViewport;
|
||||||
|
import com.badlogic.gdx.utils.viewport.StretchViewport;
|
||||||
|
|
||||||
public class AssetLoader {
|
public class AssetLoader {
|
||||||
public static Skin Skin_level;
|
public static Skin Skin_level;
|
||||||
|
@ -24,10 +30,12 @@ public class AssetLoader {
|
||||||
public static Texture Texture_fond2;
|
public static Texture Texture_fond2;
|
||||||
public static Texture Texture_logo;
|
public static Texture Texture_logo;
|
||||||
public static Sound intro;
|
public static Sound intro;
|
||||||
public static int width=1440;
|
public static int width;
|
||||||
public static int height=960;
|
public static int height;
|
||||||
|
public static float ratio;
|
||||||
public static boolean stretch=false;
|
public static boolean stretch=false;
|
||||||
private static Preferences prefs;
|
public static Preferences prefs;
|
||||||
|
public static ScalingViewport viewport;
|
||||||
|
|
||||||
public static void addstyle(TextureAtlas Atlas_level,String Name) {
|
public static void addstyle(TextureAtlas Atlas_level,String Name) {
|
||||||
AtlasRegion AnAtlasRegion = Atlas_level.findRegion(Name);
|
AtlasRegion AnAtlasRegion = Atlas_level.findRegion(Name);
|
||||||
|
@ -53,7 +61,7 @@ public class AssetLoader {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void loadall() {
|
public static void loadall() {
|
||||||
Gdx.app.log("Chargements des éléments multimédia","ok");
|
Gdx.app.debug("AssetLoader","Chargements de tout les éléments multimédia");
|
||||||
Texture_fond = new Texture(Gdx.files.internal("pictures/fond.png"));
|
Texture_fond = new Texture(Gdx.files.internal("pictures/fond.png"));
|
||||||
Texture_fond.setWrap(TextureWrap.Repeat, TextureWrap.Repeat);
|
Texture_fond.setWrap(TextureWrap.Repeat, TextureWrap.Repeat);
|
||||||
Texture_fond2 = new Texture(Gdx.files.internal("pictures/fond2.png"));
|
Texture_fond2 = new Texture(Gdx.files.internal("pictures/fond2.png"));
|
||||||
|
@ -66,29 +74,50 @@ public class AssetLoader {
|
||||||
addstyle(Atlas_level,"arrows2");
|
addstyle(Atlas_level,"arrows2");
|
||||||
addstyle(Atlas_level,"exit2");
|
addstyle(Atlas_level,"exit2");
|
||||||
Skin_level = new Skin(Gdx.files.internal("textures/level.json"),Atlas_level);
|
Skin_level = new Skin(Gdx.files.internal("textures/level.json"),Atlas_level);
|
||||||
prefs = Gdx.app.getPreferences("WireWorld");
|
|
||||||
|
|
||||||
if (!prefs.contains("resolutionx")) {
|
|
||||||
prefs.putInteger("resolutionx", 0);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static int setpref() {
|
||||||
|
prefs = Gdx.app.getPreferences("WireWorld - Evolving Games");
|
||||||
|
if (prefs.contains("log"))
|
||||||
|
return prefs.getInteger("log");
|
||||||
|
else
|
||||||
|
return Gdx.app.LOG_INFO;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void init() {
|
||||||
|
Gdx.app.debug("AssetLoader","Initialisation de la résolution virtuelle...");
|
||||||
|
int realWidth=Gdx.graphics.getWidth();
|
||||||
|
int realHeight=Gdx.graphics.getHeight();
|
||||||
|
float realRatio=realWidth/(float)realHeight;
|
||||||
|
Gdx.app.debug("AssetLoader","Résolution de "+realWidth+"x"+realHeight+" ratio de "+String.format("%.2f", realRatio)+".");
|
||||||
|
ratio=1;
|
||||||
|
width=1920;
|
||||||
|
height=1080;
|
||||||
|
if (Math.abs(16f/9f-realRatio)>Math.abs(4f/3f-realRatio)) {
|
||||||
|
ratio=4/3;
|
||||||
|
Gdx.app.debug("AssetLoader","Ratio 4/3, résolution virtuelle : 1920x1440.");
|
||||||
|
height=1440;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
Gdx.app.debug("AssetLoader","Ratio 16/9, résolution virtuelle : 1920x1080.");
|
||||||
|
if (stretch) {
|
||||||
|
viewport = new StretchViewport(realWidth,realHeight);
|
||||||
|
Gdx.app.debug("AssetLoader","Adaptation d'écran maximale, 'Aspect-Ratio' non conservé.");
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
viewport = new FitViewport(realWidth,realHeight);
|
||||||
|
Gdx.app.debug("AssetLoader","Adaptation d'écran totale, 'Aspect-Ratio' conservé.");
|
||||||
|
}
|
||||||
|
viewport.apply();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void load() {
|
public static void load() {
|
||||||
Gdx.app.log("Chargements des éléments minimalistes","ok");
|
Gdx.app.debug("AssetLoader","Chargements des éléments minimalistes");
|
||||||
Texture_logo = new Texture(Gdx.files.internal("pictures/logo.png"));
|
Texture_logo = new Texture(Gdx.files.internal("pictures/logo.png"));
|
||||||
Texture_logo.setFilter(TextureFilter.Linear,TextureFilter.Linear);
|
Texture_logo.setFilter(TextureFilter.Linear,TextureFilter.Linear);
|
||||||
intro = Gdx.audio.newSound(Gdx.files.internal("musics/intro.mp3"));
|
intro = Gdx.audio.newSound(Gdx.files.internal("musics/intro.mp3"));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void setHighScore(int val) {
|
|
||||||
prefs.putInteger("highScore", val);
|
|
||||||
prefs.flush();
|
|
||||||
}
|
|
||||||
|
|
||||||
public static int getHighScore() {
|
|
||||||
return prefs.getInteger("highScore");
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void dispose() {
|
public static void dispose() {
|
||||||
Texture_logo.dispose();
|
Texture_logo.dispose();
|
||||||
Texture_fond.dispose();
|
Texture_fond.dispose();
|
||||||
|
|
|
@ -82,7 +82,7 @@ public class Laser {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public static void drawold(float x1,float y1,float x2,float y2,float maxwidth,float power,boolean active,Color colorsrc,Color colordst) {
|
public void drawold(float x1,float y1,float x2,float y2,float maxwidth,float power,boolean active,Color colorsrc,Color colordst) {
|
||||||
ShapeRenderer Laser=new ShapeRenderer();
|
ShapeRenderer Laser=new ShapeRenderer();
|
||||||
//Laser.begin(ShapeType.Line);
|
//Laser.begin(ShapeType.Line);
|
||||||
float adding=0;
|
float adding=0;
|
||||||
|
|
|
@ -11,9 +11,52 @@ public class main extends Game {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void create() {
|
public void create() {
|
||||||
|
Gdx.app.setLogLevel(AssetLoader.setpref());
|
||||||
|
//debug();
|
||||||
|
test();
|
||||||
|
Gdx.app.debug(getClass().getSimpleName(), "Récupération de la résolution des préférences.");
|
||||||
|
if (AssetLoader.prefs.contains("ResolutionX") && AssetLoader.prefs.contains("ResolutionX")) {
|
||||||
|
try {
|
||||||
|
int ResolutionX=AssetLoader.prefs.getInteger("ResolutionX");
|
||||||
|
int ResolutionY=AssetLoader.prefs.getInteger("ResolutionY");
|
||||||
|
boolean Fullscreen=AssetLoader.prefs.getBoolean("Fullscreen");
|
||||||
|
boolean VSync=AssetLoader.prefs.getBoolean("VSync");
|
||||||
|
Gdx.graphics.setDisplayMode(ResolutionX, ResolutionY, Fullscreen);
|
||||||
|
Gdx.graphics.setVSync(VSync);
|
||||||
|
} catch (ClassCastException e) {
|
||||||
|
Gdx.app.error("****","Impossible d'appliquer les préférences graphiques");
|
||||||
|
Gdx.app.debug(getClass().getSimpleName(),e.getMessage());
|
||||||
|
} finally {
|
||||||
|
Gdx.app.log("****","Changement de résolution selon préférences graphiques");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
Gdx.app.debug(getClass().getSimpleName(), "...Aucune préférence !");
|
||||||
|
AssetLoader.init();
|
||||||
|
Gdx.app.debug(getClass().getSimpleName(), "Creation de l'objet SplashScreen.");
|
||||||
setScreen(new SplashScreen(this));
|
setScreen(new SplashScreen(this));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void debug() {
|
||||||
|
AssetLoader.prefs.putInteger("ResolutionX", 1280);
|
||||||
|
AssetLoader.prefs.putInteger("ResolutionY", 1024);
|
||||||
|
AssetLoader.prefs.putBoolean("Fullscreen", false);
|
||||||
|
AssetLoader.prefs.putBoolean("VSync", false);
|
||||||
|
AssetLoader.prefs.putInteger("log", Gdx.app.LOG_DEBUG);
|
||||||
|
Gdx.app.setLogLevel(Gdx.app.LOG_DEBUG);
|
||||||
|
AssetLoader.prefs.flush();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void test() {
|
||||||
|
AssetLoader.prefs.putInteger("ResolutionX", 1280);
|
||||||
|
AssetLoader.prefs.putInteger("ResolutionY", 1024);
|
||||||
|
AssetLoader.prefs.putBoolean("Fullscreen", true);
|
||||||
|
AssetLoader.prefs.putBoolean("VSync", true);
|
||||||
|
AssetLoader.prefs.putInteger("log", Gdx.app.LOG_INFO);
|
||||||
|
Gdx.app.setLogLevel(Gdx.app.LOG_INFO);
|
||||||
|
AssetLoader.prefs.flush();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void dispose() {
|
public void dispose() {
|
||||||
super.dispose();
|
super.dispose();
|
||||||
|
|
|
@ -32,26 +32,22 @@ import fr.evolving.effects.Laser;
|
||||||
|
|
||||||
|
|
||||||
public class LevelScreen implements Screen {
|
public class LevelScreen implements Screen {
|
||||||
protected static final Class<? extends Actor> ButtonLevel = null;
|
|
||||||
public ButtonLevel[] buttonLevels;
|
public ButtonLevel[] buttonLevels;
|
||||||
private LevelRenderer Renderer;
|
private LevelRenderer Renderer;
|
||||||
private float runTime;
|
private float runTime;
|
||||||
private Timer ScrollTimer;
|
private Timer ScrollTimer;
|
||||||
private TimerTask ScrollTask;
|
private TimerTask ScrollTask;
|
||||||
private Stage stage = new Stage();
|
private Stage stage;
|
||||||
private Table table = new Table();
|
private Table table;
|
||||||
private ImageButton Previous,Next,Exit;
|
private ImageButton Previous,Next,Exit;
|
||||||
private TextButton buttonPlay,buttonExit;
|
private TextButton buttonPlay,buttonExit;
|
||||||
private Level[] thelevels=new Level[9];
|
private Level[] thelevels;
|
||||||
private TextArea TextDescriptive;
|
private TextArea TextDescriptive;
|
||||||
private ScalingViewport viewport;
|
|
||||||
|
|
||||||
public LevelScreen() {
|
public LevelScreen() {
|
||||||
if (AssetLoader.stretch)
|
Gdx.app.debug(getClass().getSimpleName(),"Création des boutons.");
|
||||||
viewport = new StretchViewport(AssetLoader.width,AssetLoader.height);
|
stage = new Stage(AssetLoader.viewport);
|
||||||
else
|
table = new Table();
|
||||||
viewport = new FitViewport(AssetLoader.width,AssetLoader.height);
|
|
||||||
viewport.apply();
|
|
||||||
Renderer=new LevelRenderer(this);
|
Renderer=new LevelRenderer(this);
|
||||||
buttonLevels = new ButtonLevel[10];
|
buttonLevels = new ButtonLevel[10];
|
||||||
thelevels= SaveObject.initObject();
|
thelevels= SaveObject.initObject();
|
||||||
|
@ -105,12 +101,12 @@ public class LevelScreen implements Screen {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void resize(int width, int height) {
|
public void resize(int width, int height) {
|
||||||
viewport.update(width,height);
|
AssetLoader.viewport.update(width,height);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void show() {
|
public void show() {
|
||||||
Gdx.app.log("Affichage du LevelScreen","ok");
|
Gdx.app.log("*****","Affichage du choix des mondes & niveaux.");
|
||||||
for (int i=0;i<10;i++) {
|
for (int i=0;i<10;i++) {
|
||||||
if (buttonLevels[i]!=null) {
|
if (buttonLevels[i]!=null) {
|
||||||
stage.addActor(buttonLevels[i]);
|
stage.addActor(buttonLevels[i]);
|
||||||
|
|
|
@ -17,23 +17,23 @@ import fr.evolving.game.main;
|
||||||
public class SplashScreen implements Screen {
|
public class SplashScreen implements Screen {
|
||||||
|
|
||||||
private main game;
|
private main game;
|
||||||
private Stage stage = new Stage();
|
private Stage stage;
|
||||||
private Image splashImage;
|
private Image splashImage;
|
||||||
|
private float scale;
|
||||||
|
|
||||||
public SplashScreen(main game) {
|
public SplashScreen(main game) {
|
||||||
this.game = game;
|
this.game = game;
|
||||||
AssetLoader.load();
|
AssetLoader.load();
|
||||||
|
stage = new Stage();
|
||||||
splashImage = new Image(AssetLoader.Texture_logo);
|
splashImage = new Image(AssetLoader.Texture_logo);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void show() {
|
public void show() {
|
||||||
float width = Gdx.graphics.getWidth();
|
Gdx.app.log("****","Affichage du SplashScreen");
|
||||||
float height = Gdx.graphics.getHeight();
|
scale=2;
|
||||||
float desiredWidth = width * .7f;
|
splashImage.setScale(scale);
|
||||||
float scale = desiredWidth / splashImage.getWidth();
|
splashImage.setPosition((AssetLoader.width / 2) - (scale * splashImage.getWidth() / 2), (AssetLoader.height / 2) - (scale * splashImage.getHeight() / 2));
|
||||||
splashImage.setSize(splashImage.getWidth() * scale, splashImage.getHeight() * scale);
|
|
||||||
splashImage.setPosition((width / 2) - (splashImage.getWidth() / 2), (height / 2) - (splashImage.getHeight() / 2));
|
|
||||||
stage.addActor(splashImage);
|
stage.addActor(splashImage);
|
||||||
splashImage.addAction(Actions.sequence(Actions.alpha(0),Actions.fadeIn(0.5f),Actions.run(new Runnable() {
|
splashImage.addAction(Actions.sequence(Actions.alpha(0),Actions.fadeIn(0.5f),Actions.run(new Runnable() {
|
||||||
//splashImage.addAction(Actions.sequence(Actions.alpha(0),Actions.run(new Runnable() {
|
//splashImage.addAction(Actions.sequence(Actions.alpha(0),Actions.run(new Runnable() {
|
||||||
|
@ -48,10 +48,9 @@ public class SplashScreen implements Screen {
|
||||||
((Game)Gdx.app.getApplicationListener()).setScreen(new LevelScreen());
|
((Game)Gdx.app.getApplicationListener()).setScreen(new LevelScreen());
|
||||||
}
|
}
|
||||||
})));
|
})));
|
||||||
|
Gdx.app.debug("AssetLoader","Début dans la bande son \'intro\'");
|
||||||
AssetLoader.intro.setLooping(0, true);
|
AssetLoader.intro.setLooping(0, true);
|
||||||
AssetLoader.intro.play();
|
AssetLoader.intro.play();
|
||||||
Gdx.app.log("Affichage du SplashScreen","ok");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -64,6 +63,7 @@ public class SplashScreen implements Screen {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void resize(int width, int height) {
|
public void resize(int width, int height) {
|
||||||
|
AssetLoader.viewport.update(width,height);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -21,6 +21,7 @@ import fr.evolving.screens.LevelScreen;
|
||||||
public class LevelRenderer {
|
public class LevelRenderer {
|
||||||
private ShapeRenderer shapeRenderer;
|
private ShapeRenderer shapeRenderer;
|
||||||
private SpriteBatch batcher;
|
private SpriteBatch batcher;
|
||||||
|
private SpriteBatch batcher2;
|
||||||
int scrollx;
|
int scrollx;
|
||||||
int scrolly;
|
int scrolly;
|
||||||
int dirx;
|
int dirx;
|
||||||
|
@ -37,6 +38,7 @@ public class LevelRenderer {
|
||||||
this.dirx=1;
|
this.dirx=1;
|
||||||
this.diry=1;
|
this.diry=1;
|
||||||
batcher = new SpriteBatch();
|
batcher = new SpriteBatch();
|
||||||
|
batcher2 = new SpriteBatch();
|
||||||
shapeRenderer = new ShapeRenderer();
|
shapeRenderer = new ShapeRenderer();
|
||||||
Laser=new Laser();
|
Laser=new Laser();
|
||||||
}
|
}
|
||||||
|
@ -63,6 +65,7 @@ public class LevelRenderer {
|
||||||
public void render(float delta, float runTime) {
|
public void render(float delta, float runTime) {
|
||||||
Gdx.gl.glClearColor(0, 0, 0, 1);
|
Gdx.gl.glClearColor(0, 0, 0, 1);
|
||||||
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT | GL20.GL_DEPTH_BUFFER_BIT);
|
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT | GL20.GL_DEPTH_BUFFER_BIT);
|
||||||
|
//Gdx.gl.glViewport(0, 0, AssetLoader.width, AssetLoader.height);
|
||||||
|
|
||||||
batcher.begin();
|
batcher.begin();
|
||||||
batcher.setColor(0.25f,0.25f,0.25f,1);
|
batcher.setColor(0.25f,0.25f,0.25f,1);
|
||||||
|
@ -86,10 +89,11 @@ public class LevelRenderer {
|
||||||
shapeRenderer.rect(1134, 620, AssetLoader.width-1144, AssetLoader.height-620);
|
shapeRenderer.rect(1134, 620, AssetLoader.width-1144, AssetLoader.height-620);
|
||||||
shapeRenderer.end();
|
shapeRenderer.end();
|
||||||
|
|
||||||
batcher.begin();
|
batcher2.begin();
|
||||||
batcher.draw(AssetLoader.Atlas_game.findRegion("cout"),1150,40);
|
batcher2.setColor(1f,1f,1f,1f);
|
||||||
batcher.draw(AssetLoader.Atlas_game.findRegion("tech"),1280,40);
|
batcher2.draw(AssetLoader.Atlas_game.findRegion("cout"),1150,40);
|
||||||
batcher.end();
|
batcher2.draw(AssetLoader.Atlas_game.findRegion("tech"),1280,40);
|
||||||
|
batcher2.end();
|
||||||
|
|
||||||
for (int i=0;i<LevelScreen.buttonLevels.length;i++) {
|
for (int i=0;i<LevelScreen.buttonLevels.length;i++) {
|
||||||
if (LevelScreen.buttonLevels[i]!=null) {
|
if (LevelScreen.buttonLevels[i]!=null) {
|
||||||
|
|
Loading…
Reference in New Issue