123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114 |
- using UnityEngine;
- using UnityEngine.UI;
- using System.Collections;
- using System.Collections.Generic;
- public class ChatBarReplayItem : ItemRenderer
- {
- public Text titleTxt;
- public Text timeTxt;
- public Transform blueList;
- public Transform redList;
- public Transform shareBtnTrans;
- public Text shareBtnLabel;
- public Transform playBtnTrans;
- public Text playBtnLabel;
- private ChatMsg chatMsg;
- void Awake()
- {
- shareBtnLabel.text = Language.GetStr ("Public", "share");
- playBtnLabel.text = Language.GetStr ("Public", "watch");
- }
- public override object data {
- get {
- return base.data;
- }
- set {
- base.data = value;
- chatMsg = value as ChatMsg;
- if (chatMsg != null) {
- titleTxt.text = UserCache.GetNick (chatMsg.sender) + Language.GetStr ("ChatPanel", "replayTitle");
- timeTxt.text = chatMsg.GetTimeStr ();
- ReplayInfo replayInfo = chatMsg.GetReplayInfo ();
- int blueCount = 0;
- int redCount = 0;
- List<Player> playerList = replayInfo.playerList;
- for(int i=0; i<playerList.Count; i++)
- {
- Player player = playerList [i];
- if(player.team == TeamUtil.Team.Blue)
- {
- if (blueCount >= blueList.childCount)
- continue;
-
- Text txt = blueList.GetChild (blueCount).GetComponent<Text>();
- txt.text = player.nick;
- blueCount++;
- }
- else if(player.team == TeamUtil.Team.Red)
- {
- if (redCount >= redList.childCount)
- continue;
- Text txt = redList.GetChild (redCount).GetComponent<Text>();
- txt.text = player.nick;
- redCount++;
- }
- }
- for(int i=blueCount; i<blueList.childCount; i++)
- {
- Text txt = blueList.GetChild (i).GetComponent<Text>();
- txt.text = "";
- }
- for(int i=redCount; i<redList.childCount; i++)
- {
- Text txt = redList.GetChild (i).GetComponent<Text>();
- txt.text = "";
- }
- playBtnTrans.gameObject.SetActive (true);
- shareBtnTrans.gameObject.SetActive (chatMsg.id <= 0);
- } else {
- shareBtnTrans.gameObject.SetActive (false);
- playBtnTrans.gameObject.SetActive (false);
- }
- }
- }
- public void Share()
- {
- ChatManager.GetInstance ().ShareReplayMsg (chatMsg, this);
- }
- public void Play()
- {
- if (chatMsg != null) {
- LoadingPanel loadingPanel = LoadingPanel.Show(false);
- loadingPanel.ReachTargetProgress.AddListener (StartReplay);
- LoadingPanel.Increase(0.1f);
- }
- }
- private void StartReplay()
- {
- LoadingPanel.GetCurrentPanel().ReachTargetProgress.RemoveListener (StartReplay);
- if (chatMsg != null) {
- string fileName = chatMsg.extra;
- ReplayManager.GetInstance ().Load (fileName);
- } else {
- LoadingPanel.Complete (null);
- }
- }
- }
|