diff options
author | syeyoung <cyong06@naver.com> | 2021-02-27 01:37:32 +0900 |
---|---|---|
committer | syeyoung <cyong06@naver.com> | 2021-02-27 01:37:32 +0900 |
commit | a67de30acd54d4781dded0e86e5980bbb5402809 (patch) | |
tree | 992ec5b247852c919b994e18427fcac7f3834571 /src | |
parent | 1e124379b19d71d1d8af28832decd407f49d1a4b (diff) | |
download | Skyblock-Dungeons-Guide-a67de30acd54d4781dded0e86e5980bbb5402809.tar.gz Skyblock-Dungeons-Guide-a67de30acd54d4781dded0e86e5980bbb5402809.tar.bz2 Skyblock-Dungeons-Guide-a67de30acd54d4781dded0e86e5980bbb5402809.zip |
types
Diffstat (limited to 'src')
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()); |