OpenServerStoryView.cs 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  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 OpenServerStoryView : BaseWindow
  9. {
  10. private UI_OpenServerStoryUI _ui;
  11. private Dictionary<int,List<StoryLevelCfg>> _storyLevelCfgs = new Dictionary<int, List<StoryLevelCfg>>();
  12. private int _activityId;
  13. private int _activityType;
  14. private ActivityOpenCfg _activityCfg;
  15. public override void Dispose()
  16. {
  17. if (_ui != null)
  18. {
  19. _ui.Dispose();
  20. _ui = null;
  21. }
  22. base.Dispose();
  23. }
  24. protected override void Init()
  25. {
  26. base.Init();
  27. }
  28. protected override void OnInit()
  29. {
  30. base.OnInit();
  31. packageName = UI_OpenServerStoryUI.PACKAGE_NAME;
  32. _ui = UI_OpenServerStoryUI.Create();
  33. viewCom = _ui.target;
  34. isfullScreen = true;
  35. isReturnView = true;
  36. _ui.m_btnBack.onClick.Add(OnClickBtnBack);
  37. _ui.m_list.itemRenderer = RenderListItem;
  38. }
  39. protected override void AddEventListener()
  40. {
  41. base.AddEventListener();
  42. }
  43. protected override void OnShown()
  44. {
  45. base.OnShown();
  46. _activityType = (int)this.viewData;
  47. StudioDataManager.Instance.VIEW_NAME = typeof(OpenServerStoryView).FullName;
  48. StudioDataManager.Instance.PROPERTY_SELECT_INDEX = _activityType;
  49. _ui.m_loaBg.url = ResPathUtil.GetBgImgPath("sdcy_jq_bg");
  50. _activityId = ActivityDataManager.Instance.GetCurOpenActiveByType(_activityType);
  51. _activityCfg = ActivityOpenCfgArray.Instance.GetCfg(_activityId);
  52. _storyLevelCfgs.Clear();
  53. _ui.m_list.numItems = _activityCfg.params4Arr.Length;
  54. }
  55. protected override void OnHide()
  56. {
  57. base.OnHide();
  58. }
  59. protected override void RemoveEventListener()
  60. {
  61. base.RemoveEventListener();
  62. }
  63. private void OnClickBtnBack()
  64. {
  65. ViewManager.GoBackFrom(typeof(OpenServerStoryView).FullName);
  66. }
  67. private void RenderListItem(int index, GObject obj)
  68. {
  69. int posRedX = -130;
  70. int posRedY = 30;
  71. bool redVisible = false;
  72. UI_StoryItem item = UI_StoryItem.Proxy(obj);
  73. ActivityStoryCfg activityStoryCfg = ActivityStoryCfgArray.Instance.GetCfg(_activityCfg.params4Arr[index]);
  74. var storyLevelCfg = StoryLevelCfgArray.Instance.GetCfgsBytypeAndsubTypeAndchapterId(activityStoryCfg.type, activityStoryCfg.subType, _activityCfg.params4Arr[index]);
  75. _storyLevelCfgs.Add(index, storyLevelCfg);
  76. item.m_posType.selectedIndex = index % 2;
  77. item.m_txtTitle.text = activityStoryCfg.name;
  78. item.m_txtNumber.text = "0" + (index + 1);
  79. item.m_rewardItem.m_txtCount.text = storyLevelCfg[0].bonusOnceArr[0][1].ToString();
  80. ItemCfg itemCfg = ItemCfgArray.Instance.GetCfg(storyLevelCfg[0].bonusOnceArr[0][0]);
  81. item.m_rewardItem.m_loaIcon.url = ResPathUtil.GetIconPath(itemCfg);
  82. if (item.m_rewardItem.target.data == null)
  83. item.m_rewardItem.target.onClick.Add(OnClickIcon);
  84. item.m_rewardItem.target.data = itemCfg.id;
  85. if (index > 0 && (!InstanceZonesDataManager.CheckLevelPass(_storyLevelCfgs[index - 1][0].id) || !ItemDataManager.ItemCollect.ContainsKey(activityStoryCfg.needItemsArr[0][0]) || ItemDataManager.ItemCollect[activityStoryCfg.needItemsArr[0][0]] < activityStoryCfg.needItemsArr[0][1]))
  86. {
  87. item.m_storyImageType.selectedIndex = 0;
  88. }
  89. else {
  90. item.m_storyImageType.selectedIndex = index + 1;
  91. }
  92. if (item.m_posType.selectedIndex == 1) {
  93. posRedX = -52;
  94. posRedY = 30;
  95. }
  96. if ((index == 0 && !InstanceZonesDataManager.CheckLevelPass(_storyLevelCfgs[index][0].id)) || (index > 0 && InstanceZonesDataManager.CheckLevelPass(_storyLevelCfgs[index - 1][0].id) && !InstanceZonesDataManager.CheckLevelPass(_storyLevelCfgs[index][0].id) && ItemDataManager.ItemCollect.ContainsKey(activityStoryCfg.needItemsArr[0][0]) && ItemDataManager.ItemCollect[activityStoryCfg.needItemsArr[0][0]] >= activityStoryCfg.needItemsArr[0][1]))
  97. {
  98. redVisible = true;
  99. }
  100. RedDotController.Instance.SetComRedDot(item.target, redVisible, "", posRedX, posRedY);
  101. if (activityStoryCfg.needItemsArr.Length > 0) {
  102. item.m_txtNotOpenTitle.text = string.Format("收集{0}/{1}个", ItemDataManager.ItemCollect[activityStoryCfg.needItemsArr[0][0]], activityStoryCfg.needItemsArr[0][1]);
  103. ItemCfg itemNeedCfg = ItemCfgArray.Instance.GetCfg(activityStoryCfg.needItemsArr[0][0]);
  104. item.m_loaNeedIcon.url = ResPathUtil.GetIconPath(itemNeedCfg);
  105. }
  106. if (item.m_loaItemBg.data == null)
  107. item.m_loaItemBg.onClick.Add(OnClickBtnPlay);
  108. item.m_loaItemBg.data = index;
  109. UI_StoryItem.ProxyEnd();
  110. }
  111. private void OnClickIcon(EventContext context)
  112. {
  113. GObject obj = context.sender as GObject;
  114. int itemId = (int)obj.data;
  115. GoodsItemTipsController.ShowItemTips(itemId);
  116. }
  117. private void OnClickBtnPlay(EventContext context)
  118. {
  119. GObject obj = context.sender as GObject;
  120. int index = (int)obj.data;
  121. ActivityStoryCfg activityStoryCfg = ActivityStoryCfgArray.Instance.GetCfg(_activityCfg.params4Arr[index]);
  122. StoryLevelCfg storyLevelCfg = _storyLevelCfgs[index][0];
  123. if (index > 0 && !InstanceZonesDataManager.CheckLevelPass(_storyLevelCfgs[index - 1][0].id))
  124. {
  125. PromptController.Instance.ShowFloatTextPrompt("需通关前置关卡");
  126. return;
  127. }
  128. if(index > 0 && ItemDataManager.ItemCollect[activityStoryCfg.needItemsArr[0][0]] < activityStoryCfg.needItemsArr[0][1])
  129. {
  130. PromptController.Instance.ShowFloatTextPrompt("需收集物达到开启需求");
  131. return;
  132. }
  133. MainStoryDataManager.currentLevelCfgId = storyLevelCfg.id;
  134. InstanceZonesController.ShowLevelView(storyLevelCfg.id, StudioDataManager.Instance.OnFinishStudioStoryLevel);
  135. }
  136. }
  137. }