Browse Source

Centre Search Box

Unknown 6 years ago
parent
commit
b54b3416e0

+ 1 - 1
build.gradle

@@ -6,7 +6,7 @@ sourceCompatibility = 1.8
 targetCompatibility = 1.8
 
 archivesBaseName = "RoughlyEnoughItems"
-version = "1.3-5"
+version = "1.3-6"
 
 minecraft {
 }

+ 1 - 0
src/main/java/me/shedaniel/config/REIConfig.java

@@ -12,5 +12,6 @@ public class REIConfig {
     public int recipeKeyBind = KeyEvent.VK_R;
     public int usageKeyBind = KeyEvent.VK_U;
     public int hideKeyBind = KeyEvent.VK_O;
+    public boolean centreSearchBox = false;
     
 }

+ 27 - 2
src/main/java/me/shedaniel/gui/ConfigGui.java

@@ -5,9 +5,11 @@ import me.shedaniel.Core;
 import me.shedaniel.gui.widget.KeyBindButton;
 import net.minecraft.client.MinecraftClient;
 import net.minecraft.client.gui.Gui;
+import net.minecraft.client.gui.widget.ButtonWidget;
 import net.minecraft.client.resource.language.I18n;
 
 import java.io.IOException;
+import java.util.Arrays;
 
 public class ConfigGui extends Gui {
     
@@ -28,7 +30,7 @@ public class ConfigGui extends Gui {
                 e.printStackTrace();
             }
         }));
