ChatBarReplayItem.cs 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. using UnityEngine;
  2. using UnityEngine.UI;
  3. using System.Collections;
  4. using System.Collections.Generic;
  5. public class ChatBarReplayItem : ItemRenderer
  6. {
  7. public Text titleTxt;
  8. public Text timeTxt;
  9. public Transform blueList;
  10. public Transform redList;
  11. public Transform shareBtnTrans;
  12. public Text shareBtnLabel;
  13. public Transform playBtnTrans;
  14. public Text playBtnLabel;
  15. private ChatMsg chatMsg;
  16. void Awake()
  17. {
  18. shareBtnLabel.text = Language.GetStr ("Public", "share");
  19. playBtnLabel.text = Language.GetStr ("Public", "watch");
  20. }
  21. public override object data {
  22. get {
  23. return base.data;
  24. }
  25. set {
  26. base.data = value;
  27. chatMsg = value as ChatMsg;
  28. if (chatMsg != null) {
  29. titleTxt.text = UserCache.GetNick (chatMsg.sender) + Language.GetStr ("ChatPanel", "replayTitle");
  30. timeTxt.text = chatMsg.GetTimeStr ();
  31. ReplayInfo replayInfo = chatMsg.GetReplayInfo ();
  32. int blueCount = 0;
  33. int redCount = 0;
  34. List<Player> playerList = replayInfo.playerList;
  35. for(int i=0; i<playerList.Count; i++)
  36. {
  37. Player player = playerList [i];
  38. if(player.team == TeamUtil.Team.Blue)
  39. {
  40. if (blueCount >= blueList.childCount)
  41. continue;
  42. Text txt = blueList.GetChild (blueCount).GetComponent<Text>();
  43. txt.text = player.nick;
  44. blueCount++;
  45. }
  46. else if(player.team == TeamUtil.Team.Red)
  47. {
  48. if (redCount >= redList.childCount)
  49. continue;
  50. Text txt = redList.GetChild (redCount).GetComponent<Text>();
  51. txt.text = player.nick;
  52. redCount++;
  53. }
  54. }
  55. for(int i=blueCount; i<blueList.childCount; i++)
  56. {
  57. Text txt = blueList.GetChild (i).GetComponent<Text>();
  58. txt.text = "";
  59. }
  60. for(int i=redCount; i<redList.childCount; i++)
  61. {
  62. Text txt = redList.GetChild (i).GetComponent<Text>();
  63. txt.text = "";
  64. }
  65. playBtnTrans.gameObject.SetActive (true);
  66. shareBtnTrans.gameObject.SetActive (chatMsg.id <= 0);
  67. } else {
  68. shareBtnTrans.gameObject.SetActive (false);
  69. playBtnTrans.gameObject.SetActive (false);
  70. }
  71. }
  72. }
  73. public void Share()
  74. {
  75. ChatManager.GetInstance ().ShareReplayMsg (chatMsg, this);
  76. }
  77. public void Play()
  78. {
  79. if (chatMsg != null) {
  80. LoadingPanel loadingPanel = LoadingPanel.Show(false);
  81. loadingPanel.ReachTargetProgress.AddListener (StartReplay);
  82. LoadingPanel.Increase(0.1f);
  83. }
  84. }
  85. private void StartReplay()
  86. {
  87. LoadingPanel.GetCurrentPanel().ReachTargetProgress.RemoveListener (StartReplay);
  88. if (chatMsg != null) {
  89. string fileName = chatMsg.extra;
  90. ReplayManager.GetInstance ().Load (fileName);
  91. } else {
  92. LoadingPanel.Complete (null);
  93. }
  94. }
  95. }