aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/gregtech/nei/NEIHandlerAbsoluteTooltip.java
blob: e136a67c9968c325262989646cd66f9b853bddfc (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 gregtech.nei;

import codechicken.lib.gui.GuiDraw;
import java.awt.*;
import java.util.List;

public class NEIHandlerAbsoluteTooltip {
    private final Rectangle area;
    private final String tooltip;
    private Dimension displaySize;

    public NEIHandlerAbsoluteTooltip(String tooltip, Rectangle area) {
        this.tooltip = tooltip;
        this.area = area;
    }

    public void handleTooltip(List<String> currenttip, int recipeIndex) {
        displaySize = GuiDraw.displaySize();
        if (shouldAddTooltip(recipeIndex)) {
            currenttip.add(tooltip);
        }
    }

    private boolean shouldAddTooltip(int recipeIndex) {
        return isPageFirstRecipe(recipeIndex) && mouseInArea();
    }

    private boolean mouseInArea() {
        Point mousePos = getRelMouse();
        return area.contains(mousePos);
    }

    private Point getRelMouse() {
        int ySize = Math.min(Math.max(displaySize.height - 68, 166), 370);
        int guiLeft = (displaySize.width - 176) / 2;
        int guiTop = (displaySize.height - ySize) / 2 + 10;
        Point mousePos = GuiDraw.getMousePosition();
        return new Point(mousePos.x - guiLeft - 5, mousePos.y - guiTop - 38);
    }

    private boolean isPageFirstRecipe(int recipe) {
        int actualRecipesPerPage = getActualRecipesPerPage();
        return actualRecipesPerPage < 2 || recipe % 2 == 0;
    }

    private int getActualRecipesPerPage() {
        int ySize = Math.min(Math.max(displaySize.height - 68, 166), 370);
        return (ySize - (12 * 3)) / 135;
    }
}