1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071 |
- using UnityEngine;
- using UnityEngine.UI;
- using System.Collections;
- public class ChatView : View
- {
- public Text titleTxt;
- public Transform container;
- public ChatItem itemPrefab;
- private Follower follower;
- public FriendChatInput chatInput;
- protected override void OnDestroy ()
- {
- base.OnDestroy ();
- if (follower != null)
- follower.OnMsgAdded.RemoveListener (OnAddMsg);
- }
- protected override void OnInitCompleted ()
- {
- data = data;
- }
- public override object data {
- get {
- return base.data;
- }
- set {
- base.data = value;
- if(value == null || !initialized)
- {
- return;
- }
- int targetId = (int)value;
- chatInput.targetId = targetId;
- if (follower != null)
- follower.OnMsgAdded.RemoveListener (OnAddMsg);
- follower = FollowManager.GetInstance ().GetFollower (targetId);
- if (follower != null) {
- follower.OnMsgAdded.AddListener (OnAddMsg);
- ListHelper.FillList<ChatMsg> (container, follower.GetMsgList(), itemPrefab, ChatManager.MAX_FOLLOW);
- titleTxt.text = Language.GetStr ("ChatPanel", "chatWith").Replace("%NICK%", UserCache.GetNick(targetId));
- } else {
- ListHelper.FillList<ChatMsg> (container, null, null);
- titleTxt.text = "";
- }
- }
- }
- private void OnAddMsg(ChatMsg chatMsg)
- {
- ListHelper.AddToList<ChatMsg> (container, chatMsg, itemPrefab, ChatManager.MAX_FOLLOW);
- }
- public void ShowProfile()
- {
- if(data == null || !initialized)
- return;
- ProfilePanel.Show ((int)data);
- }
- }
|