Refactored and reformatted code to use less static variables

This commit is contained in:
CrushedPixel
2015-04-23 14:09:54 +02:00
parent f22416be2c
commit 0003f040ed
109 changed files with 9037 additions and 10229 deletions

View File

@@ -2,27 +2,26 @@ package eu.crushedpixel.replaymod.gui;
import eu.crushedpixel.replaymod.replay.ReplayProcess;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.GuiScreen;
import net.minecraft.client.gui.GuiYesNo;
import net.minecraft.client.gui.GuiYesNoCallback;
public class GuiCancelRender extends GuiYesNo {
private static Minecraft mc = Minecraft.getMinecraft();
private static GuiYesNoCallback callback = new GuiYesNoCallback() {
@Override
public void confirmClicked(boolean result, int id) {
if(result) {
ReplayProcess.stopReplayProcess(false);
}
mc.displayGuiScreen(null);
}
};
public GuiCancelRender() {
super(callback, "Cancel Rendering", "Are you sure that you want to cancel the current rendering process?", 0);
}
private static Minecraft mc = Minecraft.getMinecraft();
private static GuiYesNoCallback callback = new GuiYesNoCallback() {
@Override
public void confirmClicked(boolean result, int id) {
if(result) {
ReplayProcess.stopReplayProcess(false);
}
mc.displayGuiScreen(null);
}
};
public GuiCancelRender() {
super(callback, "Cancel Rendering", "Are you sure that you want to cancel the current rendering process?", 0);
}
}

View File

@@ -2,47 +2,47 @@ package eu.crushedpixel.replaymod.gui;
public class GuiConstants {
public static final int CENTER_MY_REPLAYS_BUTTON = 2001;
public static final int CENTER_SEARCH_BUTTON = 2002;
public static final int CENTER_BACK_BUTTON = 2003;
public static final int CENTER_LOGOUT_BUTTON = 2004;
public static final int CENTER_RECENT_BUTTON = 2005;
public static final int CENTER_BEST_BUTTON = 2006;
public static final int CENTER_MANAGER_BUTTON = 2007;
public static final int UPLOAD_NAME_INPUT = 3001;
public static final int UPLOAD_CATEGORY_BUTTON = 3002;
public static final int UPLOAD_START_BUTTON = 3003;
public static final int UPLOAD_CANCEL_BUTTON = 3004;
public static final int UPLOAD_BACK_BUTTON = 3005;
public static final int UPLOAD_INFO_FIELD = 3006;
public static final int UPLOAD_TAG_INPUT = 3007;
public static final int UPLOAD_TAG_PLACEHOLDER = 3008;
public static final int EXIT_REPLAY_BUTTON = 4001;
public static final int REPLAY_OPTIONS_BUTTON_ID = 8000;
public static final int REPLAY_MANAGER_BUTTON_ID = 9001;
public static final int REPLAY_EDITOR_BUTTON_ID = 9002;
public static final int REPLAY_CENTER_BUTTON_ID = 9003;
public static final int REPLAY_CENTER_LOGIN_TEXT_ID = 9004;
public static final int REPLAY_CENTER_PASSWORD_TEXT_ID = 9005;
public static final int LOGIN_OKAY_BUTTON = 1100;
public static final int LOGIN_CANCEL_BUTTON = 1101;
public static final int REPLAY_EDITOR_TRIM_TAB = 5000;
public static final int REPLAY_EDITOR_CONNECT_TAB = 5001;
public static final int REPLAY_EDITOR_MODIFY_TAB = 5002;
public static final int REPLAY_EDITOR_SAVEMODE_BUTTON = 5003;
public static final int REPLAY_EDITOR_SAVE_BUTTON = 5004;
public static final int REPLAY_EDITOR_BACK_BUTTON = 5005;
public static final int REPLAY_EDITOR_UP_BUTTON = 5006;
public static final int REPLAY_EDITOR_DOWN_BUTTON = 5007;
public static final int REPLAY_EDITOR_REMOVE_BUTTON = 5008;
public static final int REPLAY_EDITOR_ADD_BUTTON = 5009;
public static final int CENTER_MY_REPLAYS_BUTTON = 2001;
public static final int CENTER_SEARCH_BUTTON = 2002;
public static final int CENTER_BACK_BUTTON = 2003;
public static final int CENTER_LOGOUT_BUTTON = 2004;
public static final int CENTER_RECENT_BUTTON = 2005;
public static final int CENTER_BEST_BUTTON = 2006;
public static final int CENTER_MANAGER_BUTTON = 2007;
public static final int UPLOAD_NAME_INPUT = 3001;
public static final int UPLOAD_CATEGORY_BUTTON = 3002;
public static final int UPLOAD_START_BUTTON = 3003;
public static final int UPLOAD_CANCEL_BUTTON = 3004;
public static final int UPLOAD_BACK_BUTTON = 3005;
public static final int UPLOAD_INFO_FIELD = 3006;
public static final int UPLOAD_TAG_INPUT = 3007;
public static final int UPLOAD_TAG_PLACEHOLDER = 3008;
public static final int EXIT_REPLAY_BUTTON = 4001;
public static final int REPLAY_OPTIONS_BUTTON_ID = 8000;
public static final int REPLAY_MANAGER_BUTTON_ID = 9001;
public static final int REPLAY_EDITOR_BUTTON_ID = 9002;
public static final int REPLAY_CENTER_BUTTON_ID = 9003;
public static final int REPLAY_CENTER_LOGIN_TEXT_ID = 9004;
public static final int REPLAY_CENTER_PASSWORD_TEXT_ID = 9005;
public static final int LOGIN_OKAY_BUTTON = 1100;
public static final int LOGIN_CANCEL_BUTTON = 1101;
public static final int REPLAY_EDITOR_TRIM_TAB = 5000;
public static final int REPLAY_EDITOR_CONNECT_TAB = 5001;
public static final int REPLAY_EDITOR_MODIFY_TAB = 5002;
public static final int REPLAY_EDITOR_SAVEMODE_BUTTON = 5003;
public static final int REPLAY_EDITOR_SAVE_BUTTON = 5004;
public static final int REPLAY_EDITOR_BACK_BUTTON = 5005;
public static final int REPLAY_EDITOR_UP_BUTTON = 5006;
public static final int REPLAY_EDITOR_DOWN_BUTTON = 5007;
public static final int REPLAY_EDITOR_REMOVE_BUTTON = 5008;
public static final int REPLAY_EDITOR_ADD_BUTTON = 5009;
}

View File

@@ -0,0 +1,7 @@
package eu.crushedpixel.replaymod.gui;
import net.minecraft.client.gui.GuiScreen;
public class GuiMouseInput extends GuiScreen {
}

View File

@@ -1,33 +1,27 @@
package eu.crushedpixel.replaymod.gui;
import java.awt.Color;
import eu.crushedpixel.replaymod.gui.replayviewer.GuiReplayViewer;
import eu.crushedpixel.replaymod.recording.ConnectionEventHandler;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.GuiIngameMenu;
import net.minecraft.client.gui.GuiScreen;
import net.minecraftforge.fml.client.FMLClientHandler;
public class GuiReplaySaving extends GuiScreen {
public static boolean replaySaving = false;
private GuiScreen waiting = null;
public GuiReplaySaving(GuiScreen waiting) {
this.waiting = waiting;
}
@Override
public void drawScreen(int mouseX, int mouseY, float partialTicks) {
this.drawDefaultBackground();
this.drawCenteredString(this.fontRendererObj, "Saving Replay File...", this.width / 2, 20, 16777215);
this.drawCenteredString(this.fontRendererObj, "Please wait while your recent Replay is being saved.", this.width / 2, 40, 16777215);
super.drawScreen(mouseX, mouseY, partialTicks);
if(!replaySaving) {
Minecraft.getMinecraft().displayGuiScreen(waiting);
}
}
public static boolean replaySaving = false;
private GuiScreen waiting = null;
public GuiReplaySaving(GuiScreen waiting) {
this.waiting = waiting;
}
@Override
public void drawScreen(int mouseX, int mouseY, float partialTicks) {
this.drawDefaultBackground();
this.drawCenteredString(this.fontRendererObj, "Saving Replay File...", this.width / 2, 20, 16777215);
this.drawCenteredString(this.fontRendererObj, "Please wait while your recent Replay is being saved.", this.width / 2, 40, 16777215);
super.drawScreen(mouseX, mouseY, partialTicks);
if(!replaySaving) {
Minecraft.getMinecraft().displayGuiScreen(waiting);
}
}
}

View File

@@ -1,192 +1,188 @@
package eu.crushedpixel.replaymod.gui;
import java.awt.Color;
import java.io.IOException;
import net.minecraft.client.gui.GuiButton;
import net.minecraft.client.gui.GuiScreen;
import net.minecraft.client.resources.I18n;
import net.minecraftforge.fml.client.FMLClientHandler;
import eu.crushedpixel.replaymod.ReplayMod;
import eu.crushedpixel.replaymod.settings.ReplaySettings;
import eu.crushedpixel.replaymod.settings.ReplaySettings.RecordingOptions;
import eu.crushedpixel.replaymod.settings.ReplaySettings.RenderOptions;
import eu.crushedpixel.replaymod.settings.ReplaySettings.ReplayOptions;
import net.minecraft.client.gui.GuiButton;
import net.minecraft.client.gui.GuiScreen;
import net.minecraft.client.resources.I18n;
import net.minecraftforge.fml.client.FMLClientHandler;
import java.awt.*;
import java.io.IOException;
public class GuiReplaySettings extends GuiScreen {
private GuiScreen parentGuiScreen;
protected String screenTitle = "Replay Mod Settings";
//TODO: Move to GuiConstants
private static final int QUALITY_SLIDER_ID = 9003;
private static final int RECORDSERVER_ID = 9004;
private static final int RECORDSP_ID = 9005;
private static final int SEND_CHAT = 9006;
private static final int FORCE_LINEAR = 9007;
private static final int ENABLE_LIGHTING = 9008;
private static final int FRAMERATE_SLIDER_ID = 9009;
private static final int RESOURCEPACK_ID = 9010;
private static final int WAITFORCHUNKS_ID = 9011;
private static final int INDICATOR_ID = 9012;
protected String screenTitle = "Replay Mod Settings";
private GuiScreen parentGuiScreen;
private GuiButton recordServerButton, recordSPButton, sendChatButton, linearButton, lightingButton,
resourcePackButton, waitForChunksButton, showIndicatorButton;
//TODO: Move to GuiConstants
private static final int QUALITY_SLIDER_ID = 9003;
private static final int RECORDSERVER_ID = 9004;
private static final int RECORDSP_ID = 9005;
private static final int SEND_CHAT = 9006;
private static final int FORCE_LINEAR = 9007;
private static final int ENABLE_LIGHTING = 9008;
private static final int FRAMERATE_SLIDER_ID = 9009;
private static final int RESOURCEPACK_ID = 9010;
private static final int WAITFORCHUNKS_ID = 9011;
private static final int INDICATOR_ID = 9012;
public GuiReplaySettings(GuiScreen parentGuiScreen) {
this.parentGuiScreen = parentGuiScreen;
}
private GuiButton recordServerButton, recordSPButton, sendChatButton, linearButton, lightingButton,
resourcePackButton, waitForChunksButton, showIndicatorButton;
public void initGui() {
this.screenTitle = I18n.format("Replay Mod Settings", new Object[0]);
this.buttonList.clear();
this.buttonList.add(new GuiButton(200, this.width / 2 - 100, this.height - 27, I18n.format("gui.done", new Object[0])));
public GuiReplaySettings(GuiScreen parentGuiScreen) {
this.parentGuiScreen = parentGuiScreen;
}
ReplaySettings settings = ReplayMod.replaySettings;
public void initGui() {
this.screenTitle = I18n.format("Replay Mod Settings", new Object[0]);
this.buttonList.clear();
this.buttonList.add(new GuiButton(200, this.width / 2 - 100, this.height - 27, I18n.format("gui.done", new Object[0])));
int k = 0;
int i = 0;
ReplaySettings settings = ReplayMod.replaySettings;
for(RecordingOptions o : RecordingOptions.values()) {
if(o == RecordingOptions.notifications) {
this.buttonList.add(sendChatButton = new GuiButton(SEND_CHAT,
this.width / 2 - 155 + i % 2 * 160, this.height / 6 + 24 * (i >> 1), 150, 20,
"Enable Notifications: " + onOff(settings.isShowNotifications())));
} else if(o == RecordingOptions.recordServer) {
this.buttonList.add(recordServerButton = new GuiButton(RECORDSERVER_ID,
this.width / 2 - 155 + i % 2 * 160, this.height / 6 + 24 * (i >> 1), 150, 20, "Record Server: "
+ onOff(settings.isEnableRecordingServer())));
} else if(o == RecordingOptions.recordSingleplayer) {
this.buttonList.add(recordSPButton = new GuiButton(RECORDSP_ID, this.width / 2 - 155 + i % 2 * 160,
this.height / 6 + 24 * (i >> 1), 150, 20, "Record Singleplayer: " + onOff(settings.isEnableRecordingSingleplayer())));
} else if(o == RecordingOptions.indicator) {
this.buttonList.add(showIndicatorButton = new GuiButton(INDICATOR_ID, this.width / 2 - 155 + i % 2 * 160,
this.height / 6 + 24 * (i >> 1), 150, 20, "Show Recording Indicator: " + onOff(settings.showRecordingIndicator())));
}
int k = 0;
int i = 0;
for(RecordingOptions o : RecordingOptions.values()) {
if(o == RecordingOptions.notifications) {
this.buttonList.add(sendChatButton = new GuiButton(SEND_CHAT,
this.width / 2 - 155 + i % 2 * 160, this.height / 6 + 24 * (i >> 1), 150, 20,
"Enable Notifications: "+onOff(settings.isShowNotifications())));
} else if(o == RecordingOptions.recordServer) {
this.buttonList.add(recordServerButton = new GuiButton(RECORDSERVER_ID,
this.width / 2 - 155 + i % 2 * 160, this.height / 6 + 24 * (i >> 1), 150, 20, "Record Server: "
+onOff(settings.isEnableRecordingServer())));
} else if(o == RecordingOptions.recordSingleplayer) {
this.buttonList.add(recordSPButton = new GuiButton(RECORDSP_ID, this.width / 2 - 155 + i % 2 * 160,
this.height / 6 + 24 * (i >> 1), 150, 20, "Record Singleplayer: "+onOff(settings.isEnableRecordingSingleplayer())));
} else if(o == RecordingOptions.indicator) {
this.buttonList.add(showIndicatorButton = new GuiButton(INDICATOR_ID, this.width / 2 - 155 + i % 2 * 160,
this.height / 6 + 24 * (i >> 1), 150, 20, "Show Recording Indicator: "+onOff(settings.showRecordingIndicator())));
}
++i;
++k;
}
if (i % 2 == 1)
{
++i;
}
for(ReplayOptions o : ReplayOptions.values()) {
if(o == ReplayOptions.lighting) {
this.buttonList.add(lightingButton = new GuiButton(ENABLE_LIGHTING, this.width / 2 - 155 + i % 2 * 160,
this.height / 6 + 24 * (i >> 1), 150, 20, "Enable Lighting: "+onOff(settings.isLightingEnabled())));
} else if(o == ReplayOptions.linear) {
this.buttonList.add(linearButton = new GuiButton(FORCE_LINEAR, this.width / 2 - 155 + i % 2 * 160,
this.height / 6 + 24 * (i >> 1), 150, 20, "Camera Path: "+linearOnOff(settings.isLinearMovement())));
} else if(o == ReplayOptions.useResources) {
this.buttonList.add(resourcePackButton = new GuiButton(RESOURCEPACK_ID, this.width / 2 - 155 + i % 2 * 160,
this.height / 6 + 24 * (i >> 1), 150, 20, "Server Resource Packs: "+onOff(settings.getUseResourcePacks())));
}
++i;
++k;
}
if (i % 2 == 1)
{
++i;
}
for(RenderOptions o : RenderOptions.values()) {
if(o == RenderOptions.videoFramerate) {
this.buttonList.add(new GuiVideoFramerateSlider(FRAMERATE_SLIDER_ID,
this.width / 2 - 155 + i % 2 * 160, this.height / 6 + 24 * (i >> 1), settings.getVideoFramerate(), "Video Framerate"));
} else if(o == RenderOptions.videoQuality) {
this.buttonList.add(new GuiVideoQualitySlider(QUALITY_SLIDER_ID,
this.width / 2 - 155 + i % 2 * 160, this.height / 6 + 24 * (i >> 1), (float)settings.getVideoQuality(), "Video Quality"));
} else if(o == RenderOptions.waitForChunks) {
this.buttonList.add(resourcePackButton = new GuiButton(WAITFORCHUNKS_ID, this.width / 2 - 155 + i % 2 * 160,
this.height / 6 + 24 * (i >> 1), 150, 20, "Force Render Chunks: "+onOff(settings.getWaitForChunks())));
}
++i;
++k;
}
}
private String onOff(boolean on) {
return on ? "ON" : "OFF";
}
private String linearOnOff(boolean on) {
return on ? "Linear" : "Cubic";
}
@Override
public void drawScreen(int mouseX, int mouseY, float partialTicks) {
this.drawDefaultBackground();
this.drawCenteredString(this.fontRendererObj, "Replay Mod Settings", this.width / 2, 20, 16777215);
if (FMLClientHandler.instance().getClient().thePlayer != null) {
this.drawCenteredString(this.fontRendererObj, "WARNING: Recording settings are going to be", this.width / 2, 180, Color.RED.getRGB());
this.drawCenteredString(this.fontRendererObj, "applied the next time you join a world.", this.width / 2, 190, Color.RED.getRGB());
}
super.drawScreen(mouseX, mouseY, partialTicks);
}
++i;
++k;
}
protected void actionPerformed(GuiButton button) throws IOException {
if (button.enabled) {
switch(button.id) {
case 200:
this.mc.displayGuiScreen(this.parentGuiScreen);
break;
case RECORDSERVER_ID:
boolean enabled = ReplayMod.replaySettings.isEnableRecordingServer();
enabled = !enabled;
recordServerButton.displayString = "Record Server: "+onOff(enabled);
ReplayMod.replaySettings.setEnableRecordingServer(enabled);
break;
case RECORDSP_ID:
enabled = ReplayMod.replaySettings.isEnableRecordingSingleplayer();
enabled = !enabled;
recordSPButton.displayString = "Record Singleplayer: "+onOff(enabled);
ReplayMod.replaySettings.setEnableRecordingSingleplayer(enabled);
break;
case SEND_CHAT:
enabled = ReplayMod.replaySettings.isShowNotifications();
enabled = !enabled;
sendChatButton.displayString = "Enable Notifications: "+onOff(enabled);
ReplayMod.replaySettings.setShowNotifications(enabled);
break;
case FORCE_LINEAR:
enabled = ReplayMod.replaySettings.isLinearMovement();
enabled = !enabled;
linearButton.displayString = "Camera Path: "+linearOnOff(enabled);
ReplayMod.replaySettings.setLinearMovement(enabled);
break;
case ENABLE_LIGHTING:
enabled = ReplayMod.replaySettings.isLightingEnabled();
enabled = !enabled;
lightingButton.displayString = "Enable Lighting: "+onOff(enabled);
ReplayMod.replaySettings.setLightingEnabled(enabled);
break;
case RESOURCEPACK_ID:
enabled = ReplayMod.replaySettings.getUseResourcePacks();
enabled = !enabled;
resourcePackButton.displayString = "Server Resource Packs: "+onOff(enabled);
ReplayMod.replaySettings.setUseResourcePacks(enabled);
break;
case WAITFORCHUNKS_ID:
enabled = ReplayMod.replaySettings.getWaitForChunks();
enabled = !enabled;
resourcePackButton.displayString = "Force Render Chunks: "+onOff(enabled);
ReplayMod.replaySettings.setWaitForChunks(enabled);
break;
case INDICATOR_ID:
enabled = ReplayMod.replaySettings.showRecordingIndicator();
enabled = !enabled;
showIndicatorButton.displayString = "Show Recording Indicator: "+onOff(enabled);
ReplayMod.replaySettings.setEnableIndicator(enabled);
break;
}
}
}
if(i % 2 == 1) {
++i;
}
for(ReplayOptions o : ReplayOptions.values()) {
if(o == ReplayOptions.lighting) {
this.buttonList.add(lightingButton = new GuiButton(ENABLE_LIGHTING, this.width / 2 - 155 + i % 2 * 160,
this.height / 6 + 24 * (i >> 1), 150, 20, "Enable Lighting: " + onOff(settings.isLightingEnabled())));
} else if(o == ReplayOptions.linear) {
this.buttonList.add(linearButton = new GuiButton(FORCE_LINEAR, this.width / 2 - 155 + i % 2 * 160,
this.height / 6 + 24 * (i >> 1), 150, 20, "Camera Path: " + linearOnOff(settings.isLinearMovement())));
} else if(o == ReplayOptions.useResources) {
this.buttonList.add(resourcePackButton = new GuiButton(RESOURCEPACK_ID, this.width / 2 - 155 + i % 2 * 160,
this.height / 6 + 24 * (i >> 1), 150, 20, "Server Resource Packs: " + onOff(settings.getUseResourcePacks())));
}
++i;
++k;
}
if(i % 2 == 1) {
++i;
}
for(RenderOptions o : RenderOptions.values()) {
if(o == RenderOptions.videoFramerate) {
this.buttonList.add(new GuiVideoFramerateSlider(FRAMERATE_SLIDER_ID,
this.width / 2 - 155 + i % 2 * 160, this.height / 6 + 24 * (i >> 1), settings.getVideoFramerate(), "Video Framerate"));
} else if(o == RenderOptions.videoQuality) {
this.buttonList.add(new GuiVideoQualitySlider(QUALITY_SLIDER_ID,
this.width / 2 - 155 + i % 2 * 160, this.height / 6 + 24 * (i >> 1), (float) settings.getVideoQuality(), "Video Quality"));
} else if(o == RenderOptions.waitForChunks) {
this.buttonList.add(resourcePackButton = new GuiButton(WAITFORCHUNKS_ID, this.width / 2 - 155 + i % 2 * 160,
this.height / 6 + 24 * (i >> 1), 150, 20, "Force Render Chunks: " + onOff(settings.getWaitForChunks())));
}
++i;
++k;
}
}
private String onOff(boolean on) {
return on ? "ON" : "OFF";
}
private String linearOnOff(boolean on) {
return on ? "Linear" : "Cubic";
}
@Override
public void drawScreen(int mouseX, int mouseY, float partialTicks) {
this.drawDefaultBackground();
this.drawCenteredString(this.fontRendererObj, "Replay Mod Settings", this.width / 2, 20, 16777215);
if(FMLClientHandler.instance().getClient().thePlayer != null) {
this.drawCenteredString(this.fontRendererObj, "WARNING: Recording settings are going to be", this.width / 2, 180, Color.RED.getRGB());
this.drawCenteredString(this.fontRendererObj, "applied the next time you join a world.", this.width / 2, 190, Color.RED.getRGB());
}
super.drawScreen(mouseX, mouseY, partialTicks);
}
protected void actionPerformed(GuiButton button) throws IOException {
if(button.enabled) {
switch(button.id) {
case 200:
this.mc.displayGuiScreen(this.parentGuiScreen);
break;
case RECORDSERVER_ID:
boolean enabled = ReplayMod.replaySettings.isEnableRecordingServer();
enabled = !enabled;
recordServerButton.displayString = "Record Server: " + onOff(enabled);
ReplayMod.replaySettings.setEnableRecordingServer(enabled);
break;
case RECORDSP_ID:
enabled = ReplayMod.replaySettings.isEnableRecordingSingleplayer();
enabled = !enabled;
recordSPButton.displayString = "Record Singleplayer: " + onOff(enabled);
ReplayMod.replaySettings.setEnableRecordingSingleplayer(enabled);
break;
case SEND_CHAT:
enabled = ReplayMod.replaySettings.isShowNotifications();
enabled = !enabled;
sendChatButton.displayString = "Enable Notifications: " + onOff(enabled);
ReplayMod.replaySettings.setShowNotifications(enabled);
break;
case FORCE_LINEAR:
enabled = ReplayMod.replaySettings.isLinearMovement();
enabled = !enabled;
linearButton.displayString = "Camera Path: " + linearOnOff(enabled);
ReplayMod.replaySettings.setLinearMovement(enabled);
break;
case ENABLE_LIGHTING:
enabled = ReplayMod.replaySettings.isLightingEnabled();
enabled = !enabled;
lightingButton.displayString = "Enable Lighting: " + onOff(enabled);
ReplayMod.replaySettings.setLightingEnabled(enabled);
break;
case RESOURCEPACK_ID:
enabled = ReplayMod.replaySettings.getUseResourcePacks();
enabled = !enabled;
resourcePackButton.displayString = "Server Resource Packs: " + onOff(enabled);
ReplayMod.replaySettings.setUseResourcePacks(enabled);
break;
case WAITFORCHUNKS_ID:
enabled = ReplayMod.replaySettings.getWaitForChunks();
enabled = !enabled;
resourcePackButton.displayString = "Force Render Chunks: " + onOff(enabled);
ReplayMod.replaySettings.setWaitForChunks(enabled);
break;
case INDICATOR_ID:
enabled = ReplayMod.replaySettings.showRecordingIndicator();
enabled = !enabled;
showIndicatorButton.displayString = "Show Recording Indicator: " + onOff(enabled);
ReplayMod.replaySettings.setEnableIndicator(enabled);
break;
}
}
}
}

View File

