fix: gestion des résolution plein écran ou non création de préférences par défaut desactivation des résolutions sous android correction bogues affichages

This commit is contained in:
Nicolas Hordé 2016-01-05 23:33:05 +01:00
parent 1b5cc4ad5c
commit 5f91eb41ca
4 changed files with 89 additions and 15 deletions

View File

@ -22,12 +22,14 @@ public class ButtonLevel extends ImageTextButton {
TextureRegion Finalled,Locked; TextureRegion Finalled,Locked;
Label Thelabel; Label Thelabel;
float scale; float scale;
float ratio;
ImageTextButtonStyle style; ImageTextButtonStyle style;
LabelStyle stylelabel; LabelStyle stylelabel;
public ButtonLevel(Level level, boolean Activated) { public ButtonLevel(Level level, boolean Activated,float ratio) {
super(level.Name, AssetLoader.Skin_level, "world"+String.valueOf(level.aWorld)); super(level.Name, AssetLoader.Skin_level, "world"+String.valueOf(level.aWorld));
this.level=level; this.level=level;
this.ratio=ratio;
this.Activated=Activated; this.Activated=Activated;
if (level.Special==true) { if (level.Special==true) {
Finalled=AssetLoader.Skin_level.getAtlas().findRegion("boss"); Finalled=AssetLoader.Skin_level.getAtlas().findRegion("boss");
@ -38,17 +40,17 @@ public class ButtonLevel extends ImageTextButton {
} }
this.setColor(1f, 0.47f+(float)level.X/1024f*0.529f,0.607f+(float)level.X/768f*0.392f, 1f); this.setColor(1f, 0.47f+(float)level.X/1024f*0.529f,0.607f+(float)level.X/768f*0.392f, 1f);
this.scale=1f; this.scale=1f;
this.setBounds(level.X, level.Y*AssetLoader.ratio, 111*scale, 125*scale); this.setBounds(level.X, level.Y*ratio, 111*scale, 125*scale);
Thelabel=new Label(level.Element, AssetLoader.Skin_level,"Levelshort"); Thelabel=new Label(level.Element, AssetLoader.Skin_level,"Levelshort");
Thelabel.setColor(level.X/1024f,level.X/1024f,level.X/1024f,1f); Thelabel.setColor(level.X/1024f,level.X/1024f,level.X/1024f,1f);
Thelabel.setPosition(level.X+54*scale, level.Y*AssetLoader.ratio+20*scale, Align.bottom | Align.center); Thelabel.setPosition(level.X+54*scale, level.Y*ratio+20*scale, Align.bottom | Align.center);
} }
@Override @Override
public void setScale(float scale) { public void setScale(float scale) {
this.scale=scale; this.scale=scale;
this.setBounds(level.X, level.Y*AssetLoader.ratio, 111*scale, 125*scale); this.setBounds(level.X, level.Y*ratio, 111*scale, 125*scale);
Thelabel.setPosition(level.X+54*scale, level.Y*AssetLoader.ratio+20*scale, Align.bottom | Align.center); Thelabel.setPosition(level.X+54*scale, level.Y*ratio+20*scale, Align.bottom | Align.center);
stylelabel=Thelabel.getStyle(); stylelabel=Thelabel.getStyle();
//stylelabel.font.setScale(scale); //stylelabel.font.setScale(scale);
Thelabel.setStyle(stylelabel); Thelabel.setStyle(stylelabel);
@ -71,7 +73,7 @@ public class ButtonLevel extends ImageTextButton {
level.X=x; level.X=x;
level.Y=y; level.Y=y;
Thelabel.setColor(level.X/1024f,level.X/1024f,level.X/1024f,1f); Thelabel.setColor(level.X/1024f,level.X/1024f,level.X/1024f,1f);
Thelabel.setPosition(level.X+54*scale, level.Y*AssetLoader.ratio+20*scale, Align.bottom | Align.center); Thelabel.setPosition(level.X+54*scale, level.Y*ratio+20*scale, Align.bottom | Align.center);
this.setColor(1f, 0.47f+(float)level.X/1024f*0.529f,0.607f+(float)level.X/768f*0.392f, 1f); this.setColor(1f, 0.47f+(float)level.X/1024f*0.529f,0.607f+(float)level.X/768f*0.392f, 1f);
} }
@ -79,10 +81,10 @@ public class ButtonLevel extends ImageTextButton {
public void draw(Batch batch, float parentAlpha) { public void draw(Batch batch, float parentAlpha) {
super.draw(batch, parentAlpha); super.draw(batch, parentAlpha);
if (level.Special) { if (level.Special) {
batch.draw(Finalled,level.X,level.Y*AssetLoader.ratio,Finalled.getRegionWidth()*scale,Finalled.getRegionHeight()*scale); batch.draw(Finalled,level.X,level.Y*ratio,Finalled.getRegionWidth()*scale,Finalled.getRegionHeight()*scale);
} }
if (!Activated) { if (!Activated) {
batch.draw(Locked,level.X+this.getWidth()-Locked.getRegionWidth(),level.Y*AssetLoader.ratio+this.getHeight()-Locked.getRegionHeight(),Locked.getRegionWidth()*scale,Locked.getRegionHeight()*scale); batch.draw(Locked,level.X+this.getWidth()-Locked.getRegionWidth(),level.Y*ratio+this.getHeight()-Locked.getRegionHeight(),Locked.getRegionWidth()*scale,Locked.getRegionHeight()*scale);
} }
Thelabel.draw(batch, 1f); Thelabel.draw(batch, 1f);
} }

View File

@ -1,7 +1,10 @@
package fr.evolving.assets; package fr.evolving.assets;
import com.badlogic.gdx.Gdx; import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.Graphics;
import com.badlogic.gdx.Graphics.DisplayMode;
import com.badlogic.gdx.Preferences; import com.badlogic.gdx.Preferences;
import com.badlogic.gdx.math.Vector2;
public class Preference { public class Preference {
public static Preferences prefs; public static Preferences prefs;
@ -13,7 +16,45 @@ public class Preference {
if (prefs.contains("log")) if (prefs.contains("log"))
return prefs.getInteger("log"); return prefs.getInteger("log");
else else
{
defaults();
return Gdx.app.LOG_INFO; return Gdx.app.LOG_INFO;
}
}
public static Vector2 getmaxresolution() {
Graphics.DisplayMode[] modes=Gdx.graphics.getDisplayModes();
int totalpixel=0;
int res;
for(DisplayMode mode:modes) {
int temppixel=mode.height*mode.width;
if (temppixel>totalpixel) totalpixel=temppixel;
}
for(DisplayMode mode:modes)
if (totalpixel==mode.height*mode.width)
return new Vector2(mode.width,mode.height);
return null;
}
public static void defaults() {
Vector2 maxres=getmaxresolution();
Gdx.app.log("Preferences","Preference par defaut avec resolution native :"+maxres.x+"x"+maxres.y);
Preference.prefs.putInteger("ResolutionX", (int)maxres.x);
Preference.prefs.putInteger("ResolutionY", (int)maxres.y);
Preference.prefs.putInteger("Resolution", 9);
Preference.prefs.putBoolean("Fullscreen", true);
Preference.prefs.putBoolean("Sound", true);
Preference.prefs.putBoolean("Tutorial", true);
Preference.prefs.putBoolean("VSync", true);
Preference.prefs.putBoolean("Refresh", false);
Preference.prefs.putBoolean("Animation", true);
Preference.prefs.putBoolean("Language", false);
Preference.prefs.putFloat("Effect", 1.0f);
Preference.prefs.putFloat("Music",0.75f);
Preference.prefs.putInteger("Adaptation", 1);
Preference.prefs.putInteger("Quality", 2);
Preference.prefs.putInteger("log", Gdx.app.LOG_INFO);
Preference.prefs.flush();
} }
public static void debug() { public static void debug() {

View File

@ -7,9 +7,11 @@ import java.util.Iterator;
import java.util.Timer; import java.util.Timer;
import java.util.TimerTask; import java.util.TimerTask;
import com.badlogic.gdx.Application.ApplicationType;
import com.badlogic.gdx.Game; import com.badlogic.gdx.Game;
import com.badlogic.gdx.Gdx; import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.Graphics.DisplayMode; import com.badlogic.gdx.Graphics.DisplayMode;
import com.badlogic.gdx.Graphics;
import com.badlogic.gdx.InputMultiplexer; import com.badlogic.gdx.InputMultiplexer;
import com.badlogic.gdx.InputProcessor; import com.badlogic.gdx.InputProcessor;
import com.badlogic.gdx.Screen; import com.badlogic.gdx.Screen;
@ -153,15 +155,23 @@ public class GameScreen implements Screen {
rmax("resolution Native",0,0) rmax("resolution Native",0,0)
; ;
private final String text; private final String text;
private final int resx,resy; private int resx,resy;
boolean full;
private resolutions(final String text,int resx,int resy) { private resolutions(final String text,int resx,int resy) {
this.text = text; this.text = text;
this.resx=resx; this.resx=resx;
this.resy=resy; this.resy=resy;
} }
@Override @Override
public String toString() { public String toString()
return text; {
if (full)
return text+" Fullscreen";
else
return text;
}
public void SetFull(boolean fullscreen) {
full=fullscreen;
} }
public int getResolutionX() { public int getResolutionX() {
return resx; return resx;
@ -169,6 +179,12 @@ public class GameScreen implements Screen {
public int getResolutionY() { public int getResolutionY() {
return resy; return resy;
} }
public void setResolutionX(int x) {
resx=x;
}
public void setResolutionY(int y) {
resy=y;
}
} }
GestureDetector gesturedetector; GestureDetector gesturedetector;
@ -262,7 +278,7 @@ public class GameScreen implements Screen {
objectives=new Objectives(); objectives=new Objectives();
objectives.setVictory(level.Victory); objectives.setVictory(level.Victory);
objectives.setPosition(890,AssetLoader.height-95); objectives.setPosition(890,AssetLoader.height-95);
buttonlevel=new ButtonLevel(level,true); buttonlevel=new ButtonLevel(level,true,1.0f);
buttonlevel.setPosition(1760,AssetLoader.height-125); buttonlevel.setPosition(1760,AssetLoader.height-125);
Gdx.app.debug(getClass().getSimpleName(),"Création de la barre d'information"); Gdx.app.debug(getClass().getSimpleName(),"Création de la barre d'information");
info_tech=new ImageTextButton("0",AssetLoader.Skin_level,"info_tech"); info_tech=new ImageTextButton("0",AssetLoader.Skin_level,"info_tech");
@ -645,7 +661,7 @@ public class GameScreen implements Screen {
stage_info.addActor(info_cout); stage_info.addActor(info_cout);
stage_info.addActor(info_desc); stage_info.addActor(info_desc);
stage_menu.addActor(map); stage_menu.addActor(map);
stage_tooltip.addActor(tooltip); //stage_tooltip.addActor(tooltip);
stage.addActor(objectives); stage.addActor(objectives);
stage.addActor(buttonlevel); stage.addActor(buttonlevel);
stage.addActor(rayon); stage.addActor(rayon);
@ -886,7 +902,6 @@ public class GameScreen implements Screen {
} }
public Table Createoption() { public Table Createoption() {
Table layer = new Table();
winOptions = new Window("Options", AssetLoader.Skin_ui); winOptions = new Window("Options", AssetLoader.Skin_ui);
winOptions.add(SettingsVideo()).row(); winOptions.add(SettingsVideo()).row();
winOptions.add(SettingsAudio()).row(); winOptions.add(SettingsAudio()).row();
@ -997,6 +1012,22 @@ public class GameScreen implements Screen {
tablev3.add(selTexturequal).left().row(); tablev3.add(selTexturequal).left().row();
table.add(tablev3).left(); table.add(tablev3).left();
table.row(); table.row();
if(Gdx.app.getType() == ApplicationType.Desktop) {
Graphics.DisplayMode[] modes=Gdx.graphics.getDisplayModes();
for(resolutions res:resolutions.values()) {
res.SetFull(false);
for(DisplayMode mode:modes) {
if (res.resx==mode.width && res.resy==mode.height)
res.SetFull(true);
}
}
Vector2 maxres=Preference.getmaxresolution();
resolutions.rmax.SetFull(true);
resolutions.rmax.setResolutionX((int)maxres.x);
resolutions.rmax.setResolutionY((int)maxres.y);
}
else
selResolution.setDisabled(true);
return table; return table;
} }

View File

@ -74,7 +74,7 @@ public class LevelScreen implements Screen {
buttonLevels = new ButtonLevel[10]; buttonLevels = new ButtonLevel[10];
for (Level level :thelevels) { for (Level level :thelevels) {
if (level!=null && level.aWorld==aworld) { if (level!=null && level.aWorld==aworld) {
buttonLevels[i]=new ButtonLevel(level,true); buttonLevels[i]=new ButtonLevel(level,true,AssetLoader.ratio);
Gdx.app.debug(getClass().getSimpleName(),"Ajout du niveau :"+level.Name+""+String.valueOf(level.aLevel)); Gdx.app.debug(getClass().getSimpleName(),"Ajout du niveau :"+level.Name+""+String.valueOf(level.aLevel));
buttonLevels[i++].addListener(new ClickListener(){ buttonLevels[i++].addListener(new ClickListener(){
@Override @Override