Skip to content

Commit 5ad9d25

Browse files
authored
Allow setting click sound for ButtonWidget (#115)
1 parent a7779c1 commit 5ad9d25

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

src/main/java/com/cleanroommc/modularui/widgets/ButtonWidget.java

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ public static ButtonWidget<?> panelCloseButton() {
2828
}
2929

3030
private boolean playClickSound = true;
31+
private Runnable clickSound;
3132
private IGuiAction.MousePressed mousePressed;
3233
private IGuiAction.MouseReleased mouseReleased;
3334
private IGuiAction.MousePressed mouseTapped;
@@ -51,7 +52,11 @@ public WidgetTheme getWidgetThemeInternal(ITheme theme) {
5152

5253
public void playClickSound() {
5354
if (this.playClickSound) {
54-
Interactable.playButtonClickSound();
55+
if (this.clickSound != null) {
56+
this.clickSound.run();
57+
} else {
58+
Interactable.playButtonClickSound();
59+
}
5560
}
5661
}
5762

@@ -168,4 +173,9 @@ public W playClickSound(boolean play) {
168173
this.playClickSound = play;
169174
return getThis();
170175
}
176+
177+
public W clickSound(Runnable clickSound) {
178+
this.clickSound = clickSound;
179+
return getThis();
180+
}
171181
}

0 commit comments

Comments
 (0)