ValueBarController.cs 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. using UI.CommonGame;
  2. using FairyGUI;
  3. namespace GFGGame
  4. {
  5. public class ValueBarController
  6. {
  7. private UI_ComponentValueBar _valueBar;
  8. public ValueBarController(GComponent valueBar, int ctrlSelected = 0)
  9. {
  10. _valueBar = UI_ComponentValueBar.Create(valueBar);
  11. _valueBar.m_c1.selectedIndex = ctrlSelected;
  12. // _valueBar.target.x = 370;
  13. _valueBar.m_btnGold.onClick.Add(() =>
  14. {
  15. ItemUtil.AddGold();
  16. });
  17. _valueBar.m_btnPower.onClick.Add(() =>
  18. {
  19. ItemUtil.AddPower();
  20. });
  21. _valueBar.m_btnDiamondPurple.onClick.Add(() =>
  22. {
  23. ItemUtil.AddDiamondPurple();
  24. });
  25. _valueBar.m_btnDiamondRed.onClick.Add(() =>
  26. {
  27. ItemUtil.AddDiamondRed();
  28. });
  29. _valueBar.m_btnCJLuoXing.onClick.Add(() =>
  30. {
  31. ViewManager.Show(ViewName.LUCKY_BOX_VIEW);
  32. });
  33. _valueBar.m_btnCJHuoDong.onClick.Add(() =>
  34. {
  35. ViewManager.Show(ViewName.LUCKY_BOX_VIEW);
  36. });
  37. _valueBar.m_btnCJ.onClick.Add(() =>
  38. {
  39. int luckyBoxId = LuckyBoxBonusDataCache.currentBoxId;
  40. LuckyBoxCfg luckyBoxCfg = LuckyBoxCfgArray.Instance.GetCfg(luckyBoxId);
  41. CurrencyRatioCfg currencyRatioCfg = ItemUtil.GetCurrencyRatioCfgById(luckyBoxCfg.costID);
  42. ItemUtil.ExchangeItemById(luckyBoxCfg.costID, currencyRatioCfg != null ? currencyRatioCfg.num : 20, true);
  43. });
  44. }
  45. public void Dispose()
  46. {
  47. if (_valueBar != null)
  48. {
  49. _valueBar.Dispose();
  50. }
  51. _valueBar = null;
  52. }
  53. public void OnShown()
  54. {
  55. UpdateGold();
  56. UpdatePower();
  57. UpdateDiamondPurple();
  58. UpdateDiamondRed();
  59. UpdateCJExchange();
  60. UpdateCJ(LuckyBoxBonusDataCache.currentBoxId);
  61. EventAgent.AddEventListener(ConstMessage.ROLE_GOLD_CHANGED, UpdateGold);
  62. EventAgent.AddEventListener(ConstMessage.ROLE_POWER_CHANGED, UpdatePower);
  63. EventAgent.AddEventListener(ConstMessage.ROLE_DIAMOND_PURPLE_CHANGED, UpdateDiamondPurple);
  64. EventAgent.AddEventListener(ConstMessage.ROLE_DIAMOND_RED_CHANGED, UpdateDiamondRed);
  65. EventAgent.AddEventListener(ConstMessage.ITEM_CHANGED, UpdateItem);
  66. }
  67. public void Controller(int ctrlSelected)
  68. {
  69. _valueBar.m_c1.selectedIndex = ctrlSelected;
  70. }
  71. public void OnHide()
  72. {
  73. EventAgent.RemoveEventListener(ConstMessage.ROLE_GOLD_CHANGED, UpdateGold);
  74. EventAgent.RemoveEventListener(ConstMessage.ROLE_POWER_CHANGED, UpdatePower);
  75. EventAgent.RemoveEventListener(ConstMessage.ROLE_DIAMOND_PURPLE_CHANGED, UpdateDiamondPurple);
  76. EventAgent.RemoveEventListener(ConstMessage.ROLE_DIAMOND_RED_CHANGED, UpdateDiamondRed);
  77. EventAgent.RemoveEventListener(ConstMessage.ITEM_CHANGED, UpdateItem);
  78. }
  79. private void UpdateItem()
  80. {
  81. UpdateCJExchange();
  82. UpdateCJ(LuckyBoxBonusDataCache.currentBoxId);
  83. }
  84. private void UpdateGold()
  85. {
  86. _valueBar.m_btnGold.text = "" + RoleDataManager.gold;
  87. EventAgent.DispatchEvent(ConstMessage.MONEY_CHANGE, RoleDataManager.gold);
  88. }
  89. private void UpdatePower()
  90. {
  91. _valueBar.m_btnPower.text = "" + RoleDataManager.power;
  92. EventAgent.DispatchEvent(ConstMessage.MONEY_CHANGE, RoleDataManager.power);
  93. }
  94. private void UpdateDiamondPurple()
  95. {
  96. _valueBar.m_btnDiamondPurple.text = "" + RoleDataManager.diaP;
  97. EventAgent.DispatchEvent(ConstMessage.MONEY_CHANGE, RoleDataManager.diaP);
  98. }
  99. private void UpdateDiamondRed()
  100. {
  101. _valueBar.m_btnDiamondRed.text = "" + RoleDataManager.diaR;
  102. EventAgent.DispatchEvent(ConstMessage.MONEY_CHANGE, RoleDataManager.diaR);
  103. }
  104. //ÕªÐÇ£¨³é½±£©¶Ò»»
  105. private void UpdateCJExchange()
  106. {
  107. int luckyBoxId1 = LuckyBoxDataManager.Instance.luckyBoxIds[1];
  108. LuckyBoxCfg luckyBoxCfg1 = LuckyBoxCfgArray.Instance.GetCfg(luckyBoxId1);
  109. _valueBar.m_btnCJLuoXing.text = "" + ItemDataManager.GetItemNum(luckyBoxCfg1.drop);
  110. _valueBar.m_btnCJLuoXing.icon = ResPathUtil.GetCommonGameResPath(ItemCfgArray.Instance.GetCfg(luckyBoxCfg1.drop).res);
  111. int luckyBoxId2 = LuckyBoxDataManager.Instance.luckyBoxIds[2];
  112. LuckyBoxCfg luckyBoxCfg2 = LuckyBoxCfgArray.Instance.GetCfg(luckyBoxId2);
  113. _valueBar.m_btnCJHuoDong.text = "" + ItemDataManager.GetItemNum(luckyBoxCfg2.drop);
  114. _valueBar.m_btnCJHuoDong.icon = ResPathUtil.GetCommonGameResPath(ItemCfgArray.Instance.GetCfg(luckyBoxCfg2.drop).res);
  115. }
  116. public void UpdateCJ(int id)
  117. {
  118. LuckyBoxCfg luckyBoxCfg = LuckyBoxCfgArray.Instance.GetCfg(id);
  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. }
  124. }