Guest User

GuiMultiArea

a guest
Feb 25th, 2015
245
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 10.44 KB | None | 0 0
  1. package org.medievalminecraft.social.client.gui.report.elements;
  2.  
  3. import java.util.ArrayList;
  4. import java.util.List;
  5.  
  6. import net.minecraft.client.Minecraft;
  7. import net.minecraft.client.gui.FontRenderer;
  8. import net.minecraft.client.gui.GuiScreen;
  9. import net.minecraft.client.gui.GuiTextField;
  10. import net.minecraft.client.renderer.Tessellator;
  11. import net.minecraft.util.MathHelper;
  12. import net.minecraft.util.ResourceLocation;
  13.  
  14. import org.lwjgl.input.Mouse;
  15. import org.lwjgl.opengl.GL11;
  16. import org.medievalminecraft.social.proxy.ClientProxy;
  17. import org.medievalminecraft.social.utils.RenderingHelper;
  18.  
  19. import scala.xml.dtd.SystemID;
  20.  
  21. import com.sun.org.apache.xml.internal.serialize.LineSeparator;
  22. import com.sun.org.apache.xml.internal.serializer.utils.SystemIDResolver;
  23. import com.sun.xml.internal.messaging.saaj.packaging.mime.util.LineInputStream;
  24.  
  25. public class GuiMultiArea extends GuiTextField {
  26.  
  27.        public boolean inMenu = true;
  28.        public boolean numbersOnly = false;
  29.        private int posX;
  30.        private int posY;
  31.        private int width;
  32.        private int height;
  33.        private int cursorCounter;
  34.        private int cursorPosition = 0;
  35.        private int listHeight;
  36.        private float scrolledY = 0.0F;
  37.        private int startClick = -1;
  38.        private boolean clickVerticalBar = false;
  39.        private boolean wrapLine = true;
  40.        public boolean canEdit;
  41.  
  42.  
  43.        public GuiMultiArea(int id, GuiScreen guiscreen, FontRenderer fontrenderer, int i, int j, int k, int l, String s) {
  44.           super(fontrenderer, i, j, k, l);
  45.           this.posX = i;
  46.           this.posY = j;
  47.           this.width = k;
  48.           this.listHeight = this.height = l;
  49.           this.setMaxStringLength(1500);
  50.           this.setText(s);
  51.           this.canEdit = true;
  52.        }
  53.  
  54.        public void updateCursorCounter() {
  55.           ++this.cursorCounter;
  56.        }
  57.  
  58.        public boolean textboxKeyTyped(char c, int i) {
  59.           if(this.isFocused() && this.canEdit) {
  60.              String originalText = this.getText();
  61.              this.setText(originalText);
  62.              if(c == 13 || c == 10) {
  63.                 this.setText(originalText.substring(0, this.cursorPosition) + c + originalText.substring(this.cursorPosition));
  64.              }
  65.  
  66.              this.setCursorPositionZero();
  67.              this.moveCursorBy(this.cursorPosition);
  68.              boolean bo = super.textboxKeyTyped(c, i);
  69.              String newText = this.getText();
  70.              if(i != 211) {
  71.                 this.cursorPosition += newText.length() - originalText.length();
  72.              }
  73.  
  74.              if(i == 203 && this.cursorPosition > 0) {
  75.                 --this.cursorPosition;
  76.              }
  77.  
  78.              if(i == 205 && this.cursorPosition < newText.length()) {
  79.                 ++this.cursorPosition;
  80.              }
  81.  
  82.              return bo;
  83.           } else {
  84.              return false;
  85.           }
  86.        }
  87.  
  88.        public void mouseClicked(int x, int y, int button) {
  89.           //Here goes the code
  90.        }
  91.  
  92.        private List getLines() {
  93.           ArrayList list = new ArrayList();
  94.           String line = "";
  95.           char[] arr$ = this.getText().toCharArray();
  96.           int len$ = arr$.length;
  97.  
  98.           for(int i$ = 0; i$ < len$; ++i$) {
  99.              char c = arr$[i$];
  100.              if(c != 13 && c != 10) {
  101.                 line = line + c;
  102.              } else {
  103.                 list.add(line);
  104.                 line = "";
  105.              }
  106.           }
  107.  
  108.           list.add(line);
  109.           return list;
  110.        }
  111.  
  112.        private int getStartLineY() {
  113.           if(!this.isScrolling()) {
  114.              this.scrolledY = 0.0F;
  115.           }
  116.  
  117.           return MathHelper.ceiling_double_int((double)(this.scrolledY * (float)this.listHeight / (float)RenderingHelper.FONT_14.getLineHeight() / 2F ));
  118.        }
  119.  
  120.        public void drawTextBox(int mouseX, int mouseY) {
  121. //        drawRect(this.posX - 1, this.posY - 1, this.posX + this.width + 1, this.posY + this.height + 1, -6250336);
  122. //        drawRect(this.posX, this.posY, this.posX + this.width, this.posY + this.height, -16777216);
  123.           int color = 0xFFFFFF;
  124.           boolean flag = this.isFocused() && this.cursorCounter / 6 % 2 == 0;
  125.           int startLine = this.getStartLineY();
  126.           int maxLine = this.height / RenderingHelper.getFontHeight() + startLine;
  127.           List lines = this.getLines();
  128.           int charCount = 0;
  129.           int lineCount = 0;
  130.           int maxSize = this.width - 14;
  131.  
  132.           int loopIndex;
  133.           for(loopIndex = 0; loopIndex < lines.size(); ++loopIndex) {
  134.              String wholeLine = (String)lines.get(loopIndex);
  135.              String line = "";
  136.              char[] xx = wholeLine.toCharArray();
  137.              int yy = xx.length;
  138.  
  139.              for(int i$ = 0; i$ < yy; ++i$) {
  140.                 char c = xx[i$];
  141.                 if((RenderingHelper.FONT_14.getWidth(line + c) / 2F)  > maxSize && this.wrapLine) {
  142.                    if(lineCount >= startLine && lineCount < maxLine) {
  143.                       GL11.glPushMatrix();
  144.                       GL11.glColor3f(1, 1, 1);
  145.                       RenderingHelper.renderString(line, this.posX + 4, (float) (this.posY + 4 + (lineCount - startLine) * (RenderingHelper.getFontHeight()) / 1));
  146.                       GL11.glPopMatrix();
  147.                    }
  148.  
  149.                    line = "";
  150.                    ++lineCount;
  151.                 }
  152.  
  153.                 if(flag && charCount == this.cursorPosition && lineCount >= startLine && lineCount < maxLine && this.canEdit) {
  154.                    int horizontalCursorPos = (int) (this.posX + (RenderingHelper.FONT_14.getWidth(line) / 2F) + 4);
  155.                    int verticalCursorPos = this.posY + (lineCount - startLine) * RenderingHelper.getFontHeight() + 4;
  156.                    if(this.getText().length() == this.cursorPosition) {
  157.                        RenderingHelper.renderString("_", horizontalCursorPos, verticalCursorPos);
  158.                    } else {
  159. //                    this.drawCursorVertical(horizontalCursorPos, verticalCursorPos, horizontalCursorPos, verticalCursorPos + (RenderingHelper.getFontHeight()));
  160.                        RenderingHelper.renderString("|", horizontalCursorPos, verticalCursorPos);
  161.                    }
  162.                 }
  163.  
  164.                 ++charCount;
  165.                 line = line + c;
  166.              }
  167.  
  168.              if(lineCount >= startLine && lineCount < maxLine) {
  169.                  GL11.glPushMatrix();
  170.                  GL11.glColor3f(1, 1, 1);
  171.                  RenderingHelper.renderString(line, this.posX + 4, this.posY + 4 + (lineCount - startLine) * RenderingHelper.getFontHeight());
  172.                 GL11.glPopMatrix();
  173.                 if(flag && charCount == this.cursorPosition && this.canEdit) {
  174.                    int var20 = (int) (this.posX + (RenderingHelper.FONT_14.getWidth(line) / 2F) + 3);
  175.                    yy = this.posY + (lineCount - startLine) * RenderingHelper.getFontHeight() + 3;
  176.                    if(this.getText().length() == this.cursorPosition) {
  177.                        RenderingHelper.renderString("_", var20, yy);
  178.                    } else {
  179.                       this.drawCursorVertical(var20, yy, var20 + 1, (int) (yy + (RenderingHelper.FONT_14.getLineHeight() / 2F)));
  180.                    }
  181.                 }
  182.              }
  183.  
  184.              ++lineCount;
  185.              ++charCount;
  186.           }
  187.  
  188.           loopIndex = Mouse.getDWheel();
  189.           if(loopIndex != 0 && this.isFocused()) {
  190.              this.addScrollY(loopIndex < 0?-10:10);
  191.           }
  192.  
  193.           if(Mouse.isButtonDown(0)) {
  194.              if(this.clickVerticalBar) {
  195.                 if(this.startClick >= 0) {
  196.                    this.addScrollY(this.startClick - (mouseY - this.posY));
  197.                 }
  198.  
  199.                 if(this.hoverVerticalScrollBar(mouseX, mouseY)) {
  200.                    this.startClick = mouseY - this.posY;
  201.                 }
  202.  
  203.                 this.startClick = mouseY - this.posY;
  204.              }
  205.           } else {
  206.              this.clickVerticalBar = false;
  207.           }
  208.  
  209.           this.listHeight = lineCount * RenderingHelper.getFontHeight();
  210.           this.drawVerticalScrollBar();
  211.        }
  212.  
  213.        private boolean isScrolling() {
  214.           return this.listHeight > this.height - 4;
  215.        }
  216.  
  217.        private void addScrollY(int scrolled) {
  218.           this.scrolledY -= 1.0F * (float)scrolled / (float)this.height;
  219.           if(this.scrolledY < 0.0F) {
  220.              this.scrolledY = 0.0F;
  221.           }
  222.  
  223.           float max = 0.9F - 1.0F * (float)(this.height) / (float)this.listHeight;
  224.           if(this.scrolledY > max) {
  225.              this.scrolledY = max;
  226.           }
  227.  
  228.        }
  229.  
  230.        private boolean hoverVerticalScrollBar(int x, int y) {
  231.           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);
  232.        }
  233.  
  234.        private void drawCursorVertical(int p_146188_1_, int p_146188_2_, int p_146188_3_, int p_146188_4_) {
  235.           int i1;
  236.           if(p_146188_1_ < p_146188_3_) {
  237.              i1 = p_146188_1_;
  238.              p_146188_1_ = p_146188_3_;
  239.              p_146188_3_ = i1;
  240.           }
  241.  
  242.           if(p_146188_2_ < p_146188_4_) {
  243.              i1 = p_146188_2_;
  244.              p_146188_2_ = p_146188_4_;
  245.              p_146188_4_ = i1;
  246.           }
  247.  
  248.           if(p_146188_3_ > this.posX + this.width) {
  249.              p_146188_3_ = this.posX + this.width;
  250.           }
  251.  
  252.           if(p_146188_1_ > this.posX + this.width) {
  253.              p_146188_1_ = this.posX + this.width;
  254.           }
  255.  
  256.           Tessellator tessellator = Tessellator.instance;
  257.           GL11.glColor4f(0.0F, 0.0F, 255.0F, 255.0F);
  258.           GL11.glDisable(3553);
  259.           GL11.glEnable(3058);
  260.           GL11.glLogicOp(5387);
  261.           tessellator.startDrawingQuads();
  262.           tessellator.addVertex((double)p_146188_1_, (double)p_146188_4_, 0.0D);
  263.           tessellator.addVertex((double)p_146188_3_, (double)p_146188_4_, 0.0D);
  264.           tessellator.addVertex((double)p_146188_3_, (double)p_146188_2_, 0.0D);
  265.           tessellator.addVertex((double)p_146188_1_, (double)p_146188_2_, 0.0D);
  266.           tessellator.draw();
  267.           GL11.glDisable(3058);
  268.           GL11.glEnable(3553);
  269.        }
  270.  
  271.        private int getVerticalBarSize() {
  272.           return (int)(1.0F * (float)this.height / (float)this.listHeight * (float)(this.height - 4));
  273.        }
  274.  
  275.        private void drawVerticalScrollBar() {
  276.               if(this.listHeight > this.height - 4) {
  277.                   Minecraft.getMinecraft().renderEngine.bindTexture(ClientProxy.scroll_texture);
  278.                   int x = this.posX + this.width - 8;
  279.                   int y = (int)((float)this.posY + this.scrolledY * (float)this.height) + 2;
  280.                   GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
  281.                   int sbSize = this.getVerticalBarSize();
  282.                   this.drawTexturedModalRect(x, y, 0, 0, 6, 36);
  283. //
  284. //                for(int k = 0; k < sbSize; ++k) {
  285. //                   this.drawTexturedModalRect(x, y + k, 0, 0, 6, 26);
  286. //                }
  287. //
  288. //                this.drawTexturedModalRect(x, y, 0, 0, 6, 1);
  289.                }
  290.        }
  291. }
Advertisement
Add Comment
Please, Sign In to add comment