aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/cc/polyfrost/oneconfig/gui
diff options
context:
space:
mode:
authornextdaydelivery <79922345+nxtdaydelivery@users.noreply.github.com>2022-07-25 11:51:01 +0100
committerGitHub <noreply@github.com>2022-07-25 11:51:01 +0100
commit580fd1d5c4ec5625c813f6d593928a401a500869 (patch)
treed8a1255f6620b61203338e6471b4ed370e837e7d /src/main/java/cc/polyfrost/oneconfig/gui
parent64329ad7ccedba53c47ccd3a08b9eb97e756122c (diff)
downloadOneConfig-580fd1d5c4ec5625c813f6d593928a401a500869.tar.gz
OneConfig-580fd1d5c4ec5625c813f6d593928a401a500869.tar.bz2
OneConfig-580fd1d5c4ec5625c813f6d593928a401a500869.zip
Buttons but with a key twist (#70)
* config checker 9000 * apiDump * rename * put in package and remove javadocs * put in package and remove javadocs * button methods
Diffstat (limited to 'src/main/java/cc/polyfrost/oneconfig/gui')
-rw-r--r--src/main/java/cc/polyfrost/oneconfig/gui/elements/config/ConfigButton.java22
1 files changed, 22 insertions, 0 deletions
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
index 9879ac2..1480ff8 100644
--- a/src/main/java/cc/polyfrost/oneconfig/gui/elements/config/ConfigButton.java
+++ b/src/main/java/cc/polyfrost/oneconfig/gui/elements/config/ConfigButton.java
@@ -9,6 +9,8 @@ import cc.polyfrost.oneconfig.renderer.font.Fonts;
import cc.polyfrost.oneconfig.utils.color.ColorPalette;
import java.lang.reflect.Field;
+import java.lang.reflect.Method;
+import java.util.Arrays;
public class ConfigButton extends BasicOption {
private final BasicButton button;
@@ -25,11 +27,31 @@ public class ConfigButton extends BasicOption {
this.button.setClickAction(getRunnableFromField(field, parent));
}
+ public ConfigButton(Method method, Object parent, String name, String category, String subcategory, int size, String text) {
+ super(null, parent, name, category, subcategory, size);
+ this.button = new BasicButton(size == 1 ? 128 : 256, 32, text, BasicButton.ALIGNMENT_CENTER, ColorPalette.PRIMARY);
+ this.button.setClickAction(() -> {
+ try {
+ method.invoke(parent);
+ } catch (Exception e) {
+ if (e.getMessage() != null && e.getMessage().contains("wrong number of arguments")) {
+ throw new IllegalArgumentException("Button method " + method.getDeclaringClass().getName() + "." + method.getName() + "(" + Arrays.toString(method.getGenericParameterTypes()) + ") must take no arguments!");
+ } else e.printStackTrace();
+ }
+ });
+ }
+
public static ConfigButton create(Field field, Object parent) {
Button button = field.getAnnotation(Button.class);
return new ConfigButton(field, parent, button.name(), button.category(), button.subcategory(), button.size(), button.text());
}
+ public static ConfigButton create(Method method, Object parent) {
+ method.setAccessible(true);
+ Button button = method.getAnnotation(Button.class);
+ return new ConfigButton(method, parent, button.name(), button.category(), button.subcategory(), button.size(), button.text());
+ }
+
private static Runnable getRunnableFromField(Field field, Object parent) {
Runnable runnable = () -> {
};