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)

View File

@@ -4,7 +4,7 @@
**Goal:** Build `com.jovian.popup-system`, a low-allocation popup/tooltip package with category-based isolation, fluent content builder, grow-only element cache, screen edge clamping, and extensible animations.
**Architecture:** Per-game-state `IPopupSystem` instances with registered categories. Each category lazily creates one `PopupView` MonoBehaviour that reuses cached content elements. `PopupTrigger` MonoBehaviour handles hover detection. `PopupContentBuilder` struct operates directly on cached elements. Float-based timers in `Tick()` — no coroutines.
**Architecture:** Per-game-state `IPopupSystem` instances with registered categories. Each category lazily creates one `PopupReference` MonoBehaviour that reuses cached content elements. `PopupTrigger` MonoBehaviour handles hover detection. `PopupContentBuilder` struct operates directly on cached elements. Float-based timers in `Tick()` — no coroutines.
**Tech Stack:** Unity 6 / C# 9, TextMeshPro, Unity Input System, Newtonsoft.Json
@@ -373,12 +373,12 @@ git commit -m "feat: add IPopupAnimator interface and FadePopupAnimator"
---
### Task 5: PopupView MonoBehaviour with element cache
### Task 5: PopupReference MonoBehaviour with element cache
**Files:**
- Create: `Packages/com.jovian.popup-system/Runtime/UI/PopupView.cs`
- Create: `Packages/com.jovian.popup-system/Runtime/UI/PopupReference.cs`
**Step 1: Implement PopupView with grow-only element cache, positioning, and screen clamping**
**Step 1: Implement PopupReference with grow-only element cache, positioning, and screen clamping**
```csharp
using System.Collections.Generic;
@@ -388,7 +388,7 @@ using UnityEngine.InputSystem;
using UnityEngine.UI;
namespace Jovian.PopupSystem.UI {
public class PopupView : MonoBehaviour {
public class PopupReference : MonoBehaviour {
[SerializeField] RectTransform content;
[SerializeField] CanvasGroup canvasGroup;
[SerializeField] RectTransform background;
@@ -563,8 +563,8 @@ namespace Jovian.PopupSystem.UI {
**Step 2: Commit**
```bash
git add Packages/com.jovian.popup-system/Runtime/UI/PopupView.cs
git commit -m "feat: add PopupView with grow-only element cache and positioning"
git add Packages/com.jovian.popup-system/Runtime/UI/PopupReference.cs
git commit -m "feat: add PopupReference with grow-only element cache and positioning"
```
---
@@ -582,9 +582,9 @@ using UnityEngine;
namespace Jovian.PopupSystem {
public struct PopupContentBuilder {
readonly PopupView view;
readonly PopupReference view;
public PopupContentBuilder(PopupView view) {
public PopupContentBuilder(PopupReference view) {
this.view = view;
}
@@ -685,11 +685,11 @@ using Object = UnityEngine.Object;
namespace Jovian.PopupSystem {
public sealed class PopupSystem : IPopupSystem {
readonly PopupSettings settings;
readonly PopupView viewPrefab;
readonly PopupReference viewPrefab;
readonly IPopupAnimator animator;
readonly Dictionary<PopupCategory, ViewState> categories = new();
public PopupSystem(PopupSettings settings, PopupView viewPrefab, IPopupAnimator animator = null) {
public PopupSystem(PopupSettings settings, PopupReference viewPrefab, IPopupAnimator animator = null) {
this.settings = settings;
this.viewPrefab = viewPrefab;
this.animator = animator ?? new FadePopupAnimator();
@@ -847,7 +847,7 @@ namespace Jovian.PopupSystem {
}
private sealed class ViewState {
public PopupView view;
public PopupReference view;
public int priority;
public float delay;
public float delayTimer;
@@ -993,7 +993,7 @@ git commit -m "feat: add PopupSettingsProvider for Project Settings"
| `Packages/com.jovian.popup-system/Runtime/PopupContentBuilder.cs` | Create | Fluent builder struct |
| `Packages/com.jovian.popup-system/Runtime/IPopupSystem.cs` | Create | System interface |
| `Packages/com.jovian.popup-system/Runtime/PopupSystem.cs` | Create | System implementation |
| `Packages/com.jovian.popup-system/Runtime/UI/PopupView.cs` | Create | MonoBehaviour with element cache |
| `Packages/com.jovian.popup-system/Runtime/UI/PopupReference.cs` | Create | MonoBehaviour with element cache |
| `Packages/com.jovian.popup-system/Runtime/UI/PopupTrigger.cs` | Create | Hover trigger MonoBehaviour |
| `Packages/com.jovian.popup-system/README.md` | Create | Package documentation |
| `Packages/com.jovian.popup-system/Editor/PopupSettingsProvider.cs` | Create | Project Settings UI |