| | 1 | | using DCL.Social.Chat; |
| | 2 | | using System; |
| | 3 | | using TMPro; |
| | 4 | | using UnityEngine; |
| | 5 | | using UnityEngine.UI; |
| | 6 | |
|
| | 7 | | namespace DCL.Social.Chat |
| | 8 | | { |
| | 9 | | public class CreateChannelWindowComponentView : BaseComponentView, ICreateChannelWindowView |
| | 10 | | { |
| | 11 | | [SerializeField] internal Button createButton; |
| | 12 | | [SerializeField] internal Button[] closeButtons; |
| | 13 | | [SerializeField] internal Button joinButton; |
| | 14 | | [SerializeField] internal TMP_InputField channelNameInput; |
| | 15 | | [SerializeField] internal GameObject channelExistsContainer; |
| | 16 | | [SerializeField] internal GameObject channelExistsWithJoinOptionContainer; |
| | 17 | | [SerializeField] internal GameObject specialCharactersErrorContainer; |
| | 18 | | [SerializeField] internal GameObject tooShortErrorContainer; |
| | 19 | | [SerializeField] internal GameObject exceededLimitErrorContainer; |
| | 20 | | [SerializeField] internal GameObject unknownErrorContainer; |
| | 21 | | [SerializeField] internal TMP_Text channelNameLengthLabel; |
| | 22 | | [SerializeField] internal GameObject inputFieldErrorBevel; |
| | 23 | | [SerializeField] internal Color errorColor; |
| | 24 | |
|
| | 25 | | private Color lengthLabelOriginalColor; |
| | 26 | |
|
| | 27 | | public event Action<string> OnChannelNameUpdated; |
| | 28 | | public event Action OnCreateSubmit; |
| | 29 | | public event Action OnClose; |
| | 30 | | public event Action OnJoinChannel; |
| | 31 | |
|
| | 32 | | public override void Awake() |
| | 33 | | { |
| 16 | 34 | | base.Awake(); |
| | 35 | |
|
| 17 | 36 | | createButton.onClick.AddListener(() => OnCreateSubmit?.Invoke()); |
| 16 | 37 | | channelNameInput.onValueChanged.AddListener(text => |
| | 38 | | { |
| 3 | 39 | | channelNameLengthLabel.text = $"{Mathf.Min(20, text.Length)}/20"; |
| 3 | 40 | | OnChannelNameUpdated?.Invoke(text); |
| 0 | 41 | | }); |
| 16 | 42 | | channelNameInput.onSubmit.AddListener(text => |
| | 43 | | { |
| 0 | 44 | | OnCreateSubmit?.Invoke(); |
| 0 | 45 | | }); |
| 96 | 46 | | foreach (var button in closeButtons) |
| 33 | 47 | | button.onClick.AddListener(() => OnClose?.Invoke()); |
| 17 | 48 | | joinButton.onClick.AddListener(() => OnJoinChannel?.Invoke()); |
| 16 | 49 | | lengthLabelOriginalColor = channelNameLengthLabel.color; |
| 16 | 50 | | } |
| | 51 | |
|
| | 52 | | public override void RefreshControl() |
| | 53 | | { |
| 0 | 54 | | throw new NotImplementedException(); |
| | 55 | | } |
| | 56 | |
|
| 0 | 57 | | public RectTransform Transform => (RectTransform) transform; |
| | 58 | |
|
| 2 | 59 | | public void Show() => gameObject.SetActive(true); |
| | 60 | |
|
| 2 | 61 | | public void Hide() => gameObject.SetActive(false); |
| | 62 | |
|
| | 63 | | public void ShowChannelExistsError(bool showJoinChannelOption) |
| | 64 | | { |
| 2 | 65 | | channelExistsContainer.SetActive(!showJoinChannelOption); |
| 2 | 66 | | channelExistsWithJoinOptionContainer.SetActive(showJoinChannelOption); |
| 2 | 67 | | inputFieldErrorBevel.SetActive(true); |
| 2 | 68 | | specialCharactersErrorContainer.SetActive(false); |
| 2 | 69 | | tooShortErrorContainer.SetActive(false); |
| 2 | 70 | | exceededLimitErrorContainer.SetActive(false); |
| 2 | 71 | | unknownErrorContainer.SetActive(false); |
| 2 | 72 | | channelNameLengthLabel.color = errorColor; |
| 2 | 73 | | } |
| | 74 | |
|
| | 75 | | public void ClearError() |
| | 76 | | { |
| 2 | 77 | | channelExistsContainer.SetActive(false); |
| 2 | 78 | | channelExistsWithJoinOptionContainer.SetActive(false); |
| 2 | 79 | | inputFieldErrorBevel.SetActive(false); |
| 2 | 80 | | specialCharactersErrorContainer.SetActive(false); |
| 2 | 81 | | tooShortErrorContainer.SetActive(false); |
| 2 | 82 | | exceededLimitErrorContainer.SetActive(false); |
| 2 | 83 | | unknownErrorContainer.SetActive(false); |
| 2 | 84 | | channelNameLengthLabel.color = lengthLabelOriginalColor; |
| 2 | 85 | | } |
| | 86 | |
|
| 2 | 87 | | public void DisableCreateButton() => createButton.interactable = false; |
| | 88 | |
|
| 2 | 89 | | public void EnableCreateButton() => createButton.interactable = true; |
| | 90 | |
|
| 1 | 91 | | public void ClearInputText() => channelNameInput.text = ""; |
| | 92 | |
|
| 1 | 93 | | public void FocusInputField() => channelNameInput.Select(); |
| | 94 | |
|
| | 95 | | public void ShowWrongFormatError() |
| | 96 | | { |
| 1 | 97 | | channelExistsContainer.SetActive(false); |
| 1 | 98 | | channelExistsWithJoinOptionContainer.SetActive(false); |
| 1 | 99 | | inputFieldErrorBevel.SetActive(true); |
| 1 | 100 | | specialCharactersErrorContainer.SetActive(true); |
| 1 | 101 | | tooShortErrorContainer.SetActive(false); |
| 1 | 102 | | exceededLimitErrorContainer.SetActive(false); |
| 1 | 103 | | unknownErrorContainer.SetActive(false); |
| 1 | 104 | | channelNameLengthLabel.color = errorColor; |
| 1 | 105 | | } |
| | 106 | |
|
| | 107 | | public void ShowTooShortError() |
| | 108 | | { |
| 0 | 109 | | channelExistsContainer.SetActive(false); |
| 0 | 110 | | channelExistsWithJoinOptionContainer.SetActive(false); |
| 0 | 111 | | inputFieldErrorBevel.SetActive(true); |
| 0 | 112 | | specialCharactersErrorContainer.SetActive(false); |
| 0 | 113 | | tooShortErrorContainer.SetActive(true); |
| 0 | 114 | | exceededLimitErrorContainer.SetActive(false); |
| 0 | 115 | | unknownErrorContainer.SetActive(false); |
| 0 | 116 | | channelNameLengthLabel.color = errorColor; |
| 0 | 117 | | } |
| | 118 | |
|
| | 119 | | public void ShowChannelsExceededError() |
| | 120 | | { |
| 1 | 121 | | channelExistsContainer.SetActive(false); |
| 1 | 122 | | channelExistsWithJoinOptionContainer.SetActive(false); |
| 1 | 123 | | inputFieldErrorBevel.SetActive(true); |
| 1 | 124 | | specialCharactersErrorContainer.SetActive(false); |
| 1 | 125 | | tooShortErrorContainer.SetActive(false); |
| 1 | 126 | | exceededLimitErrorContainer.SetActive(true); |
| 1 | 127 | | unknownErrorContainer.SetActive(false); |
| 1 | 128 | | channelNameLengthLabel.color = errorColor; |
| 1 | 129 | | } |
| | 130 | |
|
| | 131 | | public void ShowUnknownError() |
| | 132 | | { |
| 0 | 133 | | channelExistsContainer.SetActive(false); |
| 0 | 134 | | channelExistsWithJoinOptionContainer.SetActive(false); |
| 0 | 135 | | inputFieldErrorBevel.SetActive(true); |
| 0 | 136 | | specialCharactersErrorContainer.SetActive(false); |
| 0 | 137 | | tooShortErrorContainer.SetActive(false); |
| 0 | 138 | | exceededLimitErrorContainer.SetActive(false); |
| 0 | 139 | | unknownErrorContainer.SetActive(true); |
| 0 | 140 | | channelNameLengthLabel.color = errorColor; |
| 0 | 141 | | } |
| | 142 | | } |
| | 143 | | } |