ExchangeGoodsView.cs 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  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);
  64. ItemExchangeCfg itemExchangeCfg = ItemExchangeCfgArray.Instance.GetCfg(_skillId);
  65. RarityIconController.UpdateRarityIcon(item.m_loaRarity, itemCfg.id, false);
  66. string ext = ItemUtil.GetItemResExt(itemCfg.itemType, itemCfg.subType, true);
  67. item.m_CountType.selectedIndex = 1;
  68. item.m_txtDecomCount.text = ItemDataManager.GetItemNum(itemCfg.id).ToString();
  69. item.m_txtDecomHasCount.text = "/" + (itemExchangeCfg.costNumArr[index] * _nowCount).ToString();
  70. item.m_loaIcon.url = ResPathUtil.GetIconPath(itemCfg.res, ext);
  71. item.m_QualityType.selectedIndex = itemCfg.rarity - 1;
  72. if (item.target.data == null)
  73. item.target.onClick.Add(() => { GoodsItemTipsController.ShowItemTips(itemSkill); });
  74. item.target.data = index;
  75. UI_ComItem.ProxyEnd();
  76. }
  77. protected override void OnHide()
  78. {
  79. base.OnHide();
  80. _maxCount = 0;
  81. _nowCount = 0;
  82. _ui.m_txtChooseLevel.text = _nowCount.ToString();
  83. }
  84. private void getMaxCount()
  85. {
  86. ItemCfg itemCfg = ItemCfgArray.Instance.GetCfg(_skillId);
  87. ItemExchangeCfg itemExchangeCfg = ItemExchangeCfgArray.Instance.GetCfg(_skillId);
  88. foreach (var info in itemExchangeCfg.costNumArr) {
  89. long cout = ItemDataManager.GetItemNum(itemExchangeCfg.costId) / info;
  90. if (_maxCount == 0 || _maxCount > cout)
  91. _maxCount = cout;
  92. }
  93. }
  94. private void OnBtnCancelClick()
  95. {
  96. ViewManager.GoBackFrom(typeof(ExchangeGoodsView).FullName);
  97. }
  98. private async void OnBtnUseClick()
  99. {
  100. //兑换物品
  101. if(_nowCount <= 0)
  102. {
  103. PromptController.Instance.ShowFloatTextPrompt("请选择兑换数量");
  104. return;
  105. }
  106. await ItemExchangeSProxy.ItemExchange(_skillId, _nowCount);
  107. }
  108. private void OnClickAllChoose()
  109. {
  110. _nowCount = _maxCount;
  111. ReferViewInfo();
  112. ReferSlide();
  113. }
  114. private void OnClickBtnAdd()
  115. {
  116. _nowCount += 1;
  117. if (_nowCount > _maxCount)
  118. _nowCount = _maxCount;
  119. ReferViewInfo();
  120. ReferSlide();
  121. }
  122. private void OnClickBtnReduce()
  123. {
  124. _nowCount -= 1;
  125. if (_nowCount < 0)
  126. _nowCount = 0;
  127. ReferViewInfo();
  128. ReferSlide();
  129. }
  130. private void OnChangeUpLevel()
  131. {
  132. float volumn = (float)_ui.m_slideUpLevel.value / 100;
  133. _nowCount = (int)(volumn * _maxCount);
  134. ReferViewInfo();
  135. }
  136. private void ReferViewInfo()
  137. {
  138. _ui.m_txtChooseLevel.text = _nowCount.ToString();
  139. }
  140. private void ReferSlide()
  141. {
  142. _ui.m_slideUpLevel.value = (float)_nowCount / _maxCount * 100;
  143. UpdateItem();
  144. }
  145. private void UpdateItem()
  146. {
  147. ItemCfg itemCfg = ItemCfgArray.Instance.GetCfg(_skillId);
  148. UI_ComItem item = UI_ComItem.Proxy(_ui.m_itemSkill);
  149. RarityIconController.UpdateRarityIcon(item.m_loaRarity, itemCfg.id, false);
  150. string ext = ItemUtil.GetItemResExt(itemCfg.itemType, itemCfg.subType, true);
  151. item.m_ShowName.selectedIndex = 2;
  152. long hasNum = ItemDataManager.GetItemNum(itemCfg.id);
  153. item.m_txtCount.text = hasNum.ToString();
  154. item.m_txtName.text = itemCfg.name;
  155. item.m_loaIcon.url = ResPathUtil.GetIconPath(itemCfg.res, ext);
  156. item.m_QualityType.selectedIndex = itemCfg.rarity - 1;
  157. UI_ComItem.ProxyEnd();
  158. _ui.m_txtHasNum.text = "已拥有:" + hasNum;
  159. _ui.m_listConsume.numItems = itemCfg.param1Arr.Length;
  160. }
  161. }
  162. }