aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/cc/polyfrost/oneconfig/gui/elements
diff options
context:
space:
mode:
authornextdaydelivery <79922345+nxtdaydelivery@users.noreply.github.com>2022-05-10 20:19:07 +0100
committernextdaydelivery <79922345+nxtdaydelivery@users.noreply.github.com>2022-05-10 20:19:07 +0100
commitcefe13f6c232ed5ca2d458b896a76df2ee25a8a3 (patch)
treed64f34e2ee55124ce9c3469fea9333d94ccfb23f /src/main/java/cc/polyfrost/oneconfig/gui/elements
parentb5a1aea2239b0beace4d4407d2ab75294c6eab12 (diff)
parent3872c0ae8746e69671ac9b44ff94dc3c7b194817 (diff)
downloadOneConfig-cefe13f6c232ed5ca2d458b896a76df2ee25a8a3.tar.gz
OneConfig-cefe13f6c232ed5ca2d458b896a76df2ee25a8a3.tar.bz2
OneConfig-cefe13f6c232ed5ca2d458b896a76df2ee25a8a3.zip
reduce dependency on minecraft + stuff
Diffstat (limited to 'src/main/java/cc/polyfrost/oneconfig/gui/elements')
-rw-r--r--src/main/java/cc/polyfrost/oneconfig/gui/elements/ModCard.java3
-rw-r--r--src/main/java/cc/polyfrost/oneconfig/gui/elements/config/ConfigButton.java36
-rw-r--r--src/main/java/cc/polyfrost/oneconfig/gui/elements/config/ConfigHeader.java30
-rw-r--r--src/main/java/cc/polyfrost/oneconfig/gui/elements/text/TextInputField.java7
4 files changed, 72 insertions, 4 deletions
diff --git a/src/main/java/cc/polyfrost/oneconfig/gui/elements/ModCard.java b/src/main/java/cc/polyfrost/oneconfig/gui/elements/ModCard.java
index 48a6218..8d2ad16 100644
--- a/src/main/java/cc/polyfrost/oneconfig/gui/elements/ModCard.java
+++ b/src/main/java/cc/polyfrost/oneconfig/gui/elements/ModCard.java
@@ -12,7 +12,6 @@ import cc.polyfrost.oneconfig.lwjgl.image.Images;
import cc.polyfrost.oneconfig.utils.ColorUtils;
import cc.polyfrost.oneconfig.utils.InputUtils;
import net.minecraft.client.Minecraft;
-import net.minecraft.command.CommandException;
import net.minecraftforge.client.ClientCommandHandler;
import net.minecraftforge.fml.common.ModMetadata;
import org.jetbrains.annotations.NotNull;
@@ -109,7 +108,7 @@ public class ModCard extends BasicElement {
if (possibleCommands.contains(command)) {
try {
ClientCommandHandler.instance.getCommands().get(command).processCommand(Minecraft.getMinecraft().thePlayer, new String[]{});
- } catch (CommandException e) {
+ } catch (Exception e) {
throw new RuntimeException(e);
}
break;
diff --git a/src/main/java/cc/polyfrost/oneconfig/gui/elements/config/ConfigButton.java b/src/main/java/cc/polyfrost/oneconfig/gui/elements/config/ConfigButton.java
new file mode 100644
index 0000000..fdb0157
--- /dev/null
+++ b/src/main/java/cc/polyfrost/oneconfig/gui/elements/config/ConfigButton.java
@@ -0,0 +1,36 @@
+package cc.polyfrost.oneconfig.gui.elements.config;
+
+import cc.polyfrost.oneconfig.config.OneConfigConfig;
+import cc.polyfrost.oneconfig.config.interfaces.BasicOption;
+import cc.polyfrost.oneconfig.gui.elements.BasicButton;
+import cc.polyfrost.oneconfig.lwjgl.RenderManager;
+import cc.polyfrost.oneconfig.lwjgl.font.Fonts;
+
+import java.lang.reflect.Field;
+
+public class ConfigButton extends BasicOption {
+ private final BasicButton button;
+
+ public ConfigButton(Field field, String name, int size, String text) {
+ super(field, name, size);
+ Runnable runnable = () -> {
+ };
+ try {
+ runnable = (Runnable) get();
+ } catch (IllegalAccessException e) {
+ e.printStackTrace();
+ }
+ this.button = new BasicButton(size == 1 ? 128 : 256, 32, text, null, null, 1, BasicButton.ALIGNMENT_CENTER, runnable);
+ }
+
+ @Override
+ public void draw(long vg, int x, int y) {
+ RenderManager.drawString(vg, name, x, y + 17, OneConfigConfig.WHITE, 14f, Fonts.MEDIUM);
+ button.draw(vg, x + (size == 1 ? 352 : 736), y);
+ }
+
+ @Override
+ public int getHeight() {
+ return 32;
+ }
+}
diff --git a/src/main/java/cc/polyfrost/oneconfig/gui/elements/config/ConfigHeader.java b/src/main/java/cc/polyfrost/oneconfig/gui/elements/config/ConfigHeader.java
new file mode 100644
index 0000000..3ef3d06
--- /dev/null
+++ b/src/main/java/cc/polyfrost/oneconfig/gui/elements/config/ConfigHeader.java
@@ -0,0 +1,30 @@
+package cc.polyfrost.oneconfig.gui.elements.config;
+
+import cc.polyfrost.oneconfig.config.OneConfigConfig;
+import cc.polyfrost.oneconfig.config.interfaces.BasicOption;
+import cc.polyfrost.oneconfig.lwjgl.RenderManager;
+import cc.polyfrost.oneconfig.lwjgl.font.Fonts;
+import cc.polyfrost.oneconfig.lwjgl.scissor.Scissor;
+import cc.polyfrost.oneconfig.lwjgl.scissor.ScissorManager;
+
+import java.lang.reflect.Field;
+
+public class ConfigHeader extends BasicOption {
+
+ public ConfigHeader(Field field, String name, int size) {
+ super(field, name, size);
+ }
+
+ @Override
+ public void draw(long vg, int x, int y) {
+ Scissor scissor = ScissorManager.scissor(vg, x, y, size == 1 ? 480 : 992, 32);
+ RenderManager.drawString(vg, name, x, y + 17, OneConfigConfig.WHITE_90, 24, Fonts.MEDIUM);
+ ScissorManager.resetScissor(vg, scissor);
+ }
+
+
+ @Override
+ public int getHeight() {
+ return 32;
+ }
+}
diff --git a/src/main/java/cc/polyfrost/oneconfig/gui/elements/text/TextInputField.java b/src/main/java/cc/polyfrost/oneconfig/gui/elements/text/TextInputField.java
index dbca002..349e7af 100644
--- a/src/main/java/cc/polyfrost/oneconfig/gui/elements/text/TextInputField.java
+++ b/src/main/java/cc/polyfrost/oneconfig/gui/elements/text/TextInputField.java
@@ -8,7 +8,6 @@ import cc.polyfrost.oneconfig.lwjgl.scissor.ScissorManager;
import cc.polyfrost.oneconfig.lwjgl.font.Fonts;
import cc.polyfrost.oneconfig.utils.InputUtils;
import net.minecraft.client.gui.GuiScreen;
-import net.minecraft.util.ChatAllowedCharacters;
import org.jetbrains.annotations.NotNull;
import org.lwjgl.input.Keyboard;
import org.lwjgl.input.Mouse;
@@ -344,7 +343,7 @@ public class TextInputField extends BasicElement {
if (!Character.isDefined(key)) return;
if (!Character.isDefined(c)) return;
if (GuiScreen.isCtrlKeyDown()) return;
- if (ChatAllowedCharacters.isAllowedCharacter(c)) {
+ if (isAllowedCharacter(c)) {
if (selectedText != null) {
if (caretPos > prevCaret) {
input = input.substring(0, prevCaret) + input.substring(prevCaret, caretPos);
@@ -426,4 +425,8 @@ public class TextInputField extends BasicElement {
return RenderManager.getTextWidth(vg, s, 14.0f, Fonts.REGULAR);
}
}
+
+ public static boolean isAllowedCharacter(char character) {
+ return character != 167 && character >= ' ' && character != 127;
+ }
}