| | | 1 | | namespace Chronicis.Client.Services; |
| | | 2 | | |
| | | 3 | | /// <summary> |
| | | 4 | | /// Default implementation for coordinating mutually-exclusive right-side drawers. |
| | | 5 | | /// </summary> |
| | | 6 | | public class DrawerCoordinator : IDrawerCoordinator |
| | | 7 | | { |
| | | 8 | | private DrawerType _current = DrawerType.None; |
| | | 9 | | private bool _isForcedOpen; |
| | | 10 | | |
| | 56 | 11 | | public DrawerType Current => _current; |
| | | 12 | | |
| | | 13 | | public bool IsForcedOpen |
| | | 14 | | { |
| | 2 | 15 | | get => _isForcedOpen; |
| | | 16 | | set |
| | | 17 | | { |
| | 8 | 18 | | if (_isForcedOpen == value) |
| | | 19 | | { |
| | 1 | 20 | | return; |
| | | 21 | | } |
| | | 22 | | |
| | 7 | 23 | | _isForcedOpen = value; |
| | | 24 | | |
| | 7 | 25 | | if (_isForcedOpen && _current != DrawerType.Tutorial) |
| | | 26 | | { |
| | 3 | 27 | | _current = DrawerType.Tutorial; |
| | | 28 | | } |
| | | 29 | | |
| | 7 | 30 | | OnChanged?.Invoke(); |
| | 2 | 31 | | } |
| | | 32 | | } |
| | | 33 | | |
| | | 34 | | public event Action? OnChanged; |
| | | 35 | | |
| | | 36 | | public void Open(DrawerType type) |
| | | 37 | | { |
| | 37 | 38 | | if (type == DrawerType.None) |
| | | 39 | | { |
| | 1 | 40 | | Close(); |
| | 1 | 41 | | return; |
| | | 42 | | } |
| | | 43 | | |
| | 36 | 44 | | if (_isForcedOpen && type != DrawerType.Tutorial) |
| | | 45 | | { |
| | 1 | 46 | | type = DrawerType.Tutorial; |
| | | 47 | | } |
| | | 48 | | |
| | 36 | 49 | | if (_current == type) |
| | | 50 | | { |
| | 4 | 51 | | return; |
| | | 52 | | } |
| | | 53 | | |
| | 32 | 54 | | _current = type; |
| | 32 | 55 | | OnChanged?.Invoke(); |
| | 18 | 56 | | } |
| | | 57 | | |
| | | 58 | | public void Close() |
| | | 59 | | { |
| | 14 | 60 | | if (_isForcedOpen && _current == DrawerType.Tutorial) |
| | | 61 | | { |
| | 1 | 62 | | return; |
| | | 63 | | } |
| | | 64 | | |
| | 13 | 65 | | if (_current == DrawerType.None) |
| | | 66 | | { |
| | 3 | 67 | | return; |
| | | 68 | | } |
| | | 69 | | |
| | 10 | 70 | | _current = DrawerType.None; |
| | 10 | 71 | | OnChanged?.Invoke(); |
| | 6 | 72 | | } |
| | | 73 | | |
| | | 74 | | public void Toggle(DrawerType type) |
| | | 75 | | { |
| | 15 | 76 | | if (type == DrawerType.None) |
| | | 77 | | { |
| | 1 | 78 | | Close(); |
| | 1 | 79 | | return; |
| | | 80 | | } |
| | | 81 | | |
| | 14 | 82 | | if (_isForcedOpen && type != DrawerType.Tutorial) |
| | | 83 | | { |
| | 1 | 84 | | Open(DrawerType.Tutorial); |
| | 1 | 85 | | return; |
| | | 86 | | } |
| | | 87 | | |
| | 13 | 88 | | if (_current == type) |
| | | 89 | | { |
| | 5 | 90 | | if (_isForcedOpen && type == DrawerType.Tutorial) |
| | | 91 | | { |
| | 1 | 92 | | return; |
| | | 93 | | } |
| | | 94 | | |
| | 4 | 95 | | Close(); |
| | 4 | 96 | | return; |
| | | 97 | | } |
| | | 98 | | |
| | 8 | 99 | | Open(type); |
| | 8 | 100 | | } |
| | | 101 | | } |