| | 1 | | using System; |
| | 2 | | using DCL.TransactionHUDModel; |
| | 3 | | using UnityEngine; |
| | 4 | |
|
| | 5 | | public class TransactionListHUDView : MonoBehaviour |
| | 6 | | { |
| | 7 | | [SerializeField] |
| | 8 | | private RectTransform transactionPanel; |
| | 9 | |
|
| | 10 | | public event Action<ITransactionHUD> OnTransactionAcceptedEvent; |
| | 11 | | public event Action<ITransactionHUD> OnTransactionRejectedEvent; |
| | 12 | |
|
| | 13 | | private const string VIEW_PATH = "TransactionListHUD"; |
| | 14 | | private const string VIEW_CHILD_PATH = "TransactionHUD"; |
| | 15 | | private const string VIEW_OBJECT_NAME = "_TransactionListHUD"; |
| | 16 | |
|
| | 17 | | internal static TransactionListHUDView Create() |
| | 18 | | { |
| 3 | 19 | | TransactionListHUDView view = Instantiate(Resources.Load<TransactionListHUDView>(VIEW_PATH)); |
| 3 | 20 | | view.Initialize(); |
| 3 | 21 | | return view; |
| | 22 | | } |
| | 23 | |
|
| 6 | 24 | | private void Initialize() { gameObject.name = VIEW_OBJECT_NAME; } |
| | 25 | |
|
| | 26 | | public void ShowTransaction(ITransactionHUD transaction, Model model = null) |
| | 27 | | { |
| 4 | 28 | | transaction.OnTransactionAccepted += OnTransactionAccepted; |
| 4 | 29 | | transaction.OnTransactionRejected += OnTransactionRejected; |
| | 30 | |
|
| 4 | 31 | | if (model != null) |
| 4 | 32 | | transaction.Show(model); |
| 4 | 33 | | } |
| | 34 | |
|
| | 35 | | public TransactionHUD ShowTransaction(Model transactionModel) |
| | 36 | | { |
| 4 | 37 | | if (transactionModel == null) |
| 0 | 38 | | return null; |
| | 39 | |
|
| 4 | 40 | | TransactionHUD transactionHUD = Instantiate(Resources.Load<TransactionHUD>(VIEW_CHILD_PATH), transactionPanel); |
| 4 | 41 | | ShowTransaction(transactionHUD, transactionModel); |
| 4 | 42 | | return transactionHUD; |
| | 43 | | } |
| | 44 | |
|
| | 45 | | private void OnTransactionAccepted(ITransactionHUD transaction) |
| | 46 | | { |
| 0 | 47 | | OnTransactionAcceptedEvent?.Invoke(transaction); |
| 0 | 48 | | } |
| | 49 | |
|
| | 50 | | private void OnTransactionRejected(ITransactionHUD transaction) |
| | 51 | | { |
| 0 | 52 | | OnTransactionRejectedEvent?.Invoke(transaction); |
| 0 | 53 | | } |
| | 54 | |
|
| 0 | 55 | | public void SetActive(bool active) { gameObject.SetActive(active); } |
| | 56 | | } |