| 1 | package net.minecraft.client.gui;
|
| 2 |
|
| 3 | import com.google.common.base.Predicate;
|
| 4 | import com.google.common.base.Predicates;
|
| 5 | import net.minecraft.client.renderer.GlStateManager;
|
| 6 | import net.minecraft.client.renderer.Tessellator;
|
| 7 | import net.minecraft.client.renderer.WorldRenderer;
|
| 8 | import net.minecraft.client.renderer.vertex.DefaultVertexFormats;
|
| 9 | import net.minecraft.util.ChatAllowedCharacters;
|
| 10 | import net.minecraft.util.MathHelper;
|
| 11 |
|
| 12 | public class GuiTextField extends Gui
|
| 13 | {
|
| 14 | private final int id;
|
| 15 | private final FontRenderer fontRendererInstance;
|
| 16 | public int xPosition;
|
| 17 | public int yPosition;
|
| 18 |
|
| 19 | /** The width of this text field. */
|
| 20 | private final int width;
|
| 21 | private final int height;
|
| 22 |
|
| 23 | /** Has the current text being edited on the textbox. */
|
| 24 | private String text = "";
|
| 25 | private int maxStringLength = 32;
|
| 26 | private int cursorCounter;
|
| 27 | private boolean enableBackgroundDrawing = true;
|
| 28 |
|
| 29 | /**
|
| 30 | * if true the textbox can lose focus by clicking elsewhere on the screen
|
| 31 | */
|
| 32 | private boolean canLoseFocus = true;
|
| 33 |
|
| 34 | /**
|
| 35 | * If this value is true along with isEnabled, keyTyped will process the keys.
|
| 36 | */
|
| 37 | private boolean isFocused;
|
| 38 |
|
| 39 | /**
|
| 40 | * If this value is true along with isFocused, keyTyped will process the keys.
|
| 41 | */
|
| 42 | private boolean isEnabled = true;
|
| 43 |
|
| 44 | /**
|
| 45 | * The current character index that should be used as start of the rendered text.
|
| 46 | */
|
| 47 | private int lineScrollOffset;
|
| 48 | private int cursorPosition;
|
| 49 |
|
| 50 | /** other selection position, maybe the same as the cursor */
|
| 51 | private int selectionEnd;
|
| 52 | private int enabledColor = 14737632;
|
| 53 | private int disabledColor = 7368816;
|
| 54 |
|
| 55 | /** True if this textbox is visible */
|
| 56 | private boolean visible = true;
|
| 57 | private GuiPageButtonList.GuiResponder field_175210_x;
|
| 58 | private Predicate<String> validator = Predicates.<String>alwaysTrue();
|
| 59 |
|
| 60 | public GuiTextField(int componentId, FontRenderer fontrendererObj, int x, int y, int par5Width, int par6Height)
|
| 61 | {
|
| 62 | this.id = componentId;
|
| 63 | this.fontRendererInstance = fontrendererObj;
|
| 64 | this.xPosition = x;
|
| 65 | this.yPosition = y;
|
| 66 | this.width = par5Width;
|
| 67 | this.height = par6Height;
|
| 68 | }
|
| 69 |
|
| 70 | public void func_175207_a(GuiPageButtonList.GuiResponder p_175207_1_)
|
| 71 | {
|
| 72 | this.field_175210_x = p_175207_1_;
|
| 73 | }
|
| 74 |
|
| 75 | /**
|
| 76 | * Increments the cursor counter
|
| 77 | */
|
| 78 | public void updateCursorCounter()
|
| 79 | {
|
| 80 | ++this.cursorCounter;
|
| 81 | }
|
| 82 |
|
| 83 | /**
|
| 84 | * Sets the text of the textbox
|
| 85 | */
|
| 86 | public void setText(String p_146180_1_)
|
| 87 | {
|
| 88 | if (this.validator.apply(p_146180_1_))
|
| 89 | {
|
| 90 | if (p_146180_1_.length() > this.maxStringLength)
|
| 91 | {
|
| 92 | this.text = p_146180_1_.substring(0, this.maxStringLength);
|
| 93 | }
|
| 94 | else
|
| 95 | {
|
| 96 | this.text = p_146180_1_;
|
| 97 | }
|
| 98 |
|
| 99 | this.setCursorPositionEnd();
|
| 100 | }
|
| 101 | }
|
| 102 |
|
| 103 | /**
|
| 104 | * Returns the contents of the textbox
|
| 105 | */
|
| 106 | public String getText()
|
| 107 | {
|
| 108 | return this.text;
|
| 109 | }
|
| 110 |
|
| 111 | /**
|
| 112 | * returns the text between the cursor and selectionEnd
|
| 113 | */
|
| 114 | public String getSelectedText()
|
| 115 | {
|
| 116 | int i = this.cursorPosition < this.selectionEnd ? this.cursorPosition : this.selectionEnd;
|
| 117 | int j = this.cursorPosition < this.selectionEnd ? this.selectionEnd : this.cursorPosition;
|
| 118 | return this.text.substring(i, j);
|
| 119 | }
|
| 120 |
|
| 121 | public void setValidator(Predicate<String> theValidator)
|
| 122 | {
|
| 123 | this.validator = theValidator;
|
| 124 | }
|
| 125 |
|
| 126 | /**
|
| 127 | * replaces selected text, or inserts text at the position on the cursor
|
| 128 | */
|
| 129 | public void writeText(String p_146191_1_)
|
| 130 | {
|
| 131 | String s = "";
|
| 132 | String s1 = ChatAllowedCharacters.filterAllowedCharacters(p_146191_1_);
|
| 133 | int i = this.cursorPosition < this.selectionEnd ? this.cursorPosition : this.selectionEnd;
|
| 134 | int j = this.cursorPosition < this.selectionEnd ? this.selectionEnd : this.cursorPosition;
|
| 135 | int k = this.maxStringLength - this.text.length() - (i - j);
|
| 136 | int l = 0;
|
| 137 |
|
| 138 | if (this.text.length() > 0)
|
| 139 | {
|
| 140 | s = s + this.text.substring(0, i);
|
| 141 | }
|
| 142 |
|
| 143 | if (k < s1.length())
|
| 144 | {
|
| 145 | s = s + s1.substring(0, k);
|
| 146 | l = k;
|
| 147 | }
|
| 148 | else
|
| 149 | {
|
| 150 | s = s + s1;
|
| 151 | l = s1.length();
|
| 152 | }
|
| 153 |
|
| 154 | if (this.text.length() > 0 && j < this.text.length())
|
| 155 | {
|
| 156 | s = s + this.text.substring(j);
|
| 157 | }
|
| 158 |
|
| 159 | if (this.validator.apply(s))
|
| 160 | {
|
| 161 | this.text = s;
|
| 162 | this.moveCursorBy(i - this.selectionEnd + l);
|
| 163 |
|
| 164 | if (this.field_175210_x != null)
|
| 165 | {
|
| 166 | this.field_175210_x.func_175319_a(this.id, this.text);
|
| 167 | }
|
| 168 | }
|
| 169 | }
|
| 170 |
|
| 171 | /**
|
| 172 | * Deletes the specified number of words starting at the cursor position. Negative numbers will delete words left of
|
| 173 | * the cursor.
|
| 174 | */
|
| 175 | public void deleteWords(int p_146177_1_)
|
| 176 | {
|
| 177 | if (this.text.length() != 0)
|
| 178 | {
|
| 179 | if (this.selectionEnd != this.cursorPosition)
|
| 180 | {
|
| 181 | this.writeText("");
|
| 182 | }
|
| 183 | else
|
| 184 | {
|
| 185 | this.deleteFromCursor(this.getNthWordFromCursor(p_146177_1_) - this.cursorPosition);
|
| 186 | }
|
| 187 | }
|
| 188 | }
|
| 189 |
|
| 190 | /**
|
| 191 | * delete the selected text, otherwsie deletes characters from either side of the cursor. params: delete num
|
| 192 | */
|
| 193 | public void deleteFromCursor(int p_146175_1_)
|
| 194 | {
|
| 195 | if (this.text.length() != 0)
|
| 196 | {
|
| 197 | if (this.selectionEnd != this.cursorPosition)
|
| 198 | {
|
| 199 | this.writeText("");
|
| 200 | }
|
| 201 | else
|
| 202 | {
|
| 203 | boolean flag = p_146175_1_ < 0;
|
| 204 | int i = flag ? this.cursorPosition + p_146175_1_ : this.cursorPosition;
|
| 205 | int j = flag ? this.cursorPosition : this.cursorPosition + p_146175_1_;
|
| 206 | String s = "";
|
| 207 |
|
| 208 | if (i >= 0)
|
| 209 | {
|
| 210 | s = this.text.substring(0, i);
|
| 211 | }
|
| 212 |
|
| 213 | if (j < this.text.length())
|
| 214 | {
|
| 215 | s = s + this.text.substring(j);
|
| 216 | }
|
| 217 |
|
| 218 | if (this.validator.apply(s))
|
| 219 | {
|
| 220 | this.text = s;
|
| 221 |
|
| 222 | if (flag)
|
| 223 | {
|
| 224 | this.moveCursorBy(p_146175_1_);
|
| 225 | }
|
| 226 |
|
| 227 | if (this.field_175210_x != null)
|
| 228 | {
|
| 229 | this.field_175210_x.func_175319_a(this.id, this.text);
|
| 230 | }
|
| 231 | }
|
| 232 | }
|
| 233 | }
|
| 234 | }
|
| 235 |
|
| 236 | public int getId()
|
| 237 | {
|
| 238 | return this.id;
|
| 239 | }
|
| 240 |
|
| 241 | /**
|
| 242 | * see @getNthNextWordFromPos() params: N, position
|
| 243 | */
|
| 244 | public int getNthWordFromCursor(int p_146187_1_)
|
| 245 | {
|
| 246 | return this.getNthWordFromPos(p_146187_1_, this.getCursorPosition());
|
| 247 | }
|
| 248 |
|
| 249 | /**
|
| 250 | * gets the position of the nth word. N may be negative, then it looks backwards. params: N, position
|
| 251 | */
|
| 252 | public int getNthWordFromPos(int p_146183_1_, int p_146183_2_)
|
| 253 | {
|
| 254 | return this.func_146197_a(p_146183_1_, p_146183_2_, true);
|
| 255 | }
|
| 256 |
|
| 257 | public int func_146197_a(int p_146197_1_, int p_146197_2_, boolean p_146197_3_)
|
| 258 | {
|
| 259 | int i = p_146197_2_;
|
| 260 | boolean flag = p_146197_1_ < 0;
|
| 261 | int j = Math.abs(p_146197_1_);
|
| 262 |
|
| 263 | for (int k = 0; k < j; ++k)
|
| 264 | {
|
| 265 | if (!flag)
|
| 266 | {
|
| 267 | int l = this.text.length();
|
| 268 | i = this.text.indexOf(32, i);
|
| 269 |
|
| 270 | if (i == -1)
|
| 271 | {
|
| 272 | i = l;
|
| 273 | }
|
| 274 | else
|
| 275 | {
|
| 276 | while (p_146197_3_ && i < l && this.text.charAt(i) == 32)
|
| 277 | {
|
| 278 | ++i;
|
| 279 | }
|
| 280 | }
|
| 281 | }
|
| 282 | else
|
| 283 | {
|
| 284 | while (p_146197_3_ && i > 0 && this.text.charAt(i - 1) == 32)
|
| 285 | {
|
| 286 | --i;
|
| 287 | }
|
| 288 |
|
| 289 | while (i > 0 && this.text.charAt(i - 1) != 32)
|
| 290 | {
|
| 291 | --i;
|
| 292 | }
|
| 293 | }
|
| 294 | }
|
| 295 |
|
| 296 | return i;
|
| 297 | }
|
| 298 |
|
| 299 | /**
|
| 300 | * Moves the text cursor by a specified number of characters and clears the selection
|
| 301 | */
|
| 302 | public void moveCursorBy(int p_146182_1_)
|
| 303 | {
|
| 304 | this.setCursorPosition(this.selectionEnd + p_146182_1_);
|
| 305 | }
|
| 306 |
|
| 307 | /**
|
| 308 | * sets the position of the cursor to the provided index
|
| 309 | */
|
| 310 | public void setCursorPosition(int p_146190_1_)
|
| 311 | {
|
| 312 | this.cursorPosition = p_146190_1_;
|
| 313 | int i = this.text.length();
|
| 314 | this.cursorPosition = MathHelper.clamp_int(this.cursorPosition, 0, i);
|
| 315 | this.setSelectionPos(this.cursorPosition);
|
| 316 | }
|
| 317 |
|
| 318 | /**
|
| 319 | * sets the cursors position to the beginning
|
| 320 | */
|
| 321 | public void setCursorPositionZero()
|
| 322 | {
|
| 323 | this.setCursorPosition(0);
|
| 324 | }
|
| 325 |
|
| 326 | /**
|
| 327 | * sets the cursors position to after the text
|
| 328 | */
|
| 329 | public void setCursorPositionEnd()
|
| 330 | {
|
| 331 | this.setCursorPosition(this.text.length());
|
| 332 | }
|
| 333 |
|
| 334 | /**
|
| 335 | * Call this method from your GuiScreen to process the keys into the textbox
|
| 336 | */
|
| 337 | public boolean textboxKeyTyped(char p_146201_1_, int p_146201_2_)
|
| 338 | {
|
| 339 | if (!this.isFocused)
|
| 340 | {
|
| 341 | return false;
|
| 342 | }
|
| 343 | else if (GuiScreen.isKeyComboCtrlA(p_146201_2_))
|
| 344 | {
|
| 345 | this.setCursorPositionEnd();
|
| 346 | this.setSelectionPos(0);
|
| 347 | return true;
|
| 348 | }
|
| 349 | else if (GuiScreen.isKeyComboCtrlC(p_146201_2_))
|
| 350 | {
|
| 351 | GuiScreen.setClipboardString(this.getSelectedText());
|
| 352 | return true;
|
| 353 | }
|
| 354 | else if (GuiScreen.isKeyComboCtrlV(p_146201_2_))
|
| 355 | {
|
| 356 | if (this.isEnabled)
|
| 357 | {
|
| 358 | this.writeText(GuiScreen.getClipboardString());
|
| 359 | }
|
| 360 |
|
| 361 | return true;
|
| 362 | }
|
| 363 | else if (GuiScreen.isKeyComboCtrlX(p_146201_2_))
|
| 364 | {
|
| 365 | GuiScreen.setClipboardString(this.getSelectedText());
|
| 366 |
|
| 367 | if (this.isEnabled)
|
| 368 | {
|
| 369 | this.writeText("");
|
| 370 | }
|
| 371 |
|
| 372 | return true;
|
| 373 | }
|
| 374 | else
|
| 375 | {
|
| 376 | switch (p_146201_2_)
|
| 377 | {
|
| 378 | case 14:
|
| 379 | if (GuiScreen.isCtrlKeyDown())
|
| 380 | {
|
| 381 | if (this.isEnabled)
|
| 382 | {
|
| 383 | this.deleteWords(-1);
|
| 384 | }
|
| 385 | }
|
| 386 | else if (this.isEnabled)
|
| 387 | {
|
| 388 | this.deleteFromCursor(-1);
|
| 389 | }
|
| 390 |
|
| 391 | return true;
|
| 392 |
|
| 393 | case 199:
|
| 394 | if (GuiScreen.isShiftKeyDown())
|
| 395 | {
|
| 396 | this.setSelectionPos(0);
|
| 397 | }
|
| 398 | else
|
| 399 | {
|
| 400 | this.setCursorPositionZero();
|
| 401 | }
|
| 402 |
|
| 403 | return true;
|
| 404 |
|
| 405 | case 203:
|
| 406 | if (GuiScreen.isShiftKeyDown())
|
| 407 | {
|
| 408 | if (GuiScreen.isCtrlKeyDown())
|
| 409 | {
|
| 410 | this.setSelectionPos(this.getNthWordFromPos(-1, this.getSelectionEnd()));
|
| 411 | }
|
| 412 | else
|
| 413 | {
|
| 414 | this.setSelectionPos(this.getSelectionEnd() - 1);
|
| 415 | }
|
| 416 | }
|
| 417 | else if (GuiScreen.isCtrlKeyDown())
|
| 418 | {
|
| 419 | this.setCursorPosition(this.getNthWordFromCursor(-1));
|
| 420 | }
|
| 421 | else
|
| 422 | {
|
| 423 | this.moveCursorBy(-1);
|
| 424 | }
|
| 425 |
|
| 426 | return true;
|
| 427 |
|
| 428 | case 205:
|
| 429 | if (GuiScreen.isShiftKeyDown())
|
| 430 | {
|
| 431 | if (GuiScreen.isCtrlKeyDown())
|
| 432 | {
|
| 433 | this.setSelectionPos(this.getNthWordFromPos(1, this.getSelectionEnd()));
|
| 434 | }
|
| 435 | else
|
| 436 | {
|
| 437 | this.setSelectionPos(this.getSelectionEnd() + 1);
|
| 438 | }
|
| 439 | }
|
| 440 | else if (GuiScreen.isCtrlKeyDown())
|
| 441 | {
|
| 442 | this.setCursorPosition(this.getNthWordFromCursor(1));
|
| 443 | }
|
| 444 | else
|
| 445 | {
|
| 446 | this.moveCursorBy(1);
|
| 447 | }
|
| 448 |
|
| 449 | return true;
|
| 450 |
|
| 451 | case 207:
|
| 452 | if (GuiScreen.isShiftKeyDown())
|
| 453 | {
|
| 454 | this.setSelectionPos(this.text.length());
|
| 455 | }
|
| 456 | else
|
| 457 | {
|
| 458 | this.setCursorPositionEnd();
|
| 459 | }
|
| 460 |
|
| 461 | return true;
|
| 462 |
|
| 463 | case 211:
|
| 464 | if (GuiScreen.isCtrlKeyDown())
|
| 465 | {
|
| 466 | if (this.isEnabled)
|
| 467 | {
|
| 468 | this.deleteWords(1);
|
| 469 | }
|
| 470 | }
|
| 471 | else if (this.isEnabled)
|
| 472 | {
|
| 473 | this.deleteFromCursor(1);
|
| 474 | }
|
| 475 |
|
| 476 | return true;
|
| 477 |
|
| 478 | default:
|
| 479 | if (ChatAllowedCharacters.isAllowedCharacter(p_146201_1_))
|
| 480 | {
|
| 481 | if (this.isEnabled)
|
| 482 | {
|
| 483 | this.writeText(Character.toString(p_146201_1_));
|
| 484 | }
|
| 485 |
|
| 486 | return true;
|
| 487 | }
|
| 488 | else
|
| 489 | {
|
| 490 | return false;
|
| 491 | }
|
| 492 | }
|
| 493 | }
|
| 494 | }
|
| 495 |
|
| 496 | /**
|
| 497 | * Args: x, y, buttonClicked
|
| 498 | */
|
| 499 | public void mouseClicked(int p_146192_1_, int p_146192_2_, int p_146192_3_)
|
| 500 | {
|
| 501 | boolean flag = p_146192_1_ >= this.xPosition && p_146192_1_ < this.xPosition + this.width && p_146192_2_ >= this.yPosition && p_146192_2_ < this.yPosition + this.height;
|
| 502 |
|
| 503 | if (this.canLoseFocus)
|
| 504 | {
|
| 505 | this.setFocused(flag);
|
| 506 | }
|
| 507 |
|
| 508 | if (this.isFocused && flag && p_146192_3_ == 0)
|
| 509 | {
|
| 510 | int i = p_146192_1_ - this.xPosition;
|
| 511 |
|
| 512 | if (this.enableBackgroundDrawing)
|
| 513 | {
|
| 514 | i -= 4;
|
| 515 | }
|
| 516 |
|
| 517 | String s = this.fontRendererInstance.trimStringToWidth(this.text.substring(this.lineScrollOffset), this.getWidth());
|
| 518 | this.setCursorPosition(this.fontRendererInstance.trimStringToWidth(s, i).length() + this.lineScrollOffset);
|
| 519 | }
|
| 520 | }
|
| 521 |
|
| 522 | /**
|
| 523 | * Draws the textbox
|
| 524 | */
|
| 525 | public void drawTextBox()
|
| 526 | {
|
| 527 | if (this.getVisible())
|
| 528 | {
|
| 529 | if (this.getEnableBackgroundDrawing())
|
| 530 | {
|
| 531 | drawRect(this.xPosition - 1, this.yPosition - 1, this.xPosition + this.width + 1, this.yPosition + this.height + 1, -6250336);
|
| 532 | drawRect(this.xPosition, this.yPosition, this.xPosition + this.width, this.yPosition + this.height, -16777216);
|
| 533 | }
|
| 534 |
|
| 535 | int i = this.isEnabled ? this.enabledColor : this.disabledColor;
|
| 536 | int j = this.cursorPosition - this.lineScrollOffset;
|
| 537 | int k = this.selectionEnd - this.lineScrollOffset;
|
| 538 | String s = this.fontRendererInstance.trimStringToWidth(this.text.substring(this.lineScrollOffset), this.getWidth());
|
| 539 | boolean flag = j >= 0 && j <= s.length();
|
| 540 | boolean flag1 = this.isFocused && this.cursorCounter / 6 % 2 == 0 && flag;
|
| 541 | int l = this.enableBackgroundDrawing ? this.xPosition + 4 : this.xPosition;
|
| 542 | int i1 = this.enableBackgroundDrawing ? this.yPosition + (this.height - 8) / 2 : this.yPosition;
|
| 543 | int j1 = l;
|
| 544 |
|
| 545 | if (k > s.length())
|
| 546 | {
|
| 547 | k = s.length();
|
| 548 | }
|
| 549 |
|
| 550 | if (s.length() > 0)
|
| 551 | {
|
| 552 | String s1 = flag ? s.substring(0, j) : s;
|
| 553 | j1 = this.fontRendererInstance.drawStringWithShadow(s1, (float)l, (float)i1, i);
|
| 554 | }
|
| 555 |
|
| 556 | boolean flag2 = this.cursorPosition < this.text.length() || this.text.length() >= this.getMaxStringLength();
|
| 557 | int k1 = j1;
|
| 558 |
|
| 559 | if (!flag)
|
| 560 | {
|
| 561 | k1 = j > 0 ? l + this.width : l;
|
| 562 | }
|
| 563 | else if (flag2)
|
| 564 | {
|
| 565 | k1 = j1 - 1;
|
| 566 | --j1;
|
| 567 | }
|
| 568 |
|
| 569 | if (s.length() > 0 && flag && j < s.length())
|
| 570 | {
|
| 571 | j1 = this.fontRendererInstance.drawStringWithShadow(s.substring(j), (float)j1, (float)i1, i);
|
| 572 | }
|
| 573 |
|
| 574 | if (flag1)
|
| 575 | {
|
| 576 | if (flag2)
|
| 577 | {
|
| 578 | Gui.drawRect(k1, i1 - 1, k1 + 1, i1 + 1 + this.fontRendererInstance.FONT_HEIGHT, -3092272);
|
| 579 | }
|
| 580 | else
|
| 581 | {
|
| 582 | this.fontRendererInstance.drawStringWithShadow("_", (float)k1, (float)i1, i);
|
| 583 | }
|
| 584 | }
|
| 585 |
|
| 586 | if (k != j)
|
| 587 | {
|
| 588 | int l1 = l + this.fontRendererInstance.getStringWidth(s.substring(0, k));
|
| 589 | this.drawCursorVertical(k1, i1 - 1, l1 - 1, i1 + 1 + this.fontRendererInstance.FONT_HEIGHT);
|
| 590 | }
|
| 591 | }
|
| 592 | }
|
| 593 |
|
| 594 | /**
|
| 595 | * draws the vertical line cursor in the textbox
|
| 596 | */
|
| 597 | private void drawCursorVertical(int p_146188_1_, int p_146188_2_, int p_146188_3_, int p_146188_4_)
|
| 598 | {
|
| 599 | if (p_146188_1_ < p_146188_3_)
|
| 600 | {
|
| 601 | int i = p_146188_1_;
|
| 602 | p_146188_1_ = p_146188_3_;
|
| 603 | p_146188_3_ = i;
|
| 604 | }
|
| 605 |
|
| 606 | if (p_146188_2_ < p_146188_4_)
|
| 607 | {
|
| 608 | int j = p_146188_2_;
|
| 609 | p_146188_2_ = p_146188_4_;
|
| 610 | p_146188_4_ = j;
|
| 611 | }
|
| 612 |
|
| 613 | if (p_146188_3_ > this.xPosition + this.width)
|
| 614 | {
|
| 615 | p_146188_3_ = this.xPosition + this.width;
|
| 616 | }
|
| 617 |
|
| 618 | if (p_146188_1_ > this.xPosition + this.width)
|
| 619 | {
|
| 620 | p_146188_1_ = this.xPosition + this.width;
|
| 621 | }
|
| 622 |
|
| 623 | Tessellator tessellator = Tessellator.getInstance();
|
| 624 | WorldRenderer worldrenderer = tessellator.getWorldRenderer();
|
| 625 | GlStateManager.color(0.0F, 0.0F, 255.0F, 255.0F);
|
| 626 | GlStateManager.disableTexture2D();
|
| 627 | GlStateManager.enableColorLogic();
|
| 628 | GlStateManager.colorLogicOp(5387);
|
| 629 | worldrenderer.begin(7, DefaultVertexFormats.POSITION);
|
| 630 | worldrenderer.pos((double)p_146188_1_, (double)p_146188_4_, 0.0D).endVertex();
|
| 631 | worldrenderer.pos((double)p_146188_3_, (double)p_146188_4_, 0.0D).endVertex();
|
| 632 | worldrenderer.pos((double)p_146188_3_, (double)p_146188_2_, 0.0D).endVertex();
|
| 633 | worldrenderer.pos((double)p_146188_1_, (double)p_146188_2_, 0.0D).endVertex();
|
| 634 | tessellator.draw();
|
| 635 | GlStateManager.disableColorLogic();
|
| 636 | GlStateManager.enableTexture2D();
|
| 637 | }
|
| 638 |
|
| 639 | public void setMaxStringLength(int p_146203_1_)
|
| 640 | {
|
| 641 | this.maxStringLength = p_146203_1_;
|
| 642 |
|
| 643 | if (this.text.length() > p_146203_1_)
|
| 644 | {
|
| 645 | this.text = this.text.substring(0, p_146203_1_);
|
| 646 | }
|
| 647 | }
|
| 648 |
|
| 649 | /**
|
| 650 | * returns the maximum number of character that can be contained in this textbox
|
| 651 | */
|
| 652 | public int getMaxStringLength()
|
| 653 | {
|
| 654 | return this.maxStringLength;
|
| 655 | }
|
| 656 |
|
| 657 | /**
|
| 658 | * returns the current position of the cursor
|
| 659 | */
|
| 660 | public int getCursorPosition()
|
| 661 | {
|
| 662 | return this.cursorPosition;
|
| 663 | }
|
| 664 |
|
| 665 | /**
|
| 666 | * get enable drawing background and outline
|
| 667 | */
|
| 668 | public boolean getEnableBackgroundDrawing()
|
| 669 | {
|
| 670 | return this.enableBackgroundDrawing;
|
| 671 | }
|
| 672 |
|
| 673 | /**
|
| 674 | * enable drawing background and outline
|
| 675 | */
|
| 676 | public void setEnableBackgroundDrawing(boolean p_146185_1_)
|
| 677 | {
|
| 678 | this.enableBackgroundDrawing = p_146185_1_;
|
| 679 | }
|
| 680 |
|
| 681 | /**
|
| 682 | * Sets the text colour for this textbox (disabled text will not use this colour)
|
| 683 | */
|
| 684 | public void setTextColor(int p_146193_1_)
|
| 685 | {
|
| 686 | this.enabledColor = p_146193_1_;
|
| 687 | }
|
| 688 |
|
| 689 | public void setDisabledTextColour(int p_146204_1_)
|
| 690 | {
|
| 691 | this.disabledColor = p_146204_1_;
|
| 692 | }
|
| 693 |
|
| 694 | /**
|
| 695 | * Sets focus to this gui element
|
| 696 | */
|
| 697 | public void setFocused(boolean p_146195_1_)
|
| 698 | {
|
| 699 | if (p_146195_1_ && !this.isFocused)
|
| 700 | {
|
| 701 | this.cursorCounter = 0;
|
| 702 | }
|
| 703 |
|
| 704 | this.isFocused = p_146195_1_;
|
| 705 | }
|
| 706 |
|
| 707 | /**
|
| 708 | * Getter for the focused field
|
| 709 | */
|
| 710 | public boolean isFocused()
|
| 711 | {
|
| 712 | return this.isFocused;
|
| 713 | }
|
| 714 |
|
| 715 | public void setEnabled(boolean p_146184_1_)
|
| 716 | {
|
| 717 | this.isEnabled = p_146184_1_;
|
| 718 | }
|
| 719 |
|
| 720 | /**
|
| 721 | * the side of the selection that is not the cursor, may be the same as the cursor
|
| 722 | */
|
| 723 | public int getSelectionEnd()
|
| 724 | {
|
| 725 | return this.selectionEnd;
|
| 726 | }
|
| 727 |
|
| 728 | /**
|
| 729 | * returns the width of the textbox depending on if background drawing is enabled
|
| 730 | */
|
| 731 | public int getWidth()
|
| 732 | {
|
| 733 | return this.getEnableBackgroundDrawing() ? this.width - 8 : this.width;
|
| 734 | }
|
| 735 |
|
| 736 | /**
|
| 737 | * Sets the position of the selection anchor (i.e. position the selection was started at)
|
| 738 | */
|
| 739 | public void setSelectionPos(int p_146199_1_)
|
| 740 | {
|
| 741 | int i = this.text.length();
|
| 742 |
|
| 743 | if (p_146199_1_ > i)
|
| 744 | {
|
| 745 | p_146199_1_ = i;
|
| 746 | }
|
| 747 |
|
| 748 | if (p_146199_1_ < 0)
|
| 749 | {
|
| 750 | p_146199_1_ = 0;
|
| 751 | }
|
| 752 |
|
| 753 | this.selectionEnd = p_146199_1_;
|
| 754 |
|
| 755 | if (this.fontRendererInstance != null)
|
| 756 | {
|
| 757 | if (this.lineScrollOffset > i)
|
| 758 | {
|
| 759 | this.lineScrollOffset = i;
|
| 760 | }
|
| 761 |
|
| 762 | int j = this.getWidth();
|
| 763 | String s = this.fontRendererInstance.trimStringToWidth(this.text.substring(this.lineScrollOffset), j);
|
| 764 | int k = s.length() + this.lineScrollOffset;
|
| 765 |
|
| 766 | if (p_146199_1_ == this.lineScrollOffset)
|
| 767 | {
|
| 768 | this.lineScrollOffset -= this.fontRendererInstance.trimStringToWidth(this.text, j, true).length();
|
| 769 | }
|
| 770 |
|
| 771 | if (p_146199_1_ > k)
|
| 772 | {
|
| 773 | this.lineScrollOffset += p_146199_1_ - k;
|
| 774 | }
|
| 775 | else if (p_146199_1_ <= this.lineScrollOffset)
|
| 776 | {
|
| 777 | this.lineScrollOffset -= this.lineScrollOffset - p_146199_1_;
|
| 778 | }
|
| 779 |
|
| 780 | this.lineScrollOffset = MathHelper.clamp_int(this.lineScrollOffset, 0, i);
|
| 781 | }
|
| 782 | }
|
| 783 |
|
| 784 | /**
|
| 785 | * if true the textbox can lose focus by clicking elsewhere on the screen
|
| 786 | */
|
| 787 | public void setCanLoseFocus(boolean p_146205_1_)
|
| 788 | {
|
| 789 | this.canLoseFocus = p_146205_1_;
|
| 790 | }
|
| 791 |
|
| 792 | /**
|
| 793 | * returns true if this textbox is visible
|
| 794 | */
|
| 795 | public boolean getVisible()
|
| 796 | {
|
| 797 | return this.visible;
|
| 798 | }
|
| 799 |
|
| 800 | /**
|
| 801 | * Sets whether or not this textbox is visible
|
| 802 | */
|
| 803 | public void setVisible(boolean p_146189_1_)
|
| 804 | {
|
| 805 | this.visible = p_146189_1_;
|
| 806 | }
|
| 807 | }
|
| 808 |
|