StoryLevelInfoView.cs 8.8 KB

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