| | 1 | | using System; |
| | 2 | | using DCL; |
| | 3 | | using UnityEngine; |
| | 4 | |
|
| | 5 | | public class EmotesHUDController : IHUD |
| | 6 | | { |
| | 7 | | internal EmotesHUDView view; |
| 20 | 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.OnAvatarEmoteSet += 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 | | { |
| | 43 | | // Avoid locking cursor. It produces undesired mouse locking the first time you gain focus in the window |
| | 44 | | // during loading screen or first avatar creation |
| | 45 | | //DCL.Helpers.Utils.LockCursor(); |
| 7 | 46 | | ownUserProfile.snapshotObserver.RemoveListener(view.UpdateAvatarSprite); |
| | 47 | | } |
| 7 | 48 | | } |
| | 49 | |
|
| | 50 | | public void Dispose() |
| | 51 | | { |
| 6 | 52 | | ownUserProfile.snapshotObserver.RemoveListener(view.UpdateAvatarSprite); |
| 6 | 53 | | closeWindow.OnTriggered -= OnCloseWindowPressed; |
| 6 | 54 | | ownUserProfile.OnAvatarEmoteSet -= OnAvatarEmoteSet; |
| 6 | 55 | | emotesVisible.OnChange -= OnEmoteVisibleChanged; |
| | 56 | |
|
| 6 | 57 | | if (view != null) |
| | 58 | | { |
| 6 | 59 | | view.CleanUp(); |
| 6 | 60 | | UnityEngine.Object.Destroy(view.gameObject); |
| | 61 | | } |
| 6 | 62 | | } |
| | 63 | |
|
| 4 | 64 | | public void EmoteCalled(string id) { UserProfile.GetOwnUserProfile().SetAvatarExpression(id); } |
| | 65 | |
|
| 0 | 66 | | private void OnViewClosed() { emotesVisible.Set(false); } |
| 4 | 67 | | private void OnAvatarEmoteSet(string id, long timestamp) { emotesVisible.Set(false); } |
| 0 | 68 | | private void OnCloseWindowPressed(DCLAction_Trigger action) { emotesVisible.Set(false); } |
| | 69 | | } |