diff options
author | Maximusbarcz <maxim.baranek@gmail.com> | 2023-01-07 19:36:26 +0100 |
---|---|---|
committer | Maximusbarcz <maxim.baranek@gmail.com> | 2023-01-07 19:36:26 +0100 |
commit | 86b6bcf1d1406b5a3517d9b2351e3792054a6163 (patch) | |
tree | 5ac798ead82eea78a697b8b6dd1f600e1ba6fb31 /src/main/java/dev/mayaqq/ygasi/gui/ConfigGui.java | |
parent | 255cbe744535466951b8f1699202763520f1fc95 (diff) | |
download | ygasi-86b6bcf1d1406b5a3517d9b2351e3792054a6163.tar.gz ygasi-86b6bcf1d1406b5a3517d9b2351e3792054a6163.tar.bz2 ygasi-86b6bcf1d1406b5a3517d9b2351e3792054a6163.zip |
Added some more translations and also a Config GUI you can access by doing /ygasi config in game
Diffstat (limited to 'src/main/java/dev/mayaqq/ygasi/gui/ConfigGui.java')
-rw-r--r-- | src/main/java/dev/mayaqq/ygasi/gui/ConfigGui.java | 146 |
1 files changed, 146 insertions, 0 deletions
diff --git a/src/main/java/dev/mayaqq/ygasi/gui/ConfigGui.java b/src/main/java/dev/mayaqq/ygasi/gui/ConfigGui.java new file mode 100644 index 0000000..f847227 --- /dev/null +++ b/src/main/java/dev/mayaqq/ygasi/gui/ConfigGui.java @@ -0,0 +1,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(); + } + } +}
\ No newline at end of file |