StoryLevelInfoView.cs 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234
  1. using FairyGUI;
  2. using UI.Main;
  3. using System.Collections.Generic;
  4. using UI.CommonGame;
  5. using System;
  6. namespace GFGGame
  7. {
  8. public class StoryLevelInfoView : BaseWindow
  9. {
  10. private UI_StoryLevelInfoUI _ui;
  11. private int _fightID;
  12. private string _levelID;
  13. private int _storyType;
  14. private List<ItemData> _bonusList = new List<ItemData>();
  15. private int _fightTimes;
  16. private const int _timeCount = 10;
  17. protected override void OnInit()
  18. {
  19. base.OnInit();
  20. _ui = UI_StoryLevelInfoUI.Create();
  21. this.viewCom = _ui.target;
  22. this.viewCom.Center();
  23. this.modal = true;
  24. viewAnimationType = EnumViewAnimationType.ZOOM_CENTER;
  25. _ui.m_listBonus.itemRenderer = UpdateBonusItem;
  26. // _ui.m_listBonus.onClickItem.Add(OnClickListBonusItem);
  27. _ui.m_btnStart.onClick.Add(OnClickBtnStart);
  28. _ui.m_btnFightOnce.onClick.Add(OnClickBtnFightOnce);
  29. _ui.m_btnFightTimes.onClick.Add(OnClickBtnFightTimes);
  30. _ui.m_listTag.itemRenderer = RenderListTagItem;
  31. }
  32. protected override void OnShown()
  33. {
  34. base.OnShown();
  35. _levelID = (string)viewData;
  36. _storyType = int.Parse(_levelID.Split('_')[0]) / 10000;
  37. UpdateView();
  38. GuideController.TryGuideChapterInfoViewBtnStart(_ui.m_btnStart, "点击按钮,开始挑战");
  39. EventAgent.AddEventListener(ConstMessage.ROLE_POWER_CHANGED, UpdateBtnFightTimes);
  40. }
  41. protected override void OnHide()
  42. {
  43. base.OnHide();
  44. EventAgent.RemoveEventListener(ConstMessage.ROLE_POWER_CHANGED, UpdateBtnFightTimes);
  45. }
  46. private void OnClickBtnStart()
  47. {
  48. int time = StoryDataManager.GetCanFightTime(_levelID);
  49. if (time > 0)
  50. {
  51. GuideController.HideGuide();
  52. ViewManager.Show(ViewName.DRESS_UP_FIGHT_VIEW, _levelID, null, true);
  53. }
  54. else
  55. {
  56. ItemUtil.AddPower("体力不足", OnClickBtnStart);
  57. }
  58. }
  59. private void OnClickBtnFightOnce()
  60. {
  61. int time = StoryDataManager.GetCanFightTime(_levelID);
  62. if (time > 0)
  63. {
  64. ViewManager.Show(ViewName.STORY_FIGHT_QUICKLY_VIEW, 1);
  65. }
  66. else
  67. {
  68. ItemUtil.AddPower("体力不足", OnClickBtnFightOnce);
  69. }
  70. }
  71. private void OnClickBtnFightTimes()
  72. {
  73. if (_storyType == ConstStoryType.NORMAL_TYPE)
  74. {
  75. if (_fightTimes < _timeCount)
  76. {
  77. ItemUtil.AddPower("体力不足", OnClickBtnFightTimes);
  78. }
  79. else
  80. {
  81. ViewManager.Show(ViewName.STORY_FIGHT_QUICKLY_VIEW, _fightTimes);
  82. }
  83. }
  84. else if (_storyType == ConstStoryType.HARD_TYPE)
  85. {
  86. ViewManager.Show(ViewName.STORY_FIGHT_QUICKLY_VIEW, _fightTimes);
  87. }
  88. }
  89. private void UpdateBonusItem(int index, GObject item)
  90. {
  91. ItemData itemData = _bonusList[index] as ItemData;
  92. UI_ComItem listItem = UI_ComItem.Proxy(item);
  93. if (item.data == null)
  94. {
  95. item.data = new ItemView(item as GComponent);
  96. }
  97. (item.data as ItemView).SetData(itemData);
  98. }
  99. private void UpdateBtnFightTimes()
  100. {
  101. if (_ui.m_groupPass.visible)
  102. {
  103. int time = StoryDataManager.GetCanFightTime(_levelID);
  104. time = Math.Min(GameConst.MAX_COUNT_FIGHT_QUICKLY, time);
  105. if (_storyType == ConstStoryType.NORMAL_TYPE)
  106. {
  107. _ui.m_btnFightTimes.visible = true;
  108. _fightTimes = time;
  109. _ui.m_btnFightTimes.text = "挑战" + NumberUtil.GetChiniseNumberText(_timeCount) + "次";
  110. }
  111. else if (_storyType == ConstStoryType.HARD_TYPE)
  112. {
  113. _ui.m_btnFightTimes.visible = time > 0;
  114. if (_ui.m_btnFightTimes.visible)
  115. {
  116. _fightTimes = time;
  117. _ui.m_btnFightTimes.text = "挑战" + NumberUtil.GetChiniseNumberText(time) + "次";
  118. }
  119. }
  120. }
  121. }
  122. private void UpdateView()
  123. {
  124. StoryLevelCfg levelCfg = StoryLevelCfgArray.Instance.GetCfg(_levelID);
  125. StoryFightCfg fightCfg = StoryFightCfgArray.Instance.GetCfg(levelCfg.fightID);
  126. _ui.m_txtTitle.text = StoryDataManager.currentChapter + "-" + StoryDataManager.currentLevel + " " + levelCfg.name;
  127. _ui.m_txtLevelDesc.text = levelCfg.desc;
  128. _ui.m_txtPowerDesc.SetVar("power", "" + levelCfg.power).FlushVars();
  129. _ui.m_scoreType.url = "ui://CommonGame/kp_sx_" + fightCfg.scoreType;
  130. if (fightCfg.targetName != null && fightCfg.targetName.Length > 0)
  131. {
  132. _ui.m_txtTargetName.text = "挑战对手 : " + fightCfg.targetName;
  133. _ui.m_loaderHead.url = ResPathUtil.GetNpcHeadPath(fightCfg.targetRes);
  134. }
  135. else
  136. {
  137. _ui.m_txtTargetName.text = RoleDataManager.roleName;
  138. _ui.m_loaderHead.url = ResPathUtil.GetNpcHeadPath("self");
  139. }
  140. _bonusList.Clear();
  141. if (StoryDataManager.CheckCurrentLevelPass())
  142. {
  143. _bonusList = StoryBonusDataCache.GetBonusList(_levelID, false);
  144. _ui.m_groupPass.visible = true;
  145. _ui.m_groupUnpass.visible = false;
  146. UpdateBtnFightTimes();
  147. }
  148. else
  149. {
  150. _bonusList = StoryBonusDataCache.GetBonusList(_levelID, true);
  151. _ui.m_groupPass.visible = false;
  152. _ui.m_groupUnpass.visible = true;
  153. _ui.m_txtUnpassTips.SetVar("count", NumberUtil.GetChiniseNumberText(fightCfg.quickFightStart)).FlushVars();
  154. }
  155. _ui.m_listBonus.numItems = _bonusList.Count;
  156. if (_ui.m_listBonus.numItems > 4)
  157. {
  158. _ui.m_listBonus.columnGap = 40;
  159. }
  160. else
  161. {
  162. _ui.m_listBonus.columnGap = 60;
  163. }
  164. int score = StoryDataManager.GetScoreHighest(_levelID);
  165. if (score > 0)
  166. {
  167. string scoreStr = "" + score;
  168. if (score <= fightCfg.score1)
  169. {
  170. scoreStr = "[color=#fddadb]失败 " + scoreStr + "[/color]";
  171. }
  172. _ui.m_txtHighestScore.text = scoreStr;
  173. _ui.m_flower.target.visible = true;
  174. int starCount = StoryDataManager.GetStarCountHistory(_levelID, score);
  175. StoryUtil.UpdateStar(starCount, _ui.m_flower.target);
  176. }
  177. else
  178. {
  179. _ui.m_txtHighestScore.text = "--";
  180. _ui.m_flower.target.visible = false;
  181. }
  182. _ui.m_ctrlNeed.selectedIndex = 0;
  183. if (fightCfg.needItemId != 0)
  184. {
  185. _ui.m_ctrlNeed.selectedIndex = 1;
  186. ItemCfg cfg = ItemCfgArray.Instance.GetCfg(fightCfg.needItemId);
  187. _ui.m_txtNeed.text = cfg.name;
  188. }
  189. else if (fightCfg.needSuitId != 0)
  190. {
  191. _ui.m_ctrlNeed.selectedIndex = 1;
  192. SuitCfg cfg = SuitCfgArray.Instance.GetCfg(fightCfg.needSuitId);
  193. _ui.m_txtNeed.text = cfg.name;
  194. }
  195. else if (fightCfg.needTagsArr.Length > 0)
  196. {
  197. _ui.m_ctrlNeed.selectedIndex = 2;
  198. _ui.m_listTag.numItems = fightCfg.needTagsArr.Length;
  199. }
  200. }
  201. private void RenderListTagItem(int index, GObject obj)
  202. {
  203. UI_ListTagItem item = UI_ListTagItem.Proxy(obj);
  204. StoryLevelCfg levelCfg = StoryLevelCfgArray.Instance.GetCfg(_levelID);
  205. StoryFightCfg fightCfg = StoryFightCfgArray.Instance.GetCfg(levelCfg.fightID);
  206. string[] tag = fightCfg.needTagsArr[index].Split('_');
  207. item.m_loaTag.url = ResPathUtil.GetCommonGameResPath("fzd_bqbq_" + tag[0]);
  208. item.m_txtTag.text = tag[1];
  209. }
  210. }
  211. }