GiftBoxSelectorView.cs 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. using System;
  2. using System.Collections.Generic;
  3. using ET;
  4. using FairyGUI;
  5. using UI.Bag;
  6. using UI.CommonGame;
  7. using UnityEngine;
  8. namespace GFGGame
  9. {
  10. public class GiftBoxSelectorView : BaseWindow
  11. {
  12. private UI_GiftBoxSelectorUI _ui;
  13. private int _itemId;
  14. private int _count;
  15. public override void Dispose()
  16. {
  17. base.Dispose();
  18. if (_ui != null)
  19. {
  20. _ui.Dispose();
  21. _ui = null;
  22. }
  23. }
  24. protected override void OnInit()
  25. {
  26. base.OnInit();
  27. packageName = UI_GiftBoxSelectorUI.PACKAGE_NAME;
  28. _ui = UI_GiftBoxSelectorUI.Create();
  29. this.viewCom = _ui.target;
  30. this.viewCom.Center();
  31. this.modal = true;
  32. _ui.m_btnCancel.onClick.Add(OnBtnCancelClick);
  33. _ui.m_list.SetVirtual();
  34. _ui.m_list.itemRenderer = ListItemRender;
  35. _ui.m_list.onClickItem.Add(OnListSelectorItemClick);
  36. }
  37. protected override void AddEventListener()
  38. {
  39. base.AddEventListener();
  40. }
  41. protected override void OnShown()
  42. {
  43. base.OnShown();
  44. _itemId = (int)this.viewData;
  45. _count = (int)ItemDataManager.GetItemNum(_itemId);
  46. UpdateView();
  47. UpdateList();
  48. }
  49. protected override void OnHide()
  50. {
  51. if (_ui.m_list.numItems > 0)
  52. {
  53. _ui.m_list.ScrollToView(0);
  54. }
  55. _ui.m_list.numItems = 0;
  56. base.OnHide();
  57. }
  58. protected override void RemoveEventListener()
  59. {
  60. base.RemoveEventListener();
  61. }
  62. private void UpdateView()
  63. {
  64. ItemCfg itemCfg = ItemCfgArray.Instance.GetCfg(_itemId);
  65. _ui.m_loaIcon.url = ResPathUtil.GetIconPath(itemCfg);
  66. _ui.m_txtName.text = itemCfg.name;
  67. _ui.m_txtTotalNum.text = $"已拥有:{_count}";
  68. _ui.m_txtItemDes.text = string.IsNullOrEmpty(itemCfg.desc) ? "暂无描述" : itemCfg.desc;
  69. }
  70. private void UpdateList()
  71. {
  72. _ui.m_list.numItems = _count;
  73. }
  74. private void ListItemRender(int index, GObject obj)
  75. {
  76. ItemCfg itemCfg = ItemCfgArray.Instance.GetCfg(_itemId);
  77. UI_ListSelectorItem uiItemChild = UI_ListSelectorItem.Proxy(obj);
  78. int[] itemChildArr = itemCfg.itemsArr[index];
  79. ItemCfg itemCfgChild = ItemCfgArray.Instance.GetCfg(itemChildArr[0]);
  80. uiItemChild.m_loaIcon.url = ResPathUtil.GetIconPath(itemCfgChild);
  81. uiItemChild.m_comItemNumBag.m_txtNum.text = itemChildArr[1].ToString();
  82. uiItemChild.target.data = itemCfgChild;
  83. }
  84. private void OnListSelectorItemClick(EventContext context)
  85. {
  86. GComponent comItem = (context.data as GComponent);
  87. ItemCfg itemCfg = comItem.data as ItemCfg;
  88. //弹出物品详细描述框
  89. }
  90. private void OnBtnCancelClick()
  91. {
  92. this.Hide();
  93. }
  94. }
  95. }