ExchangeGoodsView.cs 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  1. using FairyGUI;
  2. using System;
  3. using UI.CommonGame;
  4. using UI.PopWindow;
  5. namespace GFGGame
  6. {
  7. public class ExchangeGoodsView : BaseWindow
  8. {
  9. private UI_ExchangeGoodsUI _ui;
  10. private int _skillId = 0;
  11. private long _nowCount = 0; //当前选择的数量
  12. private long _maxCount = 0; //可选择的最大数量
  13. public override void Dispose()
  14. {
  15. if (_ui != null)
  16. {
  17. _ui.Dispose();
  18. _ui = null;
  19. }
  20. base.Dispose();
  21. }
  22. protected override void OnInit()
  23. {
  24. base.OnInit();
  25. packageName = UI_ExchangeGoodsUI.PACKAGE_NAME;
  26. _ui = UI_ExchangeGoodsUI.Create();
  27. this.viewCom = _ui.target;
  28. this.viewCom.Center();
  29. this.modal = true;
  30. viewAnimationType = EnumViewAnimationType.ZOOM_CENTER;
  31. _ui.m_listConsume.itemRenderer = RenderListConsumeItem;
  32. _ui.m_btnCancel.onClick.Add(OnBtnCancelClick);
  33. _ui.m_btnUse.onClick.Add(OnBtnUseClick);
  34. _ui.m_btnReduce.onClick.Add(OnClickBtnReduce);
  35. _ui.m_btnAdd.onClick.Add(OnClickBtnAdd);
  36. _ui.m_btnAllChoose.onClick.Add(OnClickAllChoose);
  37. _ui.m_slideUpLevel.onChanged.Add(OnChangeUpLevel);
  38. }
  39. protected override void AddEventListener()
  40. {
  41. base.AddEventListener();
  42. EventAgent.AddEventListener(ConstMessage.ITEM_CHANGED, UpdateItem);
  43. }
  44. protected override void RemoveEventListener()
  45. {
  46. base.RemoveEventListener();
  47. EventAgent.RemoveEventListener(ConstMessage.ITEM_CHANGED, UpdateItem);
  48. }
  49. protected override void OnShown()
  50. {
  51. base.OnShown();
  52. _skillId = (int)this.viewData;
  53. _ui.m_slideUpLevel.visible = false;
  54. ItemExchangeCfg itemCfg = ItemExchangeCfgArray.Instance.GetCfg(_skillId);
  55. getMaxCount();
  56. _ui.m_listConsume.data = itemCfg.costId;
  57. UpdateItem();
  58. }
  59. private void RenderListConsumeItem(int index, GObject obj)
  60. {
  61. var itemSkill = (int[][])obj.parent.data;
  62. UI_ComItem item = UI_ComItem.Proxy(obj);
  63. ItemCfg itemCfg = ItemCfgArray.Instance.GetCfg(itemSkill[index][0]);
  64. RarityIconController.UpdateRarityIcon(item.m_loaRarity, itemCfg.id, false);
  65. string ext = ItemUtil.GetItemResExt(itemCfg.itemType, itemCfg.subType, true);
  66. item.m_CountType.selectedIndex = 1;
  67. item.m_txtDecomCount.text = ItemDataManager.GetItemNum(itemCfg.id).ToString();
  68. item.m_txtDecomHasCount.text = "/" + (itemSkill[index][1]*_nowCount).ToString();
  69. item.m_loaIcon.url = ResPathUtil.GetIconPath(itemCfg.res, ext);
  70. item.m_QualityType.selectedIndex = itemCfg.rarity - 1;
  71. if (item.target.data == null)
  72. item.target.onClick.Add(() => { GoodsItemTipsController.ShowItemTips(itemSkill[index][0]); });
  73. item.target.data = index;
  74. UI_ComItem.ProxyEnd();
  75. }
  76. protected override void OnHide()
  77. {
  78. base.OnHide();
  79. }
  80. private void getMaxCount()
  81. {
  82. ItemCfg itemCfg = ItemCfgArray.Instance.GetCfg(_skillId);
  83. foreach (var info in itemCfg.param1Arr) {
  84. long cout = ItemDataManager.GetItemNum(info[0]) / info[1];
  85. if (_maxCount == 0 || _maxCount > cout)
  86. _maxCount = cout;
  87. }
  88. }
  89. private void OnBtnCancelClick()
  90. {
  91. ViewManager.GoBackFrom(typeof(ExchangeGoodsView).FullName);
  92. }
  93. private async void OnBtnUseClick()
  94. {
  95. //兑换物品
  96. await ItemExchangeSProxy.ItemExchange(_skillId, _nowCount);
  97. }
  98. private void OnClickAllChoose()
  99. {
  100. _nowCount = _maxCount;
  101. ReferViewInfo();
  102. ReferSlide();
  103. }
  104. private void OnClickBtnAdd()
  105. {
  106. _nowCount += 1;
  107. if (_nowCount > _maxCount)
  108. _nowCount = _maxCount;
  109. ReferViewInfo();
  110. ReferSlide();
  111. }
  112. private void OnClickBtnReduce()
  113. {
  114. _nowCount -= 1;
  115. if (_nowCount < 0)
  116. _nowCount = 0;
  117. ReferViewInfo();
  118. ReferSlide();
  119. }
  120. private void OnChangeUpLevel()
  121. {
  122. float volumn = (float)_ui.m_slideUpLevel.value / 100;
  123. _nowCount = (int)(volumn * _maxCount);
  124. ReferViewInfo();
  125. }
  126. private void ReferViewInfo()
  127. {
  128. _ui.m_txtChooseLevel.text = _nowCount.ToString();
  129. }
  130. private void ReferSlide()
  131. {
  132. _ui.m_slideUpLevel.value = (float)_nowCount / _maxCount * 100;
  133. UpdateItem();
  134. }
  135. private void UpdateItem()
  136. {
  137. ItemCfg itemCfg = ItemCfgArray.Instance.GetCfg(_skillId);
  138. UI_ComItem item = UI_ComItem.Proxy(_ui.m_itemSkill);
  139. RarityIconController.UpdateRarityIcon(item.m_loaRarity, itemCfg.id, false);
  140. string ext = ItemUtil.GetItemResExt(itemCfg.itemType, itemCfg.subType, true);
  141. item.m_ShowName.selectedIndex = 2;
  142. long hasNum = ItemDataManager.GetItemNum(itemCfg.id);
  143. item.m_txtCount.text = hasNum.ToString();
  144. item.m_txtName.text = itemCfg.name;
  145. item.m_loaIcon.url = ResPathUtil.GetIconPath(itemCfg.res, ext);
  146. item.m_QualityType.selectedIndex = itemCfg.rarity - 1;
  147. UI_ComItem.ProxyEnd();
  148. _ui.m_txtHasNum.text = "已拥有:" + hasNum;
  149. _ui.m_listConsume.numItems = itemCfg.param1Arr.Length;
  150. }
  151. }
  152. }