Rewrite main menu button offset to be more compatible (closes #341)
In particular, we now position it relative to the realms (fallback to multiplayer) button. This removes the need for special-casing ModMenu and fixes compatibility with Better Mod Button.
This commit is contained in:
@@ -5,7 +5,6 @@ import com.replaymod.compat.ReplayModCompat;
|
||||
import com.replaymod.core.gui.GuiBackgroundProcesses;
|
||||
import com.replaymod.core.gui.GuiReplaySettings;
|
||||
import com.replaymod.core.gui.RestoreReplayGui;
|
||||
import com.replaymod.core.handler.MainMenuHandler;
|
||||
import com.replaymod.core.mixin.MinecraftAccessor;
|
||||
import com.replaymod.core.versions.MCVer;
|
||||
import com.replaymod.editor.ReplayModEditor;
|
||||
@@ -324,8 +323,6 @@ public class ReplayMod implements
|
||||
|
||||
@Override
|
||||
public void initClient() {
|
||||
new MainMenuHandler().register();
|
||||
|
||||
//#if MC<=10710
|
||||
//$$ FML_BUS.register(this); // For runLater(Runnable)
|
||||
//#endif
|
||||
|
||||
@@ -1,124 +0,0 @@
|
||||
package com.replaymod.core.handler;
|
||||
|
||||
import com.replaymod.core.mixin.GuiMainMenuAccessor;
|
||||
import de.johni0702.minecraft.gui.utils.EventRegistrations;
|
||||
import net.minecraft.client.MinecraftClient;
|
||||
import net.minecraft.client.gui.screen.TitleScreen;
|
||||
import net.minecraft.client.gui.screen.Screen;
|
||||
import org.lwjgl.opengl.GL11;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import static com.replaymod.core.versions.MCVer.*;
|
||||
|
||||
//#if MC>=11400 && MC<11600
|
||||
//$$ import net.minecraft.realms.RealmsScreenProxy;
|
||||
//#endif
|
||||
|
||||
//#if FABRIC>=1
|
||||
import de.johni0702.minecraft.gui.versions.callbacks.InitScreenCallback;
|
||||
//#else
|
||||
//$$ import net.minecraftforge.client.event.GuiScreenEvent;
|
||||
//$$ import net.minecraftforge.common.MinecraftForge;
|
||||
//$$ import net.minecraftforge.eventbus.api.SubscribeEvent;
|
||||
//#endif
|
||||
|
||||
//#if MC>=11400
|
||||
import net.minecraft.client.gui.widget.AbstractButtonWidget;
|
||||
import net.minecraft.client.resource.language.I18n;
|
||||
//#else
|
||||
//$$ import net.minecraft.client.gui.GuiButton;
|
||||
//#endif
|
||||
|
||||
/**
|
||||
* Moves certain buttons on the main menu upwards so we can inject our own.
|
||||
*/
|
||||
public class MainMenuHandler extends EventRegistrations {
|
||||
//#if FABRIC>=1
|
||||
{ on(InitScreenCallback.EVENT, this::onInit); }
|
||||
public void onInit(Screen guiScreen, List<AbstractButtonWidget> buttonList) {
|
||||
//#else
|
||||
//$$ @SubscribeEvent
|
||||
//$$ public void onInit(GuiScreenEvent.InitGuiEvent.Post event) {
|
||||
//$$ Screen guiScreen = getGui(event);
|
||||
//$$ List<Widget> buttonList = getButtonList(event);
|
||||
//#endif
|
||||
if (guiScreen instanceof TitleScreen) {
|
||||
TitleScreen gui = (TitleScreen) guiScreen;
|
||||
int realmsOffset = 0;
|
||||
//#if MC>=11400
|
||||
final String BUTTON_REALMS = I18n.translate("menu.online");
|
||||
for (AbstractButtonWidget button : buttonList) {
|
||||
//#else
|
||||
//$$ for (GuiButton button : buttonList) {
|
||||
//#endif
|
||||
// Buttons that aren't in a rectangle directly above our space don't need moving
|
||||
if (button.x + width(button) < gui.width / 2 - 100
|
||||
|| button.x > gui.width / 2 + 100
|
||||
|| button.y > gui.height / 4 + 10 + 4 * 24 + 20) continue;
|
||||
// Move button up to make space for one rows of buttons
|
||||
// and then move back down by 10 to compensate for the space to the exit button that was already there
|
||||
int offset = -1 * 24 + 10;
|
||||
button.y += offset;
|
||||
|
||||
//#if MC>=11400
|
||||
//#if MC>=11400
|
||||
if (BUTTON_REALMS.equals(button.getMessage())) {
|
||||
//#else
|
||||
//$$ if (button.id == 14) {
|
||||
//#endif
|
||||
realmsOffset = offset;
|
||||
}
|
||||
//#endif
|
||||
}
|
||||
//#if MC>=11400 && MC<11600
|
||||
//$$ GuiMainMenuAccessor guiA = (GuiMainMenuAccessor) gui;
|
||||
//$$ if (realmsOffset != 0 && guiA.getRealmsNotification() instanceof RealmsScreenProxy) {
|
||||
//$$ guiA.setRealmsNotification(new RealmsNotificationProxy((RealmsScreenProxy) guiA.getRealmsNotification(), realmsOffset));
|
||||
//$$ }
|
||||
//#endif
|
||||
}
|
||||
}
|
||||
|
||||
//#if MC>=11400 && MC<11600
|
||||
//$$ private static class RealmsNotificationProxy extends Screen {
|
||||
//$$ private final RealmsScreenProxy proxy;
|
||||
//$$ private final int offset;
|
||||
//$$
|
||||
//$$ private RealmsNotificationProxy(RealmsScreenProxy proxy, int offset) {
|
||||
//#if MC>=11400
|
||||
//$$ super(null);
|
||||
//#endif
|
||||
//$$ this.proxy = proxy;
|
||||
//$$ this.offset = offset;
|
||||
//$$ }
|
||||
//$$
|
||||
//$$ @Override
|
||||
//$$ public void init(MinecraftClient mc, int width, int height) {
|
||||
//$$ proxy.init(mc, width, height);
|
||||
//$$ }
|
||||
//$$
|
||||
//$$ @Override
|
||||
//$$ public void tick() {
|
||||
//$$ proxy.tick();
|
||||
//$$ }
|
||||
//$$
|
||||
//$$ @Override
|
||||
//$$ public void render(int mouseX, int mouseY, float partialTicks) {
|
||||
//$$ GL11.glTranslated(0, offset, 0);
|
||||
//$$ proxy.render(mouseX, mouseY - offset, partialTicks);
|
||||
//$$ GL11.glTranslated(0, -offset, 0);
|
||||
//$$ }
|
||||
//$$
|
||||
//$$ @Override
|
||||
//$$ public boolean mouseClicked(double mouseX, double mouseY, int mouseButton) {
|
||||
//$$ return proxy.mouseClicked(mouseX, mouseY - offset, mouseButton);
|
||||
//$$ }
|
||||
//$$
|
||||
//$$ @Override
|
||||
//$$ public void removed() {
|
||||
//$$ proxy.removed();
|
||||
//$$ }
|
||||
//$$ }
|
||||
//#endif
|
||||
}
|
||||
@@ -38,7 +38,6 @@ import java.util.ArrayList;
|
||||
//#if MC>=11400
|
||||
import com.replaymod.core.mixin.AbstractButtonWidgetAccessor;
|
||||
import net.minecraft.SharedConstants;
|
||||
import net.minecraft.client.gui.screen.TitleScreen;
|
||||
import net.minecraft.client.gui.widget.ButtonWidget;
|
||||
import net.minecraft.client.gui.widget.AbstractButtonWidget;
|
||||
|
||||
@@ -598,13 +597,6 @@ public class MCVer {
|
||||
//#endif
|
||||
) {
|
||||
GuiScreenAccessor acc = (GuiScreenAccessor) screen;
|
||||
//#if MC>=11400
|
||||
if (screen instanceof TitleScreen && isModLoaded("modmenu")) {
|
||||
// Since we bypass the usual addButton, we need to manually move our buttons down
|
||||
// https://github.com/Prospector/ModMenu/blob/eea70ec37581a7229142cf21df795fdacc6a7b4c/src/main/java/io/github/prospector/modmenu/mixin/TitleScreenMixin.java#L42
|
||||
button.y += 12;
|
||||
}
|
||||
//#endif
|
||||
acc.getButtons().add(button);
|
||||
//#if MC>=11400
|
||||
acc.getChildren().add(button);
|
||||
|
||||
Reference in New Issue
Block a user