StoryFightQuicklyView.cs 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224
  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<List<ItemData>> _totalBonusList;
  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. _ui.m_btnExit.onClick.Add(Hide);
  42. _ui.m_btnFightTimes.onClick.Add(StartFight);
  43. }
  44. protected override void AddEventListener()
  45. {
  46. base.AddEventListener();
  47. EventAgent.AddEventListener(ConstMessage.NUMERIC_CHANGE, UpdateBtnFightTimes);
  48. EventAgent.AddEventListener(ConstMessage.STORY_FIGHT_QUICKLY_SUCCESS, StartShowBonus);
  49. }
  50. protected override void OnShown()
  51. {
  52. base.OnShown();
  53. _fightType = (int)(viewData as object[])[0];
  54. _needItemId = (int)(viewData as object[])[1];
  55. _needItemCount = (int)(viewData as object[])[2];
  56. _levelID = InstanceZonesDataManager.currentLevelCfgId;
  57. InstanceZonesDataManager.isQuicklyFighting = true;
  58. StoryLevelCfg levelCfg = StoryLevelCfgArray.Instance.GetCfg(_levelID);
  59. StoryFightCfg fightCfg = StoryFightCfgArray.Instance.GetCfg(levelCfg.fightID);
  60. _type = levelCfg.type;
  61. _storyType = levelCfg.subType;
  62. _expAdd = fightCfg.exp;
  63. _power = levelCfg.power;
  64. string title = levelCfg.name;
  65. switch (levelCfg.type)
  66. {
  67. case ConstInstanceZonesType.Story:
  68. title = MainStoryDataManager.CurrentChapterOrder + "-" + InstanceZonesDataManager.currentLevelOrder + " " + levelCfg.name;
  69. break;
  70. }
  71. _ui.m_txtName.text = title;
  72. updateNeedItem();
  73. StartFight();
  74. }
  75. protected override void OnHide()
  76. {
  77. base.OnHide();
  78. Timers.inst.Remove(ShowBonusItem);
  79. ViewManager.GoBackFrom(typeof(StoryFightQuicklyView).Name);
  80. InstanceZonesDataManager.isQuicklyFighting = false;
  81. }
  82. protected override void RemoveEventListener()
  83. {
  84. base.RemoveEventListener();
  85. EventAgent.RemoveEventListener(ConstMessage.NUMERIC_CHANGE, UpdateBtnFightTimes);
  86. EventAgent.RemoveEventListener(ConstMessage.STORY_FIGHT_QUICKLY_SUCCESS, StartShowBonus);
  87. }
  88. private void StartFight()
  89. {
  90. InstanceZonesDataManager.GetCanFightTime(_type, _storyType, _levelID, out int times, out string title);
  91. if (times == 0)
  92. {
  93. StoryLevelCfg levelCfg = StoryLevelCfgArray.Instance.GetCfg(_levelID);
  94. if (levelCfg.type == ConstInstanceZonesType.Story)
  95. {
  96. ItemUtil.AddPower("体力不足", StartFight);
  97. }
  98. else if (levelCfg.type == ConstInstanceZonesType.Studio)
  99. {
  100. StudioData studioData = StudioDataManager.Instance.GetStudioDataById(levelCfg.chapterId);
  101. if (studioData.TotalPlayTimes - studioData.PlayTimes == 0)
  102. {
  103. PromptController.Instance.ShowFloatTextPrompt("挑战次数不足");
  104. ViewManager.Show<StudioBuyNumView>(levelCfg.chapterId);
  105. }
  106. else
  107. {
  108. ItemUtil.AddPower("体力不足", StartFight);
  109. }
  110. }
  111. return;
  112. }
  113. this.clickBlankToClose = false;
  114. // _ui.m_t0.Play(() =>
  115. // {
  116. _ui.m_btnExit.visible = false;
  117. _ui.m_btnFightTimes.visible = false;
  118. _ui.m_txtPowerDesc.visible = false;
  119. _ui.m_list.RemoveChildren();
  120. InstanceZonesDataManager.isQuicklyFighting = true;
  121. InstanceZonesSProxy.FinishStoryFightQuickly(_levelID, _fightType == 1 ? 1 : times).Coroutine();
  122. this.clickBlankToClose = true;
  123. // });
  124. }
  125. private void StartShowBonus(EventContext eventContext)
  126. {
  127. _totalBonusList = (List<List<ItemData>>)eventContext.data;
  128. _index = 0;
  129. ShowBonusItem();
  130. Timers.inst.Add(0.3f, 0, ShowBonusItem);
  131. }
  132. private void ShowBonusItem(object param = null)
  133. {
  134. if (_index < _totalBonusList.Count)
  135. {
  136. List<ItemData> bonusList = _totalBonusList[_index] as List<ItemData>;
  137. UI_StoryFightQuicklyBonusListItem listItem = UI_StoryFightQuicklyBonusListItem.Proxy();
  138. listItem.m_list.itemRenderer = ListItemRender;
  139. _ui.m_list.AddChild(listItem.target);
  140. int order = _index + 1;
  141. listItem.m_txtTimes.SetVar("n", "" + NumberUtil.GetChiniseNumberText(order)).FlushVars();
  142. listItem.m_txtExp.SetVar("n", "" + _expAdd).FlushVars();
  143. listItem.m_list.numItems = bonusList.Count;
  144. listItem.m_list.ResizeToFit();
  145. listItem.target.height = listItem.m_list.y + listItem.m_list.height;
  146. _index++;
  147. UI_StoryFightQuicklyBonusListItem.ProxyEnd();
  148. }
  149. else
  150. {
  151. UI_StoryFightQuicklyComplete completeItem = UI_StoryFightQuicklyComplete.Proxy();
  152. _ui.m_list.AddChild(completeItem.target);
  153. UI_StoryFightQuicklyComplete.ProxyEnd();
  154. Timers.inst.Remove(ShowBonusItem);
  155. InstanceZonesDataManager.isQuicklyFighting = false;
  156. _ui.m_btnExit.visible = true;
  157. UpdateBtnFightTimes();
  158. updateNeedItem();
  159. }
  160. _ui.m_list.ScrollToView(_index - 1, true);
  161. //.ScrollBottom();
  162. }
  163. private void ListItemRender(int index, GObject item)
  164. {
  165. List<ItemData> bonusList = _totalBonusList[_index] as List<ItemData>;
  166. ItemData itemData = bonusList[index] as ItemData;
  167. if (item.data == null)
  168. {
  169. item.data = new ItemView(item as GComponent);
  170. }
  171. (item.data as ItemView).SetData(itemData);
  172. (item.data as ItemView).TxtHasCountVisble = false;
  173. }
  174. private void UpdateBtnFightTimes()
  175. {
  176. if (_ui.m_btnExit.visible)
  177. {
  178. StoryLevelCfg levelCfg = StoryLevelCfgArray.Instance.GetCfg(_levelID);
  179. InstanceZonesDataManager.GetCanFightTime(_type, _storyType, _levelID, out int times, out string title);
  180. _ui.m_btnFightTimes.title = _fightType == 1 ? "挑战一次" : title;
  181. _ui.m_btnFightTimes.visible = times > 0;
  182. _ui.m_txtPowerDesc.visible = _ui.m_btnFightTimes.visible;
  183. if (_ui.m_txtPowerDesc.visible)
  184. {
  185. int power = times * levelCfg.power;
  186. _ui.m_txtPowerDesc.SetVar("v1", "" + power).FlushVars();
  187. }
  188. }
  189. }
  190. private void updateNeedItem()
  191. {
  192. if (_needItemId <= 0 || _needItemCount <= 0)
  193. {
  194. _ui.m_c1.selectedIndex = 0;
  195. return;
  196. }
  197. _ui.m_c1.selectedIndex = 1;
  198. _ui.m_txtItemName.text = string.Format("目标道具:{0}", ItemCfgArray.Instance.GetCfg(_needItemId).name);
  199. int hasCount = ItemDataManager.GetItemNum(_needItemId);
  200. _ui.m_txtItemNeedNum.text = string.Format("还需:{0}个", Math.Max(0, _needItemCount - hasCount));
  201. }
  202. }
  203. }