Made the popup system a lot more generic

This commit is contained in:
Sebastian Bularca
2026-04-06 20:38:58 +02:00
parent fa7659d905
commit cfe202da44
21 changed files with 840 additions and 682 deletions

View File

@@ -189,8 +189,8 @@ namespace Jovian.PopupSystem {
/// <inheritdoc />
public void Dispose() {
foreach(var kvp in categories) {
if(kvp.Value.view != null) {
Object.Destroy(kvp.Value.view.gameObject);
if(kvp.Value.view?.Reference != null) {
Object.Destroy(kvp.Value.view.Reference.gameObject);
}
}
categories.Clear();
@@ -210,7 +210,7 @@ namespace Jovian.PopupSystem {
// Force full layout rebuild so positioning has correct size on first show
Canvas.ForceUpdateCanvases();
LayoutRebuilder.ForceRebuildLayoutImmediate(state.view.Content);
LayoutRebuilder.ForceRebuildLayoutImmediate((RectTransform)state.view.transform);
LayoutRebuilder.ForceRebuildLayoutImmediate((RectTransform)state.view.Transform);
if(state.pendingScreenPos.HasValue) {
state.view.SetFixedPosition(state.pendingScreenPos.Value, settings.screenEdgePadding);
@@ -234,21 +234,21 @@ namespace Jovian.PopupSystem {
return;
}
PopupReference popupRef;
if(canvasParent != null) {
// Parent under existing scene Canvas — nested Canvas inherits CanvasScaler
state.view = Object.Instantiate(viewPrefab, canvasParent);
popupRef = Object.Instantiate(viewPrefab, canvasParent);
}
else {
state.view = Object.Instantiate(viewPrefab);
popupRef = Object.Instantiate(viewPrefab);
}
// Configure Canvas as override sorting so it renders on top
var canvas = state.view.GetComponent<Canvas>();
var canvas = popupRef.GetComponent<Canvas>();
if(canvas != null) {
canvas.overrideSorting = true;
canvas.sortingOrder = settings.sortingOrder;
}
state.view = new PopupView(popupRef, settings);
state.view.SetVisible(false);
state.view.SetMaxWidth(settings.maxPopupWidth);
}
@@ -266,7 +266,7 @@ namespace Jovian.PopupSystem {
}
private sealed class ViewState {
public PopupReference view;
public PopupView view;
public IPopupAnimator animator;
public int priority;
public float delay;