Skip to content

Commit

Permalink
Merge Fix 0.14.0
Browse files Browse the repository at this point in the history
Show a "Loading..." before startup.

#77 #79

Option to remove some spinner UI.

Moved db and config files around.

use Opsu ErrorHandler to generate report.

Too lazy to do gradient.
  • Loading branch information
fd committed Jan 22, 2017
1 parent 2e2c317 commit a7719c3
Show file tree
Hide file tree
Showing 36 changed files with 306 additions and 174 deletions.
8 changes: 8 additions & 0 deletions src/fluddokt/ex/DeviceInfo.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package fluddokt.ex;

public class DeviceInfo {
public static DeviceInfo info = new DeviceInfo();
public String getInfo() {
return "";
}
}
20 changes: 19 additions & 1 deletion src/fluddokt/opsu/fake/DynamicFreeTypeFont.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import com.badlogic.gdx.graphics.g2d.freetype.FreeType.SizeMetrics;
import com.badlogic.gdx.graphics.glutils.PixmapTextureData;
import com.badlogic.gdx.utils.GdxRuntimeException;
import com.badlogic.gdx.utils.IntFloatMap;
import com.badlogic.gdx.utils.IntMap;

public class DynamicFreeTypeFont {
Expand Down Expand Up @@ -56,6 +57,8 @@ public DynamicFreeTypeFont(FileHandle font, Font fontParam) {
// ArrayList<Texture> pages = new ArrayList<Texture>();
//HashMap<Character, CharInfo> charmap = new HashMap<Character, CharInfo>();
IntMap<CharInfo> charmap = new IntMap<CharInfo>();
IntFloatMap charwidth = new IntFloatMap();

Pixmap curPixmap;
Texture curTexture;

Expand Down Expand Up @@ -280,12 +283,27 @@ public int getHeight(String str) {
public int getWidth(String str) {
float len = 0;
for (int i = 0; i < str.length(); i++) {
float t = getCharInfo(str.charAt(i)).horadvance;
char c = str.charAt(i);
if (!charwidth.containsKey(c)) {
charwidth.put(c, getCharWidth(c));
}
float t = charwidth.get(c, 0);
len += t;
}
return (int) len;
}

private float getCharWidth(char c) {
FreeType.loadChar(face, c,
fontParam.size < 16 ? FreeType.FT_LOAD_DEFAULT :
FreeType.FT_LOAD_NO_HINTING
|FreeType.FT_LOAD_NO_BITMAP
);
GlyphSlot slot = face.getGlyph();
GlyphMetrics metrics = slot.getMetrics();
return to26p6float(metrics.getHoriAdvance());
}

public int getLineHeight() {
return ascent - descent ;

Expand Down
100 changes: 52 additions & 48 deletions src/fluddokt/opsu/fake/GameOpsu.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,6 @@
import java.io.IOException;
import java.io.PrintWriter;
import java.io.StringWriter;
import java.net.URI;
import java.net.URISyntaxException;

import itdelatrisu.opsu.ErrorHandler;
import itdelatrisu.opsu.GameImage;
import itdelatrisu.opsu.Opsu;
Expand All @@ -25,7 +22,7 @@

public class GameOpsu extends com.badlogic.gdx.Game {

final String VERSION = "OpsuAnd0.13.0a";
public final static String VERSION = "OpsuAnd0.14.0a";
public StateBasedGame sbg;

Stage stage;
Expand All @@ -36,6 +33,8 @@ public class GameOpsu extends com.badlogic.gdx.Game {
boolean inited = false;

private int dialogCnt;

Label loadingLabel;
public GameOpsu() {
gameOpsu = this;
}
Expand Down Expand Up @@ -82,53 +81,61 @@ public void dispose() {
}
}

int delayLoad = 0;
@Override
public void render() {
super.render();
if (dialogCnt == 0){

if (delayLoad>2 && dialogCnt == 0){
try{
if (!inited){
if (Gdx.graphics.getWidth() > Gdx.graphics.getHeight()){
Opsu.main(new String[0]);
sbg = Opsu.opsu;
sbg.gc.width = Gdx.graphics.getWidth();
sbg.gc.height = Gdx.graphics.getHeight();


if (!inited){
if (Gdx.graphics.getWidth() > Gdx.graphics.getHeight()){
Opsu.main(new String[0]);
sbg = Opsu.opsu;
sbg.gc.width = Gdx.graphics.getWidth();
sbg.gc.height = Gdx.graphics.getHeight();

Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);

try {
sbg.init();
} catch (SlickException e) {
e.printStackTrace();
error("SlickErrorInit", e);
}
File dataDir = Options.DATA_DIR;
System.out.println("dataDir :"+dataDir+" "+dataDir.isExternal()+" "+dataDir.exists());
if(dataDir.isExternal()){
File nomediafile = new File(dataDir, ".nomedia");
if(!nomediafile.exists())
new FileOutputStream(nomediafile.getIOFile()).close();
}
System.out.println("Local Dir:"+Gdx.files.getLocalStoragePath());
Gdx.input.setInputProcessor(new InputMultiplexer(stage, sbg));
inited = true;
table.removeActor(loadingLabel);
}
} else {
Color bgcolor = Graphics.bgcolor;
if (bgcolor != null)
Gdx.gl.glClearColor(bgcolor.r, bgcolor.g, bgcolor.b, 1);
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
try {
sbg.init();
sbg.render();
} catch (SlickException e) {
e.printStackTrace();
error("SlickErrorInit", e);
error("SlickErrorRender", e);
}
File dataDir = Options.DATA_DIR;
System.out.println("dataDir :"+dataDir+" "+dataDir.isExternal()+" "+dataDir.exists());
if(dataDir.isExternal()){
File nomediafile = new File(dataDir, ".nomedia");
if(!nomediafile.exists())
new FileOutputStream(nomediafile.getIOFile()).close();
}
Gdx.input.setInputProcessor(new InputMultiplexer(stage, sbg));
inited = true;
//loadingImage.draw(32, 32,128, 128);
Graphics.checkMode(0);
}
} else {
Color bgcolor = Graphics.bgcolor;
if (bgcolor != null)
Gdx.gl.glClearColor(bgcolor.r, bgcolor.g, bgcolor.b, 1);
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
try {
sbg.render();
} catch (SlickException e) {
} catch (Throwable e){
e.printStackTrace();
error("SlickErrorRender", e);
error("RenderError", e);
}
Graphics.checkMode(0);
}
} catch (Throwable e){
e.printStackTrace();
error("RenderError", e);
}
} else {
if (delayLoad<=2)
delayLoad++;
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
}
stage.act(Gdx.graphics.getDeltaTime());
Expand Down Expand Up @@ -178,6 +185,7 @@ public void uncaughtException(Thread t, Throwable e) {
+ Gdx.files.getLocalStoragePath() , null);
}
}

Gdx.graphics.setVSync(false);
Gdx.input.setCatchBackKey(true);

Expand All @@ -187,6 +195,9 @@ public void uncaughtException(Thread t, Throwable e) {

Graphics.init();

loadingLabel = new Label("Loading...", skin);
table.addActor(loadingLabel);

}

public static void error(String string, Throwable e) {
Expand Down Expand Up @@ -217,16 +228,9 @@ protected void result(Object object) {
try {
System.out.println("Reporting");
Desktop.getDesktop().browse(
new URI("https://github.com/fluddokt/opsu/issues/new?"
+"title="+java.net.URLEncoder.encode(title, "UTF-8")
+"&body="+java.net.URLEncoder.encode(title+"\n"+VERSION+"\n"+body ,"UTF-8")
)
ErrorHandler.getIssueURI(title, e, body)
);
} catch (URISyntaxException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
} catch (IOException e) {
e.printStackTrace();
}
}
Expand Down
59 changes: 26 additions & 33 deletions src/fluddokt/opsu/fake/Graphics.java
Original file line number Diff line number Diff line change
Expand Up @@ -161,41 +161,34 @@ public void drawLine(float x1, float y1, float x2, float y2) {
shapeRender.line(x1, y1, x2, y2);
}


static void endMode() {
Gdx.gl20.glLineWidth(lineWidth);
switch (mode) {
case SPRITE:
batch.end();
break;
case SHAPEFILLED:
case SHAPELINE:
shapeRender.end();
break;
}
mode = 0;
}

static void beginMode(int nmode) {
switch (nmode) {
case SPRITE:
batch.begin();
break;
case SHAPEFILLED:
Gdx.gl.glEnable(GL20.GL_BLEND);
shapeRender.begin(ShapeType.Filled);
break;
case SHAPELINE:
shapeRender.begin(ShapeType.Line);
break;
}
mode = nmode;
}

public static void checkMode(int nmode) {
if (mode != nmode) {
endMode();
beginMode(nmode);
Gdx.gl20.glLineWidth(lineWidth);
//end
switch (mode) {
case SPRITE:
batch.end();
break;
case SHAPEFILLED:
case SHAPELINE:
shapeRender.end();
break;
}
//begin
switch (nmode) {
case SPRITE:
batch.begin();
break;
case SHAPEFILLED:
Gdx.gl.glEnable(GL20.GL_BLEND);
shapeRender.begin(ShapeType.Filled);
break;
case SHAPELINE:
Gdx.gl.glEnable(GL20.GL_BLEND);
shapeRender.begin(ShapeType.Line);
break;
}
mode = nmode;
}
}

Expand Down
8 changes: 8 additions & 0 deletions src/fluddokt/opsu/fake/Image.java
Original file line number Diff line number Diff line change
Expand Up @@ -457,5 +457,13 @@ public void drawEmbedded(float x, float y, float w, float h, int angle) {
w, h, angle);
}

public void setFlipped(boolean x, boolean y) {
/* isFlipped false true
flip? false false true
true true false
*/
tex.flip(x ^ tex.isFlipX(), y ^ !tex.isFlipY());
}


}
8 changes: 8 additions & 0 deletions src/fluddokt/opsu/fake/Input.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
package fluddokt.opsu.fake;


import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.Input.Buttons;
import com.badlogic.gdx.Input.Keys;

import fluddokt.opsu.fake.gui.MouseListener;

public class Input {

public static final int MOUSE_LEFT_BUTTON = Buttons.LEFT;
Expand Down Expand Up @@ -123,4 +126,9 @@ public void setMouseRighButtontDown(boolean b) {
isRightButtonDown = b;
}

public void addMouseListener(MouseListener mouseListener) {
GameOpsu.gameOpsu.sbg.addKeyListener(mouseListener);

}

}
1 change: 0 additions & 1 deletion src/fluddokt/opsu/fake/Music.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ public Music(String path, boolean b) {
try {
music = new MusicJL3(path, this);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
//else
Expand Down
1 change: 0 additions & 1 deletion src/fluddokt/opsu/fake/MusicJL3.java
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,6 @@ public String getName() {

@Override
public void setPitch(float pitch) {
// TODO Auto-generated method stub
player.setPitch(pitch);
}

Expand Down
23 changes: 0 additions & 23 deletions src/fluddokt/opsu/fake/StateBasedGame.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,6 @@ public abstract class StateBasedGame extends Game2 implements InputProcessor {
public StateBasedGame(String name) {
this.title = name;
Display.setTitle(name);
// gc.width = Gdx.graphics.getWidth();
// gc.height = Gdx.graphics.getHeight();
}

public BasicGameState getState(int state) {
Expand All @@ -46,7 +44,6 @@ public void enterState(int newState) {
}

public void enterState(int newState, Transition leaveT, Transition enterT) {
System.out.println("Enter State Transition " + newState+" "+enterT+" "+leaveT);
this.enterT = enterT;
this.leaveT = leaveT;
oldState = currentState;
Expand Down Expand Up @@ -137,27 +134,7 @@ public void render() throws SlickException {
} else {
currentState.render(gc, this, g);
}

/*
if(Graphics.curFont!=null){
if(GameContainer.music!=null)
g.drawString(""
+" "+(GameContainer.music.lastTime&0xffff)
+" "+pad(""+(int)((GameContainer.music.music.getPosition()-GameContainer.music.lastGetPos)*1000))
+" avg:"+pad(""+(int)(GameContainer.music.avgDiff*1000)/1000f)
//+" "+GameContainer.music.music.getPosition()
//+" "+GameContainer.music.lastGPos
, 10, 100);
}
*/
}
}

private String pad(String s) {
while(s.length()<6){
s=' '+s;
}
return s;
}

public void init() throws SlickException {
Expand Down
2 changes: 0 additions & 2 deletions src/fluddokt/opsu/fake/TextField.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,7 @@

import com.badlogic.gdx.Gdx;

import fluddokt.opsu.fake.gui.AbstractComponent;
import fluddokt.opsu.fake.gui.GInputAdapter;
import fluddokt.opsu.fake.gui.GInputListener;

public class TextField extends GInputAdapter {

Expand Down
Loading

0 comments on commit a7719c3

Please sign in to comment.