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