aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/kr/syeyoung
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/kr/syeyoung')
-rw-r--r--src/main/java/kr/syeyoung/dungeonsguide/config/types/GUIRectangle.java22
-rw-r--r--src/main/java/kr/syeyoung/dungeonsguide/config/types/TCGUIRectangle.java33
-rw-r--r--src/main/java/kr/syeyoung/dungeonsguide/config/types/TypeConverterRegistry.java1
3 files changed, 56 insertions, 0 deletions
diff --git a/src/main/java/kr/syeyoung/dungeonsguide/config/types/GUIRectangle.java b/src/main/java/kr/syeyoung/dungeonsguide/config/types/GUIRectangle.java
new file mode 100644
index 00000000..f45cbb99
--- /dev/null
+++ b/src/main/java/kr/syeyoung/dungeonsguide/config/types/GUIRectangle.java
@@ -0,0 +1,22 @@
+package kr.syeyoung.dungeonsguide.config.types;
+
+import lombok.Data;
+import net.minecraft.client.Minecraft;
+import net.minecraft.client.gui.ScaledResolution;
+
+import java.awt.*;
+
+@Data
+public class GUIRectangle {
+ private double x;
+ private double y;
+ private double width;
+ private double height;
+
+ public Rectangle getRectangle() {
+ return getRectangle(new ScaledResolution(Minecraft.getMinecraft()));
+ }
+ public Rectangle getRectangle(ScaledResolution scaledResolution) {
+ return new Rectangle((int) x * scaledResolution.getScaledWidth(), (int) y * scaledResolution.getScaledHeight(), (int) width * scaledResolution.getScaledWidth(), (int) height * scaledResolution.getScaledHeight());
+ }
+}
diff --git a/src/main/java/kr/syeyoung/dungeonsguide/config/types/TCGUIRectangle.java b/src/main/java/kr/syeyoung/dungeonsguide/config/types/TCGUIRectangle.java
new file mode 100644
index 00000000..473c1970
--- /dev/null
+++ b/src/main/java/kr/syeyoung/dungeonsguide/config/types/TCGUIRectangle.java
@@ -0,0 +1,33 @@
+package kr.syeyoung.dungeonsguide.config.types;
+
+import com.google.gson.JsonElement;
+import com.google.gson.JsonObject;
+
+import java.awt.*;
+
+public class TCGUIRectangle implements TypeConverter<GUIRectangle> {
+ @Override
+ public String getTypeString() {
+ return "guirect";
+ }
+
+ @Override
+ public GUIRectangle deserialize(JsonElement element) {
+ GUIRectangle rectangle = new GUIRectangle();
+ rectangle.setX(((JsonObject)element).get("x").getAsDouble());
+ rectangle.setY(((JsonObject)element).get("y").getAsDouble());
+ rectangle.setWidth(((JsonObject)element).get("width").getAsDouble());
+ rectangle.setHeight(((JsonObject)element).get("height").getAsDouble());
+ return rectangle;
+ }
+
+ @Override
+ public JsonElement serialize(GUIRectangle element) {
+ JsonObject object = new JsonObject();
+ object.addProperty("x", element.getX());
+ object.addProperty("y", element.getY());
+ object.addProperty("width", element.getWidth());
+ object.addProperty("height", element.getHeight());
+ return object;
+ }
+}
diff --git a/src/main/java/kr/syeyoung/dungeonsguide/config/types/TypeConverterRegistry.java b/src/main/java/kr/syeyoung/dungeonsguide/config/types/TypeConverterRegistry.java
index 5e48b76c..b100d62f 100644
--- a/src/main/java/kr/syeyoung/dungeonsguide/config/types/TypeConverterRegistry.java
+++ b/src/main/java/kr/syeyoung/dungeonsguide/config/types/TypeConverterRegistry.java
@@ -23,6 +23,7 @@ public class TypeConverterRegistry {
register(new TCBoolean());
register(new TCInteger());
register(new TCRectangle());
+ register(new TCGUIRectangle());
register(new TCString());
register(new TCColor());
register(new TCFloat());