From 0e8ee9eacd5c69f2522f173f193f8691223afdd7 Mon Sep 17 00:00:00 2001 From: Persson-dev Date: Sun, 18 May 2025 11:25:10 +0200 Subject: [PATCH] blocking popups --- app/src/main/java/chess/OpenGLMain.java | 2 +- .../java/chess/view/DDDrender/DDDView.java | 20 +++++++++++++++---- 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/app/src/main/java/chess/OpenGLMain.java b/app/src/main/java/chess/OpenGLMain.java index 7f80446..1fadc76 100644 --- a/app/src/main/java/chess/OpenGLMain.java +++ b/app/src/main/java/chess/OpenGLMain.java @@ -11,7 +11,7 @@ public class OpenGLMain { Game game = new Game(); CommandExecutor commandExecutor = new CommandExecutor(game); - PgnFileSimulator fileSimulator = new PgnFileSimulator(commandExecutor, "games/CastlingTest.pgn"); + PgnFileSimulator fileSimulator = new PgnFileSimulator(commandExecutor, "games/FoolCheckmate.pgn"); DDDView ddd = new DDDView(commandExecutor); diff --git a/app/src/main/java/chess/view/DDDrender/DDDView.java b/app/src/main/java/chess/view/DDDrender/DDDView.java index 829f962..d988ef4 100644 --- a/app/src/main/java/chess/view/DDDrender/DDDView.java +++ b/app/src/main/java/chess/view/DDDrender/DDDView.java @@ -7,7 +7,7 @@ import java.util.function.Consumer; import chess.controller.commands.*; import imgui.ImGui; -import imgui.type.ImBoolean; +import imgui.flag.ImGuiWindowFlags; import org.joml.Vector2f; import org.joml.Vector3f; @@ -44,7 +44,6 @@ public class DDDView extends GameAdapter implements CommandSender { private float moveProgress = 0.0f; private String waitingPopup = null; - private final ImBoolean popupOpened = new ImBoolean(false); public DDDView(CommandExecutor commandExecutor) { this.commandExecutor = commandExecutor; @@ -377,8 +376,14 @@ public class DDDView extends GameAdapter implements CommandSender { } private void renderPopup(String title, String text) { - if (ImGui.beginPopupModal(title, popupOpened)) { + if (ImGui.beginPopupModal(title, null, ImGuiWindowFlags.AlwaysAutoResize)) { ImGui.text(text); + if (ImGui.button("Close")) { + ImGui.closeCurrentPopup(); + synchronized (this) { + notifyAll(); + } + } ImGui.endPopup(); } } @@ -397,8 +402,15 @@ public class DDDView extends GameAdapter implements CommandSender { } private void openPopup(String title) { - this.popupOpened.set(true); this.waitingPopup = title; + // block the current thread until the popup is closed + synchronized (this) { + try { + wait(); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } } @Override