StoryFightQuicklyView.cs 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  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 _storyType;
  15. private List<List<ItemData>> _totalBonusList;
  16. private int _index;
  17. private int _expAdd;
  18. private int _power;
  19. private int _fightTimes;
  20. private const int _timeCount = 10;
  21. protected override void OnInit()
  22. {
  23. base.OnInit();
  24. _ui = UI_StoryFightQuicklyUI.Create();
  25. this.viewCom = _ui.target;
  26. this.viewCom.Center();
  27. this.modal = true;
  28. _ui.m_btnExit.onClick.Add(() =>
  29. {
  30. this.Hide();
  31. });
  32. _ui.m_btnFightTimes.onClick.Add(() =>
  33. {
  34. StartFight(_fightTimes);
  35. });
  36. }
  37. protected override void OnShown()
  38. {
  39. base.OnShown();
  40. int count = (int)viewData;
  41. _levelID = StoryDataManager.currentLevelCfgId;
  42. _storyType = _levelID/GameConst.STORY_LEVEL_KEY_NUM / 10000;
  43. StoryLevelCfg levelCfg = StoryLevelCfgArray.Instance.GetCfg(_levelID);
  44. StoryFightCfg fightCfg = StoryFightCfgArray.Instance.GetCfg(levelCfg.fightID);
  45. _expAdd = fightCfg.exp;
  46. _power = levelCfg.power;
  47. StartFight(count);
  48. EventAgent.AddEventListener(ConstMessage.NUMERIC_CHANGE, UpdateBtnFightTimes);
  49. EventAgent.AddEventListener(ConstMessage.STORY_FIGHT_QUICKLY_SUCCESS, StartShowBonus);
  50. }
  51. protected override void OnHide()
  52. {
  53. base.OnHide();
  54. Timers.inst.Remove(ShowBonusItem);
  55. EventAgent.RemoveEventListener(ConstMessage.NUMERIC_CHANGE, UpdateBtnFightTimes);
  56. EventAgent.RemoveEventListener(ConstMessage.STORY_FIGHT_QUICKLY_SUCCESS, StartShowBonus);
  57. }
  58. private void StartFight(int count)
  59. {
  60. int time = StoryDataManager.GetCanFightTime(_levelID);
  61. if (_storyType == ConstStoryType.NORMAL_TYPE && time < count)
  62. {
  63. ItemUtil.AddPower("体力不足", () => { StartFight(count); });
  64. return;
  65. }
  66. _ui.m_btnExit.visible = false;
  67. _ui.m_btnFightTimes.visible = false;
  68. _ui.m_txtPowerDesc.visible = false;
  69. _ui.m_list.RemoveChildren();
  70. //_totalBonusList = new List<List<ItemData>>();
  71. //for (int i = 1; i <= count; i++)
  72. //{
  73. // bool fistPassLastLvl = false;
  74. // bool curLvfirstPass = false;
  75. // List<ItemData> bonusList = StoryDataManager.PassCurrentLevel(out fistPassLastLvl, out curLvfirstPass);
  76. // _totalBonusList.Add(bonusList);
  77. //}
  78. StorySProxy.FinishStoryFightQuickly(_levelID, count).Coroutine();
  79. }
  80. private void StartShowBonus(EventContext eventContext)
  81. {
  82. _totalBonusList = (List<List<ItemData>>)eventContext.data;
  83. _index = 0;
  84. ShowBonusItem();
  85. Timers.inst.Add(0.3f, 0, ShowBonusItem);
  86. }
  87. private void ShowBonusItem(object param = null)
  88. {
  89. if (_index < _totalBonusList.Count)
  90. {
  91. List<ItemData> bonusList = _totalBonusList[_index] as List<ItemData>;
  92. UI_StoryFightQuicklyBonusListItem listItem = UI_StoryFightQuicklyBonusListItem.Proxy();
  93. listItem.m_list.itemRenderer = ListItemRender;
  94. _ui.m_list.AddChild(listItem.target);
  95. int order = _index + 1;
  96. listItem.m_txtTimes.SetVar("n", "" + NumberUtil.GetChiniseNumberText(order)).FlushVars();
  97. listItem.m_txtExp.SetVar("n", "" + _expAdd).FlushVars();
  98. listItem.m_list.numItems = bonusList.Count;
  99. listItem.m_list.ResizeToFit();
  100. listItem.target.height = listItem.m_list.y + listItem.m_list.height;
  101. _index++;
  102. }
  103. else
  104. {
  105. UI_StoryFightQuicklyComplete completeItem = UI_StoryFightQuicklyComplete.Proxy();
  106. _ui.m_list.AddChild(completeItem.target);
  107. Timers.inst.Remove(ShowBonusItem);
  108. _ui.m_btnExit.visible = true;
  109. UpdateBtnFightTimes();
  110. }
  111. _ui.m_list.scrollPane.ScrollBottom();
  112. }
  113. private void ListItemRender(int index, GObject item)
  114. {
  115. List<ItemData> bonusList = _totalBonusList[_index] as List<ItemData>;
  116. ItemData itemData = bonusList[index] as ItemData;
  117. if (item.data == null)
  118. {
  119. item.data = new ItemView(item as GComponent);
  120. }
  121. (item.data as ItemView).SetData(itemData);
  122. (item.data as ItemView).TxtHasCountVisble = false;
  123. }
  124. private void UpdateBtnFightTimes()
  125. {
  126. if (_ui.m_btnExit.visible)
  127. {
  128. StoryLevelCfg levelCfg = StoryLevelCfgArray.Instance.GetCfg(_levelID);
  129. int time = StoryDataManager.GetCanFightTime(_levelID);
  130. time = Math.Min(GameConst.MAX_COUNT_FIGHT_QUICKLY, time);
  131. _ui.m_btnFightTimes.visible = time > 0;
  132. _ui.m_txtPowerDesc.visible = _ui.m_btnFightTimes.visible;
  133. if (_storyType == ConstStoryType.NORMAL_TYPE)
  134. {
  135. _ui.m_btnFightTimes.visible = true;
  136. _fightTimes = (int)viewData;
  137. _ui.m_btnFightTimes.text = "挑战" + NumberUtil.GetChiniseNumberText((int)viewData) + "次";
  138. }
  139. else if (_storyType == ConstStoryType.HARD_TYPE)
  140. {
  141. _ui.m_btnFightTimes.visible = time > 1;
  142. if (_ui.m_btnFightTimes.visible)
  143. {
  144. _fightTimes = time;
  145. _ui.m_btnFightTimes.text = "挑战" + NumberUtil.GetChiniseNumberText(time) + "次";
  146. }
  147. }
  148. if (_ui.m_txtPowerDesc.visible)
  149. {
  150. int power = time * levelCfg.power;
  151. _ui.m_txtPowerDesc.SetVar("v1", "" + power).FlushVars();
  152. }
  153. }
  154. }
  155. }
  156. }