StoryFightQuicklyView.cs 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256
  1. using FairyGUI;
  2. using UI.Main;
  3. using System.Collections;
  4. using UI.CommonGame;
  5. using System;
  6. using System.Collections.Generic;
  7. using cfg.GfgCfg;
  8. using ET;
  9. namespace GFGGame
  10. {
  11. public class StoryFightQuicklyView : BaseWindow
  12. {
  13. private UI_StoryFightQuicklyUI _ui;
  14. private int _fightID;
  15. private int _levelID;
  16. private int _type;
  17. private int _storyType;
  18. private int _fightType;
  19. private int _needItemId;
  20. private int _needItemCount;
  21. private List<ItemData> _bonusList;
  22. private int _index;
  23. private int _expAdd;
  24. private int _power;
  25. private int _fightTimes;
  26. private const int _timeCount = 10;
  27. public override void Dispose()
  28. {
  29. if (_ui != null)
  30. {
  31. _ui.Dispose();
  32. _ui = null;
  33. }
  34. base.Dispose();
  35. }
  36. protected override void OnInit()
  37. {
  38. base.OnInit();
  39. _ui = UI_StoryFightQuicklyUI.Create();
  40. this.viewCom = _ui.target;
  41. this.viewCom.Center();
  42. this.modal = true;
  43. this.clickBlankToClose = false;
  44. _ui.m_btnExit.onClick.Add(Hide);
  45. _ui.m_btnFightTimes.onClick.Add(StartFight);
  46. }
  47. protected override void AddEventListener()
  48. {
  49. base.AddEventListener();
  50. EventAgent.AddEventListener(ConstMessage.NUMERIC_CHANGE, UpdateBtnFightTimes);
  51. // EventAgent.AddEventListener(ConstMessage.STORY_FIGHT_QUICKLY_SUCCESS, StartShowBonus);
  52. }
  53. protected override void OnShown()
  54. {
  55. base.OnShown();
  56. _fightType = (int)(viewData as object[])[0];
  57. _needItemId = (int)(viewData as object[])[1];
  58. _needItemCount = (int)(viewData as object[])[2];
  59. _levelID = InstanceZonesDataManager.currentLevelCfgId;
  60. InstanceZonesDataManager.isQuicklyFighting = true;
  61. StoryLevelCfg levelCfg = CommonDataManager.Tables.TblStoryLevelCfg.GetOrDefault(_levelID);
  62. StoryFightCfg fightCfg = CommonDataManager.Tables.TblStoryFightCfg.GetOrDefault(int.Parse(levelCfg.FightID));
  63. _type = levelCfg.Type;
  64. _storyType = levelCfg.SubType;
  65. _expAdd = fightCfg.Exp;
  66. _power = levelCfg.Power;
  67. string title = levelCfg.Name;
  68. switch (levelCfg.Type)
  69. {
  70. case ConstInstanceZonesType.Story:
  71. title = MainStoryDataManager.CurrentChapterOrder + "-" + InstanceZonesDataManager.currentLevelOrder + " " + levelCfg.Name;
  72. break;
  73. }
  74. _ui.m_txtName.text = title;
  75. _ui.m_c1.selectedIndex = _needItemId <= 0 || _needItemCount <= 0 || ItemDataManager.GetItemNum(_needItemId) >= _needItemCount ? 0 : 1;
  76. updateNeedItem();
  77. StartFight();
  78. }
  79. protected override void OnHide()
  80. {
  81. base.OnHide();
  82. // Timers.inst.Remove(ShowBonusItem);
  83. Timers.inst.Remove(ReqFightQuickly);
  84. ViewManager.GoBackFrom(typeof(StoryFightQuicklyView).Name);
  85. InstanceZonesDataManager.isQuicklyFighting = false;
  86. }
  87. protected override void RemoveEventListener()
  88. {
  89. base.RemoveEventListener();
  90. EventAgent.RemoveEventListener(ConstMessage.NUMERIC_CHANGE, UpdateBtnFightTimes);
  91. // EventAgent.RemoveEventListener(ConstMessage.STORY_FIGHT_QUICKLY_SUCCESS, StartShowBonus);
  92. }
  93. private void StartFight()
  94. {
  95. InstanceZonesDataManager.GetCanFightTime(_type, _storyType, _levelID, out _fightTimes, out string title);
  96. if (_fightTimes == 0)
  97. {
  98. StoryLevelCfg levelCfg = CommonDataManager.Tables.TblStoryLevelCfg.GetOrDefault(_levelID);
  99. if (levelCfg.Type == ConstInstanceZonesType.Story)
  100. {
  101. ItemUtil.AddPower(StartFight);
  102. }
  103. else if (levelCfg.Type == ConstInstanceZonesType.Studio)
  104. {
  105. var studioCfg = CommonDataManager.Tables.TblStudioCfg.GetOrDefault(levelCfg.ChapterId);
  106. if (!RoleLimitDataManager.CheckPlayTimesEnough(studioCfg.Limit, 1))
  107. {
  108. PromptController.Instance.ShowFloatTextPrompt("挑战次数不足");
  109. ViewManager.Show<StudioBuyNumView>(studioCfg.Limit);
  110. }
  111. else
  112. {
  113. ItemUtil.AddPower(StartFight);
  114. }
  115. }
  116. return;
  117. }
  118. // this.clickBlankToClose = false;
  119. // _ui.m_t0.Play(() =>
  120. // {
  121. _fightTimes = _fightType == 1 ? 1 : _fightTimes;
  122. _ui.m_btnExit.visible = false;
  123. _ui.m_btnFightTimes.visible = false;
  124. _ui.m_comCostCurrent.visible = false;
  125. _ui.m_list.RemoveChildrenToPool();
  126. InstanceZonesDataManager.isQuicklyFighting = true;
  127. // InstanceZonesSProxy.FinishStoryFightQuickly(_levelID, _fightType == 1 ? 1 : times).Coroutine();
  128. _index = 0;
  129. ReqFightQuickly(null);
  130. // });
  131. }
  132. private async void ReqFightQuickly(object param)
  133. {
  134. long hasCount = ItemDataManager.GetItemNum(_needItemId);
  135. bool isFinish = _needItemId > 0 && _needItemCount > 0 && hasCount >= _needItemCount;
  136. _ui.m_txtItemNeedNum.text = string.Format("还需:{0}个", Math.Max(0, _needItemCount - hasCount));
  137. if (_index >= _fightTimes || isFinish)
  138. {
  139. if (isFinish)
  140. {
  141. _ui.m_txtItemNeedNum.text = "材料已足够";
  142. PromptController.Instance.ShowFloatTextPrompt("材料已足够");
  143. }
  144. ShowEnding();
  145. }
  146. else
  147. {
  148. List<ItemData> result = await InstanceZonesSProxy.FinishStoryFightQuickly(_levelID, 1);
  149. if (result != null)
  150. {
  151. _bonusList = result;
  152. ShowBonusItem();
  153. _index++;
  154. Timers.inst.Add(0.3f, 1, ReqFightQuickly);
  155. }
  156. }
  157. }
  158. private void ShowBonusItem()
  159. {
  160. _ui.m_list.AddItemFromPool("ui://Main/StoryFightQuicklyBonusListItem");//AddChild(listItem.target);
  161. GObject obj = _ui.m_list.GetChildAt(_index);
  162. UI_StoryFightQuicklyBonusListItem listItem = UI_StoryFightQuicklyBonusListItem.Proxy(obj);
  163. listItem.m_list.itemRenderer = ListItemRender;
  164. listItem.m_txtTimes.SetVar("n", "" + NumberUtil.GetChiniseNumberText(_index + 1)).FlushVars();
  165. listItem.m_txtExp.SetVar("n", "" + _expAdd).FlushVars();
  166. listItem.m_list.numItems = _bonusList.Count;
  167. listItem.m_list.ResizeToFit();
  168. listItem.target.height = listItem.m_list.y + listItem.m_list.height;
  169. UI_StoryFightQuicklyBonusListItem.ProxyEnd();
  170. _ui.m_list.ScrollToView(_index, true);
  171. }
  172. private void ShowEnding()
  173. {
  174. // UI_StoryFightQuicklyComplete completeItem = UI_StoryFightQuicklyComplete.Proxy();
  175. _ui.m_list.AddItemFromPool("ui://Main/StoryFightQuicklyComplete");//AddChild(completeItem.target);
  176. // UI_StoryFightQuicklyComplete.ProxyEnd();
  177. InstanceZonesDataManager.isQuicklyFighting = false;
  178. _ui.m_btnExit.visible = true;
  179. _ui.m_list.ScrollToView(_index, true);
  180. UpdateBtnFightTimes();
  181. updateNeedItem();
  182. // _ui.m_comCostCurrent.visible = true;
  183. _index = 0;
  184. // this.clickBlankToClose = true;
  185. }
  186. private void ListItemRender(int index, GObject item)
  187. {
  188. ItemData itemData = _bonusList[index] as ItemData;
  189. if (item.data == null)
  190. {
  191. item.data = new ItemView(item as GComponent);
  192. }
  193. (item.data as ItemView).SetData(itemData);
  194. (item.data as ItemView).ShowName = true;
  195. (item.data as ItemView).SetTxtNameScale = 1.2f;
  196. // (item.data as ItemView).ShowHasCount = false;
  197. }
  198. private void UpdateBtnFightTimes()
  199. {
  200. if (_ui.m_btnExit.visible)
  201. {
  202. StoryLevelCfg levelCfg = CommonDataManager.Tables.TblStoryLevelCfg.GetOrDefault(_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}", CommonDataManager.Tables.TblItemCfg.GetOrDefault(_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. }