login + network changes, add forms
This commit is contained in:
parent
111226fe28
commit
eba8f6ea98
44 changed files with 894 additions and 224 deletions
|
@ -765,6 +765,7 @@ public class Client implements IThreadListener {
|
|||
else if (this.connection != null)
|
||||
{
|
||||
this.connection.processReceivedPackets();
|
||||
this.connection.checkDisconnected();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -2388,11 +2389,9 @@ public class Client implements IThreadListener {
|
|||
}
|
||||
|
||||
public void unload(boolean loading) {
|
||||
if(this.world != null) {
|
||||
if(this.getNetHandler() != null)
|
||||
this.getNetHandler().getNetworkManager().closeChannel("Quitting");
|
||||
this.unloadWorld();
|
||||
}
|
||||
if(this.world != null && this.getNetHandler() != null)
|
||||
this.getNetHandler().getNetworkManager().closeChannel("Quitting");
|
||||
this.unloadWorld();
|
||||
this.displayGuiScreen(GuiMenu.INSTANCE);
|
||||
}
|
||||
|
||||
|
|
118
client/src/client/gui/ingame/GuiForm.java
Normal file
118
client/src/client/gui/ingame/GuiForm.java
Normal file
|
@ -0,0 +1,118 @@
|
|||
package client.gui.ingame;
|
||||
|
||||
import client.gui.Gui;
|
||||
import client.gui.element.ActButton;
|
||||
import client.gui.element.ActButton.Mode;
|
||||
import client.gui.element.Element;
|
||||
import client.gui.element.Label;
|
||||
import client.gui.element.NavButton;
|
||||
import client.gui.element.Switch;
|
||||
import client.gui.element.Textbox;
|
||||
import client.gui.element.Textbox.Action;
|
||||
import client.gui.element.Toggle;
|
||||
import client.network.ClientPlayer;
|
||||
import common.color.TextColor;
|
||||
import common.packet.CPacketForm;
|
||||
import common.util.ExtMath;
|
||||
import common.util.Triplet;
|
||||
|
||||
public class GuiForm extends Gui implements ActButton.Callback {
|
||||
private final int id;
|
||||
private final String title;
|
||||
private final Element[] inputs;
|
||||
private final Label[] labels;
|
||||
private final Triplet<String, Object, Integer>[] inputData;
|
||||
private final Object[] outputData;
|
||||
|
||||
private boolean sent;
|
||||
|
||||
public void init(int width, int height) {
|
||||
this.add(new Label(0, -100, 300, 20, this.title));
|
||||
for(int z = 0; z < this.inputs.length; z++) {
|
||||
final int index = z;
|
||||
final String name = this.inputData[z].first;
|
||||
Object obj = this.inputData[z].second;
|
||||
int param = this.inputData[z].third;
|
||||
if(obj instanceof Boolean) {
|
||||
this.inputs[z] = this.add(new Toggle(0, 50 * z, 300, 24, (Boolean)obj, (Boolean)obj, new Toggle.Callback() {
|
||||
public void use(Toggle elem, boolean value) {
|
||||
GuiForm.this.outputData[index] = value;
|
||||
}
|
||||
}, name));
|
||||
}
|
||||
else if(obj instanceof String[]) {
|
||||
final String[] strs = (String[])obj;
|
||||
param = ExtMath.clampi(param, 0, strs.length - 1);
|
||||
this.inputs[z] = this.add(new Switch<String>(0, 50 * z, 300, 24, strs, strs[param], strs[param], new Switch.Callback<String>() {
|
||||
public void use(Switch<String> elem, String value) {
|
||||
for(int n = 0; n < strs.length; n++) {
|
||||
if(value == strs[n]) {
|
||||
GuiForm.this.outputData[index] = n;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}, name));
|
||||
}
|
||||
else {
|
||||
this.labels[z] = this.add(new Label(0, 50 * z - 20, 300, 20, name, true));
|
||||
this.inputs[z] = this.add(new Textbox(0, 50 * z, 300, 24, Math.min(param & 0xffff, 256), true, new Textbox.Callback() {
|
||||
public void use(Textbox elem, Action value) {
|
||||
if(value == Action.FOCUS)
|
||||
GuiForm.this.labels[index].setText(name);
|
||||
}
|
||||
}, (String)obj));
|
||||
}
|
||||
}
|
||||
this.add(new NavButton(0, 50 * (this.inputs.length + 1), 148, 24, null, "Abbrechen"));
|
||||
this.add(new ActButton(152, 50 * (this.inputs.length + 1), 148, 24, this, "Senden"));
|
||||
this.shift();
|
||||
}
|
||||
|
||||
public String getTitle() {
|
||||
return this.title;
|
||||
}
|
||||
|
||||
public void onGuiClosed() {
|
||||
if(!this.sent) {
|
||||
ClientPlayer nethandler = this.gm.getNetHandler();
|
||||
if(nethandler != null) {
|
||||
nethandler.addToSendQueue(new CPacketForm(this.id, null));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public GuiForm(int id, String title, Triplet<String, Object, Integer>[] data) {
|
||||
this.id = id;
|
||||
this.title = title;
|
||||
this.inputs = new Element[data.length];
|
||||
this.labels = new Label[data.length];
|
||||
this.inputData = data;
|
||||
this.outputData = new Object[data.length];
|
||||
for(int z = 0; z < data.length; z++) {
|
||||
Object obj = data[z].second;
|
||||
this.outputData[z] = obj instanceof String[] ? data[z].third : obj;
|
||||
}
|
||||
}
|
||||
|
||||
public void use(ActButton elem, Mode action) {
|
||||
for(int z = 0; z < this.inputs.length; z++) {
|
||||
if(this.inputs[z] instanceof Textbox) {
|
||||
int min = this.inputData[z].third >> 16;
|
||||
String text = this.inputs[z].getText();
|
||||
if(text.length() < min) {
|
||||
if(!GuiForm.this.labels[z].getText().startsWith("" + TextColor.RED))
|
||||
GuiForm.this.labels[z].setText(TextColor.RED + GuiForm.this.labels[z].getText());
|
||||
return;
|
||||
}
|
||||
this.outputData[z] = text;
|
||||
}
|
||||
}
|
||||
this.sent = true;
|
||||
ClientPlayer nethandler = this.gm.getNetHandler();
|
||||
if(nethandler != null) {
|
||||
nethandler.addToSendQueue(new CPacketForm(this.id, this.outputData));
|
||||
}
|
||||
this.gm.displayGuiScreen(null);
|
||||
}
|
||||
}
|
|
@ -1,6 +1,7 @@
|
|||
package client.gui.ingame;
|
||||
|
||||
import client.gui.Gui;
|
||||
import client.gui.element.Label;
|
||||
import client.gui.element.NavButton;
|
||||
import client.gui.element.Textbox;
|
||||
import client.gui.element.Textbox.Action;
|
||||
|
@ -10,11 +11,14 @@ import common.util.BlockPos;
|
|||
|
||||
public class GuiSign extends Gui implements Textbox.Callback {
|
||||
private final BlockPos position;
|
||||
private final Textbox[] lines = new Textbox[4];
|
||||
private final String[] tempLines = new String[this.lines.length];
|
||||
private final Textbox[] lines;
|
||||
private final String[] tempLines;
|
||||
|
||||
|
||||
public void init(int width, int height) {
|
||||
this.add(new Label(0, -140, 300, 20, "Bearbeite Schild"));
|
||||
this.add(new Label(0, -80, 300, 20, String.format("%d, %d, %d", this.position.getX(), this.position.getY(), this.position.getZ())));
|
||||
this.add(new Label(0, -50, 300, 20, this.gm.world == null ? "<?>" : this.gm.world.dimension.getFormattedName(false)));
|
||||
for(int z = 0; z < this.lines.length; z++) {
|
||||
this.lines[z] = this.add(new Textbox(0, 40 * z, 300, 24, 50, true, this, this.tempLines[z] == null ? "" : this.tempLines[z]));
|
||||
}
|
||||
|
@ -25,7 +29,6 @@ public class GuiSign extends Gui implements Textbox.Callback {
|
|||
public String getTitle() {
|
||||
return "Schild bearbeiten";
|
||||
}
|
||||
|
||||
|
||||
public void onGuiClosed() {
|
||||
ClientPlayer nethandler = this.gm.getNetHandler();
|
||||
|
@ -39,7 +42,9 @@ public class GuiSign extends Gui implements Textbox.Callback {
|
|||
|
||||
public GuiSign(BlockPos sign, String[] lines) {
|
||||
this.position = sign;
|
||||
System.arraycopy(lines, 0, this.tempLines, 0, this.lines.length);
|
||||
this.lines = new Textbox[lines.length];
|
||||
this.tempLines = new String[lines.length];
|
||||
System.arraycopy(lines, 0, this.tempLines, 0, lines.length);
|
||||
}
|
||||
|
||||
public void use(Textbox elem, Action value) {
|
||||
|
|
|
@ -25,6 +25,7 @@ import client.gui.container.GuiMachine;
|
|||
import client.gui.container.GuiMerchant;
|
||||
import client.gui.container.GuiRepair;
|
||||
import client.gui.ingame.GuiSign;
|
||||
import client.gui.ingame.GuiForm;
|
||||
import client.renderer.particle.EntityPickupFX;
|
||||
import client.renderer.texture.EntityTexManager;
|
||||
import client.world.WorldClient;
|
||||
|
@ -104,6 +105,7 @@ import common.packet.SPacketCollectItem;
|
|||
import common.packet.SPacketDestroyEntities;
|
||||
import common.packet.SPacketDimensionName;
|
||||
import common.packet.SPacketDisconnect;
|
||||
import common.packet.SPacketDisplayForm;
|
||||
import common.packet.SPacketEntityEquipment;
|
||||
import common.packet.SPacketEntityVelocity;
|
||||
import common.packet.SPacketHeldItemChange;
|
||||
|
@ -795,7 +797,7 @@ public class ClientPlayer extends NetHandler implements IClientPlayer
|
|||
*/
|
||||
public void handleDisconnect(SPacketDisconnect packetIn)
|
||||
{
|
||||
this.netManager.closeChannel("Getrennt");
|
||||
this.netManager.closeChannel(packetIn.getMessage());
|
||||
}
|
||||
|
||||
public void onDisconnect(String reason)
|
||||
|
@ -1284,6 +1286,11 @@ public class ClientPlayer extends NetHandler implements IClientPlayer
|
|||
|
||||
this.gameController.player.openEditSign((TileEntitySign)tileentity);
|
||||
}
|
||||
|
||||
public void handleForm(SPacketDisplayForm packet) {
|
||||
NetHandler.checkThread(packet, this, this.gameController, this.clientWorldController);
|
||||
this.gameController.displayGuiScreen(new GuiForm(packet.getId(), packet.getTitle(), packet.getData()));
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates a specified sign with the specified text lines
|
||||
|
@ -2061,8 +2068,8 @@ public class ClientPlayer extends NetHandler implements IClientPlayer
|
|||
this.gameController.displayGuiScreen(new GuiMerchant(inventory, title, worldObj));
|
||||
}
|
||||
|
||||
public void displayGuiSign(BlockPos pos, String[] signText) {
|
||||
this.gameController.displayGuiScreen(new GuiSign(pos, signText));
|
||||
public void displayGuiSign(BlockPos pos, String[] text) {
|
||||
this.gameController.displayGuiScreen(new GuiSign(pos, text));
|
||||
}
|
||||
|
||||
public void closeGui() {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue