mirror of
https://github.com/KAMKEEL/CustomNPC-Plus.git
synced 2026-11-17 12:15:11 +00:00
Only Scroll when Hovered above specified area
This commit is contained in:
1 parent
62bca2ca0a
commit
84991d93ce
2 files changed
+17
-3
No files matched your search
@@ -236,8 +236,10 @@ public class GuiQuestLog extends GuiCNPCInventory implements ITopButtonListener,
|
||||
final float SMOOTHING_FACTOR = 0.1F; // Adjust this value for smoother or faster scrolling
|
||||
|
||||
int maxScroll = Math.max(0, this.sideButtons.size() - 9) * 22;
|
||||
this.destSideButtonScroll = ValueUtil.clamp(this.destSideButtonScroll - Math.signum(this.mouseWheel) * 22, -maxScroll, 0);
|
||||
|
||||
// Adjust scrolling only if the mouse is in the scroll zone
|
||||
if (isMouseInScrollZone(i, j)) {
|
||||
this.destSideButtonScroll = ValueUtil.clamp(this.destSideButtonScroll - Math.signum(this.mouseWheel) * 22, -maxScroll, 0);
|
||||
}
|
||||
// Apply smoothing to the scroll transition
|
||||
this.sideButtonScroll += (this.destSideButtonScroll - this.sideButtonScroll) * SMOOTHING_FACTOR;
|
||||
|
||||
@@ -418,4 +420,13 @@ public class GuiQuestLog extends GuiCNPCInventory implements ITopButtonListener,
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public boolean isMouseInScrollZone(int x, int y) {
|
||||
int scrollZoneLeft = guiLeft - 69; // Left boundary of the scroll zone
|
||||
int scrollZoneRight = guiLeft - 69 + 70; // Right boundary of the scroll zone
|
||||
int scrollZoneTop = guiTop + 2; // Top boundary of the scroll zone
|
||||
int scrollZoneBottom = guiTop + 2 + 8 * 21; // Bottom boundary of the scroll zone
|
||||
|
||||
return x >= scrollZoneLeft && x <= scrollZoneRight && y >= scrollZoneTop && y <= scrollZoneBottom;
|
||||
}
|
||||
}
|
||||
@@ -82,6 +82,7 @@ public class GuiCustomScroll extends GuiScreen
|
||||
public void drawScreen(int i, int j, float f, int mouseScrolled){
|
||||
if(!visible)
|
||||
return;
|
||||
|
||||
drawGradientRect(guiLeft, guiTop, xSize+guiLeft ,ySize+guiTop, 0xc0101010, 0xd0101010);
|
||||
GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
|
||||
mc.renderEngine.bindTexture(resource);
|
||||
@@ -96,6 +97,8 @@ public class GuiCustomScroll extends GuiScreen
|
||||
GL11.glTranslatef(guiLeft, guiTop, 0.0F);
|
||||
GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
|
||||
|
||||
boolean isMouseOverComponent = isMouseOver(i, j);
|
||||
|
||||
if(selectable)
|
||||
hover = getMouseOver(i,j);
|
||||
|
||||
@@ -140,7 +143,7 @@ public class GuiCustomScroll extends GuiScreen
|
||||
}
|
||||
}
|
||||
|
||||
if(mouseScrolled != 0){
|
||||
if(mouseScrolled != 0 && isMouseOverComponent){
|
||||
scrollY += mouseScrolled > 0?-14:14;
|
||||
if(scrollY > maxScrollY)
|
||||
scrollY = maxScrollY;
|
||||
|
||||
Reference in new issue
Block a user