This commit is contained in:
Johannes Schmelz
2024-12-09 23:57:45 +01:00
parent b680d7bc58
commit ed27e0aaf1
20 changed files with 990 additions and 801 deletions

View File

@@ -19,6 +19,8 @@ import java.util.Deque;
import static java.lang.Math.max;
import java.lang.System.Logger;
/**
* Manages dialog boxes within the application, handling their display, positioning, and focus.
*/
@@ -28,11 +30,15 @@ public class DialogManager {
*/
private final SimpleApplication app;
private final static Logger LOGGER = System.getLogger(DialogManager.class.getName());
/**
* A stack to keep track of the dialogs.
*/
private final Deque<Dialog> dialogStack = new ArrayDeque<>();
private final Deque<PopupDialog> popUpStack = new ArrayDeque<>();
/**
* Constructs a DialogManager for the specified application.
*
@@ -112,11 +118,45 @@ public class DialogManager {
* @param dialog the dialog to open
*/
public void open(Dialog dialog) {
if(dialog instanceof PopupDialog) {
popUpStack.push((PopupDialog) dialog);
processPopUps();
} else {
showDialog(dialog);
}
}
private void showDialog(Dialog dialog) {
dialogStack.push(dialog);
if(dialog instanceof PopupDialog) {
((PopupDialog)dialog).show();
}
dialog.update();
app.getGuiNode().attachChild(dialog);
}
private void processPopUps() {
if (popUpStack.isEmpty()) {
return; // Nothing to process
}
// Check if a popup dialog is already on top
if (dialogStack.peek() instanceof PopupDialog) {
LOGGER.log(Logger.Level.DEBUG, "Popup dialog already on top");
return; // Already a popup dialog on top
} else {
// Pop the next popup from the stack and validate before showing
PopupDialog popUp = popUpStack.pop();
showDialog( (Dialog) popUp);
}
}
/**
* Checks if the specified dialog is the topmost dialog in the dialog stack.
*
@@ -140,6 +180,8 @@ public class DialogManager {
if (!dialogStack.isEmpty())
dialogStack.peek().update();
app.getGuiNode().detachChild(dialog);
processPopUps();
}
/**

View File

@@ -0,0 +1,5 @@
package pp.dialog;
public interface PopupDialog {
void show();
}