diff options
Diffstat (limited to 'src/main/java')
9 files changed, 289 insertions, 10 deletions
diff --git a/src/main/java/kr/syeyoung/dungeonsguide/config/guiconfig/GuiGuiLocationConfig.java b/src/main/java/kr/syeyoung/dungeonsguide/config/guiconfig/GuiGuiLocationConfig.java index 2304378b..b68c0b0c 100755 --- a/src/main/java/kr/syeyoung/dungeonsguide/config/guiconfig/GuiGuiLocationConfig.java +++ b/src/main/java/kr/syeyoung/dungeonsguide/config/guiconfig/GuiGuiLocationConfig.java @@ -40,6 +40,7 @@ import java.util.List; public class GuiGuiLocationConfig extends MGui { + @Getter private final GuiScreen before; @Getter diff --git a/src/main/java/kr/syeyoung/dungeonsguide/config/guiconfig/PanelDelegate.java b/src/main/java/kr/syeyoung/dungeonsguide/config/guiconfig/PanelDelegate.java index 71cafd83..bfd92cef 100644 --- a/src/main/java/kr/syeyoung/dungeonsguide/config/guiconfig/PanelDelegate.java +++ b/src/main/java/kr/syeyoung/dungeonsguide/config/guiconfig/PanelDelegate.java @@ -21,6 +21,8 @@ package kr.syeyoung.dungeonsguide.config.guiconfig; 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.RenderUtils; import net.minecraft.client.Minecraft; import net.minecraft.client.gui.FontRenderer; @@ -65,6 +67,7 @@ public class PanelDelegate extends MPanel { @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); @@ -277,9 +280,13 @@ public class PanelDelegate extends MPanel { } } + 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(); @@ -306,6 +313,10 @@ public class PanelDelegate extends MPanel { 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"); } @@ -313,6 +324,7 @@ public class PanelDelegate extends MPanel { @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)); } @@ -323,6 +335,7 @@ public class PanelDelegate extends MPanel { @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) { diff --git a/src/main/java/kr/syeyoung/dungeonsguide/features/GuiFeature.java b/src/main/java/kr/syeyoung/dungeonsguide/features/GuiFeature.java index d878c28b..ceb7ec69 100644 --- a/src/main/java/kr/syeyoung/dungeonsguide/features/GuiFeature.java +++ b/src/main/java/kr/syeyoung/dungeonsguide/features/GuiFeature.java @@ -19,24 +19,31 @@ package kr.syeyoung.dungeonsguide.features; import com.google.gson.JsonObject; +import kr.syeyoung.dungeonsguide.config.guiconfig.GuiConfig; +import kr.syeyoung.dungeonsguide.config.guiconfig.GuiGuiLocationConfig; import kr.syeyoung.dungeonsguide.config.types.GUIRectangle; import kr.syeyoung.dungeonsguide.config.types.TypeConverterRegistry; import kr.syeyoung.dungeonsguide.features.listener.ScreenRenderListener; -import kr.syeyoung.dungeonsguide.gui.elements.MTooltip; +import kr.syeyoung.dungeonsguide.features.text.TextHUDFeature; +import kr.syeyoung.dungeonsguide.gui.MPanel; +import kr.syeyoung.dungeonsguide.gui.elements.*; import lombok.AccessLevel; 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.gui.GuiScreen; import net.minecraft.client.gui.ScaledResolution; import net.minecraft.client.renderer.GlStateManager; -import net.minecraft.client.renderer.OpenGlHelper; import org.lwjgl.opengl.GL11; import org.lwjgl.opengl.GL14; -import org.w3c.dom.css.Rect; -import javax.sound.midi.MidiEvent; import java.awt.*; +import java.lang.reflect.Array; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; @Getter public abstract class GuiFeature extends AbstractFeature implements ScreenRenderListener { @@ -114,7 +121,44 @@ public abstract class GuiFeature extends AbstractFeature implements ScreenRender return object; } - public MTooltip getTooltipForEditor() { - return null; + public List<MPanel> getTooltipForEditor(GuiGuiLocationConfig guiGuiLocationConfig) { + ArrayList<MPanel> mPanels = new ArrayList<>(); + mPanels.add(new MLabel(){ + { + setText(getName()); + } + + @Override + public Dimension getPreferredSize() { + return new Dimension(Minecraft.getMinecraft().fontRendererObj.getStringWidth(getName()), 30); + } + }); + mPanels.add(new MButton() { + { + setText("Edit"); + setOnActionPerformed(() -> { + GuiScreen guiScreen = guiGuiLocationConfig.getBefore(); + if (guiScreen == null) { + guiScreen = new GuiConfig(); + } + Minecraft.getMinecraft().displayGuiScreen(guiScreen); + if (guiScreen instanceof GuiConfig) { + ((GuiConfig) guiScreen).getTabbedPane().setCurrentPage(getEditRoute((GuiConfig) guiScreen)); + } + }); + } + + @Override + public Dimension getPreferredSize() { + return new Dimension(150,30); + } + }); + mPanels.add(new MPassiveLabelAndElement("Enabled", new MToggleButton() {{ + setEnabled(GuiFeature.this.isEnabled()); + setOnToggle(() ->{ + GuiFeature.this.setEnabled(isEnabled()); + }); } + })); + return mPanels; } } diff --git a/src/main/java/kr/syeyoung/dungeonsguide/features/text/TextHUDFeature.java b/src/main/java/kr/syeyoung/dungeonsguide/features/text/TextHUDFeature.java index 463e1b2f..9ee1814c 100644 --- a/src/main/java/kr/syeyoung/dungeonsguide/features/text/TextHUDFeature.java +++ b/src/main/java/kr/syeyoung/dungeonsguide/features/text/TextHUDFeature.java @@ -21,12 +21,17 @@ package kr.syeyoung.dungeonsguide.features.text; import com.google.common.base.Supplier; import kr.syeyoung.dungeonsguide.config.guiconfig.ConfigPanelCreator; import kr.syeyoung.dungeonsguide.config.guiconfig.GuiConfig; +import kr.syeyoung.dungeonsguide.config.guiconfig.GuiGuiLocationConfig; import kr.syeyoung.dungeonsguide.config.guiconfig.PanelDefaultParameterConfig; import kr.syeyoung.dungeonsguide.config.types.AColor; import kr.syeyoung.dungeonsguide.features.AbstractFeature; import kr.syeyoung.dungeonsguide.features.FeatureParameter; import kr.syeyoung.dungeonsguide.features.GuiFeature; import kr.syeyoung.dungeonsguide.gui.MPanel; +import kr.syeyoung.dungeonsguide.gui.elements.MFloatSelectionButton; +import kr.syeyoung.dungeonsguide.gui.elements.MLabelAndElement; +import kr.syeyoung.dungeonsguide.gui.elements.MPassiveLabelAndElement; +import kr.syeyoung.dungeonsguide.gui.elements.MToggleButton; import kr.syeyoung.dungeonsguide.utils.RenderUtils; import lombok.AllArgsConstructor; import lombok.Data; @@ -45,9 +50,8 @@ public abstract class TextHUDFeature extends GuiFeature implements StyledTextPro this.parameters.put("textStylesNEW", new FeatureParameter<List<TextStyle>>("textStylesNEW", "", "", new ArrayList<TextStyle>(), "list_textStyle")); this.parameters.put("alignRight", new FeatureParameter<Boolean>("alignRight", "Align Right", "Align text to right", false, "boolean")); this.parameters.put("alignCenter", new FeatureParameter<Boolean>("alignCenter", "Align Center", "Align text to center (overrides alignright)", false, "boolean")); - if (!doesScaleWithHeight()) { - this.parameters.put("scale", new FeatureParameter<Float>("scale", "Scale", "Scale", 1.0f, "float")); - } + this.parameters.put("scale", new FeatureParameter<Float>("scale", "Scale", "Scale", 1.0f, "float")); + } @Override @@ -140,4 +144,30 @@ public abstract class TextHUDFeature extends GuiFeature implements StyledTextPro }); return "base." + getKey() ; } + + @Override + public List<MPanel> getTooltipForEditor(GuiGuiLocationConfig guiGuiLocationConfig) { + List<MPanel> mPanels = super.getTooltipForEditor(guiGuiLocationConfig); + mPanels.add(new MPassiveLabelAndElement("Align Right", new MToggleButton() {{ + setEnabled(TextHUDFeature.this.<Boolean>getParameter("alignRight").getValue()); + setOnToggle(() ->{ + TextHUDFeature.this.<Boolean>getParameter("alignRight").setValue(isEnabled()); + }); } + })); + mPanels.add(new MPassiveLabelAndElement("Align Center", new MToggleButton() {{ + setEnabled(TextHUDFeature.this.<Boolean>getParameter("alignCenter").getValue()); + setOnToggle(() ->{ + TextHUDFeature.this.<Boolean>getParameter("alignCenter").setValue(isEnabled()); + }); } + })); + if (!doesScaleWithHeight()) { + mPanels.add(new MPassiveLabelAndElement("Scale", new MFloatSelectionButton(TextHUDFeature.this.<Float>getParameter("scale").getValue()) {{ + setOnUpdate(() ->{ + TextHUDFeature.this.<Float>getParameter("scale").setValue(this.getData()); + }); } + })); + } + + return mPanels; + } } diff --git a/src/main/java/kr/syeyoung/dungeonsguide/gui/elements/MLabel.java b/src/main/java/kr/syeyoung/dungeonsguide/gui/elements/MLabel.java index cd0289a0..b9896802 100755 --- a/src/main/java/kr/syeyoung/dungeonsguide/gui/elements/MLabel.java +++ b/src/main/java/kr/syeyoung/dungeonsguide/gui/elements/MLabel.java @@ -67,6 +67,6 @@ public class MLabel extends MPanel { 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); - renderer.drawString(getText(), x,y, 0xffffff); + renderer.drawString(getText(), x,y, 0xffffffff); } } diff --git a/src/main/java/kr/syeyoung/dungeonsguide/gui/elements/MLabelAndElement.java b/src/main/java/kr/syeyoung/dungeonsguide/gui/elements/MLabelAndElement.java index 462dda24..c47eda61 100755 --- a/src/main/java/kr/syeyoung/dungeonsguide/gui/elements/MLabelAndElement.java +++ b/src/main/java/kr/syeyoung/dungeonsguide/gui/elements/MLabelAndElement.java @@ -43,6 +43,11 @@ public class MLabelAndElement extends MPanel { } @Override + public Dimension getPreferredSize() { + return new Dimension(200, 30); + } + + @Override public void render(int absMousex, int absMousey, int relMousex0, int relMousey0, float partialTicks, Rectangle scissor) { if (hover != null && new Rectangle(new Point(0,0),getBounds().getSize()).contains(relMousex0, relMousey0)) { Gui.drawRect(0,0,getBounds().width, getBounds().height, hover.getRGB()); diff --git a/src/main/java/kr/syeyoung/dungeonsguide/gui/elements/MPassiveLabelAndElement.java b/src/main/java/kr/syeyoung/dungeonsguide/gui/elements/MPassiveLabelAndElement.java new file mode 100755 index 00000000..af29f92a --- /dev/null +++ b/src/main/java/kr/syeyoung/dungeonsguide/gui/elements/MPassiveLabelAndElement.java @@ -0,0 +1,68 @@ +/* + * Dungeons Guide - The most intelligent Hypixel Skyblock Dungeons Mod + * Copyright (C) 2021 cyoung06 + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published + * by the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see <https://www.gnu.org/licenses/>. + */ + +package kr.syeyoung.dungeonsguide.gui.elements; + +import kr.syeyoung.dungeonsguide.gui.MPanel; +import lombok.Getter; +import lombok.Setter; +import net.minecraft.client.gui.Gui; + +import java.awt.*; + +public class MPassiveLabelAndElement extends MPanel { + private final MLabel label; + private final MPanel element; + + @Getter @Setter + private Color hover; + @Getter @Setter + private Runnable onClick; + + public MPassiveLabelAndElement(String label, MPanel element) { + this.add(this.label = new MLabel()); + this.label.setText(label); + this.add(element); + this.element = element; + } + + @Override + public Dimension getPreferredSize() { + return new Dimension(200, 30); + } + + @Override + public void render(int absMousex, int absMousey, int relMousex0, int relMousey0, float partialTicks, Rectangle scissor) { + if (hover != null && new Rectangle(new Point(0,0),getBounds().getSize()).contains(relMousex0, relMousey0)) { + Gui.drawRect(0,0,getBounds().width, getBounds().height, hover.getRGB()); + } + } + + @Override + public void mouseClicked(int absMouseX, int absMouseY, int relMouseX, int relMouseY, int mouseButton) { + if (onClick!= null && lastAbsClip.contains(absMouseX, absMouseY)) { + onClick.run(); + } + } + + @Override + public void onBoundsUpdate() { + label.setBounds(new Rectangle(0,0,getBounds().width / 3, getBounds().height)); + element.setBounds(new Rectangle(getBounds().width / 3,0,getBounds().width / 3 * 2, getBounds().height)); + } +} diff --git a/src/main/java/kr/syeyoung/dungeonsguide/gui/elements/MPopupMenu.java b/src/main/java/kr/syeyoung/dungeonsguide/gui/elements/MPopupMenu.java new file mode 100644 index 00000000..242d5a03 --- /dev/null +++ b/src/main/java/kr/syeyoung/dungeonsguide/gui/elements/MPopupMenu.java @@ -0,0 +1,75 @@ +/* + * Dungeons Guide - The most intelligent Hypixel Skyblock Dungeons Mod + * Copyright (C) 2021 cyoung06 + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published + * by the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see <https://www.gnu.org/licenses/>. + */ + +package kr.syeyoung.dungeonsguide.gui.elements; + +import kr.syeyoung.dungeonsguide.gui.MPanel; +import kr.syeyoung.dungeonsguide.utils.RenderUtils; +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.MathHelper; +import org.lwjgl.opengl.GL11; + +import java.awt.*; +import java.util.List; + +public class MPopupMenu extends MTooltip { + public MPopupMenu(int x, int y, List<MPanel> popupMenuElementList) { + int maxWidth = 150; + for (MPanel mPanel : popupMenuElementList) { + Dimension dimension = mPanel.getPreferredSize(); + if (dimension.width > maxWidth) maxWidth = dimension.width; + } + int h1 = 7; + for (MPanel mPanel : popupMenuElementList) { + Dimension dimension = mPanel.getPreferredSize(); + mPanel.setBounds(new Rectangle(7,h1, maxWidth-13, dimension.height)); + h1 += dimension.height + 7; + add(mPanel); + } + + if (y + h1 > Minecraft.getMinecraft().displayHeight) + y = Minecraft.getMinecraft().displayHeight - h1; + if (x + maxWidth+ 2 > Minecraft.getMinecraft().displayWidth) + x = Minecraft.getMinecraft().displayWidth - maxWidth-2; + setBounds(new Rectangle(x,y,maxWidth+2, h1)); + } + + @Override + public void render(int absMousex, int absMousey, int relMousex0, int relMousey0, float partialTicks, Rectangle scissor) { + super.render(absMousex, absMousey, relMousex0, relMousey0, partialTicks, scissor); + int radius = 7; + double deltaDegree = Math.PI/6; + RenderUtils.drawRoundedRectangle(0,0,getBounds().width,getBounds().height,radius,deltaDegree, RenderUtils.blendAlpha(0x121212, 0.0f)); + for (int i = 1; i < getChildComponents().size(); i++) { + MPanel childComponent = getChildComponents().get(i); + Gui.drawRect(7,childComponent.getBounds().y - 4, getBounds().width-7, childComponent.getBounds().y - 3, RenderUtils.blendAlpha(0x121212, 0.10f)); + } + } + + @Override + public void mouseClicked(int absMouseX, int absMouseY, int relMouseX, int relMouseY, int mouseButton) { + if (!getBounds().contains(absMouseX, absMouseY)) { + close(); + } + } +} diff --git a/src/main/java/kr/syeyoung/dungeonsguide/utils/RenderUtils.java b/src/main/java/kr/syeyoung/dungeonsguide/utils/RenderUtils.java index c2dfdb68..b6c5c22d 100755 --- a/src/main/java/kr/syeyoung/dungeonsguide/utils/RenderUtils.java +++ b/src/main/java/kr/syeyoung/dungeonsguide/utils/RenderUtils.java @@ -55,6 +55,49 @@ public class RenderUtils { public static boolean allowScrolling; public static int scrollX = 0; + public static void drawRoundedRectangle(int x, int y, int width, int height, int radius, double delta, int color) { + GlStateManager.pushMatrix(); + GlStateManager.translate(width/2.0+x, height/2.0+y, 0); + Tessellator t = Tessellator.getInstance(); + GlStateManager.disableTexture2D(); + GlStateManager.disableCull(); + RenderUtils.GL_SETCOLOR(color); + WorldRenderer wr = t.getWorldRenderer(); + wr.begin(GL11.GL_POLYGON, DefaultVertexFormats.POSITION); + for (double i = 0.1; i < Math.PI*2; i+= delta) { + double cos = MathHelper.cos((float) i); + double sin = MathHelper.sin((float) i); + if (cos != 0 || sin != 0) + wr.pos(cos * radius + (cos < 0 ? -width/2.0+radius : width/2.0-radius), + sin * radius + (sin <= 0 ? -height/2.0+radius : height/2.0-radius), 0) + .endVertex(); // .color((int) (i/(Math.PI*2) * 255),0,0,255) + if (cos *MathHelper.cos((float) (i + delta)) <= 0) { // X Change + sin = Math.round(sin); + + wr.pos((cos < 0 ? -1 : 1) * (width/2.0 - radius), + sin * radius + (sin < 0 ? -height/2.0+radius : height/2.0-radius), 0).endVertex(); + wr.pos((cos < 0 ? 1 : -1) * (width/2.0 - radius), + sin * radius + (sin < 0 ? -height/2.0+radius : height/2.0-radius), 0).endVertex(); + } else if (sin * MathHelper.sin((float) (i+delta)) <= 0) { // Y Change + cos = Math.round(cos); + + wr.pos(cos * radius + (cos < 0 ? -width/2.0+radius : width/2.0-radius), + (sin < 0 ? -1 : 1) *(height/2.0 - radius), 0).endVertex(); + wr.pos(cos * radius + (cos < 0 ? -width/2.0+radius : width/2.0-radius), + (sin < 0 ? 1 : -1) *(height/2.0 - radius), 0).endVertex(); + } + } + t.draw(); + GlStateManager.popMatrix(); + } + + public static void GL_SETCOLOR(int color) { + float f3 = (float)(color >> 24 & 255) / 255.0F; + float f = (float)(color >> 16 & 255) / 255.0F; + float f1 = (float)(color >> 8 & 255) / 255.0F; + float f2 = (float)(color & 255) / 255.0F; + GlStateManager.color(f, f1, f2, f3); + } public static int blendTwoColors(int background, int newColor) { float alpha = ((newColor >> 24) & 0xFF) /255.0f; |