ClothScreenRegistry.java 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. /*
  2. * Roughly Enough Items by Danielshe.
  3. * Licensed under the MIT License.
  4. */
  5. package me.shedaniel.rei.utils;
  6. import me.shedaniel.cloth.api.ConfigScreenBuilder;
  7. import me.shedaniel.cloth.gui.entries.BooleanListEntry;
  8. import me.shedaniel.cloth.gui.entries.EnumListEntry;
  9. import me.shedaniel.cloth.gui.entries.IntegerSliderEntry;
  10. import me.shedaniel.cloth.gui.entries.StringListEntry;
  11. import me.shedaniel.cloth.hooks.ScreenHooks;
  12. import me.shedaniel.rei.RoughlyEnoughItemsCore;
  13. import me.shedaniel.rei.api.ItemCheatingMode;
  14. import me.shedaniel.rei.client.RecipeScreenType;
  15. import me.shedaniel.rei.gui.config.ItemListOrderingConfig;
  16. import me.shedaniel.rei.gui.credits.CreditsScreen;
  17. import net.minecraft.client.MinecraftClient;
  18. import net.minecraft.client.gui.Screen;
  19. import net.minecraft.client.gui.widget.ButtonWidget;
  20. import net.minecraft.client.resource.language.I18n;
  21. import java.io.IOException;
  22. import java.util.Optional;
  23. public class ClothScreenRegistry {
  24. public static final String RESET = "text.cloth-config.reset_value";
  25. public static Screen getConfigScreen(Screen parent) {
  26. ConfigScreenBuilder builder = ConfigScreenBuilder.create(parent, "text.rei.config.title", savedConfig -> {
  27. try {
  28. RoughlyEnoughItemsCore.getConfigManager().saveConfig();
  29. } catch (IOException e) {
  30. e.printStackTrace();
  31. }
  32. });
  33. builder.addCategory("text.rei.config.general").addOption(new BooleanListEntry("text.rei.config.cheating", RoughlyEnoughItemsCore.getConfigManager().getConfig().cheating, RESET, () -> false, bool -> RoughlyEnoughItemsCore.getConfigManager().getConfig().cheating = bool) {
  34. @Override
  35. public Optional<String[]> getTooltip() {
  36. String s = null;
  37. if (!getObject())
  38. s = I18n.translate("text.rei.cheating_disabled");
  39. else if (!RoughlyEnoughItemsCore.hasOperatorPermission())
  40. s = I18n.translate("text.rei.cheating_enabled_no_perms");
  41. else if (RoughlyEnoughItemsCore.hasPermissionToUsePackets())
  42. s = I18n.translate("text.rei.cheating_enabled");
  43. else
  44. s = I18n.translate("text.rei.cheating_limited_enabled");
  45. return Optional.ofNullable(new String[]{s});
  46. }
  47. });
  48. ConfigScreenBuilder.CategoryBuilder appearance = builder.addCategory("text.rei.config.appearance");
  49. appearance.addOption(new EnumListEntry<>("text.rei.config.recipe_screen_type", RecipeScreenType.class, RoughlyEnoughItemsCore.getConfigManager().getConfig().screenType, RESET, () -> RecipeScreenType.UNSET, bool -> RoughlyEnoughItemsCore.getConfigManager().getConfig().screenType = bool, EnumListEntry.DEFAULT_NAME_PROVIDER, () -> getConfigTooltip("recipe_screen_type")));
  50. appearance.addOption(new BooleanListEntry("text.rei.config.side_search_box", RoughlyEnoughItemsCore.getConfigManager().getConfig().sideSearchField, RESET, () -> false, bool -> RoughlyEnoughItemsCore.getConfigManager().getConfig().sideSearchField = bool, () -> getConfigTooltip("side_search_box")));
  51. appearance.addOption(new EnumListEntry<>("text.rei.config.list_ordering", ItemListOrderingConfig.class, ItemListOrderingConfig.from(RoughlyEnoughItemsCore.getConfigManager().getConfig().itemListOrdering, RoughlyEnoughItemsCore.getConfigManager().getConfig().isAscending), RESET, () -> ItemListOrderingConfig.REGISTRY_ASCENDING, config -> {
  52. RoughlyEnoughItemsCore.getConfigManager().getConfig().itemListOrdering = config.getOrdering();
  53. RoughlyEnoughItemsCore.getConfigManager().getConfig().isAscending = config.isAscending();
  54. }, EnumListEntry.DEFAULT_NAME_PROVIDER, () -> getConfigTooltip("list_ordering", ItemListOrderingConfig.REGISTRY_ASCENDING.toString())));
  55. appearance.addOption(new BooleanListEntry("text.rei.config.item_list_position", RoughlyEnoughItemsCore.getConfigManager().getConfig().mirrorItemPanel, RESET, () -> false, bool -> RoughlyEnoughItemsCore.getConfigManager().getConfig().mirrorItemPanel = bool, () -> getConfigTooltip("item_list_position")) {
  56. @Override
  57. public String getYesNoText(boolean bool) {
  58. return I18n.translate(bool ? "text.rei.config.item_list_position.left" : "text.rei.config.item_list_position.right");
  59. }
  60. });
  61. appearance.addOption(new IntegerSliderEntry("text.rei.config.max_recipes_per_page", 2, 99, RoughlyEnoughItemsCore.getConfigManager().getConfig().maxRecipePerPage, RESET, () -> 3, i -> RoughlyEnoughItemsCore.getConfigManager().getConfig().maxRecipePerPage = i, () -> getConfigTooltip("max_recipes_per_page")));
  62. appearance.addOption(new BooleanListEntry("text.rei.config.light_gray_recipe_border", RoughlyEnoughItemsCore.getConfigManager().getConfig().lightGrayRecipeBorder, RESET, () -> false, bool -> RoughlyEnoughItemsCore.getConfigManager().getConfig().lightGrayRecipeBorder = bool, () -> getConfigTooltip("light_gray_recipe_border")));
  63. appearance.addOption(new BooleanListEntry("text.rei.config.prefer_visible_recipes", RoughlyEnoughItemsCore.getConfigManager().getConfig().preferVisibleRecipes, RESET, () -> false, bool -> RoughlyEnoughItemsCore.getConfigManager().getConfig().preferVisibleRecipes = bool, () -> getConfigTooltip("prefer_visible_recipes")));
  64. ConfigScreenBuilder.CategoryBuilder action = builder.addCategory("text.rei.config.action");
  65. action.addOption(new EnumListEntry<>("text.rei.config.item_cheating_mode", ItemCheatingMode.class, RoughlyEnoughItemsCore.getConfigManager().getConfig().itemCheatingMode, RESET, () -> ItemCheatingMode.REI_LIKE, i -> RoughlyEnoughItemsCore.getConfigManager().getConfig().itemCheatingMode = i, e -> {
  66. return I18n.translate("text.rei.config.item_cheating_mode." + e.name().toLowerCase());
  67. }, () -> getConfigTooltip("item_cheating_mode")));
  68. action.addOption(new StringListEntry("text.rei.give_command", RoughlyEnoughItemsCore.getConfigManager().getConfig().giveCommand, RESET, () -> "/give {player_name} {item_identifier}{nbt} {count}", s -> RoughlyEnoughItemsCore.getConfigManager().getConfig().giveCommand = s, () -> getConfigTooltip("give_command")));
  69. action.addOption(new StringListEntry("text.rei.gamemode_command", RoughlyEnoughItemsCore.getConfigManager().getConfig().gamemodeCommand, RESET, () -> "/gamemode {gamemode}", s -> RoughlyEnoughItemsCore.getConfigManager().getConfig().gamemodeCommand = s, () -> getConfigTooltip("gamemode_command")));
  70. action.addOption(new StringListEntry("text.rei.weather_command", RoughlyEnoughItemsCore.getConfigManager().getConfig().weatherCommand, RESET, () -> "/weather {weather}", s -> RoughlyEnoughItemsCore.getConfigManager().getConfig().weatherCommand = s, () -> getConfigTooltip("weather_command")));
  71. ConfigScreenBuilder.CategoryBuilder modules = builder.addCategory("text.rei.config.modules");
  72. modules.addOption(new BooleanListEntry("text.rei.config.enable_craftable_only", RoughlyEnoughItemsCore.getConfigManager().getConfig().enableCraftableOnlyButton, RESET, () -> true, bool -> RoughlyEnoughItemsCore.getConfigManager().getConfig().enableCraftableOnlyButton = bool, () -> getConfigTooltip("enable_craftable_only")));
  73. modules.addOption(new BooleanListEntry("text.rei.config.enable_util_buttons", RoughlyEnoughItemsCore.getConfigManager().getConfig().showUtilsButtons, RESET, () -> false, bool -> RoughlyEnoughItemsCore.getConfigManager().getConfig().showUtilsButtons = bool, () -> getConfigTooltip("enable_util_buttons")));
  74. modules.addOption(new BooleanListEntry("text.rei.config.disable_recipe_book", RoughlyEnoughItemsCore.getConfigManager().getConfig().disableRecipeBook, RESET, () -> false, bool -> RoughlyEnoughItemsCore.getConfigManager().getConfig().disableRecipeBook = bool, () -> getConfigTooltip("disable_recipe_book")));
  75. ConfigScreenBuilder.CategoryBuilder aprilFools = builder.addCategory("text.rei.config.april_fools");
  76. aprilFools.addOption(new BooleanListEntry("text.rei.config.april_fools.2019", RoughlyEnoughItemsCore.getConfigManager().getConfig().aprilFoolsFish2019, RESET, () -> false, bool -> RoughlyEnoughItemsCore.getConfigManager().getConfig().aprilFoolsFish2019 = bool, () -> getConfigTooltip("april_fools.2019")));
  77. return builder.build(screen -> {
  78. ButtonWidget w = new ButtonWidget(6, 6, 60, 20, I18n.translate("text.rei.credits"), widget -> MinecraftClient.getInstance().openScreen(new CreditsScreen(MinecraftClient.getInstance().currentScreen)));
  79. ((ScreenHooks) screen).cloth_getButtonWidgets().add(0, w);
  80. ((ScreenHooks) screen).cloth_getChildren().add(0, w);
  81. });
  82. }
  83. private static Optional<String[]> getConfigTooltip(String s, Object... o) {
  84. if (I18n.hasTranslation("tooltip.rei.config." + s))
  85. return Optional.ofNullable(I18n.translate("tooltip.rei.config." + s, o).split("\n"));
  86. return Optional.empty();
  87. }
  88. }