StoryLevelInfoView.cs 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267
  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 int _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_btnClose.onClick.Add(() =>
  31. // {
  32. // this.Hide();
  33. // });
  34. _ui.m_listTag.itemRenderer = RenderListTagItem;
  35. }
  36. protected override void OnShown()
  37. {
  38. base.OnShown();
  39. _levelID = (int)viewData;
  40. StoryLevelCfg levelCfg = StoryLevelCfgArray.Instance.GetCfg(_levelID);
  41. _storyType = levelCfg.subType;
  42. _ui.m_btnStart.touchable = true;
  43. UpdateView();
  44. EventAgent.AddEventListener(ConstMessage.NUMERIC_CHANGE, UpdateBtnFightTimes);
  45. }
  46. protected override void OnHide()
  47. {
  48. base.OnHide();
  49. EventAgent.RemoveEventListener(ConstMessage.NUMERIC_CHANGE, UpdateBtnFightTimes);
  50. }
  51. private void OnClickBtnStart()
  52. {
  53. int time = StoryDataManager.GetCanFightTime(_levelID);
  54. if (time > 0)
  55. {
  56. ViewManager.Show(ViewName.DRESS_UP_FIGHT_VIEW, _levelID, null, true);
  57. }
  58. else
  59. {
  60. ItemUtil.AddPower("体力不足", OnClickBtnStart);
  61. }
  62. }
  63. private void OnClickBtnFightOnce()
  64. {
  65. int time = StoryDataManager.GetCanFightTime(_levelID);
  66. if (time > 0)
  67. {
  68. ViewManager.Show(ViewName.STORY_FIGHT_QUICKLY_VIEW, 1);
  69. }
  70. else
  71. {
  72. ItemUtil.AddPower("体力不足", OnClickBtnFightOnce);
  73. }
  74. }
  75. private void OnClickBtnFightTimes()
  76. {
  77. if (_storyType == ConstInstanceZonesSubType.Normal)
  78. {
  79. if (_fightTimes < _timeCount)
  80. {
  81. ItemUtil.AddPower("体力不足", OnClickBtnFightTimes);
  82. }
  83. else
  84. {
  85. ViewManager.Show(ViewName.STORY_FIGHT_QUICKLY_VIEW, _fightTimes);
  86. }
  87. }
  88. else if (_storyType == ConstInstanceZonesSubType.Hard)
  89. {
  90. ViewManager.Show(ViewName.STORY_FIGHT_QUICKLY_VIEW, _fightTimes);
  91. }
  92. }
  93. private void UpdateBonusItem(int index, GObject item)
  94. {
  95. ItemData itemData = _bonusList[index] as ItemData;
  96. UI_ComItem listItem = UI_ComItem.Proxy(item);
  97. if (item.data == null)
  98. {
  99. item.data = new ItemView(item as GComponent);
  100. }
  101. (item.data as ItemView).SetData(itemData);
  102. List<ItemData> bonusOnceData = StoryBonusDataCache.GetBonusData(_levelID).bonusOnce;
  103. (item.data as ItemView).LoaShouTongRewardVisble = !StoryDataManager.CheckCurrentLevelPass() && index < bonusOnceData.Count;
  104. }
  105. private void UpdateBtnFightTimes()
  106. {
  107. if (_ui.m_groupPass.visible)
  108. {
  109. int time = StoryDataManager.GetCanFightTime(_levelID);
  110. time = Math.Min(GameConst.MAX_COUNT_FIGHT_QUICKLY, time);
  111. if (_storyType == ConstInstanceZonesSubType.Normal)
  112. {
  113. _ui.m_btnFightTimes.visible = true;
  114. _fightTimes = time;
  115. _ui.m_btnFightTimes.text = "挑战" + NumberUtil.GetChiniseNumberText(_timeCount) + "次";
  116. }
  117. else if (_storyType == ConstInstanceZonesSubType.Hard)
  118. {
  119. _ui.m_btnFightTimes.visible = time > 0;
  120. if (_ui.m_btnFightTimes.visible)
  121. {
  122. _fightTimes = time;
  123. _ui.m_btnFightTimes.text = "挑战" + NumberUtil.GetChiniseNumberText(time) + "次";
  124. }
  125. }
  126. }
  127. }
  128. private void UpdateView()
  129. {
  130. StoryLevelCfg levelCfg = StoryLevelCfgArray.Instance.GetCfg(_levelID);
  131. StoryFightCfg fightCfg = StoryFightCfgArray.Instance.GetCfg(levelCfg.fightID);
  132. _ui.m_txtTitle.text = StoryDataManager.CurrentChapterOrder + "-" + StoryDataManager.currentLevelOrder + " " + levelCfg.name;
  133. _ui.m_txtLevelDesc.text = levelCfg.desc;
  134. _ui.m_txtPowerDesc.SetVar("power", "" + levelCfg.power).FlushVars();
  135. _ui.m_scoreType.url = "ui://CommonGame/kp_sx_" + fightCfg.scoreType;
  136. if (fightCfg.targetName != null && fightCfg.targetName.Length > 0)
  137. {
  138. _ui.m_txtTargetName.text = "挑战对手 : " + fightCfg.targetName;
  139. _ui.m_loaderHead.url = ResPathUtil.GetNpcHeadPath(fightCfg.targetRes);
  140. }
  141. else
  142. {
  143. _ui.m_txtTargetName.text = RoleDataManager.roleName;
  144. _ui.m_loaderHead.url = ResPathUtil.GetNpcHeadPath("self");
  145. }
  146. _bonusList.Clear();
  147. if (StoryDataManager.CheckCurrentLevelPass())
  148. {
  149. _bonusList = StoryBonusDataCache.GetBonusList(_levelID, false);
  150. _ui.m_groupPass.visible = true;
  151. _ui.m_groupUnpass.visible = false;
  152. UpdateBtnFightTimes();
  153. }
  154. else
  155. {
  156. _bonusList = StoryBonusDataCache.GetBonusList(_levelID, true);
  157. _ui.m_groupPass.visible = false;
  158. _ui.m_groupUnpass.visible = true;
  159. _ui.m_txtUnpassTips.SetVar("count", NumberUtil.GetChiniseNumberText(fightCfg.quickFightStart)).FlushVars();
  160. }
  161. _ui.m_listBonus.numItems = _bonusList.Count;
  162. if (_ui.m_listBonus.numItems > 4)
  163. {
  164. _ui.m_listBonus.columnGap = 40;
  165. }
  166. else
  167. {
  168. _ui.m_listBonus.columnGap = 60;
  169. }
  170. int score = StoryDataManager.GetScoreHighest(_levelID);
  171. if (score > 0)
  172. {
  173. string scoreStr = "" + score;
  174. if (score <= fightCfg.score1)
  175. {
  176. scoreStr = "[color=#A28D77]失败 " + scoreStr + "[/color]";
  177. }
  178. _ui.m_txtHighestScore.text = scoreStr;
  179. _ui.m_flower.target.visible = true;
  180. int starCount = StoryDataManager.GetStarCountHistory(_levelID);
  181. StoryUtil.UpdateStar(starCount, _ui.m_flower.target);
  182. }
  183. else
  184. {
  185. _ui.m_txtHighestScore.text = "--";
  186. _ui.m_flower.target.visible = false;
  187. }
  188. _ui.m_ctrlNeed.selectedIndex = 0;
  189. if (fightCfg.needItemId != 0)
  190. {
  191. _ui.m_ctrlNeed.selectedIndex = 1;
  192. ItemCfg cfg = ItemCfgArray.Instance.GetCfg(fightCfg.needItemId);
  193. _ui.m_txtNeed.text = cfg.name;
  194. }
  195. else if (fightCfg.needSuitId != 0)
  196. {
  197. _ui.m_ctrlNeed.selectedIndex = 1;
  198. SuitCfg cfg = SuitCfgArray.Instance.GetCfg(fightCfg.needSuitId);
  199. _ui.m_txtNeed.text = cfg.name;
  200. }
  201. else if (fightCfg.needTagsArr.Length > 0)
  202. {
  203. _ui.m_ctrlNeed.selectedIndex = 2;
  204. _ui.m_listTag.numItems = fightCfg.needTagsArr.Length;
  205. }
  206. }
  207. private void RenderListTagItem(int index, GObject obj)
  208. {
  209. UI_ListTagItem item = UI_ListTagItem.Proxy(obj);
  210. StoryLevelCfg levelCfg = StoryLevelCfgArray.Instance.GetCfg(_levelID);
  211. StoryFightCfg fightCfg = StoryFightCfgArray.Instance.GetCfg(levelCfg.fightID);
  212. string[] tag = fightCfg.needTagsArr[index].Split('_');
  213. item.m_loaTag.url = ResPathUtil.GetCommonGameResPath("fzd_bqbq_" + tag[0]);
  214. item.m_txtTag.text = tag[1];
  215. }
  216. protected override void UpdateToCheckGuide(object param)
  217. {
  218. if (!ViewManager.CheckIsTopView(this.viewCom)) return;
  219. GuideController.TryGuide(_ui.m_btnStart, ConstGuideId.SINGLE_FIGHT, 2, "点击开启换装");
  220. if (GuideController.TryGuide(_ui.m_txtNeed, ConstGuideId.CLOTHING_SYNTHETIC, 2, "这次必需品,要通过合成获得"))
  221. {
  222. _ui.m_btnStart.touchable = false;
  223. }
  224. GuideController.TryGuide(null, ConstGuideId.CLOTHING_SYNTHETIC, 3, "点击空白处关闭", false, 0, true, false, (int)(this.viewCom.y + _ui.m_groupPass.y));
  225. GuideController.TryGuide(_ui.m_listTag, ConstGuideId.OPEN_TAGS, 1, "选择相应的关卡标签,可提高分数", false, 0, true, false, 0);
  226. GuideController.TryCompleteGuide(ConstGuideId.OPEN_TAGS, 1);
  227. }
  228. protected override void TryCompleteGuide()
  229. {
  230. GuideCfg cfg = GuideCfgArray.Instance.GetCfg(ConstGuideId.CLOTHING_SYNTHETIC);
  231. GuideController.TryCompleteGuideIndex(cfg.id, 3);
  232. }
  233. }
  234. }