popup changes

This commit is contained in:
Sebastian Bularca
2026-04-06 10:44:16 +02:00
parent 61ca3701ae
commit cbf9f384d9
39 changed files with 1222 additions and 45 deletions

View File

@@ -16,11 +16,11 @@ Game Code / PopupTrigger MonoBehaviour
IPopupSystem (per-game-state instance, injected via constructor DI)
│ RegisterCategory(PopupCategory, priority)
│ One PopupView per category (lazy-created on first Show)
│ One PopupReference per category (lazy-created on first Show)
│ Priority: higher priority category dismisses lower on show
│ Tick()-driven delay timers and animations (no coroutines)
PopupView (MonoBehaviour — one instance per registered category)
PopupReference (MonoBehaviour — one instance per registered category)
│ Canvas + CanvasGroup for transitions
│ Content parent (VerticalLayoutGroup + ContentSizeFitter)
│ Grow-only element cache (reuse, never destroy)
@@ -34,7 +34,7 @@ IPopupAnimator (extensible interface for show/hide transitions)
PopupContentBuilder (struct, fluent API)
.AddHeader(text) .AddText(text) .AddStat(label, value)
.AddImage(sprite) .AddSeparator()
→ activates pre-existing child elements in PopupView
→ activates pre-existing child elements in PopupReference
```
## Core Types
@@ -106,24 +106,24 @@ public interface IPopupSystem {
### PopupSystem (implementation)
- `Dictionary<PopupCategory, PopupViewState>` — O(1) lookup by category
- `PopupViewState` holds: PopupView instance (null until first show), priority, delay timer, pending show data
- `Dictionary<PopupCategory, PopupReferenceState>` — O(1) lookup by category
- `PopupReferenceState` holds: PopupReference instance (null until first show), priority, delay timer, pending show data
- `Tick(deltaTime)` drives delay countdown and animation lerp — no coroutines
- On `Show()`:
- If a higher-priority popup is already visible, queue or cancel
- Start delay timer; on expiry, activate the view
- PopupView clears content (deactivates cached elements), runs builder callback, positions, animates in
- PopupReference clears content (deactivates cached elements), runs builder callback, positions, animates in
- On `Hide()`:
- Animate out, deactivate
- On `Dispose()`:
- Destroy all PopupView GameObjects
- Destroy all PopupReference GameObjects
### PopupView (MonoBehaviour)
### PopupReference (MonoBehaviour)
Single prefab, instantiated once per category:
```
PopupView (Canvas, CanvasGroup, RectMask2D)
PopupReference (Canvas, CanvasGroup, RectMask2D)
├── Content (RectTransform, VerticalLayoutGroup, ContentSizeFitter)
│ ├── [cached] HeaderElement (TMP_Text, deactivated)
│ ├── [cached] TextElement x N (TMP_Text, deactivated)
@@ -153,7 +153,7 @@ PopupView (Canvas, CanvasGroup, RectMask2D)
```csharp
public struct PopupContentBuilder {
readonly PopupView view;
readonly PopupReference view;
public PopupContentBuilder AddHeader(string text);
public PopupContentBuilder AddText(string text);
@@ -165,7 +165,7 @@ public struct PopupContentBuilder {
}
```
Each method activates a cached element from PopupView, sets its data, calls `SetAsLastSibling()` for ordering. Returns `this` for chaining. No allocations.
Each method activates a cached element from PopupReference, sets its data, calls `SetAsLastSibling()` for ordering. Returns `this` for chaining. No allocations.
### PopupTrigger (MonoBehaviour)
@@ -244,7 +244,7 @@ Packages/com.jovian.popup-system/
│ ├── FadePopupAnimator.cs
│ ├── PopupContentBuilder.cs
│ └── UI/
│ ├── PopupView.cs
│ ├── PopupReference.cs
│ └── PopupTrigger.cs
├── Editor/
│ ├── Jovian.PopupSystem.Editor.asmdef
@@ -264,7 +264,7 @@ Packages/com.jovian.popup-system/
```csharp
// In GameModeGameState or similar:
var popupSettings = Addressables.LoadAssetAsync<PopupSettings>("PopupSettings").WaitForCompletion();
var popupViewPrefab = Addressables.LoadAssetAsync<PopupView>("PopupViewPrefab").WaitForCompletion();
var popupViewPrefab = Addressables.LoadAssetAsync<PopupReference>("PopupReferencePrefab").WaitForCompletion();
var popupSystem = new PopupSystem(popupSettings, popupViewPrefab);
popupSystem.RegisterCategory(PopupCategory.Character, priority: 10);
popupSystem.RegisterCategory(PopupCategory.Item, priority: 5);
@@ -291,7 +291,7 @@ popupSystem.Dispose();
## Prefab Setup
### PopupView prefab
### PopupReference prefab
1. Root: Canvas (Screen Space Overlay, sorting order from settings), CanvasGroup (alpha=0)
2. Child "Content": RectTransform, VerticalLayoutGroup (Child Force Expand Width: true, Height: false, Spacing: 4, Padding: 8), ContentSizeFitter (Vertical Fit: Preferred Size, Horizontal Fit: Preferred Size up to maxPopupWidth)