MarketPageComp.cs 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using Api;
  4. using Mono.Cecil.Cil;
  5. using Plugins.CxShine.page;
  6. using UI;
  7. using UI.Common;
  8. using Unity.VisualScripting;
  9. using UnityEngine;
  10. public class MarketPageComp : MonoBehaviour
  11. {
  12. public Transform ScrollRect;
  13. public GameObject CockItemPreafab;
  14. void Start()
  15. {
  16. ApiComp.Instance.cockMarket(data =>
  17. {
  18. foreach (var marketCock in data.market)
  19. {
  20. var itemComp=Instantiate(CockItemPreafab, ScrollRect, false).GetComponent<CockUIItemComp>();
  21. itemComp.ModeBuy(marketCock);
  22. itemComp.ClickBuyAction += BuyCock;
  23. }
  24. }, null);
  25. GetComponent<PageComp>().setOnPageCloseListener((() =>
  26. {
  27. HallComp.Instance.BackToHallAndRefreshUI();
  28. ;
  29. }));
  30. }
  31. private void BuyCock(MarketCock marketCock)
  32. {
  33. if (marketCock.diamond > AccountManager.Instance.GetDiamond())
  34. {
  35. TipsComp.ShowTips("Not enough diamonds");
  36. return;
  37. }
  38. ApiComp.Instance.BuyCock(marketCock.marketId, data =>
  39. {
  40. TipsComp.ShowTips("Success!");
  41. }, (code, err) =>
  42. {
  43. TipsComp.ShowTips(err);
  44. });
  45. }
  46. }