DivineSenceRestoredWidget.cs 5.3 KB

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