diff options
Diffstat (limited to 'src/main/java/kr/syeyoung/dungeonsguide/features')
10 files changed, 699 insertions, 474 deletions
diff --git a/src/main/java/kr/syeyoung/dungeonsguide/features/FeatureRegistry.java b/src/main/java/kr/syeyoung/dungeonsguide/features/FeatureRegistry.java index c5bff650..ee81ee2f 100644 --- a/src/main/java/kr/syeyoung/dungeonsguide/features/FeatureRegistry.java +++ b/src/main/java/kr/syeyoung/dungeonsguide/features/FeatureRegistry.java @@ -32,12 +32,11 @@ import kr.syeyoung.dungeonsguide.features.impl.dungeon.*; import kr.syeyoung.dungeonsguide.features.impl.etc.*; import kr.syeyoung.dungeonsguide.features.impl.etc.ability.FeatureAbilityCooldown; import kr.syeyoung.dungeonsguide.features.impl.party.APIKey; -import kr.syeyoung.dungeonsguide.features.impl.party.FeatureGoodParties; import kr.syeyoung.dungeonsguide.features.impl.party.customgui.FeatureCustomPartyFinder; import kr.syeyoung.dungeonsguide.features.impl.party.playerpreview.FeatureViewPlayerOnJoin; import kr.syeyoung.dungeonsguide.features.impl.secret.FeatureActions; import kr.syeyoung.dungeonsguide.features.impl.secret.FeatureFreezePathfind; -import kr.syeyoung.dungeonsguide.features.impl.secret.FeatureMechanicBrowse; +import kr.syeyoung.dungeonsguide.features.impl.secret.mechanicbrowser.FeatureMechanicBrowse; import kr.syeyoung.dungeonsguide.features.impl.secret.FeatureSoulRoomWarning; import lombok.Getter; diff --git a/src/main/java/kr/syeyoung/dungeonsguide/features/GuiFeature.java b/src/main/java/kr/syeyoung/dungeonsguide/features/GuiFeature.java index 396d244d..52278f6b 100644 --- a/src/main/java/kr/syeyoung/dungeonsguide/features/GuiFeature.java +++ b/src/main/java/kr/syeyoung/dungeonsguide/features/GuiFeature.java @@ -65,7 +65,7 @@ public abstract class GuiFeature extends AbstractFeature implements ScreenRender @Override public void drawScreen(float partialTicks) { if (!isEnabled()) return; - GlStateManager.pushAttrib(); + GlStateManager.pushMatrix(); Rectangle featureRect = this.featureRect.getRectangleNoScale(); ScaledResolution scaledResolution = new ScaledResolution(Minecraft.getMinecraft()); @@ -78,7 +78,7 @@ public abstract class GuiFeature extends AbstractFeature implements ScreenRender GL11.glDisable(GL11.GL_SCISSOR_TEST); GlStateManager.popMatrix(); - GlStateManager.popAttrib(); + GlStateManager.enableBlend(); GlStateManager.color(1,1,1,1); diff --git a/src/main/java/kr/syeyoung/dungeonsguide/features/impl/dungeon/FeatureDungeonMap.java b/src/main/java/kr/syeyoung/dungeonsguide/features/impl/dungeon/FeatureDungeonMap.java index f206c092..e5d41de3 100644 --- a/src/main/java/kr/syeyoung/dungeonsguide/features/impl/dungeon/FeatureDungeonMap.java +++ b/src/main/java/kr/syeyoung/dungeonsguide/features/impl/dungeon/FeatureDungeonMap.java @@ -189,7 +189,7 @@ public class FeatureDungeonMap extends GuiFeature implements DungeonEndListener, if (this.<Boolean>getParameter("showtotalsecrets").getValue()) { for (DungeonRoom dungeonRoom : context.getDungeonRoomList()) { GlStateManager.pushMatrix(); - GlStateManager.pushAttrib(); + Point mapPt = mapProcessor.roomPointToMapPoint(dungeonRoom.getUnitPoints().get(0)); GlStateManager.translate(mapPt.x + mapProcessor.getUnitRoomDimension().width / 2, mapPt.y + mapProcessor.getUnitRoomDimension().height / 2, 0); @@ -218,7 +218,7 @@ public class FeatureDungeonMap extends GuiFeature implements DungeonEndListener, 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(str, -(fr.getStringWidth(str) / 2), -(fr.FONT_HEIGHT / 2), dungeonRoom.getCurrentState() == DungeonRoom.RoomState.FINISHED ? 0xFF00FF00 : (dungeonRoom.getColor() == 74 ? 0xff000000 : 0xFFFFFFFF)); - GlStateManager.popAttrib(); + GlStateManager.popMatrix(); } } diff --git a/src/main/java/kr/syeyoung/dungeonsguide/features/impl/party/playerpreview/FeatureViewPlayerOnJoin.java b/src/main/java/kr/syeyoung/dungeonsguide/features/impl/party/playerpreview/FeatureViewPlayerOnJoin.java index f74834e7..4d523e1e 100644 --- a/src/main/java/kr/syeyoung/dungeonsguide/features/impl/party/playerpreview/FeatureViewPlayerOnJoin.java +++ b/src/main/java/kr/syeyoung/dungeonsguide/features/impl/party/playerpreview/FeatureViewPlayerOnJoin.java @@ -348,7 +348,7 @@ public class FeatureViewPlayerOnJoin extends SimpleFeature implements GuiPostRen int ry = relY - startY; - GlStateManager.pushAttrib(); + GlStateManager.disableRescaleNormal(); RenderHelper.enableGUIStandardItemLighting(); GlStateManager.disableLighting(); @@ -364,7 +364,7 @@ public class FeatureViewPlayerOnJoin extends SimpleFeature implements GuiPostRen Minecraft.getMinecraft().getRenderItem().renderItemAndEffectIntoGUI(playerProfile.get().getInventory()[(i+9) % 36], (i%9) * 18+1,(i/9) * 18+1); } - GlStateManager.popAttrib(); + if (toHover != null) { List<String> list = toHover.getTooltip(Minecraft.getMinecraft().thePlayer, Minecraft.getMinecraft().gameSettings.advancedItemTooltips); for (int i = 0; i < list.size(); ++i) { diff --git a/src/main/java/kr/syeyoung/dungeonsguide/features/impl/secret/FeatureMechanicBrowse.java b/src/main/java/kr/syeyoung/dungeonsguide/features/impl/secret/FeatureMechanicBrowse.java deleted file mode 100644 index 5bd37c62..00000000 --- a/src/main/java/kr/syeyoung/dungeonsguide/features/impl/secret/FeatureMechanicBrowse.java +++ /dev/null @@ -1,466 +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 <https://www.gnu.org/licenses/>. - */ - -package kr.syeyoung.dungeonsguide.features.impl.secret; - -import com.google.common.collect.Lists; -import kr.syeyoung.dungeonsguide.DungeonsGuide; -import kr.syeyoung.dungeonsguide.SkyblockStatus; -import kr.syeyoung.dungeonsguide.config.guiconfig.location.GuiGuiLocationConfig; -import kr.syeyoung.dungeonsguide.config.types.AColor; -import kr.syeyoung.dungeonsguide.dungeon.DungeonContext; -import kr.syeyoung.dungeonsguide.dungeon.actions.tree.ActionRoute; -import kr.syeyoung.dungeonsguide.dungeon.mechanics.*; -import kr.syeyoung.dungeonsguide.dungeon.roomfinder.DungeonRoom; -import kr.syeyoung.dungeonsguide.features.FeatureParameter; -import kr.syeyoung.dungeonsguide.features.GuiFeature; -import kr.syeyoung.dungeonsguide.features.listener.GuiClickListener; -import kr.syeyoung.dungeonsguide.features.listener.GuiPreRenderListener; -import kr.syeyoung.dungeonsguide.features.listener.WorldRenderListener; -import kr.syeyoung.dungeonsguide.roomedit.gui.GuiDungeonAddSet; -import kr.syeyoung.dungeonsguide.roomedit.gui.GuiDungeonParameterEdit; -import kr.syeyoung.dungeonsguide.roomedit.gui.GuiDungeonRoomEdit; -import kr.syeyoung.dungeonsguide.roomedit.gui.GuiDungeonValueEdit; -import kr.syeyoung.dungeonsguide.roomprocessor.GeneralRoomProcessor; -import net.minecraft.client.Minecraft; -import net.minecraft.client.entity.EntityPlayerSP; -import net.minecraft.client.gui.*; -import net.minecraft.client.gui.inventory.GuiContainer; -import net.minecraft.client.renderer.GlStateManager; -import net.minecraft.util.MathHelper; -import net.minecraftforge.client.event.GuiScreenEvent; -import org.lwjgl.input.Mouse; -import org.lwjgl.opengl.GL11; -import org.lwjgl.opengl.GL14; - -import java.awt.*; -import java.util.List; -import java.util.ArrayList; -import java.util.Map; -import java.util.UUID; - -public class FeatureMechanicBrowse extends GuiFeature implements GuiPreRenderListener, GuiClickListener, WorldRenderListener { - public FeatureMechanicBrowse() { - super("Dungeon Secret.Secret Pathfind","Secret Browser", "Browse and Pathfind secrets and mechanics in the current room", "secret.mechanicbrowse", false, 100, 300); - parameters.put("linecolor2", new FeatureParameter<AColor>("linecolor2", "Color", "Color of Pathfind line", new AColor(0xFF00FF00, true), "acolor")); - parameters.put("linethickness", new FeatureParameter<Float>("linethickness", "Thickness", "Thickness of Pathfind line", 1.0f, "float")); - parameters.put("refreshrate", new FeatureParameter<Integer>("refreshrate", "Line Refreshrate", "How many ticks per line refresh?", 10, "integer")); - } - - public AColor getColor() { - return this.<AColor>getParameter("linecolor2").getValue(); - } - public float getThickness() { - return this.<Float>getParameter("linethickness").getValue(); - } - public int getRefreshRate() { - return this.<Integer>getParameter("refreshrate").getValue(); - } - - SkyblockStatus skyblockStatus = DungeonsGuide.getDungeonsGuide().getSkyblockStatus(); - private UUID lastRoomUID = null; - @Override - public void drawHUD(float partialTicks) { - if (Minecraft.getMinecraft().currentScreen != null && !(Minecraft.getMinecraft().currentScreen instanceof GuiGuiLocationConfig - || Minecraft.getMinecraft().currentScreen instanceof GuiDungeonRoomEdit - || Minecraft.getMinecraft().currentScreen instanceof GuiDungeonAddSet - || Minecraft.getMinecraft().currentScreen instanceof GuiDungeonParameterEdit - || Minecraft.getMinecraft().currentScreen instanceof GuiDungeonValueEdit - || Minecraft.getMinecraft().currentScreen instanceof GuiContainer - || Minecraft.getMinecraft().currentScreen instanceof GuiIngameMenu)) return; - if (!skyblockStatus.isOnDungeon()) return; - if (skyblockStatus.getContext() == null || !skyblockStatus.getContext().getMapProcessor().isInitialized()) return; - DungeonContext context = skyblockStatus.getContext(); - - EntityPlayerSP thePlayer = Minecraft.getMinecraft().thePlayer; - Point roomPt = context.getMapProcessor().worldPointToRoomPoint(thePlayer.getPosition()); - DungeonRoom dungeonRoom = context.getRoomMapper().get(roomPt); - if (dungeonRoom == null) return; - if (!dungeonRoom.getDungeonRoomInfo().getUuid().equals(lastRoomUID)) { - selected = -1; - selectedState = -1; - dy = 0; - } - lastRoomUID = dungeonRoom.getDungeonRoomInfo().getUuid(); - - if (!(dungeonRoom.getRoomProcessor() instanceof GeneralRoomProcessor)) return; - - GeneralRoomProcessor grp = (GeneralRoomProcessor) dungeonRoom.getRoomProcessor(); - - Rectangle feature = getFeatureRect().getRectangle(); - FontRenderer fr = getFontRenderer(); - - Gui.drawRect(0, 0, feature.width, fr.FONT_HEIGHT + 4, 0xFF444444); - Gui.drawRect(1, 1, feature.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() == null) - fr.drawString("Nothing", fr.getStringWidth("Selected: ") + 2,2, 0xFFAA0000); - else { - ActionRoute route = grp.getPath(); - fr.drawString(route.getMechanic()+" -> "+route.getState(), fr.getStringWidth("Selected: ") + 2,2, 0xFFFFFF00); - } - fr.drawString("Open any gui to browse", 2, fr.FONT_HEIGHT + 5, 0xFFAAAAAA); - } - - @Override - public void drawDemo(float partialTicks) { - Rectangle feature = getFeatureRect().getRectangle(); - FontRenderer fr = getFontRenderer(); - - Gui.drawRect(0, 0, feature.width, fr.FONT_HEIGHT + 4, 0xFF444444); - Gui.drawRect(1, 1, feature.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); - fr.drawString("Nothing", fr.getStringWidth("Selected: ") + 2,2, 0xFFAA0000); - fr.drawString("Open any gui to browse", 2, fr.FONT_HEIGHT + 5, 0xFFAAAAAA); - } - - @Override - public void onGuiPreRender(GuiScreenEvent.DrawScreenEvent.Pre rendered) { - if (!isEnabled()) return; - if (!(Minecraft.getMinecraft().currentScreen instanceof GuiChat)) return; - - if (!skyblockStatus.isOnDungeon()) return; - if (skyblockStatus.getContext() == null || !skyblockStatus.getContext().getMapProcessor().isInitialized()) return; - DungeonContext context = skyblockStatus.getContext(); - - 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; - int width = Minecraft.getMinecraft().displayWidth; - int height = Minecraft.getMinecraft().displayHeight; - int mouseX = Mouse.getX() ; - int mouseY = height - Mouse.getY() - 1; - GlStateManager.pushMatrix(); - GlStateManager.enableTexture2D(); - GlStateManager.disableLighting(); - GlStateManager.color(1, 1, 1, 1); - - GeneralRoomProcessor grp = (GeneralRoomProcessor) dungeonRoom.getRoomProcessor(); - - Rectangle feature = getFeatureRect().getRectangle(); - FontRenderer fr = getFontRenderer(); - GlStateManager.translate(feature.x, feature.y, 0); - Gui.drawRect(0, 0, feature.width, fr.FONT_HEIGHT + 4, 0xFF444444); - Gui.drawRect(1, 1, feature.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() == null) - fr.drawString("Nothing", fr.getStringWidth("Selected: ") + 2,2, 0xFFAA0000); - else { - ActionRoute route = grp.getPath(); - fr.drawString(route.getMechanic()+" -> "+route.getState(), fr.getStringWidth("Selected: ") + 2,2, 0xFFFFFF00); - } - GlStateManager.translate(0, fr.FONT_HEIGHT + 4, 0); - Gui.drawRect(0, 0, feature.width, feature.height - fr.FONT_HEIGHT - 4, 0xFF444444); - Gui.drawRect(1, 1, feature.width - 1,feature.height - fr.FONT_HEIGHT - 5, 0xFF262626); - clip(new ScaledResolution(Minecraft.getMinecraft()), feature.x, feature.y + fr.FONT_HEIGHT + 5, feature.width , feature.height - fr.FONT_HEIGHT - 6); - GL11.glEnable(GL11.GL_SCISSOR_TEST); - GlStateManager.translate(0, -dy, 0); - - GlStateManager.pushMatrix(); - GlStateManager.translate(2,2, 0); - setupMechanics(); - for (int i = 0; i < sortedMechanics.size(); i++) { - Object obj = sortedMechanics.get(i); - if (selected == i) { - Gui.drawRect(-1, i * fr.FONT_HEIGHT, feature.width - 3, i * fr.FONT_HEIGHT + fr.FONT_HEIGHT - 1, 0xFF444444); - } else if (new Rectangle(feature.x, feature.y + fr.FONT_HEIGHT + 6 - dy + i * fr.FONT_HEIGHT, feature.width, fr.FONT_HEIGHT).contains(mouseX, mouseY)) { - Gui.drawRect(-1, i * fr.FONT_HEIGHT, feature.width - 3, i * fr.FONT_HEIGHT + fr.FONT_HEIGHT - 1, 0xFF555555); - } - 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); - if (obj instanceof DungeonMechanic) { - String name = sortedMechanicsName.get(i); - fr.drawString(name, 3, i * fr.FONT_HEIGHT, 0xFFFFFF00); - fr.drawString(" ("+ ((DungeonMechanic) obj).getCurrentState(dungeonRoom) +", "+ - (((DungeonMechanic) obj).getRepresentingPoint(dungeonRoom) != null ? - String.format("%.1f", MathHelper.sqrt_double(((DungeonMechanic) obj).getRepresentingPoint(dungeonRoom).getBlockPos(dungeonRoom).distanceSq(Minecraft.getMinecraft().thePlayer.getPosition()))) : "") - +"m)",fr.getStringWidth(name) + 3, i * fr.FONT_HEIGHT, 0xFFAAAAAA); - } else if ("$SPECIAL-CANCEL".equals(obj)) { - fr.drawString("Cancel Current", 3, i * fr.FONT_HEIGHT, 0xFF00FFFF); - } else { - Gui.drawRect(-1, i * fr.FONT_HEIGHT, feature.width - 3, i * fr.FONT_HEIGHT + fr.FONT_HEIGHT - 1, 0xFF444444); - 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((String)obj, 3, i * fr.FONT_HEIGHT, 0xFFEEEEEE); - } - } - GlStateManager.popMatrix(); - - if (selected != -1) { - - boolean overFlows = new ScaledResolution(Minecraft.getMinecraft()).getScaledWidth() < feature.x + 2*feature.width; - - clip(new ScaledResolution(Minecraft.getMinecraft()), overFlows ? feature.x - feature.width : feature.x + feature.width, feature.y + fr.FONT_HEIGHT + 5, feature.width , feature.height - fr.FONT_HEIGHT - 6); - GlStateManager.translate(overFlows ? - feature.width : feature.width, selected * fr.FONT_HEIGHT, 0); - Gui.drawRect(0, 0, feature.width, fr.FONT_HEIGHT * possibleStates.size() + 4, 0xFF444444); - Gui.drawRect(-1, 1, feature.width - 1, fr.FONT_HEIGHT * possibleStates.size() + 3, 0xFF262626); - GlStateManager.translate(2,2, 0); - - Point popupStart = new Point(overFlows ? feature.x - feature.width : feature.x + feature.width, (selected + 1) * fr.FONT_HEIGHT +6 + feature.y - dy + 2); - for (int i = 0; i < possibleStates.size(); i++) { - if (new Rectangle(overFlows ? feature.x - feature.width : feature.x + feature.width, popupStart.y + i * fr.FONT_HEIGHT, feature.width, fr.FONT_HEIGHT).contains(mouseX, mouseY)) { - Gui.drawRect(-2, i * fr.FONT_HEIGHT, feature.width - 3, i * fr.FONT_HEIGHT + fr.FONT_HEIGHT - 1, 0xFF555555); - } - 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(possibleStates.get(i), 0, i * fr.FONT_HEIGHT, 0xFFFFFFFF); - } - } - GL11.glDisable(GL11.GL_SCISSOR_TEST); - - GlStateManager.popMatrix(); - GlStateManager.enableTexture2D(); - 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); - } - - private void clip(ScaledResolution resolution, int x, int y, int width, int height) { - int scale = resolution.getScaleFactor(); - GL11.glScissor((x ) * scale, Minecraft.getMinecraft().displayHeight - (y + height) * scale, (width) * scale, height * scale); - } - - private int dy = 0; - private int selected = -1; - private int selectedState = -1; - private List<String> possibleStates = new ArrayList<String>(); - private final List<Object> sortedMechanics = new ArrayList<Object>(); - private final List<String> sortedMechanicsName = new ArrayList<String>(); - private void setupMechanics() { - sortedMechanics.clear(); - sortedMechanicsName.clear(); - - if (!skyblockStatus.isOnDungeon()) return; - if (skyblockStatus.getContext() == null || !skyblockStatus.getContext().getMapProcessor().isInitialized()) return; - DungeonContext context = skyblockStatus.getContext(); - - 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; - - sortedMechanics.add("$SPECIAL-CANCEL"); - sortedMechanicsName.add(""); - - boolean found = false; - for (Map.Entry<String, DungeonMechanic> value : ((GeneralRoomProcessor) dungeonRoom.getRoomProcessor()).getDungeonRoom().getMechanics().entrySet()) { - if (value.getValue() instanceof DungeonFairySoul) { - if (!found) { - sortedMechanics.add("Fairy Souls"); - sortedMechanicsName.add(""); - found = true; - } - sortedMechanics.add(value.getValue()); - sortedMechanicsName.add(value.getKey()); - } - } - found = false; - for (Map.Entry<String, DungeonMechanic> value : ((GeneralRoomProcessor) dungeonRoom.getRoomProcessor()).getDungeonRoom().getMechanics().entrySet()) { - if (value.getValue() instanceof DungeonSecret) { - if (!found) { - sortedMechanics.add("Secrets"); - sortedMechanicsName.add(""); - found = true; - } - sortedMechanics.add(value.getValue()); - sortedMechanicsName.add(value.getKey()); - } - } - found = false; - for (Map.Entry<String, DungeonMechanic> value : ((GeneralRoomProcessor) dungeonRoom.getRoomProcessor()).getDungeonRoom().getMechanics().entrySet()) { - if (value.getValue() instanceof DungeonTomb) { - if (!found) { - sortedMechanics.add("Crypts"); - sortedMechanicsName.add(""); - found = true; - } - sortedMechanics.add(value.getValue()); - sortedMechanicsName.add(value.getKey()); - } - } - found = false; - for (Map.Entry<String, DungeonMechanic> value : ((GeneralRoomProcessor) dungeonRoom.getRoomProcessor()).getDungeonRoom().getMechanics().entrySet()) { - if (value.getValue() instanceof DungeonNPC) { - if (!found) { - sortedMechanics.add("NPC"); - sortedMechanicsName.add(""); - found = true; - } - sortedMechanics.add(value.getValue()); - sortedMechanicsName.add(value.getKey()); - } - } - found = false; - for (Map.Entry<String, DungeonMechanic> value : ((GeneralRoomProcessor) dungeonRoom.getRoomProcessor()).getDungeonRoom().getMechanics().entrySet()) { - if (value.getValue() instanceof DungeonJournal) { - if (!found) { - sortedMechanics.add("Journals"); - sortedMechanicsName.add(""); - found = true; - } - sortedMechanics.add(value.getValue()); - sortedMechanicsName.add(value.getKey()); - } - } - found = false; - for (Map.Entry<String, DungeonMechanic> value : ((GeneralRoomProcessor) dungeonRoom.getRoomProcessor()).getDungeonRoom().getMechanics().entrySet()) { - if (value.getValue() instanceof DungeonRoomDoor){ - if (!found) { - sortedMechanics.add("Gates"); - sortedMechanicsName.add(""); - found = true; - } - sortedMechanics.add(value.getValue()); - sortedMechanicsName.add(value.getKey()); - } - } - found = false; - for (Map.Entry<String, DungeonMechanic> value : ((GeneralRoomProcessor) dungeonRoom.getRoomProcessor()).getDungeonRoom().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) { - sortedMechanics.add("ETC"); - sortedMechanicsName.add(""); - found = true; - } - sortedMechanics.add(value.getValue()); - sortedMechanicsName.add(value.getKey()); - } - } - } - - @Override - public void onMouseInput(GuiScreenEvent.MouseInputEvent.Pre mouseInputEvent) { - if (!isEnabled()) return; - if (!(Minecraft.getMinecraft().currentScreen instanceof GuiChat)) return; - - - if (!skyblockStatus.isOnDungeon()) return; - if (skyblockStatus.getContext() == null || !skyblockStatus.getContext().getMapProcessor().isInitialized()) return; - DungeonContext context = skyblockStatus.getContext(); - - 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; - - int width = Minecraft.getMinecraft().displayWidth; - int height = Minecraft.getMinecraft().displayHeight; - int mouseX = Mouse.getX(); - int mouseY = height - Mouse.getY() - 1; - - Rectangle feature = getFeatureRect().getRectangle(); - FontRenderer fr = Minecraft.getMinecraft().fontRendererObj; - boolean overFlows = new ScaledResolution(Minecraft.getMinecraft()).getScaledWidth() < feature.x + 2*feature.width; - - Point popupStart = new Point(overFlows ? feature.x - feature.width : feature.x + feature.width, (selected + 1) * fr.FONT_HEIGHT +6 + feature.y - dy); - if (feature.contains(mouseX, mouseY)) { - mouseInputEvent.setCanceled(true); - - int wheel = Mouse.getDWheel(); - if (wheel > 0) dy -= fr.FONT_HEIGHT; - else if (wheel < 0) dy += fr.FONT_HEIGHT; - - if (-dy + sortedMechanics.size() * fr.FONT_HEIGHT < feature.height - fr.FONT_HEIGHT - 6) dy = -(feature.height - fr.FONT_HEIGHT - 6) + sortedMechanics.size() * fr.FONT_HEIGHT; - if (dy < 0) dy = 0; - - - if (Mouse.getEventButton() != -1) { - int yDiff = mouseY + dy - feature.y - fr.FONT_HEIGHT - 6; - selected = yDiff / fr.FONT_HEIGHT; - - if (selected < 0) selected = -1; - if (selected >= sortedMechanics.size()) selected = -1; - if (selected == -1) { - possibleStates.clear(); - } else if (sortedMechanics.get(selected) instanceof DungeonMechanic){ - possibleStates = Lists.newArrayList(((DungeonMechanic) sortedMechanics.get(selected)).getPossibleStates(dungeonRoom)); - } else if ("$SPECIAL-CANCEL".equals(sortedMechanics.get(selected))) { - ((GeneralRoomProcessor) dungeonRoom.getRoomProcessor()).cancel(); - possibleStates.clear(); - selected = -1; - selectedState = -1; - } else { - possibleStates.clear(); - selected = -1; - selectedState = -1; - } - } - } else if (selected != -1 && sortedMechanics.get(selected) instanceof DungeonMechanic && - new Rectangle(popupStart, new Dimension(feature.width, ((DungeonMechanic) sortedMechanics.get(selected)).getPossibleStates(dungeonRoom).size() * fr.FONT_HEIGHT)).contains(mouseX, mouseY)) { - mouseInputEvent.setCanceled(true); - if (Mouse.getEventButton() != -1) { - int yDiff = mouseY - popupStart.y - 2; - int preSelectedState = yDiff / fr.FONT_HEIGHT ; - if (preSelectedState < 0) preSelectedState = -1; - if (preSelectedState >= possibleStates.size()) preSelectedState = - possibleStates.size() - 1; - - if (preSelectedState == selectedState && preSelectedState != -1) { - ((GeneralRoomProcessor) dungeonRoom.getRoomProcessor()).pathfind(sortedMechanicsName.get(selected), - possibleStates.get(selectedState)); - selected = -1; - selectedState = -1; - possibleStates.clear(); - } - selectedState = preSelectedState; - } - } else if (Mouse.getEventButton() != -1){ - possibleStates.clear(); - selectedState = -1; - selected = -1; - } - } - - @Override - public void drawWorld(float partialTicks) { - if (!isEnabled()) return; - if (!skyblockStatus.isOnDungeon()) return; - if (skyblockStatus.getContext() == null || !skyblockStatus.getContext().getMapProcessor().isInitialized()) return; - DungeonContext context = skyblockStatus.getContext(); - - 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; - if (selected != -1) { - if (sortedMechanics.size() <= selected) return; - ((DungeonMechanic)sortedMechanics.get(selected)).highlight(new Color(0,255,255,50), sortedMechanicsName.get(selected) +" ("+(((DungeonMechanic) - sortedMechanics.get(selected)).getRepresentingPoint(dungeonRoom) != null ? - String.format("%.1f", MathHelper.sqrt_double(((DungeonMechanic) sortedMechanics.get(selected)).getRepresentingPoint(dungeonRoom).getBlockPos(dungeonRoom).distanceSq(Minecraft.getMinecraft().thePlayer.getPosition()))) : "") - +"m)", dungeonRoom, partialTicks); - } - } -} diff --git a/src/main/java/kr/syeyoung/dungeonsguide/features/impl/secret/mechanicbrowser/FeatureMechanicBrowse.java b/src/main/java/kr/syeyoung/dungeonsguide/features/impl/secret/mechanicbrowser/FeatureMechanicBrowse.java new file mode 100644 index 00000000..1eaaa15f --- /dev/null +++ b/src/main/java/kr/syeyoung/dungeonsguide/features/impl/secret/mechanicbrowser/FeatureMechanicBrowse.java @@ -0,0 +1,188 @@ +/* + * 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.features.impl.secret.mechanicbrowser; + +import com.google.common.collect.Lists; +import kr.syeyoung.dungeonsguide.DungeonsGuide; +import kr.syeyoung.dungeonsguide.SkyblockStatus; +import kr.syeyoung.dungeonsguide.config.guiconfig.location.GuiGuiLocationConfig; +import kr.syeyoung.dungeonsguide.config.types.AColor; +import kr.syeyoung.dungeonsguide.config.types.GUIRectangle; +import kr.syeyoung.dungeonsguide.dungeon.DungeonContext; +import kr.syeyoung.dungeonsguide.dungeon.actions.tree.ActionRoute; +import kr.syeyoung.dungeonsguide.dungeon.mechanics.*; +import kr.syeyoung.dungeonsguide.dungeon.roomfinder.DungeonRoom; +import kr.syeyoung.dungeonsguide.features.FeatureParameter; +import kr.syeyoung.dungeonsguide.features.GuiFeature; +import kr.syeyoung.dungeonsguide.features.impl.secret.mechanicbrowser.MGuiMechanicBrowser; +import kr.syeyoung.dungeonsguide.features.listener.GuiClickListener; +import kr.syeyoung.dungeonsguide.features.listener.GuiPreRenderListener; +import kr.syeyoung.dungeonsguide.features.listener.WorldRenderListener; +import kr.syeyoung.dungeonsguide.features.text.StyledTextRenderer; +import kr.syeyoung.dungeonsguide.features.text.TextHUDFeature; +import kr.syeyoung.dungeonsguide.gui.MPanel; +import kr.syeyoung.dungeonsguide.gui.elements.MFloatSelectionButton; +import kr.syeyoung.dungeonsguide.gui.elements.MPassiveLabelAndElement; +import kr.syeyoung.dungeonsguide.gui.elements.MStringSelectionButton; +import kr.syeyoung.dungeonsguide.roomedit.gui.GuiDungeonAddSet; +import kr.syeyoung.dungeonsguide.roomedit.gui.GuiDungeonParameterEdit; +import kr.syeyoung.dungeonsguide.roomedit.gui.GuiDungeonRoomEdit; +import kr.syeyoung.dungeonsguide.roomedit.gui.GuiDungeonValueEdit; +import kr.syeyoung.dungeonsguide.roomprocessor.GeneralRoomProcessor; +import kr.syeyoung.dungeonsguide.utils.GlStateUtils; +import net.minecraft.client.Minecraft; +import net.minecraft.client.entity.EntityPlayerSP; +import net.minecraft.client.gui.*; +import net.minecraft.client.gui.inventory.GuiContainer; +import net.minecraft.client.renderer.GlStateManager; +import net.minecraft.client.renderer.OpenGlHelper; +import net.minecraft.util.MathHelper; +import net.minecraftforge.client.event.GuiScreenEvent; +import org.lwjgl.input.Mouse; +import org.lwjgl.opengl.GL11; +import org.lwjgl.opengl.GL14; + +import java.awt.*; +import java.io.IOException; +import java.util.*; +import java.util.List; + +public class FeatureMechanicBrowse extends GuiFeature implements GuiPreRenderListener, GuiClickListener, WorldRenderListener { + public FeatureMechanicBrowse() { + super("Dungeon Secret.Secret Pathfind","Secret Browser", "Browse and Pathfind secrets and mechanics in the current room", "secret.mechanicbrowse", false, 100, 300); + parameters.put("linecolor2", new FeatureParameter<AColor>("linecolor2", "Color", "Color of Pathfind line", new AColor(0xFF00FF00, true), "acolor")); + parameters.put("linethickness", new FeatureParameter<Float>("linethickness", "Thickness", "Thickness of Pathfind line", 1.0f, "float")); + parameters.put("refreshrate", new FeatureParameter<Integer>("refreshrate", "Line Refreshrate", "How many ticks per line refresh?", 10, "integer")); + parameters.put("scale", new FeatureParameter<Float>("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 AColor getColor() { + return this.<AColor>getParameter("linecolor2").getValue(); + } + public float getThickness() { + return this.<Float>getParameter("linethickness").getValue(); + } + public int getRefreshRate() { + return this.<Integer>getParameter("refreshrate").getValue(); + } + public double getScale() { + return this.<Float>getParameter("scale").getValue(); + } + + private MGuiMechanicBrowser mGuiMechanicBrowser; + + + @Override + public void drawDemo(float partialTicks) { + super.drawDemo(partialTicks); + double scale = FeatureMechanicBrowse.this.<Float>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); + fr.drawString("Nothing", fr.getStringWidth("Selected: ") + 2,2, 0xFFAA0000); + fr.drawString("Open Chat to Select Secrets", 2, fr.FONT_HEIGHT + 5, 0xFFAAAAAA); + } + + private int lastWidth, lastHeight; + + @Override + public void drawScreen(float partialTicks) { + if (!isEnabled()) return; + 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); + } + + @Override + public void setFeatureRect(GUIRectangle featureRect) { + super.setFeatureRect(featureRect); + mGuiMechanicBrowser.initGui(); + } + + @Override + public void drawHUD(float partialTicks) { } + + @Override + public void onMouseInput(GuiScreenEvent.MouseInputEvent.Pre mouseInputEvent) { + try { + mGuiMechanicBrowser.handleMouseInput(); + } catch (IOException e) { + e.printStackTrace(); + } + } + + + @Override + public void onGuiPreRender(GuiScreenEvent.DrawScreenEvent.Pre rendered) { + int i = Mouse.getEventX(); + int j = Minecraft.getMinecraft().displayHeight - Mouse.getEventY(); + mGuiMechanicBrowser.drawScreen(i, j, rendered.renderPartialTicks); + } + + @Override + public void drawWorld(float partialTicks) { + if (!isEnabled()) return; + SkyblockStatus skyblockStatus = DungeonsGuide.getDungeonsGuide().getSkyblockStatus(); + if (!skyblockStatus.isOnDungeon()) return; + if (skyblockStatus.getContext() == null || !skyblockStatus.getContext().getMapProcessor().isInitialized()) return; + DungeonContext context = skyblockStatus.getContext(); + + 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; + String id = mGuiMechanicBrowser.getPanelMechanicBrowser().getSelectedID(); + if (id != null) { + Optional.ofNullable(dungeonRoom.getMechanics().get(mGuiMechanicBrowser.getPanelMechanicBrowser().getSelectedID())) + .ifPresent(a -> { + a.highlight(new Color(0,255,255,50), id +" ("+( + dungeonRoom.getMechanics().get(id).getRepresentingPoint(dungeonRoom) != null ? + String.format("%.1f", MathHelper.sqrt_double((dungeonRoom.getMechanics().get(id)).getRepresentingPoint(dungeonRoom).getBlockPos(dungeonRoom).distanceSq(Minecraft.getMinecraft().thePlayer.getPosition()))) : "") + +"m)", dungeonRoom, partialTicks); + }); + } + } + @Override + public List<MPanel> getTooltipForEditor(GuiGuiLocationConfig guiGuiLocationConfig) { + List<MPanel> mPanels = super.getTooltipForEditor(guiGuiLocationConfig); + + mPanels.add(new MPassiveLabelAndElement("Scale", new MFloatSelectionButton(FeatureMechanicBrowse.this.<Float>getParameter("scale").getValue()) {{ + setOnUpdate(() ->{ + FeatureMechanicBrowse.this.<Float>getParameter("scale").setValue(this.getData()); + }); } + })); + + return mPanels; + } +} diff --git a/src/main/java/kr/syeyoung/dungeonsguide/features/impl/secret/mechanicbrowser/MGuiMechanicBrowser.java b/src/main/java/kr/syeyoung/dungeonsguide/features/impl/secret/mechanicbrowser/MGuiMechanicBrowser.java new file mode 100644 index 00000000..6ef99866 --- /dev/null +++ b/src/main/java/kr/syeyoung/dungeonsguide/features/impl/secret/mechanicbrowser/MGuiMechanicBrowser.java @@ -0,0 +1,45 @@ +/* + * Dungeons Guide - The most intelligent Hypixel Skyblock Dungeons Mod + * Copyright (C) 2021 cyoung06 + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published + * by the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see <https://www.gnu.org/licenses/>. + */ + +package kr.syeyoung.dungeonsguide.features.impl.secret.mechanicbrowser; + +import kr.syeyoung.dungeonsguide.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(); + } + + @Override + public void drawScreen(int mouseX, int mouseY, float partialTicks) { + panelMechanicBrowser.setBounds(featureMechanicBrowse.getFeatureRect().getRectangle()); + panelMechanicBrowser.setScale(featureMechanicBrowse.getScale()); + super.drawScreen(mouseX, mouseY, partialTicks); + } +} diff --git a/src/main/java/kr/syeyoung/dungeonsguide/features/impl/secret/mechanicbrowser/MechanicBrowserElement.java b/src/main/java/kr/syeyoung/dungeonsguide/features/impl/secret/mechanicbrowser/MechanicBrowserElement.java new file mode 100644 index 00000000..ca803bff --- /dev/null +++ b/src/main/java/kr/syeyoung/dungeonsguide/features/impl/secret/mechanicbrowser/MechanicBrowserElement.java @@ -0,0 +1,65 @@ +/* + * 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.features.impl.secret.mechanicbrowser; + +import kr.syeyoung.dungeonsguide.gui.MPanel; +import kr.syeyoung.dungeonsguide.utils.GlStateUtils; +import kr.syeyoung.dungeonsguide.utils.cursor.EnumCursor; +import lombok.AllArgsConstructor; +import net.minecraft.client.Minecraft; +import net.minecraft.client.gui.Gui; +import net.minecraft.client.renderer.GlStateManager; +import org.lwjgl.opengl.GL11; + +import java.awt.*; +import java.util.function.BiConsumer; +import java.util.function.Consumer; +import java.util.function.Supplier; + +@AllArgsConstructor +public class MechanicBrowserElement extends MPanel { + private Supplier<String> name; + private boolean isCategory = false; + private BiConsumer<MechanicBrowserElement, Point> 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/src/main/java/kr/syeyoung/dungeonsguide/features/impl/secret/mechanicbrowser/MechanicBrowserTooltip.java b/src/main/java/kr/syeyoung/dungeonsguide/features/impl/secret/mechanicbrowser/MechanicBrowserTooltip.java new file mode 100644 index 00000000..e2a0d028 --- /dev/null +++ b/src/main/java/kr/syeyoung/dungeonsguide/features/impl/secret/mechanicbrowser/MechanicBrowserTooltip.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.features.impl.secret.mechanicbrowser; + +import kr.syeyoung.dungeonsguide.gui.elements.MList; +import kr.syeyoung.dungeonsguide.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/src/main/java/kr/syeyoung/dungeonsguide/features/impl/secret/mechanicbrowser/PanelMechanicBrowser.java b/src/main/java/kr/syeyoung/dungeonsguide/features/impl/secret/mechanicbrowser/PanelMechanicBrowser.java new file mode 100644 index 00000000..866d5773 --- /dev/null +++ b/src/main/java/kr/syeyoung/dungeonsguide/features/impl/secret/mechanicbrowser/PanelMechanicBrowser.java @@ -0,0 +1,326 @@ +/* + * 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.features.impl.secret.mechanicbrowser; + +import kr.syeyoung.dungeonsguide.DungeonsGuide; +import kr.syeyoung.dungeonsguide.dungeon.DungeonContext; +import kr.syeyoung.dungeonsguide.dungeon.actions.tree.ActionRoute; +import kr.syeyoung.dungeonsguide.dungeon.mechanics.*; +import kr.syeyoung.dungeonsguide.dungeon.roomfinder.DungeonRoom; +import kr.syeyoung.dungeonsguide.gui.MPanel; +import kr.syeyoung.dungeonsguide.gui.elements.MList; +import kr.syeyoung.dungeonsguide.gui.elements.MPanelScaledGUI; +import kr.syeyoung.dungeonsguide.gui.elements.MScrollablePanel; +import kr.syeyoung.dungeonsguide.roomprocessor.GeneralRoomProcessor; +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.*; +import java.util.List; + +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()); + + Optional<DungeonRoom> dungeonRoomOpt = Optional.ofNullable(DungeonsGuide.getDungeonsGuide().getSkyblockStatus().getContext()) + .map(DungeonContext::getMapProcessor).map(a->a.worldPointToRoomPoint(Minecraft.getMinecraft().thePlayer.getPosition())) + .map(a -> DungeonsGuide.getDungeonsGuide().getSkyblockStatus().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() == null) + fr.drawString("Nothing", fr.getStringWidth("Selected: ") + 2,2, 0xFFAA0000); + else { + ActionRoute route = grp.getPath(); + 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<String, DungeonMechanic> 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<String, DungeonMechanic> 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<String, DungeonMechanic> 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<String, DungeonMechanic> 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<String, DungeonMechanic> 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<String, DungeonMechanic> 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<String, DungeonMechanic> 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<DungeonRoom> dungeonRoomOpt = Optional.ofNullable(DungeonsGuide.getDungeonsGuide().getSkyblockStatus().getContext()) + .map(DungeonContext::getMapProcessor).map(a->a.worldPointToRoomPoint(Minecraft.getMinecraft().thePlayer.getPosition())) + .map(a -> DungeonsGuide.getDungeonsGuide().getSkyblockStatus().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<String> states = dungeonMechanic1.getPossibleStates(dungeonRoom); + System.out.println(states); + + + 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(id, state); + mechanicBrowserTooltip.close(); + mechanicBrowserTooltip = null; + })); + } + mechanicBrowserTooltip.setScale(getScale()); + Dimension prefSize = mechanicBrowserTooltip.getPreferredSize(); + mechanicBrowserTooltip.setBounds(new Rectangle(bounds.x + bounds.width, latestTooltipDY + bounds.y, prefSize.width, prefSize.height)); + mechanicBrowserTooltip.open(this); + } + + public void cancel(MechanicBrowserElement mechanicBrowserElement) { + Optional<DungeonRoom> dungeonRoomOpt = Optional.ofNullable(DungeonsGuide.getDungeonsGuide().getSkyblockStatus().getContext()) + .map(DungeonContext::getMapProcessor).map(a->a.worldPointToRoomPoint(Minecraft.getMinecraft().thePlayer.getPosition())) + .map(a -> DungeonsGuide.getDungeonsGuide().getSkyblockStatus().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(); + } + + 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.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<MPanel> 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); + } +} |