| | | 1 | | namespace Chronicis.Client.Services; |
| | | 2 | | |
| | | 3 | | /// <summary> |
| | | 4 | | /// Service for coordinating quest drawer toggle events. |
| | | 5 | | /// Wraps the shared drawer coordinator and preserves the existing event-based API. |
| | | 6 | | /// </summary> |
| | | 7 | | public class QuestDrawerService : IQuestDrawerService, IDisposable |
| | | 8 | | { |
| | | 9 | | private readonly IDrawerCoordinator _drawerCoordinator; |
| | | 10 | | private bool _isOpen; |
| | | 11 | | private bool _disposed; |
| | | 12 | | |
| | | 13 | | public event Action? OnOpen; |
| | | 14 | | public event Action? OnClose; |
| | | 15 | | |
| | 13 | 16 | | public bool IsOpen => _isOpen; |
| | | 17 | | |
| | | 18 | | public QuestDrawerService(IDrawerCoordinator drawerCoordinator) |
| | | 19 | | { |
| | 18 | 20 | | _drawerCoordinator = drawerCoordinator; |
| | 18 | 21 | | _isOpen = _drawerCoordinator.Current == DrawerType.Quests; |
| | 18 | 22 | | _drawerCoordinator.OnChanged += OnDrawerCoordinatorChanged; |
| | 18 | 23 | | } |
| | | 24 | | |
| | | 25 | | public void Open() |
| | | 26 | | { |
| | 11 | 27 | | if (_disposed) |
| | 2 | 28 | | return; |
| | | 29 | | |
| | 9 | 30 | | _drawerCoordinator.Open(DrawerType.Quests); |
| | 9 | 31 | | } |
| | | 32 | | |
| | | 33 | | public void Close() |
| | | 34 | | { |
| | 4 | 35 | | if (_disposed || !_isOpen) |
| | 3 | 36 | | return; |
| | | 37 | | |
| | 1 | 38 | | _drawerCoordinator.Close(); |
| | 1 | 39 | | } |
| | | 40 | | |
| | | 41 | | public void Toggle() |
| | | 42 | | { |
| | 6 | 43 | | if (_disposed) |
| | 1 | 44 | | return; |
| | | 45 | | |
| | 5 | 46 | | _drawerCoordinator.Toggle(DrawerType.Quests); |
| | 5 | 47 | | } |
| | | 48 | | |
| | | 49 | | private void OnDrawerCoordinatorChanged() |
| | | 50 | | { |
| | 18 | 51 | | if (_disposed) |
| | | 52 | | { |
| | 1 | 53 | | return; |
| | | 54 | | } |
| | | 55 | | |
| | 17 | 56 | | var isOpenNow = _drawerCoordinator.Current == DrawerType.Quests; |
| | 17 | 57 | | if (_isOpen == isOpenNow) |
| | | 58 | | { |
| | 1 | 59 | | return; |
| | | 60 | | } |
| | | 61 | | |
| | 16 | 62 | | _isOpen = isOpenNow; |
| | 16 | 63 | | if (_isOpen) |
| | | 64 | | { |
| | 11 | 65 | | OnOpen?.Invoke(); |
| | | 66 | | } |
| | | 67 | | else |
| | | 68 | | { |
| | 5 | 69 | | OnClose?.Invoke(); |
| | | 70 | | } |
| | 2 | 71 | | } |
| | | 72 | | |
| | | 73 | | public void Dispose() |
| | | 74 | | { |
| | 27 | 75 | | if (_disposed) |
| | 9 | 76 | | return; |
| | | 77 | | |
| | 18 | 78 | | _disposed = true; |
| | 18 | 79 | | _drawerCoordinator.OnChanged -= OnDrawerCoordinatorChanged; |
| | 18 | 80 | | OnOpen = null; |
| | 18 | 81 | | OnClose = null; |
| | | 82 | | |
| | 18 | 83 | | GC.SuppressFinalize(this); |
| | 18 | 84 | | } |
| | | 85 | | } |