StoryLevelInfoView.cs 10 KB

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