Unknown 5 years ago
parent
commit
9a464562ba

+ 2 - 1
src/main/java/me/shedaniel/rei/api/ConfigObject.java

@@ -8,6 +8,7 @@ package me.shedaniel.rei.api;
 import me.shedaniel.rei.gui.config.ItemCheatingMode;
 import me.shedaniel.rei.gui.config.ItemListOrdering;
 import me.shedaniel.rei.gui.config.RecipeScreenType;
+import me.shedaniel.rei.gui.config.SearchFieldLocation;
 import me.zeroeightsix.fiber.tree.ConfigNode;
 
 public interface ConfigObject {
@@ -34,7 +35,7 @@ public interface ConfigObject {
     
     boolean isLoadingDefaultPlugin();
     
-    boolean isSideSearchField();
+    SearchFieldLocation getSearchFieldLocation();
     
     boolean isLeftHandSidePanel();
     

+ 2 - 1
src/main/java/me/shedaniel/rei/api/DisplayHelper.java

@@ -7,6 +7,7 @@ package me.shedaniel.rei.api;
 
 import me.shedaniel.math.api.Rectangle;
 import me.shedaniel.rei.RoughlyEnoughItemsCore;
+import me.shedaniel.rei.gui.config.SearchFieldLocation;
 import net.minecraft.util.ActionResult;
 
 import java.util.List;
@@ -112,7 +113,7 @@ public interface DisplayHelper {
          * @return the item list bounds
          */
         default Rectangle getItemListArea(Rectangle rectangle) {
-            return new Rectangle(rectangle.x + 1, rectangle.y + 2 + (RoughlyEnoughItemsCore.getConfigManager().getConfig().isEntryListWidgetScrolled() ? 0 : 22), rectangle.width - 2, rectangle.height - (RoughlyEnoughItemsCore.getConfigManager().getConfig().isSideSearchField() ? 27 + 22 : 27) + (!RoughlyEnoughItemsCore.getConfigManager().getConfig().isEntryListWidgetScrolled() ? 0 : 22));
+            return new Rectangle(rectangle.x + 1, rectangle.y + 2 + (RoughlyEnoughItemsCore.getConfigManager().getConfig().getSearchFieldLocation() == SearchFieldLocation.TOP_SIDE ? 24 : 0) + (RoughlyEnoughItemsCore.getConfigManager().getConfig().isEntryListWidgetScrolled() ? 0 : 22), rectangle.width - 2, rectangle.height - (RoughlyEnoughItemsCore.getConfigManager().getConfig().getSearchFieldLocation() != SearchFieldLocation.CENTER ? 27 + 22 : 27) + (!RoughlyEnoughItemsCore.getConfigManager().getConfig().isEntryListWidgetScrolled() ? 0 : 22));
         }
         
         /**

+ 5 - 1
src/main/java/me/shedaniel/rei/gui/ContainerScreenOverlay.java

@@ -15,6 +15,7 @@ import me.shedaniel.rei.api.ClientHelper;
 import me.shedaniel.rei.api.DisplayHelper;
 import me.shedaniel.rei.api.Entry;
 import me.shedaniel.rei.api.RecipeHelper;
+import me.shedaniel.rei.gui.config.SearchFieldLocation;
 import me.shedaniel.rei.gui.widget.*;
 import me.shedaniel.rei.impl.RecipeHelperImpl;
 import me.shedaniel.rei.impl.ScreenHelper;
@@ -327,8 +328,11 @@ public class ContainerScreenOverlay extends Widget {
     
     private Rectangle getTextFieldArea() {
         int widthRemoved = RoughlyEnoughItemsCore.getConfigManager().getConfig().isCraftableFilterEnabled() ? 22 : 2;
-        if (RoughlyEnoughItemsCore.getConfigManager().getConfig().isSideSearchField())
+        SearchFieldLocation searchFieldLocation = RoughlyEnoughItemsCore.getConfigManager().getConfig().getSearchFieldLocation();
+        if (searchFieldLocation == SearchFieldLocation.BOTTOM_SIDE)
             return new Rectangle(rectangle.x + 2, window.getScaledHeight() - 22, rectangle.width - 6 - widthRemoved, 18);
+        if (searchFieldLocation == SearchFieldLocation.TOP_SIDE)
+            return new Rectangle(rectangle.x + 2, 4, rectangle.width - 6 - widthRemoved, 18);
         if (MinecraftClient.getInstance().currentScreen instanceof RecipeViewingScreen) {
             RecipeViewingScreen widget = (RecipeViewingScreen) MinecraftClient.getInstance().currentScreen;
             return new Rectangle(widget.getBounds().x, window.getScaledHeight() - 22, widget.getBounds().width - widthRemoved, 18);

+ 19 - 0
src/main/java/me/shedaniel/rei/gui/config/SearchFieldLocation.java

@@ -0,0 +1,19 @@
+/*
+ * Roughly Enough Items by Danielshe.
+ * Licensed under the MIT License.
+ */
+
+package me.shedaniel.rei.gui.config;
+
+import net.minecraft.client.resource.language.I18n;
+
+import java.util.Locale;
+
+public enum SearchFieldLocation {
+    CENTER, BOTTOM_SIDE, TOP_SIDE;
+    
+    @Override
+    public String toString() {
+        return I18n.translate("config.roughlyenoughitems.searchFieldLocation.%s", name().toLowerCase(Locale.ROOT));
+    }
+}

+ 6 - 9
src/main/java/me/shedaniel/rei/impl/ConfigObjectImpl.java

@@ -6,10 +6,7 @@
 package me.shedaniel.rei.impl;
 
 import me.shedaniel.rei.api.ConfigObject;
-import me.shedaniel.rei.gui.config.ItemCheatingMode;
-import me.shedaniel.rei.gui.config.ItemListOrdering;
-import me.shedaniel.rei.gui.config.ItemListOrderingConfig;
-import me.shedaniel.rei.gui.config.RecipeScreenType;
+import me.shedaniel.rei.gui.config.*;
 import me.zeroeightsix.fiber.exception.FiberException;
 import me.zeroeightsix.fiber.tree.ConfigNode;
 import me.zeroeightsix.fiber.tree.ConfigValue;
@@ -59,11 +56,11 @@ public class ConfigObjectImpl implements ConfigObject {
             .withName("loadDefaultPlugin")
             .build();
     
-    private ConfigValue<Boolean> sideSearchField = ConfigValue.builder(Boolean.class)
+    private ConfigValue<SearchFieldLocation> sideSearchField = ConfigValue.builder(SearchFieldLocation.class)
             .withParent(appearance)
-            .withDefaultValue(false)
+            .withDefaultValue(SearchFieldLocation.CENTER)
             .withComment("Declares the position of the search field.")
-            .withName("sideSearchField")
+            .withName("searchFieldLocation")
             .build();
     
     private ConfigValue<Boolean> mirrorItemPanel = ConfigValue.builder(Boolean.class)
@@ -238,8 +235,8 @@ public class ConfigObjectImpl implements ConfigObject {
     }
     
     @Override
-    public boolean isSideSearchField() {
-        return sideSearchField.getValue().booleanValue();
+    public SearchFieldLocation getSearchFieldLocation() {
+        return sideSearchField.getValue();
     }
     
     @Override

+ 9 - 0
src/main/java/me/shedaniel/rei/utils/ClothScreenRegistry.java

@@ -12,6 +12,7 @@ import me.shedaniel.rei.api.ConfigManager;
 import me.shedaniel.rei.gui.config.ItemCheatingMode;
 import me.shedaniel.rei.gui.config.ItemListOrderingConfig;
 import me.shedaniel.rei.gui.config.RecipeScreenType;
+import me.shedaniel.rei.gui.config.SearchFieldLocation;
 import me.zeroeightsix.fiber.exception.FiberException;
 import me.zeroeightsix.fiber.tree.ConfigValue;
 import net.minecraft.client.gui.screen.Screen;
@@ -57,6 +58,14 @@ public class ClothScreenRegistry {
                     .setSaveConsumer(var -> configValue.setValue((ItemCheatingMode) var))
                     .setErrorSupplier(var -> error((List) configValue.getConstraints(), var, ItemCheatingMode.class))
                     .build();
+        }).registerConfigEntryFunction(SearchFieldLocation.class, o -> {
+            ConfigValue<SearchFieldLocation> configValue = (ConfigValue<SearchFieldLocation>) o;
+            return configEntryBuilder.startEnumSelector("config.roughlyenoughitems." + configValue.getName(), SearchFieldLocation.class, configValue.getValue())
+                    .setDefaultValue(configValue.getDefaultValue())
+                    .setTooltip(splitLine(configValue.getComment()))
+                    .setSaveConsumer(var -> configValue.setValue((SearchFieldLocation) var))
+                    .setErrorSupplier(var -> error((List) configValue.getConstraints(), var, SearchFieldLocation.class))
+                    .build();
         }).build().getScreen();
     }
     

+ 4 - 3
src/main/resources/assets/roughlyenoughitems/lang/en_us.json

@@ -96,9 +96,10 @@
   "config.roughlyenoughitems.mirrorItemPanel": "Item List Position:",
   "config.roughlyenoughitems.mirrorItemPanel.boolean.true": "Left Side",
   "config.roughlyenoughitems.mirrorItemPanel.boolean.false": "Right Side",
-  "config.roughlyenoughitems.sideSearchField": "Search Field Position:",
-  "config.roughlyenoughitems.sideSearchField.boolean.true": "Left / Right Side",
-  "config.roughlyenoughitems.sideSearchField.boolean.false": "Middle",
+  "config.roughlyenoughitems.searchFieldLocation": "Search Field Position:",
+  "config.roughlyenoughitems.searchFieldLocation.bottom_side": "Bottom Left / Right",
+  "config.roughlyenoughitems.searchFieldLocation.top_side": "Top Left / Right",
+  "config.roughlyenoughitems.searchFieldLocation.center": "Middle",
   "config.roughlyenoughitems.villagerScreenPermanentScrollBar": "Villager Recipe Screen Scrollbar:",
   "config.roughlyenoughitems.villagerScreenPermanentScrollBar.boolean.true": "Permanent",
   "config.roughlyenoughitems.villagerScreenPermanentScrollBar.boolean.false": "Auto Fade Out",

+ 2 - 3
src/main/resources/assets/roughlyenoughitems/lang/ja_jp.json

@@ -84,9 +84,8 @@
   "config.roughlyenoughitems.mirrorItemPanel": "アイテムリストの位置:",
   "config.roughlyenoughitems.mirrorItemPanel.boolean.true": "左",
   "config.roughlyenoughitems.mirrorItemPanel.boolean.false": "右",
-  "config.roughlyenoughitems.sideSearchField": "Search Field Position:",
-  "config.roughlyenoughitems.sideSearchField.boolean.true": "左 / 右",
-  "config.roughlyenoughitems.sideSearchField.boolean.false": "中間",
+  "config.roughlyenoughitems.searchFieldLocation": "Search Field Position:",
+  "config.roughlyenoughitems.searchFieldLocation.false": "中間",
   "config.roughlyenoughitems.villagerScreenPermanentScrollBar": "Villager Recipe Screen Scrollbar:",
   "config.roughlyenoughitems.villagerScreenPermanentScrollBar.boolean.true": "Permanent",
   "config.roughlyenoughitems.villagerScreenPermanentScrollBar.boolean.false": "Auto Fade Out",

+ 2 - 3
src/main/resources/assets/roughlyenoughitems/lang/zh_tw.json

@@ -94,9 +94,8 @@
   "config.roughlyenoughitems.mirrorItemPanel": "物品列表的位置:",
   "config.roughlyenoughitems.mirrorItemPanel.boolean.true": "左邊",
   "config.roughlyenoughitems.mirrorItemPanel.boolean.false": "右邊",
-  "config.roughlyenoughitems.sideSearchField": "搜索框的位置:",
-  "config.roughlyenoughitems.sideSearchField.boolean.true": "左 / 右邊",
-  "config.roughlyenoughitems.sideSearchField.boolean.false": "中間",
+  "config.roughlyenoughitems.searchFieldLocation": "搜索框的位置:",
+  "config.roughlyenoughitems.searchFieldLocation.center": "中間",
   "config.roughlyenoughitems.villagerScreenPermanentScrollBar": "合成介面的滾動條:",
   "config.roughlyenoughitems.villagerScreenPermanentScrollBar.boolean.true": "永久顯示",
   "config.roughlyenoughitems.villagerScreenPermanentScrollBar.boolean.false": "自動淡出",