|
19 | 19 | import com.llamalad7.mixinextras.injector.wrapoperation.Operation; |
20 | 20 | import com.llamalad7.mixinextras.injector.wrapoperation.WrapOperation; |
21 | 21 | import dev.terminalmc.signtweaks.SignTweaks; |
| 22 | +import dev.terminalmc.signtweaks.gui.widget.UnfocusingButton; |
22 | 23 | import dev.terminalmc.signtweaks.util.inject.ISignScreen; |
| 24 | +import net.minecraft.ChatFormatting; |
23 | 25 | import net.minecraft.client.gui.components.Button; |
24 | | -import net.minecraft.client.gui.components.CycleButton; |
| 26 | +import net.minecraft.client.gui.components.Tooltip; |
25 | 27 | import net.minecraft.client.gui.components.events.GuiEventListener; |
26 | 28 | import net.minecraft.client.gui.screens.Screen; |
27 | 29 | import net.minecraft.client.gui.screens.inventory.AbstractSignEditScreen; |
28 | 30 | import net.minecraft.network.chat.Component; |
29 | 31 | import net.minecraft.world.level.block.entity.SignBlockEntity; |
30 | | -import org.jetbrains.annotations.NotNull; |
31 | 32 | import org.spongepowered.asm.mixin.Final; |
32 | 33 | import org.spongepowered.asm.mixin.Mixin; |
33 | 34 | import org.spongepowered.asm.mixin.Shadow; |
@@ -55,6 +56,9 @@ protected AbstractSignEditScreenMixin(Component title) { |
55 | 56 | @Shadow |
56 | 57 | public abstract void onClose(); |
57 | 58 |
|
| 59 | + @Unique |
| 60 | + private boolean signTweaks$isReloading; |
| 61 | + |
58 | 62 | /** |
59 | 63 | * On creation of an {@link AbstractSignEditScreen}, resets the value of |
60 | 64 | * {@link SignTweaks#enhancedEditing} to the default value and stores the original sign text. |
@@ -96,8 +100,6 @@ private GuiEventListener wrapAddDoneButton( |
96 | 100 | int rowCount = 0; |
97 | 101 | if (options().showActionButtons) |
98 | 102 | rowCount++; |
99 | | - if (options().showEditorToggleButton) |
100 | | - rowCount++; |
101 | 103 |
|
102 | 104 | int totalWidth = 200; |
103 | 105 | int buttonHeight = 20; |
@@ -154,31 +156,45 @@ private GuiEventListener wrapAddDoneButton( |
154 | 156 | .bounds(movingX, movingY, buttonWidth, buttonHeight) |
155 | 157 | .build(); |
156 | 158 | original.call(instance, revertButton); |
157 | | - |
158 | | - movingY += rowHeight; |
159 | 159 | } |
160 | 160 |
|
161 | | - // Enhanced editor toggle button |
| 161 | + // Add the 'Done' button last. |
162 | 162 | if (options().showEditorToggleButton) { |
163 | | - CycleButton<@NotNull Boolean> statusButton = CycleButton |
164 | | - .onOffBuilder(SignTweaks.enhancedEditing) |
165 | | - .create( |
166 | | - baseX, |
167 | | - movingY, |
168 | | - totalWidth, |
169 | | - buttonHeight, |
170 | | - localized("button", "enhancedEditing"), |
171 | | - (button, status) -> { |
172 | | - if (SignTweaks.enhancedEditing != status) { |
173 | | - SignTweaks.enhancedEditing = status; |
174 | | - init(); |
175 | | - } |
176 | | - } |
177 | | - ); |
178 | | - original.call(instance, statusButton); |
179 | | - } |
| 163 | + if (doneButton instanceof Button button) { |
| 164 | + // reduce width to add space for editor toggle button |
| 165 | + button.setWidth(button.getWidth() - spaceX - buttonHeight); |
| 166 | + GuiEventListener result = original.call(instance, button); |
180 | 167 |
|
181 | | - // Add the 'Done' button last. |
| 168 | + // add editor toggle button |
| 169 | + UnfocusingButton toggleButton = new UnfocusingButton( |
| 170 | + button.getX() + button.getWidth() + spaceX, |
| 171 | + button.getY(), |
| 172 | + buttonHeight, // square |
| 173 | + buttonHeight, |
| 174 | + Component.literal("\u270E").withStyle(SignTweaks.enhancedEditing // ✎ |
| 175 | + ? ChatFormatting.GREEN |
| 176 | + : ChatFormatting.RED), |
| 177 | + (b) -> { |
| 178 | + SignTweaks.enhancedEditing = !SignTweaks.enhancedEditing; |
| 179 | + init(); |
| 180 | + } |
| 181 | + ); |
| 182 | + toggleButton.setTooltip(Tooltip.create(localized( |
| 183 | + "button", |
| 184 | + "enhancedEditing.tooltip." + (SignTweaks.enhancedEditing |
| 185 | + ? "enabled" |
| 186 | + : "disabled") |
| 187 | + ))); |
| 188 | + original.call(instance, toggleButton); |
| 189 | + return result; |
| 190 | + } else { |
| 191 | + SignTweaks.LOG.error( |
| 192 | + "Done button has wrong type! Expected '{}', got '{}'", |
| 193 | + Button.class, |
| 194 | + doneButton.getClass() |
| 195 | + ); |
| 196 | + } |
| 197 | + } |
182 | 198 | return original.call(instance, doneButton); |
183 | 199 | } |
184 | 200 |
|
|
0 commit comments