DaoYouLevelWidget.cs 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. using System.Collections.Generic;
  2. using System.Linq;
  3. using Core.Language;
  4. using Excel2Json;
  5. using Fort23.UTool;
  6. using GameLogic.Bag;
  7. namespace Fort23.Mono
  8. {
  9. [UIBinding(prefab = "DaoYouLevelWidget")]
  10. public partial class DaoYouLevelWidget : UIComponent
  11. {
  12. private AccountFileInfo.DaoYouData daoYouData;
  13. public DaoyouLevelupConfig _daoyouLevelupConfig;
  14. List<DaoYouWidgetItem> _widgetItems = new List<DaoYouWidgetItem>();
  15. private void Init()
  16. {
  17. }
  18. public override void AddEvent()
  19. {
  20. }
  21. public override void DelEvent()
  22. {
  23. }
  24. public override void AddButtonEvent()
  25. {
  26. Btn_Award.onClick.AddListener(() =>
  27. {
  28. if (daoYouData.awardLevels.Contains(_daoyouLevelupConfig.ID) || daoYouData.favorabilityLv < _daoyouLevelupConfig.ID)
  29. {
  30. return;
  31. }
  32. List<ItemInfo> items = new List<ItemInfo>();
  33. DaoyouModelConfig daoyouModelConfig = ConfigComponent.Instance.Get<DaoyouModelConfig>(daoYouData.id);
  34. for (var i = 0; i < _daoyouLevelupConfig.prizeID?.Length; i++)
  35. {
  36. items.Add(new ItemInfo(_daoyouLevelupConfig.prizeID[i], _daoyouLevelupConfig.prizeNum[i]));
  37. }
  38. if (daoyouModelConfig.EmotionLvforspecialGift.Contains(_daoyouLevelupConfig.ID))
  39. {
  40. int index = daoyouModelConfig.EmotionLvforspecialGift.ToList().IndexOf(_daoyouLevelupConfig.ID);
  41. items.Add(new ItemInfo(daoyouModelConfig.specialGiftID[index], daoyouModelConfig.specialGiftNum[index]));
  42. }
  43. daoYouData.awardLevels.Add(_daoyouLevelupConfig.ID);
  44. if (items.Count > 0)
  45. {
  46. PlayerManager.Instance.BagController.AddItem(items);
  47. RewardsPanel.OpenPanel(items);
  48. }
  49. Text_Tips.gameObject.SetActive(true);
  50. foreach (var widgetItem in _widgetItems)
  51. {
  52. widgetItem.transform.RecoverColor();
  53. widgetItem.ShowGou();
  54. }
  55. AccountFileInfo.Instance.SavePlayerData();
  56. });
  57. }
  58. public async void CustomInit(AccountFileInfo.DaoYouData daoYouData, int configId)
  59. {
  60. this.daoYouData = daoYouData;
  61. _daoyouLevelupConfig = ConfigComponent.Instance.Get<DaoyouLevelupConfig>(configId);
  62. DaoyouModelConfig daoyouModelConfig = ConfigComponent.Instance.Get<DaoyouModelConfig>(daoYouData.id);
  63. Text_Level.text = configId.ToString();
  64. Text_Name.text = LanguageManager.Instance.Text(_daoyouLevelupConfig.name);
  65. for (var i = 0; i < _daoyouLevelupConfig.prizeID?.Length; i++)
  66. {
  67. DaoYouWidgetItem widgetItem = await UIManager.Instance.CreateGComponent<DaoYouWidgetItem>(null, ItemRoot);
  68. widgetItem.CustomInit(new ItemInfo(_daoyouLevelupConfig.prizeID[i], _daoyouLevelupConfig.prizeNum[i]));
  69. _widgetItems.Add(widgetItem);
  70. }
  71. if (daoyouModelConfig.EmotionLvforspecialGift.Contains(configId))
  72. {
  73. int index = daoyouModelConfig.EmotionLvforspecialGift.ToList().IndexOf(configId);
  74. DaoYouWidgetItem widgetItem = await UIManager.Instance.CreateGComponent<DaoYouWidgetItem>(null, ItemRoot);
  75. widgetItem.CustomInit(new ItemInfo(daoyouModelConfig.specialGiftID[index], daoyouModelConfig.specialGiftNum[index]));
  76. _widgetItems.Add(widgetItem);
  77. }
  78. //已经领取奖励
  79. if (daoYouData.awardLevels.Contains(configId))
  80. {
  81. Text_Tips.gameObject.SetActive(true);
  82. foreach (var widgetItem in _widgetItems)
  83. {
  84. widgetItem.transform.RecoverColor();
  85. widgetItem.ShowGou();
  86. }
  87. }
  88. else
  89. {
  90. //可以领取
  91. if (daoYouData.favorabilityLv >= _daoyouLevelupConfig.ID)
  92. {
  93. foreach (var widgetItem in _widgetItems)
  94. {
  95. widgetItem.transform.RecoverColor();
  96. widgetItem.Award();
  97. }
  98. }
  99. //不能领取
  100. else
  101. {
  102. foreach (var widgetItem in _widgetItems)
  103. {
  104. widgetItem.transform.Gray();
  105. }
  106. }
  107. Text_Tips.gameObject.SetActive(false);
  108. }
  109. }
  110. public override void DormancyObj()
  111. {
  112. foreach (var widgetItem in _widgetItems)
  113. {
  114. UIManager.Instance.DormancyGComponent(widgetItem);
  115. }
  116. _widgetItems.Clear();
  117. base.DormancyObj();
  118. }
  119. }
  120. }