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