Use new Gui API for GuiLoginPrompt and GuiRegister

This commit is contained in:
johni0702
2015-07-08 16:18:46 +02:00
parent db8b5a9be0
commit d4e04feaeb
5 changed files with 215 additions and 373 deletions

View File

@@ -45,7 +45,7 @@ public class GuiEventHandler {
if(ReplayMod.firstMainMenu) {
ReplayMod.firstMainMenu = false;
if(!AuthenticationHandler.isAuthenticated()) {
event.gui = new GuiLoginPrompt(event.gui, event.gui);
event.gui = new GuiLoginPrompt(event.gui, event.gui).toMinecraft();
return;
}
} else {
@@ -155,7 +155,7 @@ public class GuiEventHandler {
if(AuthenticationHandler.isAuthenticated()) {
mc.displayGuiScreen(new GuiReplayCenter());
} else {
mc.displayGuiScreen(new GuiLoginPrompt(event.gui, new GuiReplayCenter()));
mc.displayGuiScreen(new GuiLoginPrompt(event.gui, new GuiReplayCenter()).toMinecraft());
}
} else if(event.button.id == GuiConstants.REPLAY_EDITOR_BUTTON_ID) {
mc.displayGuiScreen(new GuiReplayEditor());

View File

@@ -1,204 +1,117 @@
package eu.crushedpixel.replaymod.gui.online;
import eu.crushedpixel.replaymod.gui.GuiConstants;
import eu.crushedpixel.replaymod.gui.PasswordTextField;
import de.johni0702.minecraft.gui.container.AbstractGuiScreen;
import de.johni0702.minecraft.gui.element.GuiButton;
import de.johni0702.minecraft.gui.element.GuiLabel;
import de.johni0702.minecraft.gui.element.GuiPasswordField;
import de.johni0702.minecraft.gui.element.GuiTextField;
import de.johni0702.minecraft.gui.layout.CustomLayout;
import eu.crushedpixel.replaymod.online.authentication.AuthenticationHandler;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.GuiButton;
import net.minecraft.client.gui.GuiScreen;
import net.minecraft.client.gui.GuiTextField;
import net.minecraft.client.resources.I18n;
import org.lwjgl.input.Keyboard;
import java.awt.*;
import java.io.IOException;
import java.util.List;
public class GuiLoginPrompt extends AbstractGuiScreen<GuiLoginPrompt> {
public class GuiLoginPrompt extends GuiScreen {
private final net.minecraft.client.gui.GuiScreen parent, successScreen;
private static final int EMPTY = 0;
private static final int LOGGING_IN = 1;
private static final int INVALID_LOGIN = 2;
private static final int NO_CONNECTION = 3;
private static Minecraft mc = Minecraft.getMinecraft();
private GuiScreen parent, successScreen;
private int textState = 0;
private GuiTextField username;
private PasswordTextField password;
private GuiButton loginButton;
private GuiButton cancelButton;
private GuiButton registerButton;
private GuiLabel usernameLabel = new GuiLabel(this).setI18nText("replaymod.gui.username");
private GuiLabel passwordLabel = new GuiLabel(this).setI18nText("replaymod.gui.password");
private GuiLabel noAccountLabel = new GuiLabel(this).setI18nText("replaymod.gui.login.noacc");
private GuiLabel statusLabel = new GuiLabel(this);
private GuiButton loginButton = new GuiButton(this).setI18nLabel("replaymod.gui.login").setWidth(150).setEnabled(false);
private GuiButton cancelButton = new GuiButton(this).setI18nLabel("replaymod.gui.cancel").setWidth(150);
private GuiButton registerButton = new GuiButton(this).setI18nLabel("replaymod.gui.register").setWidth(150);
private GuiTextField username = new GuiTextField(this).setSize(145, 20).setMaxLength(16).setFocused(true);
private GuiPasswordField password = new GuiPasswordField(this).setSize(145, 20).setNext(username).setPrevious(username);
private String noacc;
private int strwidth;
private boolean initialized = false;
public GuiScreen getSuccessScreen() {
return successScreen;
}
public GuiLoginPrompt(GuiScreen parent, GuiScreen successScreen) {
this.parent = parent;
this.successScreen = successScreen;
}
@Override
public void initGui() {
Keyboard.enableRepeatEvents(true);
if(!initialized) {
username = new GuiTextField(GuiConstants.LOGIN_USERNAME_FIELD, fontRendererObj, this.width / 2 - 45, 30, 145, 20);
username.setEnabled(true);
username.setFocused(true);
username.setMaxStringLength(16);
password = new PasswordTextField(GuiConstants.LOGIN_PASSWORD_FIELD, fontRendererObj, this.width / 2 - 45, 60, 145, 20);
password.setEnabled(true);
password.setFocused(false);
loginButton = new GuiButton(GuiConstants.LOGIN_OKAY_BUTTON, this.width / 2 - 150 - 2, 110, I18n.format("replaymod.gui.login"));
loginButton.enabled = false;
loginButton.width = 150;
cancelButton = new GuiButton(GuiConstants.LOGIN_CANCEL_BUTTON, this.width / 2 + 2, 110, I18n.format("replaymod.gui.cancel"));
cancelButton.width = 150;
registerButton = new GuiButton(GuiConstants.LOGIN_REGISTER_BUTTON, 0, this.height-30, I18n.format("replaymod.gui.register"));
registerButton.width = 150;
} else {
username.xPosition = password.xPosition = this.width / 2 - 45;
loginButton.xPosition = this.width / 2 - 150 - 2;
cancelButton.xPosition = this.width / 2 + 2;
registerButton.yPosition = this.height-30;
}
noacc = I18n.format("replaymod.gui.login.noacc");
strwidth = fontRendererObj.getStringWidth(noacc);
int tw = 150+5+strwidth;
registerButton.xPosition = (width/2) - (tw/2) + strwidth+5;
@SuppressWarnings("unchecked")
List<GuiButton> buttonList = this.buttonList;
buttonList.add(loginButton);
buttonList.add(cancelButton);
buttonList.add(registerButton);
initialized = true;
}
@Override
protected void actionPerformed(GuiButton button) throws IOException {
if(button.id == GuiConstants.LOGIN_OKAY_BUTTON) {
if(button.enabled) {
//Authenticate
textState = LOGGING_IN;
{
Runnable doLogin = new Runnable() {
@Override
public void run() {
if (!loginButton.isEnabled()) return;
statusLabel.setI18nText("replaymod.gui.login.logging");
new Thread(new Runnable() {
@Override
public void run() {
switch(AuthenticationHandler.authenticate(username.getText(), password.getText())) {
case AuthenticationHandler.SUCCESS:
textState = EMPTY;
mc.addScheduledTask(new Runnable() {
statusLabel.setText("");
getMinecraft().addScheduledTask(new Runnable() {
@Override
public void run() {
mc.displayGuiScreen(successScreen);
getMinecraft().displayGuiScreen(successScreen);
}
});
break;
case AuthenticationHandler.INVALID:
textState = INVALID_LOGIN;
statusLabel.setI18nText("replaymod.gui.login.incorrect");
break;
case AuthenticationHandler.NO_CONNECTION:
textState = NO_CONNECTION;
statusLabel.setI18nText("replaymod.gui.login.connectionerror");
break;
}
}
}, "replaymod-auth").start();
}
} else if(button.id == GuiConstants.LOGIN_CANCEL_BUTTON) {
mc.displayGuiScreen(parent);
} else if(button.id == GuiConstants.LOGIN_REGISTER_BUTTON) {
mc.displayGuiScreen(new GuiRegister(this));
}
}
private String usernameLabel = I18n.format("replaymod.gui.username");
private String passwordLabel = I18n.format("replaymod.gui.password");
@Override
public void drawScreen(int mouseX, int mouseY, float partialTicks) {
this.drawDefaultBackground();
drawCenteredString(fontRendererObj, I18n.format("replaymod.gui.login.title"), this.width / 2, 10, Color.WHITE.getRGB());
drawString(fontRendererObj, usernameLabel, username.xPosition-10-fontRendererObj.getStringWidth(usernameLabel),
37, Color.WHITE.getRGB());
username.drawTextBox();
drawString(fontRendererObj, passwordLabel, password.xPosition-10-fontRendererObj.getStringWidth(passwordLabel),
67, Color.WHITE.getRGB());
password.drawTextBox();
switch(textState) {
case INVALID_LOGIN:
drawCenteredString(fontRendererObj, I18n.format("replaymod.gui.login.incorrect"), this.width / 2, 92, Color.RED.getRGB());
break;
case LOGGING_IN:
drawCenteredString(fontRendererObj, I18n.format("replaymod.gui.login.logging"), this.width / 2, 92, Color.WHITE.getRGB());
break;
case NO_CONNECTION:
drawCenteredString(fontRendererObj, I18n.format("replaymod.gui.login.connectionerror"), this.width / 2, 92, Color.RED.getRGB());
break;
}
int tw = 150+5+strwidth;
drawString(fontRendererObj, noacc, this.width / 2 - (tw/2), this.height-22, Color.WHITE.getRGB());
super.drawScreen(mouseX, mouseY, partialTicks);
}
@Override
public void mouseClicked(int mouseX, int mouseY, int mouseButton) throws IOException {
super.mouseClicked(mouseX, mouseY, mouseButton);
username.mouseClicked(mouseX, mouseY, mouseButton);
password.mouseClicked(mouseX, mouseY, mouseButton);
}
@Override
public void updateScreen() {
username.updateCursorCounter();
password.updateCursorCounter();
}
@Override
public void onGuiClosed() {
Keyboard.enableRepeatEvents(false);
}
@Override
protected void keyTyped(char typedChar, int keyCode) throws IOException {
if(keyCode == Keyboard.KEY_TAB) {
if(password.isFocused()) {
password.setFocused(false);
username.setFocused(true);
} else {
username.setFocused(false);
password.setFocused(true);
};
username.onEnter(doLogin);
password.onEnter(doLogin);
loginButton.onClick(doLogin);
cancelButton.onClick(new Runnable() {
@Override
public void run() {
getMinecraft().displayGuiScreen(parent);
}
return;
} else if(keyCode == Keyboard.KEY_RETURN) {
actionPerformed(loginButton);
return;
}
if(username.isFocused()) {
username.textboxKeyTyped(typedChar, keyCode);
} else if(password.isFocused()) {
password.textboxKeyTyped(typedChar, keyCode);
}
loginButton.enabled = username.getText().length() > 0 && password.getText().length() > 0;
});
registerButton.onClick(new Runnable() {
@Override
public void run() {
new GuiRegister(GuiLoginPrompt.this).display();
}
});
Runnable contentValidation = new Runnable() {
@Override
public void run() {
loginButton.setEnabled(!username.getText().isEmpty() && !password.getText().isEmpty());
}
};
username.onTextChanged(contentValidation);
password.onTextChanged(contentValidation);
}
super.keyTyped(typedChar, keyCode);
public GuiLoginPrompt(net.minecraft.client.gui.GuiScreen parent, net.minecraft.client.gui.GuiScreen successScreen) {
this.parent = parent;
this.successScreen = successScreen;
setLayout(new CustomLayout<GuiLoginPrompt>() {
@Override
protected void layout(GuiLoginPrompt container, int width, int height) {
pos(username, width / 2 - 45, 30);
pos(password, width / 2 - 45, 60);
pos(loginButton, width / 2 - 152, 110);
pos(cancelButton, width / 2 + 2, 110);
pos(usernameLabel, x(username) - 10 - usernameLabel.getMinSize().getWidth(), y(username) + 7);
pos(passwordLabel, x(password) - 10 - passwordLabel.getMinSize().getWidth(), y(password) + 7);
pos(statusLabel, width / 2 - statusLabel.getMinSize().getWidth() / 2, 92);
int labelWidth = noAccountLabel.getMinSize().getWidth();
int buttonWidth = registerButton.getPreferredSize().getWidth();
int lineWidth = labelWidth + 5 + buttonWidth;
int lineStart = width / 2 - lineWidth / 2;
pos(noAccountLabel, lineStart, height - 22);
pos(registerButton, lineStart + labelWidth + 5, height - 30);
}
});
setTitle(new GuiLabel().setI18nText("replaymod.gui.login.title"));
}
public net.minecraft.client.gui.GuiScreen getSuccessScreen() {
return successScreen;
}
@Override
protected GuiLoginPrompt getThis() {
return this;
}
}

View File

@@ -1,216 +1,145 @@
package eu.crushedpixel.replaymod.gui.online;
import com.mojang.authlib.exceptions.AuthenticationException;
import de.johni0702.minecraft.gui.container.AbstractGuiScreen;
import de.johni0702.minecraft.gui.container.GuiPanel;
import de.johni0702.minecraft.gui.element.*;
import de.johni0702.minecraft.gui.layout.CustomLayout;
import de.johni0702.minecraft.gui.layout.HorizontalLayout;
import de.johni0702.minecraft.gui.layout.VerticalLayout;
import eu.crushedpixel.replaymod.api.ApiException;
import eu.crushedpixel.replaymod.gui.GuiConstants;
import eu.crushedpixel.replaymod.gui.PasswordTextField;
import eu.crushedpixel.replaymod.online.authentication.AuthenticationHandler;
import eu.crushedpixel.replaymod.utils.EmailAddressUtils;
import net.minecraft.client.gui.GuiButton;
import net.minecraft.client.gui.GuiScreen;
import net.minecraft.client.gui.GuiTextField;
import net.minecraft.client.resources.I18n;
import org.lwjgl.input.Keyboard;
import org.lwjgl.util.ReadableColor;
import java.awt.*;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
public class GuiRegister extends AbstractGuiScreen<GuiRegister> {
private final GuiPanel inputs;
private final GuiTextField usernameInput, mailInput;
private final GuiPasswordField passwordInput, passwordConfirmation;
private final GuiButton registerButton = new GuiButton(this).setI18nLabel("replaymod.gui.register").setWidth(150).setDisabled();
private final GuiButton cancelButton = new GuiButton(this).setI18nLabel("replaymod.gui.cancel").setWidth(150);
private final GuiLabel statusLabel = new GuiLabel(this).setColor(ReadableColor.RED);
public class GuiRegister extends GuiScreen {
private String message = null;
{
inputs = new GuiPanel(this).setLayout(new VerticalLayout().setSpacing(10));
HorizontalLayout.Data data = new HorizontalLayout.Data(0, VerticalLayout.Alignment.CENTER);
inputs.addElements(new VerticalLayout.Data(0, HorizontalLayout.Alignment.RIGHT),
new GuiPanel().setLayout(new HorizontalLayout(HorizontalLayout.Alignment.RIGHT).setSpacing(10))
.addElements(data, new GuiLabel().setI18nText("replaymod.gui.username"))
.addElements(data, usernameInput = new GuiTextField().setMaxLength(16).setSize(145, 20)),
new GuiPanel().setLayout(new HorizontalLayout(HorizontalLayout.Alignment.RIGHT).setSpacing(10))
.addElements(data, new GuiLabel().setI18nText("replaymod.gui.mail"))
.addElements(data, mailInput = new GuiTextField().setSize(145, 20)),
new GuiPanel().setLayout(new HorizontalLayout(HorizontalLayout.Alignment.RIGHT).setSpacing(10))
.addElements(data, new GuiLabel().setI18nText("replaymod.gui.password"))
.addElements(data, passwordInput = new GuiPasswordField().setMaxLength(32).setSize(145, 20)),
new GuiPanel().setLayout(new HorizontalLayout(HorizontalLayout.Alignment.RIGHT).setSpacing(10))
.addElements(data, new GuiLabel().setI18nText("replaymod.gui.register.confirmpw"))
.addElements(data, passwordConfirmation = new GuiPasswordField().setMaxLength(32).setSize(145, 20))
);
usernameInput.setNext(mailInput)
.getNext().setNext(passwordInput)
.getNext().setNext(passwordConfirmation)
.getNext().setNext(usernameInput);
private GuiTextField usernameInput, mailInput;
private PasswordTextField passwordInput, passwordConfirmation;
private GuiButton registerButton, cancelButton;
setLayout(new CustomLayout<GuiRegister>() {
@Override
protected void layout(GuiRegister container, int width, int height) {
pos(inputs, width / 2 - inputs.getMinSize().getWidth() / 2, 30);
pos(registerButton, width / 2 - 152, 170);
pos(cancelButton, width / 2 + 2, 170);
pos(statusLabel, width / 2 - statusLabel.getMinSize().getWidth() / 2, 152);
}
});
private boolean initialized = false;
setTitle(new GuiLabel().setI18nText("replaymod.gui.register.title"));
private String[] labels = new String[]{I18n.format("replaymod.gui.username"), I18n.format("replaymod.gui.mail"), I18n.format("replaymod.gui.password"),
I18n.format("replaymod.gui.register.confirmpw")};
Runnable doRegister = new Runnable() {
@Override
public void run() {
if (!registerButton.isEnabled()) return;
private List<GuiTextField> inputFields;
inputs.forEach(IGuiTextField.class).setDisabled();
statusLabel.setI18nText("replaymod.gui.login.logging");
private GuiLoginPrompt parent = null;
new Thread(new Runnable() {
@Override
public void run() {
try {
String username = usernameInput.getText().trim();
String mail = mailInput.getText().trim();
String password = passwordInput.getText();
AuthenticationHandler.register(username, mail, password);
getMinecraft().addScheduledTask(new Runnable() {
@Override
public void run() {
getMinecraft().displayGuiScreen(parent.getSuccessScreen());
}
});
} catch (ApiException ae) {
statusLabel.setText(ae.getLocalizedMessage());
} catch (AuthenticationException aue) {
aue.printStackTrace();
statusLabel.setI18nText("replaymod.gui.register.error.authfailed");
} catch (Exception e) {
e.printStackTrace();
statusLabel.setI18nText("replaymod.gui.login.connectionerror");
} finally {
inputs.forEach(IGuiTextField.class).setEnabled();
}
}
}, "replaymod-register").start();
}
};
inputs.forEach(IGuiTextField.class).onEnter(doRegister);
registerButton.onClick(doRegister);
Runnable contentValidation = new Runnable() {
@Override
public void run() {
String status = null;
if (usernameInput.getText().length() < 5) {
status = "replaymod.gui.register.error.shortusername";
} else if (passwordInput.getText().length() < 5) {
status = "replaymod.gui.register.error.shortpw";
} else if (!EmailAddressUtils.isValidEmailAddress(mailInput.getText())) {
status = "replaymod.api.invalidmail";
} else if (!passwordConfirmation.getText().equals(passwordInput.getText())) {
status = "replaymod.gui.register.error.nomatch";
}
registerButton.setEnabled(status == null);
if (status != null
&& !usernameInput.getText().isEmpty()
&& !mailInput.getText().isEmpty()
&& !passwordInput.getText().isEmpty()
&& !passwordConfirmation.getText().isEmpty()) {
statusLabel.setI18nText(status);
} else {
statusLabel.setText("");
}
}
};
inputs.forEach(IGuiTextField.class).onTextChanged(contentValidation);
cancelButton.onClick(new Runnable() {
@Override
public void run() {
parent.display();
}
});
}
private GuiLoginPrompt parent;
public GuiRegister(GuiLoginPrompt parent) {
this.parent = parent;
}
@Override
public void initGui() {
Keyboard.enableRepeatEvents(true);
if(!initialized) {
usernameInput = new GuiTextField(GuiConstants.REGISTER_USERNAME_FIELD, fontRendererObj, this.width / 2 - 45, 30, 145, 20);
usernameInput.setMaxStringLength(16);
mailInput = new GuiTextField(GuiConstants.REGISTER_MAIL_FIELD, fontRendererObj, this.width / 2 - 45, 60, 145, 20);
passwordInput = new PasswordTextField(GuiConstants.REGISTER_PASSWORD_FIELD, fontRendererObj, this.width / 2 - 45, 90, 145, 20);
passwordConfirmation = new PasswordTextField(GuiConstants.REGISTER_PASSWORD_CONFIRM_FIELD, fontRendererObj, this.width / 2 - 45, 120, 145, 20);
passwordInput.setMaxStringLength(32);
passwordConfirmation.setMaxStringLength(32);
registerButton = new GuiButton(GuiConstants.REGISTER_OKAY_BUTTON, this.width / 2 - 150 - 2, 170, I18n.format("replaymod.gui.register"));
registerButton.enabled = false;
registerButton.width = 150;
cancelButton = new GuiButton(GuiConstants.REGISTER_CANCEL_BUTTON, this.width / 2 + 2, 170, I18n.format("replaymod.gui.cancel"));
cancelButton.width = 150;
} else {
usernameInput.xPosition = mailInput.xPosition = passwordInput.xPosition = passwordConfirmation.xPosition = this.width / 2 - 45;
}
inputFields = new ArrayList<GuiTextField>();
inputFields.add(usernameInput);
inputFields.add(mailInput);
inputFields.add(passwordInput);
inputFields.add(passwordConfirmation);
int strwidth = Math.max(Math.max(fontRendererObj.getStringWidth(labels[0]), fontRendererObj.getStringWidth(labels[1])),
Math.max(fontRendererObj.getStringWidth(labels[2]), fontRendererObj.getStringWidth(labels[3])));
int totalwidth = 145 + 10 + strwidth;
for(GuiTextField f : inputFields)
f.xPosition = (width/2) - (totalwidth /2) + strwidth +5;
@SuppressWarnings("unchecked")
List<GuiButton> buttonList = this.buttonList;
buttonList.add(registerButton);
buttonList.add(cancelButton);
initialized = true;
}
@Override
public void drawScreen(int mouseX, int mouseY, float partialTicks) {
this.drawDefaultBackground();
drawCenteredString(fontRendererObj, I18n.format("replaymod.gui.register.title"), this.width / 2, 10, Color.WHITE.getRGB());
for(GuiTextField f : inputFields) {
f.drawTextBox();
}
int i = 0;
for(String label : labels) {
drawString(fontRendererObj, label, inputFields.get(i).xPosition-10-fontRendererObj.getStringWidth(label),
37+(i*30), Color.WHITE.getRGB());
i++;
}
if(message != null) {
drawCenteredString(fontRendererObj, message, this.width / 2, 152, Color.RED.getRGB());
}
super.drawScreen(mouseX, mouseY, partialTicks);
}
@Override
public void mouseClicked(int mouseX, int mouseY, int mouseButton) throws IOException {
super.mouseClicked(mouseX, mouseY, mouseButton);
for(GuiTextField f : inputFields) {
f.mouseClicked(mouseX, mouseY, mouseButton);
}
}
@Override
public void updateScreen() {
for(GuiTextField f : inputFields) {
f.updateCursorCounter();
}
}
@Override
protected void keyTyped(char typedChar, int keyCode) throws IOException {
if(keyCode == Keyboard.KEY_TAB) {
int i = 0;
for(GuiTextField f : inputFields) {
if(f.isFocused()) {
i = inputFields.indexOf(f);
f.setFocused(false);
}
}
if(i == inputFields.size()-1) {
i = 0;
} else {
i++;
}
inputFields.get(i).setFocused(true);
} else if(keyCode == Keyboard.KEY_RETURN) {
actionPerformed(registerButton);
return;
}
for(GuiTextField f : inputFields) {
if(f.isFocused()) f.textboxKeyTyped(typedChar, keyCode);
}
registerButton.enabled = usernameInput.getText().length() >= 5 && EmailAddressUtils.isValidEmailAddress(mailInput.getText())
&& passwordInput.getText().length() >= 5 && passwordConfirmation.getText().equals(passwordInput.getText());
//only show message if user has filled out every text field
if(!registerButton.enabled && usernameInput.getText().length() > 0 && mailInput.getText().length() > 0
&& passwordInput.getText().length() > 0 && passwordConfirmation.getText().length() > 0) {
if(usernameInput.getText().length() < 5) {
message = I18n.format("replaymod.gui.register.error.shortusername");
} else if(!EmailAddressUtils.isValidEmailAddress(mailInput.getText())) {
message = I18n.format("replaymod.api.invalidmail");
} else if(!(passwordInput.getText().length() >= 5)) {
message = I18n.format("replaymod.gui.register.error.shortpw");
} else if(!passwordConfirmation.getText().equals(passwordInput.getText())) {
message = I18n.format("replaymod.gui.register.error.nomatch");
}
} else {
message = null;
}
super.keyTyped(typedChar, keyCode);
}
@Override
public void onGuiClosed() {
Keyboard.enableRepeatEvents(false);
}
@Override
protected void actionPerformed(GuiButton button) {
if(!button.enabled) return;
switch(button.id) {
case GuiConstants.REGISTER_CANCEL_BUTTON:
mc.displayGuiScreen(parent);
break;
case GuiConstants.REGISTER_OKAY_BUTTON:
message = I18n.format("replaymod.gui.login.logging");
new Thread(new Runnable() {
@Override
public void run() {
try {
AuthenticationHandler.register(usernameInput.getText().trim(),
mailInput.getText().trim(), passwordInput.getText());
mc.addScheduledTask(new Runnable() {
@Override
public void run() {
mc.displayGuiScreen(parent.getSuccessScreen());
}
});
} catch(ApiException ae) {
message = ae.getLocalizedMessage();
} catch(AuthenticationException aue) {
aue.printStackTrace();
message = I18n.format("replaymod.gui.register.error.authfailed");
} catch(Exception e) {
e.printStackTrace();
message = I18n.format("replaymod.gui.login.connectionerror");
}
}
}, "replaymod-register").start();
break;
}
protected GuiRegister getThis() {
return this;
}
}

View File

@@ -57,7 +57,7 @@ public class GuiReplayCenter extends GuiScreen implements GuiYesNoCallback {
if(!initialized) {
if(!AuthenticationHandler.isAuthenticated()) {
mc.displayGuiScreen(new GuiLoginPrompt(new GuiMainMenu(), this));
mc.displayGuiScreen(new GuiLoginPrompt(new GuiMainMenu(), this).toMinecraft());
}
//Top Button Bar

View File

@@ -142,7 +142,7 @@ public class GuiUploadFile extends GuiScreen implements ProgressUpdateListener {
}
if(!AuthenticationHandler.isAuthenticated()) {
mc.displayGuiScreen(new GuiLoginPrompt(parent, this));
mc.displayGuiScreen(new GuiLoginPrompt(parent, this).toMinecraft());
return;
}