command completion
This commit is contained in:
parent
0839beb98e
commit
a8f6af2b37
11 changed files with 400 additions and 347 deletions
|
@ -1,45 +1,49 @@
|
|||
package game.gui.world;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.Set;
|
||||
|
||||
import game.collect.Sets;
|
||||
import game.color.TextColor;
|
||||
import game.dimension.DimType;
|
||||
import game.dimension.Dimension;
|
||||
import game.dimension.Space;
|
||||
import game.gui.GuiScreen;
|
||||
import game.gui.element.Button;
|
||||
import game.gui.element.TextField;
|
||||
import game.gui.Gui;
|
||||
import game.gui.element.ActButton;
|
||||
import game.gui.element.Label;
|
||||
import game.gui.element.Textbox;
|
||||
import game.gui.element.ActButton.Mode;
|
||||
import game.gui.element.Textbox.Action;
|
||||
import game.gui.element.TransparentBox;
|
||||
import game.init.Config;
|
||||
import game.init.UniverseRegistry;
|
||||
import game.lib.input.Keyboard;
|
||||
import game.log.Log;
|
||||
import game.nbt.NBTLoader;
|
||||
import game.nbt.NBTTagCompound;
|
||||
import game.network.NetHandlerPlayServer;
|
||||
import game.renderer.FontRenderer;
|
||||
import game.rng.Random;
|
||||
import game.util.Predicate;
|
||||
import game.util.Util;
|
||||
import game.world.Region;
|
||||
import game.world.World;
|
||||
|
||||
public class GuiCreate extends GuiScreen
|
||||
public class GuiCreate extends Gui implements ActButton.Callback, Textbox.Callback
|
||||
{
|
||||
public static final GuiCreate INSTANCE = new GuiCreate();
|
||||
private static final String MBASE32_CHARS = "ABCDEFGHIJKLMNOPQRSTUVWXYZ!?-_<3";
|
||||
private static final String MBASE64A_CHARS = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz-!";
|
||||
private static final String MBASE64B_CHARS = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz<_";
|
||||
|
||||
private GuiScreen parentScreen;
|
||||
private TextField worldNameField;
|
||||
private TextField worldSeedField;
|
||||
private TextField worldUserField;
|
||||
// private Button modeButton;
|
||||
private Button dimButton;
|
||||
// private String descLine1;
|
||||
// private String descLine2;
|
||||
private String[] descLines;
|
||||
private Textbox worldNameField;
|
||||
private Textbox worldSeedField;
|
||||
private Textbox worldUserField;
|
||||
private ActButton dimButton;
|
||||
private ActButton createButton;
|
||||
private Label actionLabel;
|
||||
private Label nameLabel;
|
||||
private Label userLabel;
|
||||
private Label seed;
|
||||
private Label decoded;
|
||||
private TransparentBox descLines;
|
||||
|
||||
private boolean alreadyGenerated;
|
||||
private boolean fileExists;
|
||||
private boolean fileInvalid;
|
||||
private String seed;
|
||||
private String decoded;
|
||||
private int dimension;
|
||||
|
||||
private static long getSeed(String str) {
|
||||
|
@ -171,235 +175,143 @@ public class GuiCreate extends GuiScreen
|
|||
return (def == null ? ("" + seed) : def);
|
||||
}
|
||||
|
||||
public GuiCreate(GuiScreen parent)
|
||||
private GuiCreate()
|
||||
{
|
||||
UniverseRegistry.clear();
|
||||
this.parentScreen = parent;
|
||||
// this.worldSeed = "";
|
||||
// this.worldName = "Neue Welt";
|
||||
}
|
||||
|
||||
public void updateScreen()
|
||||
{
|
||||
this.worldNameField.updateCursorCounter();
|
||||
this.worldSeedField.updateCursorCounter();
|
||||
this.worldUserField.updateCursorCounter();
|
||||
String text = this.worldSeedField.getText();
|
||||
if(text.isEmpty()) {
|
||||
this.seed = "Zufällig";
|
||||
this.decoded = "-";
|
||||
this.seed.setText("Startwert [Zufällig]");
|
||||
this.decoded.setText("Dekodiert: -");
|
||||
}
|
||||
else {
|
||||
this.seed = "" + getSeed(text);
|
||||
this.seed.setText("Startwert [" + getSeed(text) + "]");
|
||||
try {
|
||||
this.decoded = decodeSeed(Long.parseLong(text), "-");
|
||||
this.decoded.setText("Dekodiert: " + decodeSeed(Long.parseLong(text), "-"));
|
||||
}
|
||||
catch(NumberFormatException e) {
|
||||
this.decoded = decodeSeed(getSeed(text), "-");
|
||||
this.decoded.setText("Dekodiert: " + decodeSeed(getSeed(text), "-"));
|
||||
}
|
||||
}
|
||||
this.fileExists = false;
|
||||
this.fileInvalid = false;
|
||||
text = this.worldNameField.getText().trim();
|
||||
// for(String n : GuiCreate.DISALLOWED_FILES) {
|
||||
// if(text.equalsIgnoreCase(n)) {
|
||||
// ((Button)this.buttonList.get(0)).enabled = false;
|
||||
// this.fileInvalid = true;
|
||||
// return;
|
||||
// }
|
||||
// }
|
||||
if(this.fileInvalid = GuiCreate.DISALLOWED_FILES.contains(text.toUpperCase())) {
|
||||
((Button)this.buttonList.get(0)).enabled = false;
|
||||
return;
|
||||
}
|
||||
this.createButton.enabled = !text.isEmpty() && !this.worldUserField.getText().isEmpty();
|
||||
if(this.fileExists = (!text.isEmpty() && new File(Region.SAVE_DIR, text).exists()))
|
||||
((Button)this.buttonList.get(0)).enabled = false;
|
||||
this.createButton.enabled = false;
|
||||
this.actionLabel.setText(this.getFolderDesc());
|
||||
this.userLabel.setText(this.getUserDesc());
|
||||
}
|
||||
|
||||
public void initGui()
|
||||
public void init(int width, int height)
|
||||
{
|
||||
Keyboard.enableRepeatEvents(true);
|
||||
this.buttonList.clear();
|
||||
this.buttonList.add(new Button(0, this.width / 2 - 155, this.height - 28, 150, 20, "Neue Welt erstellen"));
|
||||
this.buttonList.add(new Button(1, this.width / 2 + 5, this.height - 28, 150, 20, "Abbrechen"));
|
||||
// this.buttonList.add(this.modeButton = new Button(2, this.width / 2 - 155, 175, 310, 20, ""));
|
||||
this.buttonList.add(this.dimButton = new Button(2, this.width / 2 - 155, 220, 310, 20, ""));
|
||||
this.worldNameField = new TextField(this.width / 2 - 100, 60, 200, 20);
|
||||
this.worldNameField.setFocused(true);
|
||||
this.worldNameField.setValidator(new Predicate<String>() {
|
||||
public boolean apply(String name) {
|
||||
for(int z = 0; z < name.length(); z++) {
|
||||
if(DISALLOWED_CHARS.contains(name.charAt(z)))
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
});
|
||||
// this.worldNameField.setText("Welt");
|
||||
this.worldSeedField = new TextField(this.width / 2 - 100, 136, 200, 20);
|
||||
// this.worldSeedField.setText(this.worldSeed);
|
||||
this.worldUserField = new TextField(this.width / 2 - 100, 98, 200, 20);
|
||||
this.worldUserField.setMaxStringLength(16);
|
||||
this.worldUserField.setValidator(new Predicate<String>() {
|
||||
public boolean apply(String name) {
|
||||
return NetHandlerPlayServer.isValidUser(name);
|
||||
}
|
||||
});
|
||||
// this.calcSaveDirName();
|
||||
// this.setModeButton();
|
||||
UniverseRegistry.clear();
|
||||
this.alreadyGenerated = false;
|
||||
this.dimension = Integer.MAX_VALUE;
|
||||
this.createButton = this.add(new ActButton(width / 2 - 155, height - 28, 150, 20, (ActButton.Callback)this, "Neue Welt erstellen"));
|
||||
this.add(new ActButton(width / 2 + 5, height - 28, 150, 20, (Gui)GuiWorlds.INSTANCE, "Abbrechen"));
|
||||
this.dimButton = this.add(new ActButton(width / 2 - 155, 220, 310, 20, (ActButton.Callback)this, ""));
|
||||
this.worldNameField = this.add(new Textbox(width / 2 - 100, 60, 200, 20, 256, true, this, GuiWorlds.VALID_FILE, ""));
|
||||
this.worldNameField.setSelected();
|
||||
this.worldSeedField = this.add(new Textbox(width / 2 - 100, 136, 200, 20, 256, true, this, ""));
|
||||
this.worldUserField = this.add(new Textbox(width / 2 - 100, 98, 200, 20, NetHandlerPlayServer.MAX_USER_LENGTH, true, this, NetHandlerPlayServer.VALID_USER, ""));
|
||||
this.createButton.enabled = false;
|
||||
this.actionLabel = this.add(new Label(width / 2 - 100, 49, 200, 20, this.getFolderDesc(), true));
|
||||
this.userLabel = this.add(new Label(width / 2 - 100, 87, 200, 20, this.getUserDesc(), true));
|
||||
this.seed = this.add(new Label(width / 2 - 100, 125, 200, 20, "", true));
|
||||
this.decoded = this.add(new Label(width / 2 - 100, 160, 200, 20, "", true));
|
||||
this.descLines = this.add(new TransparentBox(width / 2 - 153, 242, 306, 160, ""));
|
||||
this.setDimButton();
|
||||
((Button)this.buttonList.get(0)).enabled = false;
|
||||
}
|
||||
|
||||
// private void setModeButton() {
|
||||
// this.modeButton.display = "Kreativmodus: " + (this.noCreative ? "Aus" : "An");
|
||||
// this.descLine1 = this.noCreative ? "Suche nach Ressourcen, baue Werkzeuge, Waffen und mehr"
|
||||
// : "Unbegrenzte Rohstoffe, Flugmodus, Unverwundbarkeit, keine";
|
||||
// this.descLine2 = this.noCreative ? "Gegenstände, sammle Erfahrung und erkunde die Welten"
|
||||
// : "Energie oder Mana und sofortiges Zerstören von Blöcken";
|
||||
// }
|
||||
public String getTitle() {
|
||||
return "Neue Welt erstellen";
|
||||
}
|
||||
|
||||
private void setDimButton() {
|
||||
Dimension dim = this.dimension == Integer.MAX_VALUE ? Space.INSTANCE : UniverseRegistry.getBaseDimensions().get(this.dimension);
|
||||
this.dimButton.display = (dim == Space.INSTANCE ? "" :
|
||||
this.dimButton.setText((dim == Space.INSTANCE ? "" :
|
||||
((dim.getDimensionId() >= UniverseRegistry.MORE_DIM_ID ?
|
||||
"Vorlage" : (dim.getType() == DimType.PLANET ? "Heimplanet" : "Dimension")) + ": ")) +
|
||||
(dim.getDimensionId() >= UniverseRegistry.MORE_DIM_ID ? dim.getCustomName() :
|
||||
dim.getFormattedName(false));
|
||||
this.descLines = dim.getFormattedName(true).split(" / ");
|
||||
dim.getFormattedName(false)));
|
||||
this.descLines.setText(Util.buildLines(dim.getFormattedName(true).split(" / ")));
|
||||
}
|
||||
|
||||
// private void calcSaveDirName()
|
||||
// {
|
||||
// this.saveDirName = this.worldNameField.getText().trim();
|
||||
//
|
||||
//// for (char c : DISALLOWED_CHARS)
|
||||
//// {
|
||||
//// this.saveDirName = this.saveDirName.replace(c, '_');
|
||||
//// }
|
||||
//
|
||||
// if (!this.saveDirName.isEmpty())
|
||||
//// {
|
||||
//// this.saveDirName = "World";
|
||||
//// }
|
||||
//
|
||||
// this.saveDirName = getUncollidingSaveDirName(Region.SAVE_DIR, this.saveDirName);
|
||||
// }
|
||||
|
||||
public void onGuiClosed()
|
||||
|
||||
public void use(ActButton button, Mode mode)
|
||||
{
|
||||
Keyboard.enableRepeatEvents(false);
|
||||
}
|
||||
|
||||
protected void actionPerformed(Button button) throws IOException
|
||||
{
|
||||
if (button.enabled)
|
||||
if (button == this.createButton)
|
||||
{
|
||||
if (button.id == 1)
|
||||
{
|
||||
this.gm.displayGuiScreen(this.parentScreen);
|
||||
// this.gm.displayGuiScreen(null);
|
||||
if(this.alreadyGenerated)
|
||||
return;
|
||||
this.alreadyGenerated = true;
|
||||
Config.clear();
|
||||
UniverseRegistry.clear();
|
||||
Dimension dim = this.dimension == Integer.MAX_VALUE ? Space.INSTANCE :
|
||||
UniverseRegistry.getBaseDimensions().get(this.dimension);
|
||||
dim.setSeed(getSeed(this.worldSeedField.getText()));
|
||||
File dir = new File(Region.SAVE_DIR, this.worldNameField.getText().trim());
|
||||
Dimension[] dims = UniverseRegistry.registerPreset(dim);
|
||||
Config.set("spawnDim", "" + dims[0].getDimensionId(), null);
|
||||
Region.saveWorldInfo(dir, World.START_TIME, this.worldUserField.getText());
|
||||
for(Dimension sdim : dims) {
|
||||
NBTTagCompound data = new NBTTagCompound();
|
||||
data.setTag("Generator", sdim.toNbt(true));
|
||||
File chunkDir = new File(new File(dir, "chunk"), sdim.getDimensionName());
|
||||
chunkDir.mkdirs();
|
||||
File file = new File(chunkDir, "data.nbt");
|
||||
try {
|
||||
NBTLoader.writeGZip(data, file);
|
||||
}
|
||||
catch(Exception e) {
|
||||
Log.IO.error(e, "Konnte Weltdaten nicht speichern");
|
||||
}
|
||||
}
|
||||
else if (button.id == 0)
|
||||
{
|
||||
this.gm.displayGuiScreen(null);
|
||||
if(this.alreadyGenerated)
|
||||
return;
|
||||
this.alreadyGenerated = true;
|
||||
Dimension dim = this.dimension == Integer.MAX_VALUE ? Space.INSTANCE :
|
||||
UniverseRegistry.getBaseDimensions().get(this.dimension);
|
||||
dim.setSeed(getSeed(this.worldSeedField.getText()));
|
||||
this.gm.launchIntegratedServer(this.worldNameField.getText().trim(), dim, this.worldUserField.getText());
|
||||
}
|
||||
// else if (button.id == 2)
|
||||
// {
|
||||
// this.noCreative ^= true;
|
||||
// this.setModeButton();
|
||||
// }
|
||||
else if (button.id == 2)
|
||||
{
|
||||
// int index = Integer.MAX_VALUE;
|
||||
// for(int z = 0; z < UniverseRegistry.getBasePlanets().size(); z++) {
|
||||
// if(UniverseRegistry.getBasePlanets().get(z).getDimensionId() == this.dimension) {
|
||||
// index = z;
|
||||
// break;
|
||||
// }
|
||||
// }
|
||||
if(this.dimension == Integer.MAX_VALUE) {
|
||||
this.dimension = GuiScreen.isShiftKeyDown() ? UniverseRegistry.getBaseDimensions().size() - 1 : 0;
|
||||
this.gm.startServer(dir, this.worldUserField.getText());
|
||||
}
|
||||
else if (button == this.dimButton)
|
||||
{
|
||||
if(mode == Mode.TERTIARY) {
|
||||
this.dimension = Integer.MAX_VALUE;
|
||||
}
|
||||
else if(this.dimension == Integer.MAX_VALUE) {
|
||||
this.dimension = mode == Mode.SECONDARY ? UniverseRegistry.getBaseDimensions().size() - 1 : 0;
|
||||
}
|
||||
else {
|
||||
if(mode == Mode.SECONDARY) {
|
||||
if(--this.dimension < 0)
|
||||
this.dimension = Integer.MAX_VALUE;
|
||||
}
|
||||
else {
|
||||
if(GuiScreen.isShiftKeyDown()) {
|
||||
if(--this.dimension < 0)
|
||||
this.dimension = Integer.MAX_VALUE;
|
||||
}
|
||||
else {
|
||||
if(++this.dimension >= UniverseRegistry.getBaseDimensions().size())
|
||||
this.dimension = Integer.MAX_VALUE;
|
||||
}
|
||||
if(++this.dimension >= UniverseRegistry.getBaseDimensions().size())
|
||||
this.dimension = Integer.MAX_VALUE;
|
||||
}
|
||||
// this.dimension = index == Integer.MAX_VALUE ? Space.INSTANCE.getDimensionId() :
|
||||
// UniverseRegistry.getBasePlanets().get(index).getDimensionId();
|
||||
this.setDimButton();
|
||||
}
|
||||
}
|
||||
this.setDimButton();
|
||||
}
|
||||
}
|
||||
|
||||
protected void keyTyped(char typedChar, int keyCode) throws IOException
|
||||
{
|
||||
// if (this.worldNameField.isFocused())
|
||||
// {
|
||||
this.worldNameField.textboxKeyTyped(typedChar, keyCode);
|
||||
// this.worldName = this.worldNameField.getText();
|
||||
|
||||
public void use(Textbox elem, Action action) {
|
||||
if(action == Action.SEND)
|
||||
this.use(this.createButton, Mode.PRIMARY);
|
||||
}
|
||||
|
||||
private String getFolderDesc() {
|
||||
// FontRenderer.drawStringWithShadow("Startwert [" + this.seed + "]", this.width / 2 - 100, 125, -6250336);
|
||||
// FontRenderer.drawStringWithShadow("Dekodiert: " + this.decoded, this.width / 2 - 100, 160, -6250336);
|
||||
// FontRenderer.drawStringWithShadow(, this.width / 2 - 100, 49, -6250336);
|
||||
// FontRenderer.drawStringWithShadow((this.worldUserField.getText().isEmpty() ? TextColor.DARK_RED : "") + "Spielername", this.width / 2 - 100, 87, -6250336);
|
||||
//
|
||||
// for(int z = 1; z < this.descLines.length; z++) {
|
||||
// FontRenderer.drawStringWithShadow(this.descLines[z], this.width / 2 - 153, 242 + (z - 1) * (FontRenderer.FONT_HEIGHT + 1), -6250336);
|
||||
// }
|
||||
// else if (this.worldSeedField.isFocused())
|
||||
// {
|
||||
this.worldSeedField.textboxKeyTyped(typedChar, keyCode);
|
||||
// this.worldSeed = this.worldSeedField.getText();
|
||||
// }
|
||||
// else if (this.worldUserField.isFocused())
|
||||
// {
|
||||
this.worldUserField.textboxKeyTyped(typedChar, keyCode);
|
||||
// }
|
||||
|
||||
if (keyCode == 28 || keyCode == 156)
|
||||
{
|
||||
this.actionPerformed((Button)this.buttonList.get(0));
|
||||
}
|
||||
|
||||
((Button)this.buttonList.get(0)).enabled = this.worldNameField.getText().length() > 0 && this.worldUserField.getText().length() > 0;
|
||||
// this.calcSaveDirName();
|
||||
}
|
||||
|
||||
protected void mouseClicked(int mouseX, int mouseY, int mouseButton) throws IOException
|
||||
{
|
||||
super.mouseClicked(mouseX, mouseY, mouseButton);
|
||||
|
||||
this.worldSeedField.mouseClicked(mouseX, mouseY, mouseButton);
|
||||
this.worldNameField.mouseClicked(mouseX, mouseY, mouseButton);
|
||||
this.worldUserField.mouseClicked(mouseX, mouseY, mouseButton);
|
||||
}
|
||||
|
||||
public void drawScreen(int mouseX, int mouseY, float partialTicks)
|
||||
{
|
||||
this.drawBackground();
|
||||
FontRenderer.drawCenteredString("Neue Welt erstellen", this.width / 2, 20, -1);
|
||||
|
||||
FontRenderer.drawStringWithShadow("Startwert [" + this.seed + "]", this.width / 2 - 100, 125, -6250336);
|
||||
FontRenderer.drawStringWithShadow("Dekodiert: " + this.decoded, this.width / 2 - 100, 160, -6250336);
|
||||
FontRenderer.drawStringWithShadow((this.worldNameField.getText().trim().isEmpty() || this.fileExists || this.fileInvalid ? TextColor.DARK_RED : "")
|
||||
+ "Ordner der Welt" + (this.fileExists ? " - Existiert bereits" : ""), this.width / 2 - 100, 49, -6250336);
|
||||
FontRenderer.drawStringWithShadow((this.worldUserField.getText().isEmpty() ? TextColor.DARK_RED : "") + "Spielername", this.width / 2 - 100, 87, -6250336);
|
||||
|
||||
this.worldSeedField.drawTextBox();
|
||||
this.worldNameField.drawTextBox();
|
||||
this.worldUserField.drawTextBox();
|
||||
|
||||
// FontRenderer.drawStringWithShadow(this.descLine1, this.width / 2 - 153, 197, -6250336);
|
||||
// FontRenderer.drawStringWithShadow(this.descLine2, this.width / 2 - 153, 197 + FontRenderer.FONT_HEIGHT + 1, -6250336);
|
||||
for(int z = 1; z < this.descLines.length; z++) {
|
||||
FontRenderer.drawStringWithShadow(this.descLines[z], this.width / 2 - 153, 242 + (z - 1) * (FontRenderer.FONT_HEIGHT + 1), -6250336);
|
||||
}
|
||||
|
||||
super.drawScreen(mouseX, mouseY, partialTicks);
|
||||
return (this.worldNameField.getText().trim().isEmpty() || this.fileExists ? TextColor.DRED : "")
|
||||
+ "Ordner der Welt" + (this.fileExists ? " - Existiert bereits" : "");
|
||||
}
|
||||
|
||||
private String getUserDesc() {
|
||||
return (this.worldUserField.getText().isEmpty() ? TextColor.DRED : "") + "Spielername";
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue