aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/kr/syeyoung/dungeonsguide/config
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/kr/syeyoung/dungeonsguide/config')
-rwxr-xr-xsrc/main/java/kr/syeyoung/dungeonsguide/config/guiconfig/GuiGuiLocationConfig.java104
-rw-r--r--src/main/java/kr/syeyoung/dungeonsguide/config/guiconfig/Marker.java46
-rwxr-xr-xsrc/main/java/kr/syeyoung/dungeonsguide/config/guiconfig/PanelDefaultParameterConfig.java17
-rw-r--r--src/main/java/kr/syeyoung/dungeonsguide/config/guiconfig/PanelDelegate.java283
-rw-r--r--src/main/java/kr/syeyoung/dungeonsguide/config/types/GUIRectangle.java9
5 files changed, 381 insertions, 78 deletions
diff --git a/src/main/java/kr/syeyoung/dungeonsguide/config/guiconfig/GuiGuiLocationConfig.java b/src/main/java/kr/syeyoung/dungeonsguide/config/guiconfig/GuiGuiLocationConfig.java
index 11dd2db2..2304378b 100755
--- a/src/main/java/kr/syeyoung/dungeonsguide/config/guiconfig/GuiGuiLocationConfig.java
+++ b/src/main/java/kr/syeyoung/dungeonsguide/config/guiconfig/GuiGuiLocationConfig.java
@@ -24,44 +24,110 @@ import kr.syeyoung.dungeonsguide.features.GuiFeature;
import kr.syeyoung.dungeonsguide.gui.MGui;
import kr.syeyoung.dungeonsguide.gui.MPanel;
import kr.syeyoung.dungeonsguide.gui.elements.MButton;
+import lombok.Getter;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.GuiScreen;
import net.minecraft.client.gui.ScaledResolution;
import net.minecraft.client.renderer.GlStateManager;
+import net.minecraft.util.Vec3;
import org.lwjgl.input.Mouse;
import org.lwjgl.opengl.GL11;
import java.awt.*;
import java.io.IOException;
+import java.util.*;
+import java.util.List;
public class GuiGuiLocationConfig extends MGui {
private final GuiScreen before;
+ @Getter
+ private TreeMap<Integer, List<Marker>> markerTreeMapByX = new TreeMap<>();
+ @Getter
+ private TreeMap<Integer, List<Marker>> markerTreeMapByY = new TreeMap<>();
+ @Getter
+ private Set<Marker> markerSet = new HashSet<>();
+
+
+ Marker[] markers = new Marker[4];
+
+
public GuiGuiLocationConfig(final GuiScreen before, AbstractFeature featureWhitelist) {
this.before = before;
for (AbstractFeature feature : FeatureRegistry.getFeatureList()) {
if (feature instanceof GuiFeature && feature.isEnabled()) {
- getMainPanel().add(new PanelDelegate((GuiFeature) feature, featureWhitelist == null || feature == featureWhitelist));
+ getMainPanel().add(new PanelDelegate((GuiFeature) feature, featureWhitelist == null || feature == featureWhitelist, this));
}
}
- getMainPanel().setBackgroundColor(new Color(0,0,0, 60));
- {
- MButton button = new MButton() {
- @Override
- public void resize(int parentWidth, int parentHeight) {
- setBounds(new Rectangle(parentWidth-50,parentHeight-20,50,20));
+ getMainPanel().setBackgroundColor(new Color(0,0,0, 100));
+ }
+
+ public static final Vec3[] facing = new Vec3[] {
+ new Vec3(0, 0.5, 2),
+ new Vec3(0.5, 0, 1),
+ new Vec3(0.5, 1, 3),
+ new Vec3(1, 0.5, 4),
+ };
+
+ public void removeAndAddMarker(Marker prev, Marker newM) {
+ if (prev != null) {
+ markerTreeMapByX.computeIfPresent(prev.getX(),(k,v) -> {
+ v.remove(prev);
+ if (v.isEmpty()) return null;
+ else return v;
+ });
+ markerTreeMapByY.computeIfPresent(prev.getY(),(k,v) -> {
+ v.remove(prev);
+ if (v.isEmpty()) return null;
+ else return v;
+ });
+ markerSet.remove(prev);
+ }
+ if (newM != null) {
+ markerTreeMapByX.compute(newM.getX(), (k,v) -> {
+ if (v == null) {
+ return new ArrayList<>(Arrays.asList(newM));
+ } else {
+ v.add(newM);
+ return v;
}
- };
- button.setText("back");
- button.setOnActionPerformed(new Runnable() {
- @Override
- public void run() {
- Minecraft.getMinecraft().displayGuiScreen(before);
+ });
+ markerTreeMapByY.compute(newM.getY(), (k,v) -> {
+ if (v == null) {
+ return new ArrayList<>(Arrays.asList(newM));
+ } else {
+ v.add(newM);
+ return v;
}
});
- getMainPanel().add(button);
+ markerSet.add(newM);
+ }
+ }
+
+ public void setupMarkers() {
+ for (int i1 = 0; i1 < markers.length; i1++) {
+ Marker orig = markers[i1];
+ Vec3 pt = facing[i1];
+ markers[i1] = new Marker((int) (pt.xCoord * getMainPanel().getBounds().width), (int) (pt.yCoord * getMainPanel().getBounds().height), (int) pt.zCoord, this);
+
+ removeAndAddMarker(orig, markers[i1]);
+ }
+ }
+
+
+ @Override
+ public void keyTyped(char typedChar, int keyCode) throws IOException {
+ try {
+ getMainPanel().keyTyped0(typedChar, keyCode);
+
+ if (keyCode == 1) {
+ Minecraft.getMinecraft().displayGuiScreen(before);
+ }
+ } catch (Throwable e) {
+ if (!e.getMessage().contains("hack to stop"))
+ e.printStackTrace();
}
}
@@ -69,6 +135,16 @@ public class GuiGuiLocationConfig extends MGui {
public void initGui() {
super.initGui();
getMainPanel().setBounds(new Rectangle(0,0,Minecraft.getMinecraft().displayWidth,Minecraft.getMinecraft().displayHeight));
+ markerTreeMapByX.clear();
+ markerTreeMapByY.clear();
+ markerSet.clear();
+ setupMarkers();
+ for (MPanel childComponent : getMainPanel().getChildComponents()) {
+ if (childComponent instanceof PanelDelegate) {
+ ((PanelDelegate) childComponent).rebuildMarker();
+ }
+ }
+
}
}
diff --git a/src/main/java/kr/syeyoung/dungeonsguide/config/guiconfig/Marker.java b/src/main/java/kr/syeyoung/dungeonsguide/config/guiconfig/Marker.java
new file mode 100644
index 00000000..27ced7ee
--- /dev/null
+++ b/src/main/java/kr/syeyoung/dungeonsguide/config/guiconfig/Marker.java
@@ -0,0 +1,46 @@
+/*
+ * Dungeons Guide - The most intelligent Hypixel Skyblock Dungeons Mod
+ * Copyright (C) 2021 cyoung06
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published
+ * by the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <https://www.gnu.org/licenses/>.
+ */
+
+package kr.syeyoung.dungeonsguide.config.guiconfig;
+
+import lombok.AllArgsConstructor;
+import lombok.Data;
+import lombok.Getter;
+import lombok.ToString;
+
+@Getter
+@ToString
+@AllArgsConstructor
+public class Marker {
+ private final int x;
+ private final int y;
+ /**
+ * 0xABCDEFGH
+ * A: ?
+ * B: ?
+ * C: ?
+ * D: ?
+ * EF: 0~3 (TC 0x00 CL 0x01 BC 0x10 CR 0x11)
+ */
+ private final int type;
+ private final Object parent;
+
+ public int distanceSQ(Marker m2) {
+ return (m2.x - x)*(m2.x - x) + (m2.y - y)*(m2.y - y);
+ }
+}
diff --git a/src/main/java/kr/syeyoung/dungeonsguide/config/guiconfig/PanelDefaultParameterConfig.java b/src/main/java/kr/syeyoung/dungeonsguide/config/guiconfig/PanelDefaultParameterConfig.java
index 0af9e2f0..a38f1a06 100755
--- a/src/main/java/kr/syeyoung/dungeonsguide/config/guiconfig/PanelDefaultParameterConfig.java
+++ b/src/main/java/kr/syeyoung/dungeonsguide/config/guiconfig/PanelDefaultParameterConfig.java
@@ -22,6 +22,8 @@ import kr.syeyoung.dungeonsguide.features.AbstractFeature;
import kr.syeyoung.dungeonsguide.features.FeatureParameter;
import kr.syeyoung.dungeonsguide.gui.MPanel;
import kr.syeyoung.dungeonsguide.gui.elements.MButton;
+import kr.syeyoung.dungeonsguide.gui.elements.MTooltip;
+import kr.syeyoung.dungeonsguide.gui.elements.MTooltipText;
import kr.syeyoung.dungeonsguide.utils.RenderUtils;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.GuiScreen;
@@ -68,6 +70,8 @@ public class PanelDefaultParameterConfig extends MPanel {
MPanel within;
+ MTooltip mTooltip;
+ MParameter lastWithin;
@Override
public void render(int absMousex, int absMousey, int relMousex0, int relMousey0, float partialTicks, Rectangle scissor) {
int heights = 0;
@@ -80,9 +84,16 @@ public class PanelDefaultParameterConfig extends MPanel {
}
if (within instanceof MParameter) {
FeatureParameter feature = ((MParameter) within).getParameter();
- GL11.glDisable(GL11.GL_SCISSOR_TEST);
- RenderUtils.drawHoveringText(new ArrayList<String>(Arrays.asList(feature.getDescription().split("\n"))), relMousex0,relMousey0, Minecraft.getMinecraft().fontRendererObj);
- GL11.glEnable(GL11.GL_SCISSOR_TEST);
+ if (lastWithin != within) {
+ if (mTooltip != null) mTooltip.close();
+ mTooltip = new MTooltipText(Arrays.asList(feature.getDescription().split("\n")));
+ mTooltip.open(this);
+ }
+ } else {
+ if (mTooltip != null) {
+ mTooltip.close();
+ mTooltip = null;
+ }
}
}
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 7abb54b9..4e107766 100644
--- a/src/main/java/kr/syeyoung/dungeonsguide/config/guiconfig/PanelDelegate.java
+++ b/src/main/java/kr/syeyoung/dungeonsguide/config/guiconfig/PanelDelegate.java
@@ -23,18 +23,38 @@ import kr.syeyoung.dungeonsguide.features.GuiFeature;
import kr.syeyoung.dungeonsguide.gui.MPanel;
import kr.syeyoung.dungeonsguide.utils.RenderUtils;
import net.minecraft.client.Minecraft;
+import net.minecraft.client.gui.FontRenderer;
import net.minecraft.client.gui.Gui;
import net.minecraft.client.gui.ScaledResolution;
import net.minecraft.client.renderer.GlStateManager;
+import net.minecraft.client.renderer.Tessellator;
+import net.minecraft.client.renderer.WorldRenderer;
+import net.minecraft.client.renderer.vertex.DefaultVertexFormats;
+import net.minecraft.util.EnumFacing;
+import net.minecraft.util.Tuple;
+import net.minecraft.util.Vec3;
+import org.lwjgl.opengl.GL11;
import java.awt.*;
+import java.util.*;
+import java.util.List;
+import java.util.stream.Stream;
public class PanelDelegate extends MPanel {
private final GuiFeature guiFeature;
private boolean draggable = false;
- public PanelDelegate(GuiFeature guiFeature, boolean draggable) {
+ private GuiGuiLocationConfig guiGuiLocationConfig;
+
+ private Set<Marker> markerSet = new HashSet<>();
+ public PanelDelegate(GuiFeature guiFeature, boolean draggable, GuiGuiLocationConfig guiGuiLocationConfig) {
this.guiFeature = guiFeature;
this.draggable = draggable;
+ this.guiGuiLocationConfig = guiGuiLocationConfig;
+ }
+
+ public void rebuildMarker() {
+ internallyThinking = guiFeature.getFeatureRect().getRectangleNoScale();
+ applyConstraint();
}
@Override
@@ -70,6 +90,43 @@ public class PanelDelegate extends MPanel {
GlStateManager.enableBlend();
}
+ @Override
+ public void render0(ScaledResolution resolution, Point parentPoint, Rectangle parentClip, int absMousex, int absMousey, int relMousex0, int relMousey0, float partialTicks) {
+ if (selectedPart != -2) {
+ Gui.drawRect(internallyThinking.x, internallyThinking.y, internallyThinking.x + internallyThinking.width, internallyThinking.y + internallyThinking.height, 0xFF000000);
+ FontRenderer fontRenderer = Minecraft.getMinecraft().fontRendererObj;
+ fontRenderer.drawString(internallyThinking.width + "x"+internallyThinking.height, internallyThinking.x, internallyThinking.y, 0xFFFFFFFF);
+ }
+
+ GlStateManager.pushMatrix();
+ super.render0(resolution, parentPoint, parentClip, absMousex, absMousey, relMousex0, relMousey0, partialTicks);
+ GlStateManager.popMatrix();
+
+ if (snapped != null && selectedPart != -2) {
+ Tessellator tessellator = Tessellator.getInstance();
+ GlStateManager.disableTexture2D();
+ WorldRenderer worldRenderer = tessellator.getWorldRenderer();
+ worldRenderer.begin(GL11.GL_LINES, DefaultVertexFormats.POSITION_COLOR);
+ GL11.glLineWidth(1);
+ for (Tuple<Marker[], EnumFacing.Axis> markerAxisTuple : snapped) {
+// worldRenderer.pos(markerAxisTuple.getFirst()[0].getX(), markerAxisTuple.getFirst()[0].getY(), 0).color(255,255,255,255).endVertex();
+// worldRenderer.pos(markerAxisTuple.getFirst()[1].getX(), markerAxisTuple.getFirst()[1].getY(), 0).color(255,255,255,255).endVertex();
+
+ if (markerAxisTuple.getSecond() == EnumFacing.Axis.X) {
+ worldRenderer.pos(markerAxisTuple.getFirst()[0].getX(), 0, 0).color(0,255,0,255).endVertex();
+ worldRenderer.pos(markerAxisTuple.getFirst()[0].getX(), Minecraft.getMinecraft().displayHeight, 0).color(0,255,0,255).endVertex();
+ } else {
+ worldRenderer.pos(0, markerAxisTuple.getFirst()[0].getY(), 0).color(0,255,0,255).endVertex();
+ worldRenderer.pos(Minecraft.getMinecraft().displayWidth, markerAxisTuple.getFirst()[0].getY(), 0).color(0,255,0,255).endVertex();
+ }
+ }
+ tessellator.draw();
+ for (Marker marker : guiGuiLocationConfig.getMarkerSet()) {
+ Gui.drawRect(marker.getX(),marker.getY(), marker.getX()+1, marker.getY()+1, 0xFFFF0000);
+ }
+ }
+ }
+
private int selectedPart = -2;
private int lastX = 0;
@@ -78,77 +135,187 @@ public class PanelDelegate extends MPanel {
private Rectangle internallyThinking;
private Rectangle constraintApplied;
+ private Set<Tuple<Marker[], EnumFacing.Axis>> snapped = new HashSet<>();
+
public void applyConstraint() {
- Rectangle rectangle = internallyThinking.getBounds();
-
- int minWidth;
- int minHeight;
- if (guiFeature.isKeepRatio()) {
- minHeight = (int) Math.max(8, 8 / guiFeature.getDefaultRatio());
- minWidth = (int) (guiFeature.getDefaultRatio() * minHeight);
- } else {
- minWidth = 8;
- minHeight = 8;
- }
+ constraintApplied = internallyThinking.getBounds();
- if (Math.abs(rectangle.width) < minWidth) rectangle.width = rectangle.width < 0 ? -minWidth : minWidth;
- if (Math.abs(rectangle.height) < minHeight) rectangle.height = rectangle.height < 0 ? -minHeight : minHeight;
+ // SNAP Moving Point.
+ snapped.clear();
+ int scailingThreshold = 5;
+ if (selectedPart == 0){
+ Point snapPt = new Point(constraintApplied.x +constraintApplied.width, constraintApplied.y + constraintApplied.height);
+ Optional<Marker> snapX, snapY;
+ SortedMap<Integer, List<Marker>> markerSortedMap = guiGuiLocationConfig.getMarkerTreeMapByX().subMap(snapPt.x-scailingThreshold, snapPt.x +scailingThreshold);
+ snapX = markerSortedMap.values().stream()
+ .filter(Objects::nonNull)
+ .flatMap(Collection::stream)
+ .filter(a -> a.getParent() != this)
+ .min(Comparator.comparingInt(a -> (int) snapPt.distanceSq(a.getX(), a.getY())));
+ markerSortedMap = guiGuiLocationConfig.getMarkerTreeMapByY().subMap(snapPt.y-scailingThreshold, snapPt.y +scailingThreshold);
+ snapY = markerSortedMap.values().stream()
+ .filter(Objects::nonNull)
+ .flatMap(Collection::stream)
+ .filter(a -> a.getParent() != this)
+ .min(Comparator.comparingInt(a -> (int) snapPt.distanceSq(a.getX(), a.getY())));
+ snapX.ifPresent(a -> {
+ snapPt.x = a.getX();
+ });
+ snapY.ifPresent(a -> {
+ snapPt.y = a.getY();
+ });
- if (guiFeature.isKeepRatio()) {
- double ratio = guiFeature.getDefaultRatio();
+ constraintApplied = new Rectangle(constraintApplied.x, constraintApplied.y, snapPt.x - constraintApplied.x, snapPt.y - constraintApplied.y);
- if (ratio >= 1) {
- int width1 = Math.abs(rectangle.width);
- int height1 = (int) (width1 / ratio);
- rectangle.width = rectangle.width < 0 ? -width1 : width1;
- rectangle.height = rectangle.height < 0 ? -height1 : height1;
+
+
+ int minWidth;
+ int minHeight;
+ if (guiFeature.isKeepRatio()) {
+ if (guiFeature.getDefaultRatio() >= 1) {
+ minHeight = constraintApplied.height < 0 ? -8 : 8;
+ minWidth = (int) (guiFeature.getDefaultRatio() * minHeight);
+ } else {
+ minWidth = constraintApplied.width < 0 ? -8 : 8;
+ minHeight = (int) (minWidth / guiFeature.getDefaultRatio());
+ }
} else {
- int width2 = (int) Math.abs(rectangle.height * ratio);
- int height2 = Math.abs(rectangle.height);
- rectangle.width = rectangle.width < 0 ? -width2 : width2;
- rectangle.height = rectangle.height < 0 ? -height2 : height2;
+ minWidth = constraintApplied.width < 0 ? -8 : 8;
+ minHeight = constraintApplied.height < 0 ? -8 : 8;
}
- }
- if (rectangle.height < 0) {
- rectangle.height = -rectangle.height;
- rectangle.y -= rectangle.height;
- }
- if (rectangle.width < 0) {
- rectangle.width = -rectangle.width;
- rectangle.x -= rectangle.width;
+ constraintApplied.width = Math.abs(constraintApplied.width) > Math.abs(minWidth) ? constraintApplied.width :
+ Math.abs(internallyThinking.width) > Math.abs(minWidth) ? internallyThinking.width : minWidth;
+ constraintApplied.height = Math.abs(constraintApplied.height) > Math.abs(minHeight) ? constraintApplied.height :
+ Math.abs(internallyThinking.height) > Math.abs(minHeight) ? internallyThinking.height : minHeight;
+
+ if (guiFeature.isKeepRatio()) {
+ double ratio = guiFeature.getDefaultRatio();
+
+ int heightWhenWidthFix = (int) Math.abs(constraintApplied.width / ratio);
+ int widthWhenHeightFix = (int) Math.abs(ratio * constraintApplied.height);
+ if (Math.abs(heightWhenWidthFix) <= Math.abs(constraintApplied.height)) {
+ constraintApplied.height = constraintApplied.height < 0 ? -heightWhenWidthFix : heightWhenWidthFix;
+ } else if (Math.abs(widthWhenHeightFix) <= Math.abs(constraintApplied.width)) {
+ constraintApplied.width =constraintApplied.width < 0 ? - widthWhenHeightFix : widthWhenHeightFix;
+ }
+ }
+
+
+ snapX.ifPresent(a -> {
+ if (snapPt.x - constraintApplied.x == constraintApplied.width) {
+ Marker m = new Marker((int) (GuiGuiLocationConfig.facing[3].xCoord * constraintApplied.width) + constraintApplied.x, (int) (GuiGuiLocationConfig.facing[3].yCoord * constraintApplied.height) + constraintApplied.y, (int) GuiGuiLocationConfig.facing[3].zCoord, this);
+ snapped.add(new Tuple<>(new Marker[]{a, m}, EnumFacing.Axis.X));
+ }
+ });
+ snapY.ifPresent(a -> {
+ if (snapPt.y - constraintApplied.y == constraintApplied.height) {
+ Marker m = new Marker((int) (GuiGuiLocationConfig.facing[2].xCoord * constraintApplied.width) + constraintApplied.x, (int) (GuiGuiLocationConfig.facing[2].yCoord * constraintApplied.height) + constraintApplied.y, (int) GuiGuiLocationConfig.facing[2].zCoord, this);
+ snapped.add(new Tuple<>(new Marker[]{a, m}, EnumFacing.Axis.Y));
+ }
+ });
+
+ if (constraintApplied.height < 0) {
+ constraintApplied.height = -constraintApplied.height;
+ constraintApplied.y -= constraintApplied.height;
+ }
+
+ if (constraintApplied.width < 0) {
+ constraintApplied.width = -constraintApplied.width;
+ constraintApplied.x -= constraintApplied.width;
+ }
+ } else if (selectedPart == -1) {
+ for (int i : Arrays.asList(0,3,1,2)) {
+ Vec3 pt = GuiGuiLocationConfig.facing[i];
+ Marker m = new Marker((int) (pt.xCoord * constraintApplied.width) + constraintApplied.x, (int) (pt.yCoord * constraintApplied.height) + constraintApplied.y, (int) pt.zCoord, this);
+ Optional<Marker> result = guiGuiLocationConfig.getMarkerTreeMapByX().subMap(m.getX()-scailingThreshold, m.getX() +scailingThreshold).values().stream()
+ .filter(Objects::nonNull)
+ .flatMap(Collection::stream)
+ .filter(a -> a.getParent() != this)
+ .filter(a -> Math.abs(a.getX() - m.getX()) < scailingThreshold)
+ .filter(a -> ((a.getX() - pt.xCoord * constraintApplied.width) >= 0
+ && (a.getX() - pt.xCoord * constraintApplied.width + constraintApplied.width) <= Minecraft.getMinecraft().displayWidth))
+ .min(Comparator.comparingInt(a -> a.distanceSQ(m)));
+ if (result.isPresent()) {
+ int x = result.get().getX();
+ constraintApplied.x = (int) (x - pt.xCoord * constraintApplied.width);
+
+ snapped.add(new Tuple<>(new Marker[] {result.get(), m}, EnumFacing.Axis.X));
+ break;
+ }
+ }
+ for (int i : Arrays.asList(1,2,0,3)) {
+ Vec3 pt = GuiGuiLocationConfig.facing[i];
+ Marker m = new Marker((int) (pt.xCoord * constraintApplied.width) + constraintApplied.x, (int) (pt.yCoord * constraintApplied.height) + constraintApplied.y, (int) pt.zCoord, this);
+ Optional<Marker> result = guiGuiLocationConfig.getMarkerTreeMapByY().subMap(m.getY()-scailingThreshold, m.getY() +scailingThreshold).values().stream()
+ .filter(Objects::nonNull)
+ .flatMap(Collection::stream)
+ .filter(a -> a.getParent() != this)
+ .filter(a -> Math.abs(a.getY() - m.getY()) < scailingThreshold)
+ .filter(a -> ((a.getY() - pt.yCoord * constraintApplied.height) >= 0
+ && (a.getY() - pt.yCoord * constraintApplied.height+ constraintApplied.height) <= Minecraft.getMinecraft().displayHeight))
+ .min(Comparator.comparingInt(a -> a.distanceSQ(m)));
+ if (result.isPresent()) {
+ int y = result.get().getY();
+ constraintApplied.y = (int) (y - pt.yCoord * constraintApplied.height);
+ snapped.add(new Tuple<>(new Marker[] {result.get(), m}, EnumFacing.Axis.Y));
+ break;
+ }
+ }
}
- if (rectangle.x < 0) rectangle.x = 0;
- if (rectangle.y < 0) rectangle.y = 0;
- if (rectangle.x + rectangle.width + 1 >=Minecraft.getMinecraft().displayWidth) rectangle.x = Minecraft.getMinecraft().displayWidth - rectangle.width - 1;
- if (rectangle.y + rectangle.height + 1>= Minecraft.getMinecraft().displayHeight) rectangle.y = Minecraft.getMinecraft().displayHeight - rectangle.height - 1;
+ if (constraintApplied.x < 0) constraintApplied.x = 0;
+ if (constraintApplied.y < 0) constraintApplied.y = 0;
+ if (constraintApplied.x + constraintApplied.width + 1 >=Minecraft.getMinecraft().displayWidth) constraintApplied.x = Minecraft.getMinecraft().displayWidth - constraintApplied.width - 1;
+ if (constraintApplied.y + constraintApplied.height + 1>= Minecraft.getMinecraft().displayHeight) constraintApplied.y = Minecraft.getMinecraft().displayHeight - constraintApplied.height - 1;
+
+
+ setupMarkers();
+ }
+
+ Marker[] markers = new Marker[4];
+ public void setupMarkers() {
+ for (int i1 = 0; i1 < markers.length; i1++) {
+ Marker orig = markers[i1];
+ Vec3 pt = GuiGuiLocationConfig.facing[i1];
+ markers[i1] = new Marker((int) (pt.xCoord * constraintApplied.width) + constraintApplied.x, (int) (pt.yCoord * constraintApplied.height) + constraintApplied.y, (int) pt.zCoord, this);
- constraintApplied = rectangle;
+ guiGuiLocationConfig.removeAndAddMarker(orig, markers[i1]);
+ }
}
@Override
public void mouseClicked(int absMouseX, int absMouseY, int relMouseX, int relMouseY, int mouseButton) {
if (!draggable) return;
if (!lastAbsClip.contains(absMouseX, absMouseY)) return;
- if (relMouseX < 4 && relMouseY < 4) {
- selectedPart = 0;
- } else if (relMouseX < 4 && relMouseY > getBounds().height - 4) {
- selectedPart = 2;
- } else if (relMouseX > getBounds().width - 4 && relMouseY > getBounds().height - 4) {
- selectedPart = 3;
- } else if (relMouseX > getBounds().width - 4 && relMouseY < 4) {
- selectedPart = 1;
- } else {
- selectedPart = -1;
- }
- lastX = absMouseX;
- lastY = absMouseY;
- internallyThinking = guiFeature.getFeatureRect().getRectangleNoScale();
- applyConstraint();
+ if (mouseButton == 0) {
+ internallyThinking = guiFeature.getFeatureRect().getRectangleNoScale();
+ if (relMouseX < 4 && relMouseY < 4) { // TL
+ selectedPart = 0;
+ internallyThinking.y += internallyThinking.height;
+ internallyThinking.height = -internallyThinking.height;
+ internallyThinking.x += internallyThinking.width;
+ internallyThinking.width = -internallyThinking.width;
+ } else if (relMouseX < 4 && relMouseY > getBounds().height - 4) { // BL
+ selectedPart = 0;
+ internallyThinking.x += internallyThinking.width;
+ internallyThinking.width = -internallyThinking.width;
+ } else if (relMouseX > getBounds().width - 4 && relMouseY > getBounds().height - 4) { // BR
+ selectedPart = 0;
+ } else if (relMouseX > getBounds().width - 4 && relMouseY < 4) { // TR
+ selectedPart = 0;
+ internallyThinking.y += internallyThinking.height;
+ internallyThinking.height = -internallyThinking.height;
+ } else {
+ selectedPart = -1;
+ }
+ lastX = absMouseX;
+ lastY = absMouseY;
+ applyConstraint();
+ }
throw new IllegalArgumentException("bruh, a hack to stop event progress");
}
@@ -170,25 +337,19 @@ public class PanelDelegate extends MPanel {
if (selectedPart >= 0) {
Rectangle rectangle = internallyThinking;
- boolean revChangeX = (selectedPart & 0x1) == 0;
- boolean revChangeY = (selectedPart & 0x2) == 0;
int prevWidth = rectangle.width;
int prevHeight= rectangle.height;
- rectangle.width = prevWidth + (revChangeX ? -1 : 1) * dx;
- rectangle.height = prevHeight + (revChangeY ? -1 : 1 ) * dy;
+ rectangle.width = prevWidth + dx;
+ rectangle.height = prevHeight + dy;
if (rectangle.height * prevHeight <= 0 && prevHeight != rectangle.height) {
- System.out.println("Flip!");
rectangle.height += prevHeight < 0 ? 4 : -4;
}
if (rectangle.width * prevWidth <= 0 && prevWidth != rectangle.width) {
- System.out.println("Flip!");
rectangle.width += prevWidth < 0 ? 4 : -4;
}
- if (revChangeX) rectangle.x -= (rectangle.width - prevWidth );
- if (revChangeY) rectangle.y -= (rectangle.height - prevHeight);
applyConstraint();
guiFeature.setFeatureRect(new GUIRectangle(constraintApplied));
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 c4fa75d2..1c129d2e 100644
--- a/src/main/java/kr/syeyoung/dungeonsguide/config/types/GUIRectangle.java
+++ b/src/main/java/kr/syeyoung/dungeonsguide/config/types/GUIRectangle.java
@@ -64,6 +64,15 @@ public class GUIRectangle {
// (int)Math.abs(width), (int)Math.abs(height));
// }
public Rectangle getRectangleNoScale() {
+ int x = this.x, y = this.y;
+ if (Math.abs(x) > Minecraft.getMinecraft().displayWidth / 2) {
+ x = x < 0 ? -Minecraft.getMinecraft().displayWidth/2 : Minecraft.getMinecraft().displayWidth/2;
+ }
+ if (Math.abs(y) > Minecraft.getMinecraft().displayHeight / 2) {
+ y = y < 0 ? -Minecraft.getMinecraft().displayHeight/2 : Minecraft.getMinecraft().displayHeight/2;
+ }
+
+
double realX = (int) (x < 0 ? Minecraft.getMinecraft().displayWidth + x : x);
double realY = (int) (y < 0 ? Minecraft.getMinecraft().displayHeight + y : y);