123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189 |
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- using UnityEngine.UI;
- public class FashionShowCommentPanel : Regist
- {
- #region Config
- private static Text NicknameTitle;
- private static Text ContentTitle;
- private static Text Title;
- private static Text CloseButtonText;
- private static Text SendCommentButtonText;
- private static Text Placeholder;
- private static Button CloseButton;
- private static Button SendCommentButton;
- private static Transform Mask;
- private static InputField commentInputField;
- private static VirtualScrollRectPlus VirtualScrollRectPlus;
- private static int currentCommentPage;
- private static int currentCommentIndex;
- private static bool requesting;
- private static ShowCommentsHttp commentDataHttp;
- private static GetFashionShowData showData;
- private static List<ShowCommentData> commentDatas = new List<ShowCommentData>();
- private static List<ShowComment> commentItems = new List<ShowComment>();
- #endregion
- public override void RegistReference()
- {
- base.RegistReference();
- NicknameTitle = ResourceManager.Get<Text>(CanvasLabel.Ph_NicknameTitle);
- ContentTitle = ResourceManager.Get<Text>(CanvasLabel.Ph_ContentTitle);
- Title = ResourceManager.Get<Text>(CanvasLabel.Ph_Title);
- CloseButtonText = ResourceManager.Get<Text>(CanvasLabel.Ph_CloseButtonText);
- SendCommentButtonText = ResourceManager.Get<Text>(CanvasLabel.Ph_SendCommentButtonText);
- Placeholder = ResourceManager.Get<Text>(CanvasLabel.Ph_Placeholder);
- CloseButton = ResourceManager.Get<Button>(CanvasLabel.Ph_CloseButton);
- SendCommentButton = ResourceManager.Get<Button>(CanvasLabel.Ph_SendCommentButton);
- Mask = ResourceManager.Get(CanvasLabel.Ph_CommentMask);
- commentInputField = ResourceManager.Get<InputField>(CanvasLabel.Ph_InputField);
- VirtualScrollRectPlus = ResourceManager.Get<VirtualScrollRectPlus>(CanvasLabel.Ph_ScrollRect);
- LanguageManager.Add(Title, new MulLanStr(LanguageLabel.UI__Ph_Tit));
- LanguageManager.Add(NicknameTitle, new MulLanStr(LanguageLabel.UI__Ph_NicknameTitle));
- LanguageManager.Add(ContentTitle, new MulLanStr(LanguageLabel.UI__Ph_ContentTitle));
- LanguageManager.Add(CloseButtonText, new MulLanStr(LanguageLabel.UI__Ph_CloseLab));
- LanguageManager.Add(SendCommentButtonText, new MulLanStr(LanguageLabel.UI__Ph_CommentLab));
- LanguageManager.Add(Placeholder, new MulLanStr(LanguageLabel.UI__Ph_Placeholder));
- Mask.CreateTweenCG(0, 1, 0.25f, false, true, Curve.EaseOutQuad);
- VirtualScrollRectPlus.Init(1, 1000000);
- VirtualScrollRectPlus.OnGetNextItem += OnGetNextItem;
- CloseButton.onClick.AddListener(OnCloseButtonClick);
- SendCommentButton.onClick.AddListener(OnSendCommentButtonClick);
- }
- public static void ShowPanel(GetFashionShowData data)
- {
- ResetPanel(data);
- Mask.TweenForCG();
- }
- private static void ResetPanel(GetFashionShowData data)
- {
- showData = data;
- requesting = false;
- currentCommentPage = 0;
- currentCommentIndex = 0;
- commentDatas = new List<ShowCommentData>();
- foreach (var commentItem in commentItems)
- {
- DestroyImmediate(commentItem.gameObject);
- }
- commentItems = new List<ShowComment>();
- commentInputField.text = "";
- OnGetNextItem(0);
- }
- public static void HidePanel()
- {
- Mask.TweenBacCG();
- }
- private static void OnCloseButtonClick()
- {
- if (commentDataHttp != null)
- {
- commentDataHttp.disable = true;
- }
- AudioManager.PlayClip(ResourceLabel.CloseClip);
- HidePanel();
- }
- private static VirtualScrollRectItem OnGetNextItem(int index)
- {
- if (commentDatas.Count > currentCommentIndex)
- {
- ShowCommentData data = commentDatas[currentCommentIndex];
- ShowComment item = ResourceManager.GetShowComment(data);
- commentItems.Add(item);
- currentCommentIndex++;
- return null;
- }
- else
- {
- GetCommentData();
- return null;
- }
- }
- private static void OnSendCommentButtonClick()
- {
- AudioManager.PlayClip(ResourceLabel.BtnClip);
- SendComment();
- }
- private static void SendComment()
- {
- string comment = commentInputField.text;
- if (StringFilter.ContainSensitiveWord(comment))
- {
- Bubble.Show(null, Language.GetStr(LanguageLabel.Common__ContainSensitiveWord));
- return;
- }
- SendCommentButton.interactable = false;
- long playerId = HttpManager.GetPlayerId();
- CommentShowHttp.Comment(playerId, showData.showId, comment,
- OnSendCommentSuccees, OnSendCommentFail);
- }
- private static void OnSendCommentSuccees()
- {
- commentInputField.text = "";
- SendCommentButton.interactable = true;
- ResetPanel(showData);
- }
- private static void OnSendCommentFail()
- {
- SendCommentButton.interactable = true;
- }
- private static void GetCommentData()
- {
- if (requesting)
- {
- return;
- }
- requesting = true;
- commentDataHttp = ShowCommentsHttp.Get(currentCommentPage, showData.showId,
- OnGetCommentDataSuccess, OnGetCommentDataFail);
- }
- private static void OnGetCommentDataSuccess(object obj)
- {
- requesting = false;
- currentCommentPage++;
- List<ShowCommentData> datas = (List<ShowCommentData>) obj;
- foreach (var data in datas)
- {
- commentDatas.AddUnique(data, (data0, data1) => data0.id == data1.id);
- }
- if (commentItems.Count == 0)
- {
- OnGetNextItem(0);
- OnGetNextItem(0);
- OnGetNextItem(0);
- OnGetNextItem(0);
- OnGetNextItem(0);
- }
- }
- private static void OnGetCommentDataFail()
- {
- requesting = false;
- }
- }
|