|
1 | 1 | package com.terraformersmc.modmenu.mixin; |
2 | 2 |
|
| 3 | +import com.llamalad7.mixinextras.expression.Definition; |
| 4 | +import com.llamalad7.mixinextras.expression.Expression; |
| 5 | +import com.llamalad7.mixinextras.sugar.Local; |
3 | 6 | import com.terraformersmc.modmenu.api.ModMenuApi; |
4 | 7 | import com.terraformersmc.modmenu.config.ModMenuConfig; |
5 | 8 | import com.terraformersmc.modmenu.event.ModMenuEventHandler; |
6 | 9 | import com.terraformersmc.modmenu.gui.ModsScreen; |
7 | 10 | import com.terraformersmc.modmenu.gui.widget.ModMenuButtonWidget; |
8 | 11 | 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 | 12 | 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; |
| 13 | +import net.minecraft.client.gui.layouts.GridLayout; |
| 14 | +import net.minecraft.client.gui.layouts.LinearLayout; |
22 | 15 | import net.minecraft.client.gui.screens.PauseScreen; |
23 | 16 | import net.minecraft.client.gui.screens.Screen; |
| 17 | +import net.minecraft.client.server.IntegratedServer; |
24 | 18 | import net.minecraft.network.chat.Component; |
| 19 | +import org.spongepowered.asm.mixin.Mixin; |
| 20 | +import org.spongepowered.asm.mixin.injection.At; |
| 21 | +import org.spongepowered.asm.mixin.injection.Inject; |
| 22 | +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; |
25 | 23 |
|
26 | 24 | @Mixin(PauseScreen.class) |
27 | 25 | public abstract class MixinPauseScreen extends Screen { |
28 | 26 | protected MixinPauseScreen(Component title) { |
29 | 27 | super(title); |
30 | 28 | } |
31 | 29 |
|
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.getWidgets(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 | | - } |
| 30 | + @Definition(id = "integratedServer", local = @Local(type = IntegratedServer.class, name = "integratedServer")) |
| 31 | + @Expression("integratedServer = ?") |
| 32 | + @Inject(method = "createPauseMenu", at = @At("MIXINEXTRAS:EXPRESSION")) |
| 33 | + private void insertModMenuIconButton(CallbackInfo ci, @Local(name = "iconButtonRow") LinearLayout iconButtonRow) { |
| 34 | + if (!ModMenuConfig.MODIFY_GAME_MENU.getValue()) return; |
| 35 | + ModMenuConfig.GameMenuButtonStyle style = ModMenuConfig.GAME_MENU_BUTTON_STYLE.getValue(); |
| 36 | + if (style == ModMenuConfig.GameMenuButtonStyle.ICON) { |
| 37 | + iconButtonRow.addChild(new UpdateCheckerTexturedButtonWidget( |
| 38 | + 0, |
| 39 | + 0, |
| 40 | + 20, |
| 41 | + 20, |
| 42 | + 0, |
| 43 | + 0, |
| 44 | + 20, |
| 45 | + ModMenuEventHandler.MODS_BUTTON_TEXTURE, |
| 46 | + 32, |
| 47 | + 64, |
| 48 | + _ -> Minecraft.getInstance().gui.setScreen(new ModsScreen(this)), |
| 49 | + ModMenuApi.createModsButtonText() |
| 50 | + )); |
| 51 | + } |
58 | 52 |
|
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 | | - } |
| 53 | + } |
89 | 54 |
|
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().gui.setScreen(new ModsScreen(this)), |
113 | | - ModMenuApi.createModsButtonText() |
114 | | - )); |
115 | | - } |
116 | | - } |
| 55 | + @Inject(method = "createPauseMenu", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/layouts/GridLayout$RowHelper;addChild(Lnet/minecraft/client/gui/layouts/LayoutElement;ILnet/minecraft/client/gui/layouts/LayoutSettings;)Lnet/minecraft/client/gui/layouts/LayoutElement;", ordinal = 1, shift = At.Shift.AFTER)) |
| 56 | + private void insertModMenuFullButton(CallbackInfo ci, @Local(name = "helper") GridLayout.RowHelper helper) { |
| 57 | + if (!ModMenuConfig.MODIFY_GAME_MENU.getValue()) return; |
| 58 | + ModMenuConfig.GameMenuButtonStyle style = ModMenuConfig.GAME_MENU_BUTTON_STYLE.getValue(); |
| 59 | + if (style == ModMenuConfig.GameMenuButtonStyle.INSERT) { |
| 60 | + final int fullWidthButton = 204; // PauseScreen.BUTTON_WIDTH_FULL |
| 61 | + helper.addChild(new ModMenuButtonWidget( |
| 62 | + 0, |
| 63 | + 0, |
| 64 | + fullWidthButton, |
| 65 | + 20, |
| 66 | + ModMenuApi.createModsButtonText(), |
| 67 | + this |
| 68 | + ), 2); |
117 | 69 | } |
118 | 70 | } |
119 | 71 | } |
0 commit comments