@@ -1,190 +1,170 @@
package eu.crushedpixel.replaymod.gui;
import eu.crushedpixel.replaymod.ReplayMod;
import eu.crushedpixel.replaymod.gui.elements.GuiMouseInput;
import eu.crushedpixel.replaymod.replay.ReplayHandler;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.FontRenderer;
import net.minecraft.client.gui.GuiButton;
import net.minecraft.client.renderer.GlStateManager;
import net.minecraft.client.settings.GameSettings;
import net.minecraft.util.MathHelper;
import net.minecraftforge.fml.client.FMLClientHandler;
public class GuiReplaySpeedSlider extends GuiButton {
private float sliderValue;
private float sliderValue;
private float valueStep, valueMin, valueMax;
private String displayKey;
private boolean dragging = false;
private float valueStep, valueMin, valueMax;
private String displayKey;
private boolean dragging = false;
public GuiReplaySpeedSlider(int buttonId, int p_i45017_2_, int p_i45017_3_, String displayKey)
{
super(buttonId, p_i45017_2_, p_i45017_3_, 150, 20, "");
sliderValue = (9f/38f);
public GuiReplaySpeedSlider(int buttonId, int p_i45017_2_, int p_i45017_3_, String displayKey) {
super(buttonId, p_i45017_2_, p_i45017_3_, 150, 20, "");
sliderValue = (9f / 38f);
this.width = 100;
this.valueMin = 1;
this.valueMax = 38;
this.valueStep = 1;
this.displayString = displayKey+": 1x";
this.displayKey = displayKey;
this.width = 100;
this.valueMin = 1;
this.valueMax = 38;
this.valueStep = 1;
this.displayString = displayKey + ": 1x";
this.displayKey = displayKey;
Minecraft.getMinecraft().getTextureManager().bindTexture(buttonTextures);
GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F);
this.drawTexturedModalRect(this.xPosition + (int)(sliderValue * (float)(this.width - 8)), this.yPosition, 0, 66, 4, 20);
this.drawTexturedModalRect(this.xPosition + (int)(sliderValue * (float)(this.width - 8)) + 4, this.yPosition, 196, 66, 4, 20);
}
Minecraft.getMinecraft().getTextureManager().bindTexture(buttonTextures);
GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F);
this.drawTexturedModalRect(this.xPosition + (int) (sliderValue * (float) (this.width - 8)), this.yPosition, 0, 66, 4, 20);
this.drawTexturedModalRect(this.xPosition + (int) (sliderValue * (float) (this.width - 8)) + 4, this.yPosition, 196, 66, 4, 20);
}
@Override
protected int getHoverState(boolean mouseOver) {
return 0;
}
public static float convertScaleRet(float value) {
if(value <= 1) {
return Math.round(value * 10);
}
float steps = value - 1;
return Math.round(steps / 0.25f);
}
@Override
public void drawButton(Minecraft mc, int mouseX, int mouseY)
{
if (this.visible)
{
try {
FontRenderer fontrenderer = mc.fontRendererObj;
mc.getTextureManager().bindTexture(buttonTextures);
GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F);
this.hovered = mouseX >= this.xPosition && mouseY >= this.yPosition && mouseX < this.xPosition + this.width && mouseY < this.yPosition + this.height;
int k = this.getHoverState(this.hovered);
GlStateManager.enableBlend();
GlStateManager.tryBlendFuncSeparate(770, 771, 1, 0);
GlStateManager.blendFunc(770, 771);
this.drawTexturedModalRect(this.xPosition, this.yPosition, 0, 46 + k * 20, this.width / 2, this.height);
this.drawTexturedModalRect(this.xPosition + this.width / 2, this.yPosition, 200 - this.width / 2, 46 + k * 20, this.width / 2, this.height);
this.mouseDragged(mc, mouseX, mouseY);
int l = 14737632;
public static float convertScale(float value) {
if(value == 10) {
return 1;
}
if(value <= 9) {
return value / 10f;
}
return 1 + (0.25f * (value - 10));
}
if (packedFGColour != 0)
{
l = packedFGColour;
}
else if (!this.enabled)
{
l = 10526880;
}
else if (this.hovered && FMLClientHandler.instance().isGUIOpen(GuiMouseInput.class))
{
l = 16777120;
}
@Override
protected int getHoverState(boolean mouseOver) {
return 0;
}
this.drawCenteredString(fontrenderer, this.displayString, this.xPosition + this.width / 2, this.yPosition + (this.height - 8) / 2, l);
} catch(Exception e) {}
}
}
@Override
public void drawButton(Minecraft mc, int mouseX, int mouseY) {
if(this.visible) {
try {
FontRenderer fontrenderer = mc.fontRendererObj;
mc.getTextureManager().bindTexture(buttonTextures);
GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F);
this.hovered = mouseX >= this.xPosition && mouseY >= this.yPosition && mouseX < this.xPosition + this.width && mouseY < this.yPosition + this.height;
int k = this.getHoverState(this.hovered);
GlStateManager.enableBlend();
GlStateManager.tryBlendFuncSeparate(770, 771, 1, 0);
GlStateManager.blendFunc(770, 771);
this.drawTexturedModalRect(this.xPosition, this.yPosition, 0, 46 + k * 20, this.width / 2, this.height);
this.drawTexturedModalRect(this.xPosition + this.width / 2, this.yPosition, 200 - this.width / 2, 46 + k * 20, this.width / 2, this.height);
this.mouseDragged(mc, mouseX, mouseY);
int l = 14737632;
private String translate(float f) {
return f+"x";
}
if(packedFGColour != 0) {
l = packedFGColour;
} else if(!this.enabled) {
l = 10526880;
} else if(this.hovered && FMLClientHandler.instance().isGUIOpen(GuiMouseInput.class)) {
l = 16777120;
}
public static float convertScaleRet(float value) {
if(value <= 1) {
return Math.round(value*10);
}
float steps = value-1;
return Math.round(steps/0.25f);
}
this.drawCenteredString(fontrenderer, this.displayString, this.xPosition + this.width / 2, this.yPosition + (this.height - 8) / 2, l);
} catch(Exception e) {
}
}
}
public static float convertScale(float value) {
if(value == 10) {
return 1;
}
if(value <= 9) {
return value/10f;
}
return 1+(0.25f*(value-10));
}
private String translate(float f) {
return f + "x";
}
public double getSliderValue() {
return convertScale(normalizedToReal(sliderValue));
}
public double getSliderValue() {
return convertScale(normalizedToReal(sliderValue));
}
@Override
protected void mouseDragged(Minecraft mc, int mouseX, int mouseY) {
if(this.visible) {
try {
if(this.dragging) {
sliderValue = (float) (mouseX - (this.xPosition + 4)) / (float) (this.width - 8);
sliderValue = MathHelper.clamp_float(sliderValue, 0.0F, 1.0F);
float f = denormalizeValue(sliderValue);
sliderValue = normalizeValue(f);
if(ReplayMod.replaySender.getReplaySpeed() != 0) {
ReplayMod.replaySender.setReplaySpeed(convertScale(normalizedToReal(sliderValue)));
}
this.displayString = displayKey + ": " + translate(convertScale(normalizedToReal(sliderValue)));
}
@Override
protected void mouseDragged(Minecraft mc, int mouseX, int mouseY) {
if (this.visible) {
try {
if(this.dragging) {
sliderValue = (float)(mouseX - (this.xPosition + 4)) / (float)(this.width - 8);
sliderValue = MathHelper.clamp_float(sliderValue, 0.0F, 1.0F);
float f = denormalizeValue(sliderValue);
sliderValue = normalizeValue(f);
if(ReplayHandler.getSpeed() != 0) {
ReplayHandler.setSpeed(convertScale(normalizedToReal(sliderValue)));
}
this.displayString = displayKey+": "+translate(convertScale(normalizedToReal(sliderValue)));
}
mc.getTextureManager().bindTexture(buttonTextures);
GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F);
this.drawTexturedModalRect(this.xPosition + (int) (sliderValue * (float) (this.width - 8)), this.yPosition, 0, 66, 4, 20);
this.drawTexturedModalRect(this.xPosition + (int) (sliderValue * (float) (this.width - 8)) + 4, this.yPosition, 196, 66, 4, 20);
} catch(Exception e) {
}
}
}
mc.getTextureManager().bindTexture(buttonTextures);
GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F);
this.drawTexturedModalRect(this.xPosition + (int)(sliderValue * (float)(this.width - 8)), this.yPosition, 0, 66, 4, 20);
this.drawTexturedModalRect(this.xPosition + (int)(sliderValue * (float)(this.width - 8)) + 4, this.yPosition, 196, 66, 4, 20);
} catch(Exception e) {}
}
}
public float normalizeValue(float p_148266_1_) {
return MathHelper.clamp_float((this.snapToStepClamp(p_148266_1_) - this.valueMin) / (this.valueMax - this.valueMin), 0.0F, 1.0F);
}
public float normalizeValue(float p_148266_1_)
{
return MathHelper.clamp_float((this.snapToStepClamp(p_148266_1_) - this.valueMin) / (this.valueMax - this.valueMin), 0.0F, 1.0F);
}
public float realToNormalized(float value) {
float min = 0 - valueMin;
float max = valueMax + min;
public float realToNormalized(float value) {
float min = 0 - valueMin;
float max = valueMax + min;
return value / (max) - min;
}
return value/(max) - min;
}
public float denormalizeValue(float p_148262_1_) {
return this.snapToStepClamp(this.valueMin + (this.valueMax - this.valueMin) * MathHelper.clamp_float(p_148262_1_, 0.0F, 1.0F));
}
public float denormalizeValue(float p_148262_1_)
{
return this.snapToStepClamp(this.valueMin + (this.valueMax - this.valueMin) * MathHelper.clamp_float(p_148262_1_, 0.0F, 1.0F));
}
public float snapToStepClamp(float p_148268_1_) {
p_148268_1_ = this.snapToStep(p_148268_1_);
return MathHelper.clamp_float(p_148268_1_, this.valueMin, this.valueMax);
}
public float snapToStepClamp(float p_148268_1_)
{
p_148268_1_ = this.snapToStep(p_148268_1_);
return MathHelper.clamp_float(p_148268_1_, this.valueMin, this.valueMax);
}
protected float snapToStep(float p_148264_1_) {
if(this.valueStep > 0.0F) {
p_148264_1_ = this.valueStep * (float) Math.round(p_148264_1_ / this.valueStep);
}
protected float snapToStep(float p_148264_1_)
{
if (this.valueStep > 0.0F)
{
p_148264_1_ = this.valueStep * (float)Math.round(p_148264_1_ / this.valueStep);
}
return p_148264_1_;
}
return p_148264_1_;
}
public float normalizedToReal(float value) {
float min = 0 - valueMin;
float max = valueMax + min;
public float normalizedToReal(float value) {
float min = 0 - valueMin;
float max = valueMax + min;
return Math.round(value * (max) - min);
}
return Math.round(value*(max) - min);
}
public boolean mousePressed(Minecraft mc, int mouseX, int mouseY) {
if(super.mousePressed(mc, mouseX, mouseY)) {
this.dragging = true;
return true;
} else {
return false;
}
}
public boolean mousePressed(Minecraft mc, int mouseX, int mouseY)
{
if (super.mousePressed(mc, mouseX, mouseY))
{
this.dragging = true;
return true;
}
else
{
return false;
}
}
public void mouseReleased(int mouseX, int mouseY)
{
this.dragging = false;
}
public void mouseReleased(int mouseX, int mouseY) {
this.dragging = false;
}
}

View File

@@ -1,14 +1,8 @@
package eu.crushedpixel.replaymod.gui;
import java.awt.Color;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import org.lwjgl.input.Mouse;
import com.mojang.realmsclient.util.Pair;
import eu.crushedpixel.replaymod.ReplayMod;
import eu.crushedpixel.replaymod.replay.ReplayHandler;
import net.minecraft.client.entity.AbstractClientPlayer;
import net.minecraft.client.gui.Gui;
import net.minecraft.client.gui.GuiScreen;
@@ -17,199 +11,200 @@ import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.EnumPlayerModelParts;
import net.minecraft.potion.Potion;
import net.minecraft.util.ResourceLocation;
import org.lwjgl.input.Mouse;
import com.mojang.realmsclient.util.Pair;
import eu.crushedpixel.replaymod.replay.ReplayHandler;
import java.awt.*;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
public class GuiSpectateSelection extends GuiScreen {
private List<Pair<EntityPlayer, ResourceLocation>> players;
private int playerCount;
private int upperPlayer = 0;
private List<Pair<EntityPlayer, ResourceLocation>> players;
private int playerCount;
private int upperPlayer = 0;
private int upperBound = 30;
private int lowerBound;
private double prevSpeed;
private int upperBound = 30;
private int lowerBound;
private class PlayerComparator implements Comparator<EntityPlayer> {
private double prevSpeed;
private boolean drag = false;
private int lastY = 0;
private int fitting = 0;
@Override
public int compare(EntityPlayer o1, EntityPlayer o2) {
if(isSpectator(o1) && !isSpectator(o2)) {
return 1;
} else if(isSpectator(o2) && !isSpectator(o1)) {
return -1;
} else {
return o1.getName().compareToIgnoreCase(o2.getName());
}
}
}
private boolean isSpectator(EntityPlayer e) {
return e.isInvisible() && e.getActivePotionEffect(Potion.invisibility) == null;
}
public GuiSpectateSelection(List<EntityPlayer> players) {
this.prevSpeed = ReplayHandler.getSpeed();
Collections.sort(players, new PlayerComparator());
this.players = new ArrayList<Pair<EntityPlayer, ResourceLocation>>();
public GuiSpectateSelection(List<EntityPlayer> players) {
this.prevSpeed = ReplayMod.replaySender.getReplaySpeed();
for(EntityPlayer p : players) {
ResourceLocation loc = new ResourceLocation("/temp-skins/"+p.getGameProfile().getName());
AbstractClientPlayer.getDownloadImageSkin(loc, p.getName());
this.players.add(Pair.of(p, loc));
}
Collections.sort(players, new PlayerComparator());
playerCount = players.size();
ReplayHandler.setSpeed(0);
}
this.players = new ArrayList<Pair<EntityPlayer, ResourceLocation>>();
private boolean drag = false;
for(EntityPlayer p : players) {
ResourceLocation loc = new ResourceLocation("/temp-skins/" + p.getGameProfile().getName());
AbstractClientPlayer.getDownloadImageSkin(loc, p.getName());
this.players.add(Pair.of(p, loc));
}
@Override
protected void mouseClicked(int mouseX, int mouseY, int mouseButton)
throws IOException {
playerCount = players.size();
if(fitting < playerCount) {
float visiblePerc = (float)fitting/(float)playerCount;
ReplayMod.replaySender.setReplaySpeed(0);
}
int h = this.height-32-32;
int offset = Math.round((upperPlayer/(fitting))*visiblePerc*h);
private boolean isSpectator(EntityPlayer e) {
return e.isInvisible() && e.getActivePotionEffect(Potion.invisibility) == null;
}
int lower = Math.round(32+offset+(h*visiblePerc))-2;
@Override
protected void mouseClicked(int mouseX, int mouseY, int mouseButton)
throws IOException {
int k2 = (int)(this.width*0.4);
if(fitting < playerCount) {
float visiblePerc = (float) fitting / (float) playerCount;
if(mouseX >= k2-16 && mouseX <= k2-12 && mouseY >= 32-2+offset && mouseY <= lower) {
lastY = mouseY;
drag = true;
return;
}
}
int k2 = (int)(this.width*0.4);
int l2 = 30;
if(mouseX >= k2 && mouseX <= (this.width*0.6) && mouseY >= 30 && mouseY <= lowerBound) {
int off = mouseY-30;
int p = (off/21) + upperPlayer;
ReplayHandler.spectateEntity(players.get(p).first());
ReplayHandler.setSpeed(prevSpeed);
mc.displayGuiScreen(null);
}
}
int h = this.height - 32 - 32;
int offset = Math.round((upperPlayer / (fitting)) * visiblePerc * h);
private int lastY = 0;
int lower = Math.round(32 + offset + (h * visiblePerc)) - 2;
@Override
protected void mouseClickMove(int mouseX, int mouseY,
int clickedMouseButton, long timeSinceLastClick) {
int k2 = (int) (this.width * 0.4);
if(drag) {
float step = 1f/(float)playerCount;
if(mouseX >= k2 - 16 && mouseX <= k2 - 12 && mouseY >= 32 - 2 + offset && mouseY <= lower) {
lastY = mouseY;
drag = true;
return;
}
}
int k2 = (int) (this.width * 0.4);
int l2 = 30;
int diff = mouseY-lastY;
int h = this.height-32-32;
if(mouseX >= k2 && mouseX <= (this.width * 0.6) && mouseY >= 30 && mouseY <= lowerBound) {
int off = mouseY - 30;
int p = (off / 21) + upperPlayer;
ReplayHandler.spectateEntity(players.get(p).first());
ReplayMod.replaySender.setReplaySpeed(prevSpeed);
mc.displayGuiScreen(null);
}
}
float percDiff = (float)diff/(float)h;
if(Math.abs(percDiff) > Math.abs(step)) {
int s = (int)(percDiff/step);
lastY = mouseY;
upperPlayer += s;
if(upperPlayer > playerCount-fitting) {
upperPlayer = playerCount-fitting;
} else if(upperPlayer < 0) {
upperPlayer = 0;
}
}
}
@Override
protected void mouseClickMove(int mouseX, int mouseY,
int clickedMouseButton, long timeSinceLastClick) {
super.mouseClickMove(mouseX, mouseY, clickedMouseButton, timeSinceLastClick);
}
@Override
public void onGuiClosed() {
ReplayHandler.setSpeed(prevSpeed);
}
if(drag) {
float step = 1f / (float) playerCount;
@Override
protected void mouseReleased(int mouseX, int mouseY, int state) {
drag = false;
int diff = mouseY - lastY;
int h = this.height - 32 - 32;
super.mouseReleased(mouseX, mouseY, state);
}
float percDiff = (float) diff / (float) h;
if(Math.abs(percDiff) > Math.abs(step)) {
int s = (int) (percDiff / step);
lastY = mouseY;
upperPlayer += s;
if(upperPlayer > playerCount - fitting) {
upperPlayer = playerCount - fitting;
} else if(upperPlayer < 0) {
upperPlayer = 0;
}
}
}
@Override
public void initGui() {
upperPlayer = 0;
lowerBound = this.height-10;
}
super.mouseClickMove(mouseX, mouseY, clickedMouseButton, timeSinceLastClick);
}
private int fitting = 0;
@Override
public void onGuiClosed() {
ReplayMod.replaySender.setReplaySpeed(prevSpeed);
}
@Override
public void drawScreen(int mouseX, int mouseY, float partialTicks) {
this.drawCenteredString(fontRendererObj, "Spectate Player", this.width/2, 5, Color.WHITE.getRGB());
int k2 = (int)(this.width*0.4);
int l2 = 30;
@Override
protected void mouseReleased(int mouseX, int mouseY, int state) {
drag = false;
drawGradientRect(k2-10, l2-10, (int)(this.width*0.6)+20, this.height-30-2+10, -1072689136, -804253680);
super.mouseReleased(mouseX, mouseY, state);
}
fitting = 0;
@Override
public void initGui() {
upperPlayer = 0;
lowerBound = this.height - 10;
}
int sk = 0;
for(Pair<EntityPlayer, ResourceLocation> p : players) {
if(sk < upperPlayer) {
sk++;
continue;
}
boolean spec = isSpectator(p.first());
this.drawString(fontRendererObj, p.first().getName(), k2+16+5, l2+8-(fontRendererObj.FONT_HEIGHT/2),
spec ? Color.DARK_GRAY.getRGB() : Color.WHITE.getRGB());
mc.getTextureManager().bindTexture(p.second());
this.drawScaledCustomSizeModalRect(k2, l2, 8.0F, 8.0F, 8, 8, 16, 16, 64.0F, 64.0F);
if(p.first().func_175148_a(EnumPlayerModelParts.HAT))
Gui.drawScaledCustomSizeModalRect(k2, l2, 40.0F, 8.0F, 8, 8, 16, 16, 64.0F, 64.0F);
@Override
public void drawScreen(int mouseX, int mouseY, float partialTicks) {
this.drawCenteredString(fontRendererObj, "Spectate Player", this.width / 2, 5, Color.WHITE.getRGB());
int k2 = (int) (this.width * 0.4);
int l2 = 30;
GlStateManager.resetColor();
l2 += 16+5;
fitting++;
if(l2+32 > lowerBound) {
break;
}
}
int dw = Mouse.getDWheel();
if(dw > 0) {
dw = -1;
} else if(dw < 0) {
dw = 1;
}
upperPlayer = Math.max(Math.min(upperPlayer+dw, playerCount-fitting), 0);
drawGradientRect(k2 - 10, l2 - 10, (int) (this.width * 0.6) + 20, this.height - 30 - 2 + 10, -1072689136, -804253680);
if(fitting < playerCount) {
float visiblePerc = ((float)fitting)/playerCount;
int barHeight = (int)(visiblePerc*(height-32-32));
fitting = 0;
float posPerc = ((float)upperPlayer)/playerCount;
int barY = (int)(posPerc*(height-32-32));
int sk = 0;
for(Pair<EntityPlayer, ResourceLocation> p : players) {
if(sk < upperPlayer) {
sk++;
continue;
}
boolean spec = isSpectator(p.first());
this.drawRect(k2-18, 30-2, k2-10, this.height-30-2, Color.BLACK.getRGB());
this.drawRect(k2-16, 32-2+barY, k2-12, 32-1+barY+barHeight, Color.LIGHT_GRAY.getRGB());
} else {
this.drawString(fontRendererObj, p.first().getName(), k2 + 16 + 5, l2 + 8 - (fontRendererObj.FONT_HEIGHT / 2),
spec ? Color.DARK_GRAY.getRGB() : Color.WHITE.getRGB());
}
mc.getTextureManager().bindTexture(p.second());
super.drawScreen(mouseX, mouseY, partialTicks);
}
this.drawScaledCustomSizeModalRect(k2, l2, 8.0F, 8.0F, 8, 8, 16, 16, 64.0F, 64.0F);
if(p.first().func_175148_a(EnumPlayerModelParts.HAT))
Gui.drawScaledCustomSizeModalRect(k2, l2, 40.0F, 8.0F, 8, 8, 16, 16, 64.0F, 64.0F);
GlStateManager.resetColor();
l2 += 16 + 5;
fitting++;
if(l2 + 32 > lowerBound) {
break;
}
}
int dw = Mouse.getDWheel();
if(dw > 0) {
dw = -1;
} else if(dw < 0) {
dw = 1;
}
upperPlayer = Math.max(Math.min(upperPlayer + dw, playerCount - fitting), 0);
if(fitting < playerCount) {
float visiblePerc = ((float) fitting) / playerCount;
int barHeight = (int) (visiblePerc * (height - 32 - 32));
float posPerc = ((float) upperPlayer) / playerCount;
int barY = (int) (posPerc * (height - 32 - 32));
this.drawRect(k2 - 18, 30 - 2, k2 - 10, this.height - 30 - 2, Color.BLACK.getRGB());
this.drawRect(k2 - 16, 32 - 2 + barY, k2 - 12, 32 - 1 + barY + barHeight, Color.LIGHT_GRAY.getRGB());
} else {
}
super.drawScreen(mouseX, mouseY, partialTicks);
}
private class PlayerComparator implements Comparator<EntityPlayer> {
@Override
public int compare(EntityPlayer o1, EntityPlayer o2) {
if(isSpectator(o1) && !isSpectator(o2)) {
return 1;
} else if(isSpectator(o2) && !isSpectator(o1)) {
return -1;
} else {
return o1.getName().compareToIgnoreCase(o2.getName());
}
}
}
}

View File

@@ -1,71 +1,69 @@
package eu.crushedpixel.replaymod.gui;
import eu.crushedpixel.replaymod.ReplayMod;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.GuiButton;
import net.minecraft.client.renderer.GlStateManager;
import net.minecraft.client.settings.GameSettings;
import net.minecraft.util.MathHelper;
import eu.crushedpixel.replaymod.ReplayMod;
public class GuiVideoFramerateSlider extends GuiButton {
public GuiVideoFramerateSlider(int buttonId, int p_i45017_2_, int p_i45017_3_, int initialFramerate, String displayKey) {
super(buttonId, p_i45017_2_, p_i45017_3_, 150, 20, "");
this.sliderValue = normalizeValue(initialFramerate);
this.displayString = displayKey+": "+translate(initialFramerate);
this.displayKey = displayKey;
}
private String displayKey;
private float sliderValue;
public boolean dragging;
private String translate(int value) {
return String.valueOf(value);
}
public boolean dragging;
private String displayKey;
private float sliderValue;
public GuiVideoFramerateSlider(int buttonId, int p_i45017_2_, int p_i45017_3_, int initialFramerate, String displayKey) {
super(buttonId, p_i45017_2_, p_i45017_3_, 150, 20, "");
this.sliderValue = normalizeValue(initialFramerate);
this.displayString = displayKey + ": " + translate(initialFramerate);
this.displayKey = displayKey;
}
protected int getHoverState(boolean mouseOver) {
return 0;
}
private String translate(int value) {
return String.valueOf(value);
}
@Override
protected void mouseDragged(Minecraft mc, int mouseX, int mouseY) {
if (this.visible) {
if (this.dragging) {
sliderValue = (float)(mouseX - (this.xPosition + 4)) / (float)(this.width - 8);
sliderValue = MathHelper.clamp_float(sliderValue, 0.0F, 1.0F);
int f = denormalizeValue(sliderValue);
this.displayString = displayKey+": "+translate(f);
ReplayMod.replaySettings.setVideoFramerate(f);
}
protected int getHoverState(boolean mouseOver) {
return 0;
}
mc.getTextureManager().bindTexture(buttonTextures);
GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F);
this.drawTexturedModalRect(this.xPosition + (int)(sliderValue * (float)(this.width - 8)), this.yPosition, 0, 66, 4, 20);
this.drawTexturedModalRect(this.xPosition + (int)(sliderValue * (float)(this.width - 8)) + 4, this.yPosition, 196, 66, 4, 20);
}
}
@Override
protected void mouseDragged(Minecraft mc, int mouseX, int mouseY) {
if(this.visible) {
if(this.dragging) {
sliderValue = (float) (mouseX - (this.xPosition + 4)) / (float) (this.width - 8);
sliderValue = MathHelper.clamp_float(sliderValue, 0.0F, 1.0F);
int f = denormalizeValue(sliderValue);
this.displayString = displayKey + ": " + translate(f);
ReplayMod.replaySettings.setVideoFramerate(f);
}
private float normalizeValue(int val) {
return (val-10)/110f;
}
private int denormalizeValue(float val) {
//Transfers the value ranging from 0.0 to 1.0 to the scale of 10 to 120
float r = 110f*val;
return Math.round(10+r);
}
mc.getTextureManager().bindTexture(buttonTextures);
GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F);
this.drawTexturedModalRect(this.xPosition + (int) (sliderValue * (float) (this.width - 8)), this.yPosition, 0, 66, 4, 20);
this.drawTexturedModalRect(this.xPosition + (int) (sliderValue * (float) (this.width - 8)) + 4, this.yPosition, 196, 66, 4, 20);
}
}
public boolean mousePressed(Minecraft mc, int mouseX, int mouseY) {
if (super.mousePressed(mc, mouseX, mouseY)) {
this.dragging = true;
return true;
} else {
return false;
}
}
private float normalizeValue(int val) {
return (val - 10) / 110f;
}
public void mouseReleased(int mouseX, int mouseY) {
this.dragging = false;
}
private int denormalizeValue(float val) {
//Transfers the value ranging from 0.0 to 1.0 to the scale of 10 to 120
float r = 110f * val;
return Math.round(10 + r);
}
public boolean mousePressed(Minecraft mc, int mouseX, int mouseY) {
if(super.mousePressed(mc, mouseX, mouseY)) {
this.dragging = true;
return true;
} else {
return false;
}
}
public void mouseReleased(int mouseX, int mouseY) {
this.dragging = false;
}
}

View File

@@ -1,85 +1,83 @@
package eu.crushedpixel.replaymod.gui;
import eu.crushedpixel.replaymod.ReplayMod;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.GuiButton;
import net.minecraft.client.renderer.GlStateManager;
import net.minecraft.client.settings.GameSettings;
import net.minecraft.util.MathHelper;
import eu.crushedpixel.replaymod.ReplayMod;
public class GuiVideoQualitySlider extends GuiButton {
public GuiVideoQualitySlider(int buttonId, int p_i45017_2_, int p_i45017_3_, float d, String displayKey) {
super(buttonId, p_i45017_2_, p_i45017_3_, 150, 20, "");
this.sliderValue = normalizeValue(d);
this.displayString = displayKey+": "+translate(d);
this.displayKey = displayKey;
}
private String displayKey;
private float sliderValue;
public boolean dragging;
private String translate(float value) {
if(value <= 0.3) {
return "Draft";
} else if(value <= 0.5) {
return "Normal";
} else if(value <= 0.7) {
return "Good";
}
return "Best";
}
public boolean dragging;
private String displayKey;
private float sliderValue;
public GuiVideoQualitySlider(int buttonId, int p_i45017_2_, int p_i45017_3_, float d, String displayKey) {
super(buttonId, p_i45017_2_, p_i45017_3_, 150, 20, "");
this.sliderValue = normalizeValue(d);
this.displayString = displayKey + ": " + translate(d);
this.displayKey = displayKey;
}
protected int getHoverState(boolean mouseOver) {
return 0;
}
private String translate(float value) {
if(value <= 0.3) {
return "Draft";
} else if(value <= 0.5) {
return "Normal";
} else if(value <= 0.7) {
return "Good";
}
return "Best";
}
@Override
protected void mouseDragged(Minecraft mc, int mouseX, int mouseY) {
if (this.visible) {
if (this.dragging) {
sliderValue = (float)(mouseX - (this.xPosition + 4)) / (float)(this.width - 8);
sliderValue = MathHelper.clamp_float(sliderValue, 0.0F, 1.0F);
float f = denormalizeValue(sliderValue);
f = snapValue(f);
sliderValue = normalizeValue(f);
this.displayString = displayKey+": "+translate(f);
ReplayMod.replaySettings.setVideoQuality(f);
}
protected int getHoverState(boolean mouseOver) {
return 0;
}
mc.getTextureManager().bindTexture(buttonTextures);
GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F);
this.drawTexturedModalRect(this.xPosition + (int)(sliderValue * (float)(this.width - 8)), this.yPosition, 0, 66, 4, 20);
this.drawTexturedModalRect(this.xPosition + (int)(sliderValue * (float)(this.width - 8)) + 4, this.yPosition, 196, 66, 4, 20);
}
}
private float snapValue(float val) {
int i = Math.round(val*10);
return i/10f;
}
@Override
protected void mouseDragged(Minecraft mc, int mouseX, int mouseY) {
if(this.visible) {
if(this.dragging) {
sliderValue = (float) (mouseX - (this.xPosition + 4)) / (float) (this.width - 8);
sliderValue = MathHelper.clamp_float(sliderValue, 0.0F, 1.0F);
float f = denormalizeValue(sliderValue);
f = snapValue(f);
sliderValue = normalizeValue(f);
this.displayString = displayKey + ": " + translate(f);
ReplayMod.replaySettings.setVideoQuality(f);
}
private float normalizeValue(float val) {
return (val-0.1f)/0.8f;
}
private float denormalizeValue(float val) {
//Transfers the value ranging from 0.0 to 1.0 to the scale of 0.1 to 0.9
float r = 0.8f*val;
return 0.1f+r;
}
mc.getTextureManager().bindTexture(buttonTextures);
GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F);
this.drawTexturedModalRect(this.xPosition + (int) (sliderValue * (float) (this.width - 8)), this.yPosition, 0, 66, 4, 20);
this.drawTexturedModalRect(this.xPosition + (int) (sliderValue * (float) (this.width - 8)) + 4, this.yPosition, 196, 66, 4, 20);
}
}
public boolean mousePressed(Minecraft mc, int mouseX, int mouseY) {
if (super.mousePressed(mc, mouseX, mouseY)) {
this.dragging = true;
return true;
} else {
return false;
}
}
private float snapValue(float val) {
int i = Math.round(val * 10);
return i / 10f;
}
public void mouseReleased(int mouseX, int mouseY) {
this.dragging = false;
}
private float normalizeValue(float val) {
return (val - 0.1f) / 0.8f;
}
private float denormalizeValue(float val) {
//Transfers the value ranging from 0.0 to 1.0 to the scale of 0.1 to 0.9
float r = 0.8f * val;
return 0.1f + r;
}
public boolean mousePressed(Minecraft mc, int mouseX, int mouseY) {
if(super.mousePressed(mc, mouseX, mouseY)) {
this.dragging = true;
return true;
} else {
return false;
}
}
public void mouseReleased(int mouseX, int mouseY) {
this.dragging = false;
}
}

View File

@@ -1,46 +1,46 @@
package eu.crushedpixel.replaymod.gui;
import java.lang.reflect.Field;
import eu.crushedpixel.replaymod.reflection.MCPNames;
import net.minecraft.client.gui.FontRenderer;
import net.minecraft.client.gui.GuiTextField;
import java.lang.reflect.Field;
public class PasswordTextField extends GuiTextField {
private static Field text;
private static Field text;
static {
try {
text = GuiTextField.class.getDeclaredField(MCPNames.field("field_146216_j"));
text.setAccessible(true);
} catch(Exception e) {
e.printStackTrace();
}
}
static {
try {
text = GuiTextField.class.getDeclaredField(MCPNames.field("field_146216_j"));
text.setAccessible(true);
} catch(Exception e) {
e.printStackTrace();
}
}
public PasswordTextField(int p_i45542_1_, FontRenderer p_i45542_2_,
int p_i45542_3_, int p_i45542_4_, int p_i45542_5_, int p_i45542_6_) {
super(p_i45542_1_, p_i45542_2_, p_i45542_3_, p_i45542_4_, p_i45542_5_,
p_i45542_6_);
}
public PasswordTextField(int p_i45542_1_, FontRenderer p_i45542_2_,
int p_i45542_3_, int p_i45542_4_, int p_i45542_5_, int p_i45542_6_) {
super(p_i45542_1_, p_i45542_2_, p_i45542_3_, p_i45542_4_, p_i45542_5_,
p_i45542_6_);
}
@Override
public void drawTextBox() {
String prev = getText();
@Override
public void drawTextBox() {
String prev = getText();
String pw = "";
for(int i=0; i<prev.length(); i++) {
pw += "*";
}
try {
text.set(this, pw);
super.drawTextBox();
text.set(this, prev);
} catch(Exception e) {}
}
String pw = "";
for(int i = 0; i < prev.length(); i++) {
pw += "*";
}
try {
text.set(this, pw);
super.drawTextBox();
text.set(this, prev);
} catch(Exception e) {
}
}
}

View File

@@ -1,40 +1,38 @@
package eu.crushedpixel.replaymod.gui.elements;
import java.awt.Color;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.GuiButton;
import java.awt.*;
public class GuiArrowButton extends GuiButton {
private Minecraft mc = Minecraft.getMinecraft();
private boolean upwards = false;
private boolean upwards = false;
public GuiArrowButton(int buttonId, int x, int y, String buttonText, boolean upwards) {
super(buttonId, x, y, buttonText);
public GuiArrowButton(int buttonId, int x, int y, String buttonText, boolean upwards) {
super(buttonId, x, y, buttonText);
this.upwards = upwards;
width = 20;
height = 20;
}
this.upwards = upwards;
width = 20;
height = 20;
}
@Override
public void drawButton(Minecraft mc, int mouseX, int mouseY) {
try {
super.drawButton(mc, mouseX, mouseY);
if(upwards) {
for(int i=0; i<=Math.ceil(height/2)-5; i++) {
drawHorizontalLine(xPosition+width-height+i+4, xPosition+width-i-6, yPosition+height-((height/3)+i+2), Color.BLACK.getRGB());
}
} else {
for(int i=0; i<=Math.ceil(height/2)-5; i++) {
drawHorizontalLine(xPosition+width-height+i+4, xPosition+width-i-6, yPosition+(height/3)+i+2, Color.BLACK.getRGB());
}
}
} catch(Exception e) {
e.printStackTrace();
}
}
@Override
public void drawButton(Minecraft mc, int mouseX, int mouseY) {
try {
super.drawButton(mc, mouseX, mouseY);
if(upwards) {
for(int i = 0; i <= Math.ceil(height / 2) - 5; i++) {
drawHorizontalLine(xPosition + width - height + i + 4, xPosition + width - i - 6, yPosition + height - ((height / 3) + i + 2), Color.BLACK.getRGB());
}
} else {
for(int i = 0; i <= Math.ceil(height / 2) - 5; i++) {
drawHorizontalLine(xPosition + width - height + i + 4, xPosition + width - i - 6, yPosition + (height / 3) + i + 2, Color.BLACK.getRGB());
}
}
} catch(Exception e) {
e.printStackTrace();
}
}
}

View File

@@ -1,197 +1,192 @@
package eu.crushedpixel.replaymod.gui.elements;
import java.awt.Color;
import java.util.ArrayList;
import java.util.List;
import org.lwjgl.input.Mouse;
import eu.crushedpixel.replaymod.gui.elements.listeners.SelectionListener;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.FontRenderer;
import net.minecraft.client.gui.GuiTextField;
import org.lwjgl.input.Mouse;
import java.awt.*;
import java.util.ArrayList;
import java.util.List;
public class GuiDropdown<T> extends GuiTextField {
private int selectionIndex = -1;
private boolean open = false;
private final int visibleDropout;
private final int dropoutElementHeight = 14;
private final int maxDropoutHeight;
private int selectionIndex = -1;
private boolean open = false;
private Minecraft mc = Minecraft.getMinecraft();
private List<SelectionListener> selectionListeners = new ArrayList<SelectionListener>();
private Minecraft mc = Minecraft.getMinecraft();
private int upperIndex = 0;
private List<T> elements = new ArrayList<T>();
private final int visibleDropout;
private final int dropoutElementHeight = 14;
private final int maxDropoutHeight;
public GuiDropdown(int id, FontRenderer fontRenderer,
int xPos, int yPos, int width, int visibleDropout) {
super(id, fontRenderer, xPos, yPos, width, 20);
this.visibleDropout = visibleDropout;
this.maxDropoutHeight = dropoutElementHeight * visibleDropout;
}
private List<SelectionListener> selectionListeners = new ArrayList<SelectionListener>();
private int upperIndex = 0;
@Override
public void drawTextBox() {
if(elements.size() > selectionIndex && selectionIndex >= 0) {
setText(mc.fontRendererObj.trimStringToWidth(
elements.get(selectionIndex).toString(), width - 8));
} else {
setText("");
}
super.drawTextBox();
public GuiDropdown(int id, FontRenderer fontRenderer,
int xPos, int yPos, int width, int visibleDropout) {
super(id, fontRenderer, xPos, yPos, width, 20);
this.visibleDropout = visibleDropout;
this.maxDropoutHeight = dropoutElementHeight*visibleDropout;
}
@Override
public void drawTextBox() {
if(elements.size() > selectionIndex && selectionIndex >= 0) {
setText(mc.fontRendererObj.trimStringToWidth(
elements.get(selectionIndex).toString(), width-8));
} else {
setText("");
}
super.drawTextBox();
//Draw the right part of the Dropdown
drawRect(xPosition + width - height, yPosition, xPosition + width, yPosition + height, -16777216);
drawRect(xPosition + width - height, yPosition, this.xPosition + width - height + 1, yPosition + height, -6250336);
//Draw the right part of the Dropdown
drawRect(xPosition+width-height, yPosition, xPosition+width, yPosition+height, -16777216);
drawRect(xPosition+width-height, yPosition, this.xPosition+width-height+1, yPosition+height, -6250336);
//heroically draw the triangle line by line instead of using a texture
for(int i = 0; i <= Math.ceil(height / 2) - 4; i++) {
drawHorizontalLine(xPosition + width - height + i + 4, xPosition + width - i - 4, yPosition + (height / 4) + i + 2, -6250336);
}
//heroically draw the triangle line by line instead of using a texture
for(int i=0; i<=Math.ceil(height/2)-4; i++) {
drawHorizontalLine(xPosition+width-height+i+4, xPosition+width-i-4, yPosition+(height/4)+i+2, -6250336);
}
if(open && elements.size() > 0) {
//draw the dropout part when opened
if(open && elements.size() > 0) {
//draw the dropout part when opened
boolean drawScrollBar = false;
boolean drawScrollBar = false;
int requiredHeight = elements.size() * dropoutElementHeight;
if(requiredHeight > maxDropoutHeight) {
requiredHeight = maxDropoutHeight;
drawScrollBar = true;
}
int requiredHeight = elements.size()*dropoutElementHeight;
if(requiredHeight > maxDropoutHeight) {
requiredHeight = maxDropoutHeight;
drawScrollBar = true;
}
//The light outline
drawRect(xPosition - 1, yPosition + height, xPosition + width + 1, yPosition + height + requiredHeight + 1, -6250336);
//The light outline
drawRect(xPosition-1, yPosition+height, xPosition+width+1, yPosition+height+requiredHeight+1, -6250336);
//The dark inside
drawRect(xPosition, yPosition + height + 1, xPosition + width, yPosition + height + requiredHeight, -16777216);
//The dark inside
drawRect(xPosition, yPosition+height+1, xPosition+width, yPosition+height+requiredHeight, -16777216);
//The elements
int y = 0;
int i = 0;
for(T obj : elements) {
if(i < upperIndex) {
i++;
continue;
}
drawHorizontalLine(xPosition, xPosition + width, yPosition + height + y, -6250336);
String toWrite = mc.fontRendererObj.trimStringToWidth(obj.toString(), width - 8);
drawString(mc.fontRendererObj, toWrite, xPosition + 4, yPosition + height + y + 4, Color.WHITE.getRGB());
//The elements
int y = 0;
int i = 0;
for(T obj : elements) {
if(i<upperIndex) {
i++;
continue;
}
drawHorizontalLine(xPosition, xPosition+width, yPosition+height+y, -6250336);
String toWrite = mc.fontRendererObj.trimStringToWidth(obj.toString(), width-8);
drawString(mc.fontRendererObj, toWrite, xPosition+4, yPosition+height+y+4, Color.WHITE.getRGB());
y += dropoutElementHeight;
i++;
if(y >= requiredHeight) {
break;
}
}
y += dropoutElementHeight;
i++;
if(y >= requiredHeight) {
break;
}
}
if(drawScrollBar) {
//The scroll bar
int dw = Mouse.getDWheel();
if(dw > 0) {
dw = -1;
} else if(dw < 0) {
dw = 1;
}
if(drawScrollBar) {
//The scroll bar
int dw = Mouse.getDWheel();
if(dw > 0) {
dw = -1;
} else if(dw < 0) {
dw = 1;
}
upperIndex = Math.max(Math.min(upperIndex + dw, elements.size() - visibleDropout), 0);
upperIndex = Math.max(Math.min(upperIndex+dw, elements.size()-visibleDropout), 0);
drawRect(xPosition + width - 3, yPosition + height + 1, xPosition + width, yPosition + height + requiredHeight, Color.DARK_GRAY.getRGB());
drawRect(xPosition+width-3, yPosition+height+1, xPosition+width, yPosition+height+requiredHeight, Color.DARK_GRAY.getRGB());
float visiblePerc = ((float) visibleDropout) / elements.size();
int barHeight = (int) (visiblePerc * (requiredHeight - 1));
float visiblePerc = ((float)visibleDropout)/elements.size();
int barHeight = (int)(visiblePerc*(requiredHeight-1));
float posPerc = ((float) upperIndex) / elements.size();
int barY = (int) (posPerc * (requiredHeight - 1));
float posPerc = ((float)upperIndex)/elements.size();
int barY = (int)(posPerc*(requiredHeight-1));
drawRect(xPosition + width - 3, yPosition + height + barY, xPosition + width, yPosition + height + 2 + barY + barHeight, -6250336);
}
}
}
drawRect(xPosition+width-3, yPosition+height+barY, xPosition+width, yPosition+height+2+barY+barHeight, -6250336);
}
}
}
@Override
public void mouseClicked(int xPos, int yPos, int mouseButton) {
if(xPos > xPosition + width - height && xPos < xPosition + width && yPos > yPosition && yPos < yPosition + height) {
open = !open;
} else {
if(xPos > xPosition && xPos < xPosition + width && open) {
int requiredHeight = Math.min(maxDropoutHeight, elements.size() * dropoutElementHeight);
if(yPos > yPosition + height && yPos < yPosition + height + requiredHeight) {
int clickedIndex = (int) Math.floor((yPos - (yPosition + height)) / dropoutElementHeight) + upperIndex;
this.selectionIndex = clickedIndex;
fireSelectionChangeEvent();
}
open = false;
} else {
open = false;
}
}
}
@Override
public void mouseClicked(int xPos, int yPos, int mouseButton) {
if(xPos > xPosition+width-height && xPos < xPosition+width && yPos > yPosition && yPos < yPosition+height) {
open = !open;
} else {
if(xPos > xPosition && xPos < xPosition+width && open) {
int requiredHeight = Math.min(maxDropoutHeight, elements.size()*dropoutElementHeight);
if(yPos > yPosition+height && yPos < yPosition+height+requiredHeight) {
int clickedIndex = (int)Math.floor((yPos - (yPosition+height)) / dropoutElementHeight) + upperIndex;
this.selectionIndex = clickedIndex;
fireSelectionChangeEvent();
}
open = false;
} else {
open = false;
}
}
}
@Override
public void setText(String text) {
if(!getText().equals(text)) {
super.setText(text);
}
}
@Override
public void setText(String text) {
if(!getText().equals(text)) {
super.setText(text);
}
}
public void setElements(List<T> elements) {
this.elements = elements;
if(selectionIndex == -1 && elements.size() > 0) {
selectionIndex = 0;
}
}
private List<T> elements = new ArrayList<T>();
public void clearElements() {
this.elements = new ArrayList<T>();
selectionIndex = -1;
}
public void setSelectionIndex(int index) {
this.selectionIndex = index;
if(selectionIndex < 0) selectionIndex = -1;
fireSelectionChangeEvent();
}
public void addElement(T element) {
this.elements.add(element);
if(selectionIndex == -1) {
selectionIndex = 0;
}
}
public void setElements(List<T> elements) {
this.elements = elements;
if(selectionIndex == -1 && elements.size() > 0) {
selectionIndex = 0;
}
}
public T getElement(int index) {
return elements.get(index);
}
public void clearElements() {
this.elements = new ArrayList<T>();
selectionIndex = -1;
}
public List<T> getAllElements() {
return elements;
}
public void addElement(T element) {
this.elements.add(element);
if(selectionIndex == -1) {
selectionIndex = 0;
}
}
public int getSelectionIndex() {
return selectionIndex;
}
public T getElement(int index) {
return elements.get(index);
}
public void setSelectionIndex(int index) {
this.selectionIndex = index;
if(selectionIndex < 0) selectionIndex = -1;
fireSelectionChangeEvent();
}
public List<T> getAllElements() {
return elements;
}
public int getSelectionIndex() {
return selectionIndex;
}
private void fireSelectionChangeEvent() {
for(SelectionListener listener : selectionListeners) {
listener.onSelectionChanged(selectionIndex);
}
}
private void fireSelectionChangeEvent() {
for(SelectionListener listener : selectionListeners) {
listener.onSelectionChanged(selectionIndex);
}
}
public void addSelectionListener(SelectionListener listener) {
this.selectionListeners.add(listener);
}
public void addSelectionListener(SelectionListener listener) {
this.selectionListeners.add(listener);
}
public void removeSelectionListener(SelectionListener listener) {
this.selectionListeners.remove(listener);
}
public void removeSelectionListener(SelectionListener listener) {
this.selectionListeners.remove(listener);
}
public boolean isExpanded() {
return open;
}
public boolean isExpanded() {
return open;
}
}

View File

@@ -1,150 +1,146 @@
package eu.crushedpixel.replaymod.gui.elements;
import java.awt.Color;
import java.util.ArrayList;
import java.util.List;
import org.lwjgl.input.Mouse;
import eu.crushedpixel.replaymod.gui.elements.listeners.SelectionListener;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.FontRenderer;
import net.minecraft.client.gui.GuiTextField;
import org.lwjgl.input.Mouse;
import java.awt.*;
import java.util.ArrayList;
import java.util.List;
public class GuiEntryList<T> extends GuiTextField {
private int selectionIndex = -1;
public final static int elementHeight = 14;
private int selectionIndex = -1;
private Minecraft mc = Minecraft.getMinecraft();
private int visibleElements;
private int upperIndex = 0;
private Minecraft mc = Minecraft.getMinecraft();
private List<SelectionListener> selectionListeners = new ArrayList<SelectionListener>();
private List<T> elements = new ArrayList<T>();
private int visibleElements;
public final static int elementHeight = 14;
public GuiEntryList(int id, FontRenderer fontRenderer,
int xPos, int yPos, int width, int visibleEntries) {
super(id, fontRenderer, xPos, yPos, width, elementHeight * visibleEntries - 1);
this.visibleElements = visibleEntries;
}
private int upperIndex = 0;
public void setVisibleElements(int rows) {
this.visibleElements = rows;
this.height = elementHeight * visibleElements - 1;
}
private List<SelectionListener> selectionListeners = new ArrayList<SelectionListener>();
@Override
public void drawTextBox() {
try {
super.drawTextBox();
//drawing the entries
for(int i = 0; i - upperIndex < visibleElements; i++) {
if(i < upperIndex) continue;
public GuiEntryList(int id, FontRenderer fontRenderer,
int xPos, int yPos, int width, int visibleEntries) {
super(id, fontRenderer, xPos, yPos, width, elementHeight*visibleEntries-1);
this.visibleElements = visibleEntries;
}
if(i >= elements.size()) break;
public void setVisibleElements(int rows) {
this.visibleElements = rows;
this.height = elementHeight*visibleElements-1;
}
if(i == selectionIndex) {
drawRect(xPosition, yPosition + (i - upperIndex) * elementHeight, xPosition + width,
yPosition + (i + 1 - upperIndex) * elementHeight - 1, Color.GRAY.getRGB());
}
@Override
public void drawTextBox() {
try {
super.drawTextBox();
//drawing the entries
for(int i=0; i-upperIndex<visibleElements; i++) {
if(i<upperIndex) continue;
drawRect(xPosition, yPosition + (i + 1 - upperIndex) * elementHeight - 1, xPosition + width,
yPosition + (i + 1 - upperIndex) * elementHeight, -6250336);
drawString(mc.fontRendererObj, mc.fontRendererObj.trimStringToWidth(elements.get(i).toString(), width - 4),
xPosition + 2, yPosition + (i - upperIndex) * elementHeight + 3, Color.WHITE.getRGB());
}
if(i >= elements.size()) break;
//drawing the scroll bar
if(elements.size() > visibleElements) {
//handle scroll events
int dw = Mouse.getDWheel();
if(dw > 0) {
dw = -1;
} else if(dw < 0) {
dw = 1;
}
if(i == selectionIndex) {
drawRect(xPosition, yPosition+(i-upperIndex)*elementHeight, xPosition+width,
yPosition+(i+1-upperIndex)*elementHeight-1, Color.GRAY.getRGB());
}
upperIndex = Math.max(Math.min(upperIndex + dw, elements.size() - visibleElements), 0);
drawRect(xPosition, yPosition+(i+1-upperIndex)*elementHeight-1, xPosition+width,
yPosition+(i+1-upperIndex)*elementHeight, -6250336);
drawString(mc.fontRendererObj, mc.fontRendererObj.trimStringToWidth(elements.get(i).toString(), width-4),
xPosition+2, yPosition+(i-upperIndex)*elementHeight+3, Color.WHITE.getRGB());
}
float visiblePerc = ((float) visibleElements) / elements.size();
int barHeight = (int) (visiblePerc * (height - 1));
//drawing the scroll bar
if(elements.size() > visibleElements) {
//handle scroll events
int dw = Mouse.getDWheel();
if(dw > 0) {
dw = -1;
} else if(dw < 0) {
dw = 1;
}
float posPerc = ((float) upperIndex) / elements.size();
int barY = (int) (posPerc * (height - 1));
upperIndex = Math.max(Math.min(upperIndex+dw, elements.size()-visibleElements), 0);
drawRect(xPosition + width - 3, yPosition, xPosition + width, yPosition + height, Color.DARK_GRAY.getRGB());
drawRect(xPosition + width - 3, yPosition + barY, xPosition + width, yPosition + 1 + barY + barHeight, -6250336);
}
} catch(Exception e) {
e.printStackTrace();
}
}
float visiblePerc = ((float)visibleElements)/elements.size();
int barHeight = (int)(visiblePerc*(height-1));
@Override
public void mouseClicked(int xPos, int yPos, int mouseButton) {
if(!(xPos >= xPosition && xPos <= xPosition + width && yPos >= yPosition && yPos <= yPosition + height)) return;
int clickedIndex = (int) Math.floor((yPos - yPosition) / elementHeight) + upperIndex;
if(clickedIndex < elements.size() && clickedIndex >= 0) {
selectionIndex = clickedIndex;
fireSelectionChangeEvent();
}
}
float posPerc = ((float)upperIndex)/elements.size();
int barY = (int)(posPerc*(height-1));
private void fireSelectionChangeEvent() {
for(SelectionListener listener : selectionListeners) {
listener.onSelectionChanged(selectionIndex);
}
}
drawRect(xPosition+width-3, yPosition, xPosition+width, yPosition+height, Color.DARK_GRAY.getRGB());
drawRect(xPosition+width-3, yPosition+barY, xPosition+width, yPosition+1+barY+barHeight, -6250336);
}
} catch(Exception e) {
e.printStackTrace();
}
}
@Override
public void setText(String text) {
}
@Override
public void mouseClicked(int xPos, int yPos, int mouseButton) {
if(!(xPos >= xPosition && xPos <= xPosition+width && yPos >= yPosition && yPos <= yPosition+height)) return;
int clickedIndex = (int)Math.floor((yPos-yPosition) / elementHeight) + upperIndex;
if(clickedIndex < elements.size() && clickedIndex >= 0) {
selectionIndex = clickedIndex;
fireSelectionChangeEvent();
}
}
public void setElements(List<T> elements) {
this.elements = elements;
if(selectionIndex == -1 && elements.size() > 0) {
selectionIndex = 0;
}
}
private void fireSelectionChangeEvent() {
for(SelectionListener listener : selectionListeners) {
listener.onSelectionChanged(selectionIndex);
}
}
public void clearElements() {
this.elements = new ArrayList<T>();
selectionIndex = -1;
}
@Override
public void setText(String text) {}
public void addElement(T element) {
this.elements.add(element);
if(selectionIndex == -1) {
selectionIndex = 0;
}
}
private List<T> elements = new ArrayList<T>();
public T getElement(int index) {
if(index >= 0) {
return elements.get(index);
}
return null;
}
public void setElements(List<T> elements) {
this.elements = elements;
if(selectionIndex == -1 && elements.size() > 0) {
selectionIndex = 0;
}
}
public int getSelectionIndex() {
return selectionIndex;
}
public void clearElements() {
this.elements = new ArrayList<T>();
selectionIndex = -1;
}
public void setSelectionIndex(int index) {
this.selectionIndex = index;
if(selectionIndex < 0) selectionIndex = -1;
fireSelectionChangeEvent();
}
public void addElement(T element) {
this.elements.add(element);
if(selectionIndex == -1) {
selectionIndex = 0;
}
}
public void addSelectionListener(SelectionListener listener) {
this.selectionListeners.add(listener);
}
public T getElement(int index) {
if(index >= 0) {
return elements.get(index);
}
return null;
}
public int getSelectionIndex() {
return selectionIndex;
}
public void setSelectionIndex(int index) {
this.selectionIndex = index;
if(selectionIndex < 0) selectionIndex = -1;
fireSelectionChangeEvent();
}
public void addSelectionListener(SelectionListener listener) {
this.selectionListeners.add(listener);
}
public void removeSelectionListener(SelectionListener listener) {
this.selectionListeners.remove(listener);
}
public void removeSelectionListener(SelectionListener listener) {
this.selectionListeners.remove(listener);
}
}

View File

@@ -1,10 +0,0 @@
package eu.crushedpixel.replaymod.gui.elements;
import org.lwjgl.input.Keyboard;
import net.minecraft.client.gui.GuiScreen;
import net.minecraft.client.gui.GuiTextField;
public class GuiMouseInput extends GuiScreen {
}

View File

@@ -1,26 +1,26 @@
package eu.crushedpixel.replaymod.gui.elements;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.FontRenderer;
import net.minecraft.client.gui.GuiTextField;
public class GuiNumberInput extends GuiTextField {
private int limit;
public GuiNumberInput(int id, FontRenderer fontRenderer,
int xPos, int yPos, int width, int limit) {
super(id, fontRenderer, xPos, yPos, width, 20);
this.limit = limit;
}
@Override
public void writeText(String text) {
try {
Integer.valueOf(text);
if(limit > 0 && (getText()+text).length() > limit) return;
super.writeText(text);
} catch(NumberFormatException e) {}
}
private int limit;
public GuiNumberInput(int id, FontRenderer fontRenderer,
int xPos, int yPos, int width, int limit) {
super(id, fontRenderer, xPos, yPos, width, 20);
this.limit = limit;
}
@Override
public void writeText(String text) {
try {
Integer.valueOf(text);
if(limit > 0 && (getText() + text).length() > limit) return;
super.writeText(text);
} catch(NumberFormatException e) {
}
}
}

View File

@@ -1,5 +1,14 @@
package eu.crushedpixel.replaymod.gui.elements;
import eu.crushedpixel.replaymod.api.client.holders.FileInfo;
import eu.crushedpixel.replaymod.utils.ResourceHelper;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.Gui;
import net.minecraft.client.gui.GuiListExtended.IGuiListEntry;
import net.minecraft.client.renderer.texture.DynamicTexture;
import net.minecraft.util.ResourceLocation;
import javax.imageio.ImageIO;
import java.awt.image.BufferedImage;
import java.io.File;
import java.text.DateFormat;
@@ -9,114 +18,102 @@ import java.util.Date;
import java.util.List;
import java.util.concurrent.TimeUnit;
import javax.imageio.ImageIO;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.Gui;
import net.minecraft.client.gui.GuiListExtended.IGuiListEntry;
import net.minecraft.client.renderer.texture.DynamicTexture;
import net.minecraft.util.ResourceLocation;
import eu.crushedpixel.replaymod.api.client.holders.FileInfo;
import eu.crushedpixel.replaymod.utils.ResourceHelper;
public class GuiReplayListEntry implements IGuiListEntry {
private Minecraft minecraft = Minecraft.getMinecraft();
private final DateFormat dateFormat = new SimpleDateFormat();
private final DateFormat dateFormat = new SimpleDateFormat();
boolean registered = false;
private Minecraft minecraft = Minecraft.getMinecraft();
private FileInfo fileInfo;
private ResourceLocation textureResource;
private DynamicTexture dynTex = null;
private File imageFile;
private BufferedImage image = null;
private GuiReplayListExtended parent;
private FileInfo fileInfo;
private ResourceLocation textureResource;
private DynamicTexture dynTex = null;
public GuiReplayListEntry(GuiReplayListExtended parent, FileInfo fileInfo, File imageFile) {
this.fileInfo = fileInfo;
this.parent = parent;
dynTex = null;
this.imageFile = imageFile;
}
private File imageFile;
private BufferedImage image = null;
private GuiReplayListExtended parent;
public FileInfo getFileInfo() {
return fileInfo;
}
public FileInfo getFileInfo() {
return fileInfo;
}
public GuiReplayListEntry(GuiReplayListExtended parent, FileInfo fileInfo, File imageFile) {
this.fileInfo = fileInfo;
this.parent = parent;
dynTex = null;
this.imageFile = imageFile;
}
@Override
public void drawEntry(int slotIndex, int x, int y, int listWidth, int slotHeight, int mouseX, int mouseY, boolean isSelected) {
try {
if(fileInfo.getName() == null || fileInfo.getName().length() < 1) {
fileInfo.setName("No Name");
}
minecraft.fontRendererObj.drawString(fileInfo.getName(), x + 3, y + 1, 16777215);
boolean registered = false;
if(y < -slotHeight || y > parent.height) {
if(registered) {
registered = false;
ResourceHelper.freeResource(textureResource);
textureResource = null;
image = null;
dynTex = null;
}
return;
} else {
if(!registered) {
textureResource = new ResourceLocation("thumbs/" + fileInfo.getName() + fileInfo.getId());
if(imageFile == null) {
image = ResourceHelper.getDefaultThumbnail();
} else {
image = ImageIO.read(imageFile);
}
dynTex = new DynamicTexture(image);
minecraft.getTextureManager().loadTexture(textureResource, dynTex);
dynTex.updateDynamicTexture();
ResourceHelper.registerResource(textureResource);
registered = true;
}
@Override
public void drawEntry(int slotIndex, int x, int y, int listWidth, int slotHeight, int mouseX, int mouseY, boolean isSelected) {
try {
if(fileInfo.getName() == null || fileInfo.getName().length() < 1) {
fileInfo.setName("No Name");
}
minecraft.fontRendererObj.drawString(fileInfo.getName(), x + 3, y + 1, 16777215);
minecraft.getTextureManager().bindTexture(textureResource);
Gui.drawScaledCustomSizeModalRect(x - 60, y, 0, 0, 1280, 720, 57, 32, 1280, 720);
}
if(y < -slotHeight || y > parent.height) {
if(registered) {
registered = false;
ResourceHelper.freeResource(textureResource);
textureResource = null;
image = null;
dynTex = null;
}
return;
} else {
if(!registered) {
textureResource = new ResourceLocation("thumbs/"+fileInfo.getName()+fileInfo.getId());
if(imageFile == null) {
image = ResourceHelper.getDefaultThumbnail();
} else {
image = ImageIO.read(imageFile);
}
dynTex = new DynamicTexture(image);
minecraft.getTextureManager().loadTexture(textureResource, dynTex);
dynTex.updateDynamicTexture();
ResourceHelper.registerResource(textureResource);
registered = true;
}
List<String> list = new ArrayList<String>();
list.add(fileInfo.getMetadata().getServerName() + " (" + dateFormat.format(new Date(fileInfo.getMetadata().getDate())) + ")");
minecraft.getTextureManager().bindTexture(textureResource);
Gui.drawScaledCustomSizeModalRect(x-60, y, 0, 0, 1280, 720, 57, 32, 1280, 720);
}
list.add(String.format("%02dm%02ds",
TimeUnit.MILLISECONDS.toMinutes(fileInfo.getMetadata().getDuration()),
TimeUnit.MILLISECONDS.toSeconds(fileInfo.getMetadata().getDuration()) -
TimeUnit.MINUTES.toSeconds(TimeUnit.MILLISECONDS.toMinutes(fileInfo.getMetadata().getDuration()))
));
List<String> list = new ArrayList<String>();
list.add(fileInfo.getMetadata().getServerName()+" ("+dateFormat.format(new Date(fileInfo.getMetadata().getDate()))+")");
for(int l1 = 0; l1 < Math.min(list.size(), 2); ++l1) {
minecraft.fontRendererObj.drawString((String) list.get(l1), x + 3, y + 12 + minecraft.fontRendererObj.FONT_HEIGHT * l1, 8421504);
}
} catch(Exception e) {
e.printStackTrace();
}
}
list.add(String.format("%02dm%02ds",
TimeUnit.MILLISECONDS.toMinutes(fileInfo.getMetadata().getDuration()),
TimeUnit.MILLISECONDS.toSeconds(fileInfo.getMetadata().getDuration()) -
TimeUnit.MINUTES.toSeconds(TimeUnit.MILLISECONDS.toMinutes(fileInfo.getMetadata().getDuration()))
));
@Override
public void setSelected(int p_178011_1_, int p_178011_2_, int p_178011_3_) {
}
for (int l1 = 0; l1 < Math.min(list.size(), 2); ++l1) {
minecraft.fontRendererObj.drawString((String)list.get(l1), x + 3, y + 12 + minecraft.fontRendererObj.FONT_HEIGHT * l1, 8421504);
}
} catch(Exception e) {
e.printStackTrace();
}
}
@Override
public boolean mousePressed(int p_148278_1_, int p_148278_2_,
int p_148278_3_, int p_148278_4_, int p_148278_5_, int p_148278_6_) {
for(int slot = 0; slot < parent.getSize(); slot++) {
if(parent.getListEntry(slot) == this) {
parent.elementClicked(slot, false, p_148278_5_, p_148278_6_);
break;
}
}
@Override
public void setSelected(int p_178011_1_, int p_178011_2_, int p_178011_3_) {}
return true;
}
@Override
public boolean mousePressed(int p_148278_1_, int p_148278_2_,
int p_148278_3_, int p_148278_4_, int p_148278_5_, int p_148278_6_) {
for(int slot = 0; slot<parent.getSize(); slot++) {
if(parent.getListEntry(slot) == this) {
parent.elementClicked(slot, false, p_148278_5_, p_148278_6_);
break;
}
}
return true;
}
@Override
public void mouseReleased(int slotIndex, int x, int y, int mouseEvent,
int relativeX, int relativeY) {}
@Override
public void mouseReleased(int slotIndex, int x, int y, int mouseEvent,
int relativeX, int relativeY) {
}
}

View File

