aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/eu/olli/cowlection/search/GuiTooltip.java
diff options
context:
space:
mode:
authorCow <cow@volloeko.de>2020-07-05 05:42:45 +0200
committerCow <cow@volloeko.de>2020-07-05 05:42:45 +0200
commit1b446698398c648b38311975a6cfd54859ea5cfe (patch)
tree521ecc4ce9ad968281094eb8c5453dca606931e3 /src/main/java/eu/olli/cowlection/search/GuiTooltip.java
parentedaca1fd41a612c71c526ceb20b89c5dec2d81b3 (diff)
downloadCowlection-1b446698398c648b38311975a6cfd54859ea5cfe.tar.gz
Cowlection-1b446698398c648b38311975a6cfd54859ea5cfe.tar.bz2
Cowlection-1b446698398c648b38311975a6cfd54859ea5cfe.zip
Renamed mod to Cowlection
Bumped version to 1.8.9-0.7.0
Diffstat (limited to 'src/main/java/eu/olli/cowlection/search/GuiTooltip.java')
-rw-r--r--src/main/java/eu/olli/cowlection/search/GuiTooltip.java50
1 files changed, 50 insertions, 0 deletions
diff --git a/src/main/java/eu/olli/cowlection/search/GuiTooltip.java b/src/main/java/eu/olli/cowlection/search/GuiTooltip.java
new file mode 100644
index 0000000..f76bf2d
--- /dev/null
+++ b/src/main/java/eu/olli/cowlection/search/GuiTooltip.java
@@ -0,0 +1,50 @@
+package eu.olli.cowlection.search;
+
+import net.minecraft.client.gui.Gui;
+import net.minecraft.client.gui.GuiButton;
+import net.minecraft.client.gui.GuiTextField;
+import net.minecraftforge.fml.client.config.GuiCheckBox;
+import net.minecraftforge.fml.client.config.HoverChecker;
+
+import java.util.List;
+
+public class GuiTooltip {
+ private final HoverChecker hoverChecker;
+ private final List<String> tooltip;
+
+ public <T extends Gui> GuiTooltip(T field, List<String> tooltip) {
+ if (field instanceof GuiCheckBox) {
+ // checkbox
+ GuiCheckBox guiCheckBox = (GuiCheckBox) field;
+ int top = guiCheckBox.yPosition;
+ int bottom = guiCheckBox.yPosition + guiCheckBox.height;
+ int left = guiCheckBox.xPosition;
+ int right = guiCheckBox.xPosition + guiCheckBox.width;
+
+ this.hoverChecker = new HoverChecker(top, bottom, left, right, 300);
+ } else if (field instanceof GuiTextField) {
+ // text field
+ GuiTextField guiTextField = (GuiTextField) field;
+ int top = guiTextField.yPosition;
+ int bottom = guiTextField.yPosition + guiTextField.height;
+ int left = guiTextField.xPosition;
+ int right = guiTextField.xPosition + guiTextField.width;
+
+ this.hoverChecker = new HoverChecker(top, bottom, left, right, 300);
+ } else if (field instanceof GuiButton) {
+ // button
+ this.hoverChecker = new HoverChecker((GuiButton) field, 300);
+ } else {
+ throw new IllegalArgumentException("Tried to add a tooltip to an illegal field type: " + field.getClass());
+ }
+ this.tooltip = tooltip;
+ }
+
+ public List<String> getText() {
+ return tooltip;
+ }
+
+ public boolean checkHover(int mouseX, int mouseY) {
+ return hoverChecker.checkHover(mouseX, mouseY);
+ }
+}