mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-19 12:18:00 +00:00
Merge pull request #1101 from kevlahnota/master
update ImageCache check
This commit is contained in:
@@ -786,10 +786,6 @@ public class Forge implements ApplicationListener {
|
|||||||
try {
|
try {
|
||||||
ImageCache.allowSingleLoad();
|
ImageCache.allowSingleLoad();
|
||||||
ForgeAnimation.advanceAll();
|
ForgeAnimation.advanceAll();
|
||||||
if (needsUpdate) {
|
|
||||||
if (getAssets().manager.update())
|
|
||||||
needsUpdate = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT); // Clear the screen.
|
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT); // Clear the screen.
|
||||||
|
|
||||||
@@ -880,6 +876,11 @@ public class Forge implements ApplicationListener {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
//update here
|
||||||
|
if (needsUpdate) {
|
||||||
|
if (getAssets().manager.update())
|
||||||
|
needsUpdate = false;
|
||||||
|
}
|
||||||
graphics.end();
|
graphics.end();
|
||||||
} catch (Exception ex) {
|
} catch (Exception ex) {
|
||||||
graphics.end();
|
graphics.end();
|
||||||
|
|||||||
@@ -23,7 +23,6 @@ import com.badlogic.gdx.scenes.scene2d.ui.Image;
|
|||||||
import com.badlogic.gdx.scenes.scene2d.ui.Label;
|
import com.badlogic.gdx.scenes.scene2d.ui.Label;
|
||||||
import com.badlogic.gdx.utils.Align;
|
import com.badlogic.gdx.utils.Align;
|
||||||
import com.badlogic.gdx.utils.Array;
|
import com.badlogic.gdx.utils.Array;
|
||||||
import com.badlogic.gdx.utils.ObjectMap;
|
|
||||||
import com.badlogic.gdx.utils.Scaling;
|
import com.badlogic.gdx.utils.Scaling;
|
||||||
import forge.Forge;
|
import forge.Forge;
|
||||||
import forge.adventure.character.*;
|
import forge.adventure.character.*;
|
||||||
@@ -43,6 +42,7 @@ import forge.sound.SoundEffectType;
|
|||||||
import forge.sound.SoundSystem;
|
import forge.sound.SoundSystem;
|
||||||
|
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import static forge.adventure.util.Paths.MANA_ATLAS;
|
import static forge.adventure.util.Paths.MANA_ATLAS;
|
||||||
@@ -69,7 +69,7 @@ public class MapStage extends GameStage {
|
|||||||
private final Vector2 oldPosition3 = new Vector2();
|
private final Vector2 oldPosition3 = new Vector2();
|
||||||
private final Vector2 oldPosition4 = new Vector2();
|
private final Vector2 oldPosition4 = new Vector2();
|
||||||
private boolean isLoadingMatch = false;
|
private boolean isLoadingMatch = false;
|
||||||
private ObjectMap<String, Byte> mapFlags = new ObjectMap<>(); //Stores local map flags. These aren't available outside this map.
|
private HashMap<String, Byte> mapFlags = new HashMap<>(); //Stores local map flags. These aren't available outside this map.
|
||||||
|
|
||||||
private Dialog dialog;
|
private Dialog dialog;
|
||||||
private Stage dialogStage;
|
private Stage dialogStage;
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ package forge.assets;
|
|||||||
import java.io.FileInputStream;
|
import java.io.FileInputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.nio.charset.StandardCharsets;
|
import java.nio.charset.StandardCharsets;
|
||||||
|
import java.util.HashMap;
|
||||||
|
|
||||||
import com.badlogic.gdx.Gdx;
|
import com.badlogic.gdx.Gdx;
|
||||||
import com.badlogic.gdx.files.FileHandle;
|
import com.badlogic.gdx.files.FileHandle;
|
||||||
@@ -21,7 +22,6 @@ import com.badlogic.gdx.graphics.glutils.PixmapTextureData;
|
|||||||
import com.badlogic.gdx.utils.Array;
|
import com.badlogic.gdx.utils.Array;
|
||||||
|
|
||||||
import com.badlogic.gdx.utils.IntSet;
|
import com.badlogic.gdx.utils.IntSet;
|
||||||
import com.badlogic.gdx.utils.ObjectMap;
|
|
||||||
import forge.Forge;
|
import forge.Forge;
|
||||||
import forge.gui.FThreads;
|
import forge.gui.FThreads;
|
||||||
import forge.localinstance.properties.ForgeConstants;
|
import forge.localinstance.properties.ForgeConstants;
|
||||||
@@ -38,11 +38,7 @@ public class FSkinFont {
|
|||||||
private static final int MAX_FONT_SIZE_MANY_GLYPHS = 36;
|
private static final int MAX_FONT_SIZE_MANY_GLYPHS = 36;
|
||||||
|
|
||||||
private static final String TTF_FILE = "font1.ttf";
|
private static final String TTF_FILE = "font1.ttf";
|
||||||
|
private static HashMap<String, String> langUniqueCharacterSet = new HashMap<>();
|
||||||
private static final String commonCharacterSet = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklm"
|
|
||||||
+ "nopqrstuvwxyz1234567890\"!?'.,;:()[]{}<>|/@\\^$-%+=#_&*\u2014"
|
|
||||||
+ "\u2022ÁÉÍÓÚáéíóúÀÈÌÒÙàèìòùÑñÄËÏÖÜäëïöüẞß¿¡";
|
|
||||||
private static ObjectMap<String, String> langUniqueCharacterSet = new ObjectMap<>();
|
|
||||||
|
|
||||||
static {
|
static {
|
||||||
FileUtil.ensureDirectoryExists(ForgeConstants.FONTS_DIR);
|
FileUtil.ensureDirectoryExists(ForgeConstants.FONTS_DIR);
|
||||||
@@ -62,7 +58,8 @@ public class FSkinFont {
|
|||||||
public static FSkinFont forHeight(final float height) {
|
public static FSkinFont forHeight(final float height) {
|
||||||
int size = MIN_FONT_SIZE + 1;
|
int size = MIN_FONT_SIZE + 1;
|
||||||
while (true) {
|
while (true) {
|
||||||
if (_get(size).getLineHeight() > height) {
|
FSkinFont f = _get(size);
|
||||||
|
if (f != null && f.getLineHeight() > height) {
|
||||||
return _get(size - 1);
|
return _get(size - 1);
|
||||||
}
|
}
|
||||||
size++;
|
size++;
|
||||||
@@ -120,6 +117,8 @@ public class FSkinFont {
|
|||||||
|
|
||||||
}
|
}
|
||||||
public int computeVisibleGlyphs (CharSequence str, int start, int end, float availableWidth) {
|
public int computeVisibleGlyphs (CharSequence str, int start, int end, float availableWidth) {
|
||||||
|
if (font == null)
|
||||||
|
return 0;
|
||||||
BitmapFontData data = font.getData();
|
BitmapFontData data = font.getData();
|
||||||
int index = start;
|
int index = start;
|
||||||
float width = 0;
|
float width = 0;
|
||||||
@@ -173,6 +172,9 @@ public class FSkinFont {
|
|||||||
return getBounds(str, 0, str.length());
|
return getBounds(str, 0, str.length());
|
||||||
}
|
}
|
||||||
public TextBounds getBounds(CharSequence str, int start, int end) {
|
public TextBounds getBounds(CharSequence str, int start, int end) {
|
||||||
|
if (font == null) {
|
||||||
|
return new TextBounds(0f, 0f);
|
||||||
|
}
|
||||||
BitmapFontData data = font.getData();
|
BitmapFontData data = font.getData();
|
||||||
//int start = 0;
|
//int start = 0;
|
||||||
//int end = str.length();
|
//int end = str.length();
|
||||||
@@ -221,6 +223,9 @@ public class FSkinFont {
|
|||||||
}
|
}
|
||||||
public TextBounds getMultiLineBounds(CharSequence str) {
|
public TextBounds getMultiLineBounds(CharSequence str) {
|
||||||
updateScale();
|
updateScale();
|
||||||
|
if (font == null) {
|
||||||
|
return new TextBounds(0f, 0f);
|
||||||
|
}
|
||||||
BitmapFontData data = font.getData();
|
BitmapFontData data = font.getData();
|
||||||
int start = 0;
|
int start = 0;
|
||||||
float maxWidth = 0;
|
float maxWidth = 0;
|
||||||
@@ -240,6 +245,9 @@ public class FSkinFont {
|
|||||||
}
|
}
|
||||||
public TextBounds getWrappedBounds(CharSequence str, float wrapWidth) {
|
public TextBounds getWrappedBounds(CharSequence str, float wrapWidth) {
|
||||||
updateScale();
|
updateScale();
|
||||||
|
if (font == null) {
|
||||||
|
return new TextBounds(0f, 0f);
|
||||||
|
}
|
||||||
BitmapFontData data = font.getData();
|
BitmapFontData data = font.getData();
|
||||||
if (wrapWidth <= 0) wrapWidth = Integer.MAX_VALUE;
|
if (wrapWidth <= 0) wrapWidth = Integer.MAX_VALUE;
|
||||||
int start = 0;
|
int start = 0;
|
||||||
@@ -296,14 +304,20 @@ public class FSkinFont {
|
|||||||
return new TextBounds(maxWidth, data.capHeight + (numLines - 1) * data.lineHeight);
|
return new TextBounds(maxWidth, data.capHeight + (numLines - 1) * data.lineHeight);
|
||||||
}
|
}
|
||||||
public float getAscent() {
|
public float getAscent() {
|
||||||
|
if (font == null)
|
||||||
|
return 0f;
|
||||||
updateScale();
|
updateScale();
|
||||||
return font.getAscent();
|
return font.getAscent();
|
||||||
}
|
}
|
||||||
public float getCapHeight() {
|
public float getCapHeight() {
|
||||||
|
if (font == null)
|
||||||
|
return 0f;
|
||||||
updateScale();
|
updateScale();
|
||||||
return font.getCapHeight();
|
return font.getCapHeight();
|
||||||
}
|
}
|
||||||
public float getLineHeight() {
|
public float getLineHeight() {
|
||||||
|
if (font == null)
|
||||||
|
return 0f;
|
||||||
updateScale();
|
updateScale();
|
||||||
return font.getLineHeight();
|
return font.getLineHeight();
|
||||||
}
|
}
|
||||||
@@ -316,9 +330,13 @@ public class FSkinFont {
|
|||||||
|
|
||||||
//update scale of font if needed
|
//update scale of font if needed
|
||||||
private void updateScale() {
|
private void updateScale() {
|
||||||
|
try {
|
||||||
if (font.getScaleX() != scale) {
|
if (font.getScaleX() != scale) {
|
||||||
font.getData().setScale(scale);
|
font.getData().setScale(scale);
|
||||||
}
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean canShrink() {
|
public boolean canShrink() {
|
||||||
@@ -341,10 +359,10 @@ public class FSkinFont {
|
|||||||
if (langUniqueCharacterSet.containsKey(langCode)) {
|
if (langUniqueCharacterSet.containsKey(langCode)) {
|
||||||
return langUniqueCharacterSet.get(langCode);
|
return langUniqueCharacterSet.get(langCode);
|
||||||
}
|
}
|
||||||
StringBuilder characters = new StringBuilder(commonCharacterSet);
|
StringBuilder characters = new StringBuilder(FreeTypeFontGenerator.DEFAULT_CHARS);
|
||||||
IntSet characterSet = new IntSet();
|
IntSet characterSet = new IntSet();
|
||||||
for (int offset = 0; offset < commonCharacterSet.length();) {
|
for (int offset = 0; offset < FreeTypeFontGenerator.DEFAULT_CHARS.length();) {
|
||||||
final int codePoint = commonCharacterSet.codePointAt(offset);
|
final int codePoint = FreeTypeFontGenerator.DEFAULT_CHARS.codePointAt(offset);
|
||||||
characterSet.add(codePoint);
|
characterSet.add(codePoint);
|
||||||
offset += Character.charCount(codePoint);
|
offset += Character.charCount(codePoint);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -18,6 +18,7 @@
|
|||||||
package forge.assets;
|
package forge.assets;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
import java.util.HashMap;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Queue;
|
import java.util.Queue;
|
||||||
@@ -29,8 +30,6 @@ import com.badlogic.gdx.files.FileHandle;
|
|||||||
import com.badlogic.gdx.graphics.Pixmap;
|
import com.badlogic.gdx.graphics.Pixmap;
|
||||||
import com.badlogic.gdx.graphics.TextureData;
|
import com.badlogic.gdx.graphics.TextureData;
|
||||||
import com.badlogic.gdx.graphics.glutils.PixmapTextureData;
|
import com.badlogic.gdx.graphics.glutils.PixmapTextureData;
|
||||||
import com.badlogic.gdx.utils.ObjectMap;
|
|
||||||
import com.badlogic.gdx.utils.ObjectSet;
|
|
||||||
import com.google.common.collect.EvictingQueue;
|
import com.google.common.collect.EvictingQueue;
|
||||||
import com.google.common.collect.Queues;
|
import com.google.common.collect.Queues;
|
||||||
import com.google.common.collect.Sets;
|
import com.google.common.collect.Sets;
|
||||||
@@ -75,7 +74,7 @@ import forge.util.ImageUtil;
|
|||||||
* @version $Id: ImageCache.java 24769 2014-02-09 13:56:04Z Hellfish $
|
* @version $Id: ImageCache.java 24769 2014-02-09 13:56:04Z Hellfish $
|
||||||
*/
|
*/
|
||||||
public class ImageCache {
|
public class ImageCache {
|
||||||
private static final ObjectSet<String> missingIconKeys = new ObjectSet<>();
|
private static final HashSet<String> missingIconKeys = new HashSet<>();
|
||||||
private static List<String> borderlessCardlistKey = FileUtil.readFile(ForgeConstants.BORDERLESS_CARD_LIST_FILE);
|
private static List<String> borderlessCardlistKey = FileUtil.readFile(ForgeConstants.BORDERLESS_CARD_LIST_FILE);
|
||||||
static int maxCardCapacity = 400; //default card capacity
|
static int maxCardCapacity = 400; //default card capacity
|
||||||
static EvictingQueue<String> q;
|
static EvictingQueue<String> q;
|
||||||
@@ -98,7 +97,7 @@ public class ImageCache {
|
|||||||
public static final Texture defaultImage;
|
public static final Texture defaultImage;
|
||||||
public static FImage BlackBorder = FSkinImage.IMG_BORDER_BLACK;
|
public static FImage BlackBorder = FSkinImage.IMG_BORDER_BLACK;
|
||||||
public static FImage WhiteBorder = FSkinImage.IMG_BORDER_WHITE;
|
public static FImage WhiteBorder = FSkinImage.IMG_BORDER_WHITE;
|
||||||
private static final ObjectMap<String, Pair<String, Boolean>> imageBorder = new ObjectMap<>(1024);
|
private static final HashMap<String, Pair<String, Boolean>> imageBorder = new HashMap<>(1024);
|
||||||
|
|
||||||
private static boolean imageLoaded, delayLoadRequested;
|
private static boolean imageLoaded, delayLoadRequested;
|
||||||
public static void allowSingleLoad() {
|
public static void allowSingleLoad() {
|
||||||
@@ -277,6 +276,9 @@ public class ImageCache {
|
|||||||
static Texture loadAsset(String imageKey, File file, boolean others) {
|
static Texture loadAsset(String imageKey, File file, boolean others) {
|
||||||
if (file == null)
|
if (file == null)
|
||||||
return null;
|
return null;
|
||||||
|
Texture check = getAsset(imageKey, file, others);
|
||||||
|
if (check != null)
|
||||||
|
return check;
|
||||||
if (!others) {
|
if (!others) {
|
||||||
syncQ.add(file.getPath());
|
syncQ.add(file.getPath());
|
||||||
cardsLoaded.add(file.getPath());
|
cardsLoaded.add(file.getPath());
|
||||||
@@ -294,17 +296,17 @@ public class ImageCache {
|
|||||||
if (others) {
|
if (others) {
|
||||||
return Forge.getAssets().manager.get(fileName, Texture.class, false);
|
return Forge.getAssets().manager.get(fileName, Texture.class, false);
|
||||||
} else {
|
} else {
|
||||||
Texture t = Forge.getAssets().manager.get(fileName, Texture.class, false);
|
Texture cardTexture = Forge.getAssets().manager.get(fileName, Texture.class, false);
|
||||||
//if full bordermasking is enabled, update the border color
|
//if full bordermasking is enabled, update the border color
|
||||||
if (Forge.enableUIMask.equals("Full")) {
|
if (Forge.enableUIMask.equals("Full")) {
|
||||||
boolean borderless = isBorderless(imageKey);
|
boolean borderless = isBorderless(imageKey);
|
||||||
updateBorders(t.toString(), borderless ? Pair.of(Color.valueOf("#171717").toString(), false): isCloserToWhite(getpixelColor(t)));
|
updateBorders(cardTexture.toString(), borderless ? Pair.of(Color.valueOf("#171717").toString(), false): isCloserToWhite(getpixelColor(cardTexture)));
|
||||||
//if borderless, generate new texture from the asset and store
|
//if borderless, generate new texture from the asset and store
|
||||||
if (borderless) {
|
if (borderless) {
|
||||||
Forge.getAssets().generatedCards.put(imageKey, generateTexture(new FileHandle(file), t, Forge.isTextureFilteringEnabled()));
|
Forge.getAssets().generatedCards.put(imageKey, generateTexture(new FileHandle(file), cardTexture, Forge.isTextureFilteringEnabled()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return t;
|
return cardTexture;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
static void unloadCardTextures(AssetManager manager) {
|
static void unloadCardTextures(AssetManager manager) {
|
||||||
@@ -421,10 +423,10 @@ public class ImageCache {
|
|||||||
|
|
||||||
return borderColor(t);
|
return borderColor(t);
|
||||||
}
|
}
|
||||||
public static Texture generateTexture(FileHandle fh, Texture t, boolean textureFilter) {
|
public static Texture generateTexture(FileHandle fh, Texture cardTexture, boolean textureFilter) {
|
||||||
if (t == null || fh == null)
|
if (cardTexture == null || fh == null)
|
||||||
return t;
|
return cardTexture;
|
||||||
final Texture[] n = new Texture[1];
|
final Texture[] placeholder = new Texture[1];
|
||||||
FThreads.invokeInEdtNowOrLater(() -> {
|
FThreads.invokeInEdtNowOrLater(() -> {
|
||||||
Pixmap pImage = new Pixmap(fh);
|
Pixmap pImage = new Pixmap(fh);
|
||||||
int w = pImage.getWidth();
|
int w = pImage.getWidth();
|
||||||
@@ -437,13 +439,13 @@ public class ImageCache {
|
|||||||
Format.RGBA8888,
|
Format.RGBA8888,
|
||||||
textureFilter, //use mipmaps
|
textureFilter, //use mipmaps
|
||||||
false, true);
|
false, true);
|
||||||
n[0] = new Texture(textureData);
|
placeholder[0] = new Texture(textureData);
|
||||||
if (textureFilter)
|
if (textureFilter)
|
||||||
n[0].setFilter(Texture.TextureFilter.MipMapLinearLinear, Texture.TextureFilter.Linear);
|
placeholder[0].setFilter(Texture.TextureFilter.MipMapLinearLinear, Texture.TextureFilter.Linear);
|
||||||
pImage.dispose();
|
pImage.dispose();
|
||||||
pMask.dispose();
|
pMask.dispose();
|
||||||
});
|
});
|
||||||
return n[0];
|
return placeholder[0];
|
||||||
}
|
}
|
||||||
public static Pixmap createRoundedRectangle(int width, int height, int cornerRadius, Color color) {
|
public static Pixmap createRoundedRectangle(int width, int height, int cornerRadius, Color color) {
|
||||||
Pixmap pixmap = new Pixmap(width, height, Pixmap.Format.RGBA8888);
|
Pixmap pixmap = new Pixmap(width, height, Pixmap.Format.RGBA8888);
|
||||||
|
|||||||
Reference in New Issue
Block a user