aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/kr/syeyoung/dungeonsguide/config/guiconfig/PanelDelegate.java
diff options
context:
space:
mode:
authorsyeyoung <cyong06@naver.com>2021-07-20 13:35:06 +0900
committersyeyoung <cyong06@naver.com>2021-07-20 14:42:12 +0900
commiteb27fcef7ac26c71941c7911ebf6aa20254a2855 (patch)
tree65a84edb26375f34bf1f43b6ec4315700032da23 /src/main/java/kr/syeyoung/dungeonsguide/config/guiconfig/PanelDelegate.java
parent0af44a60844be83fb371c2f0eaeb2feccd1f0207 (diff)
downloadSkyblock-Dungeons-Guide-eb27fcef7ac26c71941c7911ebf6aa20254a2855.tar.gz
Skyblock-Dungeons-Guide-eb27fcef7ac26c71941c7911ebf6aa20254a2855.tar.bz2
Skyblock-Dungeons-Guide-eb27fcef7ac26c71941c7911ebf6aa20254a2855.zip
Better snapping and use the new tooltips
Diffstat (limited to 'src/main/java/kr/syeyoung/dungeonsguide/config/guiconfig/PanelDelegate.java')
-rw-r--r--src/main/java/kr/syeyoung/dungeonsguide/config/guiconfig/PanelDelegate.java283
1 files changed, 222 insertions, 61 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 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));