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