-        addButton(new KeyBindButton(997, parent.width / 2 - 20, 60, 80, 20, Core.config.usageKeyBind, key -> {
+        addButton(new KeyBindButton(998, parent.width / 2 - 20, 60, 80, 20, Core.config.usageKeyBind, key -> {
             Core.config.usageKeyBind = key;
             ClientListener.usageKeyBind.setKey(key);
             try {
@@ -37,7 +39,7 @@ public class ConfigGui extends Gui {
                 e.printStackTrace();
             }
         }));
-        addButton(new KeyBindButton(997, parent.width / 2 - 20, 90, 80, 20, Core.config.hideKeyBind, key -> {
+        addButton(new KeyBindButton(999, parent.width / 2 - 20, 90, 80, 20, Core.config.hideKeyBind, key -> {
             Core.config.hideKeyBind = key;
             ClientListener.hideKeyBind.setKey(key);
             try {
@@ -46,6 +48,29 @@ public class ConfigGui extends Gui {
                 e.printStackTrace();
             }
         }));
+        addButton(new ButtonWidget(1000, parent.width / 2 - 90, 120, 150, 20, "") {
+            @Override
+            public void onPressed(double double_1, double double_2) {
+                Core.config.centreSearchBox = !Core.config.centreSearchBox;
+                try {
+                    Core.saveConfig();
+                } catch (IOException e) {
+                    e.printStackTrace();
+                }
+            }
+            
+            @Override
+            public void draw(int int_1, int int_2, float float_1) {
+                this.text = I18n.translate("text.rei.centre_searchbox", Core.config.centreSearchBox ? "§a" : "§c", Core.config.centreSearchBox);
+                super.draw(int_1, int_2, float_1);
+                if (this.hovered)
+                    drawSuggestion(int_1, int_2);
+            }
+            
+            protected void drawSuggestion(int x, int y) {
+                drawTooltip(Arrays.asList(I18n.translate("text.rei.centre_searchbox.tooltip").split("\n")), x, y);
+            }
+        });
     }
     
     @Override

+ 11 - 1
src/main/java/me/shedaniel/gui/GuiItemList.java

@@ -99,7 +99,7 @@ public class GuiItemList extends Drawable {
         if (searchBox != null) {
             savedText = searchBox.getText();
         }
-        searchBox = new TextBox(rect.x, rect.height - 31, rect.width - 4, 18);
+        searchBox = new TextBox(getSearchBoxArea());
         searchBox.setText(savedText);
         controls.add(searchBox);
         buttonCheating = new Button(5, 5, 45, 20, getCheatModeText());
@@ -117,6 +117,16 @@ public class GuiItemList extends Drawable {
         controls.addAll(displaySlots);
     }
     
+    private Rectangle getSearchBoxArea() {
+        int ch = ((IMixinContainerGui) overlayedGui).getContainerHeight(), cw = ((IMixinContainerGui) overlayedGui).getContainerWidth();
+        if (Core.config.centreSearchBox) {
+            if (ch + 4 + 18 > rect.height) //Will be out of bounds
+                return new Rectangle(overlayedGui.width / 2 - cw / 2, rect.height + 100, cw, 18);
+            return new Rectangle(overlayedGui.width / 2 - cw / 2, rect.height - 31, cw, 18);
+        }
+        return new Rectangle(rect.x, rect.height - 31, rect.width - 4, 18);
+    }
+    
     private void fillSlots() {
         page = MathHelper.clamp(page, 0, (int) Math.floor(view.size() / displaySlots.size()));
         int firstSlot = page * displaySlots.size();

+ 8 - 0
src/main/java/me/shedaniel/gui/widget/TextBox.java

@@ -20,6 +20,14 @@ public class TextBox extends Control implements IFocusable {
         this.charPressed = this::charTyped;
     }
     
+    public TextBox(Rectangle rectangle) {
+        super(rectangle);
+        textField = new TextFieldWidget(-1, REIRenderHelper.getFontRenderer(), rectangle.x, rectangle.y, rectangle.width, rectangle.height);
+        this.onClick = this::doMouseClick;
+        this.onKeyDown = this::onKeyPressed;
+        this.charPressed = this::charTyped;
+    }
+    
     @Override
     public void draw() {
         textField.render(0, 0, 0);

+ 4 - 0
src/main/java/me/shedaniel/listenerdefinitions/IMixinContainerGui.java

@@ -8,6 +8,10 @@ public interface IMixinContainerGui {
     
     public int getGuiLeft();
     
+    public int getContainerHeight();
+    
+    public int getContainerWidth();
+    
     public int getXSize();
     
     public Slot getHoveredSlot();

+ 10 - 0
src/main/java/me/shedaniel/mixins/MixinContainerGui.java

@@ -90,4 +90,14 @@ public abstract class MixinContainerGui extends Gui implements IMixinContainerGu
     public Slot getHoveredSlot() {
         return focusedSlot;
     }
+    
+    @Override
+    public int getContainerHeight() {
+        return containerHeight;
+    }
+    
+    @Override
+    public int getContainerWidth() {
+        return containerWidth;
+    }
 }

+ 6 - 11
src/main/java/me/shedaniel/mixins/MixinCreativePlayerInventoryGui.java

@@ -4,9 +4,7 @@ import me.shedaniel.Core;
 import me.shedaniel.listenerdefinitions.GuiKeyDown;
 import net.minecraft.client.gui.ingame.AbstractPlayerInventoryGui;
 import net.minecraft.client.gui.ingame.CreativePlayerInventoryGui;
-import net.minecraft.client.gui.widget.TextFieldWidget;
 import net.minecraft.container.Container;
-import net.minecraft.container.Slot;
 import net.minecraft.item.ItemGroup;
 import org.spongepowered.asm.mixin.Mixin;
 import org.spongepowered.asm.mixin.Shadow;
@@ -30,15 +28,12 @@ public abstract class MixinCreativePlayerInventoryGui extends AbstractPlayerInve
     @Inject(method = "keyPressed(III)Z", at = @At("HEAD"), cancellable = true)
     public void keyPressed(int p_keyPressed_1_, int p_keyPressed_2_, int p_keyPressed_3_, CallbackInfoReturnable<Boolean> ci) {
         boolean handled = false;
-        if (method_2469() != ItemGroup.SEARCH.getId()) {
-            if (method_2469() == ItemGroup.INVENTORY.getId()) {
-                for(GuiKeyDown listener : Core.getListeners(GuiKeyDown.class))
-                    if (listener.keyDown(p_keyPressed_1_, p_keyPressed_2_, p_keyPressed_3_)) {
-                        ci.setReturnValue(true);
-                        handled = true;
-                    }
-            }
-        }
+        if (method_2469() == ItemGroup.INVENTORY.getId())
+            for(GuiKeyDown listener : Core.getListeners(GuiKeyDown.class))
+                if (listener.keyDown(p_keyPressed_1_, p_keyPressed_2_, p_keyPressed_3_)) {
+                    ci.setReturnValue(true);
+                    handled = true;
+                }
         if (handled)
             ci.cancel();
     }

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

@@ -16,5 +16,7 @@
   "category.rei.brewing.reactant": "§eIngredient",
   "category.rei.brewing.result": "§eResulted Potion",
   "text.rei.config": "Config",
-  "text.rei.listeningkey": "Listening Key"
+  "text.rei.listeningkey": "Listening Key",
+  "text.rei.centre_searchbox": "Center Search Box: %s%b",
+  "text.rei.centre_searchbox.tooltip": "Please resize the window after editing\nthis config to apply the changes"
 }

+ 3 - 1
src/main/resources/assets/roughlyenoughitems/lang/zh_cn.json

@@ -16,5 +16,7 @@
   "category.rei.brewing.reactant": "§e材料",
   "category.rei.brewing.result": "§e输出药水",
   "text.rei.config": "设置",
-  "text.rei.listeningkey": "正聆听按键"
+  "text.rei.listeningkey": "正聆听按键",
+  "text.rei.centre_searchbox": "置中搜索栏: %s%b",
+  "text.rei.centre_searchbox.tooltip": "更改此设置后请调整窗口大小以完成更改"
 }

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

@@ -16,5 +16,7 @@
   "category.rei.brewing.reactant": "§e材料",
   "category.rei.brewing.result": "§e輸出藥水",
   "text.rei.config": "設置",
-  "text.rei.listeningkey": "正聆聽按鍵"
+  "text.rei.listeningkey": "正聆聽按鍵",
+  "text.rei.centre_searchbox": "置中搜索欄: %s%b",
+  "text.rei.centre_searchbox.tooltip": "更改此設置後請調整窗口大小以完成更改"
 }

+ 1 - 1
src/main/resources/fabric.mod.json

@@ -2,7 +2,7 @@
   "id": "roughlyenoughitems",
   "name": "RoughlyEnoughItems",
   "description": "To allow players to view items and recipes.",
-  "version": "1.2",
+  "version": "1.3",
   "side": "client",
   "authors": [
     "Danielshe"