ChatBarChatView.cs 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. using UnityEngine;
  2. using UnityEngine.UI;
  3. using System.Collections;
  4. public class ChatBarChatView : View
  5. {
  6. public Text findFriendBtnLabel;
  7. public Transform container;
  8. public ChatBarChatItem itemPrefab;
  9. protected override void OnInitCompleted ()
  10. {
  11. findFriendBtnLabel.text = Language.GetStr ("ChatPanel", "findMorePlayer");
  12. if (!FollowManager.GetInstance ().initialized)
  13. {
  14. ListHelper.HideAll (container);
  15. FollowManager.GetInstance ().InitCompletion.AddListener (OnFollowersInit);
  16. FollowManager.GetInstance ().Init ();
  17. }
  18. else
  19. {
  20. OnFollowersInit ();
  21. }
  22. }
  23. protected override void OnDestroy ()
  24. {
  25. base.OnDestroy ();
  26. FollowManager.GetInstance ().InitCompletion.RemoveListener (OnFollowersInit);
  27. FollowManager.GetInstance ().FollowAdded.RemoveListener (OnFollowAdded);
  28. FollowManager.GetInstance ().FollowDeleted.RemoveListener (OnFollowDeleted);
  29. }
  30. private void OnFollowersInit()
  31. {
  32. FollowManager.GetInstance ().InitCompletion.RemoveListener (OnFollowersInit);
  33. FollowManager.GetInstance ().FollowAdded.AddListener (OnFollowAdded);
  34. FollowManager.GetInstance ().FollowDeleted.AddListener (OnFollowDeleted);
  35. OnVisibleChanged ();
  36. if (!ChatManager.GetInstance ().initialized)
  37. ChatManager.GetInstance ().Init ();
  38. }
  39. protected override void OnVisibleChanged ()
  40. {
  41. if(visible && FollowManager.GetInstance().initialized)
  42. {
  43. ListHelper.FillList<Follower> (container, FollowManager.GetInstance().GetFollowList(), itemPrefab);
  44. }
  45. }
  46. private void OnFollowAdded(int userId)
  47. {
  48. Follower follower = FollowManager.GetInstance ().GetFollower (userId);
  49. if(follower != null)
  50. {
  51. ListHelper.AddToList<Follower> (container, follower, itemPrefab);
  52. }
  53. }
  54. private void OnFollowDeleted(object follower)
  55. {
  56. ListHelper.Remove<Follower> (container, follower as Follower);
  57. }
  58. public void ShowFindFriendPanel()
  59. {
  60. ChatPanel.ShowFindFriend ();
  61. }
  62. }