mirror of
https://github.com/xiaozhou233/OrangeX-Client.git
synced 2026-12-05 21:15:53 +08:00
[Feat] Custom Font Render
This commit is contained in:
1 parent
328a545b99
commit
17e4b417d8
14 files changed
+827
-9
No files matched your search
@@ -1,5 +1,6 @@
|
||||
package cn.xiaozhou233.orangex;
|
||||
|
||||
import cn.xiaozhou233.orangex.font.FontManager;
|
||||
import cn.xiaozhou233.orangex.mixin.MixinManager;
|
||||
import cn.xiaozhou233.orangex.module.ModuleManager;
|
||||
import lombok.Getter;
|
||||
@@ -19,6 +20,8 @@ public class OrangeX {
|
||||
private static ModuleManager moduleManager = new ModuleManager();
|
||||
@Getter
|
||||
private static String orangexDir = new File(System.getProperty("user.dir") + "/.orangex/").getAbsolutePath();
|
||||
@Getter
|
||||
private static FontManager fontManager = new FontManager();
|
||||
|
||||
public static void start() {
|
||||
System.out.println("OrangeX loading...");
|
||||
|
||||
@@ -0,0 +1,208 @@
|
||||
package cn.xiaozhou233.orangex.font;
|
||||
|
||||
|
||||
import net.minecraft.client.renderer.texture.DynamicTexture;
|
||||
import org.lwjgl.opengl.GL11;
|
||||
|
||||
import java.awt.*;
|
||||
import java.awt.geom.Rectangle2D;
|
||||
import java.awt.image.BufferedImage;
|
||||
|
||||
|
||||
|
||||
public class CFont
|
||||
{
|
||||
private float imgSize = 512;
|
||||
protected CharData[] charData = new CharData[256];
|
||||
protected Font font;
|
||||
protected boolean antiAlias;
|
||||
protected boolean fractionalMetrics;
|
||||
protected int fontHeight = -1;
|
||||
protected int charOffset = 0;
|
||||
protected DynamicTexture tex;
|
||||
|
||||
public CFont(Font font, boolean antiAlias, boolean fractionalMetrics)
|
||||
{
|
||||
this.font = font;
|
||||
this.antiAlias = antiAlias;
|
||||
this.fractionalMetrics = fractionalMetrics;
|
||||
tex = setupTexture(font, antiAlias, fractionalMetrics, this.charData);
|
||||
}
|
||||
|
||||
public DynamicTexture setupTexture(Font font, boolean antiAlias, boolean fractionalMetrics, CharData[] chars)
|
||||
{
|
||||
BufferedImage img = generateFontImage(font, antiAlias, fractionalMetrics, chars);
|
||||
|
||||
try
|
||||
{
|
||||
return new DynamicTexture(img);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
protected BufferedImage generateFontImage(Font font, boolean antiAlias, boolean fractionalMetrics, CharData[] chars)
|
||||
{
|
||||
int imgSize = (int) this.imgSize;
|
||||
BufferedImage bufferedImage = new BufferedImage(imgSize, imgSize, BufferedImage.TYPE_INT_ARGB);
|
||||
Graphics2D g = (Graphics2D) bufferedImage.getGraphics();
|
||||
g.setFont(font);
|
||||
g.setColor(new Color(255, 255, 255, 0));
|
||||
g.fillRect(0, 0, imgSize, imgSize);
|
||||
g.setColor(Color.WHITE);
|
||||
g.setRenderingHint(RenderingHints.KEY_FRACTIONALMETRICS, fractionalMetrics ? RenderingHints.VALUE_FRACTIONALMETRICS_ON : RenderingHints.VALUE_FRACTIONALMETRICS_OFF);
|
||||
g.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, antiAlias ? RenderingHints.VALUE_TEXT_ANTIALIAS_ON : RenderingHints.VALUE_TEXT_ANTIALIAS_OFF);
|
||||
g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, antiAlias ? RenderingHints.VALUE_ANTIALIAS_ON : RenderingHints.VALUE_ANTIALIAS_OFF);
|
||||
FontMetrics fontMetrics = g.getFontMetrics();
|
||||
int charHeight = 0;
|
||||
int positionX = 0;
|
||||
int positionY = 1;
|
||||
|
||||
for (int i = 0; i < chars.length; i++)
|
||||
{
|
||||
char ch = (char) i;
|
||||
CharData charData = new CharData();
|
||||
Rectangle2D dimensions = fontMetrics.getStringBounds(String.valueOf(ch), g);
|
||||
charData.width = (dimensions.getBounds().width + 8);
|
||||
charData.height = dimensions.getBounds().height;
|
||||
|
||||
if (positionX + charData.width >= imgSize)
|
||||
{
|
||||
positionX = 0;
|
||||
positionY += charHeight;
|
||||
charHeight = 0;
|
||||
}
|
||||
|
||||
if (charData.height > charHeight)
|
||||
{
|
||||
charHeight = charData.height;
|
||||
}
|
||||
|
||||
charData.storedX = positionX;
|
||||
charData.storedY = positionY;
|
||||
|
||||
if (charData.height > this.fontHeight)
|
||||
{
|
||||
this.fontHeight = charData.height;
|
||||
}
|
||||
|
||||
chars[i] = charData;
|
||||
g.drawString(String.valueOf(ch), positionX + 2, positionY + fontMetrics.getAscent());
|
||||
positionX += charData.width;
|
||||
}
|
||||
|
||||
return bufferedImage;
|
||||
}
|
||||
|
||||
public void drawChar(CharData[] chars, char c, float x, float y) throws ArrayIndexOutOfBoundsException
|
||||
{
|
||||
try
|
||||
{
|
||||
drawQuad(x, y, chars[c].width, chars[c].height, chars[c].storedX, chars[c].storedY, chars[c].width, chars[c].height);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
protected void drawQuad(float x, float y, float width, float height, float srcX, float srcY, float srcWidth, float srcHeight)
|
||||
{
|
||||
float renderSRCX = srcX / imgSize;
|
||||
float renderSRCY = srcY / imgSize;
|
||||
float renderSRCWidth = srcWidth / imgSize;
|
||||
float renderSRCHeight = srcHeight / imgSize;
|
||||
GL11.glTexCoord2f(renderSRCX + renderSRCWidth, renderSRCY);
|
||||
GL11.glVertex2d(x + width, y);
|
||||
GL11.glTexCoord2f(renderSRCX, renderSRCY);
|
||||
GL11.glVertex2d(x, y);
|
||||
GL11.glTexCoord2f(renderSRCX, renderSRCY + renderSRCHeight);
|
||||
GL11.glVertex2d(x, y + height);
|
||||
GL11.glTexCoord2f(renderSRCX, renderSRCY + renderSRCHeight);
|
||||
GL11.glVertex2d(x, y + height);
|
||||
GL11.glTexCoord2f(renderSRCX + renderSRCWidth, renderSRCY + renderSRCHeight);
|
||||
GL11.glVertex2d(x + width, y + height);
|
||||
GL11.glTexCoord2f(renderSRCX + renderSRCWidth, renderSRCY);
|
||||
GL11.glVertex2d(x + width, y);
|
||||
}
|
||||
|
||||
public int getStringHeight(String text)
|
||||
{
|
||||
return getHeight();
|
||||
}
|
||||
|
||||
public int getHeight()
|
||||
{
|
||||
return (this.fontHeight - 8) / 2;
|
||||
}
|
||||
|
||||
public int getStringWidth(String text)
|
||||
{
|
||||
int width = 0;
|
||||
|
||||
for (char c : text.toCharArray())
|
||||
{
|
||||
if ((c < this.charData.length) && (c >= 0))
|
||||
{
|
||||
width += this.charData[c].width - 8 + this.charOffset;
|
||||
}
|
||||
}
|
||||
|
||||
return width / 2;
|
||||
}
|
||||
|
||||
public boolean isAntiAlias()
|
||||
{
|
||||
return this.antiAlias;
|
||||
}
|
||||
|
||||
public void setAntiAlias(boolean antiAlias)
|
||||
{
|
||||
if (this.antiAlias != antiAlias)
|
||||
{
|
||||
this.antiAlias = antiAlias;
|
||||
tex = setupTexture(this.font, antiAlias, this.fractionalMetrics, this.charData);
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isFractionalMetrics()
|
||||
{
|
||||
return this.fractionalMetrics;
|
||||
}
|
||||
|
||||
public void setFractionalMetrics(boolean fractionalMetrics)
|
||||
{
|
||||
if (this.fractionalMetrics != fractionalMetrics)
|
||||
{
|
||||
this.fractionalMetrics = fractionalMetrics;
|
||||
tex = setupTexture(this.font, this.antiAlias, fractionalMetrics, this.charData);
|
||||
}
|
||||
}
|
||||
|
||||
public Font getFont()
|
||||
{
|
||||
return this.font;
|
||||
}
|
||||
|
||||
public void setFont(Font font)
|
||||
{
|
||||
this.font = font;
|
||||
tex = setupTexture(font, this.antiAlias, this.fractionalMetrics, this.charData);
|
||||
}
|
||||
|
||||
protected class CharData
|
||||
{
|
||||
public int width;
|
||||
public int height;
|
||||
public int storedX;
|
||||
public int storedY;
|
||||
|
||||
protected CharData()
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
package cn.xiaozhou233.orangex.font;
|
||||
|
||||
import java.awt.*;
|
||||
|
||||
public class FontManager {
|
||||
public FontRenderer MontserratRegular18 = new FontRenderer("Montserrat-Bold.ttf", 18, Font.PLAIN, true, true);
|
||||
public FontRenderer MontserratRegular32 = new FontRenderer("Montserrat-Bold.ttf", 32, Font.PLAIN, true, true);
|
||||
public FontRenderer MontserratMedium18 = new FontRenderer("Montserrat-Medium.ttf", 18, Font.PLAIN, true, true);
|
||||
public FontRenderer MontserratMedium32 = new FontRenderer("Montserrat-Medium.ttf", 32, Font.PLAIN, true, true);
|
||||
public FontRenderer MontserratBold18 = new FontRenderer("Montserrat-Bold.ttf", 18, Font.PLAIN, true, true);
|
||||
public FontRenderer MontserratBold32 = new FontRenderer("Montserrat-Bold.ttf", 32, Font.PLAIN, true, true);
|
||||
|
||||
public FontRenderer JelloMedium32 = new FontRenderer("JelloMedium.ttf", 32, Font.PLAIN, true, true);
|
||||
}
|
||||
@@ -0,0 +1,474 @@
|
||||
package cn.xiaozhou233.orangex.font;
|
||||
|
||||
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.renderer.GlStateManager;
|
||||
import net.minecraft.client.renderer.texture.DynamicTexture;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import org.lwjgl.opengl.GL11;
|
||||
|
||||
import java.awt.*;
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.InputStream;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
|
||||
public class FontRenderer extends CFont {
|
||||
protected CFont.CharData[] boldChars = new CFont.CharData[256];
|
||||
protected CFont.CharData[] italicChars = new CFont.CharData[256];
|
||||
protected CFont.CharData[] boldItalicChars = new CFont.CharData[256];
|
||||
|
||||
private final int[] colorCode = new int[32];
|
||||
|
||||
/*
|
||||
CREDIT G0dwhitelight.
|
||||
*/
|
||||
public FontRenderer(Font font, boolean antiAlias, boolean fractionalMetrics) {
|
||||
super(font, antiAlias, fractionalMetrics);
|
||||
setupMinecraftColorcodes();
|
||||
setupBoldItalicIDs();
|
||||
}
|
||||
|
||||
public FontRenderer(String filePath, int size, int fontType, boolean antiAlias, boolean fractionalMetrics) {
|
||||
super(FontUtil.getFontFromTTF(
|
||||
FontRenderer.class.getClassLoader().getResourceAsStream("fonts/" + filePath), size, fontType),
|
||||
antiAlias, fractionalMetrics);
|
||||
setupMinecraftColorcodes();
|
||||
setupBoldItalicIDs();
|
||||
}
|
||||
|
||||
public float drawString(String text, float x, float y, int color) {
|
||||
return drawString(text, x, y, color, false);
|
||||
}
|
||||
|
||||
public float drawString(String text, double x, double y, int color) {
|
||||
return drawString(text, x, y, color, false);
|
||||
}
|
||||
|
||||
public float drawStringWithShadow(String text, float x, float y, int color) {
|
||||
float shadowWidth = drawString(text, x + 1D, y + .5D, color, true);
|
||||
return Math.max(shadowWidth, drawString(text, x, y, color, false));
|
||||
}
|
||||
|
||||
public float drawStringWithShadow(String text, double x, double y, int color) {
|
||||
float shadowWidth = drawString(text, x + 1, y + .5, color, true);
|
||||
return Math.max(shadowWidth, drawString(text, x, y, color, false));
|
||||
}
|
||||
|
||||
public float drawCenteredString(String text, float x, float y, int color) {
|
||||
return drawString(text, x - getStringWidth(text) / 2, y, color);
|
||||
}
|
||||
|
||||
public float drawCenteredString(String text, double x, double y, int color) {
|
||||
return drawString(text, x - getStringWidth(text) / 2, y, color);
|
||||
}
|
||||
|
||||
public float drawCenteredStringWithShadow(String text, float x, float y, int color) {
|
||||
float shadowWidth = drawString(text, x - getStringWidth(text) / 2 + 0.45D, y + 0.5D, color, true);
|
||||
return drawString(text, x - getStringWidth(text) / 2, y, color);
|
||||
}
|
||||
|
||||
public void drawStringWithOutline(String text, double x, double y, int color) {
|
||||
drawString(text, x - .5, y, 0x000000);
|
||||
|
||||
drawString(text, x + .5, y, 0x000000);
|
||||
|
||||
drawString(text, x, y - .5, 0x000000);
|
||||
|
||||
drawString(text, x, y + .5, 0x000000);
|
||||
|
||||
drawString(text, x, y, color);
|
||||
}
|
||||
|
||||
public void drawCenteredStringWithOutline(String text, double x, double y, int color) {
|
||||
drawCenteredString(text, x - .5, y, 0x000000);
|
||||
|
||||
drawCenteredString(text, x + .5, y, 0x000000);
|
||||
|
||||
drawCenteredString(text, x, y - .5, 0x000000);
|
||||
|
||||
drawCenteredString(text, x, y + .5, 0x000000);
|
||||
|
||||
drawCenteredString(text, x, y, color);
|
||||
}
|
||||
|
||||
public float drawCenteredStringWithShadow(String text, double x, double y, int color) {
|
||||
float shadowWidth = drawString(text, x - getStringWidth(text) / 2 + 0.45D, y + 0.5D, color, true);
|
||||
return drawString(text, x - getStringWidth(text) / 2, y, color);
|
||||
}
|
||||
|
||||
public float drawString(String text, double x, double y, int color, boolean shadow) {
|
||||
Minecraft mc = Minecraft.getMinecraft();
|
||||
x -= 1;
|
||||
|
||||
if (text == null) {
|
||||
return 0.0F;
|
||||
}
|
||||
|
||||
if (color == 553648127) {
|
||||
color = 16777215;
|
||||
}
|
||||
|
||||
if ((color & 0xFC000000) == 0) {
|
||||
color |= -16777216;
|
||||
}
|
||||
|
||||
if (shadow) {
|
||||
color = (color & 0xFCFCFC) >> 2 | color & new Color(20, 20, 20, 200).getRGB();
|
||||
}
|
||||
|
||||
CFont.CharData[] currentData = this.charData;
|
||||
float alpha = (color >> 24 & 0xFF) / 255.0F;
|
||||
boolean randomCase = false;
|
||||
boolean bold = false;
|
||||
boolean italic = false;
|
||||
boolean strikethrough = false;
|
||||
boolean underline = false;
|
||||
boolean render = true;
|
||||
x *= 2.0D;
|
||||
y = (y - 3.0D) * 2.0D;
|
||||
|
||||
if (render) {
|
||||
GL11.glPushMatrix();
|
||||
GlStateManager.scale(0.5D, 0.5D, 0.5D);
|
||||
GlStateManager.enableBlend();
|
||||
GlStateManager.blendFunc(770, 771);
|
||||
GlStateManager.color((color >> 16 & 0xFF) / 255.0F, (color >> 8 & 0xFF) / 255.0F, (color & 0xFF) / 255.0F, alpha);
|
||||
int size = text.length();
|
||||
GlStateManager.enableTexture2D();
|
||||
GlStateManager.bindTexture(tex.getGlTextureId());
|
||||
|
||||
GL11.glBindTexture(GL11.GL_TEXTURE_2D, tex.getGlTextureId());
|
||||
|
||||
for (int i = 0; i < size; i++) {
|
||||
char character = text.charAt(i);
|
||||
if ((String.valueOf(character).equals("\247")) && (i < size)) {
|
||||
int colorIndex = 21;
|
||||
|
||||
try {
|
||||
colorIndex = "0123456789abcdefklmnor".indexOf(text.charAt(i + 1));
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
if (colorIndex < 16) {
|
||||
bold = false;
|
||||
italic = false;
|
||||
randomCase = false;
|
||||
underline = false;
|
||||
strikethrough = false;
|
||||
GlStateManager.bindTexture(tex.getGlTextureId());
|
||||
// GL11.glfunc_179144_i(GL11.GL_TEXTURE_2D,
|
||||
// tex.getGlTextureId());
|
||||
currentData = this.charData;
|
||||
|
||||
if ((colorIndex < 0) || (colorIndex > 15)) {
|
||||
colorIndex = 15;
|
||||
}
|
||||
|
||||
if (shadow) {
|
||||
colorIndex += 16;
|
||||
}
|
||||
|
||||
int colorcode = this.colorCode[colorIndex];
|
||||
GlStateManager.color((colorcode >> 16 & 0xFF) / 255.0F, (colorcode >> 8 & 0xFF) / 255.0F, (colorcode & 0xFF) / 255.0F, alpha);
|
||||
} else if (colorIndex == 16) {
|
||||
randomCase = true;
|
||||
} else if (colorIndex == 17) {
|
||||
bold = true;
|
||||
|
||||
if (italic) {
|
||||
GlStateManager.bindTexture(texItalicBold.getGlTextureId());
|
||||
// GL11.glfunc_179144_i(GL11.GL_TEXTURE_2D,
|
||||
// texItalicBold.getGlTextureId());
|
||||
currentData = this.boldItalicChars;
|
||||
} else {
|
||||
GlStateManager.bindTexture(texBold.getGlTextureId());
|
||||
// GL11.glfunc_179144_i(GL11.GL_TEXTURE_2D,
|
||||
// texBold.getGlTextureId());
|
||||
currentData = this.boldChars;
|
||||
}
|
||||
} else if (colorIndex == 18) {
|
||||
strikethrough = true;
|
||||
} else if (colorIndex == 19) {
|
||||
underline = true;
|
||||
} else if (colorIndex == 20) {
|
||||
italic = true;
|
||||
|
||||
if (bold) {
|
||||
GlStateManager.bindTexture(texItalicBold.getGlTextureId());
|
||||
// GL11.glfunc_179144_i(GL11.GL_TEXTURE_2D,
|
||||
// texItalicBold.getGlTextureId());
|
||||
currentData = this.boldItalicChars;
|
||||
} else {
|
||||
GlStateManager.bindTexture(texItalic.getGlTextureId());
|
||||
// GL11.glfunc_179144_i(GL11.GL_TEXTURE_2D,
|
||||
// texItalic.getGlTextureId());
|
||||
currentData = this.italicChars;
|
||||
}
|
||||
} else if (colorIndex == 21) {
|
||||
bold = false;
|
||||
italic = false;
|
||||
randomCase = false;
|
||||
underline = false;
|
||||
strikethrough = false;
|
||||
GlStateManager.color((color >> 16 & 0xFF) / 255.0F, (color >> 8 & 0xFF) / 255.0F, (color & 0xFF) / 255.0F, alpha);
|
||||
GlStateManager.bindTexture(tex.getGlTextureId());
|
||||
// GL11.glfunc_179144_i(GL11.GL_TEXTURE_2D,
|
||||
// tex.getGlTextureId());
|
||||
currentData = this.charData;
|
||||
}
|
||||
|
||||
i++;
|
||||
} else if ((character < currentData.length) && (character >= 0)) {
|
||||
GL11.glBegin(GL11.GL_TRIANGLES);
|
||||
drawChar(currentData, character, (float) x, (float) y);
|
||||
GL11.glEnd();
|
||||
|
||||
if (strikethrough) {
|
||||
drawLine(x, y + currentData[character].height / 2, x + currentData[character].width - 8.0D, y + currentData[character].height / 2, 1.0F);
|
||||
}
|
||||
|
||||
if (underline) {
|
||||
drawLine(x, y + currentData[character].height - 2.0D, x + currentData[character].width - 8.0D, y + currentData[character].height - 2.0D, 1.0F);
|
||||
}
|
||||
|
||||
x += currentData[character].width - 8 + this.charOffset;
|
||||
}
|
||||
}
|
||||
|
||||
GL11.glHint(GL11.GL_POLYGON_SMOOTH_HINT, GL11.GL_DONT_CARE);
|
||||
GL11.glPopMatrix();
|
||||
}
|
||||
|
||||
return (float) x / 2.0F;
|
||||
}
|
||||
|
||||
public int getStringWidth(String text) {
|
||||
if (text == null) {
|
||||
return 0;
|
||||
}
|
||||
int width = 0;
|
||||
CFont.CharData[] currentData = this.charData;
|
||||
boolean bold = false;
|
||||
boolean italic = false;
|
||||
int size = text.length();
|
||||
|
||||
for (int i = 0; i < size; i++) {
|
||||
char character = text.charAt(i);
|
||||
|
||||
if ((String.valueOf(character).equals("\247")) && (i < size)) {
|
||||
int colorIndex = "0123456789abcdefklmnor".indexOf(character);
|
||||
|
||||
if (colorIndex < 16) {
|
||||
bold = false;
|
||||
italic = false;
|
||||
} else if (colorIndex == 17) {
|
||||
bold = true;
|
||||
|
||||
if (italic) {
|
||||
currentData = this.boldItalicChars;
|
||||
} else {
|
||||
currentData = this.boldChars;
|
||||
}
|
||||
} else if (colorIndex == 20) {
|
||||
italic = true;
|
||||
|
||||
if (bold) {
|
||||
currentData = this.boldItalicChars;
|
||||
} else {
|
||||
currentData = this.italicChars;
|
||||
}
|
||||
} else if (colorIndex == 21) {
|
||||
bold = false;
|
||||
italic = false;
|
||||
currentData = this.charData;
|
||||
}
|
||||
|
||||
i++;
|
||||
} else if ((character < currentData.length) && (character >= 0)) {
|
||||
width += currentData[character].width - 8 + this.charOffset;
|
||||
}
|
||||
}
|
||||
|
||||
return width / 2;
|
||||
}
|
||||
|
||||
public int getStringWidthCust(String text) {
|
||||
if (text == null) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
int width = 0;
|
||||
CFont.CharData[] currentData = this.charData;
|
||||
boolean bold = false;
|
||||
boolean italic = false;
|
||||
int size = text.length();
|
||||
|
||||
for (int i = 0; i < size; i++) {
|
||||
char character = text.charAt(i);
|
||||
|
||||
if ((String.valueOf(character).equals("§")) && (i < size)) {
|
||||
int colorIndex = "0123456789abcdefklmnor".indexOf(character);
|
||||
|
||||
if (colorIndex < 16) {
|
||||
bold = false;
|
||||
italic = false;
|
||||
} else if (colorIndex == 17) {
|
||||
bold = true;
|
||||
|
||||
if (italic) {
|
||||
currentData = this.boldItalicChars;
|
||||
} else {
|
||||
currentData = this.boldChars;
|
||||
}
|
||||
} else if (colorIndex == 20) {
|
||||
italic = true;
|
||||
|
||||
if (bold) {
|
||||
currentData = this.boldItalicChars;
|
||||
} else {
|
||||
currentData = this.italicChars;
|
||||
}
|
||||
} else if (colorIndex == 21) {
|
||||
bold = false;
|
||||
italic = false;
|
||||
currentData = this.charData;
|
||||
}
|
||||
|
||||
i++;
|
||||
} else if ((character < currentData.length) && (character >= 0)) {
|
||||
width += currentData[character].width - 8 + this.charOffset;
|
||||
}
|
||||
}
|
||||
|
||||
return (width - this.charOffset) / 2;
|
||||
}
|
||||
|
||||
public void setFont(Font font) {
|
||||
super.setFont(font);
|
||||
setupBoldItalicIDs();
|
||||
}
|
||||
|
||||
public void setAntiAlias(boolean antiAlias) {
|
||||
super.setAntiAlias(antiAlias);
|
||||
setupBoldItalicIDs();
|
||||
}
|
||||
|
||||
public void setFractionalMetrics(boolean fractionalMetrics) {
|
||||
super.setFractionalMetrics(fractionalMetrics);
|
||||
setupBoldItalicIDs();
|
||||
}
|
||||
|
||||
protected DynamicTexture texBold;
|
||||
protected DynamicTexture texItalic;
|
||||
protected DynamicTexture texItalicBold;
|
||||
|
||||
private void setupBoldItalicIDs() {
|
||||
texBold = setupTexture(this.font.deriveFont(1), this.antiAlias, this.fractionalMetrics, this.boldChars);
|
||||
texItalic = setupTexture(this.font.deriveFont(2), this.antiAlias, this.fractionalMetrics, this.italicChars);
|
||||
texItalicBold = setupTexture(this.font.deriveFont(3), this.antiAlias, this.fractionalMetrics, this.boldItalicChars);
|
||||
}
|
||||
|
||||
private void drawLine(double x, double y, double x1, double y1, float width) {
|
||||
GL11.glDisable(GL11.GL_TEXTURE_2D);
|
||||
GL11.glLineWidth(width);
|
||||
GL11.glBegin(GL11.GL_LINES);
|
||||
GL11.glVertex2d(x, y);
|
||||
GL11.glVertex2d(x1, y1);
|
||||
GL11.glEnd();
|
||||
GL11.glEnable(GL11.GL_TEXTURE_2D);
|
||||
}
|
||||
|
||||
public List<String> wrapWords(String text, double width) {
|
||||
List finalWords = new ArrayList();
|
||||
|
||||
if (getStringWidth(text) > width) {
|
||||
String[] words = text.split(" ");
|
||||
String currentWord = "";
|
||||
char lastColorCode = 65535;
|
||||
|
||||
for (String word : words) {
|
||||
for (int i = 0; i < word.toCharArray().length; i++) {
|
||||
char c = word.toCharArray()[i];
|
||||
|
||||
if ((String.valueOf(c).equals("§")) && (i < word.toCharArray().length - 1)) {
|
||||
lastColorCode = word.toCharArray()[(i + 1)];
|
||||
}
|
||||
}
|
||||
|
||||
if (getStringWidth(currentWord + word + " ") < width) {
|
||||
currentWord = currentWord + word + " ";
|
||||
} else {
|
||||
finalWords.add(currentWord);
|
||||
currentWord = "" + lastColorCode + word + " ";
|
||||
}
|
||||
}
|
||||
|
||||
if (currentWord.length() > 0) if (getStringWidth(currentWord) < width) {
|
||||
finalWords.add("" + lastColorCode + currentWord + " ");
|
||||
currentWord = "";
|
||||
} else {
|
||||
for (String s : formatString(currentWord, width)) {
|
||||
finalWords.add(s);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
finalWords.add(text);
|
||||
}
|
||||
|
||||
return finalWords;
|
||||
}
|
||||
|
||||
public List<String> formatString(String string, double width) {
|
||||
List finalWords = new ArrayList();
|
||||
String currentWord = "";
|
||||
char lastColorCode = 65535;
|
||||
char[] chars = string.toCharArray();
|
||||
|
||||
for (int i = 0; i < chars.length; i++) {
|
||||
char c = chars[i];
|
||||
|
||||
if ((String.valueOf(c).equals("§")) && (i < chars.length - 1))//Why does intelij replace "§" with §
|
||||
{
|
||||
lastColorCode = chars[(i + 1)];
|
||||
}
|
||||
|
||||
if (getStringWidth(currentWord + c) < width) {
|
||||
currentWord = currentWord + c;
|
||||
} else {
|
||||
finalWords.add(currentWord);
|
||||
currentWord = "" + lastColorCode + String.valueOf(c);
|
||||
}
|
||||
}
|
||||
|
||||
if (currentWord.length() > 0) {
|
||||
finalWords.add(currentWord);
|
||||
}
|
||||
|
||||
return finalWords;
|
||||
}
|
||||
|
||||
private void setupMinecraftColorcodes() {
|
||||
for (int index = 0; index < 32; index++) {
|
||||
int noClue = (index >> 3 & 0x1) * 85;
|
||||
int red = (index >> 2 & 0x1) * 170 + noClue;
|
||||
int green = (index >> 1 & 0x1) * 170 + noClue;
|
||||
int blue = (index >> 0 & 0x1) * 170 + noClue;
|
||||
|
||||
if (index == 6) {
|
||||
red += 85;
|
||||
}
|
||||
|
||||
if (index >= 16) {
|
||||
red /= 4;
|
||||
green /= 4;
|
||||
blue /= 4;
|
||||
}
|
||||
|
||||
this.colorCode[index] = ((red & 0xFF) << 16 | (green & 0xFF) << 8 | blue & 0xFF);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
package cn.xiaozhou233.orangex.font;
|
||||
|
||||
import java.awt.*;
|
||||
import java.io.InputStream;
|
||||
|
||||
|
||||
public class FontUtil {
|
||||
|
||||
public static Font getFontFromTTF(InputStream inputStream, float fontSize, int fontType) {
|
||||
Font output = null;
|
||||
try {
|
||||
output = Font.createFont(fontType, inputStream);
|
||||
output = output.deriveFont(fontSize);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return output;
|
||||
}
|
||||
}
|
||||
@@ -2,13 +2,14 @@ package cn.xiaozhou233.orangex.module.impl.render;
|
||||
|
||||
import cn.xiaozhou233.orangex.OrangeX;
|
||||
import cn.xiaozhou233.orangex.event.impl.EventRender2D;
|
||||
import cn.xiaozhou233.orangex.font.FontRenderer;
|
||||
import cn.xiaozhou233.orangex.module.Module;
|
||||
import cn.xiaozhou233.orangex.module.ModuleCategory;
|
||||
import net.minecraft.client.gui.Gui;
|
||||
import net.minecraft.client.gui.ScaledResolution;
|
||||
import org.greenrobot.eventbus.Subscribe;
|
||||
|
||||
import java.awt.Color;
|
||||
import java.awt.*;
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
@@ -17,7 +18,6 @@ public class HUD extends Module {
|
||||
|
||||
private float rainbowTick = 0f;
|
||||
|
||||
// HUD 常量
|
||||
private static final int MARGIN = 6;
|
||||
private static final int PADDING = 2;
|
||||
private static final int MODULE_SPACING = 4;
|
||||
@@ -43,7 +43,7 @@ public class HUD extends Module {
|
||||
}
|
||||
|
||||
private void renderLogo() {
|
||||
fr.drawStringWithShadow("OrangeX Client", MARGIN, MARGIN, LOGO_COLOR);
|
||||
OrangeX.getFontManager().JelloMedium32.drawStringWithShadow("OrangeX", 5, 5, LOGO_COLOR);
|
||||
}
|
||||
|
||||
private void renderModuleList(ScaledResolution sr) {
|
||||
@@ -51,7 +51,8 @@ public class HUD extends Module {
|
||||
.getAllModules()
|
||||
.stream()
|
||||
.filter(Module::isEnabled)
|
||||
.sorted(Comparator.comparingInt((Module m) -> fr.getStringWidth(m.getName())).reversed())
|
||||
.sorted(Comparator.comparingInt((Module m) ->
|
||||
OrangeX.getFontManager().MontserratMedium18.getStringWidth(m.getName())).reversed())
|
||||
.collect(Collectors.toList());
|
||||
|
||||
int y = MARGIN;
|
||||
@@ -59,26 +60,29 @@ public class HUD extends Module {
|
||||
|
||||
for (int i = 0; i < enabledModules.size(); i++) {
|
||||
Module module = enabledModules.get(i);
|
||||
int textWidth = fr.getStringWidth(module.getName());
|
||||
int textWidth = OrangeX.getFontManager().MontserratMedium18.getStringWidth(module.getName());
|
||||
int x = screenWidth - textWidth - MARGIN;
|
||||
|
||||
int color = getRainbowColor(rainbowTick + i * 6f);
|
||||
drawHudString(module.getName(), x, y, color);
|
||||
|
||||
y += fr.FONT_HEIGHT + MODULE_SPACING;
|
||||
y += OrangeX.getFontManager().MontserratMedium18.getStringHeight(module.getName()) + MODULE_SPACING;
|
||||
}
|
||||
}
|
||||
|
||||
private void drawHudString(String text, int x, int y, int color) {
|
||||
int textWidth = fr.getStringWidth(text);
|
||||
FontRenderer font = OrangeX.getFontManager().MontserratMedium18;
|
||||
int textWidth = font.getStringWidth(text);
|
||||
|
||||
Gui.drawRect(
|
||||
x - PADDING,
|
||||
y - PADDING,
|
||||
x + textWidth + PADDING,
|
||||
y + fr.FONT_HEIGHT + PADDING,
|
||||
y + font.getStringHeight(text) + PADDING,
|
||||
(BACKGROUND_ALPHA << 24) | 0x000000
|
||||
);
|
||||
fr.drawStringWithShadow(text, x, y, color);
|
||||
|
||||
font.drawStringWithShadow(text, x, y, color);
|
||||
}
|
||||
|
||||
private int getRainbowColor(float tick) {
|
||||
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -0,0 +1,93 @@
|
||||
Copyright 2024 The Montserrat.Git Project Authors (https://github.com/JulietaUla/Montserrat.git)
|
||||
|
||||
This Font Software is licensed under the SIL Open Font License, Version 1.1.
|
||||
This license is copied below, and is also available with a FAQ at:
|
||||
https://openfontlicense.org
|
||||
|
||||
|
||||
-----------------------------------------------------------
|
||||
SIL OPEN FONT LICENSE Version 1.1 - 26 February 2007
|
||||
-----------------------------------------------------------
|
||||
|
||||
PREAMBLE
|
||||
The goals of the Open Font License (OFL) are to stimulate worldwide
|
||||
development of collaborative font projects, to support the font creation
|
||||
efforts of academic and linguistic communities, and to provide a free and
|
||||
open framework in which fonts may be shared and improved in partnership
|
||||
with others.
|
||||
|
||||
The OFL allows the licensed fonts to be used, studied, modified and
|
||||
redistributed freely as long as they are not sold by themselves. The
|
||||
fonts, including any derivative works, can be bundled, embedded,
|
||||
redistributed and/or sold with any software provided that any reserved
|
||||
names are not used by derivative works. The fonts and derivatives,
|
||||
however, cannot be released under any other type of license. The
|
||||
requirement for fonts to remain under this license does not apply
|
||||
to any document created using the fonts or their derivatives.
|
||||
|
||||
DEFINITIONS
|
||||
"Font Software" refers to the set of files released by the Copyright
|
||||
Holder(s) under this license and clearly marked as such. This may
|
||||
include source files, build scripts and documentation.
|
||||
|
||||
"Reserved Font Name" refers to any names specified as such after the
|
||||
copyright statement(s).
|
||||
|
||||
"Original Version" refers to the collection of Font Software components as
|
||||
distributed by the Copyright Holder(s).
|
||||
|
||||
"Modified Version" refers to any derivative made by adding to, deleting,
|
||||
or substituting -- in part or in whole -- any of the components of the
|
||||
Original Version, by changing formats or by porting the Font Software to a
|
||||
new environment.
|
||||
|
||||
"Author" refers to any designer, engineer, programmer, technical
|
||||
writer or other person who contributed to the Font Software.
|
||||
|
||||
PERMISSION & CONDITIONS
|
||||
Permission is hereby granted, free of charge, to any person obtaining
|
||||
a copy of the Font Software, to use, study, copy, merge, embed, modify,
|
||||
redistribute, and sell modified and unmodified copies of the Font
|
||||
Software, subject to the following conditions:
|
||||
|
||||
1) Neither the Font Software nor any of its individual components,
|
||||
in Original or Modified Versions, may be sold by itself.
|
||||
|
||||
2) Original or Modified Versions of the Font Software may be bundled,
|
||||
redistributed and/or sold with any software, provided that each copy
|
||||
contains the above copyright notice and this license. These can be
|
||||
included either as stand-alone text files, human-readable headers or
|
||||
in the appropriate machine-readable metadata fields within text or
|
||||
binary files as long as those fields can be easily viewed by the user.
|
||||
|
||||
3) No Modified Version of the Font Software may use the Reserved Font
|
||||
Name(s) unless explicit written permission is granted by the corresponding
|
||||
Copyright Holder. This restriction only applies to the primary font name as
|
||||
presented to the users.
|
||||
|
||||
4) The name(s) of the Copyright Holder(s) or the Author(s) of the Font
|
||||
Software shall not be used to promote, endorse or advertise any
|
||||
Modified Version, except to acknowledge the contribution(s) of the
|
||||
Copyright Holder(s) and the Author(s) or with their explicit written
|
||||
permission.
|
||||
|
||||
5) The Font Software, modified or unmodified, in part or in whole,
|
||||
must be distributed entirely under this license, and must not be
|
||||
distributed under any other license. The requirement for fonts to
|
||||
remain under this license does not apply to any document created
|
||||
using the Font Software.
|
||||
|
||||
TERMINATION
|
||||
This license becomes null and void if any of the above conditions are
|
||||
not met.
|
||||
|
||||
DISCLAIMER
|
||||
THE FONT SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OF
|
||||
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT
|
||||
OF COPYRIGHT, PATENT, TRADEMARK, OR OTHER RIGHT. IN NO EVENT SHALL THE
|
||||
COPYRIGHT HOLDER BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
||||
INCLUDING ANY GENERAL, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL
|
||||
DAMAGES, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
FROM, OUT OF THE USE OR INABILITY TO USE THE FONT SOFTWARE OR FROM
|
||||
OTHER DEALINGS IN THE FONT SOFTWARE.
|
||||
Reference in new issue
Block a user