diff options
Diffstat (limited to 'src/main/java/kr/syeyoung/dungeonsguide/features/impl')
-rw-r--r-- | src/main/java/kr/syeyoung/dungeonsguide/features/impl/secret/FeatureMechanicBrowse.java | 190 |
1 files changed, 161 insertions, 29 deletions
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 index daa3c0e8..95ac96e2 100644 --- a/src/main/java/kr/syeyoung/dungeonsguide/features/impl/secret/FeatureMechanicBrowse.java +++ b/src/main/java/kr/syeyoung/dungeonsguide/features/impl/secret/FeatureMechanicBrowse.java @@ -1,6 +1,9 @@ package kr.syeyoung.dungeonsguide.features.impl.secret; +import com.google.common.collect.Lists; import kr.syeyoung.dungeonsguide.SkyblockStatus; +import kr.syeyoung.dungeonsguide.config.guiconfig.GuiConfig; +import kr.syeyoung.dungeonsguide.config.guiconfig.GuiGuiLocationConfig; import kr.syeyoung.dungeonsguide.dungeon.DungeonContext; import kr.syeyoung.dungeonsguide.dungeon.actions.tree.ActionRoute; import kr.syeyoung.dungeonsguide.dungeon.mechanics.*; @@ -9,6 +12,11 @@ import kr.syeyoung.dungeonsguide.e; import kr.syeyoung.dungeonsguide.features.GuiFeature; import kr.syeyoung.dungeonsguide.features.listener.GuiClickListener; import kr.syeyoung.dungeonsguide.features.listener.GuiPostRenderListener; +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 kr.syeyoung.dungeonsguide.roomprocessor.RoomProcessor; import net.minecraft.client.Minecraft; @@ -17,6 +25,7 @@ import net.minecraft.client.gui.FontRenderer; import net.minecraft.client.gui.Gui; import net.minecraft.client.gui.ScaledResolution; 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; @@ -24,10 +33,12 @@ import org.lwjgl.opengl.GL11; import java.awt.*; import java.util.List; import java.util.ArrayList; +import java.util.Map; +import java.util.Set; -public class FeatureMechanicBrowse extends GuiFeature implements GuiPostRenderListener, GuiClickListener { +public class FeatureMechanicBrowse extends GuiFeature implements GuiPostRenderListener, GuiClickListener, WorldRenderListener { - protected FeatureMechanicBrowse(String category, String name, String description, String key, boolean keepRatio, int width, int height) { + public FeatureMechanicBrowse() { super("secret","Mechanic(Secret) Browser", "Browse and Pathfind secrets and mechanics in the current room", "secret.mechanicbrowse", false, 100, 300); } @@ -59,7 +70,7 @@ public class FeatureMechanicBrowse extends GuiFeature implements GuiPostRenderLi ActionRoute route = grp.getPath(); fr.drawString(route.getMechanic()+" -> "+route.getState(), fr.getStringWidth("Selected: ") + 2,2, 0xFFFFFF00); } - fr.drawString("Press T to browse mechanic", 2, fr.FONT_HEIGHT + 5, 0xFFAAAAAA); + fr.drawString("Open any gui to browse", 2, fr.FONT_HEIGHT + 5, 0xFFAAAAAA); } @Override @@ -71,11 +82,18 @@ public class FeatureMechanicBrowse extends GuiFeature implements GuiPostRenderLi Gui.drawRect(1, 1, feature.width - 1, fr.FONT_HEIGHT + 3, 0xFF262626); fr.drawString("Selected: ", 2,2, 0xFFAAAAAA); fr.drawString("Nothing", fr.getStringWidth("Selected: ") + 2,2, 0xFFAA0000); - fr.drawString("Press T to browse mechanic", 2, fr.FONT_HEIGHT + 5, 0xFFAAAAAA); + fr.drawString("Open any gui to browse", 2, fr.FONT_HEIGHT + 5, 0xFFAAAAAA); } @Override public void onGuiPostRender(GuiScreenEvent.DrawScreenEvent.Post rendered) { + if (Minecraft.getMinecraft().currentScreen instanceof GuiGuiLocationConfig + || Minecraft.getMinecraft().currentScreen instanceof GuiConfig + || Minecraft.getMinecraft().currentScreen instanceof GuiDungeonRoomEdit + || Minecraft.getMinecraft().currentScreen instanceof GuiDungeonAddSet + || Minecraft.getMinecraft().currentScreen instanceof GuiDungeonParameterEdit + || Minecraft.getMinecraft().currentScreen instanceof GuiDungeonValueEdit) return; + if (!skyblockStatus.isOnDungeon()) return; if (skyblockStatus.getContext() == null || !skyblockStatus.getContext().getMapProcessor().isInitialized()) return; DungeonContext context = skyblockStatus.getContext(); @@ -85,6 +103,11 @@ public class FeatureMechanicBrowse extends GuiFeature implements GuiPostRenderLi DungeonRoom dungeonRoom = context.getRoomMapper().get(roomPt); if (dungeonRoom == null) return; if (!(dungeonRoom.getRoomProcessor() instanceof GeneralRoomProcessor)) return; + ScaledResolution scaledResolution = new ScaledResolution(Minecraft.getMinecraft()); + int width = scaledResolution.getScaledWidth(); + int height = scaledResolution.getScaledHeight(); + int mouseX = Mouse.getX() * width / Minecraft.getMinecraft().displayWidth; + int mouseY = height - Mouse.getY() * height / Minecraft.getMinecraft().displayHeight - 1; GeneralRoomProcessor grp = (GeneralRoomProcessor) dungeonRoom.getRoomProcessor(); @@ -101,11 +124,53 @@ public class FeatureMechanicBrowse extends GuiFeature implements GuiPostRenderLi ActionRoute route = grp.getPath(); fr.drawString(route.getMechanic()+" -> "+route.getState(), fr.getStringWidth("Selected: ") + 2,2, 0xFFFFFF00); } - clip(new ScaledResolution(Minecraft.getMinecraft()), 0, fr.FONT_HEIGHT + 4, feature.width, fr.FONT_HEIGHT * 10 + 4); + clip(new ScaledResolution(Minecraft.getMinecraft()), feature.x, feature.y + fr.FONT_HEIGHT + 4, feature.width , fr.FONT_HEIGHT * 10 + 4); + GL11.glEnable(GL11.GL_SCISSOR_TEST); + GlStateManager.translate(0, fr.FONT_HEIGHT + 4, 0); + Gui.drawRect(0, 0, feature.width, fr.FONT_HEIGHT * 9 + 4, 0xFF444444); + Gui.drawRect(1, 1, feature.width - 1, fr.FONT_HEIGHT * 9 + 3, 0xFF262626); + 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); + } + 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() != null ? + String.format("%.1f", MathHelper.sqrt_double(((DungeonMechanic) obj).getRepresentingPoint().getBlockPos(dungeonRoom).distanceSq(Minecraft.getMinecraft().thePlayer.getPosition()))) : "") + +"m)",fr.getStringWidth(name) + 3, i * fr.FONT_HEIGHT, 0xFFAAAAAA); + } else { + Gui.drawRect(-1, i * fr.FONT_HEIGHT, feature.width - 3, i * fr.FONT_HEIGHT + fr.FONT_HEIGHT - 1, 0xFF444444); + fr.drawString((String)obj, 3, i * fr.FONT_HEIGHT, 0xFFEEEEEE); + } + } + GlStateManager.popMatrix();; - Gui.drawRect(0, fr.FONT_HEIGHT + 4, feature.width, fr.FONT_HEIGHT * 10 + 4, 0xFF444444); - Gui.drawRect(1, fr.FONT_HEIGHT + 5, feature.width - 1, fr.FONT_HEIGHT * 10 + 3, 0xFF262626); + clip(new ScaledResolution(Minecraft.getMinecraft()), feature.x + feature.width, feature.y + fr.FONT_HEIGHT + 4, feature.width, fr.FONT_HEIGHT * 10 + 4); + if (selected != -1) { + GlStateManager.translate(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(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(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); + } + fr.drawString(possibleStates.get(i), 0, i * fr.FONT_HEIGHT, 0xFFFFFFFF); + } + } + GL11.glDisable(GL11.GL_SCISSOR_TEST); } private void clip(ScaledResolution resolution, int x, int y, int width, int height) { @@ -116,9 +181,12 @@ public class FeatureMechanicBrowse extends GuiFeature implements GuiPostRenderLi private int dy = 0; private int selected = -1; private int selectedState = -1; + private List<String> possibleStates = new ArrayList<String>(); private List<Object> sortedMechanics = new ArrayList<Object>(); + private 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; @@ -131,44 +199,64 @@ public class FeatureMechanicBrowse extends GuiFeature implements GuiPostRenderLi if (!(dungeonRoom.getRoomProcessor() instanceof GeneralRoomProcessor)) return; boolean found = false; - for (DungeonMechanic value : ((GeneralRoomProcessor) dungeonRoom.getRoomProcessor()).getDungeonRoom().getDungeonRoomInfo().getMechanics().values()) { - if (value instanceof DungeonDoor) { + for (Map.Entry<String, DungeonMechanic> value : ((GeneralRoomProcessor) dungeonRoom.getRoomProcessor()).getDungeonRoom().getDungeonRoomInfo().getMechanics().entrySet()) { + if (value.getValue() instanceof DungeonDoor) { if (!found) { sortedMechanics.add("Fairy Souls"); + sortedMechanicsName.add(""); found = true; } - sortedMechanics.add(value); + sortedMechanics.add(value.getValue()); + sortedMechanicsName.add(value.getKey()); } } found = false; - for (DungeonMechanic value : ((GeneralRoomProcessor) dungeonRoom.getRoomProcessor()).getDungeonRoom().getDungeonRoomInfo().getMechanics().values()) { - if (value instanceof DungeonSecret) { + for (Map.Entry<String, DungeonMechanic> value : ((GeneralRoomProcessor) dungeonRoom.getRoomProcessor()).getDungeonRoom().getDungeonRoomInfo().getMechanics().entrySet()) { + if (value.getValue() instanceof DungeonSecret) { if (!found) { sortedMechanics.add("Secrets"); + sortedMechanicsName.add(""); found = true; } - sortedMechanics.add(value); + sortedMechanics.add(value.getValue()); + sortedMechanicsName.add(value.getKey()); } } found = false; - for (DungeonMechanic value : ((GeneralRoomProcessor) dungeonRoom.getRoomProcessor()).getDungeonRoom().getDungeonRoomInfo().getMechanics().values()) { - if (value instanceof DungeonTomb) { + for (Map.Entry<String, DungeonMechanic> value : ((GeneralRoomProcessor) dungeonRoom.getRoomProcessor()).getDungeonRoom().getDungeonRoomInfo().getMechanics().entrySet()) { + if (value.getValue() instanceof DungeonTomb) { if (!found) { sortedMechanics.add("Crypts"); + sortedMechanicsName.add(""); found = true; } - sortedMechanics.add(value); + sortedMechanics.add(value.getValue()); + sortedMechanicsName.add(value.getKey()); } } found = false; - for (DungeonMechanic value : ((GeneralRoomProcessor) dungeonRoom.getRoomProcessor()).getDungeonRoom().getDungeonRoomInfo().getMechanics().values()) { - if (value instanceof DungeonDoor || value instanceof DungeonBreakableWall || value instanceof DungeonLever - || value instanceof DungeonOnewayDoor || value instanceof DungeonOnewayLever || value instanceof DungeonPressurePlate) { + for (Map.Entry<String, DungeonMechanic> value : ((GeneralRoomProcessor) dungeonRoom.getRoomProcessor()).getDungeonRoom().getDungeonRoomInfo().getMechanics().entrySet()) { + if (value.getValue() instanceof DungeonNPC) { if (!found) { - sortedMechanics.add("Walls & Doors & Levers & Pressure Plates"); + sortedMechanics.add("NPC"); + sortedMechanicsName.add(""); found = true; } - sortedMechanics.add(value); + sortedMechanics.add(value.getValue()); + sortedMechanicsName.add(value.getKey()); + } + } + found = false; + for (Map.Entry<String, DungeonMechanic> value : ((GeneralRoomProcessor) dungeonRoom.getRoomProcessor()).getDungeonRoom().getDungeonRoomInfo().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()); } } } @@ -193,26 +281,70 @@ public class FeatureMechanicBrowse extends GuiFeature implements GuiPostRenderLi Rectangle feature = getFeatureRect(); FontRenderer fr = Minecraft.getMinecraft().fontRendererObj; - Point popupStart = new Point(feature.x + feature.width, (selected - dy) * fr.FONT_HEIGHT + 7 + feature.y); + Point popupStart = new Point(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 ++; - else if (wheel < 0) dy --; + if (wheel > 0) dy += fr.FONT_HEIGHT; + else if (wheel < 0) dy -= fr.FONT_HEIGHT; + if (dy < 0) dy = 0; if (Mouse.getEventButton() != -1) { - int yDiff = mouseY - feature.y - fr.FONT_HEIGHT - 7; - selected = yDiff / fr.FONT_HEIGHT + dy; + 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 { + possibleStates.clear(); + selected = -1; + selectedState = -1; + } } - } else if (sortedMechanics.get(selected) instanceof DungeonMechanic && - new Rectangle(popupStart, new Dimension(feature.width, ((DungeonMechanic) sortedMechanics.get(selected)).getPossibleStates(dungeonRoom).size() * fr.FONT_HEIGHT + 6)).contains(mouseX, mouseY)) { + } 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; - selected = yDiff / fr.FONT_HEIGHT + dy; + 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)); + } + selectedState = preSelectedState; } + } else if (Mouse.getEventButton() != -1){ + possibleStates.clear(); + selectedState = -1; + selected = -1; + } + } + + @Override + public void drawWorld(float partialTicks) { + 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) { + ((DungeonMechanic)sortedMechanics.get(selected)).highlight(new Color(0,255,255,50), sortedMechanicsName.get(selected) +" ("+(((DungeonMechanic) + sortedMechanics.get(selected)).getRepresentingPoint() != null ? + String.format("%.1f", MathHelper.sqrt_double(((DungeonMechanic) sortedMechanics.get(selected)).getRepresentingPoint().getBlockPos(dungeonRoom).distanceSq(Minecraft.getMinecraft().thePlayer.getPosition()))) : "") + +"m)", dungeonRoom, partialTicks); } } } |