Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class GuiLogin
- extends GuiScreen {
- private GuiTextField username;
- private GuiMaskedTextField password;
- private LoginThread loginThread;
- private GuiScreen parent;
- public GuiLogin(GuiScreen parent) {
- this.parent = parent;
- }
- @Override
- public void initGui() {
- 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);
- Keyboard.enableRepeatEvents((boolean)true);
- this.buttonList.clear();
- this.buttonList.add(new GuiButton(0, this.width / 2 - 100, this.height / 4 + 92 + 12, "Login"));
- this.buttonList.add(new GuiButton(1, this.width / 2 - 100, this.height / 4 + 116 + 12, "Back"));
- this.username = new GuiTextField(0, this.fontRendererObj, this.width / 2 - 100, 60, 200, 20);
- this.username.setMaxStringLength(Integer.MAX_VALUE);
- this.username.setFocused(true);
- this.password = new GuiMaskedTextField(0, this.fontRendererObj, this.width / 2 - 100, 100, 200, 20);
- this.password.setMaxStringLength(Integer.MAX_VALUE);
- }
- @Override
- public void keyTyped(char character, int keyCode) {
- this.username.textboxKeyTyped(character, keyCode);
- this.password.textboxKeyTyped(character, keyCode);
- if (keyCode == 15) {
- this.username.setFocused(!this.username.isFocused());
- this.password.setFocused(!this.password.isFocused());
- }
- if (keyCode == 28) {
- this.actionPerformed((GuiButton)this.buttonList.get(0));
- }
- }
- @Override
- protected void mouseClicked(int mouseX, int mouseY, int mouseButton) throws IOException {
- super.mouseClicked(mouseX, mouseY, mouseButton);
- this.username.mouseClicked(mouseX, mouseY, mouseButton);
- this.password.mouseClicked(mouseX, mouseY, mouseButton);
- }
- @Override
- public void drawScreen(int mouseX, int mouseY, float partialTicks) {
- this.drawDefaultBackground();
- GuiLogin.drawCenteredString(GuiLogin.mc.fontRendererObj, "Login", this.width / 2, 20, -1);
- if (this.username.getText().isEmpty()) {
- GuiLogin.drawString(GuiLogin.mc.fontRendererObj, "Username / E-Mail", this.width / 2 - 96, 66.0f, -7829368);
- }
- if (this.password.getText().isEmpty()) {
- GuiLogin.drawString(GuiLogin.mc.fontRendererObj, "Password", this.width / 2 - 96, 106.0f, -7829368);
- }
- this.username.drawTextBox();
- this.password.drawTextBox();
- GuiLogin.drawCenteredString(GuiLogin.mc.fontRendererObj, this.loginThread == null ? "Waiting" : this.loginThread.getStatus(), this.width / 2, 30, -1);
- 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);
- super.drawScreen(mouseX, mouseY, partialTicks);
- }
- @Override
- protected void actionPerformed(GuiButton button) {
- switch (button.id) {
- case 0: {
- if (this.username.getText().isEmpty()) break;
- this.loginThread = new LoginThread(this.username.getText(), this.password.getText());
- this.loginThread.start();
- break;
- }
- case 1: {
- mc.displayGuiScreen(this.parent);
- }
- }
- }
- @Override
- public void onGuiClosed() {
- Keyboard.enableRepeatEvents((boolean)false);
- }
- @Override
- public void updateScreen() {
- this.username.updateCursorCounter();
- this.password.updateCursorCounter();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement