Cleaned up Gui overriding and replaced it with Forge Event Handlers
This commit is contained in:
@@ -1,139 +0,0 @@
|
||||
package eu.crushedpixel.replaymod.gui;
|
||||
|
||||
import io.netty.channel.SimpleChannelInboundHandler;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.Calendar;
|
||||
import java.util.Date;
|
||||
|
||||
import eu.crushedpixel.replaymod.reflection.MCPNames;
|
||||
import net.minecraft.client.gui.GuiButton;
|
||||
import net.minecraft.client.gui.GuiButtonLanguage;
|
||||
import net.minecraft.client.gui.GuiMainMenu;
|
||||
import net.minecraft.client.gui.GuiSelectWorld;
|
||||
import net.minecraft.client.renderer.texture.DynamicTexture;
|
||||
import net.minecraft.client.resources.I18n;
|
||||
import net.minecraft.network.Packet;
|
||||
|
||||
public class GuiCustomMainMenu extends GuiMainMenu {
|
||||
|
||||
private static final int REPLAY_MANAGER_ID = 9001;
|
||||
|
||||
@Override
|
||||
public void initGui() {
|
||||
Class<? extends GuiMainMenu> clazz = GuiMainMenu.class;
|
||||
|
||||
int i1 = this.height / 4 + 48;
|
||||
this.buttonList.add(new GuiButton(REPLAY_MANAGER_ID, this.width / 2 - 100, i1 + 2*24, I18n.format("Replay Manager", new Object[0])));
|
||||
|
||||
try {
|
||||
Field viewportTexture = clazz.getDeclaredField(MCPNames.field("field_73977_n"));
|
||||
viewportTexture.setAccessible(true);
|
||||
viewportTexture.set(this, new DynamicTexture(256, 256));
|
||||
|
||||
Field field_110351_G = clazz.getDeclaredField(MCPNames.field("field_110351_G"));
|
||||
field_110351_G.setAccessible(true);
|
||||
field_110351_G.set(this, this.mc.getTextureManager().getDynamicTextureLocation("background", (DynamicTexture)viewportTexture.get(this)));
|
||||
|
||||
Calendar calendar = Calendar.getInstance();
|
||||
calendar.setTime(new Date());
|
||||
|
||||
Field splashText = clazz.getDeclaredField(MCPNames.field("field_73975_c"));
|
||||
splashText.setAccessible(true);
|
||||
|
||||
if (calendar.get(2) + 1 == 11 && calendar.get(5) == 9)
|
||||
{
|
||||
splashText.set(this, "Happy birthday, ez!");
|
||||
}
|
||||
else if (calendar.get(2) + 1 == 6 && calendar.get(5) == 1)
|
||||
{
|
||||
splashText.set(this, "Happy birthday, Notch!");
|
||||
}
|
||||
else if (calendar.get(2) + 1 == 12 && calendar.get(5) == 24)
|
||||
{
|
||||
splashText.set(this, "Merry X-Mas!");
|
||||
}
|
||||
else if (calendar.get(2) + 1 == 1 && calendar.get(5) == 1)
|
||||
{
|
||||
splashText.set(this, "Happy new year!");
|
||||
}
|
||||
else if (calendar.get(2) + 1 == 10 && calendar.get(5) == 31)
|
||||
{
|
||||
splashText.set(this, "OOoooOOOoooo! Spooky!");
|
||||
}
|
||||
|
||||
boolean flag = true;
|
||||
int i = this.height / 4 + 48;
|
||||
|
||||
if (this.mc.isDemo())
|
||||
{
|
||||
Method addDemoButtons = clazz.getDeclaredMethod(MCPNames.method("func_73972_b"), int.class, int.class);
|
||||
addDemoButtons.setAccessible(true);
|
||||
addDemoButtons.invoke(this, i, 24);
|
||||
}
|
||||
else
|
||||
{
|
||||
Method addSingleplayerMultiplayerButtons = clazz.getDeclaredMethod(MCPNames.method("func_73969_a"), int.class, int.class);
|
||||
addSingleplayerMultiplayerButtons.setAccessible(true);
|
||||
addSingleplayerMultiplayerButtons.invoke(this, i - 24, 24);
|
||||
}
|
||||
|
||||
this.buttonList.add(new GuiButton(0, this.width / 2 - 100, i + 72 + 12, 98, 20, I18n.format("menu.options", new Object[0])));
|
||||
this.buttonList.add(new GuiButton(4, this.width / 2 + 2, i + 72 + 12, 98, 20, I18n.format("menu.quit", new Object[0])));
|
||||
this.buttonList.add(new GuiButtonLanguage(5, this.width / 2 - 124, i + 72 + 12));
|
||||
|
||||
Field threadLock = clazz.getDeclaredField(MCPNames.field("field_104025_t"));
|
||||
threadLock.setAccessible(true);
|
||||
Object object = threadLock.get(this);
|
||||
|
||||
Field field_92023_s = clazz.getDeclaredField(MCPNames.field("field_92023_s"));
|
||||
field_92023_s.setAccessible(true);
|
||||
|
||||
Field openGLWarning1 = clazz.getDeclaredField(MCPNames.field("openGLWarning1"));
|
||||
openGLWarning1.setAccessible(true);
|
||||
|
||||
Field openGLWarning2 = clazz.getDeclaredField(MCPNames.field("openGLWarning2"));
|
||||
openGLWarning2.setAccessible(true);
|
||||
|
||||
Field field_92024_r = clazz.getDeclaredField(MCPNames.field("field_92024_r"));
|
||||
field_92024_r.setAccessible(true);
|
||||
|
||||
Field field_92022_t = clazz.getDeclaredField(MCPNames.field("field_92022_t"));
|
||||
field_92022_t.setAccessible(true);
|
||||
|
||||
Field field_92021_u = clazz.getDeclaredField(MCPNames.field("field_92021_u"));
|
||||
field_92021_u.setAccessible(true);
|
||||
|
||||
Field field_92020_v = clazz.getDeclaredField(MCPNames.field("field_92020_v"));
|
||||
field_92020_v.setAccessible(true);
|
||||
|
||||
Field field_92019_w = clazz.getDeclaredField(MCPNames.field("field_92019_w"));
|
||||
field_92019_w.setAccessible(true);
|
||||
|
||||
synchronized (object)
|
||||
{
|
||||
field_92023_s.set(this, this.fontRendererObj.getStringWidth((String)openGLWarning1.get(this)));
|
||||
field_92024_r.set(this, this.fontRendererObj.getStringWidth((String)openGLWarning2.get(this)));
|
||||
int j = Math.max((Integer)(field_92023_s.get(this)), (Integer)(field_92024_r.get(this)));
|
||||
field_92022_t.set(this, (this.width - j) / 2);
|
||||
field_92021_u.set(this, ((GuiButton)this.buttonList.get(0)).yPosition - 24);
|
||||
field_92020_v.set(this, (Integer)field_92022_t.get(this) + j);
|
||||
field_92019_w.set(this, (Integer)field_92021_u.get(this) + 24);
|
||||
}
|
||||
|
||||
} catch(Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void actionPerformed(GuiButton button) throws IOException {
|
||||
if(button.id == REPLAY_MANAGER_ID) {
|
||||
this.mc.displayGuiScreen(new GuiReplayManager());
|
||||
}
|
||||
super.actionPerformed(button);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,63 +0,0 @@
|
||||
package eu.crushedpixel.replaymod.gui;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.lang.reflect.Field;
|
||||
|
||||
import com.mojang.realmsclient.util.Pair;
|
||||
|
||||
import eu.crushedpixel.replaymod.reflection.MCPNames;
|
||||
import net.minecraft.client.gui.GuiButton;
|
||||
import net.minecraft.client.gui.GuiCustomizeSkin;
|
||||
import net.minecraft.client.gui.GuiOptionButton;
|
||||
import net.minecraft.client.gui.GuiOptions;
|
||||
import net.minecraft.client.gui.GuiScreen;
|
||||
import net.minecraft.client.renderer.texture.DynamicTexture;
|
||||
import net.minecraft.client.settings.GameSettings;
|
||||
|
||||
public class GuiCustomOptions extends GuiOptions {
|
||||
|
||||
public static GuiScreen getGuiScreen(GuiOptions go) {
|
||||
try {
|
||||
Class<GuiOptions> clazz = GuiOptions.class;
|
||||
Field guiScreen = clazz.getDeclaredField(MCPNames.field(MCPNames.field("field_146441_g")));
|
||||
guiScreen.setAccessible(true);
|
||||
Object obj = guiScreen.get(go);
|
||||
return (GuiScreen)obj;
|
||||
} catch(Exception e) {
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public static GameSettings getGameSettings(GuiOptions go) {
|
||||
try {
|
||||
Class<GuiOptions> clazz = GuiOptions.class;
|
||||
Field gameSettings = clazz.getDeclaredField(MCPNames.field(MCPNames.field("field_146443_h")));
|
||||
gameSettings.setAccessible(true);
|
||||
Object obj = gameSettings.get(go);
|
||||
return (GameSettings)obj;
|
||||
} catch(Exception e) {
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public GuiCustomOptions(GuiScreen guiScreen, GameSettings gameSettings) {
|
||||
super(guiScreen, gameSettings);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initGui() {
|
||||
super.initGui();
|
||||
buttonList.add(new GuiButton(9001, this.width / 2 - 155, this.height / 6 + 48 - 6 - 24, 310, 20, "Replay Mod Settings..."));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void actionPerformed(GuiButton button) throws IOException {
|
||||
super.actionPerformed(button);
|
||||
if (button.enabled && button.id == 9001) { //Replay Mod Settings...
|
||||
this.mc.displayGuiScreen(new GuiReplaySettings(this));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -45,19 +45,17 @@ public class GuiExitReplay extends GuiIngameMenu {
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
mc.displayGuiScreen(new GuiReplaySaving());
|
||||
ReplayHandler.endReplay();
|
||||
ReplayHandler.setSpeed(1f);
|
||||
|
||||
ReplayHandler.lastExit = System.currentTimeMillis();
|
||||
mc.theWorld.sendQuittingDisconnectingPacket();
|
||||
mc.displayGuiScreen(new GuiMainMenu());
|
||||
//mc.loadWorld((WorldClient)null);
|
||||
}
|
||||
});
|
||||
|
||||
t.run();
|
||||
|
||||
|
||||
} else {
|
||||
super.actionPerformed(button);
|
||||
}
|
||||
|
||||
@@ -5,23 +5,18 @@ import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.net.SocketAddress;
|
||||
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 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.network.NetHandlerLoginClient;
|
||||
import net.minecraft.client.resources.I18n;
|
||||
import net.minecraft.network.EnumConnectionState;
|
||||
import net.minecraft.network.NetworkManager;
|
||||
import net.minecraft.network.handshake.client.C00Handshake;
|
||||
import net.minecraft.network.login.client.C00PacketLoginStart;
|
||||
import net.minecraft.util.Util;
|
||||
|
||||
import org.apache.commons.compress.archivers.zip.ZipArchiveEntry;
|
||||
@@ -36,7 +31,6 @@ import com.mojang.realmsclient.util.Pair;
|
||||
import eu.crushedpixel.replaymod.recording.ConnectionEventHandler;
|
||||
import eu.crushedpixel.replaymod.recording.ReplayMetaData;
|
||||
import eu.crushedpixel.replaymod.replay.ReplayHandler;
|
||||
import eu.crushedpixel.replaymod.replay.ReplaySender;
|
||||
|
||||
public class GuiReplayManager extends GuiScreen implements GuiYesNoCallback {
|
||||
|
||||
@@ -103,7 +97,7 @@ public class GuiReplayManager extends GuiScreen implements GuiYesNoCallback {
|
||||
|
||||
@Override
|
||||
public int compare(Pair<File, ReplayMetaData> o1, Pair<File, ReplayMetaData> o2) {
|
||||
return (int) (o2.second().getDate() - o1.second().getDate());
|
||||
return (int)(new Date(o2.second().getDate()).compareTo(new Date(o1.second().getDate())));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,24 @@
|
||||
package eu.crushedpixel.replaymod.gui;
|
||||
|
||||
import java.awt.Color;
|
||||
|
||||
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 {
|
||||
|
||||
@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(!ConnectionEventHandler.saving) {
|
||||
Minecraft.getMinecraft().displayGuiScreen(new GuiReplayManager());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user