Enable scrolling on Color and Cycle buttons

This commit is contained in:
Wilhelm Schuster committed 2023-06-07 18:06:17 +02:00
1 parent 03ed5ff83b
commit 397bbfc490
4 files changed
+56

No files matched your search

@@ -300,12 +300,25 @@ public abstract class GuiContainerBase extends GuiContainer
ghostSlotClicked(slot, x, y, delta < 0 ? -1 : -2);
}
}
for (Object obj : buttonList) {
if (obj instanceof IconButton) {
IconButton btn = (IconButton) obj;
if (btn.mouseScrolled(mc, x, y, delta)) {
btn.func_146113_a(this.mc.getSoundHandler());
actionPerformedWheel(btn, delta);
}
}
}
}
protected void actionPerformedButton(IconButton btn, int mouseButton) {
actionPerformed(btn);
}
protected void actionPerformedWheel(IconButton btn, int scrollDelta) {
actionPerformed(btn);
}
public void addOverlay(IGuiOverlay overlay) {
overlays.add(overlay);
}
@@ -38,6 +38,21 @@ public class ColorButton extends IconButton {
return result;
}
@Override
public boolean mouseScrolled(Minecraft mc, int x, int y, int scrollDelta) {
if (super.checkMousePress(mc, x, y)) {
if (scrollDelta > 0) {
nextColor();
} else if (scrollDelta < 0) {
prevColor();
} else {
return false;
}
return true;
}
return false;
}
public String getTooltipPrefix() {
return tooltipPrefix;
}
@@ -56,6 +56,21 @@ public class CycleButton<T extends Enum<T> & ICycleEnum> extends IconButton {
return result;
}
@Override
public boolean mouseScrolled(Minecraft mc, int x, int y, int scrollDelta) {
if (super.checkMousePress(mc, x, y)) {
if (scrollDelta > 0) {
nextMode();
} else if (scrollDelta < 0) {
prevMode();
} else {
return false;
}
return true;
}
return false;
}
private void nextMode() {
setMode(modes[(mode.ordinal() + 1) % modes.length]);
}
@@ -62,6 +62,19 @@ public class IconButton extends TooltipButton {
return super.mousePressed(mc, x, y);
}
/**
* Override this to handle scrolling when the mouse is hovering over the button
*
* @param mc The MC instance
* @param x X coordinate of mouse click
* @param y Y coordinate of mouse click
* @param scrollDelta the amount by which was scrolled
* @return true if the mouse scroll is handled
*/
public boolean mouseScrolled(Minecraft mc, int x, int y, int scrollDelta) {
return false;
}
/**
* Draws this button to the screen.
*/