LuckyBoxPreShowView.cs 2.5 KB

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