StoryLevelInfoView.cs 9.7 KB

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