diff --git a/Projekte/jme-common/src/main/java/pp/dialog/DialogManager.java b/Projekte/jme-common/src/main/java/pp/dialog/DialogManager.java index f84b6e7..44364aa 100644 --- a/Projekte/jme-common/src/main/java/pp/dialog/DialogManager.java +++ b/Projekte/jme-common/src/main/java/pp/dialog/DialogManager.java @@ -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 dialogStack = new ArrayDeque<>(); + private final Deque 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(); } /** @@ -150,6 +192,11 @@ public class DialogManager { dialogStack.peek().escape(); } + /** + * Updates all dialogs in the dialog stack. + * + * @param delta the time since the last update + */ public void update(float delta) { for (Dialog dialog : dialogStack) dialog.update(delta); diff --git a/Projekte/jme-common/src/main/java/pp/dialog/PopupDialog.java b/Projekte/jme-common/src/main/java/pp/dialog/PopupDialog.java new file mode 100644 index 0000000..82bbae0 --- /dev/null +++ b/Projekte/jme-common/src/main/java/pp/dialog/PopupDialog.java @@ -0,0 +1,10 @@ +package pp.dialog; + +/** An interface for tagging Dialogs as PopUps for handling in the DialogManager */ +public interface PopupDialog { + + /** + * Shows the popup. + */ + void show(); +} diff --git a/Projekte/jme-common/src/main/resources/Interface/Lemur/pp-styles.groovy b/Projekte/jme-common/src/main/resources/Interface/Lemur/pp-styles.groovy index a569137..e9a4614 100644 --- a/Projekte/jme-common/src/main/resources/Interface/Lemur/pp-styles.groovy +++ b/Projekte/jme-common/src/main/resources/Interface/Lemur/pp-styles.groovy @@ -405,3 +405,44 @@ selector("button-clear", "pp") { playerColor -> textHAlignment = HAlignment.Center // Text-Zentrierung textVAlignment = VAlignment.Center // Text-Zentrierung } + + +def enabledCommandToolbar2= new Command