ValueBarController.cs 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. using UI.CommonGame;
  2. using FairyGUI;
  3. using ET;
  4. namespace GFGGame
  5. {
  6. public class ValueBarController
  7. {
  8. private UI_ComponentValueBar _valueBar;
  9. public ValueBarController(GComponent valueBar, int ctrlSelected = 0)
  10. {
  11. _valueBar = UI_ComponentValueBar.Create(valueBar);
  12. // _valueBar.m_c1.selectedIndex = ctrlSelected;
  13. // _valueBar.target.x = 370;
  14. _valueBar.m_btnGold.onClick.Add(() =>
  15. {
  16. ItemUtil.AddGold();
  17. });
  18. _valueBar.m_btnPower.onClick.Add(() =>
  19. {
  20. ItemUtil.AddPower();
  21. });
  22. _valueBar.m_btnDiamondPurple.onClick.Add(() =>
  23. {
  24. ItemUtil.AddDiamondPurple();
  25. });
  26. _valueBar.m_btnDiamondRed.onClick.Add(() =>
  27. {
  28. ItemUtil.AddDiamondRed();
  29. });
  30. _valueBar.m_btnCJLuoXing.onClick.Add(() =>
  31. {
  32. ViewManager.Show(ViewName.LUCKY_BOX_VIEW);
  33. });
  34. _valueBar.m_btnCJHuoDong.onClick.Add(() =>
  35. {
  36. ViewManager.Show(ViewName.LUCKY_BOX_VIEW);
  37. });
  38. _valueBar.m_btnCJ.onClick.Add((EventCallback0)(() =>
  39. {
  40. int luckyBoxId = LuckyBoxDataManager.Instance.currentBoxId;
  41. LuckyBoxCfg luckyBoxCfg = LuckyBoxCfgArray.Instance.GetCfg(luckyBoxId);
  42. ItemUtil.ExchangeItemById(luckyBoxCfg.costID, 1, true);
  43. }));
  44. _valueBar.m_btnTravel.onClick.Add(() =>
  45. {
  46. object[] sourceDatas = new object[] { GlobalCfgArray.globalCfg.travelCostArr[0], new object[] { typeof(TravelView).FullName, null } };
  47. GoodsItemTipsController.ShowItemTips(GlobalCfgArray.globalCfg.travelCostArr[0], sourceDatas);
  48. });
  49. _valueBar.m_btnGallery.onClick.Add(() =>
  50. {
  51. ViewManager.Show<PoemGalleryRuleView>();
  52. });
  53. }
  54. public void Dispose()
  55. {
  56. if (_valueBar != null)
  57. {
  58. _valueBar.Dispose();
  59. }
  60. _valueBar = null;
  61. }
  62. public void OnShown()
  63. {
  64. UpdateCurrency();
  65. UpdateNumeric();
  66. UpdateCJExchange();
  67. UpdateCJAExchange();
  68. UpdateCJ();
  69. UpdateTravel();
  70. UpdateGallery();
  71. EventAgent.AddEventListener(ConstMessage.NUMERIC_CHANGE, UpdateNumeric);
  72. EventAgent.AddEventListener(ConstMessage.ITEM_CHANGED, UpdateItem);
  73. }
  74. public void Controller(int ctrlSelected)
  75. {
  76. _valueBar.m_c1.selectedIndex = ctrlSelected;
  77. }
  78. public void OnHide()
  79. {
  80. EventAgent.RemoveEventListener(ConstMessage.NUMERIC_CHANGE, UpdateNumeric);
  81. EventAgent.RemoveEventListener(ConstMessage.ITEM_CHANGED, UpdateItem);
  82. }
  83. private void UpdateItem()
  84. {
  85. UpdateCurrency();
  86. UpdateCJExchange();
  87. UpdateCJAExchange();
  88. UpdateCJ();
  89. UpdateTravel();
  90. UpdateGallery();
  91. }
  92. private void UpdateCurrency()
  93. {
  94. _valueBar.m_btnGold.text = "" + RoleDataManager.gold;
  95. _valueBar.m_btnDiamondPurple.text = "" + RoleDataManager.diaP;
  96. _valueBar.m_btnDiamondRed.text = "" + RoleDataManager.diaR;
  97. }
  98. private void UpdateNumeric()
  99. {
  100. // _valueBar.m_btnGold.text = "" + RoleDataManager.gold; //GameGlobal.myNumericComponent.GetAsInt(NumericType.Gold);
  101. _valueBar.m_btnPower.text = string.Format("{0}/{1}", RoleDataManager.power, GameGlobal.myNumericComponent.GetAsInt(NumericType.PowerLimit));
  102. // _valueBar.m_btnDiamondPurple.text = "" + RoleDataManager.diaP;// GameGlobal.myNumericComponent.GetAsInt(NumericType.DiamondP);
  103. // _valueBar.m_btnDiamondRed.text = "" + RoleDataManager.diaR;// GameGlobal.myNumericComponent.GetAsInt(NumericType.DiamondR);
  104. }
  105. //ժ�ǣ��齱���һ�
  106. private void UpdateCJExchange()
  107. {
  108. _valueBar.m_btnCJLuoXing.text = "" + ItemDataManager.GetItemNum(ConstItemID.LUCKYBOX_STORE_COST);
  109. _valueBar.m_btnCJLuoXing.icon = ResPathUtil.GetCommonGameResPath(ItemCfgArray.Instance.GetCfg(ConstItemID.LUCKYBOX_STORE_COST).res);
  110. }
  111. private void UpdateCJAExchange()
  112. {
  113. _valueBar.m_btnCJHuoDong.text = "" + ItemDataManager.GetItemNum(ConstItemID.LUCKYBOX_ACTIVITY_STORE_COST);
  114. _valueBar.m_btnCJHuoDong.icon = ResPathUtil.GetCommonGameResPath(ItemCfgArray.Instance.GetCfg(ConstItemID.LUCKYBOX_ACTIVITY_STORE_COST).res);
  115. }
  116. public void UpdateCJ()
  117. {
  118. LuckyBoxCfg luckyBoxCfg = LuckyBoxCfgArray.Instance.GetCfg(LuckyBoxDataManager.Instance.currentBoxId);
  119. if (luckyBoxCfg == null) return;
  120. _valueBar.m_btnCJ.text = "" + ItemDataManager.GetItemNum(luckyBoxCfg.costID);
  121. _valueBar.m_btnCJ.icon = ResPathUtil.GetCommonGameResPath(ItemCfgArray.Instance.GetCfg(luckyBoxCfg.costID).res);
  122. }
  123. private void UpdateTravel()
  124. {
  125. int itemId = GlobalCfgArray.globalCfg.travelCostArr[0];
  126. _valueBar.m_btnTravel.text = "" + ItemDataManager.GetItemNum(itemId);
  127. _valueBar.m_btnTravel.icon = ResPathUtil.GetCommonGameResPath(ItemCfgArray.Instance.GetCfg(itemId).res);
  128. }
  129. private void UpdateGallery()
  130. {
  131. _valueBar.m_btnGallery.text = "" + ItemDataManager.GetItemNum(ConstItemID.GALLERY_STORE_COST);
  132. _valueBar.m_btnGallery.icon = ResPathUtil.GetCommonGameResPath(ItemCfgArray.Instance.GetCfg(ConstItemID.GALLERY_STORE_COST).res);
  133. }
  134. }
  135. }