StoryFightQuicklyView.cs 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255
  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. var studioCfg = StudioCfgArray.Instance.GetCfg(levelCfg.chapterId);
  103. if (!RoleLimitDataManager.CheckPlayTimesEnough(studioCfg.limit, 1))
  104. {
  105. PromptController.Instance.ShowFloatTextPrompt("挑战次数不足");
  106. ViewManager.Show<StudioBuyNumView>(studioCfg.limit);
  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.RemoveChildrenToPool();
  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. long hasCount = ItemDataManager.GetItemNum(_needItemId);
  132. bool isFinish = _needItemId > 0 && _needItemCount > 0 && hasCount >= _needItemCount;
  133. _ui.m_txtItemNeedNum.text = string.Format("还需:{0}个", Math.Max(0, _needItemCount - hasCount));
  134. if (_index >= _fightTimes || isFinish)
  135. {
  136. if (isFinish)
  137. {
  138. _ui.m_txtItemNeedNum.text = "材料已足够";
  139. PromptController.Instance.ShowFloatTextPrompt("材料已足够");
  140. }
  141. ShowEnding();
  142. }
  143. else
  144. {
  145. List<ItemData> result = await InstanceZonesSProxy.FinishStoryFightQuickly(_levelID, 1);
  146. ET.Log.Debug("result:" + result.Count);
  147. if (result != null)
  148. {
  149. _bonusList = result;
  150. ShowBonusItem();
  151. _index++;
  152. Timers.inst.Add(0.3f, 1, ReqFightQuickly);
  153. }
  154. }
  155. }
  156. private void ShowBonusItem()
  157. {
  158. _ui.m_list.AddItemFromPool("ui://Main/StoryFightQuicklyBonusListItem");//AddChild(listItem.target);
  159. GObject obj = _ui.m_list.GetChildAt(_index);
  160. UI_StoryFightQuicklyBonusListItem listItem = UI_StoryFightQuicklyBonusListItem.Proxy(obj);
  161. listItem.m_list.itemRenderer = ListItemRender;
  162. listItem.m_txtTimes.SetVar("n", "" + NumberUtil.GetChiniseNumberText(_index + 1)).FlushVars();
  163. listItem.m_txtExp.SetVar("n", "" + _expAdd).FlushVars();
  164. listItem.m_list.numItems = _bonusList.Count;
  165. listItem.m_list.ResizeToFit();
  166. listItem.target.height = listItem.m_list.y + listItem.m_list.height;
  167. UI_StoryFightQuicklyBonusListItem.ProxyEnd();
  168. _ui.m_list.ScrollToView(_index, true);
  169. }
  170. private void ShowEnding()
  171. {
  172. // UI_StoryFightQuicklyComplete completeItem = UI_StoryFightQuicklyComplete.Proxy();
  173. _ui.m_list.AddItemFromPool("ui://Main/StoryFightQuicklyComplete");//AddChild(completeItem.target);
  174. // UI_StoryFightQuicklyComplete.ProxyEnd();
  175. InstanceZonesDataManager.isQuicklyFighting = false;
  176. _ui.m_btnExit.visible = true;
  177. _ui.m_list.ScrollToView(_index, true);
  178. UpdateBtnFightTimes();
  179. updateNeedItem();
  180. // _ui.m_comCostCurrent.visible = true;
  181. _index = 0;
  182. // this.clickBlankToClose = true;
  183. }
  184. private void ListItemRender(int index, GObject item)
  185. {
  186. ItemData itemData = _bonusList[index] as ItemData;
  187. if (item.data == null)
  188. {
  189. item.data = new ItemView(item as GComponent);
  190. }
  191. (item.data as ItemView).SetData(itemData);
  192. (item.data as ItemView).ShowName = true;
  193. (item.data as ItemView).SetComItemScale = 0.8f;
  194. (item.data as ItemView).SetTxtCountPos(210, 160);
  195. (item.data as ItemView).SetTxtNamePos(110, 200);
  196. // (item.data as ItemView).ShowHasCount = false;
  197. }
  198. private void UpdateBtnFightTimes()
  199. {
  200. if (_ui.m_btnExit.visible)
  201. {
  202. StoryLevelCfg levelCfg = StoryLevelCfgArray.Instance.GetCfg(_levelID);
  203. InstanceZonesDataManager.GetCanFightTime(_type, _storyType, _levelID, out _fightTimes, out string title);
  204. _ui.m_btnFightTimes.title = _fightType == 1 ? "挑战一次" : title;
  205. _ui.m_btnFightTimes.visible = _fightTimes > 0;
  206. _fightTimes = _fightType == 1 ? 1 : _fightTimes;
  207. int power = _fightTimes * levelCfg.power;
  208. ItemUtil.UpdateItemNeedNum(_ui.m_comCostCurrent, ConstItemID.POWER, power);
  209. _ui.m_comCostCurrent.visible = _fightTimes > 0 && power > 0;
  210. }
  211. }
  212. private void updateNeedItem()
  213. {
  214. bool isFinish = _needItemId > 0 && _needItemCount > 0 && ItemDataManager.GetItemNum(_needItemId) >= _needItemCount;
  215. if (isFinish)
  216. {
  217. _needItemCount = 0;
  218. }
  219. if (_ui.m_c1.selectedIndex == 0) return;
  220. _ui.m_txtItemName.text = string.Format("目标道具:{0}", ItemCfgArray.Instance.GetCfg(_needItemId).name);
  221. long hasCount = ItemDataManager.GetItemNum(_needItemId);
  222. _ui.m_txtItemNeedNum.text = (_needItemCount - hasCount) <= 0 ? "材料已足够" : string.Format("还需:{0}个", Math.Max(0, _needItemCount - hasCount));
  223. }
  224. }
  225. }