/
ConfigButton.java
81 lines (72 loc) · 3.44 KB
/
ConfigButton.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
package mezz.jei.gui.overlay;
import java.util.List;
import mezz.jei.config.JEIClientConfig;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.screen.Screen;
import net.minecraft.client.settings.KeyBinding;
import net.minecraft.util.text.ITextComponent;
import net.minecraft.util.text.TextFormatting;
import mezz.jei.Internal;
import mezz.jei.api.gui.drawable.IDrawable;
import mezz.jei.config.IWorldConfig;
import mezz.jei.config.KeyBindings;
import mezz.jei.gui.elements.GuiIconToggleButton;
import mezz.jei.gui.textures.Textures;
import net.minecraft.util.text.TranslationTextComponent;
public class ConfigButton extends GuiIconToggleButton {
public static ConfigButton create(IngredientListOverlay parent, IWorldConfig worldConfig) {
Textures textures = Internal.getTextures();
return new ConfigButton(textures.getConfigButtonIcon(), textures.getConfigButtonCheatIcon(), parent, worldConfig);
}
private final IngredientListOverlay parent;
private final IWorldConfig worldConfig;
private ConfigButton(IDrawable disabledIcon, IDrawable enabledIcon, IngredientListOverlay parent, IWorldConfig worldConfig) {
super(disabledIcon, enabledIcon);
this.parent = parent;
this.worldConfig = worldConfig;
}
@Override
protected void getTooltips(List<ITextComponent> tooltip) {
tooltip.add(new TranslationTextComponent("jei.tooltip.config"));
if (!worldConfig.isOverlayEnabled()) {
TranslationTextComponent disabled = new TranslationTextComponent("jei.tooltip.ingredient.list.disabled");
TranslationTextComponent overLay = new TranslationTextComponent(KeyBindings.toggleOverlay.getTranslationKey());
TranslationTextComponent disabledFix = new TranslationTextComponent("jei.tooltip.ingredient.list.disabled.how.to.fix", overLay);
tooltip.add(disabled.mergeStyle(TextFormatting.GOLD));
tooltip.add(disabledFix.mergeStyle(TextFormatting.GOLD));
} else if (!parent.isListDisplayed()) {
TranslationTextComponent notEnoughSpace = new TranslationTextComponent("jei.tooltip.not.enough.space");
tooltip.add(notEnoughSpace.mergeStyle(TextFormatting.GOLD));
}
if (worldConfig.isCheatItemsEnabled()) {
TranslationTextComponent enabled = new TranslationTextComponent("jei.tooltip.cheat.mode.button.enabled");
tooltip.add(enabled.mergeStyle(TextFormatting.RED));
KeyBinding toggleCheatMode = KeyBindings.toggleCheatMode;
if (toggleCheatMode.getKey().getKeyCode() != 0) {
TranslationTextComponent cheatMode = new TranslationTextComponent(toggleCheatMode.getTranslationKey());
TranslationTextComponent disableHotkey = new TranslationTextComponent("jei.tooltip.cheat.mode.how.to.disable.hotkey", cheatMode);
tooltip.add(disableHotkey.mergeStyle(TextFormatting.RED));
} else {
TranslationTextComponent controlKeyLocalization = new TranslationTextComponent(Minecraft.IS_RUNNING_ON_MAC ? "key.jei.ctrl.mac" : "key.jei.ctrl");
TranslationTextComponent noHotKey = new TranslationTextComponent("jei.tooltip.cheat.mode.how.to.disable.no.hotkey", controlKeyLocalization);
tooltip.add(noHotKey.mergeStyle(TextFormatting.RED));
}
}
}
@Override
protected boolean isIconToggledOn() {
return worldConfig.isCheatItemsEnabled();
}
@Override
protected boolean onMouseClicked(double mouseX, double mouseY, int mouseButton) {
if (worldConfig.isOverlayEnabled()) {
if (Screen.hasControlDown()) {
worldConfig.toggleCheatItemsEnabled();
} else {
JEIClientConfig.openSettings();
}
return true;
}
return false;
}
}