From e0375c251e02107bc8a7a34b3bb2a841bf2233ab Mon Sep 17 00:00:00 2001 From: "Luis C.M" <42545778+c0508383@users.noreply.github.com> Date: Wed, 7 Jun 2023 18:11:26 -0500 Subject: [PATCH] Added new top alignment feature for dialogs. --- .../client/gui/player/GuiDialogInteract.java | 42 +++++++++++++++---- .../noppes/npcs/controllers/data/Dialog.java | 3 ++ 2 files changed, 38 insertions(+), 7 deletions(-) diff --git a/src/main/java/noppes/npcs/client/gui/player/GuiDialogInteract.java b/src/main/java/noppes/npcs/client/gui/player/GuiDialogInteract.java index 2a18a7bd6..ebcfdaf8e 100644 --- a/src/main/java/noppes/npcs/client/gui/player/GuiDialogInteract.java +++ b/src/main/java/noppes/npcs/client/gui/player/GuiDialogInteract.java @@ -499,13 +499,30 @@ public class GuiDialogInteract extends GuiNPCInterface implements IGuiClose private void drawDialogString(String text, int left, int count, boolean mainDialogText, TextBlockClient block){ int lineOffset = dialog.renderGradual ? (currentBlock < lineBlocks.size() ? lineBlocks.get(currentBlock).lines.size() : lineBlocks.get(lineBlocks.size()-1).lines.size()) - currentLine : 0; + int height = count - totalRows + lineOffset; int screenPos = optionStart; int y = (height * ClientProxy.Font.height()) + screenPos + scrollY; + if (!dialog.bottomAligned) { + height = count - totalRows + lineOffset + 1; + screenPos = optionStart - dialog.textHeight + ClientProxy.Font.height() + (totalRows - lineOffset); + + int scrollToOffset = 0; + if (totalRows * ClientProxy.Font.height() > dialog.textHeight) { + scrollToOffset = totalRows - lineBlocks.get(lineBlocks.size() - 1).lines.size() + (int) Math.floor(lineBlocks.size() / 2f); + } + y = ((count - scrollToOffset) * ClientProxy.Font.height()) + screenPos + scrollY + height; + } if (block.titlePos == 0 || mainDialogText) { - if (y < screenPos - dialog.textHeight || y > screenPos - ClientProxy.Font.height()) { - return; + if (!dialog.bottomAligned) { + if (y < optionStart - dialog.textHeight || y > optionStart - ClientProxy.Font.height()/2f) { + return; + } + } else { + if (y < screenPos - dialog.textHeight || y > screenPos - ClientProxy.Font.height()) { + return; + } } } @@ -567,11 +584,22 @@ public class GuiDialogInteract extends GuiNPCInterface implements IGuiClose textSoundEnabled = !textSoundEnabled; } - if (i == mc.gameSettings.keyBindBack.getKeyCode() || i == 201 && scrollY < (totalRows - 2) * ClientProxy.Font.height()) {//Page up - scrollY += ClientProxy.Font.height() * 2; - } - if (i == mc.gameSettings.keyBindBack.getKeyCode() || i == 209 && scrollY > 0) {//Page down - scrollY -= ClientProxy.Font.height() * 2; + if (!dialog.bottomAligned && totalRows * ClientProxy.Font.height() > dialog.textHeight) { + if ((i == mc.gameSettings.keyBindBack.getKeyCode() || i == 201) && scrollY < totalRows * ClientProxy.Font.height()) {//Page up + scrollY += ClientProxy.Font.height() * 2; + } + + int latestBlockSize = lineBlocks.get(lineBlocks.size() - 1).lines.size(); + if ((i == mc.gameSettings.keyBindBack.getKeyCode() || i == 209) && scrollY > -(latestBlockSize - 2) * ClientProxy.Font.height()) {//Page down + scrollY -= ClientProxy.Font.height() * 2; + } + } else { + if ((i == mc.gameSettings.keyBindBack.getKeyCode() || i == 201) && scrollY < (totalRows - 2) * ClientProxy.Font.height()) {//Page up + scrollY += ClientProxy.Font.height() * 2; + } + if ((i == mc.gameSettings.keyBindBack.getKeyCode() || i == 209) && scrollY > 0) {//Page down + scrollY -= ClientProxy.Font.height() * 2; + } } if(i == 28){ diff --git a/src/main/java/noppes/npcs/controllers/data/Dialog.java b/src/main/java/noppes/npcs/controllers/data/Dialog.java index d7e03985d..15760f7dd 100644 --- a/src/main/java/noppes/npcs/controllers/data/Dialog.java +++ b/src/main/java/noppes/npcs/controllers/data/Dialog.java @@ -38,6 +38,7 @@ public class Dialog implements ICompatibilty, IDialog { public boolean disableEsc = false; public boolean darkenScreen = true; public boolean showOptionLine = true; + public boolean bottomAligned = false; public boolean renderGradual = false; public boolean showPreviousBlocks = true; @@ -96,6 +97,8 @@ public class Dialog implements ICompatibilty, IDialog { darkenScreen = true; } + bottomAligned = compound.getBoolean("DialogScrollUpwards"); + NBTTagList options = compound.getTagList("Options", 10); HashMap newoptions = new HashMap();