From eac86380ed0db7be002e55d850ca7fea4b698c4d Mon Sep 17 00:00:00 2001 From: syeyoung Date: Wed, 18 Jan 2023 17:08:17 +0900 Subject: - upgrade mechanic browser to use guiv2 - also add #134 Signed-off-by: syeyoung --- .../mechanicbrowser/FeatureMechanicBrowse.java | 140 ++++++--- .../mechanicbrowser/MGuiMechanicBrowser.java | 45 --- .../mechanicbrowser/MechanicBrowserElement.java | 62 ---- .../mechanicbrowser/MechanicBrowserTooltip.java | 68 ---- .../mechanicbrowser/PanelMechanicBrowser.java | 344 --------------------- .../secret/mechanicbrowser/v2/WidgetCategory.java | 61 ++++ .../mechanicbrowser/v2/WidgetMechanicBrowser.java | 116 +++++++ .../secret/mechanicbrowser/v2/WidgetSecret.java | 87 ++++++ .../secret/mechanicbrowser/v2/WidgetState.java | 53 ++++ .../mechanicbrowser/v2/WidgetStateTooltip.java | 54 ++++ .../dungeonsguide/mod/guiv2/elements/AbsXY.java | 2 +- .../dungeonsguide/mod/guiv2/elements/Align.java | 2 +- .../mod/guiv2/elements/AspectRatioFitter.java | 2 +- .../mod/guiv2/elements/Background.java | 2 +- .../dungeonsguide/mod/guiv2/elements/Border.java | 10 +- .../dungeonsguide/mod/guiv2/elements/Button.java | 8 +- .../dungeonsguide/mod/guiv2/elements/Clip.java | 2 +- .../dungeonsguide/mod/guiv2/elements/Column.java | 2 +- .../mod/guiv2/elements/ConstrainedBox.java | 2 +- .../dungeonsguide/mod/guiv2/elements/Flexible.java | 2 +- .../mod/guiv2/elements/IntrinsicHeight.java | 2 +- .../mod/guiv2/elements/IntrinsicWidth.java | 2 +- .../dungeonsguide/mod/guiv2/elements/Line.java | 7 +- .../mod/guiv2/elements/LocationedPopup.java | 51 +++ .../dungeonsguide/mod/guiv2/elements/Measure.java | 2 +- .../dungeonsguide/mod/guiv2/elements/Padding.java | 2 +- .../dungeonsguide/mod/guiv2/elements/PopupMgr.java | 33 +- .../dungeonsguide/mod/guiv2/elements/Row.java | 2 +- .../dungeonsguide/mod/guiv2/elements/Scaler.java | 2 +- .../mod/guiv2/elements/ScrollablePanel.java | 10 +- .../mod/guiv2/elements/Scrollbar.java | 5 +- .../mod/guiv2/elements/SelectiveContainer.java | 6 +- .../dungeonsguide/mod/guiv2/elements/Slot.java | 2 +- .../dungeonsguide/mod/guiv2/elements/Stack.java | 2 +- .../dungeonsguide/mod/guiv2/elements/Text.java | 98 +++++- .../mod/guiv2/elements/UnconstrainedBox.java | 2 +- .../dungeonsguide/mod/guiv2/view/TestPopup.java | 2 +- .../dungeonsguide/mod/guiv2/view/TestView.java | 2 +- .../mod/guiv2/xml/DomElementRegistry.java | 2 + .../guiv2/xml/PropByPropParsedWidgetConverter.java | 11 +- .../mod/guiv2/xml/StringConversions.java | 2 +- .../dungeonsguide/mod/overlay/OverlayManager.java | 59 ++-- .../dungeonsguide/gui/elements/locationedPopup.gui | 20 ++ .../assets/dungeonsguide/gui/elements/popupmgr.gui | 2 +- .../dungeonsguide/gui/elements/scrollablePanel.gui | 2 +- .../dungeonsguide/gui/elements/simpleButton.gui | 26 +- .../assets/dungeonsguide/gui/elements/size.gui | 2 +- .../gui/features/mechanicBrowser/browser.gui | 55 ++++ .../gui/features/mechanicBrowser/category.gui | 20 +- .../gui/features/mechanicBrowser/secret.gui | 25 ++ .../gui/features/mechanicBrowser/state.gui | 25 ++ .../gui/features/mechanicBrowser/tooltip.gui | 34 ++ 52 files changed, 938 insertions(+), 643 deletions(-) delete mode 100644 mod/src/main/java/kr/syeyoung/dungeonsguide/mod/features/impl/secret/mechanicbrowser/MGuiMechanicBrowser.java delete mode 100644 mod/src/main/java/kr/syeyoung/dungeonsguide/mod/features/impl/secret/mechanicbrowser/MechanicBrowserElement.java delete mode 100644 mod/src/main/java/kr/syeyoung/dungeonsguide/mod/features/impl/secret/mechanicbrowser/MechanicBrowserTooltip.java delete mode 100644 mod/src/main/java/kr/syeyoung/dungeonsguide/mod/features/impl/secret/mechanicbrowser/PanelMechanicBrowser.java create mode 100644 mod/src/main/java/kr/syeyoung/dungeonsguide/mod/features/impl/secret/mechanicbrowser/v2/WidgetCategory.java create mode 100644 mod/src/main/java/kr/syeyoung/dungeonsguide/mod/features/impl/secret/mechanicbrowser/v2/WidgetMechanicBrowser.java create mode 100644 mod/src/main/java/kr/syeyoung/dungeonsguide/mod/features/impl/secret/mechanicbrowser/v2/WidgetSecret.java create mode 100644 mod/src/main/java/kr/syeyoung/dungeonsguide/mod/features/impl/secret/mechanicbrowser/v2/WidgetState.java create mode 100644 mod/src/main/java/kr/syeyoung/dungeonsguide/mod/features/impl/secret/mechanicbrowser/v2/WidgetStateTooltip.java create mode 100644 mod/src/main/java/kr/syeyoung/dungeonsguide/mod/guiv2/elements/LocationedPopup.java create mode 100644 mod/src/main/resources/assets/dungeonsguide/gui/elements/locationedPopup.gui create mode 100644 mod/src/main/resources/assets/dungeonsguide/gui/features/mechanicBrowser/browser.gui create mode 100644 mod/src/main/resources/assets/dungeonsguide/gui/features/mechanicBrowser/secret.gui create mode 100644 mod/src/main/resources/assets/dungeonsguide/gui/features/mechanicBrowser/state.gui create mode 100644 mod/src/main/resources/assets/dungeonsguide/gui/features/mechanicBrowser/tooltip.gui (limited to 'mod') diff --git a/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/features/impl/secret/mechanicbrowser/FeatureMechanicBrowse.java b/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/features/impl/secret/mechanicbrowser/FeatureMechanicBrowse.java index 48e515bb..91b87969 100644 --- a/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/features/impl/secret/mechanicbrowser/FeatureMechanicBrowse.java +++ b/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/features/impl/secret/mechanicbrowser/FeatureMechanicBrowse.java @@ -24,20 +24,29 @@ import kr.syeyoung.dungeonsguide.mod.SkyblockStatus; import kr.syeyoung.dungeonsguide.mod.config.guiconfig.location.GuiGuiLocationConfig; import kr.syeyoung.dungeonsguide.mod.config.types.GUIRectangle; import kr.syeyoung.dungeonsguide.mod.dungeon.DungeonContext; +import kr.syeyoung.dungeonsguide.mod.dungeon.actions.tree.ActionRoute; import kr.syeyoung.dungeonsguide.mod.dungeon.roomfinder.DungeonRoom; import kr.syeyoung.dungeonsguide.mod.dungeon.roomprocessor.GeneralRoomProcessor; import kr.syeyoung.dungeonsguide.mod.events.annotations.DGEventHandler; +import kr.syeyoung.dungeonsguide.mod.events.impl.DGTickEvent; import kr.syeyoung.dungeonsguide.mod.features.FeatureParameter; import kr.syeyoung.dungeonsguide.mod.features.GuiFeature; +import kr.syeyoung.dungeonsguide.mod.features.impl.secret.mechanicbrowser.v2.WidgetMechanicBrowser; import kr.syeyoung.dungeonsguide.mod.gui.MPanel; import kr.syeyoung.dungeonsguide.mod.gui.elements.MFloatSelectionButton; import kr.syeyoung.dungeonsguide.mod.gui.elements.MPassiveLabelAndElement; +import kr.syeyoung.dungeonsguide.mod.guiv2.primitive.Rect; +import kr.syeyoung.dungeonsguide.mod.overlay.OverlayManager; +import kr.syeyoung.dungeonsguide.mod.overlay.OverlayType; +import kr.syeyoung.dungeonsguide.mod.overlay.OverlayWidget; import net.minecraft.client.Minecraft; import net.minecraft.client.entity.EntityPlayerSP; import net.minecraft.client.gui.FontRenderer; import net.minecraft.client.gui.Gui; +import net.minecraft.client.gui.GuiChat; import net.minecraft.client.renderer.GlStateManager; import net.minecraft.util.MathHelper; +import net.minecraftforge.client.event.GuiOpenEvent; import net.minecraftforge.client.event.GuiScreenEvent; import net.minecraftforge.client.event.RenderGameOverlayEvent; import net.minecraftforge.client.event.RenderWorldLastEvent; @@ -48,27 +57,29 @@ import org.lwjgl.opengl.GL14; import java.awt.*; import java.io.IOException; import java.util.List; +import java.util.Objects; import java.util.Optional; +import java.util.UUID; public class FeatureMechanicBrowse extends GuiFeature { + + private OverlayWidget lastOpen; + private OverlayWidget widget; + private WidgetMechanicBrowser mechanicBrowser; + public FeatureMechanicBrowse() { super("Dungeon.Secrets.Secret Browser","Secret Browser", "Browse and Pathfind secrets and mechanics in the current room", "secret.mechanicbrowse", false, 100, 300); addParameter("scale", new FeatureParameter("scale", "Scale", "Scale", 1.0f, "float")); - mGuiMechanicBrowser = new MGuiMechanicBrowser(this); - mGuiMechanicBrowser.setWorldAndResolution(Minecraft.getMinecraft(), Minecraft.getMinecraft().displayWidth, Minecraft.getMinecraft().displayHeight); - lastWidth = Minecraft.getMinecraft().displayWidth; lastHeight = Minecraft.getMinecraft().displayHeight; } public double getScale() { return this.getParameter("scale").getValue(); } - private MGuiMechanicBrowser mGuiMechanicBrowser; @Override public void drawDemo(float partialTicks) { - super.drawDemo(partialTicks); double scale = FeatureMechanicBrowse.this.getParameter("scale").getValue(); GlStateManager.scale(scale, scale, 1.0); @@ -86,44 +97,59 @@ public class FeatureMechanicBrowse extends GuiFeature { fr.drawString("Open Chat to Select Secrets", 2, fr.FONT_HEIGHT + 5, 0xFFAAAAAA); } - private int lastWidth, lastHeight; - @Override - public void drawScreen(float partialTicks) { - - int i = Mouse.getEventX(); - int j = Minecraft.getMinecraft().displayHeight - Mouse.getEventY(); - if (Minecraft.getMinecraft().displayWidth != lastWidth || Minecraft.getMinecraft().displayHeight != lastHeight) mGuiMechanicBrowser.initGui(); - lastWidth = Minecraft.getMinecraft().displayWidth; lastHeight = Minecraft.getMinecraft().displayHeight; - mGuiMechanicBrowser.drawScreen(i,j,partialTicks); - } + public void drawHUD(float partialTicks) { + SkyblockStatus skyblockStatus = DungeonsGuide.getDungeonsGuide().getSkyblockStatus(); + if (!skyblockStatus.isOnDungeon()) return; + if (DungeonsGuide.getDungeonsGuide().getDungeonFacade().getContext() == null || !DungeonsGuide.getDungeonsGuide().getDungeonFacade().getContext().getMapProcessor().isInitialized()) return; + DungeonContext context = DungeonsGuide.getDungeonsGuide().getDungeonFacade().getContext(); - @Override - public void setFeatureRect(GUIRectangle featureRect) { - super.setFeatureRect(featureRect); - mGuiMechanicBrowser.initGui(); - } + EntityPlayerSP thePlayer = Minecraft.getMinecraft().thePlayer; + Point roomPt = context.getMapProcessor().worldPointToRoomPoint(thePlayer.getPosition()); + DungeonRoom dungeonRoom = context.getRoomMapper().get(roomPt); + if (dungeonRoom == null) return; + if (!(dungeonRoom.getRoomProcessor() instanceof GeneralRoomProcessor)) return; + GeneralRoomProcessor grp = (GeneralRoomProcessor) dungeonRoom.getRoomProcessor(); - @Override - public void drawHUD(float partialTicks) { } + double scale = FeatureMechanicBrowse.this.getParameter("scale").getValue(); + GlStateManager.scale(scale, scale, 1.0); + + Dimension bigDim = getFeatureRect().getRectangleNoScale().getSize(); + Dimension effectiveDim = new Dimension((int) (bigDim.width / scale),(int)( bigDim.height / scale)); + + FontRenderer fr = Minecraft.getMinecraft().fontRendererObj; + Gui.drawRect(0, 0, effectiveDim.width, fr.FONT_HEIGHT + 4, 0xFF444444); + Gui.drawRect(1, 1, effectiveDim.width - 1, fr.FONT_HEIGHT + 3, 0xFF262626); + 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("Selected: ", 2,2, 0xFFAAAAAA); + if (grp.getPath("MECH-BROWSER") == null) + fr.drawString("Nothing", fr.getStringWidth("Selected: ") + 2,2, 0xFFAA0000); + else { + ActionRoute route = grp.getPath("MECH-BROWSER"); + fr.drawString(route.getMechanic()+" -> "+route.getState(), fr.getStringWidth("Selected: ") + 2,2, 0xFFFFFF00); + } + fr.drawString("Open Chat to Select Secrets", 2, fr.FONT_HEIGHT + 5, 0xFFAAAAAA); + } @DGEventHandler public void onMouseInput(GuiScreenEvent.MouseInputEvent.Pre mouseInputEvent) { - - try { - mGuiMechanicBrowser.handleMouseInput(); - } catch (IOException e) { - e.printStackTrace(); - } +// +// try { +// mGuiMechanicBrowser.handleMouseInput(); +// } catch (IOException e) { +// e.printStackTrace(); +// } } @DGEventHandler public void onGuiPreRender(GuiScreenEvent.DrawScreenEvent.Pre rendered) { - - int i = Mouse.getEventX(); - int j = Minecraft.getMinecraft().displayHeight - Mouse.getEventY(); - mGuiMechanicBrowser.drawScreen(i, j, rendered.renderPartialTicks); +// +// int i = Mouse.getEventX(); +// int j = Minecraft.getMinecraft().displayHeight - Mouse.getEventY(); +// mGuiMechanicBrowser.drawScreen(i, j, rendered.renderPartialTicks); } @DGEventHandler @@ -140,9 +166,9 @@ public class FeatureMechanicBrowse extends GuiFeature { DungeonRoom dungeonRoom = context.getRoomMapper().get(roomPt); if (dungeonRoom == null) return; if (!(dungeonRoom.getRoomProcessor() instanceof GeneralRoomProcessor)) return; - String id = mGuiMechanicBrowser.getPanelMechanicBrowser().getSelectedID(); + String id = mechanicBrowser.getSelectedId(); if (id != null) { - Optional.ofNullable(dungeonRoom.getMechanics().get(mGuiMechanicBrowser.getPanelMechanicBrowser().getSelectedID())) + Optional.ofNullable(dungeonRoom.getMechanics().get(mechanicBrowser.getSelectedId())) .ifPresent(a -> { a.highlight(new Color(0,255,255,50), id +" ("+( dungeonRoom.getMechanics().get(id).getRepresentingPoint(dungeonRoom) != null ? @@ -158,10 +184,54 @@ public class FeatureMechanicBrowse extends GuiFeature { mPanels.add(new MPassiveLabelAndElement("Scale", new MFloatSelectionButton(FeatureMechanicBrowse.this.getParameter("scale").getValue()) {{ setOnUpdate(() ->{ FeatureMechanicBrowse.this.getParameter("scale").setValue(this.getData()); - mGuiMechanicBrowser.initGui(); }); } })); return mPanels; } + + @DGEventHandler + public void onOpen(GuiOpenEvent event) { + if (event.gui instanceof GuiChat) { + if (widget != null) + OverlayManager.getInstance().addOverlay(lastOpen = widget); + } else { + if (lastOpen != null) + OverlayManager.getInstance().removeOverlay(lastOpen); + lastOpen = null; + } + } + + + private UUID lastRoomUid = null; + @DGEventHandler + public void onTick(DGTickEvent event) { + Optional dungeonRoomOpt = Optional.ofNullable(DungeonsGuide.getDungeonsGuide().getDungeonFacade().getContext()) + .map(DungeonContext::getMapProcessor).map(a->a.worldPointToRoomPoint(Minecraft.getMinecraft().thePlayer.getPosition())) + .map(a -> { + return DungeonsGuide.getDungeonsGuide().getDungeonFacade().getContext().getRoomMapper().get(a); + }); + UUID currentUID = dungeonRoomOpt.map(a -> a.getDungeonRoomInfo().getUuid()).orElse(null); + // Event-ify above this. + + if (!Objects.equals(lastRoomUid, currentUID)) { + if (currentUID == null) { + mechanicBrowser = null; + widget = null; + } else { + if (lastOpen != null) + OverlayManager.getInstance().removeOverlay(lastOpen); + widget = new OverlayWidget( + mechanicBrowser = new WidgetMechanicBrowser(dungeonRoomOpt.get()), + OverlayType.OVER_CHAT, + () -> { + Rectangle loc = getFeatureRect().getRectangleNoScale(); + return new Rect(loc.x, loc.y, loc.width, loc.height); + }); + } + } + if (mechanicBrowser != null) + mechanicBrowser.update(); + lastRoomUid = currentUID; + } } diff --git a/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/features/impl/secret/mechanicbrowser/MGuiMechanicBrowser.java b/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/features/impl/secret/mechanicbrowser/MGuiMechanicBrowser.java deleted file mode 100644 index d7d69e0a..00000000 --- a/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/features/impl/secret/mechanicbrowser/MGuiMechanicBrowser.java +++ /dev/null @@ -1,45 +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.mod.features.impl.secret.mechanicbrowser; - -import kr.syeyoung.dungeonsguide.mod.gui.MGui; -import lombok.Getter; - -public class MGuiMechanicBrowser extends MGui { - private FeatureMechanicBrowse featureMechanicBrowse; - @Getter - private PanelMechanicBrowser panelMechanicBrowser; - public MGuiMechanicBrowser(FeatureMechanicBrowse mechanicBrowse) { - this.featureMechanicBrowse = mechanicBrowse; - panelMechanicBrowser = new PanelMechanicBrowser(mechanicBrowse); - getMainPanel().add(panelMechanicBrowser); - } - - @Override - public void initGui() { - super.initGui(); - panelMechanicBrowser.setBounds(featureMechanicBrowse.getFeatureRect().getRectangle()); - panelMechanicBrowser.setScale(featureMechanicBrowse.getScale()); - } - - @Override - public void drawScreen(int mouseX, int mouseY, float partialTicks) { - super.drawScreen(mouseX, mouseY, partialTicks); - } -} diff --git a/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/features/impl/secret/mechanicbrowser/MechanicBrowserElement.java b/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/features/impl/secret/mechanicbrowser/MechanicBrowserElement.java deleted file mode 100644 index 7ed916c0..00000000 --- a/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/features/impl/secret/mechanicbrowser/MechanicBrowserElement.java +++ /dev/null @@ -1,62 +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.mod.features.impl.secret.mechanicbrowser; - - -import kr.syeyoung.dungeonsguide.mod.gui.MPanel; -import kr.syeyoung.dungeonsguide.mod.utils.cursor.EnumCursor; -import lombok.AllArgsConstructor; -import net.minecraft.client.Minecraft; -import net.minecraft.client.gui.Gui; - -import java.awt.*; -import java.util.function.BiConsumer; -import java.util.function.Supplier; - -@AllArgsConstructor -public class MechanicBrowserElement extends MPanel { - private Supplier name; - private boolean isCategory = false; - private BiConsumer onClick; - @Override - public void render(int absMousex, int absMousey, int relMousex0, int relMousey0, float partialTicks, Rectangle scissor) { - if (isCategory || isFocused) - Gui.drawRect(0, 0, bounds.width, bounds.height, 0xFF444444); - else if (lastAbsClip.contains(absMousex, absMousey)) - Gui.drawRect(0, 0, bounds.width, bounds.height, 0xFF555555); - Minecraft.getMinecraft().fontRendererObj.drawString((String)name.get(), 4, 1, 0xFFEEEEEE); - } - - @Override - public Dimension getPreferredSize() { - return new Dimension(Minecraft.getMinecraft().fontRendererObj.getStringWidth(name.get()) + 8, Minecraft.getMinecraft().fontRendererObj.FONT_HEIGHT); - } - - @Override - public void mouseClicked(int absMouseX, int absMouseY, int relMouseX, int relMouseY, int mouseButton) { - if (lastAbsClip.contains(absMouseX, absMouseY) && onClick != null) - onClick.accept(this, new Point(lastParentPoint.x + bounds.x, lastParentPoint.y + bounds.y)); - } - - @Override - public void mouseMoved(int absMouseX, int absMouseY, int relMouseX0, int relMouseY0) { - if (lastAbsClip.contains(absMouseX, absMouseY) && onClick != null) - setCursor(EnumCursor.POINTING_HAND); - } -} diff --git a/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/features/impl/secret/mechanicbrowser/MechanicBrowserTooltip.java b/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/features/impl/secret/mechanicbrowser/MechanicBrowserTooltip.java deleted file mode 100644 index 87b100a5..00000000 --- a/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/features/impl/secret/mechanicbrowser/MechanicBrowserTooltip.java +++ /dev/null @@ -1,68 +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.mod.features.impl.secret.mechanicbrowser; - -import kr.syeyoung.dungeonsguide.mod.gui.elements.MList; -import kr.syeyoung.dungeonsguide.mod.gui.elements.MTooltip; -import lombok.Getter; -import net.minecraft.client.gui.Gui; - -import java.awt.*; - -public class MechanicBrowserTooltip extends MTooltip { - @Getter - private MList mList; - public MechanicBrowserTooltip() { - mList = new MList(); - mList.setGap(0); - add(mList); - } - - @Override - public void render(int absMousex, int absMousey, int relMousex0, int relMousey0, float partialTicks, Rectangle scissor) { - Dimension effectiveDim = getEffectiveDimension(); - Gui.drawRect(0, 0, effectiveDim.width, effectiveDim.height, 0xFF444444); - Gui.drawRect(1, 1, effectiveDim.width - 1, effectiveDim.height - 1, 0xFF262626); - } - - @Override - public void setBounds(Rectangle bounds) { - super.setBounds(bounds); - mList.setBounds(new Rectangle(1,1, getEffectiveDimension().width-2, getEffectiveDimension().height-2)); - mList.realignChildren(); - } - - @Override - public void setScale(double scale) { - super.setScale(scale); - mList.setBounds(new Rectangle(1,1, getEffectiveDimension().width-2, getEffectiveDimension().height-2)); - mList.realignChildren(); - } - - @Override - public Dimension getPreferredSize() { - Dimension dim = mList.getPreferredSize(); - return new Dimension((int) ((dim.width + 2) * getScale()), (int) ((dim.height + 2) * getScale())); - } - - @Override - public void mouseClicked(int absMouseX, int absMouseY, int relMouseX, int relMouseY, int mouseButton) { - if (!lastAbsClip.contains(absMouseX, absMouseY)) close(); - } -} diff --git a/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/features/impl/secret/mechanicbrowser/PanelMechanicBrowser.java b/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/features/impl/secret/mechanicbrowser/PanelMechanicBrowser.java deleted file mode 100644 index c108f117..00000000 --- a/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/features/impl/secret/mechanicbrowser/PanelMechanicBrowser.java +++ /dev/null @@ -1,344 +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.mod.features.impl.secret.mechanicbrowser; - - -import kr.syeyoung.dungeonsguide.dungeon.mechanics.*; -import kr.syeyoung.dungeonsguide.dungeon.mechanics.dunegonmechanic.DungeonMechanic; -import kr.syeyoung.dungeonsguide.mod.DungeonsGuide; -import kr.syeyoung.dungeonsguide.mod.dungeon.DungeonContext; -import kr.syeyoung.dungeonsguide.mod.dungeon.actions.tree.ActionRoute; -import kr.syeyoung.dungeonsguide.mod.dungeon.roomfinder.DungeonRoom; -import kr.syeyoung.dungeonsguide.mod.dungeon.roomprocessor.GeneralRoomProcessor; -import kr.syeyoung.dungeonsguide.mod.features.FeatureRegistry; -import kr.syeyoung.dungeonsguide.mod.gui.MPanel; -import kr.syeyoung.dungeonsguide.mod.gui.elements.MList; -import kr.syeyoung.dungeonsguide.mod.gui.elements.MPanelScaledGUI; -import kr.syeyoung.dungeonsguide.mod.gui.elements.MScrollablePanel; -import lombok.Getter; -import net.minecraft.client.Minecraft; -import net.minecraft.client.gui.FontRenderer; -import net.minecraft.client.gui.Gui; -import net.minecraft.client.gui.GuiChat; -import net.minecraft.client.renderer.GlStateManager; -import net.minecraft.util.MathHelper; -import org.lwjgl.opengl.GL11; -import org.lwjgl.opengl.GL14; - -import java.awt.*; -import java.util.List; -import java.util.*; - -public class PanelMechanicBrowser extends MPanelScaledGUI { - private FeatureMechanicBrowse feature; - private MScrollablePanel scrollablePanel; - private MList mList; - private MechanicBrowserTooltip mechanicBrowserTooltip; - - public PanelMechanicBrowser(FeatureMechanicBrowse mechanicBrowse) { - this.feature = mechanicBrowse; - this.scrollablePanel = new MScrollablePanel(1); - add(this.scrollablePanel); - scrollablePanel.getScrollBarY().setWidth(0); - mList = new MList() { - @Override - public void resize(int parentWidth, int parentHeight) { - setBounds(new Rectangle(0,0,parentWidth,parentHeight)); - Dimension prefSize = getPreferredSize(); - int hei = prefSize.height; - setBounds(new Rectangle(0,0,parentWidth,hei)); - realignChildren(); - } - }; - mList.setDrawLine(false); mList.setGap(0); - scrollablePanel.add(mList); - } - - @Override - public void render(int absMousex, int absMousey, int relMousex0, int relMousey0, float partialTicks, Rectangle scissor) { - toggleTooltip(openGUI()); - - if(Minecraft.getMinecraft().thePlayer == null) return; - - - Optional dungeonRoomOpt = Optional.ofNullable(DungeonsGuide.getDungeonsGuide().getDungeonFacade().getContext()) - .map(DungeonContext::getMapProcessor).map(a->a.worldPointToRoomPoint(Minecraft.getMinecraft().thePlayer.getPosition())) - .map(a -> { - - return DungeonsGuide.getDungeonsGuide().getDungeonFacade().getContext().getRoomMapper().get(a); - }); - - - DungeonRoom dungeonRoom = dungeonRoomOpt.orElse(null); - renderTick(dungeonRoom); - if (dungeonRoom == null) return; - if (!(dungeonRoom.getRoomProcessor() instanceof GeneralRoomProcessor)) return; - - GeneralRoomProcessor grp = (GeneralRoomProcessor) dungeonRoom.getRoomProcessor(); - - - FontRenderer fr = Minecraft.getMinecraft().fontRendererObj; - - Dimension effectiveDim = getEffectiveDimension(); - - Gui.drawRect(0, 0, effectiveDim.width, fr.FONT_HEIGHT + 4, 0xFF444444); - Gui.drawRect(1, 1, effectiveDim.width - 1, fr.FONT_HEIGHT + 3, 0xFF262626); - 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("Selected: ", 2,2, 0xFFAAAAAA); - if (grp.getPath("MECH-BROWSER") == null) - fr.drawString("Nothing", fr.getStringWidth("Selected: ") + 2,2, 0xFFAA0000); - else { - ActionRoute route = grp.getPath("MECH-BROWSER"); - fr.drawString(route.getMechanic()+" -> "+route.getState(), fr.getStringWidth("Selected: ") + 2,2, 0xFFFFFF00); - } - fr.drawString("Open Chat to Select Secrets", 2, fr.FONT_HEIGHT + 5, 0xFFAAAAAA); - - if (!openGUI()) return; - - Gui.drawRect(0, fr.FONT_HEIGHT + 4, effectiveDim.width, effectiveDim.height, 0xFF444444); - Gui.drawRect(1, fr.FONT_HEIGHT + 5, effectiveDim.width - 1,effectiveDim.height - 1, 0xFF262626); - } - - private UUID lastRoomUID = null; - public void renderTick(DungeonRoom dungeonRoom) { - if (dungeonRoom == null && lastRoomUID != null) { - lastRoomUID = null; - for (MPanel childComponent : mList.getChildComponents()) { - mList.remove(childComponent); - } - if (mechanicBrowserTooltip != null) { - mechanicBrowserTooltip.close(); - mechanicBrowserTooltip = null; - } - selectedID = null; - } else if (dungeonRoom != null && lastRoomUID != dungeonRoom.getDungeonRoomInfo().getUuid()) { - lastRoomUID = dungeonRoom.getDungeonRoomInfo().getUuid(); - // SETUP THINGS. - for (MPanel childComponent : mList.getChildComponents()) { - mList.remove(childComponent); - } - if (mechanicBrowserTooltip != null) { - mechanicBrowserTooltip.close(); - mechanicBrowserTooltip = null; - } - selectedID = null; - mList.add(new MechanicBrowserElement(() -> "§bCancel Current", false, (pt, me) -> cancel(pt))); - - boolean found = false; - for (Map.Entry value : dungeonRoom.getMechanics().entrySet()) { - if (value.getValue() instanceof DungeonFairySoul) { - if (!found) { - mList.add(new MechanicBrowserElement(() -> "Fairy Soul", true, null)); - found = true; - } - mList.add(new MechanicBrowserElement(() -> value.getKey()+" §7("+ value.getValue().getCurrentState(dungeonRoom) +", "+ - (value.getValue().getRepresentingPoint(dungeonRoom) != null ? - String.format("%.1f", MathHelper.sqrt_double(value.getValue().getRepresentingPoint(dungeonRoom).getBlockPos(dungeonRoom).distanceSq(Minecraft.getMinecraft().thePlayer.getPosition()))) : "") - +"m)", false, (me, pt) -> onElementClick(value.getKey(), value.getValue(), pt, me))); - } - } - found = false; - for (Map.Entry value : dungeonRoom.getMechanics().entrySet()) { - if (value.getValue() instanceof DungeonSecret) { - if (!found) { - mList.add(new MechanicBrowserElement(() -> "Secrets", true, null)); - found = true; - } - mList.add(new MechanicBrowserElement(() -> value.getKey()+" §7("+ value.getValue().getCurrentState(dungeonRoom) +", "+ - (value.getValue().getRepresentingPoint(dungeonRoom) != null ? - String.format("%.1f", MathHelper.sqrt_double(value.getValue().getRepresentingPoint(dungeonRoom).getBlockPos(dungeonRoom).distanceSq(Minecraft.getMinecraft().thePlayer.getPosition()))) : "") - +"m)", false, (me, pt) -> onElementClick(value.getKey(), value.getValue(), pt, me))); - } - } - found = false; - for (Map.Entry value : dungeonRoom.getMechanics().entrySet()) { - if (value.getValue() instanceof DungeonTomb) { - if (!found) { - mList.add(new MechanicBrowserElement(() -> "Crypts", true, null)); - found = true; - } - mList.add(new MechanicBrowserElement(() -> value.getKey()+" §7("+ value.getValue().getCurrentState(dungeonRoom) +", "+ - (value.getValue().getRepresentingPoint(dungeonRoom) != null ? - String.format("%.1f", MathHelper.sqrt_double(value.getValue().getRepresentingPoint(dungeonRoom).getBlockPos(dungeonRoom).distanceSq(Minecraft.getMinecraft().thePlayer.getPosition()))) : "") - +"m)", false, (me, pt) -> onElementClick(value.getKey(), value.getValue(), pt, me))); - } - } - found = false; - for (Map.Entry value : dungeonRoom.getMechanics().entrySet()) { - if (value.getValue() instanceof DungeonNPC) { - if (!found) { - mList.add(new MechanicBrowserElement(() -> "NPC", true, null)); - found = true; - } - mList.add(new MechanicBrowserElement(() -> value.getKey()+" §7("+ value.getValue().getCurrentState(dungeonRoom) +", "+ - (value.getValue().getRepresentingPoint(dungeonRoom) != null ? - String.format("%.1f", MathHelper.sqrt_double(value.getValue().getRepresentingPoint(dungeonRoom).getBlockPos(dungeonRoom).distanceSq(Minecraft.getMinecraft().thePlayer.getPosition()))) : "") - +"m)", false, (me, pt) -> onElementClick(value.getKey(), value.getValue(), pt, me))); - } - } - found = false; - for (Map.Entry value : dungeonRoom.getMechanics().entrySet()) { - if (value.getValue() instanceof DungeonJournal) { - if (!found) { - mList.add(new MechanicBrowserElement(() -> "Journals", true, null)); - found = true; - } - mList.add(new MechanicBrowserElement(() -> value.getKey()+" §7("+ value.getValue().getCurrentState(dungeonRoom) +", "+ - (value.getValue().getRepresentingPoint(dungeonRoom) != null ? - String.format("%.1f", MathHelper.sqrt_double(value.getValue().getRepresentingPoint(dungeonRoom).getBlockPos(dungeonRoom).distanceSq(Minecraft.getMinecraft().thePlayer.getPosition()))) : "") - +"m)", false, (me, pt) -> onElementClick(value.getKey(), value.getValue(), pt, me))); - } - } - found = false; - for (Map.Entry value : dungeonRoom.getMechanics().entrySet()) { - if (value.getValue() instanceof DungeonRoomDoor){ - if (!found) { - mList.add(new MechanicBrowserElement(() -> "Gates", true, null)); - found = true; - } - mList.add(new MechanicBrowserElement(() -> value.getKey()+" §7("+ value.getValue().getCurrentState(dungeonRoom) +", "+ - (value.getValue().getRepresentingPoint(dungeonRoom) != null ? - String.format("%.1f", MathHelper.sqrt_double(value.getValue().getRepresentingPoint(dungeonRoom).getBlockPos(dungeonRoom).distanceSq(Minecraft.getMinecraft().thePlayer.getPosition()))) : "") - +"m)", false, (me, pt) -> onElementClick(value.getKey(), value.getValue(), pt, me))); - } - } - found = false; - for (Map.Entry value : dungeonRoom.getMechanics().entrySet()) { - if (value.getValue() instanceof DungeonDoor || value.getValue() instanceof DungeonBreakableWall || value.getValue() instanceof DungeonLever - || value.getValue() instanceof DungeonOnewayDoor || value.getValue() instanceof DungeonOnewayLever || value.getValue() instanceof DungeonPressurePlate) { - if (!found) { - mList.add(new MechanicBrowserElement(() -> "ETC", true, null)); - found = true; - } - mList.add(new MechanicBrowserElement(() -> value.getKey()+" §7("+ value.getValue().getCurrentState(dungeonRoom) +", "+ - (value.getValue().getRepresentingPoint(dungeonRoom) != null ? - String.format("%.1f", MathHelper.sqrt_double(value.getValue().getRepresentingPoint(dungeonRoom).getBlockPos(dungeonRoom).distanceSq(Minecraft.getMinecraft().thePlayer.getPosition()))) : "") - +"m)", false, (me, pt) -> onElementClick(value.getKey(), value.getValue(), pt, me))); - } - } - - scrollablePanel.evalulateContentArea(); - - } - } - - private int latestTooltipDY; - @Getter - private String selectedID = null; - public void onElementClick(String id, DungeonMechanic dungeonMechanic, Point pt, MechanicBrowserElement mechanicBrowserElement) { - - Optional dungeonRoomOpt = Optional.ofNullable(DungeonsGuide.getDungeonsGuide().getDungeonFacade().getContext()) - .map(DungeonContext::getMapProcessor).map(a->a.worldPointToRoomPoint(Minecraft.getMinecraft().thePlayer.getPosition())) - .map(a -> { - - return DungeonsGuide.getDungeonsGuide().getDungeonFacade().getContext().getRoomMapper().get(a); - }); - selectedID = id; - - DungeonRoom dungeonRoom = dungeonRoomOpt.orElse(null); - if (dungeonRoom == null) return; - DungeonMechanic dungeonMechanic1 = dungeonRoom.getMechanics().get(id); - if (dungeonMechanic1 != dungeonMechanic) return; - Set states = dungeonMechanic1.getPossibleStates(dungeonRoom); - - - if (mechanicBrowserTooltip != null) { - mechanicBrowserTooltip.close(); - } - - latestTooltipDY = (int) (pt.y * getScale() - bounds.y - 1); - - mechanicBrowserTooltip = new MechanicBrowserTooltip(); - for (String state : states) { - mechanicBrowserTooltip.getMList().add(new MechanicBrowserElement(() -> state, false, (m2, pt2) -> { - if (dungeonRoom.getRoomProcessor() instanceof GeneralRoomProcessor) - ((GeneralRoomProcessor)dungeonRoom.getRoomProcessor()).pathfind("MECH-BROWSER", id, state, FeatureRegistry.SECRET_LINE_PROPERTIES_SECRET_BROWSER.getRouteProperties()); -// mechanicBrowserTooltip.close(); -// mechanicBrowserTooltip = null; - })); - } - mechanicBrowserTooltip.setScale(getScale()); - Dimension prefSize = mechanicBrowserTooltip.getPreferredSize(); - mechanicBrowserTooltip.setBounds(new Rectangle(bounds.x + - (bounds.x > Minecraft.getMinecraft().displayWidth/2 ? -prefSize.width : bounds.width), latestTooltipDY + bounds.y, prefSize.width, prefSize.height)); - mechanicBrowserTooltip.open(this); - } - - public void cancel(MechanicBrowserElement mechanicBrowserElement) { - - Optional dungeonRoomOpt = Optional.ofNullable(DungeonsGuide.getDungeonsGuide().getDungeonFacade().getContext()) - .map(DungeonContext::getMapProcessor).map(a->a.worldPointToRoomPoint(Minecraft.getMinecraft().thePlayer.getPosition())) - .map(a -> { - - return DungeonsGuide.getDungeonsGuide().getDungeonFacade().getContext().getRoomMapper().get(a); - }); - mechanicBrowserElement.setFocused(false); - if (!dungeonRoomOpt.isPresent()) return; - DungeonRoom dungeonRoom = dungeonRoomOpt.get(); - if (!(dungeonRoom.getRoomProcessor() instanceof GeneralRoomProcessor)) return; - ((GeneralRoomProcessor) dungeonRoom.getRoomProcessor()).cancel("MECH-BROWSER"); - } - - public void toggleTooltip(boolean open) { - if (mechanicBrowserTooltip != null) { - if (open) { - mechanicBrowserTooltip.open(this); - } else { - mechanicBrowserTooltip.close(); - } - } - } - - @Override - public void setBounds(Rectangle bounds) { - super.setBounds(bounds); - Dimension dimension = getEffectiveDimension(); - int y = Minecraft.getMinecraft().fontRendererObj.FONT_HEIGHT + 4; - scrollablePanel.setBounds(new Rectangle(1,y + 1, dimension.width - 2, dimension.height - y - 2)); - scrollablePanel.evalulateContentArea(); - if (mechanicBrowserTooltip != null) { - Dimension prefSize = mechanicBrowserTooltip.getPreferredSize(); - mechanicBrowserTooltip.setScale(getScale()); - mechanicBrowserTooltip.setBounds(new Rectangle(bounds.x + (bounds.x > Minecraft.getMinecraft().displayWidth/2 ? -prefSize.width: bounds.width), latestTooltipDY + bounds.y, prefSize.width, prefSize.height)); - } - } - - public boolean openGUI() { - return Minecraft.getMinecraft().currentScreen != null - && Minecraft.getMinecraft().currentScreen instanceof GuiChat && lastRoomUID != null; - } - - @Override - public List getChildComponents() { - return openGUI() ? super.getChildComponents() : Collections.emptyList(); - } - - @Override - public boolean mouseClicked0(int absMouseX, int absMouseY, int relMouseX0, int relMouseY0, int mouseButton) { - selectedID = null; - if (mechanicBrowserTooltip != null) { - mechanicBrowserTooltip.close(); - mechanicBrowserTooltip = null; - } - - return super.mouseClicked0(absMouseX, absMouseY, relMouseX0, relMouseY0, mouseButton); - } -} diff --git a/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/features/impl/secret/mechanicbrowser/v2/WidgetCategory.java b/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/features/impl/secret/mechanicbrowser/v2/WidgetCategory.java new file mode 100644 index 00000000..f87a774d --- /dev/null +++ b/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/features/impl/secret/mechanicbrowser/v2/WidgetCategory.java @@ -0,0 +1,61 @@ +/* + * 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.features.impl.secret.mechanicbrowser.v2; + +import kr.syeyoung.dungeonsguide.dungeon.mechanics.dunegonmechanic.DungeonMechanic; +import kr.syeyoung.dungeonsguide.mod.dungeon.roomfinder.DungeonRoom; +import kr.syeyoung.dungeonsguide.mod.guiv2.BindableAttribute; +import kr.syeyoung.dungeonsguide.mod.guiv2.Widget; +import kr.syeyoung.dungeonsguide.mod.guiv2.xml.AnnotatedWidget; +import kr.syeyoung.dungeonsguide.mod.guiv2.xml.annotations.Bind; +import kr.syeyoung.dungeonsguide.mod.guiv2.xml.annotations.On; +import kr.syeyoung.dungeonsguide.mod.guiv2.xml.data.WidgetList; +import net.minecraft.util.ResourceLocation; + +import java.util.ArrayList; +import java.util.List; +import java.util.Map; +import java.util.function.Consumer; + +public class WidgetCategory extends AnnotatedWidget { + @Bind(variableName = "categoryName") + public final BindableAttribute categoryName = new BindableAttribute<>(String.class); + @Bind(variableName = "visible") + public final BindableAttribute visible = new BindableAttribute<>(String.class, "open"); + @Bind(variableName = "children") + public final BindableAttribute children = new BindableAttribute<>(WidgetList.class); + public WidgetCategory(String s, DungeonRoom dungeonRoom, Map dungeonMechanics, Consumer onSelect) { + super(new ResourceLocation("dungeonsguide:gui/features/mechanicBrowser/category.gui")); + categoryName.setValue(s); + + List widgets = new ArrayList<>(); + for (Map.Entry dungeonMechanic : dungeonMechanics.entrySet()) { + widgets.add(new WidgetSecret(dungeonMechanic.getKey(), dungeonRoom, dungeonMechanic.getValue(), onSelect)); + } + children.setValue(widgets); + } + + @On(functionName = "toggle") + public void toggle() { + if (visible.getValue().equals("open")) + visible.setValue("collapsed"); + else + visible.setValue("open"); + } +} diff --git a/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/features/impl/secret/mechanicbrowser/v2/WidgetMechanicBrowser.java b/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/features/impl/secret/mechanicbrowser/v2/WidgetMechanicBrowser.java new file mode 100644 index 00000000..06990fad --- /dev/null +++ b/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/features/impl/secret/mechanicbrowser/v2/WidgetMechanicBrowser.java @@ -0,0 +1,116 @@ +/* + * 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.features.impl.secret.mechanicbrowser.v2; + +import kr.syeyoung.dungeonsguide.dungeon.mechanics.*; +import kr.syeyoung.dungeonsguide.dungeon.mechanics.dunegonmechanic.DungeonMechanic; +import kr.syeyoung.dungeonsguide.mod.dungeon.actions.tree.ActionRoute; +import kr.syeyoung.dungeonsguide.mod.dungeon.roomfinder.DungeonRoom; +import kr.syeyoung.dungeonsguide.mod.dungeon.roomprocessor.GeneralRoomProcessor; +import kr.syeyoung.dungeonsguide.mod.features.FeatureRegistry; +import kr.syeyoung.dungeonsguide.mod.guiv2.BindableAttribute; +import kr.syeyoung.dungeonsguide.mod.guiv2.Widget; +import kr.syeyoung.dungeonsguide.mod.guiv2.elements.Column; +import kr.syeyoung.dungeonsguide.mod.guiv2.xml.AnnotatedWidget; +import kr.syeyoung.dungeonsguide.mod.guiv2.xml.annotations.Bind; +import kr.syeyoung.dungeonsguide.mod.guiv2.xml.annotations.On; +import kr.syeyoung.dungeonsguide.mod.guiv2.xml.data.WidgetList; +import lombok.Getter; +import lombok.Setter; +import net.minecraft.util.ResourceLocation; + +import java.util.*; + +public class WidgetMechanicBrowser extends AnnotatedWidget { + @Bind(variableName = "current") + public final BindableAttribute current = new BindableAttribute<>(String.class); + @Bind(variableName = "children") + public final BindableAttribute children = new BindableAttribute<>(WidgetList.class); + @Bind(variableName = "scale") + public final BindableAttribute scale = new BindableAttribute<>(Double.class); + @Bind(variableName = "color") + public final BindableAttribute color = new BindableAttribute<>(Integer.class); + + + @Setter @Getter + private String selectedId; + + private static final List order = Arrays.asList( + "Fairy Soul", "Secrets", "Crypts", "NPC", "Journals", "Gates", "ETC", "Dummy" + ); + private String map(Class t) { + if (t == DungeonFairySoul.class) return "Fairy Soul"; + if (t == DungeonSecret.class) return "Secrets"; + if (t == DungeonTomb.class) return "Crypts"; + if (t == DungeonNPC.class) return "NPC"; + if (t == DungeonJournal.class) return "Journals"; + if (t == DungeonRoomDoor.class) return "Gates"; + if (t == DungeonDummy.class) return "Dummy"; + return "ETC"; + } + + private DungeonRoom dungeonRoom; + public WidgetMechanicBrowser(DungeonRoom dungeonRoom) { + super(new ResourceLocation("dungeonsguide:gui/features/mechanicBrowser/browser.gui")); + scale.setValue(FeatureRegistry.SECRET_BROWSE.getScale()); + GeneralRoomProcessor grp = (GeneralRoomProcessor) dungeonRoom.getRoomProcessor(); + this.dungeonRoom =dungeonRoom; + if (grp.getPath("MECH-BROWSER") == null) { + current.setValue("Nothing"); + color.setValue(0xFFAA0000); + } else { + ActionRoute route = grp.getPath("MECH-BROWSER"); + current.setValue(route.getMechanic()+" -> "+route.getState()); + color.setValue(0xFFFFFF00); + } + Map> map = new HashMap<>(); + for (Map.Entry stringDungeonMechanicEntry : dungeonRoom.getMechanics().entrySet()) { + String name = map(stringDungeonMechanicEntry.getValue().getClass()); + if (!map.containsKey(name)) + map.put(name, new HashMap<>()); + map.get(name).put(stringDungeonMechanicEntry.getKey(), stringDungeonMechanicEntry.getValue()); + } + + List widgets = new ArrayList<>(); + for (String s : order) { + if (!FeatureRegistry.DEBUG.isEnabled() && s.equals("Dummy")) continue; + if (map.containsKey(s)) + widgets.add(new WidgetCategory(s, dungeonRoom, map.get(s), this::setSelectedId)); + } + children.setValue(widgets); + } + + public void update() { + GeneralRoomProcessor grp = (GeneralRoomProcessor) dungeonRoom.getRoomProcessor(); + if (grp.getPath("MECH-BROWSER") == null) { + current.setValue("Nothing"); + color.setValue(0xFFAA0000); + } else { + ActionRoute route = grp.getPath("MECH-BROWSER"); + current.setValue(route.getMechanic()+" -> "+route.getState()); + color.setValue(0xFFFFFF00); + } + } + + @On(functionName = "cancel") + public void cancel() { + GeneralRoomProcessor grp = (GeneralRoomProcessor) dungeonRoom.getRoomProcessor(); + grp.cancel("MECH-BROWSER"); + } +} diff --git a/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/features/impl/secret/mechanicbrowser/v2/WidgetSecret.java b/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/features/impl/secret/mechanicbrowser/v2/WidgetSecret.java new file mode 100644 index 00000000..e0334b4c --- /dev/null +++ b/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/features/impl/secret/mechanicbrowser/v2/WidgetSecret.java @@ -0,0 +1,87 @@ +/* + * 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.features.impl.secret.mechanicbrowser.v2; + +import kr.syeyoung.dungeonsguide.dungeon.mechanics.dunegonmechanic.DungeonMechanic; +import kr.syeyoung.dungeonsguide.mod.dungeon.roomfinder.DungeonRoom; +import kr.syeyoung.dungeonsguide.mod.guiv2.BindableAttribute; +import kr.syeyoung.dungeonsguide.mod.guiv2.elements.LocationedPopup; +import kr.syeyoung.dungeonsguide.mod.guiv2.elements.PopupMgr; +import kr.syeyoung.dungeonsguide.mod.guiv2.primitive.Rect; +import kr.syeyoung.dungeonsguide.mod.guiv2.xml.AnnotatedWidget; +import kr.syeyoung.dungeonsguide.mod.guiv2.xml.annotations.Bind; +import kr.syeyoung.dungeonsguide.mod.guiv2.xml.annotations.On; +import kr.syeyoung.dungeonsguide.mod.overlay.OverlayManager; +import kr.syeyoung.dungeonsguide.mod.overlay.OverlayType; +import kr.syeyoung.dungeonsguide.mod.overlay.OverlayWidget; +import net.minecraft.client.Minecraft; +import net.minecraft.util.MathHelper; +import net.minecraft.util.ResourceLocation; + +import java.util.function.Consumer; + +public class WidgetSecret extends AnnotatedWidget { + + @Bind(variableName = "secretName") + public final BindableAttribute secretName = new BindableAttribute<>(String.class); + + private String id; + private DungeonRoom room; + private DungeonMechanic mechanic; + private Consumer onSelect; + public WidgetSecret(String name, DungeonRoom room, DungeonMechanic dungeonMechanic, Consumer selectedId) { + super(new ResourceLocation("dungeonsguide:gui/features/mechanicBrowser/secret.gui")); + secretName.setValue(name+" §7("+ dungeonMechanic.getCurrentState(room) +", "+ + (dungeonMechanic.getRepresentingPoint(room) != null ? + String.format("%.1f", MathHelper.sqrt_double(dungeonMechanic.getRepresentingPoint(room).getBlockPos(room).distanceSq(Minecraft.getMinecraft().thePlayer.getPosition()))) : "") + +"m)"); + this.id = name; + this.mechanic = dungeonMechanic; + this.room = room; + this.onSelect = selectedId; + } + + private LocationedPopup popup; + @On(functionName = "toggleStates") + public void openStates() { + Rect abs = getDomElement().getAbsBounds(); + double x = abs.getX() + abs.getWidth(); + double y = abs.getY(); + + if (x + 120 > Minecraft.getMinecraft().displayWidth) + x = abs.getX() - 120; + + + onSelect.accept(id); + + PopupMgr popupMgr = PopupMgr.getPopupMgr(getDomElement()); + popupMgr.openPopup(popup = new LocationedPopup(x, y, new WidgetStateTooltip(room, mechanic, id)), (val) -> { + if (val == null) + onSelect.accept(null); + popup = null; + }); + } + + @Override + public void onUnmount() { + PopupMgr popupMgr = PopupMgr.getPopupMgr(getDomElement()); + if (popup != null) + popupMgr.closePopup(popup, "a"); + } +} diff --git a/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/features/impl/secret/mechanicbrowser/v2/WidgetState.java b/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/features/impl/secret/mechanicbrowser/v2/WidgetState.java new file mode 100644 index 00000000..cf65849c --- /dev/null +++ b/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/features/impl/secret/mechanicbrowser/v2/WidgetState.java @@ -0,0 +1,53 @@ +/* + * 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.features.impl.secret.mechanicbrowser.v2; + +import kr.syeyoung.dungeonsguide.dungeon.mechanics.dunegonmechanic.DungeonMechanic; +import kr.syeyoung.dungeonsguide.mod.dungeon.roomfinder.DungeonRoom; +import kr.syeyoung.dungeonsguide.mod.dungeon.roomprocessor.GeneralRoomProcessor; +import kr.syeyoung.dungeonsguide.mod.features.FeatureRegistry; +import kr.syeyoung.dungeonsguide.mod.guiv2.BindableAttribute; +import kr.syeyoung.dungeonsguide.mod.guiv2.xml.AnnotatedWidget; +import kr.syeyoung.dungeonsguide.mod.guiv2.xml.annotations.Bind; +import kr.syeyoung.dungeonsguide.mod.guiv2.xml.annotations.On; +import net.minecraft.util.ResourceLocation; + +public class WidgetState extends AnnotatedWidget { + + @Bind(variableName = "state") + public final BindableAttribute state = new BindableAttribute<>(String.class); + + private DungeonRoom dungeonRoom; + private String mechanic; + private String s; + + public WidgetState(DungeonRoom dungeonRoom, String mechanic, String s) { + super(new ResourceLocation("dungeonsguide:gui/features/mechanicBrowser/state.gui")); + state.setValue(s); + this.dungeonRoom = dungeonRoom; + this.mechanic = mechanic; + this.s = s; + } + + @On(functionName = "navigate") + public void navigate() { + if (dungeonRoom.getRoomProcessor() instanceof GeneralRoomProcessor) + ((GeneralRoomProcessor)dungeonRoom.getRoomProcessor()).pathfind("MECH-BROWSER", mechanic, s, FeatureRegistry.SECRET_LINE_PROPERTIES_SECRET_BROWSER.getRouteProperties()); + } +} diff --git a/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/features/impl/secret/mechanicbrowser/v2/WidgetStateTooltip.java b/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/features/impl/secret/mechanicbrowser/v2/WidgetStateTooltip.java new file mode 100644 index 00000000..aa0eb05b --- /dev/null +++ b/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/features/impl/secret/mechanicbrowser/v2/WidgetStateTooltip.java @@ -0,0 +1,54 @@ +/* + * 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.features.impl.secret.mechanicbrowser.v2; + +import kr.syeyoung.dungeonsguide.dungeon.mechanics.dunegonmechanic.DungeonMechanic; +import kr.syeyoung.dungeonsguide.mod.dungeon.roomfinder.DungeonRoom; +import kr.syeyoung.dungeonsguide.mod.features.FeatureRegistry; +import kr.syeyoung.dungeonsguide.mod.guiv2.BindableAttribute; +import kr.syeyoung.dungeonsguide.mod.guiv2.Widget; +import kr.syeyoung.dungeonsguide.mod.guiv2.xml.AnnotatedWidget; +import kr.syeyoung.dungeonsguide.mod.guiv2.xml.annotations.Bind; +import kr.syeyoung.dungeonsguide.mod.guiv2.xml.data.WidgetList; +import net.minecraft.util.ResourceLocation; + +import java.util.ArrayList; +import java.util.List; +import java.util.Set; + +public class WidgetStateTooltip extends AnnotatedWidget { + + @Bind(variableName = "children") + public final BindableAttribute children = new BindableAttribute(WidgetList.class); + @Bind(variableName = "scale") + public final BindableAttribute scale = new BindableAttribute<>(Double.class); + private DungeonMechanic mechanic; + public WidgetStateTooltip(DungeonRoom dungeonRoom, DungeonMechanic mechanic, String mechanicId) { + super(new ResourceLocation("dungeonsguide:gui/features/mechanicBrowser/tooltip.gui")); + scale.setValue(FeatureRegistry.SECRET_BROWSE.getScale()); + this.mechanic = mechanic; + + Set state = mechanic.getPossibleStates(dungeonRoom); + List widgetList = new ArrayList<>(); + for (String s : state) { + widgetList.add(new WidgetState(dungeonRoom, mechanicId, s)); + } + children.setValue(widgetList); + } +} diff --git a/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/guiv2/elements/AbsXY.java b/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/guiv2/elements/AbsXY.java index ecfb9883..75db0973 100644 --- a/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/guiv2/elements/AbsXY.java +++ b/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/guiv2/elements/AbsXY.java @@ -32,7 +32,7 @@ import java.util.Collections; import java.util.List; public class AbsXY extends AnnotatedExportOnlyWidget implements Layouter { - @Export(attributeName = "$") + @Export(attributeName = "_") public final BindableAttribute child = new BindableAttribute<>(Widget.class); @Export(attributeName = "x") diff --git a/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/guiv2/elements/Align.java b/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/guiv2/elements/Align.java index 921ad522..34299f85 100644 --- a/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/guiv2/elements/Align.java +++ b/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/guiv2/elements/Align.java @@ -37,7 +37,7 @@ public class Align extends AnnotatedExportOnlyWidget implements Layouter { @Export(attributeName = "vAlign") public final BindableAttribute vAlign = new BindableAttribute<>(Alignment.class, Alignment.CENTER); - @Export(attributeName = "$") + @Export(attributeName = "_") public final BindableAttribute child = new BindableAttribute<>(Widget.class); public static enum Alignment { START, CENTER, END diff --git a/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/guiv2/elements/AspectRatioFitter.java b/mod/s