ConfigObjectImpl.java 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422
  1. /*
  2. * This file is licensed under the MIT License, part of Roughly Enough Items.
  3. * Copyright (c) 2018, 2019, 2020 shedaniel
  4. *
  5. * Permission is hereby granted, free of charge, to any person obtaining a copy
  6. * of this software and associated documentation files (the "Software"), to deal
  7. * in the Software without restriction, including without limitation the rights
  8. * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  9. * copies of the Software, and to permit persons to whom the Software is
  10. * furnished to do so, subject to the following conditions:
  11. *
  12. * The above copyright notice and this permission notice shall be included in all
  13. * copies or substantial portions of the Software.
  14. *
  15. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  16. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  17. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  18. * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  19. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  20. * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  21. * SOFTWARE.
  22. */
  23. package me.shedaniel.rei.impl;
  24. import me.sargunvohra.mcmods.autoconfig1u.ConfigData;
  25. import me.sargunvohra.mcmods.autoconfig1u.annotation.Config;
  26. import me.sargunvohra.mcmods.autoconfig1u.annotation.ConfigEntry;
  27. import me.sargunvohra.mcmods.autoconfig1u.shadowed.blue.endless.jankson.Comment;
  28. import me.shedaniel.clothconfig2.api.Modifier;
  29. import me.shedaniel.clothconfig2.api.ModifierKeyCode;
  30. import me.shedaniel.rei.api.ConfigObject;
  31. import me.shedaniel.rei.api.EntryStack;
  32. import me.shedaniel.rei.gui.config.*;
  33. import me.shedaniel.rei.impl.ConfigObjectImpl.DontApplyFieldName;
  34. import me.shedaniel.rei.impl.ConfigObjectImpl.UseEnumSelectorInstead;
  35. import me.shedaniel.rei.impl.ConfigObjectImpl.UseFilteringScreen;
  36. import me.shedaniel.rei.impl.ConfigObjectImpl.UseSpecialRecipeTypeScreen;
  37. import net.minecraft.client.util.InputUtil;
  38. import org.jetbrains.annotations.ApiStatus;
  39. import java.lang.annotation.ElementType;
  40. import java.lang.annotation.Retention;
  41. import java.lang.annotation.RetentionPolicy;
  42. import java.lang.annotation.Target;
  43. import java.util.ArrayList;
  44. import java.util.List;
  45. @ApiStatus.Internal
  46. @Config(name = "roughlyenoughitems/config")
  47. public class ConfigObjectImpl implements ConfigObject, ConfigData {
  48. @ConfigEntry.Category("!general") @ConfigEntry.Gui.TransitiveObject @DontApplyFieldName public General general = new General();
  49. @ConfigEntry.Category("appearance") @ConfigEntry.Gui.TransitiveObject @DontApplyFieldName private Appearance appearance = new Appearance();
  50. @ConfigEntry.Category("modules") @ConfigEntry.Gui.TransitiveObject @DontApplyFieldName private Modules modules = new Modules();
  51. @ConfigEntry.Category("technical") @ConfigEntry.Gui.TransitiveObject @DontApplyFieldName private Technical technical = new Technical();
  52. @ConfigEntry.Category("performance") @ConfigEntry.Gui.TransitiveObject @DontApplyFieldName private Performance performance = new Performance();
  53. @ConfigEntry.Category("filtering") @ConfigEntry.Gui.TransitiveObject @DontApplyFieldName private Filtering filtering = new Filtering();
  54. @Override
  55. public boolean isOverlayVisible() {
  56. return general.overlayVisible;
  57. }
  58. @Override
  59. public void setOverlayVisible(boolean overlayVisible) {
  60. general.overlayVisible = overlayVisible;
  61. }
  62. @Override
  63. public boolean isCheating() {
  64. return general.cheating;
  65. }
  66. @Override
  67. public void setCheating(boolean cheating) {
  68. general.cheating = cheating;
  69. }
  70. @Override
  71. public ItemListOrdering getItemListOrdering() {
  72. return appearance.itemListOrdering.getOrdering();
  73. }
  74. @Override
  75. public boolean isItemListAscending() {
  76. return appearance.itemListOrdering.isAscending();
  77. }
  78. @Override
  79. public boolean isUsingDarkTheme() {
  80. return appearance.darkTheme;
  81. }
  82. @Override
  83. public boolean isToastDisplayedOnCopyIdentifier() {
  84. return modules.toastDisplayedOnCopyIdentifier;
  85. }
  86. @Override
  87. public boolean doesRenderEntryEnchantmentGlint() {
  88. return performance.renderEntryEnchantmentGlint;
  89. }
  90. @Override
  91. public boolean isEntryListWidgetScrolled() {
  92. return appearance.scrollingEntryListWidget;
  93. }
  94. @Override
  95. public boolean shouldAppendModNames() {
  96. return appearance.appendModNames;
  97. }
  98. @Override
  99. public RecipeScreenType getRecipeScreenType() {
  100. return appearance.recipeScreenType;
  101. }
  102. @Override
  103. public void setRecipeScreenType(RecipeScreenType recipeScreenType) {
  104. appearance.recipeScreenType = recipeScreenType;
  105. }
  106. @Override
  107. public boolean isLoadingDefaultPlugin() {
  108. return technical.loadDefaultPlugin;
  109. }
  110. @Override
  111. public SearchFieldLocation getSearchFieldLocation() {
  112. return appearance.searchFieldLocation;
  113. }
  114. @Override
  115. public boolean isLeftHandSidePanel() {
  116. return appearance.mirrorItemPanel;
  117. }
  118. @Override
  119. public boolean isCraftableFilterEnabled() {
  120. return modules.enableCraftableOnlyButton;
  121. }
  122. @Override
  123. public String getGamemodeCommand() {
  124. return technical.gamemodeCommand;
  125. }
  126. @Override
  127. public String getGiveCommand() {
  128. return technical.giveCommand;
  129. }
  130. @Override
  131. public String getWeatherCommand() {
  132. return technical.weatherCommand;
  133. }
  134. @Override
  135. public int getMaxRecipePerPage() {
  136. return appearance.maxRecipePerPage;
  137. }
  138. @Override
  139. public boolean doesShowUtilsButtons() {
  140. return modules.showUtilsButtons;
  141. }
  142. @Override
  143. public boolean doesDisableRecipeBook() {
  144. return modules.disableRecipeBook;
  145. }
  146. @Override
  147. public boolean doesFixTabCloseContainer() {
  148. return modules.fixTabCloseContainer;
  149. }
  150. @Override
  151. public boolean areClickableRecipeArrowsEnabled() {
  152. return appearance.clickableRecipeArrows;
  153. }
  154. @Override
  155. public RecipeBorderType getRecipeBorderType() {
  156. return appearance.recipeBorder;
  157. }
  158. @Override
  159. public boolean doesVillagerScreenHavePermanentScrollBar() {
  160. return appearance.villagerScreenPermanentScrollBar;
  161. }
  162. @Override
  163. public boolean doesRegisterRecipesInAnotherThread() {
  164. return technical.registerRecipesInAnotherThread;
  165. }
  166. @Override
  167. public boolean doesSnapToRows() {
  168. return appearance.snapToRows;
  169. }
  170. @Override
  171. public boolean isFavoritesEnabled() {
  172. return general.favoritesEnabled;
  173. }
  174. @Override
  175. public boolean doDisplayFavoritesTooltip() {
  176. return isFavoritesEnabled() && appearance.displayFavoritesTooltip;
  177. }
  178. @Override
  179. public boolean doDisplayFavoritesOnTheLeft() {
  180. return appearance.displayFavoritesOnTheLeft;
  181. }
  182. @Override
  183. public boolean doesFastEntryRendering() {
  184. return performance.newFastEntryRendering;
  185. }
  186. @Override
  187. public boolean doDebugRenderTimeRequired() {
  188. return technical.debugRenderTimeRequired;
  189. }
  190. @Override
  191. public boolean doSearchFavorites() {
  192. return appearance.searchFavorites;
  193. }
  194. @Override
  195. public ModifierKeyCode getFavoriteKeyCode() {
  196. return general.favoriteKeybind == null ? ModifierKeyCode.unknown() : general.favoriteKeybind;
  197. }
  198. @Override
  199. public ModifierKeyCode getRecipeKeybind() {
  200. return general.recipeKeybind == null ? ModifierKeyCode.unknown() : general.recipeKeybind;
  201. }
  202. @Override
  203. public ModifierKeyCode getUsageKeybind() {
  204. return general.usageKeybind == null ? ModifierKeyCode.unknown() : general.usageKeybind;
  205. }
  206. @Override
  207. public ModifierKeyCode getHideKeybind() {
  208. return general.hideKeybind == null ? ModifierKeyCode.unknown() : general.hideKeybind;
  209. }
  210. @Override
  211. public ModifierKeyCode getPreviousPageKeybind() {
  212. return general.previousPageKeybind == null ? ModifierKeyCode.unknown() : general.previousPageKeybind;
  213. }
  214. @Override
  215. public ModifierKeyCode getNextPageKeybind() {
  216. return general.nextPageKeybind == null ? ModifierKeyCode.unknown() : general.nextPageKeybind;
  217. }
  218. @Override
  219. public ModifierKeyCode getFocusSearchFieldKeybind() {
  220. return general.focusSearchFieldKeybind == null ? ModifierKeyCode.unknown() : general.focusSearchFieldKeybind;
  221. }
  222. @Override
  223. public ModifierKeyCode getCopyRecipeIdentifierKeybind() {
  224. return general.copyRecipeIdentifierKeybind == null ? ModifierKeyCode.unknown() : general.copyRecipeIdentifierKeybind;
  225. }
  226. @Override
  227. public ModifierKeyCode getExportImageKeybind() {
  228. return general.exportImageKeybind == null ? ModifierKeyCode.unknown() : general.exportImageKeybind;
  229. }
  230. @Override
  231. public double getEntrySize() {
  232. return appearance.entrySize;
  233. }
  234. @Deprecated
  235. @Override
  236. public General getGeneral() {
  237. return general;
  238. }
  239. @Override
  240. public boolean isUsingCompactTabs() {
  241. return appearance.useCompactTabs;
  242. }
  243. @Override
  244. public boolean isLowerConfigButton() {
  245. return appearance.lowerConfigButton;
  246. }
  247. @Override
  248. public List<EntryStack> getFavorites() {
  249. return general.favorites;
  250. }
  251. @Override
  252. public List<EntryStack> getFilteredStacks() {
  253. return filtering.filteredStacks;
  254. }
  255. @Override
  256. @ApiStatus.Experimental
  257. public boolean shouldAsyncSearch() {
  258. return performance.asyncSearch;
  259. }
  260. @Override
  261. @ApiStatus.Experimental
  262. public int getNumberAsyncSearch() {
  263. return performance.numberAsyncSearch;
  264. }
  265. @Override
  266. @ApiStatus.Experimental
  267. public boolean doDebugSearchTimeRequired() {
  268. return technical.debugSearchTimeRequired;
  269. }
  270. @Retention(RetentionPolicy.RUNTIME)
  271. @Target({ElementType.FIELD})
  272. @interface DontApplyFieldName {}
  273. @Retention(RetentionPolicy.RUNTIME)
  274. @Target({ElementType.FIELD})
  275. @interface UseEnumSelectorInstead {}
  276. @Retention(RetentionPolicy.RUNTIME)
  277. @Target({ElementType.FIELD})
  278. @interface UseSpecialRecipeTypeScreen {}
  279. @Retention(RetentionPolicy.RUNTIME)
  280. @Target({ElementType.FIELD})
  281. @interface UseFilteringScreen {}
  282. @Retention(RetentionPolicy.RUNTIME)
  283. @Target({ElementType.FIELD})
  284. @interface UsePercentage {
  285. double min();
  286. double max();
  287. }
  288. public static class General {
  289. @ConfigEntry.Gui.Excluded public List<EntryStack> favorites = new ArrayList<>();
  290. @Comment("Declares whether cheating mode is on.") private boolean cheating = false;
  291. @Comment("Declares whether REI is visible.") @ConfigEntry.Gui.Excluded private boolean overlayVisible = true;
  292. private boolean favoritesEnabled = true;
  293. private ModifierKeyCode recipeKeybind = ModifierKeyCode.of(InputUtil.Type.KEYSYM.createFromCode(82), Modifier.none());
  294. private ModifierKeyCode usageKeybind = ModifierKeyCode.of(InputUtil.Type.KEYSYM.createFromCode(85), Modifier.none());
  295. private ModifierKeyCode hideKeybind = ModifierKeyCode.of(InputUtil.Type.KEYSYM.createFromCode(79), Modifier.of(false, true, false));
  296. private ModifierKeyCode previousPageKeybind = ModifierKeyCode.unknown();
  297. private ModifierKeyCode nextPageKeybind = ModifierKeyCode.unknown();
  298. private ModifierKeyCode focusSearchFieldKeybind = ModifierKeyCode.unknown();
  299. private ModifierKeyCode copyRecipeIdentifierKeybind = ModifierKeyCode.unknown();
  300. private ModifierKeyCode favoriteKeybind = ModifierKeyCode.of(InputUtil.Type.KEYSYM.createFromCode(65), Modifier.none());
  301. @ConfigEntry.Gui.Excluded private ModifierKeyCode exportImageKeybind = ModifierKeyCode.unknown();
  302. }
  303. public static class Appearance {
  304. @UseSpecialRecipeTypeScreen private RecipeScreenType recipeScreenType = RecipeScreenType.UNSET;
  305. @Comment("Declares the appearance of REI windows.") private boolean darkTheme = false;
  306. @Comment("The ordering of the items on the item panel.") @UseEnumSelectorInstead
  307. private ItemListOrderingConfig itemListOrdering = ItemListOrderingConfig.REGISTRY_ASCENDING;
  308. @Comment("Declares the position of the search field.") @UseEnumSelectorInstead
  309. private SearchFieldLocation searchFieldLocation = SearchFieldLocation.CENTER;
  310. @Comment("Declares the position of the item list panel.") private boolean mirrorItemPanel = false;
  311. @Comment("Declares the maximum amount of recipes displayed in a page if possible.") @ConfigEntry.BoundedDiscrete(min = 2, max = 99)
  312. private int maxRecipePerPage = 3;
  313. private boolean clickableRecipeArrows = true;
  314. @Comment("Declares the appearance of recipe's border.") @UseEnumSelectorInstead private RecipeBorderType recipeBorder = RecipeBorderType.DEFAULT;
  315. @Comment("Declares whether REI should append mod names to item stacks.") private boolean appendModNames = true;
  316. @Comment("Declares how the scrollbar in villager screen should act.") private boolean villagerScreenPermanentScrollBar = false;
  317. @Comment("Declares whether entry list widget is scrolled.") private boolean scrollingEntryListWidget = false;
  318. @Comment("Declares whether scrolled entry list widget should snap to rows.") private boolean snapToRows = false;
  319. @Comment("Declares the location of the favorites list.") private boolean displayFavoritesOnTheLeft = true;
  320. @Comment("Declares whether favorites tooltip should be displayed.") private boolean displayFavoritesTooltip = false;
  321. @Comment("Declares whether favorites will be searched.") private boolean searchFavorites = true;
  322. @UsePercentage(min = 0.25, max = 4.0) private double entrySize = 1.0;
  323. private boolean useCompactTabs = true;
  324. private boolean lowerConfigButton = false;
  325. }
  326. public static class Technical {
  327. @Comment("To disable REI's default plugin.\nDon't change this unless you understand what you are doing!") private boolean loadDefaultPlugin = true;
  328. @Comment("Declares the command used to change gamemode.") private String gamemodeCommand = "/gamemode {gamemode}";
  329. @Comment("Declares the command used in servers to cheat items.") private String giveCommand = "/give {player_name} {item_identifier}{nbt} {count}";
  330. @Comment("Declares the command used to change weather.") private String weatherCommand = "/weather {weather}";
  331. private boolean registerRecipesInAnotherThread = true;
  332. private boolean debugRenderTimeRequired = false;
  333. @Comment("Experimental: Declares whether search time should be debugged.") private boolean debugSearchTimeRequired = false;
  334. }
  335. public static class Modules {
  336. @Comment("Declares whether the craftable filter button is enabled.") private boolean enableCraftableOnlyButton = true;
  337. private boolean toastDisplayedOnCopyIdentifier = true;
  338. @Comment("Declares whether the utils buttons are shown.") private boolean showUtilsButtons = false;
  339. @Comment("Declares whether REI should remove the recipe book.") private boolean disableRecipeBook = false;
  340. @Comment("Declares whether REI should fix closing container with tab.") private boolean fixTabCloseContainer = false;
  341. }
  342. public static class Performance {
  343. @Comment("Whether REI should render entry's enchantment glint") private boolean renderEntryEnchantmentGlint = true;
  344. private boolean newFastEntryRendering = true;
  345. @Comment("Experimental: Declares whether REI should search async.") private boolean asyncSearch = true;
  346. @Comment("Experimental: Declares how many entries should be grouped one async search.") @ConfigEntry.BoundedDiscrete(min = 25, max = 400)
  347. private int numberAsyncSearch = 50;
  348. }
  349. public static class Filtering {
  350. @UseFilteringScreen private List<EntryStack> filteredStacks = new ArrayList<>();
  351. }
  352. }