ExchangeGoodsView.cs 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  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. }
  43. protected override void RemoveEventListener()
  44. {
  45. base.RemoveEventListener();
  46. }
  47. protected override void OnShown()
  48. {
  49. base.OnShown();
  50. _skillId = (int)this.viewData;
  51. ItemCfg itemCfg = ItemCfgArray.Instance.GetCfg(_skillId);
  52. long hasNum = ItemDataManager.GetItemNum(itemCfg.id);
  53. _ui.m_txtHasNum.text = "已拥有:" + hasNum;
  54. getMaxCount();
  55. UI_ComItem item = UI_ComItem.Proxy(_ui.m_itemSkill);
  56. RarityIconController.UpdateRarityIcon(item.m_loaRarity, itemCfg.id, false);
  57. string ext = ItemUtil.GetItemResExt(itemCfg.itemType, itemCfg.subType, true);
  58. item.m_ShowName.selectedIndex = 2;
  59. item.m_txtCount.text = "1";
  60. item.m_txtName.text = itemCfg.name;
  61. item.m_loaIcon.url = ResPathUtil.GetIconPath(itemCfg.res, ext);
  62. item.m_QualityType.selectedIndex = itemCfg.rarity - 1;
  63. UI_ComItem.ProxyEnd();
  64. _ui.m_listConsume.data = itemCfg.param1Arr;
  65. _ui.m_listConsume.numItems = itemCfg.param1Arr.Length;
  66. }
  67. private void RenderListConsumeItem(int index, GObject obj)
  68. {
  69. var itemSkill = (int[][])obj.parent.data;
  70. UI_ComItem item = UI_ComItem.Proxy(obj);
  71. ItemCfg itemCfg = ItemCfgArray.Instance.GetCfg(itemSkill[index][0]);
  72. RarityIconController.UpdateRarityIcon(item.m_loaRarity, itemCfg.id, false);
  73. string ext = ItemUtil.GetItemResExt(itemCfg.itemType, itemCfg.subType, true);
  74. item.m_CountType.selectedIndex = 1;
  75. item.m_txtDecomCount.text = itemSkill[index][1].ToString();
  76. item.m_txtDecomHasCount.text = "/" + ItemDataManager.GetItemNum(itemCfg.id);
  77. item.m_loaIcon.url = ResPathUtil.GetIconPath(itemCfg.res, ext);
  78. item.m_QualityType.selectedIndex = itemCfg.rarity - 1;
  79. if (item.target.data == null)
  80. item.target.onClick.Add(() => { GoodsItemTipsController.ShowItemTips(itemSkill[index][0]); });
  81. item.target.data = index;
  82. UI_ComItem.ProxyEnd();
  83. }
  84. protected override void OnHide()
  85. {
  86. base.OnHide();
  87. }
  88. private void getMaxCount()
  89. {
  90. ItemCfg itemCfg = ItemCfgArray.Instance.GetCfg(_skillId);
  91. foreach (var info in itemCfg.param1Arr) {
  92. long cout = ItemDataManager.GetItemNum(info[0]) / info[1];
  93. if (_maxCount == 0 || _maxCount > cout)
  94. _maxCount = cout;
  95. }
  96. }
  97. private void OnBtnCancelClick()
  98. {
  99. ViewManager.GoBackFrom(typeof(ExchangeGoodsView).FullName);
  100. }
  101. private void OnBtnUseClick()
  102. {
  103. //兑换物品
  104. }
  105. private void OnClickAllChoose()
  106. {
  107. _nowCount = _maxCount;
  108. ReferViewInfo();
  109. ReferSlide();
  110. }
  111. private void OnClickBtnAdd()
  112. {
  113. _nowCount += 1;
  114. if (_nowCount > _maxCount)
  115. _nowCount = _maxCount;
  116. ReferViewInfo();
  117. ReferSlide();
  118. }
  119. private void OnClickBtnReduce()
  120. {
  121. _nowCount -= 1;
  122. if (_nowCount < 0)
  123. _nowCount = 0;
  124. ReferViewInfo();
  125. ReferSlide();
  126. }
  127. private void OnChangeUpLevel()
  128. {
  129. float volumn = (float)_ui.m_slideUpLevel.value / 100;
  130. _nowCount = (int)(volumn * _maxCount);
  131. ReferViewInfo();
  132. }
  133. private void ReferViewInfo()
  134. {
  135. _ui.m_txtChooseLevel.text = _nowCount.ToString();
  136. }
  137. private void ReferSlide()
  138. {
  139. _ui.m_slideUpLevel.value = (float)_nowCount / _maxCount * 100;
  140. }
  141. }
  142. }