StoryFightQuicklyView.cs 5.9 KB

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