mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-12 16:58:57 +00:00
Merge pull request #2654 from Card-Forge/refactorTexture
refactor texture loading
This commit is contained in:
@@ -28,6 +28,10 @@
|
||||
<id>gdx-nightlies</id>
|
||||
<url>https://oss.sonatype.org/content/repositories/snapshots/</url>
|
||||
</repository>
|
||||
<repository>
|
||||
<id>jitpack.io</id>
|
||||
<url>https://jitpack.io</url>
|
||||
</repository>
|
||||
</repositories>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
@@ -50,6 +54,11 @@
|
||||
<artifactId>forge-gui</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.github.tommyettinger</groupId>
|
||||
<artifactId>textratypist</artifactId>
|
||||
<version>0.7.9</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.badlogicgames.gdx-controllers</groupId>
|
||||
<artifactId>gdx-controllers-core</artifactId>
|
||||
|
||||
@@ -253,7 +253,7 @@ public class Forge implements ApplicationListener {
|
||||
public static boolean hasGamepad() {
|
||||
//Classic Mode Various Screen GUI are not yet supported, needs control mapping for each screens
|
||||
if (isMobileAdventureMode) {
|
||||
return hasGamepad && Forge.isLandscapeMode(); //portrait is not supported for Gamepad
|
||||
return hasGamepad && isLandscapeMode(); //portrait is not supported for Gamepad
|
||||
}
|
||||
return false;
|
||||
}
|
||||
@@ -348,14 +348,14 @@ public class Forge implements ApplicationListener {
|
||||
//override transition & title bg
|
||||
try {
|
||||
FileHandle transitionFile = Config.instance().getFile("ui/transition.png");
|
||||
FileHandle titleBGFile = Forge.isLandscapeMode() ? Config.instance().getFile("ui/title_bg.png") : Config.instance().getFile("ui/title_bg_portrait.png");
|
||||
FileHandle titleBGFile = isLandscapeMode() ? Config.instance().getFile("ui/title_bg.png") : Config.instance().getFile("ui/title_bg_portrait.png");
|
||||
FileHandle vsIcon = Config.instance().getFile("ui/vs.png");
|
||||
if (vsIcon.exists())
|
||||
Forge.getAssets().fallback_skins().put(2, new Texture(vsIcon));
|
||||
getAssets().fallback_skins().put("vs", new Texture(vsIcon));
|
||||
if (transitionFile.exists())
|
||||
Forge.getAssets().fallback_skins().put(1, new Texture(transitionFile));
|
||||
getAssets().fallback_skins().put("transition", new Texture(transitionFile));
|
||||
if (titleBGFile.exists())
|
||||
Forge.getAssets().fallback_skins().put(0, new Texture(titleBGFile));
|
||||
getAssets().fallback_skins().put("title", new Texture(titleBGFile));
|
||||
AdventureScreen.preload();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
@@ -383,7 +383,7 @@ public class Forge implements ApplicationListener {
|
||||
if (selector.equals("Adventure")) {
|
||||
//preload adventure resources to speedup startup if selector is adventure. Needs in edt when setting up worldstage
|
||||
loadAdventureResources(false);
|
||||
Forge.isMobileAdventureMode = true;
|
||||
isMobileAdventureMode = true;
|
||||
}
|
||||
//selection transition
|
||||
setTransitionScreen(new TransitionScreen(() -> {
|
||||
@@ -408,7 +408,7 @@ public class Forge implements ApplicationListener {
|
||||
SoundSystem.instance.setBackgroundMusic(MusicPlaylist.MENUS);
|
||||
safeToClose = true;
|
||||
clearTransitionScreen();
|
||||
}, Forge.takeScreenshot(), false, false, true, false));
|
||||
}, takeScreenshot(), false, false, true, false));
|
||||
});
|
||||
});
|
||||
}));
|
||||
@@ -829,7 +829,7 @@ public class Forge implements ApplicationListener {
|
||||
@Override
|
||||
public void render() {
|
||||
if (showFPS)
|
||||
frameRate.update(ImageCache.counter, Forge.getAssets().manager().getMemoryInMegabytes());
|
||||
frameRate.update(ImageCache.counter, getAssets().manager().getMemoryInMegabytes());
|
||||
|
||||
try {
|
||||
ImageCache.allowSingleLoad();
|
||||
@@ -865,8 +865,8 @@ public class Forge implements ApplicationListener {
|
||||
animationBatch.setColor(1, 1, 1, 1);
|
||||
animationBatch.draw(lastScreenTexture, 0, 0, Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
|
||||
animationBatch.setColor(1, 1, 1, 1 - (1 / transitionTime) * animationTimeout);
|
||||
animationBatch.draw(getAssets().fallback_skins().get(1), 0, 0, Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
|
||||
animationBatch.draw(getAssets().fallback_skins().get(1), 0, 0, Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
|
||||
animationBatch.draw(getAssets().fallback_skins().get("transition"), 0, 0, Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
|
||||
animationBatch.draw(getAssets().fallback_skins().get("transition"), 0, 0, Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
|
||||
animationBatch.end();
|
||||
if (animationTimeout < 0) {
|
||||
currentScene.render();
|
||||
@@ -885,8 +885,8 @@ public class Forge implements ApplicationListener {
|
||||
animationBatch.setColor(1, 1, 1, 1);
|
||||
animationBatch.draw(lastScreenTexture, 0, 0, Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
|
||||
animationBatch.setColor(1, 1, 1, (1 / transitionTime) * (animationTimeout + transitionTime));
|
||||
animationBatch.draw(getAssets().fallback_skins().get(1), 0, 0, Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
|
||||
animationBatch.draw(getAssets().fallback_skins().get(1), 0, 0, Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
|
||||
animationBatch.draw(getAssets().fallback_skins().get("transition"), 0, 0, Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
|
||||
animationBatch.draw(getAssets().fallback_skins().get("transition"), 0, 0, Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
|
||||
animationBatch.end();
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -105,7 +105,7 @@ public class GuiMobile implements IGuiBase {
|
||||
@Override
|
||||
public ISkinImage getUnskinnedIcon(final String path) {
|
||||
if (isGuiThread()) {
|
||||
return new FTextureImage(new Texture(Gdx.files.absolute(path)));
|
||||
return new FTextureImage(Forge.getAssets().getTexture(Gdx.files.absolute(path)));
|
||||
}
|
||||
|
||||
//use a delay load image to avoid an error if called from background thread
|
||||
@@ -131,7 +131,7 @@ public class GuiMobile implements IGuiBase {
|
||||
|
||||
if (FileUtil.doesFileExist(overlayFilename)) {
|
||||
try {
|
||||
final Texture overlay = new Texture(Gdx.files.absolute(overlayFilename));
|
||||
final Texture overlay = Forge.getAssets().getTexture(Gdx.files.absolute(overlayFilename));
|
||||
g.drawImage(overlay, (background.getWidth() - overlay.getWidth()) / 2, (background.getHeight() - overlay.getHeight()) / 2, overlay.getWidth(), overlay.getHeight());
|
||||
} catch (final Exception e) {
|
||||
}
|
||||
|
||||
@@ -37,7 +37,7 @@ public class InventoryScene extends UIScene {
|
||||
|
||||
public InventoryScene() {
|
||||
super(Forge.isLandscapeMode() ? "ui/inventory.json" : "ui/inventory_portrait.json");
|
||||
equipOverlay = new Texture(Config.instance().getFile(Paths.ITEMS_EQUIP));
|
||||
equipOverlay = Forge.getAssets().getTexture(Config.instance().getFile(Paths.ITEMS_EQUIP));
|
||||
ui.onButtonPress("return", () -> done());
|
||||
leave = ui.findActor("return");
|
||||
ui.onButtonPress("delete", () -> showConfirm());
|
||||
|
||||
@@ -305,7 +305,6 @@ public class RewardScene extends UIScene {
|
||||
if(background!=null)
|
||||
background.setVisible(false);
|
||||
}
|
||||
// card.setDrawable(new TextureRegionDrawable(new Texture(Res.CurrentRes.GetFile("ui/transition.png"))));
|
||||
|
||||
float targetWidth = card.getWidth();
|
||||
float targetHeight = card.getHeight();
|
||||
|
||||
@@ -95,7 +95,7 @@ public class GameHUD extends Stage {
|
||||
exitToWorldMapActor = ui.findActor("exittoworldmap");
|
||||
dialog = Controls.newDialog("");
|
||||
|
||||
miniMapPlayer = new Image(new Texture(Config.instance().getFile("ui/minimap_player.png")));
|
||||
miniMapPlayer = new Image(Forge.getAssets().getTexture(Config.instance().getFile("ui/minimap_player.png")));
|
||||
//create touchpad
|
||||
touchpad = new Touchpad(10, Controls.getSkin());
|
||||
touchpad.setBounds(15, 15, TOUCHPAD_SCALE, TOUCHPAD_SCALE);
|
||||
|
||||
@@ -287,7 +287,7 @@ public class UIActor extends Group {
|
||||
for (ObjectMap.Entry property : entries) {
|
||||
switch (property.key.toString()) {
|
||||
case "image":
|
||||
Texture t = new Texture(Config.instance().getFile(property.value.toString()));
|
||||
Texture t = Forge.getAssets().getTexture(Config.instance().getFile(property.value.toString()));
|
||||
TextureRegion tr = new TextureRegion(t);
|
||||
newActor.setDrawable(new TextureRegionDrawable(tr));
|
||||
break;
|
||||
|
||||
@@ -12,6 +12,7 @@ import com.badlogic.gdx.scenes.scene2d.Actor;
|
||||
import com.badlogic.gdx.utils.Array;
|
||||
import com.badlogic.gdx.utils.Disposable;
|
||||
import com.badlogic.gdx.utils.Json;
|
||||
import forge.Forge;
|
||||
import forge.adventure.data.*;
|
||||
import forge.adventure.pointofintrest.PointOfInterest;
|
||||
import forge.adventure.pointofintrest.PointOfInterestMap;
|
||||
@@ -912,7 +913,7 @@ public class World implements Disposable, SaveFileContent {
|
||||
|
||||
public Texture getGlobalTexture() {
|
||||
if (globalTexture == null) {
|
||||
globalTexture = new Texture(Config.instance().getFile("ui/sprite_markers.png"));
|
||||
globalTexture = Forge.getAssets().getTexture(Config.instance().getFile("ui/sprite_markers.png"));
|
||||
System.out.print("Loading auxiliary sprites.\n");
|
||||
}
|
||||
return globalTexture;
|
||||
|
||||
@@ -40,7 +40,7 @@ public class Assets implements Disposable {
|
||||
private HashMap<Integer, TextureRegion> cursor;
|
||||
private ObjectMap<Integer, BitmapFont> counterFonts;
|
||||
private ObjectMap<String, Texture> generatedCards;
|
||||
private ObjectMap<Integer, Texture> fallback_skins;
|
||||
private ObjectMap<String, Texture> fallback_skins;
|
||||
private ObjectMap<String, Texture> tmxMap;
|
||||
private Texture defaultImage, dummy;
|
||||
private TextureParameter textureParameter;
|
||||
@@ -54,16 +54,16 @@ public class Assets implements Disposable {
|
||||
Texture titleBG_LQ = GuiBase.isAndroid() ?
|
||||
new Texture(Gdx.files.internal("fallback_skin").child(titleFilename)) :
|
||||
new Texture(Gdx.files.classpath("fallback_skin").child(titleFilename));
|
||||
fallback_skins().put(0, titleBG_LQ == null ? getDummy() : titleBG_LQ);
|
||||
fallback_skins().put("title", titleBG_LQ == null ? getDummy() : titleBG_LQ);
|
||||
//init transition
|
||||
Texture transitionLQ = GuiBase.isAndroid() ?
|
||||
new Texture(Gdx.files.internal("fallback_skin").child("transition.png")) :
|
||||
new Texture(Gdx.files.classpath("fallback_skin").child("transition.png"));
|
||||
fallback_skins().put(1, transitionLQ == null ? getDummy() : transitionLQ);
|
||||
fallback_skins().put("transition", transitionLQ == null ? getDummy() : transitionLQ);
|
||||
} catch (Exception e) {
|
||||
fallback_skins().clear();
|
||||
fallback_skins().put(0, getDummy());
|
||||
fallback_skins().put(1, getDummy());
|
||||
fallback_skins().put("title", getDummy());
|
||||
fallback_skins().put("transition", getDummy());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -202,7 +202,7 @@ public class Assets implements Disposable {
|
||||
return generatedCards;
|
||||
}
|
||||
|
||||
public ObjectMap<Integer, Texture> fallback_skins() {
|
||||
public ObjectMap<String, Texture> fallback_skins() {
|
||||
if (fallback_skins == null)
|
||||
fallback_skins = new ObjectMap<>();
|
||||
return fallback_skins;
|
||||
@@ -229,6 +229,28 @@ public class Assets implements Disposable {
|
||||
return textureParameter;
|
||||
}
|
||||
|
||||
public Texture getTexture(FileHandle file) {
|
||||
if (file == null || !file.exists()) {
|
||||
System.err.println("Failed to load: " + file +"!. Creating dummy texture.");
|
||||
return getDummy();
|
||||
}
|
||||
//internal path can be inside apk or jar..
|
||||
if (file.path().contains("fallback_skin")) {
|
||||
Texture f = fallback_skins().get(file.path());
|
||||
if (f == null) {
|
||||
fallback_skins().put(file.path(), new Texture(file));
|
||||
}
|
||||
return f;
|
||||
}
|
||||
Texture t = manager.get(file.path(), Texture.class, false);
|
||||
if (t == null) {
|
||||
manager.load(file.path(), Texture.class, getTextureFilter());
|
||||
manager.finishLoadingAsset(file.path());
|
||||
t = manager.get(file.path(), Texture.class);
|
||||
}
|
||||
return t;
|
||||
}
|
||||
|
||||
public Texture getDefaultImage() {
|
||||
if (defaultImage == null) {
|
||||
FileHandle blankImage = Gdx.files.absolute(ForgeConstants.NO_CARD_FILE);
|
||||
|
||||
@@ -4,6 +4,7 @@ import com.badlogic.gdx.Gdx;
|
||||
import com.badlogic.gdx.graphics.Texture;
|
||||
|
||||
import com.badlogic.gdx.graphics.g2d.TextureRegion;
|
||||
import forge.Forge;
|
||||
import forge.Graphics;
|
||||
|
||||
//Special wrapper for a texture to be loaded later when it's needed
|
||||
@@ -28,7 +29,7 @@ public class FDelayLoadImage extends FImageComplex {
|
||||
@Override
|
||||
public Texture getTexture() {
|
||||
if (texture == null) {
|
||||
texture = new Texture(Gdx.files.absolute(filename));
|
||||
texture = Forge.getAssets().getTexture(Gdx.files.absolute(filename));
|
||||
}
|
||||
return texture;
|
||||
}
|
||||
@@ -36,7 +37,7 @@ public class FDelayLoadImage extends FImageComplex {
|
||||
@Override
|
||||
public TextureRegion getTextureRegion() {
|
||||
if (texture == null) {
|
||||
texture = new Texture(Gdx.files.absolute(filename));
|
||||
texture = Forge.getAssets().getTexture(Gdx.files.absolute(filename));
|
||||
}
|
||||
return new TextureRegion(texture);
|
||||
}
|
||||
|
||||
@@ -202,13 +202,7 @@ public enum FSkinTexture implements FImage {
|
||||
FileHandle preferredFile = isPlanechaseBG ? FSkin.getCachePlanechaseFile(filename) : FSkin.getSkinFile(filename);
|
||||
if (preferredFile.exists()) {
|
||||
try {
|
||||
if (preferredFile.path().contains("fallback_skin")) {
|
||||
texture = new Texture(preferredFile);
|
||||
} else {
|
||||
Forge.getAssets().manager().load(preferredFile.path(), Texture.class);
|
||||
Forge.getAssets().manager().finishLoadingAsset(preferredFile.path());
|
||||
texture = Forge.getAssets().manager().get(preferredFile.path(), Texture.class);
|
||||
}
|
||||
texture = Forge.getAssets().getTexture(preferredFile);
|
||||
isloaded = true;
|
||||
}
|
||||
catch (final Exception e) {
|
||||
@@ -229,13 +223,7 @@ public enum FSkinTexture implements FImage {
|
||||
|
||||
if (defaultFile.exists()) {
|
||||
try {
|
||||
if (defaultFile.path().contains("fallback_skin")) {
|
||||
texture = new Texture(defaultFile);
|
||||
} else {
|
||||
Forge.getAssets().manager().load(defaultFile.path(), Texture.class);
|
||||
Forge.getAssets().manager().finishLoadingAsset(defaultFile.path());
|
||||
texture = Forge.getAssets().manager().get(defaultFile.path(), Texture.class);
|
||||
}
|
||||
texture = Forge.getAssets().getTexture(defaultFile);
|
||||
isloaded = true;
|
||||
}
|
||||
catch (final Exception e) {
|
||||
|
||||
@@ -21,7 +21,7 @@ public class ClosingScreen extends FContainer {
|
||||
private boolean drawStatic = false;
|
||||
private FileHandle adv_logo = getSkinFile("adv_logo.png");
|
||||
private FileHandle existingLogo = adv_logo.exists() ? adv_logo : getDefaultSkinFile("adv_logo.png");
|
||||
private Texture logo = existingLogo.exists() && Forge.advStartup ? new Texture(existingLogo) : FSkin.getLogo();
|
||||
private Texture logo = existingLogo.exists() && Forge.advStartup ? Forge.getAssets().getTexture(existingLogo) : FSkin.getLogo();
|
||||
|
||||
public ClosingScreen(boolean restart0) {
|
||||
bgAnimation = new BGAnimation();
|
||||
|
||||
@@ -239,7 +239,7 @@ public class SplashScreen extends FContainer {
|
||||
}
|
||||
|
||||
void drawTransition(Graphics g, boolean openAdventure, float percentage) {
|
||||
TextureRegion tr = new TextureRegion(Forge.getAssets().fallback_skins().get(0));
|
||||
TextureRegion tr = new TextureRegion(Forge.getAssets().fallback_skins().get("title"));
|
||||
float oldAlpha = g.getfloatAlphaComposite();
|
||||
g.setAlphaComposite(percentage);
|
||||
if (openAdventure) {
|
||||
|
||||
@@ -67,7 +67,7 @@ public class TransitionScreen extends FContainer {
|
||||
playerAvatarName = playerName;
|
||||
enemyAvatarName = enemyName;
|
||||
enemyAtlasPath = enemyAtlas;
|
||||
vsTexture = Forge.getAssets().fallback_skins().get(2);
|
||||
vsTexture = Forge.getAssets().fallback_skins().get("vs");
|
||||
layout = new GlyphLayout();
|
||||
}
|
||||
|
||||
@@ -207,7 +207,7 @@ public class TransitionScreen extends FContainer {
|
||||
} else if (isIntro) {
|
||||
if (textureRegion != null) {
|
||||
if (Forge.advStartup) {
|
||||
g.drawGrayTransitionImage(Forge.getAssets().fallback_skins().get(0), 0, 0, Forge.getScreenWidth(), Forge.getScreenHeight(), false, percentage);
|
||||
g.drawGrayTransitionImage(Forge.getAssets().fallback_skins().get("title"), 0, 0, Forge.getScreenWidth(), Forge.getScreenHeight(), false, percentage);
|
||||
g.setAlphaComposite(1-percentage);
|
||||
g.drawImage(textureRegion, 0, 0, Forge.getScreenWidth(), Forge.getScreenHeight());
|
||||
g.setAlphaComposite(oldAlpha);
|
||||
|
||||
@@ -40,11 +40,6 @@
|
||||
<artifactId>forge-ai</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.github.tommyettinger</groupId>
|
||||
<artifactId>textratypist</artifactId>
|
||||
<version>0.7.9</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.thoughtworks.xstream</groupId>
|
||||
<artifactId>xstream</artifactId>
|
||||
|
||||
Reference in New Issue
Block a user