ConfigObjectImpl.java 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477
  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.filtering.FilteringRule;
  34. import net.fabricmc.api.EnvType;
  35. import net.fabricmc.api.Environment;
  36. import net.minecraft.client.util.InputUtil;
  37. import org.jetbrains.annotations.ApiStatus;
  38. import java.lang.annotation.ElementType;
  39. import java.lang.annotation.Retention;
  40. import java.lang.annotation.RetentionPolicy;
  41. import java.lang.annotation.Target;
  42. import java.util.ArrayList;
  43. import java.util.List;
  44. @ApiStatus.Internal
  45. @Config(name = "roughlyenoughitems/config")
  46. @Environment(EnvType.CLIENT)
  47. public class ConfigObjectImpl implements ConfigObject, ConfigData {
  48. @ConfigEntry.Category("basics") @ConfigEntry.Gui.TransitiveObject @DontApplyFieldName
  49. public Basics basics = new Basics();
  50. @ConfigEntry.Category("appearance") @ConfigEntry.Gui.TransitiveObject @DontApplyFieldName
  51. private Appearance appearance = new Appearance();
  52. @ConfigEntry.Category("functionality") @ConfigEntry.Gui.TransitiveObject @DontApplyFieldName
  53. private Functionality functionality = new Functionality();
  54. @ConfigEntry.Category("advanced") @ConfigEntry.Gui.TransitiveObject @DontApplyFieldName
  55. public Advanced advanced = new Advanced();
  56. @Override
  57. public boolean isOverlayVisible() {
  58. return basics.overlayVisible;
  59. }
  60. @Override
  61. public void setOverlayVisible(boolean overlayVisible) {
  62. basics.overlayVisible = overlayVisible;
  63. }
  64. @Override
  65. public boolean isCheating() {
  66. return basics.cheating;
  67. }
  68. @Override
  69. public void setCheating(boolean cheating) {
  70. basics.cheating = cheating;
  71. }
  72. @Override
  73. public EntryPanelOrdering getItemListOrdering() {
  74. return advanced.layout.entryPanelOrdering.getOrdering();
  75. }
  76. @Override
  77. public boolean isItemListAscending() {
  78. return advanced.layout.entryPanelOrdering.isAscending();
  79. }
  80. @Override
  81. public boolean isUsingDarkTheme() {
  82. return appearance.theme == AppearanceTheme.DARK;
  83. }
  84. @Override
  85. public boolean isGrabbingItems() {
  86. return basics.cheatingStyle == ItemCheatingStyle.GRAB;
  87. }
  88. @Override
  89. public boolean isToastDisplayedOnCopyIdentifier() {
  90. return advanced.accessibility.toastDisplayedOnCopyIdentifier;
  91. }
  92. @Override
  93. public boolean doesRenderEntryEnchantmentGlint() {
  94. return advanced.miscellaneous.renderEntryEnchantmentGlint;
  95. }
  96. @Override
  97. public boolean isEntryListWidgetScrolled() {
  98. return appearance.scrollingEntryListWidget;
  99. }
  100. @Override
  101. public boolean shouldAppendModNames() {
  102. return advanced.tooltips.appendModNames;
  103. }
  104. @Override
  105. public RecipeScreenType getRecipeScreenType() {
  106. return appearance.recipeScreenType;
  107. }
  108. @Override
  109. public void setRecipeScreenType(RecipeScreenType recipeScreenType) {
  110. appearance.recipeScreenType = recipeScreenType;
  111. }
  112. @Override
  113. public boolean isLoadingDefaultPlugin() {
  114. return advanced.miscellaneous.loadDefaultPlugin;
  115. }
  116. @Override
  117. public SearchFieldLocation getSearchFieldLocation() {
  118. return appearance.layout.searchFieldLocation;
  119. }
  120. @Override
  121. public DisplayPanelLocation getDisplayPanelLocation() {
  122. return advanced.accessibility.displayPanelLocation;
  123. }
  124. @Override
  125. public boolean isCraftableFilterEnabled() {
  126. return appearance.layout.enableCraftableOnlyButton;
  127. }
  128. @Override
  129. public String getGamemodeCommand() {
  130. return advanced.commands.gamemodeCommand;
  131. }
  132. @Override
  133. public String getGiveCommand() {
  134. return advanced.commands.giveCommand;
  135. }
  136. @Override
  137. public String getWeatherCommand() {
  138. return advanced.commands.weatherCommand;
  139. }
  140. @Override
  141. public int getMaxRecipePerPage() {
  142. return advanced.layout.maxRecipesPerPage;
  143. }
  144. @Override
  145. public boolean doesShowUtilsButtons() {
  146. return appearance.layout.showUtilsButtons;
  147. }
  148. @Override
  149. public boolean doesDisableRecipeBook() {
  150. return functionality.disableRecipeBook;
  151. }
  152. @Override
  153. public boolean doesFixTabCloseContainer() {
  154. return functionality.disableRecipeBook;
  155. }
  156. @Override
  157. public boolean areClickableRecipeArrowsEnabled() {
  158. return advanced.miscellaneous.clickableRecipeArrows;
  159. }
  160. @Override
  161. public RecipeBorderType getRecipeBorderType() {
  162. return appearance.recipeBorder;
  163. }
  164. @Override
  165. public boolean doesVillagerScreenHavePermanentScrollBar() {
  166. return advanced.accessibility.villagerScreenPermanentScrollBar;
  167. }
  168. @Override
  169. public boolean doesRegisterRecipesInAnotherThread() {
  170. return advanced.miscellaneous.registerRecipesInAnotherThread;
  171. }
  172. @Override
  173. public boolean doesSnapToRows() {
  174. return advanced.accessibility.snapToRows;
  175. }
  176. @Override
  177. public boolean isFavoritesEnabled() {
  178. return basics.favoritesEnabled;
  179. }
  180. @Override
  181. public boolean doDisplayFavoritesTooltip() {
  182. return isFavoritesEnabled() && advanced.tooltips.displayFavoritesTooltip;
  183. }
  184. @Override
  185. public boolean doesFastEntryRendering() {
  186. return advanced.miscellaneous.newFastEntryRendering;
  187. }
  188. @Override
  189. public boolean doDebugRenderTimeRequired() {
  190. return advanced.layout.debugRenderTimeRequired;
  191. }
  192. @Override
  193. public boolean doSearchFavorites() {
  194. return advanced.search.searchFavorites;
  195. }
  196. @Override
  197. public ModifierKeyCode getFavoriteKeyCode() {
  198. return basics.keyBindings.favoriteKeybind == null ? ModifierKeyCode.unknown() : basics.keyBindings.favoriteKeybind;
  199. }
  200. @Override
  201. public ModifierKeyCode getRecipeKeybind() {
  202. return basics.keyBindings.recipeKeybind == null ? ModifierKeyCode.unknown() : basics.keyBindings.recipeKeybind;
  203. }
  204. @Override
  205. public ModifierKeyCode getUsageKeybind() {
  206. return basics.keyBindings.usageKeybind == null ? ModifierKeyCode.unknown() : basics.keyBindings.usageKeybind;
  207. }
  208. @Override
  209. public ModifierKeyCode getHideKeybind() {
  210. return basics.keyBindings.hideKeybind == null ? ModifierKeyCode.unknown() : basics.keyBindings.hideKeybind;
  211. }
  212. @Override
  213. public ModifierKeyCode getPreviousPageKeybind() {
  214. return basics.keyBindings.previousPageKeybind == null ? ModifierKeyCode.unknown() : basics.keyBindings.previousPageKeybind;
  215. }
  216. @Override
  217. public ModifierKeyCode getNextPageKeybind() {
  218. return basics.keyBindings.nextPageKeybind == null ? ModifierKeyCode.unknown() : basics.keyBindings.nextPageKeybind;
  219. }
  220. @Override
  221. public ModifierKeyCode getFocusSearchFieldKeybind() {
  222. return basics.keyBindings.focusSearchFieldKeybind == null ? ModifierKeyCode.unknown() : basics.keyBindings.focusSearchFieldKeybind;
  223. }
  224. @Override
  225. public ModifierKeyCode getCopyRecipeIdentifierKeybind() {
  226. return basics.keyBindings.copyRecipeIdentifierKeybind == null ? ModifierKeyCode.unknown() : basics.keyBindings.copyRecipeIdentifierKeybind;
  227. }
  228. @Override
  229. public ModifierKeyCode getExportImageKeybind() {
  230. return basics.keyBindings.exportImageKeybind == null ? ModifierKeyCode.unknown() : basics.keyBindings.exportImageKeybind;
  231. }
  232. @Override
  233. public double getEntrySize() {
  234. return advanced.accessibility.entrySize;
  235. }
  236. @Override
  237. public boolean isUsingCompactTabs() {
  238. return advanced.accessibility.useCompactTabs;
  239. }
  240. @Override
  241. public boolean isLowerConfigButton() {
  242. return appearance.layout.configButtonLocation == ConfigButtonPosition.LOWER;
  243. }
  244. @Override
  245. public List<EntryStack> getFavorites() {
  246. return basics.favorites;
  247. }
  248. @Override
  249. public List<EntryStack> getFilteredStacks() {
  250. return advanced.filtering.filteredStacks;
  251. }
  252. @Override
  253. public List<FilteringRule<?>> getFilteringRules() {
  254. return advanced.filtering.filteringRules;
  255. }
  256. @Override
  257. @ApiStatus.Experimental
  258. public boolean shouldAsyncSearch() {
  259. return advanced.search.asyncSearch;
  260. }
  261. @Override
  262. @ApiStatus.Experimental
  263. public int getNumberAsyncSearch() {
  264. return advanced.search.numberAsyncSearch;
  265. }
  266. @Override
  267. @ApiStatus.Experimental
  268. public boolean doDebugSearchTimeRequired() {
  269. return advanced.search.debugSearchTimeRequired;
  270. }
  271. @Override
  272. @ApiStatus.Experimental
  273. public boolean isSubsetsEnabled() {
  274. return functionality.isSubsetsEnabled;
  275. }
  276. @Override
  277. public boolean shouldResizeDynamically() {
  278. return advanced.accessibility.resizeDynamically;
  279. }
  280. @Retention(RetentionPolicy.RUNTIME)
  281. @Target({ElementType.FIELD})
  282. @interface DontApplyFieldName {}
  283. @Retention(RetentionPolicy.RUNTIME)
  284. @Target({ElementType.FIELD})
  285. @interface UseSpecialRecipeTypeScreen {}
  286. @Retention(RetentionPolicy.RUNTIME)
  287. @Target({ElementType.FIELD})
  288. @interface UseFilteringScreen {}
  289. @Retention(RetentionPolicy.RUNTIME)
  290. @Target({ElementType.FIELD})
  291. @interface UsePercentage {
  292. double min();
  293. double max();
  294. }
  295. public static class Basics {
  296. @ConfigEntry.Gui.Excluded public List<EntryStack> favorites = new ArrayList<>();
  297. @Comment("Declares whether cheating mode is on.") private boolean cheating = false;
  298. private boolean favoritesEnabled = true;
  299. @ConfigEntry.Gui.CollapsibleObject(startExpanded = true)
  300. private KeyBindings keyBindings = new KeyBindings();
  301. @Comment("Declares whether REI is visible.") @ConfigEntry.Gui.Excluded private boolean overlayVisible = true;
  302. @ConfigEntry.Gui.EnumHandler(option = ConfigEntry.Gui.EnumHandler.EnumDisplayOption.BUTTON)
  303. private ItemCheatingStyle cheatingStyle = ItemCheatingStyle.GRAB;
  304. }
  305. public static class KeyBindings {
  306. private ModifierKeyCode recipeKeybind = ModifierKeyCode.of(InputUtil.Type.KEYSYM.createFromCode(82), Modifier.none());
  307. private ModifierKeyCode usageKeybind = ModifierKeyCode.of(InputUtil.Type.KEYSYM.createFromCode(85), Modifier.none());
  308. private ModifierKeyCode hideKeybind = ModifierKeyCode.of(InputUtil.Type.KEYSYM.createFromCode(79), Modifier.of(false, true, false));
  309. private ModifierKeyCode previousPageKeybind = ModifierKeyCode.unknown();
  310. private ModifierKeyCode nextPageKeybind = ModifierKeyCode.unknown();
  311. private ModifierKeyCode focusSearchFieldKeybind = ModifierKeyCode.unknown();
  312. private ModifierKeyCode copyRecipeIdentifierKeybind = ModifierKeyCode.unknown();
  313. private ModifierKeyCode favoriteKeybind = ModifierKeyCode.of(InputUtil.Type.KEYSYM.createFromCode(65), Modifier.none());
  314. private ModifierKeyCode exportImageKeybind = ModifierKeyCode.unknown();
  315. }
  316. public static class Appearance {
  317. @UseSpecialRecipeTypeScreen private RecipeScreenType recipeScreenType = RecipeScreenType.UNSET;
  318. @Comment("Declares the appearance of REI windows.") @ConfigEntry.Gui.EnumHandler(option = ConfigEntry.Gui.EnumHandler.EnumDisplayOption.BUTTON)
  319. private AppearanceTheme theme = AppearanceTheme.LIGHT;
  320. @ConfigEntry.Gui.CollapsibleObject(startExpanded = true)
  321. private Layout layout = new Layout();
  322. @Comment("Declares the appearance of recipe's border.") @ConfigEntry.Gui.EnumHandler(option = ConfigEntry.Gui.EnumHandler.EnumDisplayOption.BUTTON)
  323. private RecipeBorderType recipeBorder = RecipeBorderType.DEFAULT;
  324. @Comment("Declares whether entry panel is scrolled.") private boolean scrollingEntryListWidget = false;
  325. public static class Layout {
  326. @Comment("Declares the position of the search field.") @ConfigEntry.Gui.EnumHandler(option = ConfigEntry.Gui.EnumHandler.EnumDisplayOption.BUTTON)
  327. private SearchFieldLocation searchFieldLocation = SearchFieldLocation.CENTER;
  328. @Comment("Declares the position of the config button.") @ConfigEntry.Gui.EnumHandler(option = ConfigEntry.Gui.EnumHandler.EnumDisplayOption.BUTTON)
  329. private ConfigButtonPosition configButtonLocation = ConfigButtonPosition.LOWER;
  330. @Comment("Declares whether the craftable filter button is enabled.") private boolean enableCraftableOnlyButton = false;
  331. @Comment("Declares whether the utils buttons are shown.") private boolean showUtilsButtons = false;
  332. }
  333. }
  334. public static class Functionality {
  335. @Comment("Declares whether REI should remove the recipe book.") private boolean disableRecipeBook = false;
  336. @Comment("Declares whether subsets is enabled.") private boolean isSubsetsEnabled = false;
  337. }
  338. public static class Advanced {
  339. @ConfigEntry.Gui.CollapsibleObject
  340. private Tooltips tooltips = new Tooltips();
  341. @ConfigEntry.Gui.CollapsibleObject
  342. private Layout layout = new Layout();
  343. @ConfigEntry.Gui.CollapsibleObject
  344. private Accessibility accessibility = new Accessibility();
  345. @ConfigEntry.Gui.CollapsibleObject
  346. private Search search = new Search();
  347. @ConfigEntry.Gui.CollapsibleObject
  348. private Commands commands = new Commands();
  349. @ConfigEntry.Gui.CollapsibleObject
  350. private Miscellaneous miscellaneous = new Miscellaneous();
  351. @ConfigEntry.Gui.CollapsibleObject(startExpanded = true)
  352. public Filtering filtering = new Filtering();
  353. public static class Tooltips {
  354. @Comment("Declares whether REI should append mod names to entries.") private boolean appendModNames = true;
  355. @Comment("Declares whether favorites tooltip should be displayed.") private boolean displayFavoritesTooltip = false;
  356. }
  357. public static class Layout {
  358. @Comment("The ordering of the items on the entry panel.")
  359. @ConfigEntry.Gui.EnumHandler(option = ConfigEntry.Gui.EnumHandler.EnumDisplayOption.BUTTON)
  360. private EntryPanelOrderingConfig entryPanelOrdering = EntryPanelOrderingConfig.REGISTRY_ASCENDING;
  361. @Comment("Declares the maximum amount of recipes displayed in a page if possible.") @ConfigEntry.BoundedDiscrete(min = 2, max = 99)
  362. private int maxRecipesPerPage = 15;
  363. @Comment("Declares whether entry rendering time should be debugged.") private boolean debugRenderTimeRequired = false;
  364. }
  365. public static class Accessibility {
  366. @UsePercentage(min = 0.25, max = 4.0) private double entrySize = 1.0;
  367. @Comment("Declares the position of the entry panel.") @ConfigEntry.Gui.EnumHandler(option = ConfigEntry.Gui.EnumHandler.EnumDisplayOption.BUTTON)
  368. private DisplayPanelLocation displayPanelLocation = DisplayPanelLocation.RIGHT;
  369. @Comment("Declares whether scrolled entry panel should snap to rows.") private boolean snapToRows = false;
  370. @Comment("Declares how the scrollbar in villager screen should act.") private boolean villagerScreenPermanentScrollBar = false;
  371. private boolean toastDisplayedOnCopyIdentifier = true;
  372. @Comment("Declares whether REI should use compact tabs for categories.") private boolean useCompactTabs = true;
  373. @Comment("Declares whether REI should resize its recipe window dynamically") private boolean resizeDynamically = false;
  374. }
  375. public static class Search {
  376. @Comment("Declares whether favorites will be searched.") private boolean searchFavorites = true;
  377. @Comment("Declares whether search time should be debugged.") private boolean debugSearchTimeRequired = false;
  378. @Comment("Declares whether REI should search async.") private boolean asyncSearch = true;
  379. @Comment("Declares how many entries should be grouped one async search.") @ConfigEntry.BoundedDiscrete(min = 25, max = 400)
  380. private int numberAsyncSearch = 50;
  381. }
  382. public static class Commands {
  383. @Comment("Declares the command used to change gamemode.") private String gamemodeCommand = "/gamemode {gamemode}";
  384. @Comment("Declares the command used in servers to cheat items.") private String giveCommand = "/give {player_name} {item_identifier}{nbt} {count}";
  385. @Comment("Declares the command used to change weather.") private String weatherCommand = "/weather {weather}";
  386. }
  387. public static class Miscellaneous {
  388. @Comment("Declares whether arrows in containers should be clickable.") private boolean clickableRecipeArrows = true;
  389. @Comment("To disable REI's default plugin.\nDon't change this unless you understand what you are doing!") private boolean loadDefaultPlugin = true;
  390. private boolean registerRecipesInAnotherThread = true;
  391. @Comment("Whether REI should render entry's enchantment glint") private boolean renderEntryEnchantmentGlint = true;
  392. private boolean newFastEntryRendering = true;
  393. }
  394. public static class Filtering {
  395. @UseFilteringScreen private List<EntryStack> filteredStacks = new ArrayList<>();
  396. @ConfigEntry.Gui.Excluded public List<FilteringRule<?>> filteringRules = new ArrayList<>();
  397. }
  398. }
  399. }