Advertisement
Guest User

Untitled

a guest
Feb 7th, 2016
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.80 KB | None | 0 0
  1.  
  2.  
  3.  
  4. public class GuiLogin
  5. extends GuiScreen {
  6. private GuiTextField username;
  7. private GuiMaskedTextField password;
  8. private LoginThread loginThread;
  9. private GuiScreen parent;
  10.  
  11. public GuiLogin(GuiScreen parent) {
  12. this.parent = parent;
  13. }
  14.  
  15. @Override
  16. public void initGui() {
  17. GuiLogin.drawString(this.fontRendererObj, "Welcome \u00a7c" + GuiLogin.mc.session.username, this.width / 2 - this.fontRendererObj.getStringWidth("Welcome " + GuiLogin.mc.session.username) / 2, this.height - 10, -1);
  18. Keyboard.enableRepeatEvents((boolean)true);
  19. this.buttonList.clear();
  20. this.buttonList.add(new GuiButton(0, this.width / 2 - 100, this.height / 4 + 92 + 12, "Login"));
  21. this.buttonList.add(new GuiButton(1, this.width / 2 - 100, this.height / 4 + 116 + 12, "Back"));
  22. this.username = new GuiTextField(0, this.fontRendererObj, this.width / 2 - 100, 60, 200, 20);
  23. this.username.setMaxStringLength(Integer.MAX_VALUE);
  24. this.username.setFocused(true);
  25. this.password = new GuiMaskedTextField(0, this.fontRendererObj, this.width / 2 - 100, 100, 200, 20);
  26. this.password.setMaxStringLength(Integer.MAX_VALUE);
  27. }
  28.  
  29. @Override
  30. public void keyTyped(char character, int keyCode) {
  31. this.username.textboxKeyTyped(character, keyCode);
  32. this.password.textboxKeyTyped(character, keyCode);
  33. if (keyCode == 15) {
  34. this.username.setFocused(!this.username.isFocused());
  35. this.password.setFocused(!this.password.isFocused());
  36. }
  37. if (keyCode == 28) {
  38. this.actionPerformed((GuiButton)this.buttonList.get(0));
  39. }
  40. }
  41.  
  42. @Override
  43. protected void mouseClicked(int mouseX, int mouseY, int mouseButton) throws IOException {
  44. super.mouseClicked(mouseX, mouseY, mouseButton);
  45. this.username.mouseClicked(mouseX, mouseY, mouseButton);
  46. this.password.mouseClicked(mouseX, mouseY, mouseButton);
  47. }
  48.  
  49. @Override
  50. public void drawScreen(int mouseX, int mouseY, float partialTicks) {
  51. this.drawDefaultBackground();
  52. GuiLogin.drawCenteredString(GuiLogin.mc.fontRendererObj, "Login", this.width / 2, 20, -1);
  53. if (this.username.getText().isEmpty()) {
  54. GuiLogin.drawString(GuiLogin.mc.fontRendererObj, "Username / E-Mail", this.width / 2 - 96, 66.0f, -7829368);
  55. }
  56. if (this.password.getText().isEmpty()) {
  57. GuiLogin.drawString(GuiLogin.mc.fontRendererObj, "Password", this.width / 2 - 96, 106.0f, -7829368);
  58. }
  59. this.username.drawTextBox();
  60. this.password.drawTextBox();
  61. GuiLogin.drawCenteredString(GuiLogin.mc.fontRendererObj, this.loginThread == null ? "Waiting" : this.loginThread.getStatus(), this.width / 2, 30, -1);
  62. GuiLogin.drawString(this.fontRendererObj, "Logged in As \u00a7c" + GuiLogin.mc.session.username, this.width / 2 - this.fontRendererObj.getStringWidth("Welcome " + GuiLogin.mc.session.username) / 2, this.height - 10, -1);
  63. super.drawScreen(mouseX, mouseY, partialTicks);
  64. }
  65.  
  66. @Override
  67. protected void actionPerformed(GuiButton button) {
  68. switch (button.id) {
  69. case 0: {
  70. if (this.username.getText().isEmpty()) break;
  71. this.loginThread = new LoginThread(this.username.getText(), this.password.getText());
  72. this.loginThread.start();
  73. break;
  74. }
  75. case 1: {
  76. mc.displayGuiScreen(this.parent);
  77. }
  78. }
  79. }
  80.  
  81. @Override
  82. public void onGuiClosed() {
  83. Keyboard.enableRepeatEvents((boolean)false);
  84. }
  85.  
  86. @Override
  87. public void updateScreen() {
  88. this.username.updateCursorCounter();
  89. this.password.updateCursorCounter();
  90. }
  91. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement