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