mirror of
https://github.com/KAMKEEL/CustomNPC-Plus.git
synced 2026-11-18 05:45:03 +00:00
Implemented syntax highlighting for scripts.
This commit is contained in:
1 parent
978358e827
commit
5f3ed66234
11 files changed
+715
-1008
No files matched your search
@@ -20,7 +20,7 @@ import noppes.npcs.entity.EntityNPCInterface;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
public class GuiScript extends GuiNPCInterface implements IGuiData, GuiYesNoCallback, ICustomScrollListener, IJTextAreaListener {
|
||||
public class GuiScript extends GuiNPCInterface implements IGuiData, GuiYesNoCallback, ICustomScrollListener, IJTextAreaListener, ITextChangeListener {
|
||||
public boolean showScript = false;
|
||||
private int activeTab = 0;
|
||||
public DataScript script;
|
||||
@@ -80,7 +80,10 @@ public class GuiScript extends GuiNPCInterface implements IGuiData, GuiYesNoCall
|
||||
|
||||
ScriptContainer container = script.getNPCScript(activeTab);
|
||||
|
||||
addTextField(new GuiNpcTextArea(2, this, guiLeft + 74, guiTop + 4, 239, 208, container == null?"":container.script));
|
||||
GuiScriptTextArea ta = new GuiScriptTextArea(this,2, guiLeft + 74, guiTop + 4, 239, 208, container == null?"":container.script);
|
||||
ta.enableCodeHighlighting();
|
||||
ta.setListener(this);
|
||||
this.addTextField(ta);
|
||||
|
||||
addButton(new GuiNpcButton(102, guiLeft + 315, guiTop + 4, 50, 20, "gui.clear"));
|
||||
addButton(new GuiNpcButton(101, guiLeft + 366, guiTop + 4, 50, 20, "gui.paste"));
|
||||
@@ -268,6 +271,12 @@ public class GuiScript extends GuiNPCInterface implements IGuiData, GuiYesNoCall
|
||||
}
|
||||
}
|
||||
|
||||
public void textUpdate(String text) {
|
||||
ScriptContainer container = script.getNPCScript(activeTab);
|
||||
if(container != null)
|
||||
container.script = text;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void saveText(String text) {
|
||||
ScriptContainer container = script.getNPCScript(activeTab);
|
||||
|
||||
@@ -94,9 +94,13 @@ public class GuiScriptInterface extends GuiNPCInterface implements GuiYesNoCallb
|
||||
hookLabel.color = 0xaaaaaa;
|
||||
addLabel(hookLabel);
|
||||
|
||||
ScriptContainer var7 = (ScriptContainer)this.handler.getScripts().get(this.activeTab - 1);
|
||||
GuiNpcTextArea left = new GuiNpcTextArea(2, this, this.guiLeft + yoffset, this.guiTop + yoffset, this.xSize - 110 - yoffset, (int)((double)this.ySize * 0.96D) - yoffset * 2, var7 == null?"":var7.script);
|
||||
this.addTextField(left);
|
||||
ScriptContainer container = (ScriptContainer)this.handler.getScripts().get(this.activeTab - 1);
|
||||
GuiScriptTextArea ta = new GuiScriptTextArea(this,2, guiLeft + 1 + yoffset, guiTop + yoffset, xSize - 108 - yoffset, (int) (ySize * 0.96) - yoffset * 2, container == null?"":container.script);
|
||||
ta.enableCodeHighlighting();
|
||||
ta.setListener(this);
|
||||
|
||||
this.addTextField(ta);
|
||||
|
||||
int left1 = this.guiLeft + this.xSize - 104;
|
||||
this.addButton(new GuiNpcButton(102, left1, this.guiTop + yoffset, 60, 20, "gui.clear"));
|
||||
this.addButton(new GuiNpcButton(101, left1 + 61, this.guiTop + yoffset, 60, 20, "gui.paste"));
|
||||
@@ -107,8 +111,8 @@ public class GuiScriptInterface extends GuiNPCInterface implements GuiYesNoCallb
|
||||
scroll.setSize(100, (int)((double)this.ySize * 0.54D) - yoffset * 2);
|
||||
scroll.guiLeft = left1;
|
||||
scroll.guiTop = this.guiTop + 88 + yoffset;
|
||||
if(var7 != null) {
|
||||
scroll.setList(var7.scripts);
|
||||
if(container != null) {
|
||||
scroll.setList(container.scripts);
|
||||
}
|
||||
|
||||
this.addScroll(scroll);
|
||||
|
||||
@@ -14,7 +14,7 @@ import org.lwjgl.opengl.GL11;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class GuiNpcTextArea extends GuiNpcTextField implements IGui{
|
||||
public class GuiNpcTextArea extends GuiNpcTextField {
|
||||
public boolean inMenu = true;
|
||||
public boolean numbersOnly = false;
|
||||
private int posX,posY,width,height;
|
||||
@@ -328,24 +328,4 @@ public class GuiNpcTextArea extends GuiNpcTextField implements IGui{
|
||||
}
|
||||
drawTexturedModalRect(x, y, width, 11, 5, 1);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getID() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void drawScreen(int var1, int var2) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateScreen() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isActive() {
|
||||
return isFieldActive();
|
||||
}
|
||||
}
|
||||
@@ -16,7 +16,7 @@ public class GuiNpcTextField extends GuiTextField{
|
||||
public int min = 0,max = Integer.MAX_VALUE,def = 0;
|
||||
public double minDouble = 0, maxDouble = Double.MAX_VALUE, defDouble = 0;
|
||||
public float minFloat = 0, maxFloat = Float.MAX_VALUE, defFloat = 0;
|
||||
private static GuiNpcTextField activeTextfield = null;
|
||||
protected static GuiNpcTextField activeTextfield = null;
|
||||
public boolean canEdit = true;
|
||||
|
||||
private final int[] allowedSpecialChars = {14,211,203,205};
|
||||
@@ -40,7 +40,7 @@ public class GuiNpcTextField extends GuiTextField{
|
||||
this(id, parent, Minecraft.getMinecraft().fontRenderer, i, j, k, l, s);
|
||||
}
|
||||
|
||||
private boolean charAllowed(char c, int i){
|
||||
protected boolean charAllowed(char c, int i){
|
||||
if(!integersOnly || Character.isDigit(c))
|
||||
return true;
|
||||
|
||||
|
||||
@@ -0,0 +1,591 @@
|
||||
//
|
||||
// Source code recreated from a .class file by IntelliJ IDEA
|
||||
// (powered by Fernflower decompiler)
|
||||
//
|
||||
|
||||
package noppes.npcs.client.gui.util;
|
||||
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.gui.GuiScreen;
|
||||
import net.minecraft.util.ChatAllowedCharacters;
|
||||
import noppes.npcs.NoppesStringUtils;
|
||||
import noppes.npcs.client.ClientProxy;
|
||||
import noppes.npcs.client.gui.util.TextContainer.LineData;
|
||||
import org.lwjgl.input.Keyboard;
|
||||
import org.lwjgl.input.Mouse;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.regex.Matcher;
|
||||
|
||||
import static net.minecraft.client.gui.GuiScreen.isCtrlKeyDown;
|
||||
|
||||
public class GuiScriptTextArea extends GuiNpcTextField {
|
||||
public int id;
|
||||
public int x;
|
||||
public int y;
|
||||
public int width;
|
||||
public int height;
|
||||
private int cursorCounter;
|
||||
private ITextChangeListener listener;
|
||||
public String text = null;
|
||||
private TextContainer container = null;
|
||||
public boolean active = false;
|
||||
public boolean enabled = true;
|
||||
public boolean visible = true;
|
||||
public boolean clicked = false;
|
||||
public boolean doubleClicked = false;
|
||||
public boolean clickScrolling = false;
|
||||
private int startSelection;
|
||||
private int endSelection;
|
||||
private int cursorPosition;
|
||||
private int scrolledLine = 0;
|
||||
private boolean enableCodeHighlighting = false;
|
||||
private static final char colorChar = '\uffff';
|
||||
public List<GuiScriptTextArea.UndoData> undoList = new ArrayList();
|
||||
public List<GuiScriptTextArea.UndoData> redoList = new ArrayList();
|
||||
public boolean undoing = false;
|
||||
private long lastClicked = 0L;
|
||||
|
||||
public GuiScriptTextArea(GuiScreen guiScreen, int id, int x, int y, int width, int height, String text) {
|
||||
super(id, guiScreen, x, y, width, height, null);
|
||||
this.id = id;
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
this.width = width;
|
||||
this.height = height;
|
||||
this.undoing = true;
|
||||
this.setText(text);
|
||||
this.undoing = false;
|
||||
}
|
||||
|
||||
public void drawTextBox(int xMouse, int yMouse){
|
||||
if(!visible)
|
||||
return;
|
||||
drawRect(x - 1, y - 1, x + width + 1, y + height + 1, 0xffa0a0a0);
|
||||
drawRect(x, y, x + width, y + height, 0xff000000);
|
||||
|
||||
container.visibleLines = height / container.lineHeight;
|
||||
|
||||
if(clicked){
|
||||
clicked = Mouse.isButtonDown(0);
|
||||
int i = getSelectionPos(xMouse, yMouse);
|
||||
if(i != cursorPosition){
|
||||
if(doubleClicked){
|
||||
startSelection = endSelection = cursorPosition;
|
||||
doubleClicked = false;
|
||||
}
|
||||
setCursor(i, true);
|
||||
}
|
||||
}
|
||||
else if(doubleClicked){
|
||||
doubleClicked = false;
|
||||
}
|
||||
|
||||
if(clickScrolling){
|
||||
clickScrolling = Mouse.isButtonDown(0);
|
||||
int diff = container.linesCount - container.visibleLines;
|
||||
scrolledLine = Math.min(Math.max((int)(1f * diff * (yMouse - y) / height), 0), diff);
|
||||
}
|
||||
int startBracket = 0, endBracket = 0;
|
||||
if(endSelection - startSelection == 1 || startSelection == endSelection && startSelection < text.length()){
|
||||
char c = text.charAt(startSelection);
|
||||
int found = 0;
|
||||
if(c == '{'){
|
||||
found = findClosingBracket(text.substring(startSelection), '{', '}');
|
||||
}
|
||||
else if(c == '['){
|
||||
found = findClosingBracket(text.substring(startSelection), '[', ']');
|
||||
}
|
||||
else if(c == '('){
|
||||
found = findClosingBracket(text.substring(startSelection), '(', ')');
|
||||
}
|
||||
else if(c == '}'){
|
||||
found = findOpeningBracket(text.substring(0, startSelection + 1), '{', '}');
|
||||
}
|
||||
else if(c == ']'){
|
||||
found = findOpeningBracket(text.substring(0, startSelection + 1), '[', ']');
|
||||
}
|
||||
else if(c == ')'){
|
||||
found = findOpeningBracket(text.substring(0, startSelection + 1), '(', ')');
|
||||
}
|
||||
if(found != 0){
|
||||
startBracket = startSelection;
|
||||
endBracket = startSelection + found;
|
||||
}
|
||||
}
|
||||
|
||||
List<LineData> list = new ArrayList<LineData>(container.lines);
|
||||
|
||||
String wordHightLight = null;
|
||||
if(startSelection != endSelection){
|
||||
Matcher m = container.regexWord.matcher(text);
|
||||
while(m.find()){
|
||||
if(m.start() == startSelection && m.end() == endSelection){
|
||||
wordHightLight = text.substring(startSelection, endSelection);
|
||||
}
|
||||
}
|
||||
}
|
||||
for(int i = 0; i < list.size(); i++){
|
||||
LineData data = list.get(i);
|
||||
String line = data.text;
|
||||
int w = line.length();
|
||||
if(startBracket != endBracket){
|
||||
if(startBracket >= data.start && startBracket < data.end){
|
||||
int s = ClientProxy.Font.width(line.substring(0, startBracket - data.start));
|
||||
int e = ClientProxy.Font.width(line.substring(0, startBracket - data.start + 1)) + 1;
|
||||
int posY = y + 1 + (i - scrolledLine) * container.lineHeight;
|
||||
drawRect(x + 1 + s, posY, x + 1 + e, posY + container.lineHeight + 1, 0x9900cc00);
|
||||
}
|
||||
if(endBracket >= data.start && endBracket < data.end){
|
||||
int s = ClientProxy.Font.width(line.substring(0, endBracket - data.start));
|
||||
int e = ClientProxy.Font.width(line.substring(0, endBracket - data.start + 1)) + 1;
|
||||
int posY = y + 1 + (i - scrolledLine) * container.lineHeight;
|
||||
drawRect(x + 1 + s, posY, x + 1 + e, posY + container.lineHeight + 1, 0x9900cc00);
|
||||
}
|
||||
}
|
||||
if(i >= scrolledLine && i < scrolledLine + container.visibleLines){
|
||||
if(wordHightLight != null){
|
||||
Matcher m = container.regexWord.matcher(line);
|
||||
while(m.find()){
|
||||
if(line.substring(m.start(), m.end()).equals(wordHightLight)){
|
||||
int s = ClientProxy.Font.width(line.substring(0, m.start()));
|
||||
int e = ClientProxy.Font.width(line.substring(0, m.end())) + 1;
|
||||
int posY = y + 1 + (i - scrolledLine) * container.lineHeight;
|
||||
drawRect(x + 1 + s, posY, x + 1 + e, posY + container.lineHeight + 1, 0x99004c00);
|
||||
}
|
||||
}
|
||||
}
|
||||
if(startSelection != endSelection && endSelection > data.start && startSelection <= data.end){
|
||||
if(startSelection < data.end){
|
||||
int s = ClientProxy.Font.width(line.substring(0, Math.max(startSelection - data.start, 0)));
|
||||
int e = ClientProxy.Font.width(line.substring(0, Math.min(endSelection - data.start, w))) + 1;
|
||||
int posY = y + 1 + (i - scrolledLine) * container.lineHeight;
|
||||
drawRect(x + 1 + s, posY, x + 1 + e, posY + container.lineHeight + 1, 0x990000ff);
|
||||
}
|
||||
}
|
||||
int yPos = y + (i - scrolledLine) * container.lineHeight + 1;
|
||||
data.drawString(x + 1, yPos, 0xFFe0e0e0);
|
||||
|
||||
if(active && isEnabled() && (cursorCounter / 6) % 2 == 0 && cursorPosition >= data.start && cursorPosition < data.end){
|
||||
int posX = x + ClientProxy.Font.width(line.substring(0, cursorPosition - data.start));
|
||||
drawRect(posX + 1, yPos, posX + 2, yPos + 1 + container.lineHeight, -3092272);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(hasVerticalScrollbar()){
|
||||
Minecraft.getMinecraft().renderEngine.bindTexture(GuiCustomScroll.resource);
|
||||
int sbSize = Math.max((int) (1f * container.visibleLines / container.linesCount * height), 2);
|
||||
|
||||
int posX = x + width - 6;
|
||||
int posY = (int) (y + 1f * scrolledLine / container.linesCount * (height - 4)) + 1;
|
||||
|
||||
drawRect(posX, posY, posX + 5, posY + sbSize, 0xFFe0e0e0);
|
||||
}
|
||||
}
|
||||
|
||||
private int findClosingBracket(String str, char s, char e) {
|
||||
int found = 0;
|
||||
char[] chars = str.toCharArray();
|
||||
|
||||
for(int i = 0; i < chars.length; ++i) {
|
||||
char c = chars[i];
|
||||
if(c == s) {
|
||||
++found;
|
||||
} else if(c == e) {
|
||||
--found;
|
||||
if(found == 0) {
|
||||
return i;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
private int findOpeningBracket(String str, char s, char e) {
|
||||
int found = 0;
|
||||
char[] chars = str.toCharArray();
|
||||
|
||||
for(int i = chars.length - 1; i >= 0; --i) {
|
||||
char c = chars[i];
|
||||
if(c == e) {
|
||||
++found;
|
||||
} else if(c == s) {
|
||||
--found;
|
||||
if(found == 0) {
|
||||
return i - chars.length + 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
private int getSelectionPos(int xMouse, int yMouse) {
|
||||
xMouse -= this.x + 1;
|
||||
yMouse -= this.y + 1;
|
||||
ArrayList list = new ArrayList(this.container.lines);
|
||||
|
||||
for(int i = 0; i < list.size(); ++i) {
|
||||
LineData data = (LineData)list.get(i);
|
||||
if(i >= this.scrolledLine && i < this.scrolledLine + this.container.visibleLines) {
|
||||
int yPos = (i - this.scrolledLine) * this.container.lineHeight;
|
||||
if(yMouse >= yPos && yMouse < yPos + this.container.lineHeight) {
|
||||
int lineWidth = 0;
|
||||
char[] chars = data.text.toCharArray();
|
||||
|
||||
for(int j = 1; j <= chars.length; ++j) {
|
||||
int w = ClientProxy.Font.width(data.text.substring(0, j));
|
||||
if(xMouse < lineWidth + (w - lineWidth) / 2) {
|
||||
return data.start + j - 1;
|
||||
}
|
||||
|
||||
lineWidth = w;
|
||||
}
|
||||
|
||||
return data.end - 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return this.container.text.length();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean textboxKeyTyped(char c, int i) {
|
||||
if(!active)
|
||||
return false;
|
||||
|
||||
if(this.isKeyComboCtrlA(i)){
|
||||
startSelection = cursorPosition = 0;
|
||||
endSelection = text.length();
|
||||
return true;
|
||||
}
|
||||
|
||||
if(!isEnabled())
|
||||
return false;
|
||||
|
||||
String original = text;
|
||||
if(i == Keyboard.KEY_LEFT){
|
||||
int j = 1;
|
||||
if(isCtrlKeyDown()){
|
||||
Matcher m = container.regexWord.matcher(text.substring(0, cursorPosition));
|
||||
while(m.find()){
|
||||
if(m.start() == m.end())
|
||||
continue;
|
||||
j = cursorPosition - m.start();
|
||||
}
|
||||
}
|
||||
setCursor(cursorPosition - j, GuiScreen.isShiftKeyDown());
|
||||
return true;
|
||||
}
|
||||
if(i == Keyboard.KEY_RIGHT){
|
||||
int j = 1;
|
||||
if(isCtrlKeyDown()){
|
||||
Matcher m = container.regexWord.matcher(text.substring(cursorPosition));
|
||||
if(m.find() && m.start() > 0 || m.find()){
|
||||
j = m.start();
|
||||
}
|
||||
}
|
||||
setCursor(cursorPosition + j, GuiScreen.isShiftKeyDown());
|
||||
return true;
|
||||
}
|
||||
if(i == Keyboard.KEY_UP){
|
||||
setCursor(cursorUp(), GuiScreen.isShiftKeyDown());
|
||||
return true;
|
||||
}
|
||||
if(i == Keyboard.KEY_DOWN){
|
||||
setCursor(cursorDown(), GuiScreen.isShiftKeyDown());
|
||||
return true;
|
||||
}
|
||||
if(i == Keyboard.KEY_DELETE){
|
||||
String s = getSelectionAfterText();
|
||||
if(!s.isEmpty() && startSelection == endSelection)
|
||||
s = s.substring(1);
|
||||
setText(getSelectionBeforeText() + s);
|
||||
endSelection = cursorPosition = startSelection;
|
||||
return true;
|
||||
}
|
||||
if(i == Keyboard.KEY_BACK){
|
||||
String s = getSelectionBeforeText();
|
||||
if(startSelection > 0 && startSelection == endSelection){
|
||||
s = s.substring(0, s.length() - 1);
|
||||
startSelection--;
|
||||
}
|
||||
setText(s + getSelectionAfterText());
|
||||
endSelection = cursorPosition = startSelection;
|
||||
return true;
|
||||
}
|
||||
if(this.isKeyComboCtrlX(i)){
|
||||
if(startSelection != endSelection){
|
||||
NoppesStringUtils.setClipboardContents(text.substring(startSelection, endSelection));
|
||||
String s = getSelectionBeforeText();
|
||||
setText(s + getSelectionAfterText());
|
||||
endSelection = startSelection = cursorPosition = s.length();
|
||||
|
||||
}
|
||||
return true;
|
||||
}
|
||||
if(this.isKeyComboCtrlC(i)){
|
||||
if(startSelection != endSelection){
|
||||
NoppesStringUtils.setClipboardContents(text.substring(startSelection, endSelection));
|
||||
}
|
||||
return true;
|
||||
}
|
||||
if(this.isKeyComboCtrlV(i)){
|
||||
addText(NoppesStringUtils.getClipboardContents());
|
||||
return true;
|
||||
}
|
||||
if(i == Keyboard.KEY_Z && isCtrlKeyDown()){
|
||||
if(undoList.isEmpty())
|
||||
return false;
|
||||
undoing = true;
|
||||
redoList.add(new UndoData(this.text, this.cursorPosition));
|
||||
UndoData data = undoList.remove(undoList.size() - 1);
|
||||
setText(data.text);
|
||||
endSelection = startSelection = cursorPosition = data.cursorPosition;
|
||||
undoing = false;
|
||||
return true;
|
||||
}
|
||||
if(i == Keyboard.KEY_Y && isCtrlKeyDown()){
|
||||
if(redoList.isEmpty())
|
||||
return false;
|
||||
undoing = true;
|
||||
undoList.add(new UndoData(this.text, this.cursorPosition));
|
||||
UndoData data = redoList.remove(redoList.size() - 1);
|
||||
setText(data.text);
|
||||
endSelection = startSelection = cursorPosition = data.cursorPosition;
|
||||
undoing = false;
|
||||
return true;
|
||||
}
|
||||
if(i == Keyboard.KEY_TAB){
|
||||
addText(" ");
|
||||
}
|
||||
if(i == Keyboard.KEY_RETURN){
|
||||
addText(Character.toString('\n') + getIndentCurrentLine());
|
||||
}
|
||||
if(ChatAllowedCharacters.isAllowedCharacter(c)){
|
||||
addText(Character.toString(c));
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private boolean isShiftKeyDown()
|
||||
{
|
||||
return Keyboard.isKeyDown(42) || Keyboard.isKeyDown(54);
|
||||
}
|
||||
|
||||
private boolean isAltKeyDown()
|
||||
{
|
||||
return Keyboard.isKeyDown(56) || Keyboard.isKeyDown(184);
|
||||
}
|
||||
|
||||
private boolean isKeyComboCtrlX(int keyID)
|
||||
{
|
||||
return keyID == 45 && isCtrlKeyDown() && !isShiftKeyDown() && !isAltKeyDown();
|
||||
}
|
||||
|
||||
private boolean isKeyComboCtrlV(int keyID)
|
||||
{
|
||||
return keyID == 47 && isCtrlKeyDown() && !isShiftKeyDown() && !isAltKeyDown();
|
||||
}
|
||||
|
||||
private boolean isKeyComboCtrlC(int keyID)
|
||||
{
|
||||
return keyID == 46 && isCtrlKeyDown() && !isShiftKeyDown() && !isAltKeyDown();
|
||||
}
|
||||
|
||||
private boolean isKeyComboCtrlA(int keyID)
|
||||
{
|
||||
return keyID == 30 && isCtrlKeyDown() && !isShiftKeyDown() && !isAltKeyDown();
|
||||
}
|
||||
|
||||
private String getIndentCurrentLine() {
|
||||
Iterator var1 = this.container.lines.iterator();
|
||||
|
||||
LineData data;
|
||||
do {
|
||||
if(!var1.hasNext()) {
|
||||
return "";
|
||||
}
|
||||
|
||||
data = (LineData)var1.next();
|
||||
} while(this.cursorPosition <= data.start || this.cursorPosition > data.end);
|
||||
|
||||
int i;
|
||||
for(i = 0; i < data.text.length() && data.text.charAt(i) == 32; ++i) {
|
||||
;
|
||||
}
|
||||
|
||||
return data.text.substring(0, i);
|
||||
}
|
||||
|
||||
private void setCursor(int i, boolean select) {
|
||||
i = Math.min(Math.max(i, 0), this.text.length());
|
||||
if(i != this.cursorPosition) {
|
||||
if(!select) {
|
||||
this.endSelection = this.startSelection = this.cursorPosition = i;
|
||||
} else {
|
||||
int diff = this.cursorPosition - i;
|
||||
if(this.cursorPosition == this.startSelection) {
|
||||
this.startSelection -= diff;
|
||||
} else if(this.cursorPosition == this.endSelection) {
|
||||
this.endSelection -= diff;
|
||||
}
|
||||
|
||||
if(this.startSelection > this.endSelection) {
|
||||
int j = this.endSelection;
|
||||
this.endSelection = this.startSelection;
|
||||
this.startSelection = j;
|
||||
}
|
||||
|
||||
this.cursorPosition = i;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void addText(String s) {
|
||||
this.setText(this.getSelectionBeforeText() + s + this.getSelectionAfterText());
|
||||
this.endSelection = this.startSelection = this.cursorPosition = this.startSelection + s.length();
|
||||
}
|
||||
|
||||
private int cursorUp() {
|
||||
for(int i = 0; i < this.container.lines.size(); ++i) {
|
||||
LineData data = (LineData)this.container.lines.get(i);
|
||||
if(this.cursorPosition >= data.start && this.cursorPosition < data.end) {
|
||||
if(i == 0) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
int var10000 = this.cursorPosition - data.start;
|
||||
return this.getSelectionPos(this.x + 1 + ClientProxy.Font.width(data.text.substring(0, this.cursorPosition - data.start)), this.y + 1 + (i - 1 - this.scrolledLine) * this.container.lineHeight);
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
private int cursorDown() {
|
||||
for(int i = 0; i < this.container.lines.size(); ++i) {
|
||||
LineData data = (LineData)this.container.lines.get(i);
|
||||
if(this.cursorPosition >= data.start && this.cursorPosition < data.end) {
|
||||
int var10000 = this.cursorPosition - data.start;
|
||||
return this.getSelectionPos(this.x + 1 + ClientProxy.Font.width(data.text.substring(0, this.cursorPosition - data.start)), this.y + 1 + (i + 1 - this.scrolledLine) * this.container.lineHeight);
|
||||
}
|
||||
}
|
||||
|
||||
return this.text.length();
|
||||
}
|
||||
|
||||
public String getSelectionBeforeText() {
|
||||
return this.startSelection == 0?"":this.text.substring(0, this.startSelection);
|
||||
}
|
||||
|
||||
public String getSelectionAfterText() {
|
||||
return this.text.substring(this.endSelection);
|
||||
}
|
||||
|
||||
public void mouseClicked(int xMouse, int yMouse, int mouseButton) {
|
||||
this.active = xMouse >= this.x && xMouse < this.x + this.width && yMouse >= this.y && yMouse < this.y + this.height;
|
||||
if(this.active) {
|
||||
this.startSelection = this.endSelection = this.cursorPosition = this.getSelectionPos(xMouse, yMouse);
|
||||
this.clicked = mouseButton == 0;
|
||||
this.doubleClicked = false;
|
||||
long time = System.currentTimeMillis();
|
||||
if(this.clicked && this.container.linesCount * this.container.lineHeight > this.height && xMouse > this.x + this.width - 8) {
|
||||
this.clicked = false;
|
||||
this.clickScrolling = true;
|
||||
} else if(time - this.lastClicked < 500L) {
|
||||
this.doubleClicked = true;
|
||||
Matcher m = this.container.regexWord.matcher(this.text);
|
||||
|
||||
while(m.find()) {
|
||||
if(this.cursorPosition > m.start() && this.cursorPosition < m.end()) {
|
||||
this.startSelection = m.start();
|
||||
this.endSelection = m.end();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
this.lastClicked = time;
|
||||
activeTextfield = this;
|
||||
}
|
||||
}
|
||||
|
||||
public void updateCursorCounter() {
|
||||
++this.cursorCounter;
|
||||
int k2 = Mouse.getDWheel();
|
||||
if(k2 != 0) {
|
||||
this.scrolledLine += k2 > 0?-1:1;
|
||||
this.scrolledLine = Math.max(Math.min(this.scrolledLine, this.container.linesCount - this.height / this.container.lineHeight), 0);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void setText(String text) {
|
||||
if (text == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
text = text.replace("\r", "");
|
||||
text = text.replace("\t", " ");
|
||||
if(this.text == null || !this.text.equals(text)) {
|
||||
if(this.listener != null) {
|
||||
this.listener.textUpdate(text);
|
||||
}
|
||||
|
||||
if(!this.undoing) {
|
||||
this.undoList.add(new GuiScriptTextArea.UndoData(this.text, this.cursorPosition));
|
||||
this.redoList.clear();
|
||||
}
|
||||
|
||||
this.text = text;
|
||||
this.container = new TextContainer(text);
|
||||
this.container.init(this.width, this.height);
|
||||
if(this.enableCodeHighlighting) {
|
||||
this.container.formatCodeText();
|
||||
}
|
||||
|
||||
if(this.scrolledLine > this.container.linesCount - this.container.visibleLines) {
|
||||
this.scrolledLine = Math.max(0, this.container.linesCount - this.container.visibleLines);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public String getText() {
|
||||
return this.text;
|
||||
}
|
||||
|
||||
public boolean isEnabled() {
|
||||
return this.enabled && this.visible;
|
||||
}
|
||||
|
||||
public boolean hasVerticalScrollbar() {
|
||||
return this.container.visibleLines < this.container.linesCount;
|
||||
}
|
||||
|
||||
public void enableCodeHighlighting() {
|
||||
this.enableCodeHighlighting = true;
|
||||
this.container.formatCodeText();
|
||||
}
|
||||
|
||||
public void setListener(ITextChangeListener listener) {
|
||||
this.listener = listener;
|
||||
}
|
||||
|
||||
class UndoData {
|
||||
public String text;
|
||||
public int cursorPosition;
|
||||
|
||||
public UndoData(String text, int cursorPosition) {
|
||||
this.text = text;
|
||||
this.cursorPosition = cursorPosition;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,469 +0,0 @@
|
||||
//
|
||||
// Source code recreated from a .class file by IntelliJ IDEA
|
||||
// (powered by Fernflower decompiler)
|
||||
//
|
||||
|
||||
package noppes.npcs.client.gui.util;
|
||||
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.gui.Gui;
|
||||
import net.minecraft.util.ChatAllowedCharacters;
|
||||
import noppes.npcs.client.gui.util.TextContainer.LineData;
|
||||
import noppes.npcs.config.ConfigClient;
|
||||
import noppes.npcs.config.TrueTypeFont;
|
||||
import org.lwjgl.input.Mouse;
|
||||
|
||||
import java.awt.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.regex.Matcher;
|
||||
|
||||
public class GuiTextArea extends Gui implements IGui, IKeyListener, IMouseListener {
|
||||
public int id;
|
||||
public int x;
|
||||
public int y;
|
||||
public int width;
|
||||
public int height;
|
||||
private int cursorCounter;
|
||||
private ITextChangeListener listener;
|
||||
private static TrueTypeFont font;
|
||||
public String text = null;
|
||||
private TextContainer container = null;
|
||||
public boolean active = false;
|
||||
public boolean enabled = true;
|
||||
public boolean visible = true;
|
||||
public boolean clicked = false;
|
||||
public boolean doubleClicked = false;
|
||||
public boolean clickScrolling = false;
|
||||
private int startSelection;
|
||||
private int endSelection;
|
||||
private int cursorPosition;
|
||||
private int scrolledLine = 0;
|
||||
private boolean enableCodeHighlighting = false;
|
||||
private static final char colorChar = '\uffff';
|
||||
public List<GuiTextArea.UndoData> undoList = new ArrayList();
|
||||
public List<GuiTextArea.UndoData> redoList = new ArrayList();
|
||||
public boolean undoing = false;
|
||||
private long lastClicked = 0L;
|
||||
|
||||
public GuiTextArea(int id, int x, int y, int width, int height, String text) {
|
||||
this.id = id;
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
this.width = width;
|
||||
this.height = height;
|
||||
this.undoing = true;
|
||||
this.setText(text);
|
||||
this.undoing = false;
|
||||
font.setSpecial('\uffff');
|
||||
}
|
||||
|
||||
public void drawScreen(int xMouse, int yMouse) {
|
||||
if(this.visible) {
|
||||
drawRect(this.x - 1, this.y - 1, this.x + this.width + 1, this.y + this.height + 1, -6250336);
|
||||
drawRect(this.x, this.y, this.x + this.width, this.y + this.height, -16777216);
|
||||
this.container.visibleLines = this.height / this.container.lineHeight;
|
||||
int startBracket;
|
||||
if(this.clicked) {
|
||||
this.clicked = Mouse.isButtonDown(0);
|
||||
startBracket = this.getSelectionPos(xMouse, yMouse);
|
||||
if(startBracket != this.cursorPosition) {
|
||||
if(this.doubleClicked) {
|
||||
this.startSelection = this.endSelection = this.cursorPosition;
|
||||
this.doubleClicked = false;
|
||||
}
|
||||
|
||||
this.setCursor(startBracket, true);
|
||||
}
|
||||
} else if(this.doubleClicked) {
|
||||
this.doubleClicked = false;
|
||||
}
|
||||
|
||||
if(this.clickScrolling) {
|
||||
this.clickScrolling = Mouse.isButtonDown(0);
|
||||
startBracket = this.container.linesCount - this.container.visibleLines;
|
||||
this.scrolledLine = Math.min(Math.max((int)(1.0F * (float)startBracket * (float)(yMouse - this.y) / (float)this.height), 0), startBracket);
|
||||
}
|
||||
|
||||
startBracket = 0;
|
||||
int endBracket = 0;
|
||||
if(this.endSelection - this.startSelection == 1 || this.startSelection == this.endSelection && this.startSelection < this.text.length()) {
|
||||
char list = this.text.charAt(this.startSelection);
|
||||
int wordHightLight = 0;
|
||||
if(list == 123) {
|
||||
wordHightLight = this.findClosingBracket(this.text.substring(this.startSelection), '{', '}');
|
||||
} else if(list == 91) {
|
||||
wordHightLight = this.findClosingBracket(this.text.substring(this.startSelection), '[', ']');
|
||||
} else if(list == 40) {
|
||||
wordHightLight = this.findClosingBracket(this.text.substring(this.startSelection), '(', ')');
|
||||
} else if(list == 125) {
|
||||
wordHightLight = this.findOpeningBracket(this.text.substring(0, this.startSelection + 1), '{', '}');
|
||||
} else if(list == 93) {
|
||||
wordHightLight = this.findOpeningBracket(this.text.substring(0, this.startSelection + 1), '[', ']');
|
||||
} else if(list == 41) {
|
||||
wordHightLight = this.findOpeningBracket(this.text.substring(0, this.startSelection + 1), '(', ')');
|
||||
}
|
||||
|
||||
if(wordHightLight != 0) {
|
||||
startBracket = this.startSelection;
|
||||
endBracket = this.startSelection + wordHightLight;
|
||||
}
|
||||
}
|
||||
|
||||
ArrayList var15 = new ArrayList(this.container.lines);
|
||||
String var18 = null;
|
||||
if(this.startSelection != this.endSelection) {
|
||||
Matcher sbSize = this.container.regexWord.matcher(this.text);
|
||||
|
||||
while(sbSize.find()) {
|
||||
if(sbSize.start() == this.startSelection && sbSize.end() == this.endSelection) {
|
||||
var18 = this.text.substring(this.startSelection, this.endSelection);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int var16;
|
||||
for(var16 = 0; var16 < var15.size(); ++var16) {
|
||||
LineData posX = (LineData)var15.get(var16);
|
||||
String posY = posX.text;
|
||||
int w = posY.length();
|
||||
int yPos;
|
||||
int posX1;
|
||||
int posY1;
|
||||
if(startBracket != endBracket) {
|
||||
if(startBracket >= posX.start && startBracket < posX.end) {
|
||||
yPos = font.width(posY.substring(0, startBracket - posX.start));
|
||||
posX1 = font.width(posY.substring(0, startBracket - posX.start + 1)) + 1;
|
||||
posY1 = this.y + 1 + (var16 - this.scrolledLine) * this.container.lineHeight;
|
||||
drawRect(this.x + 1 + yPos, posY1, this.x + 1 + posX1, posY1 + this.container.lineHeight + 1, -1728001024);
|
||||
}
|
||||
|
||||
if(endBracket >= posX.start && endBracket < posX.end) {
|
||||
yPos = font.width(posY.substring(0, endBracket - posX.start));
|
||||
posX1 = font.width(posY.substring(0, endBracket - posX.start + 1)) + 1;
|
||||
posY1 = this.y + 1 + (var16 - this.scrolledLine) * this.container.lineHeight;
|
||||
drawRect(this.x + 1 + yPos, posY1, this.x + 1 + posX1, posY1 + this.container.lineHeight + 1, -1728001024);
|
||||
}
|
||||
}
|
||||
|
||||
if(var16 >= this.scrolledLine && var16 < this.scrolledLine + this.container.visibleLines) {
|
||||
if(var18 != null) {
|
||||
Matcher var20 = this.container.regexWord.matcher(posY);
|
||||
|
||||
while(var20.find()) {
|
||||
if(posY.substring(var20.start(), var20.end()).equals(var18)) {
|
||||
posX1 = font.width(posY.substring(0, var20.start()));
|
||||
posY1 = font.width(posY.substring(0, var20.end())) + 1;
|
||||
int posY2 = this.y + 1 + (var16 - this.scrolledLine) * this.container.lineHeight;
|
||||
drawRect(this.x + 1 + posX1, posY2, this.x + 1 + posY1, posY2 + this.container.lineHeight + 1, -1728033792);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(this.startSelection != this.endSelection && this.endSelection > posX.start && this.startSelection <= posX.end && this.startSelection < posX.end) {
|
||||
yPos = font.width(posY.substring(0, Math.max(this.startSelection - posX.start, 0)));
|
||||
posX1 = font.width(posY.substring(0, Math.min(this.endSelection - posX.start, w))) + 1;
|
||||
posY1 = this.y + 1 + (var16 - this.scrolledLine) * this.container.lineHeight;
|
||||
drawRect(this.x + 1 + yPos, posY1, this.x + 1 + posX1, posY1 + this.container.lineHeight + 1, -1728052993);
|
||||
}
|
||||
|
||||
yPos = this.y + (var16 - this.scrolledLine) * this.container.lineHeight + 1;
|
||||
font.draw(posX.getFormattedString(), (float)(this.x + 1), (float)yPos, -2039584);
|
||||
if(this.active && this.isEnabled() && this.cursorCounter / 6 % 2 == 0 && this.cursorPosition >= posX.start && this.cursorPosition < posX.end) {
|
||||
posX1 = this.x + font.width(posY.substring(0, this.cursorPosition - posX.start));
|
||||
drawRect(posX1 + 1, yPos, posX1 + 2, yPos + 1 + this.container.lineHeight, -3092272);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(this.hasVerticalScrollbar()) {
|
||||
Minecraft.getMinecraft().renderEngine.bindTexture(GuiCustomScroll.resource);
|
||||
|
||||
var16 = Math.max((int)(1.0F * (float)this.container.visibleLines / (float)this.container.linesCount * (float)this.height), 2);
|
||||
int var17 = this.x + this.width - 6;
|
||||
int var19 = (int)((float)this.y + 1.0F * (float)this.scrolledLine / (float)this.container.linesCount * (float)(this.height - 4)) + 1;
|
||||
drawRect(var17, var19, var17 + 5, var19 + var16, -2039584);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
private int findClosingBracket(String str, char s, char e) {
|
||||
int found = 0;
|
||||
char[] chars = str.toCharArray();
|
||||
|
||||
for(int i = 0; i < chars.length; ++i) {
|
||||
char c = chars[i];
|
||||
if(c == s) {
|
||||
++found;
|
||||
} else if(c == e) {
|
||||
--found;
|
||||
if(found == 0) {
|
||||
return i;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
private int findOpeningBracket(String str, char s, char e) {
|
||||
int found = 0;
|
||||
char[] chars = str.toCharArray();
|
||||
|
||||
for(int i = chars.length - 1; i >= 0; --i) {
|
||||
char c = chars[i];
|
||||
if(c == e) {
|
||||
++found;
|
||||
} else if(c == s) {
|
||||
--found;
|
||||
if(found == 0) {
|
||||
return i - chars.length + 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
private int getSelectionPos(int xMouse, int yMouse) {
|
||||
xMouse -= this.x + 1;
|
||||
yMouse -= this.y + 1;
|
||||
ArrayList list = new ArrayList(this.container.lines);
|
||||
|
||||
for(int i = 0; i < list.size(); ++i) {
|
||||
LineData data = (LineData)list.get(i);
|
||||
if(i >= this.scrolledLine && i < this.scrolledLine + this.container.visibleLines) {
|
||||
int yPos = (i - this.scrolledLine) * this.container.lineHeight;
|
||||
if(yMouse >= yPos && yMouse < yPos + this.container.lineHeight) {
|
||||
int lineWidth = 0;
|
||||
char[] chars = data.text.toCharArray();
|
||||
|
||||
for(int j = 1; j <= chars.length; ++j) {
|
||||
int w = font.width(data.text.substring(0, j));
|
||||
if(xMouse < lineWidth + (w - lineWidth) / 2) {
|
||||
return data.start + j - 1;
|
||||
}
|
||||
|
||||
lineWidth = w;
|
||||
}
|
||||
|
||||
return data.end - 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return this.container.text.length();
|
||||
}
|
||||
|
||||
public int getID() {
|
||||
return this.id;
|
||||
}
|
||||
|
||||
|
||||
public void keyTyped(char c, int i) {
|
||||
if(this.active && this.isEnabled()) {
|
||||
if(i == 15) {
|
||||
this.addText(" ");
|
||||
}
|
||||
|
||||
if(i == 28) {
|
||||
this.addText(Character.toString('\n') + this.getIndentCurrentLine());
|
||||
}
|
||||
|
||||
if(ChatAllowedCharacters.isAllowedCharacter(c)) {
|
||||
this.addText(Character.toString(c));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private String getIndentCurrentLine() {
|
||||
Iterator var1 = this.container.lines.iterator();
|
||||
|
||||
LineData data;
|
||||
do {
|
||||
if(!var1.hasNext()) {
|
||||
return "";
|
||||
}
|
||||
|
||||
data = (LineData)var1.next();
|
||||
} while(this.cursorPosition <= data.start || this.cursorPosition > data.end);
|
||||
|
||||
int i;
|
||||
for(i = 0; i < data.text.length() && data.text.charAt(i) == 32; ++i) {
|
||||
;
|
||||
}
|
||||
|
||||
return data.text.substring(0, i);
|
||||
}
|
||||
|
||||
private void setCursor(int i, boolean select) {
|
||||
i = Math.min(Math.max(i, 0), this.text.length());
|
||||
if(i != this.cursorPosition) {
|
||||
if(!select) {
|
||||
this.endSelection = this.startSelection = this.cursorPosition = i;
|
||||
} else {
|
||||
int diff = this.cursorPosition - i;
|
||||
if(this.cursorPosition == this.startSelection) {
|
||||
this.startSelection -= diff;
|
||||
} else if(this.cursorPosition == this.endSelection) {
|
||||
this.endSelection -= diff;
|
||||
}
|
||||
|
||||
if(this.startSelection > this.endSelection) {
|
||||
int j = this.endSelection;
|
||||
this.endSelection = this.startSelection;
|
||||
this.startSelection = j;
|
||||
}
|
||||
|
||||
this.cursorPosition = i;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void addText(String s) {
|
||||
this.setText(this.getSelectionBeforeText() + s + this.getSelectionAfterText());
|
||||
this.endSelection = this.startSelection = this.cursorPosition = this.startSelection + s.length();
|
||||
}
|
||||
|
||||
private int cursorUp() {
|
||||
for(int i = 0; i < this.container.lines.size(); ++i) {
|
||||
LineData data = (LineData)this.container.lines.get(i);
|
||||
if(this.cursorPosition >= data.start && this.cursorPosition < data.end) {
|
||||
if(i == 0) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
int var10000 = this.cursorPosition - data.start;
|
||||
return this.getSelectionPos(this.x + 1 + font.width(data.text.substring(0, this.cursorPosition - data.start)), this.y + 1 + (i - 1 - this.scrolledLine) * this.container.lineHeight);
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
private int cursorDown() {
|
||||
for(int i = 0; i < this.container.lines.size(); ++i) {
|
||||
LineData data = (LineData)this.container.lines.get(i);
|
||||
if(this.cursorPosition >= data.start && this.cursorPosition < data.end) {
|
||||
int var10000 = this.cursorPosition - data.start;
|
||||
return this.getSelectionPos(this.x + 1 + font.width(data.text.substring(0, this.cursorPosition - data.start)), this.y + 1 + (i + 1 - this.scrolledLine) * this.container.lineHeight);
|
||||
}
|
||||
}
|
||||
|
||||
return this.text.length();
|
||||
}
|
||||
|
||||
public String getSelectionBeforeText() {
|
||||
return this.startSelection == 0?"":this.text.substring(0, this.startSelection);
|
||||
}
|
||||
|
||||
public String getSelectionAfterText() {
|
||||
return this.text.substring(this.endSelection);
|
||||
}
|
||||
|
||||
public boolean mouseClicked(int xMouse, int yMouse, int mouseButton) {
|
||||
this.active = xMouse >= this.x && xMouse < this.x + this.width && yMouse >= this.y && yMouse < this.y + this.height;
|
||||
if(this.active) {
|
||||
this.startSelection = this.endSelection = this.cursorPosition = this.getSelectionPos(xMouse, yMouse);
|
||||
this.clicked = mouseButton == 0;
|
||||
this.doubleClicked = false;
|
||||
long time = System.currentTimeMillis();
|
||||
if(this.clicked && this.container.linesCount * this.container.lineHeight > this.height && xMouse > this.x + this.width - 8) {
|
||||
this.clicked = false;
|
||||
this.clickScrolling = true;
|
||||
} else if(time - this.lastClicked < 500L) {
|
||||
this.doubleClicked = true;
|
||||
Matcher m = this.container.regexWord.matcher(this.text);
|
||||
|
||||
while(m.find()) {
|
||||
if(this.cursorPosition > m.start() && this.cursorPosition < m.end()) {
|
||||
this.startSelection = m.start();
|
||||
this.endSelection = m.end();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
this.lastClicked = time;
|
||||
}
|
||||
|
||||
return this.active;
|
||||
}
|
||||
|
||||
public void updateScreen() {
|
||||
++this.cursorCounter;
|
||||
int k2 = Mouse.getDWheel();
|
||||
if(k2 != 0) {
|
||||
this.scrolledLine += k2 > 0?-1:1;
|
||||
this.scrolledLine = Math.max(Math.min(this.scrolledLine, this.container.linesCount - this.height / this.container.lineHeight), 0);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void setText(String text) {
|
||||
text = text.replace("\r", "");
|
||||
if(this.text == null || !this.text.equals(text)) {
|
||||
if(this.listener != null) {
|
||||
this.listener.textUpdate(text);
|
||||
}
|
||||
|
||||
if(!this.undoing) {
|
||||
this.undoList.add(new GuiTextArea.UndoData(this.text, this.cursorPosition));
|
||||
this.redoList.clear();
|
||||
}
|
||||
|
||||
this.text = text;
|
||||
this.container = new TextContainer(text);
|
||||
this.container.init(font, this.width, this.height);
|
||||
if(this.enableCodeHighlighting) {
|
||||
this.container.formatCodeText();
|
||||
}
|
||||
|
||||
if(this.scrolledLine > this.container.linesCount - this.container.visibleLines) {
|
||||
this.scrolledLine = Math.max(0, this.container.linesCount - this.container.visibleLines);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public String getText() {
|
||||
return this.text;
|
||||
}
|
||||
|
||||
public boolean isEnabled() {
|
||||
return this.enabled && this.visible;
|
||||
}
|
||||
|
||||
public boolean hasVerticalScrollbar() {
|
||||
return this.container.visibleLines < this.container.linesCount;
|
||||
}
|
||||
|
||||
public void enableCodeHighlighting() {
|
||||
this.enableCodeHighlighting = true;
|
||||
this.container.formatCodeText();
|
||||
}
|
||||
|
||||
public void setListener(ITextChangeListener listener) {
|
||||
this.listener = listener;
|
||||
}
|
||||
|
||||
public boolean isActive() {
|
||||
return this.active;
|
||||
}
|
||||
|
||||
static {
|
||||
font = new TrueTypeFont(new Font("Arial Unicode MS", 0, ConfigClient.FontSize), 1.0F);
|
||||
}
|
||||
|
||||
class UndoData {
|
||||
public String text;
|
||||
public int cursorPosition;
|
||||
|
||||
public UndoData(String text, int cursorPosition) {
|
||||
this.text = text;
|
||||
this.cursorPosition = cursorPosition;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,16 +0,0 @@
|
||||
//
|
||||
// Source code recreated from a .class file by IntelliJ IDEA
|
||||
// (powered by Fernflower decompiler)
|
||||
//
|
||||
|
||||
package noppes.npcs.client.gui.util;
|
||||
|
||||
public interface IGui {
|
||||
int getID();
|
||||
|
||||
void drawScreen(int var1, int var2);
|
||||
|
||||
void updateScreen();
|
||||
|
||||
boolean isActive();
|
||||
}
|
||||
@@ -1,10 +0,0 @@
|
||||
//
|
||||
// Source code recreated from a .class file by IntelliJ IDEA
|
||||
// (powered by Fernflower decompiler)
|
||||
//
|
||||
|
||||
package noppes.npcs.client.gui.util;
|
||||
|
||||
public interface IKeyListener {
|
||||
void keyTyped(char var1, int var2);
|
||||
}
|
||||
@@ -1,10 +0,0 @@
|
||||
//
|
||||
// Source code recreated from a .class file by IntelliJ IDEA
|
||||
// (powered by Fernflower decompiler)
|
||||
//
|
||||
|
||||
package noppes.npcs.client.gui.util;
|
||||
|
||||
public interface IMouseListener {
|
||||
boolean mouseClicked(int var1, int var2, int var3);
|
||||
}
|
||||
@@ -1,119 +1,104 @@
|
||||
//
|
||||
// Source code recreated from a .class file by IntelliJ IDEA
|
||||
// (powered by Fernflower decompiler)
|
||||
//
|
||||
|
||||
package noppes.npcs.client.gui.util;
|
||||
|
||||
import noppes.npcs.config.TrueTypeFont;
|
||||
import noppes.npcs.client.ClientProxy;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Comparator;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
public class TextContainer {
|
||||
private static final char colorChar = '\uffff';
|
||||
private static final Comparator<TextContainer.MarkUp> MarkUpComparator = (o1, o2) -> {
|
||||
return o1.start > o2.start?1:(o1.start < o2.start?-1:0);
|
||||
};
|
||||
public final Pattern regexString = Pattern.compile("([\"\'])(?:(?=(\\\\?))\\2.)*?\\1", 8);
|
||||
private final static char colorChar = '\u00A7';
|
||||
|
||||
//public final Pattern regexString = Pattern.compile("\"(?:[^\"\\\\]|\\\\.)*?(\"|$)|'(?:[^'\\\\]|\\\\.)*?('|$)");
|
||||
//public final Pattern regexString = Pattern.compile("\"(.*?(?<![\\\\])(\\s)*?)*?\"");
|
||||
public final Pattern regexString = Pattern.compile("([\"'])(?:(?=(\\\\?))\\2.)*?\\1", Pattern.MULTILINE);
|
||||
public final Pattern regexFunction = Pattern.compile("\\b(if|else|switch|with|for|while|in|var|const|let|throw|then|function|continue|break|foreach|return|try|catch|finally|do|this|typeof|instanceof|new)(?=[^\\w])");
|
||||
public final Pattern regexWord = Pattern.compile("[\\p{L}-]+|\\n|$");
|
||||
public final Pattern regexNumber = Pattern.compile("\\b-?(?:0[xX][\\dA-Fa-f]+|0[bB][01]+|0[oO][0-7]+|\\d*\\.?\\d+(?:[Ee][+-]?\\d+)?(?:[fFbBdDlLsS])?|NaN|null|Infinity|unidentified|true|false)\\b");
|
||||
public final Pattern regexComment = Pattern.compile("\\/\\*[\\s\\S]*?(?:\\*\\/|$)|\\/\\/.*|#.*");
|
||||
|
||||
public String text;
|
||||
public List<TextContainer.MarkUp> makeup = new ArrayList();
|
||||
public List<TextContainer.LineData> lines = new ArrayList();
|
||||
private TrueTypeFont font;
|
||||
|
||||
public List<MarkUp> makeup = new ArrayList<MarkUp>();
|
||||
public List<LineData> lines = new ArrayList<LineData>();
|
||||
|
||||
public int lineHeight;
|
||||
public int totalHeight;
|
||||
public int visibleLines = 1;
|
||||
public int linesCount;
|
||||
|
||||
public TextContainer(String text) {
|
||||
|
||||
public TextContainer(String text){
|
||||
this.text = text;
|
||||
text.replaceAll("\\r?\\n|\\r", "\n");
|
||||
double l = 1.0D;
|
||||
double l = 1d;
|
||||
}
|
||||
|
||||
public void init(TrueTypeFont font, int width, int height) {
|
||||
this.font = font;
|
||||
this.lineHeight = font.height(this.text);
|
||||
if(this.lineHeight == 0) {
|
||||
this.lineHeight = 12;
|
||||
}
|
||||
public void init(int width, int height){
|
||||
lineHeight = ClientProxy.Font.height();
|
||||
if(lineHeight == 0)
|
||||
lineHeight = 12;
|
||||
String[] split = text.split("\n");
|
||||
|
||||
String[] split = this.text.split("\n");
|
||||
int totalChars = 0;
|
||||
String[] var6 = split;
|
||||
int var7 = split.length;
|
||||
|
||||
for(int var8 = 0; var8 < var7; ++var8) {
|
||||
String l = var6[var8];
|
||||
for(String l : split){
|
||||
StringBuilder line = new StringBuilder();
|
||||
Matcher m = this.regexWord.matcher(l);
|
||||
|
||||
for(int i = 0; m.find(); i = m.start()) {
|
||||
Matcher m = regexWord.matcher(l);
|
||||
int i = 0;
|
||||
while(m.find()){
|
||||
String word = l.substring(i, m.start());
|
||||
if(font.width(line + word) > width - 10) {
|
||||
this.lines.add(new TextContainer.LineData(line.toString(), totalChars, totalChars + line.length()));
|
||||
if(ClientProxy.Font.width(line + word) > width - 10){
|
||||
lines.add(new LineData(line.toString(), totalChars, totalChars + line.length()));
|
||||
totalChars += line.length();
|
||||
line = new StringBuilder();
|
||||
}
|
||||
|
||||
line.append(word);
|
||||
i = m.start();
|
||||
}
|
||||
lines.add(new LineData(line.toString(), totalChars, totalChars + line.length() + 1));
|
||||
|
||||
this.lines.add(new TextContainer.LineData(line.toString(), totalChars, totalChars + line.length() + 1));
|
||||
totalChars += line.length() + 1;
|
||||
}
|
||||
|
||||
this.linesCount = this.lines.size();
|
||||
this.totalHeight = this.linesCount * this.lineHeight;
|
||||
this.visibleLines = Math.max(height / this.lineHeight, 1);
|
||||
linesCount = lines.size();
|
||||
totalHeight = linesCount * lineHeight;
|
||||
visibleLines = Math.max(height / lineHeight, 1);
|
||||
}
|
||||
|
||||
public void formatCodeText() {
|
||||
TextContainer.MarkUp markup = null;
|
||||
|
||||
for(int start = 0; (markup = this.getNextMatching(start)) != null; start = markup.end) {
|
||||
this.makeup.add(markup);
|
||||
MarkUp markup = null;
|
||||
int start = 0;
|
||||
while((markup = getNextMatching(start)) != null) {
|
||||
makeup.add(markup);
|
||||
start = markup.end;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private TextContainer.MarkUp getNextMatching(int start) {
|
||||
TextContainer.MarkUp markup = null;
|
||||
String s = this.text.substring(start);
|
||||
Matcher matcher = this.regexNumber.matcher(s);
|
||||
private MarkUp getNextMatching(int start) {
|
||||
MarkUp markup = null;
|
||||
String s = text.substring(start);
|
||||
Matcher matcher = regexNumber.matcher(s);
|
||||
if(matcher.find()) {
|
||||
markup = new TextContainer.MarkUp(matcher.start(), matcher.end(), '6', 0);
|
||||
markup = new MarkUp(matcher.start(), matcher.end(), '6', 0);
|
||||
}
|
||||
|
||||
matcher = this.regexFunction.matcher(s);
|
||||
TextContainer.MarkUp markup2;
|
||||
if(matcher.find()) {
|
||||
markup2 = new TextContainer.MarkUp(matcher.start(), matcher.end(), '2', 0);
|
||||
if(this.compareMarkUps(markup, markup2)) {
|
||||
matcher = regexFunction.matcher(s);
|
||||
if(matcher.find()){
|
||||
MarkUp markup2 = new MarkUp(matcher.start(), matcher.end(), '2', 0);
|
||||
if(compareMarkUps(markup, markup2)) {
|
||||
markup = markup2;
|
||||
}
|
||||
}
|
||||
|
||||
matcher = this.regexString.matcher(s);
|
||||
if(matcher.find()) {
|
||||
markup2 = new TextContainer.MarkUp(matcher.start(), matcher.end(), '4', 7);
|
||||
if(this.compareMarkUps(markup, markup2)) {
|
||||
matcher = regexString.matcher(s);
|
||||
if(matcher.find()){
|
||||
MarkUp markup2 = new MarkUp(matcher.start(), matcher.end(), '4', 7);
|
||||
if(compareMarkUps(markup, markup2)) {
|
||||
markup = markup2;
|
||||
}
|
||||
}
|
||||
|
||||
matcher = this.regexComment.matcher(s);
|
||||
if(matcher.find()) {
|
||||
markup2 = new TextContainer.MarkUp(matcher.start(), matcher.end(), '8', 7);
|
||||
if(this.compareMarkUps(markup, markup2)) {
|
||||
matcher = regexComment.matcher(s);
|
||||
if(matcher.find()){
|
||||
MarkUp markup2 = new MarkUp(matcher.start(), matcher.end(), '8', 7);
|
||||
if(compareMarkUps(markup, markup2)) {
|
||||
markup = markup2;
|
||||
}
|
||||
}
|
||||
@@ -122,105 +107,78 @@ public class TextContainer {
|
||||
markup.start += start;
|
||||
markup.end += start;
|
||||
}
|
||||
|
||||
return markup;
|
||||
}
|
||||
|
||||
public boolean compareMarkUps(TextContainer.MarkUp mu1, TextContainer.MarkUp mu2) {
|
||||
return mu1 == null?true:mu1.start > mu2.start;
|
||||
public boolean compareMarkUps(MarkUp mu1, MarkUp mu2) {
|
||||
if(mu1 == null)
|
||||
return true;
|
||||
return mu1.start > mu2.start;
|
||||
}
|
||||
|
||||
public void addMakeUp(int start, int end, char c, int level) {
|
||||
if(this.removeConflictingMarkUp(start, end, level)) {
|
||||
this.makeup.add(new TextContainer.MarkUp(start, end, c, level));
|
||||
}
|
||||
public void addMakeUp(int start, int end, char c, int level){
|
||||
if(!removeConflictingMarkUp(start, end, level))
|
||||
return;
|
||||
makeup.add(new MarkUp(start, end, c, level));
|
||||
}
|
||||
|
||||
private boolean removeConflictingMarkUp(int start, int end, int level) {
|
||||
ArrayList conflicting = new ArrayList();
|
||||
Iterator var5 = this.makeup.iterator();
|
||||
|
||||
while(true) {
|
||||
TextContainer.MarkUp m;
|
||||
do {
|
||||
if(!var5.hasNext()) {
|
||||
this.makeup.removeAll(conflicting);
|
||||
return true;
|
||||
}
|
||||
|
||||
m = (TextContainer.MarkUp)var5.next();
|
||||
} while((start < m.start || start > m.end) && (end < m.start || end > m.end) && (start >= m.start || end <= m.start));
|
||||
|
||||
if(level < m.level || level == m.level && m.start <= start) {
|
||||
return false;
|
||||
private boolean removeConflictingMarkUp(int start, int end, int level){
|
||||
List<MarkUp> conflicting = new ArrayList<MarkUp>();
|
||||
for(MarkUp m : makeup){
|
||||
if(start >= m.start && start <= m.end || end >= m.start && end <= m.end || start < m.start && end > m.start){
|
||||
if(level < m.level || level == m.level && m.start <= start)
|
||||
return false;
|
||||
conflicting.add(m);
|
||||
}
|
||||
|
||||
conflicting.add(m);
|
||||
}
|
||||
makeup.removeAll(conflicting);
|
||||
return true;
|
||||
}
|
||||
|
||||
public String getFormattedString() {
|
||||
StringBuilder builder = new StringBuilder(this.text);
|
||||
Iterator var2 = this.makeup.iterator();
|
||||
class LineData {
|
||||
public String text;
|
||||
public int start, end;
|
||||
|
||||
while(var2.hasNext()) {
|
||||
TextContainer.MarkUp entry = (TextContainer.MarkUp)var2.next();
|
||||
builder.insert(entry.start, Character.toString('\uffff') + Character.toString(entry.c));
|
||||
builder.insert(entry.end, Character.toString('\uffff') + Character.toString('r'));
|
||||
public LineData(String text, int start, int end){
|
||||
this.text = text;
|
||||
this.start = start;
|
||||
this.end = end;
|
||||
}
|
||||
|
||||
return builder.toString();
|
||||
public void drawString(int x, int y, int color) {
|
||||
ClientProxy.Font.drawString(this.getFormattedString(), x, y, color);
|
||||
}
|
||||
|
||||
public String getFormattedString(){
|
||||
StringBuilder builder = new StringBuilder(text);
|
||||
int found = 0;
|
||||
for(MarkUp entry : makeup){
|
||||
if(entry.start >= start && entry.start < end){
|
||||
builder.insert(entry.start - start + found * 2, Character.toString(colorChar) + Character.toString(entry.c));
|
||||
found++;
|
||||
}
|
||||
if(entry.start < start && entry.end > start){
|
||||
builder.insert(0, Character.toString(colorChar) + Character.toString(entry.c));
|
||||
found++;
|
||||
}
|
||||
if(entry.end >= start && entry.end < end){
|
||||
builder.insert(entry.end - start + found * 2, Character.toString(colorChar) + Character.toString('r'));
|
||||
found++;
|
||||
}
|
||||
}
|
||||
return builder.toString();
|
||||
}
|
||||
}
|
||||
|
||||
class MarkUp {
|
||||
public int start;
|
||||
public int end;
|
||||
public int level;
|
||||
public int start, end, level;
|
||||
public char c;
|
||||
|
||||
public MarkUp(int start, int end, char c, int level) {
|
||||
public MarkUp(int start, int end, char c, int level){
|
||||
this.start = start;
|
||||
this.end = end;
|
||||
this.c = c;
|
||||
this.level = level;
|
||||
}
|
||||
}
|
||||
|
||||
class LineData {
|
||||
public String text;
|
||||
public int start;
|
||||
public int end;
|
||||
|
||||
public LineData(String text, int start, int end) {
|
||||
this.text = text;
|
||||
this.start = start;
|
||||
this.end = end;
|
||||
}
|
||||
|
||||
public String getFormattedString() {
|
||||
StringBuilder builder = new StringBuilder(this.text);
|
||||
int found = 0;
|
||||
Iterator var3 = TextContainer.this.makeup.iterator();
|
||||
|
||||
while(var3.hasNext()) {
|
||||
TextContainer.MarkUp entry = (TextContainer.MarkUp)var3.next();
|
||||
if(entry.start >= this.start && entry.start < this.end) {
|
||||
builder.insert(entry.start - this.start + found * 2, Character.toString('\uffff') + Character.toString(entry.c));
|
||||
++found;
|
||||
}
|
||||
|
||||
if(entry.start < this.start && entry.end > this.start) {
|
||||
builder.insert(0, Character.toString('\uffff') + Character.toString(entry.c));
|
||||
++found;
|
||||
}
|
||||
|
||||
if(entry.end >= this.start && entry.end < this.end) {
|
||||
builder.insert(entry.end - this.start + found * 2, Character.toString('\uffff') + Character.toString('r'));
|
||||
++found;
|
||||
}
|
||||
}
|
||||
|
||||
return builder.toString();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,330 +0,0 @@
|
||||
//
|
||||
// Source code recreated from a .class file by IntelliJ IDEA
|
||||
// (powered by Fernflower decompiler)
|
||||
//
|
||||
|
||||
package noppes.npcs.config;
|
||||
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.renderer.Tessellator;
|
||||
import net.minecraft.client.renderer.texture.TextureUtil;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import noppes.npcs.util.LRUHashMap;
|
||||
import org.lwjgl.opengl.GL11;
|
||||
|
||||
import java.awt.*;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.util.List;
|
||||
import java.util.*;
|
||||
|
||||
public class TrueTypeFont {
|
||||
private static final int MaxWidth = 512;
|
||||
private static final List<Font> allFonts = Arrays.asList(GraphicsEnvironment.getLocalGraphicsEnvironment().getAllFonts());
|
||||
private List<Font> usedFonts = new ArrayList();
|
||||
private LinkedHashMap<String, TrueTypeFont.GlyphCache> textcache = new LRUHashMap(100);
|
||||
private Map<Character, TrueTypeFont.Glyph> glyphcache = new HashMap();
|
||||
private List<TrueTypeFont.TextureCache> textures = new ArrayList();
|
||||
private Font font;
|
||||
private int lineHeight = 1;
|
||||
private Graphics2D globalG = (Graphics2D)(new BufferedImage(1, 1, 2)).getGraphics();
|
||||
public float scale = 1.0F;
|
||||
private int specialChar = 167;
|
||||
|
||||
public TrueTypeFont(Font font, float scale) {
|
||||
this.font = font;
|
||||
this.scale = scale;
|
||||
this.globalG.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
|
||||
this.lineHeight = this.globalG.getFontMetrics(font).getHeight();
|
||||
}
|
||||
|
||||
public TrueTypeFont(ResourceLocation resource, int fontSize, float scale) throws IOException, FontFormatException {
|
||||
InputStream stream = Minecraft.getMinecraft().getResourceManager().getResource(resource).getInputStream();
|
||||
GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
|
||||
Font font = Font.createFont(0, stream);
|
||||
ge.registerFont(font);
|
||||
this.font = font.deriveFont(0, (float)fontSize);
|
||||
this.scale = scale;
|
||||
this.globalG.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
|
||||
this.lineHeight = this.globalG.getFontMetrics(font).getHeight();
|
||||
}
|
||||
|
||||
public void setSpecial(char c) {
|
||||
this.specialChar = c;
|
||||
}
|
||||
|
||||
public void draw(String text, float x, float y, int color) {
|
||||
TrueTypeFont.GlyphCache cache = this.getOrCreateCache(text);
|
||||
float r = (float)(color >> 16 & 255) / 255.0F;
|
||||
float g = (float)(color >> 8 & 255) / 255.0F;
|
||||
float b = (float)(color & 255) / 255.0F;
|
||||
GL11.glColor4f(r, g, b, 1.0F);
|
||||
//GlStateManager.func_179147_l();
|
||||
GL11.glPushMatrix();
|
||||
GL11.glTranslatef(x, y, 0.0F);
|
||||
GL11.glScalef(this.scale, this.scale, 1.0F);
|
||||
float i = 0.0F;
|
||||
Iterator var10 = cache.glyphs.iterator();
|
||||
|
||||
while(var10.hasNext()) {
|
||||
TrueTypeFont.Glyph gl = (TrueTypeFont.Glyph)var10.next();
|
||||
if(gl.type != TrueTypeFont.GlyphType.NORMAL) {
|
||||
if(gl.type == TrueTypeFont.GlyphType.RESET) {
|
||||
GL11.glColor4f(r, g, b, 1.0F);
|
||||
} else if(gl.type == TrueTypeFont.GlyphType.COLOR) {
|
||||
GL11.glColor4f((float) (gl.color >> 16 & 255) / 255.0F, (float) (gl.color >> 8 & 255) / 255.0F, (float) (gl.color & 255) / 255.0F, 1.0F);
|
||||
}
|
||||
} else {
|
||||
GL11.glBindTexture(gl.texture, gl.texture);
|
||||
this.drawTexturedModalRect(i, 0.0F, (float)gl.x * this.textureScale(), (float)gl.y * this.textureScale(), (float)gl.width * this.textureScale(), (float)gl.height * this.textureScale());
|
||||
i += (float)gl.width * this.textureScale();
|
||||
}
|
||||
}
|
||||
|
||||
//GlStateManager.func_179084_k();
|
||||
GL11.glPopMatrix();
|
||||
GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
|
||||
}
|
||||
|
||||
private TrueTypeFont.GlyphCache getOrCreateCache(String text) {
|
||||
TrueTypeFont.GlyphCache cache = (TrueTypeFont.GlyphCache)this.textcache.get(text);
|
||||
if(cache != null) {
|
||||
return cache;
|
||||
} else {
|
||||
cache = new TrueTypeFont.GlyphCache();
|
||||
|
||||
for(int i = 0; i < text.length(); ++i) {
|
||||
char c = text.charAt(i);
|
||||
if(c == this.specialChar && i + 1 < text.length()) {
|
||||
char g = text.toLowerCase(Locale.ENGLISH).charAt(i + 1);
|
||||
int index = "0123456789abcdefklmnor".indexOf(g);
|
||||
if(index >= 0) {
|
||||
TrueTypeFont.Glyph g1 = new TrueTypeFont.Glyph();
|
||||
if(index < 16) {
|
||||
g1.type = TrueTypeFont.GlyphType.COLOR;
|
||||
//g1.color = Minecraft.getMinecraft().fontRenderer.func_175064_b(g);
|
||||
g1.color = 0;
|
||||
} else if(index == 16) {
|
||||
g1.type = TrueTypeFont.GlyphType.RANDOM;
|
||||
} else if(index == 17) {
|
||||
g1.type = TrueTypeFont.GlyphType.BOLD;
|
||||
} else if(index == 18) {
|
||||
g1.type = TrueTypeFont.GlyphType.STRIKETHROUGH;
|
||||
} else if(index == 19) {
|
||||
g1.type = TrueTypeFont.GlyphType.UNDERLINE;
|
||||
} else if(index == 20) {
|
||||
g1.type = TrueTypeFont.GlyphType.ITALIC;
|
||||
} else {
|
||||
g1.type = TrueTypeFont.GlyphType.RESET;
|
||||
}
|
||||
|
||||
cache.glyphs.add(g1);
|
||||
++i;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
TrueTypeFont.Glyph var8 = this.getOrCreateGlyph(c);
|
||||
cache.glyphs.add(var8);
|
||||
cache.width += var8.width;
|
||||
cache.height = Math.max(cache.height, var8.height);
|
||||
}
|
||||
|
||||
this.textcache.put(text, cache);
|
||||
return cache;
|
||||
}
|
||||
}
|
||||
|
||||
private TrueTypeFont.Glyph getOrCreateGlyph(char c) {
|
||||
TrueTypeFont.Glyph g = (TrueTypeFont.Glyph)this.glyphcache.get(Character.valueOf(c));
|
||||
if(g != null) {
|
||||
return g;
|
||||
} else {
|
||||
TrueTypeFont.TextureCache cache = this.getCurrentTexture();
|
||||
Font font = this.getFontForChar(c);
|
||||
FontMetrics metrics = this.globalG.getFontMetrics(font);
|
||||
g = new TrueTypeFont.Glyph();
|
||||
g.width = Math.max(metrics.charWidth(c), 1);
|
||||
g.height = Math.max(metrics.getHeight(), 1);
|
||||
if(cache.x + g.width >= 512) {
|
||||
cache.x = 0;
|
||||
cache.y += this.lineHeight + 1;
|
||||
if(cache.y >= 512) {
|
||||
cache.full = true;
|
||||
cache = this.getCurrentTexture();
|
||||
}
|
||||
}
|
||||
|
||||
g.x = cache.x;
|
||||
g.y = cache.y;
|
||||
cache.x += g.width + 3;
|
||||
this.lineHeight = Math.max(this.lineHeight, g.height);
|
||||
cache.g.setFont(font);
|
||||
cache.g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
|
||||
cache.g.drawString(c + "", g.x, g.y + metrics.getAscent());
|
||||
g.texture = cache.textureId;
|
||||
TextureUtil.uploadTextureImage(cache.textureId, cache.bufferedImage);
|
||||
this.glyphcache.put(Character.valueOf(c), g);
|
||||
return g;
|
||||
}
|
||||
}
|
||||
|
||||
private TrueTypeFont.TextureCache getCurrentTexture() {
|
||||
TrueTypeFont.TextureCache cache = null;
|
||||
Iterator var2 = this.textures.iterator();
|
||||
|
||||
while(var2.hasNext()) {
|
||||
TrueTypeFont.TextureCache t = (TrueTypeFont.TextureCache)var2.next();
|
||||
if(!t.full) {
|
||||
cache = t;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if(cache == null) {
|
||||
this.textures.add(cache = new TrueTypeFont.TextureCache());
|
||||
}
|
||||
|
||||
return cache;
|
||||
}
|
||||
|
||||
public void drawCentered(String text, float x, float y, int color) {
|
||||
this.draw(text, x - (float)this.width(text) / 2.0F, y, color);
|
||||
}
|
||||
|
||||
private Font getFontForChar(char c) {
|
||||
if(this.font.canDisplay(c)) {
|
||||
return this.font;
|
||||
} else {
|
||||
Iterator fa = this.usedFonts.iterator();
|
||||
|
||||
Font f;
|
||||
do {
|
||||
if(!fa.hasNext()) {
|
||||
Font fa1 = new Font("Arial Unicode MS", 0, this.font.getSize());
|
||||
if(fa1.canDisplay(c)) {
|
||||
return fa1;
|
||||
}
|
||||
|
||||
Iterator f2 = allFonts.iterator();
|
||||
|
||||
Font f1;
|
||||
do {
|
||||
if(!f2.hasNext()) {
|
||||
return this.font;
|
||||
}
|
||||
|
||||
f1 = (Font)f2.next();
|
||||
} while(!f1.canDisplay(c));
|
||||
|
||||
this.usedFonts.add(f1 = f1.deriveFont(0, (float)this.font.getSize()));
|
||||
return f1;
|
||||
}
|
||||
|
||||
f = (Font)fa.next();
|
||||
} while(!f.canDisplay(c));
|
||||
|
||||
return f;
|
||||
}
|
||||
}
|
||||
|
||||
public void drawTexturedModalRect(float p_73729_1_, float p_73729_2_, float p_73729_3_, float p_73729_4_, float p_73729_5_, float p_73729_6_)
|
||||
{
|
||||
float f = 0.00390625F;
|
||||
float f1 = 0.00390625F;
|
||||
byte zLevel = 0;
|
||||
Tessellator tessellator = Tessellator.instance;
|
||||
tessellator.startDrawingQuads();
|
||||
tessellator.addVertexWithUV((double)(p_73729_1_ + 0), (double)(p_73729_2_ + p_73729_6_), (double)zLevel, (double)((float)(p_73729_3_ + 0) * f), (double)((float)(p_73729_4_ + p_73729_6_) * f1));
|
||||
tessellator.addVertexWithUV((double)(p_73729_1_ + p_73729_5_), (double)(p_73729_2_ + p_73729_6_), (double)zLevel, (double)((float)(p_73729_3_ + p_73729_5_) * f), (double)((float)(p_73729_4_ + p_73729_6_) * f1));
|
||||
tessellator.addVertexWithUV((double)(p_73729_1_ + p_73729_5_), (double)(p_73729_2_ + 0), (double)zLevel, (double)((float)(p_73729_3_ + p_73729_5_) * f), (double)((float)(p_73729_4_ + 0) * f1));
|
||||
tessellator.addVertexWithUV((double)(p_73729_1_ + 0), (double)(p_73729_2_ + 0), (double)zLevel, (double)((float)(p_73729_3_ + 0) * f), (double)((float)(p_73729_4_ + 0) * f1));
|
||||
tessellator.draw();
|
||||
}
|
||||
|
||||
public int width(String text) {
|
||||
TrueTypeFont.GlyphCache cache = this.getOrCreateCache(text);
|
||||
return (int)((float)cache.width * this.scale * this.textureScale());
|
||||
}
|
||||
|
||||
public int height(String text) {
|
||||
if(text != null && !text.trim().isEmpty()) {
|
||||
TrueTypeFont.GlyphCache cache = this.getOrCreateCache(text);
|
||||
return Math.max(1, (int)((float)cache.height * this.scale * this.textureScale()));
|
||||
} else {
|
||||
return (int)((float)this.lineHeight * this.scale * this.textureScale());
|
||||
}
|
||||
}
|
||||
|
||||
private float textureScale() {
|
||||
return 0.5F;
|
||||
}
|
||||
|
||||
public void dispose() {
|
||||
Iterator var1 = this.textures.iterator();
|
||||
|
||||
while(var1.hasNext()) {
|
||||
TrueTypeFont.TextureCache cache = (TrueTypeFont.TextureCache)var1.next();
|
||||
GL11.glDeleteTextures(cache.textureId);
|
||||
}
|
||||
|
||||
this.textcache.clear();
|
||||
}
|
||||
|
||||
public String getFontName() {
|
||||
return this.font.getFontName();
|
||||
}
|
||||
|
||||
class GlyphCache {
|
||||
public int width;
|
||||
public int height;
|
||||
List<TrueTypeFont.Glyph> glyphs = new ArrayList();
|
||||
|
||||
GlyphCache() {
|
||||
}
|
||||
}
|
||||
|
||||
class Glyph {
|
||||
TrueTypeFont.GlyphType type;
|
||||
int color;
|
||||
int x;
|
||||
int y;
|
||||
int height;
|
||||
int width;
|
||||
int texture;
|
||||
|
||||
Glyph() {
|
||||
this.type = TrueTypeFont.GlyphType.NORMAL;
|
||||
this.color = -1;
|
||||
}
|
||||
}
|
||||
|
||||
class TextureCache {
|
||||
int x;
|
||||
int y;
|
||||
int textureId = GL11.glGenTextures();
|
||||
BufferedImage bufferedImage = new BufferedImage(512, 512, 2);
|
||||
Graphics2D g;
|
||||
boolean full;
|
||||
|
||||
TextureCache() {
|
||||
this.g = (Graphics2D)this.bufferedImage.getGraphics();
|
||||
}
|
||||
}
|
||||
|
||||
static enum GlyphType {
|
||||
NORMAL,
|
||||
COLOR,
|
||||
RANDOM,
|
||||
BOLD,
|
||||
STRIKETHROUGH,
|
||||
UNDERLINE,
|
||||
ITALIC,
|
||||
RESET,
|
||||
OTHER;
|
||||
|
||||
private GlyphType() {
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user