From 6e5e682e3a67f6cfb4dba5182ad30eb8f77d9f50 Mon Sep 17 00:00:00 2001 From: Nikita Savyolov Date: Tue, 12 Oct 2021 19:14:03 +0300 Subject: [PATCH] fix: more correct mouseReleased event WidgetTerminal still calls mouseReleased on every container click instead of terminal only (like Forge does) --- .../client/gui/ComputerScreenBase.java | 6 --- .../computercraft/client/gui/GuiComputer.java | 2 - .../client/gui/NoTermComputerScreen.java | 2 +- .../fabric/mixin/MixinHandledScreen.java | 38 +++++++++++++++++++ src/main/resources/computercraft.mixins.json | 3 +- 5 files changed, 41 insertions(+), 10 deletions(-) create mode 100644 src/main/java/dan200/computercraft/fabric/mixin/MixinHandledScreen.java diff --git a/src/main/java/dan200/computercraft/client/gui/ComputerScreenBase.java b/src/main/java/dan200/computercraft/client/gui/ComputerScreenBase.java index 6ff56841..1373bbc6 100644 --- a/src/main/java/dan200/computercraft/client/gui/ComputerScreenBase.java +++ b/src/main/java/dan200/computercraft/client/gui/ComputerScreenBase.java @@ -108,12 +108,6 @@ public final boolean mouseDragged( double x, double y, int button, double deltaX return getFocused() != null && getFocused().mouseDragged( x, y, button, deltaX, deltaY ) || super.mouseDragged( x, y, button, deltaX, deltaY ); } - @Override - public boolean mouseReleased( double mouseX, double mouseY, int button ) - { - return (getFocused() != null && getFocused().mouseReleased( mouseX, mouseY, button )) || super.mouseReleased( x, y, button ); - } - @Override protected void drawForeground( @Nonnull MatrixStack transform, int mouseX, int mouseY ) { diff --git a/src/main/java/dan200/computercraft/client/gui/GuiComputer.java b/src/main/java/dan200/computercraft/client/gui/GuiComputer.java index 5160b806..8d3eba87 100644 --- a/src/main/java/dan200/computercraft/client/gui/GuiComputer.java +++ b/src/main/java/dan200/computercraft/client/gui/GuiComputer.java @@ -11,10 +11,8 @@ import dan200.computercraft.client.gui.widgets.WidgetTerminal; import dan200.computercraft.client.render.ComputerBorderRenderer; import dan200.computercraft.client.render.RenderTypes; -//import dan200.computercraft.shared.computer.inventory.ContainerComputer; import dan200.computercraft.shared.computer.inventory.ContainerComputerBase; import dan200.computercraft.shared.computer.inventory.ContainerViewComputer; -//import dan200.computercraft.shared.pocket.inventory.ContainerPocketComputer; import net.minecraft.client.util.math.MatrixStack; import net.minecraft.entity.player.PlayerInventory; import net.minecraft.text.Text; diff --git a/src/main/java/dan200/computercraft/client/gui/NoTermComputerScreen.java b/src/main/java/dan200/computercraft/client/gui/NoTermComputerScreen.java index 9c03f5f6..5ea1642a 100644 --- a/src/main/java/dan200/computercraft/client/gui/NoTermComputerScreen.java +++ b/src/main/java/dan200/computercraft/client/gui/NoTermComputerScreen.java @@ -49,7 +49,7 @@ protected void init() super.init(); client.keyboard.setRepeatEvents( true ); - terminal = addDrawableChild( new WidgetTerminal( (ClientComputer) menu.getComputer(), 0, 0, ComputerCraft.pocketTermWidth, ComputerCraft.pocketTermHeight ) ); + terminal = addSelectableChild( new WidgetTerminal( (ClientComputer) menu.getComputer(), 0, 0, ComputerCraft.pocketTermWidth, ComputerCraft.pocketTermHeight ) ); terminal.visible = false; terminal.active = false; setFocused( terminal ); diff --git a/src/main/java/dan200/computercraft/fabric/mixin/MixinHandledScreen.java b/src/main/java/dan200/computercraft/fabric/mixin/MixinHandledScreen.java new file mode 100644 index 00000000..34eca48c --- /dev/null +++ b/src/main/java/dan200/computercraft/fabric/mixin/MixinHandledScreen.java @@ -0,0 +1,38 @@ +/* + * This file is part of ComputerCraft - http://www.computercraft.info + * Copyright Daniel Ratcliffe, 2011-2021. Do not distribute without permission. + * Send enquiries to dratcliffe@gmail.com + */ +package dan200.computercraft.fabric.mixin; + +import dan200.computercraft.client.gui.widgets.WidgetTerminal; +import net.minecraft.client.gui.Element; +import net.minecraft.client.gui.screen.Screen; +import net.minecraft.client.gui.screen.ingame.HandledScreen; +import net.minecraft.screen.ScreenHandler; +import net.minecraft.text.Text; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; + +@Mixin( HandledScreen.class ) +public class MixinHandledScreen extends Screen +{ + protected MixinHandledScreen( Text title ) + { + super( title ); + } + + @Inject( method = "mouseReleased", at = @At ( "HEAD" ) ) + public void mouseReleased( double mouseX, double mouseY, int button, CallbackInfoReturnable cir ) + { + for ( Element child : this.children() ) + { + if ( child instanceof WidgetTerminal ) + { + child.mouseReleased( mouseX, mouseY, button ); + } + } + } +} diff --git a/src/main/resources/computercraft.mixins.json b/src/main/resources/computercraft.mixins.json index 482f7cd9..be224c3c 100644 --- a/src/main/resources/computercraft.mixins.json +++ b/src/main/resources/computercraft.mixins.json @@ -21,7 +21,8 @@ "MixinMinecraftClient", "MixinScreen", "MixinGameRenderer", - "MixinWorldRenderer" + "MixinWorldRenderer", + "MixinHandledScreen" ], "server": [ "MixinLanguage"