aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/me/shedaniel/gui
diff options
context:
space:
mode:
authorUnknown <shekwancheung0528@gmail.com>2019-01-02 17:02:01 +0800
committerUnknown <shekwancheung0528@gmail.com>2019-01-02 17:02:01 +0800
commitb54b3416e0ac86e4bd0950c9722ef7d9763977c2 (patch)
tree948a84aa81c10c04ff8f07791d7e89d0a9d23eb2 /src/main/java/me/shedaniel/gui
parent22e4ae062991c856c6c9dcf584abb437c34929f7 (diff)
downloadRoughlyEnoughItems-b54b3416e0ac86e4bd0950c9722ef7d9763977c2.tar.gz
RoughlyEnoughItems-b54b3416e0ac86e4bd0950c9722ef7d9763977c2.tar.bz2
RoughlyEnoughItems-b54b3416e0ac86e4bd0950c9722ef7d9763977c2.zip
Centre Search Box
Diffstat (limited to 'src/main/java/me/shedaniel/gui')
-rw-r--r--src/main/java/me/shedaniel/gui/ConfigGui.java29
-rwxr-xr-xsrc/main/java/me/shedaniel/gui/GuiItemList.java12
-rwxr-xr-xsrc/main/java/me/shedaniel/gui/widget/TextBox.java8
3 files changed, 46 insertions, 3 deletions
diff --git a/src/main/java/me/shedaniel/gui/ConfigGui.java b/src/main/java/me/shedaniel/gui/ConfigGui.java
index 6d67488f8..c7dfad3ab 100644
--- a/src/main/java/me/shedaniel/gui/ConfigGui.java
+++ b/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
diff --git a/src/main/java/me/shedaniel/gui/GuiItemList.java b/src/main/java/me/shedaniel/gui/GuiItemList.java
index 14ec8c5b3..accd02f61 100755
--- a/src/main/java/me/shedaniel/gui/GuiItemList.java
+++ b/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();
diff --git a/src/main/java/me/shedaniel/gui/widget/TextBox.java b/src/main/java/me/shedaniel/gui/widget/TextBox.java
index 6a33031a9..849e52c8c 100755
--- a/src/main/java/me/shedaniel/gui/widget/TextBox.java
+++ b/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);