aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/me/shedaniel/rei/gui/widget/ButtonWidget.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/me/shedaniel/rei/gui/widget/ButtonWidget.java')
-rw-r--r--src/main/java/me/shedaniel/rei/gui/widget/ButtonWidget.java95
1 files changed, 44 insertions, 51 deletions
diff --git a/src/main/java/me/shedaniel/rei/gui/widget/ButtonWidget.java b/src/main/java/me/shedaniel/rei/gui/widget/ButtonWidget.java
index b16e38187..0578e8bf6 100644
--- a/src/main/java/me/shedaniel/rei/gui/widget/ButtonWidget.java
+++ b/src/main/java/me/shedaniel/rei/gui/widget/ButtonWidget.java
@@ -2,10 +2,9 @@ package me.shedaniel.rei.gui.widget;
import com.mojang.blaze3d.platform.GlStateManager;
import me.shedaniel.rei.client.ScreenHelper;
-import net.minecraft.client.MinecraftClient;
import net.minecraft.client.audio.PositionedSoundInstance;
import net.minecraft.client.font.TextRenderer;
-import net.minecraft.client.gui.InputListener;
+import net.minecraft.client.gui.Element;
import net.minecraft.client.gui.widget.AbstractButtonWidget;
import net.minecraft.sound.SoundEvents;
import net.minecraft.text.TextComponent;
@@ -20,7 +19,6 @@ public abstract class ButtonWidget extends HighlightableWidget {
public String text;
public boolean enabled;
- public boolean visible;
public boolean focused;
private Rectangle bounds;
@@ -31,7 +29,6 @@ public abstract class ButtonWidget extends HighlightableWidget {
public ButtonWidget(Rectangle rectangle, String text) {
this.bounds = rectangle;
this.enabled = true;
- this.visible = true;
this.text = text;
}
@@ -60,72 +57,68 @@ public abstract class ButtonWidget extends HighlightableWidget {
@Override
public void render(int mouseX, int mouseY, float partialTicks) {
- if (this.visible) {
- int x = bounds.x, y = bounds.y, width = bounds.width, height = bounds.height;
- MinecraftClient client = MinecraftClient.getInstance();
- TextRenderer textRenderer = client.textRenderer;
- client.getTextureManager().bindTexture(AbstractButtonWidget.WIDGETS_LOCATION);
- GlStateManager.color4f(1.0F, 1.0F, 1.0F, 1.0F);
- int textureOffset = this.getTextureId(isHovered(mouseX, mouseY));
- GlStateManager.enableBlend();
- GlStateManager.blendFuncSeparate(GlStateManager.SourceFactor.SRC_ALPHA, GlStateManager.DestFactor.ONE_MINUS_SRC_ALPHA, GlStateManager.SourceFactor.ONE, GlStateManager.DestFactor.ZERO);
- GlStateManager.blendFunc(GlStateManager.SourceFactor.SRC_ALPHA, GlStateManager.DestFactor.ONE_MINUS_SRC_ALPHA);
- //Four Corners
- this.blit(x, y, 0, 46 + textureOffset * 20, 4, 4);
- this.blit(x + width - 4, y, 196, 46 + textureOffset * 20, 4, 4);
- this.blit(x, y + height - 4, 0, 62 + textureOffset * 20, 4, 4);
- this.blit(x + width - 4, y + height - 4, 196, 62 + textureOffset * 20, 4, 4);
-
- //Sides
- this.blit(x + 4, y, 4, 46 + textureOffset * 20, width - 8, 4);
- this.blit(x + 4, y + height - 4, 4, 62 + textureOffset * 20, width - 8, 4);
-
- for(int i = y + 4; i < y + height - 4; i += 4) {
- this.blit(x, i, 0, 50 + textureOffset * 20, width / 2, MathHelper.clamp(y + height - 4 - i, 0, 4));
- this.blit(x + width / 2, i, 200 - width / 2, 50 + textureOffset * 20, width / 2, MathHelper.clamp(y + height - 4 - i, 0, 4));
- }
-
- int colour = 14737632;
- if (!this.enabled) {
- colour = 10526880;
- } else if (isHovered(mouseX, mouseY)) {
- colour = 16777120;
- }
-
- this.drawCenteredString(textRenderer, this.text, x + width / 2, y + (height - 8) / 2, colour);
-
- if (getTooltips().isPresent())
- if (isHighlighted(mouseX, mouseY))
- ScreenHelper.getLastOverlay().addTooltip(QueuedTooltip.create(getTooltips().get().split("\n")));
- else if (focused)
- ScreenHelper.getLastOverlay().addTooltip(QueuedTooltip.create(new Point(x + width / 2, y + height / 2), getTooltips().get().split("\n")));
+ int x = bounds.x, y = bounds.y, width = bounds.width, height = bounds.height;
+ TextRenderer textRenderer = minecraft.textRenderer;
+ minecraft.getTextureManager().bindTexture(AbstractButtonWidget.WIDGETS_LOCATION);
+ GlStateManager.color4f(1.0F, 1.0F, 1.0F, 1.0F);
+ int textureOffset = this.getTextureId(isHovered(mouseX, mouseY));
+ GlStateManager.enableBlend();
+ GlStateManager.blendFuncSeparate(GlStateManager.SourceFactor.SRC_ALPHA, GlStateManager.DestFactor.ONE_MINUS_SRC_ALPHA, GlStateManager.SourceFactor.ONE, GlStateManager.DestFactor.ZERO);
+ GlStateManager.blendFunc(GlStateManager.SourceFactor.SRC_ALPHA, GlStateManager.DestFactor.ONE_MINUS_SRC_ALPHA);
+ //Four Corners
+ this.blit(x, y, 0, 46 + textureOffset * 20, 4, 4);
+ this.blit(x + width - 4, y, 196, 46 + textureOffset * 20, 4, 4);
+ this.blit(x, y + height - 4, 0, 62 + textureOffset * 20, 4, 4);
+ this.blit(x + width - 4, y + height - 4, 196, 62 + textureOffset * 20, 4, 4);
+
+ //Sides
+ this.blit(x + 4, y, 4, 46 + textureOffset * 20, width - 8, 4);
+ this.blit(x + 4, y + height - 4, 4, 62 + textureOffset * 20, width - 8, 4);
+
+ for(int i = y + 4; i < y + height - 4; i += 4) {
+ this.blit(x, i, 0, 50 + textureOffset * 20, width / 2, MathHelper.clamp(y + height - 4 - i, 0, 4));
+ this.blit(x + width / 2, i, 200 - width / 2, 50 + textureOffset * 20, width / 2, MathHelper.clamp(y + height - 4 - i, 0, 4));
}
+
+ int colour = 14737632;
+ if (!this.enabled) {
+ colour = 10526880;
+ } else if (isHovered(mouseX, mouseY)) {
+ colour = 16777120;
+ }
+
+ this.drawCenteredString(textRenderer, this.text, x + width / 2, y + (height - 8) / 2, colour);
+
+ if (getTooltips().isPresent())
+ if (!focused && isHighlighted(mouseX, mouseY))
+ ScreenHelper.getLastOverlay().addTooltip(QueuedTooltip.create(getTooltips().get().split("\n")));
+ else if (focused)
+ ScreenHelper.getLastOverlay().addTooltip(QueuedTooltip.create(new Point(x + width / 2, y + height / 2), getTooltips().get().split("\n")));
}
public boolean isHovered(int mouseX, int mouseY) {
- return bounds.contains(mouseX, mouseY) || focused;
+ return isMouseOver(mouseX, mouseY) || focused;
}
@Override
public boolean isPartOfFocusCycle() {
- return visible && enabled;
+ return enabled;
}
@Override
public void onFocusChanged(boolean boolean_1, boolean boolean_2) {
- if (boolean_2)
- focused = boolean_1;
+ focused = boolean_2;
}
@Override
- public List<? extends InputListener> children() {
+ public List<? extends Element> children() {
return Collections.emptyList();
}
@Override
public boolean mouseClicked(double mouseX, double mouseY, int button) {
if (bounds.contains(mouseX, mouseY) && enabled && button == 0) {
- MinecraftClient.getInstance().getSoundManager().play(PositionedSoundInstance.master(SoundEvents.UI_BUTTON_CLICK, 1.0F));
+ minecraft.getSoundManager().play(PositionedSoundInstance.master(SoundEvents.UI_BUTTON_CLICK, 1.0F));
onPressed();
return true;
}
@@ -134,11 +127,11 @@ public abstract class ButtonWidget extends HighlightableWidget {
@Override
public boolean keyPressed(int int_1, int int_2, int int_3) {
- if (this.enabled && this.visible) {
+ if (this.enabled) {
if (int_1 != 257 && int_1 != 32 && int_1 != 335) {
return false;
} else {
- MinecraftClient.getInstance().getSoundManager().play(PositionedSoundInstance.master(SoundEvents.UI_BUTTON_CLICK, 1.0F));
+ minecraft.getSoundManager().play(PositionedSoundInstance.master(SoundEvents.UI_BUTTON_CLICK, 1.0F));
this.onPressed();
return true;
}