ChatView.cs 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. using UnityEngine;
  2. using UnityEngine.UI;
  3. using System.Collections;
  4. public class ChatView : View
  5. {
  6. public Text titleTxt;
  7. public Transform container;
  8. public ChatItem itemPrefab;
  9. private Follower follower;
  10. public FriendChatInput chatInput;
  11. protected override void OnDestroy ()
  12. {
  13. base.OnDestroy ();
  14. if (follower != null)
  15. follower.OnMsgAdded.RemoveListener (OnAddMsg);
  16. }
  17. protected override void OnInitCompleted ()
  18. {
  19. data = data;
  20. }
  21. public override object data {
  22. get {
  23. return base.data;
  24. }
  25. set {
  26. base.data = value;
  27. if(value == null || !initialized)
  28. {
  29. return;
  30. }
  31. int targetId = (int)value;
  32. chatInput.targetId = targetId;
  33. if (follower != null)
  34. follower.OnMsgAdded.RemoveListener (OnAddMsg);
  35. follower = FollowManager.GetInstance ().GetFollower (targetId);
  36. if (follower != null) {
  37. follower.OnMsgAdded.AddListener (OnAddMsg);
  38. ListHelper.FillList<ChatMsg> (container, follower.GetMsgList(), itemPrefab, ChatManager.MAX_FOLLOW);
  39. titleTxt.text = Language.GetStr ("ChatPanel", "chatWith").Replace("%NICK%", UserCache.GetNick(targetId));
  40. } else {
  41. ListHelper.FillList<ChatMsg> (container, null, null);
  42. titleTxt.text = "";
  43. }
  44. }
  45. }
  46. private void OnAddMsg(ChatMsg chatMsg)
  47. {
  48. ListHelper.AddToList<ChatMsg> (container, chatMsg, itemPrefab, ChatManager.MAX_FOLLOW);
  49. }
  50. public void ShowProfile()
  51. {
  52. if(data == null || !initialized)
  53. return;
  54. ProfilePanel.Show ((int)data);
  55. }
  56. }