DivineSenceRestoredWidget.cs 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  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(10366, Vector2.zero);
  36. return;
  37. }
  38. if (ShopItemConfig.price != 0 &&
  39. !PlayerManager.Instance.BagController.IsEnough(ShopItemConfig.costItemId,
  40. ShopItemConfig.price * 1))
  41. {
  42. ItemSourcePanel.OpenPanel(ShopItemConfig.costItemId);
  43. // TipMessagePanel.OpenTipMessagePanel(829, Vector2.zero);
  44. return;
  45. }
  46. List<ItemInfo> itemInfos = await ShopManger.Instance.BuyItem(ShopItemConfig.ID, 1);
  47. if (itemInfos != null)
  48. {
  49. //使用道具
  50. foreach (var itemInfo in itemInfos)
  51. {
  52. if (itemInfo.config.itemTag == 8)
  53. {
  54. AccountFileInfo.Instance.playerData.divineSensePoint +=
  55. itemInfo.config.associateVlaue[0];
  56. PlayerManager.Instance.BagController.DeductItem(itemInfo.config.ID, 1);
  57. }
  58. }
  59. CustomInit(ShopItemConfig.ID);
  60. }
  61. else
  62. {
  63. TipMessagePanel.OpenTipMessagePanel(833, Vector2.zero);
  64. }
  65. }
  66. //世界使用道具
  67. else
  68. {
  69. if (PlayerManager.Instance.BagController.IsEnough(itemConfig.ID, 1))
  70. {
  71. AccountFileInfo.Instance.playerData.divineSensePoint +=
  72. itemConfig.associateVlaue[0];
  73. PlayerManager.Instance.BagController.DeductItem(itemConfig.ID, 1);
  74. CustomInit1(itemConfig.ID);
  75. }
  76. else
  77. {
  78. TipMessagePanel.OpenTipMessagePanel(10324, Vector2.zero);
  79. }
  80. }
  81. EventManager.Instance.Dispatch(CustomEventType.DivineSensePointChange, null);
  82. });
  83. }
  84. public void CustomInit(int shopitemId)
  85. {
  86. openType = 1;
  87. ShopItemConfig = ConfigComponent.Instance.Get<ShopItemConfig>(shopitemId);
  88. shopItem = ShopManger.Instance.GetShopItem(shopitemId);
  89. itemConfig = ConfigComponent.Instance.Get<ItemConfig>(ShopItemConfig.itemId[0]);
  90. if (ShopItemConfig.costItemId == 0)
  91. {
  92. Group_Price.SetActive(false);
  93. Text_Free.gameObject.SetActive(true);
  94. Text_Free.text = LanguageManager.Instance.Text(10328);
  95. }
  96. else
  97. {
  98. ItemConfig costItemConfig = ConfigComponent.Instance.Get<ItemConfig>(ShopItemConfig.costItemId);
  99. Group_Price.SetActive(true);
  100. Text_Free.gameObject.SetActive(false);
  101. Icon_PriceItem.icon_name = costItemConfig.icon;
  102. Text_Price.text = ShopItemConfig.price.ToString();
  103. }
  104. Icon_Itemicon.icon_name = itemConfig.icon;
  105. Text_Count.text = $"x{itemConfig.associateVlaue[0]}";
  106. Text_Tip.text = LanguageManager.Instance.Text(10369, ShopItemConfig.buyCount - shopItem.buyCount);
  107. }
  108. public void CustomInit1(int itemId)
  109. {
  110. openType = 2;
  111. itemConfig = ConfigComponent.Instance.Get<ItemConfig>(itemId);
  112. Icon_Itemicon.icon_name = itemConfig.icon;
  113. Text_Count.text = $"x{itemConfig.associateVlaue[0]}";
  114. Text_Tip.text =
  115. LanguageManager.Instance.Text(10327, PlayerManager.Instance.BagController.GetItemCount(itemId));
  116. Group_Price.SetActive(false);
  117. Text_Free.gameObject.SetActive(true);
  118. Text_Free.text = LanguageManager.Instance.Text(10329);
  119. }
  120. }
  121. }