| | 1 | | using DCL; |
| | 2 | |
|
| | 3 | | public class PreviewMenuPlugin : IPlugin |
| | 4 | | { |
| | 5 | | private readonly IBaseVariable<bool> isPreviewMenuActive; |
| | 6 | |
|
| | 7 | | internal PreviewMenuController menuController; |
| | 8 | |
|
| 2 | 9 | | public PreviewMenuPlugin() : this(DataStore.i.debugConfig.isPreviewMenuActive) { } |
| | 10 | |
|
| 3 | 11 | | internal PreviewMenuPlugin(IBaseVariable<bool> isPreviewMenuActive) |
| | 12 | | { |
| 3 | 13 | | this.isPreviewMenuActive = isPreviewMenuActive; |
| 3 | 14 | | isPreviewMenuActive.OnChange += OnIsPreviewMenuActiveChange; |
| | 15 | |
|
| 3 | 16 | | OnIsPreviewMenuActiveChange(isPreviewMenuActive.Get(), false); |
| 3 | 17 | | } |
| | 18 | |
|
| | 19 | | public void Dispose() |
| | 20 | | { |
| 3 | 21 | | isPreviewMenuActive.OnChange -= OnIsPreviewMenuActiveChange; |
| 3 | 22 | | DisposeView(); |
| 3 | 23 | | } |
| | 24 | |
|
| | 25 | | private void InitializeView() |
| | 26 | | { |
| 2 | 27 | | menuController ??= new PreviewMenuController(); |
| 2 | 28 | | } |
| | 29 | |
|
| | 30 | | private void DisposeView() |
| | 31 | | { |
| 5 | 32 | | menuController?.Dispose(); |
| 5 | 33 | | menuController = null; |
| 5 | 34 | | } |
| | 35 | |
|
| | 36 | | private void OnIsPreviewMenuActiveChange(bool current, bool previous) |
| | 37 | | { |
| 4 | 38 | | if (current) |
| | 39 | | { |
| 2 | 40 | | InitializeView(); |
| 2 | 41 | | } |
| | 42 | | else |
| | 43 | | { |
| 2 | 44 | | DisposeView(); |
| | 45 | | } |
| 2 | 46 | | } |
| | 47 | | } |