blocking popups

This commit is contained in:
2025-05-18 11:25:10 +02:00
parent d3f0de81b1
commit 0e8ee9eacd
2 changed files with 17 additions and 5 deletions

View File

@@ -11,7 +11,7 @@ public class OpenGLMain {
Game game = new Game(); Game game = new Game();
CommandExecutor commandExecutor = new CommandExecutor(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); DDDView ddd = new DDDView(commandExecutor);

View File

@@ -7,7 +7,7 @@ import java.util.function.Consumer;
import chess.controller.commands.*; import chess.controller.commands.*;
import imgui.ImGui; import imgui.ImGui;
import imgui.type.ImBoolean; import imgui.flag.ImGuiWindowFlags;
import org.joml.Vector2f; import org.joml.Vector2f;
import org.joml.Vector3f; import org.joml.Vector3f;
@@ -44,7 +44,6 @@ public class DDDView extends GameAdapter implements CommandSender {
private float moveProgress = 0.0f; private float moveProgress = 0.0f;
private String waitingPopup = null; private String waitingPopup = null;
private final ImBoolean popupOpened = new ImBoolean(false);
public DDDView(CommandExecutor commandExecutor) { public DDDView(CommandExecutor commandExecutor) {
this.commandExecutor = commandExecutor; this.commandExecutor = commandExecutor;
@@ -377,8 +376,14 @@ public class DDDView extends GameAdapter implements CommandSender {
} }
private void renderPopup(String title, String text) { private void renderPopup(String title, String text) {
if (ImGui.beginPopupModal(title, popupOpened)) { if (ImGui.beginPopupModal(title, null, ImGuiWindowFlags.AlwaysAutoResize)) {
ImGui.text(text); ImGui.text(text);
if (ImGui.button("Close")) {
ImGui.closeCurrentPopup();
synchronized (this) {
notifyAll();
}
}
ImGui.endPopup(); ImGui.endPopup();
} }
} }
@@ -397,8 +402,15 @@ public class DDDView extends GameAdapter implements CommandSender {
} }
private void openPopup(String title) { private void openPopup(String title) {
this.popupOpened.set(true);
this.waitingPopup = title; this.waitingPopup = title;
// block the current thread until the popup is closed
synchronized (this) {
try {
wait();
} catch (InterruptedException e) {
e.printStackTrace();
}
}
} }
@Override @Override