Fix realms notifications not being offset with button (fixes #22 GH)
This commit is contained in:
@@ -2,9 +2,14 @@ package com.replaymod.core.handler;
|
|||||||
|
|
||||||
import net.minecraft.client.gui.GuiButton;
|
import net.minecraft.client.gui.GuiButton;
|
||||||
import net.minecraft.client.gui.GuiMainMenu;
|
import net.minecraft.client.gui.GuiMainMenu;
|
||||||
|
import net.minecraft.client.gui.GuiScreen;
|
||||||
|
import net.minecraft.client.gui.GuiScreenRealmsProxy;
|
||||||
import net.minecraftforge.client.event.GuiScreenEvent;
|
import net.minecraftforge.client.event.GuiScreenEvent;
|
||||||
import net.minecraftforge.common.MinecraftForge;
|
import net.minecraftforge.common.MinecraftForge;
|
||||||
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
|
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
|
||||||
|
import org.lwjgl.opengl.GL11;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Moves certain buttons on the main menu upwards so we can inject our own.
|
* Moves certain buttons on the main menu upwards so we can inject our own.
|
||||||
@@ -17,6 +22,8 @@ public class MainMenuHandler {
|
|||||||
@SubscribeEvent
|
@SubscribeEvent
|
||||||
public void onInit(GuiScreenEvent.InitGuiEvent.Post event) {
|
public void onInit(GuiScreenEvent.InitGuiEvent.Post event) {
|
||||||
if (event.getGui() instanceof GuiMainMenu) {
|
if (event.getGui() instanceof GuiMainMenu) {
|
||||||
|
GuiMainMenu gui = (GuiMainMenu) event.getGui();
|
||||||
|
int realmsOffset = 0;
|
||||||
for (GuiButton button : event.getButtonList()) {
|
for (GuiButton button : event.getButtonList()) {
|
||||||
// Buttons that aren't in a rectangle directly above our space don't need moving
|
// Buttons that aren't in a rectangle directly above our space don't need moving
|
||||||
if (button.x + button.width < event.getGui().width / 2 - 100
|
if (button.x + button.width < event.getGui().width / 2 - 100
|
||||||
@@ -24,8 +31,57 @@ public class MainMenuHandler {
|
|||||||
|| button.y > event.getGui().height / 4 + 10 + 4 * 24) continue;
|
|| button.y > event.getGui().height / 4 + 10 + 4 * 24) continue;
|
||||||
// Move button up to make space for two rows of buttons
|
// Move button up to make space for two rows of buttons
|
||||||
// and then move back down by 10 to compensate for the space to the exit button that was already there
|
// and then move back down by 10 to compensate for the space to the exit button that was already there
|
||||||
button.y -= 2 * 24 - 10;
|
int offset = -2 * 24 + 10;
|
||||||
|
button.y += offset;
|
||||||
|
if (button == gui.realmsButton) {
|
||||||
|
realmsOffset = offset;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (realmsOffset != 0 && gui.realmsNotification instanceof GuiScreenRealmsProxy) {
|
||||||
|
gui.realmsNotification = new RealmsNotificationProxy((GuiScreenRealmsProxy) gui.realmsNotification, realmsOffset);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static class RealmsNotificationProxy extends GuiScreen {
|
||||||
|
private final GuiScreenRealmsProxy proxy;
|
||||||
|
private final int offset;
|
||||||
|
|
||||||
|
private RealmsNotificationProxy(GuiScreenRealmsProxy proxy, int offset) {
|
||||||
|
this.proxy = proxy;
|
||||||
|
this.offset = offset;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setGuiSize(int w, int h) {
|
||||||
|
proxy.setGuiSize(w, h);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void initGui() {
|
||||||
|
proxy.initGui();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void updateScreen() {
|
||||||
|
proxy.updateScreen();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void drawScreen(int mouseX, int mouseY, float partialTicks) {
|
||||||
|
GL11.glTranslated(0, offset, 0);
|
||||||
|
proxy.drawScreen(mouseX, mouseY - offset, partialTicks);
|
||||||
|
GL11.glTranslated(0, -offset, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void mouseClicked(int mouseX, int mouseY, int mouseButton) throws IOException {
|
||||||
|
proxy.mouseClicked(mouseX, mouseY - offset, mouseButton);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onGuiClosed() {
|
||||||
|
proxy.onGuiClosed();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -42,6 +42,10 @@ public net.minecraft.network.play.server.SPacketSpawnPlayer field_148960_i # wat
|
|||||||
# GuiTextField
|
# GuiTextField
|
||||||
public net.minecraft.client.gui.GuiTextField field_146216_j # text
|
public net.minecraft.client.gui.GuiTextField field_146216_j # text
|
||||||
|
|
||||||
|
# GuiMainMenu
|
||||||
|
public net.minecraft.client.gui.GuiMainMenu field_175372_K # realmsButton
|
||||||
|
public net.minecraft.client.gui.GuiMainMenu field_183503_M # realmsNotification
|
||||||
|
|
||||||
# Entity
|
# Entity
|
||||||
public net.minecraft.entity.Entity field_70180_af # dataWatcher
|
public net.minecraft.entity.Entity field_70180_af # dataWatcher
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user