From baaee4f255ba339956f774b77727e34454660636 Mon Sep 17 00:00:00 2001 From: Aizistral Date: Sun, 4 Dec 2022 11:45:48 +0100 Subject: Fix duplicate tooltip on OSSC option Fixes #302 --- .../mixins/client/MixinChatOptionsScreen.java | 55 +++++----------------- .../nochatreports/mixins/client/MixinOptions.java | 10 ++-- 2 files changed, 19 insertions(+), 46 deletions(-) (limited to 'src') diff --git a/src/main/java/com/aizistral/nochatreports/mixins/client/MixinChatOptionsScreen.java b/src/main/java/com/aizistral/nochatreports/mixins/client/MixinChatOptionsScreen.java index 997f916..9fff6d9 100644 --- a/src/main/java/com/aizistral/nochatreports/mixins/client/MixinChatOptionsScreen.java +++ b/src/main/java/com/aizistral/nochatreports/mixins/client/MixinChatOptionsScreen.java @@ -1,6 +1,7 @@ package com.aizistral.nochatreports.mixins.client; import java.util.List; +import java.util.Optional; import org.jetbrains.annotations.NotNull; import org.spongepowered.asm.mixin.Mixin; @@ -18,59 +19,29 @@ import net.minecraft.client.gui.screens.SimpleOptionsSubScreen; import net.minecraft.network.chat.Component; import net.minecraft.util.FormattedCharSequence; +/** + * Mixin responsible for graying out "Only Show Secure Chat" option. + * + * @author Kevinthegreat (original implementation) + * @author Aizistral (current version) + */ + @Mixin(ChatOptionsScreen.class) public class MixinChatOptionsScreen extends SimpleOptionsSubScreen { - private AbstractWidget onlyShowSecureChat; - - /** - * @implNote Using {@link net.minecraft.client.gui.Font#split} because - * {@link net.minecraft.client.OptionInstance#splitTooltip(Minecraft, Component)} is protected. - * Field {@link net.minecraft.client.gui.screens.Screen#minecraft} is not used because it can be null. - * @author Kevinthegreat - */ - @SuppressWarnings({"JavaDoc", "JavadocReference"}) - private List secureChatTooltip; - public MixinChatOptionsScreen(Screen screen, Options options, Component component, OptionInstance[] optionInstances) { + public MixinChatOptionsScreen(Screen screen, Options options, Component component, OptionInstance... optionInstances) { super(screen, options, component, optionInstances); throw new IllegalStateException("Can't touch this"); } - /** - * Gray out the only show secure chat option by deactivating the button when the screen is initialized. - * @author Kevinthegreat - */ - @Override protected void init() { super.init(); - if (!NCRConfig.getClient().enableMod()) - return; - - this.secureChatTooltip = Minecraft.getInstance().font.split(Component.translatable("gui.nochatreports.secure_chat"), 200); - this.onlyShowSecureChat = this.list.findOption(Minecraft.getInstance().options.onlyShowSecureChat()); - - if (this.onlyShowSecureChat != null) { - this.onlyShowSecureChat.active = false; + if (NCRConfig.getClient().enableMod()) { + Optional.ofNullable(this.list.findOption(Minecraft.getInstance().options.onlyShowSecureChat())) + .ifPresent(option -> option.active = false); } } - /** - * Render the tooltip on mouseover for only show secure chat option. - * Minecraft only render tooltips when the widget is active. - * @author Kevinthegreat - */ - - @Override - public void render(@NotNull PoseStack poseStack, int x, int y, float f) { - super.render(poseStack, x, y, f); - - if (!NCRConfig.getClient().enableMod()) - return; - - if (this.onlyShowSecureChat != null && this.onlyShowSecureChat.visible && x >= (double) this.onlyShowSecureChat.getX() && y >= (double) this.onlyShowSecureChat.getY() && x < (double) (this.onlyShowSecureChat.getX() + this.onlyShowSecureChat.getWidth()) && y < (double) (this.onlyShowSecureChat.getY() + this.onlyShowSecureChat.getHeight())) { - this.renderTooltip(poseStack, this.secureChatTooltip, x, y); - } - } -} \ No newline at end of file +} diff --git a/src/main/java/com/aizistral/nochatreports/mixins/client/MixinOptions.java b/src/main/java/com/aizistral/nochatreports/mixins/client/MixinOptions.java index 579d3df..7064ed6 100644 --- a/src/main/java/com/aizistral/nochatreports/mixins/client/MixinOptions.java +++ b/src/main/java/com/aizistral/nochatreports/mixins/client/MixinOptions.java @@ -17,6 +17,7 @@ import net.minecraft.network.chat.Component; @Mixin(Options.class) public class MixinOptions { + private static final Component SECURE_CHAT_TOOLTIP = Component.translatable("gui.nochatreports.secure_chat"); private OptionInstance alternativeOption; /** @@ -31,12 +32,13 @@ public class MixinOptions { if (this.alternativeOption == null) { this.alternativeOption = new OptionInstance<>("options.onlyShowSecureChat", - OptionInstance.cachedConstantTooltip(Component.translatable("gui.nochatreports.secure_chat")), - (component, value) -> value ? CommonComponents.OPTION_ON : CommonComponents.OPTION_OFF, - new OptionInstance.Enum<>(ImmutableList.of(Boolean.FALSE), Codec.BOOL), false, (value) -> {}); + OptionInstance.cachedConstantTooltip(SECURE_CHAT_TOOLTIP), + OptionInstance.BOOLEAN_TO_STRING, + new OptionInstance.Enum<>(ImmutableList.of(Boolean.FALSE), Codec.BOOL), + false, value -> {}); } cir.setReturnValue(this.alternativeOption); } -} \ No newline at end of file +} -- cgit v1.2.3