This commit is contained in:
Anthony Calosa
2023-03-24 00:05:18 +08:00
parent dc7ffee172
commit 7da1b33681
3 changed files with 40 additions and 7 deletions

View File

@@ -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();
}
}

View File

@@ -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]":"]");
}
}

View File

@@ -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);
}