StoryFightQuicklyView.cs 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250
  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 int _needItemId;
  18. private int _needItemCount;
  19. private List<ItemData> _bonusList;
  20. private int _index;
  21. private int _expAdd;
  22. private int _power;
  23. private int _fightTimes;
  24. private const int _timeCount = 10;
  25. public override void Dispose()
  26. {
  27. if (_ui != null)
  28. {
  29. _ui.Dispose();
  30. _ui = null;
  31. }
  32. base.Dispose();
  33. }
  34. protected override void OnInit()
  35. {
  36. base.OnInit();
  37. _ui = UI_StoryFightQuicklyUI.Create();
  38. this.viewCom = _ui.target;
  39. this.viewCom.Center();
  40. this.modal = true;
  41. this.clickBlankToClose = false;
  42. _ui.m_btnExit.onClick.Add(Hide);
  43. _ui.m_btnFightTimes.onClick.Add(StartFight);
  44. }
  45. protected override void AddEventListener()
  46. {
  47. base.AddEventListener();
  48. EventAgent.AddEventListener(ConstMessage.NUMERIC_CHANGE, UpdateBtnFightTimes);
  49. // EventAgent.AddEventListener(ConstMessage.STORY_FIGHT_QUICKLY_SUCCESS, StartShowBonus);
  50. }
  51. protected override void OnShown()
  52. {
  53. base.OnShown();
  54. _fightType = (int)(viewData as object[])[0];
  55. _needItemId = (int)(viewData as object[])[1];
  56. _needItemCount = (int)(viewData as object[])[2];
  57. _levelID = InstanceZonesDataManager.currentLevelCfgId;
  58. InstanceZonesDataManager.isQuicklyFighting = true;
  59. StoryLevelCfg levelCfg = StoryLevelCfgArray.Instance.GetCfg(_levelID);
  60. StoryFightCfg fightCfg = StoryFightCfgArray.Instance.GetCfg(levelCfg.fightID);
  61. _type = levelCfg.type;
  62. _storyType = levelCfg.subType;
  63. _expAdd = fightCfg.exp;
  64. _power = levelCfg.power;
  65. string title = levelCfg.name;
  66. switch (levelCfg.type)
  67. {
  68. case ConstInstanceZonesType.Story:
  69. title = MainStoryDataManager.CurrentChapterOrder + "-" + InstanceZonesDataManager.currentLevelOrder + " " + levelCfg.name;
  70. break;
  71. }
  72. _ui.m_txtName.text = title;
  73. _ui.m_c1.selectedIndex = _needItemId <= 0 || _needItemCount <= 0 || ItemDataManager.GetItemNum(_needItemId) >= _needItemCount ? 0 : 1;
  74. updateNeedItem();
  75. StartFight();
  76. }
  77. protected override void OnHide()
  78. {
  79. base.OnHide();
  80. // Timers.inst.Remove(ShowBonusItem);
  81. ViewManager.GoBackFrom(typeof(StoryFightQuicklyView).Name);
  82. InstanceZonesDataManager.isQuicklyFighting = false;
  83. }
  84. protected override void RemoveEventListener()
  85. {
  86. base.RemoveEventListener();
  87. EventAgent.RemoveEventListener(ConstMessage.NUMERIC_CHANGE, UpdateBtnFightTimes);
  88. // EventAgent.RemoveEventListener(ConstMessage.STORY_FIGHT_QUICKLY_SUCCESS, StartShowBonus);
  89. }
  90. private void StartFight()
  91. {
  92. InstanceZonesDataManager.GetCanFightTime(_type, _storyType, _levelID, out _fightTimes, out string title);
  93. if (_fightTimes == 0)
  94. {
  95. StoryLevelCfg levelCfg = StoryLevelCfgArray.Instance.GetCfg(_levelID);
  96. if (levelCfg.type == ConstInstanceZonesType.Story)
  97. {
  98. ItemUtil.AddPower("体力不足", StartFight);
  99. }
  100. else if (levelCfg.type == ConstInstanceZonesType.Studio)
  101. {
  102. StudioData studioData = StudioDataManager.Instance.GetStudioDataById(levelCfg.chapterId);
  103. if (studioData.TotalPlayTimes - studioData.PlayTimes == 0)
  104. {
  105. PromptController.Instance.ShowFloatTextPrompt("挑战次数不足");
  106. ViewManager.Show<StudioBuyNumView>(levelCfg.chapterId);
  107. }
  108. else
  109. {
  110. ItemUtil.AddPower("体力不足", StartFight);
  111. }
  112. }
  113. return;
  114. }
  115. this.clickBlankToClose = false;
  116. // _ui.m_t0.Play(() =>
  117. // {
  118. _fightTimes = _fightType == 1 ? 1 : _fightTimes;
  119. _ui.m_btnExit.visible = false;
  120. _ui.m_btnFightTimes.visible = false;
  121. _ui.m_comCostCurrent.visible = false;
  122. _ui.m_list.RemoveChildren();
  123. InstanceZonesDataManager.isQuicklyFighting = true;
  124. // InstanceZonesSProxy.FinishStoryFightQuickly(_levelID, _fightType == 1 ? 1 : times).Coroutine();
  125. _index = 0;
  126. ReqFightQuickly(null);
  127. // });
  128. }
  129. private async void ReqFightQuickly(object param)
  130. {
  131. bool isFinish = _needItemId > 0 && _needItemCount > 0 && ItemDataManager.GetItemNum(_needItemId) >= _needItemCount;
  132. if (_index >= _fightTimes || isFinish)
  133. {
  134. if (isFinish)
  135. {
  136. PromptController.Instance.ShowFloatTextPrompt("材料已足够");
  137. }
  138. ShowEnding();
  139. }
  140. else
  141. {
  142. List<ItemData> result = await InstanceZonesSProxy.FinishStoryFightQuickly(_levelID, 1);
  143. ET.Log.Debug("result:" + result.Count);
  144. if (result != null)
  145. {
  146. _bonusList = result;
  147. ShowBonusItem();
  148. _index++;
  149. Timers.inst.Add(0.3f, 1, ReqFightQuickly);
  150. }
  151. }
  152. }
  153. private void ShowBonusItem()
  154. {
  155. UI_StoryFightQuicklyBonusListItem listItem = UI_StoryFightQuicklyBonusListItem.Proxy();
  156. _ui.m_list.AddChild(listItem.target);
  157. listItem.m_list.itemRenderer = ListItemRender;
  158. listItem.m_txtTimes.SetVar("n", "" + NumberUtil.GetChiniseNumberText(_index + 1)).FlushVars();
  159. listItem.m_txtExp.SetVar("n", "" + _expAdd).FlushVars();
  160. listItem.m_list.numItems = _bonusList.Count;
  161. listItem.m_list.ResizeToFit();
  162. listItem.target.height = listItem.m_list.y + listItem.m_list.height;
  163. UI_StoryFightQuicklyBonusListItem.ProxyEnd();
  164. _ui.m_list.ScrollToView(_index, true);
  165. }
  166. private void ShowEnding()
  167. {
  168. UI_StoryFightQuicklyComplete completeItem = UI_StoryFightQuicklyComplete.Proxy();
  169. _ui.m_list.AddChild(completeItem.target);
  170. UI_StoryFightQuicklyComplete.ProxyEnd();
  171. InstanceZonesDataManager.isQuicklyFighting = false;
  172. _ui.m_btnExit.visible = true;
  173. _ui.m_list.ScrollToView(_index, true);
  174. UpdateBtnFightTimes();
  175. updateNeedItem();
  176. _ui.m_comCostCurrent.visible = true;
  177. _index = 0;
  178. this.clickBlankToClose = true;
  179. }
  180. private void ListItemRender(int index, GObject item)
  181. {
  182. ItemData itemData = _bonusList[index] as ItemData;
  183. if (item.data == null)
  184. {
  185. item.data = new ItemView(item as GComponent);
  186. }
  187. (item.data as ItemView).SetData(itemData);
  188. (item.data as ItemView).ShowName = true;
  189. (item.data as ItemView).SetComItemScale = 0.8f;
  190. (item.data as ItemView).SetTxtCountPos(210, 160);
  191. (item.data as ItemView).SetTxtNamePos(110, 200);
  192. // (item.data as ItemView).ShowHasCount = false;
  193. }
  194. private void UpdateBtnFightTimes()
  195. {
  196. if (_ui.m_btnExit.visible)
  197. {
  198. StoryLevelCfg levelCfg = StoryLevelCfgArray.Instance.GetCfg(_levelID);
  199. InstanceZonesDataManager.GetCanFightTime(_type, _storyType, _levelID, out _fightTimes, out string title);
  200. _ui.m_btnFightTimes.title = _fightType == 1 ? "挑战一次" : title;
  201. _ui.m_btnFightTimes.visible = _fightTimes > 0;
  202. _ui.m_comCostCurrent.visible = _fightTimes > 0;
  203. _fightTimes = _fightType == 1 ? 1 : _fightTimes;
  204. int power = _fightTimes * levelCfg.power;
  205. ItemUtil.SetItemNeedNum(_ui.m_comCostCurrent, ConstItemID.POWER, power);
  206. }
  207. }
  208. private void updateNeedItem()
  209. {
  210. bool isFinish = _needItemId > 0 && _needItemCount > 0 && ItemDataManager.GetItemNum(_needItemId) >= _needItemCount;
  211. if (isFinish)
  212. {
  213. _needItemCount = 0;
  214. }
  215. if (_ui.m_c1.selectedIndex == 0) return;
  216. _ui.m_txtItemName.text = string.Format("目标道具:{0}", ItemCfgArray.Instance.GetCfg(_needItemId).name);
  217. int hasCount = ItemDataManager.GetItemNum(_needItemId);
  218. _ui.m_txtItemNeedNum.text = (_needItemCount - hasCount) <= 0 ? "材料已足够" : string.Format("还需:{0}个", Math.Max(0, _needItemCount - hasCount));
  219. }
  220. }
  221. }