mirror of
https://github.com/KAMKEEL/CustomNPC-Plus.git
synced 2026-11-17 23:55:10 +00:00
Fix mouse wheel scrolling in the script editors
Mouse.getDWheel() clears the accumulated delta, so whichever widget polled it first in a frame took it and every later reader saw zero. The script text areas polled it themselves, after the parent screen had already drained it for its scroll lists, so the wheel did nothing in the player, NPC and event script GUIs. The screen now reads the wheel once per frame into the mouseScroll field it already declared for this, and each widget zeroes it when it consumes it.
This commit is contained in:
1 parent
71bb4b451e
commit
a028142dda
3 files changed
+23
-6
No files matched your search
@@ -515,15 +515,28 @@ public abstract class GuiNPCInterface extends GuiScreen {
|
||||
}
|
||||
|
||||
boolean subGui = hasSubGui();
|
||||
|
||||
// Mouse.getDWheel() clears the accumulated delta, so only the first caller in a frame
|
||||
// ever sees it. Read it once here and let each widget take it in turn; anything that
|
||||
// consumes it zeroes it so later widgets - the script editor, for one - are not left
|
||||
// reading an already-drained wheel.
|
||||
mouseScroll = Mouse.getDWheel();
|
||||
|
||||
drawCenteredString(fontRendererObj, title, width / 2, guiTop + 4, 0xffffff);
|
||||
for (GuiNpcLabel label : labels.values())
|
||||
label.drawLabel(this, fontRendererObj);
|
||||
for (GuiCustomScroll scroll : scrolls.values()) {
|
||||
scroll.updateSubGUI(subGui);
|
||||
scroll.drawScreen(drawX, drawY, f, !subGui && scroll.isMouseOver(drawX, drawY) ? Mouse.getDWheel() : 0);
|
||||
int delta = !subGui && scroll.isMouseOver(drawX, drawY) ? mouseScroll : 0;
|
||||
if (delta != 0)
|
||||
mouseScroll = 0;
|
||||
scroll.drawScreen(drawX, drawY, f, delta);
|
||||
}
|
||||
for (GuiScrollWindow guiScrollableComponent : scrollWindows.values()) {
|
||||
guiScrollableComponent.drawScreen(drawX, drawY, f, !subGui && guiScrollableComponent.isMouseOver(drawX, drawY) ? Mouse.getDWheel() : 0);
|
||||
int delta = !subGui && guiScrollableComponent.isMouseOver(drawX, drawY) ? mouseScroll : 0;
|
||||
if (delta != 0)
|
||||
mouseScroll = 0;
|
||||
guiScrollableComponent.drawScreen(drawX, drawY, f, delta);
|
||||
}
|
||||
for (GuiDiagram diagram : diagrams.values()) {
|
||||
diagram.drawDiagram(drawX, drawY, subGui);
|
||||
|
||||
@@ -624,9 +624,11 @@ public class GuiScriptTextArea extends GuiNpcTextField {
|
||||
int maxScroll = Math.max(0, getPaddedLineCount() - container.visibleLines);
|
||||
|
||||
// Handle mouse wheel scroll
|
||||
int wheelDelta = ((GuiNPCInterface) listener).mouseScroll = Mouse.getDWheel();
|
||||
// Take whatever the parent screen has left for this frame rather than polling the wheel
|
||||
// again - the poll is destructive and the parent has already drained it.
|
||||
int wheelDelta = listener instanceof GuiNPCInterface ? ((GuiNPCInterface) listener).mouseScroll : Mouse.getDWheel();
|
||||
if (listener instanceof GuiNPCInterface) {
|
||||
((GuiNPCInterface) listener).mouseScroll = wheelDelta;
|
||||
((GuiNPCInterface) listener).mouseScroll = 0;
|
||||
|
||||
// Intercept wheel scroll for tooltip (highest priority)
|
||||
// Only consume the wheel event when the tooltip actually has content to scroll;
|
||||
|
||||
@@ -486,9 +486,11 @@ public class GuiScriptTextArea1 extends GuiNpcTextField {
|
||||
int maxScroll = Math.max(0, getPaddedLineCount() - container.visibleLines);
|
||||
|
||||
// Handle mouse wheel scroll
|
||||
int wheelDelta = ((GuiNPCInterface) listener).mouseScroll = Mouse.getDWheel();
|
||||
// Take whatever the parent screen has left for this frame rather than polling the wheel
|
||||
// again - the poll is destructive and the parent has already drained it.
|
||||
int wheelDelta = listener instanceof GuiNPCInterface ? ((GuiNPCInterface) listener).mouseScroll : Mouse.getDWheel();
|
||||
if (listener instanceof GuiNPCInterface) {
|
||||
((GuiNPCInterface) listener).mouseScroll = wheelDelta;
|
||||
((GuiNPCInterface) listener).mouseScroll = 0;
|
||||
boolean canScroll = !KEYS_OVERLAY.isVisible() || KEYS_OVERLAY.isVisible() && !KEYS_OVERLAY.aboveOverlay;
|
||||
if (wheelDelta != 0 && canScroll)
|
||||
scroll.applyWheelScroll(wheelDelta, maxScroll);
|
||||
|
||||
Reference in new issue
Block a user