From 7da1b336813a1c168ee7d53d761f43eec64d3780 Mon Sep 17 00:00:00 2001 From: Anthony Calosa Date: Fri, 24 Mar 2023 00:05:18 +0800 Subject: [PATCH] labels --- .../forge/adventure/util/DrawOnPixmap.java | 35 ++++++++++++++++++- .../src/forge/adventure/util/KeyBinding.java | 4 +-- forge-gui-mobile/src/forge/assets/Assets.java | 8 ++--- 3 files changed, 40 insertions(+), 7 deletions(-) diff --git a/forge-gui-mobile/src/forge/adventure/util/DrawOnPixmap.java b/forge-gui-mobile/src/forge/adventure/util/DrawOnPixmap.java index 481a400f71e..2d7918e8a8d 100644 --- a/forge-gui-mobile/src/forge/adventure/util/DrawOnPixmap.java +++ b/forge-gui-mobile/src/forge/adventure/util/DrawOnPixmap.java @@ -8,6 +8,7 @@ import com.badlogic.gdx.graphics.g2d.TextureRegion; import com.badlogic.gdx.graphics.glutils.FrameBuffer; import com.badlogic.gdx.math.Matrix4; import com.badlogic.gdx.utils.Align; +import com.github.tommyettinger.textra.TextraLabel; /* Class to draw directly on a pixmap @@ -26,7 +27,6 @@ public abstract class DrawOnPixmap { on.drawPixmap(textureData.consumePixmap(), x, y, from.getRegionX(), from.getRegionY(), from.getRegionWidth(), from.getRegionHeight()); } - public static void drawText(Pixmap drawingMap, String itemText, int x, int y, float width, boolean bigText, Color color) { //used for big numbers on Gold/Life for reward... BitmapFont font = bigText ? Controls.getBitmapFont("big") : Controls.getBitmapFont("default"); @@ -59,4 +59,37 @@ public abstract class DrawOnPixmap { if (bigText) //don't know why this is needed to circumvent bug getting default size for the same pixelfont Controls.getBitmapFont("default"); } + + public static void drawText(Pixmap drawingMap, TextraLabel itemText, int modX, int modY) { + FrameBuffer frameBuffer = new FrameBuffer(Pixmap.Format.RGB888, drawingMap.getWidth(), drawingMap.getHeight(), false); + SpriteBatch batch = new SpriteBatch(); + + frameBuffer.begin(); + + Gdx.gl.glClearColor(0, 0, 0, 0); + Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT); + + Matrix4 matrix = new Matrix4(); + matrix.setToOrtho2D(0, drawingMap.getHeight(), drawingMap.getWidth(), -drawingMap.getHeight()); + batch.setProjectionMatrix(matrix); + + batch.begin(); + //Rendering ends here. Create a new Pixmap to Texture with mipmaps, otherwise will render as full black. + Texture texture = new Texture(drawingMap); + batch.draw(texture, 0, 0); + itemText.setWrap(true); + itemText.setAlignment(1); + itemText.setWidth(texture.getWidth()); + itemText.setHeight(texture.getHeight()); + itemText.setX(itemText.getX()+modX); + itemText.setY(itemText.getY()+modY); + itemText.draw(batch, 1); + batch.end(); + Pixmap pixmap = Pixmap.createFromFrameBuffer(0, 0, drawingMap.getWidth(), drawingMap.getHeight()); + drawingMap.drawPixmap(pixmap, 0, 0); + frameBuffer.end(); + texture.dispose(); + batch.dispose(); + pixmap.dispose(); + } } diff --git a/forge-gui-mobile/src/forge/adventure/util/KeyBinding.java b/forge-gui-mobile/src/forge/adventure/util/KeyBinding.java index 14fd8c908f3..55a267ceacd 100644 --- a/forge-gui-mobile/src/forge/adventure/util/KeyBinding.java +++ b/forge-gui-mobile/src/forge/adventure/util/KeyBinding.java @@ -44,13 +44,13 @@ public enum KeyBinding { public String getLabelText(boolean pressed) { if(Controllers.getCurrent()!=null) { - return "[%125][+"+controllerPrefix+Input.Keys.toString(bindingController).replace(" Button","")+(pressed?"_pressed]":"]"); + return "[%120][+"+controllerPrefix+Input.Keys.toString(bindingController).replace(" Button","")+(pressed?"_pressed]":"]"); } else { if(GuiBase.isAndroid()) return ""; - return "[%125][+"+Input.Keys.toString(binding)+(pressed?"_pressed]":"]"); + return "[%120][+"+Input.Keys.toString(binding)+(pressed?"_pressed]":"]"); } } diff --git a/forge-gui-mobile/src/forge/assets/Assets.java b/forge-gui-mobile/src/forge/assets/Assets.java index 394e517e81f..a596ada31c5 100644 --- a/forge-gui-mobile/src/forge/assets/Assets.java +++ b/forge-gui-mobile/src/forge/assets/Assets.java @@ -339,8 +339,8 @@ public class Assets implements Disposable { textrafonts = new ObjectMap<>(); if (!textrafonts.containsKey("textrafont")) { Font font = new Font(bitmapFont, 0f, 2f, 0f, 0f); - font.addAtlas(item_atlas, 0f, 0f, 0f); - font.addAtlas(pixelmana_atlas, 0f, -12f, 0f); + font.addAtlas(item_atlas, 0f, 4f, 0f); + font.addAtlas(pixelmana_atlas, -90f, 20f, 0f); font.integerPosition = false; textrafonts.put("textrafont", font); } @@ -352,7 +352,7 @@ public class Assets implements Disposable { textrafonts = new ObjectMap<>(); if (!textrafonts.containsKey("keysfont")) { Font font = new Font(bitmapFont); - font.addAtlas(keys_atlas); + font.addAtlas(keys_atlas, 0f, 4f, 0f); font.integerPosition = false; textrafonts.put("keysfont", font); } @@ -364,7 +364,7 @@ public class Assets implements Disposable { textrafonts = new ObjectMap<>(); if (!textrafonts.containsKey(name)) { Font font = new Font(bitmapFont); - font.addAtlas(items_atlas); + font.addAtlas(items_atlas, 0f, 4f, 0f); font.integerPosition = false; textrafonts.put(name, font); }