StoryFightQuicklyView.cs 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
  1. using FairyGUI;
  2. using UI.Main;
  3. using System.Collections;
  4. using UI.CommonGame;
  5. using System;
  6. using System.Collections.Generic;
  7. namespace GFGGame
  8. {
  9. public class StoryFightQuicklyView : BaseWindow
  10. {
  11. private UI_StoryFightQuicklyUI _ui;
  12. private int _fightID;
  13. private int _levelID;
  14. private int _type;
  15. private int _storyType;
  16. private int _fightType;
  17. private List<List<ItemData>> _totalBonusList;
  18. private int _index;
  19. private int _expAdd;
  20. private int _power;
  21. private int _fightTimes;
  22. private const int _timeCount = 10;
  23. public override void Dispose()
  24. {
  25. if (_ui != null)
  26. {
  27. _ui.Dispose();
  28. _ui = null;
  29. }
  30. base.Dispose();
  31. }
  32. protected override void OnInit()
  33. {
  34. base.OnInit();
  35. _ui = UI_StoryFightQuicklyUI.Create();
  36. this.viewCom = _ui.target;
  37. this.viewCom.Center();
  38. this.modal = true;
  39. _ui.m_btnExit.onClick.Add(Hide);
  40. _ui.m_btnFightTimes.onClick.Add(StartFight);
  41. }
  42. protected override void AddEventListener()
  43. {
  44. base.AddEventListener();
  45. EventAgent.AddEventListener(ConstMessage.NUMERIC_CHANGE, UpdateBtnFightTimes);
  46. EventAgent.AddEventListener(ConstMessage.STORY_FIGHT_QUICKLY_SUCCESS, StartShowBonus);
  47. }
  48. protected override void OnShown()
  49. {
  50. base.OnShown();
  51. _fightType = (int)viewData;
  52. _levelID = InstanceZonesDataManager.currentLevelCfgId;
  53. InstanceZonesDataManager.isQuicklyFighting = true;
  54. StoryLevelCfg levelCfg = StoryLevelCfgArray.Instance.GetCfg(_levelID);
  55. StoryFightCfg fightCfg = StoryFightCfgArray.Instance.GetCfg(levelCfg.fightID);
  56. _type = levelCfg.type;
  57. _storyType = levelCfg.subType;
  58. _expAdd = fightCfg.exp;
  59. _power = levelCfg.power;
  60. StartFight();
  61. }
  62. protected override void OnHide()
  63. {
  64. base.OnHide();
  65. Timers.inst.Remove(ShowBonusItem);
  66. ViewManager.GoBackFrom(typeof(StoryFightQuicklyView).Name);
  67. InstanceZonesDataManager.isQuicklyFighting = false;
  68. }
  69. protected override void RemoveEventListener()
  70. {
  71. base.RemoveEventListener();
  72. EventAgent.RemoveEventListener(ConstMessage.NUMERIC_CHANGE, UpdateBtnFightTimes);
  73. EventAgent.RemoveEventListener(ConstMessage.STORY_FIGHT_QUICKLY_SUCCESS, StartShowBonus);
  74. }
  75. private void StartFight()
  76. {
  77. InstanceZonesDataManager.GetCanFightTime(_type, _storyType, _levelID, out int times, out string title);
  78. if (times == 0)
  79. {
  80. StoryLevelCfg levelCfg = StoryLevelCfgArray.Instance.GetCfg(_levelID);
  81. if (levelCfg.type == ConstInstanceZonesType.Story)
  82. {
  83. ItemUtil.AddPower("体力不足", StartFight);
  84. }
  85. else if (levelCfg.type == ConstInstanceZonesType.Studio)
  86. {
  87. StudioData studioData = StudioDataManager.Instance.GetStudioDataById(levelCfg.chapterId);
  88. if (studioData.TotalPlayTimes - studioData.PlayTimes == 0)
  89. {
  90. PromptController.Instance.ShowFloatTextPrompt("挑战次数不足");
  91. ViewManager.Show<StudioBuyNumView>(levelCfg.chapterId);
  92. }
  93. else
  94. {
  95. ItemUtil.AddPower("体力不足", StartFight);
  96. }
  97. }
  98. return;
  99. }
  100. this.clickBlankToClose = false;
  101. // _ui.m_t0.Play(() =>
  102. // {
  103. _ui.m_btnExit.visible = false;
  104. _ui.m_btnFightTimes.visible = false;
  105. _ui.m_txtPowerDesc.visible = false;
  106. _ui.m_list.RemoveChildren();
  107. InstanceZonesDataManager.isQuicklyFighting = true;
  108. InstanceZonesSProxy.FinishStoryFightQuickly(_levelID, _fightType == 1 ? 1 : times).Coroutine();
  109. this.clickBlankToClose = true;
  110. // });
  111. }
  112. private void StartShowBonus(EventContext eventContext)
  113. {
  114. _totalBonusList = (List<List<ItemData>>)eventContext.data;
  115. _index = 0;
  116. ShowBonusItem();
  117. Timers.inst.Add(0.3f, 0, ShowBonusItem);
  118. }
  119. private void ShowBonusItem(object param = null)
  120. {
  121. if (_index < _totalBonusList.Count)
  122. {
  123. List<ItemData> bonusList = _totalBonusList[_index] as List<ItemData>;
  124. UI_StoryFightQuicklyBonusListItem listItem = UI_StoryFightQuicklyBonusListItem.Proxy();
  125. listItem.m_list.itemRenderer = ListItemRender;
  126. _ui.m_list.AddChild(listItem.target);
  127. int order = _index + 1;
  128. listItem.m_txtTimes.SetVar("n", "" + NumberUtil.GetChiniseNumberText(order)).FlushVars();
  129. listItem.m_txtExp.SetVar("n", "" + _expAdd).FlushVars();
  130. listItem.m_list.numItems = bonusList.Count;
  131. listItem.m_list.ResizeToFit();
  132. listItem.target.height = listItem.m_list.y + listItem.m_list.height;
  133. _index++;
  134. UI_StoryFightQuicklyBonusListItem.ProxyEnd();
  135. }
  136. else
  137. {
  138. UI_StoryFightQuicklyComplete completeItem = UI_StoryFightQuicklyComplete.Proxy();
  139. _ui.m_list.AddChild(completeItem.target);
  140. UI_StoryFightQuicklyComplete.ProxyEnd();
  141. Timers.inst.Remove(ShowBonusItem);
  142. InstanceZonesDataManager.isQuicklyFighting = false;
  143. _ui.m_btnExit.visible = true;
  144. UpdateBtnFightTimes();
  145. }
  146. _ui.m_list.ScrollToView(_index - 1, true);
  147. //.ScrollBottom();
  148. }
  149. private void ListItemRender(int index, GObject item)
  150. {
  151. List<ItemData> bonusList = _totalBonusList[_index] as List<ItemData>;
  152. ItemData itemData = bonusList[index] as ItemData;
  153. if (item.data == null)
  154. {
  155. item.data = new ItemView(item as GComponent);
  156. }
  157. (item.data as ItemView).SetData(itemData);
  158. (item.data as ItemView).TxtHasCountVisble = false;
  159. }
  160. private void UpdateBtnFightTimes()
  161. {
  162. if (_ui.m_btnExit.visible)
  163. {
  164. StoryLevelCfg levelCfg = StoryLevelCfgArray.Instance.GetCfg(_levelID);
  165. InstanceZonesDataManager.GetCanFightTime(_type, _storyType, _levelID, out int times, out string title);
  166. _ui.m_btnFightTimes.title = _fightType == 1 ? "挑战一次" : title;
  167. _ui.m_btnFightTimes.visible = times > 0;
  168. _ui.m_txtPowerDesc.visible = _ui.m_btnFightTimes.visible;
  169. if (_ui.m_txtPowerDesc.visible)
  170. {
  171. int power = times * levelCfg.power;
  172. _ui.m_txtPowerDesc.SetVar("v1", "" + power).FlushVars();
  173. }
  174. }
  175. }
  176. }
  177. }