DaoYouLevelWidget.cs 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  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. //TODO 道友好感度
  47. PlayerManager.Instance.BagController.AddItem(items);
  48. RewardsPanel.OpenPanel(items);
  49. }
  50. Text_Tips.gameObject.SetActive(true);
  51. foreach (var widgetItem in _widgetItems)
  52. {
  53. widgetItem.transform.RecoverColor();
  54. widgetItem.ShowGou();
  55. }
  56. AccountFileInfo.Instance.SavePlayerData();
  57. });
  58. }
  59. public async void CustomInit(AccountFileInfo.DaoYouData daoYouData, int configId)
  60. {
  61. this.daoYouData = daoYouData;
  62. _daoyouLevelupConfig = ConfigComponent.Instance.Get<DaoyouLevelupConfig>(configId);
  63. DaoyouModelConfig daoyouModelConfig = ConfigComponent.Instance.Get<DaoyouModelConfig>(daoYouData.id);
  64. Text_Level.text = configId.ToString();
  65. Text_Name.text = LanguageManager.Instance.Text(_daoyouLevelupConfig.name);
  66. for (var i = 0; i < _daoyouLevelupConfig.prizeID?.Length; i++)
  67. {
  68. DaoYouWidgetItem widgetItem = await UIManager.Instance.CreateGComponent<DaoYouWidgetItem>(null, ItemRoot);
  69. widgetItem.CustomInit(new ItemInfo(_daoyouLevelupConfig.prizeID[i], _daoyouLevelupConfig.prizeNum[i]));
  70. _widgetItems.Add(widgetItem);
  71. }
  72. if (daoyouModelConfig.EmotionLvforspecialGift.Contains(configId))
  73. {
  74. int index = daoyouModelConfig.EmotionLvforspecialGift.ToList().IndexOf(configId);
  75. DaoYouWidgetItem widgetItem = await UIManager.Instance.CreateGComponent<DaoYouWidgetItem>(null, ItemRoot);
  76. widgetItem.CustomInit(new ItemInfo(daoyouModelConfig.specialGiftID[index], daoyouModelConfig.specialGiftNum[index]));
  77. _widgetItems.Add(widgetItem);
  78. }
  79. //已经领取奖励
  80. if (daoYouData.awardLevels.Contains(configId))
  81. {
  82. Text_Tips.gameObject.SetActive(true);
  83. foreach (var widgetItem in _widgetItems)
  84. {
  85. widgetItem.transform.RecoverColor();
  86. widgetItem.ShowGou();
  87. }
  88. }
  89. else
  90. {
  91. //可以领取
  92. if (daoYouData.favorabilityLv >= _daoyouLevelupConfig.ID)
  93. {
  94. foreach (var widgetItem in _widgetItems)
  95. {
  96. widgetItem.transform.RecoverColor();
  97. widgetItem.Award();
  98. }
  99. }
  100. //不能领取
  101. else
  102. {
  103. foreach (var widgetItem in _widgetItems)
  104. {
  105. widgetItem.transform.Gray();
  106. }
  107. }
  108. Text_Tips.gameObject.SetActive(false);
  109. }
  110. }
  111. public override void DormancyObj()
  112. {
  113. foreach (var widgetItem in _widgetItems)
  114. {
  115. UIManager.Instance.DormancyGComponent(widgetItem);
  116. }
  117. _widgetItems.Clear();
  118. base.DormancyObj();
  119. }
  120. }
  121. }