-
-
Notifications
You must be signed in to change notification settings - Fork 509
/
GuiResizeControls.java
94 lines (79 loc) · 3.55 KB
/
GuiResizeControls.java
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
package mekanism.client.gui.element.custom;
import java.util.function.Consumer;
import mekanism.client.SpecialColors;
import mekanism.client.gui.IGuiWrapper;
import mekanism.client.gui.element.GuiSideHolder;
import mekanism.client.gui.element.button.MekanismImageButton;
import mekanism.client.render.MekanismRenderer;
import mekanism.common.MekanismLang;
import mekanism.common.config.MekanismConfig;
import mekanism.common.inventory.container.QIOItemViewerContainer;
import mekanism.common.util.MekanismUtils;
import mekanism.common.util.MekanismUtils.ResourceType;
import net.minecraft.client.gui.GuiGraphics;
import net.minecraft.resources.ResourceLocation;
import org.jetbrains.annotations.NotNull;
public class GuiResizeControls extends GuiSideHolder {
private final MekanismImageButton expandButton, shrinkButton;
private final Consumer<ResizeType> resizeHandler;
private int tooltipTicks;
private static final ResourceLocation MINUS = MekanismUtils.getResource(ResourceType.GUI_BUTTON, "minus.png");
private static final ResourceLocation PLUS = MekanismUtils.getResource(ResourceType.GUI_BUTTON, "plus.png");
public GuiResizeControls(IGuiWrapper gui, int y, Consumer<ResizeType> resizeHandler) {
super(gui, -26, y, 39, true, false);
this.resizeHandler = resizeHandler;
expandButton = addChild(new MekanismImageButton(gui, relativeX + 4, relativeY + 5, 19, 9, 19, 9, PLUS,
() -> handleResize(ResizeType.EXPAND_Y)));
shrinkButton = addChild(new MekanismImageButton(gui, relativeX + 4, relativeY + 25, 19, 9, 19, 9, MINUS,
() -> handleResize(ResizeType.SHRINK_Y)));
updateButtonState();
active = true;
}
@Override
public void tick() {
super.tick();
tooltipTicks = Math.max(0, tooltipTicks - 1);
}
@Override
public void renderToolTip(@NotNull GuiGraphics guiGraphics, int mouseX, int mouseY) {
super.renderToolTip(guiGraphics, mouseX, mouseY);
if (tooltipTicks > 0 && !expandButton.active) {
displayTooltips(guiGraphics, mouseX, mouseY, MekanismLang.QIO_COMPENSATE_TOOLTIP.translate());
}
}
@Override
public void renderForeground(GuiGraphics guiGraphics, int mouseX, int mouseY) {
super.renderForeground(guiGraphics, mouseX, mouseY);
drawScaledCenteredTextScaledBound(guiGraphics, MekanismLang.HEIGHT.translate(), relativeX + 13.5F, relativeY + 15.5F, titleTextColor(), width - 4, 0.7F);
}
@Override
public void onClick(double mouseX, double mouseY, int button) {
super.onClick(mouseX, mouseY, button);
if (!expandButton.active && mouseX >= expandButton.getX() && mouseX < expandButton.getX() + expandButton.getWidth() &&
mouseY >= expandButton.getY() && mouseY < expandButton.getY() + expandButton.getHeight()) {
tooltipTicks = 100;
}
}
@Override
protected void colorTab(GuiGraphics guiGraphics) {
MekanismRenderer.color(guiGraphics, SpecialColors.TAB_RESIZE_CONTROLS);
}
private void handleResize(ResizeType type) {
resizeHandler.accept(type);
updateButtonState();
}
private void updateButtonState() {
int index = getIndex();
expandButton.active = index < QIOItemViewerContainer.getSlotsYMax();
shrinkButton.active = index > QIOItemViewerContainer.SLOTS_Y_MIN;
}
private int getIndex() {
return MekanismConfig.client.qioItemViewerSlotsY.get();
}
public enum ResizeType {
EXPAND_X,
EXPAND_Y,
SHRINK_X,
SHRINK_Y;
}
}