1
0
mirror of https://github.com/SquidDev-CC/CC-Tweaked synced 2025-02-03 20:59:12 +00:00

Fix mouse_drag not firing for right/middle buttons

This is a bit of an odd combination of a few bugs:
 - When the terminal component is blurred, we fire a mouse_up event for
   the last-held button. However, we had an off-by-1 error here, so this
   only triggered for the right/middle buttons.

 - This was obsucuring the second bug, which is when we clicked within
   the terminal, this caused the terminal to be blurred (thus releasing
   the mouse) and then focused again.

   We fix this by only setting the focus if there's actually a change.

Fixes #1655
This commit is contained in:
Jonathan Coates 2023-12-10 11:31:33 +00:00
parent 1f7d245876
commit 488f66eead
No known key found for this signature in database
GPG Key ID: B9E431FF07C98D06
2 changed files with 7 additions and 1 deletions

View File

@ -19,6 +19,7 @@ import dan200.computercraft.shared.network.server.UploadFileMessage;
import net.minecraft.ChatFormatting; import net.minecraft.ChatFormatting;
import net.minecraft.Util; import net.minecraft.Util;
import net.minecraft.client.gui.GuiGraphics; import net.minecraft.client.gui.GuiGraphics;
import net.minecraft.client.gui.components.events.GuiEventListener;
import net.minecraft.client.gui.screens.inventory.AbstractContainerScreen; import net.minecraft.client.gui.screens.inventory.AbstractContainerScreen;
import net.minecraft.network.chat.Component; import net.minecraft.network.chat.Component;
import net.minecraft.world.entity.player.Inventory; import net.minecraft.world.entity.player.Inventory;
@ -144,6 +145,11 @@ public abstract class AbstractComputerScreen<T extends AbstractComputerMenu> ext
|| super.mouseDragged(x, y, button, deltaX, deltaY); || super.mouseDragged(x, y, button, deltaX, deltaY);
} }
@Override
public void setFocused(@Nullable GuiEventListener listener) {
// Don't clear and re-focus if we're already focused.
if (listener != getFocused()) super.setFocused(listener);
}
@Override @Override
protected void renderLabels(GuiGraphics graphics, int mouseX, int mouseY) { protected void renderLabels(GuiGraphics graphics, int mouseX, int mouseY) {

View File

@ -246,7 +246,7 @@ public class TerminalWidget extends AbstractWidget {
keysDown.clear(); keysDown.clear();
// When blurring, we should make the last mouse button go up // When blurring, we should make the last mouse button go up
if (lastMouseButton > 0) { if (lastMouseButton >= 0) {
computer.mouseUp(lastMouseButton + 1, lastMouseX + 1, lastMouseY + 1); computer.mouseUp(lastMouseButton + 1, lastMouseX + 1, lastMouseY + 1);
lastMouseButton = -1; lastMouseButton = -1;
} }