Adventure mode match BG

- add dynamic match background for adventure mode
This commit is contained in:
Anthony Calosa
2022-11-20 11:33:09 +08:00
parent 0278b91bd3
commit ae8ef9dd12
16 changed files with 202 additions and 35 deletions

View File

@@ -41,6 +41,64 @@ public class Graphics {
private final ShaderProgram shaderGrayscale = new ShaderProgram(Gdx.files.internal("shaders").child("grayscale.vert"), Gdx.files.internal("shaders").child("grayscale.frag"));
private final ShaderProgram shaderWarp = new ShaderProgram(Gdx.files.internal("shaders").child("grayscale.vert"), Gdx.files.internal("shaders").child("warp.frag"));
private final ShaderProgram shaderUnderwater = new ShaderProgram(Gdx.files.internal("shaders").child("grayscale.vert"), Gdx.files.internal("shaders").child("underwater.frag"));
private static String vertexShaderDayNight = "attribute vec4 " + ShaderProgram.POSITION_ATTRIBUTE + ";\n"
+ "attribute vec4 " + ShaderProgram.COLOR_ATTRIBUTE + ";\n"
+ "attribute vec2 " + ShaderProgram.TEXCOORD_ATTRIBUTE + "0;\n"
+ "uniform mat4 u_projTrans;\n"
+ "uniform float u_timeOfDay;\n"
+ "varying vec4 v_color;\n"
+ "varying vec4 v_tweak;\n"
+ "varying vec2 v_texCoords;\n"
+ "varying float v_lightFix;\n"
+ "const vec3 forward = vec3(1.0 / 3.0);\n"
+ "\n"
+ "void main()\n"
+ "{\n"
+ " float st = sin(1.5707963 * sin(0.2617994 * u_timeOfDay)); // Whenever st is very high or low... \n"
+ " float ct = sin(1.5707963 * cos(0.2617994 * u_timeOfDay)); // ...ct is close to 0, and vice versa. \n"
+ " float dd = ct * ct; // Positive, small; used for dawn and dusk. \n"
+ " v_color = " + ShaderProgram.COLOR_ATTRIBUTE + ";\n"
+ " v_color.w = v_color.w * (255.0/254.0);\n"
+ " vec3 oklab = mat3(+0.2104542553, +1.9779984951, +0.0259040371, +0.7936177850, -2.4285922050, +0.7827717662, -0.0040720468, +0.4505937099, -0.8086757660) *"
+ " pow(mat3(0.4121656120, 0.2118591070, 0.0883097947, 0.5362752080, 0.6807189584, 0.2818474174, 0.0514575653, 0.1074065790, 0.6302613616) \n"
+ " * (v_color.rgb * v_color.rgb), forward);\n"
+ " // The next four lines make use of the time-based variables st, ct, and dd. Edit to fit. \n"
+ " v_color.x = clamp(oklab.x + (0.0625 * st), 0.0, 1.0);\n"
+ " v_color.yz = clamp(oklab.yz + vec2(0.0625 * dd + 0.03125 * st, 0.1 * st), -1.0, 1.0) * ((dd + 0.25) * 0.5);\n"
+ " v_tweak = vec4(0.2 * st + 0.5);\n"
+ " v_tweak.w = pow((1.0 - 0.125 * st), 1.709);\n"
+ " v_lightFix = 1.0 + pow(v_tweak.w, 1.41421356);\n"
+ " v_texCoords = " + ShaderProgram.TEXCOORD_ATTRIBUTE + "0;\n"
+ " gl_Position = u_projTrans * " + ShaderProgram.POSITION_ATTRIBUTE + ";\n"
+ "}\n";
private static String fragmentShaderDayNight =
"#ifdef GL_ES\n" +
"#define LOWP lowp\n" +
"precision mediump float;\n" +
"#else\n" +
"#define LOWP \n" +
"#endif\n" +
"varying vec2 v_texCoords;\n" +
"varying LOWP vec4 v_color;\n" +
"varying LOWP vec4 v_tweak;\n" +
"varying float v_lightFix;\n" +
"uniform sampler2D u_texture;\n" +
"const vec3 forward = vec3(1.0 / 3.0);\n" +
"void main()\n" +
"{\n" +
" vec4 tgt = texture2D( u_texture, v_texCoords );\n" +
" vec3 lab = mat3(+0.2104542553, +1.9779984951, +0.0259040371, +0.7936177850, -2.4285922050, +0.7827717662, -0.0040720468, +0.4505937099, -0.8086757660) *" +
" pow(mat3(0.4121656120, 0.2118591070, 0.0883097947, 0.5362752080, 0.6807189584, 0.2818474174, 0.0514575653, 0.1074065790, 0.6302613616) \n" +
" * (tgt.rgb * tgt.rgb), forward);\n" +
" lab.x = clamp(pow(lab.x, v_tweak.w) * v_lightFix * v_tweak.x + v_color.x - 1.0, 0.0, 1.0);\n" +
" lab.yz = clamp((lab.yz * v_tweak.yz + v_color.yz) * 1.5, -1.0, 1.0);\n" +
" lab = mat3(1.0, 1.0, 1.0, +0.3963377774, -0.1055613458, -0.0894841775, +0.2158037573, -0.0638541728, -1.2914855480) * lab;\n" +
" gl_FragColor = vec4(sqrt(clamp(" +
" mat3(+4.0767245293, -1.2681437731, -0.0041119885, -3.3072168827, +2.6093323231, -0.7034763098, +0.2307590544, -0.3411344290, +1.7068625689) *\n" +
" (lab * lab * lab)," +
" 0.0, 1.0)), v_color.a * tgt.a);\n" +
"}";
private final ShaderProgram shaderNightDay = new ShaderProgram(vertexShaderDayNight, fragmentShaderDayNight);
private Texture dummyTexture = null;
@@ -888,6 +946,25 @@ public class Graphics {
setAlphaComposite(oldalpha);
}
}
public void drawNightDay(FImage image, float x, float y, float w, float h, Float time) {
if (image == null)
return;
if (time != null) {
batch.end();
shaderNightDay.bind();
shaderNightDay.setUniformf("u_timeOfDay", time);
batch.setShader(shaderNightDay);
batch.begin();
//draw
image.draw(this, x, y, w, h);
//reset
batch.end();
batch.setShader(null);
batch.begin();
} else {
drawImage(image, x, y, w, h);
}
}
public void drawUnderWaterImage(TextureRegion image, float x, float y, float w, float h, float time) {
batch.end();
shaderUnderwater.bind();

View File

@@ -8,13 +8,16 @@ import forge.Graphics;
import forge.LobbyPlayer;
import forge.adventure.character.EnemySprite;
import forge.adventure.character.PlayerSprite;
import forge.adventure.data.BiomeData;
import forge.adventure.data.EffectData;
import forge.adventure.data.EnemyData;
import forge.adventure.data.ItemData;
import forge.adventure.player.AdventurePlayer;
import forge.adventure.stage.IAfterMatch;
import forge.adventure.stage.MapStage;
import forge.adventure.util.Config;
import forge.adventure.util.Current;
import forge.adventure.world.World;
import forge.assets.FBufferedImage;
import forge.assets.FSkin;
import forge.deck.Deck;
@@ -335,11 +338,28 @@ public class DuelScene extends ForgeScene {
public void initDuels(PlayerSprite playerSprite, EnemySprite enemySprite) {
this.player = playerSprite;
this.enemy = enemySprite;
this.playerDeck = (Deck) AdventurePlayer.current().getSelectedDeck().copyTo("PlayerDeckCopy");
this.playerDeck = (Deck) Current.player().getSelectedDeck().copyTo("PlayerDeckCopy");
this.chaosBattle = this.enemy.getData().copyPlayerDeck && Current.player().isFantasyMode();
this.AIExtras.clear();
this.playerExtras.clear();
}
public String getCurrentLocation() {
String location = "";
if(MapStage.getInstance().isInMap())
location = TileMapScene.instance().rootPoint.getData().type;
else {
World world= Current.world();
int currentBiome = World.highestBiome(world.getBiome((int) player.getX() / world.getTileSize(), (int) player.getY() / world.getTileSize()));
List<BiomeData> biomeData = Current.world().getData().GetBiomes();
try {
BiomeData data = biomeData.get(currentBiome);
location = data.name;
} catch (Exception e) {
e.printStackTrace();
}
}
return location;
}
private String selectAI(String ai) { //Decide opponent AI.
String AI = ""; //Use user settings if it's null.

View File

@@ -324,11 +324,6 @@ public class FSkin {
image.load(manager, preferredIcons);
}
}
for (FSkinTexture texture : FSkinTexture.values()) {
if (texture != FSkinTexture.BG_TEXTURE) {
texture.load();
}
}
//assemble avatar textures
int counter = 0;

View File

@@ -19,10 +19,22 @@ public enum FSkinTexture implements FImage {
BG_MATCH_NIGHT(ForgeConstants.MATCH_BG_NIGHT_FILE, false, false),
BG_SPACE(ForgeConstants.SPACE_BG_FILE, false, false),
BG_CHAOS_WHEEL(ForgeConstants.CHAOS_WHEEL_IMG_FILE, false, false),
//Adventure textures
ADV_BG_TEXTURE(ForgeConstants.ADV_TEXTURE_BG_FILE, true, false),
ADV_BG_MATCH(ForgeConstants.ADV_MATCH_BG_FILE, false, false),
ADV_BG_MATCH_DAY(ForgeConstants.ADV_MATCH_BG_DAY_FILE, false, false),
ADV_BG_MATCH_NIGHT(ForgeConstants.ADV_MATCH_BG_NIGHT_FILE, false, false),
ADV_BG_TEXTURE(ForgeConstants.ADV_TEXTURE_BG_FILE, true, false),
ADV_BG_SWAMP(ForgeConstants.ADV_BG_SWAMP_FILE, false, false),
ADV_BG_FOREST(ForgeConstants.ADV_BG_FOREST_FILE, false, false),
ADV_BG_MOUNTAIN(ForgeConstants.ADV_BG_MOUNTAIN_FILE, false, false),
ADV_BG_ISLAND(ForgeConstants.ADV_BG_ISLAND_FILE, false, false),
ADV_BG_PLAINS(ForgeConstants.ADV_BG_PLAINS_FILE, false, false),
ADV_BG_WASTE(ForgeConstants.ADV_BG_WASTE_FILE, false, false),
ADV_BG_COMMON(ForgeConstants.ADV_BG_COMMON_FILE, false, false),
ADV_BG_CAVE(ForgeConstants.ADV_BG_CAVE_FILE, false, false),
ADV_BG_DUNGEON(ForgeConstants.ADV_BG_DUNGEON_FILE, false, false),
ADV_BG_CASTLE(ForgeConstants.ADV_BG_CASTLE_FILE, false, false),
//Planechase
Academy_at_Tolaria_West(ForgeConstants.BG_1, false, true),
Agyrem(ForgeConstants.BG_2, false, true),
Akoum(ForgeConstants.BG_3, false, true),
@@ -107,6 +119,8 @@ public enum FSkinTexture implements FImage {
private Texture texture;
private final boolean isPlane;
private static List<String> PlanesValue;
private boolean isloaded = false;
private boolean hasError = false;
FSkinTexture(String filename0, boolean repeat0, boolean isPlane0) {
filename = filename0;
@@ -129,6 +143,8 @@ public enum FSkinTexture implements FImage {
}
public void load() {
if (hasError)
return;
FileHandle preferredFile = isPlane ? FSkin.getCachePlanechaseFile(filename) : FSkin.getSkinFile(filename);
if (preferredFile.exists()) {
try {
@@ -139,10 +155,13 @@ public enum FSkinTexture implements FImage {
Forge.getAssets().manager().finishLoadingAsset(preferredFile.path());
texture = Forge.getAssets().manager().get(preferredFile.path(), Texture.class);
}
isloaded = true;
}
catch (final Exception e) {
System.err.println("Failed to load skin file: " + preferredFile);
e.printStackTrace();
isloaded = false;
hasError = true;
}
}
if (texture == null) {
@@ -163,15 +182,20 @@ public enum FSkinTexture implements FImage {
Forge.getAssets().manager().finishLoadingAsset(defaultFile.path());
texture = Forge.getAssets().manager().get(defaultFile.path(), Texture.class);
}
isloaded = true;
}
catch (final Exception e) {
System.err.println("Failed to load skin file: " + defaultFile);
e.printStackTrace();
isloaded = false;
hasError = true;
return;
}
}
else {
System.err.println("Failed to load skin file: " + defaultFile);
isloaded = false;
hasError = true;
return;
}
}
@@ -182,16 +206,28 @@ public enum FSkinTexture implements FImage {
@Override
public float getWidth() {
if (!isloaded)
load();
if (hasError)
return 0f;
return texture.getWidth();
}
@Override
public float getHeight() {
if (!isloaded)
load();
if (hasError)
return 0f;
return texture.getHeight();
}
@Override
public void draw(Graphics g, float x, float y, float w, float h) {
if (!isloaded)
load();
if (hasError)
return;
if (repeat) {
g.drawRepeatingImage(texture, x, y, w, h);
} else {
@@ -200,10 +236,18 @@ public enum FSkinTexture implements FImage {
}
public void drawRotated(Graphics g, float x, float y, float w, float h, float rotation) {
if (!isloaded)
load();
if (hasError)
return;
g.drawRotatedImage(texture, x, y, w, h, x + w / 2, y + h / 2, rotation);
}
public void drawFlipped(Graphics g, float x, float y, float w, float h) {
if (!isloaded)
load();
if (hasError)
return;
g.drawFlippedImage(texture, x, y, w, h);
}
}

View File

@@ -4,6 +4,7 @@ import java.util.*;
import java.util.Map.Entry;
import com.badlogic.gdx.math.Vector2;
import forge.adventure.scene.DuelScene;
import forge.animation.ForgeAnimation;
import forge.assets.FImage;
import forge.card.CardImageRenderer;
@@ -340,7 +341,7 @@ public class MatchScreen extends FScreen {
if (game == null) { return; }
if (gameMenu!=null) {
if (gameMenu.getChildCount()>2){
if (gameMenu.getChildCount()>1){
if (viewWinLose == null) {
gameMenu.getChildAt(0).setEnabled(!game.isMulligan());
gameMenu.getChildAt(1).setEnabled(!game.isMulligan());
@@ -801,7 +802,36 @@ public class MatchScreen extends FScreen {
}
}
private String daytime2 = null;
FSkinTexture currentBG = FSkinTexture.ADV_BG_MATCH;
private Float time = null;
FSkinTexture currentBG = getBG();
FSkinTexture getBG() {
if (Forge.isMobileAdventureMode) {
//System.out.println("Adventure Location: "+DuelScene.instance().getCurrentLocation());
switch(DuelScene.instance().getCurrentLocation()) {
case "green":
return FSkinTexture.ADV_BG_FOREST;
case "black":
return FSkinTexture.ADV_BG_SWAMP;
case "red":
return FSkinTexture.ADV_BG_MOUNTAIN;
case "blue":
return FSkinTexture.ADV_BG_ISLAND;
case "white":
return FSkinTexture.ADV_BG_PLAINS;
case "waste":
return FSkinTexture.ADV_BG_WASTE;
case "cave":
return FSkinTexture.ADV_BG_CAVE;
case "dungeon":
return FSkinTexture.ADV_BG_DUNGEON;
case "castle":
return FSkinTexture.ADV_BG_CASTLE;
default:
return FSkinTexture.ADV_BG_COMMON;
}
}
return FSkinTexture.BG_MATCH;
}
private class BGAnimation extends ForgeAnimation {
private static final float DURATION = 1.5f;
private float progress = 0;
@@ -816,27 +846,16 @@ public class MatchScreen extends FScreen {
percentage = 1;
}
if (Forge.isMobileAdventureMode) {
FSkinTexture bgDay = FSkinTexture.ADV_BG_MATCH_DAY;
FSkinTexture bgNight = FSkinTexture.ADV_BG_MATCH_NIGHT;
FSkinTexture bgNeither = FSkinTexture.ADV_BG_MATCH;
//back bg
FSkinTexture backBG = bgNeither;
//front bg
FSkinTexture frontBG = bgNeither;
if (MatchController.instance.getGameView().getGame().isDay())
backBG = bgDay;
if (MatchController.instance.getGameView().getGame().isNight())
backBG = bgNight;
if (MatchController.instance.getGameView().getGame().previousTimeIsDay())
frontBG = bgDay;
if (MatchController.instance.getGameView().getGame().previousTimeIsNight())
frontBG = bgNight;
//draw backBG
g.drawImage(backBG, x, y, w, h);
//draw frontBG with alpha difference
g.setAlphaComposite(1 - (percentage * 1));
g.drawImage(frontBG, x, y, w, h);
g.setAlphaComposite(oldAlpha);
g.drawNightDay(currentBG, x, y, w, h, time);
if (MatchController.instance.getGameView().getGame().isDay()) {
g.setAlphaComposite(percentage);
g.drawNightDay(currentBG, x, y, w, h, 100f);
g.setAlphaComposite(oldAlpha);
} else if (MatchController.instance.getGameView().getGame().isNight()) {
g.setAlphaComposite(percentage);
g.drawNightDay(currentBG, x, y, w, h, -100f);
g.setAlphaComposite(oldAlpha);
}
} else {
g.setAlphaComposite(percentage);
if (!daynightTransition)
@@ -857,11 +876,11 @@ public class MatchScreen extends FScreen {
protected void onEnd(boolean endingAll) {
finished = true;
if (Forge.isMobileAdventureMode) {
//set currentBG
//set time
if (MatchController.instance.getGameView().getGame().isDay())
currentBG = FSkinTexture.ADV_BG_MATCH_DAY;
time = 100f;
if (MatchController.instance.getGameView().getGame().isNight())
currentBG = FSkinTexture.ADV_BG_MATCH_NIGHT;
time = -100f;
daytime2 = MatchController.instance.getDayTime();
}
}
@@ -901,7 +920,7 @@ public class MatchScreen extends FScreen {
bgAnimation.drawBackground(g, currentBG, x + (w - bgFullWidth) / 2, y, bgFullWidth, bgHeight, false, true);
} else {
bgAnimation.progress = 0;
g.drawImage(currentBG, x + (w - bgFullWidth) / 2, y, bgFullWidth, bgHeight);
g.drawNightDay(currentBG, x + (w - bgFullWidth) / 2, y, bgFullWidth, bgHeight, time);
}
} else { //non adventure needs update to accomodate multiple BG Effect ie Planchase + Daytime effect...
if (MatchController.instance.getDayTime() != null) {

Binary file not shown.

After

Width:  |  Height:  |  Size: 169 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 137 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 174 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 194 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 245 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 303 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 159 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 262 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 201 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 154 KiB

View File

@@ -138,11 +138,23 @@ public final class ForgeConstants {
public static final String ADV_MATCH_BG_FILE = "adv_bg_match.jpg";
public static final String ADV_MATCH_BG_DAY_FILE = "adv_bg_match_day.jpg";
public static final String ADV_MATCH_BG_NIGHT_FILE= "adv_bg_match_nigh.jpg";
public static final String ADV_TEXTURE_BG_FILE = "adv_bg_texture.jpg";
public static final String ADV_TEXTURE_BG_FILE = "adv_bg_texture.jpg";
public static final String TEXTURE_BG_FILE = "bg_texture.jpg";
public static final String SPACE_BG_FILE = "bg_space.png";
public static final String CHAOS_WHEEL_IMG_FILE = "bg_chaos_wheel.png";
public static final String DRAFT_DECK_IMG_FILE = "bg_draft_deck.png";
//Adventure locations
public static final String ADV_BG_SWAMP_FILE = "adv_bg_swamp.jpg";
public static final String ADV_BG_FOREST_FILE = "adv_bg_forest.jpg";
public static final String ADV_BG_MOUNTAIN_FILE = "adv_bg_mountain.jpg";
public static final String ADV_BG_ISLAND_FILE = "adv_bg_island.jpg";
public static final String ADV_BG_PLAINS_FILE = "adv_bg_plains.jpg";
public static final String ADV_BG_WASTE_FILE = "adv_bg_waste.jpg";
public static final String ADV_BG_COMMON_FILE = "adv_bg_common.jpg";
public static final String ADV_BG_CAVE_FILE = "adv_bg_cave.jpg";
public static final String ADV_BG_DUNGEON_FILE = "adv_bg_dungeon.jpg";
public static final String ADV_BG_CASTLE_FILE = "adv_bg_castle.jpg";
//Planes addon
public static final String BG_1 = "Academy_at_Tolaria_West.jpg";
public static final String BG_2 = "Agyrem.jpg";