/
ConfigButton.java
84 lines (75 loc) · 3.53 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
82
83
84
package mezz.jei.gui.overlay;
import java.util.List;
import mezz.jei.config.JEIClientConfig;
import mezz.jei.input.click.MouseClickState;
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.saveString());
TranslationTextComponent disabledFix = new TranslationTextComponent("jei.tooltip.ingredient.list.disabled.how.to.fix", overLay);
tooltip.add(disabled.withStyle(TextFormatting.GOLD));
tooltip.add(disabledFix.withStyle(TextFormatting.GOLD));
} else if (!parent.isListDisplayed()) {
TranslationTextComponent notEnoughSpace = new TranslationTextComponent("jei.tooltip.not.enough.space");
tooltip.add(notEnoughSpace.withStyle(TextFormatting.GOLD));
}
if (worldConfig.isCheatItemsEnabled()) {
TranslationTextComponent enabled = new TranslationTextComponent("jei.tooltip.cheat.mode.button.enabled");
tooltip.add(enabled.withStyle(TextFormatting.RED));
KeyBinding toggleCheatMode = KeyBindings.toggleCheatMode;
if (!toggleCheatMode.isUnbound()) {
TranslationTextComponent cheatMode = new TranslationTextComponent(toggleCheatMode.saveString());
TranslationTextComponent disableHotkey = new TranslationTextComponent("jei.tooltip.cheat.mode.how.to.disable.hotkey", cheatMode);
tooltip.add(disableHotkey.withStyle(TextFormatting.RED));
} else {
TranslationTextComponent controlKeyLocalization = new TranslationTextComponent(Minecraft.ON_OSX ? "key.jei.ctrl.mac" : "key.jei.ctrl");
TranslationTextComponent noHotKey = new TranslationTextComponent("jei.tooltip.cheat.mode.how.to.disable.no.hotkey", controlKeyLocalization);
tooltip.add(noHotKey.withStyle(TextFormatting.RED));
}
}
}
@Override
protected boolean isIconToggledOn() {
return worldConfig.isCheatItemsEnabled();
}
@Override
protected boolean onMouseClicked(Screen screen, double mouseX, double mouseY, int mouseButton, MouseClickState clickState) {
if (worldConfig.isOverlayEnabled()) {
if (!clickState.isSimulate()) {
if (Screen.hasControlDown()) {
worldConfig.toggleCheatItemsEnabled();
} else {
JEIClientConfig.openSettings();
}
}
return true;
}
return false;
}
}