| | 1 | | using DCL.Controllers; |
| | 2 | | using System; |
| | 3 | | using System.Collections.Generic; |
| | 4 | | using TMPro; |
| | 5 | | using UnityEngine; |
| | 6 | | using UnityEngine.UI; |
| | 7 | |
|
| | 8 | | namespace DCL.ContentModeration |
| | 9 | | { |
| | 10 | | public class ContentModerationReportingComponentView : BaseComponentView, IContentModerationReportingComponentView |
| | 11 | | { |
| | 12 | | [Header("REFERENCES")] |
| | 13 | | [SerializeField] private TMP_Text titleText; |
| | 14 | | [SerializeField] private Button backgroundButton; |
| | 15 | | [SerializeField] private ButtonComponentView cancelButton; |
| | 16 | | [SerializeField] private ButtonComponentView gotItButton1; |
| | 17 | | [SerializeField] private ButtonComponentView gotItButton2; |
| | 18 | | [SerializeField] private ButtonComponentView sendButton; |
| | 19 | | [SerializeField] private Button learnMoreButton; |
| | 20 | | [SerializeField] private ContentModerationRatingButtonComponentView teenRatingButton; |
| | 21 | | [SerializeField] private ContentModerationRatingButtonComponentView adultRatingButton; |
| | 22 | | [SerializeField] private ContentModerationRatingButtonComponentView restrictedRatingButton; |
| | 23 | | [SerializeField] private GameObject optionsSectionContainer; |
| | 24 | | [SerializeField] private TMP_Text optionsSectionTitle; |
| | 25 | | [SerializeField] private TMP_Text optionsSectionSubtitle; |
| | 26 | | [SerializeField] private GameObject markedRatingInfoContainer; |
| | 27 | | [SerializeField] private TMP_Text markedRatingInfoTitle; |
| | 28 | | [SerializeField] private TMP_Text markedRatingInfoDescription; |
| | 29 | | [SerializeField] private Transform optionsContainer; |
| | 30 | | [SerializeField] private ScrollRect optionsScroll; |
| | 31 | | [SerializeField] private GameObject mainModal; |
| | 32 | | [SerializeField] private GameObject mainFormSection; |
| | 33 | | [SerializeField] private GameObject loadingStateSection; |
| | 34 | | [SerializeField] private GameObject reportSentModal; |
| | 35 | | [SerializeField] private Image modalHeaderImage; |
| | 36 | |
|
| | 37 | | [Header("TEEN CONFIGURATION")] |
| | 38 | | [SerializeField] private Sprite teenHeaderSprite; |
| | 39 | | [SerializeField] private string teenOptionTitle; |
| | 40 | | [SerializeField] private string teenOptionSubtitle; |
| | 41 | | [SerializeField] private List<string> teenOptions; |
| | 42 | | [SerializeField] private string teenDescription; |
| | 43 | |
|
| | 44 | | [Header("ADULT CONFIGURATION")] |
| | 45 | | [SerializeField] private Sprite adultHeaderSprite; |
| | 46 | | [SerializeField] private string adultOptionTitle; |
| | 47 | | [SerializeField] private string adultOptionSubtitle; |
| | 48 | | [SerializeField] private List<string> adultOptions; |
| | 49 | | [SerializeField] private string adultDescription; |
| | 50 | |
|
| | 51 | | [Header("RESTRICTED CONFIGURATION")] |
| | 52 | | [SerializeField] private Sprite restrictedHeaderSprite; |
| | 53 | | [SerializeField] private string restrictedOptionTitle; |
| | 54 | | [SerializeField] private string restrictedOptionSubtitle; |
| | 55 | | [SerializeField] private List<string> restrictedOptions; |
| | 56 | | [SerializeField] private string restrictedDescription; |
| | 57 | |
|
| | 58 | | [Header("PREFABS")] |
| | 59 | | [SerializeField] private GameObject optionButtonPrefab; |
| | 60 | | [SerializeField] private GameObject commentsPrefab; |
| | 61 | |
|
| 0 | 62 | | private readonly List<ContentModerationReportingOptionComponentView> teenOptionButtons = new (); |
| 0 | 63 | | private readonly List<ContentModerationReportingOptionComponentView> adultOptionButtons = new (); |
| 0 | 64 | | private readonly List<ContentModerationReportingOptionComponentView> restrictedOptionButtons = new (); |
| | 65 | | private SceneContentCategory currentMarkedRating; |
| | 66 | | private SceneContentCategory currentRating; |
| 0 | 67 | | private readonly List<string> selectedOptions = new (); |
| | 68 | | private TMP_InputField commentsInput; |
| | 69 | | private bool isLoadingActive; |
| | 70 | | private string currentSceneName; |
| | 71 | |
|
| | 72 | | public event Action<bool> OnPanelClosed; |
| | 73 | | public event Action<(SceneContentCategory contentCategory, List<string> issues, string comments)> OnSendClicked; |
| | 74 | | public event Action OnLearnMoreClicked; |
| | 75 | |
|
| | 76 | | public override void Awake() |
| | 77 | | { |
| 0 | 78 | | base.Awake(); |
| 0 | 79 | | backgroundButton.onClick.AddListener(() => HidePanel(!reportSentModal.activeSelf)); |
| 0 | 80 | | cancelButton.onClick.AddListener(() => HidePanel(true)); |
| 0 | 81 | | gotItButton1.onClick.AddListener(() => HidePanel(false)); |
| 0 | 82 | | gotItButton2.onClick.AddListener(() => HidePanel(false)); |
| 0 | 83 | | sendButton.onClick.AddListener(() => SendReport((currentRating, selectedOptions, commentsInput.text))); |
| 0 | 84 | | learnMoreButton.onClick.AddListener(GoToLearnMore); |
| 0 | 85 | | teenRatingButton.RatingButton.onClick.AddListener(() => SetRating(SceneContentCategory.TEEN)); |
| 0 | 86 | | adultRatingButton.RatingButton.onClick.AddListener(() => SetRating(SceneContentCategory.ADULT)); |
| 0 | 87 | | restrictedRatingButton.RatingButton.onClick.AddListener(() => SetRating(SceneContentCategory.RESTRICTED)); |
| | 88 | |
|
| 0 | 89 | | CreateButtons(); |
| 0 | 90 | | } |
| | 91 | |
|
| | 92 | | public override void Dispose() |
| | 93 | | { |
| 0 | 94 | | backgroundButton.onClick.RemoveAllListeners(); |
| 0 | 95 | | cancelButton.onClick.RemoveAllListeners(); |
| 0 | 96 | | gotItButton1.onClick.RemoveAllListeners(); |
| 0 | 97 | | gotItButton2.onClick.RemoveAllListeners(); |
| 0 | 98 | | sendButton.onClick.RemoveAllListeners(); |
| 0 | 99 | | learnMoreButton.onClick.RemoveAllListeners(); |
| 0 | 100 | | teenRatingButton.RatingButton.onClick.RemoveAllListeners(); |
| 0 | 101 | | adultRatingButton.RatingButton.onClick.RemoveAllListeners(); |
| 0 | 102 | | restrictedRatingButton.RatingButton.onClick.RemoveAllListeners(); |
| 0 | 103 | | base.Dispose(); |
| 0 | 104 | | } |
| | 105 | |
|
| 0 | 106 | | public override void RefreshControl() { } |
| | 107 | |
|
| | 108 | | public void ShowPanel() |
| | 109 | | { |
| 0 | 110 | | Show(); |
| 0 | 111 | | SetLoadingState(false); |
| 0 | 112 | | SetPanelAsSent(false); |
| 0 | 113 | | ResetOptions(); |
| 0 | 114 | | } |
| | 115 | |
|
| | 116 | | public void HidePanel(bool isCancelled) |
| | 117 | | { |
| 0 | 118 | | if (isLoadingActive || !isVisible) |
| 0 | 119 | | return; |
| | 120 | |
|
| 0 | 121 | | Hide(); |
| 0 | 122 | | OnPanelClosed?.Invoke(isCancelled); |
| 0 | 123 | | } |
| | 124 | |
|
| | 125 | | public void SetScene(string sceneName) => |
| 0 | 126 | | currentSceneName = sceneName; |
| | 127 | |
|
| | 128 | | public void SetRatingAsMarked(SceneContentCategory contentCategory) |
| | 129 | | { |
| 0 | 130 | | currentMarkedRating = contentCategory; |
| | 131 | |
|
| 0 | 132 | | modalHeaderImage.sprite = contentCategory switch |
| | 133 | | { |
| 0 | 134 | | SceneContentCategory.TEEN => teenHeaderSprite, |
| 0 | 135 | | SceneContentCategory.ADULT => adultHeaderSprite, |
| 0 | 136 | | SceneContentCategory.RESTRICTED => restrictedHeaderSprite, |
| 0 | 137 | | _ => teenHeaderSprite, |
| | 138 | | }; |
| | 139 | |
|
| 0 | 140 | | teenRatingButton.SetCurrentMarkActive(contentCategory == SceneContentCategory.TEEN); |
| 0 | 141 | | adultRatingButton.SetCurrentMarkActive(contentCategory == SceneContentCategory.ADULT); |
| 0 | 142 | | restrictedRatingButton.SetCurrentMarkActive(contentCategory == SceneContentCategory.RESTRICTED); |
| 0 | 143 | | } |
| | 144 | |
|
| | 145 | | public void SetRating(SceneContentCategory contentCategory) |
| | 146 | | { |
| 0 | 147 | | currentRating = contentCategory; |
| | 148 | |
|
| 0 | 149 | | selectedOptions.Clear(); |
| | 150 | |
|
| 0 | 151 | | teenRatingButton.Select(contentCategory == SceneContentCategory.TEEN); |
| 0 | 152 | | adultRatingButton.Select(contentCategory == SceneContentCategory.ADULT); |
| 0 | 153 | | restrictedRatingButton.Select(contentCategory == SceneContentCategory.RESTRICTED); |
| | 154 | |
|
| 0 | 155 | | markedRatingInfoContainer.SetActive((contentCategory == SceneContentCategory.TEEN && teenRatingButton.IsMark |
| | 156 | | (contentCategory == SceneContentCategory.ADULT && adultRatingButton.IsMa |
| | 157 | | (contentCategory == SceneContentCategory.RESTRICTED && restrictedRatingB |
| 0 | 158 | | optionsSectionContainer.SetActive((contentCategory == SceneContentCategory.TEEN && !teenRatingButton.IsMarke |
| | 159 | | (contentCategory == SceneContentCategory.ADULT && !adultRatingButton.IsMar |
| | 160 | | (contentCategory == SceneContentCategory.RESTRICTED && !restrictedRatingBu |
| | 161 | |
|
| 0 | 162 | | gotItButton1.gameObject.SetActive(markedRatingInfoContainer.activeSelf); |
| 0 | 163 | | sendButton.gameObject.SetActive(!markedRatingInfoContainer.activeSelf); |
| | 164 | |
|
| | 165 | | switch (contentCategory) |
| | 166 | | { |
| | 167 | | default: |
| | 168 | | case SceneContentCategory.TEEN: |
| 0 | 169 | | optionsSectionTitle.text = teenOptionTitle; |
| 0 | 170 | | optionsSectionSubtitle.text = teenOptionSubtitle; |
| 0 | 171 | | markedRatingInfoTitle.text = teenOptionTitle; |
| 0 | 172 | | markedRatingInfoDescription.text = teenDescription; |
| 0 | 173 | | break; |
| | 174 | | case SceneContentCategory.ADULT: |
| 0 | 175 | | optionsSectionTitle.text = adultOptionTitle; |
| 0 | 176 | | optionsSectionSubtitle.text = adultOptionSubtitle; |
| 0 | 177 | | markedRatingInfoTitle.text = adultOptionTitle; |
| 0 | 178 | | markedRatingInfoDescription.text = adultDescription; |
| 0 | 179 | | break; |
| | 180 | | case SceneContentCategory.RESTRICTED: |
| 0 | 181 | | optionsSectionTitle.text = restrictedOptionTitle; |
| 0 | 182 | | optionsSectionSubtitle.text = restrictedOptionSubtitle; |
| 0 | 183 | | markedRatingInfoTitle.text = restrictedOptionTitle; |
| 0 | 184 | | markedRatingInfoDescription.text = restrictedDescription; |
| | 185 | | break; |
| | 186 | | } |
| | 187 | |
|
| 0 | 188 | | foreach (ContentModerationReportingOptionComponentView option in teenOptionButtons) |
| 0 | 189 | | option.SetActive((int)contentCategory == 0); |
| 0 | 190 | | foreach (ContentModerationReportingOptionComponentView option in adultOptionButtons) |
| 0 | 191 | | option.SetActive((int)contentCategory == 1); |
| 0 | 192 | | foreach (ContentModerationReportingOptionComponentView option in restrictedOptionButtons) |
| 0 | 193 | | option.SetActive((int)contentCategory == 2); |
| | 194 | |
|
| 0 | 195 | | ResetOptions(); |
| 0 | 196 | | SetTitle(); |
| 0 | 197 | | } |
| | 198 | |
|
| | 199 | | public void SetLoadingState(bool isLoading) |
| | 200 | | { |
| 0 | 201 | | mainFormSection.SetActive(!isLoading); |
| 0 | 202 | | loadingStateSection.SetActive(isLoading); |
| 0 | 203 | | isLoadingActive = isLoading; |
| 0 | 204 | | } |
| | 205 | |
|
| | 206 | | public void SetPanelAsSent(bool hasBeenSent) |
| | 207 | | { |
| 0 | 208 | | mainModal.SetActive(!hasBeenSent); |
| 0 | 209 | | reportSentModal.SetActive(hasBeenSent); |
| 0 | 210 | | } |
| | 211 | |
|
| | 212 | | public void ResetPanelState() |
| | 213 | | { |
| 0 | 214 | | mainFormSection.SetActive(true); |
| 0 | 215 | | loadingStateSection.SetActive(false); |
| 0 | 216 | | isLoadingActive = false; |
| 0 | 217 | | } |
| | 218 | |
|
| | 219 | | private void CreateButtons() |
| | 220 | | { |
| 0 | 221 | | foreach (string option in teenOptions) |
| | 222 | | { |
| 0 | 223 | | ContentModerationReportingOptionComponentView optionComponent = InstantiateOptionButton(option); |
| 0 | 224 | | teenOptionButtons.Add(optionComponent); |
| | 225 | | } |
| | 226 | |
|
| 0 | 227 | | foreach (string option in adultOptions) |
| | 228 | | { |
| 0 | 229 | | ContentModerationReportingOptionComponentView optionComponent = InstantiateOptionButton(option); |
| 0 | 230 | | adultOptionButtons.Add(optionComponent); |
| | 231 | | } |
| | 232 | |
|
| 0 | 233 | | foreach (string option in restrictedOptions) |
| | 234 | | { |
| 0 | 235 | | ContentModerationReportingOptionComponentView optionComponent = InstantiateOptionButton(option); |
| 0 | 236 | | restrictedOptionButtons.Add(optionComponent); |
| | 237 | | } |
| | 238 | |
|
| 0 | 239 | | commentsInput = InstantiateCommentsBox(); |
| 0 | 240 | | } |
| | 241 | |
|
| | 242 | | private ContentModerationReportingOptionComponentView InstantiateOptionButton(string option) |
| | 243 | | { |
| 0 | 244 | | ContentModerationReportingOptionComponentView optionComponent = Instantiate(optionButtonPrefab, optionsConta |
| | 245 | | .GetComponent<ContentModerationReportingOptionComponentView>(); |
| 0 | 246 | | optionComponent.SetOptionText(option); |
| 0 | 247 | | optionComponent.UnselectOption(); |
| | 248 | |
|
| 0 | 249 | | optionComponent.OptionButton.onClick.AddListener(() => |
| | 250 | | { |
| 0 | 251 | | if (!selectedOptions.Contains(option)) |
| | 252 | | { |
| 0 | 253 | | selectedOptions.Add(option); |
| 0 | 254 | | optionComponent.SelectOption(); |
| | 255 | | } |
| | 256 | | else |
| | 257 | | { |
| 0 | 258 | | selectedOptions.Remove(option); |
| 0 | 259 | | optionComponent.UnselectOption(); |
| | 260 | | } |
| | 261 | |
|
| 0 | 262 | | SetSendButtonInteractable(selectedOptions.Count > 0); |
| 0 | 263 | | }); |
| | 264 | |
|
| 0 | 265 | | return optionComponent; |
| | 266 | | } |
| | 267 | |
|
| | 268 | | private TMP_InputField InstantiateCommentsBox() |
| | 269 | | { |
| 0 | 270 | | GameObject commentsObject = Instantiate(commentsPrefab, optionsContainer); |
| 0 | 271 | | return commentsObject.GetComponentInChildren<TMP_InputField>(); |
| | 272 | | } |
| | 273 | |
|
| | 274 | | private void ResetOptions() |
| | 275 | | { |
| 0 | 276 | | foreach (ContentModerationReportingOptionComponentView option in teenOptionButtons) |
| 0 | 277 | | option.UnselectOption(); |
| 0 | 278 | | foreach (ContentModerationReportingOptionComponentView option in adultOptionButtons) |
| 0 | 279 | | option.UnselectOption(); |
| 0 | 280 | | foreach (ContentModerationReportingOptionComponentView option in restrictedOptionButtons) |
| 0 | 281 | | option.UnselectOption(); |
| | 282 | |
|
| 0 | 283 | | selectedOptions.Clear(); |
| 0 | 284 | | optionsScroll.verticalNormalizedPosition = 1f; |
| 0 | 285 | | commentsInput.text = string.Empty; |
| 0 | 286 | | SetSendButtonInteractable(false); |
| 0 | 287 | | } |
| | 288 | |
|
| | 289 | | private void SetTitle() |
| | 290 | | { |
| 0 | 291 | | titleText.text = currentMarkedRating == currentRating |
| | 292 | | ? $"{currentSceneName} has been rated as" |
| | 293 | | : $"Flag {currentSceneName} for Rating Review"; |
| 0 | 294 | | } |
| | 295 | |
|
| | 296 | | private void SetSendButtonInteractable(bool isInteractable) => |
| 0 | 297 | | sendButton.SetInteractable(isInteractable); |
| | 298 | |
|
| | 299 | | private void SendReport((SceneContentCategory contentCategory, List<string> issues, string comments) report) => |
| 0 | 300 | | OnSendClicked?.Invoke(report); |
| | 301 | |
|
| | 302 | | private void GoToLearnMore() => |
| 0 | 303 | | OnLearnMoreClicked?.Invoke(); |
| | 304 | | } |
| | 305 | | } |