| | 1 | | using System; |
| | 2 | | using TMPro; |
| | 3 | | using UIComponents.Scripts.Components; |
| | 4 | | using UnityEngine; |
| | 5 | | using UnityEngine.EventSystems; |
| | 6 | | using UnityEngine.UI; |
| | 7 | |
|
| | 8 | | namespace DCL.Quests |
| | 9 | | { |
| | 10 | | public class ActiveQuestComponentView : BaseComponentView<ActiveQuestComponentModel>, IActiveQuestComponentView, IPo |
| | 11 | | { |
| | 12 | | [SerializeField] internal TMP_Text questName; |
| | 13 | | [SerializeField] internal TMP_Text questCreator; |
| | 14 | | [SerializeField] internal GameObject pinnedIcon; |
| | 15 | | [SerializeField] internal GameObject focusOutline; |
| | 16 | | [SerializeField] internal GameObject selectedOutline; |
| | 17 | | [SerializeField] internal Image background; |
| | 18 | | [SerializeField] internal Image imageBackground; |
| | 19 | | [SerializeField] internal ImageComponentView backgroundImage; |
| | 20 | |
|
| | 21 | | [SerializeField] internal Color deselectedNameColor; |
| | 22 | | [SerializeField] internal Color selectedNameColor; |
| | 23 | | [SerializeField] internal Color deselectedCreatorColor; |
| | 24 | | [SerializeField] internal Color selectedCreatorColor; |
| | 25 | | [SerializeField] internal Color selectedBackgroundColor; |
| | 26 | | [SerializeField] internal Color deselectedBackgroundColor; |
| | 27 | | [SerializeField] internal Color deselectedBackgroundColorTransparent; |
| | 28 | |
|
| | 29 | | public event Action<QuestDetailsComponentModel> OnActiveQuestSelected; |
| | 30 | |
|
| | 31 | | internal bool isSelected = false; |
| | 32 | |
|
| | 33 | | public override void RefreshControl() |
| | 34 | | { |
| 0 | 35 | | Deselect(); |
| 0 | 36 | | SetQuestName(model.questName); |
| 0 | 37 | | SetQuestCreator(model.questCreator); |
| 0 | 38 | | SetQuestId(model.questId); |
| 0 | 39 | | SetIsPinned(model.isPinned); |
| 0 | 40 | | SetQuestImage(model.questImageUri); |
| 0 | 41 | | SetQuestDetailsModel(model.questModel); |
| 0 | 42 | | } |
| | 43 | |
|
| | 44 | | public void SetQuestDetailsModel(QuestDetailsComponentModel questDetailsComponentModel) => |
| 1 | 45 | | model.questModel = questDetailsComponentModel; |
| | 46 | |
|
| | 47 | | public void SetQuestName(string title) |
| | 48 | | { |
| 1 | 49 | | model.questName = title; |
| 1 | 50 | | questName.text = title; |
| 1 | 51 | | } |
| | 52 | |
|
| | 53 | | public void SetQuestCreator(string creator) |
| | 54 | | { |
| 1 | 55 | | model.questCreator = creator; |
| 1 | 56 | | questCreator.text = creator; |
| 1 | 57 | | model.questModel.questCreator = creator; |
| 1 | 58 | | } |
| | 59 | |
|
| | 60 | | public void SetQuestId(string questId) => |
| 0 | 61 | | model.questId = questId; |
| | 62 | |
|
| | 63 | | public void SetIsPinned(bool isPinned) |
| | 64 | | { |
| 2 | 65 | | model.isPinned = isPinned; |
| 2 | 66 | | pinnedIcon.SetActive(isPinned); |
| 2 | 67 | | } |
| | 68 | |
|
| | 69 | | public void SetQuestImage(string imageUri) |
| | 70 | | { |
| 0 | 71 | | model.questImageUri = imageUri; |
| 0 | 72 | | backgroundImage.SetImage(imageUri); |
| 0 | 73 | | } |
| | 74 | |
|
| | 75 | | public void Deselect() |
| | 76 | | { |
| 1 | 77 | | isSelected = false; |
| 1 | 78 | | selectedOutline.SetActive(false); |
| 1 | 79 | | questName.color = deselectedNameColor; |
| 1 | 80 | | questCreator.color = deselectedCreatorColor; |
| 1 | 81 | | background.color = deselectedBackgroundColorTransparent; |
| 1 | 82 | | imageBackground.color = deselectedBackgroundColor; |
| 1 | 83 | | } |
| | 84 | |
|
| | 85 | | public override void OnFocus() |
| | 86 | | { |
| 1 | 87 | | if (isSelected) return; |
| | 88 | |
|
| 1 | 89 | | focusOutline.SetActive(true); |
| 1 | 90 | | } |
| | 91 | |
|
| | 92 | | public override void OnLoseFocus() => |
| 9 | 93 | | focusOutline.SetActive(false); |
| | 94 | |
|
| | 95 | | public void OnPointerClick(PointerEventData eventData) |
| | 96 | | { |
| 1 | 97 | | OnActiveQuestSelected?.Invoke(model.questModel); |
| 1 | 98 | | isSelected = true; |
| 1 | 99 | | focusOutline.SetActive(false); |
| 1 | 100 | | selectedOutline.SetActive(true); |
| 1 | 101 | | questName.color = selectedNameColor; |
| 1 | 102 | | questCreator.color = selectedCreatorColor; |
| 1 | 103 | | background.color = selectedBackgroundColor; |
| 1 | 104 | | imageBackground.color = selectedBackgroundColor; |
| 1 | 105 | | } |
| | 106 | | } |
| | 107 | | } |