mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-15 02:08:00 +00:00
Make mobile counters scale with card size
This commit is contained in:
@@ -54,6 +54,9 @@ public class Main {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
screenWidth = 1900;
|
||||||
|
screenHeight = 1300;
|
||||||
|
|
||||||
LwjglApplicationConfiguration config = new LwjglApplicationConfiguration();
|
LwjglApplicationConfiguration config = new LwjglApplicationConfiguration();
|
||||||
config.resizable = false;
|
config.resizable = false;
|
||||||
config.width = desktopMode ? desktopScreenWidth : screenWidth;
|
config.width = desktopMode ? desktopScreenWidth : screenWidth;
|
||||||
|
|||||||
@@ -60,13 +60,15 @@ public class CardRenderer {
|
|||||||
private static final float BORDER_THICKNESS = Utils.scale(1);
|
private static final float BORDER_THICKNESS = Utils.scale(1);
|
||||||
public static final float PADDING_MULTIPLIER = 0.021f;
|
public static final float PADDING_MULTIPLIER = 0.021f;
|
||||||
|
|
||||||
private static BitmapFont counterFont;
|
private static Map<Integer, BitmapFont> counterFonts = new HashMap<>();
|
||||||
private static final Color counterBackgroundColor = new Color(0f, 0f, 0f, 0.9f);
|
private static final Color counterBackgroundColor = new Color(0f, 0f, 0f, 0.9f);
|
||||||
private static final Map<CounterType, Color> counterColorCache = new HashMap<>();
|
private static final Map<CounterType, Color> counterColorCache = new HashMap<>();
|
||||||
|
|
||||||
static {
|
static {
|
||||||
try {
|
try {
|
||||||
generateFontForCounters();
|
for (int fontSize = 11; fontSize <= 22; fontSize++) {
|
||||||
|
generateFontForCounters(fontSize);
|
||||||
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
@@ -482,11 +484,17 @@ public class CardRenderer {
|
|||||||
|
|
||||||
private static void drawCounterTabs(final CardView card, final Graphics g, final float x, final float y, final float w, final float h) {
|
private static void drawCounterTabs(final CardView card, final Graphics g, final float x, final float y, final float w, final float h) {
|
||||||
|
|
||||||
|
int fontSize = Math.max(11, Math.min(22, (int) (h * 0.08)));
|
||||||
|
BitmapFont font = counterFonts.get(fontSize);
|
||||||
|
|
||||||
|
final float additionalXOffset = 3f * ((fontSize - 11) / 11f);
|
||||||
|
final float variableWidth = ((fontSize - 11) / 11f) * 44f;
|
||||||
|
|
||||||
float otherSymbolsSize = w / 3.5f;
|
float otherSymbolsSize = w / 3.5f;
|
||||||
final float ySymbols = (h / 12) - otherSymbolsSize / 2;
|
final float ySymbols = (h / 12) - otherSymbolsSize / 2;
|
||||||
|
|
||||||
final float counterBoxHeight = 20;
|
final float counterBoxHeight = 9 + fontSize;
|
||||||
final float counterBoxBaseWidth = 50;
|
final float counterBoxBaseWidth = 50 + variableWidth + additionalXOffset * 2;
|
||||||
final float counterBoxSpacing = -4;
|
final float counterBoxSpacing = -4;
|
||||||
|
|
||||||
final float spaceFromTopOfCard = y + h - counterBoxHeight - counterBoxSpacing - otherSymbolsSize + ySymbols;
|
final float spaceFromTopOfCard = y + h - counterBoxHeight - counterBoxSpacing - otherSymbolsSize + ySymbols;
|
||||||
@@ -500,7 +508,7 @@ public class CardRenderer {
|
|||||||
maxCounters = Math.max(maxCounters, numberOfCounters);
|
maxCounters = Math.max(maxCounters, numberOfCounters);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (counterBoxBaseWidth + counterFont.getBounds(String.valueOf(maxCounters)).width > w) {
|
if (counterBoxBaseWidth + font.getBounds(String.valueOf(maxCounters)).width > w) {
|
||||||
drawCounterImage(card, g, x, y, w, h);
|
drawCounterImage(card, g, x, y, w, h);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -511,11 +519,11 @@ public class CardRenderer {
|
|||||||
|
|
||||||
final CounterType counter = counterEntry.getKey();
|
final CounterType counter = counterEntry.getKey();
|
||||||
final int numberOfCounters = counterEntry.getValue();
|
final int numberOfCounters = counterEntry.getValue();
|
||||||
final float counterBoxRealWidth = counterBoxBaseWidth + counterFont.getBounds(String.valueOf(numberOfCounters)).width + 4;
|
final float counterBoxRealWidth = counterBoxBaseWidth + font.getBounds(String.valueOf(numberOfCounters)).width + 4;
|
||||||
|
|
||||||
final float counterYOffset = spaceFromTopOfCard - (currentCounter++ * (counterBoxHeight + counterBoxSpacing));
|
final float counterYOffset = spaceFromTopOfCard - (currentCounter++ * (counterBoxHeight + counterBoxSpacing));
|
||||||
|
|
||||||
g.fillRect(counterBackgroundColor, x - 2, counterYOffset, counterBoxRealWidth, counterBoxHeight);
|
g.fillRect(counterBackgroundColor, x - 3, counterYOffset, counterBoxRealWidth, counterBoxHeight);
|
||||||
|
|
||||||
if (!counterColorCache.containsKey(counter)) {
|
if (!counterColorCache.containsKey(counter)) {
|
||||||
counterColorCache.put(counter, new Color(counter.getRed() / 255.0f, counter.getGreen() / 255.0f, counter.getBlue() / 255.0f, 1.0f));
|
counterColorCache.put(counter, new Color(counter.getRed() / 255.0f, counter.getGreen() / 255.0f, counter.getBlue() / 255.0f, 1.0f));
|
||||||
@@ -523,8 +531,8 @@ public class CardRenderer {
|
|||||||
|
|
||||||
Color counterColor = counterColorCache.get(counter);
|
Color counterColor = counterColorCache.get(counter);
|
||||||
|
|
||||||
drawText(g, counter.getCounterOnCardDisplayName(), counterFont, counterColor, x + 2, counterYOffset, counterBoxRealWidth, counterBoxHeight, HAlignment.LEFT);
|
drawText(g, counter.getCounterOnCardDisplayName(), font, counterColor, x + 2 + additionalXOffset, counterYOffset, counterBoxRealWidth, counterBoxHeight, HAlignment.LEFT);
|
||||||
drawText(g, String.valueOf(numberOfCounters), counterFont, counterColor, x + counterBoxBaseWidth - 3f, counterYOffset, counterBoxRealWidth, counterBoxHeight, HAlignment.LEFT);
|
drawText(g, String.valueOf(numberOfCounters), font, counterColor, x + counterBoxBaseWidth - 4f - additionalXOffset, counterYOffset, counterBoxRealWidth, counterBoxHeight, HAlignment.LEFT);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -686,10 +694,9 @@ public class CardRenderer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
//TODO Make FSkinFont accept more than one kind of font and merge this with it
|
//TODO Make FSkinFont accept more than one kind of font and merge this with it
|
||||||
private static void generateFontForCounters() {
|
private static void generateFontForCounters(final int fontSize) {
|
||||||
|
|
||||||
FileHandle ttfFile = Gdx.files.absolute(ForgeConstants.COMMON_FONTS_DIR).child("Roboto-Bold.ttf");
|
FileHandle ttfFile = Gdx.files.absolute(ForgeConstants.COMMON_FONTS_DIR).child("Roboto-Bold.ttf");
|
||||||
final int fontSize = 11;
|
|
||||||
|
|
||||||
if (!ttfFile.exists()) { return; }
|
if (!ttfFile.exists()) { return; }
|
||||||
|
|
||||||
@@ -729,7 +736,7 @@ public class CardRenderer {
|
|||||||
textureRegions[i] = new TextureRegion(texture);
|
textureRegions[i] = new TextureRegion(texture);
|
||||||
}
|
}
|
||||||
|
|
||||||
counterFont = new BitmapFont(fontData, textureRegions, true);
|
counterFonts.put(fontSize, new BitmapFont(fontData, textureRegions, true));
|
||||||
|
|
||||||
generator.dispose();
|
generator.dispose();
|
||||||
packer.dispose();
|
packer.dispose();
|
||||||
|
|||||||
Reference in New Issue
Block a user