diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/main/java/com/aizistral/nochatreports/gui/EncryptionButton.java | 46 | ||||
| -rw-r--r-- | src/main/java/com/aizistral/nochatreports/mixins/client/MixinChatScreen.java | 34 |
2 files changed, 51 insertions, 29 deletions
diff --git a/src/main/java/com/aizistral/nochatreports/gui/EncryptionButton.java b/src/main/java/com/aizistral/nochatreports/gui/EncryptionButton.java new file mode 100644 index 0000000..5620a6b --- /dev/null +++ b/src/main/java/com/aizistral/nochatreports/gui/EncryptionButton.java @@ -0,0 +1,46 @@ +package com.aizistral.nochatreports.gui; + +import com.aizistral.nochatreports.config.NCRConfig; +import com.aizistral.nochatreports.mixins.client.MixinChatScreen; + +import net.minecraft.client.Minecraft; +import net.minecraft.client.gui.components.ImageButton; +import net.minecraft.client.gui.screens.Screen; +import net.minecraft.network.chat.Component; +import net.minecraft.resources.ResourceLocation; + +public class EncryptionButton extends ImageButton { + private final Screen parent; + + public EncryptionButton(int x, int y, int xSize, int ySize, int xTexStart, int yTexStart, int yStateDiff, + ResourceLocation texture, int textureWidth, int textureHeight, OnPress onPress, OnTooltip onTooltip, + Component name, Screen parent) { + super(x, y, xSize, ySize, xTexStart, yTexStart, yStateDiff, texture, textureWidth, textureHeight, onPress, + onTooltip, name); + this.parent = parent; + } + + @Override + public boolean mouseClicked(double x, double y, int i) { + if (!this.active || !this.visible) + return false; + + if (i == 1 && this.clicked(x, y)) { + this.playDownSound(Minecraft.getInstance().getSoundManager()); + this.openEncryptionConfig(); + return true; + } + + return super.mouseClicked(x, y, i); + } + + public void openEncryptionConfig() { + if (!EncryptionWarningScreen.seenOnThisSession() && !NCRConfig.getEncryption().isWarningDisabled() + && !NCRConfig.getEncryption().isEnabledAndValid()) { + Minecraft.getInstance().setScreen(new EncryptionWarningScreen(this.parent)); + } else { + Minecraft.getInstance().setScreen(new EncryptionConfigScreen(this.parent)); + } + } + +} diff --git a/src/main/java/com/aizistral/nochatreports/mixins/client/MixinChatScreen.java b/src/main/java/com/aizistral/nochatreports/mixins/client/MixinChatScreen.java index ac3acb4..eec5072 100644 --- a/src/main/java/com/aizistral/nochatreports/mixins/client/MixinChatScreen.java +++ b/src/main/java/com/aizistral/nochatreports/mixins/client/MixinChatScreen.java @@ -13,6 +13,7 @@ import com.aizistral.nochatreports.config.NCRConfig; import com.aizistral.nochatreports.config.NCRConfigClient; import com.aizistral.nochatreports.core.ServerSafetyLevel; import com.aizistral.nochatreports.core.ServerSafetyState; +import com.aizistral.nochatreports.gui.EncryptionButton; import com.aizistral.nochatreports.gui.EncryptionConfigScreen; import com.aizistral.nochatreports.gui.EncryptionWarningScreen; import com.mojang.blaze3d.systems.RenderSystem; @@ -89,16 +90,16 @@ public abstract class MixinChatScreen extends Screen { int xStart = !NCRConfig.getEncryption().isValid() ? 40 : (NCRConfig.getEncryption().isEnabled() ? 0 : 20); - var button = new ImageButton(this.width - 48, this.height - 37, 20, 20, xStart, + var button = new EncryptionButton(this.width - 48, this.height - 37, 20, 20, xStart, 0, 20, ENCRYPTION_BUTTON, 64, 64, btn -> { if (!EncryptionWarningScreen.seenOnThisSession() && !NCRConfig.getEncryption().isWarningDisabled() && !NCRConfig.getEncryption().isEnabled()) { Minecraft.getInstance().setScreen(new EncryptionWarningScreen(this)); } else if (NCRConfig.getEncryption().isValid()) { NCRConfig.getEncryption().toggleEncryption(); - ((ImageButton)btn).xTexStart = NCRConfig.getEncryption().isEnabledAndValid() ? 0 : 20; + ((EncryptionButton)btn).xTexStart = NCRConfig.getEncryption().isEnabledAndValid() ? 0 : 20; } else { - MixinChatScreen.this.openEncryptionConfig(); + ((EncryptionButton)btn).openEncryptionConfig(); } }, (btn, poseStack, i, j) -> { if (NCRConfig.getEncryption().isValid()) { @@ -113,38 +114,13 @@ public abstract class MixinChatScreen extends Screen { .isEnabledAndValid() ? "on" : "off")), 250), 250), i, j); } - }, Component.empty()) { - - @Override - public boolean mouseClicked(double x, double y, int i) { - if (!this.active || !this.visible) - return false; - - if (i == 1 && this.clicked(x, y)) { - this.playDownSound(Minecraft.getInstance().getSoundManager()); - MixinChatScreen.this.openEncryptionConfig(); - return true; - } - - return super.mouseClicked(x, y, i); - } - - }; + }, Component.empty(), this); button.active = true; button.visible = true; this.addRenderableWidget(button); } - private void openEncryptionConfig() { - if (!EncryptionWarningScreen.seenOnThisSession() && !NCRConfig.getEncryption().isWarningDisabled() - && !NCRConfig.getEncryption().isEnabledAndValid()) { - Minecraft.getInstance().setScreen(new EncryptionWarningScreen(this)); - } else { - Minecraft.getInstance().setScreen(new EncryptionConfigScreen(this)); - } - } - private int getXOffset(ServerSafetyLevel level) { return switch (level) { case SECURE -> 21; |
