Merge pull request #167 from KAMKEEL/codex/fix-dialog-close-event-bug

Ensure dialog close event is always fired
This commit is contained in:
Kam authored and GitHub committed 2025-06-30 22:06:11 -04:00
commit a03c4eb712
3 files changed
+57

No files matched your search

@@ -68,6 +68,13 @@ public class GuiDialogInteract extends GuiNPCInterface implements IGuiClose {
private HashMap<Integer, GuiDialogImage> dialogImages = new HashMap<>();
/**
* Tracks if a close packet has been sent to the server. This ensures that the
* dialog closed event always triggers even when the gui is closed through
* external means such as key binds that bypass {@link #keyTyped(char, int)}.
*/
private boolean sentClosePacket = false;
public GuiDialogInteract(EntityNPCInterface npc, Dialog dialog) {
super(npc);
this.dialog = dialog;
@@ -647,6 +654,7 @@ public class GuiDialogInteract extends GuiNPCInterface implements IGuiClose {
}
private void closed() {
sentClosePacket = true;
grabMouse(false);
PacketClient.sendClient(new CheckPlayerValue(CheckPlayerValue.Type.CheckQuestCompletion));
}
@@ -657,6 +665,7 @@ public class GuiDialogInteract extends GuiNPCInterface implements IGuiClose {
public void appendDialog(Dialog dialog) {
closeOnEsc = !dialog.disableEsc;
sentClosePacket = false;
this.dialogImages.clear();
this.dialog = dialog;
this.options = new ArrayList<Integer>();
@@ -701,6 +710,17 @@ public class GuiDialogInteract extends GuiNPCInterface implements IGuiClose {
MusicController.Instance.stopAllSounds();
}
@Override
public void onGuiClosed() {
if (!sentClosePacket) {
if (dialog != null) {
PacketClient.sendClient(new DialogSelectPacket(dialog.id, -1));
}
closed();
}
super.onGuiClosed();
}
@Override
public void setClose(int i, NBTTagCompound data) {
grabMouse(false);
@@ -57,6 +57,12 @@ public class GuiModernDialogInteract extends GuiNPCInterface implements IGuiClos
private final HashMap<Integer, GuiDialogImage> dialogImages = new HashMap<>();
/**
* Similar to {@link noppes.npcs.client.gui.player.GuiDialogInteract#sentClosePacket} this flag
* tracks if a close packet was already sent to the server.
*/
private boolean sentClosePacket = false;
public GuiModernDialogInteract(EntityNPCInterface npc, Dialog dialog) {
super(npc);
this.dialog = dialog;
@@ -357,6 +363,7 @@ public class GuiModernDialogInteract extends GuiNPCInterface implements IGuiClos
}
private void closed() {
sentClosePacket = true;
grabMouse(false);
PacketClient.sendClient(new CheckPlayerValue(CheckPlayerValue.Type.CheckQuestCompletion));
}
@@ -367,6 +374,7 @@ public class GuiModernDialogInteract extends GuiNPCInterface implements IGuiClos
public void appendDialog(Dialog dialog) {
closeOnEsc = !dialog.disableEsc;
sentClosePacket = false;
this.dialogImages.clear();
this.dialog = dialog;
this.options = new ArrayList<Integer>();
@@ -423,4 +431,15 @@ public class GuiModernDialogInteract extends GuiNPCInterface implements IGuiClos
public void setClose(int i, NBTTagCompound data) {
grabMouse(false);
}
@Override
public void onGuiClosed() {
if (!sentClosePacket) {
if (dialog != null) {
PacketClient.sendClient(new DialogSelectPacket(dialog.id, -1));
}
closed();
}
super.onGuiClosed();
}
}
@@ -54,6 +54,11 @@ public class GuiModernQuestDialog extends GuiNPCInterface implements IGuiClose {
private boolean isGrabbed = false;
/**
* Flag to ensure the dialog close packet is only sent once.
*/
private boolean sentClosePacket = false;
private final HashMap<Integer, GuiDialogImage> dialogImages = new HashMap<>();
private Dialog prevDialog;
private int optionId;
@@ -70,6 +75,7 @@ public class GuiModernQuestDialog extends GuiNPCInterface implements IGuiClose {
public void initGui() {
super.initGui();
isGrabbed = false;
sentClosePacket = false;
guiTop = (height - ySize);
calculateRowHeight();
this.scaledResolution = new ScaledResolution(mc, mc.displayWidth, mc.displayHeight);
@@ -353,6 +359,7 @@ public class GuiModernQuestDialog extends GuiNPCInterface implements IGuiClose {
}
private void closed() {
sentClosePacket = true;
grabMouse(false);
PacketClient.sendClient(new CheckPlayerValue(CheckPlayerValue.Type.CheckQuestCompletion));
}
@@ -403,4 +410,15 @@ public class GuiModernQuestDialog extends GuiNPCInterface implements IGuiClose {
public void setClose(int i, NBTTagCompound data) {
grabMouse(false);
}
@Override
public void onGuiClosed() {
if (!sentClosePacket) {
if (prevDialog != null) {
PacketClient.sendClient(new DialogSelectPacket(prevDialog.id, -1));
}
closed();
}
super.onGuiClosed();
}
}