aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/me/shedaniel/gui/ConfigGui.java
blob: 6deeb24ea07487fc68783ea8e90c65881c687ed8 (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
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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
package me.shedaniel.gui;

import me.shedaniel.ClientListener;
import me.shedaniel.Core;
import me.shedaniel.config.REIItemListOrdering;
import me.shedaniel.gui.widget.KeyBindButton;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.gui.Gui;
import net.minecraft.client.gui.widget.ButtonWidget;
import net.minecraft.client.render.GuiLighting;
import net.minecraft.client.resource.language.I18n;

import java.io.IOException;
import java.util.Arrays;

public class ConfigGui extends Gui {
    
    private Gui parent;
    
    public ConfigGui(Gui parent) {
        this.parent = parent;
    }
    
    @Override
    protected void onInitialized() {
        addButton(new KeyBindButton(997, parent.width / 2 - 20, 30, 80, 20, Core.config.recipeKeyBind, key -> {
            Core.config.recipeKeyBind = key;
            ClientListener.recipeKeyBind.setKey(key);
            try {
                Core.saveConfig();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }));
        addButton(new KeyBindButton(998, parent.width / 2 - 20, 60, 80, 20, Core.config.usageKeyBind, key -> {
            Core.config.usageKeyBind = key;
            ClientListener.usageKeyBind.setKey(key);
            try {
                Core.saveConfig();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }));
        addButton(new KeyBindButton(999, parent.width / 2 - 20, 90, 80, 20, Core.config.hideKeyBind, key -> {
            Core.config.hideKeyBind = key;
            ClientListener.hideKeyBind.setKey(key);
            try {
                Core.saveConfig();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }));
        addButton(new ButtonWidget(1000, parent.width / 2 - 90, 120, 150, 20, "") {
            @Override
            public void onPressed(double double_1, double double_2) {
                Core.config.centreSearchBox = !Core.config.centreSearchBox;
                try {
                    Core.saveConfig();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            
            @Override
            public void draw(int int_1, int int_2, float float_1) {
                this.text = I18n.translate("text.rei.centre_searchbox", Core.config.centreSearchBox ? "§a" : "§c", Core.config.centreSearchBox);
                super.draw(int_1, int_2, float_1);
                if (this.hovered)
                    drawSuggestion(int_1, int_2);
            }
            
            protected void drawSuggestion(int x, int y) {
                drawTooltip(Arrays.asList(I18n.translate("text.rei.centre_searchbox.tooltip").split("\n")), x, y);
            }
        });
        addButton(new ButtonWidget(1001, parent.width / 2 - 90, 150, 150, 20, "") {
            @Override
            public void onPressed(double double_1, double double_2) {
                Core.config.enableCraftableOnlyButton = !Core.config.enableCraftableOnlyButton;
                try {
                    Core.saveConfig();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            
            @Override
            public void draw(int int_1, int int_2, float float_1) {
                GuiLighting.disable();
                this.text = I18n.translate("text.rei.enable_craftable_only.button", Core.config.enableCraftableOnlyButton ? "§a" : "§c", Core.config.enableCraftableOnlyButton);
                super.draw(int_1, int_2, float_1);
                if (this.hovered)
                    drawSuggestion(int_1, int_2);
            }
            
            protected void drawSuggestion(int x, int y) {
                drawTooltip(Arrays.asList(I18n.translate("text.rei.enable_craftable_only.tooltip").split("\n")), x, y);
            }
        });
        addButton(new ButtonWidget(1002, parent.width / 2 - 90, 180, 150, 20, "") {
            @Override
            public void onPressed(double double_1, double double_2) {
                int index = Arrays.asList(REIItemListOrdering.values()).indexOf(Core.config.itemListOrdering) + 1;
                if (index >= REIItemListOrdering.values().length) {
                    index = 0;
                    Core.config.isAscending = !Core.config.isAscending;
                }
                Core.config.itemListOrdering = REIItemListOrdering.values()[index];
                try {
                    Core.saveConfig();
                    REIRenderHelper.reiGui.updateView();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            
            @Override
            public void draw(int int_1, int int_2, float float_1) {
                GuiLighting.disable();
                this.text = I18n.translate("text.rei.list_ordering_button", I18n.translate(Core.config.itemListOrdering.getNameTranslationKey()),
                        I18n.translate(Core.config.isAscending ? "ordering.rei.ascending" : "ordering.rei.descending"));
                super.draw(int_1, int_2, float_1);
            }
        });
    }
    
    @Override
    public void draw(int mouseX, int mouseY, float partialTicks) {
        drawBackground();
        super.draw(mouseX, mouseY, partialTicks);
        GuiLighting.disable();
        String text = I18n.translate("key.rei.recipe") + ": ";
        drawString(MinecraftClient.getInstance().fontRenderer, text, parent.width / 2 - 25 - MinecraftClient.getInstance().fontRenderer.getStringWidth(text), 30 + 6, -1);
        text = I18n.translate("key.rei.use") + ": ";
        drawString(MinecraftClient.getInstance().fontRenderer, text, parent.width / 2 - 25 - MinecraftClient.getInstance().fontRenderer.getStringWidth(text), 60 + 6, -1);
        text = I18n.translate("key.rei.hide") + ": ";
        drawString(MinecraftClient.getInstance().fontRenderer, text, parent.width / 2 - 25 - MinecraftClient.getInstance().fontRenderer.getStringWidth(text), 90 + 6, -1);
        text = I18n.translate("text.rei.list_ordering") + ": ";
        drawString(MinecraftClient.getInstance().fontRenderer, text, parent.width / 2 - 95 - MinecraftClient.getInstance().fontRenderer.getStringWidth(text), 180 + 6, -1);
    }
    
    @Override
    public boolean keyPressed(int p_keyPressed_1_, int p_keyPressed_2_, int p_keyPressed_3_) {
        if (p_keyPressed_1_ == 256 && this.doesEscapeKeyClose()) {
            this.close();
            if (parent != null)
                MinecraftClient.getInstance().openGui(parent);
            return true;
        } else {
            return super.keyPressed(p_keyPressed_1_, p_keyPressed_2_, p_keyPressed_3_);
        }
    }
    
}