From 7e99cfeb50bec4e0acec45c4d66ab203dfa841a5 Mon Sep 17 00:00:00 2001 From: CrushedPixel Date: Thu, 30 Jul 2015 11:43:18 +0200 Subject: [PATCH] Allow for spaces in Replay Names in GuiRenameReplay and use proper variable names instead of copy-pasted SrgNames --- .../gui/replayviewer/GuiRenameReplay.java | 35 ++++++++----------- 1 file changed, 15 insertions(+), 20 deletions(-) diff --git a/src/main/java/eu/crushedpixel/replaymod/gui/replayviewer/GuiRenameReplay.java b/src/main/java/eu/crushedpixel/replaymod/gui/replayviewer/GuiRenameReplay.java index 841cacde..4924aa70 100755 --- a/src/main/java/eu/crushedpixel/replaymod/gui/replayviewer/GuiRenameReplay.java +++ b/src/main/java/eu/crushedpixel/replaymod/gui/replayviewer/GuiRenameReplay.java @@ -15,17 +15,17 @@ import java.io.IOException; import java.util.List; public class GuiRenameReplay extends GuiScreen { - private GuiScreen field_146585_a; - private GuiTextField field_146583_f; + private GuiScreen parent; + private GuiTextField replayNameInput; private File file; public GuiRenameReplay(GuiScreen parent, File file) { - this.field_146585_a = parent; + this.parent = parent; this.file = file; } public void updateScreen() { - this.field_146583_f.updateCursorCounter(); + this.replayNameInput.updateCursorCounter(); } public void initGui() { @@ -36,9 +36,9 @@ public class GuiRenameReplay extends GuiScreen { buttonList.add(new GuiButton(0, this.width / 2 - 100, this.height / 4 + 96 + 12, I18n.format("replaymod.gui.rename"))); buttonList.add(new GuiButton(1, this.width / 2 - 100, this.height / 4 + 120 + 12, I18n.format("replaymod.gui.cancel"))); String s = FilenameUtils.getBaseName(file.getAbsolutePath()); - this.field_146583_f = new GuiTextField(2, this.fontRendererObj, this.width / 2 - 100, 60, 200, 20); - this.field_146583_f.setFocused(true); - this.field_146583_f.setText(s); + this.replayNameInput = new GuiTextField(2, this.fontRendererObj, this.width / 2 - 100, 60, 200, 20); + this.replayNameInput.setFocused(true); + this.replayNameInput.setText(s); } public void onGuiClosed() { @@ -48,26 +48,21 @@ public class GuiRenameReplay extends GuiScreen { protected void actionPerformed(GuiButton button) throws IOException { if(button.enabled) { if(button.id == 1) { - this.mc.displayGuiScreen(this.field_146585_a); + this.mc.displayGuiScreen(this.parent); } else if(button.id == 0) { File folder = ReplayFileIO.getReplayFolder(); - File initRenamed = new File(folder, (this.field_146583_f.getText().trim() + ReplayFile.ZIP_FILE_EXTENSION).replaceAll("[^a-zA-Z0-9\\.\\-]", "_")); - File renamed = initRenamed; - int i = 1; - while(renamed.isFile()) { - renamed = new File(initRenamed.getAbsolutePath() + "_" + i); - i++; - } + File initRenamed = new File(folder, (this.replayNameInput.getText().trim() + ReplayFile.ZIP_FILE_EXTENSION).replaceAll("[^a-zA-Z0-9\\.\\- ]", "_")); + File renamed = ReplayFileIO.getNextFreeFile(initRenamed); FileUtils.moveFile(file, renamed); - this.mc.displayGuiScreen(this.field_146585_a); + this.mc.displayGuiScreen(this.parent); } } } protected void keyTyped(char typedChar, int keyCode) throws IOException { - this.field_146583_f.textboxKeyTyped(typedChar, keyCode); - ((GuiButton) this.buttonList.get(0)).enabled = this.field_146583_f.getText().trim().length() > 0; + this.replayNameInput.textboxKeyTyped(typedChar, keyCode); + ((GuiButton) this.buttonList.get(0)).enabled = this.replayNameInput.getText().trim().length() > 0; if(keyCode == 28 || keyCode == 156) { this.actionPerformed((GuiButton) this.buttonList.get(0)); @@ -76,14 +71,14 @@ public class GuiRenameReplay extends GuiScreen { protected void mouseClicked(int mouseX, int mouseY, int mouseButton) throws IOException { super.mouseClicked(mouseX, mouseY, mouseButton); - this.field_146583_f.mouseClicked(mouseX, mouseY, mouseButton); + this.replayNameInput.mouseClicked(mouseX, mouseY, mouseButton); } public void drawScreen(int mouseX, int mouseY, float partialTicks) { this.drawDefaultBackground(); this.drawCenteredString(this.fontRendererObj, I18n.format("replaymod.gui.viewer.rename.title"), this.width / 2, 20, 16777215); this.drawString(this.fontRendererObj, I18n.format("replaymod.gui.viewer.rename.name"), this.width / 2 - 100, 47, 10526880); - this.field_146583_f.drawTextBox(); + this.replayNameInput.drawTextBox(); super.drawScreen(mouseX, mouseY, partialTicks); } }