mirror of
https://github.com/KAMKEEL/CustomNPC-Plus.git
synced 2026-11-12 20:07:32 +00:00
Added bold/italic rendering for TokenType
This commit is contained in:
1 parent
275a5f10c9
commit
86da3f21e1
3 files changed
+38
-5
No files matched your search
@@ -226,6 +226,7 @@ public class ScriptLine {
|
||||
* Draw this line with syntax highlighting using Minecraft color codes.
|
||||
* Compatible with the existing rendering system.
|
||||
* Also draws curly underlines for tokens with errors (method call validation failures).
|
||||
* Supports bold (§l) and italic (§o) formatting for certain token types.
|
||||
*/
|
||||
public void drawString(int x, int y, int defaultColor) {
|
||||
StringBuilder builder = new StringBuilder();
|
||||
@@ -246,12 +247,16 @@ public class ScriptLine {
|
||||
}
|
||||
|
||||
|
||||
// Append the colored token
|
||||
// Append style codes (bold/italic) if applicable
|
||||
String stylePrefix = t.getStylePrefix();
|
||||
|
||||
// Append the colored token with style
|
||||
builder.append(COLOR_CHAR)
|
||||
.append(t.getColorCode())
|
||||
.append(stylePrefix)
|
||||
.append(t.getText())
|
||||
.append(COLOR_CHAR)
|
||||
.append('f'); // Reset to white
|
||||
.append('r'); // Reset all formatting (color + bold/italic)
|
||||
|
||||
currentX += tokenWidth;
|
||||
lastIndex = tokenStart + t.getText().length();
|
||||
@@ -295,10 +300,11 @@ public class ScriptLine {
|
||||
}
|
||||
|
||||
// Add the colored token
|
||||
segments.add(new TextSegment(fullText.length(), t.getText(), t.getHexColor(), true));
|
||||
fullText.append(t.getText());
|
||||
String styledText = t.getStylePrefix() + t.getText();
|
||||
segments.add(new TextSegment(fullText.length(), styledText, t.getHexColor(), true));
|
||||
fullText.append(styledText);
|
||||
|
||||
lastIndex = tokenStart + t.getText().length();
|
||||
lastIndex = tokenStart + styledText.length();
|
||||
}
|
||||
|
||||
// Add any remaining text after the last token
|
||||
|
||||
@@ -248,6 +248,17 @@ public class Token {
|
||||
public char getColorCode() {
|
||||
return type.toColorCode();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the Minecraft style prefix for this token (bold/italic codes).
|
||||
* Returns empty string if no style, otherwise §l for bold, §o for italic, or both.
|
||||
*/
|
||||
public String getStylePrefix() {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
if (type.isBold()) sb.append('\u00A7').append('l');
|
||||
if (type.isItalic()) sb.append('\u00A7').append('o');
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
|
||||
@@ -45,10 +45,18 @@ public enum TokenType {
|
||||
|
||||
private final int hexColor;
|
||||
private final int priority;
|
||||
private final boolean bold;
|
||||
private final boolean italic;
|
||||
|
||||
TokenType(int hexColor, int priority) {
|
||||
this(hexColor, priority, false, false);
|
||||
}
|
||||
|
||||
TokenType(int hexColor, int priority, boolean bold, boolean italic) {
|
||||
this.hexColor = hexColor;
|
||||
this.priority = priority;
|
||||
this.bold = bold;
|
||||
this.italic = italic;
|
||||
}
|
||||
|
||||
public int getHexColor() {
|
||||
@@ -59,6 +67,14 @@ public enum TokenType {
|
||||
return priority;
|
||||
}
|
||||
|
||||
public boolean isBold() {
|
||||
return bold;
|
||||
}
|
||||
|
||||
public boolean isItalic() {
|
||||
return italic;
|
||||
}
|
||||
|
||||
public static int getColor(TypeInfo typeInfo) {
|
||||
if (typeInfo == null)
|
||||
return TokenType.IMPORTED_CLASS.getHexColor();
|
||||
|
||||
Reference in new issue
Block a user