mirror of
https://athene2.informatik.unibw-muenchen.de/progproj/gruppen-ht24/Gruppe-02.git
synced 2025-07-31 06:37:39 +02:00
popUp
This commit is contained in:
@@ -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();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@@ -0,0 +1,5 @@
|
||||
package pp.dialog;
|
||||
|
||||
public interface PopupDialog {
|
||||
void show();
|
||||
}
|
Reference in New Issue
Block a user