aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/dev/mayaqq/ygasi/gui/ConfigGui.java
blob: f847227891c2ad7a2189826f41d904b84ac993aa (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
package dev.mayaqq.ygasi.gui;

import dev.mayaqq.ygasi.registry.ConfigRegistry;
import eu.pb4.sgui.api.elements.GuiElementBuilder;
import eu.pb4.sgui.api.gui.SignGui;
import eu.pb4.sgui.api.gui.SimpleGui;
import net.minecraft.item.Items;
import net.minecraft.screen.ScreenHandlerType;
import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.sound.SoundCategory;
import net.minecraft.sound.SoundEvents;
import net.minecraft.text.Text;

public class ConfigGui {

    public static void gui(ServerPlayerEntity player) {
        SimpleGui gui = new SimpleGui(ScreenHandlerType.GENERIC_9X6, player, false) {
            @Override
            public void onClose() {
                ConfigRegistry.save();
                super.onClose();
            }
        };

        gui.setTitle(Text.translatable("config.ygasi.title"));

        gui.setSlot(0, new GuiElementBuilder()
                .setItem(Items.ENDER_EYE)
                .setName(Text.translatable("config.ygasi.pointsRewarded.title"))
                .addLoreLine(Text.translatable("config.ygasi.current").append(Text.of(String.valueOf(ConfigRegistry.CONFIG.pointsRewarded))))
                .setCallback((index, clickType, actionType) -> {
                    textInput(player, "pointsRewarded");
                    player.playSound(SoundEvents.UI_BUTTON_CLICK, SoundCategory.PLAYERS, 1.0F, 1.0F);
                })
        );

        gui.setSlot(1, new GuiElementBuilder()
                .setItem(Items.OAK_SAPLING)
                .setName(Text.translatable("config.ygasi.branchCost.title"))
                .addLoreLine(Text.translatable("config.ygasi.current").append(Text.of(String.valueOf(ConfigRegistry.CONFIG.branchCost))))
                .setCallback((index, clickType, actionType) -> {
                    textInput(player, "branchCost");
                    player.playSound(SoundEvents.UI_BUTTON_CLICK, SoundCategory.PLAYERS, 1.0F, 1.0F);
                })
        );

        gui.setSlot(2, new GuiElementBuilder()
                .setItem(Items.BOOK)
                .setName(Text.translatable("config.ygasi.enableSkillBook.title"))
                .addLoreLine(Text.translatable("config.ygasi.current").append(Text.of(String.valueOf(ConfigRegistry.CONFIG.enableSkillBook))))
                .setCallback((index, clickType, actionType) -> {
                    ConfigRegistry.CONFIG.enableSkillBook = !ConfigRegistry.CONFIG.enableSkillBook;
                    gui.close();
                    gui(player);
                    player.playSound(SoundEvents.UI_BUTTON_CLICK, SoundCategory.PLAYERS, 1.0F, 1.0F);
                })
        );

        gui.setSlot(3, new GuiElementBuilder()
                .setItem(Items.STICK)
                .setName(Text.translatable("config.ygasi.T1Cost.title"))
                .addLoreLine(Text.translatable("config.ygasi.current").append(Text.of(String.valueOf(ConfigRegistry.CONFIG.T1Cost))))
                .setCallback((index, clickType, actionType) -> {
                    textInput(player, "T1Cost");
                    player.playSound(SoundEvents.UI_BUTTON_CLICK, SoundCategory.PLAYERS, 1.0F, 1.0F);
                })
        );

        gui.setSlot(4, new GuiElementBuilder()
                .setItem(Items.STICK)
                .setCount(2)
                .setName(Text.translatable("config.ygasi.T2Cost.title"))
                .addLoreLine(Text.translatable("config.ygasi.current").append(Text.of(String.valueOf(ConfigRegistry.CONFIG.T2Cost))))
                .setCallback((index, clickType, actionType) -> {
                    textInput(player, "T2Cost");
                    player.playSound(SoundEvents.UI_BUTTON_CLICK, SoundCategory.PLAYERS, 1.0F, 1.0F);
                })
        );

        gui.setSlot(5, new GuiElementBuilder()
                .setItem(Items.STICK)
                .setCount(3)
                .setName(Text.translatable("config.ygasi.T3Cost.title"))
                .addLoreLine(Text.translatable("config.ygasi.current").append(Text.of(String.valueOf(ConfigRegistry.CONFIG.T3Cost))))
                .setCallback((index, clickType, actionType) -> {
                    textInput(player, "T3Cost");
                    player.playSound(SoundEvents.UI_BUTTON_CLICK, SoundCategory.PLAYERS, 1.0F, 1.0F);
                })
        );

        gui.open();
    }


    private static void textInput(ServerPlayerEntity player, String option) {
        try {
            SignGui gui = new SignGui(player) {
                @Override
                public void onClose() {
                    switch (option) {
                        case "pointsRewarded" -> {
                            try {
                                ConfigRegistry.CONFIG.pointsRewarded = Integer.parseInt(this.getLine(0).getString());
                            } catch (NumberFormatException e) {
                                player.sendMessage(Text.translatable("config.ygasi.invalid.number"), false);
                            }
                        }
                        case "branchCost" -> {
                            try {
                                ConfigRegistry.CONFIG.branchCost = Integer.parseInt(this.getLine(0).getString());
                            } catch (NumberFormatException e) {
                                player.sendMessage(Text.translatable("config.ygasi.invalid.number"), false);
                            }
                        }
                        case "T1Cost" -> {
                            try {
                                ConfigRegistry.CONFIG.T1Cost = Integer.parseInt(this.getLine(0).getString());
                            } catch (NumberFormatException e) {
                                player.sendMessage(Text.translatable("config.ygasi.invalid.number"), false);
                            }
                        }
                        case "T2Cost" -> {
                            try {
                                ConfigRegistry.CONFIG.T2Cost = Integer.parseInt(this.getLine(0).getString());
                            } catch (NumberFormatException e) {
                                player.sendMessage(Text.translatable("config.ygasi.invalid.number"), false);
                            }
                        }
                        case "T3Cost" -> {
                            try {
                                ConfigRegistry.CONFIG.T3Cost = Integer.parseInt(this.getLine(0).getString());
                            } catch (NumberFormatException e) {
                                player.sendMessage(Text.translatable("config.ygasi.invalid.number"), false);
                            }
                        }
                    }
                    gui(player);
                }
            };
            gui.open();

        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}