blob: 41b3b89d9122d31359d32d641610a623ba0a10c0 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
|
package de.cowtipper.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);
}
}
|