StoryFightQuicklyView.cs 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  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 string _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.currentLevelID;
  42. _storyType = int.Parse(_levelID.Split('_')[0]) / 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. }
  50. protected override void OnHide()
  51. {
  52. base.OnHide();
  53. Timers.inst.Remove(ShowBonusItem);
  54. EventAgent.RemoveEventListener(ConstMessage.NUMERIC_CHANGE, UpdateBtnFightTimes);
  55. }
  56. private void StartFight(int count)
  57. {
  58. int time = StoryDataManager.GetCanFightTime(_levelID);
  59. if (_storyType == ConstStoryType.NORMAL_TYPE && time < count)
  60. {
  61. ItemUtil.AddPower("体力不足", () => { StartFight(count); });
  62. return;
  63. }
  64. _ui.m_btnExit.visible = false;
  65. _ui.m_btnFightTimes.visible = false;
  66. _ui.m_txtPowerDesc.visible = false;
  67. _ui.m_list.RemoveChildren();
  68. _totalBonusList = new List<List<ItemData>>();
  69. for (int i = 1; i <= count; i++)
  70. {
  71. bool fistPassLastLvl = false;
  72. bool curLvfirstPass = false;
  73. List<ItemData> bonusList = StoryDataManager.PassCurrentLevel(out fistPassLastLvl, out curLvfirstPass);
  74. _totalBonusList.Add(bonusList);
  75. }
  76. _index = 0;
  77. ShowBonusItem();
  78. Timers.inst.Add(0.3f, 0, ShowBonusItem);
  79. }
  80. private void ShowBonusItem(object param = null)
  81. {
  82. if (_index < _totalBonusList.Count)
  83. {
  84. List<ItemData> bonusList = _totalBonusList[_index] as List<ItemData>;
  85. UI_StoryFightQuicklyBonusListItem listItem = UI_StoryFightQuicklyBonusListItem.Proxy();
  86. listItem.m_list.itemRenderer = ListItemRender;
  87. _ui.m_list.AddChild(listItem.target);
  88. int order = _index + 1;
  89. listItem.m_txtTimes.SetVar("n", "" + NumberUtil.GetChiniseNumberText(order)).FlushVars();
  90. listItem.m_txtExp.SetVar("n", "" + _expAdd).FlushVars();
  91. listItem.m_list.numItems = bonusList.Count;
  92. listItem.m_list.ResizeToFit();
  93. listItem.target.height = listItem.m_list.y + listItem.m_list.height;
  94. _index++;
  95. }
  96. else
  97. {
  98. UI_StoryFightQuicklyComplete completeItem = UI_StoryFightQuicklyComplete.Proxy();
  99. _ui.m_list.AddChild(completeItem.target);
  100. Timers.inst.Remove(ShowBonusItem);
  101. _ui.m_btnExit.visible = true;
  102. UpdateBtnFightTimes();
  103. }
  104. _ui.m_list.scrollPane.ScrollBottom();
  105. }
  106. private void ListItemRender(int index, GObject item)
  107. {
  108. List<ItemData> bonusList = _totalBonusList[_index] as List<ItemData>;
  109. ItemData itemData = bonusList[index] as ItemData;
  110. if (item.data == null)
  111. {
  112. item.data = new ItemView(item as GComponent);
  113. }
  114. (item.data as ItemView).SetData(itemData);
  115. (item.data as ItemView).TxtHasCountVisble = false;
  116. }
  117. private void UpdateBtnFightTimes()
  118. {
  119. if (_ui.m_btnExit.visible)
  120. {
  121. StoryLevelCfg levelCfg = StoryLevelCfgArray.Instance.GetCfg(_levelID);
  122. int time = StoryDataManager.GetCanFightTime(_levelID);
  123. time = Math.Min(GameConst.MAX_COUNT_FIGHT_QUICKLY, time);
  124. _ui.m_btnFightTimes.visible = time > 0;
  125. _ui.m_txtPowerDesc.visible = _ui.m_btnFightTimes.visible;
  126. if (_storyType == ConstStoryType.NORMAL_TYPE)
  127. {
  128. _ui.m_btnFightTimes.visible = true;
  129. _fightTimes = (int)viewData;
  130. _ui.m_btnFightTimes.text = "挑战" + NumberUtil.GetChiniseNumberText((int)viewData) + "次";
  131. }
  132. else if (_storyType == ConstStoryType.HARD_TYPE)
  133. {
  134. _ui.m_btnFightTimes.visible = time > 1;
  135. if (_ui.m_btnFightTimes.visible)
  136. {
  137. _fightTimes = time;
  138. _ui.m_btnFightTimes.text = "挑战" + NumberUtil.GetChiniseNumberText(time) + "次";
  139. }
  140. }
  141. if (_ui.m_txtPowerDesc.visible)
  142. {
  143. int power = time * levelCfg.power;
  144. _ui.m_txtPowerDesc.SetVar("v1", "" + power).FlushVars();
  145. }
  146. }
  147. }
  148. }
  149. }