OpenServerFightView.cs 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  1. using UnityEngine;
  2. using FairyGUI;
  3. using UI.OpenServerActivity;
  4. using UI.CommonGame;
  5. using System.Collections.Generic;
  6. namespace GFGGame
  7. {
  8. public class OpenServerFightView : BaseWindow
  9. {
  10. private UI_OpenServerFightUI _ui;
  11. private int itemIndex = 0;
  12. private List<StoryLevelCfg> _storyLevelCfgs;
  13. private ActivityFightCfg _activityFightCfg;
  14. private int _activityId;
  15. private int _activityType;
  16. private ActivityOpenCfg _activityCfg;
  17. public override void Dispose()
  18. {
  19. if (_ui != null)
  20. {
  21. _ui.Dispose();
  22. _ui = null;
  23. }
  24. base.Dispose();
  25. }
  26. protected override void Init()
  27. {
  28. base.Init();
  29. }
  30. protected override void OnInit()
  31. {
  32. base.OnInit();
  33. packageName = UI_OpenServerFightUI.PACKAGE_NAME;
  34. _ui = UI_OpenServerFightUI.Create();
  35. this.viewCom = _ui.target;
  36. isfullScreen = true;
  37. isReturnView = true;
  38. _ui.m_list.itemRenderer = RenderListItem;
  39. _ui.m_btnBack.onClick.Add(OnClickBtnBack);
  40. _ui.m_iconSuidAdd.onClick.Add(OnClickIconSuidAdd);
  41. }
  42. protected override void OnShown()
  43. {
  44. base.OnShown();
  45. _activityType = (int)this.viewData;
  46. StudioDataManager.Instance.VIEW_NAME = typeof(OpenServerFightView).FullName;
  47. StudioDataManager.Instance.PROPERTY_SELECT_INDEX = _activityType;
  48. _ui.m_loaBg.url = ResPathUtil.GetBgImgPath("bg_sdcy_gq");
  49. _activityId = ActivityDataManager.Instance.GetCurOpenActiveByType(_activityType);
  50. _activityCfg = ActivityOpenCfgArray.Instance.GetCfg(_activityId);
  51. _activityFightCfg = ActivityFightCfgArray.Instance.GetCfg(_activityCfg.params3Arr[0]);
  52. _storyLevelCfgs = StoryLevelCfgArray.Instance.GetCfgsBytypeAndsubTypeAndchapterId(_activityFightCfg.type, _activityFightCfg.subType, _activityCfg.params3Arr[0]);
  53. _ui.m_list.numItems = _storyLevelCfgs.Count;
  54. UpdateItem();
  55. RefreshTxtFreeNum();
  56. _ui.m_txtTitle.SetVar("name", _activityCfg.themeName).FlushVars();
  57. }
  58. private void RefreshTxtFreeNum()
  59. {
  60. RoleLimitData limitData = RoleLimitDataManager.GetLimitData(_activityFightCfg.limit);
  61. int time = limitData.TotalPlayMax - limitData.PlayTimes;
  62. _ui.m_txtFreeNum.text = time + "/" + limitData.TotalPlayMax;
  63. }
  64. protected override void OnHide()
  65. {
  66. base.OnHide();
  67. }
  68. protected override void AddEventListener()
  69. {
  70. base.AddEventListener();
  71. EventAgent.AddEventListener(ConstMessage.FIGHT_QUICKLY, RefreshTxtFreeNum);
  72. }
  73. protected override void RemoveEventListener()
  74. {
  75. base.RemoveEventListener();
  76. EventAgent.RemoveEventListener(ConstMessage.FIGHT_QUICKLY, RefreshTxtFreeNum);
  77. }
  78. private void OnClickBtnBack()
  79. {
  80. ViewManager.GoBackFrom(typeof(OpenServerFightView).FullName);
  81. }
  82. private void OnClickIconSuidAdd()
  83. {
  84. ViewManager.Show<OpenServerSuitAdditionView>(new object[] { ConstLimitTimeActivityType.ActLimitStlyc, _storyLevelCfgs[0].id });
  85. }
  86. private void RenderListItem(int index, GObject obj)
  87. {
  88. UI_OpenSererFightItem item = UI_OpenSererFightItem.Proxy(obj);
  89. item.m_txtName.text = _storyLevelCfgs[index].name;
  90. item.m_loaIcon.visible = false;
  91. item.m_loaItem.visible = true;
  92. StoryFightCfg storyFightCfg = StoryFightCfgArray.Instance.GetCfg(_storyLevelCfgs[index].fightID);
  93. int itemId = storyFightCfg.bonusBaseArr[0][0];
  94. ItemCfg itemCfg = ItemCfgArray.Instance.GetCfg(itemId);
  95. item.m_loaItem.url = ResPathUtil.GetIconPath(itemCfg);
  96. if (item.m_loaItem.data == null)
  97. {
  98. item.m_loaItem.onClick.Add(OnLoaItemClick);
  99. }
  100. item.m_loaItem.data = index;
  101. item.m_grpLock.visible = index > 0 && !InstanceZonesDataManager.CheckLevelPass(_storyLevelCfgs[index - 1].id);
  102. if (!item.m_grpLock.visible)
  103. item.m_comFirstPass.visible = !InstanceZonesDataManager.CheckLevelPass(_storyLevelCfgs[index].id);
  104. else
  105. item.m_comFirstPass.visible = false;
  106. item.m_comFlower.m_c1.selectedIndex = InstanceZonesDataManager.GetStarCountHistory(_storyLevelCfgs[index].id);
  107. if (item.m_loaBg.data == null)
  108. {
  109. item.m_loaBg.onClick.Add(OnListItemClick);
  110. }
  111. item.m_loaBg.data = index;
  112. UI_OpenSererFightItem.ProxyEnd();
  113. }
  114. private void OnListItemClick(EventContext context)
  115. {
  116. GObject obj = context.sender as GObject;
  117. int index = (int)obj.data;
  118. StoryLevelCfg storyLevelCfg = _storyLevelCfgs[index];
  119. if (index > 0 && !InstanceZonesDataManager.CheckLevelPass(_storyLevelCfgs[index - 1].id))
  120. {
  121. PromptController.Instance.ShowFloatTextPrompt("需通关前置关卡");
  122. return;
  123. }
  124. MainStoryDataManager.currentLevelCfgId = storyLevelCfg.id;
  125. InstanceZonesController.ShowLevelView(storyLevelCfg.id, StudioDataManager.Instance.OnFinishStudioStoryLevel);
  126. }
  127. private void OnLoaItemClick(EventContext context)
  128. {
  129. GObject obj = context.sender as GObject;
  130. int index = (int)obj.data;
  131. StoryFightCfg storyFightCfg = StoryFightCfgArray.Instance.GetCfg(_storyLevelCfgs[index].fightID);
  132. int itemId = storyFightCfg.bonusBaseArr[0][0];
  133. GoodsItemTipsController.ShowItemTips(itemId);
  134. }
  135. private void UpdateItem()
  136. {
  137. for (int i = 0; i < _ui.m_list.numChildren; i++)
  138. {
  139. _ui.m_list.GetChildAt(i).visible = false;
  140. }
  141. itemIndex = 0;
  142. Timers.inst.Add(0.05f, _ui.m_list.numChildren, AddItemUpdate, 1);
  143. }
  144. private void AddItemUpdate(object param)
  145. {
  146. _ui.m_list.GetChildAt(itemIndex).visible = true;
  147. UI_ListLevelItem item = UI_ListLevelItem.Proxy(_ui.m_list.GetChildAt(itemIndex));
  148. item.m_Left.Play();
  149. itemIndex++;
  150. UI_ListLevelItem.ProxyEnd();
  151. }
  152. }
  153. }