BattleUI.cs 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  1. using UnityEngine;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. public class BattleUI : MonoBehaviour {
  5. public GameObject radioPanelPrefab;
  6. public GameObject OptionPanelPrefab;
  7. public GameObject battleMissionPrefab;
  8. public GameObject myRankPanelPrefab;
  9. public GameObject battleReadyPrefab;
  10. public ScoreBar scoreBar;
  11. public MiniMap miniMap;
  12. public PowerIconContainer powerIconContainer;
  13. public BattleClockUI battleClock;
  14. public BottomTip bottomTip;
  15. public BattleInfo battleInfo;
  16. public GameObject replayBar;
  17. public GameObject optionBtnObj;
  18. private RadioPanel radioPanel;
  19. public Sprite[] crystalPowerIcons;
  20. public BattleController battleController;
  21. public void Init(BattleController battleController, bool isMenu = false)
  22. {
  23. this.battleController = battleController;
  24. if(isMenu)
  25. {
  26. optionBtnObj.SetActive(false);
  27. scoreBar.gameObject.SetActive(false);
  28. miniMap.gameObject.SetActive(false);
  29. battleClock.gameObject.SetActive(false);
  30. battleInfo.gameObject.SetActive(false);
  31. }
  32. if (battleController.isReplay) {
  33. } else {
  34. replayBar.SetActive (false);
  35. }
  36. Map map = battleController.GetMap();
  37. miniMap.Init(battleController);
  38. for(int i=0; i<map.GetCrystalBaseList().Count; i++)
  39. {
  40. miniMap.CreateCrystalBase(map.GetCrystalBaseList()[i]);
  41. }
  42. battleClock.Init(battleController);
  43. scoreBar.Init(battleController);
  44. powerIconContainer.isMenu = isMenu;
  45. }
  46. public void UpdateScoreText()
  47. {
  48. scoreBar.updateScore (battleController.blueScore, battleController.redScore);
  49. }
  50. public void ShowBottomTip(string info, bool newOne=true)
  51. {
  52. bottomTip.Show(info, newOne);
  53. }
  54. public MiniMap GetMiniMap()
  55. {
  56. return miniMap;
  57. }
  58. public void ShowBattleReady(string host, string guest, CallBackUtil.SimpleCallBack callBack)
  59. {
  60. GameObject gameObj = Instantiate<GameObject> (battleReadyPrefab);
  61. PopUpManager.AddToMainCanvas (gameObj);
  62. BattleReady br = gameObj.GetComponent<BattleReady> ();
  63. br.Show (host, guest, callBack);
  64. }
  65. public void ShowMission(string mission)
  66. {
  67. GameObject gameObj = Instantiate<GameObject>(battleMissionPrefab);
  68. PopUpManager.AddToMainCanvas(gameObj);
  69. BattleMission bm = gameObj.GetComponent<BattleMission>();
  70. bm.infoTxt.text = mission;
  71. }
  72. public void ShowBattleInfo(string info, string combo="", bool isAlly=true)
  73. {
  74. battleInfo.Show(info, combo, isAlly);
  75. }
  76. public void ToggleRadioPanel()
  77. {
  78. if(radioPanel == null)
  79. {
  80. GameObject radioObj = Instantiate<GameObject>(radioPanelPrefab);
  81. PopUpManager.AddToMainCanvas(radioObj);
  82. radioPanel = radioObj.GetComponent<RadioPanel>();
  83. }
  84. else
  85. {
  86. Destroy(radioPanel.gameObject);
  87. radioPanel = null;
  88. }
  89. }
  90. public void ToggleSwapPanel()
  91. {
  92. CraftSelectionPanel.Show(true);
  93. }
  94. public void HideRadioPanel()
  95. {
  96. if(radioPanel != null)
  97. {
  98. Destroy(radioPanel.gameObject);
  99. radioPanel = null;
  100. }
  101. }
  102. public void DealRadio(int userId, int craftId, int index)
  103. {
  104. Player player = battleController.GetBattleSession().GetPlayer(userId);
  105. if(player.team == battleController.GetMyPlayer().team)
  106. {
  107. string info = Language.GetStr ("Radio", "info");
  108. info = info.Replace("%COLOR%", TeamUtil.GetTeamColorString(player.team));
  109. info = info.Replace("%NICK%", player.nick);
  110. info = info.Replace("%INFO%", RadioItem.GetName(index));
  111. ShowBottomTip(info);
  112. SoundManager.GetInstatnce().effectSound.Play(RadioItem.GetSound(index));
  113. Craft craft = battleController.GetMap ().GetBattleObject (craftId) as Craft;
  114. if(craft != null)
  115. {
  116. craft.RadioAlert();
  117. }
  118. }
  119. }
  120. public void ShowOptionPanel()
  121. {
  122. GameObject gameObj = Instantiate<GameObject> (OptionPanelPrefab);
  123. PopUpManager.AddToMainCanvas (gameObj);
  124. OptionPanel optionPanel = gameObj.GetComponent<OptionPanel> ();
  125. optionPanel.battleController = battleController;
  126. }
  127. public void ShowResultPanel()
  128. {
  129. Player me = battleController.GetMyPlayer ();
  130. Player opp = battleController.GetBattleSession ().GetPlayerByTeam (TeamUtil.GetOpponentTeam (me.team));
  131. ResultPanel.Result result = ResultPanel.Result.Lose;
  132. if (battleController.winTeam == TeamUtil.Team.Yellow)
  133. result = ResultPanel.Result.Draw;
  134. else if(battleController.winTeam == me.team)
  135. result = ResultPanel.Result.Win;
  136. int crystalSpend = battleController.GetBattleSession ().myPlayer.coinSpend;
  137. ResultPanel.Show (new ResultPanel.ResultData(me, opp, result, crystalSpend));
  138. }
  139. public void ShowMyRankPanel(int start, int target)
  140. {
  141. GameObject myRankPanelObj = Instantiate<GameObject> (myRankPanelPrefab);
  142. PopUpManager.AddToMainCanvas (myRankPanelObj);
  143. MyRankPanel myRankPanel = myRankPanelObj.GetComponent<MyRankPanel> ();
  144. myRankPanel.startRank = start;
  145. myRankPanel.targetRank = target;
  146. }
  147. }