| | 1 | | using System; |
| | 2 | | using TMPro; |
| | 3 | | using System.Collections.Generic; |
| | 4 | | using DCL.Controllers; |
| | 5 | | using DCL.Helpers; |
| | 6 | | using UnityEngine; |
| | 7 | | using UnityEngine.UI; |
| | 8 | | using DCL.TransactionHUDModel; |
| | 9 | | using UnityEngine.SocialPlatforms.Impl; |
| | 10 | | using Type = DCL.TransactionHUDModel.Type; |
| | 11 | |
|
| | 12 | | public class TransactionHUD : MonoBehaviour, ITransactionHUD |
| | 13 | | { |
| | 14 | | [SerializeField] private Button acceptButton; |
| | 15 | |
|
| | 16 | | [SerializeField] private Button rejectButton; |
| | 17 | |
|
| | 18 | | [SerializeField] private TMP_Text messageLabel; |
| | 19 | |
|
| 5 | 20 | | public Model model { get; private set; } = new Model(); |
| | 21 | |
|
| | 22 | | public event Action<ITransactionHUD> OnTransactionAccepted; |
| | 23 | |
|
| | 24 | | public event Action<ITransactionHUD> OnTransactionRejected; |
| | 25 | |
|
| | 26 | | private void OnEnable() |
| | 27 | | { |
| 4 | 28 | | acceptButton.onClick.AddListener(AcceptTransaction); |
| | 29 | |
|
| 4 | 30 | | rejectButton.onClick.AddListener(RejectTransaction); |
| 4 | 31 | | } |
| | 32 | |
|
| | 33 | | public IParcelScene FindScene(string sceneId) |
| | 34 | | { |
| 4 | 35 | | if (DCL.Environment.i.world?.state?.scenesSortedByDistance != null) |
| | 36 | | { |
| 0 | 37 | | foreach (IParcelScene scene in DCL.Environment.i.world.state.scenesSortedByDistance) |
| | 38 | | { |
| 0 | 39 | | if (scene.sceneData.id == sceneId) |
| 0 | 40 | | return scene; |
| | 41 | | } |
| | 42 | | } |
| | 43 | |
|
| 4 | 44 | | return null; |
| 0 | 45 | | } |
| | 46 | |
|
| | 47 | | private void OnDisable() |
| | 48 | | { |
| 4 | 49 | | acceptButton.onClick.RemoveAllListeners(); |
| 4 | 50 | | rejectButton.onClick.RemoveAllListeners(); |
| 4 | 51 | | } |
| | 52 | |
|
| | 53 | | private static string ShortAddress(string address) |
| | 54 | | { |
| 0 | 55 | | if (address == null) |
| 0 | 56 | | return "Null"; |
| | 57 | |
|
| 0 | 58 | | if (address.Length >= 12) |
| 0 | 59 | | return $"{address.Substring(0, 6)}...{address.Substring(address.Length - 4)}"; |
| | 60 | |
|
| 0 | 61 | | return address; |
| | 62 | | } |
| | 63 | |
|
| | 64 | | private void ShowSignMessage(Model model) |
| | 65 | | { |
| 4 | 66 | | var scene = FindScene(model.sceneId); |
| | 67 | |
|
| 4 | 68 | | if (scene != null) |
| | 69 | | { |
| 0 | 70 | | messageLabel.text = $"This scene {scene.sceneData.basePosition.ToString()} wants you to sign a message. Pres |
| | 71 | | } |
| 4 | 72 | | } |
| | 73 | |
|
| | 74 | | public void Show(Model model) |
| | 75 | | { |
| 4 | 76 | | if (Utils.IsCursorLocked) |
| 0 | 77 | | Utils.UnlockCursor(); |
| | 78 | |
|
| 4 | 79 | | this.model = model; |
| | 80 | |
|
| 4 | 81 | | ShowSignMessage(model); |
| 4 | 82 | | } |
| | 83 | |
|
| | 84 | | public void AcceptTransaction() |
| | 85 | | { |
| 0 | 86 | | OnTransactionAccepted?.Invoke(this); |
| 0 | 87 | | Destroy(gameObject); |
| 0 | 88 | | } |
| | 89 | |
|
| | 90 | | public void RejectTransaction() |
| | 91 | | { |
| 0 | 92 | | OnTransactionRejected?.Invoke(this); |
| 0 | 93 | | Destroy(gameObject); |
| 0 | 94 | | } |
| | 95 | | } |