BagExchangeView.cs 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222
  1. using System;
  2. using System.Collections.Generic;
  3. using cfg.GfgCfg;
  4. using ET;
  5. using FairyGUI;
  6. using UI.Bag;
  7. using UnityEngine;
  8. using UI.CommonGame;
  9. namespace GFGGame
  10. {
  11. public class BagExchangeView : BaseWindow
  12. {
  13. private UI.Bag.UI_ItemExchangeUI _ui;
  14. private int _itemId;
  15. private long _count;
  16. private List<ItemParamProto> _itemList = new List<ItemParamProto>();
  17. // private LongPressGesture _longPressAdd;
  18. // private LongPressGesture _longPressMinus;
  19. public override void Dispose()
  20. {
  21. if (_ui != null)
  22. {
  23. _ui.Dispose();
  24. _ui = null;
  25. }
  26. base.Dispose();
  27. }
  28. protected override void OnInit()
  29. {
  30. base.OnInit();
  31. packageName = UI.Bag.UI_ItemExchangeUI.PACKAGE_NAME;
  32. _ui = UI.Bag.UI_ItemExchangeUI.Create();
  33. this.viewCom = _ui.target;
  34. this.viewCom.Center();
  35. this.modal = true;
  36. _ui.m_btnAdd.onClick.Add(OnBtnAddClick);
  37. _ui.m_btnMinus.target.onClick.Add(OnBtnMinusClick);
  38. _ui.m_btnMax.target.onClick.Add(OnBtnMaxClick);
  39. _ui.m_btnConfirm.onClick.Add(OnBtnConfirmClick);
  40. _ui.m_btnCancle.onClick.Add(OnBtnCancleClick);
  41. _ui.m_listItem.itemRenderer = ListItemRenderer;
  42. _ui.m_comBg.GetChild("btnClose").asCom.onClick.Add(Hide);
  43. }
  44. protected override void AddEventListener()
  45. {
  46. base.AddEventListener();
  47. }
  48. protected override void OnShown()
  49. {
  50. base.OnShown();
  51. _itemId = (int)this.viewData;
  52. _count = 1;
  53. UpdateView();
  54. UpdateUseView();
  55. }
  56. protected override void OnHide()
  57. {
  58. base.OnHide();
  59. }
  60. protected override void RemoveEventListener()
  61. {
  62. base.RemoveEventListener();
  63. // EventAgent.RemoveEventListener(ConstMessage.ITEM_CHANGED, UpdateList);
  64. }
  65. private void UpdateView()
  66. {
  67. ItemCfg itemCfg = CommonDataManager.Tables.TblItemCfg.GetOrDefault(_itemId);
  68. _ui.m_comBg.GetChild("txtTitle").asTextField.text = itemCfg.Name;
  69. _ui.m_txtOwned.SetVar("count", "" + ItemDataManager.GetItemNum(itemCfg.Id)).FlushVars();
  70. _ui.m_txtDesc.text = string.IsNullOrEmpty(itemCfg.Desc) ? "暂无描述" : itemCfg.Desc;
  71. _ui.m_loaIcon.url = ResPathUtil.GetIconPath(itemCfg);
  72. _ui.m_txtRmbCost.visible = false;
  73. _ui.m_grpScore.visible = false;
  74. _ui.m_listTag.visible = false;
  75. UpdateThItemList(itemCfg);
  76. _ui.m_listItem.numItems = _itemList.Count; //itemCfg.itemsArr.Length;
  77. _ui.m_listItem.visible = itemCfg.ItemType == ConstItemType.USEABLE &&
  78. itemCfg.SubType != ConstItemSubType.USEABLE_AUTO;
  79. }
  80. private void UpdateThItemList(ItemCfg itemCfg)
  81. {
  82. _itemList.Clear();
  83. //普通物品
  84. foreach (var t in itemCfg.Items)
  85. {
  86. _itemList.Add(t.ToGfgGameItemParam());
  87. }
  88. if (itemCfg.SubType == ConstItemSubType.USEABLE_GIFT_BAG_RANDOM)
  89. {
  90. if (itemCfg.Param2.Count > 0)
  91. {
  92. //特殊物品 不存在的套装部件id
  93. List<int> noExistSuitItemIds = new List<int>();
  94. foreach (var suitId in itemCfg.Param2)
  95. {
  96. noExistSuitItemIds.Clear();
  97. SuitCfg suitCfg = CommonDataManager.Tables.TblSuitCfg.GetOrDefault(suitId);
  98. foreach (var suitItemId in suitCfg.Parts)
  99. {
  100. if (!ItemUtil.CheckItemEnough(suitItemId, 1))
  101. {
  102. noExistSuitItemIds.Add(suitItemId);
  103. }
  104. }
  105. foreach (var noExistSuitItemId in noExistSuitItemIds)
  106. {
  107. ItemParamProto itemParam = new ItemParamProto();
  108. itemParam.ItemId = noExistSuitItemId;
  109. itemParam.Count = 1;
  110. _itemList.Add(itemParam);
  111. }
  112. }
  113. }
  114. }
  115. //保底物品
  116. if (itemCfg.Param1.Count > 0)
  117. {
  118. foreach (var t in itemCfg.Param1)
  119. {
  120. ItemParamProto itemParam = new ItemParamProto();
  121. itemParam.ItemId = t.ItemId;
  122. itemParam.Count = t.Count;
  123. _itemList.Add(itemParam);
  124. }
  125. }
  126. }
  127. private void UpdateUseView()
  128. {
  129. ItemCfg itemCfg = CommonDataManager.Tables.TblItemCfg.GetOrDefault(_itemId);
  130. _ui.m_txtCostCount.text = _count.ToString();
  131. _ui.m_btnMinus.m_c1.selectedIndex = _count == 1 ? 1 : 0;
  132. _ui.m_btnMinus.target.touchable = _count == 1 ? false : true;
  133. long hasCount = ItemDataManager.GetItemNum(_itemId);
  134. _ui.m_btnAdd.GetController("c1").selectedIndex = _count == hasCount ? 1 : 0;
  135. _ui.m_btnAdd.touchable = _count == hasCount ? false : true;
  136. _ui.m_btnMax.m_c1.selectedIndex = _count == hasCount ? 1 : 0;
  137. _ui.m_btnMax.target.touchable = _count == hasCount ? false : true;
  138. _ui.m_txtExchangeCount.text = string.Format("{0}", hasCount);
  139. _ui.m_txtShow.text = "选择使用数量";
  140. _ui.m_txtTips.text = string.Format("是否使用{0}个{1}?", _count, itemCfg.Name);
  141. }
  142. private void ListItemRenderer(int index, GObject obj)
  143. {
  144. //ItemCfg itemCfg = ItemCfgArray.Instance.GetCfg(_itemId);
  145. var DD = _itemList[index];
  146. ItemData itemData = ItemUtil.createItemData(_itemList[index]);
  147. if (obj.data == null)
  148. {
  149. obj.data = new ItemView(obj as GComponent);
  150. }
  151. (obj.data as ItemView).SetData(itemData);
  152. (obj.data as ItemView).ChangeTxtCountStyle();
  153. }
  154. private void OnBtnAddClick()
  155. {
  156. _count++;
  157. long hasCount = ItemDataManager.GetItemNum(_itemId);
  158. _count = Math.Min(hasCount, _count);
  159. UpdateUseView();
  160. }
  161. private void OnBtnMinusClick()
  162. {
  163. _count--;
  164. _count = Math.Max(1, _count);
  165. UpdateUseView();
  166. }
  167. private void OnBtnMaxClick()
  168. {
  169. _count = ItemDataManager.GetItemNum(_itemId);
  170. UpdateUseView();
  171. }
  172. private void OnBtnConfirmClick()
  173. {
  174. ItemCfg itemCfg = CommonDataManager.Tables.TblItemCfg.GetOrDefault(_itemId);
  175. if (itemCfg.ItemType == ConstItemType.USEABLE &&
  176. itemCfg.SubType == ConstItemSubType.USEABLE_GIFT_BAG_RANDOM)
  177. {
  178. ItemProxy.ReqUseRandomItem(_itemId, _count).Coroutine();
  179. }
  180. else
  181. {
  182. ItemProxy.ReqUseItem(_itemId, _count).Coroutine();
  183. }
  184. this.Hide();
  185. }
  186. private void OnBtnCancleClick()
  187. {
  188. this.Hide();
  189. }
  190. }
  191. }