aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/kr/syeyoung/dungeonsguide/features/GuiFeature.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/kr/syeyoung/dungeonsguide/features/GuiFeature.java')
-rw-r--r--src/main/java/kr/syeyoung/dungeonsguide/features/GuiFeature.java23
1 files changed, 15 insertions, 8 deletions
diff --git a/src/main/java/kr/syeyoung/dungeonsguide/features/GuiFeature.java b/src/main/java/kr/syeyoung/dungeonsguide/features/GuiFeature.java
index f15b10b5..36ae4c78 100644
--- a/src/main/java/kr/syeyoung/dungeonsguide/features/GuiFeature.java
+++ b/src/main/java/kr/syeyoung/dungeonsguide/features/GuiFeature.java
@@ -1,6 +1,7 @@
package kr.syeyoung.dungeonsguide.features;
import com.google.gson.JsonObject;
+import kr.syeyoung.dungeonsguide.config.types.GUIRectangle;
import kr.syeyoung.dungeonsguide.config.types.TypeConverterRegistry;
import kr.syeyoung.dungeonsguide.features.listener.ScreenRenderListener;
import lombok.AccessLevel;
@@ -12,6 +13,7 @@ import net.minecraft.client.gui.ScaledResolution;
import net.minecraft.client.renderer.GlStateManager;
import net.minecraft.client.renderer.OpenGlHelper;
import org.lwjgl.opengl.GL11;
+import org.w3c.dom.css.Rect;
import javax.sound.midi.MidiEvent;
import java.awt.*;
@@ -19,22 +21,24 @@ import java.awt.*;
@Getter
public abstract class GuiFeature extends AbstractFeature implements ScreenRenderListener {
@Setter
- private Rectangle featureRect;
+ private GUIRectangle featureRect;
@Setter(value = AccessLevel.PROTECTED)
private boolean keepRatio;
@Setter(value = AccessLevel.PROTECTED)
- private int defaultWidth;
+ private double defaultWidth;
@Setter(value = AccessLevel.PROTECTED)
- private int defaultHeight;
+ private double defaultHeight;
private double defaultRatio;
- protected GuiFeature(String category, String name, String description, String key, boolean keepRatio, int width, int height) {
+ protected GuiFeature(String category, String name, String description, String key, boolean keepRatio, double width, double height) {
super(category, name, description, key);
this.keepRatio = keepRatio;
this.defaultWidth = width;
this.defaultHeight = height;
this.defaultRatio = defaultWidth / (double)defaultHeight;
- this.featureRect = new Rectangle(0, 0, width, height);
+ if (width > 1) width = width / 720;
+ if (height > 1) height = height / 480;
+ this.featureRect = new GUIRectangle(0, 0, width, height);
}
@Override
@@ -44,7 +48,9 @@ public abstract class GuiFeature extends AbstractFeature implements ScreenRender
GlStateManager.color(1,1,1,1);
GlStateManager.disableFog();GL11.glDisable(GL11.GL_FOG);
GlStateManager.disableLighting();
- clip(new ScaledResolution(Minecraft.getMinecraft()), featureRect.x, featureRect.y, featureRect.width, featureRect.height);
+ ScaledResolution scaledResolution = new ScaledResolution(Minecraft.getMinecraft());
+ Rectangle featureRect = this.featureRect.getRectangle(scaledResolution);
+ clip(scaledResolution, featureRect.x, featureRect.y, featureRect.width, featureRect.height);
GL11.glEnable(GL11.GL_SCISSOR_TEST);
GlStateManager.translate(featureRect.x, featureRect.y, 0);
@@ -74,13 +80,14 @@ public abstract class GuiFeature extends AbstractFeature implements ScreenRender
@Override
public void loadConfig(JsonObject jsonObject) {
super.loadConfig(jsonObject);
- featureRect = TypeConverterRegistry.getTypeConverter("rect", Rectangle.class).deserialize(jsonObject.get("$bounds"));
+ GUIRectangle featureRect = TypeConverterRegistry.getTypeConverter("guirect",GUIRectangle.class).deserialize(jsonObject.get("$bounds2"));
+ if (featureRect != null && featureRect.getWidth() <= 1 && featureRect.getHeight() <= 1) this.featureRect = featureRect;
}
@Override
public JsonObject saveConfig() {
JsonObject object = super.saveConfig();
- object.add("$bounds", TypeConverterRegistry.getTypeConverter("rect", Rectangle.class).serialize(featureRect));
+ object.add("$bounds2", TypeConverterRegistry.getTypeConverter("guirect", GUIRectangle.class).serialize(featureRect));
return object;
}
}