LuckyBoxPreShowView.cs 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  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.numItems = _bonusList.Count;
  39. }
  40. protected override void OnHide()
  41. {
  42. base.OnHide();
  43. if (_ui.m_list.numItems > 0) _ui.m_list.ScrollToView(0);
  44. _ui.m_list.RemoveChildrenToPool();
  45. }
  46. private void ListItemRenderer(int index, GObject item)
  47. {
  48. UI_CompLuckyBoxBonusListItem listItem = UI_CompLuckyBoxBonusListItem.Proxy(item);
  49. LuckyBoxBonusData luckyBoxBonusData = _bonusList[index];
  50. listItem.m_txtName.text = luckyBoxBonusData.name;
  51. if (listItem.m_list.data == null)
  52. {
  53. listItem.m_list.itemRenderer = ListItemRewardRender;
  54. }
  55. listItem.m_list.data = luckyBoxBonusData.itemList;
  56. listItem.m_list.numItems = luckyBoxBonusData.itemList.Count;
  57. listItem.m_list.ResizeToFit();
  58. listItem.target.height = listItem.m_list.y + listItem.m_list.height;
  59. UI_CompLuckyBoxBonusListItem.ProxyEnd();
  60. }
  61. private void ListItemRewardRender(int index, GObject obj)
  62. {
  63. ItemData itemData = (obj.parent.data as List<ItemData>)[index];
  64. if (obj.data == null)
  65. {
  66. obj.data = new ItemView(obj as GComponent);
  67. }
  68. (obj.data as ItemView).SetData(itemData);
  69. (obj.data as ItemView).ShowHasCount = false;
  70. (obj.data as ItemView).ImgHasVisible = ItemDataManager.GetItemNum(itemData.id) > 0;
  71. }
  72. }
  73. }