DaoYouLevelWidget.cs 4.5 KB

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