| | 1 | | using DCL.Helpers; |
| | 2 | | using TMPro; |
| | 3 | | using UnityEngine; |
| | 4 | | using UnityEngine.Events; |
| | 5 | | using UnityEngine.UI; |
| | 6 | |
|
| | 7 | | public class AirdroppingHUDView : MonoBehaviour |
| | 8 | | { |
| | 9 | | private const string VIEW_PATH = "AirdroppingHUD"; |
| | 10 | |
|
| | 11 | | [SerializeField] internal GenericFactory collectiblesFactory; |
| | 12 | | [SerializeField] internal GenericFactory erc20Factory; |
| | 13 | |
|
| | 14 | | [SerializeField] internal GameObject content; |
| | 15 | |
|
| | 16 | | [Header("Initial Screen")] |
| | 17 | | [SerializeField] internal GameObject initialScreen; |
| | 18 | | [SerializeField] internal TextMeshProUGUI initialScreenTitle; |
| | 19 | | [SerializeField] internal TextMeshProUGUI initialScreenSubtitle; |
| | 20 | | [SerializeField] internal Button initialScreenDoneButton; |
| | 21 | |
|
| | 22 | | [Header("Single Item Screen")] |
| | 23 | | [SerializeField] internal GameObject singleItemScreen; |
| | 24 | | [SerializeField] internal GameObject singleItemContainer; |
| | 25 | | [SerializeField] internal Button singleItemDoneButton; |
| | 26 | | [SerializeField] internal TextMeshProUGUI itemsLeft; |
| | 27 | |
|
| | 28 | | [Header("Summary Screen")] |
| | 29 | | [SerializeField] internal GameObject summaryScreen; |
| | 30 | | [SerializeField] internal GameObject summaryItemsContainer; |
| | 31 | | [SerializeField] internal Button summaryDoneButton; |
| | 32 | |
|
| | 33 | | [Header("Summary No Items Screen")] |
| | 34 | | [SerializeField] internal GameObject summaryNoItemsScreen; |
| | 35 | | [SerializeField] internal Button summaryNoItemsDoneButton; |
| | 36 | |
|
| 8 | 37 | | internal static AirdroppingHUDView Create() { return Instantiate(Resources.Load<GameObject>(VIEW_PATH)).GetComponent |
| | 38 | |
|
| | 39 | | public void Initialize(UnityAction nextStateCallback) |
| | 40 | | { |
| 8 | 41 | | initialScreenDoneButton.onClick.RemoveAllListeners(); |
| 8 | 42 | | initialScreenDoneButton.onClick.AddListener(nextStateCallback); |
| | 43 | |
|
| 8 | 44 | | singleItemDoneButton.onClick.RemoveAllListeners(); |
| 8 | 45 | | singleItemDoneButton.onClick.AddListener(nextStateCallback); |
| | 46 | |
|
| 8 | 47 | | summaryDoneButton.onClick.RemoveAllListeners(); |
| 8 | 48 | | summaryDoneButton.onClick.AddListener(nextStateCallback); |
| | 49 | |
|
| 8 | 50 | | summaryNoItemsDoneButton.onClick.RemoveAllListeners(); |
| 8 | 51 | | summaryNoItemsDoneButton.onClick.AddListener(nextStateCallback); |
| | 52 | |
|
| 8 | 53 | | CleanState(); |
| 8 | 54 | | } |
| | 55 | |
|
| | 56 | | public void ShowInitialScreen(string title, string subtitle) |
| | 57 | | { |
| 4 | 58 | | CleanState(); |
| 4 | 59 | | initialScreen.SetActive(true); |
| 4 | 60 | | initialScreenTitle.text = title; |
| 4 | 61 | | initialScreenSubtitle.text = subtitle; |
| 4 | 62 | | } |
| | 63 | |
|
| | 64 | | public void ShowItemScreen(AirdroppingHUDController.ItemModel model, int itemsleft) |
| | 65 | | { |
| 3 | 66 | | CleanState(); |
| 3 | 67 | | singleItemScreen.SetActive(true); |
| 3 | 68 | | itemsLeft.text = itemsleft.ToString(); |
| 3 | 69 | | CreateItemPanel(singleItemContainer.transform, model).SetData(model.name, model.subtitle, model.thumbnailURL); |
| 3 | 70 | | } |
| | 71 | |
|
| | 72 | | public void ShowSummaryScreen(AirdroppingHUDController.ItemModel[] items) |
| | 73 | | { |
| 2 | 74 | | CleanState(); |
| 2 | 75 | | summaryScreen.SetActive(true); |
| 12 | 76 | | for (int index = 0; index < items.Length; index++) |
| | 77 | | { |
| 4 | 78 | | var item = items[index]; |
| 4 | 79 | | CreateItemPanel(summaryItemsContainer.transform, items[index]).SetData(item.name, item.subtitle, item.thumbn |
| | 80 | | } |
| 2 | 81 | | } |
| | 82 | |
|
| | 83 | | public void ShowSummaryNoItemsScreen() |
| | 84 | | { |
| 1 | 85 | | CleanState(); |
| 1 | 86 | | summaryNoItemsScreen.SetActive(true); |
| 1 | 87 | | } |
| | 88 | |
|
| | 89 | | public void CleanState() |
| | 90 | | { |
| 19 | 91 | | initialScreen.SetActive(false); |
| | 92 | |
|
| 19 | 93 | | singleItemScreen.SetActive(false); |
| 19 | 94 | | singleItemContainer.transform.DestroyAllChild(); |
| | 95 | |
|
| 19 | 96 | | summaryScreen.SetActive(false); |
| 19 | 97 | | summaryItemsContainer.transform.DestroyAllChild(); |
| | 98 | |
|
| 19 | 99 | | summaryNoItemsScreen.SetActive(false); |
| 19 | 100 | | } |
| | 101 | |
|
| 26 | 102 | | public void SetContentActive(bool active) { content.SetActive(active); } |
| | 103 | |
|
| 2 | 104 | | public void SetVisibility(bool active) { gameObject.SetActive(active); } |
| | 105 | |
|
| | 106 | | private AirdroppingItemPanel CreateItemPanel(Transform parent, AirdroppingHUDController.ItemModel model) |
| | 107 | | { |
| 7 | 108 | | AirdroppingItemPanel item = null; |
| 7 | 109 | | if (model.type == "collectible") |
| | 110 | | { |
| 7 | 111 | | item = collectiblesFactory.Instantiate<AirdroppingItemPanel>(model.rarity, parent); |
| | 112 | | } |
| | 113 | |
|
| 7 | 114 | | if (model.type == "erc20") |
| | 115 | | { |
| 0 | 116 | | item = erc20Factory.Instantiate<AirdroppingItemPanel>(model.rarity, parent); |
| | 117 | | } |
| | 118 | |
|
| 7 | 119 | | return item; |
| | 120 | | } |
| | 121 | | } |