| | 1 | | using System; |
| | 2 | | using DCL; |
| | 3 | | using UnityEngine; |
| | 4 | |
|
| | 5 | | public class EmotesHUDController : IHUD |
| | 6 | | { |
| | 7 | | internal EmotesHUDView view; |
| 0 | 8 | | private BaseVariable<bool> emotesVisible => DataStore.i.HUDs.emotesVisible; |
| | 9 | |
|
| 26 | 10 | | private UserProfile ownUserProfile => UserProfile.GetOwnUserProfile(); |
| | 11 | | private InputAction_Trigger closeWindow; |
| | 12 | |
|
| 6 | 13 | | public EmotesHUDController() |
| | 14 | | { |
| 6 | 15 | | closeWindow = Resources.Load<InputAction_Trigger>("CloseWindow"); |
| 6 | 16 | | closeWindow.OnTriggered += OnCloseWindowPressed; |
| 6 | 17 | | view = EmotesHUDView.Create(); |
| 6 | 18 | | view.Initialize(EmoteCalled); |
| 6 | 19 | | view.OnClose += OnViewClosed; |
| | 20 | |
|
| 6 | 21 | | ownUserProfile.OnAvatarExpressionSet += OnAvatarEmoteSet; |
| 6 | 22 | | emotesVisible.OnChange += OnEmoteVisibleChanged; |
| 6 | 23 | | OnEmoteVisibleChanged(emotesVisible.Get(), false); |
| 6 | 24 | | } |
| | 25 | |
|
| | 26 | | public void SetVisibility(bool visible) |
| | 27 | | { |
| | 28 | | //TODO once kernel sends visible properly |
| | 29 | | //expressionsVisible.Set(visible); |
| 2 | 30 | | } |
| 16 | 31 | | private void OnEmoteVisibleChanged(bool current, bool previous) { SetVisibility_Internal(current); } |
| | 32 | | public void SetVisibility_Internal(bool visible) |
| | 33 | | { |
| 8 | 34 | | view.SetVisiblity(visible); |
| | 35 | |
|
| 8 | 36 | | if ( visible ) |
| | 37 | | { |
| 1 | 38 | | DCL.Helpers.Utils.UnlockCursor(); |
| 1 | 39 | | ownUserProfile.snapshotObserver.AddListener(view.UpdateAvatarSprite); |
| 1 | 40 | | } |
| | 41 | | else |
| | 42 | | { |
| 7 | 43 | | DCL.Helpers.Utils.LockCursor(); |
| 7 | 44 | | ownUserProfile.snapshotObserver.RemoveListener(view.UpdateAvatarSprite); |
| | 45 | | } |
| 7 | 46 | | } |
| | 47 | |
|
| | 48 | | public void Dispose() |
| | 49 | | { |
| 6 | 50 | | ownUserProfile.snapshotObserver.RemoveListener(view.UpdateAvatarSprite); |
| 6 | 51 | | closeWindow.OnTriggered -= OnCloseWindowPressed; |
| 6 | 52 | | ownUserProfile.OnAvatarExpressionSet -= OnAvatarEmoteSet; |
| 6 | 53 | | emotesVisible.OnChange -= OnEmoteVisibleChanged; |
| | 54 | |
|
| 6 | 55 | | if (view != null) |
| | 56 | | { |
| 6 | 57 | | view.CleanUp(); |
| 6 | 58 | | UnityEngine.Object.Destroy(view.gameObject); |
| | 59 | | } |
| 6 | 60 | | } |
| | 61 | |
|
| 4 | 62 | | public void EmoteCalled(string id) { UserProfile.GetOwnUserProfile().SetAvatarExpression(id); } |
| | 63 | |
|
| 0 | 64 | | private void OnViewClosed() { emotesVisible.Set(false); } |
| 4 | 65 | | private void OnAvatarEmoteSet(string id, long timestamp) { emotesVisible.Set(false); } |
| 0 | 66 | | private void OnCloseWindowPressed(DCLAction_Trigger action) { emotesVisible.Set(false); } |
| | 67 | | } |