From b8f4f4d07766a22970f97584a957ce0b6f68f905 Mon Sep 17 00:00:00 2001 From: Kam Date: Mon, 4 Mar 2024 23:14:41 -0500 Subject: [PATCH] Remember last opened CNPC+ Tab, better scrolling for quest tabs, party details button --- .../noppes/npcs/client/ClientTickHandler.java | 20 ++++- .../gui/player/inventory/GuiFaction.java | 1 - .../client/gui/player/inventory/GuiParty.java | 1 - .../gui/player/inventory/GuiQuestLog.java | 84 +++++++++++++++---- 4 files changed, 83 insertions(+), 23 deletions(-) diff --git a/src/main/java/noppes/npcs/client/ClientTickHandler.java b/src/main/java/noppes/npcs/client/ClientTickHandler.java index 12614415a..bfbb559b3 100644 --- a/src/main/java/noppes/npcs/client/ClientTickHandler.java +++ b/src/main/java/noppes/npcs/client/ClientTickHandler.java @@ -12,6 +12,9 @@ import noppes.npcs.CustomNpcs; import noppes.npcs.NoppesUtilPlayer; import noppes.npcs.client.controllers.MusicController; import noppes.npcs.client.controllers.ScriptSoundController; +import noppes.npcs.client.gui.player.inventory.GuiCNPCInventory; +import noppes.npcs.client.gui.player.inventory.GuiFaction; +import noppes.npcs.client.gui.player.inventory.GuiParty; import noppes.npcs.client.gui.player.inventory.GuiQuestLog; import noppes.npcs.client.renderer.RenderNPCInterface; import noppes.npcs.constants.EnumPlayerPacket; @@ -28,7 +31,7 @@ public class ClientTickHandler{ private int buttonPressed = -1; private long buttonTime = 0L; private final int[] ignoreKeys = new int[]{157, 29, 54, 42, 184, 56, 220, 219}; - + @SubscribeEvent(priority = EventPriority.LOWEST) public void onClientTick(TickEvent.ClientTickEvent event){ Minecraft mc = Minecraft.getMinecraft(); @@ -91,8 +94,19 @@ public class ClientTickHandler{ public void onKey(InputEvent.KeyInputEvent event){ if(ClientProxy.QuestLog.isPressed()){ Minecraft mc = Minecraft.getMinecraft(); - if(mc.currentScreen == null) - NoppesUtil.openGUI(mc.thePlayer, new GuiQuestLog(mc.thePlayer)); + if(mc.currentScreen == null){ + switch (GuiCNPCInventory.activeTab){ + case 0: + NoppesUtil.openGUI(mc.thePlayer, new GuiQuestLog(mc.thePlayer)); + break; + case 1: + NoppesUtil.openGUI(mc.thePlayer, new GuiParty(mc.thePlayer)); + break; + case 2: + NoppesUtil.openGUI(mc.thePlayer, new GuiFaction()); + break; + } + } else if(mc.currentScreen instanceof GuiQuestLog) mc.setIngameFocus(); } diff --git a/src/main/java/noppes/npcs/client/gui/player/inventory/GuiFaction.java b/src/main/java/noppes/npcs/client/gui/player/inventory/GuiFaction.java index 7c84a4747..1b668fa1b 100644 --- a/src/main/java/noppes/npcs/client/gui/player/inventory/GuiFaction.java +++ b/src/main/java/noppes/npcs/client/gui/player/inventory/GuiFaction.java @@ -38,7 +38,6 @@ public class GuiFaction extends GuiCNPCInventory implements IGuiData{ ySize = 180; this.drawDefaultBackground = false; title = ""; - activeTab = 2; NoppesUtilPlayer.sendData(EnumPlayerPacket.FactionsGet); } diff --git a/src/main/java/noppes/npcs/client/gui/player/inventory/GuiParty.java b/src/main/java/noppes/npcs/client/gui/player/inventory/GuiParty.java index 6b7816d4a..13822a997 100644 --- a/src/main/java/noppes/npcs/client/gui/player/inventory/GuiParty.java +++ b/src/main/java/noppes/npcs/client/gui/player/inventory/GuiParty.java @@ -49,7 +49,6 @@ public class GuiParty extends GuiCNPCInventory implements ITextfieldListener, IT xSize = 280; ySize = 180; drawDefaultBackground = false; - activeTab = 1; Client.sendData(EnumPacketServer.GetPartyData); } diff --git a/src/main/java/noppes/npcs/client/gui/player/inventory/GuiQuestLog.java b/src/main/java/noppes/npcs/client/gui/player/inventory/GuiQuestLog.java index d4748513c..e5fc9a9ba 100644 --- a/src/main/java/noppes/npcs/client/gui/player/inventory/GuiQuestLog.java +++ b/src/main/java/noppes/npcs/client/gui/player/inventory/GuiQuestLog.java @@ -33,7 +33,8 @@ public class GuiQuestLog extends GuiCNPCInventory implements ITopButtonListener, private HashMap otherButtons = new HashMap(); private QuestLogData data = new QuestLogData(); private boolean noQuests = false; - private boolean questDetails = true; + private byte questPages = 1; + private static long lastClicked = System.currentTimeMillis(); private HashMap questAlertsOnOpen; private String trackedQuestKeyOnOpen; @@ -50,7 +51,6 @@ public class GuiQuestLog extends GuiCNPCInventory implements ITopButtonListener, ySize = 180; NoppesUtilPlayer.sendData(EnumPlayerPacket.QuestLog); drawDefaultBackground = false; - activeTab = 0; } public void initGui(){ super.initGui(); @@ -68,12 +68,14 @@ public class GuiQuestLog extends GuiCNPCInventory implements ITopButtonListener, List categories = new ArrayList(); categories.addAll(data.categories.keySet()); Collections.sort(categories,String.CASE_INSENSITIVE_ORDER); + + addButton(new GuiNpcButton(100,guiLeft - 68, this.guiTop, 68,12, "UP")); + int i = 0; for(String category : categories){ if(data.selectedCategory.isEmpty()) data.selectedCategory = category; sideButtons.put(i, new GuiMenuSideButton(i,guiLeft - 69, this.guiTop +2 + i*21, 70,22, category)); - otherButtons.put(i, new GuiNpcButton(i,guiLeft - 69, this.guiTop +2 + i*21, 70,22, category)); i++; } sideButtons.get(categories.indexOf(data.selectedCategory)).active = true; @@ -87,10 +89,19 @@ public class GuiQuestLog extends GuiCNPCInventory implements ITopButtonListener, scroll.guiTop = guiTop + 15; addScroll(scroll); + // Text Forward-- addButton(new GuiButtonNextPage(1, guiLeft + 286, guiTop + 176, true)); + + // Objectives Back-- addButton(new GuiButtonNextPage(2, guiLeft + 144, guiTop + 176, false)); if (data.partyQuests.containsKey(data.selectedCategory + ":" + data.selectedQuest)) { + // Objectives Forward-- + addButton(new GuiButtonNextPage(11, guiLeft + 286, guiTop + 176, true)); + + // Party Back-- + addButton(new GuiButtonNextPage(10, guiLeft + 144, guiTop + 176, false)); + String questName = ClientCacheHandler.party != null ? ClientCacheHandler.party.getCurrentQuestName() : null; GuiNpcButton partyButton = new GuiNpcButton(3, guiLeft + 150, guiTop + 151, 50, 20, new String[]{"party.party", "party.partying"}, Objects.equals(questName, data.selectedQuest) ? 1 : 0); addButton(partyButton); @@ -100,6 +111,9 @@ public class GuiQuestLog extends GuiCNPCInventory implements ITopButtonListener, if (partyButton.enabled && Objects.equals(questName, data.selectedQuest)) { partyButton.packedFGColour = 0x32CD32; } + + getButton(11).visible = questPages == 0 && data.hasSelectedQuest(); + getButton(10).visible = questPages == 1 && data.hasSelectedQuest(); } GuiNpcButton trackingButton = new GuiNpcButton(4, guiLeft + 260, guiTop + 151, 50, 20, new String[]{"quest.track", "quest.tracking"}, data.trackedQuestKey.equals(data.selectedCategory + ":" + data.selectedQuest) ? 1 : 0); @@ -111,8 +125,8 @@ public class GuiQuestLog extends GuiCNPCInventory implements ITopButtonListener, GuiNpcButton alertButton = new GuiNpcButton(5, guiLeft + 205, guiTop + 151, 50, 20, new String[]{"quest.alerts", "quest.noAlerts"}, data.getQuestAlerts() ? 0 : 1); addButton(alertButton); - getButton(1).visible = questDetails && data.hasSelectedQuest(); - getButton(2).visible = !questDetails && data.hasSelectedQuest(); + getButton(1).visible = questPages == 1 && data.hasSelectedQuest(); + getButton(2).visible = questPages == 2 && data.hasSelectedQuest(); getButton(4).visible = !data.selectedQuest.isEmpty() && getButton(1).visible; getButton(5).visible = getButton(4).visible; if (getButton(3) != null) { @@ -137,12 +151,25 @@ public class GuiQuestLog extends GuiCNPCInventory implements ITopButtonListener, @Override protected void actionPerformed(GuiButton guibutton){ - if(guibutton.id == 1){ - questDetails = false; + if(lastClicked > System.currentTimeMillis() - 10){ + return; + } + + if(guibutton.id == 11){ + questPages = 1; + lastClicked = System.currentTimeMillis(); + } + else if(guibutton.id == 10){ + questPages = 0; + } + else if(guibutton.id == 1){ + questPages = 2; } - if(guibutton.id == 2){ - questDetails = true; + else if(guibutton.id == 2){ + questPages = 1; + lastClicked = System.currentTimeMillis(); } + if (guibutton.id == 3) { if (Objects.equals(ClientCacheHandler.party.getCurrentQuestName(), data.selectedQuest)) { @@ -192,32 +219,51 @@ public class GuiQuestLog extends GuiCNPCInventory implements ITopButtonListener, return; } - int maxScroll = Math.max(0, this.sideButtons.size() - 10) * 22; - this.destSideButtonScroll = ValueUtil.clamp(this.destSideButtonScroll - Math.signum(this.mouseWheel) * 22, -maxScroll, 0); - this.sideButtonScroll = this.sideButtonScroll * (1.0F - 0.2F) + (this.destSideButtonScroll * 0.2F); + // Define constants for smoothing the scroll + final float SMOOTHING_FACTOR = 0.1F; // Adjust this value for smoother or faster scrolling - for(Map.Entry entry : this.sideButtons.entrySet()){ + int maxScroll = Math.max(0, this.sideButtons.size() - 9) * 22; + this.destSideButtonScroll = ValueUtil.clamp(this.destSideButtonScroll - Math.signum(this.mouseWheel) * 22, -maxScroll, 0); + + // Apply smoothing to the scroll transition + this.sideButtonScroll += (this.destSideButtonScroll - this.sideButtonScroll) * SMOOTHING_FACTOR; + + // Loop through the side buttons and render them + for (Map.Entry entry : this.sideButtons.entrySet()) { int buttonNumber = entry.getKey(); GuiMenuSideButton button = entry.getValue(); - button.yPosition = (int) (this.guiTop +2 + buttonNumber*21 + this.sideButtonScroll); - if (button.yPosition >= this.guiTop && button.yPosition < this.guiTop + 22 * 8) { + float rawYPosition = (this.guiTop + 2 + buttonNumber * 21 + this.sideButtonScroll); + int smoothedYPosition = Math.round(rawYPosition); + + // Render the button if it's within the visible area + if (smoothedYPosition >= this.guiTop && smoothedYPosition < this.guiTop + 22 * 8) { + button.yPosition = smoothedYPosition; button.drawButton(mc, i, j); } } - fontRendererObj.drawString(data.selectedCategory,guiLeft + 5,guiTop + 5, CustomNpcResourceListener.DefaultTextColor); + + fontRendererObj.drawString(data.selectedCategory,guiLeft + 5,guiTop + 5, CustomNpcResourceListener.DefaultTextColor); if(!data.hasSelectedQuest()) return; - if (questDetails) { + if (questPages == 1) { drawProgress(); String title = StatCollector.translateToLocal("gui.text"); fontRendererObj.drawString(title, guiLeft + 284 - fontRendererObj.getStringWidth(title), guiTop + 179, CustomNpcResourceListener.DefaultTextColor); + + if(data.partyQuests.containsKey(data.selectedCategory + ":" + data.selectedQuest)){ + title = StatCollector.translateToLocal("party.party"); + fontRendererObj.drawString(title, guiLeft + 170, guiTop + 179, CustomNpcResourceListener.DefaultTextColor); + } + } else if (questPages == 0) { + String title = StatCollector.translateToLocal("quest.objectives"); + fontRendererObj.drawString(title, guiLeft + 284 - fontRendererObj.getStringWidth(title), guiTop + 179, CustomNpcResourceListener.DefaultTextColor); } else { drawQuestText(); String title = StatCollector.translateToLocal("quest.objectives"); - fontRendererObj.drawString(title, guiLeft + 168, guiTop + 179, CustomNpcResourceListener.DefaultTextColor); + fontRendererObj.drawString(title, guiLeft + 170, guiTop + 179, CustomNpcResourceListener.DefaultTextColor); } GL11.glPushMatrix(); @@ -284,6 +330,8 @@ public class GuiQuestLog extends GuiCNPCInventory implements ITopButtonListener, NoppesUtil.clickSound(); data.selectedCategory = button.displayString; data.selectedQuest = ""; + if(scroll != null) + scroll.selected = -1; this.initGui(); } @Override