aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/io
diff options
context:
space:
mode:
authorJuuxel <kasperi.kauppi@gmail.com>2019-07-27 22:18:22 +0300
committerJuuxel <kasperi.kauppi@gmail.com>2019-07-27 22:18:22 +0300
commitf0c8020eaab7fbb8839365fc7e579985d442c0db (patch)
tree1bad6c08312e72217375d2e278434d8cf967cec2 /src/main/java/io
parent2fea106344bb346011c425b5416a738045ca3400 (diff)
downloadLibGui-f0c8020eaab7fbb8839365fc7e579985d442c0db.tar.gz
LibGui-f0c8020eaab7fbb8839365fc7e579985d442c0db.tar.bz2
LibGui-f0c8020eaab7fbb8839365fc7e579985d442c0db.zip
Add support for disabling buttons
Diffstat (limited to 'src/main/java/io')
-rw-r--r--src/main/java/io/github/cottonmc/cotton/gui/widget/WButton.java27
1 files changed, 19 insertions, 8 deletions
diff --git a/src/main/java/io/github/cottonmc/cotton/gui/widget/WButton.java b/src/main/java/io/github/cottonmc/cotton/gui/widget/WButton.java
index bfae32f..532dffb 100644
--- a/src/main/java/io/github/cottonmc/cotton/gui/widget/WButton.java
+++ b/src/main/java/io/github/cottonmc/cotton/gui/widget/WButton.java
@@ -11,6 +11,7 @@ public class WButton extends WWidget {
private Text label;
protected int color = WLabel.DEFAULT_TEXT_COLOR;
protected int darkmodeColor = WLabel.DEFAULT_TEXT_COLOR;
+ private boolean active = true;
private Runnable onClick;
@@ -32,7 +33,8 @@ public class WButton extends WWidget {
public void paintForeground(int x, int y, int mouseX, int mouseY) {
boolean hovered = (mouseX>=x && mouseY>=y && mouseX<x+getWidth() && mouseY<y+getHeight());
int int_3 = 1; //1=regular. 2=hovered. 0=disabled.
- if (hovered) int_3 = 2;
+ if (!active) int_3 = 0;
+ else if (hovered) int_3 = 2;
float px = 1/256f;
float buttonLeft = 0 * px;
@@ -48,12 +50,11 @@ public class WButton extends WWidget {
ScreenDrawing.rect(AbstractButtonWidget.WIDGETS_LOCATION, x+(getWidth()/2), y, getWidth()/2, 20, buttonEndLeft, buttonTop, 200*px, buttonTop+buttonHeight, 0xFFFFFFFF);
if (label!=null) {
- boolean active = true;
- int color = 14737632;
+ int color = 0xE0E0E0;
if (!active) {
- color = 10526880;
+ color = 0xA0A0A0;
} else if (hovered) {
- color = 16777120;
+ color = 0xFFFFA0;
}
ScreenDrawing.drawCenteredWithShadow(label.asFormattedString(), x+(getWidth()/2), y + ((20 - 8) / 2), color); //LibGuiClient.config.darkMode ? darkmodeColor : color);
@@ -68,12 +69,22 @@ public class WButton extends WWidget {
public void onClick(int x, int y, int button) {
super.onClick(x, y, button);
- MinecraftClient.getInstance().getSoundManager().play(PositionedSoundInstance.master(SoundEvents.UI_BUTTON_CLICK, 1.0F));
-
- if (onClick!=null) onClick.run();
+ if (active) {
+ MinecraftClient.getInstance().getSoundManager().play(PositionedSoundInstance.master(SoundEvents.UI_BUTTON_CLICK, 1.0F));
+
+ if (onClick!=null) onClick.run();
+ }
}
public void setOnClick(Runnable r) {
this.onClick = r;
}
+
+ public boolean isActive() {
+ return active;
+ }
+
+ public void setActive(boolean active) {
+ this.active = active;
+ }
}