ShopBuyItemPanel.cs 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306
  1. using System;
  2. using Core.Language;
  3. using Core.Utility;
  4. using Excel2Json;
  5. using Fort23.Core;
  6. using Fort23.UTool;
  7. using GameLogic.Bag;
  8. using GameLogic.Hero;
  9. using Utility;
  10. namespace Fort23.Mono
  11. {
  12. /// <summary>
  13. /// 商店购买确认弹框
  14. /// </summary>
  15. [UIBinding(prefab = "ShopBuyItemPanel")]
  16. public partial class ShopBuyItemPanel : UIPanel
  17. {
  18. private string _poolName = "ShopBuyItemPanelItemWidget";
  19. private string _ShopPackBuyItemPanelPoolName = "ShopPackBuyItemPanelPoolName";
  20. public int currentSelectCount;
  21. public int maxCount;
  22. private AccountFileInfo.ShopItem _shopItem;
  23. private ShopItemConfig _shopItemConfig;
  24. private Action<bool, int> _callback;
  25. private bool _buyMark = false;
  26. private void Init()
  27. {
  28. }
  29. public override CTask GetFocus()
  30. {
  31. if (PlayerGuideManager.Instance.GuideIsCanDo(7, 5))
  32. {
  33. PlayerGuideManager.Instance.NextGuide();
  34. }
  35. return base.GetFocus();
  36. }
  37. public async void CustomInit(AccountFileInfo.ShopItem shopItem, Action<bool, int> callback)
  38. {
  39. _buyMark = false;
  40. UIManager.Instance.DormancyAllGComponent<WidgetItem>(_poolName);
  41. _shopItem = shopItem;
  42. _shopItemConfig = ConfigComponent.Instance.Get<ShopItemConfig>(shopItem.id);
  43. _callback = callback;
  44. WidgetItem itemWidget =
  45. await UIManager.Instance.CreateGComponent<WidgetItem>(null, ItemRoot, poolName: _poolName);
  46. itemWidget.InitWidget(new ItemInfo(_shopItemConfig.itemId[0], _shopItemConfig.itemCount[0]));
  47. ItemConfig itemConfig = ConfigComponent.Instance.Get<ItemConfig>(_shopItemConfig.itemId[0]);
  48. Text_name.text = LanguageManager.Instance.Text(itemConfig.itemName);
  49. //法宝
  50. if (itemWidget.itemInfo.config.itemTag == 11)
  51. {
  52. AccountFileInfo.FaBaoData faaData = new AccountFileInfo.FaBaoData();
  53. faaData.id = itemWidget.itemInfo.config.associateVlaue[1];
  54. faaData.level = 1;
  55. faaData.useIndex = -1;
  56. FaBaoInfo faBaoInfo = new FaBaoInfo(faaData);
  57. Text_desc.text = UtilTools.GetString(LanguageManager.Instance.Text(faBaoInfo.SkillConfig.dec),
  58. faBaoInfo.effectValue);
  59. }
  60. //功法
  61. else if (itemWidget.itemInfo.config.itemTag == 13)
  62. {
  63. AccountFileInfo.SkillData skillData = new AccountFileInfo.SkillData();
  64. skillData.id = itemWidget.itemInfo.config.associateVlaue[1];
  65. skillData.star = 1;
  66. skillData.level = 1;
  67. skillData.useIndex = -1;
  68. SkillInfo skillInfo = new SkillInfo(skillData);
  69. SkillConfig skillConfig =
  70. ConfigComponent.Instance.Get<SkillConfig>(itemConfig.associateVlaue[1] * 10 + 1);
  71. Text_desc.text =
  72. UtilTools.GetString(LanguageManager.Instance.Text(skillConfig.dec), skillInfo.effectValue);
  73. }
  74. else
  75. {
  76. Text_desc.text = LanguageManager.Instance.Text(itemWidget.itemInfo.config.itemDesc);
  77. }
  78. Text_ItemCount.text =
  79. "当前持有:" + PlayerManager.Instance.BagController.GetItemCount(_shopItemConfig.itemId[0]);
  80. // UseSlider.value = 1;
  81. // UseSlider.minValue = 1;
  82. Text_BuyCount.text = "1";
  83. Refresh();
  84. UpdateShowData(1);
  85. ChangeBtnState();
  86. }
  87. private void Refresh()
  88. {
  89. //无限制 最多购买十个
  90. if (_shopItemConfig.buyCount == -1)
  91. {
  92. LimitObj.SetActive(false);
  93. Text_LimitCount.text = "无";
  94. if (_shopItemConfig.price != 0)
  95. {
  96. int total = (int)(PlayerManager.Instance.BagController.GetItemCount(_shopItemConfig.costItemId) /
  97. _shopItemConfig.price);
  98. maxCount = total >= 10 ? 10 : total;
  99. }
  100. if (maxCount <= 1)
  101. {
  102. maxCount = 1;
  103. }
  104. SliderObj.SetActive(maxCount > 1);
  105. // UseSlider.maxValue = maxCount;
  106. // UseSlider.value = 1;
  107. }
  108. else
  109. {
  110. LimitObj.SetActive(true);
  111. Text_LimitCount.text = $"{_shopItem.buyCount}/{_shopItemConfig.buyCount}";
  112. maxCount = _shopItemConfig.buyCount - _shopItem.buyCount;
  113. if (_shopItemConfig.price != 0)
  114. {
  115. int temp = (int)(PlayerManager.Instance.BagController.GetItemCount(_shopItemConfig.costItemId) /
  116. _shopItemConfig.price);
  117. if (temp < maxCount)
  118. {
  119. maxCount = temp;
  120. }
  121. }
  122. if (maxCount <= 1)
  123. {
  124. maxCount = 1;
  125. }
  126. SliderObj.SetActive(maxCount > 1);
  127. // UseSlider.maxValue = maxCount;
  128. // UseSlider.value = 1;
  129. }
  130. if (_shopItemConfig.costItemId == GlobalParam.RMB_1031)
  131. {
  132. Text_Price.text = "¥" + _shopItemConfig.price.ToString();
  133. ImageCurrency.gameObject.SetActive(false);
  134. }
  135. else if (_shopItemConfig.costItemId == 0)
  136. {
  137. ImageCurrency.gameObject.SetActive(false);
  138. Text_Price.text = "免费";
  139. }
  140. else
  141. {
  142. Text_Price.text = _shopItemConfig.price.ToString();
  143. ImageCurrency.gameObject.SetActive(true);
  144. }
  145. ImageCurrency.icon_name = ConfigComponent.Instance.Get<ItemConfig>(_shopItemConfig.costItemId).icon;
  146. }
  147. protected override void AddEvent()
  148. {
  149. }
  150. protected override void DelEvent()
  151. {
  152. }
  153. public override void AddButtonEvent()
  154. {
  155. // Btn_Close.onClick.AddListener((() => { UIManager.Instance.HideUIUIPanel(this); }));
  156. Btn_Close1.onClick.AddListener((() => { UIManager.Instance.HideUIUIPanel(this); }));
  157. // UseSlider.onValueChanged.AddListener(OnValueChanged);
  158. Btn_Add.onClick.AddListener(Add);
  159. Btn_Reduce.onClick.AddListener(Reduce);
  160. Btn_Function.onClick.AddListener(Function);
  161. Btn_Min.onClick.AddListener(ReduceMin);
  162. Btn_Max.onClick.AddListener(AddMax);
  163. }
  164. private async void Function()
  165. {
  166. _buyMark = true;
  167. UIManager.Instance.HideUIUIPanel(this);
  168. if (PlayerGuideManager.Instance.GuideIsCanDo(7, 6))
  169. {
  170. PlayerGuideManager.Instance.NextGuide();
  171. }
  172. }
  173. private void Reduce()
  174. {
  175. currentSelectCount--;
  176. if (currentSelectCount < 1)
  177. {
  178. currentSelectCount = 1;
  179. }
  180. ChangeBtnState();
  181. OnValueChanged(currentSelectCount);
  182. // UseSlider.value = currentSelectCount;
  183. }
  184. private void Add()
  185. {
  186. currentSelectCount++;
  187. if (currentSelectCount > maxCount)
  188. {
  189. currentSelectCount = maxCount;
  190. }
  191. ChangeBtnState();
  192. OnValueChanged(currentSelectCount);
  193. // UseSlider.value = currentSelectCount;
  194. }
  195. private void ReduceMin()
  196. {
  197. currentSelectCount = 1;
  198. ChangeBtnState();
  199. OnValueChanged(currentSelectCount);
  200. }
  201. private void AddMax()
  202. {
  203. currentSelectCount = maxCount;
  204. ChangeBtnState();
  205. OnValueChanged(currentSelectCount);
  206. }
  207. private void ChangeBtnState()
  208. {
  209. if (currentSelectCount == 1)
  210. {
  211. Btn_Min.transform.Gray();
  212. Btn_Reduce.transform.Gray();
  213. }
  214. else
  215. {
  216. Btn_Min.transform.RecoverColor();
  217. Btn_Reduce.transform.RecoverColor();
  218. }
  219. if (currentSelectCount == maxCount)
  220. {
  221. Btn_Max.transform.Gray();
  222. Btn_Add.transform.Gray();
  223. }
  224. else
  225. {
  226. Btn_Max.transform.RecoverColor();
  227. Btn_Add.transform.RecoverColor();
  228. }
  229. }
  230. private void OnValueChanged(float arg0)
  231. {
  232. UpdateShowData(arg0);
  233. }
  234. private void UpdateShowData(float arg0)
  235. {
  236. int count = (int)arg0;
  237. currentSelectCount = count;
  238. Text_BuyCount.text = count.ToString();
  239. if (_shopItemConfig.costItemId == GlobalParam.RMB_1031)
  240. {
  241. Text_Price.text = $"¥{(count * _shopItemConfig.price).ToString()}";
  242. ImageCurrency.gameObject.SetActive(false);
  243. }
  244. else if (_shopItemConfig.costItemId == 0)
  245. {
  246. Text_Price.text = "免费";
  247. }
  248. else
  249. {
  250. Text_Price.text = $"{(count * _shopItemConfig.price).ToString()}";
  251. ImageCurrency.gameObject.SetActive(true);
  252. }
  253. // Text_Price.text = $"{(count * _shopItemConfig.price).ToString()}";
  254. }
  255. public async override CTask Close()
  256. {
  257. await base.Close();
  258. UIManager.Instance.DormancyAllGComponent<WidgetItem>(_poolName);
  259. _callback?.Invoke(_buyMark, currentSelectCount);
  260. }
  261. }
  262. }