split char gui
This commit is contained in:
parent
1b9ef61599
commit
5e20c6f90d
10 changed files with 105 additions and 29 deletions
129
java/src/game/gui/server/GuiConnect.java
Normal file
129
java/src/game/gui/server/GuiConnect.java
Normal file
|
@ -0,0 +1,129 @@
|
|||
package game.gui.server;
|
||||
|
||||
import game.color.TextColor;
|
||||
import game.gui.Gui;
|
||||
import game.gui.GuiMenu;
|
||||
import game.gui.element.ActButton;
|
||||
import game.gui.element.Label;
|
||||
import game.gui.element.Textbox;
|
||||
import game.gui.element.Textbox.Action;
|
||||
import game.init.Config;
|
||||
import game.network.Player;
|
||||
import game.vars.CVarCategory;
|
||||
import game.vars.Variable;
|
||||
|
||||
public class GuiConnect extends Gui implements Textbox.Callback {
|
||||
public static final GuiConnect INSTANCE = new GuiConnect();
|
||||
|
||||
private GuiConnect() {
|
||||
}
|
||||
|
||||
private Textbox addrBox;
|
||||
private Textbox portBox;
|
||||
private Textbox userBox;
|
||||
private Textbox passBox;
|
||||
private Textbox accBox;
|
||||
private Label addrLabel;
|
||||
private Label portLabel;
|
||||
private Label userLabel;
|
||||
private Label passLabel;
|
||||
private Label accLabel;
|
||||
|
||||
@Variable(name = "srv_last_address", category = CVarCategory.SYSTEM, min = 1, max = 128, display = "Letzte Server-Adresse")
|
||||
private String lastAddr = "";
|
||||
@Variable(name = "srv_last_port", category = CVarCategory.SYSTEM, min = 0, max = 65535, display = "Letzter Server-Port")
|
||||
private int lastPort = Config.PORT;
|
||||
@Variable(name = "srv_last_user", category = CVarCategory.SYSTEM, max = Player.MAX_USER_LENGTH, display = "Letzter Server-Nutzer", validator = Player.UserValidator.class)
|
||||
private String lastUser = "";
|
||||
@Variable(name = "srv_last_password", category = CVarCategory.SYSTEM, max = Player.MAX_PASS_LENGTH, display = "Letztes Server-Passwort")
|
||||
private String lastPass = "";
|
||||
@Variable(name = "srv_last_access", category = CVarCategory.SYSTEM, max = Player.MAX_PASS_LENGTH, display = "Letzter Server-Zugang")
|
||||
private String lastAcc = "";
|
||||
|
||||
public void init(int width, int height) {
|
||||
this.addrBox = this.add(new Textbox(0, 20, 400, 24, 128, true, this, this.lastAddr));
|
||||
this.portBox = this.add(new Textbox(404, 20, 76, 24, 5, true, this, "" + this.lastPort));
|
||||
this.userBox = this.add(new Textbox(0, 70, 220, 24, Player.MAX_USER_LENGTH, true, this, Player.VALID_USER, this.lastUser));
|
||||
this.passBox = this.add(new Textbox(0, 120, 480, 24, Player.MAX_PASS_LENGTH, true, this, this.lastPass));
|
||||
this.accBox = this.add(new Textbox(0, 170, 480, 24, Player.MAX_PASS_LENGTH, true, this, this.lastAcc));
|
||||
this.add(new ActButton(0, 220, 480, 24, new ActButton.Callback() {
|
||||
public void use(ActButton elem, ActButton.Mode action) {
|
||||
GuiConnect.this.connect();
|
||||
}
|
||||
}, "Verbinden"));
|
||||
this.add(new ActButton(0, 250, 480, 24, new ActButton.Callback() {
|
||||
public void use(ActButton elem, ActButton.Mode action) {
|
||||
GuiConnect.this.gm.displayGuiScreen(GuiMenu.INSTANCE);
|
||||
}
|
||||
}, "Zurück"));
|
||||
this.addrLabel = this.add(new Label(0, 0, 410, 20, "Adresse", true));
|
||||
this.portLabel = this.add(new Label(414, 0, 66, 20, "Port", true));
|
||||
this.userLabel = this.add(new Label(0, 50, 220, 20, "Nutzer", true));
|
||||
this.passLabel = this.add(new Label(0, 100, 480, 20, "Passwort", true));
|
||||
this.accLabel = this.add(new Label(0, 150, 480, 20, "Zugang", true));
|
||||
this.shift();
|
||||
}
|
||||
|
||||
public String getTitle() {
|
||||
return "Mit Server verbinden";
|
||||
}
|
||||
|
||||
private void connect() {
|
||||
if(this.gm.theWorld != null)
|
||||
return;
|
||||
String addr = this.addrBox.getText();
|
||||
if(addr.isEmpty()) {
|
||||
this.addrLabel.setText(TextColor.RED + "Adresse");
|
||||
return;
|
||||
}
|
||||
int port = -1;
|
||||
if(this.portBox.getText().isEmpty()) {
|
||||
this.portLabel.setText(TextColor.RED + "Port");
|
||||
return;
|
||||
}
|
||||
else {
|
||||
try {
|
||||
port = Integer.parseInt(this.portBox.getText());
|
||||
}
|
||||
catch(NumberFormatException e) {
|
||||
}
|
||||
if(port < 0 || port > 65535) {
|
||||
this.portLabel.setText(TextColor.RED + "Port");
|
||||
return;
|
||||
}
|
||||
}
|
||||
String user = this.userBox.getText();
|
||||
if(user.isEmpty()) {
|
||||
this.userLabel.setText(TextColor.RED + "Nutzer");
|
||||
return;
|
||||
}
|
||||
String pass = this.passBox.getText();
|
||||
String acc = this.accBox.getText();
|
||||
this.lastAddr = addr;
|
||||
this.lastPort = port;
|
||||
this.lastUser = user;
|
||||
this.lastPass = pass;
|
||||
this.lastAcc = acc;
|
||||
this.gm.setDirty();
|
||||
this.gm.connect(addr, port, user, pass, acc);
|
||||
}
|
||||
|
||||
public void use(Textbox elem, Action value) {
|
||||
if(value == Action.SEND) {
|
||||
elem.setDeselected();
|
||||
this.connect();
|
||||
}
|
||||
else if(value == Action.FOCUS) {
|
||||
if(elem == this.addrBox)
|
||||
this.addrLabel.setText("Adresse");
|
||||
else if(elem == this.portBox)
|
||||
this.portLabel.setText("Port");
|
||||
else if(elem == this.userBox)
|
||||
this.userLabel.setText("Nutzer");
|
||||
}
|
||||
}
|
||||
|
||||
// public void updateScreen() {
|
||||
//
|
||||
// }
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue