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