ValueBarController.cs 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  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 = LuckyBoxBonusDataCache.currentBoxId;
  41. LuckyBoxCfg luckyBoxCfg = LuckyBoxCfgArray.Instance.GetCfg(luckyBoxId);
  42. ExchangeCfg currencyRatioCfg = ItemUtil.GetCurrencyRatioCfgById(luckyBoxCfg.costID);
  43. ItemUtil.ExchangeItemById(luckyBoxCfg.costID, (int)(currencyRatioCfg != null ? currencyRatioCfg.num : 20), true);
  44. }));
  45. }
  46. public void Dispose()
  47. {
  48. if (_valueBar != null)
  49. {
  50. _valueBar.Dispose();
  51. }
  52. _valueBar = null;
  53. }
  54. public void OnShown()
  55. {
  56. UpdateNumeric();
  57. UpdateCJExchange();
  58. UpdateCJ(LuckyBoxBonusDataCache.currentBoxId);
  59. EventAgent.AddEventListener(ConstMessage.NUMERIC_CHANGE, UpdateNumeric);
  60. EventAgent.AddEventListener(ConstMessage.ITEM_CHANGED, UpdateItem);
  61. }
  62. public void Controller(int ctrlSelected)
  63. {
  64. _valueBar.m_c1.selectedIndex = ctrlSelected;
  65. }
  66. public void OnHide()
  67. {
  68. EventAgent.RemoveEventListener(ConstMessage.NUMERIC_CHANGE, UpdateNumeric);
  69. EventAgent.RemoveEventListener(ConstMessage.ITEM_CHANGED, UpdateItem);
  70. }
  71. private void UpdateItem()
  72. {
  73. UpdateCJExchange();
  74. UpdateCJ(LuckyBoxBonusDataCache.currentBoxId);
  75. }
  76. private void UpdateNumeric()
  77. {
  78. _valueBar.m_btnGold.text = "" + GameGlobal.myNumericComponent.GetAsInt(NumericType.Gold);
  79. _valueBar.m_btnPower.text = "" + GameGlobal.myNumericComponent.GetAsInt(NumericType.Power);
  80. _valueBar.m_btnDiamondPurple.text = "" + GameGlobal.myNumericComponent.GetAsInt(NumericType.DiamondP);
  81. _valueBar.m_btnDiamondRed.text = "" + GameGlobal.myNumericComponent.GetAsInt(NumericType.DiamondR);
  82. }
  83. //ÕªÐÇ£¨³é½±£©¶Ò»»
  84. private void UpdateCJExchange()
  85. {
  86. int luckyBoxId1 = LuckyBoxDataManager.BOX_ID_2;
  87. LuckyBoxCfg luckyBoxCfg1 = LuckyBoxCfgArray.Instance.GetCfg(luckyBoxId1);
  88. _valueBar.m_btnCJLuoXing.text = "" + ItemDataManager.GetItemNum(luckyBoxCfg1.drop);
  89. _valueBar.m_btnCJLuoXing.icon = ResPathUtil.GetCommonGameResPath(ItemCfgArray.Instance.GetCfg(luckyBoxCfg1.drop).res);
  90. int luckyBoxId2 = LuckyBoxDataManager.BOX_ID_1;
  91. LuckyBoxCfg luckyBoxCfg2 = LuckyBoxCfgArray.Instance.GetCfg(luckyBoxId2);
  92. _valueBar.m_btnCJHuoDong.text = "" + ItemDataManager.GetItemNum(luckyBoxCfg2.drop);
  93. _valueBar.m_btnCJHuoDong.icon = ResPathUtil.GetCommonGameResPath(ItemCfgArray.Instance.GetCfg(luckyBoxCfg2.drop).res);
  94. }
  95. public void UpdateCJ(int id)
  96. {
  97. LuckyBoxCfg luckyBoxCfg = LuckyBoxCfgArray.Instance.GetCfg(id);
  98. if (luckyBoxCfg == null) return;
  99. _valueBar.m_btnCJ.text = "" + ItemDataManager.GetItemNum(luckyBoxCfg.costID);
  100. _valueBar.m_btnCJ.icon = ResPathUtil.GetCommonGameResPath(ItemCfgArray.Instance.GetCfg(luckyBoxCfg.costID).res);
  101. }
  102. }
  103. }