|
| 1 | +package com.terraformersmc.modmenu.mixin; |
| 2 | + |
| 3 | +import com.terraformersmc.modmenu.api.ModMenuApi; |
| 4 | +import com.terraformersmc.modmenu.config.ModMenuConfig; |
| 5 | +import com.terraformersmc.modmenu.event.ModMenuEventHandler; |
| 6 | +import com.terraformersmc.modmenu.gui.ModsScreen; |
| 7 | +import com.terraformersmc.modmenu.gui.widget.ModMenuButtonWidget; |
| 8 | +import com.terraformersmc.modmenu.gui.widget.UpdateCheckerTexturedButtonWidget; |
| 9 | +import net.fabricmc.fabric.api.client.screen.v1.Screens; |
| 10 | +import org.spongepowered.asm.mixin.Mixin; |
| 11 | +import org.spongepowered.asm.mixin.gen.Accessor; |
| 12 | +import org.spongepowered.asm.mixin.injection.At; |
| 13 | +import org.spongepowered.asm.mixin.injection.Inject; |
| 14 | +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; |
| 15 | + |
| 16 | +import java.util.List; |
| 17 | + |
| 18 | +import net.minecraft.client.Minecraft; |
| 19 | +import net.minecraft.client.gui.components.AbstractWidget; |
| 20 | +import net.minecraft.client.gui.components.Tooltip; |
| 21 | +import net.minecraft.client.gui.layouts.LayoutElement; |
| 22 | +import net.minecraft.client.gui.screens.PauseScreen; |
| 23 | +import net.minecraft.client.gui.screens.Screen; |
| 24 | +import net.minecraft.network.chat.Component; |
| 25 | + |
| 26 | +@Mixin(PauseScreen.class) |
| 27 | +public abstract class MixinPauseScreen extends Screen { |
| 28 | + protected MixinPauseScreen(Component title) { |
| 29 | + super(title); |
| 30 | + } |
| 31 | + |
| 32 | + @Accessor |
| 33 | + private static Tooltip getCUSTOM_OPTIONS_TOOLTIP() { |
| 34 | + throw new AssertionError(); |
| 35 | + } |
| 36 | + |
| 37 | + @Inject(method = "createPauseMenu", at = @At("TAIL")) |
| 38 | + private void onCreatePauseMenu(CallbackInfo ci) { |
| 39 | + List<AbstractWidget> buttons = Screens.getButtons(this); |
| 40 | + |
| 41 | + if (ModMenuConfig.MODIFY_GAME_MENU.getValue()) { |
| 42 | + int modsButtonIndex = -1; |
| 43 | + final int spacing = 24; |
| 44 | + int buttonsY = this.height / 4 + 8; |
| 45 | + ModMenuConfig.GameMenuButtonStyle style = ModMenuConfig.GAME_MENU_BUTTON_STYLE.getValue(); |
| 46 | + int vanillaButtonsY = this.height / 4 + 72 - 16 + 1; |
| 47 | + final int fullWidthButton = 204; |
| 48 | + for (int i = 0; i < buttons.size(); i++) { |
| 49 | + LayoutElement widget = buttons.get(i); |
| 50 | + if (style == ModMenuConfig.GameMenuButtonStyle.INSERT) { |
| 51 | + if (!(widget instanceof AbstractWidget button) || button.visible) { |
| 52 | + ModMenuEventHandler.shiftButtons(widget, modsButtonIndex == -1 || ModMenuEventHandler.buttonHasText(widget, "menu.reportBugs", "menu.server_links") || ModMenuEventHandler.buttonHasTooltip(widget, getCUSTOM_OPTIONS_TOOLTIP()), spacing); |
| 53 | + if (modsButtonIndex == -1) { |
| 54 | + buttonsY = widget.getY(); |
| 55 | + } |
| 56 | + } |
| 57 | + } |
| 58 | + |
| 59 | + boolean isShortFeedback = ModMenuEventHandler.buttonHasText(widget, "menu.feedback"); |
| 60 | + boolean isLongFeedback = ModMenuEventHandler.buttonHasText(widget, "menu.sendFeedback"); |
| 61 | + if (isShortFeedback || isLongFeedback) { |
| 62 | + modsButtonIndex = i + 1; |
| 63 | + vanillaButtonsY = widget.getY(); |
| 64 | + if (style == ModMenuConfig.GameMenuButtonStyle.REPLACE) { |
| 65 | + buttons.set(i, new ModMenuButtonWidget( |
| 66 | + widget.getX(), |
| 67 | + widget.getY(), |
| 68 | + isShortFeedback ? widget.getWidth() : fullWidthButton, |
| 69 | + widget.getHeight(), |
| 70 | + ModMenuApi.createModsButtonText(), |
| 71 | + this |
| 72 | + )); |
| 73 | + buttons.stream() |
| 74 | + .filter(w -> ModMenuEventHandler.buttonHasText(w, "menu.reportBugs")) |
| 75 | + .forEach(w -> { |
| 76 | + if (w instanceof AbstractWidget cw) { |
| 77 | + cw.visible = false; |
| 78 | + cw.active = false; |
| 79 | + } |
| 80 | + }); |
| 81 | + } else { |
| 82 | + modsButtonIndex = i + 1; |
| 83 | + if (!(widget instanceof AbstractWidget button) || button.visible) { |
| 84 | + buttonsY = widget.getY(); |
| 85 | + } |
| 86 | + } |
| 87 | + } |
| 88 | + } |
| 89 | + |
| 90 | + if (modsButtonIndex != -1) { |
| 91 | + if (style == ModMenuConfig.GameMenuButtonStyle.INSERT) { |
| 92 | + buttons.add(modsButtonIndex, new ModMenuButtonWidget( |
| 93 | + this.width / 2 - 102, |
| 94 | + buttonsY + spacing, |
| 95 | + fullWidthButton, |
| 96 | + 20, |
| 97 | + ModMenuApi.createModsButtonText(), |
| 98 | + this |
| 99 | + )); |
| 100 | + } else if (style == ModMenuConfig.GameMenuButtonStyle.ICON) { |
| 101 | + buttons.add(modsButtonIndex, new UpdateCheckerTexturedButtonWidget( |
| 102 | + this.width / 2 + 4 + 100 + 2, |
| 103 | + vanillaButtonsY, |
| 104 | + 20, |
| 105 | + 20, |
| 106 | + 0, |
| 107 | + 0, |
| 108 | + 20, |
| 109 | + ModMenuEventHandler.MODS_BUTTON_TEXTURE, |
| 110 | + 32, |
| 111 | + 64, |
| 112 | + button -> Minecraft.getInstance().setScreen(new ModsScreen(this)), |
| 113 | + ModMenuApi.createModsButtonText() |
| 114 | + )); |
| 115 | + } |
| 116 | + } |
| 117 | + } |
| 118 | + } |
| 119 | +} |
0 commit comments