mirror of
https://github.com/IvarK/AntimatterDimensionsSourceCode.git
synced 2025-02-18 00:20:13 +00:00
Merge pull request #2633 from IvarK/modal-priority-v3
Fix modal priorities acting up with immediate modal closures
This commit is contained in:
commit
f948b39826
@ -76,14 +76,17 @@ export class Modal {
|
||||
this._props = Object.assign({}, modalConfig || {});
|
||||
|
||||
const modalQueue = ui.view.modal.queue;
|
||||
// Add this modal to the front of the queue and sort based on priority to ensure priority is maintained.
|
||||
modalQueue.unshift(this);
|
||||
modalQueue.sort((x, y) => y.priority - x.priority);
|
||||
// Filter out multiple instances of the same modal.
|
||||
const singleQueue = [...new Set(modalQueue)];
|
||||
ui.view.modal.queue = singleQueue;
|
||||
// If the front of the queue is what is currently presented, we dont need to do anything.
|
||||
if (!singleQueue[0].isOpen) ui.view.modal.current = singleQueue[0];
|
||||
// Add this modal to the back of the queue and sort based on priority to ensure priority is maintained.
|
||||
modalQueue.push(this);
|
||||
|
||||
// Unfortunately, we can't do it directly because a lot of modal interactions depend on a modal
|
||||
// being shown that shows up at the back, followed by an immediate closing of the current modal.
|
||||
// This will not work if, say, a modal of priority 2 is shown right before a modal of priority 1 is closed.
|
||||
// So we have to wait just a little while.
|
||||
EventHub.ui.on(GAME_EVENT.UPDATE, () => {
|
||||
Modal.sortModalQueue();
|
||||
EventHub.ui.offAll(Modal.sortModalQueue);
|
||||
}, Modal.sortModalQueue);
|
||||
}
|
||||
|
||||
get isOpen() {
|
||||
@ -106,6 +109,16 @@ export class Modal {
|
||||
return this._priority;
|
||||
}
|
||||
|
||||
static sortModalQueue() {
|
||||
const modalQueue = ui.view.modal.queue;
|
||||
modalQueue.sort((x, y) => y.priority - x.priority);
|
||||
// Filter out multiple instances of the same modal.
|
||||
const singleQueue = [...new Set(modalQueue)];
|
||||
ui.view.modal.queue = singleQueue;
|
||||
// If the front of the queue is what is currently presented, we dont need to do anything.
|
||||
if (!singleQueue[0].isOpen) ui.view.modal.current = singleQueue[0];
|
||||
}
|
||||
|
||||
static hide() {
|
||||
if (!GameUI.initialized) return;
|
||||
ui.view.modal.queue.shift();
|
||||
|
Loading…
Reference in New Issue
Block a user