StoryFightQuicklyView.cs 5.7 KB

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