OpenServerFightView.cs 6.8 KB

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