diff --git a/java/src/game/Game.java b/java/src/game/Game.java index e21dfbf..21b4136 100755 --- a/java/src/game/Game.java +++ b/java/src/game/Game.java @@ -789,8 +789,11 @@ public class Game implements IThreadListener { entity.getHealth() + TextColor.GRAY + " / " + EntityLiving.getMaxHpColor(entity.getMaxHealth()) + entity.getMaxHealth() + TextColor.GRAY + "]"; Drawing.drawTextboxCentered(s, x, y, 0x3f000000); - Drawing.drawRectColor(x - 200, y + 20, 400, 10, 0xff000000); - Drawing.drawRectColor(x - 200, y + 20, (int)(400.0f * ((float)entity.getHealth() / (float)entity.getMaxHealth())), 10, 0xff000000 | entity.getColor()); + Drawing.drawRect2GradBorder(x - 200, y + 20, 400, 10, 0xff000000, 0xff202020, 0xffcfcfcf, 0xff9f9f9f, 0xff9f9f9f, 0xff6f6f6f); + Drawing.drawGradient(x - 200 + 2, y + 20 + 2, (int)(396.0f * ((float)entity.getHealth() / (float)entity.getMaxHealth())), 6, entity.getColor() | 0xff000000, + Drawing.mixColor(entity.getColor() | 0xff000000, 0xff000000)); +// Drawing.drawRectColor(x - 200, y + 20, 400, 10, 0xff000000); +// Drawing.drawRectColor(x - 200, y + 20, , 0xff000000 | ); y += 40; } else { @@ -2121,8 +2124,11 @@ public class Game implements IThreadListener { this.full(!this.fullscreen); } if(!(this.open instanceof GuiLoading)) { - if(!(this.open instanceof GuiConsole) && Bind.COMMAND.isPressed()) { - this.displayGuiScreen(GuiConsole.INSTANCE); + if(!(this.open instanceof GuiConsole) && Bind.CONSOLE.isPressed()) { + this.displayGuiScreen(GuiConsole.INSTANCE.setFull(true)); + } + else if(this.open == null && Bind.COMMAND.isPressed()) { + this.displayGuiScreen(GuiConsole.INSTANCE.setFull(false)); } // if(this.theWorld != null && this.open == null && Bind.COMMAND.isPressed()) { // this.displayGuiScreen(GuiChat.INSTANCE); @@ -2722,6 +2728,10 @@ public class Game implements IThreadListener { public T getVar(String name) { return (T)cvars.get(name); } + + public Iterable getVars() { + return this.cvars.keySet(); + } public void setDirty() { cfgDirty = true; @@ -2859,7 +2869,7 @@ public class Game implements IThreadListener { } Log.CONSOLE.user(TextColor.GREEN + "CVARs insgesamt registriert: %d", cvars.size()); // this.command(line); -// return; + return; } else if(line.startsWith("#")) { String tok = line.substring(1); @@ -2882,7 +2892,7 @@ public class Game implements IThreadListener { } } if(this.thePlayer != null && this.getNetHandler() != null) - this.getNetHandler().addToSendQueue(new CPacketMessage(CPacketMessage.Type.CHAT, line)); + this.getNetHandler().addToSendQueue(new CPacketMessage(line.startsWith("/") ? CPacketMessage.Type.COMMAND : CPacketMessage.Type.CHAT, line.startsWith("/") ? line.substring(1) : line)); // Log.CONSOLE.user("%s", line); // this.command(line); } @@ -2900,6 +2910,7 @@ public class Game implements IThreadListener { public void log(String prefixed, String line) { String msg = this.conTimestamps ? prefixed : line; +// this.addMessage(msg); if((buffer.length() + msg.length() + 1) > LOG_BUFFER) { int offset = (msg.length() + 1) > 1024 ? (msg.length() + 1) : 1024; int nl = buffer.indexOf('\n', offset); diff --git a/java/src/game/gui/GuiConsole.java b/java/src/game/gui/GuiConsole.java index dcdb2a9..b9d2cae 100644 --- a/java/src/game/gui/GuiConsole.java +++ b/java/src/game/gui/GuiConsole.java @@ -4,43 +4,58 @@ import java.util.List; import com.google.common.collect.Lists; +import game.Game; +import game.color.TextColor; import game.gui.element.ActButton; import game.gui.element.Fill; import game.gui.element.Textbox; import game.gui.element.Textbox.Action; import game.gui.element.TransparentBox; -import game.log.Log; import game.network.NetHandlerPlayServer; import game.packet.CPacketComplete; import game.util.ExtMath; +import game.vars.BoolVar; +import game.vars.CVar; import game.window.Keysym; public class GuiConsole extends Gui implements Textbox.Callback { public static final GuiConsole INSTANCE = new GuiConsole(); private final List sentMessages = Lists.newArrayList(); - + + private boolean full; + private String historyBuffer = ""; private int sentHistoryCursor = -1; private boolean playerNamesFound; private boolean waitingOnAutocomplete; + private boolean reverse; + private String prefixFirst; private int autocompleteIndex; private List foundPlayerNames = Lists.newArrayList(); private Textbox inputField; private TransparentBox logBox; + public GuiConsole setFull(boolean full) { + this.full = full; + return this; + } + public void init(int width, int height) { - this.addSelector("con_autoclose", 0, 0, 160, 24); - this.addSelector("con_timestamps", 160, 0, 160, 24); - this.addSelector("con_loglevel", 320, 0, 160, 24); - this.add(new ActButton(480, 0, 160, 24, new ActButton.Callback() { - public void use(ActButton elem, ActButton.Mode action) { - GuiConsole.this.reset(); - GuiConsole.this.setLog(GuiConsole.this.gm.getBuffer()); - } - }, "Löschen")); - this.logBox = this.add(new TransparentBox(0, 24, width, height - 48, this.gm.getBuffer())); - this.add(new Fill(640, 0, width - 640, 24)); + if(this.full) { + this.addSelector("con_autoclose", 0, 0, 160, 24); + this.addSelector("con_timestamps", 160, 0, 160, 24); + this.addSelector("con_loglevel", 320, 0, 160, 24); + this.add(new ActButton(480, 0, 160, 24, new ActButton.Callback() { + public void use(ActButton elem, ActButton.Mode action) { + GuiConsole.this.reset(); + GuiConsole.this.setLog(GuiConsole.this.gm.getBuffer()); + } + }, "Löschen")); + } + this.logBox = this.add(new TransparentBox(0, this.full ? 24 : 0, width, height - (this.full ? 48 : 24), this.gm.getBuffer())); + if(this.full) + this.add(new Fill(640, 0, width - 640, 24)); this.inputField = this.add(new Textbox(0, height - 24, width, 24, NetHandlerPlayServer.MAX_CMD_LENGTH, true, this, "")); this.inputField.setSelected(); this.sentHistoryCursor = this.sentMessages.size(); @@ -69,7 +84,7 @@ public class GuiConsole extends Gui implements Textbox.Callback { public void key(Keysym key, boolean ctrl, boolean shift) { super.key(key, ctrl, shift); // this.waitingOnAutocomplete = false; - if(key != Keysym.TAB) + if(key != Keysym.TAB && key != Keysym.LEFT_SHIFT && key != Keysym.RIGHT_SHIFT) this.playerNamesFound = false; } @@ -77,8 +92,9 @@ public class GuiConsole extends Gui implements Textbox.Callback { { this.waitingOnAutocomplete = false; - if ((value == Action.FORWARD || value == Action.BACKWARD) && this.gm.thePlayer != null) + if (value == Action.FORWARD || value == Action.BACKWARD) { + this.reverse = value == Action.BACKWARD; this.autocompletePlayerNames(); } else @@ -98,13 +114,14 @@ public class GuiConsole extends Gui implements Textbox.Callback { { if(this.sentMessages.isEmpty() || !((String)this.sentMessages.get(this.sentMessages.size() - 1)).equals(s)) this.sentMessages.add(s); + this.sentHistoryCursor = this.sentMessages.size(); this.gm.exec(s); // if(this.gm.thePlayer != null) // this.gm.thePlayer.sendQueue.addToSendQueue(new CPacketMessage(CPacketMessage.Type.CHAT, s)); } this.inputField.setText(""); - if(this.gm.conAutoclose && this.gm.theWorld != null) + if((this.gm.conAutoclose || !this.full) && this.gm.theWorld != null) this.gm.displayGuiScreen(null); } } @@ -120,6 +137,16 @@ public class GuiConsole extends Gui implements Textbox.Callback { this.inputField.insertText(newChatText); } } + + private void addMessage(String msg) { + String buffer = this.gm.getBuffer(); + if((buffer.length() + msg.length() + 2) > Game.LOG_BUFFER) { + int offset = (msg.length() + 2) > 1024 ? (msg.length() + 2) : 1024; + int nl = buffer.indexOf('\n', offset); + buffer = nl >= 0 ? buffer.substring(nl + 1) : ""; + } + this.setLog(buffer + "\n" + TextColor.RESET + msg); + } public void autocompletePlayerNames() { @@ -131,6 +158,10 @@ public class GuiConsole extends Gui implements Textbox.Callback { { this.autocompleteIndex = 0; } + else if (this.autocompleteIndex < 0) + { + this.autocompleteIndex = this.foundPlayerNames.size() - 1; + } } else { @@ -139,7 +170,11 @@ public class GuiConsole extends Gui implements Textbox.Callback { this.autocompleteIndex = 0; String s = this.inputField.getText().substring(i).toLowerCase(); String s1 = this.inputField.getText().substring(0, this.inputField.getCursorPosition()); - this.sendAutocompleteRequest(s1, s); + String[] localMatches = this.sendAutocompleteRequest(s1, s); + if(localMatches != null) { + this.onAutocompleteResponse(localMatches); + return; + } if (this.foundPlayerNames.isEmpty()) { @@ -164,13 +199,42 @@ public class GuiConsole extends Gui implements Textbox.Callback { stringbuilder.append(s2); } - Log.CONSOLE.user(stringbuilder.toString()); + this.addMessage(stringbuilder.toString()); } - this.inputField.insertText((String)this.foundPlayerNames.get(this.autocompleteIndex++)); + this.inputField.insertText((String)this.foundPlayerNames.get(this.autocompleteIndex)); + this.autocompleteIndex += this.reverse ? -1 : 1; } - - private void sendAutocompleteRequest(String currentText, String newText) + + private String[] complete(String s) { + List list = Lists.newArrayList(); + String[] argv = s.split(" ", -1); + String pre = argv[0]; + s = argv[argv.length - 1]; + Iterable res = pre.startsWith("#") ? + (argv.length == 1 ? this.gm.getVars() : (argv.length == 2 ? getVarCompletion(argv[0].substring(1)) : Lists.newArrayList())) : + (this.gm.thePlayer == null ? Lists.newArrayList() : this.gm.thePlayer.sendQueue.getPlayerNames()); + if(argv.length == 1 && pre.startsWith("#")) + s = s.substring(1); + for(String s1 : res) { + if(s1.regionMatches(true, 0, s, 0, s.length())) + list.add((argv.length == 1 && pre.startsWith("#") ? "#" : "") + s1); + } + return list.isEmpty() ? null : list.toArray(new String[list.size()]); + } + + private List getVarCompletion(String var) { + CVar cv = this.gm.getVar(var); + if(cv == null) + return Lists.newArrayList(); + if(cv instanceof BoolVar) + return Boolean.parseBoolean(cv.format()) ? Lists.newArrayList("false", "true") : Lists.newArrayList("true", "false"); + else + return Lists.newArrayList(cv.getDefault()); +// return Lists.newArrayList(); + } + + private String[] sendAutocompleteRequest(String currentText, String newText) { if (currentText.length() >= 1) { @@ -185,10 +249,23 @@ public class GuiConsole extends Gui implements Textbox.Callback { // { // eid = this.gm.pointed.entity.getId(); // } - - this.gm.thePlayer.sendQueue.addToSendQueue(new CPacketComplete(currentText)); - this.waitingOnAutocomplete = true; + if(currentText.startsWith("/")) { + if(this.gm.thePlayer != null) { + currentText = currentText.substring(1); + this.prefixFirst = currentText.split(" ", -1).length == 1 ? "/" : null; + this.gm.thePlayer.sendQueue.addToSendQueue(new CPacketComplete(currentText)); + this.waitingOnAutocomplete = true; + } + } + else { + String[] comp = this.complete(currentText); + this.prefixFirst = null; + if(comp != null) + this.waitingOnAutocomplete = true; + return comp; + } } + return null; } private void getSentHistory(int msgPos) @@ -224,8 +301,11 @@ public class GuiConsole extends Gui implements Textbox.Callback { this.playerNamesFound = false; this.foundPlayerNames.clear(); - for (String s : choices) + for (int z = 0; z < choices.length; z++) { + String s = choices[z]; + if(this.prefixFirst != null) + choices[z] = s = this.prefixFirst + s; if (s.length() > 0) { this.foundPlayerNames.add(s); diff --git a/java/src/game/gui/container/GuiContainer.java b/java/src/game/gui/container/GuiContainer.java index a4c48bb..418f5f2 100755 --- a/java/src/game/gui/container/GuiContainer.java +++ b/java/src/game/gui/container/GuiContainer.java @@ -295,8 +295,10 @@ public abstract class GuiContainer extends Gui this.renderItemOverlayIntoGUI(overlay.stack, overlay.x, overlay.y, overlay.alt); } this.drawnOverlays.clear(); - if(this.tooltip != null) - Drawing.drawTextbox(this.tooltip, this.hover_x, this.hover_y, 0xaf000000); + if(this.tooltip != null) { + int width = Drawing.getBoxWidth(this.tooltip); + Drawing.drawTextbox(this.tooltip, this.hover_x + width > this.gm.fb_x ? this.hover_x - width - 32 : this.hover_x, this.hover_y, 0xaf000000); + } this.tooltip = null; } diff --git a/java/src/game/gui/world/GuiCreate.java b/java/src/game/gui/world/GuiCreate.java index badd44d..ec2cda0 100755 --- a/java/src/game/gui/world/GuiCreate.java +++ b/java/src/game/gui/world/GuiCreate.java @@ -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() { - 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() { - 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"; + } } diff --git a/java/src/game/gui/world/GuiWorlds.java b/java/src/game/gui/world/GuiWorlds.java index 5b5b6b6..be7a7e9 100755 --- a/java/src/game/gui/world/GuiWorlds.java +++ b/java/src/game/gui/world/GuiWorlds.java @@ -347,7 +347,7 @@ public class GuiWorlds extends GuiList implements ActButton. this.gm.startServer(null, "debug"); } else { - // this.gm.displayGuiScreen(new GuiCreate(this)); //TODO: create + this.gm.displayGuiScreen(GuiCreate.INSTANCE); } } } diff --git a/java/src/game/network/NetHandlerPlayClient.java b/java/src/game/network/NetHandlerPlayClient.java index 2926200..12f62bb 100755 --- a/java/src/game/network/NetHandlerPlayClient.java +++ b/java/src/game/network/NetHandlerPlayClient.java @@ -1855,4 +1855,9 @@ public class NetHandlerPlayClient extends NetHandler { return this.playerList.entrySet(); } + + public Iterable getPlayerNames() + { + return this.playerList.keySet(); + } } diff --git a/java/src/game/network/NetHandlerPlayServer.java b/java/src/game/network/NetHandlerPlayServer.java index 257184d..f558b7d 100755 --- a/java/src/game/network/NetHandlerPlayServer.java +++ b/java/src/game/network/NetHandlerPlayServer.java @@ -1628,7 +1628,7 @@ public class NetHandlerPlayServer extends NetHandler implements ICrafting } private boolean setVar(String line) { - if(!this.isAdmin() || !line.startsWith("#")) + if(!this.isAdmin()) return false; if(line.length() < 2) { for(Entry entry : Config.VARS.entrySet()) { @@ -1650,7 +1650,7 @@ public class NetHandlerPlayServer extends NetHandler implements ICrafting this.addFeed(TextColor.GREEN + "SVARs insgesamt registriert: %d", Config.VARS.size()); return true; } - line = line.substring(1).trim(); + line = line.trim(); String[] args = /* line.isEmpty() ? new String[0] : */ line.split(" ", -1); if(args.length == 1) { // case 0: @@ -1838,114 +1838,120 @@ public class NetHandlerPlayServer extends NetHandler implements ICrafting } private boolean teleport(String line) { - if((!Config.teleportAllowed && !this.isAdmin()) || !line.startsWith("/")) + if(!Config.teleportAllowed && !this.isAdmin()) return false; - line = line.substring(1).trim(); + line = line.trim(); String[] argv = line.split(" ", -1); - if(line.isEmpty() || argv.length == 0 || argv.length == 2) { - this.addFeed(TextColor.DRED + "Spieler, @Warp, *Dimension oder X Y Z [Dimension]"); - return true; - } - if(argv.length != 1) { - Double ax = parseCoordinate(argv[0], true); +// if(line.isEmpty() || argv.length == 0 || argv.length == 2) { +// this.addFeed(TextColor.DRED + "+Spieler, @Warp, *Dimension oder X Y Z [Dimension]"); +// return true; +// } + String tgt = argv[0]; + if(tgt.equals("#")) { + if(argv.length < 4) { + this.addFeed(TextColor.DRED + "# X Y Z [Dimension]"); + return true; + } + Double ax = parseCoordinate(argv[1], true); if(ax == null) return true; - Double ay = parseCoordinate(argv[1], false); + Double ay = parseCoordinate(argv[2], false); if(ay == null) return true; - Double az = parseCoordinate(argv[2], true); + Double az = parseCoordinate(argv[3], true); if(az == null) return true; int dimension = this.entity.worldObj.dimension.getDimensionId(); - if(argv.length > 3) { + if(argv.length > 4) { WorldServer world; try { - world = this.server.getWorld(Integer.parseInt(argv[3])); + world = this.server.getWorld(Integer.parseInt(argv[4])); } catch(NumberFormatException e) { - world = this.server.getWorld(argv[3]); + world = this.server.getWorld(argv[4]); } if(world == null) { - this.addFeed(TextColor.DRED + "Dimension '%s' existiert nicht", argv[3]); + this.addFeed(TextColor.DRED + "Dimension '%s' existiert nicht", argv[4]); return true; } dimension = world.dimension.getDimensionId(); } this.entity.teleport(ax, ay, az, this.entity.rotYaw, this.entity.rotPitch, dimension); } - else { - String tgt = argv[0]; - if(tgt.startsWith("@")) { - tgt = tgt.substring(1); - if(tgt.equals("spawn")) { - WorldServer world = this.server.getWorld(Config.spawnDim); - world = world == null ? this.server.getSpace() : world; - int y = Config.spawnY; - while(world.getState(new BlockPos(Config.spawnX, y, Config.spawnZ)).getBlock().getMaterial().blocksMovement() && y < 511) - y++; - this.entity.teleport(Config.spawnX + 0.5d, (double)y, Config.spawnZ + 0.5d, - Config.spawnYaw, Config.spawnPitch, world.dimension.getDimensionId()); - } - else { - Position pos = this.server.getWarps().get(tgt); - if(pos == null) { - this.addFeed(TextColor.DRED + "Warp '%s' existiert nicht", tgt); - return true; - } - if(this.server.getWorld(pos.dim) == null) { - this.addFeed(TextColor.DRED + "Warp '%s' hat kein Level (%s)", tgt, pos.dim); - return true; - } - this.entity.teleport(pos); - } - } - else if(tgt.startsWith("*")) { - tgt = tgt.substring(1); - WorldServer world; - try { - world = this.server.getWorld(Integer.parseInt(tgt)); - } - catch(NumberFormatException e) { - world = this.server.getWorld(tgt); - } - if(world == null) { - this.addFeed(TextColor.DRED + "Dimension '%s' existiert nicht", tgt); - return true; - } -// int dimension = world.dimension.getDimensionId(); -// int dimension = parseDimension(sender, tgt); - BlockPos pos = this.entity.getPosition(); -// WorldServer world = Server.getServer().getWorld(dimension); - pos = pos.getY() < 0 ? new BlockPos(pos.getX(), 0, pos.getZ()) : pos; - if(world.getState(pos).getBlock().getMaterial().blocksMovement() || world.getState(pos).getBlock().getMaterial().isLiquid()) { - while((world.getState(pos).getBlock().getMaterial().blocksMovement() || world.getState(pos).getBlock().getMaterial().isLiquid()) && pos.getY() < 511) - pos = pos.up(); - } - else { - while(!(world.getState(pos).getBlock().getMaterial().blocksMovement() || world.getState(pos).getBlock().getMaterial().isLiquid()) && pos.getY() > 0) - pos = pos.down(); - pos = pos.up(); - } - this.entity.teleport(pos, world.dimension.getDimensionId()); + if(tgt.startsWith("@")) { + tgt = tgt.substring(1); + if(tgt.equals("spawn")) { + WorldServer world = this.server.getWorld(Config.spawnDim); + world = world == null ? this.server.getSpace() : world; + int y = Config.spawnY; + while(world.getState(new BlockPos(Config.spawnX, y, Config.spawnZ)).getBlock().getMaterial().blocksMovement() && y < 511) + y++; + this.entity.teleport(Config.spawnX + 0.5d, (double)y, Config.spawnZ + 0.5d, + Config.spawnYaw, Config.spawnPitch, world.dimension.getDimensionId()); } else { - NetHandlerPlayServer conn = this.server.getPlayer(tgt); - if(conn == null) { - Position pos = this.server.getOfflinePosition(tgt); - if(pos == null) { - this.addFeed(TextColor.DRED + "Spieler '%s' konnte nicht gefunden werden", tgt); - return true; - } - this.entity.teleport(pos); + Position pos = this.server.getWarps().get(tgt); + if(pos == null) { + this.addFeed(TextColor.DRED + "Warp '%s' existiert nicht", tgt); + return true; } - else { - EntityNPC dest = conn.getEntity(); - if(dest != null) - this.entity.teleport(dest.posX, dest.posY, dest.posZ, dest.rotYaw, dest.rotPitch, dest.worldObj.dimension.getDimensionId()); + if(this.server.getWorld(pos.dim) == null) { + this.addFeed(TextColor.DRED + "Warp '%s' hat kein Level (%s)", tgt, pos.dim); + return true; } + this.entity.teleport(pos); } + return true; } - return true; + else if(tgt.startsWith("*")) { + tgt = tgt.substring(1); + WorldServer world; + try { + world = this.server.getWorld(Integer.parseInt(tgt)); + } + catch(NumberFormatException e) { + world = this.server.getWorld(tgt); + } + if(world == null) { + this.addFeed(TextColor.DRED + "Dimension '%s' existiert nicht", tgt); + return true; + } +// int dimension = world.dimension.getDimensionId(); +// int dimension = parseDimension(sender, tgt); + BlockPos pos = this.entity.getPosition(); +// WorldServer world = Server.getServer().getWorld(dimension); + pos = pos.getY() < 0 ? new BlockPos(pos.getX(), 0, pos.getZ()) : pos; + if(world.getState(pos).getBlock().getMaterial().blocksMovement() || world.getState(pos).getBlock().getMaterial().isLiquid()) { + while((world.getState(pos).getBlock().getMaterial().blocksMovement() || world.getState(pos).getBlock().getMaterial().isLiquid()) && pos.getY() < 511) + pos = pos.up(); + } + else { + while(!(world.getState(pos).getBlock().getMaterial().blocksMovement() || world.getState(pos).getBlock().getMaterial().isLiquid()) && pos.getY() > 0) + pos = pos.down(); + pos = pos.up(); + } + this.entity.teleport(pos, world.dimension.getDimensionId()); + return true; + } + else if(tgt.startsWith("+")) { + tgt = tgt.substring(1); + NetHandlerPlayServer conn = this.server.getPlayer(tgt); + if(conn == null) { + Position pos = this.server.getOfflinePosition(tgt); + if(pos == null) { + this.addFeed(TextColor.DRED + "Spieler '%s' konnte nicht gefunden werden", tgt); + return true; + } + this.entity.teleport(pos); + } + else { + EntityNPC dest = conn.getEntity(); + if(dest != null) + this.entity.teleport(dest.posX, dest.posY, dest.posZ, dest.rotYaw, dest.rotPitch, dest.worldObj.dimension.getDimensionId()); + } + return true; + } + return false; } public void processMessage(CPacketMessage packetIn) @@ -1959,11 +1965,16 @@ public class NetHandlerPlayServer extends NetHandler implements ICrafting throw new IllegalArgumentException("Ungültige Zeichen in Nachricht"); } switch(packetIn.getType()) { + case COMMAND: + if(!this.teleport(msg) && !this.setVar(msg) && !this.setAdmin(msg)) + this.addFeed(TextColor.RED + "Befehl wurde nicht gefunden"); + break; + case CHAT: - if(!this.teleport(msg) && !this.sendPlayer(msg) && !this.setVar(msg) && !this.setAdmin(msg)) + if(!this.sendPlayer(msg)) this.server.sendPacket(new SPacketMessage(String.format("%s %s", this.entity.getColoredName(TextColor.LGRAY), msg))); break; - + case DISPLAY: if(msg.isEmpty() || !isValidNick(msg) || msg.length() > MAX_NICK_LENGTH) throw new IllegalArgumentException("Ungültiger Anzeigename"); @@ -2891,16 +2902,20 @@ public class NetHandlerPlayServer extends NetHandler implements ICrafting } } - private List getWarpList() { - List warps = Lists.newArrayList(this.server.getUsers()); - warps.add("@spawn"); - for(String warp : this.server.getWarps().keySet()) { - warps.add("@" + warp); + private Iterable getWarpList(char pre) { + switch(pre) { + case '+': + return Lists.newArrayList(this.server.getUsers()); + case '@': + List warps = Lists.newArrayList("spawn"); + for(String warp : this.server.getWarps().keySet()) { + warps.add(warp); + } + return warps; + case '*': + return UniverseRegistry.getWorldNames(); } - for(String dim : UniverseRegistry.getWorldNames()) { - warps.add("*" + dim); - } - return warps; + return Lists.newArrayList(); } private static List getVarList() { @@ -2933,15 +2948,14 @@ public class NetHandlerPlayServer extends NetHandler implements ICrafting // if(list == null) { // list = Lists.newArrayList(); String s = packetIn.getMessage(); - char pre = s.startsWith("@") || (this.isAdmin() && (s.startsWith("#") || s.startsWith("!"))) || ((Config.teleportAllowed || this.isAdmin()) && s.startsWith("/")) ? s.charAt(0) : 0; + char pre = s.startsWith("#") || s.startsWith("!") || s.startsWith("+") || s.startsWith("*") || s.startsWith("@") ? s.charAt(0) : 0; s = pre == 0 ? s : s.substring(1); String[] argv = s.split(" ", -1); s = argv[argv.length - 1]; - Iterable res = pre == '#' ? - (argv.length == 1 ? getVarList() : (argv.length == 2 ? (argv[0].equals("time") ? Lists.newArrayList("day", "night", "noon", "midnight", "sunrise", "sunset") : getVarCompletion(argv[0])) : Lists.newArrayList())) : (pre == '/' ? (argv.length == 4 ? UniverseRegistry.getWorldNames() : (argv.length == 1 ? this.getWarpList() : Lists.newArrayList())) : this.server.getAllUsernames()); + Iterable res = pre == '#' && (Config.teleportAllowed || this.isAdmin()) ? (argv.length == 5 ? UniverseRegistry.getWorldNames() : Lists.newArrayList()) : ((pre == '+' || pre == '*' || pre == '@') && (Config.teleportAllowed || this.isAdmin()) ? (argv.length == 1 ? this.getWarpList(pre) : Lists.newArrayList()) : (pre == '!' && this.isAdmin() ? this.server.getAllUsernames() : ((this.isAdmin() ? (argv.length == 1 ? getVarList() : (argv.length == 2 ? (argv[0].equals("time") ? Lists.newArrayList("day", "night", "noon", "midnight", "sunrise", "sunset") : getVarCompletion(argv[0])) : Lists.newArrayList())) : Lists.newArrayList())))); for(String s1 : res) { if(s1.regionMatches(true, 0, s, 0, s.length())) - list.add((argv.length == 1 ? pre : "") + s1); + list.add((argv.length == 1 && pre != 0 ? pre : "") + s1); } // } diff --git a/java/src/game/packet/CPacketMessage.java b/java/src/game/packet/CPacketMessage.java index f5a4ce0..85640c4 100755 --- a/java/src/game/packet/CPacketMessage.java +++ b/java/src/game/packet/CPacketMessage.java @@ -49,7 +49,7 @@ public class CPacketMessage implements Packet } public static enum Type { - CHAT(NetHandlerPlayServer.MAX_CMD_LENGTH), DISPLAY(NetHandlerPlayServer.MAX_NICK_LENGTH); // , ITEM(30); + COMMAND(NetHandlerPlayServer.MAX_CMD_LENGTH), CHAT(NetHandlerPlayServer.MAX_CMD_LENGTH), DISPLAY(NetHandlerPlayServer.MAX_NICK_LENGTH); // , ITEM(30); private final int length; diff --git a/java/src/game/renderer/Drawing.java b/java/src/game/renderer/Drawing.java index 59d7336..e383ea0 100644 --- a/java/src/game/renderer/Drawing.java +++ b/java/src/game/renderer/Drawing.java @@ -512,6 +512,10 @@ public abstract class Drawing { return txt_size(0, 0, 0, 0, Integer.MAX_VALUE, Integer.MAX_VALUE, str).xpos; } + public static int getBoxWidth(String str) { + return txt_box(0, 0, 0, 0, Integer.MAX_VALUE, Integer.MAX_VALUE, str).xpos + 4; + } + public static void drawTextbox(String str, int x, int y, int back) { Vec2i size = txt_box(x + 2, y, x + 2, y, Integer.MAX_VALUE, Integer.MAX_VALUE, str); drawRect(x, y, size.xpos + 2, size.ypos, back); diff --git a/java/src/game/util/Util.java b/java/src/game/util/Util.java index 88dfeee..7d1b147 100644 --- a/java/src/game/util/Util.java +++ b/java/src/game/util/Util.java @@ -245,6 +245,18 @@ int utf_len(const char *str) { return buildLines("\n", func, elems); } + public static String buildLines(String separator, Iterable elems) { + return buildLines(separator, new Function() { + public String apply(T t) { + return String.valueOf(t); + } + }, elems); + } + + public static String buildLines(Iterable elems) { + return buildLines("\n", elems); + } + public static String buildLines(String separator, Function func, T ... elems) { StringBuilder sb = new StringBuilder(); for(T elem : elems) { @@ -258,4 +270,16 @@ int utf_len(const char *str) { public static String buildLines(Function func, T ... elems) { return buildLines("\n", func, elems); } + + public static String buildLines(String separator, T ... elems) { + return buildLines(separator, new Function() { + public String apply(T t) { + return String.valueOf(t); + } + }, elems); + } + + public static String buildLines(T ... elems) { + return buildLines("\n", elems); + } } diff --git a/java/src/game/window/Bind.java b/java/src/game/window/Bind.java index d10f7a3..7758149 100644 --- a/java/src/game/window/Bind.java +++ b/java/src/game/window/Bind.java @@ -31,6 +31,7 @@ public enum Bind implements IStringSerializable, CVar { SELECT7("select7", "Auswahl #7", Keysym.N7), SELECT8("select8", "Auswahl #8", Keysym.N8), SELECT9("select9", "Auswahl #9", Keysym.N9), + CONSOLE("console", "Konsole", Keysym.F1), COMMAND("command", "Befehl / Chat", Keysym.C), INFO("info", "Infos einblenden", Keysym.TAB), PERSPECTIVE("perspective", "Perspektive ändern", Keysym.F5),