From bc3185a0ccd2ca53bda50d7f03e7dd6e39dc18d0 Mon Sep 17 00:00:00 2001 From: Anthony Calosa Date: Sat, 11 Mar 2023 11:39:55 +0800 Subject: [PATCH] update initial skin texture load - directly create texture if absolute path is not available - dispose overridden texture --- forge-gui-mobile/src/forge/Forge.java | 21 ++++++++---- forge-gui-mobile/src/forge/assets/Assets.java | 8 ++--- forge-gui-mobile/src/forge/assets/FSkin.java | 34 +++++++------------ 3 files changed, 32 insertions(+), 31 deletions(-) diff --git a/forge-gui-mobile/src/forge/Forge.java b/forge-gui-mobile/src/forge/Forge.java index 6e93c9a9c01..a11c8f5417b 100644 --- a/forge-gui-mobile/src/forge/Forge.java +++ b/forge-gui-mobile/src/forge/Forge.java @@ -350,12 +350,21 @@ public class Forge implements ApplicationListener { FileHandle transitionFile = Config.instance().getFile("ui/transition.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()) - getAssets().fallback_skins().put("vs", new Texture(vsIcon)); - if (transitionFile.exists()) - getAssets().fallback_skins().put("transition", new Texture(transitionFile)); - if (titleBGFile.exists()) - getAssets().fallback_skins().put("title", new Texture(titleBGFile)); + if (vsIcon.exists()) { + Texture old = getAssets().fallback_skins().put("vs", new Texture(vsIcon)); + if (old != null) + old.dispose(); + } + if (transitionFile.exists()) { + Texture old = getAssets().fallback_skins().put("transition", new Texture(transitionFile)); + if (old != null) + old.dispose(); + } + if (titleBGFile.exists()) { + Texture old = getAssets().fallback_skins().put("title", new Texture(titleBGFile)); + if (old != null) + old.dispose(); + } AdventureScreen.preload(); } catch (Exception e) { e.printStackTrace(); diff --git a/forge-gui-mobile/src/forge/assets/Assets.java b/forge-gui-mobile/src/forge/assets/Assets.java index 70727026140..8ff2c4298bc 100644 --- a/forge-gui-mobile/src/forge/assets/Assets.java +++ b/forge-gui-mobile/src/forge/assets/Assets.java @@ -1,5 +1,6 @@ package forge.assets; +import com.badlogic.gdx.Files.FileType; import com.badlogic.gdx.Gdx; import com.badlogic.gdx.assets.AssetLoaderParameters; import com.badlogic.gdx.assets.AssetManager; @@ -235,12 +236,11 @@ public class Assets implements Disposable { 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) { + if (!FileType.Absolute.equals(file.type()) || file.path().contains("fallback_skin")) { + if (!fallback_skins().containsKey(file.path())) { fallback_skins().put(file.path(), new Texture(file)); } - return f; + return fallback_skins().get(file.path()); } Texture t = manager.get(file.path(), Texture.class, false); if (t == null) { diff --git a/forge-gui-mobile/src/forge/assets/FSkin.java b/forge-gui-mobile/src/forge/assets/FSkin.java index f5231de5bf4..b1cc8341583 100644 --- a/forge-gui-mobile/src/forge/assets/FSkin.java +++ b/forge-gui-mobile/src/forge/assets/FSkin.java @@ -168,39 +168,31 @@ public class FSkin { } try { - int w, h; - if (f.path().contains("fallback_skin")) { - //the file is not accesible by the assetmanager using absolute fileresolver since it resides on internal path or classpath - Texture txSplash = new Texture(f); - w = txSplash.getWidth(); - h = txSplash.getHeight(); - splashScreen.setSplashTexture(new TextureRegion(txSplash, 0, 0, w, h - 100)); - } else { - manager.load(f.path(), Texture.class); - manager.finishLoadingAsset(f.path()); - w = manager.get(f.path(), Texture.class).getWidth(); - h = manager.get(f.path(), Texture.class).getHeight(); + int w=0, h=0; + Texture texF = Forge.getAssets().getTexture(f); + if (f2.exists()) { + Texture texF2 = Forge.getAssets().getTexture(f2); + w = texF2.getWidth(); + h = texF2.getHeight(); + splashScreen.setSplashTexture(new TextureRegion(texF2)); + } else if (texF != null) { + w = texF.getWidth(); + h = texF.getHeight(); + splashScreen.setSplashTexture(new TextureRegion(texF, 0, 0, w, h - 100)); - if (f2.exists()) { - manager.load(f2.path(), Texture.class, Forge.getAssets().getTextureFilter()); - manager.finishLoadingAsset(f2.path()); - splashScreen.setSplashTexture(new TextureRegion(manager.get(f2.path(), Texture.class))); - } else { - splashScreen.setSplashTexture(new TextureRegion(manager.get(f.path(), Texture.class), 0, 0, w, h - 100)); - } } Pixmap pxSplash = new Pixmap(f); //override splashscreen startup if (Forge.selector.equals("Adventure")) { if (f3.exists()) { - Texture advSplash = new Texture(f3); + Texture advSplash = Forge.getAssets().getTexture(f3); w = advSplash.getWidth(); h = advSplash.getHeight(); splashScreen.setSplashTexture(new TextureRegion(advSplash, 0, 0, w, h - 100)); pxSplash = new Pixmap(f3); } if (f4.exists()) { - Texture advBG = new Texture(f4); + Texture advBG = Forge.getAssets().getTexture(f4); advBG.setWrap(Texture.TextureWrap.Repeat, Texture.TextureWrap.Repeat); splashScreen.setSplashBGTexture(advBG); }