diff options
Diffstat (limited to 'src/main/java/me/shedaniel/rei/gui/widget/SearchFieldWidget.java')
| -rw-r--r-- | src/main/java/me/shedaniel/rei/gui/widget/SearchFieldWidget.java | 57 |
1 files changed, 57 insertions, 0 deletions
diff --git a/src/main/java/me/shedaniel/rei/gui/widget/SearchFieldWidget.java b/src/main/java/me/shedaniel/rei/gui/widget/SearchFieldWidget.java new file mode 100644 index 000000000..8cf521ee2 --- /dev/null +++ b/src/main/java/me/shedaniel/rei/gui/widget/SearchFieldWidget.java @@ -0,0 +1,57 @@ +package me.shedaniel.rei.gui.widget; + +import com.mojang.blaze3d.platform.GlStateManager; +import net.minecraft.client.audio.PositionedSoundInstance; +import net.minecraft.client.render.GuiLighting; +import net.minecraft.sound.SoundEvents; + +public class SearchFieldWidget extends TextFieldWidget { + + public static boolean isSearching = false; + protected long lastClickedTime = -1; + + public SearchFieldWidget(int x, int y, int width, int height) { + super(x, y, width, height); + } + + public void laterRender(int int_1, int int_2, float float_1) { + GuiLighting.disable(); + GlStateManager.disableDepthTest(); + setEditableColor(isSearching ? -1313241 : 14737632); + super.render(int_1, int_2, float_1); + GlStateManager.enableDepthTest(); + } + + @Override + public void renderBorder() { + if (!isSearching) + super.renderBorder(); + else { + fill(this.getBounds().x - 1, this.getBounds().y - 1, this.getBounds().x + this.getBounds().width + 1, this.getBounds().y + this.getBounds().height + 1, -1313241); + fill(this.getBounds().x, this.getBounds().y, this.getBounds().x + this.getBounds().width, this.getBounds().y + this.getBounds().height, -16777216); + } + } + + @Override + public boolean mouseClicked(double double_1, double double_2, int int_1) { + boolean contains = isHighlighted(double_1, double_2); + if (isVisible() && contains && int_1 == 1) + setText(""); + if (contains && int_1 == 0) + if (lastClickedTime == -1) + lastClickedTime = System.currentTimeMillis(); + else if (System.currentTimeMillis() - lastClickedTime > 1200) + lastClickedTime = -1; + else { + lastClickedTime = -1; + isSearching = !isSearching; + minecraft.getSoundManager().play(PositionedSoundInstance.master(SoundEvents.UI_BUTTON_CLICK, 1.0F)); + } + return super.mouseClicked(double_1, double_2, int_1); + } + + @Override + public void render(int int_1, int int_2, float float_1) { + } + +} |
