Merge pull request #2022 from kevlahnota/newmaster2

update LoadingOverlay
This commit is contained in:
Anthony Calosa
2022-12-05 20:18:37 +08:00
committed by GitHub
4 changed files with 85 additions and 12 deletions

View File

@@ -52,6 +52,7 @@ public class Graphics {
private final ShaderProgram shaderHueShift = new ShaderProgram(Shaders.vertPixelateShader, Shaders.fragHueShift); private final ShaderProgram shaderHueShift = new ShaderProgram(Shaders.vertPixelateShader, Shaders.fragHueShift);
private final ShaderProgram shaderRoundedRect = new ShaderProgram(Shaders.vertPixelateShader, Shaders.fragRoundedRect); private final ShaderProgram shaderRoundedRect = new ShaderProgram(Shaders.vertPixelateShader, Shaders.fragRoundedRect);
private final ShaderProgram shaderNoiseFade = new ShaderProgram(Shaders.vertPixelateShader, Shaders.fragNoiseFade); private final ShaderProgram shaderNoiseFade = new ShaderProgram(Shaders.vertPixelateShader, Shaders.fragNoiseFade);
private final ShaderProgram shaderPortal = new ShaderProgram(Shaders.vertPixelateShader, Shaders.fragPortal);
private Texture dummyTexture = null; private Texture dummyTexture = null;
@@ -944,6 +945,28 @@ public class Graphics {
} }
} }
public void drawPortalFade(TextureRegion image, float x, float y, float w, float h, Float time, boolean opaque) {
if (image == null)
return;
if (time != null) {
batch.end();
shaderPortal.bind();
shaderPortal.setUniformf("u_resolution", image.getRegionWidth(), image.getRegionHeight());
shaderPortal.setUniformf("u_time", time);
shaderPortal.setUniformf("u_opaque", opaque ? 1f : 0f);
batch.setShader(shaderPortal);
batch.begin();
//draw
batch.draw(image, x, y, w, h);
//reset
batch.end();
batch.setShader(null);
batch.begin();
} else {
drawImage(image, x, y, w, h);
}
}
public void drawHueShift(Texture image, float x, float y, float w, float h, Float time) { public void drawHueShift(Texture image, float x, float y, float w, float h, Float time) {
if (image == null) if (image == null)
return; return;

View File

@@ -42,6 +42,52 @@ public class Shaders {
" v_texCoords = a_texCoord0;\n" + " v_texCoords = a_texCoord0;\n" +
" gl_Position = u_projTrans * a_position;\n" + " gl_Position = u_projTrans * a_position;\n" +
"}"; "}";
public static final String fragPortal="#ifdef GL_ES\n" +
"#define LOWP lowp\n" +
"#define PI 3.14159\n" +
"precision mediump float;\n" +
"#else\n" +
"#define LOWP \n" +
"#define PI 3.14159\n" +
"#endif\n" +
"\n" +
"uniform sampler2D u_texture;\n" +
"varying vec2 v_texCoords;\n" +
"uniform vec2 u_resolution;\n" +
"uniform float u_time;\n" +
"uniform float u_opaque;\n" +
"\n" +
"void main()\n" +
"{\n" +
" vec2 uv = v_texCoords;\n" +
" \n" +
" float t1 = u_time;\n" +
" if (t1>1.25)\n" +
" t1=0.0;\n" +
" t1 = clamp(t1,0.0,1.0);\n" +
" float nt = fract(t1);\n" +
"\n" +
" float eRad = 1.5 * nt;\n" +
" float eAng = (2. * PI) * (nt*4.5);\n" +
"\n" +
" vec2 centre = vec2(.5,.5);\n" +
" uv -= centre;\n" +
" float len = length(uv * vec2(u_resolution.x / u_resolution.y, 1.));\n" +
" float ang = atan(uv.y, uv.x) + eAng * smoothstep(eRad, 0., len);\n" +
" float rad = length(uv);\n" +
" \n" +
" vec3 col1 = texture2D(u_texture, vec2(rad * cos(ang), rad * sin(ang)) + centre ).xyz; \n" +
" float nt2 = (len*2.0) - (nt*2.0);\n" +
" nt2 = mix(1.0,nt2-nt,nt);\n" +
" nt2 = clamp(nt2,0.0,1.0);\n" +
" \tvec3 col2 = texture2D(u_texture,uv+ centre).xyz; \n" +
" col2 = vec3(0.0);\n" +
" \n" +
" vec4 col3 = vec4(mix(col2,col1,nt2), 1.);\n" +
" if (u_opaque < 1.)" +
" col3.a *= nt2;\n" +
" gl_FragColor = col3;\n" +
"}";
public static final String fragNoiseFade="#ifdef GL_ES\n" + public static final String fragNoiseFade="#ifdef GL_ES\n" +
"#define LOWP lowp\n" + "#define LOWP lowp\n" +
"precision mediump float;\n" + "precision mediump float;\n" +

View File

@@ -119,16 +119,16 @@ public class DuelScene extends ForgeScene {
@Override @Override
public void run(Integer result) { public void run(Integer result) {
if (result == 0) { if (result == 0) {
afterGameEnd(enemyName, finalWinner, true); afterGameEnd(enemyName, finalWinner, true, true);
} }
} }
})); }));
} else { } else {
afterGameEnd(enemyName, winner, false); afterGameEnd(enemyName, winner, false, false);
} }
} }
void afterGameEnd(String enemyName, boolean winner, boolean showOverlay) { void afterGameEnd(String enemyName, boolean winner, boolean showOverlay, boolean alternate) {
Runnable runnable = () -> Gdx.app.postRunnable(()-> { Runnable runnable = () -> Gdx.app.postRunnable(()-> {
SoundSystem.instance.setBackgroundMusic(MusicPlaylist.MENUS); //start background music SoundSystem.instance.setBackgroundMusic(MusicPlaylist.MENUS); //start background music
dungeonEffect = null; dungeonEffect = null;
@@ -144,7 +144,7 @@ public class DuelScene extends ForgeScene {
}); });
if (showOverlay) { if (showOverlay) {
FThreads.invokeInEdtNowOrLater(() -> { FThreads.invokeInEdtNowOrLater(() -> {
matchOverlay = new LoadingOverlay(runnable, true); matchOverlay = new LoadingOverlay(runnable, true, alternate);
matchOverlay.show(); matchOverlay.show();
}); });
} else { } else {
@@ -335,7 +335,7 @@ public class DuelScene extends ForgeScene {
if (FSkin.getAvatars().get(90001) != null) if (FSkin.getAvatars().get(90001) != null)
g.drawImage(FSkin.getAvatars().get(90001), 0, 0, w, h); g.drawImage(FSkin.getAvatars().get(90001), 0, 0, w, h);
} }
}))), false); }))), false, true);
} else { } else {
matchOverlay = new LoadingOverlay(null); matchOverlay = new LoadingOverlay(null);
} }

