DivineSenceRestoredWidget.cs 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194
  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. //TODO 消耗:神识丹(代金卷直购)
  61. PlayerManager.Instance.BagController.DeductItem(itemInfo.config.ID, 1);
  62. }
  63. }
  64. UIManager.Instance.GetComponent<DivineSenceRestoredPanel>().CreatWidget();
  65. // CustomInit(ShopItemConfig.ID);
  66. }
  67. else
  68. {
  69. TipMessagePanel.OpenTipMessagePanel(833, Vector2.zero);
  70. }
  71. }
  72. //直接使用道具
  73. else
  74. {
  75. if (PlayerManager.Instance.BagController.IsEnough(itemConfig.ID, 1))
  76. {
  77. AudioManager.Instance.PlayAudio("ui_tycg.wav");
  78. AccountFileInfo.Instance.playerData.divineSensePoint +=
  79. itemConfig.associateVlaue[0];
  80. //TODO 消耗:神识丹(自有道具)
  81. PlayerManager.Instance.BagController.DeductItem(itemConfig.ID, 1);
  82. EventManager.Instance.Dispatch(CustomEventType.DivineSensePointChange, null);
  83. UIManager.Instance.GetComponent<DivineSenceRestoredPanel>().CreatWidget();
  84. }
  85. else
  86. {
  87. AudioManager.Instance.PlayAudio("ui_chaozuoshibai.wav");
  88. ItemSourcePanel.OpenPanel(itemConfig.ID);
  89. // TipMessagePanel.OpenTipMessagePanel(10324, Vector2.zero);
  90. }
  91. }
  92. EventManager.Instance.Dispatch(CustomEventType.DivineSensePointChange, null);
  93. });
  94. }
  95. public async void CustomInit(int shopitemId)
  96. {
  97. openType = 1;
  98. ShopItemConfig = ConfigComponent.Instance.Get<ShopItemConfig>(shopitemId);
  99. shopItem = ShopManger.Instance.GetShopItem(shopitemId);
  100. itemConfig = ConfigComponent.Instance.Get<ItemConfig>(ShopItemConfig.itemId[0]);
  101. if (ShopItemConfig.costItemId == 0)
  102. {
  103. Group_Price.SetActive(false);
  104. Text_Free.gameObject.SetActive(true);
  105. Text_Free.text = LanguageManager.Instance.Text(10328);
  106. }
  107. else
  108. {
  109. ItemConfig costItemConfig = ConfigComponent.Instance.Get<ItemConfig>(ShopItemConfig.costItemId);
  110. Group_Price.SetActive(true);
  111. Text_Free.gameObject.SetActive(false);
  112. Icon_PriceItem.icon_name = costItemConfig.icon;
  113. Text_Price.text = ShopItemConfig.price.ToString();
  114. }
  115. Text_Name.text = LanguageManager.Instance.Text(itemConfig.itemName);
  116. Text_Count.text = $"+{itemConfig.associateVlaue[0]}";
  117. Text_Tip.text = LanguageManager.Instance.Text(10369, ShopItemConfig.buyCount - shopItem.buyCount);
  118. bool isCanBuy = true;
  119. if (ShopItemConfig.buyCount != -1 && shopItem.buyCount >= ShopItemConfig.buyCount)
  120. {
  121. isCanBuy = false;
  122. }
  123. if (ShopItemConfig.price != 0 &&
  124. !PlayerManager.Instance.BagController.IsEnough(ShopItemConfig.costItemId,
  125. ShopItemConfig.price * 1))
  126. {
  127. isCanBuy = false;
  128. }
  129. if (isCanBuy)
  130. {
  131. Btn_Use.transform.RecoverColor();
  132. }
  133. else
  134. {
  135. Btn_Use.transform.Gray();
  136. }
  137. WidgetItem widgetItem =
  138. await UIManager.Instance.CreateGComponentForObject<WidgetItem>(WidgetItemGam, null, itemRoot);
  139. widgetItem.InitWidget(new ItemInfo(itemConfig.ID, 0));
  140. }
  141. public async void CustomInit1(int itemId)
  142. {
  143. openType = 2;
  144. itemConfig = ConfigComponent.Instance.Get<ItemConfig>(itemId);
  145. Text_Name.text = LanguageManager.Instance.Text(itemConfig.itemName);
  146. Text_Count.text = $"+{itemConfig.associateVlaue[0]}";
  147. Text_Tip.text =
  148. LanguageManager.Instance.Text(10327, PlayerManager.Instance.BagController.GetItemCount(itemId));
  149. Group_Price.SetActive(false);
  150. Text_Free.gameObject.SetActive(true);
  151. Text_Free.text = LanguageManager.Instance.Text(10329);
  152. if (PlayerManager.Instance.BagController.IsEnough(itemConfig.ID, 1))
  153. {
  154. Btn_Use.transform.RecoverColor();
  155. }
  156. else
  157. {
  158. Btn_Use.transform.Gray();
  159. }
  160. WidgetItem widgetItem =
  161. await UIManager.Instance.CreateGComponentForObject<WidgetItem>(WidgetItemGam, null, itemRoot);
  162. widgetItem.InitWidget(new ItemInfo(itemConfig.ID, 0));
  163. }
  164. }
  165. }