DivineSenceRestoredWidget.cs 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  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. UIManager.Instance.GetComponent<DivineSenceRestoredPanel>().CreatWidget();
  60. // CustomInit(ShopItemConfig.ID);
  61. }
  62. else
  63. {
  64. TipMessagePanel.OpenTipMessagePanel(833, Vector2.zero);
  65. }
  66. }
  67. //世界使用道具
  68. else
  69. {
  70. if (PlayerManager.Instance.BagController.IsEnough(itemConfig.ID, 1))
  71. {
  72. AccountFileInfo.Instance.playerData.divineSensePoint +=
  73. itemConfig.associateVlaue[0];
  74. PlayerManager.Instance.BagController.DeductItem(itemConfig.ID, 1);
  75. UIManager.Instance.GetComponent<DivineSenceRestoredPanel>().CreatWidget();
  76. }
  77. else
  78. {
  79. TipMessagePanel.OpenTipMessagePanel(10324, Vector2.zero);
  80. }
  81. }
  82. EventManager.Instance.Dispatch(CustomEventType.DivineSensePointChange, null);
  83. });
  84. }
  85. public void CustomInit(int shopitemId)
  86. {
  87. openType = 1;
  88. ShopItemConfig = ConfigComponent.Instance.Get<ShopItemConfig>(shopitemId);
  89. shopItem = ShopManger.Instance.GetShopItem(shopitemId);
  90. itemConfig = ConfigComponent.Instance.Get<ItemConfig>(ShopItemConfig.itemId[0]);
  91. if (ShopItemConfig.costItemId == 0)
  92. {
  93. Group_Price.SetActive(false);
  94. Text_Free.gameObject.SetActive(true);
  95. Text_Free.text = LanguageManager.Instance.Text(10328);
  96. }
  97. else
  98. {
  99. ItemConfig costItemConfig = ConfigComponent.Instance.Get<ItemConfig>(ShopItemConfig.costItemId);
  100. Group_Price.SetActive(true);
  101. Text_Free.gameObject.SetActive(false);
  102. Icon_PriceItem.icon_name = costItemConfig.icon;
  103. Text_Price.text = ShopItemConfig.price.ToString();
  104. }
  105. Icon_Itemicon.icon_name = itemConfig.icon;
  106. Text_Count.text = $"x{itemConfig.associateVlaue[0]}";
  107. Text_Tip.text = LanguageManager.Instance.Text(10369, ShopItemConfig.buyCount - shopItem.buyCount);
  108. }
  109. public void CustomInit1(int itemId)
  110. {
  111. openType = 2;
  112. itemConfig = ConfigComponent.Instance.Get<ItemConfig>(itemId);
  113. Icon_Itemicon.icon_name = itemConfig.icon;
  114. Text_Count.text = $"x{itemConfig.associateVlaue[0]}";
  115. Text_Tip.text =
  116. LanguageManager.Instance.Text(10327, PlayerManager.Instance.BagController.GetItemCount(itemId));
  117. Group_Price.SetActive(false);
  118. Text_Free.gameObject.SetActive(true);
  119. Text_Free.text = LanguageManager.Instance.Text(10329);
  120. }
  121. }
  122. }