diff options
Diffstat (limited to 'src/main/java')
4 files changed, 54 insertions, 40 deletions
diff --git a/src/main/java/kr/syeyoung/dungeonsguide/config/guiconfig/PanelDelegate.java b/src/main/java/kr/syeyoung/dungeonsguide/config/guiconfig/PanelDelegate.java index c9a1922c..14661871 100644 --- a/src/main/java/kr/syeyoung/dungeonsguide/config/guiconfig/PanelDelegate.java +++ b/src/main/java/kr/syeyoung/dungeonsguide/config/guiconfig/PanelDelegate.java @@ -94,18 +94,12 @@ public class PanelDelegate extends MPanel { rectangle.width = minWidth; rectangle.height= minHeight; } - + ScaledResolution sr = new ScaledResolution(Minecraft.getMinecraft()); if (rectangle.x < 0) rectangle.x = 0; if (rectangle.y < 0) rectangle.y = 0; - - ScaledResolution scaledResolution = new ScaledResolution(Minecraft.getMinecraft()); - GUIRectangle guiRectangle = new GUIRectangle( - rectangle.x / scaledResolution.getScaledWidth_double(), - rectangle.y / scaledResolution.getScaledHeight_double(), - rectangle.width / scaledResolution.getScaledWidth_double(), - rectangle.height / scaledResolution.getScaledHeight_double() - ); - guiFeature.setFeatureRect(guiRectangle); + if (rectangle.x + rectangle.width + 1 >= sr.getScaledWidth()) rectangle.x = sr.getScaledWidth() - rectangle.width - 1; + if (rectangle.y + rectangle.height + 1>= sr.getScaledHeight()) rectangle.y = sr.getScaledHeight() - rectangle.height - 1; + guiFeature.setFeatureRect(new GUIRectangle(rectangle)); } selectedPart = -2; @@ -166,26 +160,24 @@ public class PanelDelegate extends MPanel { lastX += revChangeX ? 3 : 3; } - ScaledResolution scaledResolution = new ScaledResolution(Minecraft.getMinecraft()); - GUIRectangle guiRectangle = new GUIRectangle( - rectangle.x / scaledResolution.getScaledWidth_double(), - rectangle.y / scaledResolution.getScaledHeight_double(), - rectangle.width / scaledResolution.getScaledWidth_double(), - rectangle.height / scaledResolution.getScaledHeight_double() - ); - guiFeature.setFeatureRect(guiRectangle); + ScaledResolution sr = new ScaledResolution(Minecraft.getMinecraft()); + if (rectangle.x < 0) rectangle.x = 0; + if (rectangle.y < 0) rectangle.y = 0; + if (rectangle.x + rectangle.width + 1 >= sr.getScaledWidth()) rectangle.x = sr.getScaledWidth() - rectangle.width - 1; + if (rectangle.y + rectangle.height + 1>= sr.getScaledHeight()) rectangle.y = sr.getScaledHeight() - rectangle.height - 1; + + guiFeature.setFeatureRect(new GUIRectangle(rectangle)); throw new IllegalArgumentException("bruh, a hack to stop event progress"); } else if (selectedPart == -1){ Rectangle rectangle = guiFeature.getFeatureRect().getRectangle().getBounds(); rectangle.translate(dx, dy); - ScaledResolution scaledResolution = new ScaledResolution(Minecraft.getMinecraft()); - GUIRectangle guiRectangle = new GUIRectangle( - rectangle.x / scaledResolution.getScaledWidth_double(), - rectangle.y / scaledResolution.getScaledHeight_double(), - rectangle.width / scaledResolution.getScaledWidth_double(), - rectangle.height / scaledResolution.getScaledHeight_double() - ); - guiFeature.setFeatureRect(guiRectangle); + + ScaledResolution sr = new ScaledResolution(Minecraft.getMinecraft()); + if (rectangle.x < 0) rectangle.x = 0; + if (rectangle.y < 0) rectangle.y = 0; + if (rectangle.x + rectangle.width + 1 >= sr.getScaledWidth()) rectangle.x = sr.getScaledWidth() - rectangle.width - 1; + if (rectangle.y + rectangle.height + 1>= sr.getScaledHeight()) rectangle.y = sr.getScaledHeight() - rectangle.height - 1; + guiFeature.setFeatureRect(new GUIRectangle(rectangle)); lastX = absMouseX; lastY = absMouseY; } diff --git a/src/main/java/kr/syeyoung/dungeonsguide/config/types/GUIRectangle.java b/src/main/java/kr/syeyoung/dungeonsguide/config/types/GUIRectangle.java index 085a568c..ceabe366 100644 --- a/src/main/java/kr/syeyoung/dungeonsguide/config/types/GUIRectangle.java +++ b/src/main/java/kr/syeyoung/dungeonsguide/config/types/GUIRectangle.java @@ -12,15 +12,39 @@ import java.awt.*; @AllArgsConstructor @NoArgsConstructor public class GUIRectangle { - private double x; - private double y; - private double width; - private double height; + public GUIRectangle(Rectangle rectangle) { + + ScaledResolution sr = new ScaledResolution(Minecraft.getMinecraft()); + if (rectangle.x < sr.getScaledWidth() / 2) { + this.x = rectangle.x; + this.width = rectangle.width; + } else { + this.x = rectangle.x + rectangle.width - sr.getScaledWidth(); + this.width = -rectangle.width; + } + + if (rectangle.y < sr.getScaledHeight() / 2) { + this.y = rectangle.y; + this.height = rectangle.height; + } else { + this.y = rectangle.y +rectangle.height - sr.getScaledHeight(); + this.height = -rectangle.height; + } + } + + private int x; + private int y; + private int width; + private int 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())); + int realX = x < 0 ? scaledResolution.getScaledWidth() + x : x; + int realY = y < 0 ? scaledResolution.getScaledHeight() + y : y; + + return new Rectangle(Math.min(realX + width, realX), Math.min(realY + height, realY), + Math.abs(width), Math.abs(height)); } } diff --git a/src/main/java/kr/syeyoung/dungeonsguide/config/types/TCGUIRectangle.java b/src/main/java/kr/syeyoung/dungeonsguide/config/types/TCGUIRectangle.java index 746ce555..b4ca931d 100644 --- a/src/main/java/kr/syeyoung/dungeonsguide/config/types/TCGUIRectangle.java +++ b/src/main/java/kr/syeyoung/dungeonsguide/config/types/TCGUIRectangle.java @@ -15,10 +15,10 @@ public class TCGUIRectangle implements TypeConverter<GUIRectangle> { public GUIRectangle deserialize(JsonElement element) { if (element == null) return null; 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()); + rectangle.setX(((JsonObject)element).get("x").getAsInt()); + rectangle.setY(((JsonObject)element).get("y").getAsInt()); + rectangle.setWidth(((JsonObject)element).get("width").getAsInt()); + rectangle.setHeight(((JsonObject)element).get("height").getAsInt()); return rectangle; } diff --git a/src/main/java/kr/syeyoung/dungeonsguide/features/GuiFeature.java b/src/main/java/kr/syeyoung/dungeonsguide/features/GuiFeature.java index 36ae4c78..39dc2759 100644 --- a/src/main/java/kr/syeyoung/dungeonsguide/features/GuiFeature.java +++ b/src/main/java/kr/syeyoung/dungeonsguide/features/GuiFeature.java @@ -30,14 +30,12 @@ public abstract class GuiFeature extends AbstractFeature implements ScreenRender private double defaultHeight; private double defaultRatio; - protected GuiFeature(String category, String name, String description, String key, boolean keepRatio, double width, double height) { + protected GuiFeature(String category, String name, String description, String key, boolean keepRatio, int width, int height) { super(category, name, description, key); this.keepRatio = keepRatio; this.defaultWidth = width; this.defaultHeight = height; this.defaultRatio = defaultWidth / (double)defaultHeight; - if (width > 1) width = width / 720; - if (height > 1) height = height / 480; this.featureRect = new GUIRectangle(0, 0, width, height); } @@ -80,14 +78,14 @@ public abstract class GuiFeature extends AbstractFeature implements ScreenRender @Override public void loadConfig(JsonObject jsonObject) { super.loadConfig(jsonObject); - GUIRectangle featureRect = TypeConverterRegistry.getTypeConverter("guirect",GUIRectangle.class).deserialize(jsonObject.get("$bounds2")); + GUIRectangle featureRect = TypeConverterRegistry.getTypeConverter("guirect",GUIRectangle.class).deserialize(jsonObject.get("$bounds")); if (featureRect != null && featureRect.getWidth() <= 1 && featureRect.getHeight() <= 1) this.featureRect = featureRect; } @Override public JsonObject saveConfig() { JsonObject object = super.saveConfig(); - object.add("$bounds2", TypeConverterRegistry.getTypeConverter("guirect", GUIRectangle.class).serialize(featureRect)); + object.add("$bounds", TypeConverterRegistry.getTypeConverter("guirect", GUIRectangle.class).serialize(featureRect)); return object; } } |