StoryLevelInfoView.cs 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274
  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 = InstanceZonesDataManager.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 = InstanceZonesDataManager.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 = !MainStoryDataManager.CheckCurrentLevelPass() && index < bonusOnceData.Count;
  104. }
  105. private void UpdateBtnFightTimes()
  106. {
  107. if (_ui.m_groupPass.visible)
  108. {
  109. int time = InstanceZonesDataManager.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. var title = levelCfg.name;
  133. switch (levelCfg.type)
  134. {
  135. case ConstInstanceZonesType.Story:
  136. title = MainStoryDataManager.CurrentChapterOrder + "-" + InstanceZonesDataManager.currentLevelOrder + " " + levelCfg.name;
  137. break;
  138. }
  139. _ui.m_txtTitle.text = title;
  140. _ui.m_txtLevelDesc.text = levelCfg.desc;
  141. _ui.m_txtPowerDesc.SetVar("power", "" + levelCfg.power).FlushVars();
  142. _ui.m_scoreType.url = "ui://CommonGame/kp_sx_" + fightCfg.scoreType;
  143. if (fightCfg.targetName != null && fightCfg.targetName.Length > 0)
  144. {
  145. _ui.m_txtTargetName.text = "挑战对手 : " + fightCfg.targetName;
  146. _ui.m_loaderHead.url = ResPathUtil.GetNpcHeadPath(fightCfg.targetRes);
  147. }
  148. else
  149. {
  150. _ui.m_txtTargetName.text = RoleDataManager.roleName;
  151. _ui.m_loaderHead.url = ResPathUtil.GetNpcHeadPath("self");
  152. }
  153. _bonusList.Clear();
  154. if (MainStoryDataManager.CheckCurrentLevelPass())
  155. {
  156. _bonusList = StoryBonusDataCache.GetBonusList(_levelID, false);
  157. _ui.m_groupPass.visible = true;
  158. _ui.m_groupUnpass.visible = false;
  159. UpdateBtnFightTimes();
  160. }
  161. else
  162. {
  163. _bonusList = StoryBonusDataCache.GetBonusList(_levelID, true);
  164. _ui.m_groupPass.visible = false;
  165. _ui.m_groupUnpass.visible = true;
  166. _ui.m_txtUnpassTips.SetVar("count", NumberUtil.GetChiniseNumberText(fightCfg.quickFightStart)).FlushVars();
  167. }
  168. _ui.m_listBonus.numItems = _bonusList.Count;
  169. if (_ui.m_listBonus.numItems > 4)
  170. {
  171. _ui.m_listBonus.columnGap = 40;
  172. }
  173. else
  174. {
  175. _ui.m_listBonus.columnGap = 60;
  176. }
  177. int score = InstanceZonesDataManager.GetScoreHighest(_levelID);
  178. if (score > 0)
  179. {
  180. string scoreStr = "" + score;
  181. if (score <= fightCfg.score1)
  182. {
  183. scoreStr = "[color=#A28D77]失败 " + scoreStr + "[/color]";
  184. }
  185. _ui.m_txtHighestScore.text = scoreStr;
  186. _ui.m_flower.target.visible = true;
  187. int starCount = InstanceZonesDataManager.GetStarCountHistory(_levelID);
  188. StoryUtil.UpdateStar(starCount, _ui.m_flower.target);
  189. }
  190. else
  191. {
  192. _ui.m_txtHighestScore.text = "--";
  193. _ui.m_flower.target.visible = false;
  194. }
  195. _ui.m_ctrlNeed.selectedIndex = 0;
  196. if (fightCfg.needItemId != 0)
  197. {
  198. _ui.m_ctrlNeed.selectedIndex = 1;
  199. ItemCfg cfg = ItemCfgArray.Instance.GetCfg(fightCfg.needItemId);
  200. _ui.m_txtNeed.text = cfg.name;
  201. }
  202. else if (fightCfg.needSuitId != 0)
  203. {
  204. _ui.m_ctrlNeed.selectedIndex = 1;
  205. SuitCfg cfg = SuitCfgArray.Instance.GetCfg(fightCfg.needSuitId);
  206. _ui.m_txtNeed.text = cfg.name;
  207. }
  208. else if (fightCfg.needTagsArr.Length > 0)
  209. {
  210. _ui.m_ctrlNeed.selectedIndex = 2;
  211. _ui.m_listTag.numItems = fightCfg.needTagsArr.Length;
  212. }
  213. }
  214. private void RenderListTagItem(int index, GObject obj)
  215. {
  216. UI_ListTagItem item = UI_ListTagItem.Proxy(obj);
  217. StoryLevelCfg levelCfg = StoryLevelCfgArray.Instance.GetCfg(_levelID);
  218. StoryFightCfg fightCfg = StoryFightCfgArray.Instance.GetCfg(levelCfg.fightID);
  219. string[] tag = fightCfg.needTagsArr[index].Split('_');
  220. item.m_loaTag.url = ResPathUtil.GetCommonGameResPath("fzd_bqbq_" + tag[0]);
  221. item.m_txtTag.text = tag[1];
  222. }
  223. protected override void UpdateToCheckGuide(object param)
  224. {
  225. if (!ViewManager.CheckIsTopView(this.viewCom)) return;
  226. GuideController.TryGuide(_ui.m_btnStart, ConstGuideId.SINGLE_FIGHT, 2, "点击开启换装");
  227. if (GuideController.TryGuide(_ui.m_txtNeed, ConstGuideId.CLOTHING_SYNTHETIC, 2, "这次必需品,要通过合成获得"))
  228. {
  229. _ui.m_btnStart.touchable = false;
  230. }
  231. GuideController.TryGuide(null, ConstGuideId.CLOTHING_SYNTHETIC, 3, "点击空白处关闭", false, 0, true, false, (int)(this.viewCom.y + _ui.m_groupPass.y));
  232. GuideController.TryGuide(_ui.m_listTag, ConstGuideId.OPEN_TAGS, 1, "选择相应的关卡标签,可提高分数", false, 0, true, false, 0);
  233. GuideController.TryCompleteGuide(ConstGuideId.OPEN_TAGS, 1);
  234. }
  235. protected override void TryCompleteGuide()
  236. {
  237. GuideCfg cfg = GuideCfgArray.Instance.GetCfg(ConstGuideId.CLOTHING_SYNTHETIC);
  238. GuideController.TryCompleteGuideIndex(cfg.id, 3);
  239. }
  240. }
  241. }