From d1621e334a9df13294e5694582769251e8e3294f Mon Sep 17 00:00:00 2001 From: syeyoung Date: Fri, 27 Jan 2023 15:23:37 +0900 Subject: - Snapping, and new gui config Signed-off-by: syeyoung --- mod/build.gradle | 3 +- .../mod/config/guiconfig/RootConfigPanel.java | 5 +- .../guiconfig/location/GuiGuiLocationConfig.java | 128 ++-- .../mod/config/guiconfig/location/Marker.java | 90 +-- .../config/guiconfig/location/PanelDelegate.java | 808 ++++++++++----------- .../guiconfig/location2/HUDConfigRootWidget.java | 314 ++++++++ .../guiconfig/location2/HUDLocationConfig.java | 43 ++ .../guiconfig/location2/HUDWidgetWrapper.java | 392 ++++++++++ .../config/guiconfig/location2/MarkerProvider.java | 27 + .../guiconfig/location2/WidgetPopupMenu.java | 33 + .../mod/config/types/GUIPosition.java | 143 ++++ .../mod/config/types/GUIRectangle.java | 81 --- .../mod/config/types/TCGUIPosition.java | 54 ++ .../mod/config/types/TCGUIRectangle.java | 50 -- .../mod/config/types/TypeConverterRegistry.java | 2 +- .../mod/cosmetics/CosmeticsManager.java | 1 + .../mod/features/AbstractHUDFeature.java | 83 ++- .../mod/features/RawRenderingGuiFeature.java | 75 +- .../features/impl/advanced/FeatureDebugTrap.java | 2 +- .../impl/advanced/FeatureDebuggableMap.java | 23 +- .../impl/advanced/FeatureRoomCoordDisplay.java | 2 +- .../impl/advanced/FeatureRoomDebugInfo.java | 2 +- .../mod/features/impl/boss/FeatureBossHealth.java | 8 +- .../features/impl/boss/FeatureCurrentPhase.java | 2 +- .../features/impl/boss/FeatureTerracotaTimer.java | 2 +- .../impl/boss/FeatureThornBearPercentage.java | 2 +- .../impl/boss/FeatureThornSpiritBowTimer.java | 2 +- .../dungeon/FeatureDungeonCurrentRoomSecrets.java | 2 +- .../impl/dungeon/FeatureDungeonDeaths.java | 10 +- .../features/impl/dungeon/FeatureDungeonMap.java | 23 +- .../impl/dungeon/FeatureDungeonMilestone.java | 6 +- .../impl/dungeon/FeatureDungeonRealTime.java | 2 +- .../impl/dungeon/FeatureDungeonRoomName.java | 2 +- .../impl/dungeon/FeatureDungeonSBTime.java | 2 +- .../features/impl/dungeon/FeatureDungeonScore.java | 2 +- .../impl/dungeon/FeatureDungeonSecrets.java | 2 +- .../features/impl/dungeon/FeatureDungeonTombs.java | 5 +- .../impl/dungeon/FeatureWarnLowHealth.java | 6 +- .../impl/dungeon/FeatureWatcherWarning.java | 3 +- .../features/impl/etc/FeatureCooldownCounter.java | 7 +- .../impl/etc/ability/FeatureAbilityCooldown.java | 7 +- .../mod/features/impl/party/FeaturePartyList.java | 7 +- .../mod/features/impl/party/FeaturePartyReady.java | 7 +- .../mod/features/impl/secret/FeatureActions.java | 7 +- .../impl/secret/FeatureSoulRoomWarning.java | 2 +- .../mechanicbrowser/FeatureMechanicBrowse.java | 14 +- .../mod/features/text/TextHUDFeature.java | 111 ++- .../dungeonsguide/mod/guiv2/DomElement.java | 13 +- .../dungeonsguide/mod/guiv2/GuiScreenAdapter.java | 2 +- .../mod/guiv2/elements/GlobalHUDScale.java | 124 ++++ .../mod/guiv2/elements/RoundRect.java | 2 +- .../mod/overlay/GUIRectPositioner.java | 40 + .../mod/overlay/GUIRectanglePositioner.java | 63 -- .../dungeonsguide/mod/overlay/OverlayManager.java | 15 +- .../assets/dungeonsguide/gui/config/hudconfig.gui | 28 + .../assets/dungeonsguide/gui/config/popupmenu.gui | 49 ++ 56 files changed, 2051 insertions(+), 889 deletions(-) create mode 100644 mod/src/main/java/kr/syeyoung/dungeonsguide/mod/config/guiconfig/location2/HUDConfigRootWidget.java create mode 100644 mod/src/main/java/kr/syeyoung/dungeonsguide/mod/config/guiconfig/location2/HUDLocationConfig.java create mode 100644 mod/src/main/java/kr/syeyoung/dungeonsguide/mod/config/guiconfig/location2/HUDWidgetWrapper.java create mode 100644 mod/src/main/java/kr/syeyoung/dungeonsguide/mod/config/guiconfig/location2/MarkerProvider.java create mode 100644 mod/src/main/java/kr/syeyoung/dungeonsguide/mod/config/guiconfig/location2/WidgetPopupMenu.java create mode 100644 mod/src/main/java/kr/syeyoung/dungeonsguide/mod/config/types/GUIPosition.java delete mode 100644 mod/src/main/java/kr/syeyoung/dungeonsguide/mod/config/types/GUIRectangle.java create mode 100644 mod/src/main/java/kr/syeyoung/dungeonsguide/mod/config/types/TCGUIPosition.java delete mode 100644 mod/src/main/java/kr/syeyoung/dungeonsguide/mod/config/types/TCGUIRectangle.java create mode 100644 mod/src/main/java/kr/syeyoung/dungeonsguide/mod/guiv2/elements/GlobalHUDScale.java create mode 100644 mod/src/main/java/kr/syeyoung/dungeonsguide/mod/overlay/GUIRectPositioner.java delete mode 100644 mod/src/main/java/kr/syeyoung/dungeonsguide/mod/overlay/GUIRectanglePositioner.java create mode 100644 mod/src/main/resources/assets/dungeonsguide/gui/config/hudconfig.gui create mode 100644 mod/src/main/resources/assets/dungeonsguide/gui/config/popupmenu.gui (limited to 'mod') diff --git a/mod/build.gradle b/mod/build.gradle index 53ed0be3..ad799d39 100644 --- a/mod/build.gradle +++ b/mod/build.gradle @@ -71,7 +71,8 @@ dependencies { if (testWithNeu) { runtimeOnly 'org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.7.22' - add("devenvMod", 'com.github.notenoughupdates:notenoughupdates:1f4d692:all') +// add("devenvMod", 'com.github.notenoughupdates:notenoughupdates:1f4d692:all') +// add("devenvMod", 'com.github.notenoughupdates:notenoughupdates:museumthing-SNAPSHOT:all') } def files= fileTree("../runtime/mods2").filter { it.isFile() } add("devenvMod", files) diff --git a/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/config/guiconfig/RootConfigPanel.java b/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/config/guiconfig/RootConfigPanel.java index 0bc16fbb..ebe09875 100644 --- a/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/config/guiconfig/RootConfigPanel.java +++ b/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/config/guiconfig/RootConfigPanel.java @@ -21,10 +21,13 @@ package kr.syeyoung.dungeonsguide.mod.config.guiconfig; import com.google.common.base.Function; import kr.syeyoung.dungeonsguide.launcher.auth.AuthManager; import kr.syeyoung.dungeonsguide.mod.config.guiconfig.location.GuiGuiLocationConfig; +import kr.syeyoung.dungeonsguide.mod.config.guiconfig.location2.HUDLocationConfig; import kr.syeyoung.dungeonsguide.mod.features.AbstractFeature; import kr.syeyoung.dungeonsguide.mod.features.FeatureRegistry; import kr.syeyoung.dungeonsguide.mod.gui.MPanel; import kr.syeyoung.dungeonsguide.mod.gui.elements.*; +import kr.syeyoung.dungeonsguide.mod.guiv2.GuiScreenAdapter; +import kr.syeyoung.dungeonsguide.mod.guiv2.elements.GlobalHUDScale; import kr.syeyoung.dungeonsguide.mod.utils.RenderUtils; import lombok.Getter; import lombok.Setter; @@ -99,7 +102,7 @@ public class RootConfigPanel extends MPanelScaledGUI { guiRelocate = new MButton(); guiRelocate.setText("Edit Gui Locations"); guiRelocate.setOnActionPerformed(() -> { - Minecraft.getMinecraft().displayGuiScreen(new GuiGuiLocationConfig(gui, null)); + Minecraft.getMinecraft().displayGuiScreen(new GuiScreenAdapter(new GlobalHUDScale(new HUDLocationConfig()))); guiRelocate.setBeingClicked(false); }); guiRelocate.setBorder(RenderUtils.blendTwoColors(0xFF141414,0x7702EE67)); diff --git a/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/config/guiconfig/location/GuiGuiLocationConfig.java b/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/config/guiconfig/location/GuiGuiLocationConfig.java index 365a1182..d88991be 100755 --- a/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/config/guiconfig/location/GuiGuiLocationConfig.java +++ b/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/config/guiconfig/location/GuiGuiLocationConfig.java @@ -42,24 +42,24 @@ public class GuiGuiLocationConfig extends MGui { @Getter private final GuiScreen before; - @Getter - private TreeMap> markerTreeMapByX = new TreeMap<>(); - @Getter - private TreeMap> markerTreeMapByY = new TreeMap<>(); - @Getter - private Set markerSet = new HashSet<>(); - - - Marker[] markers = new Marker[4]; +// @Getter +// private TreeMap> markerTreeMapByX = new TreeMap<>(); +// @Getter +// private TreeMap> markerTreeMapByY = new TreeMap<>(); +// @Getter +// private Set 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 AbstractHUDFeature && feature.isEnabled()) { - getMainPanel().add(new PanelDelegate((AbstractHUDFeature) feature, featureWhitelist == null || feature == featureWhitelist, this)); - } - } +// for (AbstractFeature feature : FeatureRegistry.getFeatureList()) { +// if (feature instanceof AbstractHUDFeature && feature.isEnabled()) { +// getMainPanel().add(new PanelDelegate((AbstractHUDFeature) feature, featureWhitelist == null || feature == featureWhitelist, this)); +// } +// } getMainPanel().setBackgroundColor(new Color(0,0,0, 100)); } @@ -71,49 +71,49 @@ public class GuiGuiLocationConfig extends MGui { 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; - } - }); - markerTreeMapByY.compute(newM.getY(), (k,v) -> { - if (v == null) { - return new ArrayList<>(Arrays.asList(newM)); - } else { - v.add(newM); - return v; - } - }); - markerSet.add(newM); - } - } +// 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; +// } +// }); +// markerTreeMapByY.compute(newM.getY(), (k,v) -> { +// if (v == null) { +// return new ArrayList<>(Arrays.asList(newM)); +// } else { +// v.add(newM); +// return v; +// } +// }); +// 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]); - } +// 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 @@ -151,15 +151,15 @@ 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(); - } - } +// markerTreeMapByX.clear(); +// markerTreeMapByY.clear(); +// markerSet.clear(); +// setupMarkers(); +// for (MPanel childComponent : getMainPanel().getChildComponents()) { +// if (childComponent instanceof PanelDelegate) { +// ((PanelDelegate) childComponent).rebuildMarker(); +// } +// } } diff --git a/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/config/guiconfig/location/Marker.java b/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/config/guiconfig/location/Marker.java index 10683425..b622e3b6 100644 --- a/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/config/guiconfig/location/Marker.java +++ b/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/config/guiconfig/location/Marker.java @@ -1,45 +1,45 @@ -/* - * 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 . - */ - -package kr.syeyoung.dungeonsguide.mod.config.guiconfig.location; - -import lombok.AllArgsConstructor; -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); - } -} +///* +// * 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 . +// */ +// +//package kr.syeyoung.dungeonsguide.mod.config.guiconfig.location; +// +//import lombok.AllArgsConstructor; +//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/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/config/guiconfig/location/PanelDelegate.java b/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/config/guiconfig/location/PanelDelegate.java index 3bcae70b..b12e59c6 100644 --- a/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/config/guiconfig/location/PanelDelegate.java +++ b/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/config/guiconfig/location/PanelDelegate.java @@ -1,404 +1,404 @@ -/* - * 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 . - */ - -package kr.syeyoung.dungeonsguide.mod.config.guiconfig.location; - - -import kr.syeyoung.dungeonsguide.mod.config.types.GUIRectangle; -import kr.syeyoung.dungeonsguide.mod.features.AbstractHUDFeature; -import kr.syeyoung.dungeonsguide.mod.gui.MPanel; -import kr.syeyoung.dungeonsguide.mod.gui.elements.MPopupMenu; -import kr.syeyoung.dungeonsguide.mod.gui.elements.MTooltip; -import kr.syeyoung.dungeonsguide.mod.utils.cursor.EnumCursor; -import net.minecraft.client.Minecraft; -import net.minecraft.client.gui.Gui; -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.List; -import java.util.*; - -public class PanelDelegate extends MPanel { - private final AbstractHUDFeature guiFeature; - private boolean draggable = false; - private GuiGuiLocationConfig guiGuiLocationConfig; - - private Set markerSet = new HashSet<>(); - public PanelDelegate(AbstractHUDFeature guiFeature, boolean draggable, GuiGuiLocationConfig guiGuiLocationConfig) { - this.guiFeature = guiFeature; - this.draggable = draggable; - this.guiGuiLocationConfig = guiGuiLocationConfig; - } - - public void rebuildMarker() { - internallyThinking = guiFeature.getFeatureRect().getRectangleNoScale(); - applyConstraint(); - } - - @Override - public Rectangle getBounds() { - Rectangle rectangle = guiFeature.getFeatureRect().getRectangle(); - return new Rectangle(rectangle.x, rectangle.y, rectangle.width, rectangle.height); - } - - @Override - public void render(int absMousex, int absMousey, int relMouseX, int relMouseY, float partialTicks, Rectangle scissor) { - if (!guiFeature.isEnabled()) return; - - GlStateManager.pushMatrix(); - guiFeature.drawDemo(partialTicks); - GlStateManager.popMatrix(); - if (!draggable) return; - Gui.drawRect(0,0, 4, 4, 0xFFBBBBBB); - Gui.drawRect(0, getBounds().height - 4, 4, getBounds().height, 0xFFBBBBBB); - Gui.drawRect(getBounds().width - 4,0, getBounds().width, 4, 0xFFBBBBBB); - Gui.drawRect(getBounds().width - 4,getBounds().height - 4, getBounds().width, getBounds().height, 0xFFBBBBBB); - if (lastAbsClip.contains(absMousex, absMousey)) { - if (relMouseX < 4 && relMouseY < 4) { - Gui.drawRect(0,0, 4, 4, 0x55FFFFFF); - } else if (relMouseX < 4 && relMouseY > getBounds().height - 4) { - Gui.drawRect(0, getBounds().height - 4, 4, getBounds().height, 0x55FFFFFF); - } else if (relMouseX > getBounds().width - 4 && relMouseY > getBounds().height - 4) { - Gui.drawRect(getBounds().width - 4,getBounds().height - 4, getBounds().width, getBounds().height, 0x55FFFFFF); - } else if (relMouseX > getBounds().width - 4 && relMouseY < 4) { - Gui.drawRect(getBounds().width - 4,0, getBounds().width, 4, 0x55FFFFFF); - } else if (selectedPart == -2){ - Gui.drawRect(0,0, getBounds().width, getBounds().height, 0x55FFFFFF); - } - } - GlStateManager.enableBlend(); - } - - @Override - public void render0(double scale, Point parentPoint, Rectangle parentClip, int absMousex, int absMousey, int relMousex0, int relMousey0, float partialTicks) { - GlStateManager.pushMatrix(); - super.render0(scale, 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 markerAxisTuple : snapped) { - 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; - private int lastY = 0; - - private Rectangle internallyThinking; - private Rectangle constraintApplied; - - private Set> snapped = new HashSet<>(); - - public void applyConstraint() { - constraintApplied = internallyThinking.getBounds(); - - // SNAP Moving Point. - snapped.clear(); - int scailingThreshold = 5; - if (selectedPart == 0){ - Point snapPt = new Point(constraintApplied.x +constraintApplied.width, constraintApplied.y + constraintApplied.height); - Optional snapX, snapY; - SortedMap> 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(); - }); - - constraintApplied = new Rectangle(constraintApplied.x, constraintApplied.y, snapPt.x - constraintApplied.x, snapPt.y - constraintApplied.y); - - - - 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 { - minWidth = constraintApplied.width < 0 ? -8 : 8; - minHeight = constraintApplied.height < 0 ? -8 : 8; - } - - - 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 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 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 (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); - - guiGuiLocationConfig.removeAndAddMarker(orig, markers[i1]); - } - } - - MTooltip mTooltip; - - @Override - public void mouseClicked(int absMouseX, int absMouseY, int relMouseX, int relMouseY, int mouseButton) { - if (!draggable) return; - if (!guiFeature.isEnabled()) return; - if (getTooltipsOpen() > 0) return; - if (!lastAbsClip.contains(absMouseX, absMouseY)) return; - 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(); - - } else if (getTooltipsOpen() == 0){ - if (mTooltip != null) mTooltip.close(); - mTooltip = new MPopupMenu(absMouseX, absMouseY, guiFeature.getTooltipForEditor(guiGuiLocationConfig)); - mTooltip.setScale(2.0f); - mTooltip.open(this); - } - throw new IllegalArgumentException("bruh, a hack to stop event progress"); - } - - @Override - public void mouseReleased(int absMouseX, int absMouseY, int relMouseX, int relMouseY, int state) { - if (!draggable) return; - if (!guiFeature.isEnabled()) return; - if (selectedPart >= -1) { - guiFeature.setFeatureRect(new GUIRectangle(constraintApplied)); - } - - selectedPart = -2; - } - - @Override - public void mouseClickMove(int absMouseX, int absMouseY, int relMouseX, int relMouseY, int clickedMouseButton, long timeSinceLastClick) { - if (!draggable) return; - if (!guiFeature.isEnabled()) return; - int dx = (absMouseX - lastX); - int dy = (absMouseY - lastY); - if (selectedPart >= 0) { - Rectangle rectangle = internallyThinking; - - int prevWidth = rectangle.width; - int prevHeight= rectangle.height; - - rectangle.width = prevWidth + dx; - rectangle.height = prevHeight + dy; - - if (rectangle.height * prevHeight <= 0 && prevHeight != rectangle.height) { - rectangle.height += prevHeight < 0 ? 4 : -4; - } - if (rectangle.width * prevWidth <= 0 && prevWidth != rectangle.width) { - rectangle.width += prevWidth < 0 ? 4 : -4; - } - - - applyConstraint(); - guiFeature.setFeatureRect(new GUIRectangle(constraintApplied)); - lastX = absMouseX; - lastY = absMouseY; - throw new IllegalArgumentException("bruh, a hack to stop event progress"); - } else if (selectedPart == -1){ - Rectangle rectangle = internallyThinking; - rectangle.translate(dx, dy); - applyConstraint(); - guiFeature.setFeatureRect(new GUIRectangle(constraintApplied)); - lastX = absMouseX; - lastY = absMouseY; - } - } - - @Override - public void mouseMoved(int absMouseX, int absMouseY, int relMouseX, int relMouseY) { - if (!draggable) return; - if (!guiFeature.isEnabled()) return; - if (getTooltipsOpen() > 0) return; - - if (selectedPart == -1) { - setCursor(EnumCursor.CLOSED_HAND); - } else if (selectedPart >= 0) { - if (internallyThinking.width < 0 && internallyThinking.height < 0) { - setCursor(EnumCursor.RESIZE_TLDR); - } else if (internallyThinking.width < 0 && internallyThinking.height >= 0) { - setCursor(EnumCursor.RESIZE_TRDL); - } else if (internallyThinking.width >= 0 && internallyThinking.height >= 0) { - setCursor(EnumCursor.RESIZE_TLDR); - } else if (internallyThinking.width >= 0 && internallyThinking.height < 0) { - setCursor(EnumCursor.RESIZE_TRDL); - } - } else if (lastAbsClip.contains(absMouseX, absMouseY)) { - if (relMouseX < 4 && relMouseY < 4) { - setCursor(EnumCursor.RESIZE_TLDR); - } else if (relMouseX < 4 && relMouseY > getBounds().height - 4) { - setCursor(EnumCursor.RESIZE_TRDL); - } else if (relMouseX > getBounds().width - 4 && relMouseY > getBounds().height - 4) { - setCursor(EnumCursor.RESIZE_TLDR); - } else if (relMouseX > getBounds().width - 4 && relMouseY < 4) { - setCursor(EnumCursor.RESIZE_TRDL); - } else { - setCursor(EnumCursor.OPEN_HAND); - } - } - } -} +///* +// * 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 . +// */ +// +//package kr.syeyoung.dungeonsguide.mod.config.guiconfig.location; +// +// +//import kr.syeyoung.dungeonsguide.mod.features.AbstractHUDFeature; +//import kr.syeyoung.dungeonsguide.mod.gui.MPanel; +//import kr.syeyoung.dungeonsguide.mod.gui.elements.MPopupMenu; +//import kr.syeyoung.dungeonsguide.mod.gui.elements.MTooltip; +//import kr.syeyoung.dungeonsguide.mod.utils.cursor.EnumCursor; +//import net.minecraft.client.Minecraft; +//import net.minecraft.client.gui.Gui; +//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.List; +//import java.util.*; +// +//public class PanelDelegate extends MPanel { +// private final AbstractHUDFeature guiFeature; +// private boolean draggable = false; +// private GuiGuiLocationConfig guiGuiLocationConfig; +// +// private Set markerSet = new HashSet<>(); +// public PanelDelegate(AbstractHUDFeature guiFeature, boolean draggable, GuiGuiLocationConfig guiGuiLocationConfig) { +// this.guiFeature = guiFeature; +// this.draggable = draggable; +// this.guiGuiLocationConfig = guiGuiLocationConfig; +// } +// +// public void rebuildMarker() { +//// internallyThinking = guiFeature.getFeatureRect().getRectangleNoScale(); +// applyConstraint(); +// } +// +// @Override +// public Rectangle getBounds() { +//// Rectangle rectangle = guiFeature.getFeatureRect().getRectangle(); +//// return new Rectangle(rectangle.x, rectangle.y, rectangle.width, rectangle.height); +// return null; +// } +// +// @Override +// public void render(int absMousex, int absMousey, int relMouseX, int relMouseY, float partialTicks, Rectangle scissor) { +// if (!guiFeature.isEnabled()) return; +// +// GlStateManager.pushMatrix(); +// guiFeature.drawDemo(partialTicks); +// GlStateManager.popMatrix(); +// if (!draggable) return; +// Gui.drawRect(0,0, 4, 4, 0xFFBBBBBB); +// Gui.drawRect(0, getBounds().height - 4, 4, getBounds().height, 0xFFBBBBBB); +// Gui.drawRect(getBounds().width - 4,0, getBounds().width, 4, 0xFFBBBBBB); +// Gui.drawRect(getBounds().width - 4,getBounds().height - 4, getBounds().width, getBounds().height, 0xFFBBBBBB); +// if (lastAbsClip.contains(absMousex, absMousey)) { +// if (relMouseX < 4 && relMouseY < 4) { +// Gui.drawRect(0,0, 4, 4, 0x55FFFFFF); +// } else if (relMouseX < 4 && relMouseY > getBounds().height - 4) { +// Gui.drawRect(0, getBounds().height - 4, 4, getBounds().height, 0x55FFFFFF); +// } else if (relMouseX > getBounds().width - 4 && relMouseY > getBounds().height - 4) { +// Gui.drawRect(getBounds().width - 4,getBounds().height - 4, getBounds().width, getBounds().height, 0x55FFFFFF); +// } else if (relMouseX > getBounds().width - 4 && relMouseY < 4) { +// Gui.drawRect(getBounds().width - 4,0, getBounds().width, 4, 0x55FFFFFF); +// } else if (selectedPart == -2){ +// Gui.drawRect(0,0, getBounds().width, getBounds().height, 0x55FFFFFF); +// } +// } +// GlStateManager.enableBlend(); +// } +// +// @Override +// public void render0(double scale, Point parentPoint, Rectangle parentClip, int absMousex, int absMousey, int relMousex0, int relMousey0, float partialTicks) { +// GlStateManager.pushMatrix(); +// super.render0(scale, 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 markerAxisTuple : snapped) { +// 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; +// private int lastY = 0; +// +// private Rectangle internallyThinking; +// private Rectangle constraintApplied; +// +// private Set> snapped = new HashSet<>(); +// +// public void applyConstraint() { +// constraintApplied = internallyThinking.getBounds(); +// +// // SNAP Moving Point. +// snapped.clear(); +// int scailingThreshold = 5; +// if (selectedPart == 0){ +// Point snapPt = new Point(constraintApplied.x +constraintApplied.width, constraintApplied.y + constraintApplied.height); +// Optional snapX, snapY; +// SortedMap> 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(); +// }); +// +// constraintApplied = new Rectangle(constraintApplied.x, constraintApplied.y, snapPt.x - constraintApplied.x, snapPt.y - constraintApplied.y); +// +// +// +// 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 { +// minWidth = constraintApplied.width < 0 ? -8 : 8; +// minHeight = constraintApplied.height < 0 ? -8 : 8; +// } +// +// +// 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 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 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 (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); +// +// guiGuiLocationConfig.removeAndAddMarker(orig, markers[i1]); +// } +// } +// +// MTooltip mTooltip; +// +// @Override +// public void mouseClicked(int absMouseX, int absMouseY, int relMouseX, int relMouseY, int mouseButton) { +// if (!draggable) return; +// if (!guiFeature.isEnabled()) return; +// if (getTooltipsOpen() > 0) return; +// if (!lastAbsClip.contains(absMouseX, absMouseY)) return; +// 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(); +// +// } else if (getTooltipsOpen() == 0){ +// if (mTooltip != null) mTooltip.close(); +// mTooltip = new MPopupMenu(absMouseX, absMouseY, guiFeature.getTooltipForEditor(guiGuiLocationConfig)); +// mTooltip.setScale(2.0f); +// mTooltip.open(this); +// } +// throw new IllegalArgumentException("bruh, a hack to stop event progress"); +// } +// +// @Override +// public void mouseReleased(int absMouseX, int absMouseY, int relMouseX, int relMouseY, int state) { +// if (!draggable) return; +// if (!guiFeature.isEnabled()) return; +// if (selectedPart >= -1) { +// guiFeature.setFeatureRect(new GUIRectangle(constraintApplied)); +// } +// +// selectedPart = -2; +// } +// +// @Override +// public void mouseClickMove(int absMouseX, int absMouseY, int relMouseX, int relMouseY, int clickedMouseButton, long timeSinceLastClick) { +// if (!draggable) return; +// if (!guiFeature.isEnabled()) return; +// int dx = (absMouseX - lastX); +// int dy = (absMouseY - lastY); +// if (selectedPart >= 0) { +// Rectangle rectangle = internallyThinking; +// +// int prevWidth = rectangle.width; +// int prevHeight= rectangle.height; +// +// rectangle.width = prevWidth + dx; +// rectangle.height = prevHeight + dy; +// +// if (rectangle.height * prevHeight <= 0 && prevHeight != rectangle.height) { +// rectangle.height += prevHeight < 0 ? 4 : -4; +// } +// if (rectangle.width * prevWidth <= 0 && prevWidth != rectangle.width) { +// rectangle.width += prevWidth < 0 ? 4 : -4; +// } +// +// +// applyConstraint(); +// guiFeature.setFeatureRect(new GUIRectangle(constraintApplied)); +// lastX = absMouseX; +// lastY = absMouseY; +// throw new IllegalArgumentException("bruh, a hack to stop event progress"); +// } else if (selectedPart == -1){ +// Rectangle rectangle = internallyThinking; +// rectangle.translate(dx, dy); +// applyConstraint(); +// guiFeature.setFeatureRect(new GUIRectangle(constraintApplied)); +// lastX = absMouseX; +// lastY = absMouseY; +// } +// } +// +// @Override +// public void mouseMoved(int absMouseX, int absMouseY, int relMouseX, int relMouseY) { +// if (!draggable) return; +// if (!guiFeature.isEnabled()) return; +// if (getTooltipsOpen() > 0) return; +// +// if (selectedPart == -1) { +// setCursor(EnumCursor.CLOSED_HAND); +// } else if (selectedPart >= 0) { +// if (internallyThinking.width < 0 && internallyThinking.height < 0) { +// setCursor(EnumCursor.RESIZE_TLDR); +// } else if (internallyThinking.width < 0 && internallyThinking.height >= 0) { +// setCursor(EnumCursor.RESIZE_TRDL); +// } else if (internallyThinking.width >= 0 && internallyThinking.height >= 0) { +// setCursor(EnumCursor.RESIZE_TLDR); +// } else if (internallyThinking.width >= 0 && internallyThinking.height < 0) { +// setCursor(EnumCursor.RESIZE_TRDL); +// } +// } else if (lastAbsClip.contains(absMouseX, absMouseY)) { +// if (relMouseX < 4 && relMouseY < 4) { +// setCursor(EnumCursor.RESIZE_TLDR); +// } else if (relMouseX < 4 && relMouseY > getBounds().height - 4) { +// setCursor(EnumCursor.RESIZE_TRDL); +// } else if (relMouseX > getBounds().width - 4 && relMouseY > getBounds().height - 4) { +// setCursor(EnumCursor.RESIZE_TLDR); +// } else if (relMouseX > getBounds().width - 4 && relMouseY < 4) { +// setCursor(EnumCursor.RESIZE_TRDL); +// } else { +// setCursor(EnumCursor.OPEN_HAND); +// } +// } +// } +//} diff --git a/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/config/guiconfig/location2/HUDConfigRootWidget.java b/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/config/guiconfig/location2/HUDConfigRootWidget.java new file mode 100644 index 00000000..6fe1a8e9 --- /dev/null +++ b/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/config/guiconfig/location2/HUDConfigRootWidget.java @@ -0,0 +1,314 @@ +/* + * Dungeons Guide - The most intelligent Hypixel Skyblock Dungeons Mod + * Copyright (C) 2023 cyoung06 (syeyoung) + * + * 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 . + */ + +package kr.syeyoung.dungeonsguide.mod.config.guiconfig.location2; + +import kr.syeyoung.dungeonsguide.mod.config.types.GUIPosition; +import kr.syeyoung.dungeonsguide.mod.features.AbstractFeature; +import kr.syeyoung.dungeonsguide.mod.features.AbstractHUDFeature; +import kr.syeyoung.dungeonsguide.mod.features.FeatureRegistry; +import kr.syeyoung.dungeonsguide.mod.guiv2.DomElement; +import kr.syeyoung.dungeonsguide.mod.guiv2.Widget; +import kr.syeyoung.dungeonsguide.mod.guiv2.layouter.Layouter; +import kr.syeyoung.dungeonsguide.mod.guiv2.primitive.ConstraintBox; +import kr.syeyoung.dungeonsguide.mod.guiv2.primitive.Position; +import kr.syeyoung.dungeonsguide.mod.guiv2.primitive.Rect; +import kr.syeyoung.dungeonsguide.mod.guiv2.primitive.Size; +import kr.syeyoung.dungeonsguide.mod.guiv2.renderer.OnlyChildrenRenderer; +import kr.syeyoung.dungeonsguide.mod.guiv2.renderer.Renderer; +import kr.syeyoung.dungeonsguide.mod.guiv2.renderer.RenderingContext; +import kr.syeyoung.dungeonsguide.mod.overlay.GUIRectPositioner; +import kr.syeyoung.dungeonsguide.mod.overlay.OverlayWidget; +import kr.syeyoung.dungeonsguide.mod.overlay.Positioner; +import lombok.Getter; +import net.minecraft.client.gui.Gui; +import net.minecraft.client.renderer.GlStateManager; + +import java.util.*; +import java.util.stream.Collectors; +import java.util.stream.Stream; + + +// Stack'em +// +public class HUDConfigRootWidget extends Widget implements Layouter, Renderer { + + private List widgets = new ArrayList<>(); + private List widgets2= new ArrayList<>(); + + private TreeSet markersX = new TreeSet<>(Comparator.comparingDouble(Position::getX)); + private TreeSet markersY = new TreeSet<>(Comparator.comparingDouble(Position::getY)); + + private double ySnap = -1; + private double xSnap = -1; + + private Position getVerticalSnapMarker(Position x) { + Position pos1 = markersX.floor(x); + Position pos2 = markersX.ceiling(x); + return Stream.of(pos1, pos2) + .filter(Objects::nonNull) + .filter(a -> Math.abs(a.x - x.x) <= 3) + .min(Comparator.comparingDouble(a -> Math.abs(a.x - x.x))) + .orElse(null); + } + + private Position getHorizontalSnapMarker(Position x) { + Position pos1 = markersY.floor(x); + Position pos2 = markersY.ceiling(x); + return Stream.of(pos1, pos2) + .filter(Objects::nonNull) + .filter(a -> Math.abs(a.y - x.y) <= 3) + .min(Comparator.comparingDouble(a -> Math.abs(a.y - x.y))) + .orElse(null); + } + + private void updateMarkers(HUDWidgetWrapper skip) { + markersX.clear(); + markersY.clear(); + + for (HUDWidgetWrapper widgetWrapper : widgets2) { + if (widgetWrapper == skip) continue; + if (widgetWrapper.getDemoWidget() instanceof MarkerProvider) { + List pos = ((MarkerProvider) widgetWrapper.getDemoWidget()).getMarkers(); + pos.stream() + .map(a -> new Position(a.x + widgetWrapper.getDomElement().getRelativeBound().getX(), a.y + widgetWrapper.getDomElement().getRelativeBound().getY())) + .forEach(a -> { + markersY.add(a); + markersX.add(a); + }); + } + } + markersX.add(new Position(lastWidth/2, 0)); + markersY.add(new Position(0, lastHeight/2)); + } + +