Added basic (and functional!) Login screen

Metadata now ignores the Forge part of the Minecraft version String
This commit is contained in:
Marius Metzger
2015-01-28 13:20:03 +01:00
parent d31180654f
commit 4659abc98e
9 changed files with 283 additions and 30 deletions

View File

@@ -0,0 +1,15 @@
package eu.crushedpixel.replaymod.gui;
public class GuiConstants {
public static final int REPLAY_OPTIONS_BUTTON_ID = 8000;
public static final int REPLAY_MANAGER_BUTTON_ID = 9001;
public static final int REPLAY_CENTER_BUTTON_ID = 1000;
public static final int REPLAY_CENTER_LOGIN_TEXT_ID = 1001;
public static final int REPLAY_CENTER_PASSWORD_TEXT_ID = 1002;
public static final int LOGIN_OKAY_BUTTON = 1100;
public static final int LOGIN_CANCEL_BUTTON = 1101;
}

View File

@@ -0,0 +1,46 @@
package eu.crushedpixel.replaymod.gui;
import java.lang.reflect.Field;
import eu.crushedpixel.replaymod.reflection.MCPNames;
import net.minecraft.client.gui.FontRenderer;
import net.minecraft.client.gui.GuiTextField;
public class PasswordTextField extends GuiTextField {
private static Field text;
static {
try {
text = GuiTextField.class.getDeclaredField(MCPNames.field("field_146216_j"));
text.setAccessible(true);
} catch(Exception e) {
e.printStackTrace();
}
}
public PasswordTextField(int p_i45542_1_, FontRenderer p_i45542_2_,
int p_i45542_3_, int p_i45542_4_, int p_i45542_5_, int p_i45542_6_) {
super(p_i45542_1_, p_i45542_2_, p_i45542_3_, p_i45542_4_, p_i45542_5_,
p_i45542_6_);
}
@Override
public void drawTextBox() {
String prev = getText();
String pw = "";
for(int i=0; i<prev.length(); i++) {
pw += "*";
}
try {
text.set(this, pw);
super.drawTextBox();
text.set(this, prev);
} catch(Exception e) {}
}
}

View File

@@ -0,0 +1,164 @@
package eu.crushedpixel.replaymod.gui.online;
import java.awt.Color;
import java.io.IOException;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.GuiButton;
import net.minecraft.client.gui.GuiScreen;
import net.minecraft.client.gui.GuiTextField;
import org.lwjgl.input.Keyboard;
import eu.crushedpixel.replaymod.gui.GuiConstants;
import eu.crushedpixel.replaymod.gui.PasswordTextField;
import eu.crushedpixel.replaymod.online.authentication.AuthenticationHandler;
public class GuiLoginPrompt extends GuiScreen {
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 GuiScreen parent, successScreen;
private int textState = 0;
private static Minecraft mc = Minecraft.getMinecraft();
private GuiTextField username;
private PasswordTextField password;
private GuiButton loginButton;
private GuiButton cancelButton;
public GuiLoginPrompt(GuiScreen parent, GuiScreen successScreen) {
this.parent = parent;
this.successScreen = successScreen;
}
@Override
public void initGui() {
Keyboard.enableRepeatEvents(true);
username = new GuiTextField(GuiConstants.REPLAY_CENTER_LOGIN_TEXT_ID, fontRendererObj, this.width/2 - 45, 30, 145, 20);
username.setEnabled(true);
username.setFocused(true);
password = new PasswordTextField(GuiConstants.REPLAY_CENTER_PASSWORD_TEXT_ID, 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, "Login");
loginButton.width = 150;
loginButton.enabled = false;
buttonList.add(loginButton);
cancelButton = new GuiButton(GuiConstants.LOGIN_CANCEL_BUTTON, this.width/2 + 2, 110, "Cancel");
cancelButton.width = 150;
buttonList.add(cancelButton);
}
@Override
protected void actionPerformed(GuiButton button) throws IOException {
if(button.id == GuiConstants.LOGIN_OKAY_BUTTON) {
if(button.enabled) {
//Authenticate
textState = LOGGING_IN;
Thread loginThread = new Thread(new Runnable() {
@Override
public void run() {
switch(AuthenticationHandler.authenticate(username.getText(), password.getText())) {
case AuthenticationHandler.SUCCESS:
textState = EMPTY;
mc.displayGuiScreen(successScreen);
break;
case AuthenticationHandler.INVALID:
textState = INVALID_LOGIN;
break;
case AuthenticationHandler.NO_CONNECTION:
textState = NO_CONNECTION;
break;
}
}
});
loginThread.start();
}
} else if(button.id == GuiConstants.LOGIN_CANCEL_BUTTON) {
mc.displayGuiScreen(parent);
}
}
private int lastMouseX, lastMouseY;
private float lastPartialTicks;
@Override
public void drawScreen(int mouseX, int mouseY, float partialTicks) {
lastMouseX = mouseX;
lastMouseY = mouseY;
lastPartialTicks = partialTicks;
this.drawDefaultBackground();
drawCenteredString(fontRendererObj, "Login to ReplayMod.com", this.width/2, 10, Color.WHITE.getRGB());
drawString(fontRendererObj, "Username", this.width/2 - 100, 37, Color.WHITE.getRGB());
username.drawTextBox();
drawString(fontRendererObj, "Password", this.width/2 - 100, 67, Color.WHITE.getRGB());
password.drawTextBox();
switch(textState) {
case INVALID_LOGIN:
drawCenteredString(fontRendererObj, "Incorrect username or password.", this.width/2, 92, Color.RED.getRGB());
break;
case LOGGING_IN:
drawCenteredString(fontRendererObj, "Logging in...", this.width/2, 92, Color.WHITE.getRGB());
break;
}
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);
}
return;
}
if(keyCode == 28) { //Enter key
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;
}
}

View File

@@ -0,0 +1,7 @@
package eu.crushedpixel.replaymod.gui.online;
import net.minecraft.client.gui.GuiScreen;
public class GuiReplayCenter extends GuiScreen {
}

View File

@@ -89,15 +89,7 @@ public class GuiReplayManager extends GuiScreen implements GuiYesNoCallback {
BufferedImage bimg = ImageIO.read(is);
if(bimg != null) {
img = ImageUtils.scaleImage(bimg, new Dimension(1280, 720));
}
/* Old way of reading thumbnail
else {
is = archive.getInputStream(image);
bimg = ImageIO.read(is);
img = ImageUtils.scaleImage(bimg, new Dimension(1280, 720));
}
*/
}
InputStream is = archive.getInputStream(metadata);
@@ -136,8 +128,8 @@ public class GuiReplayManager extends GuiScreen implements GuiYesNoCallback {
}
public void initGui()
{
@Override
public void initGui() {
replayGuiList = new GuiReplayListExtended(this, this.mc, this.width, this.height, 32, this.height - 64, 36);
Keyboard.enableRepeatEvents(true);
this.buttonList.clear();