DivineSenceRestoredWidget.cs 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. using System.Collections.Generic;
  2. using Core.Language;
  3. using Excel2Json;
  4. using Fort23.Core;
  5. using Fort23.UTool;
  6. using GameLogic.Bag;
  7. using UnityEngine;
  8. namespace Fort23.Mono
  9. {
  10. [UIBinding(prefab = "DivineSenceRestoredWidget")]
  11. public partial class DivineSenceRestoredWidget : UIComponent
  12. {
  13. private ShopItemConfig ShopItemConfig;
  14. private AccountFileInfo.ShopItem shopItem;
  15. private ItemConfig itemConfig;
  16. private int openType;
  17. private void Init()
  18. {
  19. }
  20. public override void AddEvent()
  21. {
  22. }
  23. public override void DelEvent()
  24. {
  25. }
  26. public override void AddButtonEvent()
  27. {
  28. Btn_Use.onClick.AddListener(async () =>
  29. {
  30. //购买并使用道具
  31. if (openType == 1)
  32. {
  33. if (ShopItemConfig.buyCount != -1 && shopItem.buyCount >= ShopItemConfig.buyCount)
  34. {
  35. TipMessagePanel.OpenTipMessagePanel(811, Vector2.zero);
  36. return;
  37. }
  38. List<ItemInfo> itemInfos = await ShopManger.Instance.BuyItem(ShopItemConfig.ID, 1);
  39. if (itemInfos != null)
  40. {
  41. //使用道具
  42. foreach (var itemInfo in itemInfos)
  43. {
  44. if (itemInfo.config.itemTag == 8)
  45. {
  46. AccountFileInfo.Instance.playerData.divineSensePoint +=
  47. itemInfo.config.associateVlaue[0];
  48. PlayerManager.Instance.BagController.DeductItem(itemInfo.config.ID, 1);
  49. }
  50. }
  51. CustomInit(ShopItemConfig.ID);
  52. }
  53. else
  54. {
  55. TipMessagePanel.OpenTipMessagePanel(833, Vector2.zero);
  56. }
  57. }
  58. //世界使用道具
  59. else
  60. {
  61. if (PlayerManager.Instance.BagController.IsEnough(itemConfig.ID, 1))
  62. {
  63. AccountFileInfo.Instance.playerData.divineSensePoint +=
  64. itemConfig.associateVlaue[0];
  65. PlayerManager.Instance.BagController.DeductItem(itemConfig.ID, 1);
  66. CustomInit(itemConfig.ID);
  67. }
  68. else
  69. {
  70. TipMessagePanel.OpenTipMessagePanel(10324, Vector2.zero);
  71. }
  72. }
  73. EventManager.Instance.Dispatch(CustomEventType.DivineSensePointChange, null);
  74. });
  75. }
  76. public void CustomInit(int shopitemId)
  77. {
  78. openType = 1;
  79. ShopItemConfig = ConfigComponent.Instance.Get<ShopItemConfig>(shopitemId);
  80. shopItem = ShopManger.Instance.GetShopItem(shopitemId);
  81. itemConfig = ConfigComponent.Instance.Get<ItemConfig>(ShopItemConfig.itemId[0]);
  82. if (ShopItemConfig.costItemId == 0)
  83. {
  84. Group_Price.SetActive(false);
  85. Text_Free.gameObject.SetActive(true);
  86. Text_Free.text = LanguageManager.Instance.Text(10328);
  87. }
  88. else
  89. {
  90. ItemConfig costItemConfig = ConfigComponent.Instance.Get<ItemConfig>(ShopItemConfig.costItemId);
  91. Group_Price.SetActive(true);
  92. Text_Free.gameObject.SetActive(false);
  93. Icon_PriceItem.icon_name = costItemConfig.icon;
  94. Text_Price.text = ShopItemConfig.price.ToString();
  95. }
  96. Text_Count.text = $"x{itemConfig.associateVlaue[0]}";
  97. Text_Tip.text = LanguageManager.Instance.Text(10327, ShopItemConfig.buyCount - shopItem.buyCount);
  98. }
  99. public void CustomInit1(int itemId)
  100. {
  101. openType = 2;
  102. itemConfig = ConfigComponent.Instance.Get<ItemConfig>(itemId);
  103. Text_Count.text = $"x{itemConfig.associateVlaue[0]}";
  104. Text_Tip.text =
  105. LanguageManager.Instance.Text(10327, PlayerManager.Instance.BagController.GetItemCount(itemId));
  106. Group_Price.SetActive(false);
  107. Text_Free.gameObject.SetActive(true);
  108. Text_Free.text = LanguageManager.Instance.Text(10329);
  109. }
  110. }
  111. }