DivineSenceRestoredWidget.cs 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192
  1. using System.Collections.Generic;
  2. using Core.Audio;
  3. using Core.Language;
  4. using Excel2Json;
  5. using Fort23.Core;
  6. using Fort23.UTool;
  7. using GameLogic.Bag;
  8. using UnityEngine;
  9. namespace Fort23.Mono
  10. {
  11. [UIBinding(prefab = "DivineSenceRestoredWidget")]
  12. public partial class DivineSenceRestoredWidget : UIComponent
  13. {
  14. private ShopItemConfig ShopItemConfig;
  15. private AccountFileInfo.ShopItem shopItem;
  16. private ItemConfig itemConfig;
  17. private int openType;
  18. private void Init()
  19. {
  20. }
  21. public override void AddEvent()
  22. {
  23. }
  24. public override void DelEvent()
  25. {
  26. }
  27. public override void AddButtonEvent()
  28. {
  29. Btn_Use.onClick.AddListener(async () =>
  30. {
  31. //购买并使用道具
  32. if (openType == 1)
  33. {
  34. if (ShopItemConfig.buyCount != -1 && shopItem.buyCount >= ShopItemConfig.buyCount)
  35. {
  36. TipMessagePanel.OpenTipMessagePanel(10366, Vector2.zero);
  37. return;
  38. }
  39. if (ShopItemConfig.price != 0 &&
  40. !PlayerManager.Instance.BagController.IsEnough(ShopItemConfig.costItemId,
  41. ShopItemConfig.price * 1))
  42. {
  43. AudioManager.Instance.PlayAudio("ui_chaozuoshibai.wav");
  44. ItemSourcePanel.OpenPanel(ShopItemConfig.costItemId);
  45. // TipMessagePanel.OpenTipMessagePanel(829, Vector2.zero);
  46. return;
  47. }
  48. List<ItemInfo> itemInfos = await ShopManger.Instance.BuyItem(ShopItemConfig.ID, 1);
  49. if (itemInfos != null)
  50. {
  51. AudioManager.Instance.PlayAudio("ui_tycg.wav");
  52. //使用道具
  53. foreach (var itemInfo in itemInfos)
  54. {
  55. if (itemInfo.config.itemTag == 8)
  56. {
  57. AccountFileInfo.Instance.playerData.divineSensePoint +=
  58. itemInfo.config.associateVlaue[0];
  59. EventManager.Instance.Dispatch(CustomEventType.DivineSensePointChange, null);
  60. PlayerManager.Instance.BagController.DeductItem(itemInfo.config.ID, 1);
  61. }
  62. }
  63. UIManager.Instance.GetComponent<DivineSenceRestoredPanel>().CreatWidget();
  64. // CustomInit(ShopItemConfig.ID);
  65. }
  66. else
  67. {
  68. TipMessagePanel.OpenTipMessagePanel(833, Vector2.zero);
  69. }
  70. }
  71. //世界使用道具
  72. else
  73. {
  74. if (PlayerManager.Instance.BagController.IsEnough(itemConfig.ID, 1))
  75. {
  76. AudioManager.Instance.PlayAudio("ui_tycg.wav");
  77. AccountFileInfo.Instance.playerData.divineSensePoint +=
  78. itemConfig.associateVlaue[0];
  79. PlayerManager.Instance.BagController.DeductItem(itemConfig.ID, 1);
  80. EventManager.Instance.Dispatch(CustomEventType.DivineSensePointChange, null);
  81. UIManager.Instance.GetComponent<DivineSenceRestoredPanel>().CreatWidget();
  82. }
  83. else
  84. {
  85. AudioManager.Instance.PlayAudio("ui_chaozuoshibai.wav");
  86. ItemSourcePanel.OpenPanel(itemConfig.ID);
  87. // TipMessagePanel.OpenTipMessagePanel(10324, Vector2.zero);
  88. }
  89. }
  90. EventManager.Instance.Dispatch(CustomEventType.DivineSensePointChange, null);
  91. });
  92. }
  93. public async void CustomInit(int shopitemId)
  94. {
  95. openType = 1;
  96. ShopItemConfig = ConfigComponent.Instance.Get<ShopItemConfig>(shopitemId);
  97. shopItem = ShopManger.Instance.GetShopItem(shopitemId);
  98. itemConfig = ConfigComponent.Instance.Get<ItemConfig>(ShopItemConfig.itemId[0]);
  99. if (ShopItemConfig.costItemId == 0)
  100. {
  101. Group_Price.SetActive(false);
  102. Text_Free.gameObject.SetActive(true);
  103. Text_Free.text = LanguageManager.Instance.Text(10328);
  104. }
  105. else
  106. {
  107. ItemConfig costItemConfig = ConfigComponent.Instance.Get<ItemConfig>(ShopItemConfig.costItemId);
  108. Group_Price.SetActive(true);
  109. Text_Free.gameObject.SetActive(false);
  110. Icon_PriceItem.icon_name = costItemConfig.icon;
  111. Text_Price.text = ShopItemConfig.price.ToString();
  112. }
  113. Text_Name.text = LanguageManager.Instance.Text(itemConfig.itemName);
  114. Text_Count.text = $"+{itemConfig.associateVlaue[0]}";
  115. Text_Tip.text = LanguageManager.Instance.Text(10369, ShopItemConfig.buyCount - shopItem.buyCount);
  116. bool isCanBuy = true;
  117. if (ShopItemConfig.buyCount != -1 && shopItem.buyCount >= ShopItemConfig.buyCount)
  118. {
  119. isCanBuy = false;
  120. }
  121. if (ShopItemConfig.price != 0 &&
  122. !PlayerManager.Instance.BagController.IsEnough(ShopItemConfig.costItemId,
  123. ShopItemConfig.price * 1))
  124. {
  125. isCanBuy = false;
  126. }
  127. if (isCanBuy)
  128. {
  129. Btn_Use.transform.RecoverColor();
  130. }
  131. else
  132. {
  133. Btn_Use.transform.Gray();
  134. }
  135. WidgetItem widgetItem =
  136. await UIManager.Instance.CreateGComponentForObject<WidgetItem>(WidgetItemGam, null, itemRoot);
  137. widgetItem.InitWidget(new ItemInfo(itemConfig.ID, 0));
  138. }
  139. public async void CustomInit1(int itemId)
  140. {
  141. openType = 2;
  142. itemConfig = ConfigComponent.Instance.Get<ItemConfig>(itemId);
  143. Text_Name.text = LanguageManager.Instance.Text(itemConfig.itemName);
  144. Text_Count.text = $"+{itemConfig.associateVlaue[0]}";
  145. Text_Tip.text =
  146. LanguageManager.Instance.Text(10327, PlayerManager.Instance.BagController.GetItemCount(itemId));
  147. Group_Price.SetActive(false);
  148. Text_Free.gameObject.SetActive(true);
  149. Text_Free.text = LanguageManager.Instance.Text(10329);
  150. if (PlayerManager.Instance.BagController.IsEnough(itemConfig.ID, 1))
  151. {
  152. Btn_Use.transform.RecoverColor();
  153. }
  154. else
  155. {
  156. Btn_Use.transform.Gray();
  157. }
  158. WidgetItem widgetItem =
  159. await UIManager.Instance.CreateGComponentForObject<WidgetItem>(WidgetItemGam, null, itemRoot);
  160. widgetItem.InitWidget(new ItemInfo(itemConfig.ID, 0));
  161. }
  162. }
  163. }