@@ -1,196 +1,163 @@
package eu.crushedpixel.replaymod.gui.elements;
import java.io.File;
import java.util.ArrayList;
import java.util.List;
import eu.crushedpixel.replaymod.api.client.holders.FileInfo;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.GuiListExtended;
import net.minecraft.client.renderer.GlStateManager;
import net.minecraft.client.renderer.Tessellator;
import net.minecraft.client.renderer.WorldRenderer;
import net.minecraft.util.MathHelper;
import org.lwjgl.input.Mouse;
import eu.crushedpixel.replaymod.api.client.holders.FileInfo;
import java.io.File;
import java.util.ArrayList;
import java.util.List;
public abstract class GuiReplayListExtended extends GuiListExtended {
public GuiReplayListExtended(Minecraft mcIn, int p_i45010_2_,
int p_i45010_3_, int p_i45010_4_, int p_i45010_5_, int p_i45010_6_) {
super(mcIn, p_i45010_2_, p_i45010_3_, p_i45010_4_, p_i45010_5_, p_i45010_6_);
}
public int selected = -1;
private List<GuiReplayListEntry> entries = new ArrayList<GuiReplayListEntry>();
public int selected = -1;
@Override
protected void elementClicked(int slotIndex, boolean isDoubleClick,
int mouseX, int mouseY) {
super.elementClicked(slotIndex, isDoubleClick, mouseX, mouseY);
this.selected = slotIndex;
}
@Override
protected void drawSelectionBox(int p_148120_1_, int p_148120_2_, int p_148120_3_, int p_148120_4_)
{
public GuiReplayListExtended(Minecraft mcIn, int p_i45010_2_,
int p_i45010_3_, int p_i45010_4_, int p_i45010_5_, int p_i45010_6_) {
super(mcIn, p_i45010_2_, p_i45010_3_, p_i45010_4_, p_i45010_5_, p_i45010_6_);
}
@Override
protected void elementClicked(int slotIndex, boolean isDoubleClick,
int mouseX, int mouseY) {
super.elementClicked(slotIndex, isDoubleClick, mouseX, mouseY);
this.selected = slotIndex;
}
@Override
protected void drawSelectionBox(int p_148120_1_, int p_148120_2_, int p_148120_3_, int p_148120_4_) {
int i1 = this.getSize();
Tessellator tessellator = Tessellator.getInstance();
WorldRenderer worldrenderer = tessellator.getWorldRenderer();
for (int j1 = 0; j1 < i1; ++j1)
{
for(int j1 = 0; j1 < i1; ++j1) {
int k1 = p_148120_2_ + j1 * this.slotHeight + this.headerPadding;
int l1 = this.slotHeight - 4;
if (k1 > this.bottom || k1 + l1 < this.top)
{
if(k1 > this.bottom || k1 + l1 < this.top) {
this.func_178040_a(j1, p_148120_1_, k1);
}
if (this.showSelectionBox && selected == j1)
{
if(this.showSelectionBox && selected == j1) {
int i2 = this.left + (this.width / 2 - this.getListWidth() / 2);
int j2 = this.left + this.width / 2 + this.getListWidth() / 2;
GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F);
GlStateManager.disableTexture2D();
worldrenderer.startDrawingQuads();
worldrenderer.setColorOpaque_I(8421504);
worldrenderer.addVertexWithUV((double)i2, (double)(k1 + l1 + 2), 0.0D, 0.0D, 1.0D);
worldrenderer.addVertexWithUV((double)j2, (double)(k1 + l1 + 2), 0.0D, 1.0D, 1.0D);
worldrenderer.addVertexWithUV((double)j2, (double)(k1 - 2), 0.0D, 1.0D, 0.0D);
worldrenderer.addVertexWithUV((double)i2, (double)(k1 - 2), 0.0D, 0.0D, 0.0D);
worldrenderer.addVertexWithUV((double) i2, (double) (k1 + l1 + 2), 0.0D, 0.0D, 1.0D);
worldrenderer.addVertexWithUV((double) j2, (double) (k1 + l1 + 2), 0.0D, 1.0D, 1.0D);
worldrenderer.addVertexWithUV((double) j2, (double) (k1 - 2), 0.0D, 1.0D, 0.0D);
worldrenderer.addVertexWithUV((double) i2, (double) (k1 - 2), 0.0D, 0.0D, 0.0D);
worldrenderer.setColorOpaque_I(0);
worldrenderer.addVertexWithUV((double)(i2 + 1), (double)(k1 + l1 + 1), 0.0D, 0.0D, 1.0D);
worldrenderer.addVertexWithUV((double)(j2 - 1), (double)(k1 + l1 + 1), 0.0D, 1.0D, 1.0D);
worldrenderer.addVertexWithUV((double)(j2 - 1), (double)(k1 - 1), 0.0D, 1.0D, 0.0D);
worldrenderer.addVertexWithUV((double)(i2 + 1), (double)(k1 - 1), 0.0D, 0.0D, 0.0D);
worldrenderer.addVertexWithUV((double) (i2 + 1), (double) (k1 + l1 + 1), 0.0D, 0.0D, 1.0D);
worldrenderer.addVertexWithUV((double) (j2 - 1), (double) (k1 + l1 + 1), 0.0D, 1.0D, 1.0D);
worldrenderer.addVertexWithUV((double) (j2 - 1), (double) (k1 - 1), 0.0D, 1.0D, 0.0D);
worldrenderer.addVertexWithUV((double) (i2 + 1), (double) (k1 - 1), 0.0D, 0.0D, 0.0D);
tessellator.draw();
GlStateManager.enableTexture2D();
}
this.drawSlot(j1, p_148120_1_, k1, l1, p_148120_3_, p_148120_4_);
}
}
private List<GuiReplayListEntry> entries = new ArrayList<GuiReplayListEntry>();
public void clearEntries() {
entries = new ArrayList<GuiReplayListEntry>();
}
public void addEntry(FileInfo fileInfo, File image) {
entries.add(new GuiReplayListEntry(this, fileInfo, image));
}
public void clearEntries() {
entries = new ArrayList<GuiReplayListEntry>();
}
@Override
public GuiReplayListEntry getListEntry(int index) {
return entries.get(index);
}
public void addEntry(FileInfo fileInfo, File image) {
entries.add(new GuiReplayListEntry(this, fileInfo, image));
}
@Override
protected int getSize() {
return entries.size();
}
@Override
public GuiReplayListEntry getListEntry(int index) {
return entries.get(index);
}
@Override
protected int getSize() {
return entries.size();
}
@Override
public void handleMouseInput()
{
if (this.isMouseYWithinSlotBounds(this.mouseY))
{
if (Mouse.isButtonDown(0))
{
if (this.initialClickY == -1.0F)
{
int i2 = this.getScrollBarX();
@Override
public void handleMouseInput() {
if(this.isMouseYWithinSlotBounds(this.mouseY)) {
if(Mouse.isButtonDown(0)) {
if(this.initialClickY == -1.0F) {
int i2 = this.getScrollBarX();
int i1 = i2 + 6;
boolean flag = true;
if (this.mouseY >= this.top && this.mouseY <= this.bottom && this.mouseX <= i1)
{
if(this.mouseY >= this.top && this.mouseY <= this.bottom && this.mouseX <= i1) {
int i = this.width / 2 - this.getListWidth() / 2;
int j = this.width / 2 + this.getListWidth() / 2;
int k = this.mouseY - this.top - this.headerPadding + (int)this.amountScrolled - 4;
int k = this.mouseY - this.top - this.headerPadding + (int) this.amountScrolled - 4;
int l = k / this.slotHeight;
if (this.mouseX >= i && this.mouseX <= j && l >= 0 && k >= 0 && l < this.getSize())
{
if(this.mouseX >= i && this.mouseX <= j && l >= 0 && k >= 0 && l < this.getSize()) {
boolean flag1 = l == this.selectedElement && Minecraft.getSystemTime() - this.lastClicked < 250L;
this.elementClicked(l, flag1, this.mouseX, this.mouseY);
this.selectedElement = l;
this.lastClicked = Minecraft.getSystemTime();
}
else if (this.mouseX >= i && this.mouseX <= j && k < 0)
{
this.func_148132_a(this.mouseX - i, this.mouseY - this.top + (int)this.amountScrolled - 4);
} else if(this.mouseX >= i && this.mouseX <= j && k < 0) {
this.func_148132_a(this.mouseX - i, this.mouseY - this.top + (int) this.amountScrolled - 4);
flag = false;
}
if (this.mouseX >= i2 && this.mouseX <= i1)
{
if(this.mouseX >= i2 && this.mouseX <= i1) {
this.scrollMultiplier = -1.0F;
int j1 = this.func_148135_f();
if (j1 < 1)
{
if(j1 < 1) {
j1 = 1;
}
int k1 = (int)((float)((this.bottom - this.top) * (this.bottom - this.top)) / (float)this.getContentHeight());
int k1 = (int) ((float) ((this.bottom - this.top) * (this.bottom - this.top)) / (float) this.getContentHeight());
k1 = MathHelper.clamp_int(k1, 32, this.bottom - this.top - 8);
this.scrollMultiplier /= (float)(this.bottom - this.top - k1) / (float)j1;
}
else
{
this.scrollMultiplier /= (float) (this.bottom - this.top - k1) / (float) j1;
} else {
this.scrollMultiplier = 1.0F;
}
if (flag)
{
this.initialClickY = (float)this.mouseY;
}
else
{
if(flag) {
this.initialClickY = (float) this.mouseY;
} else {
this.initialClickY = -2.0F;
}
}
else
{
} else {
this.initialClickY = -2.0F;
}
} else if(this.initialClickY >= 0.0F) {
this.amountScrolled -= ((float) this.mouseY - this.initialClickY) * this.scrollMultiplier;
this.initialClickY = (float) this.mouseY;
}
else if (this.initialClickY >= 0.0F)
{
this.amountScrolled -= ((float)this.mouseY - this.initialClickY) * this.scrollMultiplier;
this.initialClickY = (float)this.mouseY;
}
}
else
{
} else {
this.initialClickY = -1.0F;
}
int l1 = Mouse.getEventDWheel();
if (l1 != 0)
{
if (l1 > 0)
{
if(l1 != 0) {
if(l1 > 0) {
l1 = -1;
}
else if (l1 < 0)
{
} else if(l1 < 0) {
l1 = 1;
}
this.amountScrolled += (float)(l1 * this.slotHeight / 2);
this.amountScrolled += (float) (l1 * this.slotHeight / 2);
}
}
}
}

View File

@@ -1,7 +1,7 @@
package eu.crushedpixel.replaymod.gui.elements.listeners;
public abstract class SelectionListener {
public interface SelectionListener {
void onSelectionChanged(int selectionIndex);
public abstract void onSelectionChanged(int selectionIndex);
}

View File

@@ -1,170 +1,163 @@
package eu.crushedpixel.replaymod.gui.online;
import java.awt.Color;
import java.io.IOException;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.GuiButton;
import net.minecraft.client.gui.GuiScreen;
import net.minecraft.client.gui.GuiTextField;
import org.lwjgl.input.Keyboard;
import eu.crushedpixel.replaymod.gui.GuiConstants;
import eu.crushedpixel.replaymod.gui.PasswordTextField;
import eu.crushedpixel.replaymod.online.authentication.AuthenticationHandler;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.GuiButton;
import net.minecraft.client.gui.GuiScreen;
import net.minecraft.client.gui.GuiTextField;
import org.lwjgl.input.Keyboard;
import java.awt.*;
import java.io.IOException;
public class GuiLoginPrompt extends GuiScreen {
private static final int EMPTY = 0;
private static final int LOGGING_IN = 1;
private static final int INVALID_LOGIN = 2;
private static final int NO_CONNECTION = 3;
private GuiScreen parent, successScreen;
private int textState = 0;
private static final int EMPTY = 0;
private static final int LOGGING_IN = 1;
private static final int INVALID_LOGIN = 2;
private static final int NO_CONNECTION = 3;
private static Minecraft mc = Minecraft.getMinecraft();
private GuiScreen parent, successScreen;
private int textState = 0;
private GuiTextField username;
private PasswordTextField password;
private GuiButton loginButton;
private GuiButton cancelButton;
private int lastMouseX, lastMouseY;
private float lastPartialTicks;
private static Minecraft mc = Minecraft.getMinecraft();
public GuiLoginPrompt(GuiScreen parent, GuiScreen successScreen) {
this.parent = parent;
this.successScreen = successScreen;
}
private GuiTextField username;
private PasswordTextField password;
private GuiButton loginButton;
private GuiButton cancelButton;
@Override
public void initGui() {
Keyboard.enableRepeatEvents(true);
public GuiLoginPrompt(GuiScreen parent, GuiScreen successScreen) {
this.parent = parent;
this.successScreen = successScreen;
}
username = new GuiTextField(GuiConstants.REPLAY_CENTER_LOGIN_TEXT_ID, fontRendererObj, this.width / 2 - 45, 30, 145, 20);
username.setEnabled(true);
username.setFocused(true);
@Override
public void initGui() {
Keyboard.enableRepeatEvents(true);
password = new PasswordTextField(GuiConstants.REPLAY_CENTER_PASSWORD_TEXT_ID, fontRendererObj, this.width / 2 - 45, 60, 145, 20);
password.setEnabled(true);
password.setFocused(false);
username = new GuiTextField(GuiConstants.REPLAY_CENTER_LOGIN_TEXT_ID, fontRendererObj, this.width/2 - 45, 30, 145, 20);
username.setEnabled(true);
username.setFocused(true);
loginButton = new GuiButton(GuiConstants.LOGIN_OKAY_BUTTON, this.width / 2 - 150 - 2, 110, "Login");
loginButton.width = 150;
loginButton.enabled = false;
buttonList.add(loginButton);
password = new PasswordTextField(GuiConstants.REPLAY_CENTER_PASSWORD_TEXT_ID, fontRendererObj, this.width/2 - 45, 60, 145, 20);
password.setEnabled(true);
password.setFocused(false);
cancelButton = new GuiButton(GuiConstants.LOGIN_CANCEL_BUTTON, this.width / 2 + 2, 110, "Cancel");
cancelButton.width = 150;
buttonList.add(cancelButton);
}
loginButton = new GuiButton(GuiConstants.LOGIN_OKAY_BUTTON, this.width/2 - 150 - 2, 110, "Login");
loginButton.width = 150;
loginButton.enabled = false;
buttonList.add(loginButton);
@Override
protected void actionPerformed(GuiButton button) throws IOException {
if(button.id == GuiConstants.LOGIN_OKAY_BUTTON) {
if(button.enabled) {
//Authenticate
textState = LOGGING_IN;
cancelButton = new GuiButton(GuiConstants.LOGIN_CANCEL_BUTTON, this.width/2 + 2, 110, "Cancel");
cancelButton.width = 150;
buttonList.add(cancelButton);
}
new Thread(new Runnable() {
@Override
public void run() {
switch(AuthenticationHandler.authenticate(username.getText(), password.getText())) {
case AuthenticationHandler.SUCCESS:
textState = EMPTY;
mc.addScheduledTask(new Runnable() {
@Override
public void run() {
mc.displayGuiScreen(successScreen);
}
});
break;
case AuthenticationHandler.INVALID:
textState = INVALID_LOGIN;
break;
case AuthenticationHandler.NO_CONNECTION:
textState = NO_CONNECTION;
break;
}
}
}).start();
}
} else if(button.id == GuiConstants.LOGIN_CANCEL_BUTTON) {
mc.displayGuiScreen(parent);
}
}
@Override
protected void actionPerformed(GuiButton button) throws IOException {
if(button.id == GuiConstants.LOGIN_OKAY_BUTTON) {
if(button.enabled) {
//Authenticate
textState = LOGGING_IN;
new Thread(new Runnable() {
@Override
public void run() {
switch(AuthenticationHandler.authenticate(username.getText(), password.getText())) {
case AuthenticationHandler.SUCCESS:
textState = EMPTY;
mc.addScheduledTask(new Runnable() {
@Override
public void run() {
mc.displayGuiScreen(successScreen);
}
});
break;
case AuthenticationHandler.INVALID:
textState = INVALID_LOGIN;
break;
case AuthenticationHandler.NO_CONNECTION:
textState = NO_CONNECTION;
break;
}
}
}).start();
}
} else if(button.id == GuiConstants.LOGIN_CANCEL_BUTTON) {
mc.displayGuiScreen(parent);
}
}
@Override
public void drawScreen(int mouseX, int mouseY, float partialTicks) {
lastMouseX = mouseX;
lastMouseY = mouseY;
lastPartialTicks = partialTicks;
private int lastMouseX, lastMouseY;
private float lastPartialTicks;
@Override
public void drawScreen(int mouseX, int mouseY, float partialTicks) {
lastMouseX = mouseX;
lastMouseY = mouseY;
lastPartialTicks = partialTicks;
this.drawDefaultBackground();
drawCenteredString(fontRendererObj, "Login to ReplayMod.com", this.width/2, 10, Color.WHITE.getRGB());
this.drawDefaultBackground();
drawCenteredString(fontRendererObj, "Login to ReplayMod.com", this.width / 2, 10, Color.WHITE.getRGB());
drawString(fontRendererObj, "Username", this.width/2 - 100, 37, Color.WHITE.getRGB());
username.drawTextBox();
drawString(fontRendererObj, "Username", this.width / 2 - 100, 37, Color.WHITE.getRGB());
username.drawTextBox();
drawString(fontRendererObj, "Password", this.width/2 - 100, 67, Color.WHITE.getRGB());
password.drawTextBox();
switch(textState) {
case INVALID_LOGIN:
drawCenteredString(fontRendererObj, "Incorrect username or password.", this.width/2, 92, Color.RED.getRGB());
break;
case LOGGING_IN:
drawCenteredString(fontRendererObj, "Logging in...", this.width/2, 92, Color.WHITE.getRGB());
break;
case NO_CONNECTION:
drawCenteredString(fontRendererObj, "Could not connect to ReplayMod.com", this.width/2, 92, Color.RED.getRGB());
break;
}
super.drawScreen(mouseX, mouseY, partialTicks);
}
drawString(fontRendererObj, "Password", this.width / 2 - 100, 67, Color.WHITE.getRGB());
password.drawTextBox();
@Override
public void mouseClicked(int mouseX, int mouseY, int mouseButton) throws IOException {
super.mouseClicked(mouseX, mouseY, mouseButton);
username.mouseClicked(mouseX, mouseY, mouseButton);
password.mouseClicked(mouseX, mouseY, mouseButton);
}
switch(textState) {
case INVALID_LOGIN:
drawCenteredString(fontRendererObj, "Incorrect username or password.", this.width / 2, 92, Color.RED.getRGB());
break;
case LOGGING_IN:
drawCenteredString(fontRendererObj, "Logging in...", this.width / 2, 92, Color.WHITE.getRGB());
break;
case NO_CONNECTION:
drawCenteredString(fontRendererObj, "Could not connect to ReplayMod.com", this.width / 2, 92, Color.RED.getRGB());
break;
}
super.drawScreen(mouseX, mouseY, partialTicks);
}
@Override
public void updateScreen() {
username.updateCursorCounter();
password.updateCursorCounter();
}
@Override
public void mouseClicked(int mouseX, int mouseY, int mouseButton) throws IOException {
super.mouseClicked(mouseX, mouseY, mouseButton);
username.mouseClicked(mouseX, mouseY, mouseButton);
password.mouseClicked(mouseX, mouseY, mouseButton);
}
@Override
public void onGuiClosed() {
Keyboard.enableRepeatEvents(false);
}
@Override
public void updateScreen() {
username.updateCursorCounter();
password.updateCursorCounter();
}
@Override
protected void keyTyped(char typedChar, int keyCode) throws IOException {
if(keyCode == Keyboard.KEY_TAB) {
if(password.isFocused()) {
password.setFocused(false);
username.setFocused(true);
} else {
username.setFocused(false);
password.setFocused(true);
}
return;
}
if(keyCode == 28) { //Enter key
actionPerformed(loginButton);
return;
}
if(username.isFocused()) {
username.textboxKeyTyped(typedChar, keyCode);
} else if(password.isFocused()) {
password.textboxKeyTyped(typedChar, keyCode);
}
loginButton.enabled = username.getText().length() > 0 && password.getText().length() > 0;
}
@Override
public void onGuiClosed() {
Keyboard.enableRepeatEvents(false);
}
@Override
protected void keyTyped(char typedChar, int keyCode) throws IOException {
if(keyCode == Keyboard.KEY_TAB) {
if(password.isFocused()) {
password.setFocused(false);
username.setFocused(true);
} else {
username.setFocused(false);
password.setFocused(true);
}
return;
}
if(keyCode == 28) { //Enter key
actionPerformed(loginButton);
return;
}
if(username.isFocused()) {
username.textboxKeyTyped(typedChar, keyCode);
} else if(password.isFocused()) {
password.textboxKeyTyped(typedChar, keyCode);
}
loginButton.enabled = username.getText().length() > 0 && password.getText().length() > 0;
}
}

View File

@@ -1,22 +1,6 @@
package eu.crushedpixel.replaymod.gui.online;
import java.awt.Color;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import net.minecraft.client.gui.GuiButton;
import net.minecraft.client.gui.GuiMainMenu;
import net.minecraft.client.gui.GuiScreen;
import net.minecraft.client.gui.GuiYesNo;
import net.minecraft.client.gui.GuiYesNoCallback;
import net.minecraft.client.resources.I18n;
import org.lwjgl.input.Keyboard;
import eu.crushedpixel.replaymod.ReplayMod;
import eu.crushedpixel.replaymod.api.client.ApiException;
import eu.crushedpixel.replaymod.api.client.SearchPagination;
import eu.crushedpixel.replaymod.api.client.SearchQuery;
import eu.crushedpixel.replaymod.api.client.holders.FileInfo;
@@ -24,247 +8,251 @@ import eu.crushedpixel.replaymod.gui.GuiConstants;
import eu.crushedpixel.replaymod.gui.elements.GuiReplayListExtended;
import eu.crushedpixel.replaymod.gui.replayviewer.GuiReplayViewer;
import eu.crushedpixel.replaymod.online.authentication.AuthenticationHandler;
import net.minecraft.client.gui.*;
import net.minecraft.client.resources.I18n;
import org.lwjgl.input.Keyboard;
import java.awt.*;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
public class GuiReplayCenter extends GuiScreen implements GuiYesNoCallback {
private enum Tab {
RECENT_FILES, BEST_FILES, MY_FILES, SEARCH;
}
private static final SearchQuery recentFileSearchQuery = new SearchQuery(false, null, null, null, null, null,
null, null, null, null);
private static final SearchQuery bestFileSearchQuery = new SearchQuery(true, null, null, null, null, null,
null, null, null, null);
private static final int LOGOUT_CALLBACK_ID = 1;
private final SearchPagination recentFilePagination = new SearchPagination(recentFileSearchQuery);
private final SearchPagination bestFilePagination = new SearchPagination(bestFileSearchQuery);
private GuiReplayListExtended currentList;
private ReplayFileList recentFileList, bestFileList, myFileList, searchFileList;
private Tab currentTab = Tab.RECENT_FILES;
private SearchPagination myFilePagination;
private GuiReplayListExtended currentList;
public static GuiYesNo getYesNoGui(GuiYesNoCallback p_152129_0_, int p_152129_2_) {
String s1 = I18n.format("Do you really want to log out?", new Object[0]);
GuiYesNo guiyesno = new GuiYesNo(p_152129_0_, s1, "", "Logout", "Cancel", p_152129_2_);
return guiyesno;
}
private ReplayFileList recentFileList, bestFileList, myFileList, searchFileList;
@Override
public void initGui() {
Keyboard.enableRepeatEvents(true);
private Tab currentTab = Tab.RECENT_FILES;
if(AuthenticationHandler.isAuthenticated()) {
SearchQuery query = new SearchQuery();
query.auth = AuthenticationHandler.getKey();
query.order = false;
myFilePagination = new SearchPagination(query);
}
private static final SearchQuery recentFileSearchQuery = new SearchQuery(false, null, null, null, null, null,
null, null, null, null);
//Top Button Bar
List<GuiButton> buttonBar = new ArrayList<GuiButton>();
private static final SearchQuery bestFileSearchQuery = new SearchQuery(true, null, null, null, null, null,
null, null, null, null);
GuiButton recentButton = new GuiButton(GuiConstants.CENTER_RECENT_BUTTON, 20, 30, "Newest Replays");
buttonBar.add(recentButton);
private final SearchPagination recentFilePagination = new SearchPagination(recentFileSearchQuery);
private final SearchPagination bestFilePagination = new SearchPagination(bestFileSearchQuery);
private SearchPagination myFilePagination;
GuiButton bestButton = new GuiButton(GuiConstants.CENTER_BEST_BUTTON, 20, 30, "Best Replays");
buttonBar.add(bestButton);
@Override
public void initGui() {
Keyboard.enableRepeatEvents(true);
GuiButton ownReplayButton = new GuiButton(GuiConstants.CENTER_MY_REPLAYS_BUTTON, 20, 30, "My Replays");
ownReplayButton.enabled = AuthenticationHandler.isAuthenticated();
buttonBar.add(ownReplayButton);
if(AuthenticationHandler.isAuthenticated()) {
SearchQuery query = new SearchQuery();
query.auth = AuthenticationHandler.getKey();
query.order = false;
myFilePagination = new SearchPagination(query);
}
GuiButton searchButton = new GuiButton(GuiConstants.CENTER_SEARCH_BUTTON, 20, 30, "Search");
buttonBar.add(searchButton);
//Top Button Bar
List<GuiButton> buttonBar = new ArrayList<GuiButton>();
int i = 0;
for(GuiButton b : buttonBar) {
int w = this.width - 30;
int w2 = w / buttonBar.size();
GuiButton recentButton = new GuiButton(GuiConstants.CENTER_RECENT_BUTTON, 20, 30, "Newest Replays");
buttonBar.add(recentButton);
int x = 15 + (w2 * i);
b.xPosition = x + 2;
b.yPosition = 20;
b.width = w2 - 4;
GuiButton bestButton = new GuiButton(GuiConstants.CENTER_BEST_BUTTON, 20, 30, "Best Replays");
buttonBar.add(bestButton);
buttonList.add(b);
GuiButton ownReplayButton = new GuiButton(GuiConstants.CENTER_MY_REPLAYS_BUTTON, 20, 30, "My Replays");
ownReplayButton.enabled = AuthenticationHandler.isAuthenticated();
buttonBar.add(ownReplayButton);
i++;
}
GuiButton searchButton = new GuiButton(GuiConstants.CENTER_SEARCH_BUTTON, 20, 30, "Search");
buttonBar.add(searchButton);
//Bottom Button Bar (dat alliteration)
List<GuiButton> bottomBar = new ArrayList<GuiButton>();
int i = 0;
for(GuiButton b : buttonBar) {
int w = this.width - 30;
int w2 = w/buttonBar.size();
GuiButton exitButton = new GuiButton(GuiConstants.CENTER_BACK_BUTTON, 20, 20, "Main Menu");
bottomBar.add(exitButton);
int x = 15+(w2*i);
b.xPosition = x+2;
b.yPosition = 20;
b.width = w2-4;
GuiButton managerButton = new GuiButton(GuiConstants.CENTER_MANAGER_BUTTON, 20, 20, "Replay Viewer");
bottomBar.add(managerButton);
buttonList.add(b);
GuiButton logoutButton = new GuiButton(GuiConstants.CENTER_LOGOUT_BUTTON, 20, 20, "Logout");
bottomBar.add(logoutButton);
i++;
}
i = 0;
for(GuiButton b : bottomBar) {
int w = this.width - 30;
int w2 = w / bottomBar.size();
//Bottom Button Bar (dat alliteration)
List<GuiButton> bottomBar = new ArrayList<GuiButton>();
int x = 15 + (w2 * i);
b.xPosition = x + 2;
b.yPosition = height - 30;
b.width = w2 - 4;
GuiButton exitButton = new GuiButton(GuiConstants.CENTER_BACK_BUTTON, 20, 20, "Main Menu");
bottomBar.add(exitButton);
buttonList.add(b);
GuiButton managerButton = new GuiButton(GuiConstants.CENTER_MANAGER_BUTTON, 20, 20, "Replay Viewer");
bottomBar.add(managerButton);
i++;
}
GuiButton logoutButton = new GuiButton(GuiConstants.CENTER_LOGOUT_BUTTON, 20, 20, "Logout");
bottomBar.add(logoutButton);
showOnlineRecent();
}
i = 0;
for(GuiButton b : bottomBar) {
int w = this.width - 30;
int w2 = w/bottomBar.size();
@Override
protected void actionPerformed(GuiButton button) throws java.io.IOException {
if(!button.enabled) return;
if(button.id == GuiConstants.CENTER_BACK_BUTTON) {
mc.displayGuiScreen(new GuiMainMenu());
} else if(button.id == GuiConstants.CENTER_LOGOUT_BUTTON) {
mc.displayGuiScreen(getYesNoGui(this, LOGOUT_CALLBACK_ID));
} else if(button.id == GuiConstants.CENTER_MANAGER_BUTTON) {
mc.displayGuiScreen(new GuiReplayViewer());
} else if(button.id == GuiConstants.CENTER_RECENT_BUTTON) {
showOnlineRecent();
} else if(button.id == GuiConstants.CENTER_BEST_BUTTON) {
showOnlineBest();
} else if(button.id == GuiConstants.CENTER_MY_REPLAYS_BUTTON) {
showOnlineOwnFiles();
} else if(button.id == GuiConstants.CENTER_SEARCH_BUTTON) {
int x = 15+(w2*i);
b.xPosition = x+2;
b.yPosition = height-30;
b.width = w2-4;
}
}
buttonList.add(b);
@Override
public void confirmClicked(boolean result, int id) {
if(id == LOGOUT_CALLBACK_ID) {
if(result) {
mc.addScheduledTask(new Runnable() {
@Override
public void run() {
AuthenticationHandler.logout();
mc.displayGuiScreen(new GuiMainMenu());
}
});
} else {
mc.displayGuiScreen(this);
}
}
}
i++;
}
@Override
public void drawScreen(int mouseX, int mouseY, float partialTicks) {
this.drawDefaultBackground();
this.drawCenteredString(fontRendererObj, "Replay Center", this.width / 2, 8, Color.WHITE.getRGB());
showOnlineRecent();
}
if(currentList != null) {
currentList.drawScreen(mouseX, mouseY, partialTicks);
}
@Override
protected void actionPerformed(GuiButton button) throws java.io.IOException {
if(!button.enabled) return;
if(button.id == GuiConstants.CENTER_BACK_BUTTON) {
mc.displayGuiScreen(new GuiMainMenu());
} else if(button.id == GuiConstants.CENTER_LOGOUT_BUTTON) {
mc.displayGuiScreen(getYesNoGui(this, LOGOUT_CALLBACK_ID));
} else if(button.id == GuiConstants.CENTER_MANAGER_BUTTON) {
mc.displayGuiScreen(new GuiReplayViewer());
} else if(button.id == GuiConstants.CENTER_RECENT_BUTTON) {
showOnlineRecent();
} else if(button.id == GuiConstants.CENTER_BEST_BUTTON) {
showOnlineBest();
} else if(button.id == GuiConstants.CENTER_MY_REPLAYS_BUTTON) {
showOnlineOwnFiles();
} else if(button.id == GuiConstants.CENTER_SEARCH_BUTTON) {
super.drawScreen(mouseX, mouseY, partialTicks);
}
}
}
@Override
public void handleMouseInput() throws IOException {
super.handleMouseInput();
if(currentList != null) {
this.currentList.handleMouseInput();
}
}
private static final int LOGOUT_CALLBACK_ID = 1;
@Override
public void confirmClicked(boolean result, int id) {
if(id == LOGOUT_CALLBACK_ID) {
if(result) {
mc.addScheduledTask(new Runnable() {
@Override
public void run() {
AuthenticationHandler.logout();
mc.displayGuiScreen(new GuiMainMenu());
}
});
} else {
mc.displayGuiScreen(this);
}
}
}
@Override
protected void mouseClicked(int mouseX, int mouseY, int mouseButton) throws IOException {
super.mouseClicked(mouseX, mouseY, mouseButton);
if(currentList != null) {
this.currentList.mouseClicked(mouseX, mouseY, mouseButton);
}
}
public static GuiYesNo getYesNoGui(GuiYesNoCallback p_152129_0_, int p_152129_2_) {
String s1 = I18n.format("Do you really want to log out?", new Object[0]);
GuiYesNo guiyesno = new GuiYesNo(p_152129_0_, s1, "", "Logout", "Cancel", p_152129_2_);
return guiyesno;
}
@Override
protected void mouseReleased(int mouseX, int mouseY, int state) {
super.mouseReleased(mouseX, mouseY, state);
if(currentList != null) {
this.currentList.mouseReleased(mouseX, mouseY, state);
}
}
@Override
public void drawScreen(int mouseX, int mouseY, float partialTicks) {
this.drawDefaultBackground();
this.drawCenteredString(fontRendererObj, "Replay Center", this.width/2, 8, Color.WHITE.getRGB());
@Override
public void onGuiClosed() {
Keyboard.enableRepeatEvents(false);
}
if(currentList != null) {
currentList.drawScreen(mouseX, mouseY, partialTicks);
}
private void updateCurrentList(ReplayFileList list, SearchPagination pagination) {
currentList = list;
if(currentList == null) {
currentList = new ReplayFileList(mc, width, height, 50, height - 40, 36);
} else {
currentList.clearEntries();
currentList.width = width;
currentList.height = height;
currentList.top = 50;
currentList.bottom = height - 40;
}
super.drawScreen(mouseX, mouseY, partialTicks);
}
if(pagination.getLoadedPages() < 0) {
pagination.fetchPage();
}
@Override
public void handleMouseInput() throws IOException {
super.handleMouseInput();
if(currentList != null) {
this.currentList.handleMouseInput();
}
}
for(FileInfo i : pagination.getFiles()) {
try {
File tmp = null;
if(i.hasThumbnail()) {
tmp = File.createTempFile("thumb_online_" + i.getId(), "jpg");
ReplayMod.apiClient.downloadThumbnail(i.getId(), tmp);
}
currentList.addEntry(i, tmp);
} catch(Exception e) {
e.printStackTrace();
}
}
}
@Override
protected void mouseClicked(int mouseX, int mouseY, int mouseButton) throws IOException {
super.mouseClicked(mouseX, mouseY, mouseButton);
if(currentList != null) {
this.currentList.mouseClicked(mouseX, mouseY, mouseButton);
}
}
public void showOnlineRecent() {
Thread t = new Thread(new Runnable() {
@Override
public void run() {
updateCurrentList(recentFileList, recentFilePagination);
currentTab = Tab.RECENT_FILES;
}
});
t.start();
}
@Override
protected void mouseReleased(int mouseX, int mouseY, int state) {
super.mouseReleased(mouseX, mouseY, state);
if(currentList != null) {
this.currentList.mouseReleased(mouseX, mouseY, state);
}
}
public void showOnlineBest() {
Thread t = new Thread(new Runnable() {
@Override
public void run() {
updateCurrentList(bestFileList, bestFilePagination);
currentTab = Tab.BEST_FILES;
}
});
t.start();
}
@Override
public void onGuiClosed() {
Keyboard.enableRepeatEvents(false);
}
public void showOnlineOwnFiles() {
if(!AuthenticationHandler.isAuthenticated() || myFilePagination == null) return;
Thread t = new Thread(new Runnable() {
@Override
public void run() {
updateCurrentList(myFileList, myFilePagination);
currentTab = Tab.MY_FILES;
}
});
t.start();
}
private void updateCurrentList(ReplayFileList list, SearchPagination pagination) {
currentList = list;
if(currentList == null) {
currentList = new ReplayFileList(mc, width, height, 50, height-40, 36);
} else {
currentList.clearEntries();
currentList.width = width;
currentList.height = height;
currentList.top = 50;
currentList.bottom = height-40;
}
if(pagination.getLoadedPages() < 0) {
pagination.fetchPage();
}
for(FileInfo i : pagination.getFiles()) {
try {
File tmp = null;
if(i.hasThumbnail()) {
tmp = File.createTempFile("thumb_online_"+i.getId(), "jpg");
ReplayMod.apiClient.downloadThumbnail(i.getId(), tmp);
}
currentList.addEntry(i, tmp);
} catch(Exception e) {
e.printStackTrace();
}
}
}
public void showOnlineRecent() {
Thread t = new Thread(new Runnable() {
@Override
public void run() {
updateCurrentList(recentFileList, recentFilePagination);
currentTab = Tab.RECENT_FILES;
}
});
t.start();
}
public void showOnlineBest() {
Thread t = new Thread(new Runnable() {
@Override
public void run() {
updateCurrentList(bestFileList, bestFilePagination);
currentTab = Tab.BEST_FILES;
}
});
t.start();
}
public void showOnlineOwnFiles() {
if(!AuthenticationHandler.isAuthenticated() || myFilePagination == null) return;
Thread t = new Thread(new Runnable() {
@Override
public void run() {
updateCurrentList(myFileList, myFilePagination);
currentTab = Tab.MY_FILES;
}
});
t.start();
}
private enum Tab {
RECENT_FILES, BEST_FILES, MY_FILES, SEARCH;
}
}

View File

@@ -1,36 +1,6 @@
package eu.crushedpixel.replaymod.gui.online;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.image.BufferedImage;
import java.io.BufferedReader;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.TimeUnit;
import java.util.regex.Pattern;
import javax.imageio.ImageIO;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.Gui;
import net.minecraft.client.gui.GuiButton;
import net.minecraft.client.gui.GuiMainMenu;
import net.minecraft.client.gui.GuiScreen;
import net.minecraft.client.gui.GuiTextField;
import net.minecraft.client.renderer.texture.DynamicTexture;
import net.minecraft.util.ResourceLocation;
import org.apache.commons.compress.archivers.zip.ZipArchiveEntry;
import org.apache.commons.compress.archivers.zip.ZipFile;
import org.apache.commons.io.FilenameUtils;
import org.lwjgl.input.Keyboard;
import com.google.gson.Gson;
import eu.crushedpixel.replaymod.api.client.ApiException;
import eu.crushedpixel.replaymod.api.client.FileUploader;
import eu.crushedpixel.replaymod.api.client.holders.Category;
@@ -42,361 +12,374 @@ import eu.crushedpixel.replaymod.recording.ReplayMetaData;
import eu.crushedpixel.replaymod.reflection.MCPNames;
import eu.crushedpixel.replaymod.utils.ImageUtils;
import eu.crushedpixel.replaymod.utils.ResourceHelper;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.Gui;
import net.minecraft.client.gui.GuiButton;
import net.minecraft.client.gui.GuiScreen;
import net.minecraft.client.gui.GuiTextField;
import net.minecraft.client.renderer.texture.DynamicTexture;
import net.minecraft.util.ResourceLocation;
import org.apache.commons.compress.archivers.zip.ZipArchiveEntry;
import org.apache.commons.compress.archivers.zip.ZipFile;
import org.apache.commons.io.FilenameUtils;
import org.lwjgl.input.Keyboard;
import javax.imageio.ImageIO;
import java.awt.*;
import java.awt.image.BufferedImage;
import java.io.*;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.TimeUnit;
import java.util.regex.Pattern;
public class GuiUploadFile extends GuiScreen {
private GuiTextField fileTitleInput, tagInput, messageTextField, tagPlaceholder;
private GuiButton categoryButton, startUploadButton, cancelUploadButton, backButton;
private static final Pattern p = Pattern.compile("[^a-z0-9 \\-_]", Pattern.CASE_INSENSITIVE);
private static final Pattern pt = Pattern.compile("[^a-z0-9,]", Pattern.CASE_INSENSITIVE);
private final ResourceLocation textureResource;
private GuiTextField fileTitleInput, tagInput, messageTextField, tagPlaceholder;
private GuiButton categoryButton, startUploadButton, cancelUploadButton, backButton;
private Gson gson = new Gson();
private File replayFile;
private ReplayMetaData metaData;
private BufferedImage thumb;
private FileUploader uploader = new FileUploader();
private Category category = Category.MINIGAME;
private DynamicTexture dynTex = null;
private Minecraft mc = Minecraft.getMinecraft();
private GuiReplayViewer parent;
private Gson gson = new Gson();
public GuiUploadFile(File file, GuiReplayViewer parent) {
this.parent = parent;
private File replayFile;
private ReplayMetaData metaData;
private BufferedImage thumb;
this.textureResource = new ResourceLocation("upload_thumbs/" + FilenameUtils.getBaseName(file.getAbsolutePath()));
dynTex = null;
private FileUploader uploader = new FileUploader();
boolean correctFile = false;
this.replayFile = file;
private Category category = Category.MINIGAME;
if(("." + FilenameUtils.getExtension(file.getAbsolutePath())).equals(ConnectionEventHandler.ZIP_FILE_EXTENSION)) {
ZipFile archive = null;
try {
archive = new ZipFile(file);
ZipArchiveEntry recfile = archive.getEntry("recording" + ConnectionEventHandler.TEMP_FILE_EXTENSION);
ZipArchiveEntry metadata = archive.getEntry("metaData" + ConnectionEventHandler.JSON_FILE_EXTENSION);
private final ResourceLocation textureResource;
private DynamicTexture dynTex = null;
ZipArchiveEntry image = archive.getEntry("thumb");
BufferedImage img = null;
if(image != null) {
InputStream is = archive.getInputStream(image);
is.skip(7);
BufferedImage bimg = ImageIO.read(is);
if(bimg != null) {
thumb = ImageUtils.scaleImage(bimg, new Dimension(1280, 720));
}
}
private Minecraft mc = Minecraft.getMinecraft();
InputStream is = archive.getInputStream(metadata);
BufferedReader br = new BufferedReader(new InputStreamReader(is));
String json = br.readLine();
private static final Pattern p = Pattern.compile("[^a-z0-9 \\-_]", Pattern.CASE_INSENSITIVE);
private static final Pattern pt = Pattern.compile("[^a-z0-9,]", Pattern.CASE_INSENSITIVE);
metaData = gson.fromJson(json, ReplayMetaData.class);
private GuiReplayViewer parent;
public GuiUploadFile(File file, GuiReplayViewer parent) {
this.parent = parent;
this.textureResource = new ResourceLocation("upload_thumbs/"+FilenameUtils.getBaseName(file.getAbsolutePath()));
dynTex = null;
archive.close();
correctFile = true;
} catch(Exception e) {
e.printStackTrace();
} finally {
if(archive != null) {
try {
archive.close();
} catch(IOException e) {
}
}
}
}
boolean correctFile = false;
this.replayFile = file;
if(!correctFile) {
System.out.println("Invalid file provided to upload");
mc.displayGuiScreen(parent); //TODO: Error message
replayFile = null;
return;
}
if(("."+FilenameUtils.getExtension(file.getAbsolutePath())).equals(ConnectionEventHandler.ZIP_FILE_EXTENSION)) {
ZipFile archive = null;
try {
archive = new ZipFile(file);
ZipArchiveEntry recfile = archive.getEntry("recording"+ConnectionEventHandler.TEMP_FILE_EXTENSION);
ZipArchiveEntry metadata = archive.getEntry("metaData"+ConnectionEventHandler.JSON_FILE_EXTENSION);
//If thumb is null, set image to placeholder
if(thumb == null) {
try {
thumb = ImageIO.read(MCPNames.class.getClassLoader().getResourceAsStream("default_thumb.jpg"));
} catch(Exception e) {
e.printStackTrace();
}
}
}
ZipArchiveEntry image = archive.getEntry("thumb");
BufferedImage img = null;
if(image != null) {
InputStream is = archive.getInputStream(image);
is.skip(7);
BufferedImage bimg = ImageIO.read(is);
if(bimg != null) {
thumb = ImageUtils.scaleImage(bimg, new Dimension(1280, 720));
}
}
@Override
public void initGui() {
if(replayFile == null) return;
InputStream is = archive.getInputStream(metadata);
BufferedReader br = new BufferedReader(new InputStreamReader(is));
String json = br.readLine();
if(fileTitleInput == null) {
fileTitleInput = new GuiTextField(GuiConstants.UPLOAD_NAME_INPUT, fontRendererObj, (this.width / 2) + 20 + 10, 21, Math.min(200, this.width - 20 - 260), 20);
String fname = FilenameUtils.getBaseName(replayFile.getAbsolutePath());
fileTitleInput.setText(fname);
fileTitleInput.setMaxStringLength(30);
} else {
fileTitleInput.xPosition = (this.width / 2) + 20 + 10;
//fileTitleInput.yPosition = 21;
fileTitleInput.width = Math.min(200, this.width - 20 - 260);
//fileTitleInput.height = 20;
}
metaData = gson.fromJson(json, ReplayMetaData.class);
if(categoryButton == null) {
categoryButton = new GuiButton(GuiConstants.UPLOAD_CATEGORY_BUTTON, (this.width / 2) + 20 + 10 - 1, 80, "Category: " + category.toNiceString());
categoryButton.width = Math.min(202, this.width - 20 - 260 + 2);
buttonList.add(categoryButton);
} else {
categoryButton.xPosition = (this.width / 2) + 20 + 10 - 1;
}
archive.close();
correctFile = true;
} catch(Exception e) {
e.printStackTrace();
} finally {
if(archive != null) {
try {
archive.close();
} catch (IOException e) {}
}
}
}
if(startUploadButton == null) {
List<GuiButton> bottomBar = new ArrayList<GuiButton>();
startUploadButton = new GuiButton(GuiConstants.UPLOAD_START_BUTTON, 0, 0, "Start Upload");
bottomBar.add(startUploadButton);
if(!correctFile) {
System.out.println("Invalid file provided to upload");
mc.displayGuiScreen(parent); //TODO: Error message
replayFile = null;
return;
}
cancelUploadButton = new GuiButton(GuiConstants.UPLOAD_CANCEL_BUTTON, 0, 0, "Cancel Upload");
cancelUploadButton.enabled = false;
bottomBar.add(cancelUploadButton);
//If thumb is null, set image to placeholder
if(thumb == null) {
try {
thumb = ImageIO.read(MCPNames.class.getClassLoader().getResourceAsStream("default_thumb.jpg"));
} catch(Exception e) {
e.printStackTrace();
}
}
}
backButton = new GuiButton(GuiConstants.UPLOAD_BACK_BUTTON, 0, 0, "Back");
bottomBar.add(backButton);
@Override
public void initGui() {
if(replayFile == null) return;
int i = 0;
for(GuiButton b : bottomBar) {
int w = this.width - 30;
int w2 = w / bottomBar.size();
if(fileTitleInput == null) {
fileTitleInput = new GuiTextField(GuiConstants.UPLOAD_NAME_INPUT, fontRendererObj, (this.width/2)+20+10, 21, Math.min(200, this.width-20-260), 20);
String fname = FilenameUtils.getBaseName(replayFile.getAbsolutePath());
fileTitleInput.setText(fname);
fileTitleInput.setMaxStringLength(30);
} else {
fileTitleInput.xPosition = (this.width/2)+20+10;
//fileTitleInput.yPosition = 21;
fileTitleInput.width = Math.min(200, this.width-20-260);
//fileTitleInput.height = 20;
}
int x = 15 + (w2 * i);
b.xPosition = x + 2;
b.yPosition = height - 30;
b.width = w2 - 4;
if(categoryButton == null) {
categoryButton = new GuiButton(GuiConstants.UPLOAD_CATEGORY_BUTTON, (this.width/2)+20+10-1, 80, "Category: "+category.toNiceString());
categoryButton.width = Math.min(202, this.width-20-260+2);
buttonList.add(categoryButton);
} else {
categoryButton.xPosition = (this.width/2)+20+10-1;
}
buttonList.add(b);
if(startUploadButton == null) {
List<GuiButton> bottomBar = new ArrayList<GuiButton>();
startUploadButton = new GuiButton(GuiConstants.UPLOAD_START_BUTTON, 0, 0, "Start Upload");
bottomBar.add(startUploadButton);
i++;
}
} else {
List<GuiButton> bottomBar = new ArrayList<GuiButton>();
cancelUploadButton = new GuiButton(GuiConstants.UPLOAD_CANCEL_BUTTON, 0, 0, "Cancel Upload");
cancelUploadButton.enabled = false;
bottomBar.add(cancelUploadButton);
bottomBar.add(startUploadButton);
bottomBar.add(cancelUploadButton);
bottomBar.add(backButton);
backButton = new GuiButton(GuiConstants.UPLOAD_BACK_BUTTON, 0, 0, "Back");
bottomBar.add(backButton);
int i = 0;
for(GuiButton b : bottomBar) {
int w = this.width - 30;
int w2 = w / bottomBar.size();
int i = 0;
for(GuiButton b : bottomBar) {
int w = this.width - 30;
int w2 = w/bottomBar.size();
int x = 15 + (w2 * i);
b.xPosition = x + 2;
b.yPosition = height - 30;
b.width = w2 - 4;
int x = 15+(w2*i);
b.xPosition = x+2;
b.yPosition = height-30;
b.width = w2-4;
buttonList.add(b);
buttonList.add(b);
i++;
}
}
i++;
}
} else {
List<GuiButton> bottomBar = new ArrayList<GuiButton>();
if(messageTextField == null) {
messageTextField = new GuiTextField(GuiConstants.UPLOAD_INFO_FIELD, fontRendererObj, 20, height - 80, width - 40, 20);
messageTextField.setEnabled(true);
messageTextField.setFocused(false);
messageTextField.setMaxStringLength(Integer.MAX_VALUE);
} else {
messageTextField.yPosition = height - 80;
messageTextField.width = width - 40;
}
bottomBar.add(startUploadButton);
bottomBar.add(cancelUploadButton);
bottomBar.add(backButton);
if(tagInput == null) {
tagInput = new GuiTextField(GuiConstants.UPLOAD_TAG_INPUT, fontRendererObj, (this.width / 2) + 20 + 10, 110, Math.min(200, this.width - 20 - 260), 20);
tagInput.setMaxStringLength(30);
} else {
tagInput.xPosition = (this.width / 2) + 20 + 10;
tagInput.width = Math.min(200, this.width - 20 - 260);
}
int i = 0;
for(GuiButton b : bottomBar) {
int w = this.width - 30;
int w2 = w/bottomBar.size();
if(tagPlaceholder == null) {
tagPlaceholder = new GuiTextField(GuiConstants.UPLOAD_TAG_PLACEHOLDER, fontRendererObj, (this.width / 2) + 20 + 10, 110, Math.min(200, this.width - 20 - 260), 20);
tagPlaceholder.setTextColor(Color.DARK_GRAY.getRGB());
tagPlaceholder.setText("Tags separated by comma");
} else {
tagPlaceholder.xPosition = (this.width / 2) + 20 + 10;
tagPlaceholder.width = Math.min(200, this.width - 20 - 260);
}
int x = 15+(w2*i);
b.xPosition = x+2;
b.yPosition = height-30;
b.width = w2-4;
validateStartButton();
}
buttonList.add(b);
@Override
protected void actionPerformed(GuiButton button) throws IOException {
if(!button.enabled) return;
if(button.id == GuiConstants.UPLOAD_CATEGORY_BUTTON) {
category = category.next();
categoryButton.displayString = "Category: " + category.toNiceString();
} else if(button.id == GuiConstants.UPLOAD_BACK_BUTTON) {
mc.displayGuiScreen(parent);
} else if(button.id == GuiConstants.UPLOAD_START_BUTTON) {
final String name = fileTitleInput.getText().trim();
new Thread(new Runnable() {
@Override
public void run() {
try {
String tagsRaw = tagInput.getText();
String[] split = tagsRaw.split(",");
List<String> tags = new ArrayList<String>();
for(String str : split) {
if(!tags.contains(str) && str.length() > 0) {
tags.add(str);
}
}
uploader.uploadFile(GuiUploadFile.this, AuthenticationHandler.getKey(), name, tags, replayFile, category);
} catch(ApiException e) { //TODO: Error handling
e.printStackTrace();
//mc.displayGuiScreen(new GuiMainMenu());
} catch(RuntimeException e) {
e.printStackTrace();
//mc.displayGuiScreen(new GuiMainMenu());
} catch(IOException e) {
e.printStackTrace();
}
}
}).start();
} else if(button.id == GuiConstants.UPLOAD_CANCEL_BUTTON) {
uploader.cancelUploading();
}
}
i++;
}
}
@Override
public void drawScreen(int mouseX, int mouseY, float partialTicks) {
this.drawDefaultBackground();
if(messageTextField == null) {
messageTextField = new GuiTextField(GuiConstants.UPLOAD_INFO_FIELD, fontRendererObj, 20, height-80, width-40, 20);
messageTextField.setEnabled(true);
messageTextField.setFocused(false);
messageTextField.setMaxStringLength(Integer.MAX_VALUE);
} else {
messageTextField.yPosition = height-80;
messageTextField.width = width-40;
}
drawString(fontRendererObj, metaData.getServerName(), (this.width / 2) + 20 + 10, 50, Color.GRAY.getRGB());
drawString(fontRendererObj, "Duration: " + String.format("%02dm%02ds",
TimeUnit.MILLISECONDS.toMinutes(metaData.getDuration()),
TimeUnit.MILLISECONDS.toSeconds(metaData.getDuration()) -
TimeUnit.MINUTES.toSeconds(TimeUnit.MILLISECONDS.toMinutes(metaData.getDuration()))
), (this.width / 2) + 20 + 10, 65, Color.GRAY.getRGB());
if(tagInput == null) {
tagInput = new GuiTextField(GuiConstants.UPLOAD_TAG_INPUT, fontRendererObj, (this.width/2)+20+10, 110, Math.min(200, this.width-20-260), 20);
tagInput.setMaxStringLength(30);
} else {
tagInput.xPosition = (this.width/2)+20+10;
tagInput.width = Math.min(200, this.width-20-260);
}
drawCenteredString(fontRendererObj, "Upload File", this.width / 2, 5, Color.WHITE.getRGB());
if(tagPlaceholder == null) {
tagPlaceholder = new GuiTextField(GuiConstants.UPLOAD_TAG_PLACEHOLDER, fontRendererObj, (this.width/2)+20+10, 110, Math.min(200, this.width-20-260), 20);
tagPlaceholder.setTextColor(Color.DARK_GRAY.getRGB());
tagPlaceholder.setText("Tags separated by comma");
} else {
tagPlaceholder.xPosition = (this.width/2)+20+10;
tagPlaceholder.width = Math.min(200, this.width-20-260);
}
//Draw thumbnail
if(thumb != null) {
if(dynTex == null) {
dynTex = new DynamicTexture(thumb);
mc.getTextureManager().loadTexture(textureResource, dynTex);
dynTex.updateDynamicTexture();
ResourceHelper.registerResource(textureResource);
}
validateStartButton();
}
mc.getTextureManager().bindTexture(textureResource); //Will be freed by the ResourceHelper
int wid = (this.width) / 2;
int hei = Math.round(wid * (720f / 1280f));
Gui.drawScaledCustomSizeModalRect(19, 20, 0, 0, 1280, 720, wid, hei, 1280, 720);
}
@Override
protected void actionPerformed(GuiButton button) throws IOException {
if(!button.enabled) return;
if(button.id == GuiConstants.UPLOAD_CATEGORY_BUTTON) {
category = category.next();
categoryButton.displayString = "Category: "+category.toNiceString();
} else if(button.id == GuiConstants.UPLOAD_BACK_BUTTON) {
mc.displayGuiScreen(parent);
} else if(button.id == GuiConstants.UPLOAD_START_BUTTON) {
final String name = fileTitleInput.getText().trim();
new Thread(new Runnable() {
@Override
public void run() {
try {
String tagsRaw = tagInput.getText();
String[] split = tagsRaw.split(",");
List<String> tags = new ArrayList<String>();
for(String str : split) {
if(!tags.contains(str) && str.length() > 0) {
tags.add(str);
}
}
uploader.uploadFile(GuiUploadFile.this, AuthenticationHandler.getKey(), name, tags, replayFile, category);
} catch (ApiException e) { //TODO: Error handling
e.printStackTrace();
//mc.displayGuiScreen(new GuiMainMenu());
} catch (RuntimeException e) {
e.printStackTrace();
//mc.displayGuiScreen(new GuiMainMenu());
} catch (IOException e) {
e.printStackTrace();
}
}
}).start();
} else if(button.id == GuiConstants.UPLOAD_CANCEL_BUTTON) {
uploader.cancelUploading();
}
}
fileTitleInput.drawTextBox();
messageTextField.drawTextBox();
@Override
public void drawScreen(int mouseX, int mouseY, float partialTicks) {
this.drawDefaultBackground();
if(tagInput.getText().length() > 0 || tagInput.isFocused()) {
tagInput.drawTextBox();
} else {
tagPlaceholder.drawTextBox();
}
drawString(fontRendererObj, metaData.getServerName(), (this.width/2)+20+10, 50, Color.GRAY.getRGB());
drawString(fontRendererObj, "Duration: "+String.format("%02dm%02ds",
TimeUnit.MILLISECONDS.toMinutes(metaData.getDuration()),
TimeUnit.MILLISECONDS.toSeconds(metaData.getDuration()) -
TimeUnit.MINUTES.toSeconds(TimeUnit.MILLISECONDS.toMinutes(metaData.getDuration()))
), (this.width/2)+20+10, 65, Color.GRAY.getRGB());
super.drawScreen(mouseX, mouseY, partialTicks);
drawCenteredString(fontRendererObj, "Upload File", this.width/2, 5, Color.WHITE.getRGB());
this.drawRect(19, this.height - 52, width - 19, this.height - 37, Color.BLACK.getRGB());
this.drawRect(21, this.height - 50, width - 21, this.height - 39, Color.WHITE.getRGB());
//Draw thumbnail
if(thumb != null) {
if(dynTex == null) {
dynTex = new DynamicTexture(thumb);
mc.getTextureManager().loadTexture(textureResource, dynTex);
dynTex.updateDynamicTexture();
ResourceHelper.registerResource(textureResource);
}
int width = this.width - 21 - 21;
float prog = uploader.getUploadProgress();
float w = width * prog;
mc.getTextureManager().bindTexture(textureResource); //Will be freed by the ResourceHelper
int wid = (this.width)/2;
int hei = Math.round(wid*(720f/1280f));
Gui.drawScaledCustomSizeModalRect(19, 20, 0, 0, 1280, 720, wid, hei, 1280, 720);
}
this.drawRect(21, this.height - 50, Math.round(21 + w), this.height - 39, Color.RED.getRGB());
fileTitleInput.drawTextBox();
messageTextField.drawTextBox();
String perc = (int) Math.floor(prog * 100) + "%";
fontRendererObj.drawString(perc, this.width / 2 - fontRendererObj.getStringWidth(perc) / 2, this.height - 48, Color.BLACK.getRGB());
}
if(tagInput.getText().length() > 0 || tagInput.isFocused()) {
tagInput.drawTextBox();
} else {
tagPlaceholder.drawTextBox();
}
@Override
public void mouseClicked(int mouseX, int mouseY, int mouseButton) throws IOException {
super.mouseClicked(mouseX, mouseY, mouseButton);
fileTitleInput.mouseClicked(mouseX, mouseY, mouseButton);
tagInput.mouseClicked(mouseX, mouseY, mouseButton);
}
super.drawScreen(mouseX, mouseY, partialTicks);
@Override
public void updateScreen() {
fileTitleInput.updateCursorCounter();
tagInput.updateCursorCounter();
}
this.drawRect(19, this.height-52, width-19, this.height-37, Color.BLACK.getRGB());
this.drawRect(21, this.height-50, width-21, this.height-39, Color.WHITE.getRGB());
@Override
public void onGuiClosed() {
Keyboard.enableRepeatEvents(false);
}
int width = this.width-21 - 21;
float prog = uploader.getUploadProgress();
float w = width*prog;
@Override
protected void keyTyped(char typedChar, int keyCode) throws IOException {
if(fileTitleInput.isFocused()) {
fileTitleInput.textboxKeyTyped(typedChar, keyCode);
} else if(tagInput.isFocused()) {
tagInput.textboxKeyTyped(typedChar, keyCode);
}
this.drawRect(21, this.height-50, Math.round(21+w), this.height-39, Color.RED.getRGB());
if(uploader.isUploading()) {
startUploadButton.enabled = false;
} else {
validateStartButton();
}
}
String perc = (int)Math.floor(prog*100)+"%";
fontRendererObj.drawString(perc, this.width/2 - fontRendererObj.getStringWidth(perc)/2, this.height-48, Color.BLACK.getRGB());
}
private void validateStartButton() {
boolean enabled = true;
if(fileTitleInput.getText().trim().length() < 5 || fileTitleInput.getText().trim().length() > 30) {
enabled = false;
} else if(p.matcher(fileTitleInput.getText()).find()) {
enabled = false;
fileTitleInput.setTextColor(Color.RED.getRGB());
} else if(pt.matcher(tagInput.getText()).find()) {
enabled = false;
tagInput.setTextColor(Color.RED.getRGB());
} else {
fileTitleInput.setTextColor(Color.WHITE.getRGB());
tagInput.setTextColor(Color.WHITE.getRGB());
}
startUploadButton.enabled = enabled;
}
@Override
public void mouseClicked(int mouseX, int mouseY, int mouseButton) throws IOException {
super.mouseClicked(mouseX, mouseY, mouseButton);
fileTitleInput.mouseClicked(mouseX, mouseY, mouseButton);
tagInput.mouseClicked(mouseX, mouseY, mouseButton);
}
public void onStartUploading() {
startUploadButton.enabled = false;
cancelUploadButton.enabled = true;
backButton.enabled = false;
categoryButton.enabled = false;
fileTitleInput.setEnabled(false);
messageTextField.setText("Uploading...");
messageTextField.setTextColor(Color.WHITE.getRGB());
}
@Override
public void updateScreen() {
fileTitleInput.updateCursorCounter();
tagInput.updateCursorCounter();
}
@Override
public void onGuiClosed() {
Keyboard.enableRepeatEvents(false);
}
@Override
protected void keyTyped(char typedChar, int keyCode) throws IOException {
if(fileTitleInput.isFocused()) {
fileTitleInput.textboxKeyTyped(typedChar, keyCode);
} else if(tagInput.isFocused()) {
tagInput.textboxKeyTyped(typedChar, keyCode);
}
if(uploader.isUploading()) {
startUploadButton.enabled = false;
} else {
validateStartButton();
}
}
private void validateStartButton() {
boolean enabled = true;
if(fileTitleInput.getText().trim().length() < 5 || fileTitleInput.getText().trim().length() > 30) {
enabled = false;
} else if(p.matcher(fileTitleInput.getText()).find()) {
enabled = false;
fileTitleInput.setTextColor(Color.RED.getRGB());
} else if(pt.matcher(tagInput.getText()).find()) {
enabled = false;
tagInput.setTextColor(Color.RED.getRGB());
} else {
fileTitleInput.setTextColor(Color.WHITE.getRGB());
tagInput.setTextColor(Color.WHITE.getRGB());
}
startUploadButton.enabled = enabled;
}
public void onStartUploading() {
startUploadButton.enabled = false;
cancelUploadButton.enabled = true;
backButton.enabled = false;
categoryButton.enabled = false;
fileTitleInput.setEnabled(false);
messageTextField.setText("Uploading...");
messageTextField.setTextColor(Color.WHITE.getRGB());
}
public void onFinishUploading(boolean success, String info) {
validateStartButton();
cancelUploadButton.enabled = false;
backButton.enabled = true;
categoryButton.enabled = true;
fileTitleInput.setEnabled(true);
if(success) {
messageTextField.setText("File has been successfully uploaded");
messageTextField.setTextColor(Color.GREEN.getRGB());
} else {
messageTextField.setText(info);
messageTextField.setTextColor(Color.RED.getRGB());
}
}
public void onFinishUploading(boolean success, String info) {
validateStartButton();
cancelUploadButton.enabled = false;
backButton.enabled = true;
categoryButton.enabled = true;
fileTitleInput.setEnabled(true);
if(success) {
messageTextField.setText("File has been successfully uploaded");
messageTextField.setTextColor(Color.GREEN.getRGB());
} else {
messageTextField.setText(info);
messageTextField.setTextColor(Color.RED.getRGB());
}
}
}

View File

@@ -1,12 +1,12 @@
package eu.crushedpixel.replaymod.gui.online;
import net.minecraft.client.Minecraft;
import eu.crushedpixel.replaymod.gui.elements.GuiReplayListExtended;
import net.minecraft.client.Minecraft;
public class ReplayFileList extends GuiReplayListExtended {
public ReplayFileList(Minecraft mcIn, int p_i45010_2_, int p_i45010_3_,
int p_i45010_4_, int p_i45010_5_, int p_i45010_6_) {
super(mcIn, p_i45010_2_, p_i45010_3_, p_i45010_4_, p_i45010_5_, p_i45010_6_);
}
public ReplayFileList(Minecraft mcIn, int p_i45010_2_, int p_i45010_3_,
int p_i45010_4_, int p_i45010_5_, int p_i45010_6_) {
super(mcIn, p_i45010_2_, p_i45010_3_, p_i45010_4_, p_i45010_5_, p_i45010_6_);
}
}

View File

@@ -1,200 +1,198 @@
package eu.crushedpixel.replaymod.gui.replaystudio;
import java.awt.Color;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.GuiButton;
import org.apache.commons.io.FilenameUtils;
import eu.crushedpixel.replaymod.gui.GuiConstants;
import eu.crushedpixel.replaymod.gui.elements.GuiArrowButton;
import eu.crushedpixel.replaymod.gui.elements.GuiDropdown;
import eu.crushedpixel.replaymod.gui.elements.GuiEntryList;
import eu.crushedpixel.replaymod.gui.elements.listeners.SelectionListener;
import eu.crushedpixel.replaymod.registry.ReplayGuiRegistry;
import eu.crushedpixel.replaymod.utils.ReplayFileIO;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.GuiButton;
import org.apache.commons.io.FilenameUtils;
import java.awt.*;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
public class GuiConnectPart extends GuiStudioPart {
private static final String DESCRIPTION = "Connects multiple Replays in the same order as the list.";
private static final String TITLE = "Connect Replays";
private static final String DESCRIPTION = "Connects multiple Replays in the same order as the list.";
private static final String TITLE = "Connect Replays";
private boolean initialized = false;
private boolean initialized = false;
private GuiEntryList<String> concatList;
private GuiDropdown<String> replayDropdown;
private GuiEntryList<String> concatList;
private GuiDropdown<String> replayDropdown;
private GuiButton removeButton, addButton;
private GuiArrowButton upButton, downButton;
private GuiButton removeButton, addButton;
private GuiArrowButton upButton, downButton;
private List<File> replayFiles;
private List<String> filesToConcat;
private List<File> replayFiles;
private List<String> filesToConcat;
public GuiConnectPart(int yPos) {
super(yPos);
this.mc = Minecraft.getMinecraft();
fontRendererObj = mc.fontRendererObj;
}
public GuiConnectPart(int yPos) {
super(yPos);
this.mc = Minecraft.getMinecraft();
fontRendererObj = mc.fontRendererObj;
}
@Override
public void applyFilters(File replayFile, File outputFile) {
// TODO Auto-generated method stub
}
@Override
public String getDescription() {
return DESCRIPTION;
}
@Override
public void applyFilters(File replayFile, File outputFile) {
// TODO Auto-generated method stub
@Override
public String getTitle() {
return TITLE;
}
}
@Override
public void initGui() {
if(!initialized) {
concatList = new GuiEntryList(1, fontRendererObj, 30, yPos, 150, 0);
filesToConcat = new ArrayList<String>();
String selectedName = FilenameUtils.getBaseName(GuiReplayStudio.instance.getSelectedFile().getAbsolutePath());
filesToConcat.add(selectedName);
concatList.setElements(filesToConcat);
@Override
public String getDescription() {
return DESCRIPTION;
}
concatList.setSelectionIndex(0);
@Override
public String getTitle() {
return TITLE;
}
replayDropdown = new GuiDropdown(1, fontRendererObj, 250, yPos+5, 0, 4);
@Override
public void initGui() {
if(!initialized) {
concatList = new GuiEntryList(1, fontRendererObj, 30, yPos, 150, 0);
filesToConcat = new ArrayList<String>();
String selectedName = FilenameUtils.getBaseName(GuiReplayStudio.instance.getSelectedFile().getAbsolutePath());
filesToConcat.add(selectedName);
concatList.setElements(filesToConcat);
replayDropdown.clearElements();
replayFiles = ReplayFileIO.getAllReplayFiles();
int index = -1;
int i=0;
for(File file : replayFiles) {
String name = FilenameUtils.getBaseName(file.getAbsolutePath());
replayDropdown.addElement(name);
if(name.equals(selectedName)) {
index = i;
}
i++;
}
concatList.setSelectionIndex(0);
replayDropdown.setSelectionPos(index);
replayDropdown = new GuiDropdown(1, fontRendererObj, 250, yPos + 5, 0, 4);
replayDropdown.addSelectionListener(new SelectionListener() {
replayDropdown.clearElements();
replayFiles = ReplayFileIO.getAllReplayFiles();
int index = -1;
int i = 0;
for(File file : replayFiles) {
String name = FilenameUtils.getBaseName(file.getAbsolutePath());
replayDropdown.addElement(name);
if(name.equals(selectedName)) {
index = i;
}
i++;
}
@Override
public void onSelectionChanged(int selectionIndex) {
try {
filesToConcat.set(concatList.getSelectionIndex(), (String)replayDropdown.getElement(selectionIndex));
concatList.setElements(filesToConcat);
} catch(Exception e) {} //Sorry, too lazy to properly avoid this Exception here
}
});
replayDropdown.setSelectionPos(index);
concatList.addSelectionListener(new SelectionListener() {
@Override
public void onSelectionChanged(int selectionIndex) {
String selName = (String)concatList.getElement(selectionIndex);
int i = 0;
for(Object s : replayDropdown.getAllElements()) {
String str = (String)s;
if(str.equals(selName)) {
replayDropdown.setSelectionIndex(i);
break;
}
i++;
}
removeButton.enabled = upButton.enabled = downButton.enabled = !(selectionIndex < 0 || selectionIndex >= filesToConcat.size());
if(upButton.enabled && selectionIndex == 0) upButton.enabled = false;
if(downButton.enabled && selectionIndex == filesToConcat.size()-1) downButton.enabled = false;
}
});
replayDropdown.addSelectionListener(new SelectionListener() {
upButton = new GuiArrowButton(GuiConstants.REPLAY_EDITOR_UP_BUTTON, 195, yPos+40, "", true);
buttonList.add(upButton);
@Override
public void onSelectionChanged(int selectionIndex) {
try {
filesToConcat.set(concatList.getSelectionIndex(), (String) replayDropdown.getElement(selectionIndex));
concatList.setElements(filesToConcat);
} catch(Exception e) {
} //Sorry, too lazy to properly avoid this Exception here
}
});
downButton = new GuiArrowButton(GuiConstants.REPLAY_EDITOR_DOWN_BUTTON, 219, yPos+40, "", false);
buttonList.add(downButton);
concatList.addSelectionListener(new SelectionListener() {
@Override
public void onSelectionChanged(int selectionIndex) {
String selName = (String) concatList.getElement(selectionIndex);
int i = 0;
for(Object s : replayDropdown.getAllElements()) {
String str = (String) s;
if(str.equals(selName)) {
replayDropdown.setSelectionIndex(i);
break;
}
i++;
}
removeButton.enabled = upButton.enabled = downButton.enabled = !(selectionIndex < 0 || selectionIndex >= filesToConcat.size());
if(upButton.enabled && selectionIndex == 0) upButton.enabled = false;
if(downButton.enabled && selectionIndex == filesToConcat.size() - 1) downButton.enabled = false;
}
});
int w = GuiReplayStudio.instance.width-243-20-4;
upButton = new GuiArrowButton(GuiConstants.REPLAY_EDITOR_UP_BUTTON, 195, yPos + 40, "", true);
buttonList.add(upButton);
removeButton = new GuiButton(GuiConstants.REPLAY_EDITOR_REMOVE_BUTTON, 249, yPos+40, "Remove");
buttonList.add(removeButton);
downButton = new GuiArrowButton(GuiConstants.REPLAY_EDITOR_DOWN_BUTTON, 219, yPos + 40, "", false);
buttonList.add(downButton);
addButton = new GuiButton(GuiConstants.REPLAY_EDITOR_ADD_BUTTON, 0, yPos+40, "Add");
buttonList.add(addButton);
int w = GuiReplayStudio.instance.width - 243 - 20 - 4;
concatList.setSelectionIndex(0);
}
removeButton = new GuiButton(GuiConstants.REPLAY_EDITOR_REMOVE_BUTTON, 249, yPos + 40, "Remove");
buttonList.add(removeButton);
int w = GuiReplayStudio.instance.width-249-20-4;
addButton.xPosition = 249+6+(w/2);
addButton = new GuiButton(GuiConstants.REPLAY_EDITOR_ADD_BUTTON, 0, yPos + 40, "Add");
buttonList.add(addButton);
addButton.width = w/2+2;
removeButton.width = w/2+2;
concatList.setSelectionIndex(0);
}
replayDropdown.width = GuiReplayStudio.instance.width-250-18;
int w = GuiReplayStudio.instance.width - 249 - 20 - 4;
addButton.xPosition = 249 + 6 + (w / 2);
int h = GuiReplayStudio.instance.height-yPos-20;
int rows = (int)(h / (float)GuiEntryList.elementHeight);
concatList.setVisibleElements(rows);
addButton.width = w / 2 + 2;
removeButton.width = w / 2 + 2;
initialized = true;
}
replayDropdown.width = GuiReplayStudio.instance.width - 250 - 18;
@Override
public void mouseClicked(int mouseX, int mouseY, int mouseButton) throws IOException {
super.mouseClicked(mouseX, mouseY, mouseButton); //call this first to ensure the dropdown is still open
concatList.mouseClicked(mouseX, mouseY, mouseButton);
replayDropdown.mouseClicked(mouseX, mouseY, mouseButton);
}
int h = GuiReplayStudio.instance.height - yPos - 20;
int rows = (int) (h / (float) GuiEntryList.elementHeight);
concatList.setVisibleElements(rows);
@Override
public void drawScreen(int mouseX, int mouseY, float partialTicks) {
super.drawScreen(mouseX, mouseY, partialTicks);
concatList.drawTextBox();
replayDropdown.drawTextBox();
initialized = true;
}
drawString(fontRendererObj, "Replay:", 200, yPos+5+7, Color.WHITE.getRGB());
}
@Override
public void mouseClicked(int mouseX, int mouseY, int mouseButton) throws IOException {
super.mouseClicked(mouseX, mouseY, mouseButton); //call this first to ensure the dropdown is still open
concatList.mouseClicked(mouseX, mouseY, mouseButton);
replayDropdown.mouseClicked(mouseX, mouseY, mouseButton);
}
@Override
public void updateScreen() {
if(!initialized) initGui();
}
@Override
public void drawScreen(int mouseX, int mouseY, float partialTicks) {
super.drawScreen(mouseX, mouseY, partialTicks);
concatList.drawTextBox();
replayDropdown.drawTextBox();
@Override
public void keyTyped(char typedChar, int keyCode) {
drawString(fontRendererObj, "Replay:", 200, yPos + 5 + 7, Color.WHITE.getRGB());
}
}
@Override
public void updateScreen() {
if(!initialized) initGui();
}
@Override
protected void actionPerformed(GuiButton button) {
if(!button.enabled || replayDropdown.isExpanded()) {
return;
}
@Override
public void keyTyped(char typedChar, int keyCode) {
if(button.id == GuiConstants.REPLAY_EDITOR_ADD_BUTTON) {
filesToConcat.add(FilenameUtils.getBaseName(replayFiles.get(0).getAbsolutePath()));
concatList.setElements(filesToConcat);
concatList.setSelectionIndex(filesToConcat.size()-1);
} else if(button.id == GuiConstants.REPLAY_EDITOR_REMOVE_BUTTON) {
int indexBefore = concatList.getSelectionIndex();
if(indexBefore >= 0 && indexBefore < filesToConcat.size()) {
filesToConcat.remove(indexBefore);
concatList.setElements(filesToConcat);
if(filesToConcat.size() <= indexBefore) {
concatList.setSelectionIndex(filesToConcat.size()-1);
} else {
concatList.setSelectionIndex(indexBefore);
}
}
}
}
}
@Override
protected void actionPerformed(GuiButton button) {
if(!button.enabled || replayDropdown.isExpanded()) {
return;
}
if(button.id == GuiConstants.REPLAY_EDITOR_ADD_BUTTON) {
filesToConcat.add(FilenameUtils.getBaseName(replayFiles.get(0).getAbsolutePath()));
concatList.setElements(filesToConcat);
concatList.setSelectionIndex(filesToConcat.size() - 1);
} else if(button.id == GuiConstants.REPLAY_EDITOR_REMOVE_BUTTON) {
int indexBefore = concatList.getSelectionIndex();
if(indexBefore >= 0 && indexBefore < filesToConcat.size()) {
filesToConcat.remove(indexBefore);
concatList.setElements(filesToConcat);
if(filesToConcat.size() <= indexBefore) {
concatList.setSelectionIndex(filesToConcat.size() - 1);
} else {
concatList.setSelectionIndex(indexBefore);
}
}
}
}
}

View File

@@ -1,220 +1,216 @@
package eu.crushedpixel.replaymod.gui.replaystudio;
import java.awt.Color;
import eu.crushedpixel.replaymod.gui.GuiConstants;
import eu.crushedpixel.replaymod.gui.elements.GuiDropdown;
import eu.crushedpixel.replaymod.utils.ReplayFileIO;
import net.minecraft.client.gui.GuiButton;
import net.minecraft.client.gui.GuiMainMenu;
import net.minecraft.client.gui.GuiScreen;
import org.apache.commons.io.FilenameUtils;
import java.awt.*;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import net.minecraft.client.gui.GuiButton;
import net.minecraft.client.gui.GuiMainMenu;
import net.minecraft.client.gui.GuiScreen;
import org.apache.commons.io.FilenameUtils;
import eu.crushedpixel.replaymod.gui.GuiConstants;
import eu.crushedpixel.replaymod.gui.elements.GuiDropdown;
import eu.crushedpixel.replaymod.utils.ReplayFileIO;
public class GuiReplayStudio extends GuiScreen {
public static GuiReplayStudio instance = null;
private static final int tabYPos = 110;
public static GuiReplayStudio instance = null;
private StudioTab currentTab = StudioTab.TRIM;
private GuiDropdown replayDropdown;
private GuiButton saveModeButton, saveButton;
private boolean overrideSave = false;
private boolean initialized = false;
private List<File> replayFiles = new ArrayList<File>();
private static final int tabYPos = 110;
public GuiReplayStudio() {
instance = this;
}
private enum StudioTab {
TRIM(new GuiTrimPart(tabYPos)), CONNECT(new GuiConnectPart(tabYPos)), MODIFY(new GuiConnectPart(tabYPos));
public File getSelectedFile() {
try {
return replayFiles.get(replayDropdown.getSelectionIndex());
} catch(ArrayIndexOutOfBoundsException e) {
return null;
}
}
private GuiStudioPart studioPart;
private void refreshReplayDropdown() {
replayDropdown.clearElements();
replayFiles = ReplayFileIO.getAllReplayFiles();
for(File file : replayFiles) {
String name = FilenameUtils.getBaseName(file.getAbsolutePath());
replayDropdown.addElement(name);
}
}
public GuiStudioPart getStudioPart() {
return studioPart;
}
@Override
public void initGui() {
List<GuiButton> tabButtons = new ArrayList<GuiButton>();
private StudioTab(GuiStudioPart part) {
this.studioPart = part;
}
}
tabButtons.add(new GuiButton(GuiConstants.REPLAY_EDITOR_TRIM_TAB, 0, 0, "Trim Replay"));
tabButtons.add(new GuiButton(GuiConstants.REPLAY_EDITOR_CONNECT_TAB, 0, 0, "Connect Replays"));
tabButtons.add(new GuiButton(GuiConstants.REPLAY_EDITOR_MODIFY_TAB, 0, 0, "Modify Replay"));
public GuiReplayStudio() {
instance = this;
}
int w = this.width - 30;
int w2 = w / tabButtons.size();
int i = 0;
for(GuiButton b : tabButtons) {
int x = 15 + (w2 * i);
b.xPosition = x + 2;
b.yPosition = 30;
b.width = w2 - 4;
private StudioTab currentTab = StudioTab.TRIM;
buttonList.add(b);
private GuiDropdown replayDropdown;
private GuiButton saveModeButton, saveButton;
i++;
}
private boolean overrideSave = false;
int modeWidth = tabButtons.get(0).width;
private boolean initialized = false;
if(!initialized) {
replayDropdown = new GuiDropdown(1, fontRendererObj, 15 + 2 + 1 + 80, 60, this.width - 30 - 8 - 80 - modeWidth - 4, 5);
refreshReplayDropdown();
} else {
replayDropdown.width = this.width - 30 - 8 - 80 - modeWidth - 4;
}
private List<File> replayFiles = new ArrayList<File>();
public File getSelectedFile() {
try {
return replayFiles.get(replayDropdown.getSelectionIndex());
} catch(ArrayIndexOutOfBoundsException e) {
return null;
}
}
private void refreshReplayDropdown() {
replayDropdown.clearElements();
replayFiles = ReplayFileIO.getAllReplayFiles();
for(File file : replayFiles) {
String name = FilenameUtils.getBaseName(file.getAbsolutePath());
replayDropdown.addElement(name);
}
}
@Override
public void initGui() {
List<GuiButton> tabButtons = new ArrayList<GuiButton>();
tabButtons.add(new GuiButton(GuiConstants.REPLAY_EDITOR_TRIM_TAB, 0, 0, "Trim Replay"));
tabButtons.add(new GuiButton(GuiConstants.REPLAY_EDITOR_CONNECT_TAB, 0, 0, "Connect Replays"));
tabButtons.add(new GuiButton(GuiConstants.REPLAY_EDITOR_MODIFY_TAB, 0, 0, "Modify Replay"));
int w = this.width - 30;
int w2 = w/tabButtons.size();
int i = 0;
for(GuiButton b : tabButtons) {
int x = 15+(w2*i);
b.xPosition = x+2;
b.yPosition = 30;
b.width = w2-4;
buttonList.add(b);
i++;
}
int modeWidth = tabButtons.get(0).width;
if(!initialized) {
replayDropdown = new GuiDropdown(1, fontRendererObj, 15+2+1+80, 60, this.width-30-8-80-modeWidth-4, 5);
refreshReplayDropdown();
} else {
replayDropdown.width = this.width-30-8-80-modeWidth-4;
}
if(!initialized) {
saveModeButton = new GuiButton(GuiConstants.REPLAY_EDITOR_SAVEMODE_BUTTON, width-15-modeWidth-3, 60, getSaveModeLabel());
} else {
saveModeButton.xPosition = width-15-modeWidth-3;
}
saveModeButton.width = modeWidth;
buttonList.add(saveModeButton);
if(!initialized) {
saveModeButton = new GuiButton(GuiConstants.REPLAY_EDITOR_SAVEMODE_BUTTON, width - 15 - modeWidth - 3, 60, getSaveModeLabel());
} else {
saveModeButton.xPosition = width - 15 - modeWidth - 3;
}
saveModeButton.width = modeWidth;
buttonList.add(saveModeButton);
GuiButton backButton = new GuiButton(GuiConstants.REPLAY_EDITOR_BACK_BUTTON, width-70-18, height-20-5, "Back");
backButton.width = 70;
buttonList.add(backButton);
GuiButton backButton = new GuiButton(GuiConstants.REPLAY_EDITOR_BACK_BUTTON, width - 70 - 18, height - 20 - 5, "Back");
backButton.width = 70;
buttonList.add(backButton);
saveButton = new GuiButton(GuiConstants.REPLAY_EDITOR_SAVE_BUTTON, width-70-18, height-(2*20)-5-3, "Save");
saveButton.width = 70;
buttonList.add(saveButton);
saveButton = new GuiButton(GuiConstants.REPLAY_EDITOR_SAVE_BUTTON, width - 70 - 18, height - (2 * 20) - 5 - 3, "Save");
saveButton.width = 70;
buttonList.add(saveButton);
for(StudioTab tab : StudioTab.values()) {
tab.getStudioPart().initGui();
}
initialized = true;
};
for(StudioTab tab : StudioTab.values()) {
tab.getStudioPart().initGui();
}
private String getSaveModeLabel() {
return overrideSave ? "Replace Source File" : "Save to new File";
}
initialized = true;
}
@Override
protected void actionPerformed(GuiButton button) throws IOException {
if(!button.enabled) return;
if(button.id == GuiConstants.REPLAY_EDITOR_SAVEMODE_BUTTON) {
overrideSave = !overrideSave;
button.displayString = getSaveModeLabel();
} else if(button.id == GuiConstants.REPLAY_EDITOR_BACK_BUTTON) {
mc.displayGuiScreen(new GuiMainMenu());
} else if(button.id == GuiConstants.REPLAY_EDITOR_TRIM_TAB) {
currentTab = StudioTab.TRIM;
} else if(button.id == GuiConstants.REPLAY_EDITOR_CONNECT_TAB) {
currentTab = StudioTab.CONNECT;
} else if(button.id == GuiConstants.REPLAY_EDITOR_MODIFY_TAB) {
currentTab = StudioTab.MODIFY;
} else if(button.id == GuiConstants.REPLAY_EDITOR_SAVE_BUTTON) {
File outputFile = getSelectedFile();
File folder = ReplayFileIO.getReplayFolder();
if(!overrideSave) {
String name = FilenameUtils.getBaseName(outputFile.getAbsolutePath())+"_edited";
File f = new File(folder, name+".mcpr");
int num = 0;
while(f.exists()) {
num++;
String fileName = name+"_"+num;
f = new File(folder, fileName+".mcpr");
}
outputFile = f;
}
currentTab.getStudioPart().applyFilters(getSelectedFile(), outputFile);
}
}
private String getSaveModeLabel() {
return overrideSave ? "Replace Source File" : "Save to new File";
}
@Override
protected void mouseClicked(int mouseX, int mouseY, int mouseButton)
throws IOException {
replayDropdown.mouseClicked(mouseX, mouseY, mouseButton);
currentTab.getStudioPart().mouseClicked(mouseX, mouseY, mouseButton);
super.mouseClicked(mouseX, mouseY, mouseButton);
}
;
@Override
public void drawScreen(int mouseX, int mouseY, float partialTicks) {
drawDefaultBackground();
super.drawScreen(mouseX, mouseY, partialTicks);
currentTab.getStudioPart().drawScreen(mouseX, mouseY, partialTicks);
@Override
protected void actionPerformed(GuiButton button) throws IOException {
if(!button.enabled) return;
if(button.id == GuiConstants.REPLAY_EDITOR_SAVEMODE_BUTTON) {
overrideSave = !overrideSave;
button.displayString = getSaveModeLabel();
} else if(button.id == GuiConstants.REPLAY_EDITOR_BACK_BUTTON) {
mc.displayGuiScreen(new GuiMainMenu());
} else if(button.id == GuiConstants.REPLAY_EDITOR_TRIM_TAB) {
currentTab = StudioTab.TRIM;
} else if(button.id == GuiConstants.REPLAY_EDITOR_CONNECT_TAB) {
currentTab = StudioTab.CONNECT;
} else if(button.id == GuiConstants.REPLAY_EDITOR_MODIFY_TAB) {
currentTab = StudioTab.MODIFY;
} else if(button.id == GuiConstants.REPLAY_EDITOR_SAVE_BUTTON) {
File outputFile = getSelectedFile();
File folder = ReplayFileIO.getReplayFolder();
if(!overrideSave) {
String name = FilenameUtils.getBaseName(outputFile.getAbsolutePath()) + "_edited";
File f = new File(folder, name + ".mcpr");
int num = 0;
while(f.exists()) {
num++;
String fileName = name + "_" + num;
f = new File(folder, fileName + ".mcpr");
}
outputFile = f;
}
currentTab.getStudioPart().applyFilters(getSelectedFile(), outputFile);
}
}
drawCenteredString(fontRendererObj, "§n"+currentTab.getStudioPart().getTitle(), width/2, 92, Color.WHITE.getRGB());
@Override
protected void mouseClicked(int mouseX, int mouseY, int mouseButton)
throws IOException {
replayDropdown.mouseClicked(mouseX, mouseY, mouseButton);
currentTab.getStudioPart().mouseClicked(mouseX, mouseY, mouseButton);
super.mouseClicked(mouseX, mouseY, mouseButton);
}
List<String> rows = new ArrayList<String>();
String remaining = currentTab.getStudioPart().getDescription();
while(remaining.length() > 0) {
String[] split = remaining.split(" ");
String b = "";
for(String sp : split) {
b += sp+" ";
if(fontRendererObj.getStringWidth(b.trim()) > width-30-70-20) {
b = b.substring(0, b.trim().length()-(sp.length()));
break;
}
}
String trimmed = b.trim();
rows.add(trimmed);
try {
remaining = remaining.substring(trimmed.length()+1);
} catch(Exception e) {break;}
}
@Override
public void drawScreen(int mouseX, int mouseY, float partialTicks) {
drawDefaultBackground();
super.drawScreen(mouseX, mouseY, partialTicks);
currentTab.getStudioPart().drawScreen(mouseX, mouseY, partialTicks);
int i=0;
for(String row : rows) {
drawString(fontRendererObj, row, 30, height-(15*(rows.size()-i)), Color.WHITE.getRGB());
i++;
}
drawCenteredString(fontRendererObj, "§n" + currentTab.getStudioPart().getTitle(), width / 2, 92, Color.WHITE.getRGB());
drawCenteredString(fontRendererObj, "Replay Studio", this.width / 2, 10, 16777215);
drawString(fontRendererObj, "Replay File:", 30, 67, Color.WHITE.getRGB());
replayDropdown.drawTextBox();
}
List<String> rows = new ArrayList<String>();
String remaining = currentTab.getStudioPart().getDescription();
while(remaining.length() > 0) {
String[] split = remaining.split(" ");
String b = "";
for(String sp : split) {
b += sp + " ";
if(fontRendererObj.getStringWidth(b.trim()) > width - 30 - 70 - 20) {
b = b.substring(0, b.trim().length() - (sp.length()));
break;
}
}
String trimmed = b.trim();
rows.add(trimmed);
try {
remaining = remaining.substring(trimmed.length() + 1);
} catch(Exception e) {
break;
}
}
@Override
protected void keyTyped(char typedChar, int keyCode) throws IOException {
currentTab.getStudioPart().keyTyped(typedChar, keyCode);
super.keyTyped(typedChar, keyCode);
}
int i = 0;
for(String row : rows) {
drawString(fontRendererObj, row, 30, height - (15 * (rows.size() - i)), Color.WHITE.getRGB());
i++;
}
@Override
public void updateScreen() {
currentTab.getStudioPart().updateScreen();
super.updateScreen();
}
drawCenteredString(fontRendererObj, "Replay Studio", this.width / 2, 10, 16777215);
drawString(fontRendererObj, "Replay File:", 30, 67, Color.WHITE.getRGB());
replayDropdown.drawTextBox();
}
@Override
protected void keyTyped(char typedChar, int keyCode) throws IOException {
currentTab.getStudioPart().keyTyped(typedChar, keyCode);
super.keyTyped(typedChar, keyCode);
}
@Override
public void updateScreen() {
currentTab.getStudioPart().updateScreen();
super.updateScreen();
}
private enum StudioTab {
TRIM(new GuiTrimPart(tabYPos)), CONNECT(new GuiConnectPart(tabYPos)), MODIFY(new GuiConnectPart(tabYPos));
private GuiStudioPart studioPart;
private StudioTab(GuiStudioPart part) {
this.studioPart = part;
}
public GuiStudioPart getStudioPart() {
return studioPart;
}
}
}

View File

@@ -1,29 +1,29 @@
package eu.crushedpixel.replaymod.gui.replaystudio;
import net.minecraft.client.gui.GuiScreen;
import java.io.File;
import java.io.IOException;
import net.minecraft.client.gui.GuiScreen;
public abstract class GuiStudioPart extends GuiScreen {
public GuiStudioPart(int yPos) {
this.yPos = yPos;
}
protected int yPos = 0;
public abstract void applyFilters(File replayFile, File outputFile);
public abstract String getDescription();
public abstract String getTitle();
@Override
public abstract void keyTyped(char typedChar, int keyCode);
@Override
public void mouseClicked(int mouseX, int mouseY, int mouseButton) throws IOException {
super.mouseClicked(mouseX, mouseY, mouseButton);
}
protected int yPos = 0;
public GuiStudioPart(int yPos) {
this.yPos = yPos;
}
public abstract void applyFilters(File replayFile, File outputFile);
public abstract String getDescription();
public abstract String getTitle();
@Override
public abstract void keyTyped(char typedChar, int keyCode);
@Override
public void mouseClicked(int mouseX, int mouseY, int mouseButton) throws IOException {
super.mouseClicked(mouseX, mouseY, mouseButton);
}
}

View File

@@ -1,163 +1,156 @@
package eu.crushedpixel.replaymod.gui.replaystudio;
import java.awt.Color;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import net.minecraft.client.Minecraft;
import org.lwjgl.input.Keyboard;
import eu.crushedpixel.replaymod.gui.elements.GuiNumberInput;
import eu.crushedpixel.replaymod.studio.StudioImplementation;
import net.minecraft.client.Minecraft;
import org.lwjgl.input.Keyboard;
import java.awt.*;
import java.io.File;
import java.util.ArrayList;
import java.util.List;
public class GuiTrimPart extends GuiStudioPart {
private Minecraft mc = Minecraft.getMinecraft();
private static final String DESCRIPTION = "Removes the beginning and end of a Replay File and only keeps the Replay between the given timestamps.";
private static final String TITLE = "Trim Replay";
private Minecraft mc = Minecraft.getMinecraft();
private boolean initialized = false;
private static final String DESCRIPTION = "Removes the beginning and end of a Replay File and only keeps the Replay between the given timestamps.";
private static final String TITLE = "Trim Replay";
private GuiNumberInput startMinInput, startSecInput, startMsInput;
private GuiNumberInput endMinInput, endSecInput, endMsInput;
private boolean initialized = false;
private List<GuiNumberInput> inputOrder = new ArrayList<GuiNumberInput>();
private GuiNumberInput startMinInput, startSecInput, startMsInput;
private GuiNumberInput endMinInput, endSecInput, endMsInput;
public GuiTrimPart(int yPos) {
super(yPos);
fontRendererObj = mc.fontRendererObj;
}
private List<GuiNumberInput> inputOrder = new ArrayList<GuiNumberInput>();
@Override
public void applyFilters(File replayFile, File outputFile) {
try {
StudioImplementation.trimReplay(replayFile, false, getStartTimestamp(), getEndTimestamp(), outputFile);
} catch(Exception e) {
e.printStackTrace();
}
}
public GuiTrimPart(int yPos) {
super(yPos);
fontRendererObj = mc.fontRendererObj;
}
private int valueOf(String text) {
try {
return Integer.valueOf(text);
} catch(NumberFormatException e) {
return 0;
}
}
@Override
public void applyFilters(File replayFile, File outputFile) {
try {
StudioImplementation.trimReplay(replayFile, false, getStartTimestamp(), getEndTimestamp(), outputFile);
} catch(Exception e) {
e.printStackTrace();
}
}
private int getStartTimestamp() {
int mins = valueOf(startMinInput.getText());
int secs = valueOf(startSecInput.getText());
int ms = valueOf(startMsInput.getText());
private int valueOf(String text) {
try {
return Integer.valueOf(text);
} catch(NumberFormatException e) {
return 0;
}
}
return (mins * 60 * 1000) + (secs * 1000) + ms;
}
private int getStartTimestamp() {
int mins = valueOf(startMinInput.getText());
int secs = valueOf(startSecInput.getText());
int ms = valueOf(startMsInput.getText());
private int getEndTimestamp() {
int mins = valueOf(endMinInput.getText());
int secs = valueOf(endSecInput.getText());
int ms = valueOf(endMsInput.getText());
return (mins*60*1000)+(secs*1000)+ms;
}
return (mins * 60 * 1000) + (secs * 1000) + ms;
}
private int getEndTimestamp() {
int mins = valueOf(endMinInput.getText());
int secs = valueOf(endSecInput.getText());
int ms = valueOf(endMsInput.getText());
@Override
public String getDescription() {
return DESCRIPTION;
}
return (mins*60*1000)+(secs*1000)+ms;
}
@Override
public String getTitle() {
return TITLE;
}
@Override
public String getDescription() {
return DESCRIPTION;
}
@Override
public void initGui() {
if(!initialized) {
startMinInput = new GuiNumberInput(1, fontRendererObj, 70, yPos, 30, 3);
startSecInput = new GuiNumberInput(1, fontRendererObj, 120, yPos, 25, 2);
startMsInput = new GuiNumberInput(1, fontRendererObj, 165, yPos, 30, 3);
@Override
public String getTitle() {
return TITLE;
}
endMinInput = new GuiNumberInput(1, fontRendererObj, 70, yPos + 30, 30, 3);
endSecInput = new GuiNumberInput(1, fontRendererObj, 120, yPos + 30, 25, 2);
endMsInput = new GuiNumberInput(1, fontRendererObj, 165, yPos + 30, 30, 3);
@Override
public void initGui() {
if(!initialized) {
startMinInput = new GuiNumberInput(1, fontRendererObj, 70, yPos, 30, 3);
startSecInput = new GuiNumberInput(1, fontRendererObj, 120, yPos, 25, 2);
startMsInput = new GuiNumberInput(1, fontRendererObj, 165, yPos, 30, 3);
inputOrder.clear();
endMinInput = new GuiNumberInput(1, fontRendererObj, 70, yPos+30, 30, 3);
endSecInput = new GuiNumberInput(1, fontRendererObj, 120, yPos+30, 25, 2);
endMsInput = new GuiNumberInput(1, fontRendererObj, 165, yPos+30, 30, 3);
inputOrder.add(startMinInput);
inputOrder.add(startSecInput);
inputOrder.add(startMsInput);
inputOrder.add(endMinInput);
inputOrder.add(endSecInput);
inputOrder.add(endMsInput);
}
inputOrder.clear();
initialized = true;
}
inputOrder.add(startMinInput);
inputOrder.add(startSecInput);
inputOrder.add(startMsInput);
inputOrder.add(endMinInput);
inputOrder.add(endSecInput);
inputOrder.add(endMsInput);
}
@Override
public void mouseClicked(int mouseX, int mouseY, int mouseButton) {
for(GuiNumberInput input : inputOrder) {
input.mouseClicked(mouseX, mouseY, mouseButton);
}
}
initialized = true;
}
@Override
public void drawScreen(int mouseX, int mouseY, float partialTicks) {
drawString(mc.fontRendererObj, "Start:", 30, yPos + 7, Color.WHITE.getRGB());
drawString(mc.fontRendererObj, "End:", 30, yPos + 7 + 30, Color.WHITE.getRGB());
drawString(mc.fontRendererObj, "m", 105, yPos + 7, Color.WHITE.getRGB());
drawString(mc.fontRendererObj, "m", 105, yPos + 7 + 30, Color.WHITE.getRGB());
drawString(mc.fontRendererObj, "s", 150, yPos + 7, Color.WHITE.getRGB());
drawString(mc.fontRendererObj, "s", 150, yPos + 7 + 30, Color.WHITE.getRGB());
drawString(mc.fontRendererObj, "ms", 200, yPos + 7, Color.WHITE.getRGB());
drawString(mc.fontRendererObj, "ms", 200, yPos + 7 + 30, Color.WHITE.getRGB());
@Override
public void mouseClicked(int mouseX, int mouseY, int mouseButton) {
for(GuiNumberInput input: inputOrder) {
input.mouseClicked(mouseX, mouseY, mouseButton);
}
}
drawString(mc.fontRendererObj, "Timestamp: " + getStartTimestamp(), 230, yPos + 7, Color.WHITE.getRGB());
drawString(mc.fontRendererObj, "Timestamp: " + getEndTimestamp(), 230, yPos + 30 + 7, Color.WHITE.getRGB());
@Override
public void drawScreen(int mouseX, int mouseY, float partialTicks) {
drawString(mc.fontRendererObj, "Start:", 30, yPos+7, Color.WHITE.getRGB());
drawString(mc.fontRendererObj, "End:", 30, yPos+7+30, Color.WHITE.getRGB());
drawString(mc.fontRendererObj, "m", 105, yPos+7, Color.WHITE.getRGB());
drawString(mc.fontRendererObj, "m", 105, yPos+7+30, Color.WHITE.getRGB());
drawString(mc.fontRendererObj, "s", 150, yPos+7, Color.WHITE.getRGB());
drawString(mc.fontRendererObj, "s", 150, yPos+7+30, Color.WHITE.getRGB());
drawString(mc.fontRendererObj, "ms", 200, yPos+7, Color.WHITE.getRGB());
drawString(mc.fontRendererObj, "ms", 200, yPos+7+30, Color.WHITE.getRGB());
for(GuiNumberInput input : inputOrder) {
input.drawTextBox();
}
drawString(mc.fontRendererObj, "Timestamp: "+getStartTimestamp(), 230, yPos+7, Color.WHITE.getRGB());
drawString(mc.fontRendererObj, "Timestamp: "+getEndTimestamp(), 230, yPos+30+7, Color.WHITE.getRGB());
super.drawScreen(mouseX, mouseY, partialTicks);
}
for(GuiNumberInput input: inputOrder) {
input.drawTextBox();
}
@Override
public void updateScreen() {
if(!initialized) {
initGui();
} else {
for(GuiNumberInput input : inputOrder) {
input.updateCursorCounter();
}
}
}
super.drawScreen(mouseX, mouseY, partialTicks);
}
@Override
public void updateScreen() {
if(!initialized) {
initGui();
} else {
for(GuiNumberInput input: inputOrder) {
input.updateCursorCounter();
}
}
}
@Override
public void keyTyped(char typedChar, int keyCode) {
if(keyCode == Keyboard.KEY_TAB) { //Tab handling
int i=0;
for(GuiNumberInput input: inputOrder) {
if(input.isFocused()) {
input.setFocused(false);
i++;
if(i >= inputOrder.size()) i=0;
inputOrder.get(i).setFocused(true);
break;
}
i++;
}
} else {
for(GuiNumberInput input: inputOrder) {
input.textboxKeyTyped(typedChar, keyCode);
}
}
}
@Override
public void keyTyped(char typedChar, int keyCode) {
if(keyCode == Keyboard.KEY_TAB) { //Tab handling
int i = 0;
for(GuiNumberInput input : inputOrder) {
if(input.isFocused()) {
input.setFocused(false);
i++;
if(i >= inputOrder.size()) i = 0;
inputOrder.get(i).setFocused(true);
break;
}
i++;
}
} else {
for(GuiNumberInput input : inputOrder) {
input.textboxKeyTyped(typedChar, keyCode);
}
}
}
}

View File

@@ -1,40 +1,33 @@
package eu.crushedpixel.replaymod.gui.replayviewer;
import java.io.File;
import java.io.IOException;
import eu.crushedpixel.replaymod.recording.ConnectionEventHandler;
import eu.crushedpixel.replaymod.utils.ReplayFileIO;
import net.minecraft.client.gui.GuiButton;
import net.minecraft.client.gui.GuiScreen;
import net.minecraft.client.gui.GuiTextField;
import net.minecraft.client.resources.I18n;
import org.apache.commons.io.FilenameUtils;
import org.lwjgl.input.Keyboard;
import eu.crushedpixel.replaymod.recording.ConnectionEventHandler;
import eu.crushedpixel.replaymod.utils.ReplayFileIO;
import java.io.File;
import java.io.IOException;
public class GuiRenameReplay extends GuiScreen
{
public class GuiRenameReplay extends GuiScreen {
private static final String __OBFID = "CL_00000709";
private GuiScreen field_146585_a;
private GuiTextField field_146583_f;
private static final String __OBFID = "CL_00000709";
private File file;
public GuiRenameReplay(GuiScreen parent, File file)
{
public GuiRenameReplay(GuiScreen parent, File file) {
this.field_146585_a = parent;
this.file = file;
}
public void updateScreen()
{
public void updateScreen() {
this.field_146583_f.updateCursorCounter();
}
public void initGui()
{
public void initGui() {
Keyboard.enableRepeatEvents(true);
this.buttonList.clear();
this.buttonList.add(new GuiButton(0, this.width / 2 - 100, this.height / 4 + 96 + 12, I18n.format("Rename", new Object[0])));
@@ -45,29 +38,23 @@ public class GuiRenameReplay extends GuiScreen
this.field_146583_f.setText(s);
}
public void onGuiClosed()
{
public void onGuiClosed() {
Keyboard.enableRepeatEvents(false);
}
protected void actionPerformed(GuiButton button) throws IOException
{
if (button.enabled)
{
if (button.id == 1)
{
protected void actionPerformed(GuiButton button) throws IOException {
if(button.enabled) {
if(button.id == 1) {
this.mc.displayGuiScreen(this.field_146585_a);
}
else if (button.id == 0)
{
File folder = ReplayFileIO.getReplayFolder();
} else if(button.id == 0) {
File folder = ReplayFileIO.getReplayFolder();
File initRenamed = new File(folder, this.field_146583_f.getText().trim()+ConnectionEventHandler.ZIP_FILE_EXTENSION.replaceAll("[^a-zA-Z0-9\\.\\-]", "_"));
File renamed = initRenamed;
int i=1;
File initRenamed = new File(folder, this.field_146583_f.getText().trim() + ConnectionEventHandler.ZIP_FILE_EXTENSION.replaceAll("[^a-zA-Z0-9\\.\\-]", "_"));
File renamed = initRenamed;
int i = 1;
while(renamed.isFile()) {
renamed = new File(initRenamed.getAbsolutePath()+"_"+i);
i++;
renamed = new File(initRenamed.getAbsolutePath() + "_" + i);
i++;
}
file.renameTo(renamed);
this.mc.displayGuiScreen(this.field_146585_a);
@@ -75,25 +62,21 @@ public class GuiRenameReplay extends GuiScreen
}
}
protected void keyTyped(char typedChar, int keyCode) throws IOException
{
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;
((GuiButton) this.buttonList.get(0)).enabled = this.field_146583_f.getText().trim().length() > 0;
if (keyCode == 28 || keyCode == 156)
{
this.actionPerformed((GuiButton)this.buttonList.get(0));
if(keyCode == 28 || keyCode == 156) {
this.actionPerformed((GuiButton) this.buttonList.get(0));
}
}
protected void mouseClicked(int mouseX, int mouseY, int mouseButton) throws IOException
{
protected void mouseClicked(int mouseX, int mouseY, int mouseButton) throws IOException {
super.mouseClicked(mouseX, mouseY, mouseButton);
this.field_146583_f.mouseClicked(mouseX, mouseY, mouseButton);
}
public void drawScreen(int mouseX, int mouseY, float partialTicks)
{
public void drawScreen(int mouseX, int mouseY, float partialTicks) {
this.drawDefaultBackground();
this.drawCenteredString(this.fontRendererObj, I18n.format("Rename World", new Object[0]), this.width / 2, 20, 16777215);
this.drawString(this.fontRendererObj, I18n.format("Replay Name", new Object[0]), this.width / 2 - 100, 47, 10526880);

View File

@@ -1,37 +1,7 @@
package eu.crushedpixel.replaymod.gui.replayviewer;
import java.awt.Dimension;
import java.awt.image.BufferedImage;
import java.io.BufferedReader;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.URI;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.Date;
import java.util.List;
import javax.imageio.ImageIO;
import net.minecraft.client.gui.GuiButton;
import net.minecraft.client.gui.GuiScreen;
import net.minecraft.client.gui.GuiYesNo;
import net.minecraft.client.gui.GuiYesNoCallback;
import net.minecraft.client.resources.I18n;
import net.minecraft.util.Util;
import org.apache.commons.compress.archivers.zip.ZipArchiveEntry;
import org.apache.commons.compress.archivers.zip.ZipFile;
import org.apache.commons.io.FilenameUtils;
import org.lwjgl.Sys;
import org.lwjgl.input.Keyboard;
import com.google.gson.Gson;
import com.mojang.realmsclient.util.Pair;
import eu.crushedpixel.replaymod.api.client.holders.FileInfo;
import eu.crushedpixel.replaymod.gui.GuiReplaySettings;
import eu.crushedpixel.replaymod.gui.elements.GuiReplayListExtended;
@@ -42,265 +12,271 @@ import eu.crushedpixel.replaymod.recording.ReplayMetaData;
import eu.crushedpixel.replaymod.replay.ReplayHandler;
import eu.crushedpixel.replaymod.utils.ImageUtils;
import eu.crushedpixel.replaymod.utils.ReplayFileIO;
import net.minecraft.client.gui.GuiButton;
import net.minecraft.client.gui.GuiScreen;
import net.minecraft.client.gui.GuiYesNo;
import net.minecraft.client.gui.GuiYesNoCallback;
import net.minecraft.client.resources.I18n;
import net.minecraft.util.Util;
import org.apache.commons.compress.archivers.zip.ZipArchiveEntry;
import org.apache.commons.compress.archivers.zip.ZipFile;
import org.apache.commons.io.FilenameUtils;
import org.lwjgl.Sys;
import org.lwjgl.input.Keyboard;
import javax.imageio.ImageIO;
import java.awt.*;
import java.awt.image.BufferedImage;
import java.io.*;
import java.net.URI;
import java.util.*;
import java.util.List;
public class GuiReplayViewer extends GuiScreen implements GuiYesNoCallback {
private GuiScreen parentScreen;
private GuiButton btnEditServer;
private GuiButton btnSelectServer;
private GuiButton btnDeleteServer;
private String hoveringText;
private boolean initialized;
private GuiReplayListExtended replayGuiList;
private List<Pair<Pair<File, ReplayMetaData>, File>> replayFileList = new ArrayList<Pair<Pair<File, ReplayMetaData>, File>>();
private GuiButton loadButton, uploadButton, folderButton, renameButton, deleteButton, cancelButton, settingsButton;
private static final int LOAD_BUTTON_ID = 9001;
private static final int UPLOAD_BUTTON_ID = 9002;
private static final int FOLDER_BUTTON_ID = 9003;
private static final int RENAME_BUTTON_ID = 9004;
private static final int DELETE_BUTTON_ID = 9005;
private static final int SETTINGS_BUTTON_ID = 9006;
private static final int CANCEL_BUTTON_ID = 9007;
private static Gson gson = new Gson();
private GuiScreen parentScreen;
private GuiButton btnEditServer;
private GuiButton btnSelectServer;
private GuiButton btnDeleteServer;
private String hoveringText;
private boolean initialized;
private GuiReplayListExtended replayGuiList;
private List<Pair<Pair<File, ReplayMetaData>, File>> replayFileList = new ArrayList<Pair<Pair<File, ReplayMetaData>, File>>();
private GuiButton loadButton, uploadButton, folderButton, renameButton, deleteButton, cancelButton, settingsButton;
private boolean replaying = false;
private boolean delete_file = false;
private static Gson gson = new Gson();
private boolean replaying = false;
public static GuiYesNo getYesNoGui(GuiYesNoCallback p_152129_0_, String file, int p_152129_2_) {
String s1 = I18n.format("Are you sure you want to delete this replay?", new Object[0]);
String s2 = "\'" + file + "\' " + I18n.format("will be lost forever! (A long time!)", new Object[0]);
String s3 = I18n.format("Delete", new Object[0]);
String s4 = I18n.format("Cancel", new Object[0]);
GuiYesNo guiyesno = new GuiYesNo(p_152129_0_, s1, s2, s3, s4, p_152129_2_);
return guiyesno;
}
private static final int LOAD_BUTTON_ID = 9001;
private static final int UPLOAD_BUTTON_ID = 9002;
private static final int FOLDER_BUTTON_ID = 9003;
private static final int RENAME_BUTTON_ID = 9004;
private static final int DELETE_BUTTON_ID = 9005;
private static final int SETTINGS_BUTTON_ID = 9006;
private static final int CANCEL_BUTTON_ID = 9007;
private void reloadFiles() {
replayGuiList.clearEntries();
replayFileList = new ArrayList<Pair<Pair<File, ReplayMetaData>, File>>();
private boolean delete_file = false;
for(File file : ReplayFileIO.getAllReplayFiles()) {
try {
ZipFile archive = new ZipFile(file);
ZipArchiveEntry recfile = archive.getEntry("recording" + ConnectionEventHandler.TEMP_FILE_EXTENSION);
ZipArchiveEntry metadata = archive.getEntry("metaData" + ConnectionEventHandler.JSON_FILE_EXTENSION);
private void reloadFiles() {
replayGuiList.clearEntries();
replayFileList = new ArrayList<Pair<Pair<File, ReplayMetaData>, File>>();
ZipArchiveEntry image = archive.getEntry("thumb");
BufferedImage img = null;
if(image != null) {
InputStream is = archive.getInputStream(image);
is.skip(7);
BufferedImage bimg = ImageIO.read(is);
if(bimg != null) {
img = ImageUtils.scaleImage(bimg, new Dimension(1280, 720));
}
}
for(File file : ReplayFileIO.getAllReplayFiles()) {
try {
ZipFile archive = new ZipFile(file);
ZipArchiveEntry recfile = archive.getEntry("recording"+ConnectionEventHandler.TEMP_FILE_EXTENSION);
ZipArchiveEntry metadata = archive.getEntry("metaData"+ConnectionEventHandler.JSON_FILE_EXTENSION);
File tmp = null;
if(img != null) {
tmp = File.createTempFile(FilenameUtils.getBaseName(file.getAbsolutePath()), "jpg");
tmp.deleteOnExit();
ZipArchiveEntry image = archive.getEntry("thumb");
BufferedImage img = null;
if(image != null) {
InputStream is = archive.getInputStream(image);
is.skip(7);
BufferedImage bimg = ImageIO.read(is);
if(bimg != null) {
img = ImageUtils.scaleImage(bimg, new Dimension(1280, 720));
}
}
ImageIO.write(img, "jpg", tmp);
}
File tmp = null;
if(img != null) {
tmp = File.createTempFile(FilenameUtils.getBaseName(file.getAbsolutePath()), "jpg");
tmp.deleteOnExit();
InputStream is = archive.getInputStream(metadata);
BufferedReader br = new BufferedReader(new InputStreamReader(is));
ImageIO.write(img, "jpg", tmp);
}
String json = br.readLine();
InputStream is = archive.getInputStream(metadata);
BufferedReader br = new BufferedReader(new InputStreamReader(is));
ReplayMetaData metaData = gson.fromJson(json, ReplayMetaData.class);
String json = br.readLine();
replayFileList.add(Pair.of(Pair.of(file, metaData), tmp));
ReplayMetaData metaData = gson.fromJson(json, ReplayMetaData.class);
archive.close();
} catch(Exception e) {
}
}
replayFileList.add(Pair.of(Pair.of(file, metaData), tmp));
Collections.sort(replayFileList, new FileAgeComparator());
archive.close();
} catch(Exception e) {}
}
for(Pair<Pair<File, ReplayMetaData>, File> p : replayFileList) {
FileInfo fileInfo = new FileInfo(-1, p.first().second(), null, null,
-1, -1, -1, FilenameUtils.getBaseName(p.first().first().getName()), true);
replayGuiList.addEntry(fileInfo, p.second());
}
}
Collections.sort(replayFileList, new FileAgeComparator());
@Override
public void initGui() {
replayGuiList = new ReplayList(this, this.mc, this.width, this.height, 32, this.height - 64, 36);
Keyboard.enableRepeatEvents(true);
this.buttonList.clear();
for(Pair<Pair<File, ReplayMetaData>, File> p : replayFileList) {
FileInfo fileInfo = new FileInfo(-1, p.first().second(), null, null,
-1, -1, -1, FilenameUtils.getBaseName(p.first().first().getName()), true);
replayGuiList.addEntry(fileInfo, p.second());
}
}
if(!this.initialized) {
this.initialized = true;
} else {
this.replayGuiList.setDimensions(this.width, this.height, 32, this.height - 64);
}
public class FileAgeComparator implements Comparator<Pair<Pair<File, ReplayMetaData>, File>> {
reloadFiles();
this.createButtons();
}
@Override
public int compare(Pair<Pair<File, ReplayMetaData>, File> o1, Pair<Pair<File, ReplayMetaData>, File> o2) {
try {
return (int)(new Date(o2.first().second().getDate()).compareTo(new Date(o1.first().second().getDate())));
} catch(Exception e) {
return 0;
}
}
private void createButtons() {
this.buttonList.add(loadButton = new GuiButton(LOAD_BUTTON_ID, this.width / 2 - 154, this.height - 52, 73, 20, I18n.format("Load", new Object[0])));
this.buttonList.add(uploadButton = new GuiButton(UPLOAD_BUTTON_ID, this.width / 2 - 154 + 78, this.height - 52, 73, 20, I18n.format("Upload", new Object[0])));
this.buttonList.add(folderButton = new GuiButton(FOLDER_BUTTON_ID, this.width / 2 + 4, this.height - 52, 150, 20, I18n.format("Open Replay Folder...", new Object[0])));
this.buttonList.add(renameButton = new GuiButton(RENAME_BUTTON_ID, this.width / 2 - 154, this.height - 28, 72, 20, I18n.format("Rename", new Object[0])));
this.buttonList.add(deleteButton = new GuiButton(DELETE_BUTTON_ID, this.width / 2 - 76, this.height - 28, 72, 20, I18n.format("Delete", new Object[0])));
this.buttonList.add(settingsButton = new GuiButton(SETTINGS_BUTTON_ID, this.width / 2 + 4, this.height - 28, 72, 20, I18n.format("Settings", new Object[0])));
this.buttonList.add(cancelButton = new GuiButton(CANCEL_BUTTON_ID, this.width / 2 + 4 + 78, this.height - 28, 72, 20, I18n.format("Cancel", new Object[0])));
setButtonsEnabled(false);
}
}
@Override
public void handleMouseInput() throws IOException {
super.handleMouseInput();
this.replayGuiList.handleMouseInput();
}
@Override
public void initGui() {
replayGuiList = new ReplayList(this, this.mc, this.width, this.height, 32, this.height - 64, 36);
Keyboard.enableRepeatEvents(true);
this.buttonList.clear();
@Override
protected void mouseClicked(int mouseX, int mouseY, int mouseButton) throws IOException {
super.mouseClicked(mouseX, mouseY, mouseButton);
this.replayGuiList.mouseClicked(mouseX, mouseY, mouseButton);
}
if (!this.initialized) {
this.initialized = true;
}
else {
this.replayGuiList.setDimensions(this.width, this.height, 32, this.height - 64);
}
@Override
protected void mouseReleased(int mouseX, int mouseY, int state) {
super.mouseReleased(mouseX, mouseY, state);
this.replayGuiList.mouseReleased(mouseX, mouseY, state);
}
reloadFiles();
this.createButtons();
}
@Override
public void drawScreen(int mouseX, int mouseY, float partialTicks) {
this.hoveringText = null;
this.drawDefaultBackground();
this.replayGuiList.drawScreen(mouseX, mouseY, partialTicks);
this.drawCenteredString(this.fontRendererObj, "Replay Viewer", this.width / 2, 20, 16777215);
super.drawScreen(mouseX, mouseY, partialTicks);
}
private void createButtons() {
this.buttonList.add(loadButton = new GuiButton(LOAD_BUTTON_ID, this.width / 2 - 154, this.height - 52, 73, 20, I18n.format("Load", new Object[0])));
this.buttonList.add(uploadButton = new GuiButton(UPLOAD_BUTTON_ID, this.width / 2 - 154 + 78, this.height - 52, 73, 20, I18n.format("Upload", new Object[0])));
this.buttonList.add(folderButton = new GuiButton(FOLDER_BUTTON_ID, this.width / 2 + 4, this.height - 52, 150, 20, I18n.format("Open Replay Folder...", new Object[0])));
this.buttonList.add(renameButton = new GuiButton(RENAME_BUTTON_ID, this.width / 2 - 154, this.height - 28, 72, 20, I18n.format("Rename", new Object[0])));
this.buttonList.add(deleteButton = new GuiButton(DELETE_BUTTON_ID, this.width / 2 - 76, this.height - 28, 72, 20, I18n.format("Delete", new Object[0])));
this.buttonList.add(settingsButton = new GuiButton(SETTINGS_BUTTON_ID, this.width / 2 + 4, this.height - 28, 72, 20, I18n.format("Settings", new Object[0])));
this.buttonList.add(cancelButton = new GuiButton(CANCEL_BUTTON_ID, this.width / 2 + 4 + 78, this.height - 28, 72, 20, I18n.format("Cancel", new Object[0])));
setButtonsEnabled(false);
}
@Override
protected void actionPerformed(GuiButton button) throws IOException {
if(button.enabled) {
if(button.id == LOAD_BUTTON_ID) {
loadReplay(replayGuiList.selected);
} else if(button.id == CANCEL_BUTTON_ID) {
mc.displayGuiScreen(parentScreen);
} else if(button.id == DELETE_BUTTON_ID) {
String s = replayGuiList.getListEntry(replayGuiList.selected).getFileInfo().getName();
@Override
public void handleMouseInput() throws IOException {
super.handleMouseInput();
this.replayGuiList.handleMouseInput();
}
if(s != null) {
delete_file = true;
GuiYesNo guiyesno = getYesNoGui(this, s, 1);
this.mc.displayGuiScreen(guiyesno);
}
} else if(button.id == SETTINGS_BUTTON_ID) {
this.mc.displayGuiScreen(new GuiReplaySettings(this));
} else if(button.id == RENAME_BUTTON_ID) {
File file = replayFileList.get(replayGuiList.selected).first().first();
this.mc.displayGuiScreen(new GuiRenameReplay(this, file));
} else if(button.id == UPLOAD_BUTTON_ID) {
File file = replayFileList.get(replayGuiList.selected).first().first();
this.mc.displayGuiScreen(new GuiUploadFile(file, this));
} else if(button.id == FOLDER_BUTTON_ID) {
File file1 = ReplayFileIO.getReplayFolder();
@Override
protected void mouseClicked(int mouseX, int mouseY, int mouseButton) throws IOException {
super.mouseClicked(mouseX, mouseY, mouseButton);
this.replayGuiList.mouseClicked(mouseX, mouseY, mouseButton);
}
String s = file1.getAbsolutePath();
@Override
protected void mouseReleased(int mouseX, int mouseY, int state) {
super.mouseReleased(mouseX, mouseY, state);
this.replayGuiList.mouseReleased(mouseX, mouseY, state);
}
if(Util.getOSType() == Util.EnumOS.OSX) {
try {
Runtime.getRuntime().exec(new String[]{"/usr/bin/open", s});
return;
} catch(IOException ioexception1) {
}
} else if(Util.getOSType() == Util.EnumOS.WINDOWS) {
String s1 = String.format("cmd.exe /C start \"Open file\" \"%s\"", new Object[]{s});
@Override
public void drawScreen(int mouseX, int mouseY, float partialTicks) {
this.hoveringText = null;
this.drawDefaultBackground();
this.replayGuiList.drawScreen(mouseX, mouseY, partialTicks);
this.drawCenteredString(this.fontRendererObj, "Replay Viewer", this.width / 2, 20, 16777215);
super.drawScreen(mouseX, mouseY, partialTicks);
}
try {
Runtime.getRuntime().exec(s1);
return;
} catch(IOException ioexception) {
}
}
@Override
protected void actionPerformed(GuiButton button) throws IOException {
if(button.enabled) {
if(button.id == LOAD_BUTTON_ID) {
loadReplay(replayGuiList.selected);
}
else if(button.id == CANCEL_BUTTON_ID) {
mc.displayGuiScreen(parentScreen);
}
else if(button.id == DELETE_BUTTON_ID) {
String s = replayGuiList.getListEntry(replayGuiList.selected).getFileInfo().getName();
boolean flag = false;
if (s != null) {
delete_file = true;
GuiYesNo guiyesno = getYesNoGui(this, s, 1);
this.mc.displayGuiScreen(guiyesno);
}
}
else if(button.id == SETTINGS_BUTTON_ID) {
this.mc.displayGuiScreen(new GuiReplaySettings(this));
}
else if(button.id == RENAME_BUTTON_ID) {
File file = replayFileList.get(replayGuiList.selected).first().first();
this.mc.displayGuiScreen(new GuiRenameReplay(this, file));
}
else if(button.id == UPLOAD_BUTTON_ID) {
File file = replayFileList.get(replayGuiList.selected).first().first();
this.mc.displayGuiScreen(new GuiUploadFile(file, this));
}
else if(button.id == FOLDER_BUTTON_ID) {
File file1 = ReplayFileIO.getReplayFolder();
String s = file1.getAbsolutePath();
try {
Class oclass = Class.forName("java.awt.Desktop");
Object object = oclass.getMethod("getDesktop", new Class[0]).invoke((Object) null, new Object[0]);
oclass.getMethod("browse", new Class[]{URI.class}).invoke(object, new Object[]{file1.toURI()});
} catch(Throwable throwable) {
flag = true;
}
if(Util.getOSType() == Util.EnumOS.OSX) {
try {
Runtime.getRuntime().exec(new String[] {"/usr/bin/open", s});
return;
}
catch(IOException ioexception1) {}
}
else if(Util.getOSType() == Util.EnumOS.WINDOWS) {
String s1 = String.format("cmd.exe /C start \"Open file\" \"%s\"", new Object[] {s});
if(flag) {
Sys.openURL("file://" + s);
}
}
}
}
try{
Runtime.getRuntime().exec(s1);
return;
}
catch(IOException ioexception) {}
}
public void confirmClicked(boolean result, int id) {
if(this.delete_file) {
this.delete_file = false;
boolean flag = false;
if(result) {
replayFileList.get(replayGuiList.selected).first().first().delete();
replayFileList.remove(replayGuiList.selected);
}
try {
Class oclass = Class.forName("java.awt.Desktop");
Object object = oclass.getMethod("getDesktop", new Class[0]).invoke((Object)null, new Object[0]);
oclass.getMethod("browse", new Class[] {URI.class}).invoke(object, new Object[] {file1.toURI()});
}
catch(Throwable throwable) {
flag = true;
}
this.mc.displayGuiScreen(this);
}
}
if(flag) {
Sys.openURL("file://" + s);
}
}
}
}
public void setButtonsEnabled(boolean b) {
loadButton.enabled = b;
if(!b || !AuthenticationHandler.isAuthenticated()) {
uploadButton.enabled = false;
} else {
uploadButton.enabled = true;
}
public void confirmClicked(boolean result, int id) {
if (this.delete_file)
{
this.delete_file = false;
renameButton.enabled = b;
deleteButton.enabled = b;
}
if (result)
{
replayFileList.get(replayGuiList.selected).first().first().delete();
replayFileList.remove(replayGuiList.selected);
}
public void loadReplay(int id) {
mc.displayGuiScreen((GuiScreen) null);
this.mc.displayGuiScreen(this);
}
}
try {
ReplayHandler.startReplay(replayFileList.get(id).first().first());
} catch(Exception e) {
e.printStackTrace();
}
public static GuiYesNo getYesNoGui(GuiYesNoCallback p_152129_0_, String file, int p_152129_2_) {
String s1 = I18n.format("Are you sure you want to delete this replay?", new Object[0]);
String s2 = "\'" + file + "\' " + I18n.format("will be lost forever! (A long time!)", new Object[0]);
String s3 = I18n.format("Delete", new Object[0]);
String s4 = I18n.format("Cancel", new Object[0]);
GuiYesNo guiyesno = new GuiYesNo(p_152129_0_, s1, s2, s3, s4, p_152129_2_);
return guiyesno;
}
}
public void setButtonsEnabled(boolean b) {
loadButton.enabled = b;
if(!b || !AuthenticationHandler.isAuthenticated()) {
uploadButton.enabled = false;
} else {
uploadButton.enabled = true;
}
public class FileAgeComparator implements Comparator<Pair<Pair<File, ReplayMetaData>, File>> {
renameButton.enabled = b;
deleteButton.enabled = b;
}
@Override
public int compare(Pair<Pair<File, ReplayMetaData>, File> o1, Pair<Pair<File, ReplayMetaData>, File> o2) {
try {
return (int) (new Date(o2.first().second().getDate()).compareTo(new Date(o1.first().second().getDate())));
} catch(Exception e) {
return 0;
}
}
public void loadReplay(int id) {
mc.displayGuiScreen((GuiScreen)null);
try {
ReplayHandler.startReplay(replayFileList.get(id).first().first());
} catch(Exception e) {
e.printStackTrace();
}
}
}
}

View File

@@ -5,25 +5,25 @@ import net.minecraft.client.Minecraft;
public class ReplayList extends GuiReplayListExtended {
private GuiReplayViewer parent;
public ReplayList(GuiReplayViewer parent, Minecraft mcIn,
int p_i45010_2_, int p_i45010_3_, int p_i45010_4_, int p_i45010_5_,
int p_i45010_6_) {
super(mcIn, p_i45010_2_, p_i45010_3_, p_i45010_4_, p_i45010_5_,
p_i45010_6_);
private GuiReplayViewer parent;
this.parent = parent;
}
@Override
protected void elementClicked(int slotIndex, boolean isDoubleClick,
int mouseX, int mouseY) {
super.elementClicked(slotIndex, isDoubleClick, mouseX, mouseY);
parent.setButtonsEnabled(true);
if(isDoubleClick) {
parent.loadReplay(slotIndex);
}
}
public ReplayList(GuiReplayViewer parent, Minecraft mcIn,
int p_i45010_2_, int p_i45010_3_, int p_i45010_4_, int p_i45010_5_,
int p_i45010_6_) {
super(mcIn, p_i45010_2_, p_i45010_3_, p_i45010_4_, p_i45010_5_,
p_i45010_6_);
this.parent = parent;
}
@Override
protected void elementClicked(int slotIndex, boolean isDoubleClick,
int mouseX, int mouseY) {
super.elementClicked(slotIndex, isDoubleClick, mouseX, mouseY);
parent.setButtonsEnabled(true);
if(isDoubleClick) {
parent.loadReplay(slotIndex);
}
}
}