Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package org.medievalminecraft.social.client.gui.report.elements;
- import java.util.ArrayList;
- import java.util.List;
- import net.minecraft.client.Minecraft;
- import net.minecraft.client.gui.FontRenderer;
- import net.minecraft.client.gui.GuiScreen;
- import net.minecraft.client.gui.GuiTextField;
- import net.minecraft.client.renderer.Tessellator;
- import net.minecraft.util.MathHelper;
- import net.minecraft.util.ResourceLocation;
- import org.lwjgl.input.Mouse;
- import org.lwjgl.opengl.GL11;
- import org.medievalminecraft.social.proxy.ClientProxy;
- import org.medievalminecraft.social.utils.RenderingHelper;
- import scala.xml.dtd.SystemID;
- import com.sun.org.apache.xml.internal.serialize.LineSeparator;
- import com.sun.org.apache.xml.internal.serializer.utils.SystemIDResolver;
- import com.sun.xml.internal.messaging.saaj.packaging.mime.util.LineInputStream;
- public class GuiMultiArea extends GuiTextField {
- public boolean inMenu = true;
- public boolean numbersOnly = false;
- private int posX;
- private int posY;
- private int width;
- private int height;
- private int cursorCounter;
- private int cursorPosition = 0;
- private int listHeight;
- private float scrolledY = 0.0F;
- private int startClick = -1;
- private boolean clickVerticalBar = false;
- private boolean wrapLine = true;
- public boolean canEdit;
- public GuiMultiArea(int id, GuiScreen guiscreen, FontRenderer fontrenderer, int i, int j, int k, int l, String s) {
- super(fontrenderer, i, j, k, l);
- this.posX = i;
- this.posY = j;
- this.width = k;
- this.listHeight = this.height = l;
- this.setMaxStringLength(1500);
- this.setText(s);
- this.canEdit = true;
- }
- public void updateCursorCounter() {
- ++this.cursorCounter;
- }
- public boolean textboxKeyTyped(char c, int i) {
- if(this.isFocused() && this.canEdit) {
- String originalText = this.getText();
- this.setText(originalText);
- if(c == 13 || c == 10) {
- this.setText(originalText.substring(0, this.cursorPosition) + c + originalText.substring(this.cursorPosition));
- }
- this.setCursorPositionZero();
- this.moveCursorBy(this.cursorPosition);
- boolean bo = super.textboxKeyTyped(c, i);
- String newText = this.getText();
- if(i != 211) {
- this.cursorPosition += newText.length() - originalText.length();
- }
- if(i == 203 && this.cursorPosition > 0) {
- --this.cursorPosition;
- }
- if(i == 205 && this.cursorPosition < newText.length()) {
- ++this.cursorPosition;
- }
- return bo;
- } else {
- return false;
- }
- }
- public void mouseClicked(int x, int y, int button) {
- //Here goes the code
- }
- private List getLines() {
- ArrayList list = new ArrayList();
- String line = "";
- char[] arr$ = this.getText().toCharArray();
- int len$ = arr$.length;
- for(int i$ = 0; i$ < len$; ++i$) {
- char c = arr$[i$];
- if(c != 13 && c != 10) {
- line = line + c;
- } else {
- list.add(line);
- line = "";
- }
- }
- list.add(line);
- return list;
- }
- private int getStartLineY() {
- if(!this.isScrolling()) {
- this.scrolledY = 0.0F;
- }
- return MathHelper.ceiling_double_int((double)(this.scrolledY * (float)this.listHeight / (float)RenderingHelper.FONT_14.getLineHeight() / 2F ));
- }
- public void drawTextBox(int mouseX, int mouseY) {
- // drawRect(this.posX - 1, this.posY - 1, this.posX + this.width + 1, this.posY + this.height + 1, -6250336);
- // drawRect(this.posX, this.posY, this.posX + this.width, this.posY + this.height, -16777216);
- int color = 0xFFFFFF;
- boolean flag = this.isFocused() && this.cursorCounter / 6 % 2 == 0;
- int startLine = this.getStartLineY();
- int maxLine = this.height / RenderingHelper.getFontHeight() + startLine;
- List lines = this.getLines();
- int charCount = 0;
- int lineCount = 0;
- int maxSize = this.width - 14;
- int loopIndex;
- for(loopIndex = 0; loopIndex < lines.size(); ++loopIndex) {
- String wholeLine = (String)lines.get(loopIndex);
- String line = "";
- char[] xx = wholeLine.toCharArray();
- int yy = xx.length;
- for(int i$ = 0; i$ < yy; ++i$) {
- char c = xx[i$];
- if((RenderingHelper.FONT_14.getWidth(line + c) / 2F) > maxSize && this.wrapLine) {
- if(lineCount >= startLine && lineCount < maxLine) {
- GL11.glPushMatrix();
- GL11.glColor3f(1, 1, 1);
- RenderingHelper.renderString(line, this.posX + 4, (float) (this.posY + 4 + (lineCount - startLine) * (RenderingHelper.getFontHeight()) / 1));
- GL11.glPopMatrix();
- }
- line = "";
- ++lineCount;
- }
- if(flag && charCount == this.cursorPosition && lineCount >= startLine && lineCount < maxLine && this.canEdit) {
- int horizontalCursorPos = (int) (this.posX + (RenderingHelper.FONT_14.getWidth(line) / 2F) + 4);
- int verticalCursorPos = this.posY + (lineCount - startLine) * RenderingHelper.getFontHeight() + 4;
- if(this.getText().length() == this.cursorPosition) {
- RenderingHelper.renderString("_", horizontalCursorPos, verticalCursorPos);
- } else {
- // this.drawCursorVertical(horizontalCursorPos, verticalCursorPos, horizontalCursorPos, verticalCursorPos + (RenderingHelper.getFontHeight()));
- RenderingHelper.renderString("|", horizontalCursorPos, verticalCursorPos);
- }
- }
- ++charCount;
- line = line + c;
- }
- if(lineCount >= startLine && lineCount < maxLine) {
- GL11.glPushMatrix();
- GL11.glColor3f(1, 1, 1);
- RenderingHelper.renderString(line, this.posX + 4, this.posY + 4 + (lineCount - startLine) * RenderingHelper.getFontHeight());
- GL11.glPopMatrix();
- if(flag && charCount == this.cursorPosition && this.canEdit) {
- int var20 = (int) (this.posX + (RenderingHelper.FONT_14.getWidth(line) / 2F) + 3);
- yy = this.posY + (lineCount - startLine) * RenderingHelper.getFontHeight() + 3;
- if(this.getText().length() == this.cursorPosition) {
- RenderingHelper.renderString("_", var20, yy);
- } else {
- this.drawCursorVertical(var20, yy, var20 + 1, (int) (yy + (RenderingHelper.FONT_14.getLineHeight() / 2F)));
- }
- }
- }
- ++lineCount;
- ++charCount;
- }
- loopIndex = Mouse.getDWheel();
- if(loopIndex != 0 && this.isFocused()) {
- this.addScrollY(loopIndex < 0?-10:10);
- }
- if(Mouse.isButtonDown(0)) {
- if(this.clickVerticalBar) {
- if(this.startClick >= 0) {
- this.addScrollY(this.startClick - (mouseY - this.posY));
- }
- if(this.hoverVerticalScrollBar(mouseX, mouseY)) {
- this.startClick = mouseY - this.posY;
- }
- this.startClick = mouseY - this.posY;
- }
- } else {
- this.clickVerticalBar = false;
- }
- this.listHeight = lineCount * RenderingHelper.getFontHeight();
- this.drawVerticalScrollBar();
- }
- private boolean isScrolling() {
- return this.listHeight > this.height - 4;
- }
- private void addScrollY(int scrolled) {
- this.scrolledY -= 1.0F * (float)scrolled / (float)this.height;
- if(this.scrolledY < 0.0F) {
- this.scrolledY = 0.0F;
- }
- float max = 0.9F - 1.0F * (float)(this.height) / (float)this.listHeight;
- if(this.scrolledY > max) {
- this.scrolledY = max;
- }
- }
- private boolean hoverVerticalScrollBar(int x, int y) {
- return this.listHeight <= this.height - 4?false:this.posY < y && this.posY + this.height > y && x < this.posX + this.width && x > this.posX + (this.width - 8);
- }
- private void drawCursorVertical(int p_146188_1_, int p_146188_2_, int p_146188_3_, int p_146188_4_) {
- int i1;
- if(p_146188_1_ < p_146188_3_) {
- i1 = p_146188_1_;
- p_146188_1_ = p_146188_3_;
- p_146188_3_ = i1;
- }
- if(p_146188_2_ < p_146188_4_) {
- i1 = p_146188_2_;
- p_146188_2_ = p_146188_4_;
- p_146188_4_ = i1;
- }
- if(p_146188_3_ > this.posX + this.width) {
- p_146188_3_ = this.posX + this.width;
- }
- if(p_146188_1_ > this.posX + this.width) {
- p_146188_1_ = this.posX + this.width;
- }
- Tessellator tessellator = Tessellator.instance;
- GL11.glColor4f(0.0F, 0.0F, 255.0F, 255.0F);
- GL11.glDisable(3553);
- GL11.glEnable(3058);
- GL11.glLogicOp(5387);
- tessellator.startDrawingQuads();
- tessellator.addVertex((double)p_146188_1_, (double)p_146188_4_, 0.0D);
- tessellator.addVertex((double)p_146188_3_, (double)p_146188_4_, 0.0D);
- tessellator.addVertex((double)p_146188_3_, (double)p_146188_2_, 0.0D);
- tessellator.addVertex((double)p_146188_1_, (double)p_146188_2_, 0.0D);
- tessellator.draw();
- GL11.glDisable(3058);
- GL11.glEnable(3553);
- }
- private int getVerticalBarSize() {
- return (int)(1.0F * (float)this.height / (float)this.listHeight * (float)(this.height - 4));
- }
- private void drawVerticalScrollBar() {
- if(this.listHeight > this.height - 4) {
- Minecraft.getMinecraft().renderEngine.bindTexture(ClientProxy.scroll_texture);
- int x = this.posX + this.width - 8;
- int y = (int)((float)this.posY + this.scrolledY * (float)this.height) + 2;
- GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
- int sbSize = this.getVerticalBarSize();
- this.drawTexturedModalRect(x, y, 0, 0, 6, 36);
- //
- // for(int k = 0; k < sbSize; ++k) {
- // this.drawTexturedModalRect(x, y + k, 0, 0, 6, 26);
- // }
- //
- // this.drawTexturedModalRect(x, y, 0, 0, 6, 1);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment