| | 1 | | using DCL; |
| | 2 | | using UnityEngine; |
| | 3 | |
|
| | 4 | | public class LoadingHUDController : IHUD |
| | 5 | | { |
| | 6 | | internal LoadingHUDView view; |
| 8 | 7 | | internal BaseVariable<bool> visible => DataStore.i.HUDs.loadingHUD.visible; |
| 12 | 8 | | internal BaseVariable<bool> fadeIn => DataStore.i.HUDs.loadingHUD.fadeIn; |
| 6 | 9 | | internal BaseVariable<bool> fadeOut => DataStore.i.HUDs.loadingHUD.fadeOut; |
| 19 | 10 | | internal BaseVariable<string> message => DataStore.i.HUDs.loadingHUD.message; |
| 19 | 11 | | internal BaseVariable<float> percentage => DataStore.i.HUDs.loadingHUD.percentage; |
| 19 | 12 | | internal BaseVariable<bool> showTips => DataStore.i.HUDs.loadingHUD.showTips; |
| | 13 | |
|
| 6 | 14 | | protected internal virtual LoadingHUDView CreateView() { return LoadingHUDView.CreateView(); } |
| | 15 | |
|
| | 16 | | public void Initialize() |
| | 17 | | { |
| 6 | 18 | | view = CreateView(); |
| 6 | 19 | | ClearEvents(); |
| 6 | 20 | | SetViewVisible(fadeIn.Get(), true); |
| 6 | 21 | | view?.SetMessage(message.Get()); |
| 6 | 22 | | view?.SetPercentage(percentage.Get() / 100f); |
| 6 | 23 | | view?.SetTips(showTips.Get()); |
| | 24 | |
|
| | 25 | | // set initial states to prevent reconciliation errors |
| 6 | 26 | | fadeIn.OnChange += OnFadeInChange; |
| 6 | 27 | | fadeOut.OnChange += OnFadeOutChange; |
| | 28 | |
|
| 6 | 29 | | message.OnChange += OnMessageChanged; |
| 6 | 30 | | percentage.OnChange += OnPercentageChanged; |
| 6 | 31 | | showTips.OnChange += OnShowTipsChanged; |
| 6 | 32 | | } |
| | 33 | |
|
| 0 | 34 | | private void OnVisibleHUDChanged(bool current, bool previous) { SetViewVisible(current, false); } |
| 2 | 35 | | private void OnMessageChanged(string current, string previous) { view?.SetMessage(current); } |
| 0 | 36 | | private void OnPercentageChanged(float current, float previous) { view?.SetPercentage(current / 100f); } |
| 2 | 37 | | private void OnShowTipsChanged(bool current, bool previous) { view?.SetTips(current); } |
| | 38 | | private void OnFadeInChange(bool current, bool previous) |
| | 39 | | { |
| 1 | 40 | | if (current) |
| 1 | 41 | | SetViewVisible(true, false); |
| 1 | 42 | | } |
| | 43 | | private void OnFadeOutChange(bool current, bool previous) |
| | 44 | | { |
| 1 | 45 | | if (current) |
| 0 | 46 | | SetViewVisible(false, false); |
| 1 | 47 | | } |
| | 48 | |
|
| 2 | 49 | | public void SetVisibility(bool visible) { this.visible.Set(visible); } |
| | 50 | |
|
| | 51 | | public void Dispose() |
| | 52 | | { |
| 1 | 53 | | ClearEvents(); |
| 1 | 54 | | view?.Dispose(); |
| 1 | 55 | | } |
| | 56 | |
|
| | 57 | | internal void ClearEvents() |
| | 58 | | { |
| 7 | 59 | | visible.OnChange -= OnVisibleHUDChanged; |
| 7 | 60 | | message.OnChange -= OnMessageChanged; |
| 7 | 61 | | percentage.OnChange -= OnPercentageChanged; |
| 7 | 62 | | showTips.OnChange -= OnShowTipsChanged; |
| 7 | 63 | | } |
| | 64 | |
|
| 14 | 65 | | internal void SetViewVisible(bool isVisible, bool instant) { view?.SetVisible(isVisible, instant); } |
| | 66 | | } |