LuckyBoxPreShowView.cs 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. using UI.LuckyBox;
  2. using UI.CommonGame;
  3. using System.Collections.Generic;
  4. using FairyGUI;
  5. namespace GFGGame
  6. {
  7. public class LuckyBoxPreShowView : BaseWindow
  8. {
  9. private UI_LuckyBoxPreShowUI _ui;
  10. private List<LuckyBoxBonusData> _bonusList;
  11. public override void Dispose()
  12. {
  13. if (_ui != null)
  14. {
  15. _ui.Dispose();
  16. _ui = null;
  17. }
  18. base.Dispose();
  19. }
  20. protected override void OnInit()
  21. {
  22. base.OnInit();
  23. _ui = UI_LuckyBoxPreShowUI.Create();
  24. this.viewCom = _ui.target;
  25. this.viewCom.Center();
  26. this.modal = true;
  27. }
  28. protected override void OnShown()
  29. {
  30. base.OnShown();
  31. int boxId = (int)this.viewData;
  32. LuckyBoxCfg cfg = LuckyBoxCfgArray.Instance.GetCfg(boxId);
  33. string probShow = cfg.probShow.Replace("\\n", "\n");
  34. _ui.m_compText.m_txtShow.text = probShow;
  35. _bonusList = LuckyBoxDataManager.Instance.GetCurrentShowList(boxId);
  36. _ui.m_list.RemoveChildrenToPool();
  37. _ui.m_list.itemRenderer = ListItemRenderer;
  38. _ui.m_list.SetVirtual();
  39. _ui.m_list.numItems = _bonusList.Count;
  40. }
  41. protected override void OnHide()
  42. {
  43. base.OnHide();
  44. if (_ui.m_list.numItems > 0) _ui.m_list.ScrollToView(0);
  45. _ui.m_list.RemoveChildrenToPool();
  46. }
  47. private void ListItemRenderer(int index, GObject item)
  48. {
  49. UI_CompLuckyBoxBonusListItem listItem = UI_CompLuckyBoxBonusListItem.Proxy(item);
  50. LuckyBoxBonusData luckyBoxBonusData = _bonusList[index];
  51. listItem.m_txtName.text = luckyBoxBonusData.name;
  52. if (listItem.m_list.data == null)
  53. {
  54. listItem.m_list.itemRenderer = ListItemRewardRender;
  55. }
  56. listItem.m_list.data = luckyBoxBonusData.itemList;
  57. listItem.m_list.numItems = luckyBoxBonusData.itemList.Count;
  58. listItem.m_list.ResizeToFit();
  59. listItem.target.height = listItem.m_list.y + listItem.m_list.height;
  60. UI_CompLuckyBoxBonusListItem.ProxyEnd();
  61. }
  62. private void ListItemRewardRender(int index, GObject obj)
  63. {
  64. ItemData itemData = (obj.parent.data as List<ItemData>)[index];
  65. if (obj.data == null)
  66. {
  67. obj.data = new ItemView(obj as GComponent);
  68. }
  69. (obj.data as ItemView).SetData(itemData);
  70. (obj.data as ItemView).ImgHasVisible = ItemDataManager.GetItemNum(itemData.id) > 0;
  71. }
  72. }
  73. }