diff options
author | Falkreon <falkreon@gmail.com> | 2019-07-28 01:31:28 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-07-28 01:31:28 -0500 |
commit | 1fa69a1b0effc9f692bc7dd71bcdcfd89b8f5d8d (patch) | |
tree | f3913856b3b5777847c855b67fb8a5f328caa9e5 /src/main/java | |
parent | 175e1fbb2782d44ad973686872db03471db4b693 (diff) | |
parent | c560951ff9a6e44c9f95c489180c8599eaf560b5 (diff) | |
download | LibGui-1fa69a1b0effc9f692bc7dd71bcdcfd89b8f5d8d.tar.gz LibGui-1fa69a1b0effc9f692bc7dd71bcdcfd89b8f5d8d.tar.bz2 LibGui-1fa69a1b0effc9f692bc7dd71bcdcfd89b8f5d8d.zip |
Merge pull request #1 from Juuxel/button-disabling
Button disabling
Diffstat (limited to 'src/main/java')
-rw-r--r-- | src/main/java/io/github/cottonmc/cotton/gui/widget/WButton.java | 33 |
1 files changed, 22 insertions, 11 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..3b6c299 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 enabled = true; private Runnable onClick; @@ -31,12 +32,13 @@ public class WButton extends WWidget { @Override 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; + int state = 1; //1=regular. 2=hovered. 0=disabled. + if (!enabled) state = 0; + else if (hovered) state = 2; float px = 1/256f; float buttonLeft = 0 * px; - float buttonTop = (46 + (int_3*20)) * px; + float buttonTop = (46 + (state*20)) * px; int halfWidth = getWidth()/2; if (halfWidth>198) halfWidth=198; float buttonWidth = halfWidth*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; - if (!active) { - color = 10526880; + int color = 0xE0E0E0; + if (!enabled) { + 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 (enabled) { + 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 isEnabled() { + return enabled; + } + + public void setEnabled(boolean enabled) { + this.enabled = enabled; + } } |