View File

@@ -24,7 +24,7 @@ public class LoadingOverlay extends FOverlay {
private static final FSkinFont FONT = FSkinFont.get(22); private static final FSkinFont FONT = FSkinFont.get(22);
private BGAnimation bgAnimation; private BGAnimation bgAnimation;
private Runnable runnable; private Runnable runnable;
private boolean afterMatch; private boolean afterMatch, alternate;
private static FSkinColor getOverlayColor() { private static FSkinColor getOverlayColor() {
if (Forge.isMobileAdventureMode) if (Forge.isMobileAdventureMode)
@@ -70,17 +70,18 @@ public class LoadingOverlay extends FOverlay {
textMode = textOnly; textMode = textOnly;
} }
public LoadingOverlay(Runnable toRunBeforeMatch) { public LoadingOverlay(Runnable runnable) {
this(toRunBeforeMatch, false); this(runnable, false, false);
} }
public LoadingOverlay(Runnable toRunBeforeMatch, boolean aftermatch) { public LoadingOverlay(Runnable toRun, boolean aftermatch, boolean otherTransition) {
caption = ""; caption = "";
textMode = true; textMode = true;
textureRegion = Forge.takeScreenshot(); textureRegion = Forge.takeScreenshot();
match = true; match = true;
bgAnimation = new BGAnimation(); bgAnimation = new BGAnimation();
runnable = toRunBeforeMatch; runnable = toRun;
afterMatch = aftermatch; afterMatch = aftermatch;
alternate = otherTransition;
} }
public void setCaption(String caption0) { public void setCaption(String caption0) {
@@ -148,7 +149,7 @@ public class LoadingOverlay extends FOverlay {
} }
private class BGAnimation extends ForgeAnimation { private class BGAnimation extends ForgeAnimation {
float DURATION = 1f; float DURATION = afterMatch ? 0.8f : 1.3f;
private float progress = 0; private float progress = 0;
public void drawBackground(Graphics g) { public void drawBackground(Graphics g) {
@@ -162,7 +163,10 @@ public class LoadingOverlay extends FOverlay {
if (afterMatch) { if (afterMatch) {
g.drawGrayTransitionImage(textureRegion, 0, 0, Forge.getScreenWidth(), Forge.getScreenHeight(), false, percentage); g.drawGrayTransitionImage(textureRegion, 0, 0, Forge.getScreenWidth(), Forge.getScreenHeight(), false, percentage);
} else { } else {
g.drawNoiseFade(textureRegion, 0, 0, Forge.getScreenWidth(), Forge.getScreenHeight(), percentage); if (alternate)
g.drawPortalFade(textureRegion, 0, 0, Forge.getScreenWidth(), Forge.getScreenHeight(), percentage > 0.8f ? 0.8f : percentage, afterMatch);
else
g.drawNoiseFade(textureRegion, 0, 0, Forge.getScreenWidth(), Forge.getScreenHeight(), percentage);
} }
} }