From d1c36c2412b98350f8336e38361e49b3655982d5 Mon Sep 17 00:00:00 2001 From: syeyoung Date: Sun, 1 Aug 2021 23:43:10 +0900 Subject: Too many changes to describe Config gui overhaul. --- .../commands/CommandDungeonsGuide.java | 1 - .../guiconfig/location/GuiGuiLocationConfig.java | 1 - .../config/guiconfig/location/PanelDelegate.java | 405 +++++++++++++++++++++ .../config/guiconfig/nyu/ConfigPanelCreator.java | 40 ++ .../config/guiconfig/nyu/GuiConfigV2.java | 19 +- .../config/guiconfig/nyu/MCategory.java | 17 +- .../config/guiconfig/nyu/MCategoryElement.java | 7 +- .../config/guiconfig/nyu/MFeature.java | 148 ++++++++ .../config/guiconfig/nyu/MFeatureEdit.java | 86 +++++ .../config/guiconfig/nyu/MPanelCategory.java | 11 +- .../config/guiconfig/nyu/MParameterEdit.java | 156 ++++++++ .../config/guiconfig/nyu/RootConfigPanel.java | 81 ++++- .../config/guiconfig/old/ConfigPanelCreator.java | 40 -- .../config/guiconfig/old/FeatureEditPane.java | 108 ------ .../config/guiconfig/old/GuiConfig.java | 92 ----- .../guiconfig/old/GuiParameterValueEdit.java | 117 ------ .../config/guiconfig/old/MFeature.java | 139 ------- .../config/guiconfig/old/MParameter.java | 142 -------- .../guiconfig/old/PanelDefaultParameterConfig.java | 105 ------ .../config/guiconfig/old/PanelDelegate.java | 405 --------------------- .../dungeonsguide/features/AbstractFeature.java | 12 +- .../dungeonsguide/features/FeatureRegistry.java | 2 + .../dungeonsguide/features/GuiFeature.java | 8 +- .../features/impl/boss/FeatureWarningOnPortal.java | 21 +- .../impl/cosmetics/FeatureNicknameColor.java | 8 +- .../impl/cosmetics/FeatureNicknamePrefix.java | 8 +- .../features/impl/cosmetics/PrefixSelectorGUI.java | 5 +- .../impl/dungeon/FeatureDungeonRoomName.java | 2 +- .../party/playerpreview/DataRendererEditor.java | 5 +- .../playerpreview/FeatureViewPlayerOnJoin.java | 22 +- .../impl/secret/FeatureMechanicBrowse.java | 2 - .../features/text/PanelTextParameterConfig.java | 10 +- .../features/text/TextHUDFeature.java | 73 ++-- .../java/kr/syeyoung/dungeonsguide/gui/MGui.java | 1 + .../java/kr/syeyoung/dungeonsguide/gui/MPanel.java | 6 +- .../dungeonsguide/gui/elements/MButton.java | 9 +- .../dungeonsguide/gui/elements/MCollapsable.java | 2 +- .../gui/elements/MEditableAColor.java | 18 +- .../syeyoung/dungeonsguide/gui/elements/MList.java | 8 +- .../gui/elements/MPanelScaledGUI.java | 8 +- .../gui/elements/MPortableColorEdit.java | 63 +--- .../dungeonsguide/gui/elements/MScrollBar.java | 33 +- .../gui/elements/MScrollablePanel.java | 7 +- .../gui/elements/MStringSelectionButton.java | 2 + .../dungeonsguide/gui/elements/MTextField.java | 67 +++- .../dungeonsguide/gui/elements/MToggleButton.java | 6 +- .../dungeonsguide/gui/elements/MTooltip.java | 33 +- .../syeyoung/dungeonsguide/roomedit/Parameter.java | 12 +- 48 files changed, 1200 insertions(+), 1373 deletions(-) create mode 100644 src/main/java/kr/syeyoung/dungeonsguide/config/guiconfig/location/PanelDelegate.java create mode 100644 src/main/java/kr/syeyoung/dungeonsguide/config/guiconfig/nyu/ConfigPanelCreator.java create mode 100644 src/main/java/kr/syeyoung/dungeonsguide/config/guiconfig/nyu/MFeature.java create mode 100644 src/main/java/kr/syeyoung/dungeonsguide/config/guiconfig/nyu/MFeatureEdit.java create mode 100644 src/main/java/kr/syeyoung/dungeonsguide/config/guiconfig/nyu/MParameterEdit.java delete mode 100644 src/main/java/kr/syeyoung/dungeonsguide/config/guiconfig/old/ConfigPanelCreator.java delete mode 100755 src/main/java/kr/syeyoung/dungeonsguide/config/guiconfig/old/FeatureEditPane.java delete mode 100755 src/main/java/kr/syeyoung/dungeonsguide/config/guiconfig/old/GuiConfig.java delete mode 100755 src/main/java/kr/syeyoung/dungeonsguide/config/guiconfig/old/GuiParameterValueEdit.java delete mode 100755 src/main/java/kr/syeyoung/dungeonsguide/config/guiconfig/old/MFeature.java delete mode 100755 src/main/java/kr/syeyoung/dungeonsguide/config/guiconfig/old/MParameter.java delete mode 100755 src/main/java/kr/syeyoung/dungeonsguide/config/guiconfig/old/PanelDefaultParameterConfig.java delete mode 100644 src/main/java/kr/syeyoung/dungeonsguide/config/guiconfig/old/PanelDelegate.java (limited to 'src/main/java') diff --git a/src/main/java/kr/syeyoung/dungeonsguide/commands/CommandDungeonsGuide.java b/src/main/java/kr/syeyoung/dungeonsguide/commands/CommandDungeonsGuide.java index 28bc50bc..437c1689 100644 --- a/src/main/java/kr/syeyoung/dungeonsguide/commands/CommandDungeonsGuide.java +++ b/src/main/java/kr/syeyoung/dungeonsguide/commands/CommandDungeonsGuide.java @@ -22,7 +22,6 @@ import com.google.gson.JsonObject; import kr.syeyoung.dungeonsguide.DungeonsGuide; import kr.syeyoung.dungeonsguide.SkyblockStatus; import kr.syeyoung.dungeonsguide.config.guiconfig.nyu.GuiConfigV2; -import kr.syeyoung.dungeonsguide.config.guiconfig.old.GuiConfig; import kr.syeyoung.dungeonsguide.cosmetics.CosmeticsManager; import kr.syeyoung.dungeonsguide.dungeon.DungeonContext; import kr.syeyoung.dungeonsguide.dungeon.MapProcessor; diff --git a/src/main/java/kr/syeyoung/dungeonsguide/config/guiconfig/location/GuiGuiLocationConfig.java b/src/main/java/kr/syeyoung/dungeonsguide/config/guiconfig/location/GuiGuiLocationConfig.java index 645ba3a9..9f33536e 100755 --- a/src/main/java/kr/syeyoung/dungeonsguide/config/guiconfig/location/GuiGuiLocationConfig.java +++ b/src/main/java/kr/syeyoung/dungeonsguide/config/guiconfig/location/GuiGuiLocationConfig.java @@ -18,7 +18,6 @@ package kr.syeyoung.dungeonsguide.config.guiconfig.location; -import kr.syeyoung.dungeonsguide.config.guiconfig.old.PanelDelegate; import kr.syeyoung.dungeonsguide.features.AbstractFeature; import kr.syeyoung.dungeonsguide.features.FeatureRegistry; import kr.syeyoung.dungeonsguide.features.GuiFeature; diff --git a/src/main/java/kr/syeyoung/dungeonsguide/config/guiconfig/location/PanelDelegate.java b/src/main/java/kr/syeyoung/dungeonsguide/config/guiconfig/location/PanelDelegate.java new file mode 100644 index 00000000..4e776eef --- /dev/null +++ b/src/main/java/kr/syeyoung/dungeonsguide/config/guiconfig/location/PanelDelegate.java @@ -0,0 +1,405 @@ +/* + * 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.config.guiconfig.location; + +import kr.syeyoung.dungeonsguide.config.guiconfig.location.GuiGuiLocationConfig; +import kr.syeyoung.dungeonsguide.config.guiconfig.location.Marker; +import kr.syeyoung.dungeonsguide.config.types.GUIRectangle; +import kr.syeyoung.dungeonsguide.features.GuiFeature; +import kr.syeyoung.dungeonsguide.gui.MPanel; +import kr.syeyoung.dungeonsguide.gui.elements.MPopupMenu; +import kr.syeyoung.dungeonsguide.gui.elements.MTooltip; +import kr.syeyoung.dungeonsguide.utils.cursor.EnumCursor; +import net.minecraft.client.Minecraft; +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; + +public class PanelDelegate extends MPanel { + private final GuiFeature guiFeature; + private boolean draggable = false; + private GuiGuiLocationConfig guiGuiLocationConfig; + + private Set 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 + 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.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_TL); + } else if (internallyThinking.width < 0 && internallyThinking.height >= 0) { + setCursor(EnumCursor.RESIZE_DL); + } else if (internallyThinking.width >= 0 && internallyThinking.height >= 0) { + setCursor(EnumCursor.RESIZE_DR); + } else if (internallyThinking.width >= 0 && internallyThinking.height < 0) { + setCursor(EnumCursor.RESIZE_TR); + } + } else if (lastAbsClip.contains(absMouseX, absMouseY)) { + if (relMouseX < 4 && relMouseY < 4) { + setCursor(EnumCursor.RESIZE_TL); + } else if (relMouseX < 4 && relMouseY > getBounds().height - 4) { + setCursor(EnumCursor.RESIZE_DL); + } else if (relMouseX > getBounds().width - 4 && relMouseY > getBounds().height - 4) { + setCursor(EnumCursor.RESIZE_DR); + } else if (relMouseX > getBounds().width - 4 && relMouseY < 4) { + setCursor(EnumCursor.RESIZE_TR); + } else { + setCursor(EnumCursor.OPEN_HAND); + } + } + } +} diff --git a/src/main/java/kr/syeyoung/dungeonsguide/config/guiconfig/nyu/ConfigPanelCreator.java b/src/main/java/kr/syeyoung/dungeonsguide/config/guiconfig/nyu/ConfigPanelCreator.java new file mode 100644 index 00000000..76515e69 --- /dev/null +++ b/src/main/java/kr/syeyoung/dungeonsguide/config/guiconfig/nyu/ConfigPanelCreator.java @@ -0,0 +1,40 @@ +/* + * 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.config.guiconfig.nyu; + +import com.google.common.base.Function; +import com.google.common.base.Supplier; +import kr.syeyoung.dungeonsguide.gui.MPanel; +import org.jetbrains.annotations.Nullable; + +import java.util.HashMap; +import java.util.Map; + +public class ConfigPanelCreator implements Function { + public static final ConfigPanelCreator INSTANCE = new ConfigPanelCreator(); + + public static final Map> map = new HashMap>(); + + @Nullable + @Override + public MPanel apply(@Nullable String input) { + if (!map.containsKey(input)) return null; + return map.get(input).get(); + } +} diff --git a/src/main/java/kr/syeyoung/dungeonsguide/config/guiconfig/nyu/GuiConfigV2.java b/src/main/java/kr/syeyoung/dungeonsguide/config/guiconfig/nyu/GuiConfigV2.java index 94dec77b..267d9a5a 100644 --- a/src/main/java/kr/syeyoung/dungeonsguide/config/guiconfig/nyu/GuiConfigV2.java +++ b/src/main/java/kr/syeyoung/dungeonsguide/config/guiconfig/nyu/GuiConfigV2.java @@ -18,20 +18,15 @@ package kr.syeyoung.dungeonsguide.config.guiconfig.nyu; -import kr.syeyoung.dungeonsguide.config.guiconfig.old.ConfigPanelCreator; import kr.syeyoung.dungeonsguide.gui.MGui; -import kr.syeyoung.dungeonsguide.utils.cursor.EnumCursor; -import kr.syeyoung.dungeonsguide.utils.cursor.GLCursors; +import lombok.Getter; import net.minecraft.client.Minecraft; -import org.lwjgl.LWJGLException; -import org.lwjgl.input.Cursor; -import org.lwjgl.input.Mouse; import java.awt.*; -import java.io.IOException; public class GuiConfigV2 extends MGui { + @Getter private RootConfigPanel rootConfigPanel; public GuiConfigV2() { @@ -46,7 +41,13 @@ public class GuiConfigV2 extends MGui { super.initGui(); int dw = Minecraft.getMinecraft().displayWidth; int dh = Minecraft.getMinecraft().displayHeight; - rootConfigPanel.setBounds(new Rectangle((dw-1000)/2, (dh-800)/2, 1000,800)); - rootConfigPanel.setScale(2.0f); + rootConfigPanel.setBounds(new Rectangle((dw-1500)/2, (dh-800)/2, 1500,800)); + rootConfigPanel.setScale(2.0); + } + + @Override + public void drawScreen(int mouseX, int mouseY, float partialTicks) { + super.drawDefaultBackground(); + super.drawScreen(mouseX, mouseY, partialTicks); } } diff --git a/src/main/java/kr/syeyoung/dungeonsguide/config/guiconfig/nyu/MCategory.java b/src/main/java/kr/syeyoung/dungeonsguide/config/guiconfig/nyu/MCategory.java index be7dcfa6..cf57619f 100644 --- a/src/main/java/kr/syeyoung/dungeonsguide/config/guiconfig/nyu/MCategory.java +++ b/src/main/java/kr/syeyoung/dungeonsguide/config/guiconfig/nyu/MCategory.java @@ -18,8 +18,9 @@ package kr.syeyoung.dungeonsguide.config.guiconfig.nyu; -import kr.syeyoung.dungeonsguide.config.guiconfig.old.MFeature; +import kr.syeyoung.dungeonsguide.features.FeatureRegistry; import kr.syeyoung.dungeonsguide.gui.MPanel; +import kr.syeyoung.dungeonsguide.utils.RenderUtils; import kr.syeyoung.dungeonsguide.utils.cursor.EnumCursor; import lombok.Getter; import lombok.Setter; @@ -46,7 +47,9 @@ public class MCategory extends MPanel { @Override public void render(int absMousex, int absMousey, int relMousex0, int relMousey0, float partialTicks, Rectangle scissor) { - Gui.drawRect(0,0,getBounds().width, getBounds().height,0xFF444444); + Gui.drawRect(0,0,getBounds().width, getBounds().height, RenderUtils.blendAlpha(0x141414, 0.12f)); + Gui.drawRect(1,18,getBounds().width -1, getBounds().height-1, RenderUtils.blendAlpha(0x141414, 0.15f)); + Gui.drawRect(0,17,getBounds().width, 18,RenderUtils.blendAlpha(0x141414, 0.12f)); FontRenderer fr = Minecraft.getMinecraft().fontRendererObj; @@ -60,18 +63,22 @@ public class MCategory extends MPanel { fr.drawString((lastAbsClip.contains(absMousex, absMousey) ? "§n" : "") + nestedCategory.categoryName(), 0,0, 0xFFFFFFFF); GlStateManager.popMatrix(); - fr.drawSplitString("NO DESC", 5, 23, getBounds().width -10, 0xFFBFBFBF); + fr.drawSplitString(FeatureRegistry.getCategoryDescription().getOrDefault(nestedCategory.categoryFull(), ""), 5, 23, getBounds().width -10, 0xFFBFBFBF); } @Override public Dimension getPreferredSize() { - return new Dimension(100, 17); + FontRenderer fr = Minecraft.getMinecraft().fontRendererObj; + int descriptionHeight = fr.listFormattedStringToWidth(FeatureRegistry.getCategoryDescription().getOrDefault(nestedCategory.categoryFull(), ""), Math.max(100, getBounds().width - 10)).size() * fr.FONT_HEIGHT; + + return new Dimension(100, descriptionHeight + 28); } + @Override public void mouseClicked(int absMouseX, int absMouseY, int relMouseX, int relMouseY, int mouseButton) { if (lastAbsClip.contains(absMouseX, absMouseY)) - rootConfigPanel.setCurrentPage(nestedCategory.categoryFull()); + rootConfigPanel.setCurrentPageAndPushHistory(nestedCategory.categoryFull()); } @Override diff --git a/src/main/java/kr/syeyoung/dungeonsguide/config/guiconfig/nyu/MCategoryElement.java b/src/main/java/kr/syeyoung/dungeonsguide/config/guiconfig/nyu/MCategoryElement.java index 3e7bba67..67087dd8 100644 --- a/src/main/java/kr/syeyoung/dungeonsguide/config/guiconfig/nyu/MCategoryElement.java +++ b/src/main/java/kr/syeyoung/dungeonsguide/config/guiconfig/nyu/MCategoryElement.java @@ -46,14 +46,13 @@ public class MCategoryElement extends MPanel { @Override public void render(int absMousex, int absMousey, int relMousex0, int relMousey0, float partialTicks, Rectangle scissor) { if (rootConfigPanel.getCurrentPage().equals(category)) { - GL11.glDisable(GL11.GL_SCISSOR_TEST); + clip(0,scissor.y, Minecraft.getMinecraft().displayWidth, scissor.height); Gui.drawRect(leftPad - offsetX, 0, getBounds().width, getBounds().height, RenderUtils.blendAlpha(0x141414, 0.13f)); - GL11.glEnable(GL11.GL_SCISSOR_TEST); } else if (lastAbsClip.contains(absMousex, absMousey)) { - GL11.glDisable(GL11.GL_SCISSOR_TEST); + clip(0,scissor.y, Minecraft.getMinecraft().displayWidth, scissor.height); Gui.drawRect(leftPad - offsetX, 0, getBounds().width, getBounds().height, RenderUtils.blendAlpha(0x141414, 0.09f)); - GL11.glEnable(GL11.GL_SCISSOR_TEST); } + clip(scissor.x, scissor.y, scissor.width, scissor.height); FontRenderer fr = Minecraft.getMinecraft().fontRendererObj; diff --git a/src/main/java/kr/syeyoung/dungeonsguide/config/guiconfig/nyu/MFeature.java b/src/main/java/kr/syeyoung/dungeonsguide/config/guiconfig/nyu/MFeature.java new file mode 100644 index 00000000..15b36216 --- /dev/null +++ b/src/main/java/kr/syeyoung/dungeonsguide/config/guiconfig/nyu/MFeature.java @@ -0,0 +1,148 @@ +/* + * 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.config.guiconfig.nyu; + +import kr.syeyoung.dungeonsguide.config.guiconfig.location.GuiGuiLocationConfig; +import kr.syeyoung.dungeonsguide.features.AbstractFeature; +import kr.syeyoung.dungeonsguide.features.GuiFeature; +import kr.syeyoung.dungeonsguide.gui.MPanel; +import kr.syeyoung.dungeonsguide.gui.elements.MButton; +import kr.syeyoung.dungeonsguide.gui.elements.MToggleButton; +import kr.syeyoung.dungeonsguide.utils.RenderUtils; +import lombok.Getter; +import lombok.Setter; +import net.minecraft.client.Minecraft; +import net.minecraft.client.gui.FontRenderer; +import net.minecraft.client.gui.Gui; +import net.minecraft.client.renderer.GlStateManager; +import org.lwjgl.opengl.GL11; +import org.lwjgl.opengl.GL14; + +import java.awt.*; +import java.util.ArrayList; +import java.util.List; + +public class MFeature extends MPanel { + + @Getter + private final AbstractFeature feature; + + private final List addons = new ArrayList(); + + @Getter @Setter + private Color hover; + + private final RootConfigPanel panel; + + public MFeature(final AbstractFeature abstractFeature, final RootConfigPanel panel) { + this.panel = panel; + this.feature = abstractFeature; + + if (abstractFeature.isDisyllable()) { + final MToggleButton mStringSelectionButton = new MToggleButton(); + mStringSelectionButton.setOnToggle(new Runnable() { + @Override + public void run() { + boolean selected = mStringSelectionButton.isEnabled(); + feature.setEnabled(selected); + } + }); + mStringSelectionButton.setBackground(RenderUtils.blendAlpha(0x141414, 0.07f)); + addons.add(mStringSelectionButton); + mStringSelectionButton.setEnabled(feature.isEnabled()); + mStringSelectionButton.setSize(new Dimension(40, 15)); + add(mStringSelectionButton); + } + if (abstractFeature.getParameters().size() != 0) { + MButton button = new MButton(); + button.setText("Edit"); + button.setOnActionPerformed(new Runnable() { + @Override + public void run() { + panel.setCurrentPageAndPushHistory(abstractFeature.getEditRoute(panel)); + } + }); + button.setBackground(RenderUtils.blendAlpha(0x141414, 0.07f)); + button.setClicked(RenderUtils.blendAlpha(0x141414, 0.17f)); + button.setHover(RenderUtils.blendAlpha(0x141414, 0.17f)); + addons.add(button); + button.setSize(new Dimension(50, 15)); + add(button); + } + if (abstractFeature instanceof GuiFeature) { + MButton button = new MButton(); + button.setText("Relocate"); + button.setOnActionPerformed(new Runnable() { + @Override + public void run() { + Minecraft.getMinecraft().displayGuiScreen(new GuiGuiLocationConfig(Minecraft.getMinecraft().currentScreen, abstractFeature)); + button.setIsclicked(false); + } + }); + button.setBackground(RenderUtils.blendAlpha(0x141414, 0.07f)); + button.setClicked(RenderUtils.blendAlpha(0x141414, 0.17f)); + button.setHover(RenderUtils.blendAlpha(0x141414, 0.17f)); + addons.add(button); + button.setSize(new Dimension(75, 15)); + add(button); + } + } + + @Override + public void render(int absMousex, int absMousey, int relMousex0, int relMousey0, float partialTicks, Rectangle scissor) { + Gui.drawRect(0,0,getBounds().width, getBounds().height, RenderUtils.blendAlpha(0x141414, 0.12f)); + Gui.drawRect(1,18,getBounds().width -1, getBounds().height-1, RenderUtils.blendAlpha(0x141414, 0.15f)); + Gui.drawRect(0,17,getBounds().width, 18,RenderUtils.blendAlpha(0x141414, 0.12f)); + + + FontRenderer fr = Minecraft.getMinecraft().fontRendererObj; + GlStateManager.pushMatrix(); + GlStateManager.translate(5,5,0); + GlStateManager.scale(1.0,1.0,0); + GlStateManager.enableBlend(); + GL14.glBlendFuncSeparate(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA, GL11.GL_ONE, GL11.GL_ONE_MINUS_SRC_ALPHA); + GlStateManager.tryBlendFuncSeparate(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA, GL11.GL_ONE, GL11.GL_ONE_MINUS_SRC_ALPHA); + fr.drawString(feature.getName(), 0,0, 0xFFFFFFFF); + GlStateManager.popMatrix(); + + fr.drawSplitString(feature.getDescription(), 5, 23, getBounds().width -10, 0xFFBFBFBF); + } + + @Override + public void resize(int parentWidth, int parentHeight) { + this.setSize(new Dimension(parentWidth, getBounds().height)); + } + + @Override + public Dimension getPreferredSize() { + FontRenderer fr = Minecraft.getMinecraft().fontRendererObj; + int descriptionHeight = fr.listFormattedStringToWidth(feature.getDescription(), Math.max(100, getBounds().width - 10)).size() * fr.FONT_HEIGHT; + + return new Dimension(100, descriptionHeight + 28); + } + + @Override + public void onBoundsUpdate() { + int x = getBounds().width - 5; + for (MPanel panel : addons) { + panel.setBounds(new Rectangle(x - panel.getPreferredSize().width, 3, panel.getPreferredSize().width, 12)); + x -= panel.getPreferredSize().width + 5; + } + } +} diff --git a/src/main/java/kr/syeyoung/dungeonsguide/config/guiconfig/nyu/MFeatureEdit.java b/src/main/java/kr/syeyoung/dungeonsguide/config/guiconfig/nyu/MFeatureEdit.java new file mode 100644 index 00000000..3256c408 --- /dev/null +++ b/src/main/java/kr/syeyoung/dungeonsguide/config/guiconfig/nyu/MFeatureEdit.java @@ -0,0 +1,86 @@ +/* + * 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.config.guiconfig.nyu; + +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.MList; + +import java.awt.*; +import java.util.HashMap; +import java.util.Map; + +public class MFeatureEdit extends MPanel { + private MList list; + private MButton goBack; + private RootConfigPanel rootConfigPanel; + private AbstractFeature abstractFeature; + + private Map parameterEdits = new HashMap<>(); + + public MFeatureEdit(AbstractFeature abstractFeature, RootConfigPanel rootConfigPanel) { + this.abstractFeature = abstractFeature; + this.rootConfigPanel = rootConfigPanel; + list = new MList(); + list.setGap(5); + list.setDrawLine(false); + add(list); + + goBack = new MButton(); + goBack.setText("< Go Back"); + goBack.setOnActionPerformed(rootConfigPanel::goBack); + add(goBack); + } + + public void addParameterEdit(String name, MPanel paramEdit) { + parameterEdits.put(name, paramEdit); + list.add(paramEdit); + } + public MPanel removeParameterEdit(String name) { + MPanel panel = parameterEdits.remove(name); + list.remove(panel); + return panel; + } + + @Override + public void resize(int parentWidth, int parentHeight) { + super.resize(parentWidth, parentHeight); + setBounds(new Rectangle(0,0,parentWidth,parentHeight)); + Dimension prefSize = getPreferredSize(); + int hei = prefSize.height; + setBounds(new Rectangle(0,0,parentWidth,hei)); + } + + @Override + public void setBounds(Rectangle bounds) { + super.setBounds(bounds); + goBack.setBounds(new Rectangle(5,5,75,15)); + + list.setBounds(new Rectangle(5,25,bounds.width - 10, bounds.height - 10)); + list.realignChildren(); + } + + @Override + public Dimension getPreferredSize() { + Dimension listPref = list.getPreferredSize(); + return new Dimension(listPref.width + 10, listPref.height + 30); + } +} diff --git a/src/main/java/kr/syeyoung/dungeonsguide/config/guiconfig/nyu/MPanelCategory.java b/src/main/java/kr/syeyoung/dungeonsguide/config/guiconfig/nyu/MPanelCategory.java index 5b6d9bbd..5df29c3b 100644 --- a/src/main/java/kr/syeyoung/dungeonsguide/config/guiconfig/nyu/MPanelCategory.java +++ b/src/main/java/kr/syeyoung/dungeonsguide/config/guiconfig/nyu/MPanelCategory.java @@ -18,7 +18,6 @@ package kr.syeyoung.dungeonsguide.config.guiconfig.nyu; -import kr.syeyoung.dungeonsguide.config.guiconfig.old.MFeature; import kr.syeyoung.dungeonsguide.features.AbstractFeature; import kr.syeyoung.dungeonsguide.features.FeatureRegistry; import kr.syeyoung.dungeonsguide.gui.MPanel; @@ -49,7 +48,7 @@ public class MPanelCategory extends MPanel { String actualCategory = nestedCategory.categoryFull().substring(5); if (FeatureRegistry.getFeaturesByCategory().containsKey(actualCategory)) for (AbstractFeature abstractFeature : FeatureRegistry.getFeaturesByCategory().get(actualCategory)) { - MFeature mFeature = new MFeature(abstractFeature, null); + MFeature mFeature = new MFeature(abstractFeature, rootConfigPanel); list.add(mFeature); mFeature.setHover(new Color(94, 94, 94, 255)); } @@ -60,10 +59,10 @@ public class MPanelCategory extends MPanel { @Override public void resize(int parentWidth, int parentHeight) { super.resize(parentWidth, parentHeight); - Dimension prefSize = list.getPreferredSize(); - int wid = Math.max(prefSize.width + 10, parentWidth); - int hei = prefSize.height + 10; - setBounds(new Rectangle(0,0,wid,hei)); + setBounds(new Rectangle(0,0,parentWidth,parentHeight)); + Dimension prefSize = getPreferredSize(); + int hei = prefSize.height; + setBounds(new Rectangle(0,0,parentWidth,hei)); } @Override diff --git a/src/main/java/kr/syeyoung/dungeonsguide/config/guiconfig/nyu/MParameterEdit.java b/src/main/java/kr/syeyoung/dungeonsguide/config/guiconfig/nyu/MParameterEdit.java new file mode 100644 index 00000000..341705ee --- /dev/null +++ b/src/main/java/kr/syeyoung/dungeonsguide/config/guiconfig/nyu/MParameterEdit.java @@ -0,0 +1,156 @@ +/* + * 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.config.guiconfig.nyu; + +import kr.syeyoung.dungeonsguide.config.types.AColor; +import kr.syeyoung.dungeonsguide.features.AbstractFeature; +import kr.syeyoung.dungeonsguide.features.FeatureParameter; +import kr.syeyoung.dungeonsguide.features.FeatureRegistry; +import kr.syeyoung.dungeonsguide.gui.MPanel; +import kr.syeyoung.dungeonsguide.gui.elements.*; +import kr.syeyoung.dungeonsguide.roomedit.Parameter; +import kr.syeyoung.dungeonsguide.roomedit.valueedit.ValueEdit; +import kr.syeyoung.dungeonsguide.roomedit.valueedit.ValueEditCreator; +import kr.syeyoung.dungeonsguide.roomedit.valueedit.ValueEditRegistry; +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.renderer.GlStateManager; +import org.lwjgl.opengl.GL11; +import org.lwjgl.opengl.GL14; + +import java.awt.*; + +public class MParameterEdit extends MPanel { + private AbstractFeature abstractFeature; + private FeatureParameter featureParameter; + private RootConfigPanel rootConfigPanel; + private MPanel valueEditHolder; + private MPanel valueEdit; + + public MParameterEdit(AbstractFeature abstractFeature, FeatureParameter parameter, RootConfigPanel rootConfigPanel) { + this.abstractFeature = abstractFeature; + this.featureParameter = parameter; + this.rootConfigPanel = rootConfigPanel; + + if (parameter.getValue_type().equals("string")) { + valueEdit = new MTextField() { + @Override + public void edit(String str) { + parameter.setValue(str); + } + }; + ((MTextField)valueEdit).setText((String) parameter.getValue()); + } else if (parameter.getValue_type().equals("integer")) { + valueEdit = new MIntegerSelectionButton((Integer) parameter.getValue()); + ((MIntegerSelectionButton)valueEdit).setOnUpdate(() -> { + parameter.setValue(((MIntegerSelectionButton) valueEdit).getData()); + }); + } else if (parameter.getValue_type().equals("float")) { + valueEdit = new MFloatSelectionButton((Float) parameter.getValue()); + ((MFloatSelectionButton)valueEdit).setOnUpdate(() -> { + parameter.setValue(((MFloatSelectionButton) valueEdit).getData()); + }); + } else if (parameter.getValue_type().equals("acolor")) { + valueEdit = new MEditableAColor(); + ((MEditableAColor)valueEdit).setColor((AColor) parameter.getValue()); + ((MEditableAColor)valueEdit).setEnableEdit(true); + ((MEditableAColor)valueEdit).setOnUpdate(() -> { + parameter.setValue(((MEditableAColor) valueEdit).getColor()); + }); + } else if (parameter.getValue_type().equals("color")) { + valueEdit = new MEditableAColor(); + ((MEditableAColor)valueEdit).setColor(new AColor(((Color) parameter.getValue()).getRGB(), true)); + ((MEditableAColor)valueEdit).setEnableEdit(true); + ((MEditableAColor)valueEdit).setOnUpdate(() -> { + parameter.setValue(((MEditableAColor) valueEdit).getColor()); + }); + } else if (parameter.getValue_type().equals("boolean")) { + valueEdit = new MToggleButton(); + ((MToggleButton)valueEdit).setEnabled((Boolean) parameter.getValue()); + ((MToggleButton)valueEdit).setOnToggle(() -> { + parameter.setValue(((MToggleButton) valueEdit).isEnabled()); + }); + } else { + valueEdit = new MLabel(); + ((MLabel)valueEdit).setText("????"); + } + + + valueEditHolder = new MPanel() { + @Override + public void setBounds(Rectangle bounds) { + super.setBounds(bounds); + Dimension dimension = valueEdit.getPreferredSize(); + if (dimension.width <= 0) dimension.width = bounds.width/2; + if (dimension.height <= 0) dimension.height = bounds.height/2; + valueEdit.setBounds(new Rectangle((bounds.width - dimension.width)/2,(bounds.height - dimension.height)/2,dimension.width, dimension.height)); + } + }; + add(valueEditHolder); + valueEditHolder.add(valueEdit); + } + public MParameterEdit(AbstractFeature abstractFeature, FeatureParameter parameter, RootConfigPanel rootConfigPanel, MPanel valueEdit) { + this.abstractFeature = abstractFeature; + this.featureParameter = parameter; + this.rootConfigPanel = rootConfigPanel; + + + valueEditHolder = new MPanel() { + @Override + public void setBounds(Rectangle bounds) { + super.setBounds(bounds); + Dimension dimension = valueEdit.getPreferredSize(); + if (dimension.width <= 0) dimension.width = bounds.width/2; + if (dimension.height <= 0) dimension.height = bounds.height/2; + valueEdit.setBounds(new Rectangle((bounds.width - dimension.width)/2,(bounds.height - dimension.height)/2,dimension.width, dimension.height)); + } + }; + add(valueEditHolder); + valueEditHolder.add(valueEdit); + } + + @Override + public void render(int absMousex, int absMousey, int relMousex0, int relMousey0, float partialTicks, Rectangle scissor) { + Gui.drawRect(0,0,getBounds().width, getBounds().height, RenderUtils.blendAlpha(0x141414, 0.12f)); + Gui.drawRect(2*bounds.width / 3,1,getBounds().width -1, getBounds().height-1, RenderUtils.blendAlpha(0x141414, 0.15f)); + Gui.drawRect(4, 15,2*bounds.width / 3-5, 16, RenderUtils.blendAlpha(0x141414, 0.3f)); + + + FontRenderer fr = Minecraft.getMinecraft().fontRendererObj; + fr.drawString(featureParameter.getName(), 5,5, 0xFFFFFFFF); + fr.drawSplitString(featureParameter.getDescription(), 5,18, 2*bounds.width /3-10, 0xFFAAAAAA); + + } + + @Override + public Dimension getPreferredSize() { + FontRenderer fr = Minecraft.getMinecraft().fontRendererObj; + int descriptionHeight = fr.listFormattedStringToWidth(FeatureRegistry.getCategoryDescription().getOrDefault(featureParameter.getDescription(), ""), Math.max(100, getBounds().width - 10)).size() * fr.FONT_HEIGHT; + + return new Dimension(100, Math.max(Math.max(30, descriptionHeight + 23), valueEditHolder.getPreferredSize().height)); + } + + @Override + public void setBounds(Rectangle bounds) { + super.setBounds(bounds); + valueEditHolder.setBounds(new Rectangle(2*bounds.width / 3, 0, bounds.width / 3, bounds.height)); + } +} diff --git a/src/main/java/kr/syeyoung/dungeonsguide/config/guiconfig/nyu/RootConfigPanel.java b/src/main/java/kr/syeyoung/dungeonsguide/config/guiconfig/nyu/RootConfigPanel.java index e156e849..e2b97b7f 100644 --- a/src/main/java/kr/syeyoung/dungeonsguide/config/guiconfig/nyu/RootConfigPanel.java +++ b/src/main/java/kr/syeyoung/dungeonsguide/config/guiconfig/nyu/RootConfigPanel.java @@ -20,8 +20,6 @@ package kr.syeyoung.dungeonsguide.config.guiconfig.nyu; import com.google.common.base.Function; import kr.syeyoung.dungeonsguide.config.guiconfig.location.GuiGuiLocationConfig; -import kr.syeyoung.dungeonsguide.config.guiconfig.old.ConfigPanelCreator; -import kr.syeyoung.dungeonsguide.config.guiconfig.old.GuiConfig; import kr.syeyoung.dungeonsguide.features.AbstractFeature; import kr.syeyoung.dungeonsguide.features.FeatureRegistry; import kr.syeyoung.dungeonsguide.gui.MPanel; @@ -30,15 +28,15 @@ import kr.syeyoung.dungeonsguide.utils.RenderUtils; import lombok.Getter; import lombok.Setter; import net.minecraft.client.Minecraft; +import net.minecraft.client.gui.FontRenderer; import net.minecraft.client.gui.Gui; import java.awt.*; import java.util.HashMap; -import java.util.List; import java.util.Map; +import java.util.Stack; public class RootConfigPanel extends MPanelScaledGUI { - private MScrollablePanel navigationScroll; private MList navigation = new MList(); @@ -55,14 +53,38 @@ public class RootConfigPanel extends MPanelScaledGUI { private GuiConfigV2 gui; + private long lastPageSet = System.currentTimeMillis(); + + private MTextField search; + private MButton guiRelocate; + + private final Stack history = new Stack(); + public RootConfigPanel(GuiConfigV2 guiConfigV2) { this.gui = guiConfigV2; + search = new MTextField() { + @Override + public void edit(String str) { + } + }; + search.setPlaceHolder("Search..."); + add(search); + guiRelocate = new MButton(); + guiRelocate.setText("Edit Gui Locations"); + guiRelocate.setOnActionPerformed(() -> { + Minecraft.getMinecraft().displayGuiScreen(new GuiGuiLocationConfig(gui, null)); + guiRelocate.setIsclicked(false); + }); + guiRelocate.setBorder(RenderUtils.blendTwoColors(0xFF141414,0x7702EE67)); + add(guiRelocate); + navigationScroll = new MScrollablePanel(1); navigationScroll.setHideScrollBarWhenNotNecessary(false); + + add(navigationScroll); navigationScroll.add(navigation); - navigationScroll.add(new MSpacer(0,0,1,1)); contentScroll = new MScrollablePanel(3); contentScroll.setHideScrollBarWhenNotNecessary(true); @@ -72,6 +94,7 @@ public class RootConfigPanel extends MPanelScaledGUI { navigation.setGap(0); navigation.setDrawLine(false); + rePlaceElements(); } @@ -91,23 +114,18 @@ public class RootConfigPanel extends MPanelScaledGUI { for (NestedCategory value : root.children().values()) { setupNavigationRecursive(value, navigation, 0, 17); } - - MCategoryElement current = new MCategoryElement("GUI Relocate",() -> { - Minecraft.getMinecraft().displayGuiScreen(new GuiGuiLocationConfig(gui, null)); - }, 17,17, this); - navigation.add(current); } private void setupNavigationRecursive(NestedCategory nestedCategory, MPanel parent, int depth, int offset) { ConfigPanelCreator.map.put(nestedCategory.categoryFull(), () -> new MPanelCategory(nestedCategory, this)); if (nestedCategory.children().size() == 0) { MCategoryElement current = new MCategoryElement(nestedCategory.categoryFull(),() -> { - setCurrentPage(nestedCategory.categoryFull()); + setCurrentPageAndPushHistory(nestedCategory.categoryFull()); }, 13 * depth + 17, offset, this); parent.add(current); } else { MCategoryElement current = new MCategoryElement(nestedCategory.categoryFull(),() -> { - setCurrentPage(nestedCategory.categoryFull()); + setCurrentPageAndPushHistory(nestedCategory.categoryFull()); }, 3,offset, this); MCollapsable mCollapsable = new MCollapsable(current, this::rePlaceElements); mCollapsable.setLeftPad(offset-13); @@ -123,9 +141,19 @@ public class RootConfigPanel extends MPanelScaledGUI { } - public void setCurrentPage(String currentPage) { + public void setCurrentPageAndPushHistory(String currentPage) { + if (!this.currentPage.equals(currentPage)) + history.push(this.currentPage); this.currentPage = currentPage; + setupPage(); + } + public void goBack() { + if (history.size() == 0) return; + this.currentPage = history.pop(); + setupPage(); + } + private void setupPage() { contentScroll.getContentArea().getChildComponents().forEach(contentScroll.getContentArea()::remove); if (!pages.containsKey(currentPage)) { MPanel page = pageGenerator.apply(currentPage); @@ -139,9 +167,21 @@ public class RootConfigPanel extends MPanelScaledGUI { @Override public void render(int absMousex, int absMousey, int relMousex0, int relMousey0, float partialTicks, Rectangle scissor) { Dimension effectiveDim = getEffectiveDimension(); - Gui.drawRect(0,0, (int) (effectiveDim.width), (int) (effectiveDim.height), RenderUtils.blendAlpha(0, 0.0f)); - Gui.drawRect(1,1, (int) (effectiveDim.width)-1, (int) (effectiveDim.height) - 1, RenderUtils.blendAlpha(0x141414, 0.00f)); - Gui.drawRect(1,1, (int) (effectiveDim.width)-1, 25, RenderUtils.blendAlpha(0x0, 0.20f)); + Gui.drawRect(0,0, (int) (effectiveDim.width), (int) (effectiveDim.height), RenderUtils.blendAlpha(0x141414, 0.00f)); + Gui.drawRect(0,0, (int) (effectiveDim.width), 25, RenderUtils.blendAlpha(0x0, 0.20f)); +// Gui.drawRect(navigationScroll.getBounds().x + navigationScroll.getBounds().width - 10, 25, navigationScroll.getBounds().x + navigationScroll.getBounds().width , 50, RenderUtils.blendAlpha(0xFF141414, 0.04f)); + Gui.drawRect(0, 25,navigationScroll.getBounds().x + navigationScroll.getBounds().width , 50, RenderUtils.blendAlpha(0xFF141414, 0.08f)); + + + FontRenderer fr = Minecraft.getMinecraft().fontRendererObj; + fr.drawString("DungeonsGuide by syeyoung", (effectiveDim.width - fr.getStringWidth("DungeonsGuide By syeyoung"))/2, (25 - fr.FONT_HEIGHT)/2, 0xFF02EE67); + } + + @Override + public void render0(double parentScale, Point parentPoint, Rectangle parentClip, int absMousex0, int absMousey0, int relMousex0, int relMousey0, float partialTicks) { + super.render0(parentScale, parentPoint, parentClip, absMousex0, absMousey0, relMousex0, relMousey0, partialTicks); + Dimension effectiveDim = getEffectiveDimension(); + Gui.drawRect(0,24, (int) (Double.min(1, (System.currentTimeMillis() - lastPageSet)/1000.0) * effectiveDim.width), 25, 0xFF02EE67); } @Override @@ -152,12 +192,17 @@ public class RootConfigPanel extends MPanelScaledGUI { private void rePlaceElements() { Dimension effectiveDim = getEffectiveDimension(); + navigation.setBounds(new Rectangle(new Point(0,1), new Dimension(Math.max(100, Math.max(navigation.getPreferredSize().width, navigationScroll.getBounds().width-10)), navigation.getPreferredSize().height))); navigation.realignChildren(); + navigationScroll.evalulateContentArea(); Rectangle navBound; - navigationScroll.setBounds(navBound = new Rectangle(1,25, navigation.getBounds().width+10, effectiveDim.height-24)); + navigationScroll.setBounds(navBound = new Rectangle(0,50, navigation.getBounds().width+10, effectiveDim.height-50)); + contentScroll.setBounds(new Rectangle(navBound.x + navBound.width, 25, effectiveDim.width - navBound.x - navBound.width, effectiveDim.height-25)); + + search.setBounds(new Rectangle(5,30,navBound.x + navBound.width - 10,15)); - contentScroll.setBounds(new Rectangle(navBound.x + navBound.width + 1, 25, effectiveDim.width - navBound.x - navBound.width - 2, effectiveDim.height -26)); + guiRelocate.setBounds(new Rectangle(5,5,100,15)); } } diff --git a/src/main/java/kr/syeyoung/dungeonsguide/config/guiconfig/old/ConfigPanelCreator.java b/src/main/java/kr/syeyoung/dungeonsguide/config/guiconfig/old/ConfigPanelCreator.java deleted file mode 100644 index 57db9864..00000000 --- a/src/main/java/kr/syeyoung/dungeonsguide/config/guiconfig/old/ConfigPanelCreator.java +++ /dev/null @@ -1,40 +0,0 @@ -/* - * 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.config.guiconfig.old; - -import com.google.common.base.Function; -import com.google.common.base.Supplier; -import kr.sy